Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

7.5 KB
Raw Blame

Notifications

Paths are relative to the webv2 src/ directory.

Workbench notifications are plain data in workbench state (WorkbenchNotification in workbench/projectContracts.ts). They are session-only: hydration empties the list and the saved session does not include it. Workbench state must still stay plain, cloneable data, so a notification never holds a closure. Callers record through useNotify (workbench/useNotify.ts) or commands.notifications.add; WorkbenchNotificationToaster toasts each one recorded while the editor is mounted, subject to toastPolicy.ts. Outside the editor useNotify falls back to plain platform toasts.

Actions

A notification offers buttons through actions, a list of WorkbenchNotificationAction descriptors such as { kind: 'open-widget', widgetId: 'gallery' }. notificationActions.ts maps every kind to a handler: label returns the translated button text, or null when this editor cannot offer the action (the widget is not enabled, the undo is gone or its project closed), and run acts through the NotificationActionContext; optional hold and release bracket the time a toast shows the action, which keeps it even once its record left the list. editorNotificationActions.ts builds that context from the editor's store, widget registry and focus: open-widget brings a placed widget forward (raising a floating window) or opens it, then moves focus there. reveal-queue-item opens the queue at a backend item; retry-queue-item re-runs a run's failed backend items through Queue's retry command in one request, once per set of items however many notices or toasts offer it, then withdraws the button from every notice and reports the result (shared with the queue's own Retry button, with the number of items queued again) with a way to the first rerun. A new kind is a union member plus a handler; the handler table's mapped type fails to compile until both exist. Handlers that need another owner's command reach it through that owner's public entry or a context field, never through the descriptor.

Toasts with actions stay for ACTION_TOAST_DURATION_MS (hovering or focusing pauses them) and close when the editor unmounts, so no button outlives the store it acts on. persistent: true keeps a toast until the user closes it; use it for failures the user must not miss. Persistent toasts also close with the editor, or outside it with the account, so they never carry over to the next user. A repeat of the newest error coalesces into it and takes the repeat's actions, which act on the latest occurrence. Only a repeated run outcome toasts again; an ambient repeat updates the record while a toast still showing keeps its old buttons.

A notification's text is titleKey/messageKey with titleValues/messageValues where it has one, so it follows the language; title/message hold the English and stand in otherwise (resolveNotificationText). A failed run records a persistent error naming its project and prompt or workflow, with Show in queue and Retry once the failed backend item is known. connectionNotices.ts announces a lost connection once it has lasted four seconds, and its return only if the loss was announced.

The Notifications widget lists the same records with the same buttons, repeat counts, relative times in the active language and a dismiss per item; dismissing moves focus to the next notice, else the previous, else the list. Once the list has shown its newest unread notice for a moment it counts everything as read, so a glance, or React's StrictMode remount, marks nothing. Clear empties the list and shows its Undo as a toast only (undoable with transient), since a record of it would sit in the list it emptied.

Undo

notify.undoable(title, { message, onUndo, projectId, undoLabel }) reports an action that already happened, the house style for reversible changes. It records a success notice carrying { kind: 'undo', undoId, projectId, label }; the closure waits in undoRegistry.ts, a session-only map cleared on account change. The optional undoLabel, recorded as the descriptor's label, replaces the button's "Undo" when it brings back something other than the reported action, such as Canvas's "Review N others" after an accept set the other results aside; it is stored text, translated when recorded. The record owns the closure and its toast only borrows it: an entry lives while a listed notice names its undoId or a toast holds it, so the Notifications widget still offers Undo after the toast timed out, and a notice recorded without a toast offers it there too. Undo runs at most once from either surface, then leaves both (a toast still offering it closes). The entry goes when it runs, when a newer undo supersedes it, when its notice leaves the list (dismissed, cleared, or pushed past the 100-notice limit) and no toast holds it, when its project closes, or on account change. startNotificationToasts keeps the registry in step with the list. Entries neither listed nor shown (recorded while the editor shell was not mounted) are capped at 20, oldest dropped first. A tab therefore keeps at most 100 listed and 20 idle closures per account, plus what open toasts hold (Clear's toast can hold up to 100 cleared notices'). Most capture ids or small records; Canvas's restore undo keeps a document (metadata only, pixels stay engine-owned), one per project through supersedes. Notices Clear's Undo puts back do not toast again. Clear's transient toast holds the cleared notices' actions (holdsActions), so the notices its Undo restores keep their own Undo. Outside the editor there is no center: undoable shows its Undo toast directly, closed with the account. transient: true does the same inside the editor, for undoing a change to the center itself.

supersedes names what an undo reverts (generate-settings:<projectId> for Generate's model switch, preset and reset; generate-prompt:<projectId> for prompt changes that Ctrl+Z in the prompt cannot undo, such as choosing a template, a history entry that also replaces the negative prompt, or an Expand result that landed after its popover closed; video-prompt:<projectId> for the same in Video, whose prompt is its own; layout:<projectId> for layout steps: a preset switch, a revert, discarding a preset's unsaved arrangement, a removed widget; LayoutUndoNotices also withdraws that key once its step is no longer the latest). A newer undo with the same key withdraws the older ones and closes their toasts, since undoing an older step after a newer one would leave a mix of both.

An Undo can run minutes after the change, from the list, after tab switches. onUndo therefore captures the ids of what it reverts, never "the active project", and does nothing (or reports) when its target is gone or has changed since. With projectId, closing that project withdraws the Undo from the list and closes its toast.

Confirmation dialogs are for permanent or bulk actions, not a substitute for undo.

Platform toaster

createActionToast (platform/ui/toaster.tsx) renders buttons, primary first; each dismisses the toast before it acts. Generate offers a result held back from a prompt edited meanwhile this way (Replace or Discard): a toast that stays until answered and closes with the account, never a record in the center, since its buttons hold closures. A signal dismisses the toast when its scope ends, and an already-ended signal shows nothing. The toast region takes focus with Alt+T, and Tab then reaches each toast and its buttons. The close button's name comes from common.dismissNotification.