@jini-ai/chat 0.7.3-next.2 → 0.7.3-next.4
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/README.md +49 -0
- package/dist/core/accepted-input.d.ts +1 -1
- package/dist/core/ag-ui/event-projection.d.ts +14 -69
- package/dist/core/ag-ui/event-projection.js +58 -133
- package/dist/core/ag-ui/event-reduction.d.ts +12 -2
- package/dist/core/ag-ui/event-reduction.js +35 -10
- package/dist/core/ag-ui/resume.d.ts +110 -0
- package/dist/core/ag-ui/resume.js +200 -0
- package/dist/core/ag-ui/run-input.d.ts +23 -0
- package/dist/core/ag-ui/run-input.js +45 -0
- package/dist/core/ag-ui/server.d.ts +69 -0
- package/dist/core/ag-ui/server.js +71 -0
- package/dist/core/agent-plugin-chat-state.js +13 -11
- package/dist/core/assistant-client/ag-ui-approval-relay.d.ts +113 -0
- package/dist/core/assistant-client/ag-ui-approval-relay.js +287 -0
- package/dist/core/assistant-client/ag-ui-fetch-agent.d.ts +25 -10
- package/dist/core/assistant-client/ag-ui-fetch-agent.js +25 -6
- package/dist/core/assistant-client/ag-ui-transport.d.ts +86 -3
- package/dist/core/assistant-client/ag-ui-transport.js +310 -80
- package/dist/core/assistant-client/browser-durable-subscription.d.ts +25 -0
- package/dist/core/assistant-client/browser-durable-subscription.js +78 -0
- package/dist/core/assistant-client/durable-run-subscription.js +141 -130
- package/dist/core/assistant-client/entry.d.ts +2 -1
- package/dist/core/assistant-client/entry.js +1 -0
- package/dist/core/assistant-client/transport-prompt.d.ts +94 -0
- package/dist/core/assistant-client/transport-prompt.js +180 -0
- package/dist/core/assistant-client/transport-run.d.ts +49 -0
- package/dist/core/assistant-client/transport-run.js +432 -0
- package/dist/core/assistant-client/transport-stream.d.ts +73 -0
- package/dist/core/assistant-client/transport-stream.js +128 -0
- package/dist/core/assistant-client/transport.d.ts +1 -1
- package/dist/core/assistant-client/transport.js +129 -835
- package/dist/core/assistant-content.d.ts +1 -17
- package/dist/core/assistant-content.js +16 -0
- package/dist/core/assistant-tool-metadata.d.ts +103 -0
- package/dist/core/assistant-tool-metadata.js +56 -0
- package/dist/core/checkpoint-interval.d.ts +1 -1
- package/dist/core/compact-events.d.ts +1 -1
- package/dist/core/durable-projection.d.ts +1 -1
- package/dist/core/durable-runs/continuation.d.ts +1 -1
- package/dist/core/durable-runs/ledger-contracts.d.ts +4 -1
- package/dist/core/durable-runs/ports.d.ts +2 -1
- package/dist/core/durable-runs/run-contracts.d.ts +1 -1
- package/dist/core/durable-runs/run-finalizer.d.ts +145 -0
- package/dist/core/durable-runs/run-finalizer.js +171 -0
- package/dist/core/events.d.ts +4 -82
- package/dist/core/events.js +2 -1
- package/dist/core/index.d.ts +4 -1
- package/dist/core/index.js +2 -1
- package/dist/core/messages.d.ts +1 -1
- package/dist/core/persistence/index.d.ts +1 -1
- package/dist/core/persistence/index.js +1 -1
- package/dist/core/question-form/normalize.d.ts +9 -3
- package/dist/core/question-form/normalize.js +20 -20
- package/dist/core/question-form/scan.js +15 -19
- package/dist/core/run-activity.d.ts +1 -1
- package/dist/core/run-events/entry.d.ts +11 -63
- package/dist/core/run-events/entry.js +12 -7
- package/dist/core/todos.d.ts +1 -1
- package/dist/core/todos.js +8 -0
- package/dist/core/tool-call-detail.d.ts +8 -1
- package/dist/core/tool-call-detail.js +35 -12
- package/dist/core/tool-events.d.ts +1 -1
- package/dist/core/tool-output.js +2 -6
- package/dist/core/tools.d.ts +2 -1
- package/dist/core/transport.d.ts +1 -1
- package/dist/core/turn-usage.d.ts +1 -1
- package/dist/core/util/parser.js +70 -69
- package/dist/embed-widget/browser/embed-send-bridge.d.ts +44 -0
- package/dist/embed-widget/browser/embed-send-bridge.js +60 -0
- package/dist/embed-widget/browser/frontend-invocation-handler.d.ts +39 -0
- package/dist/embed-widget/browser/frontend-invocation-handler.js +151 -0
- package/dist/embed-widget/browser/frontend-session-bridge.d.ts +28 -0
- package/dist/embed-widget/browser/frontend-session-bridge.js +201 -257
- package/dist/embed-widget/browser/lazy-loader.js +16 -12
- package/dist/embed-widget/browser/session-store.d.ts +19 -1
- package/dist/embed-widget/browser/session-store.js +48 -17
- package/dist/embed-widget/transports/fetch-sse.d.ts +1 -1
- package/dist/embed-widget/vanilla/index.js +131 -67
- package/dist/embed-widget/vanilla/state.js +53 -38
- package/dist/react/admin-execution/ai-agent-presentation.d.ts +35 -0
- package/dist/react/admin-execution/ai-agent-presentation.js +39 -0
- package/dist/react/admin-execution/hooks/use-ai-agent-presentation.hooks.d.ts +22 -0
- package/dist/react/admin-execution/hooks/use-ai-agent-presentation.hooks.js +25 -0
- package/dist/react/chat-cleanup/ChatCleanupPanel.d.ts +32 -0
- package/dist/react/chat-cleanup/ChatCleanupPanel.js +34 -0
- package/dist/react/chat-cleanup/chat-cleanup.hooks.d.ts +174 -0
- package/dist/react/chat-cleanup/chat-cleanup.hooks.js +83 -0
- package/dist/react/components/ChatCleanupDialog.d.ts +38 -0
- package/dist/react/components/ChatCleanupDialog.js +15 -0
- package/dist/react/components/ChatSettingsDialog.d.ts +3 -0
- package/dist/react/components/ChatSettingsDialog.js +3 -3
- package/dist/react/components/ConversationList.d.ts +19 -5
- package/dist/react/components/ConversationList.hooks.d.ts +1 -0
- package/dist/react/components/ConversationList.hooks.js +4 -2
- package/dist/react/components/ConversationList.js +66 -9
- package/dist/react/components/Icon.d.ts +1 -1
- package/dist/react/components/Icon.js +7 -0
- package/dist/react/components/Markdown.js +6 -6
- package/dist/react/components/MarkdownLink.d.ts +25 -0
- package/dist/react/components/MarkdownLink.js +17 -0
- package/dist/react/components/RoutedA2uiSurfaceCard.d.ts +80 -0
- package/dist/react/components/RoutedA2uiSurfaceCard.js +15 -0
- package/dist/react/components/ToolCard.d.ts +4 -2
- package/dist/react/components/ToolCard.js +46 -4
- package/dist/react/components/ToolCard.rules.d.ts +5 -2
- package/dist/react/components/ToolCard.rules.js +12 -5
- package/dist/react/components/mcp-ui-question-input.d.ts +1 -1
- package/dist/react/components/mcp-ui-surface-state.d.ts +3 -1
- package/dist/react/components/mcp-ui-surface-state.js +2 -2
- package/dist/react/components/own-link.d.ts +26 -0
- package/dist/react/components/own-link.js +36 -0
- package/dist/react/features/bridged-chat/create-staged-attachment-uploader.d.ts +7 -0
- package/dist/react/features/bridged-chat/create-staged-attachment-uploader.js +26 -0
- package/dist/react/features/bridged-chat/hooks/useBridgedChatTransport.hooks.d.ts +12 -0
- package/dist/react/features/bridged-chat/hooks/useBridgedChatTransport.hooks.js +60 -0
- package/dist/react/features/bridged-chat/index.d.ts +8 -0
- package/dist/react/features/bridged-chat/index.js +7 -0
- package/dist/react/features/bridged-chat/types.d.ts +49 -0
- package/dist/react/features/bridged-chat/types.js +2 -0
- package/dist/react/features/chat-pane/components/RuntimeDropUp.js +1 -1
- package/dist/react/features/chat-pane/create-daemon-attachment-uploader.d.ts +6 -0
- package/dist/react/features/chat-pane/create-daemon-attachment-uploader.js +101 -59
- package/dist/react/features/chat-pane/hooks/useChatPaneNewTabLinks.hooks.d.ts +3 -0
- package/dist/react/features/chat-pane/hooks/useChatPaneNewTabLinks.hooks.js +26 -16
- package/dist/react/features/chat-pane/model-options.d.ts +3 -1
- package/dist/react/features/chat-pane/model-options.js +3 -3
- package/dist/react/features/chat-pane/rules.js +4 -3
- package/dist/react/features/chat-pane/styles.d.ts +1 -1
- package/dist/react/features/chat-pane/styles.js +16 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationChatPane.d.ts +10 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationChatPane.js +19 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneChat.d.ts +12 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneChat.js +21 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneHeader.d.ts +13 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneHeader.js +9 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationDeleteConfirm.d.ts +12 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationDeleteConfirm.js +12 -0
- package/dist/react/features/conversation-chat-pane/hooks/useConversationChatPane.hooks.d.ts +7 -0
- package/dist/react/features/conversation-chat-pane/hooks/useConversationChatPane.hooks.js +43 -0
- package/dist/react/features/conversation-chat-pane/index.d.ts +9 -0
- package/dist/react/features/conversation-chat-pane/index.js +8 -0
- package/dist/react/features/conversation-chat-pane/rules.d.ts +25 -0
- package/dist/react/features/conversation-chat-pane/rules.js +29 -0
- package/dist/react/features/conversation-chat-pane/types.d.ts +139 -0
- package/dist/react/features/conversation-chat-pane/types.js +2 -0
- package/dist/react/features/conversations/conversation-controller.d.ts +16 -0
- package/dist/react/features/conversations/conversation-controller.js +280 -0
- package/dist/react/features/conversations/hooks/useConversationDeleteConfirmation.hooks.d.ts +15 -0
- package/dist/react/features/conversations/hooks/useConversationDeleteConfirmation.hooks.js +33 -0
- package/dist/react/features/conversations/hooks/useStoredConversations.hooks.d.ts +16 -0
- package/dist/react/features/conversations/hooks/useStoredConversations.hooks.js +36 -0
- package/dist/react/features/conversations/index.d.ts +9 -0
- package/dist/react/features/conversations/index.js +8 -0
- package/dist/react/features/conversations/types.d.ts +120 -0
- package/dist/react/features/conversations/types.js +2 -0
- package/dist/react/features/voice-input/space-hold-rules.d.ts +65 -0
- package/dist/react/features/voice-input/space-hold-rules.js +48 -0
- package/dist/react/hooks/testing/fake-transport.d.ts +1 -1
- package/dist/react/hooks/useAnsweredCards.d.ts +2 -1
- package/dist/react/hooks/useConversation.js +5 -2
- package/dist/react/hooks/useExtEventGroups.d.ts +1 -1
- package/dist/react/hooks/useRunActivity.d.ts +2 -1
- package/dist/react/hooks/useRunStream.d.ts +1 -1
- package/dist/react/hooks/useRunStream.js +1 -1
- package/dist/react/hooks/useSurfaceRecovery.js +3 -1
- package/dist/react/hooks/useToolTimeline.d.ts +2 -1
- package/dist/react/index.d.ts +5 -2
- package/dist/react/index.js +4 -2
- package/dist/react/message-blocks.d.ts +1 -48
- package/dist/react/message-blocks.js +47 -0
- package/dist/react/styles/chat-settings.css +42 -14
- package/dist/server/chat-cleanup-routes.d.ts +56 -0
- package/dist/server/chat-cleanup-routes.js +56 -0
- package/dist/server/durable-runs/recover.js +193 -171
- package/dist/server/run-finalizer/entry.js +133 -110
- package/dist/store/legacy/sqlite/conversations.js +29 -17
- package/dist/store/pglite/index.d.ts +1 -0
- package/dist/store/pglite/index.js +1 -0
- package/dist/store/ports.d.ts +12 -0
- package/dist/store/postgres/index.d.ts +1 -0
- package/dist/store/postgres/index.js +1 -0
- package/dist/store/runtime/attempt-base-retention.d.ts +57 -0
- package/dist/store/runtime/attempt-base-retention.js +103 -0
- package/dist/store/runtime/chat-maintenance.d.ts +16 -0
- package/dist/store/runtime/chat-maintenance.js +19 -0
- package/dist/store/runtime/chat-principal.d.ts +63 -0
- package/dist/store/runtime/chat-principal.js +39 -0
- package/dist/store/runtime/checkpoint-delta.d.ts +1 -1
- package/dist/store/runtime/durable-run-queries.d.ts +124 -0
- package/dist/store/runtime/durable-run-queries.js +122 -0
- package/dist/store/runtime/durable-run-store.d.ts +1 -1
- package/dist/store/runtime/durable-run-store.js +291 -343
- package/dist/store/runtime/entry.d.ts +3 -0
- package/dist/store/runtime/entry.js +3 -0
- package/dist/store/runtime/events-json.d.ts +1 -1
- package/dist/store/runtime/lazy-run-ledger.d.ts +19 -0
- package/dist/store/runtime/lazy-run-ledger.js +28 -0
- package/dist/store/runtime/run-ledger.d.ts +4 -1
- package/dist/store/runtime/run-ledger.js +256 -204
- package/dist/store/sql/bulk-deletion.d.ts +36 -0
- package/dist/store/sql/bulk-deletion.js +103 -0
- package/dist/store/sql/store-queries.d.ts +170 -0
- package/dist/store/sql/store-queries.js +212 -0
- package/dist/store/sql/store-rows.d.ts +106 -0
- package/dist/store/sql/store-rows.js +116 -0
- package/dist/store/sql/store-writes.d.ts +46 -0
- package/dist/store/sql/store-writes.js +161 -0
- package/dist/store/sql/store.d.ts +3 -16
- package/dist/store/sql/store.js +58 -428
- package/dist/store/sql/tables.d.ts +1 -0
- package/dist/store/sqlite/index.d.ts +1 -0
- package/dist/store/sqlite/index.js +1 -0
- package/dist/store/sqlite/schema.d.ts +1 -1
- package/dist/store/sqlite/schema.js +5 -1
- package/package.json +171 -20
package/README.md
CHANGED
|
@@ -266,3 +266,52 @@ React hosts can import `@jini-ai/chat/react/styles/chat-settings.css` for
|
|
|
266
266
|
colors, controls, keyboard focus, and bounded scrolling. Bind its
|
|
267
267
|
`--jini-chat-settings-*` custom properties to the host theme when needed; no
|
|
268
268
|
reference or host stylesheet is required for the settings presentation.
|
|
269
|
+
|
|
270
|
+
## Wiring
|
|
271
|
+
|
|
272
|
+
`AgentEvent` and `ToolResultMediaBlock` are declared in `@jini-ai/core/contracts/site/chat-core`;
|
|
273
|
+
`./core` imports them and keeps a deprecated type re-export until the next major. Hosts import them
|
|
274
|
+
from core.
|
|
275
|
+
|
|
276
|
+
### Chat principals (`@jini-ai/chat/store/runtime`)
|
|
277
|
+
|
|
278
|
+
`ChatPrincipal` (`AdminChatPrincipal | GuestChatPrincipal`), `ChatStoreFactory`, `hashSessionKey`,
|
|
279
|
+
`chatExpiryFor` and `GUEST_CHAT_TTL_MS` describe whose history a store holds. The host binds a
|
|
280
|
+
principal to `createChatHistoryStore`'s scope (`scopeId` = `workspaceId`, `ownerKind` = `kind`,
|
|
281
|
+
`ownerId` = `userId` or `hashSessionKey({ sessionKey })`), wraps it with `createRunGuardedChatStore`
|
|
282
|
+
and its own run-id policy and ledger, and hands routes only the resulting `ChatStoreFactory`. Guest
|
|
283
|
+
conversations get `chatExpiryFor({ principal })` as their expiry; admin conversations never expire.
|
|
284
|
+
|
|
285
|
+
### Chat maintenance and lazy run ledger (`@jini-ai/chat/store/runtime`)
|
|
286
|
+
|
|
287
|
+
`createChatMaintenanceForKernel({ kernel })` picks the SQLite/PGlite/Postgres expiry maintenance by
|
|
288
|
+
the borrowed chat kernel's transport; the host injects only its migrated chat `kernel` and hands
|
|
289
|
+
the result to `sweepExpiredChats`/`startChatExpirySweep` at composition time (never to a scoped
|
|
290
|
+
store). `createLazyChatRunLedger({ peek, open, ledgerFor })` serves a `ChatRunLedger` over a
|
|
291
|
+
database opened on first use: the host injects `open` (opens and memoizes its kernel), `peek`
|
|
292
|
+
(the kernel if already open) and `ledgerFor({ kernel })` (its own ledger, with any wrappers).
|
|
293
|
+
`hasActiveRuns` and `reconcileInterrupted` never open an unopened database.
|
|
294
|
+
|
|
295
|
+
### Visitor transcript store (`@jini-ai/chat/browser/session-store`)
|
|
296
|
+
|
|
297
|
+
`createBrowserSessionStore({ storage, transcriptKey, maxMessages, maxBytes, validateMessage,
|
|
298
|
+
overCapReads?, onFailure? })` keeps one bounded per-tab transcript envelope. The host injects the
|
|
299
|
+
`storage` port (usually a `sessionStorage` wrapper, which may namespace keys), the key, both caps
|
|
300
|
+
and the message validator. Optional: `overCapReads: 'read'` keeps rehydrating an envelope stored
|
|
301
|
+
over the caps (default `'clear'` treats it as corrupt; writes are capped either way), and
|
|
302
|
+
`onFailure({ operation, error })` receives each swallowed `load` / `decode` / `serialize` / `save` /
|
|
303
|
+
`clear` failure (default: silent). A throw from `onFailure` escapes the call.
|
|
304
|
+
|
|
305
|
+
### Embed send bridge (`@jini-ai/chat/browser/embed-send-bridge`)
|
|
306
|
+
|
|
307
|
+
An embedding page can drive a mounted widget through `installEmbedSendBridge`. The host decides
|
|
308
|
+
`enabled` and names the events; ordinary visitors get no listener. The host injects `send` (the
|
|
309
|
+
mounted widget's own conversation owner — the bridge never opens a parallel transport),
|
|
310
|
+
`requestEventName` (the CustomEvent dispatched on the mount root with `{ text, done }`),
|
|
311
|
+
`readyMessageType` (posted to the parent frame once listening) and optionally `busyMessage`.
|
|
312
|
+
React widgets pass `agentControl: createEmbedSendAgentControl({ root, enabled, invocationId,
|
|
313
|
+
requestEventName, readyMessageType }, { capabilityId?, unmountedMessage? })` to `ChatPane`, which
|
|
314
|
+
relays each request through the existing `chat.send_message` capability.
|
|
315
|
+
`./core/durable-runs/run-finalizer` holds a host run finalizer's pure slices (checkpoint growth and
|
|
316
|
+
size rules, `reportSafely`, `releaseUnreadBody`, and the `RunTimerPort`/`RunLogPort` types). The host
|
|
317
|
+
injects its timer and log through those ports and keeps the ledger, daemon client and watch state.
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* are injected, with official AG-UI types authoritative; auth, routes and encoder stay with the host.
|
|
8
8
|
* The host emits RUN_STARTED and terminal RUN_FINISHED/RUN_ERROR outside this pure projection. */
|
|
9
9
|
import { EventType, type AGUIEvent, type Interrupt } from '@ag-ui/core';
|
|
10
|
-
import type { AgentEvent } from '../events.js';
|
|
11
10
|
import { type RunNotices } from '../run-events/entry.js';
|
|
11
|
+
import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
|
|
12
|
+
export { confirmationInterrupt, readConfirmationResume, createAgUiPauseStore } from './resume.js';
|
|
12
13
|
export interface EventIdGenerator {
|
|
13
14
|
next(args: {
|
|
14
15
|
prefix: string;
|
|
@@ -52,74 +53,18 @@ interface AgUiFrameContext {
|
|
|
52
53
|
notices: RunNotices;
|
|
53
54
|
write: (event: AgUiEvent) => void;
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
type PauseOn = (required: {
|
|
57
|
+
event: AgUiEvent;
|
|
58
|
+
cursor: string | undefined;
|
|
59
|
+
}, optional: Record<string, never>) => Interrupt | undefined;
|
|
60
|
+
type DrainStatus = "succeeded" | "failed" | "canceled";
|
|
61
|
+
/** Project daemon frames until a verdict, accepted pause, or interruption. Owns reader cleanup. */
|
|
62
|
+
export declare function drainRunFramesToAgUi(ctx: AgUiFrameContext, { interruptionMessage, failureMessage, pauseOn }?: {
|
|
63
|
+
interruptionMessage?: string;
|
|
64
|
+
failureMessage?: string;
|
|
65
|
+
pauseOn?: PauseOn;
|
|
66
|
+
}): Promise<{
|
|
67
|
+
status: DrainStatus;
|
|
65
68
|
error?: unknown;
|
|
66
69
|
}>;
|
|
67
|
-
export declare function confirmationInterrupt({ threadId, runId, interrupt }: {
|
|
68
|
-
threadId: string;
|
|
69
|
-
runId: string;
|
|
70
|
-
interrupt: Interrupt;
|
|
71
|
-
}, _optional?: Record<string, never>): Extract<AgUiEvent, {
|
|
72
|
-
type: EventType.RUN_FINISHED;
|
|
73
|
-
}>;
|
|
74
|
-
export declare function readConfirmationResume({ input, threadId, runId, interruptId }: {
|
|
75
|
-
input: unknown;
|
|
76
|
-
threadId: string;
|
|
77
|
-
runId: string;
|
|
78
|
-
interruptId: string;
|
|
79
|
-
}, _optional?: Record<string, never>): {
|
|
80
|
-
decision: 'allow' | 'deny';
|
|
81
|
-
} | undefined;
|
|
82
|
-
export declare function createAgUiPauseStore({ caps, nowMs }: {
|
|
83
|
-
caps: {
|
|
84
|
-
global: number;
|
|
85
|
-
perScope: number;
|
|
86
|
-
};
|
|
87
|
-
nowMs: () => number;
|
|
88
|
-
}, _optional?: Record<string, never>): {
|
|
89
|
-
park(entry: Parameters<(key: string, value: {
|
|
90
|
-
owner: string;
|
|
91
|
-
threadId: string;
|
|
92
|
-
runId: string;
|
|
93
|
-
interruptId: string;
|
|
94
|
-
state: unknown;
|
|
95
|
-
scopeKey: string;
|
|
96
|
-
abandonAtMs: number;
|
|
97
|
-
}) => Map<string, {
|
|
98
|
-
owner: string;
|
|
99
|
-
threadId: string;
|
|
100
|
-
runId: string;
|
|
101
|
-
interruptId: string;
|
|
102
|
-
state: unknown;
|
|
103
|
-
scopeKey: string;
|
|
104
|
-
abandonAtMs: number;
|
|
105
|
-
}>>[1], _optional?: Record<string, never>): boolean;
|
|
106
|
-
claim({ owner, threadId, runId, interruptId }: {
|
|
107
|
-
owner: string;
|
|
108
|
-
threadId: string;
|
|
109
|
-
runId: string;
|
|
110
|
-
interruptId: string;
|
|
111
|
-
}, _optional?: Record<string, never>): {
|
|
112
|
-
owner: string;
|
|
113
|
-
threadId: string;
|
|
114
|
-
runId: string;
|
|
115
|
-
interruptId: string;
|
|
116
|
-
state: unknown;
|
|
117
|
-
scopeKey: string;
|
|
118
|
-
abandonAtMs: number;
|
|
119
|
-
} | undefined;
|
|
120
|
-
remove({ interruptId }: {
|
|
121
|
-
interruptId: string;
|
|
122
|
-
}, _optional?: Record<string, never>): boolean;
|
|
123
|
-
};
|
|
124
|
-
export {};
|
|
125
70
|
//# sourceMappingURL=event-projection.d.ts.map
|
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
* reads them back. Strict interruption ordering closes a message before a tool starts. IDs and custom event names
|
|
7
7
|
* are injected, with official AG-UI types authoritative; auth, routes and encoder stay with the host.
|
|
8
8
|
* The host emits RUN_STARTED and terminal RUN_FINISHED/RUN_ERROR outside this pure projection. */
|
|
9
|
-
import { EventType
|
|
9
|
+
import { EventType } from '@ag-ui/core';
|
|
10
|
+
import { InterruptSchema } from '@ag-ui/core/schemas';
|
|
10
11
|
import { readSseFrames, readTerminalReason, translateRunFrame } from '../run-events/entry.js';
|
|
12
|
+
import { confirmationInterrupt } from './resume.js';
|
|
13
|
+
export { confirmationInterrupt, readConfirmationResume, createAgUiPauseStore } from './resume.js';
|
|
11
14
|
/** Create isolated per-run translation state with explicit IDs and custom-event wire names. */
|
|
12
15
|
export function createAgUiTranslationState({ ids, customEventNames }) {
|
|
13
16
|
return { openTextMessageId: null, openReasoningMessageId: null, nextId: 0, ids, customEventNames: { ...customEventNames } };
|
|
@@ -113,32 +116,6 @@ export function translateAgentEventToAgUi({ event, state }) {
|
|
|
113
116
|
export function closeAgUiRun({ state }) {
|
|
114
117
|
return closeOpenMessages(state);
|
|
115
118
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Hands Jini's `readSseFrames` the daemon response as a stream while this route keeps the reader.
|
|
118
|
-
*
|
|
119
|
-
* `readSseFrames` takes a stream and holds its only reader until the frames end. The route needs
|
|
120
|
-
* its own handle on the daemon response too: the `res.on("close", ...)` hook cancels that reader so
|
|
121
|
-
* a client that leaves stops the upstream read at once, not at the daemon's next frame. A
|
|
122
|
-
* `ReadableStream` can only have one active reader at a time — a second `body.getReader()` throws
|
|
123
|
-
* `TypeError: ReadableStream is locked` — so the route keeps the one reader and Jini pulls through
|
|
124
|
-
* it. Cancelling the reader resolves the pending pull as done, which ends the frames the same way
|
|
125
|
-
* a daemon close does.
|
|
126
|
-
*
|
|
127
|
-
* `id:` lines are ignored by the frame reader: this path has no reattach story to resume a cursor
|
|
128
|
-
* for.
|
|
129
|
-
*/
|
|
130
|
-
function streamFromReader({ reader }, _optional = {}) {
|
|
131
|
-
return new ReadableStream({
|
|
132
|
-
async pull(controller) {
|
|
133
|
-
const { done, value } = await reader.read();
|
|
134
|
-
if (done)
|
|
135
|
-
controller.close();
|
|
136
|
-
else
|
|
137
|
-
controller.enqueue(value);
|
|
138
|
-
},
|
|
139
|
-
cancel: (reason) => reader.cancel(reason),
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
119
|
/** Writes every event in `events` to `res`, in order — the repeated `for (const e of events)
|
|
143
120
|
* writeAgUiEvent(res, e)` pattern below, named once so each caller is a flat sequence of
|
|
144
121
|
* statements rather than its own loop. */
|
|
@@ -146,27 +123,33 @@ function writeAllAgUiEvents({ write, events }, _optional = {}) {
|
|
|
146
123
|
for (const event of events)
|
|
147
124
|
write(event);
|
|
148
125
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
126
|
+
function frameEvent({ event, daemonError, failureMessage }) {
|
|
127
|
+
if (!daemonError || event.kind !== "status")
|
|
128
|
+
return event;
|
|
129
|
+
return { kind: "status", label: failureMessage, ...(event.code ? { code: event.code } : {}) };
|
|
130
|
+
}
|
|
131
|
+
/** Offer each projected event to the host before writing it. A refused card is unchanged. */
|
|
132
|
+
function writeFrameEvents({ frame, outcome, ctx, failureMessage, pauseOn }) {
|
|
133
|
+
const daemonError = Boolean(outcome.error) && !outcome.terminal;
|
|
134
|
+
const projected = outcome.events.flatMap(event => translateAgentEventToAgUi({
|
|
135
|
+
event: frameEvent({ event, daemonError, failureMessage }), state: ctx.state,
|
|
136
|
+
}));
|
|
137
|
+
for (const event of projected) {
|
|
138
|
+
const interrupt = pauseOn?.({ event, cursor: frame.cursor }, {});
|
|
139
|
+
ctx.write(event);
|
|
140
|
+
if (interrupt)
|
|
141
|
+
return interrupt;
|
|
142
|
+
}
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
/** Maps a terminal frame to its closing events and the run's final status; `null` (and nothing
|
|
146
|
+
* written) for a frame that neither errors nor ends the run. */
|
|
147
|
+
function writeFrameTerminal({ frame, outcome, ctx, failureMessage }, _optional = {}) {
|
|
165
148
|
if (!outcome.error && !outcome.terminal)
|
|
166
149
|
return null;
|
|
167
150
|
writeAllAgUiEvents({ write: ctx.write, events: closeAgUiRun({ state: ctx.state }) });
|
|
168
151
|
if (outcome.error) {
|
|
169
|
-
ctx.write({ type: EventType.RUN_ERROR, message:
|
|
152
|
+
ctx.write({ type: EventType.RUN_ERROR, message: failureMessage });
|
|
170
153
|
return "failed";
|
|
171
154
|
}
|
|
172
155
|
const canceled = outcome.terminal === "canceled";
|
|
@@ -174,102 +157,44 @@ function writeFrameOutcome({ frame, outcome, ctx }, _optional = {}) {
|
|
|
174
157
|
ctx.write({ type: EventType.RUN_FINISHED, threadId: ctx.threadId, runId: ctx.runId, result: { reason } });
|
|
175
158
|
return canceled ? "canceled" : "succeeded";
|
|
176
159
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
160
|
+
function handleFrame({ frame, ctx, carry, failureMessage, pauseOn }) {
|
|
161
|
+
let marked;
|
|
162
|
+
const outcome = translateRunFrame({ kind: frame.event, raw: frame.data, notices: ctx.notices }, {
|
|
163
|
+
carry,
|
|
164
|
+
onAgentPayload: ({ pendingApproval }) => {
|
|
165
|
+
const marker = InterruptSchema.safeParse(pendingApproval);
|
|
166
|
+
// The validator's optional field types include explicit undefined, unlike Interrupt.
|
|
167
|
+
if (marker.success)
|
|
168
|
+
marked = marker.data;
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
// The existing daemon marker is control-only. New host parks deliver the ordinary card first.
|
|
172
|
+
const interrupt = marked ?? writeFrameEvents({ frame, outcome, ctx, failureMessage, pauseOn });
|
|
173
|
+
if (!interrupt)
|
|
174
|
+
return writeFrameTerminal({ frame, outcome, ctx, failureMessage });
|
|
175
|
+
writeAllAgUiEvents({ write: ctx.write, events: closeAgUiRun({ state: ctx.state }) });
|
|
176
|
+
ctx.write(confirmationInterrupt({ threadId: ctx.threadId, runId: ctx.runId, interrupt }));
|
|
177
|
+
return "succeeded";
|
|
178
|
+
}
|
|
179
|
+
function writeInterrupted({ ctx, message }) {
|
|
180
|
+
writeAllAgUiEvents({ write: ctx.write, events: closeAgUiRun({ state: ctx.state }) });
|
|
181
|
+
ctx.write({ type: EventType.RUN_ERROR, message });
|
|
182
|
+
}
|
|
183
|
+
/** Project daemon frames until a verdict, accepted pause, or interruption. Owns reader cleanup. */
|
|
184
|
+
export async function drainRunFramesToAgUi(ctx, { interruptionMessage = "The response was interrupted. Try again.", failureMessage = "The run failed. Try again.", pauseOn } = {}) {
|
|
187
185
|
const carry = {};
|
|
188
186
|
try {
|
|
189
|
-
for await (const frame of readSseFrames({
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
192
|
-
const marker = InterruptSchema.safeParse(JSON.parse(frame.data).payload.pendingApproval);
|
|
193
|
-
if (marker.success) {
|
|
194
|
-
writeAllAgUiEvents({ write: ctx.write, events: closeAgUiRun({ state: ctx.state }) });
|
|
195
|
-
ctx.write(confirmationInterrupt({ threadId: ctx.threadId, runId: ctx.runId, interrupt: marker.data }));
|
|
196
|
-
return { status: 'succeeded' };
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
const status = writeFrameOutcome({ frame, outcome, ctx });
|
|
200
|
-
if (status) {
|
|
187
|
+
for await (const frame of readSseFrames({ reader: ctx.reader }, { includeCursor: true })) {
|
|
188
|
+
const status = handleFrame({ frame, ctx, carry, failureMessage, pauseOn });
|
|
189
|
+
if (status)
|
|
201
190
|
return { status };
|
|
202
|
-
}
|
|
203
191
|
}
|
|
204
|
-
writeAllAgUiEvents({ write: ctx.write, events: closeAgUiRun({ state: ctx.state }) });
|
|
205
|
-
ctx.write({ type: EventType.RUN_FINISHED, threadId: ctx.threadId, runId: ctx.runId, result: { reason: "stop" } });
|
|
206
|
-
return { status: "succeeded" };
|
|
207
192
|
}
|
|
208
193
|
catch (error) {
|
|
209
|
-
|
|
210
|
-
ctx.write({ type: EventType.RUN_ERROR, message: error instanceof Error ? error.message : String(error) });
|
|
194
|
+
writeInterrupted({ ctx, message: interruptionMessage });
|
|
211
195
|
return { status: "failed", error };
|
|
212
196
|
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return { type: EventType.RUN_FINISHED, threadId, runId,
|
|
216
|
-
outcome: { type: 'interrupt', interrupts: [{ ...interrupt, reason: 'confirmation' }] } };
|
|
217
|
-
}
|
|
218
|
-
export function readConfirmationResume({ input, threadId, runId, interruptId }, _optional = {}) {
|
|
219
|
-
const parsed = RunAgentInputSchema.safeParse(input);
|
|
220
|
-
if (!parsed.success)
|
|
221
|
-
return undefined;
|
|
222
|
-
const value = parsed.data;
|
|
223
|
-
if (value.threadId !== threadId || value.parentRunId !== runId)
|
|
224
|
-
return undefined;
|
|
225
|
-
if (value.resume?.length !== 1)
|
|
226
|
-
return undefined;
|
|
227
|
-
const entry = value.resume[0];
|
|
228
|
-
if (entry.interruptId !== interruptId)
|
|
229
|
-
return undefined;
|
|
230
|
-
if (entry.status === 'cancelled')
|
|
231
|
-
return { decision: 'deny' };
|
|
232
|
-
if (entry.payload === 'allow')
|
|
233
|
-
return { decision: 'allow' };
|
|
234
|
-
if (['deny', 'dismissed'].includes(entry.payload))
|
|
235
|
-
return { decision: 'deny' };
|
|
236
|
-
return undefined;
|
|
237
|
-
}
|
|
238
|
-
export function createAgUiPauseStore({ caps, nowMs }, _optional = {}) {
|
|
239
|
-
const records = new Map();
|
|
240
|
-
return {
|
|
241
|
-
park(entry, _optional = {}) {
|
|
242
|
-
const now = nowMs();
|
|
243
|
-
let scoped = 0;
|
|
244
|
-
for (const [id, record] of records) {
|
|
245
|
-
if (record.abandonAtMs <= now)
|
|
246
|
-
records.delete(id);
|
|
247
|
-
else if (record.scopeKey === entry.scopeKey)
|
|
248
|
-
scoped++;
|
|
249
|
-
}
|
|
250
|
-
if (entry.abandonAtMs <= now || records.has(entry.interruptId))
|
|
251
|
-
return false;
|
|
252
|
-
if (records.size >= caps.global || scoped >= caps.perScope)
|
|
253
|
-
return false;
|
|
254
|
-
records.set(entry.interruptId, { ...entry });
|
|
255
|
-
return true;
|
|
256
|
-
},
|
|
257
|
-
claim({ owner, threadId, runId, interruptId }, _optional = {}) {
|
|
258
|
-
const record = records.get(interruptId);
|
|
259
|
-
if (!record)
|
|
260
|
-
return undefined;
|
|
261
|
-
if (record.abandonAtMs <= nowMs()) {
|
|
262
|
-
records.delete(interruptId);
|
|
263
|
-
return undefined;
|
|
264
|
-
}
|
|
265
|
-
if (record.owner !== owner || record.threadId !== threadId || record.runId !== runId)
|
|
266
|
-
return undefined;
|
|
267
|
-
records.delete(interruptId);
|
|
268
|
-
return record;
|
|
269
|
-
},
|
|
270
|
-
remove({ interruptId }, _optional = {}) {
|
|
271
|
-
return records.delete(interruptId);
|
|
272
|
-
},
|
|
273
|
-
};
|
|
197
|
+
writeInterrupted({ ctx, message: interruptionMessage });
|
|
198
|
+
return { status: "failed" };
|
|
274
199
|
}
|
|
275
200
|
//# sourceMappingURL=event-projection.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AgentEvent } from '../events.js';
|
|
2
1
|
import type { AgUiEvent, CustomEventNames } from './event-projection.js';
|
|
2
|
+
import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
|
|
3
3
|
/**
|
|
4
4
|
* Accumulates `TOOL_CALL_ARGS` deltas by `toolCallId` between a call's `TOOL_CALL_START` and
|
|
5
5
|
* `TOOL_CALL_END` — the inverse of `assistant-ag-ui.ts`'s server-side translator, which emits all
|
|
@@ -11,6 +11,7 @@ import type { AgUiEvent, CustomEventNames } from './event-projection.js';
|
|
|
11
11
|
export interface AgUiToAgentTranslationState {
|
|
12
12
|
toolCalls: Map<string, AgUiOpenToolCall>;
|
|
13
13
|
readonly customEventNames: CustomEventNames;
|
|
14
|
+
readonly toolOptions?: ToolDecodeOptions;
|
|
14
15
|
}
|
|
15
16
|
/** One call between its `TOOL_CALL_START` and `TOOL_CALL_END`. `toolOrigin` and `bridgeCall` are
|
|
16
17
|
* the start event's extra fields as received, not yet checked. */
|
|
@@ -20,9 +21,17 @@ export interface AgUiOpenToolCall {
|
|
|
20
21
|
toolOrigin?: unknown;
|
|
21
22
|
bridgeCall?: unknown;
|
|
22
23
|
}
|
|
24
|
+
interface ToolDecodeOptions {
|
|
25
|
+
acceptToolCall?: (required: {
|
|
26
|
+
toolCallId: string;
|
|
27
|
+
toolCallName: string;
|
|
28
|
+
}, optional: Record<string, never>) => boolean;
|
|
29
|
+
maxToolArgsChars?: number;
|
|
30
|
+
}
|
|
31
|
+
/** Start one segment's decoder. Opt-in tool policies drop malformed calls instead of displaying raw arguments. */
|
|
23
32
|
export declare function createAgUiToAgentTranslationState({ customEventNames }: {
|
|
24
33
|
customEventNames: CustomEventNames;
|
|
25
|
-
},
|
|
34
|
+
}, toolOptions?: ToolDecodeOptions): AgUiToAgentTranslationState;
|
|
26
35
|
/**
|
|
27
36
|
* Translates one AG-UI event into zero or more chat-core `AgentEvent`s, threading `state` across
|
|
28
37
|
* calls within a single run for tool-call argument accumulation.
|
|
@@ -36,4 +45,5 @@ export declare function translateAgUiEventToAgentEvent({ event, state }: {
|
|
|
36
45
|
event: AgUiEvent;
|
|
37
46
|
state: AgUiToAgentTranslationState;
|
|
38
47
|
}, _options?: Record<string, never>): AgentEvent[];
|
|
48
|
+
export {};
|
|
39
49
|
//# sourceMappingURL=event-reduction.d.ts.map
|
|
@@ -5,15 +5,39 @@
|
|
|
5
5
|
* the daemon wire accept and ignore exactly the same shapes. */
|
|
6
6
|
import { EventType } from '@ag-ui/core';
|
|
7
7
|
import { asString, translateRunAgentPayload } from '../run-events/entry.js';
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/** Read one of the projection's extra fields off a validated event. AG-UI 1.0's generated event
|
|
9
|
+
* types are closed, but its validators stay passthrough (as 0.x's were), so these fields still
|
|
10
|
+
* arrive on the wire; they read as `unknown`, exactly as 0.x's passthrough index signature typed
|
|
11
|
+
* them, and the payload reducer narrows them.
|
|
12
|
+
* @complexity O(1). */
|
|
13
|
+
function readExtraField({ event, key }, _optional = {}) {
|
|
14
|
+
return event[key];
|
|
15
|
+
}
|
|
16
|
+
/** Start one segment's decoder. Opt-in tool policies drop malformed calls instead of displaying raw arguments. */
|
|
17
|
+
export function createAgUiToAgentTranslationState({ customEventNames }, toolOptions = {}) {
|
|
18
|
+
return { toolCalls: new Map(), customEventNames: { ...customEventNames },
|
|
19
|
+
...(toolOptions.acceptToolCall || toolOptions.maxToolArgsChars !== undefined ? { toolOptions: { ...toolOptions } } : {}) };
|
|
20
|
+
}
|
|
21
|
+
function beginToolCall({ event, state }) {
|
|
22
|
+
const { toolCallId, toolCallName } = event;
|
|
23
|
+
if (state.toolOptions?.acceptToolCall?.({ toolCallId, toolCallName }, {}) === false) {
|
|
24
|
+
state.toolCalls.delete(toolCallId);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
state.toolCalls.set(toolCallId, { name: toolCallName, argsJson: "",
|
|
28
|
+
toolOrigin: readExtraField({ event, key: "toolOrigin" }), bridgeCall: readExtraField({ event, key: "bridgeCall" }) });
|
|
10
29
|
}
|
|
11
30
|
/** The `TOOL_CALL_ARGS` case of {@link translateAgUiEventToAgentEvent} — accumulates one delta onto
|
|
12
31
|
* the in-flight call's buffer, a silent no-op for an id with no matching `TOOL_CALL_START`. Split
|
|
13
32
|
* out so this `if` is scored in its own complexity budget rather than the switch's. */
|
|
14
33
|
function accumulateToolCallArgs({ toolCallId, delta, state }) {
|
|
15
34
|
const call = state.toolCalls.get(toolCallId);
|
|
16
|
-
if (call)
|
|
35
|
+
if (!call)
|
|
36
|
+
return;
|
|
37
|
+
const max = state.toolOptions?.maxToolArgsChars ?? Infinity;
|
|
38
|
+
if (call.argsJson.length + delta.length > max)
|
|
39
|
+
state.toolCalls.delete(toolCallId);
|
|
40
|
+
else
|
|
17
41
|
call.argsJson += delta;
|
|
18
42
|
}
|
|
19
43
|
/** `TEXT_MESSAGE_START` keeps an explicit step boundary so two assistant messages cannot fuse into
|
|
@@ -27,16 +51,17 @@ function translateAgUiStepStart({ event }, _options = {}) {
|
|
|
27
51
|
/** The `TOOL_CALL_END` case of {@link translateAgUiEventToAgentEvent} — parses the accumulated
|
|
28
52
|
* args buffer (already removed from `state` by the caller) into one `tool_use` event, or `[]` for
|
|
29
53
|
* an id with no matching `TOOL_CALL_START`. */
|
|
30
|
-
function finalizeToolCallAgentEvent({ toolCallId, call }) {
|
|
31
|
-
if (!call)
|
|
54
|
+
function finalizeToolCallAgentEvent({ toolCallId, call, strict }) {
|
|
55
|
+
if (!call || (strict && !call.argsJson))
|
|
32
56
|
return [];
|
|
33
57
|
let input = {};
|
|
34
58
|
try {
|
|
35
59
|
input = call.argsJson.length > 0 ? JSON.parse(call.argsJson) : {};
|
|
36
60
|
}
|
|
37
61
|
catch {
|
|
38
|
-
|
|
39
|
-
|
|
62
|
+
if (strict)
|
|
63
|
+
return [];
|
|
64
|
+
// An unbounded display adapter can still show the raw arguments.
|
|
40
65
|
input = call.argsJson;
|
|
41
66
|
}
|
|
42
67
|
return reduced({ payload: { type: "tool_use", id: toolCallId, name: call.name, input, toolOrigin: call.toolOrigin, bridgeCall: call.bridgeCall } });
|
|
@@ -73,7 +98,7 @@ export function translateAgUiEventToAgentEvent({ event, state }, _options = {})
|
|
|
73
98
|
case EventType.REASONING_MESSAGE_CONTENT:
|
|
74
99
|
return [{ kind: "thinking", text: event.delta }];
|
|
75
100
|
case EventType.TOOL_CALL_START:
|
|
76
|
-
|
|
101
|
+
beginToolCall({ event, state });
|
|
77
102
|
return [];
|
|
78
103
|
case EventType.TOOL_CALL_ARGS:
|
|
79
104
|
accumulateToolCallArgs({ toolCallId: event.toolCallId, delta: event.delta, state });
|
|
@@ -81,13 +106,13 @@ export function translateAgUiEventToAgentEvent({ event, state }, _options = {})
|
|
|
81
106
|
case EventType.TOOL_CALL_END: {
|
|
82
107
|
const call = state.toolCalls.get(event.toolCallId);
|
|
83
108
|
state.toolCalls.delete(event.toolCallId);
|
|
84
|
-
return finalizeToolCallAgentEvent({ toolCallId: event.toolCallId, call });
|
|
109
|
+
return finalizeToolCallAgentEvent({ toolCallId: event.toolCallId, call, strict: state.toolOptions !== undefined });
|
|
85
110
|
}
|
|
86
111
|
case EventType.TOOL_CALL_RESULT:
|
|
87
112
|
// AG-UI's `ToolCallResultEvent` has no standard `isError`, `media` or `outcome` field. The
|
|
88
113
|
// projection writes them as extra fields; a server that sends none (an older one, or another
|
|
89
114
|
// AG-UI server) reads as a plain successful result, as before.
|
|
90
|
-
return reduced({ payload: { type: "tool_result", toolUseId: event.toolCallId, content: event.content, isError: event
|
|
115
|
+
return reduced({ payload: { type: "tool_result", toolUseId: event.toolCallId, content: event.content, isError: readExtraField({ event, key: "isError" }), media: readExtraField({ event, key: "media" }), outcome: readExtraField({ event, key: "outcome" }) } });
|
|
91
116
|
case EventType.RAW:
|
|
92
117
|
return [{ kind: "raw", line: asString({ value: event.event }) }];
|
|
93
118
|
case EventType.CUSTOM:
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** One-use, host-owned confirmation handoff. No route, authentication or run I/O lives here. */
|
|
2
|
+
import { EventType, type Interrupt } from '@ag-ui/core';
|
|
3
|
+
import type { AgUiEvent } from './event-projection.js';
|
|
4
|
+
type Empty = Record<string, never>;
|
|
5
|
+
type ResumeDecision = 'allow' | 'deny' | 'cancelled';
|
|
6
|
+
export declare function confirmationInterrupt({ threadId, runId, interrupt }: {
|
|
7
|
+
threadId: string;
|
|
8
|
+
runId: string;
|
|
9
|
+
interrupt: Interrupt;
|
|
10
|
+
}, _optional?: Empty): Extract<AgUiEvent, {
|
|
11
|
+
type: EventType.RUN_FINISHED;
|
|
12
|
+
}>;
|
|
13
|
+
/** Legacy readers treat dismissed and cancelled answers as denials. */
|
|
14
|
+
export declare function readConfirmationResume({ input, threadId, runId, interruptId }: {
|
|
15
|
+
input: unknown;
|
|
16
|
+
threadId: string;
|
|
17
|
+
runId: string;
|
|
18
|
+
interruptId: string;
|
|
19
|
+
}, _optional?: Empty): {
|
|
20
|
+
decision: 'allow' | 'deny';
|
|
21
|
+
} | undefined;
|
|
22
|
+
type Caps = {
|
|
23
|
+
global: number;
|
|
24
|
+
perScope: number;
|
|
25
|
+
};
|
|
26
|
+
type PauseAddress = {
|
|
27
|
+
ownerKey: string;
|
|
28
|
+
threadId: string;
|
|
29
|
+
parentRunId: string;
|
|
30
|
+
};
|
|
31
|
+
export interface AgUiResumeRecord<State> extends PauseAddress {
|
|
32
|
+
scopeKey: string;
|
|
33
|
+
interruptId: string;
|
|
34
|
+
expiresAtMs: number;
|
|
35
|
+
state: State;
|
|
36
|
+
}
|
|
37
|
+
type AbandonReason = 'expired' | 'stopped' | 'shutdown';
|
|
38
|
+
type Abandoned<State> = {
|
|
39
|
+
entry: AgUiResumeRecord<State>;
|
|
40
|
+
reason: AbandonReason;
|
|
41
|
+
};
|
|
42
|
+
export interface AgUiResumeRegistry<State> {
|
|
43
|
+
park(required: AgUiResumeRecord<State>, optional?: Empty): boolean;
|
|
44
|
+
claim(required: {
|
|
45
|
+
input: unknown;
|
|
46
|
+
ownerKey: string;
|
|
47
|
+
}, optional?: Empty): {
|
|
48
|
+
entry: AgUiResumeRecord<State>;
|
|
49
|
+
runId: string;
|
|
50
|
+
decision: ResumeDecision;
|
|
51
|
+
} | undefined;
|
|
52
|
+
abandon(required: {
|
|
53
|
+
interruptId: string;
|
|
54
|
+
reason: AbandonReason;
|
|
55
|
+
}, optional?: Empty): boolean;
|
|
56
|
+
abandonWhere(required: {
|
|
57
|
+
matches: (entry: AgUiResumeRecord<State>) => boolean;
|
|
58
|
+
reason: AbandonReason;
|
|
59
|
+
}, optional?: Empty): number;
|
|
60
|
+
shutdown(required: Empty, optional?: Empty): void;
|
|
61
|
+
}
|
|
62
|
+
/** Park typed host state until its verified owner claims it, or one abandonment path takes it. */
|
|
63
|
+
export declare function createAgUiResumeRegistry<State>({ caps, nowMs, schedule, onAbandon }: {
|
|
64
|
+
caps: Caps;
|
|
65
|
+
nowMs: () => number;
|
|
66
|
+
schedule: (required: {
|
|
67
|
+
delayMs: number;
|
|
68
|
+
callback: () => void;
|
|
69
|
+
}, optional: Empty) => () => void;
|
|
70
|
+
onAbandon: (required: Abandoned<State>, optional: Empty) => void;
|
|
71
|
+
}, { maxWireIdChars }?: {
|
|
72
|
+
maxWireIdChars?: number;
|
|
73
|
+
}): AgUiResumeRegistry<State>;
|
|
74
|
+
type LegacyAddress = {
|
|
75
|
+
owner: string;
|
|
76
|
+
threadId: string;
|
|
77
|
+
runId: string;
|
|
78
|
+
interruptId: string;
|
|
79
|
+
};
|
|
80
|
+
type LegacyEntry = LegacyAddress & {
|
|
81
|
+
state: unknown;
|
|
82
|
+
scopeKey: string;
|
|
83
|
+
abandonAtMs: number;
|
|
84
|
+
};
|
|
85
|
+
interface LegacyStore {
|
|
86
|
+
park(entry: LegacyEntry, optional?: Empty): boolean;
|
|
87
|
+
claim(address: LegacyAddress, optional?: Empty): LegacyEntry | undefined;
|
|
88
|
+
remove(required: {
|
|
89
|
+
interruptId: string;
|
|
90
|
+
}, optional?: Empty): boolean;
|
|
91
|
+
}
|
|
92
|
+
/** Preserve the original untimed store interface over the same one-use pause table. */
|
|
93
|
+
export declare function createAgUiPauseStore({ caps, nowMs }: {
|
|
94
|
+
caps: Caps;
|
|
95
|
+
nowMs: () => number;
|
|
96
|
+
}, _optional?: Empty): LegacyStore;
|
|
97
|
+
export interface AgUiApprovalCard {
|
|
98
|
+
exchangeId: string;
|
|
99
|
+
toolId: string;
|
|
100
|
+
message: string;
|
|
101
|
+
expiresAtMs?: number;
|
|
102
|
+
}
|
|
103
|
+
/** Identify only MCP-UI exchange cards with both confirmation actions. Other cards stay ordinary. */
|
|
104
|
+
export declare function readAgUiApprovalCard({ event, extensionPrefix, fallbackMessage }: {
|
|
105
|
+
event: AgUiEvent;
|
|
106
|
+
extensionPrefix: string;
|
|
107
|
+
fallbackMessage: string;
|
|
108
|
+
}, _optional?: Empty): AgUiApprovalCard | undefined;
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=resume.d.ts.map
|