@proteos/component-sdk 0.87.0 → 0.88.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/context.tsx CHANGED
@@ -16,12 +16,15 @@ import {
16
16
  type CloseAgentWindowMessage,
17
17
  type Envelope,
18
18
  isHostMessage,
19
+ type KnowledgeEditorCreateDefaults,
20
+ type KnowledgeEditorModalResult,
19
21
  MESSAGE_SOURCE,
20
22
  type ModalResultMessage,
21
23
  type ModalWidth,
22
24
  type NavigateMessage,
23
25
  type OpenAgentWindowMessage,
24
26
  type OpenCallMessage,
27
+ type OpenKnowledgeEditorMessage,
25
28
  type OpenModalMessage,
26
29
  type OpenPeekMessage,
27
30
  type OpenRecordDraftReviewMessage,
@@ -54,6 +57,21 @@ export interface OpenModalOptions {
54
57
  height?: number
55
58
  }
56
59
 
60
+ /** Options for {@link RuntimeContextValue.openKnowledgeEditor}. */
61
+ export interface OpenKnowledgeEditorOptions {
62
+ /** The node to open. Omit to create a new markdown node on the first save. */
63
+ nodeId?: string
64
+ /** Dialog heading. Defaults to the node's title (or "New note"). */
65
+ title?: string
66
+ /** Where an unsaved draft of a NEW node is kept across reloads — a key
67
+ * stable for what the node is for, e.g. `note:deal:<record id>`. */
68
+ draftKey?: string
69
+ /** Fields for the created node (no `nodeId`). */
70
+ createDefaults?: KnowledgeEditorCreateDefaults
71
+ /** Open in edit mode. Default: read for an existing node, edit for a new one. */
72
+ mode?: 'read' | 'edit'
73
+ }
74
+
57
75
  /** What {@link AgentWindowController.open} opens the host's agent window to. */
58
76
  export interface OpenAgentWindowOptions {
59
77
  /** Resume this session (its agent comes with it). */
@@ -167,6 +185,12 @@ export interface RuntimeContextValue extends RuntimeValue {
167
185
  * resolves with the draft's terminal status, or null when it closed
168
186
  * undecided or could not be opened. */
169
187
  openRecordDraftReview: (recordDraftId: string) => Promise<RecordDraftReviewOutcome | null>
188
+ /** Open the host's knowledge editor on a node, or on a new one (posts
189
+ * OPEN_KNOWLEDGE_EDITOR); resolves once it closed — with the node when it
190
+ * was saved or created, null otherwise. */
191
+ openKnowledgeEditor: (
192
+ options?: OpenKnowledgeEditorOptions,
193
+ ) => Promise<KnowledgeEditorModalResult | null>
170
194
  /** Open another component in a host-rendered modal; resolves with the value
171
195
  * that component closed with (`undefined` if dismissed). */
172
196
  openModal: (
@@ -247,6 +271,10 @@ function navigate(to: string, options?: NavigateOptions): void {
247
271
  const pendingModals = new Map<string, (result: unknown) => void>()
248
272
  const pendingPageActions = new Map<string, (outcome: PageActionOutcome) => void>()
249
273
  const pendingDraftReviews = new Map<string, (outcome: RecordDraftReviewOutcome | null) => void>()
274
+ const pendingKnowledgeEditors = new Map<
275
+ string,
276
+ (result: KnowledgeEditorModalResult | null) => void
277
+ >()
250
278
  let replyListenerAttached = false
251
279
 
252
280
  function ensureReplyListener(): void {
@@ -275,6 +303,13 @@ function ensureReplyListener(): void {
275
303
  if (!resolve) return
276
304
  pendingDraftReviews.delete(data.requestId)
277
305
  resolve(data.outcome ?? null)
306
+ return
307
+ }
308
+ if (data.type === 'KNOWLEDGE_EDITOR_CLOSED') {
309
+ const resolve = pendingKnowledgeEditors.get(data.requestId)
310
+ if (!resolve) return
311
+ pendingKnowledgeEditors.delete(data.requestId)
312
+ resolve(data.result ?? null)
278
313
  }
279
314
  })
280
315
  }
@@ -397,6 +432,33 @@ function openRecordDraftReview(recordDraftId: string): Promise<RecordDraftReview
397
432
  })
398
433
  }
399
434
 
435
+ /** Post OPEN_KNOWLEDGE_EDITOR and resolve when the host answers
436
+ * KNOWLEDGE_EDITOR_CLOSED. Focus goes back to the pressed control. */
437
+ function openKnowledgeEditor(
438
+ options: OpenKnowledgeEditorOptions = {},
439
+ ): Promise<KnowledgeEditorModalResult | null> {
440
+ ensureReplyListener()
441
+ const requestId = newRequestId()
442
+ const envelope: Envelope<OpenKnowledgeEditorMessage> = {
443
+ source: MESSAGE_SOURCE,
444
+ type: 'OPEN_KNOWLEDGE_EDITOR',
445
+ requestId,
446
+ ...(options.nodeId !== undefined ? { nodeId: options.nodeId } : {}),
447
+ ...(options.title !== undefined ? { title: options.title } : {}),
448
+ ...(options.draftKey !== undefined ? { draftKey: options.draftKey } : {}),
449
+ ...(options.createDefaults !== undefined ? { createDefaults: options.createDefaults } : {}),
450
+ ...(options.mode !== undefined ? { mode: options.mode } : {}),
451
+ }
452
+ const opener = document.activeElement instanceof HTMLElement ? document.activeElement : null
453
+ return new Promise<KnowledgeEditorModalResult | null>((resolve) => {
454
+ pendingKnowledgeEditors.set(requestId, (result) => {
455
+ restoreFocus(opener)
456
+ resolve(result)
457
+ })
458
+ window.parent?.postMessage(envelope, '*')
459
+ })
460
+ }
461
+
400
462
  /** Post MODAL_RESULT — the component inside a host modal closing with a value. */
401
463
  export function postModalResult(requestId: string, result?: unknown): void {
402
464
  const envelope: Envelope<ModalResultMessage> = {
@@ -425,6 +487,7 @@ export function RuntimeProvider({ value, children }: { value: RuntimeValue; chil
425
487
  navigate,
426
488
  openCall,
427
489
  openRecordDraftReview,
490
+ openKnowledgeEditor,
428
491
  openModal,
429
492
  agentWindow,
430
493
  runPageAction,
package/src/hooks.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  type AgentWindowController,
6
6
  type ComponentSdk,
7
7
  type NavigateOptions,
8
+ type OpenKnowledgeEditorOptions,
8
9
  type OpenModalOptions,
9
10
  type OverlayController,
10
11
  postModalResult,
@@ -12,6 +13,7 @@ import {
12
13
  type RuntimeContextValue,
13
14
  } from './context'
14
15
  import type {
16
+ KnowledgeEditorModalResult,
15
17
  PageActionContext,
16
18
  PageActionOutcome,
17
19
  PageContext,
@@ -106,6 +108,37 @@ export function useRecordDraftReview(): (
106
108
  return useRuntime().openRecordDraftReview
107
109
  }
108
110
 
111
+ /**
112
+ * Open the HOST's knowledge editor in a dialog — the platform's own
113
+ * `KnowledgeEditor` on one knowledge node, or on a new one. Any module can
114
+ * use it to let a person read and write a note: read mode with an outline,
115
+ * Edit for the slash menu and selection toolbar, drafts kept on the device,
116
+ * and a save that never overwrites a node someone changed meanwhile.
117
+ *
118
+ * ```ts
119
+ * const openKnowledgeEditor = useKnowledgeEditorModal()
120
+ * // Edit an existing node:
121
+ * await openKnowledgeEditor({ nodeId })
122
+ * // Create one; link it to your record once it exists:
123
+ * const saved = await openKnowledgeEditor({
124
+ * title: 'New note',
125
+ * draftKey: `note:deal:${recordId}`,
126
+ * createDefaults: { title: 'Call with ACME' },
127
+ * })
128
+ * if (saved?.created) await linkNote(saved.nodeId)
129
+ * ```
130
+ *
131
+ * Resolves once the dialog closed: `{ nodeId, title, created }` when the node
132
+ * was saved (or created) at least once, null otherwise — dismissed (an
133
+ * unsaved draft stays on the device), or the host could not open it (public
134
+ * pages, previews, one from this component already open).
135
+ */
136
+ export function useKnowledgeEditorModal(): (
137
+ options?: OpenKnowledgeEditorOptions,
138
+ ) => Promise<KnowledgeEditorModalResult | null> {
139
+ return useRuntime().openKnowledgeEditor
140
+ }
141
+
109
142
  /**
110
143
  * Open or minimize the HOST's agent session window (the floating assistant)
111
144
  * from a component — the iframe cannot render it itself.
package/src/index.ts CHANGED
@@ -12,6 +12,7 @@ export type {
12
12
  ComponentSdk,
13
13
  NavigateOptions,
14
14
  OpenAgentWindowOptions,
15
+ OpenKnowledgeEditorOptions,
15
16
  OpenModalOptions,
16
17
  OverlayController,
17
18
  RuntimeContextValue,
@@ -26,6 +27,7 @@ export {
26
27
  useComponentModal,
27
28
  useFillViewportHeight,
28
29
  useHostLocation,
30
+ useKnowledgeEditorModal,
29
31
  useModalHost,
30
32
  useNavigate,
31
33
  useOpenCall,
@@ -51,6 +53,9 @@ export {
51
53
  type InitMessage,
52
54
  isHostMessage,
53
55
  isRuntimeMessage,
56
+ type KnowledgeEditorClosedMessage,
57
+ type KnowledgeEditorCreateDefaults,
58
+ type KnowledgeEditorModalResult,
54
59
  MESSAGE_SOURCE,
55
60
  type ModalClosedMessage,
56
61
  type ModalResultMessage,
@@ -58,6 +63,7 @@ export {
58
63
  type NavigateMessage,
59
64
  type OpenAgentWindowMessage,
60
65
  type OpenCallMessage,
66
+ type OpenKnowledgeEditorMessage,
61
67
  type OpenModalMessage,
62
68
  type OpenPeekMessage,
63
69
  type OpenRecordDraftReviewMessage,
package/src/protocol.ts CHANGED
@@ -219,6 +219,27 @@ export interface RecordDraftReviewClosedMessage {
219
219
  outcome?: RecordDraftReviewOutcome
220
220
  }
221
221
 
222
+ /** What a host knowledge-editor modal reports once it closes, when it saved
223
+ * (or created) the node at least once. */
224
+ export interface KnowledgeEditorModalResult {
225
+ /** The node edited — or created, see `created`. */
226
+ nodeId: string
227
+ /** Its title as last saved. */
228
+ title: string
229
+ /** True when the modal created the node (no `nodeId` was passed). */
230
+ created: boolean
231
+ }
232
+
233
+ /** Resolution of an OPEN_KNOWLEDGE_EDITOR request: the modal closed. `result`
234
+ * is absent when nothing was saved — dismissed (an unsaved draft stays on
235
+ * the device), or the host could not open it (a public page, a preview, a
236
+ * modal from this frame already open). */
237
+ export interface KnowledgeEditorClosedMessage {
238
+ type: 'KNOWLEDGE_EDITOR_CLOSED'
239
+ requestId: string
240
+ result?: KnowledgeEditorModalResult
241
+ }
242
+
222
243
  export type HostMessage =
223
244
  | InitMessage
224
245
  | AgentTabsAvailabilityMessage
@@ -228,6 +249,7 @@ export type HostMessage =
228
249
  | ModalClosedMessage
229
250
  | PageActionSettledMessage
230
251
  | RecordDraftReviewClosedMessage
252
+ | KnowledgeEditorClosedMessage
231
253
 
232
254
  // ── Runtime → host ──────────────────────────────────────────────────────────
233
255
 
@@ -278,6 +300,42 @@ export interface OpenRecordDraftReviewMessage {
278
300
  recordDraftId: string
279
301
  }
280
302
 
303
+ /** Fields for a knowledge node the editor modal creates on its first save. */
304
+ export interface KnowledgeEditorCreateDefaults {
305
+ /** Prefills the title field. */
306
+ title?: string
307
+ summary?: string
308
+ /** File the node into a space. Omitted: unassigned. */
309
+ space_slug?: string
310
+ status?: 'draft' | 'published'
311
+ label_ids?: string[]
312
+ }
313
+
314
+ /** Ask the host to open its knowledge editor — the app's own `KnowledgeEditor`
315
+ * in a dialog — on one knowledge node, or on a new one. Read mode with an
316
+ * outline, Edit for the tools, local drafts, and a save that refuses to
317
+ * overwrite a node changed meanwhile. The host answers
318
+ * KNOWLEDGE_EDITOR_CLOSED with the same `requestId`.
319
+ *
320
+ * One per frame at a time; ignored (answered without a result) on public
321
+ * pages and by hosts without one. */
322
+ export interface OpenKnowledgeEditorMessage {
323
+ type: 'OPEN_KNOWLEDGE_EDITOR'
324
+ /** Correlates the eventual KNOWLEDGE_EDITOR_CLOSED. Generated by the runtime. */
325
+ requestId: string
326
+ /** The node to open. Omit to create one on the first save. */
327
+ nodeId?: string
328
+ /** Dialog heading. Defaults to the node's title (or "New note"). */
329
+ title?: string
330
+ /** Where an unsaved draft of a NEW node is kept, so it survives a reload —
331
+ * a key stable for what the node is for, e.g. `note:deal:<record id>`. */
332
+ draftKey?: string
333
+ /** Used when creating (no `nodeId`). */
334
+ createDefaults?: KnowledgeEditorCreateDefaults
335
+ /** Open straight into edit mode. Default: read for an existing node. */
336
+ mode?: 'read' | 'edit'
337
+ }
338
+
281
339
  /** The runtime has (or no longer has) an overlay open and needs the host to
282
340
  * promote (or restore) the iframe. See {@link COMPONENT_OVERLAY_Z_INDEX}.
283
341
  *
@@ -460,6 +518,7 @@ export type RuntimeMessage =
460
518
  | OpenPeekMessage
461
519
  | OpenCallMessage
462
520
  | OpenRecordDraftReviewMessage
521
+ | OpenKnowledgeEditorMessage
463
522
  | OverlayStateMessage
464
523
  | OpenModalMessage
465
524
  | ModalResultMessage
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/protocol.ts"],"names":[],"mappings":";;;AAYO,IAAM,cAAA,GAAiB;AAuBvB,IAAM,yBAAA,GAA4B;AAwblC,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-7LS4T4F2.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 /** Whether OPEN_AGENT_WINDOW with a `tab` opens it here (a host with an\n * agent and a workspace beside it). AGENT_TABS_AVAILABILITY updates it. */\n canOpenAgentTabs?: boolean\n}\n\n/** The host can now (or no longer) open OPEN_AGENT_WINDOW's `tab` — e.g. its\n * agents finished loading after INIT. */\nexport interface AgentTabsAvailabilityMessage {\n type: 'AGENT_TABS_AVAILABILITY'\n canOpenAgentTabs: boolean\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\n/** How a host record-draft review ended: the draft's terminal status. */\nexport type RecordDraftReviewOutcome = 'approved' | 'approved_with_changes' | 'rejected'\n\n/** Resolution of an OPEN_RECORD_DRAFT_REVIEW request: the review closed.\n * `outcome` is absent when it closed undecided — the draft stays proposed —\n * or when the host could not open it (a public page, a preview, a review\n * from this frame already open). */\nexport interface RecordDraftReviewClosedMessage {\n type: 'RECORD_DRAFT_REVIEW_CLOSED'\n requestId: string\n outcome?: RecordDraftReviewOutcome\n}\n\nexport type HostMessage =\n | InitMessage\n | AgentTabsAvailabilityMessage\n | AuthRefreshMessage\n | DataInvalidateMessage\n | OverlayRectMessage\n | ModalClosedMessage\n | PageActionSettledMessage\n | RecordDraftReviewClosedMessage\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/** Ask the host to open its review of a record draft (a proposed record\n * write): the current values next to the proposed ones, editable for one\n * record, a table for several. The host answers RECORD_DRAFT_REVIEW_CLOSED\n * with the same `requestId` once the review closes. Approving writes the\n * records server-side as the viewer; the host then sends DATA_INVALIDATE.\n *\n * One review per frame at a time; ignored (answered without an outcome) on\n * public pages and by hosts without one. */\nexport interface OpenRecordDraftReviewMessage {\n type: 'OPEN_RECORD_DRAFT_REVIEW'\n /** Correlates the eventual RECORD_DRAFT_REVIEW_CLOSED. Generated by the runtime. */\n requestId: string\n /** The record draft to review. */\n recordDraftId: 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/** A stored draft the host opens as a workspace tab beside the assistant. */\nexport type AgentWindowTab =\n | { kind: 'message-draft'; messageId: string }\n | { kind: 'record-draft'; recordDraftId: string }\n\n/** Ask the host to open its agent session window (the floating assistant).\n *\n * - `tab` set (\"Edit with Ava\"): the host opens that draft as a workspace\n * tab, full-screen, beside a fresh session with the org's primary agent,\n * and closes the component modal this frame sits in so the window is not\n * hidden behind it. The other fields are ignored then; a host that cannot\n * show the workspace (a phone) does nothing.\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 tab?: AgentWindowTab\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 | OpenRecordDraftReviewMessage\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;AAwblC,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-UEPSZRI7.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 /** Whether OPEN_AGENT_WINDOW with a `tab` opens it here (a host with an\n * agent and a workspace beside it). AGENT_TABS_AVAILABILITY updates it. */\n canOpenAgentTabs?: boolean\n}\n\n/** The host can now (or no longer) open OPEN_AGENT_WINDOW's `tab` — e.g. its\n * agents finished loading after INIT. */\nexport interface AgentTabsAvailabilityMessage {\n type: 'AGENT_TABS_AVAILABILITY'\n canOpenAgentTabs: boolean\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\n/** How a host record-draft review ended: the draft's terminal status. */\nexport type RecordDraftReviewOutcome = 'approved' | 'approved_with_changes' | 'rejected'\n\n/** Resolution of an OPEN_RECORD_DRAFT_REVIEW request: the review closed.\n * `outcome` is absent when it closed undecided — the draft stays proposed —\n * or when the host could not open it (a public page, a preview, a review\n * from this frame already open). */\nexport interface RecordDraftReviewClosedMessage {\n type: 'RECORD_DRAFT_REVIEW_CLOSED'\n requestId: string\n outcome?: RecordDraftReviewOutcome\n}\n\nexport type HostMessage =\n | InitMessage\n | AgentTabsAvailabilityMessage\n | AuthRefreshMessage\n | DataInvalidateMessage\n | OverlayRectMessage\n | ModalClosedMessage\n | PageActionSettledMessage\n | RecordDraftReviewClosedMessage\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/** Ask the host to open its review of a record draft (a proposed record\n * write): the current values next to the proposed ones, editable for one\n * record, a table for several. The host answers RECORD_DRAFT_REVIEW_CLOSED\n * with the same `requestId` once the review closes. Approving writes the\n * records server-side as the viewer; the host then sends DATA_INVALIDATE.\n *\n * One review per frame at a time; ignored (answered without an outcome) on\n * public pages and by hosts without one. */\nexport interface OpenRecordDraftReviewMessage {\n type: 'OPEN_RECORD_DRAFT_REVIEW'\n /** Correlates the eventual RECORD_DRAFT_REVIEW_CLOSED. Generated by the runtime. */\n requestId: string\n /** The record draft to review. */\n recordDraftId: 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/** A stored draft the host opens as a workspace tab beside the assistant. */\nexport type AgentWindowTab =\n | { kind: 'message-draft'; messageId: string }\n | { kind: 'record-draft'; recordDraftId: string }\n\n/** Ask the host to open its agent session window (the floating assistant).\n *\n * - `tab` set (\"Edit with Ava\"): the host opens that draft as a workspace\n * tab, full-screen, beside a fresh session with the org's primary agent,\n * and closes the component modal this frame sits in so the window is not\n * hidden behind it. The other fields are ignored then; a host that cannot\n * show the workspace (a phone) does nothing.\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 tab?: AgentWindowTab\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 | OpenRecordDraftReviewMessage\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"]}