@assistant-ui/react-ag-ui 0.0.31 → 0.0.33
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/dist/index.d.ts +3 -4
- package/dist/index.js +2 -2
- package/dist/runtime/AgUiThreadRuntimeCore.d.ts +85 -82
- package/dist/runtime/AgUiThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtime/AgUiThreadRuntimeCore.js +542 -628
- package/dist/runtime/AgUiThreadRuntimeCore.js.map +1 -1
- package/dist/runtime/adapter/conversions.d.ts +39 -36
- package/dist/runtime/adapter/conversions.d.ts.map +1 -1
- package/dist/runtime/adapter/conversions.js +294 -390
- package/dist/runtime/adapter/conversions.js.map +1 -1
- package/dist/runtime/adapter/run-aggregator.d.ts +54 -51
- package/dist/runtime/adapter/run-aggregator.d.ts.map +1 -1
- package/dist/runtime/adapter/run-aggregator.js +367 -413
- package/dist/runtime/adapter/run-aggregator.js.map +1 -1
- package/dist/runtime/adapter/subscriber.d.ts +94 -91
- package/dist/runtime/adapter/subscriber.d.ts.map +1 -1
- package/dist/runtime/adapter/subscriber.js +77 -86
- package/dist/runtime/adapter/subscriber.js.map +1 -1
- package/dist/runtime/event-parser.d.ts +9 -5
- package/dist/runtime/event-parser.d.ts.map +1 -1
- package/dist/runtime/event-parser.js +172 -177
- package/dist/runtime/event-parser.js.map +1 -1
- package/dist/runtime/logger.d.ts +7 -4
- package/dist/runtime/logger.d.ts.map +1 -1
- package/dist/runtime/logger.js +7 -3
- package/dist/runtime/logger.js.map +1 -1
- package/dist/runtime/types.d.ts +121 -117
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/types.js +0 -2
- package/dist/useAgUiRuntime.d.ts +10 -6
- package/dist/useAgUiRuntime.d.ts.map +1 -1
- package/dist/useAgUiRuntime.js +105 -142
- package/dist/useAgUiRuntime.js.map +1 -1
- package/package.json +7 -7
- package/src/useAgUiRuntime.ts +3 -47
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/runtime/types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAgUiRuntime.js","
|
|
1
|
+
{"version":3,"file":"useAgUiRuntime.js","names":[],"sources":["../src/useAgUiRuntime.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n useExternalStoreRuntime,\n useRuntimeAdapters,\n} from \"@assistant-ui/core/react\";\nimport type { ToolExecutionStatus } from \"@assistant-ui/core\";\nimport type {\n AssistantRuntime,\n AppendMessage,\n ExternalStoreAdapter,\n ThreadMessage,\n} from \"@assistant-ui/core\";\nimport type { ReadonlyJSONValue } from \"assistant-stream/utils\";\nimport { makeLogger } from \"./runtime/logger\";\nimport type {\n AgUiInterrupt,\n AgUiResumeEntry,\n UseAgUiRuntimeOptions,\n} from \"./runtime/types\";\nimport { AgUiThreadRuntimeCore } from \"./runtime/AgUiThreadRuntimeCore\";\n\nexport type AgUiAssistantRuntime = AssistantRuntime & {\n unstable_getPendingInterrupts: () => readonly AgUiInterrupt[];\n unstable_submitInterruptResponses: (\n responses: readonly AgUiResumeEntry[],\n ) => Promise<void>;\n};\n\nexport function useAgUiRuntime(\n options: UseAgUiRuntimeOptions,\n): AgUiAssistantRuntime {\n const logger = useMemo(() => makeLogger(options.logger), [options.logger]);\n const [_version, setVersion] = useState(0);\n const notifyUpdate = useCallback(() => setVersion((v) => v + 1), []);\n const coreRef = useRef<AgUiThreadRuntimeCore | null>(null);\n const runtimeAdapters = useRuntimeAdapters();\n\n const historyAdapter = options.adapters?.history ?? runtimeAdapters?.history;\n const threadListAdapter = options.adapters?.threadList;\n\n if (!coreRef.current) {\n coreRef.current = new AgUiThreadRuntimeCore({\n agent: options.agent,\n logger,\n showThinking: options.showThinking ?? true,\n ...(options.onError && { onError: options.onError }),\n ...(options.onCancel && { onCancel: options.onCancel }),\n ...(historyAdapter && { history: historyAdapter }),\n notifyUpdate,\n });\n }\n\n const core = coreRef.current;\n core.updateOptions({\n agent: options.agent,\n logger,\n showThinking: options.showThinking ?? true,\n ...(options.onError && { onError: options.onError }),\n ...(options.onCancel && { onCancel: options.onCancel }),\n ...(historyAdapter && { history: historyAdapter }),\n });\n\n const [toolStatuses, setToolStatuses] = useState<\n Record<string, ToolExecutionStatus>\n >({});\n\n const hasExecutingTools = Object.values(toolStatuses).some(\n (s) => s?.type === \"executing\",\n );\n\n const threadList = useMemo(() => {\n if (!threadListAdapter) return undefined;\n\n const { onSwitchToNewThread, onSwitchToThread } = threadListAdapter;\n\n return {\n threadId: threadListAdapter.threadId,\n onSwitchToNewThread: onSwitchToNewThread\n ? async () => {\n await onSwitchToNewThread();\n core.applyExternalMessages([]);\n }\n : undefined,\n onSwitchToThread: onSwitchToThread\n ? async (threadId: string) => {\n const result = await onSwitchToThread(threadId);\n core.applyExternalMessages(result.messages);\n if (result.state) {\n core.loadExternalState(result.state);\n }\n }\n : undefined,\n };\n }, [threadListAdapter, core]);\n\n const adapters = options.adapters;\n const adapterAdapters = useMemo(\n () => ({\n attachments: adapters?.attachments ?? runtimeAdapters?.attachments,\n speech: adapters?.speech,\n dictation: adapters?.dictation,\n feedback: adapters?.feedback,\n threadList,\n }),\n [adapters, runtimeAdapters, threadList],\n );\n\n const store = useMemo(\n () => {\n void _version; // rerender on version change\n\n return {\n isLoading: core.isLoading,\n messages: core.getMessages(),\n state: core.getState(),\n isRunning: core.isRunning() || hasExecutingTools,\n unstable_enableToolInvocations: true,\n setToolStatuses,\n onNew: (message: AppendMessage) => core.append(message),\n onEdit: (message: AppendMessage) => core.edit(message),\n onReload: (parentId: string | null, config: { runConfig?: any }) =>\n core.reload(parentId, config),\n onCancel: async () => {\n core.cancel();\n },\n onAddToolResult: (options) => core.addToolResult(options),\n onResume: (config) => core.resume(config),\n setMessages: (messages: readonly ThreadMessage[]) =>\n core.applyExternalMessages(messages),\n onImport: (messages: readonly ThreadMessage[]) =>\n core.applyExternalMessages(messages),\n onLoadExternalState: (state: ReadonlyJSONValue) =>\n core.loadExternalState(state),\n adapters: adapterAdapters,\n } satisfies ExternalStoreAdapter<ThreadMessage>;\n },\n // _version is intentionally included to trigger re-computation when core state changes via notifyUpdate\n // toolInvocations intentionally excluded: abort/resume use refs internally and work with stale captures\n [adapterAdapters, core, _version, hasExecutingTools],\n );\n\n const baseRuntime = useExternalStoreRuntime(store);\n\n const runtime = useMemo<AgUiAssistantRuntime>(() => {\n const wrapper = Object.create(baseRuntime) as AgUiAssistantRuntime;\n wrapper.unstable_getPendingInterrupts = () =>\n core.getPendingInterrupts()?.interrupts ?? [];\n wrapper.unstable_submitInterruptResponses = (responses) =>\n core.submitInterruptResponses(responses);\n return wrapper;\n }, [baseRuntime, core]);\n\n useEffect(() => {\n core.attachRuntime(runtime);\n return () => {\n core.detachRuntime();\n };\n }, [core, runtime]);\n\n useEffect(() => {\n core.__internal_load();\n }, [core]);\n\n return runtime;\n}\n"],"mappings":";;;;;;AA8BA,SAAgB,eACd,SACsB;CACtB,MAAM,SAAS,cAAc,WAAW,QAAQ,MAAM,GAAG,CAAC,QAAQ,MAAM,CAAC;CACzE,MAAM,CAAC,UAAU,cAAc,SAAS,CAAC;CACzC,MAAM,eAAe,kBAAkB,YAAY,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC;CACnE,MAAM,UAAU,OAAqC,IAAI;CACzD,MAAM,kBAAkB,mBAAmB;CAE3C,MAAM,iBAAiB,QAAQ,UAAU,WAAW,iBAAiB;CACrE,MAAM,oBAAoB,QAAQ,UAAU;CAE5C,IAAI,CAAC,QAAQ,SACX,QAAQ,UAAU,IAAI,sBAAsB;EAC1C,OAAO,QAAQ;EACf;EACA,cAAc,QAAQ,gBAAgB;EACtC,GAAI,QAAQ,WAAW,EAAE,SAAS,QAAQ,QAAQ;EAClD,GAAI,QAAQ,YAAY,EAAE,UAAU,QAAQ,SAAS;EACrD,GAAI,kBAAkB,EAAE,SAAS,eAAe;EAChD;CACF,CAAC;CAGH,MAA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OAAO;GACrD,WAAW,UAAyB,WAClC,KAAK,OAAO,UAAU,MAAM;GAC9B,UAAU,YAAY;IACpB,KAAK,OAAO;GACd;GACA,kBAAkB,YAAY,KAAK,cAAc,OAAO;GACxD,WAAW,WAAW,KAAK,OAAO,MAAM;GACxC,cAAc,aACZ,KAAK,sBAAsB,QAAQ;GACrC,WAAW,aACT,KAAK,sBAAsB,QAAQ;GACrC,sBAAsB,UACpB,KAAK,kBAAkB,KAAK;GAC9B,UAAU;EACZ;CACF,GAGA;EAAC;EAAiB;EAAM;EAAU;CAAiB,CAGL,CAAC;CAEjD,MAAM,UAAU,cAAoC;EAClD,MAAM,UAAU,OAAO,OAAO,WAAW;EACzC,QAAQ,sCACN,KAAK,qBAAqB,GAAG,cAAc,CAAC;EAC9C,QAAQ,qCAAqC,cAC3C,KAAK,yBAAyB,SAAS;EACzC,OAAO;CACT,GAAG,CAAC,aAAa,IAAI,CAAC;CAEtB,gBAAgB;EACd,KAAK,cAAc,OAAO;EAC1B,aAAa;GACX,KAAK,cAAc;EACrB;CACF,GAAG,CAAC,MAAM,OAAO,CAAC;CAElB,gBAAgB;EACd,KAAK,gBAAgB;CACvB,GAAG,CAAC,IAAI,CAAC;CAET,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/react-ag-ui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"description": "AG-UI protocol adapter for assistant-ui",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ag-ui",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"sideEffects": false,
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@ag-ui/client": "^0.0.53",
|
|
33
|
-
"@assistant-ui/core": "^0.2.
|
|
34
|
-
"assistant-stream": "^0.3.
|
|
33
|
+
"@assistant-ui/core": "^0.2.5",
|
|
34
|
+
"assistant-stream": "^0.3.16"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@types/react": "*",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/react": "^19.2.
|
|
47
|
-
"react": "^19.2.
|
|
48
|
-
"vitest": "^4.1.
|
|
46
|
+
"@types/react": "^19.2.15",
|
|
47
|
+
"react": "^19.2.6",
|
|
48
|
+
"vitest": "^4.1.7",
|
|
49
49
|
"zod": "^4.4.3",
|
|
50
|
-
"@assistant-ui/x-buildutils": "0.0.
|
|
50
|
+
"@assistant-ui/x-buildutils": "0.0.9"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public",
|
package/src/useAgUiRuntime.ts
CHANGED
|
@@ -4,9 +4,8 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
|
4
4
|
import {
|
|
5
5
|
useExternalStoreRuntime,
|
|
6
6
|
useRuntimeAdapters,
|
|
7
|
-
useToolInvocations,
|
|
8
7
|
} from "@assistant-ui/core/react";
|
|
9
|
-
import type { ToolExecutionStatus } from "@assistant-ui/core
|
|
8
|
+
import type { ToolExecutionStatus } from "@assistant-ui/core";
|
|
10
9
|
import type {
|
|
11
10
|
AssistantRuntime,
|
|
12
11
|
AppendMessage,
|
|
@@ -71,18 +70,6 @@ export function useAgUiRuntime(
|
|
|
71
70
|
(s) => s?.type === "executing",
|
|
72
71
|
);
|
|
73
72
|
|
|
74
|
-
const [runtimeRef] = useState(() => ({
|
|
75
|
-
get current(): AssistantRuntime {
|
|
76
|
-
return runtime;
|
|
77
|
-
},
|
|
78
|
-
}));
|
|
79
|
-
|
|
80
|
-
const toolInvocationsRef = useRef({
|
|
81
|
-
reset: () => {},
|
|
82
|
-
abort: (): Promise<void> => Promise.resolve(),
|
|
83
|
-
resume: (_toolCallId: string, _payload: unknown) => {},
|
|
84
|
-
});
|
|
85
|
-
|
|
86
73
|
const threadList = useMemo(() => {
|
|
87
74
|
if (!threadListAdapter) return undefined;
|
|
88
75
|
|
|
@@ -92,14 +79,12 @@ export function useAgUiRuntime(
|
|
|
92
79
|
threadId: threadListAdapter.threadId,
|
|
93
80
|
onSwitchToNewThread: onSwitchToNewThread
|
|
94
81
|
? async () => {
|
|
95
|
-
toolInvocationsRef.current.reset();
|
|
96
82
|
await onSwitchToNewThread();
|
|
97
83
|
core.applyExternalMessages([]);
|
|
98
84
|
}
|
|
99
85
|
: undefined,
|
|
100
86
|
onSwitchToThread: onSwitchToThread
|
|
101
87
|
? async (threadId: string) => {
|
|
102
|
-
toolInvocationsRef.current.reset();
|
|
103
88
|
const result = await onSwitchToThread(threadId);
|
|
104
89
|
core.applyExternalMessages(result.messages);
|
|
105
90
|
if (result.state) {
|
|
@@ -122,31 +107,6 @@ export function useAgUiRuntime(
|
|
|
122
107
|
[adapters, runtimeAdapters, threadList],
|
|
123
108
|
);
|
|
124
109
|
|
|
125
|
-
const toolInvocations = useToolInvocations({
|
|
126
|
-
state: {
|
|
127
|
-
messages: core.getMessages(),
|
|
128
|
-
isRunning: core.isRunning() || hasExecutingTools,
|
|
129
|
-
},
|
|
130
|
-
getTools: () => runtimeRef.current.thread.getModelContext().tools,
|
|
131
|
-
onResult: (command) => {
|
|
132
|
-
if (command.type === "add-tool-result") {
|
|
133
|
-
const messageId = core.findMessageIdForToolCall(command.toolCallId);
|
|
134
|
-
if (messageId) {
|
|
135
|
-
core.addToolResult({
|
|
136
|
-
messageId,
|
|
137
|
-
toolCallId: command.toolCallId,
|
|
138
|
-
toolName: command.toolName,
|
|
139
|
-
result: command.result,
|
|
140
|
-
isError: command.isError,
|
|
141
|
-
...(command.artifact && { artifact: command.artifact }),
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
setToolStatuses,
|
|
147
|
-
});
|
|
148
|
-
toolInvocationsRef.current = toolInvocations;
|
|
149
|
-
|
|
150
110
|
const store = useMemo(
|
|
151
111
|
() => {
|
|
152
112
|
void _version; // rerender on version change
|
|
@@ -156,21 +116,17 @@ export function useAgUiRuntime(
|
|
|
156
116
|
messages: core.getMessages(),
|
|
157
117
|
state: core.getState(),
|
|
158
118
|
isRunning: core.isRunning() || hasExecutingTools,
|
|
119
|
+
unstable_enableToolInvocations: true,
|
|
120
|
+
setToolStatuses,
|
|
159
121
|
onNew: (message: AppendMessage) => core.append(message),
|
|
160
122
|
onEdit: (message: AppendMessage) => core.edit(message),
|
|
161
123
|
onReload: (parentId: string | null, config: { runConfig?: any }) =>
|
|
162
124
|
core.reload(parentId, config),
|
|
163
125
|
onCancel: async () => {
|
|
164
126
|
core.cancel();
|
|
165
|
-
await toolInvocationsRef.current.abort();
|
|
166
127
|
},
|
|
167
128
|
onAddToolResult: (options) => core.addToolResult(options),
|
|
168
129
|
onResume: (config) => core.resume(config),
|
|
169
|
-
onResumeToolCall: (options) =>
|
|
170
|
-
toolInvocationsRef.current.resume(
|
|
171
|
-
options.toolCallId,
|
|
172
|
-
options.payload,
|
|
173
|
-
),
|
|
174
130
|
setMessages: (messages: readonly ThreadMessage[]) =>
|
|
175
131
|
core.applyExternalMessages(messages),
|
|
176
132
|
onImport: (messages: readonly ThreadMessage[]) =>
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,4BAAyB;AAClD,YAAY,EAAE,oBAAoB,EAAE,4BAAyB;AAC7D,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,GACzB,2BAAwB"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,4BAAyB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/runtime/types.ts"],"names":[],"mappings":""}
|