@proteos/component-sdk 0.86.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.
@@ -118,6 +118,15 @@ interface InitMessage {
118
118
  * `useModalHost()` and closes with a result by posting MODAL_RESULT with
119
119
  * this id. Absent on ordinary page-hosted frames. */
120
120
  modalRequestId?: string;
121
+ /** Whether OPEN_AGENT_WINDOW with a `tab` opens it here (a host with an
122
+ * agent and a workspace beside it). AGENT_TABS_AVAILABILITY updates it. */
123
+ canOpenAgentTabs?: boolean;
124
+ }
125
+ /** The host can now (or no longer) open OPEN_AGENT_WINDOW's `tab` — e.g. its
126
+ * agents finished loading after INIT. */
127
+ interface AgentTabsAvailabilityMessage {
128
+ type: 'AGENT_TABS_AVAILABILITY';
129
+ canOpenAgentTabs: boolean;
121
130
  }
122
131
  interface AuthRefreshMessage {
123
132
  type: 'AUTH_REFRESH';
@@ -205,7 +214,26 @@ interface RecordDraftReviewClosedMessage {
205
214
  requestId: string;
206
215
  outcome?: RecordDraftReviewOutcome;
207
216
  }
208
- type HostMessage = InitMessage | AuthRefreshMessage | DataInvalidateMessage | OverlayRectMessage | ModalClosedMessage | PageActionSettledMessage | RecordDraftReviewClosedMessage;
217
+ /** What a host knowledge-editor modal reports once it closes, when it saved
218
+ * (or created) the node at least once. */
219
+ interface KnowledgeEditorModalResult {
220
+ /** The node edited — or created, see `created`. */
221
+ nodeId: string;
222
+ /** Its title as last saved. */
223
+ title: string;
224
+ /** True when the modal created the node (no `nodeId` was passed). */
225
+ created: boolean;
226
+ }
227
+ /** Resolution of an OPEN_KNOWLEDGE_EDITOR request: the modal closed. `result`
228
+ * is absent when nothing was saved — dismissed (an unsaved draft stays on
229
+ * the device), or the host could not open it (a public page, a preview, a
230
+ * modal from this frame already open). */
231
+ interface KnowledgeEditorClosedMessage {
232
+ type: 'KNOWLEDGE_EDITOR_CLOSED';
233
+ requestId: string;
234
+ result?: KnowledgeEditorModalResult;
235
+ }
236
+ type HostMessage = InitMessage | AgentTabsAvailabilityMessage | AuthRefreshMessage | DataInvalidateMessage | OverlayRectMessage | ModalClosedMessage | PageActionSettledMessage | RecordDraftReviewClosedMessage | KnowledgeEditorClosedMessage;
209
237
  interface ReadyMessage {
210
238
  type: 'READY';
211
239
  }
@@ -247,6 +275,40 @@ interface OpenRecordDraftReviewMessage {
247
275
  /** The record draft to review. */
248
276
  recordDraftId: string;
249
277
  }
278
+ /** Fields for a knowledge node the editor modal creates on its first save. */
279
+ interface KnowledgeEditorCreateDefaults {
280
+ /** Prefills the title field. */
281
+ title?: string;
282
+ summary?: string;
283
+ /** File the node into a space. Omitted: unassigned. */
284
+ space_slug?: string;
285
+ status?: 'draft' | 'published';
286
+ label_ids?: string[];
287
+ }
288
+ /** Ask the host to open its knowledge editor — the app's own `KnowledgeEditor`
289
+ * in a dialog — on one knowledge node, or on a new one. Read mode with an
290
+ * outline, Edit for the tools, local drafts, and a save that refuses to
291
+ * overwrite a node changed meanwhile. The host answers
292
+ * KNOWLEDGE_EDITOR_CLOSED with the same `requestId`.
293
+ *
294
+ * One per frame at a time; ignored (answered without a result) on public
295
+ * pages and by hosts without one. */
296
+ interface OpenKnowledgeEditorMessage {
297
+ type: 'OPEN_KNOWLEDGE_EDITOR';
298
+ /** Correlates the eventual KNOWLEDGE_EDITOR_CLOSED. Generated by the runtime. */
299
+ requestId: string;
300
+ /** The node to open. Omit to create one on the first save. */
301
+ nodeId?: string;
302
+ /** Dialog heading. Defaults to the node's title (or "New note"). */
303
+ title?: string;
304
+ /** Where an unsaved draft of a NEW node is kept, so it survives a reload —
305
+ * a key stable for what the node is for, e.g. `note:deal:<record id>`. */
306
+ draftKey?: string;
307
+ /** Used when creating (no `nodeId`). */
308
+ createDefaults?: KnowledgeEditorCreateDefaults;
309
+ /** Open straight into edit mode. Default: read for an existing node. */
310
+ mode?: 'read' | 'edit';
311
+ }
250
312
  /** The runtime has (or no longer has) an overlay open and needs the host to
251
313
  * promote (or restore) the iframe. See {@link COMPONENT_OVERLAY_Z_INDEX}.
252
314
  *
@@ -314,8 +376,21 @@ interface ModalResultMessage {
314
376
  requestId: string;
315
377
  result?: unknown;
316
378
  }
379
+ /** A stored draft the host opens as a workspace tab beside the assistant. */
380
+ type AgentWindowTab = {
381
+ kind: 'message-draft';
382
+ messageId: string;
383
+ } | {
384
+ kind: 'record-draft';
385
+ recordDraftId: string;
386
+ };
317
387
  /** Ask the host to open its agent session window (the floating assistant).
318
388
  *
389
+ * - `tab` set ("Edit with Ava"): the host opens that draft as a workspace
390
+ * tab, full-screen, beside a fresh session with the org's primary agent,
391
+ * and closes the component modal this frame sits in so the window is not
392
+ * hidden behind it. The other fields are ignored then; a host that cannot
393
+ * show the workspace (a phone) does nothing.
319
394
  * - `sessionId` set: the window resumes THAT session (its agent is read from
320
395
  * the session). A `prompt` is sent into it.
321
396
  * - no `sessionId`: a fresh session with `agentKey` (or the agent currently
@@ -330,6 +405,7 @@ interface OpenAgentWindowMessage {
330
405
  prompt?: string;
331
406
  /** Model-only context sent with `prompt`; never rendered. */
332
407
  context?: string;
408
+ tab?: AgentWindowTab;
333
409
  }
334
410
  /** Ask the host to minimize its agent session window. The active session and
335
411
  * its stream stay alive — reopening resumes it. */
@@ -399,11 +475,11 @@ interface ErrorMessage {
399
475
  message: string;
400
476
  stack?: string;
401
477
  }
402
- type RuntimeMessage = ReadyMessage | ResizeMessage | NavigateMessage | OpenPeekMessage | OpenCallMessage | OpenRecordDraftReviewMessage | OverlayStateMessage | OpenModalMessage | ModalResultMessage | EscapePressedMessage | OpenAgentWindowMessage | CloseAgentWindowMessage | RecordWrittenMessage | RunPageActionMessage | ErrorMessage;
478
+ type RuntimeMessage = ReadyMessage | ResizeMessage | NavigateMessage | OpenPeekMessage | OpenCallMessage | OpenRecordDraftReviewMessage | OpenKnowledgeEditorMessage | OverlayStateMessage | OpenModalMessage | ModalResultMessage | EscapePressedMessage | OpenAgentWindowMessage | CloseAgentWindowMessage | RecordWrittenMessage | RunPageActionMessage | ErrorMessage;
403
479
  type Envelope<T> = T & {
404
480
  source: typeof MESSAGE_SOURCE;
405
481
  };
406
482
  declare function isHostMessage(data: unknown): data is Envelope<HostMessage>;
407
483
  declare function isRuntimeMessage(data: unknown): data is Envelope<RuntimeMessage>;
408
484
 
409
- export { type AuthRefreshMessage, COMPONENT_OVERLAY_Z_INDEX, type CloseAgentWindowMessage, type DataInvalidateMessage, type Envelope, type ErrorMessage, type EscapePressedMessage, type HostMessage, type InitMessage, MESSAGE_SOURCE, type ModalClosedMessage, type ModalResultMessage, type ModalWidth, type NavigateMessage, type OpenAgentWindowMessage, type OpenCallMessage, type OpenModalMessage, type OpenPeekMessage, type OpenRecordDraftReviewMessage, type OverlayRect, type OverlayRectMessage, type OverlayStateMessage, type PageActionContext, type PageActionOutcome, type PageActionRecord, type PageActionSettledMessage, type PageContext, type PageMode, type ReadyMessage, type RecordDraftReviewClosedMessage, type RecordDraftReviewOutcome, type RecordWrittenMessage, type ResizeMessage, type RunPageActionMessage, type RuntimeMessage, type TriggerPhase, isHostMessage, isRuntimeMessage };
485
+ export { type AgentTabsAvailabilityMessage, type AgentWindowTab, type AuthRefreshMessage, COMPONENT_OVERLAY_Z_INDEX, type CloseAgentWindowMessage, type DataInvalidateMessage, type Envelope, type ErrorMessage, type EscapePressedMessage, type HostMessage, type InitMessage, type KnowledgeEditorClosedMessage, type KnowledgeEditorCreateDefaults, type KnowledgeEditorModalResult, MESSAGE_SOURCE, type ModalClosedMessage, type ModalResultMessage, type ModalWidth, type NavigateMessage, type OpenAgentWindowMessage, type OpenCallMessage, type OpenKnowledgeEditorMessage, type OpenModalMessage, type OpenPeekMessage, type OpenRecordDraftReviewMessage, type OverlayRect, type OverlayRectMessage, type OverlayStateMessage, type PageActionContext, type PageActionOutcome, type PageActionRecord, type PageActionSettledMessage, type PageContext, type PageMode, type ReadyMessage, type RecordDraftReviewClosedMessage, type RecordDraftReviewOutcome, type RecordWrittenMessage, type ResizeMessage, type RunPageActionMessage, type RuntimeMessage, type TriggerPhase, isHostMessage, isRuntimeMessage };
@@ -118,6 +118,15 @@ interface InitMessage {
118
118
  * `useModalHost()` and closes with a result by posting MODAL_RESULT with
119
119
  * this id. Absent on ordinary page-hosted frames. */
120
120
  modalRequestId?: string;
121
+ /** Whether OPEN_AGENT_WINDOW with a `tab` opens it here (a host with an
122
+ * agent and a workspace beside it). AGENT_TABS_AVAILABILITY updates it. */
123
+ canOpenAgentTabs?: boolean;
124
+ }
125
+ /** The host can now (or no longer) open OPEN_AGENT_WINDOW's `tab` — e.g. its
126
+ * agents finished loading after INIT. */
127
+ interface AgentTabsAvailabilityMessage {
128
+ type: 'AGENT_TABS_AVAILABILITY';
129
+ canOpenAgentTabs: boolean;
121
130
  }
122
131
  interface AuthRefreshMessage {
123
132
  type: 'AUTH_REFRESH';
@@ -205,7 +214,26 @@ interface RecordDraftReviewClosedMessage {
205
214
  requestId: string;
206
215
  outcome?: RecordDraftReviewOutcome;
207
216
  }
208
- type HostMessage = InitMessage | AuthRefreshMessage | DataInvalidateMessage | OverlayRectMessage | ModalClosedMessage | PageActionSettledMessage | RecordDraftReviewClosedMessage;
217
+ /** What a host knowledge-editor modal reports once it closes, when it saved
218
+ * (or created) the node at least once. */
219
+ interface KnowledgeEditorModalResult {
220
+ /** The node edited — or created, see `created`. */
221
+ nodeId: string;
222
+ /** Its title as last saved. */
223
+ title: string;
224
+ /** True when the modal created the node (no `nodeId` was passed). */
225
+ created: boolean;
226
+ }
227
+ /** Resolution of an OPEN_KNOWLEDGE_EDITOR request: the modal closed. `result`
228
+ * is absent when nothing was saved — dismissed (an unsaved draft stays on
229
+ * the device), or the host could not open it (a public page, a preview, a
230
+ * modal from this frame already open). */
231
+ interface KnowledgeEditorClosedMessage {
232
+ type: 'KNOWLEDGE_EDITOR_CLOSED';
233
+ requestId: string;
234
+ result?: KnowledgeEditorModalResult;
235
+ }
236
+ type HostMessage = InitMessage | AgentTabsAvailabilityMessage | AuthRefreshMessage | DataInvalidateMessage | OverlayRectMessage | ModalClosedMessage | PageActionSettledMessage | RecordDraftReviewClosedMessage | KnowledgeEditorClosedMessage;
209
237
  interface ReadyMessage {
210
238
  type: 'READY';
211
239
  }
@@ -247,6 +275,40 @@ interface OpenRecordDraftReviewMessage {
247
275
  /** The record draft to review. */
248
276
  recordDraftId: string;
249
277
  }
278
+ /** Fields for a knowledge node the editor modal creates on its first save. */
279
+ interface KnowledgeEditorCreateDefaults {
280
+ /** Prefills the title field. */
281
+ title?: string;
282
+ summary?: string;
283
+ /** File the node into a space. Omitted: unassigned. */
284
+ space_slug?: string;
285
+ status?: 'draft' | 'published';
286
+ label_ids?: string[];
287
+ }
288
+ /** Ask the host to open its knowledge editor — the app's own `KnowledgeEditor`
289
+ * in a dialog — on one knowledge node, or on a new one. Read mode with an
290
+ * outline, Edit for the tools, local drafts, and a save that refuses to
291
+ * overwrite a node changed meanwhile. The host answers
292
+ * KNOWLEDGE_EDITOR_CLOSED with the same `requestId`.
293
+ *
294
+ * One per frame at a time; ignored (answered without a result) on public
295
+ * pages and by hosts without one. */
296
+ interface OpenKnowledgeEditorMessage {
297
+ type: 'OPEN_KNOWLEDGE_EDITOR';
298
+ /** Correlates the eventual KNOWLEDGE_EDITOR_CLOSED. Generated by the runtime. */
299
+ requestId: string;
300
+ /** The node to open. Omit to create one on the first save. */
301
+ nodeId?: string;
302
+ /** Dialog heading. Defaults to the node's title (or "New note"). */
303
+ title?: string;
304
+ /** Where an unsaved draft of a NEW node is kept, so it survives a reload —
305
+ * a key stable for what the node is for, e.g. `note:deal:<record id>`. */
306
+ draftKey?: string;
307
+ /** Used when creating (no `nodeId`). */
308
+ createDefaults?: KnowledgeEditorCreateDefaults;
309
+ /** Open straight into edit mode. Default: read for an existing node. */
310
+ mode?: 'read' | 'edit';
311
+ }
250
312
  /** The runtime has (or no longer has) an overlay open and needs the host to
251
313
  * promote (or restore) the iframe. See {@link COMPONENT_OVERLAY_Z_INDEX}.
252
314
  *
@@ -314,8 +376,21 @@ interface ModalResultMessage {
314
376
  requestId: string;
315
377
  result?: unknown;
316
378
  }
379
+ /** A stored draft the host opens as a workspace tab beside the assistant. */
380
+ type AgentWindowTab = {
381
+ kind: 'message-draft';
382
+ messageId: string;
383
+ } | {
384
+ kind: 'record-draft';
385
+ recordDraftId: string;
386
+ };
317
387
  /** Ask the host to open its agent session window (the floating assistant).
318
388
  *
389
+ * - `tab` set ("Edit with Ava"): the host opens that draft as a workspace
390
+ * tab, full-screen, beside a fresh session with the org's primary agent,
391
+ * and closes the component modal this frame sits in so the window is not
392
+ * hidden behind it. The other fields are ignored then; a host that cannot
393
+ * show the workspace (a phone) does nothing.
319
394
  * - `sessionId` set: the window resumes THAT session (its agent is read from
320
395
  * the session). A `prompt` is sent into it.
321
396
  * - no `sessionId`: a fresh session with `agentKey` (or the agent currently
@@ -330,6 +405,7 @@ interface OpenAgentWindowMessage {
330
405
  prompt?: string;
331
406
  /** Model-only context sent with `prompt`; never rendered. */
332
407
  context?: string;
408
+ tab?: AgentWindowTab;
333
409
  }
334
410
  /** Ask the host to minimize its agent session window. The active session and
335
411
  * its stream stay alive — reopening resumes it. */
@@ -399,11 +475,11 @@ interface ErrorMessage {
399
475
  message: string;
400
476
  stack?: string;
401
477
  }
402
- type RuntimeMessage = ReadyMessage | ResizeMessage | NavigateMessage | OpenPeekMessage | OpenCallMessage | OpenRecordDraftReviewMessage | OverlayStateMessage | OpenModalMessage | ModalResultMessage | EscapePressedMessage | OpenAgentWindowMessage | CloseAgentWindowMessage | RecordWrittenMessage | RunPageActionMessage | ErrorMessage;
478
+ type RuntimeMessage = ReadyMessage | ResizeMessage | NavigateMessage | OpenPeekMessage | OpenCallMessage | OpenRecordDraftReviewMessage | OpenKnowledgeEditorMessage | OverlayStateMessage | OpenModalMessage | ModalResultMessage | EscapePressedMessage | OpenAgentWindowMessage | CloseAgentWindowMessage | RecordWrittenMessage | RunPageActionMessage | ErrorMessage;
403
479
  type Envelope<T> = T & {
404
480
  source: typeof MESSAGE_SOURCE;
405
481
  };
406
482
  declare function isHostMessage(data: unknown): data is Envelope<HostMessage>;
407
483
  declare function isRuntimeMessage(data: unknown): data is Envelope<RuntimeMessage>;
408
484
 
409
- export { type AuthRefreshMessage, COMPONENT_OVERLAY_Z_INDEX, type CloseAgentWindowMessage, type DataInvalidateMessage, type Envelope, type ErrorMessage, type EscapePressedMessage, type HostMessage, type InitMessage, MESSAGE_SOURCE, type ModalClosedMessage, type ModalResultMessage, type ModalWidth, type NavigateMessage, type OpenAgentWindowMessage, type OpenCallMessage, type OpenModalMessage, type OpenPeekMessage, type OpenRecordDraftReviewMessage, type OverlayRect, type OverlayRectMessage, type OverlayStateMessage, type PageActionContext, type PageActionOutcome, type PageActionRecord, type PageActionSettledMessage, type PageContext, type PageMode, type ReadyMessage, type RecordDraftReviewClosedMessage, type RecordDraftReviewOutcome, type RecordWrittenMessage, type ResizeMessage, type RunPageActionMessage, type RuntimeMessage, type TriggerPhase, isHostMessage, isRuntimeMessage };
485
+ export { type AgentTabsAvailabilityMessage, type AgentWindowTab, type AuthRefreshMessage, COMPONENT_OVERLAY_Z_INDEX, type CloseAgentWindowMessage, type DataInvalidateMessage, type Envelope, type ErrorMessage, type EscapePressedMessage, type HostMessage, type InitMessage, type KnowledgeEditorClosedMessage, type KnowledgeEditorCreateDefaults, type KnowledgeEditorModalResult, MESSAGE_SOURCE, type ModalClosedMessage, type ModalResultMessage, type ModalWidth, type NavigateMessage, type OpenAgentWindowMessage, type OpenCallMessage, type OpenKnowledgeEditorMessage, type OpenModalMessage, type OpenPeekMessage, type OpenRecordDraftReviewMessage, type OverlayRect, type OverlayRectMessage, type OverlayStateMessage, type PageActionContext, type PageActionOutcome, type PageActionRecord, type PageActionSettledMessage, type PageContext, type PageMode, type ReadyMessage, type RecordDraftReviewClosedMessage, type RecordDraftReviewOutcome, type RecordWrittenMessage, type ResizeMessage, type RunPageActionMessage, type RuntimeMessage, type TriggerPhase, isHostMessage, isRuntimeMessage };
package/dist/protocol.js CHANGED
@@ -1,3 +1,3 @@
1
- export { COMPONENT_OVERLAY_Z_INDEX, MESSAGE_SOURCE, isHostMessage, isRuntimeMessage } from './chunk-YK7MGFPR.js';
1
+ export { COMPONENT_OVERLAY_Z_INDEX, MESSAGE_SOURCE, isHostMessage, isRuntimeMessage } from './chunk-A4D64VS2.js';
2
2
  //# sourceMappingURL=protocol.js.map
3
3
  //# sourceMappingURL=protocol.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteos/component-sdk",
3
- "version": "0.86.0",
3
+ "version": "0.88.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Typed runtime hooks for authoring Proteos custom components — the SDK you import inside a component bundle.",
6
6
  "repository": {
@@ -42,7 +42,7 @@
42
42
  "src"
43
43
  ],
44
44
  "dependencies": {
45
- "@proteos/sdk": "^0.86.0"
45
+ "@proteos/sdk": "^0.88.0"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@tanstack/react-query": ">=5.0.0",
package/src/context.tsx CHANGED
@@ -12,15 +12,19 @@ import type {
12
12
  import { createContext, type ReactNode, useMemo } from 'react'
13
13
 
14
14
  import {
15
+ type AgentWindowTab,
15
16
  type CloseAgentWindowMessage,
16
17
  type Envelope,
17
18
  isHostMessage,
19
+ type KnowledgeEditorCreateDefaults,
20
+ type KnowledgeEditorModalResult,
18
21
  MESSAGE_SOURCE,
19
22
  type ModalResultMessage,
20
23
  type ModalWidth,
21
24
  type NavigateMessage,
22
25
  type OpenAgentWindowMessage,
23
26
  type OpenCallMessage,
27
+ type OpenKnowledgeEditorMessage,
24
28
  type OpenModalMessage,
25
29
  type OpenPeekMessage,
26
30
  type OpenRecordDraftReviewMessage,
@@ -53,6 +57,21 @@ export interface OpenModalOptions {
53
57
  height?: number
54
58
  }
55
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
+
56
75
  /** What {@link AgentWindowController.open} opens the host's agent window to. */
57
76
  export interface OpenAgentWindowOptions {
58
77
  /** Resume this session (its agent comes with it). */
@@ -68,6 +87,10 @@ export interface OpenAgentWindowOptions {
68
87
  * the record on screen, a selection …). Read by the model, never shown in
69
88
  * the chat; sent only together with a `prompt`. Not for secrets. */
70
89
  context?: string
90
+ /** Open this stored draft as a workspace tab beside a fresh session with
91
+ * the org's primary agent ("Edit with Ava"). The other options are
92
+ * ignored then. `@proteos/ui`'s draft reviews do this on their own. */
93
+ tab?: AgentWindowTab
71
94
  }
72
95
 
73
96
  /**
@@ -162,6 +185,12 @@ export interface RuntimeContextValue extends RuntimeValue {
162
185
  * resolves with the draft's terminal status, or null when it closed
163
186
  * undecided or could not be opened. */
164
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>
165
194
  /** Open another component in a host-rendered modal; resolves with the value
166
195
  * that component closed with (`undefined` if dismissed). */
167
196
  openModal: (
@@ -212,6 +241,7 @@ function openAgentWindow(options?: OpenAgentWindowOptions): void {
212
241
  ...(options?.agentKey !== undefined ? { agentKey: options.agentKey } : {}),
213
242
  ...(options?.prompt !== undefined ? { prompt: options.prompt } : {}),
214
243
  ...(options?.context !== undefined ? { context: options.context } : {}),
244
+ ...(options?.tab !== undefined ? { tab: options.tab } : {}),
215
245
  }
216
246
  window.parent?.postMessage(envelope, '*')
217
247
  }
@@ -241,6 +271,10 @@ function navigate(to: string, options?: NavigateOptions): void {
241
271
  const pendingModals = new Map<string, (result: unknown) => void>()
242
272
  const pendingPageActions = new Map<string, (outcome: PageActionOutcome) => void>()
243
273
  const pendingDraftReviews = new Map<string, (outcome: RecordDraftReviewOutcome | null) => void>()
274
+ const pendingKnowledgeEditors = new Map<
275
+ string,
276
+ (result: KnowledgeEditorModalResult | null) => void
277
+ >()
244
278
  let replyListenerAttached = false
245
279
 
246
280
  function ensureReplyListener(): void {
@@ -269,6 +303,13 @@ function ensureReplyListener(): void {
269
303
  if (!resolve) return
270
304
  pendingDraftReviews.delete(data.requestId)
271
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)
272
313
  }
273
314
  })
274
315
  }
@@ -391,6 +432,33 @@ function openRecordDraftReview(recordDraftId: string): Promise<RecordDraftReview
391
432
  })
392
433
  }
393
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
+
394
462
  /** Post MODAL_RESULT — the component inside a host modal closing with a value. */
395
463
  export function postModalResult(requestId: string, result?: unknown): void {
396
464
  const envelope: Envelope<ModalResultMessage> = {
@@ -419,6 +487,7 @@ export function RuntimeProvider({ value, children }: { value: RuntimeValue; chil
419
487
  navigate,
420
488
  openCall,
421
489
  openRecordDraftReview,
490
+ openKnowledgeEditor,
422
491
  openModal,
423
492
  agentWindow,
424
493
  runPageAction,
@@ -124,6 +124,16 @@ describe('runtime hooks', () => {
124
124
  '*',
125
125
  )
126
126
 
127
+ result.current.open({ tab: { kind: 'message-draft', messageId: 'msg_1' } })
128
+ expect(post).toHaveBeenLastCalledWith(
129
+ {
130
+ source: MESSAGE_SOURCE,
131
+ type: 'OPEN_AGENT_WINDOW',
132
+ tab: { kind: 'message-draft', messageId: 'msg_1' },
133
+ },
134
+ '*',
135
+ )
136
+
127
137
  result.current.close()
128
138
  expect(post).toHaveBeenLastCalledWith(
129
139
  { source: MESSAGE_SOURCE, type: 'CLOSE_AGENT_WINDOW' },
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,
@@ -38,6 +40,8 @@ export {
38
40
  useSdk,
39
41
  } from './hooks'
40
42
  export {
43
+ type AgentTabsAvailabilityMessage,
44
+ type AgentWindowTab,
41
45
  type AuthRefreshMessage,
42
46
  type CloseAgentWindowMessage,
43
47
  COMPONENT_OVERLAY_Z_INDEX,
@@ -49,6 +53,9 @@ export {
49
53
  type InitMessage,
50
54
  isHostMessage,
51
55
  isRuntimeMessage,
56
+ type KnowledgeEditorClosedMessage,
57
+ type KnowledgeEditorCreateDefaults,
58
+ type KnowledgeEditorModalResult,
52
59
  MESSAGE_SOURCE,
53
60
  type ModalClosedMessage,
54
61
  type ModalResultMessage,
@@ -56,6 +63,7 @@ export {
56
63
  type NavigateMessage,
57
64
  type OpenAgentWindowMessage,
58
65
  type OpenCallMessage,
66
+ type OpenKnowledgeEditorMessage,
59
67
  type OpenModalMessage,
60
68
  type OpenPeekMessage,
61
69
  type OpenRecordDraftReviewMessage,
package/src/protocol.ts CHANGED
@@ -128,6 +128,16 @@ export interface InitMessage {
128
128
  * `useModalHost()` and closes with a result by posting MODAL_RESULT with
129
129
  * this id. Absent on ordinary page-hosted frames. */
130
130
  modalRequestId?: string
131
+ /** Whether OPEN_AGENT_WINDOW with a `tab` opens it here (a host with an
132
+ * agent and a workspace beside it). AGENT_TABS_AVAILABILITY updates it. */
133
+ canOpenAgentTabs?: boolean
134
+ }
135
+
136
+ /** The host can now (or no longer) open OPEN_AGENT_WINDOW's `tab` — e.g. its
137
+ * agents finished loading after INIT. */
138
+ export interface AgentTabsAvailabilityMessage {
139
+ type: 'AGENT_TABS_AVAILABILITY'
140
+ canOpenAgentTabs: boolean
131
141
  }
132
142
 
133
143
  export interface AuthRefreshMessage {
@@ -209,14 +219,37 @@ export interface RecordDraftReviewClosedMessage {
209
219
  outcome?: RecordDraftReviewOutcome
210
220
  }
211
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
+
212
243
  export type HostMessage =
213
244
  | InitMessage
245
+ | AgentTabsAvailabilityMessage
214
246
  | AuthRefreshMessage
215
247
  | DataInvalidateMessage
216
248
  | OverlayRectMessage
217
249
  | ModalClosedMessage
218
250
  | PageActionSettledMessage
219
251
  | RecordDraftReviewClosedMessage
252
+ | KnowledgeEditorClosedMessage
220
253
 
221
254
  // ── Runtime → host ──────────────────────────────────────────────────────────
222
255
 
@@ -267,6 +300,42 @@ export interface OpenRecordDraftReviewMessage {
267
300
  recordDraftId: string
268
301
  }
269
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
+
270
339
  /** The runtime has (or no longer has) an overlay open and needs the host to
271
340
  * promote (or restore) the iframe. See {@link COMPONENT_OVERLAY_Z_INDEX}.
272
341
  *
@@ -339,8 +408,18 @@ export interface ModalResultMessage {
339
408
  result?: unknown
340
409
  }
341
410
 
411
+ /** A stored draft the host opens as a workspace tab beside the assistant. */
412
+ export type AgentWindowTab =
413
+ | { kind: 'message-draft'; messageId: string }
414
+ | { kind: 'record-draft'; recordDraftId: string }
415
+
342
416
  /** Ask the host to open its agent session window (the floating assistant).
343
417
  *
418
+ * - `tab` set ("Edit with Ava"): the host opens that draft as a workspace
419
+ * tab, full-screen, beside a fresh session with the org's primary agent,
420
+ * and closes the component modal this frame sits in so the window is not
421
+ * hidden behind it. The other fields are ignored then; a host that cannot
422
+ * show the workspace (a phone) does nothing.
344
423
  * - `sessionId` set: the window resumes THAT session (its agent is read from
345
424
  * the session). A `prompt` is sent into it.
346
425
  * - no `sessionId`: a fresh session with `agentKey` (or the agent currently
@@ -355,6 +434,7 @@ export interface OpenAgentWindowMessage {
355
434
  prompt?: string
356
435
  /** Model-only context sent with `prompt`; never rendered. */
357
436
  context?: string
437
+ tab?: AgentWindowTab
358
438
  }
359
439
 
360
440
  /** Ask the host to minimize its agent session window. The active session and
@@ -438,6 +518,7 @@ export type RuntimeMessage =
438
518
  | OpenPeekMessage
439
519
  | OpenCallMessage
440
520
  | OpenRecordDraftReviewMessage
521
+ | OpenKnowledgeEditorMessage
441
522
  | OverlayStateMessage
442
523
  | OpenModalMessage
443
524
  | ModalResultMessage