@jini-ai/chat 0.7.2 → 0.7.3-next.2
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/CHANGELOG.md +2 -2
- package/README.md +3 -3
- package/dist/contracts/chat-bubble-style.d.ts +1 -1
- package/dist/contracts/chat-bubble-style.js +1 -1
- package/dist/core/ag-ui/event-projection.d.ts +125 -0
- package/dist/core/ag-ui/event-projection.js +275 -0
- package/dist/core/ag-ui/event-reduction.d.ts +39 -0
- package/dist/core/ag-ui/event-reduction.js +99 -0
- package/dist/core/ag-ui/run-input.d.ts +53 -0
- package/dist/core/ag-ui/run-input.js +87 -0
- package/dist/core/agentic/chat-capabilities.d.ts +1 -1
- package/dist/core/agentic/index.d.ts +2 -4
- package/dist/core/agentic/index.js +2 -3
- package/dist/core/agents-port.d.ts +50 -0
- package/dist/core/agents-port.js +2 -0
- package/dist/core/assistant-client/ag-ui-fetch-agent.d.ts +16 -0
- package/dist/core/assistant-client/ag-ui-fetch-agent.js +24 -0
- package/dist/core/assistant-client/ag-ui-transport.d.ts +15 -1
- package/dist/core/assistant-client/ag-ui-transport.js +167 -145
- package/dist/core/assistant-client/attachment-liveness.js +13 -11
- package/dist/core/assistant-client/durable-run-subscription.d.ts +3 -2
- package/dist/core/assistant-client/durable-run-subscription.js +6 -5
- package/dist/core/assistant-client/messages.d.ts +7 -4
- package/dist/core/assistant-client/messages.js +5 -4
- package/dist/core/assistant-client/transport.d.ts +1 -1
- package/dist/core/assistant-client/transport.js +4 -4
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +1 -0
- package/dist/core/page-port.d.ts +15 -0
- package/dist/core/page-port.js +2 -0
- package/dist/core/run-activity.js +1 -1
- package/dist/core/run-events/entry.js +1 -0
- package/dist/core/user-text-redaction.d.ts +1 -3
- package/dist/core/user-text-redaction.js +3 -61
- package/dist/embed-widget/browser/agent-inventory.d.ts +37 -0
- package/dist/embed-widget/browser/agent-inventory.js +36 -0
- package/dist/embed-widget/browser/frontend-session-bridge.d.ts +2 -2
- package/dist/embed-widget/browser/frontend-session-bridge.js +17 -14
- package/dist/embed-widget/react/dialog.hooks.d.ts +16 -0
- package/dist/embed-widget/react/dialog.hooks.js +15 -0
- package/dist/embed-widget/react/embed.d.ts +7 -2
- package/dist/embed-widget/react/embed.js +6 -16
- package/dist/embed-widget/react/header.d.ts +4 -1
- package/dist/embed-widget/react/header.js +2 -2
- package/dist/embed-widget/vanilla/state.js +2 -2
- package/dist/embed-widget/vanilla/style.css +4 -4
- package/dist/react/components/A2uiSurfaceCard.d.ts +18 -4
- package/dist/react/components/A2uiSurfaceCard.hooks.d.ts +36 -0
- package/dist/react/components/A2uiSurfaceCard.hooks.js +174 -0
- package/dist/react/components/A2uiSurfaceCard.js +14 -227
- package/dist/react/components/A2uiSurfaceCard.rules.d.ts +14 -0
- package/dist/react/components/A2uiSurfaceCard.rules.js +24 -0
- package/dist/react/components/AttachmentPreviewModal.d.ts +21 -1
- package/dist/react/components/AttachmentPreviewModal.hooks.js +1 -3
- package/dist/react/components/AttachmentPreviewModal.js +11 -9
- package/dist/react/components/AttachmentTray.d.ts +11 -1
- package/dist/react/components/AttachmentTray.js +12 -8
- package/dist/react/components/ChatFab.d.ts +10 -1
- package/dist/react/components/ChatFab.js +2 -2
- package/dist/react/components/ChatSettingsDialog.d.ts +4 -3
- package/dist/react/components/ChatSettingsDialog.js +9 -6
- package/dist/react/components/ChatSettingsSegmented.d.ts +1 -1
- package/dist/react/components/ChatSettingsSegmented.js +1 -1
- package/dist/react/components/Composer.d.ts +9 -1
- package/dist/react/components/Composer.hooks.d.ts +79 -0
- package/dist/react/components/Composer.hooks.js +336 -0
- package/dist/react/components/Composer.js +40 -341
- package/dist/react/components/ComposerDiscovery.js +1 -1
- package/dist/react/components/ConversationList.d.ts +34 -1
- package/dist/react/components/ConversationList.hooks.d.ts +37 -0
- package/dist/react/components/ConversationList.hooks.js +177 -1
- package/dist/react/components/ConversationList.js +7 -174
- package/dist/react/components/ConversationTitleEditor.d.ts +17 -2
- package/dist/react/components/ConversationTitleEditor.hooks.d.ts +15 -0
- package/dist/react/components/ConversationTitleEditor.hooks.js +36 -0
- package/dist/react/components/ConversationTitleEditor.js +11 -34
- package/dist/react/components/CopyMessageButton.d.ts +6 -1
- package/dist/react/components/CopyMessageButton.js +4 -4
- package/dist/react/components/ExtEventErrorBoundary.d.ts +2 -0
- package/dist/react/components/ExtEventErrorBoundary.js +5 -3
- package/dist/react/components/FolderChips.d.ts +11 -1
- package/dist/react/components/FolderChips.hooks.d.ts +12 -0
- package/dist/react/components/FolderChips.hooks.js +10 -0
- package/dist/react/components/FolderChips.js +9 -9
- package/dist/react/components/Markdown.js +7 -5
- package/dist/react/components/McpUiSurfaceCard.d.ts +29 -5
- package/dist/react/components/McpUiSurfaceCard.js +29 -16
- package/dist/react/components/MessageList.d.ts +10 -1
- package/dist/react/components/MessageList.hooks.js +4 -2
- package/dist/react/components/MessageList.js +12 -8
- package/dist/react/components/MessageRow.d.ts +46 -2
- package/dist/react/components/MessageRow.hooks.d.ts +60 -0
- package/dist/react/components/MessageRow.hooks.js +94 -0
- package/dist/react/components/MessageRow.js +53 -113
- package/dist/react/components/MidRunUserMessage.d.ts +6 -1
- package/dist/react/components/MidRunUserMessage.js +5 -5
- package/dist/react/components/NextStepActions.d.ts +3 -1
- package/dist/react/components/NextStepActions.js +3 -3
- package/dist/react/components/QuestionForm.answers.hooks.d.ts +26 -0
- package/dist/react/components/QuestionForm.answers.hooks.js +89 -0
- package/dist/react/components/QuestionForm.d.ts +6 -0
- package/dist/react/components/QuestionForm.js +23 -261
- package/dist/react/components/QuestionForm.values.d.ts +22 -0
- package/dist/react/components/QuestionForm.values.js +58 -0
- package/dist/react/components/QuestionFormField.d.ts +17 -0
- package/dist/react/components/QuestionFormField.js +114 -0
- package/dist/react/components/QuestionsPanel.d.ts +3 -1
- package/dist/react/components/QuestionsPanel.js +7 -3
- package/dist/react/components/SentAttachment.d.ts +11 -2
- package/dist/react/components/SentAttachment.hooks.d.ts +1 -1
- package/dist/react/components/SentAttachment.hooks.js +6 -5
- package/dist/react/components/SentAttachment.js +5 -3
- package/dist/react/components/TodoCard.d.ts +3 -1
- package/dist/react/components/TodoCard.js +9 -4
- package/dist/react/components/ToolCallGroup.d.ts +11 -1
- package/dist/react/components/ToolCallGroup.js +10 -4
- package/dist/react/components/ToolCard.d.ts +6 -1
- package/dist/react/components/ToolCard.js +79 -69
- package/dist/react/components/mcp-ui-question-input.d.ts +1 -1
- package/dist/react/components/mcp-ui-question-input.js +3 -3
- package/dist/react/components/mcp-ui-surface-state.d.ts +1 -1
- package/dist/react/features/chat-pane/agent-tools.d.ts +1 -1
- package/dist/react/features/chat-pane/antigravity/model-options.d.ts +2 -0
- package/dist/react/features/chat-pane/antigravity/model-options.js +2 -0
- package/dist/react/features/chat-pane/claude/model-options.d.ts +2 -0
- package/dist/react/features/chat-pane/claude/model-options.js +2 -0
- package/dist/react/features/chat-pane/codex/model-options.d.ts +2 -0
- package/dist/react/features/chat-pane/codex/model-options.js +2 -0
- package/dist/react/features/chat-pane/components/AgentPluginUsage.d.ts +4 -1
- package/dist/react/features/chat-pane/components/AgentPluginUsage.js +2 -2
- package/dist/react/features/chat-pane/components/AgentRuntimePicker.d.ts +10 -6
- package/dist/react/features/chat-pane/components/AgentRuntimePicker.js +18 -132
- package/dist/react/features/chat-pane/components/ChatPane.d.ts +24 -2
- package/dist/react/features/chat-pane/components/ChatPane.js +45 -297
- package/dist/react/features/chat-pane/components/ChatPaneComposerArea.d.ts +33 -0
- package/dist/react/features/chat-pane/components/ChatPaneComposerArea.js +119 -0
- package/dist/react/features/chat-pane/components/ChatPaneLayout.d.ts +42 -0
- package/dist/react/features/chat-pane/components/ChatPaneLayout.js +54 -0
- package/dist/react/features/chat-pane/components/ChatPaneStatus.d.ts +27 -0
- package/dist/react/features/chat-pane/components/ChatPaneStatus.js +91 -0
- package/dist/react/features/chat-pane/components/RuntimeDropUp.d.ts +6 -1
- package/dist/react/features/chat-pane/components/RuntimeDropUp.js +20 -19
- package/dist/react/features/chat-pane/components/RuntimePickerSections.d.ts +62 -0
- package/dist/react/features/chat-pane/components/RuntimePickerSections.js +122 -0
- package/dist/react/features/chat-pane/create-mcp-ui-tool-caller.d.ts +1 -1
- package/dist/react/features/chat-pane/hooks/useChatPane.hooks.d.ts +5 -3
- package/dist/react/features/chat-pane/hooks/useChatPane.hooks.js +78 -26
- package/dist/react/features/chat-pane/hooks/useChatPaneAgentControl.hooks.js +6 -6
- package/dist/react/features/chat-pane/hooks/useChatPaneFileDrop.hooks.d.ts +5 -1
- package/dist/react/features/chat-pane/hooks/useChatPaneFileDrop.hooks.js +7 -7
- package/dist/react/features/chat-pane/hooks/useRuntimeDropUp.hooks.d.ts +7 -0
- package/dist/react/features/chat-pane/hooks/useRuntimeDropUp.hooks.js +5 -0
- package/dist/react/features/chat-pane/model-options.js +7 -4
- package/dist/react/features/chat-pane/styles.d.ts +1 -1
- package/dist/react/features/chat-pane/styles.js +14 -14
- package/dist/react/features/chat-pane/types.d.ts +29 -1
- package/dist/react/hooks/assistant-chats-contracts.d.ts +1 -1
- package/dist/react/hooks/attachment-preview-cache.d.ts +1 -1
- package/dist/react/hooks/attachment-preview-cache.js +1 -1
- package/dist/react/hooks/fab-position.js +16 -18
- package/dist/react/hooks/useConversation.d.ts +6 -1
- package/dist/react/hooks/useConversation.js +11 -10
- package/dist/react/hooks/useRunStream.d.ts +3 -0
- package/dist/react/hooks/useRunStream.js +12 -12
- package/dist/react/hooks/useSurfaceRecovery.d.ts +1 -1
- package/dist/react/hooks/useSurfaceRecovery.js +2 -2
- package/dist/react/index.d.ts +6 -3
- package/dist/react/index.js +5 -3
- package/dist/react/styles/chat-settings.css +9 -9
- package/dist/react/surfaces.d.ts +91 -0
- package/dist/react/surfaces.js +28 -0
- package/dist/server/durable-runs/recover.d.ts +4 -3
- package/dist/server/durable-runs/recover.js +4 -3
- package/dist/store/legacy/sqlite/conversations.d.ts +1 -2
- package/dist/store/legacy/sqlite/conversations.js +1 -1
- package/dist/store/legacy/sqlite/messages.d.ts +2 -3
- package/dist/store/legacy/sqlite/messages.js +6 -6
- package/dist/store/pglite/index.d.ts +7 -7
- package/dist/store/pglite/index.js +1 -1
- package/dist/store/ports.d.ts +5 -2
- package/dist/store/postgres/index.d.ts +7 -7
- package/dist/store/postgres/index.js +1 -1
- package/dist/store/runtime/chat-expiry-sweep.js +2 -4
- package/dist/store/runtime/chat-history-store.js +2 -3
- package/dist/store/runtime/durable-run-store.js +16 -2
- package/dist/store/runtime/history-tools.js +33 -11
- package/dist/store/runtime/kernel.d.ts +3 -2
- package/dist/store/runtime/run-ledger.js +2 -2
- package/dist/store/sql/boundary.d.ts +5 -5
- package/dist/store/sql/maintenance.d.ts +3 -2
- package/dist/store/sql/store.d.ts +16 -8
- package/dist/store/sql/store.js +31 -14
- package/dist/store/sqlite/index.d.ts +11 -12
- package/dist/store/sqlite/index.js +5 -5
- package/dist/store/sqlite/schema.d.ts +1 -1
- package/package.json +49 -27
- package/dist/core/ag-ui/entry.d.ts +0 -84
- package/dist/core/ag-ui/entry.js +0 -225
- package/dist/core/browser/page-actions.d.ts +0 -121
- package/dist/core/browser/page-actions.js +0 -113
- package/dist/embed-widget/browser/page-actions.d.ts +0 -2
- package/dist/embed-widget/browser/page-actions.js +0 -3
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** Parse and bound one inbound AG-UI run request (`RunAgentInput`) for a host route.
|
|
2
|
+
* Pure: the history bound and the id generator are host inputs, so no host default or Node
|
|
3
|
+
* built-in lives here. The route that calls this owns authentication and the HTTP answer. */
|
|
4
|
+
function isPlainMessage(value) {
|
|
5
|
+
return typeof value === 'object' && value !== null;
|
|
6
|
+
}
|
|
7
|
+
/** Validates one raw history entry, same fail-soft posture as `resolveAgUiMessages`'s own doc:
|
|
8
|
+
* `null` for anything malformed rather than throwing, since history is passive background context,
|
|
9
|
+
* not something the caller just authored this instant. Split out of `resolveAgUiMessages` so the
|
|
10
|
+
* per-entry branching is scored in this function's own complexity budget, not the loop's. */
|
|
11
|
+
function parseAgUiMessage({ entry }, _optional = {}) {
|
|
12
|
+
if (!isPlainMessage(entry))
|
|
13
|
+
return null;
|
|
14
|
+
const role = entry.role === 'user' || entry.role === 'assistant' ? entry.role : null;
|
|
15
|
+
const content = typeof entry.content === 'string' ? entry.content : null;
|
|
16
|
+
if (role === null || content === null || content.length === 0)
|
|
17
|
+
return null;
|
|
18
|
+
return { role, content };
|
|
19
|
+
}
|
|
20
|
+
/** Validates and bounds the client-supplied `messages` array: malformed entries are dropped, not
|
|
21
|
+
* refused (history is passive background context, not something the caller just authored this
|
|
22
|
+
* instant), and only the trailing `maxHistoryMessages` are kept. The bound is the host's: each turn
|
|
23
|
+
* re-sends its whole history, so an unbounded one makes every later message in a long chat more
|
|
24
|
+
* expensive than the last.
|
|
25
|
+
* @complexity O(h) time and space in the supplied history. */
|
|
26
|
+
export function resolveAgUiMessages({ raw, maxHistoryMessages }, _optional = {}) {
|
|
27
|
+
if (!Array.isArray(raw))
|
|
28
|
+
return [];
|
|
29
|
+
const messages = [];
|
|
30
|
+
for (const entry of raw) {
|
|
31
|
+
const message = parseAgUiMessage({ entry });
|
|
32
|
+
if (message)
|
|
33
|
+
messages.push(message);
|
|
34
|
+
}
|
|
35
|
+
return messages.slice(-maxHistoryMessages);
|
|
36
|
+
}
|
|
37
|
+
/** `value` when it's a non-empty string, else `undefined` — the shared shape behind `threadId`,
|
|
38
|
+
* `runId`, and `agentId`'s "caller-supplied or minted" resolution below. */
|
|
39
|
+
function resolveNonEmptyString({ value }, _optional = {}) {
|
|
40
|
+
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
41
|
+
}
|
|
42
|
+
/** `RunAgentInput.forwardedProps` has no declared shape of its own (`z.ZodAny` in `@ag-ui/core`) —
|
|
43
|
+
* it's the schema's documented passthrough extension point, and a host's agent-selector value rides
|
|
44
|
+
* there as `forwardedProps.agentId` (there is no top-level `agentId` field on a real
|
|
45
|
+
* `RunAgentInput`; that's a separate, unrelated `AgentConfig`-level concept in `@ag-ui/client`). */
|
|
46
|
+
function resolveForwardedAgentId({ forwardedProps }, _optional = {}) {
|
|
47
|
+
if (typeof forwardedProps !== 'object' || forwardedProps === null)
|
|
48
|
+
return undefined;
|
|
49
|
+
return resolveNonEmptyString({ value: forwardedProps.agentId });
|
|
50
|
+
}
|
|
51
|
+
/** Read only the bounded attachment identity fields, never a surface id or tool handler. The
|
|
52
|
+
* daemon's registry verifies the token against the authenticated principal and originating tab.
|
|
53
|
+
* @complexity O(1) time and space. */
|
|
54
|
+
function resolveForwardedBindingField({ forwardedProps, field }, _optional = {}) {
|
|
55
|
+
if (typeof forwardedProps !== 'object' || forwardedProps === null)
|
|
56
|
+
return undefined;
|
|
57
|
+
const value = forwardedProps[field];
|
|
58
|
+
return typeof value === 'string' && value.length > 0 && value.length <= 256 ? value : undefined;
|
|
59
|
+
}
|
|
60
|
+
/** Only the literal `true` counts: the request carries a boolean signal, never the redacted text. */
|
|
61
|
+
function resolveSecretRedacted({ forwardedProps }, _optional = {}) {
|
|
62
|
+
return typeof forwardedProps === 'object' && forwardedProps !== null
|
|
63
|
+
&& forwardedProps.secretRedacted === true;
|
|
64
|
+
}
|
|
65
|
+
/** Validates and normalizes one AG-UI run request body, or `null` when it fails the one hard
|
|
66
|
+
* requirement: a non-empty `messages` array ending in a user turn. A caller-supplied `threadId` /
|
|
67
|
+
* `runId` is echoed as given (AG-UI expects the caller to own them); an absent or empty one is
|
|
68
|
+
* minted so a well-formed-but-partial request still gets a coherent stream. Ids are minted in the
|
|
69
|
+
* order thread, run, request.
|
|
70
|
+
* @complexity O(h) time and space in the supplied history; attachment fields are constant work. */
|
|
71
|
+
export function resolveAgUiRunInput({ body, maxHistoryMessages, ids }, _optional = {}) {
|
|
72
|
+
const messages = resolveAgUiMessages({ raw: body.messages, maxHistoryMessages });
|
|
73
|
+
if (messages.length === 0 || messages[messages.length - 1]?.role !== 'user')
|
|
74
|
+
return null;
|
|
75
|
+
const { forwardedProps } = body;
|
|
76
|
+
return {
|
|
77
|
+
threadId: resolveNonEmptyString({ value: body.threadId }) ?? ids.newId(),
|
|
78
|
+
runId: resolveNonEmptyString({ value: body.runId }) ?? ids.newId(),
|
|
79
|
+
requestId: ids.newId(),
|
|
80
|
+
agentId: resolveForwardedAgentId({ forwardedProps }),
|
|
81
|
+
frontendBindToken: resolveForwardedBindingField({ forwardedProps, field: 'frontendBindToken' }),
|
|
82
|
+
frontendTabId: resolveForwardedBindingField({ forwardedProps, field: 'frontendTabId' }),
|
|
83
|
+
secretRedacted: resolveSecretRedacted({ forwardedProps }),
|
|
84
|
+
messages,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=run-input.js.map
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* Chat outcomes belong here; generic capability vocabulary belongs to @jini-ai/agentic so
|
|
12
12
|
* non-chat consumers can use it independently of chat.
|
|
13
13
|
*/
|
|
14
|
-
import type { CapabilityDef } from '@jini-ai/
|
|
14
|
+
import type { CapabilityDef } from '@jini-ai/core/contracts/capabilities';
|
|
15
15
|
/** The bounded, explicit set of chat-pane capabilities every transport surface hosts. */
|
|
16
16
|
export declare const CHAT_CAPABILITIES: readonly CapabilityDef[];
|
|
17
17
|
//# sourceMappingURL=chat-capabilities.d.ts.map
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal chat capability barrel, re-exported by chat/core rather than a public ./agentic subpath.
|
|
3
|
-
* CHAT_CAPABILITIES belongs to chat; generic capability vocabulary
|
|
4
|
-
*
|
|
5
|
-
* owner, @jini-ai/agentic.
|
|
3
|
+
* CHAT_CAPABILITIES belongs to chat; the generic capability vocabulary lives in
|
|
4
|
+
* @jini-ai/core/contracts/capabilities.
|
|
6
5
|
*/
|
|
7
6
|
export { CHAT_CAPABILITIES } from './chat-capabilities.js';
|
|
8
|
-
export type { CapabilityDef, CapabilityInputSchema, CapabilityRisk } from '@jini-ai/agentic';
|
|
9
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal chat capability barrel, re-exported by chat/core rather than a public ./agentic subpath.
|
|
3
|
-
* CHAT_CAPABILITIES belongs to chat; generic capability vocabulary
|
|
4
|
-
*
|
|
5
|
-
* owner, @jini-ai/agentic.
|
|
3
|
+
* CHAT_CAPABILITIES belongs to chat; the generic capability vocabulary lives in
|
|
4
|
+
* @jini-ai/core/contracts/capabilities.
|
|
6
5
|
*/
|
|
7
6
|
export { CHAT_CAPABILITIES } from './chat-capabilities.js';
|
|
8
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** @file What chat needs from an agent runtime, as ports the host binds. Chat states the shapes with vocabulary from
|
|
2
|
+
* `@jini-ai/core/contracts/agents`; it does not pick the runtime. */
|
|
3
|
+
import type { AgentServiceFailureCode, ModelIdentityKind, NativeToolPolicyInput, RuntimeModelOption, RuntimeReasoningOption } from '@jini-ai/core/contracts/agents';
|
|
4
|
+
/** Model-selection and native-tool policy are the agent runtime's domain rules; chat receives them (React: through the chat kit's `agents` slot). */
|
|
5
|
+
export interface ChatAgentPolicyPort {
|
|
6
|
+
modelIdentityKind(required: {
|
|
7
|
+
id: string;
|
|
8
|
+
}): ModelIdentityKind;
|
|
9
|
+
concreteModelOptions(required: {
|
|
10
|
+
models?: readonly RuntimeModelOption[];
|
|
11
|
+
supportsConcreteModelSelection?: boolean;
|
|
12
|
+
defaultModelResolution?: {
|
|
13
|
+
status: string;
|
|
14
|
+
id?: string;
|
|
15
|
+
};
|
|
16
|
+
}): RuntimeModelOption[];
|
|
17
|
+
modelReasoningOptions(required: {
|
|
18
|
+
agent: {
|
|
19
|
+
reasoningOptions?: readonly RuntimeReasoningOption[];
|
|
20
|
+
reasoningInModelId?: {
|
|
21
|
+
levels: readonly RuntimeReasoningOption[];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
model?: Pick<RuntimeModelOption, 'reasoning'>;
|
|
25
|
+
}): RuntimeReasoningOption[];
|
|
26
|
+
/** A plain-words refusal to show before sending, or `null` when the policy allows the run. */
|
|
27
|
+
assessNativeToolPolicy(required: {
|
|
28
|
+
def: {
|
|
29
|
+
name: string;
|
|
30
|
+
supportsNativeToolAccess?: boolean;
|
|
31
|
+
fullCliAccessOnly?: boolean;
|
|
32
|
+
};
|
|
33
|
+
policy: NativeToolPolicyInput;
|
|
34
|
+
}): string | null;
|
|
35
|
+
}
|
|
36
|
+
/** Server side: durable-run recovery classifies saved failures. */
|
|
37
|
+
export interface ChatAgentFailurePort {
|
|
38
|
+
/** `null` for an ordinary failure that belongs to no service class. */
|
|
39
|
+
classifyServiceFailure(required: {
|
|
40
|
+
text: string;
|
|
41
|
+
}): AgentServiceFailureCode | null;
|
|
42
|
+
startupFailureMessage(required: {
|
|
43
|
+
stage: string;
|
|
44
|
+
error: unknown;
|
|
45
|
+
}, optional?: {
|
|
46
|
+
exactSecrets?: readonly string[];
|
|
47
|
+
notice?: string;
|
|
48
|
+
}): string;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=agents-port.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type RunAgentInput } from '@ag-ui/core';
|
|
2
|
+
import type { AgUiClient } from './ag-ui-transport.js';
|
|
3
|
+
declare function readAgUiResponse({ request, input, signal, observer }: {
|
|
4
|
+
request: (required: {
|
|
5
|
+
input: RunAgentInput;
|
|
6
|
+
signal: AbortSignal;
|
|
7
|
+
}) => Promise<Response>;
|
|
8
|
+
input: RunAgentInput;
|
|
9
|
+
signal: AbortSignal;
|
|
10
|
+
observer: Parameters<ReturnType<AgUiClient['run']>['subscribe']>[0];
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
export declare function createAgUiFetchAgent({ request }: {
|
|
13
|
+
request: Parameters<typeof readAgUiResponse>[0]['request'];
|
|
14
|
+
}, _optional?: Record<string, never>): AgUiClient;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=ag-ui-fetch-agent.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EventSchemas } from '@ag-ui/core';
|
|
2
|
+
import { readSseFrames } from '../run-events/entry.js';
|
|
3
|
+
async function readAgUiResponse({ request, input, signal, observer }) {
|
|
4
|
+
const response = await request({ input, signal });
|
|
5
|
+
if (!response.body)
|
|
6
|
+
throw new Error('The agent response has no event stream');
|
|
7
|
+
const body = response.body.pipeThrough(new TransformStream(), { signal });
|
|
8
|
+
for await (const frame of readSseFrames({ body })) {
|
|
9
|
+
observer.next(EventSchemas.parse(JSON.parse(frame.data)));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function createAgUiFetchAgent({ request }, _optional = {}) {
|
|
13
|
+
const abortController = new AbortController();
|
|
14
|
+
return {
|
|
15
|
+
abortController,
|
|
16
|
+
abortRun: () => abortController.abort(),
|
|
17
|
+
run: (input) => ({
|
|
18
|
+
subscribe(observer) {
|
|
19
|
+
return readAgUiResponse({ request, input, signal: abortController.signal, observer }).then(() => observer.complete(), (error) => observer.error(error));
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=ag-ui-fetch-agent.js.map
|
|
@@ -9,9 +9,11 @@
|
|
|
9
9
|
* there so an intentional stop cannot become a user-facing failure.
|
|
10
10
|
*/
|
|
11
11
|
import type { RunAgentInput } from "@ag-ui/core";
|
|
12
|
-
import type {
|
|
12
|
+
import type { AgUiToAgentTranslationState } from "../ag-ui/event-reduction.js";
|
|
13
|
+
import type { AgUiEvent, CustomEventNames } from "../ag-ui/event-projection.js";
|
|
13
14
|
import type { AgentEvent } from "../events.js";
|
|
14
15
|
import type { RunHandlers, StartRunInput } from "../transport.js";
|
|
16
|
+
export { createAgUiFetchAgent } from "./ag-ui-fetch-agent.js";
|
|
15
17
|
export interface AgUiClient {
|
|
16
18
|
readonly abortController: AbortController;
|
|
17
19
|
abortRun(): void;
|
|
@@ -24,6 +26,9 @@ export interface AgUiClient {
|
|
|
24
26
|
};
|
|
25
27
|
}
|
|
26
28
|
export interface AgUiClientPorts {
|
|
29
|
+
readonly onLiveEvent?: (required: {
|
|
30
|
+
event: AgUiEvent;
|
|
31
|
+
}) => boolean;
|
|
27
32
|
readonly endpoint: string;
|
|
28
33
|
readonly runIdPrefix: string;
|
|
29
34
|
readonly customEventNames: CustomEventNames;
|
|
@@ -53,6 +58,15 @@ export interface AgUiRunClient {
|
|
|
53
58
|
}, optional?: Record<string, never>): Promise<{
|
|
54
59
|
runId: string;
|
|
55
60
|
}>;
|
|
61
|
+
resumeAgUiRun(required: {
|
|
62
|
+
input: StartRunInput;
|
|
63
|
+
handlers: RunHandlers;
|
|
64
|
+
threadId: string;
|
|
65
|
+
parentRunId: string;
|
|
66
|
+
resume: NonNullable<RunAgentInput["resume"]>;
|
|
67
|
+
}, optional?: Record<string, never>): Promise<{
|
|
68
|
+
runId: string;
|
|
69
|
+
}>;
|
|
56
70
|
reattachAgUiRun(required: {
|
|
57
71
|
handlers: RunHandlers;
|
|
58
72
|
}, optional?: Record<string, never>): Promise<void>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { describeErrorForLog } from '@jini-ai/core/model-facing-tool-errors';
|
|
1
2
|
import { EventType } from "@ag-ui/core";
|
|
2
|
-
import { createAgUiToAgentTranslationState, translateAgUiEventToAgentEvent } from "../ag-ui/
|
|
3
|
+
import { createAgUiToAgentTranslationState, translateAgUiEventToAgentEvent } from "../ag-ui/event-reduction.js";
|
|
4
|
+
export { createAgUiFetchAgent } from "./ag-ui-fetch-agent.js";
|
|
3
5
|
/** Only the originating attachment can authorize page execution. Read its token and tab for every
|
|
4
6
|
* turn; caller-supplied tool definitions never authorize or execute a transcript event.
|
|
5
7
|
* @complexity O(1) time and space.
|
|
@@ -12,159 +14,179 @@ function frontendBinding({ input }, _options = {}) {
|
|
|
12
14
|
...(typeof tabId === "string" && tabId.length > 0 ? { frontendTabId: tabId } : {}),
|
|
13
15
|
};
|
|
14
16
|
}
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* validation entirely, and hands us finished event objects. `RUN_ERROR` with `code: "abort"` is the
|
|
27
|
-
* real package's own convention for a mid-stream abort (see module doc) — routed to `finish()`, not
|
|
28
|
-
* `onError`. Every other event is reduced through {@link translateAgUiEventToAgentEvent} and
|
|
29
|
-
* forwarded to both `collected` (the final transcript `onDone` receives) and `handlers.onEvent`
|
|
30
|
-
* (live rendering).
|
|
31
|
-
*/
|
|
32
|
-
function handleAgUiEvent(event, ctx) {
|
|
33
|
-
if (event.type === EventType.RUN_ERROR) {
|
|
34
|
-
if (event.code === "abort") {
|
|
35
|
-
ctx.finish();
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
ctx.handlers.onError(new Error(event.message || "AG-UI run failed"));
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (event.type === EventType.RUN_FINISHED) {
|
|
17
|
+
/**
|
|
18
|
+
* Dispatches one already-parsed AG-UI event. `HttpAgent` owns SSE framing and per-event zod
|
|
19
|
+
* validation entirely, and hands us finished event objects. `RUN_ERROR` with `code: "abort"` is the
|
|
20
|
+
* real package's own convention for a mid-stream abort (see module doc) — routed to `finish()`, not
|
|
21
|
+
* `onError`. Every other event is reduced through {@link translateAgUiEventToAgentEvent} and
|
|
22
|
+
* forwarded to both `collected` (the final transcript `onDone` receives) and `handlers.onEvent`
|
|
23
|
+
* (live rendering).
|
|
24
|
+
*/
|
|
25
|
+
function handleAgUiEvent({ event, ctx, onLiveEvent }, _optional = {}) {
|
|
26
|
+
if (event.type === EventType.RUN_ERROR) {
|
|
27
|
+
if (event.code === "abort") {
|
|
42
28
|
ctx.finish();
|
|
43
29
|
return;
|
|
44
30
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
ctx.handlers.onEvent(translated);
|
|
48
|
-
}
|
|
31
|
+
ctx.handlers.onError(new Error(event.message || "AG-UI run failed"));
|
|
32
|
+
return;
|
|
49
33
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return { id: message.id, role: "assistant", content: message.content };
|
|
34
|
+
if (event.type === EventType.RUN_FINISHED) {
|
|
35
|
+
onLiveEvent?.({ event });
|
|
36
|
+
ctx.finish();
|
|
37
|
+
return;
|
|
55
38
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
39
|
+
if (onLiveEvent?.({ event }))
|
|
40
|
+
return;
|
|
41
|
+
for (const translated of translateAgUiEventToAgentEvent({ event, state: ctx.state }, {})) {
|
|
42
|
+
ctx.collected.push(translated);
|
|
43
|
+
ctx.handlers.onEvent(translated);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Every AG-UI message role requires an id; preserve ChatMessage.id across translation. */
|
|
47
|
+
function toAgUiMessage({ message }, _optional = {}) {
|
|
48
|
+
if (message.role === "user")
|
|
49
|
+
return { id: message.id, role: "user", content: message.content };
|
|
50
|
+
return { id: message.id, role: "assistant", content: message.content };
|
|
51
|
+
}
|
|
52
|
+
/** The request body of one turn. The daemon owns tool registrations, so `tools` stays empty; blank
|
|
53
|
+
* messages are left out because they carry nothing to answer. */
|
|
54
|
+
function toRunAgentInput({ input, runId, threadId }, _optional = {}) {
|
|
55
|
+
return {
|
|
56
|
+
threadId,
|
|
57
|
+
runId,
|
|
58
|
+
state: null,
|
|
59
|
+
messages: input.history.filter((message) => message.content.trim().length > 0).map((message) => toAgUiMessage({ message })),
|
|
60
|
+
tools: [],
|
|
61
|
+
context: [],
|
|
62
|
+
forwardedProps: {
|
|
63
|
+
...frontendBinding({ input }),
|
|
64
|
+
...(input.agentId ? { agentId: input.agentId } : {}),
|
|
65
|
+
...(input.history.findLast(message => message.role === "user")?.secretRedaction?.secretRedacted ? { secretRedacted: true } : {}),
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** Drops the turn's two handles: its registry entry (so `stopAgUiRun` cannot reach a dead agent) and
|
|
70
|
+
* its listener on the host signal. Safe to repeat. */
|
|
71
|
+
function forgetRun({ turn }, _optional = {}) {
|
|
72
|
+
turn.agents.delete(turn.runId);
|
|
73
|
+
turn.signal.removeEventListener("abort", turn.abort);
|
|
74
|
+
}
|
|
75
|
+
/** The one place a turn is finished: `onDone` receives the collected events exactly once, however
|
|
76
|
+
* many of RUN_FINISHED, an abort, a stream error and `complete` arrive. */
|
|
77
|
+
function settleRunOnce({ turn }, _optional = {}) {
|
|
78
|
+
if (turn.settled)
|
|
79
|
+
return;
|
|
80
|
+
turn.settled = true;
|
|
81
|
+
forgetRun({ turn });
|
|
82
|
+
turn.handlers.onDone(turn.collected);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Deliberately racing the Observable's first `next`/`error`/`complete` against this Promise rather than
|
|
86
|
+
* awaiting it directly — `HttpAgent.run()` returns a cold Observable, never a Promise (module
|
|
87
|
+
* doc). The subscription itself keeps running after this Promise settles, driving `handlers`
|
|
88
|
+
* through to `settleRunOnce` in the background — matching `startByokRun`'s "resolves once STARTED, not
|
|
89
|
+
* once finished" contract.
|
|
90
|
+
*/
|
|
91
|
+
function subscribeRun({ turn, runAgentInput, state, ports }, _optional = {}) {
|
|
92
|
+
const finish = () => settleRunOnce({ turn });
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
let startSettled = false;
|
|
95
|
+
turn.agent.run(runAgentInput).subscribe({
|
|
96
|
+
next: (event) => {
|
|
97
|
+
if (!startSettled) {
|
|
98
|
+
startSettled = true;
|
|
99
|
+
resolve({ runId: turn.runId });
|
|
100
|
+
}
|
|
101
|
+
handleAgUiEvent({ event: event, onLiveEvent: ports.onLiveEvent, ctx: { collected: turn.collected, handlers: turn.handlers, state, finish } });
|
|
86
102
|
},
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const state = createAgUiToAgentTranslationState({ customEventNames: ports.customEventNames }, {});
|
|
99
|
-
// Deliberately racing the Observable's first `next`/`error`/`complete` against this Promise rather than
|
|
100
|
-
// awaiting it directly — `HttpAgent.run()` returns a cold Observable, never a Promise (module
|
|
101
|
-
// doc). The subscription itself keeps running after this Promise settles, driving `handlers`
|
|
102
|
-
// through to `finish()` in the background — matching `startByokRun`'s "resolves once STARTED, not
|
|
103
|
-
// once finished" contract.
|
|
104
|
-
return new Promise((resolve, reject) => {
|
|
105
|
-
let startSettled = false;
|
|
106
|
-
agent.run(runAgentInput).subscribe({
|
|
107
|
-
next: (event) => {
|
|
108
|
-
if (!startSettled) {
|
|
109
|
-
startSettled = true;
|
|
110
|
-
resolve({ runId });
|
|
111
|
-
}
|
|
112
|
-
handleAgUiEvent(event, { collected, handlers, state, finish });
|
|
113
|
-
},
|
|
114
|
-
error: (error) => {
|
|
115
|
-
agUiAgents.delete(runId);
|
|
116
|
-
input.signal.removeEventListener("abort", abort);
|
|
117
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
118
|
-
if (!startSettled) {
|
|
119
|
-
startSettled = true;
|
|
120
|
-
reject(err);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
// Aborting BEFORE headers arrive rejects the underlying fetch() itself, surfacing here
|
|
124
|
-
// rather than through `handleAgUiEvent`'s `code: "abort"` check (module doc).
|
|
125
|
-
if (agent.abortController.signal.aborted) {
|
|
126
|
-
finish();
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
// Error THEN finish: an errored Observable never calls `complete`, so without this the turn
|
|
130
|
-
// is never settled and the events collected before the failure never reach `onDone`. Same
|
|
131
|
-
// order as `subscribeToRun`'s `end` listener, so the run is still recorded as failed.
|
|
132
|
-
handlers.onError(err);
|
|
133
|
-
finish();
|
|
134
|
-
},
|
|
135
|
-
complete: () => {
|
|
136
|
-
// An empty stream has no first notification to settle the start promise.
|
|
137
|
-
if (!startSettled) {
|
|
138
|
-
startSettled = true;
|
|
139
|
-
resolve({ runId });
|
|
140
|
-
}
|
|
103
|
+
error: (error) => {
|
|
104
|
+
forgetRun({ turn });
|
|
105
|
+
const err = runStreamError({ error });
|
|
106
|
+
if (!startSettled) {
|
|
107
|
+
startSettled = true;
|
|
108
|
+
reject(err);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
// Aborting BEFORE headers arrive rejects the underlying fetch() itself, surfacing here
|
|
112
|
+
// rather than through `handleAgUiEvent`'s `code: "abort"` check (module doc).
|
|
113
|
+
if (turn.agent.abortController.signal.aborted) {
|
|
141
114
|
finish();
|
|
142
|
-
|
|
143
|
-
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
// Error THEN finish: an errored Observable never calls `complete`, so without this the turn
|
|
118
|
+
// is never settled and the events collected before the failure never reach `onDone`. Same
|
|
119
|
+
// order as `subscribeToRun`'s `end` listener, so the run is still recorded as failed.
|
|
120
|
+
turn.handlers.onError(err);
|
|
121
|
+
finish();
|
|
122
|
+
},
|
|
123
|
+
complete: () => {
|
|
124
|
+
// An empty stream has no first notification to settle the start promise.
|
|
125
|
+
if (!startSettled) {
|
|
126
|
+
startSettled = true;
|
|
127
|
+
resolve({ runId: turn.runId });
|
|
128
|
+
}
|
|
129
|
+
finish();
|
|
130
|
+
},
|
|
144
131
|
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function runStreamError({ error }, _optional = {}) {
|
|
135
|
+
const status = error instanceof Error && "status" in error && typeof error.status === "number" ? `HTTP ${error.status}, ` : "";
|
|
136
|
+
return new Error(`The agent run stream stopped with an error (${status}${describeErrorForLog({ err: error })}); send the message again.`, { cause: error });
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The AG-UI canary run path (ADR-059) — drives a real `@ag-ui/client` `HttpAgent` against
|
|
140
|
+
* `assistant-ag-ui.ts`'s route, same one-turn-per-call shape as `startByokRun`. `credentials:
|
|
141
|
+
* "same-origin"` is explicit even though modern `fetch()` already defaults to it for same-origin
|
|
142
|
+
* requests, matching this transport's other paths' explicitness about the session cookie.
|
|
143
|
+
*/
|
|
144
|
+
async function startRun({ ports, agents, input, handlers, resume }, _optional = {}) {
|
|
145
|
+
const runId = `${ports.runIdPrefix}${ports.mintId({}, {})}`;
|
|
146
|
+
// The conversation-level id, stable across turns — a genuine AG-UI `threadId`, distinct from the
|
|
147
|
+
// per-turn `runId` minted fresh above. Falls back to minting one only for a conversation that has
|
|
148
|
+
// none yet (e.g. the very first turn).
|
|
149
|
+
const threadId = resume?.threadId ?? input.conversationId ?? ports.mintId({}, {});
|
|
150
|
+
const agent = ports.createAgent({ url: ports.endpoint, threadId }, {});
|
|
151
|
+
if (input.signal.aborted)
|
|
152
|
+
throw new DOMException("Run cancelled", "AbortError");
|
|
153
|
+
agents.set(runId, agent);
|
|
154
|
+
const abort = () => agent.abortRun();
|
|
155
|
+
input.signal.addEventListener("abort", abort, { once: true });
|
|
156
|
+
const turn = { runId, agent, signal: input.signal, abort, handlers, collected: [], agents, settled: false };
|
|
157
|
+
const state = createAgUiToAgentTranslationState({ customEventNames: ports.customEventNames }, {});
|
|
158
|
+
return subscribeRun({ turn, runAgentInput: { ...toRunAgentInput({ input, runId, threadId }),
|
|
159
|
+
...(resume ? { parentRunId: resume.parentRunId, resume: resume.resume } : {}) }, state, ports });
|
|
160
|
+
}
|
|
161
|
+
/** No server-side run record exists on this path (module doc) — a reload has already discarded the
|
|
162
|
+
* original `fetch()`'s response body, so there is nothing to resume. Same honest "already over"
|
|
163
|
+
* answer `assistant-transport.ts`'s BYOK branch gives for the identical situation. */
|
|
164
|
+
async function reattachAgUiRun({ handlers }, _optional = {}) {
|
|
165
|
+
handlers.onDone([]);
|
|
166
|
+
}
|
|
167
|
+
/** Same reasoning as {@link reattachAgUiRun} — no server-side run record to fetch status for. */
|
|
168
|
+
async function fetchAgUiRunStatus(_required, _optional = {}) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
/** Bind the official client without adding its dependency to every chat consumer. */
|
|
172
|
+
export function createAgUiRunClient({ ports }, _options = {}) {
|
|
173
|
+
/** In-flight AG-UI turns' driving `HttpAgent`, keyed by the client-minted runId — the ONLY way
|
|
174
|
+
* `stopAgUiRun` can cancel a turn: like BYOK, there is no server-side run record on THIS
|
|
175
|
+
* path to `POST .../cancel` against. Storing the agent (not a bare `AbortController`) lets
|
|
176
|
+
* `stopAgUiRun` call its own `abortRun()`, which both aborts the fetch AND (per the package's own
|
|
177
|
+
* convention) surfaces a clean `RUN_ERROR{code:"abort"}` through the normal event path rather than
|
|
178
|
+
* a raw network error. */
|
|
179
|
+
const agents = new Map();
|
|
161
180
|
return {
|
|
162
|
-
isAgUiRunId: ({ runId },
|
|
163
|
-
handleAgUiEvent: ({ event, ctx },
|
|
164
|
-
startAgUiRun: ({ input, handlers },
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
181
|
+
isAgUiRunId: ({ runId }, _optional = {}) => runId.startsWith(ports.runIdPrefix),
|
|
182
|
+
handleAgUiEvent: ({ event, ctx }, _optional = {}) => handleAgUiEvent({ event, ctx, onLiveEvent: ports.onLiveEvent }),
|
|
183
|
+
startAgUiRun: ({ input, handlers }, _optional = {}) => startRun({ ports, agents, input, handlers }),
|
|
184
|
+
resumeAgUiRun: ({ input, handlers, threadId, parentRunId, resume }, _optional = {}) => startRun({ ports, agents, input, handlers, resume: { threadId, parentRunId, resume } }),
|
|
185
|
+
reattachAgUiRun,
|
|
186
|
+
fetchAgUiRunStatus,
|
|
187
|
+
/** An AG-UI run's only cancellation handle is the `HttpAgent` {@link startRun} registered for
|
|
188
|
+
* this exact id — same shape as BYOK's `stopRun` branch. */
|
|
189
|
+
stopAgUiRun: async ({ runId }, _optional = {}) => { agents.get(runId)?.abortRun(); },
|
|
168
190
|
};
|
|
169
191
|
}
|
|
170
192
|
//# sourceMappingURL=ag-ui-transport.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { orFallback } from "@jini-ai/core/errors/idioms";
|
|
1
2
|
/**
|
|
2
3
|
* @file Restore cached attachment references only after the host confirms their bytes still exist.
|
|
3
4
|
* Drafts persist references separately from text; staged bytes have a host-defined TTL. Dropping
|
|
@@ -23,19 +24,20 @@ const DEFAULT_TIMEOUT_MS = 10_000;
|
|
|
23
24
|
* @complexity O(1); one request, abandoned after `timeoutMs`.
|
|
24
25
|
*/
|
|
25
26
|
async function isAttachmentStillServed(ref, options) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
return orFallback({
|
|
28
|
+
work: async () => {
|
|
29
|
+
const response = await options.fetchImpl(options.endpoint({ ref }, {}), {
|
|
30
|
+
method: "HEAD",
|
|
31
|
+
credentials: "same-origin",
|
|
32
|
+
signal: AbortSignal.timeout(options.timeoutMs),
|
|
33
|
+
});
|
|
34
|
+
return response.ok;
|
|
35
|
+
},
|
|
35
36
|
// A network fault, an abort, or a same-origin policy refusal. Indistinguishable from here, and
|
|
36
37
|
// all mean the same thing: nothing was confirmed, so the reference does not come back.
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
fallback: false,
|
|
39
|
+
step: "probe saved attachment",
|
|
40
|
+
});
|
|
39
41
|
}
|
|
40
42
|
/**
|
|
41
43
|
* Runs `probe` over `refs` with at most `concurrency` in flight, answering positionally.
|