@assistant-ui/react-ag-ui 0.0.30 → 0.0.32

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.
Files changed (39) hide show
  1. package/dist/index.d.ts +3 -4
  2. package/dist/index.js +2 -2
  3. package/dist/runtime/AgUiThreadRuntimeCore.d.ts +85 -82
  4. package/dist/runtime/AgUiThreadRuntimeCore.d.ts.map +1 -1
  5. package/dist/runtime/AgUiThreadRuntimeCore.js +542 -627
  6. package/dist/runtime/AgUiThreadRuntimeCore.js.map +1 -1
  7. package/dist/runtime/adapter/conversions.d.ts +39 -36
  8. package/dist/runtime/adapter/conversions.d.ts.map +1 -1
  9. package/dist/runtime/adapter/conversions.js +294 -390
  10. package/dist/runtime/adapter/conversions.js.map +1 -1
  11. package/dist/runtime/adapter/run-aggregator.d.ts +54 -47
  12. package/dist/runtime/adapter/run-aggregator.d.ts.map +1 -1
  13. package/dist/runtime/adapter/run-aggregator.js +367 -364
  14. package/dist/runtime/adapter/run-aggregator.js.map +1 -1
  15. package/dist/runtime/adapter/subscriber.d.ts +94 -91
  16. package/dist/runtime/adapter/subscriber.d.ts.map +1 -1
  17. package/dist/runtime/adapter/subscriber.js +77 -86
  18. package/dist/runtime/adapter/subscriber.js.map +1 -1
  19. package/dist/runtime/event-parser.d.ts +9 -5
  20. package/dist/runtime/event-parser.d.ts.map +1 -1
  21. package/dist/runtime/event-parser.js +172 -177
  22. package/dist/runtime/event-parser.js.map +1 -1
  23. package/dist/runtime/logger.d.ts +7 -4
  24. package/dist/runtime/logger.d.ts.map +1 -1
  25. package/dist/runtime/logger.js +7 -3
  26. package/dist/runtime/logger.js.map +1 -1
  27. package/dist/runtime/types.d.ts +121 -117
  28. package/dist/runtime/types.d.ts.map +1 -1
  29. package/dist/runtime/types.js +0 -2
  30. package/dist/useAgUiRuntime.d.ts +10 -6
  31. package/dist/useAgUiRuntime.d.ts.map +1 -1
  32. package/dist/useAgUiRuntime.js +136 -142
  33. package/dist/useAgUiRuntime.js.map +1 -1
  34. package/package.json +9 -8
  35. package/src/runtime/AgUiThreadRuntimeCore.ts +1 -0
  36. package/src/runtime/adapter/run-aggregator.ts +111 -45
  37. package/dist/index.d.ts.map +0 -1
  38. package/dist/index.js.map +0 -1
  39. package/dist/runtime/types.js.map +0 -1
@@ -1,156 +1,160 @@
1
- import type { AttachmentAdapter, DictationAdapter, FeedbackAdapter, SpeechSynthesisAdapter, ThreadHistoryAdapter, ThreadMessage } from "@assistant-ui/core";
2
- import type { HttpAgent } from "@ag-ui/client";
3
- import type { Logger } from "./logger.js";
4
- import type { ReadonlyJSONValue } from "assistant-stream/utils";
1
+ import { Logger } from "./logger.js";
2
+ import { AttachmentAdapter, DictationAdapter, FeedbackAdapter, SpeechSynthesisAdapter, ThreadHistoryAdapter, ThreadMessage } from "@assistant-ui/core";
3
+ import { HttpAgent } from "@ag-ui/client";
4
+ import { ReadonlyJSONValue } from "assistant-stream/utils";
5
+
6
+ //#region src/runtime/types.d.ts
5
7
  /**
6
8
  * @experimental This API is still under active development and might change without notice.
7
9
  */
8
- export type UseAgUiThreadListAdapter = {
9
- threadId?: string | undefined;
10
- onSwitchToNewThread?: (() => Promise<void> | void) | undefined;
11
- onSwitchToThread?: ((threadId: string) => Promise<{
12
- messages: readonly ThreadMessage[];
13
- state?: ReadonlyJSONValue;
14
- }> | {
15
- messages: readonly ThreadMessage[];
16
- state?: ReadonlyJSONValue;
17
- }) | undefined;
10
+ type UseAgUiThreadListAdapter = {
11
+ threadId?: string | undefined;
12
+ onSwitchToNewThread?: (() => Promise<void> | void) | undefined;
13
+ onSwitchToThread?: ((threadId: string) => Promise<{
14
+ messages: readonly ThreadMessage[];
15
+ state?: ReadonlyJSONValue;
16
+ }> | {
17
+ messages: readonly ThreadMessage[];
18
+ state?: ReadonlyJSONValue;
19
+ }) | undefined;
18
20
  };
19
- export type UseAgUiRuntimeAdapters = {
20
- attachments?: AttachmentAdapter;
21
- speech?: SpeechSynthesisAdapter;
22
- dictation?: DictationAdapter;
23
- feedback?: FeedbackAdapter;
24
- history?: ThreadHistoryAdapter;
25
- /**
26
- * @experimental This API is still under active development and might change without notice.
27
- */
28
- threadList?: UseAgUiThreadListAdapter;
21
+ type UseAgUiRuntimeAdapters = {
22
+ attachments?: AttachmentAdapter;
23
+ speech?: SpeechSynthesisAdapter;
24
+ dictation?: DictationAdapter;
25
+ feedback?: FeedbackAdapter;
26
+ history?: ThreadHistoryAdapter;
27
+ /**
28
+ * @experimental This API is still under active development and might change without notice.
29
+ */
30
+ threadList?: UseAgUiThreadListAdapter;
29
31
  };
30
- export type UseAgUiRuntimeOptions = {
31
- agent: HttpAgent;
32
- logger?: Partial<Logger>;
33
- showThinking?: boolean;
34
- onError?: (e: Error) => void;
35
- onCancel?: () => void;
36
- adapters?: UseAgUiRuntimeAdapters;
32
+ type UseAgUiRuntimeOptions = {
33
+ agent: HttpAgent;
34
+ logger?: Partial<Logger>;
35
+ showThinking?: boolean;
36
+ onError?: (e: Error) => void;
37
+ onCancel?: () => void;
38
+ adapters?: UseAgUiRuntimeAdapters;
37
39
  };
38
- export type AgUiInterruptReason = "tool_call" | "input_required" | "confirmation" | (string & {});
39
- export type AgUiInterrupt = {
40
- id: string;
41
- reason: AgUiInterruptReason;
42
- message?: string;
43
- toolCallId?: string;
44
- responseSchema?: Record<string, unknown>;
45
- expiresAt?: string;
46
- metadata?: Record<string, unknown>;
40
+ type AgUiInterruptReason = "tool_call" | "input_required" | "confirmation" | (string & {});
41
+ type AgUiInterrupt = {
42
+ id: string;
43
+ reason: AgUiInterruptReason;
44
+ message?: string;
45
+ toolCallId?: string;
46
+ responseSchema?: Record<string, unknown>;
47
+ expiresAt?: string;
48
+ metadata?: Record<string, unknown>;
47
49
  };
48
- export type AgUiResumeEntry = {
49
- interruptId: string;
50
- status: "resolved" | "cancelled";
51
- payload?: unknown;
50
+ type AgUiResumeEntry = {
51
+ interruptId: string;
52
+ status: "resolved" | "cancelled";
53
+ payload?: unknown;
52
54
  };
53
- export type AgUiRunFinishedOutcome = {
54
- type: "success";
55
+ type AgUiRunFinishedOutcome = {
56
+ type: "success";
55
57
  } | {
56
- type: "interrupt";
57
- interrupts: AgUiInterrupt[];
58
+ type: "interrupt";
59
+ interrupts: AgUiInterrupt[];
58
60
  };
59
- export type AgUiEvent = {
60
- type: "RUN_STARTED";
61
- runId: string;
61
+ type AgUiEvent = {
62
+ type: "RUN_STARTED";
63
+ runId: string;
62
64
  } | {
63
- type: "RUN_FINISHED";
64
- runId: string;
65
- outcome?: AgUiRunFinishedOutcome;
65
+ type: "RUN_FINISHED";
66
+ runId: string;
67
+ outcome?: AgUiRunFinishedOutcome;
66
68
  } | {
67
- type: "RUN_CANCELLED";
68
- runId?: string;
69
+ type: "RUN_CANCELLED";
70
+ runId?: string;
69
71
  } | {
70
- type: "RUN_ERROR";
71
- message?: string;
72
- code?: string;
72
+ type: "RUN_ERROR";
73
+ message?: string;
74
+ code?: string;
73
75
  } | {
74
- type: "TEXT_MESSAGE_START";
75
- messageId?: string;
76
+ type: "TEXT_MESSAGE_START";
77
+ messageId?: string;
76
78
  } | {
77
- type: "TEXT_MESSAGE_CONTENT";
78
- messageId?: string;
79
- delta: string;
79
+ type: "TEXT_MESSAGE_CONTENT";
80
+ messageId?: string;
81
+ delta: string;
80
82
  } | {
81
- type: "TEXT_MESSAGE_END";
82
- messageId?: string;
83
+ type: "TEXT_MESSAGE_END";
84
+ messageId?: string;
83
85
  } | {
84
- type: "TEXT_MESSAGE_CHUNK";
85
- delta: string;
86
+ type: "TEXT_MESSAGE_CHUNK";
87
+ delta: string;
86
88
  } | {
87
- type: "THINKING_START";
88
- title?: string;
89
+ type: "THINKING_START";
90
+ title?: string;
89
91
  } | {
90
- type: "THINKING_TEXT_MESSAGE_START";
92
+ type: "THINKING_TEXT_MESSAGE_START";
91
93
  } | {
92
- type: "THINKING_TEXT_MESSAGE_CONTENT";
93
- delta: string;
94
+ type: "THINKING_TEXT_MESSAGE_CONTENT";
95
+ delta: string;
94
96
  } | {
95
- type: "THINKING_TEXT_MESSAGE_END";
97
+ type: "THINKING_TEXT_MESSAGE_END";
96
98
  } | {
97
- type: "THINKING_END";
99
+ type: "THINKING_END";
98
100
  } | {
99
- type: "REASONING_START";
100
- messageId?: string;
101
+ type: "REASONING_START";
102
+ messageId?: string;
101
103
  } | {
102
- type: "REASONING_MESSAGE_START";
103
- messageId?: string;
104
+ type: "REASONING_MESSAGE_START";
105
+ messageId?: string;
104
106
  } | {
105
- type: "REASONING_MESSAGE_CONTENT";
106
- messageId?: string;
107
- delta: string;
107
+ type: "REASONING_MESSAGE_CONTENT";
108
+ messageId?: string;
109
+ delta: string;
108
110
  } | {
109
- type: "REASONING_MESSAGE_END";
110
- messageId?: string;
111
+ type: "REASONING_MESSAGE_END";
112
+ messageId?: string;
111
113
  } | {
112
- type: "REASONING_END";
113
- messageId?: string;
114
+ type: "REASONING_END";
115
+ messageId?: string;
114
116
  } | {
115
- type: "TOOL_CALL_START";
116
- toolCallId: string;
117
- toolCallName?: string;
118
- parentMessageId?: string;
117
+ type: "TOOL_CALL_START";
118
+ toolCallId: string;
119
+ toolCallName?: string;
120
+ parentMessageId?: string;
119
121
  } | {
120
- type: "TOOL_CALL_ARGS";
121
- toolCallId: string;
122
- delta: string;
122
+ type: "TOOL_CALL_ARGS";
123
+ toolCallId: string;
124
+ delta: string;
123
125
  } | {
124
- type: "TOOL_CALL_END";
125
- toolCallId: string;
126
+ type: "TOOL_CALL_END";
127
+ toolCallId: string;
126
128
  } | {
127
- type: "TOOL_CALL_CHUNK";
128
- toolCallId?: string;
129
- toolCallName?: string;
130
- parentMessageId?: string;
131
- delta?: string;
129
+ type: "TOOL_CALL_CHUNK";
130
+ toolCallId?: string;
131
+ toolCallName?: string;
132
+ parentMessageId?: string;
133
+ delta?: string;
132
134
  } | {
133
- type: "TOOL_CALL_RESULT";
134
- messageId?: string;
135
- toolCallId: string;
136
- content: string;
137
- role?: "tool";
135
+ type: "TOOL_CALL_RESULT";
136
+ messageId?: string;
137
+ toolCallId: string;
138
+ content: string;
139
+ role?: "tool";
138
140
  } | {
139
- type: "RAW";
140
- event: any;
141
- source?: string;
141
+ type: "RAW";
142
+ event: any;
143
+ source?: string;
142
144
  } | {
143
- type: "CUSTOM";
144
- name: string;
145
- value: any;
145
+ type: "CUSTOM";
146
+ name: string;
147
+ value: any;
146
148
  } | {
147
- type: "STATE_SNAPSHOT";
148
- snapshot: any;
149
+ type: "STATE_SNAPSHOT";
150
+ snapshot: any;
149
151
  } | {
150
- type: "STATE_DELTA";
151
- delta: any[];
152
+ type: "STATE_DELTA";
153
+ delta: any[];
152
154
  } | {
153
- type: "MESSAGES_SNAPSHOT";
154
- messages: any[];
155
+ type: "MESSAGES_SNAPSHOT";
156
+ messages: any[];
155
157
  };
158
+ //#endregion
159
+ export { AgUiEvent, AgUiInterrupt, AgUiInterruptReason, AgUiResumeEntry, AgUiRunFinishedOutcome, UseAgUiRuntimeAdapters, UseAgUiRuntimeOptions, UseAgUiThreadListAdapter };
156
160
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/runtime/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACpB,aAAa,EACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAiB;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,mBAAmB,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;IAC/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AAAA;EACxB,IAAA;EAAqB,KAAA;AAAA;EACrB,IAAA;EAA2B,QAAA;AAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1,8 +1,12 @@
1
- import type { AssistantRuntime } from "@assistant-ui/core";
2
- import type { AgUiInterrupt, AgUiResumeEntry, UseAgUiRuntimeOptions } from "./runtime/types.js";
3
- export type AgUiAssistantRuntime = AssistantRuntime & {
4
- unstable_getPendingInterrupts: () => readonly AgUiInterrupt[];
5
- unstable_submitInterruptResponses: (responses: readonly AgUiResumeEntry[]) => Promise<void>;
1
+ import { AgUiInterrupt, AgUiResumeEntry, UseAgUiRuntimeOptions } from "./runtime/types.js";
2
+ import { AssistantRuntime } from "@assistant-ui/core";
3
+
4
+ //#region src/useAgUiRuntime.d.ts
5
+ type AgUiAssistantRuntime = AssistantRuntime & {
6
+ unstable_getPendingInterrupts: () => readonly AgUiInterrupt[];
7
+ unstable_submitInterruptResponses: (responses: readonly AgUiResumeEntry[]) => Promise<void>;
6
8
  };
7
- export declare function useAgUiRuntime(options: UseAgUiRuntimeOptions): AgUiAssistantRuntime;
9
+ declare function useAgUiRuntime(options: UseAgUiRuntimeOptions): AgUiAssistantRuntime;
10
+ //#endregion
11
+ export { AgUiAssistantRuntime, useAgUiRuntime };
8
12
  //# sourceMappingURL=useAgUiRuntime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAgUiRuntime.d.ts","sourceRoot":"","sources":["../src/useAgUiRuntime.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,gBAAgB,EAIjB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,qBAAqB,EACtB,2BAAwB;AAGzB,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,GAAG;IACpD,6BAA6B,EAAE,MAAM,SAAS,aAAa,EAAE,CAAC;IAC9D,iCAAiC,EAAE,CACjC,SAAS,EAAE,SAAS,eAAe,EAAE,KAClC,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,qBAAqB,GAC7B,oBAAoB,CAiLtB"}
1
+ {"version":3,"file":"useAgUiRuntime.d.ts","names":[],"sources":["../src/useAgUiRuntime.ts"],"mappings":";;;;KAwBY,oBAAA,GAAuB,gBAAA;EACjC,6BAAA,iBAA8C,aAAA;EAC9C,iCAAA,GACE,SAAA,WAAoB,eAAA,OACjB,OAAA;AAAA;AAAA,iBAGS,cAAA,CACd,OAAA,EAAS,qBAAA,GACR,oBAAoB"}
@@ -1,147 +1,141 @@
1
1
  "use client";
2
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
- import { useExternalStoreRuntime, useRuntimeAdapters, useToolInvocations, } from "@assistant-ui/core/react";
4
2
  import { makeLogger } from "./runtime/logger.js";
5
3
  import { AgUiThreadRuntimeCore } from "./runtime/AgUiThreadRuntimeCore.js";
6
- export function useAgUiRuntime(options) {
7
- const logger = useMemo(() => makeLogger(options.logger), [options.logger]);
8
- const [_version, setVersion] = useState(0);
9
- const notifyUpdate = useCallback(() => setVersion((v) => v + 1), []);
10
- const coreRef = useRef(null);
11
- const runtimeAdapters = useRuntimeAdapters();
12
- const historyAdapter = options.adapters?.history ?? runtimeAdapters?.history;
13
- const threadListAdapter = options.adapters?.threadList;
14
- if (!coreRef.current) {
15
- coreRef.current = new AgUiThreadRuntimeCore({
16
- agent: options.agent,
17
- logger,
18
- showThinking: options.showThinking ?? true,
19
- ...(options.onError && { onError: options.onError }),
20
- ...(options.onCancel && { onCancel: options.onCancel }),
21
- ...(historyAdapter && { history: historyAdapter }),
22
- notifyUpdate,
23
- });
24
- }
25
- const core = coreRef.current;
26
- core.updateOptions({
27
- agent: options.agent,
28
- logger,
29
- showThinking: options.showThinking ?? true,
30
- ...(options.onError && { onError: options.onError }),
31
- ...(options.onCancel && { onCancel: options.onCancel }),
32
- ...(historyAdapter && { history: historyAdapter }),
33
- });
34
- const [toolStatuses, setToolStatuses] = useState({});
35
- const hasExecutingTools = Object.values(toolStatuses).some((s) => s?.type === "executing");
36
- const [runtimeRef] = useState(() => ({
37
- get current() {
38
- return runtime;
39
- },
40
- }));
41
- const toolInvocationsRef = useRef({
42
- reset: () => { },
43
- abort: () => Promise.resolve(),
44
- resume: (_toolCallId, _payload) => { },
45
- });
46
- const threadList = useMemo(() => {
47
- if (!threadListAdapter)
48
- return undefined;
49
- const { onSwitchToNewThread, onSwitchToThread } = threadListAdapter;
50
- return {
51
- threadId: threadListAdapter.threadId,
52
- onSwitchToNewThread: onSwitchToNewThread
53
- ? async () => {
54
- toolInvocationsRef.current.reset();
55
- await onSwitchToNewThread();
56
- core.applyExternalMessages([]);
57
- }
58
- : undefined,
59
- onSwitchToThread: onSwitchToThread
60
- ? async (threadId) => {
61
- toolInvocationsRef.current.reset();
62
- const result = await onSwitchToThread(threadId);
63
- core.applyExternalMessages(result.messages);
64
- if (result.state) {
65
- core.loadExternalState(result.state);
66
- }
67
- }
68
- : undefined,
69
- };
70
- }, [threadListAdapter, core]);
71
- const adapters = options.adapters;
72
- const adapterAdapters = useMemo(() => ({
73
- attachments: adapters?.attachments ?? runtimeAdapters?.attachments,
74
- speech: adapters?.speech,
75
- dictation: adapters?.dictation,
76
- feedback: adapters?.feedback,
77
- threadList,
78
- }), [adapters, runtimeAdapters, threadList]);
79
- const toolInvocations = useToolInvocations({
80
- state: {
81
- messages: core.getMessages(),
82
- isRunning: core.isRunning() || hasExecutingTools,
83
- },
84
- getTools: () => runtimeRef.current.thread.getModelContext().tools,
85
- onResult: (command) => {
86
- if (command.type === "add-tool-result") {
87
- const messageId = core.findMessageIdForToolCall(command.toolCallId);
88
- if (messageId) {
89
- core.addToolResult({
90
- messageId,
91
- toolCallId: command.toolCallId,
92
- toolName: command.toolName,
93
- result: command.result,
94
- isError: command.isError,
95
- ...(command.artifact && { artifact: command.artifact }),
96
- });
97
- }
98
- }
99
- },
100
- setToolStatuses,
101
- });
102
- toolInvocationsRef.current = toolInvocations;
103
- const store = useMemo(() => {
104
- void _version; // rerender on version change
105
- return {
106
- isLoading: core.isLoading,
107
- messages: core.getMessages(),
108
- state: core.getState(),
109
- isRunning: core.isRunning() || hasExecutingTools,
110
- onNew: (message) => core.append(message),
111
- onEdit: (message) => core.edit(message),
112
- onReload: (parentId, config) => core.reload(parentId, config),
113
- onCancel: async () => {
114
- core.cancel();
115
- await toolInvocationsRef.current.abort();
116
- },
117
- onAddToolResult: (options) => core.addToolResult(options),
118
- onResume: (config) => core.resume(config),
119
- onResumeToolCall: (options) => toolInvocationsRef.current.resume(options.toolCallId, options.payload),
120
- setMessages: (messages) => core.applyExternalMessages(messages),
121
- onImport: (messages) => core.applyExternalMessages(messages),
122
- onLoadExternalState: (state) => core.loadExternalState(state),
123
- adapters: adapterAdapters,
124
- };
125
- },
126
- // _version is intentionally included to trigger re-computation when core state changes via notifyUpdate
127
- // toolInvocations intentionally excluded: abort/resume use refs internally and work with stale captures
128
- [adapterAdapters, core, _version, hasExecutingTools]);
129
- const baseRuntime = useExternalStoreRuntime(store);
130
- const runtime = useMemo(() => {
131
- const wrapper = Object.create(baseRuntime);
132
- wrapper.unstable_getPendingInterrupts = () => core.getPendingInterrupts()?.interrupts ?? [];
133
- wrapper.unstable_submitInterruptResponses = (responses) => core.submitInterruptResponses(responses);
134
- return wrapper;
135
- }, [baseRuntime, core]);
136
- useEffect(() => {
137
- core.attachRuntime(runtime);
138
- return () => {
139
- core.detachRuntime();
140
- };
141
- }, [core, runtime]);
142
- useEffect(() => {
143
- core.__internal_load();
144
- }, [core]);
145
- return runtime;
4
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
5
+ import { useExternalStoreRuntime, useRuntimeAdapters, useToolInvocations } from "@assistant-ui/core/react";
6
+ //#region src/useAgUiRuntime.ts
7
+ function useAgUiRuntime(options) {
8
+ const logger = useMemo(() => makeLogger(options.logger), [options.logger]);
9
+ const [_version, setVersion] = useState(0);
10
+ const notifyUpdate = useCallback(() => setVersion((v) => v + 1), []);
11
+ const coreRef = useRef(null);
12
+ const runtimeAdapters = useRuntimeAdapters();
13
+ const historyAdapter = options.adapters?.history ?? runtimeAdapters?.history;
14
+ const threadListAdapter = options.adapters?.threadList;
15
+ if (!coreRef.current) coreRef.current = new AgUiThreadRuntimeCore({
16
+ agent: options.agent,
17
+ logger,
18
+ showThinking: options.showThinking ?? true,
19
+ ...options.onError && { onError: options.onError },
20
+ ...options.onCancel && { onCancel: options.onCancel },
21
+ ...historyAdapter && { history: historyAdapter },
22
+ notifyUpdate
23
+ });
24
+ const core = coreRef.current;
25
+ core.updateOptions({
26
+ agent: options.agent,
27
+ logger,
28
+ showThinking: options.showThinking ?? true,
29
+ ...options.onError && { onError: options.onError },
30
+ ...options.onCancel && { onCancel: options.onCancel },
31
+ ...historyAdapter && { history: historyAdapter }
32
+ });
33
+ const [toolStatuses, setToolStatuses] = useState({});
34
+ const hasExecutingTools = Object.values(toolStatuses).some((s) => s?.type === "executing");
35
+ const [runtimeRef] = useState(() => ({ get current() {
36
+ return runtime;
37
+ } }));
38
+ const toolInvocationsRef = useRef({
39
+ reset: () => {},
40
+ abort: () => Promise.resolve(),
41
+ resume: (_toolCallId, _payload) => {}
42
+ });
43
+ const threadList = useMemo(() => {
44
+ if (!threadListAdapter) return void 0;
45
+ const { onSwitchToNewThread, onSwitchToThread } = threadListAdapter;
46
+ return {
47
+ threadId: threadListAdapter.threadId,
48
+ onSwitchToNewThread: onSwitchToNewThread ? async () => {
49
+ toolInvocationsRef.current.reset();
50
+ await onSwitchToNewThread();
51
+ core.applyExternalMessages([]);
52
+ } : void 0,
53
+ onSwitchToThread: onSwitchToThread ? async (threadId) => {
54
+ toolInvocationsRef.current.reset();
55
+ const result = await onSwitchToThread(threadId);
56
+ core.applyExternalMessages(result.messages);
57
+ if (result.state) core.loadExternalState(result.state);
58
+ } : void 0
59
+ };
60
+ }, [threadListAdapter, core]);
61
+ const adapters = options.adapters;
62
+ const adapterAdapters = useMemo(() => ({
63
+ attachments: adapters?.attachments ?? runtimeAdapters?.attachments,
64
+ speech: adapters?.speech,
65
+ dictation: adapters?.dictation,
66
+ feedback: adapters?.feedback,
67
+ threadList
68
+ }), [
69
+ adapters,
70
+ runtimeAdapters,
71
+ threadList
72
+ ]);
73
+ toolInvocationsRef.current = useToolInvocations({
74
+ state: {
75
+ messages: core.getMessages(),
76
+ isRunning: core.isRunning() || hasExecutingTools
77
+ },
78
+ getTools: () => runtimeRef.current.thread.getModelContext().tools,
79
+ onResult: (command) => {
80
+ if (command.type === "add-tool-result") {
81
+ const messageId = core.findMessageIdForToolCall(command.toolCallId);
82
+ if (messageId) core.addToolResult({
83
+ messageId,
84
+ toolCallId: command.toolCallId,
85
+ toolName: command.toolName,
86
+ result: command.result,
87
+ isError: command.isError,
88
+ ...command.artifact && { artifact: command.artifact }
89
+ });
90
+ }
91
+ },
92
+ setToolStatuses
93
+ });
94
+ const baseRuntime = useExternalStoreRuntime(useMemo(() => {
95
+ return {
96
+ isLoading: core.isLoading,
97
+ messages: core.getMessages(),
98
+ state: core.getState(),
99
+ isRunning: core.isRunning() || hasExecutingTools,
100
+ onNew: (message) => core.append(message),
101
+ onEdit: (message) => core.edit(message),
102
+ onReload: (parentId, config) => core.reload(parentId, config),
103
+ onCancel: async () => {
104
+ core.cancel();
105
+ await toolInvocationsRef.current.abort();
106
+ },
107
+ onAddToolResult: (options) => core.addToolResult(options),
108
+ onResume: (config) => core.resume(config),
109
+ onResumeToolCall: (options) => toolInvocationsRef.current.resume(options.toolCallId, options.payload),
110
+ setMessages: (messages) => core.applyExternalMessages(messages),
111
+ onImport: (messages) => core.applyExternalMessages(messages),
112
+ onLoadExternalState: (state) => core.loadExternalState(state),
113
+ adapters: adapterAdapters
114
+ };
115
+ }, [
116
+ adapterAdapters,
117
+ core,
118
+ _version,
119
+ hasExecutingTools
120
+ ]));
121
+ const runtime = useMemo(() => {
122
+ const wrapper = Object.create(baseRuntime);
123
+ wrapper.unstable_getPendingInterrupts = () => core.getPendingInterrupts()?.interrupts ?? [];
124
+ wrapper.unstable_submitInterruptResponses = (responses) => core.submitInterruptResponses(responses);
125
+ return wrapper;
126
+ }, [baseRuntime, core]);
127
+ useEffect(() => {
128
+ core.attachRuntime(runtime);
129
+ return () => {
130
+ core.detachRuntime();
131
+ };
132
+ }, [core, runtime]);
133
+ useEffect(() => {
134
+ core.__internal_load();
135
+ }, [core]);
136
+ return runtime;
146
137
  }
138
+ //#endregion
139
+ export { useAgUiRuntime };
140
+
147
141
  //# sourceMappingURL=useAgUiRuntime.js.map