@assistant-ui/core 0.3.7 → 0.3.9
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/LICENSE +21 -0
- package/dist/react/runtimes/cloud/auiV0.d.ts +1 -0
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js +2 -1
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.d.ts +0 -2
- package/dist/runtime/base/default-edit-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.js +18 -25
- package/dist/runtime/base/default-edit-composer-runtime-core.js.map +1 -1
- package/dist/runtime/utils/thread-message-like.js +3 -1
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/types/message.d.ts +1 -0
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js.map +1 -1
- package/package.json +15 -15
- package/src/react/runtimes/cloud/auiV0.ts +8 -1
- package/src/runtime/base/default-edit-composer-runtime-core.ts +32 -50
- package/src/runtime/utils/thread-message-like.ts +5 -1
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +5 -1
- package/src/store/runtime-clients/lookup-domains.test.ts +109 -0
- package/src/tests/auiV0Encode.test.ts +97 -0
- package/src/tests/default-edit-composer-runtime-core.test.ts +6 -2
- package/src/tests/external-store-thread-runtime-core.test.ts +36 -0
- package/src/tests/thread-message-like.test.ts +43 -0
- package/src/types/message.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","names":["ReadonlyJSONObject","ReadonlyJSONValue","ToolCallTiming","ToolModelContentPart","CompleteAttachment","PartProviderMetadata","providerName","TextMessagePart","type","text","status","MessagePartStreamStatus","providerMetadata","parentId","ReasoningMessagePart","SourceProviderMetadata","SourceMessagePart","sourceType","id","url","title","mediaType","filename","ImageMessagePart","image","FileMessagePart","data","mimeType","Unstable_AudioMessagePart","audio","format","DataMessagePart","name","T","GenerativeUINode","component","props","Record","children","key","GenerativeUISpec","root","GenerativeUIMessagePart","spec","McpAppMetadata","resourceUri","visibility","serverId","MCP_APP_URI_SCHEME","isMcpAppUri","uri","startsWith","ToolCallMessagePartMcpMetadata","app","ToolApprovalOptionKind","ToolApprovalOption","kind","label","description","grants","confirm","ToolApprovalResponse","approved","reason","optionId","ToolCallMessagePart","toolCallId","toolName","args","TArgs","result","TResult","isError","argsText","artifact","timing","mcp","modelContent","interrupt","payload","approval","isAutomatic","options","resolution","messages","ThreadMessage","ThreadUserMessagePart","ThreadAssistantMessagePart","MessagePartStatus","error","ToolCallMessagePartStatus","MessageStatus","MessageTiming","streamStartTime","firstTokenTime","totalStreamTime","tokenCount","tokensPerSecond","totalChunks","toolCallCount","ThreadStep","messageId","usage","inputTokens","outputTokens","MessageCommonProps","createdAt","Date","ThreadSystemMessage","role","content","metadata","unstable_state","unstable_annotations","unstable_data","steps","submittedFeedback","custom","ThreadUserMessage","attachments","isOptimistic","ThreadAssistantMessage","BaseThreadMessage","MessageRole","RunConfig","AppendMessage","Omit","sourceId","runConfig","startRun","steer"],"sources":["../../src/types/message.ts"],"sourcesContent":["import type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ToolCallTiming, ToolModelContentPart } from \"assistant-stream\";\nimport type { CompleteAttachment } from \"./attachment\";\n\nexport type { ToolCallTiming, ToolModelContentPart };\n\nexport type PartProviderMetadata = {\n readonly [providerName: string]: ReadonlyJSONObject;\n};\n\nexport type TextMessagePart = {\n readonly type: \"text\";\n readonly text: string;\n readonly status?: MessagePartStreamStatus;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type ReasoningMessagePart = {\n readonly type: \"reasoning\";\n readonly text: string;\n readonly status?: MessagePartStreamStatus;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type SourceProviderMetadata = PartProviderMetadata;\n\nexport type SourceMessagePart =\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"document\";\n readonly id: string;\n readonly url?: undefined;\n readonly title: string;\n readonly mediaType: string;\n readonly filename?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n };\n\nexport type ImageMessagePart = {\n readonly type: \"image\";\n readonly image: string;\n readonly filename?: string;\n};\n\nexport type FileMessagePart = {\n readonly type: \"file\";\n readonly filename?: string;\n readonly data: string;\n readonly mimeType: string;\n /** How `data` goes on the wire: a url or id reference; omitted = inferred (http(s) → url, else base64). \"url\" is honored by the LangChain-family, A2A, AG-UI, and Google ADK runtimes; \"id\" by the LangChain family only. */\n readonly sourceType?: \"url\" | \"id\";\n readonly parentId?: string;\n};\n\n/**\n * @deprecated Use {@link FileMessagePart} with an `audio/*` mime type. `file`\n * is the carrier for every non-image binary modality: it is a member of both\n * the user and assistant unions, carries a filename, and can declare how its\n * payload goes on the wire, none of which this shape can express. The payload\n * form a `file` part needs is still adapter specific; see the Part Types\n * section of the message primitive docs. Honored everywhere it is accepted; it\n * will not gain fields.\n */\nexport type Unstable_AudioMessagePart = {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n};\n\nexport type DataMessagePart<T = any> = {\n readonly type: \"data\";\n readonly name: string;\n readonly data: T;\n};\n\n/**\n * A JSON spec describing a tree of UI components to render.\n *\n * The agent emits a {@link GenerativeUIMessagePart} containing this spec, and\n * the consumer-provided component allowlist is used to resolve `component`\n * names. Any component referenced that is not present in the allowlist is\n * rejected with a typed error — the allowlist is the security boundary in the\n * default same-realm rendering path.\n */\nexport type GenerativeUINode =\n | string\n | {\n /** Allowlisted component name (resolved against the consumer registry). */\n readonly component: string;\n /** Props passed to the resolved component (must be JSON-serializable). */\n readonly props?: Record<string, unknown>;\n /** Optional children — strings render as text, objects recurse. */\n readonly children?: readonly GenerativeUINode[];\n /** Optional stable key for React reconciliation. */\n readonly key?: string;\n };\n\n/**\n * The root spec for a generative UI tree.\n */\nexport type GenerativeUISpec = {\n /** Root node(s) to render. */\n readonly root: GenerativeUINode | readonly GenerativeUINode[];\n};\n\n/**\n * A message part that carries a JSON spec describing UI to render.\n *\n * Render with `<MessagePrimitive.GenerativeUI components={...} />`. The\n * primitive resolves component names against the consumer-provided allowlist\n * — any unknown name throws a typed error rather than rendering. Stream-\n * friendly: a partially-streamed spec renders progressively.\n */\nexport type GenerativeUIMessagePart = {\n readonly type: \"generative-ui\";\n /** The JSON spec describing the UI tree. */\n readonly spec: GenerativeUISpec;\n /** Optional id (useful for replays / stable keys). */\n readonly id?: string;\n readonly parentId?: string;\n};\n\nexport type McpAppMetadata = {\n readonly resourceUri: string;\n readonly mimeType?: string;\n readonly visibility?: readonly (\"model\" | \"app\")[];\n /** Routable server identity emitted by the agent stack when multiple MCP servers back one agent; for @ag-ui/mcp-apps-middleware this is the configured serverId, falling back to its serverHash. */\n readonly serverId?: string;\n};\n\nexport const MCP_APP_URI_SCHEME = \"ui://\";\n\nexport const isMcpAppUri = (uri: string | undefined): boolean =>\n !!uri?.startsWith(MCP_APP_URI_SCHEME);\n\nexport type ToolCallMessagePartMcpMetadata = {\n readonly app?: McpAppMetadata;\n};\n\nexport type ToolApprovalOptionKind =\n | \"allow-once\"\n | \"allow-always\"\n | \"reject-once\"\n | \"reject-always\";\n\nexport type ToolApprovalOption = {\n /** Opaque, host-defined identifier. Scope semantics (session vs project vs global) belong to the option supplier. */\n readonly id: string;\n /**\n * Decision class. Drives approved-resolution and default rendering.\n * Open union: `_`-prefixed custom kinds are never auto-resolved and the\n * default kit skips them; they must be answered with an explicit\n * `approved` value (optionally alongside the `optionId`).\n */\n readonly kind: ToolApprovalOptionKind | (string & {});\n /** Human label. Renderers supply defaults per kind when omitted. */\n readonly label?: string;\n readonly description?: string;\n /** Patterns or rules this option would persist, shown before the user commits. Supplied by the host; never derived by the library. */\n readonly grants?: readonly string[];\n /** Opt-in confirmation step before this option resolves. */\n readonly confirm?: boolean | { title?: string; description?: string };\n};\n\nexport type ToolApprovalResponse =\n | { readonly approved: boolean; readonly reason?: string }\n | { readonly optionId: string; readonly reason?: string }\n | {\n readonly approved: boolean;\n readonly optionId: string;\n readonly reason?: string;\n };\n\nexport type ToolCallMessagePart<\n TArgs = ReadonlyJSONObject,\n TResult = unknown,\n> = {\n /** Identifies this part as a tool call. */\n readonly type: \"tool-call\";\n /** Stable identifier for this invocation of the tool. */\n readonly toolCallId: string;\n /** Name of the tool requested by the model. */\n readonly toolName: string;\n /**\n * Arguments supplied by the model. During streaming this is a partial parse:\n * fields may be missing or incomplete. From a tool-call renderer, use\n * `useToolArgsStatus` to detect which fields are still arriving.\n */\n readonly args: TArgs;\n /** Result returned by the tool, if it has completed. */\n readonly result?: TResult | undefined;\n /** Whether the result represents a tool execution error. */\n readonly isError?: boolean | undefined;\n /** Raw JSON argument text streamed by the model. */\n readonly argsText: string;\n /** UI-only artifact associated with the tool result. */\n readonly artifact?: unknown;\n /** Wall-clock timing for this call, when the runtime or host tracks it. */\n readonly timing?: ToolCallTiming;\n /** MCP app metadata associated with this tool call, when present. */\n readonly mcp?: ToolCallMessagePartMcpMetadata;\n /** Provider metadata associated with this tool call, when present. */\n readonly providerMetadata?: PartProviderMetadata;\n /** Content returned to the model for this tool result. */\n readonly modelContent?: readonly ToolModelContentPart[] | undefined;\n /** Human-input request that must be resolved before the run can continue. */\n readonly interrupt?: { type: \"human\"; payload: unknown };\n /** Server-side approval gate. `respondToApproval` may only be called while `approved` is undefined and no `resolution` is recorded. */\n readonly approval?: {\n readonly id: string;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n /** Available decisions for this call. Absent: a plain allow / deny pair. */\n readonly options?: readonly ToolApprovalOption[];\n /** The option chosen at resolution, when options were present. */\n readonly optionId?: string;\n /** Terminal non-decision state: the request was cancelled or expired without a user decision. Set by the host. */\n readonly resolution?: \"cancelled\" | \"expired\";\n };\n /** Parent message-part ID when this part belongs to a nested structure. */\n readonly parentId?: string;\n /**\n * Nested thread messages produced by this tool call, for example a sub-agent\n * conversation.\n */\n readonly messages?: readonly ThreadMessage[];\n};\n\nexport type ThreadUserMessagePart =\n | TextMessagePart\n | ImageMessagePart\n | FileMessagePart\n | DataMessagePart\n | Unstable_AudioMessagePart;\n\nexport type ThreadAssistantMessagePart =\n | TextMessagePart\n | ReasoningMessagePart\n | ToolCallMessagePart\n | SourceMessagePart\n | FileMessagePart\n | ImageMessagePart\n | DataMessagePart\n | GenerativeUIMessagePart;\n\nexport type MessagePartStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type MessagePartStreamStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n };\n\nexport type ToolCallMessagePartStatus =\n | {\n /** The tool call is waiting for UI or human input before continuing. */\n readonly type: \"requires-action\";\n /** Reason the tool call requires action. */\n readonly reason: \"interrupt\";\n }\n | MessagePartStatus;\n\nexport type MessageStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\" | \"interrupt\";\n }\n | {\n readonly type: \"complete\";\n readonly reason: \"stop\" | \"unknown\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"tool-calls\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: ReadonlyJSONValue;\n };\n\nexport type MessageTiming = {\n readonly streamStartTime: number;\n readonly firstTokenTime?: number;\n readonly totalStreamTime?: number;\n readonly tokenCount?: number;\n readonly tokensPerSecond?: number;\n readonly totalChunks: number;\n readonly toolCallCount: number;\n};\n\nexport type ThreadStep = {\n readonly messageId?: string;\n readonly usage?:\n | {\n readonly inputTokens: number;\n readonly outputTokens: number;\n }\n | undefined;\n};\n\ntype MessageCommonProps = {\n readonly id: string;\n readonly createdAt: Date;\n};\n\nexport type ThreadSystemMessage = MessageCommonProps & {\n readonly role: \"system\";\n readonly content: readonly [TextMessagePart];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadUserMessage = MessageCommonProps & {\n readonly role: \"user\";\n readonly content: readonly ThreadUserMessagePart[];\n readonly attachments: readonly CompleteAttachment[];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadAssistantMessage = MessageCommonProps & {\n readonly role: \"assistant\";\n readonly content: readonly ThreadAssistantMessagePart[];\n readonly status: MessageStatus;\n readonly metadata: {\n readonly unstable_state: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n /**\n * Marks a client-side optimistic placeholder. Such messages are evicted\n * once off the head branch and are never persisted.\n */\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n};\n\ntype BaseThreadMessage = {\n readonly status?: ThreadAssistantMessage[\"status\"];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations?: readonly ReadonlyJSONValue[];\n readonly unstable_data?: readonly ReadonlyJSONValue[];\n readonly steps?: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n readonly attachments?: ThreadUserMessage[\"attachments\"];\n};\n\nexport type ThreadMessage = BaseThreadMessage &\n (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);\n\nexport type MessageRole = ThreadMessage[\"role\"];\n\nexport type RunConfig = {\n readonly custom?: Record<string, unknown>;\n};\n\nexport type AppendMessage = Omit<ThreadMessage, \"id\"> & {\n parentId: string | null;\n\n /** The ID of the message that was edited or undefined. */\n sourceId: string | null;\n runConfig: RunConfig | undefined;\n startRun?: boolean | undefined;\n /** Process this message next; only meaningful for queue-capable runtimes. */\n steer?: boolean | undefined;\n};\n"],"mappings":";AAmJA,MAAagD,qBAAqB;AAElC,MAAaC,eAAeC,QAC1B,CAAC,CAACA,KAAKC,WAAWH,kBAAkB"}
|
|
1
|
+
{"version":3,"file":"message.js","names":["ReadonlyJSONObject","ReadonlyJSONValue","ToolCallTiming","ToolModelContentPart","CompleteAttachment","PartProviderMetadata","providerName","TextMessagePart","type","text","status","MessagePartStreamStatus","providerMetadata","parentId","ReasoningMessagePart","unstable_summary","SourceProviderMetadata","SourceMessagePart","sourceType","id","url","title","mediaType","filename","ImageMessagePart","image","FileMessagePart","data","mimeType","Unstable_AudioMessagePart","audio","format","DataMessagePart","name","T","GenerativeUINode","component","props","Record","children","key","GenerativeUISpec","root","GenerativeUIMessagePart","spec","McpAppMetadata","resourceUri","visibility","serverId","MCP_APP_URI_SCHEME","isMcpAppUri","uri","startsWith","ToolCallMessagePartMcpMetadata","app","ToolApprovalOptionKind","ToolApprovalOption","kind","label","description","grants","confirm","ToolApprovalResponse","approved","reason","optionId","ToolCallMessagePart","toolCallId","toolName","args","TArgs","result","TResult","isError","argsText","artifact","timing","mcp","modelContent","interrupt","payload","approval","isAutomatic","options","resolution","messages","ThreadMessage","ThreadUserMessagePart","ThreadAssistantMessagePart","MessagePartStatus","error","ToolCallMessagePartStatus","MessageStatus","MessageTiming","streamStartTime","firstTokenTime","totalStreamTime","tokenCount","tokensPerSecond","totalChunks","toolCallCount","ThreadStep","messageId","usage","inputTokens","outputTokens","MessageCommonProps","createdAt","Date","ThreadSystemMessage","role","content","metadata","unstable_state","unstable_annotations","unstable_data","steps","submittedFeedback","custom","ThreadUserMessage","attachments","isOptimistic","ThreadAssistantMessage","BaseThreadMessage","MessageRole","RunConfig","AppendMessage","Omit","sourceId","runConfig","startRun","steer"],"sources":["../../src/types/message.ts"],"sourcesContent":["import type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ToolCallTiming, ToolModelContentPart } from \"assistant-stream\";\nimport type { CompleteAttachment } from \"./attachment\";\n\nexport type { ToolCallTiming, ToolModelContentPart };\n\nexport type PartProviderMetadata = {\n readonly [providerName: string]: ReadonlyJSONObject;\n};\n\nexport type TextMessagePart = {\n readonly type: \"text\";\n readonly text: string;\n readonly status?: MessagePartStreamStatus;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type ReasoningMessagePart = {\n readonly type: \"reasoning\";\n readonly text: string;\n readonly status?: MessagePartStreamStatus;\n readonly unstable_summary?: string;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type SourceProviderMetadata = PartProviderMetadata;\n\nexport type SourceMessagePart =\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"document\";\n readonly id: string;\n readonly url?: undefined;\n readonly title: string;\n readonly mediaType: string;\n readonly filename?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n };\n\nexport type ImageMessagePart = {\n readonly type: \"image\";\n readonly image: string;\n readonly filename?: string;\n};\n\nexport type FileMessagePart = {\n readonly type: \"file\";\n readonly filename?: string;\n readonly data: string;\n readonly mimeType: string;\n /** How `data` goes on the wire: a url or id reference; omitted = inferred (http(s) → url, else base64). \"url\" is honored by the LangChain-family, A2A, AG-UI, and Google ADK runtimes; \"id\" by the LangChain family only. */\n readonly sourceType?: \"url\" | \"id\";\n readonly parentId?: string;\n};\n\n/**\n * @deprecated Use {@link FileMessagePart} with an `audio/*` mime type. `file`\n * is the carrier for every non-image binary modality: it is a member of both\n * the user and assistant unions, carries a filename, and can declare how its\n * payload goes on the wire, none of which this shape can express. The payload\n * form a `file` part needs is still adapter specific; see the Part Types\n * section of the message primitive docs. Honored everywhere it is accepted; it\n * will not gain fields.\n */\nexport type Unstable_AudioMessagePart = {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n};\n\nexport type DataMessagePart<T = any> = {\n readonly type: \"data\";\n readonly name: string;\n readonly data: T;\n};\n\n/**\n * A JSON spec describing a tree of UI components to render.\n *\n * The agent emits a {@link GenerativeUIMessagePart} containing this spec, and\n * the consumer-provided component allowlist is used to resolve `component`\n * names. Any component referenced that is not present in the allowlist is\n * rejected with a typed error — the allowlist is the security boundary in the\n * default same-realm rendering path.\n */\nexport type GenerativeUINode =\n | string\n | {\n /** Allowlisted component name (resolved against the consumer registry). */\n readonly component: string;\n /** Props passed to the resolved component (must be JSON-serializable). */\n readonly props?: Record<string, unknown>;\n /** Optional children — strings render as text, objects recurse. */\n readonly children?: readonly GenerativeUINode[];\n /** Optional stable key for React reconciliation. */\n readonly key?: string;\n };\n\n/**\n * The root spec for a generative UI tree.\n */\nexport type GenerativeUISpec = {\n /** Root node(s) to render. */\n readonly root: GenerativeUINode | readonly GenerativeUINode[];\n};\n\n/**\n * A message part that carries a JSON spec describing UI to render.\n *\n * Render with `<MessagePrimitive.GenerativeUI components={...} />`. The\n * primitive resolves component names against the consumer-provided allowlist\n * — any unknown name throws a typed error rather than rendering. Stream-\n * friendly: a partially-streamed spec renders progressively.\n */\nexport type GenerativeUIMessagePart = {\n readonly type: \"generative-ui\";\n /** The JSON spec describing the UI tree. */\n readonly spec: GenerativeUISpec;\n /** Optional id (useful for replays / stable keys). */\n readonly id?: string;\n readonly parentId?: string;\n};\n\nexport type McpAppMetadata = {\n readonly resourceUri: string;\n readonly mimeType?: string;\n readonly visibility?: readonly (\"model\" | \"app\")[];\n /** Routable server identity emitted by the agent stack when multiple MCP servers back one agent; for @ag-ui/mcp-apps-middleware this is the configured serverId, falling back to its serverHash. */\n readonly serverId?: string;\n};\n\nexport const MCP_APP_URI_SCHEME = \"ui://\";\n\nexport const isMcpAppUri = (uri: string | undefined): boolean =>\n !!uri?.startsWith(MCP_APP_URI_SCHEME);\n\nexport type ToolCallMessagePartMcpMetadata = {\n readonly app?: McpAppMetadata;\n};\n\nexport type ToolApprovalOptionKind =\n | \"allow-once\"\n | \"allow-always\"\n | \"reject-once\"\n | \"reject-always\";\n\nexport type ToolApprovalOption = {\n /** Opaque, host-defined identifier. Scope semantics (session vs project vs global) belong to the option supplier. */\n readonly id: string;\n /**\n * Decision class. Drives approved-resolution and default rendering.\n * Open union: `_`-prefixed custom kinds are never auto-resolved and the\n * default kit skips them; they must be answered with an explicit\n * `approved` value (optionally alongside the `optionId`).\n */\n readonly kind: ToolApprovalOptionKind | (string & {});\n /** Human label. Renderers supply defaults per kind when omitted. */\n readonly label?: string;\n readonly description?: string;\n /** Patterns or rules this option would persist, shown before the user commits. Supplied by the host; never derived by the library. */\n readonly grants?: readonly string[];\n /** Opt-in confirmation step before this option resolves. */\n readonly confirm?: boolean | { title?: string; description?: string };\n};\n\nexport type ToolApprovalResponse =\n | { readonly approved: boolean; readonly reason?: string }\n | { readonly optionId: string; readonly reason?: string }\n | {\n readonly approved: boolean;\n readonly optionId: string;\n readonly reason?: string;\n };\n\nexport type ToolCallMessagePart<\n TArgs = ReadonlyJSONObject,\n TResult = unknown,\n> = {\n /** Identifies this part as a tool call. */\n readonly type: \"tool-call\";\n /** Stable identifier for this invocation of the tool. */\n readonly toolCallId: string;\n /** Name of the tool requested by the model. */\n readonly toolName: string;\n /**\n * Arguments supplied by the model. During streaming this is a partial parse:\n * fields may be missing or incomplete. From a tool-call renderer, use\n * `useToolArgsStatus` to detect which fields are still arriving.\n */\n readonly args: TArgs;\n /** Result returned by the tool, if it has completed. */\n readonly result?: TResult | undefined;\n /** Whether the result represents a tool execution error. */\n readonly isError?: boolean | undefined;\n /** Raw JSON argument text streamed by the model. */\n readonly argsText: string;\n /** UI-only artifact associated with the tool result. */\n readonly artifact?: unknown;\n /** Wall-clock timing for this call, when the runtime or host tracks it. */\n readonly timing?: ToolCallTiming;\n /** MCP app metadata associated with this tool call, when present. */\n readonly mcp?: ToolCallMessagePartMcpMetadata;\n /** Provider metadata associated with this tool call, when present. */\n readonly providerMetadata?: PartProviderMetadata;\n /** Content returned to the model for this tool result. */\n readonly modelContent?: readonly ToolModelContentPart[] | undefined;\n /** Human-input request that must be resolved before the run can continue. */\n readonly interrupt?: { type: \"human\"; payload: unknown };\n /** Server-side approval gate. `respondToApproval` may only be called while `approved` is undefined and no `resolution` is recorded. */\n readonly approval?: {\n readonly id: string;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n /** Available decisions for this call. Absent: a plain allow / deny pair. */\n readonly options?: readonly ToolApprovalOption[];\n /** The option chosen at resolution, when options were present. */\n readonly optionId?: string;\n /** Terminal non-decision state: the request was cancelled or expired without a user decision. Set by the host. */\n readonly resolution?: \"cancelled\" | \"expired\";\n };\n /** Parent message-part ID when this part belongs to a nested structure. */\n readonly parentId?: string;\n /**\n * Nested thread messages produced by this tool call, for example a sub-agent\n * conversation.\n */\n readonly messages?: readonly ThreadMessage[];\n};\n\nexport type ThreadUserMessagePart =\n | TextMessagePart\n | ImageMessagePart\n | FileMessagePart\n | DataMessagePart\n | Unstable_AudioMessagePart;\n\nexport type ThreadAssistantMessagePart =\n | TextMessagePart\n | ReasoningMessagePart\n | ToolCallMessagePart\n | SourceMessagePart\n | FileMessagePart\n | ImageMessagePart\n | DataMessagePart\n | GenerativeUIMessagePart;\n\nexport type MessagePartStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type MessagePartStreamStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n };\n\nexport type ToolCallMessagePartStatus =\n | {\n /** The tool call is waiting for UI or human input before continuing. */\n readonly type: \"requires-action\";\n /** Reason the tool call requires action. */\n readonly reason: \"interrupt\";\n }\n | MessagePartStatus;\n\nexport type MessageStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\" | \"interrupt\";\n }\n | {\n readonly type: \"complete\";\n readonly reason: \"stop\" | \"unknown\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"tool-calls\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: ReadonlyJSONValue;\n };\n\nexport type MessageTiming = {\n readonly streamStartTime: number;\n readonly firstTokenTime?: number;\n readonly totalStreamTime?: number;\n readonly tokenCount?: number;\n readonly tokensPerSecond?: number;\n readonly totalChunks: number;\n readonly toolCallCount: number;\n};\n\nexport type ThreadStep = {\n readonly messageId?: string;\n readonly usage?:\n | {\n readonly inputTokens: number;\n readonly outputTokens: number;\n }\n | undefined;\n};\n\ntype MessageCommonProps = {\n readonly id: string;\n readonly createdAt: Date;\n};\n\nexport type ThreadSystemMessage = MessageCommonProps & {\n readonly role: \"system\";\n readonly content: readonly [TextMessagePart];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadUserMessage = MessageCommonProps & {\n readonly role: \"user\";\n readonly content: readonly ThreadUserMessagePart[];\n readonly attachments: readonly CompleteAttachment[];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadAssistantMessage = MessageCommonProps & {\n readonly role: \"assistant\";\n readonly content: readonly ThreadAssistantMessagePart[];\n readonly status: MessageStatus;\n readonly metadata: {\n readonly unstable_state: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n /**\n * Marks a client-side optimistic placeholder. Such messages are evicted\n * once off the head branch and are never persisted.\n */\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n};\n\ntype BaseThreadMessage = {\n readonly status?: ThreadAssistantMessage[\"status\"];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations?: readonly ReadonlyJSONValue[];\n readonly unstable_data?: readonly ReadonlyJSONValue[];\n readonly steps?: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n readonly attachments?: ThreadUserMessage[\"attachments\"];\n};\n\nexport type ThreadMessage = BaseThreadMessage &\n (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);\n\nexport type MessageRole = ThreadMessage[\"role\"];\n\nexport type RunConfig = {\n readonly custom?: Record<string, unknown>;\n};\n\nexport type AppendMessage = Omit<ThreadMessage, \"id\"> & {\n parentId: string | null;\n\n /** The ID of the message that was edited or undefined. */\n sourceId: string | null;\n runConfig: RunConfig | undefined;\n startRun?: boolean | undefined;\n /** Process this message next; only meaningful for queue-capable runtimes. */\n steer?: boolean | undefined;\n};\n"],"mappings":";AAoJA,MAAaiD,qBAAqB;AAElC,MAAaC,eAAeC,QAC1B,CAAC,CAACA,KAAKC,WAAWH,kBAAkB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"description": "Framework-agnostic core runtime for assistant-ui",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"assistant",
|
|
@@ -58,14 +58,8 @@
|
|
|
58
58
|
"README.md"
|
|
59
59
|
],
|
|
60
60
|
"sideEffects": false,
|
|
61
|
-
"scripts": {
|
|
62
|
-
"build": "aui-build",
|
|
63
|
-
"test": "vitest run",
|
|
64
|
-
"test:react-compiler": "vitest run --config vitest.react-compiler.config.ts",
|
|
65
|
-
"test:watch": "vitest"
|
|
66
|
-
},
|
|
67
61
|
"dependencies": {
|
|
68
|
-
"assistant-stream": "^0.3.
|
|
62
|
+
"assistant-stream": "^0.3.35",
|
|
69
63
|
"nanoid": "^6.0.0"
|
|
70
64
|
},
|
|
71
65
|
"optionalDevDependencies": {
|
|
@@ -94,18 +88,18 @@
|
|
|
94
88
|
}
|
|
95
89
|
},
|
|
96
90
|
"devDependencies": {
|
|
97
|
-
"@assistant-ui/store": "workspace:*",
|
|
98
|
-
"@assistant-ui/tap": "workspace:*",
|
|
99
|
-
"@assistant-ui/vite": "workspace:*",
|
|
100
|
-
"@assistant-ui/x-buildutils": "workspace:*",
|
|
101
91
|
"@testing-library/react": "^16.3.2",
|
|
102
92
|
"@types/react": "^19.2.17",
|
|
103
|
-
"assistant-cloud": "workspace:*",
|
|
104
93
|
"jsdom": "^29.1.1",
|
|
105
94
|
"react": "^19.2.8",
|
|
106
95
|
"react-dom": "^19.2.8",
|
|
107
96
|
"vitest": "^4.1.10",
|
|
108
|
-
"zustand": "^5.0.14"
|
|
97
|
+
"zustand": "^5.0.14",
|
|
98
|
+
"@assistant-ui/tap": "0.9.10",
|
|
99
|
+
"@assistant-ui/vite": "0.0.11",
|
|
100
|
+
"@assistant-ui/store": "0.3.7",
|
|
101
|
+
"@assistant-ui/x-buildutils": "0.0.21",
|
|
102
|
+
"assistant-cloud": "0.1.38"
|
|
109
103
|
},
|
|
110
104
|
"publishConfig": {
|
|
111
105
|
"access": "public",
|
|
@@ -119,5 +113,11 @@
|
|
|
119
113
|
},
|
|
120
114
|
"bugs": {
|
|
121
115
|
"url": "https://github.com/assistant-ui/assistant-ui/issues"
|
|
116
|
+
},
|
|
117
|
+
"scripts": {
|
|
118
|
+
"build": "aui-build",
|
|
119
|
+
"test": "vitest run",
|
|
120
|
+
"test:react-compiler": "vitest run --config vitest.react-compiler.config.ts",
|
|
121
|
+
"test:watch": "vitest"
|
|
122
122
|
}
|
|
123
|
-
}
|
|
123
|
+
}
|
|
@@ -32,6 +32,7 @@ type AuiV0MessagePart =
|
|
|
32
32
|
| {
|
|
33
33
|
readonly type: "reasoning";
|
|
34
34
|
readonly text: string;
|
|
35
|
+
readonly unstable_summary?: string;
|
|
35
36
|
}
|
|
36
37
|
| {
|
|
37
38
|
readonly type: "source";
|
|
@@ -226,7 +227,13 @@ export function auiV0Encode(message: ThreadMessage): AuiV0Message {
|
|
|
226
227
|
return { type: "text", text: part.text };
|
|
227
228
|
|
|
228
229
|
case "reasoning":
|
|
229
|
-
return {
|
|
230
|
+
return {
|
|
231
|
+
type: "reasoning",
|
|
232
|
+
text: part.text,
|
|
233
|
+
...(part.unstable_summary !== undefined
|
|
234
|
+
? { unstable_summary: part.unstable_summary }
|
|
235
|
+
: undefined),
|
|
236
|
+
};
|
|
230
237
|
|
|
231
238
|
case "source":
|
|
232
239
|
if (part.sourceType === "url") {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AppendMessage, ThreadMessage } from "../../types/message";
|
|
2
2
|
import type { CompleteAttachment } from "../../types/attachment";
|
|
3
3
|
import { getThreadMessageText } from "../../utils/text";
|
|
4
|
-
import {
|
|
4
|
+
import { liftNonTextParts } from "../../adapters/attachment";
|
|
5
5
|
import type { AttachmentAdapter } from "../../adapters/attachment";
|
|
6
6
|
import type { DictationAdapter } from "../../adapters/speech";
|
|
7
7
|
import type { SendOptions } from "../interfaces/composer-runtime-core";
|
|
@@ -26,8 +26,6 @@ export class DefaultEditComposerRuntimeCore extends BaseComposerRuntimeCore {
|
|
|
26
26
|
return this.runtime.adapters?.dictation;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
private _previousText;
|
|
30
|
-
private _previousAttachments: readonly CompleteAttachment[];
|
|
31
29
|
private _nonTextPassthrough: readonly ThreadMessage["content"][number][];
|
|
32
30
|
private _parentId: string | null;
|
|
33
31
|
private _sourceId: string | null;
|
|
@@ -58,24 +56,24 @@ export class DefaultEditComposerRuntimeCore extends BaseComposerRuntimeCore {
|
|
|
58
56
|
this.endEditCallback = endEditCallback;
|
|
59
57
|
this._parentId = parentId;
|
|
60
58
|
this._sourceId = message.id;
|
|
61
|
-
this.
|
|
62
|
-
this.setText(this._previousText);
|
|
59
|
+
this.setText(getThreadMessageText(message));
|
|
63
60
|
|
|
64
61
|
this.setRole(message.role);
|
|
65
62
|
|
|
63
|
+
let attachments: readonly CompleteAttachment[];
|
|
66
64
|
if (message.role === "user") {
|
|
67
|
-
|
|
65
|
+
attachments = [
|
|
68
66
|
...(message.attachments ?? []),
|
|
69
67
|
...liftNonTextParts(message.content),
|
|
70
68
|
];
|
|
71
69
|
this._nonTextPassthrough = [];
|
|
72
70
|
} else {
|
|
73
|
-
|
|
71
|
+
attachments = message.attachments ?? [];
|
|
74
72
|
this._nonTextPassthrough = message.content.filter(
|
|
75
73
|
(p) => p.type !== "text",
|
|
76
74
|
);
|
|
77
75
|
}
|
|
78
|
-
this.setAttachments(
|
|
76
|
+
this.setAttachments(attachments);
|
|
79
77
|
|
|
80
78
|
this.setRunConfig({ ...runtime.composer.runConfig });
|
|
81
79
|
}
|
|
@@ -92,49 +90,33 @@ export class DefaultEditComposerRuntimeCore extends BaseComposerRuntimeCore {
|
|
|
92
90
|
message: Omit<AppendMessage, "parentId" | "sourceId">,
|
|
93
91
|
options?: SendOptions,
|
|
94
92
|
) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
const content =
|
|
94
|
+
this._nonTextPassthrough.length > 0
|
|
95
|
+
? ([
|
|
96
|
+
...message.content,
|
|
97
|
+
...this._nonTextPassthrough,
|
|
98
|
+
] as AppendMessage["content"])
|
|
99
|
+
: message.content;
|
|
100
|
+
// Gate live state against the new branch's prefix (messages up to the
|
|
101
|
+
// parent): an unchanged interactable re-stamps the prior baseline, an
|
|
102
|
+
// interactable edited since the original message stamps its newest state.
|
|
103
|
+
const messages = this.runtime.messages;
|
|
104
|
+
const parentIndex =
|
|
105
|
+
this._parentId === null
|
|
106
|
+
? -1
|
|
107
|
+
: messages.findIndex((m) => m.id === this._parentId);
|
|
108
|
+
const composerMetadata = gateInteractableComposerMetadata(
|
|
109
|
+
this.runtime.getModelContext().unstable_composerMetadata,
|
|
110
|
+
messages.slice(0, parentIndex + 1),
|
|
100
111
|
);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
? ([
|
|
110
|
-
...message.content,
|
|
111
|
-
...this._nonTextPassthrough,
|
|
112
|
-
] as AppendMessage["content"])
|
|
113
|
-
: message.content;
|
|
114
|
-
// Gate live state against the new branch's prefix (messages up to the
|
|
115
|
-
// parent): an unchanged interactable re-stamps the prior baseline, an
|
|
116
|
-
// interactable edited since the original message stamps its newest state.
|
|
117
|
-
const messages = this.runtime.messages;
|
|
118
|
-
const parentIndex =
|
|
119
|
-
this._parentId === null
|
|
120
|
-
? -1
|
|
121
|
-
: messages.findIndex((m) => m.id === this._parentId);
|
|
122
|
-
const composerMetadata = gateInteractableComposerMetadata(
|
|
123
|
-
this.runtime.getModelContext().unstable_composerMetadata,
|
|
124
|
-
messages.slice(0, parentIndex + 1),
|
|
125
|
-
);
|
|
126
|
-
const enriched = this.enrichWithComposerMetadata(
|
|
127
|
-
message,
|
|
128
|
-
composerMetadata,
|
|
129
|
-
);
|
|
130
|
-
appendTask = this.runtime.append({
|
|
131
|
-
...enriched,
|
|
132
|
-
content,
|
|
133
|
-
parentId: this._parentId,
|
|
134
|
-
sourceId: this._sourceId,
|
|
135
|
-
startRun: options?.startRun,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
112
|
+
const enriched = this.enrichWithComposerMetadata(message, composerMetadata);
|
|
113
|
+
const appendTask = this.runtime.append({
|
|
114
|
+
...enriched,
|
|
115
|
+
content,
|
|
116
|
+
parentId: this._parentId,
|
|
117
|
+
sourceId: this._sourceId,
|
|
118
|
+
startRun: options?.startRun,
|
|
119
|
+
});
|
|
138
120
|
|
|
139
121
|
this.handleCancel();
|
|
140
122
|
return appendTask;
|
|
@@ -160,10 +160,14 @@ export const fromThreadMessageLike = (
|
|
|
160
160
|
const type = part.type;
|
|
161
161
|
switch (type) {
|
|
162
162
|
case "text":
|
|
163
|
-
case "reasoning":
|
|
164
163
|
if (!part.text?.trim()) return null;
|
|
165
164
|
return part;
|
|
166
165
|
|
|
166
|
+
case "reasoning":
|
|
167
|
+
if (!part.text?.trim() && !part.unstable_summary?.trim())
|
|
168
|
+
return null;
|
|
169
|
+
return part;
|
|
170
|
+
|
|
167
171
|
case "file":
|
|
168
172
|
case "source":
|
|
169
173
|
return part;
|
|
@@ -466,7 +466,11 @@ export class ExternalStoreThreadRuntimeCore
|
|
|
466
466
|
}
|
|
467
467
|
|
|
468
468
|
public async append(message: AppendMessage): Promise<void> {
|
|
469
|
-
|
|
469
|
+
// sourceId marks an edit send; the parent may coincide with the head
|
|
470
|
+
// after a resync (e.g. cancelRun dropped the edited message).
|
|
471
|
+
const isEdit =
|
|
472
|
+
message.sourceId != null ||
|
|
473
|
+
message.parentId !== (this.messages.at(-1)?.id ?? null);
|
|
470
474
|
|
|
471
475
|
// Buffering does not start a run, so the tool-abort below must wait until
|
|
472
476
|
// the queue flushes. By then the prior run (and its tools) has settled.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { AuiConfig, createAssistantClient } from "@assistant-ui/store/client";
|
|
3
|
+
import { RuntimeAdapter, Suggestions } from "../index";
|
|
4
|
+
import { ExternalStoreRuntimeCore } from "../../runtimes/internal";
|
|
5
|
+
import { AssistantRuntimeImpl } from "../../runtime/internal";
|
|
6
|
+
import type { ExternalStoreAdapter } from "../../runtimes/external-store/external-store-adapter";
|
|
7
|
+
|
|
8
|
+
type DemoMessage = { id: string; role: "user" | "assistant"; text: string };
|
|
9
|
+
|
|
10
|
+
const createClient = () => {
|
|
11
|
+
const adapter: ExternalStoreAdapter<DemoMessage> = {
|
|
12
|
+
messages: [
|
|
13
|
+
{ id: "u1", role: "user", text: "hi" },
|
|
14
|
+
{ id: "a1", role: "assistant", text: "hello" },
|
|
15
|
+
],
|
|
16
|
+
convertMessage: (message) => ({
|
|
17
|
+
id: message.id,
|
|
18
|
+
role: message.role,
|
|
19
|
+
content: [{ type: "text", text: message.text }],
|
|
20
|
+
}),
|
|
21
|
+
onNew: async () => {},
|
|
22
|
+
adapters: {
|
|
23
|
+
threadList: {
|
|
24
|
+
threadId: "t1",
|
|
25
|
+
threads: [{ status: "regular", id: "t1", title: "one" }],
|
|
26
|
+
archivedThreads: [{ status: "archived", id: "t2", title: "two" }],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const runtime = new AssistantRuntimeImpl(
|
|
31
|
+
new ExternalStoreRuntimeCore(adapter),
|
|
32
|
+
);
|
|
33
|
+
return createAssistantClient(
|
|
34
|
+
AuiConfig({
|
|
35
|
+
threads: RuntimeAdapter(runtime),
|
|
36
|
+
suggestions: Suggestions([
|
|
37
|
+
{ title: "a", label: "a", prompt: "a" },
|
|
38
|
+
{ title: "b", label: "b", prompt: "b" },
|
|
39
|
+
]),
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Pins each by-index lookup's valid domain to the state array that backs it.
|
|
46
|
+
* Consumers (the vue by-index providers) guard with `index < array.length`
|
|
47
|
+
* against these arrays; a lookup changing its backing array must fail here.
|
|
48
|
+
*/
|
|
49
|
+
describe("by-index lookup domains", () => {
|
|
50
|
+
it("thread.message is indexed by thread.getState().messages", () => {
|
|
51
|
+
const handle = createClient();
|
|
52
|
+
const aui = handle.getClient();
|
|
53
|
+
const length = aui.thread.getState().messages.length;
|
|
54
|
+
expect(length).toBe(2);
|
|
55
|
+
expect(aui.thread.message({ index: length - 1 }).getState().id).toBe("a1");
|
|
56
|
+
expect(() => aui.thread.message({ index: length }).getState()).toThrow(
|
|
57
|
+
/out of bounds/,
|
|
58
|
+
);
|
|
59
|
+
handle.destroy();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("message.part is indexed by message.getState().parts", () => {
|
|
63
|
+
const handle = createClient();
|
|
64
|
+
const aui = handle.getClient();
|
|
65
|
+
const message = aui.thread.message({ index: 1 });
|
|
66
|
+
const length = message.getState().parts.length;
|
|
67
|
+
expect(length).toBe(1);
|
|
68
|
+
expect(message.part({ index: length - 1 }).getState().type).toBe("text");
|
|
69
|
+
expect(() => message.part({ index: length }).getState()).toThrow(
|
|
70
|
+
/out of bounds/,
|
|
71
|
+
);
|
|
72
|
+
handle.destroy();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("suggestions.suggestion is indexed by suggestions.getState().suggestions", () => {
|
|
76
|
+
const handle = createClient();
|
|
77
|
+
const aui = handle.getClient();
|
|
78
|
+
const length = aui.suggestions.getState().suggestions.length;
|
|
79
|
+
expect(length).toBe(2);
|
|
80
|
+
expect(
|
|
81
|
+
aui.suggestions.suggestion({ index: length - 1 }).getState().title,
|
|
82
|
+
).toBe("b");
|
|
83
|
+
expect(() =>
|
|
84
|
+
aui.suggestions.suggestion({ index: length }).getState(),
|
|
85
|
+
).toThrow(/out of bounds/);
|
|
86
|
+
handle.destroy();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("threads.item is indexed by threadIds and archivedThreadIds", () => {
|
|
90
|
+
const handle = createClient();
|
|
91
|
+
const aui = handle.getClient();
|
|
92
|
+
const state = aui.threads.getState();
|
|
93
|
+
expect(state.threadIds).toHaveLength(1);
|
|
94
|
+
expect(state.archivedThreadIds).toHaveLength(1);
|
|
95
|
+
expect(aui.threads.item({ index: 0, archived: false }).getState().id).toBe(
|
|
96
|
+
"t1",
|
|
97
|
+
);
|
|
98
|
+
expect(aui.threads.item({ index: 0, archived: true }).getState().id).toBe(
|
|
99
|
+
"t2",
|
|
100
|
+
);
|
|
101
|
+
expect(() =>
|
|
102
|
+
aui.threads.item({ index: 1, archived: false }).getState(),
|
|
103
|
+
).toThrow(/not found|out of bounds/);
|
|
104
|
+
expect(() =>
|
|
105
|
+
aui.threads.item({ index: 1, archived: true }).getState(),
|
|
106
|
+
).toThrow(/not found|out of bounds/);
|
|
107
|
+
handle.destroy();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -236,6 +236,33 @@ describe("auiV0Encode", () => {
|
|
|
236
236
|
]);
|
|
237
237
|
});
|
|
238
238
|
|
|
239
|
+
it("preserves reasoning summaries and omits absent summaries", () => {
|
|
240
|
+
const encoded = auiV0Encode({
|
|
241
|
+
id: "m1",
|
|
242
|
+
createdAt: new Date("2026-03-15T00:00:00.000Z"),
|
|
243
|
+
role: "assistant",
|
|
244
|
+
status: { type: "complete", reason: "stop" },
|
|
245
|
+
metadata: {
|
|
246
|
+
unstable_state: null,
|
|
247
|
+
unstable_annotations: [],
|
|
248
|
+
unstable_data: [],
|
|
249
|
+
steps: [],
|
|
250
|
+
custom: {},
|
|
251
|
+
},
|
|
252
|
+
content: [
|
|
253
|
+
{ type: "reasoning", text: "thinking", unstable_summary: "Planning" },
|
|
254
|
+
{ type: "reasoning", text: "more thinking", unstable_summary: "" },
|
|
255
|
+
{ type: "reasoning", text: "no summary" },
|
|
256
|
+
],
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
expect(encoded.content).toEqual([
|
|
260
|
+
{ type: "reasoning", text: "thinking", unstable_summary: "Planning" },
|
|
261
|
+
{ type: "reasoning", text: "more thinking", unstable_summary: "" },
|
|
262
|
+
{ type: "reasoning", text: "no summary" },
|
|
263
|
+
]);
|
|
264
|
+
});
|
|
265
|
+
|
|
239
266
|
it("drops per-part status from attachment content in the core cloud encoder", () => {
|
|
240
267
|
const encoded = auiV0Encode({
|
|
241
268
|
id: "m1",
|
|
@@ -306,6 +333,76 @@ describe("auiV0Encode", () => {
|
|
|
306
333
|
});
|
|
307
334
|
|
|
308
335
|
describe("auiV0Decode", () => {
|
|
336
|
+
it("round-trips a reasoning summary", () => {
|
|
337
|
+
const encoded = auiV0Encode({
|
|
338
|
+
id: "local",
|
|
339
|
+
createdAt: new Date("2026-03-15T00:00:00.000Z"),
|
|
340
|
+
role: "assistant",
|
|
341
|
+
status: { type: "complete", reason: "stop" },
|
|
342
|
+
metadata: {
|
|
343
|
+
unstable_state: null,
|
|
344
|
+
unstable_annotations: [],
|
|
345
|
+
unstable_data: [],
|
|
346
|
+
steps: [],
|
|
347
|
+
custom: {},
|
|
348
|
+
},
|
|
349
|
+
content: [
|
|
350
|
+
{ type: "reasoning", text: "thinking", unstable_summary: "Planning" },
|
|
351
|
+
],
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
const { message } = auiV0Decode({
|
|
355
|
+
id: "cloud",
|
|
356
|
+
parent_id: null,
|
|
357
|
+
format: "aui/v0",
|
|
358
|
+
content: encoded,
|
|
359
|
+
created_at: new Date("2026-03-15T00:00:00.000Z"),
|
|
360
|
+
} as unknown as Parameters<typeof auiV0Decode>[0]);
|
|
361
|
+
|
|
362
|
+
expect(message.content).toEqual([
|
|
363
|
+
{ type: "reasoning", text: "thinking", unstable_summary: "Planning" },
|
|
364
|
+
]);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it("round-trips a reasoning summary without text", () => {
|
|
368
|
+
const encoded = auiV0Encode({
|
|
369
|
+
id: "local",
|
|
370
|
+
createdAt: new Date("2026-03-15T00:00:00.000Z"),
|
|
371
|
+
role: "assistant",
|
|
372
|
+
status: { type: "complete", reason: "stop" },
|
|
373
|
+
metadata: {
|
|
374
|
+
unstable_state: null,
|
|
375
|
+
unstable_annotations: [],
|
|
376
|
+
unstable_data: [],
|
|
377
|
+
steps: [],
|
|
378
|
+
custom: {},
|
|
379
|
+
},
|
|
380
|
+
content: [
|
|
381
|
+
{
|
|
382
|
+
type: "reasoning",
|
|
383
|
+
text: "",
|
|
384
|
+
unstable_summary: "Searching the codebase",
|
|
385
|
+
},
|
|
386
|
+
],
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
const { message } = auiV0Decode({
|
|
390
|
+
id: "cloud",
|
|
391
|
+
parent_id: null,
|
|
392
|
+
format: "aui/v0",
|
|
393
|
+
content: encoded,
|
|
394
|
+
created_at: new Date("2026-03-15T00:00:00.000Z"),
|
|
395
|
+
} as unknown as Parameters<typeof auiV0Decode>[0]);
|
|
396
|
+
|
|
397
|
+
expect(message.content).toEqual([
|
|
398
|
+
{
|
|
399
|
+
type: "reasoning",
|
|
400
|
+
text: "",
|
|
401
|
+
unstable_summary: "Searching the codebase",
|
|
402
|
+
},
|
|
403
|
+
]);
|
|
404
|
+
});
|
|
405
|
+
|
|
309
406
|
it("round-trips a pending tool-call approval so a paused run stays resumable", () => {
|
|
310
407
|
const content = auiV0Encode({
|
|
311
408
|
id: "local",
|
|
@@ -132,7 +132,7 @@ describe("DefaultEditComposerRuntimeCore", () => {
|
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
describe("send behavior", () => {
|
|
135
|
-
it("
|
|
135
|
+
it("calls append even when nothing changed, branching with the same message", async () => {
|
|
136
136
|
const { runtime, append } = makeRuntime();
|
|
137
137
|
const composer = new DefaultEditComposerRuntimeCore(runtime, () => {}, {
|
|
138
138
|
parentId: "p1",
|
|
@@ -141,7 +141,11 @@ describe("DefaultEditComposerRuntimeCore", () => {
|
|
|
141
141
|
}),
|
|
142
142
|
});
|
|
143
143
|
await composer.send();
|
|
144
|
-
expect(append).
|
|
144
|
+
expect(append).toHaveBeenCalledTimes(1);
|
|
145
|
+
const appended = append.mock.calls[0]![0] as AppendMessage;
|
|
146
|
+
expect(appended.content).toEqual([{ type: "text", text: "same" }]);
|
|
147
|
+
expect(appended.parentId).toBe("p1");
|
|
148
|
+
expect(appended.sourceId).toBe("msg-1");
|
|
145
149
|
});
|
|
146
150
|
|
|
147
151
|
it("calls append when text changes", async () => {
|
|
@@ -883,6 +883,42 @@ describe("ExternalStoreThreadRuntimeCore - message queue", () => {
|
|
|
883
883
|
expect(queue.steer).toHaveBeenCalledTimes(1);
|
|
884
884
|
});
|
|
885
885
|
|
|
886
|
+
it("routes an edit send to onEdit even when anchored at the head", async () => {
|
|
887
|
+
const queue = makeQueue();
|
|
888
|
+
const onNew = vi.fn();
|
|
889
|
+
const onEdit = vi.fn();
|
|
890
|
+
const runtime = new ExternalStoreThreadRuntimeCore(
|
|
891
|
+
mockContextProvider,
|
|
892
|
+
makeStore({ queue, onNew, onEdit }),
|
|
893
|
+
);
|
|
894
|
+
|
|
895
|
+
await runtime.append(appendMessage({ sourceId: "u1" }));
|
|
896
|
+
|
|
897
|
+
expect(onEdit).toHaveBeenCalledTimes(1);
|
|
898
|
+
expect(onEdit.mock.calls[0]![0]).toMatchObject({
|
|
899
|
+
sourceId: "u1",
|
|
900
|
+
parentId: null,
|
|
901
|
+
});
|
|
902
|
+
expect(onNew).not.toHaveBeenCalled();
|
|
903
|
+
expect(queue.enqueue).not.toHaveBeenCalled();
|
|
904
|
+
expect(queue.steer).not.toHaveBeenCalled();
|
|
905
|
+
});
|
|
906
|
+
|
|
907
|
+
it("throws the edit capability error for an edit send instead of queueing it", async () => {
|
|
908
|
+
const queue = makeQueue();
|
|
909
|
+
const onNew = vi.fn();
|
|
910
|
+
const runtime = new ExternalStoreThreadRuntimeCore(
|
|
911
|
+
mockContextProvider,
|
|
912
|
+
makeStore({ queue, onNew }),
|
|
913
|
+
);
|
|
914
|
+
|
|
915
|
+
await expect(
|
|
916
|
+
runtime.append(appendMessage({ sourceId: "u1" })),
|
|
917
|
+
).rejects.toThrow("Runtime does not support editing messages.");
|
|
918
|
+
expect(onNew).not.toHaveBeenCalled();
|
|
919
|
+
expect(queue.enqueue).not.toHaveBeenCalled();
|
|
920
|
+
});
|
|
921
|
+
|
|
886
922
|
it("defaults a mid-run send to steer and an idle send to enqueue", async () => {
|
|
887
923
|
const queue = makeQueue();
|
|
888
924
|
const running = new ExternalStoreThreadRuntimeCore(
|
|
@@ -147,6 +147,49 @@ describe("fromThreadMessageLike", () => {
|
|
|
147
147
|
expect(result.content).toEqual([{ type: "reasoning", text: "hi" }]);
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
+
it("keeps a reasoning part with a summary and no text", () => {
|
|
151
|
+
const result = fromThreadMessageLike(
|
|
152
|
+
{
|
|
153
|
+
role: "assistant",
|
|
154
|
+
content: [
|
|
155
|
+
{
|
|
156
|
+
type: "reasoning",
|
|
157
|
+
text: "",
|
|
158
|
+
unstable_summary: "Searching the codebase",
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
},
|
|
162
|
+
fallbackId,
|
|
163
|
+
fallbackStatus,
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
expect(result.content).toEqual([
|
|
167
|
+
{
|
|
168
|
+
type: "reasoning",
|
|
169
|
+
text: "",
|
|
170
|
+
unstable_summary: "Searching the codebase",
|
|
171
|
+
},
|
|
172
|
+
]);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("drops a reasoning part with neither text nor a summary to show", () => {
|
|
176
|
+
// the transport layers round-trip an empty summary faithfully; this is
|
|
177
|
+
// the display normalizer, so it drops a part with nothing to render for
|
|
178
|
+
// the same reason it drops whitespace-only text.
|
|
179
|
+
const message = fromThreadMessageLike(
|
|
180
|
+
{
|
|
181
|
+
role: "assistant",
|
|
182
|
+
content: [
|
|
183
|
+
{ type: "reasoning", text: "", unstable_summary: "" },
|
|
184
|
+
{ type: "reasoning", text: " ", unstable_summary: " " },
|
|
185
|
+
],
|
|
186
|
+
},
|
|
187
|
+
"m1",
|
|
188
|
+
{ type: "complete", reason: "unknown" },
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
expect(message.content).toEqual([]);
|
|
192
|
+
});
|
|
150
193
|
it("drops an assistant image part whose image is undefined", () => {
|
|
151
194
|
const result = fromThreadMessageLike(
|
|
152
195
|
{
|