@proteos/component-sdk 0.82.1 → 0.83.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/hooks.ts CHANGED
@@ -11,7 +11,12 @@ import {
11
11
  RuntimeContext,
12
12
  type RuntimeContextValue,
13
13
  } from './context'
14
- import type { PageActionContext, PageActionOutcome, PageContext } from './protocol'
14
+ import type {
15
+ PageActionContext,
16
+ PageActionOutcome,
17
+ PageContext,
18
+ RecordDraftReviewOutcome,
19
+ } from './protocol'
15
20
 
16
21
  /**
17
22
  * Low-level escape hatch: the whole runtime context (sdk, props, pageCtx,
@@ -76,6 +81,31 @@ export function useOpenCall(): (conversationBriefId: string) => void {
76
81
  return useRuntime().openCall
77
82
  }
78
83
 
84
+ /**
85
+ * Open the HOST's review of a record draft — a proposed record write (e.g. the
86
+ * `record_draft_id` an activity keeps). The review is the web app's own: the
87
+ * current values next to the proposed ones, editable for one record, a table
88
+ * for several. A component cannot render it in its frame.
89
+ *
90
+ * ```ts
91
+ * const openRecordDraftReview = useRecordDraftReview()
92
+ * const outcome = await openRecordDraftReview(activity.record_draft_id)
93
+ * if (outcome) refetch() // 'approved' | 'approved_with_changes' | 'rejected'
94
+ * ```
95
+ *
96
+ * Resolves with the draft's terminal status once the review closes (at once
97
+ * for a draft already decided), or `null` when the person closed it
98
+ * undecided — the draft stays proposed — or the host could not open it
99
+ * (public pages, previews, a review from this component already open).
100
+ * Approving writes the records as the viewer; the host then invalidates this
101
+ * component's queries.
102
+ */
103
+ export function useRecordDraftReview(): (
104
+ recordDraftId: string,
105
+ ) => Promise<RecordDraftReviewOutcome | null> {
106
+ return useRuntime().openRecordDraftReview
107
+ }
108
+
79
109
  /**
80
110
  * Open or minimize the HOST's agent session window (the floating assistant)
81
111
  * from a component — the iframe cannot render it itself.
package/src/index.ts CHANGED
@@ -33,6 +33,7 @@ export {
33
33
  usePageAction,
34
34
  usePageContext,
35
35
  useProps,
36
+ useRecordDraftReview,
36
37
  useRuntime,
37
38
  useSdk,
38
39
  } from './hooks'
@@ -57,6 +58,7 @@ export {
57
58
  type OpenCallMessage,
58
59
  type OpenModalMessage,
59
60
  type OpenPeekMessage,
61
+ type OpenRecordDraftReviewMessage,
60
62
  type OverlayRect,
61
63
  type OverlayRectMessage,
62
64
  type OverlayStateMessage,
@@ -67,6 +69,8 @@ export {
67
69
  type PageContext,
68
70
  type PageMode,
69
71
  type ReadyMessage,
72
+ type RecordDraftReviewClosedMessage,
73
+ type RecordDraftReviewOutcome,
70
74
  type ResizeMessage,
71
75
  type RunPageActionMessage,
72
76
  type RuntimeMessage,
package/src/protocol.ts CHANGED
@@ -196,6 +196,19 @@ export interface PageActionSettledMessage {
196
196
  outcome: PageActionOutcome
197
197
  }
198
198
 
199
+ /** How a host record-draft review ended: the draft's terminal status. */
200
+ export type RecordDraftReviewOutcome = 'approved' | 'approved_with_changes' | 'rejected'
201
+
202
+ /** Resolution of an OPEN_RECORD_DRAFT_REVIEW request: the review closed.
203
+ * `outcome` is absent when it closed undecided — the draft stays proposed —
204
+ * or when the host could not open it (a public page, a preview, a review
205
+ * from this frame already open). */
206
+ export interface RecordDraftReviewClosedMessage {
207
+ type: 'RECORD_DRAFT_REVIEW_CLOSED'
208
+ requestId: string
209
+ outcome?: RecordDraftReviewOutcome
210
+ }
211
+
199
212
  export type HostMessage =
200
213
  | InitMessage
201
214
  | AuthRefreshMessage
@@ -203,6 +216,7 @@ export type HostMessage =
203
216
  | OverlayRectMessage
204
217
  | ModalClosedMessage
205
218
  | PageActionSettledMessage
219
+ | RecordDraftReviewClosedMessage
206
220
 
207
221
  // ── Runtime → host ──────────────────────────────────────────────────────────
208
222
 
@@ -237,6 +251,22 @@ export interface OpenCallMessage {
237
251
  conversationBriefId: string
238
252
  }
239
253
 
254
+ /** Ask the host to open its review of a record draft (a proposed record
255
+ * write): the current values next to the proposed ones, editable for one
256
+ * record, a table for several. The host answers RECORD_DRAFT_REVIEW_CLOSED
257
+ * with the same `requestId` once the review closes. Approving writes the
258
+ * records server-side as the viewer; the host then sends DATA_INVALIDATE.
259
+ *
260
+ * One review per frame at a time; ignored (answered without an outcome) on
261
+ * public pages and by hosts without one. */
262
+ export interface OpenRecordDraftReviewMessage {
263
+ type: 'OPEN_RECORD_DRAFT_REVIEW'
264
+ /** Correlates the eventual RECORD_DRAFT_REVIEW_CLOSED. Generated by the runtime. */
265
+ requestId: string
266
+ /** The record draft to review. */
267
+ recordDraftId: string
268
+ }
269
+
240
270
  /** The runtime has (or no longer has) an overlay open and needs the host to
241
271
  * promote (or restore) the iframe. See {@link COMPONENT_OVERLAY_Z_INDEX}.
242
272
  *
@@ -407,6 +437,7 @@ export type RuntimeMessage =
407
437
  | NavigateMessage
408
438
  | OpenPeekMessage
409
439
  | OpenCallMessage
440
+ | OpenRecordDraftReviewMessage
410
441
  | OverlayStateMessage
411
442
  | OpenModalMessage
412
443
  | ModalResultMessage
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/protocol.ts"],"names":[],"mappings":";AAYO,IAAM,cAAA,GAAiB;AAuBvB,IAAM,yBAAA,GAA4B;AAmYlC,SAAS,cAAc,IAAA,EAA8C;AAC1E,EAAA,OACE,OAAO,IAAA,KAAS,QAAA,IAChB,IAAA,KAAS,IAAA,IACR,KAA8B,MAAA,KAAW,cAAA,IAC1C,OAAQ,IAAA,CAA4B,IAAA,KAAS,QAAA;AAEjD;AAEO,SAAS,iBAAiB,IAAA,EAAiD;AAChF,EAAA,OACE,OAAO,IAAA,KAAS,QAAA,IAChB,IAAA,KAAS,IAAA,IACR,KAA8B,MAAA,KAAW,cAAA,IAC1C,OAAQ,IAAA,CAA4B,IAAA,KAAS,QAAA;AAEjD","file":"chunk-IYXDPNMJ.js","sourcesContent":["// postMessage protocol between the host page and the component-runtime iframe.\n// This is the single source of truth for the wire contract: the host renderer\n// (clients/web .../component-frame.tsx), the runtime shell\n// (clients/web/component-runtime/shell.tsx), and the author-facing hooks\n// (this package's RuntimeProvider / useNavigate) all import these same types so\n// every end stays in lockstep.\n//\n// Every message carries `source: MESSAGE_SOURCE` so we can ignore the unrelated\n// postMessage traffic that shares the window (OIDC silent-renew, Vite HMR, …).\n\nimport type { PageAction } from '@proteos/sdk'\n\nexport const MESSAGE_SOURCE = 'proteos-component-runtime' as const\n\n/**\n * z-index the component iframe is promoted to while one of its own overlays\n * (modal, popover, menu, select, tooltip) is open. The iframe goes\n * `position: fixed; inset: 0` at this z so the overlay — which portals to the\n * IFRAME's body and would otherwise clip at the frame's box — can paint over\n * the rest of the page.\n *\n * Host z ladder this slots into:\n * 50 @proteos/ui Modal / Tooltip / ImageLightbox (default tier)\n * 1000+ full-page panel stack (scrim 1000, panels 1001+n)\n * 1090 peek scrim 1100 peek panel, ask-proteos window\n * 1150 ← THIS\n * 1200 menu popover, command palette, action dialog, component modal\n * 1300 select popover\n *\n * Above the peek/full-page surfaces a component can live on, below the global\n * host chrome. Note the cap: inside a peek (a `fixed` + z-index ancestor) the\n * promoted iframe paints within that 1100 stacking context — it covers the\n * peek's own content and everything under it, but host chrome at 1200+ still\n * wins. That is the intended layering, not a bug.\n */\nexport const COMPONENT_OVERLAY_Z_INDEX = 1150\n\n/** Viewport-relative box of the iframe's in-flow placeholder, in CSS px. */\nexport interface OverlayRect {\n top: number\n left: number\n width: number\n height: number\n}\n\n/** What the viewer is doing with the record on the host page.\n *\n * - `view` — a read-only record page, or a page without a record\n * (platform, kiosk, public, previews).\n * - `create` — the form for a record that is not saved yet (`record` holds\n * the seed values only, no `id`).\n * - `edit` — the form over an existing record (`record` is the SAVED row;\n * in-flight edits are not reflected).\n *\n * Inside an action's / workflow's invoke dialog (a trigger page) `mode` is\n * `create` while the person fills the params and `view` once the run is on\n * its way; `phase` says where the run is.\n *\n * A snapshot like `record`: the host remounts the frame when the page\n * switches between view and edit, so a new INIT carries the new mode. Also\n * the Liquid scope key `mode` when props are resolved. */\nexport type PageMode = 'view' | 'create' | 'edit'\n\n/** Where an invocation is in the invoke dialog's lifecycle — set only on a\n * trigger page (the dialog of an action / workflow); absent everywhere else.\n *\n * - `input` — the form over the params (`record` = the seeded params).\n * - `running` — the run is in flight (`record` = the submitted params;\n * `params.execution` for a workflow).\n * - `result` — the run ended (`record` = the params plus the action's\n * returns; `params.result` / `params.execution`).\n *\n * Also the Liquid scope key `phase`. */\nexport type TriggerPhase = 'input' | 'running' | 'result'\n\nexport interface PageContext {\n record?: Record<string, unknown>\n entity?: { slug: string; [key: string]: unknown }\n params?: Record<string, unknown>\n mode: PageMode\n phase?: TriggerPhase\n /** The signed-in viewer (absent on public pages and offline previews). The\n * host resolves `{{ current_user.* }}` and the bare `current_user` prop\n * sentinel against it before posting props. */\n current_user?: { id: string; email: string; given_name: string; family_name: string }\n [key: string]: unknown\n}\n\n// ── Host → runtime ──────────────────────────────────────────────────────────\n\nexport interface InitMessage {\n type: 'INIT'\n /** Raw bearer token (the OIDC `id_token`). The runtime's ProteosClient\n * prepends `Bearer ` when building the Authorization header, so the host\n * sends the token verbatim — NOT a full `Bearer …` header value.\n * Empty string in public mode (`isPublic: true`). */\n authToken: string\n /** API origin the bundle endpoint + SDK calls resolve against. */\n apiBaseUrl: string\n /** Content hash (hex SHA-256) of the component's deployed bundle, from the\n * component's `bundle_checksum`. The runtime appends it as `?v=` to the\n * bundle request so the server can mark the response immutable — the\n * browser then serves every later mount from its cache without a round\n * trip. Absent when the host does not know it yet (metadata still\n * loading, or a row deployed before checksum stamping); the bundle then\n * revalidates as before. */\n bundleVersion?: string\n /** Key under which the runtime shares its query cache with sibling and\n * successor frames of the same component through the host (same\n * origin): the host warms a new frame from the last state a frame with\n * this key left behind. Covers the slug AND the resolved props, so two\n * placements configured differently never share. Absent on hosts that\n * do not keep a store (previews, public pages). */\n cacheKey?: string\n /** Resolved props for the component (Liquid templating happens host-side). */\n props: Record<string, unknown>\n pageCtx: PageContext\n /** PUBLIC mode: the component renders on an unauthenticated public page.\n * The shell fetches the bundle from the public endpoint (no bearer) and\n * injects a restricted sdk — only `functions.actions.invokePublic` reaches\n * the platform. Requires `orgId`. */\n isPublic?: boolean\n /** Org id for public mode — public endpoints carry the org in the path\n * because there is no token to scope from. */\n orgId?: string\n /** Set when this frame is the CONTENT of a host component modal (opened by\n * another component via OPEN_MODAL). The component reads it through\n * `useModalHost()` and closes with a result by posting MODAL_RESULT with\n * this id. Absent on ordinary page-hosted frames. */\n modalRequestId?: string\n}\n\nexport interface AuthRefreshMessage {\n type: 'AUTH_REFRESH'\n token: string\n}\n\nexport interface DataInvalidateMessage {\n type: 'DATA_INVALIDATE'\n queryKey?: unknown[]\n}\n\n/** Where the iframe's in-flow box sits in the host viewport. Sent while the\n * frame is promoted (OVERLAY_STATE open) so the runtime can keep its content\n * parked at the original rect while the iframe itself covers the viewport —\n * and re-sent when the host window resizes under an open overlay. */\nexport interface OverlayRectMessage {\n type: 'OVERLAY_RECT'\n rect: OverlayRect\n}\n\n/** Resolution of an OPEN_MODAL request: the host modal closed. `result` is the\n * value the modal's component passed to MODAL_RESULT, and is absent when the\n * modal was dismissed (backdrop / Esc / ×). */\nexport interface ModalClosedMessage {\n type: 'MODAL_CLOSED'\n requestId: string\n result?: unknown\n}\n\n/** How a RUN_PAGE_ACTION ended, by what the button did:\n *\n * - `done` — the run went through: an action's `returns` (null when it\n * returned none), a workflow's accepted `executionId`, the\n * record an intent created / updated.\n * - `failed` — the invocation failed and the person closed the error.\n * - `cancelled` — the person stepped out before anything ran or saved.\n * - `handed_over` — an `agent` / `link` button: the chat or the tab is open;\n * what happens there is not reported back.\n * - `unavailable` — nothing was opened: `invalid` (the action does not parse),\n * `hidden` (its `visible_when` does not match, an intent\n * has no record to act on, a link no address to open),\n * `busy` (another page action is still open), `unsupported`\n * (a public page, a host without page actions — a preview —\n * or an agent button where there is no agent window). */\nexport type PageActionOutcome =\n | { status: 'done'; kind: 'action'; returns: Record<string, unknown> | null }\n | { status: 'done'; kind: 'workflow'; executionId: string }\n | {\n status: 'done'\n kind: 'intent'\n mode: 'create' | 'update'\n entitySlug: string\n recordId: string\n title: string\n }\n | { status: 'failed'; error: { code: string; message: string } }\n | { status: 'cancelled' }\n | { status: 'handed_over'; kind: 'agent' | 'link' }\n | { status: 'unavailable'; reason: 'invalid' | 'hidden' | 'busy' | 'unsupported' }\n\n/** Resolution of a RUN_PAGE_ACTION request, once the run's flow is over. */\nexport interface PageActionSettledMessage {\n type: 'PAGE_ACTION_SETTLED'\n requestId: string\n outcome: PageActionOutcome\n}\n\nexport type HostMessage =\n | InitMessage\n | AuthRefreshMessage\n | DataInvalidateMessage\n | OverlayRectMessage\n | ModalClosedMessage\n | PageActionSettledMessage\n\n// ── Runtime → host ──────────────────────────────────────────────────────────\n\nexport interface ReadyMessage {\n type: 'READY'\n}\n\nexport interface ResizeMessage {\n type: 'RESIZE'\n height: number\n}\n\nexport interface NavigateMessage {\n type: 'NAVIGATE'\n to: string\n}\n\n/** Open an in-app path in a peek (slide-over) panel instead of full-page\n * navigation. Same `/…` in-app path grammar as NAVIGATE; the host decides\n * what can peek (today: platform pages) and falls back to NAVIGATE otherwise. */\nexport interface OpenPeekMessage {\n type: 'OPEN_PEEK'\n to: string\n}\n\n/** Ask the host to open a prepared call: the host shows the conversation brief's\n * preview (its softphone owns the dial) and lets the user place the call.\n * Ignored on public pages and on hosts without a softphone. */\nexport interface OpenCallMessage {\n type: 'OPEN_CALL'\n /** The conversation brief to preview and dial from. */\n conversationBriefId: string\n}\n\n/** The runtime has (or no longer has) an overlay open and needs the host to\n * promote (or restore) the iframe. See {@link COMPONENT_OVERLAY_Z_INDEX}.\n *\n * Same-origin today, so the runtime applies the promotion styles to its own\n * `window.frameElement` synchronously (pre-paint, no flicker) and this message\n * is the host's cue to MIRROR that state into React — gate RESIZE, hold the\n * placeholder height, start posting OVERLAY_RECT. When components move to a\n * dedicated origin the runtime can no longer touch the frame and this message\n * becomes the actuation instead; the runtime hides its overlay until the\n * answering OVERLAY_RECT arrives. */\nexport interface OverlayStateMessage {\n type: 'OVERLAY_STATE'\n open: boolean\n}\n\n/** Width of a host component modal's panel: `sm` 384px, `md` 512px, `lg` 672px,\n * `xl` 896px. Below 640px the modal is a full-screen sheet whatever the\n * width. */\nexport type ModalWidth = 'sm' | 'md' | 'lg' | 'xl'\n\n/** Ask the host to open ANOTHER component in a central modal, above everything\n * this frame could reach on its own. The host answers with MODAL_CLOSED\n * carrying the same `requestId`.\n *\n * One modal per opener at a time: while a request from this frame is still\n * open, the host answers any further OPEN_MODAL from it as dismissed (a\n * double click must not stack two dialogs). The modal's own component may\n * open another — that request comes from a different frame. */\nexport interface OpenModalMessage {\n type: 'OPEN_MODAL'\n /** Correlates the eventual MODAL_CLOSED. Generated by the opener. */\n requestId: string\n /** Slug of the component to mount inside the modal. */\n componentSlug: string\n /** Props for that component. The host renders Liquid in every string value\n * against the OPENER's page scope (`record`, `entity`, `params`,\n * `current_user`) before handing them over — exactly as it does for a\n * page-placed component. So `{{ … }}` / `{% … %}` in a value is evaluated,\n * not passed through. */\n props?: Record<string, unknown>\n /** Optional modal heading. */\n title?: string\n /** Panel width. Defaults to `lg`. */\n width?: ModalWidth\n /** Height of the component's frame, in px. Set: the frame is that tall from\n * the first paint (capped at the viewport), scrolls its own content, and\n * sits edge to edge in the panel — the component owns its padding. Unset:\n * the frame grows with its content inside the host's padded body. */\n height?: number\n}\n\n/** Escape was pressed with focus inside the iframe, and nothing in the runtime\n * consumed it.\n *\n * Keyboard events don't cross the iframe boundary, and react-aria binds its\n * Escape handling to the overlay element in its own React tree — so a\n * host-rendered dialog CANNOT see Escape once the user has clicked into a\n * component. The runtime forwards it so the host can dismiss on the user's\n * behalf. Not sent while the runtime has its own overlay open: that overlay\n * owns Escape. */\nexport interface EscapePressedMessage {\n type: 'ESCAPE_PRESSED'\n}\n\n/** Posted by the component INSIDE a host modal to close it with a value. The\n * `requestId` is the one INIT carried as `modalRequestId`. */\nexport interface ModalResultMessage {\n type: 'MODAL_RESULT'\n requestId: string\n result?: unknown\n}\n\n/** Ask the host to open its agent session window (the floating assistant).\n *\n * - `sessionId` set: the window resumes THAT session (its agent is read from\n * the session). A `prompt` is sent into it.\n * - no `sessionId`: a fresh session with `agentKey` (or the agent currently\n * selected in the window); a `prompt` is sent as its first message. With\n * neither field the window just opens as it is.\n *\n * Ignored on public pages (there is no signed-in user to run an agent as). */\nexport interface OpenAgentWindowMessage {\n type: 'OPEN_AGENT_WINDOW'\n sessionId?: string\n agentKey?: string\n prompt?: string\n /** Model-only context sent with `prompt`; never rendered. */\n context?: string\n}\n\n/** Ask the host to minimize its agent session window. The active session and\n * its stream stay alive — reopening resumes it. */\nexport interface CloseAgentWindowMessage {\n type: 'CLOSE_AGENT_WINDOW'\n}\n\n/** A record write the component made through its sdk (`data.records.*`)\n * succeeded. Posted by the runtime shell — not by component code — so the\n * host can refresh what it shows of that entity and, when the component\n * sits in a surface that reports edits (the Ava workspace), tell the agent.\n * `patch` is what was submitted, `record` what the server returned. */\nexport interface RecordWrittenMessage {\n type: 'RECORD_WRITTEN'\n entitySlug: string\n operation: 'create' | 'update' | 'delete' | 'batch_upsert'\n recordId?: string\n patch?: Record<string, unknown>\n record?: Record<string, unknown>\n /** Rows in a batch upsert. */\n count?: number\n}\n\n/** A record a page action acts on, as the component names it. */\nexport interface PageActionRecord {\n entitySlug: string\n recordId: string\n /** Shown when the person picks among several records for an intent. */\n title?: string\n /** The entity's display name, shown beside `title` in that pick. */\n entityName?: string\n}\n\n/** What the component knows that the button needs — layered over what the\n * host already knows about the page. */\nexport interface PageActionContext {\n /** Merged over the page scope (`record`, `entity`, `params`, `mode`,\n * `current_user`) the action's Liquid templates render against — `params`\n * / `inputs` prefill, `prompt`, `context`, `entity`, `record`, `url`.\n * Shallow: a key given here replaces the page's. `current_user` is always\n * the host's. */\n scope?: Record<string, unknown>\n /** The records the button acts on. Default: the page record (none on a page\n * without one).\n *\n * - `action` with entity scope — the one record it is invoked on.\n * - `action` with entity_batch scope — every record, in ONE invocation.\n * - `intent` `update_record` without a `record` — the records of the\n * intent's entity it may update: one is updated, several are offered\n * to pick from. */\n records?: PageActionRecord[]\n}\n\n/** Ask the host to run a page action — the same button a page or list toolbar\n * carries, defined inline by the component. The host dispatches it exactly\n * as a toolbar press (invoke dialog, record proposal review, agent window,\n * new tab) and answers PAGE_ACTION_SETTLED with the same `requestId` once\n * the flow is over.\n *\n * One page action at a time: while one is open (from any component) the\n * host answers further requests `unavailable: busy`. */\nexport interface RunPageActionMessage {\n type: 'RUN_PAGE_ACTION'\n /** Correlates the eventual PAGE_ACTION_SETTLED. Generated by the runtime. */\n requestId: string\n action: PageAction\n context?: PageActionContext\n}\n\nexport interface ErrorMessage {\n type: 'ERROR'\n message: string\n stack?: string\n}\n\nexport type RuntimeMessage =\n | ReadyMessage\n | ResizeMessage\n | NavigateMessage\n | OpenPeekMessage\n | OpenCallMessage\n | OverlayStateMessage\n | OpenModalMessage\n | ModalResultMessage\n | EscapePressedMessage\n | OpenAgentWindowMessage\n | CloseAgentWindowMessage\n | RecordWrittenMessage\n | RunPageActionMessage\n | ErrorMessage\n\n// Wire envelope: the message plus the source discriminator.\nexport type Envelope<T> = T & { source: typeof MESSAGE_SOURCE }\n\nexport function isHostMessage(data: unknown): data is Envelope<HostMessage> {\n return (\n typeof data === 'object' &&\n data !== null &&\n (data as { source?: unknown }).source === MESSAGE_SOURCE &&\n typeof (data as { type?: unknown }).type === 'string'\n )\n}\n\nexport function isRuntimeMessage(data: unknown): data is Envelope<RuntimeMessage> {\n return (\n typeof data === 'object' &&\n data !== null &&\n (data as { source?: unknown }).source === MESSAGE_SOURCE &&\n typeof (data as { type?: unknown }).type === 'string'\n )\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/protocol.ts"],"names":[],"mappings":";;;AAYO,IAAM,cAAA,GAAiB;AAuBvB,IAAM,yBAAA,GAA4B;AAmYlC,SAAS,cAAc,IAAA,EAA8C;AAC1E,EAAA,OACE,OAAO,IAAA,KAAS,QAAA,IAChB,IAAA,KAAS,IAAA,IACR,KAA8B,MAAA,KAAW,cAAA,IAC1C,OAAQ,IAAA,CAA4B,IAAA,KAAS,QAAA;AAEjD;AAEO,SAAS,iBAAiB,IAAA,EAAiD;AAChF,EAAA,OACE,OAAO,IAAA,KAAS,QAAA,IAChB,IAAA,KAAS,IAAA,IACR,KAA8B,MAAA,KAAW,cAAA,IAC1C,OAAQ,IAAA,CAA4B,IAAA,KAAS,QAAA;AAEjD","file":"chunk-Q7PTW7DD.cjs","sourcesContent":["// postMessage protocol between the host page and the component-runtime iframe.\n// This is the single source of truth for the wire contract: the host renderer\n// (clients/web .../component-frame.tsx), the runtime shell\n// (clients/web/component-runtime/shell.tsx), and the author-facing hooks\n// (this package's RuntimeProvider / useNavigate) all import these same types so\n// every end stays in lockstep.\n//\n// Every message carries `source: MESSAGE_SOURCE` so we can ignore the unrelated\n// postMessage traffic that shares the window (OIDC silent-renew, Vite HMR, …).\n\nimport type { PageAction } from '@proteos/sdk'\n\nexport const MESSAGE_SOURCE = 'proteos-component-runtime' as const\n\n/**\n * z-index the component iframe is promoted to while one of its own overlays\n * (modal, popover, menu, select, tooltip) is open. The iframe goes\n * `position: fixed; inset: 0` at this z so the overlay — which portals to the\n * IFRAME's body and would otherwise clip at the frame's box — can paint over\n * the rest of the page.\n *\n * Host z ladder this slots into:\n * 50 @proteos/ui Modal / Tooltip / ImageLightbox (default tier)\n * 1000+ full-page panel stack (scrim 1000, panels 1001+n)\n * 1090 peek scrim 1100 peek panel, ask-proteos window\n * 1150 ← THIS\n * 1200 menu popover, command palette, action dialog, component modal\n * 1300 select popover\n *\n * Above the peek/full-page surfaces a component can live on, below the global\n * host chrome. Note the cap: inside a peek (a `fixed` + z-index ancestor) the\n * promoted iframe paints within that 1100 stacking context — it covers the\n * peek's own content and everything under it, but host chrome at 1200+ still\n * wins. That is the intended layering, not a bug.\n */\nexport const COMPONENT_OVERLAY_Z_INDEX = 1150\n\n/** Viewport-relative box of the iframe's in-flow placeholder, in CSS px. */\nexport interface OverlayRect {\n top: number\n left: number\n width: number\n height: number\n}\n\n/** What the viewer is doing with the record on the host page.\n *\n * - `view` — a read-only record page, or a page without a record\n * (platform, kiosk, public, previews).\n * - `create` — the form for a record that is not saved yet (`record` holds\n * the seed values only, no `id`).\n * - `edit` — the form over an existing record (`record` is the SAVED row;\n * in-flight edits are not reflected).\n *\n * Inside an action's / workflow's invoke dialog (a trigger page) `mode` is\n * `create` while the person fills the params and `view` once the run is on\n * its way; `phase` says where the run is.\n *\n * A snapshot like `record`: the host remounts the frame when the page\n * switches between view and edit, so a new INIT carries the new mode. Also\n * the Liquid scope key `mode` when props are resolved. */\nexport type PageMode = 'view' | 'create' | 'edit'\n\n/** Where an invocation is in the invoke dialog's lifecycle — set only on a\n * trigger page (the dialog of an action / workflow); absent everywhere else.\n *\n * - `input` — the form over the params (`record` = the seeded params).\n * - `running` — the run is in flight (`record` = the submitted params;\n * `params.execution` for a workflow).\n * - `result` — the run ended (`record` = the params plus the action's\n * returns; `params.result` / `params.execution`).\n *\n * Also the Liquid scope key `phase`. */\nexport type TriggerPhase = 'input' | 'running' | 'result'\n\nexport interface PageContext {\n record?: Record<string, unknown>\n entity?: { slug: string; [key: string]: unknown }\n params?: Record<string, unknown>\n mode: PageMode\n phase?: TriggerPhase\n /** The signed-in viewer (absent on public pages and offline previews). The\n * host resolves `{{ current_user.* }}` and the bare `current_user` prop\n * sentinel against it before posting props. */\n current_user?: { id: string; email: string; given_name: string; family_name: string }\n [key: string]: unknown\n}\n\n// ── Host → runtime ──────────────────────────────────────────────────────────\n\nexport interface InitMessage {\n type: 'INIT'\n /** Raw bearer token (the OIDC `id_token`). The runtime's ProteosClient\n * prepends `Bearer ` when building the Authorization header, so the host\n * sends the token verbatim — NOT a full `Bearer …` header value.\n * Empty string in public mode (`isPublic: true`). */\n authToken: string\n /** API origin the bundle endpoint + SDK calls resolve against. */\n apiBaseUrl: string\n /** Content hash (hex SHA-256) of the component's deployed bundle, from the\n * component's `bundle_checksum`. The runtime appends it as `?v=` to the\n * bundle request so the server can mark the response immutable — the\n * browser then serves every later mount from its cache without a round\n * trip. Absent when the host does not know it yet (metadata still\n * loading, or a row deployed before checksum stamping); the bundle then\n * revalidates as before. */\n bundleVersion?: string\n /** Key under which the runtime shares its query cache with sibling and\n * successor frames of the same component through the host (same\n * origin): the host warms a new frame from the last state a frame with\n * this key left behind. Covers the slug AND the resolved props, so two\n * placements configured differently never share. Absent on hosts that\n * do not keep a store (previews, public pages). */\n cacheKey?: string\n /** Resolved props for the component (Liquid templating happens host-side). */\n props: Record<string, unknown>\n pageCtx: PageContext\n /** PUBLIC mode: the component renders on an unauthenticated public page.\n * The shell fetches the bundle from the public endpoint (no bearer) and\n * injects a restricted sdk — only `functions.actions.invokePublic` reaches\n * the platform. Requires `orgId`. */\n isPublic?: boolean\n /** Org id for public mode — public endpoints carry the org in the path\n * because there is no token to scope from. */\n orgId?: string\n /** Set when this frame is the CONTENT of a host component modal (opened by\n * another component via OPEN_MODAL). The component reads it through\n * `useModalHost()` and closes with a result by posting MODAL_RESULT with\n * this id. Absent on ordinary page-hosted frames. */\n modalRequestId?: string\n}\n\nexport interface AuthRefreshMessage {\n type: 'AUTH_REFRESH'\n token: string\n}\n\nexport interface DataInvalidateMessage {\n type: 'DATA_INVALIDATE'\n queryKey?: unknown[]\n}\n\n/** Where the iframe's in-flow box sits in the host viewport. Sent while the\n * frame is promoted (OVERLAY_STATE open) so the runtime can keep its content\n * parked at the original rect while the iframe itself covers the viewport —\n * and re-sent when the host window resizes under an open overlay. */\nexport interface OverlayRectMessage {\n type: 'OVERLAY_RECT'\n rect: OverlayRect\n}\n\n/** Resolution of an OPEN_MODAL request: the host modal closed. `result` is the\n * value the modal's component passed to MODAL_RESULT, and is absent when the\n * modal was dismissed (backdrop / Esc / ×). */\nexport interface ModalClosedMessage {\n type: 'MODAL_CLOSED'\n requestId: string\n result?: unknown\n}\n\n/** How a RUN_PAGE_ACTION ended, by what the button did:\n *\n * - `done` — the run went through: an action's `returns` (null when it\n * returned none), a workflow's accepted `executionId`, the\n * record an intent created / updated.\n * - `failed` — the invocation failed and the person closed the error.\n * - `cancelled` — the person stepped out before anything ran or saved.\n * - `handed_over` — an `agent` / `link` button: the chat or the tab is open;\n * what happens there is not reported back.\n * - `unavailable` — nothing was opened: `invalid` (the action does not parse),\n * `hidden` (its `visible_when` does not match, an intent\n * has no record to act on, a link no address to open),\n * `busy` (another page action is still open), `unsupported`\n * (a public page, a host without page actions — a preview —\n * or an agent button where there is no agent window). */\nexport type PageActionOutcome =\n | { status: 'done'; kind: 'action'; returns: Record<string, unknown> | null }\n | { status: 'done'; kind: 'workflow'; executionId: string }\n | {\n status: 'done'\n kind: 'intent'\n mode: 'create' | 'update'\n entitySlug: string\n recordId: string\n title: string\n }\n | { status: 'failed'; error: { code: string; message: string } }\n | { status: 'cancelled' }\n | { status: 'handed_over'; kind: 'agent' | 'link' }\n | { status: 'unavailable'; reason: 'invalid' | 'hidden' | 'busy' | 'unsupported' }\n\n/** Resolution of a RUN_PAGE_ACTION request, once the run's flow is over. */\nexport interface PageActionSettledMessage {\n type: 'PAGE_ACTION_SETTLED'\n requestId: string\n outcome: PageActionOutcome\n}\n\nexport type HostMessage =\n | InitMessage\n | AuthRefreshMessage\n | DataInvalidateMessage\n | OverlayRectMessage\n | ModalClosedMessage\n | PageActionSettledMessage\n\n// ── Runtime → host ──────────────────────────────────────────────────────────\n\nexport interface ReadyMessage {\n type: 'READY'\n}\n\nexport interface ResizeMessage {\n type: 'RESIZE'\n height: number\n}\n\nexport interface NavigateMessage {\n type: 'NAVIGATE'\n to: string\n}\n\n/** Open an in-app path in a peek (slide-over) panel instead of full-page\n * navigation. Same `/…` in-app path grammar as NAVIGATE; the host decides\n * what can peek (today: platform pages) and falls back to NAVIGATE otherwise. */\nexport interface OpenPeekMessage {\n type: 'OPEN_PEEK'\n to: string\n}\n\n/** Ask the host to open a prepared call: the host shows the conversation brief's\n * preview (its softphone owns the dial) and lets the user place the call.\n * Ignored on public pages and on hosts without a softphone. */\nexport interface OpenCallMessage {\n type: 'OPEN_CALL'\n /** The conversation brief to preview and dial from. */\n conversationBriefId: string\n}\n\n/** The runtime has (or no longer has) an overlay open and needs the host to\n * promote (or restore) the iframe. See {@link COMPONENT_OVERLAY_Z_INDEX}.\n *\n * Same-origin today, so the runtime applies the promotion styles to its own\n * `window.frameElement` synchronously (pre-paint, no flicker) and this message\n * is the host's cue to MIRROR that state into React — gate RESIZE, hold the\n * placeholder height, start posting OVERLAY_RECT. When components move to a\n * dedicated origin the runtime can no longer touch the frame and this message\n * becomes the actuation instead; the runtime hides its overlay until the\n * answering OVERLAY_RECT arrives. */\nexport interface OverlayStateMessage {\n type: 'OVERLAY_STATE'\n open: boolean\n}\n\n/** Width of a host component modal's panel: `sm` 384px, `md` 512px, `lg` 672px,\n * `xl` 896px. Below 640px the modal is a full-screen sheet whatever the\n * width. */\nexport type ModalWidth = 'sm' | 'md' | 'lg' | 'xl'\n\n/** Ask the host to open ANOTHER component in a central modal, above everything\n * this frame could reach on its own. The host answers with MODAL_CLOSED\n * carrying the same `requestId`.\n *\n * One modal per opener at a time: while a request from this frame is still\n * open, the host answers any further OPEN_MODAL from it as dismissed (a\n * double click must not stack two dialogs). The modal's own component may\n * open another — that request comes from a different frame. */\nexport interface OpenModalMessage {\n type: 'OPEN_MODAL'\n /** Correlates the eventual MODAL_CLOSED. Generated by the opener. */\n requestId: string\n /** Slug of the component to mount inside the modal. */\n componentSlug: string\n /** Props for that component. The host renders Liquid in every string value\n * against the OPENER's page scope (`record`, `entity`, `params`,\n * `current_user`) before handing them over — exactly as it does for a\n * page-placed component. So `{{ … }}` / `{% … %}` in a value is evaluated,\n * not passed through. */\n props?: Record<string, unknown>\n /** Optional modal heading. */\n title?: string\n /** Panel width. Defaults to `lg`. */\n width?: ModalWidth\n /** Height of the component's frame, in px. Set: the frame is that tall from\n * the first paint (capped at the viewport), scrolls its own content, and\n * sits edge to edge in the panel — the component owns its padding. Unset:\n * the frame grows with its content inside the host's padded body. */\n height?: number\n}\n\n/** Escape was pressed with focus inside the iframe, and nothing in the runtime\n * consumed it.\n *\n * Keyboard events don't cross the iframe boundary, and react-aria binds its\n * Escape handling to the overlay element in its own React tree — so a\n * host-rendered dialog CANNOT see Escape once the user has clicked into a\n * component. The runtime forwards it so the host can dismiss on the user's\n * behalf. Not sent while the runtime has its own overlay open: that overlay\n * owns Escape. */\nexport interface EscapePressedMessage {\n type: 'ESCAPE_PRESSED'\n}\n\n/** Posted by the component INSIDE a host modal to close it with a value. The\n * `requestId` is the one INIT carried as `modalRequestId`. */\nexport interface ModalResultMessage {\n type: 'MODAL_RESULT'\n requestId: string\n result?: unknown\n}\n\n/** Ask the host to open its agent session window (the floating assistant).\n *\n * - `sessionId` set: the window resumes THAT session (its agent is read from\n * the session). A `prompt` is sent into it.\n * - no `sessionId`: a fresh session with `agentKey` (or the agent currently\n * selected in the window); a `prompt` is sent as its first message. With\n * neither field the window just opens as it is.\n *\n * Ignored on public pages (there is no signed-in user to run an agent as). */\nexport interface OpenAgentWindowMessage {\n type: 'OPEN_AGENT_WINDOW'\n sessionId?: string\n agentKey?: string\n prompt?: string\n /** Model-only context sent with `prompt`; never rendered. */\n context?: string\n}\n\n/** Ask the host to minimize its agent session window. The active session and\n * its stream stay alive — reopening resumes it. */\nexport interface CloseAgentWindowMessage {\n type: 'CLOSE_AGENT_WINDOW'\n}\n\n/** A record write the component made through its sdk (`data.records.*`)\n * succeeded. Posted by the runtime shell — not by component code — so the\n * host can refresh what it shows of that entity and, when the component\n * sits in a surface that reports edits (the Ava workspace), tell the agent.\n * `patch` is what was submitted, `record` what the server returned. */\nexport interface RecordWrittenMessage {\n type: 'RECORD_WRITTEN'\n entitySlug: string\n operation: 'create' | 'update' | 'delete' | 'batch_upsert'\n recordId?: string\n patch?: Record<string, unknown>\n record?: Record<string, unknown>\n /** Rows in a batch upsert. */\n count?: number\n}\n\n/** A record a page action acts on, as the component names it. */\nexport interface PageActionRecord {\n entitySlug: string\n recordId: string\n /** Shown when the person picks among several records for an intent. */\n title?: string\n /** The entity's display name, shown beside `title` in that pick. */\n entityName?: string\n}\n\n/** What the component knows that the button needs — layered over what the\n * host already knows about the page. */\nexport interface PageActionContext {\n /** Merged over the page scope (`record`, `entity`, `params`, `mode`,\n * `current_user`) the action's Liquid templates render against — `params`\n * / `inputs` prefill, `prompt`, `context`, `entity`, `record`, `url`.\n * Shallow: a key given here replaces the page's. `current_user` is always\n * the host's. */\n scope?: Record<string, unknown>\n /** The records the button acts on. Default: the page record (none on a page\n * without one).\n *\n * - `action` with entity scope — the one record it is invoked on.\n * - `action` with entity_batch scope — every record, in ONE invocation.\n * - `intent` `update_record` without a `record` — the records of the\n * intent's entity it may update: one is updated, several are offered\n * to pick from. */\n records?: PageActionRecord[]\n}\n\n/** Ask the host to run a page action — the same button a page or list toolbar\n * carries, defined inline by the component. The host dispatches it exactly\n * as a toolbar press (invoke dialog, record proposal review, agent window,\n * new tab) and answers PAGE_ACTION_SETTLED with the same `requestId` once\n * the flow is over.\n *\n * One page action at a time: while one is open (from any component) the\n * host answers further requests `unavailable: busy`. */\nexport interface RunPageActionMessage {\n type: 'RUN_PAGE_ACTION'\n /** Correlates the eventual PAGE_ACTION_SETTLED. Generated by the runtime. */\n requestId: string\n action: PageAction\n context?: PageActionContext\n}\n\nexport interface ErrorMessage {\n type: 'ERROR'\n message: string\n stack?: string\n}\n\nexport type RuntimeMessage =\n | ReadyMessage\n | ResizeMessage\n | NavigateMessage\n | OpenPeekMessage\n | OpenCallMessage\n | OverlayStateMessage\n | OpenModalMessage\n | ModalResultMessage\n | EscapePressedMessage\n | OpenAgentWindowMessage\n | CloseAgentWindowMessage\n | RecordWrittenMessage\n | RunPageActionMessage\n | ErrorMessage\n\n// Wire envelope: the message plus the source discriminator.\nexport type Envelope<T> = T & { source: typeof MESSAGE_SOURCE }\n\nexport function isHostMessage(data: unknown): data is Envelope<HostMessage> {\n return (\n typeof data === 'object' &&\n data !== null &&\n (data as { source?: unknown }).source === MESSAGE_SOURCE &&\n typeof (data as { type?: unknown }).type === 'string'\n )\n}\n\nexport function isRuntimeMessage(data: unknown): data is Envelope<RuntimeMessage> {\n return (\n typeof data === 'object' &&\n data !== null &&\n (data as { source?: unknown }).source === MESSAGE_SOURCE &&\n typeof (data as { type?: unknown }).type === 'string'\n )\n}\n"]}