@assistant-ui/eve 0.0.8 → 0.0.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/dist/useEveAgentRuntime.d.ts.map +1 -1
- package/dist/useEveAgentRuntime.js +18 -3
- package/dist/useEveAgentRuntime.js.map +1 -1
- package/package.json +10 -10
- package/src/useEveAgentRuntime.test.tsx +214 -0
- package/src/useEveAgentRuntime.ts +36 -2
- package/LICENSE +0 -21
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEveAgentRuntime.d.ts","names":[],"sources":["../src/useEveAgentRuntime.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"useEveAgentRuntime.d.ts","names":[],"sources":["../src/useEveAgentRuntime.ts"],"mappings":";;;KA4DY,4BAA4B,KACtC,mBAAmB,8BAGnB;WACW;aAEM,cAAc;aACd,SAAS;aACT,YAAY;aACZ,QAAQ;aACR,WAAW;;;;;;;;;;cAYjB,qBAAsB,UAAS,2DAA8B"}
|
|
@@ -9,6 +9,14 @@ const USER_STAGED_STATUS = {
|
|
|
9
9
|
type: "complete",
|
|
10
10
|
reason: "unknown"
|
|
11
11
|
};
|
|
12
|
+
const hasRunConfig = (runConfig) => runConfig?.custom !== void 0 && Object.keys(runConfig.custom).length > 0;
|
|
13
|
+
/**
|
|
14
|
+
* Only the `custom` bag crosses the wire. Eve reads `clientContext` as its own
|
|
15
|
+
* namespace and serializes it into a model-visible context message, so sending
|
|
16
|
+
* the assistant-ui envelope would surface a literal `"custom"` key in the
|
|
17
|
+
* prompt and to every eve-side handler.
|
|
18
|
+
*/
|
|
19
|
+
const toEveClientContext = (runConfig) => hasRunConfig(runConfig) ? { clientContext: runConfig.custom } : {};
|
|
12
20
|
/**
|
|
13
21
|
* Connects Eve's `useEveAgent` hook to assistant-ui's runtime contract.
|
|
14
22
|
*
|
|
@@ -96,9 +104,12 @@ const useEveAgentRuntime = (options = {}) => {
|
|
|
96
104
|
stageUserMessage(message);
|
|
97
105
|
return;
|
|
98
106
|
}
|
|
99
|
-
await agent.send({
|
|
107
|
+
await agent.send({
|
|
108
|
+
message: getEveMessageContent(message),
|
|
109
|
+
...toEveClientContext(message.runConfig)
|
|
110
|
+
});
|
|
100
111
|
},
|
|
101
|
-
...stagedMessages ? { onReload: async (parentId) => {
|
|
112
|
+
...stagedMessages ? { onReload: async (parentId, config) => {
|
|
102
113
|
const stagedRun = getStagedRun(parentId);
|
|
103
114
|
if (!stagedRun) throw new Error("Runtime does not support reloading messages.");
|
|
104
115
|
for (const { message: stagedMessage, input } of stagedRun) {
|
|
@@ -107,8 +118,12 @@ const useEveAgentRuntime = (options = {}) => {
|
|
|
107
118
|
const nextMessages = previousMessages.filter((message) => message.id !== stagedMessage.id);
|
|
108
119
|
messagesRef.current = nextMessages;
|
|
109
120
|
setStagedMessages(stagedInputsRef.current.size > 0 ? nextMessages : null);
|
|
121
|
+
const runConfig = stagedMessage.id === parentId && hasRunConfig(config.runConfig) ? config.runConfig : input.runConfig;
|
|
110
122
|
try {
|
|
111
|
-
await agent.send({
|
|
123
|
+
await agent.send({
|
|
124
|
+
message: getEveMessageContent(input.message),
|
|
125
|
+
...toEveClientContext(runConfig)
|
|
126
|
+
});
|
|
112
127
|
} catch (error) {
|
|
113
128
|
stagedInputsRef.current.set(stagedMessage.id, input);
|
|
114
129
|
messagesRef.current = previousMessages;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEveAgentRuntime.js","names":[],"sources":["../src/useEveAgentRuntime.ts"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n fromThreadMessageLike,\n generateId,\n pickExternalStoreSharedOptions,\n type AppendMessage,\n type AttachmentAdapter,\n type DictationAdapter,\n type ExternalStoreSharedOptions,\n type FeedbackAdapter,\n type RealtimeVoiceAdapter,\n type SpeechSynthesisAdapter,\n type ThreadMessage,\n type ToolExecutionStatus,\n} from \"@assistant-ui/core\";\nimport {\n useExternalStoreRuntime,\n useRuntimeAdapters,\n} from \"@assistant-ui/core/react\";\nimport {\n useEveAgent,\n type EveMessageData,\n type UseEveAgentOptions,\n} from \"eve/react\";\nimport {\n convertEveMessages,\n getEveMessageContent,\n toEveInputResponse,\n} from \"./convertEveMessages\";\n\nconst USER_STAGED_STATUS = {\n type: \"complete\",\n reason: \"unknown\",\n} as const;\n\nexport type UseEveAgentRuntimeOptions = Omit<\n UseEveAgentOptions<EveMessageData>,\n \"reducer\"\n> &\n ExternalStoreSharedOptions & {\n readonly adapters?:\n | {\n readonly attachments?: AttachmentAdapter | undefined;\n readonly speech?: SpeechSynthesisAdapter | undefined;\n readonly dictation?: DictationAdapter | undefined;\n readonly voice?: RealtimeVoiceAdapter | undefined;\n readonly feedback?: FeedbackAdapter | undefined;\n }\n | undefined;\n };\n\n/**\n * Connects Eve's `useEveAgent` hook to assistant-ui's runtime contract.\n *\n * The runtime renders Eve messages, forwards new user messages to the Eve\n * session, supports cancellation, and maps Eve input requests to assistant-ui\n * tool approval UI.\n */\nexport const useEveAgentRuntime = (options: UseEveAgentRuntimeOptions = {}) => {\n const {\n adapters,\n isDisabled: _isDisabled,\n isSendDisabled: _isSendDisabled,\n suggestions: _suggestions,\n unstable_capabilities: _unstable_capabilities,\n ...agentOptions\n } = options;\n true satisfies keyof typeof agentOptions &\n keyof ExternalStoreSharedOptions extends never\n ? true\n : never;\n\n const agent = useEveAgent(agentOptions);\n const runtimeAdapters = useRuntimeAdapters();\n const [toolStatuses, setToolStatuses] = useState<\n Record<string, ToolExecutionStatus>\n >({});\n const [stagedMessages, setStagedMessages] = useState<ThreadMessage[] | null>(\n null,\n );\n const createdAtByMessageIdRef = useRef(new Map<string, Date>());\n const stagedInputsRef = useRef(\n new Map<\n string,\n { message: AppendMessage; runConfig: AppendMessage[\"runConfig\"] }\n >(),\n );\n\n const hasExecutingTools = Object.values(toolStatuses).some(\n (status) => status?.type === \"executing\",\n );\n const isRunning =\n agent.status === \"submitted\" ||\n agent.status === \"streaming\" ||\n hasExecutingTools;\n\n const convertedMessages = useMemo(() => {\n const createdAtByMessageId = createdAtByMessageIdRef.current;\n const messageIds = new Set(\n agent.data.messages.map((message) => message.id),\n );\n for (const messageId of createdAtByMessageId.keys()) {\n if (!messageIds.has(messageId)) createdAtByMessageId.delete(messageId);\n }\n\n return convertEveMessages(agent.data, {\n isRunning,\n error: agent.error,\n getCreatedAt: (message) => {\n const existing = createdAtByMessageId.get(message.id);\n if (existing) return existing;\n\n const createdAt = new Date();\n createdAtByMessageId.set(message.id, createdAt);\n return createdAt;\n },\n });\n }, [agent.data, agent.error, isRunning]);\n\n const messages = stagedMessages ?? convertedMessages;\n const messagesRef = useRef(messages);\n messagesRef.current = messages;\n\n useEffect(() => {\n if (stagedInputsRef.current.size === 0) return;\n const baseIds = new Set(convertedMessages.map((message) => message.id));\n const remaining = messagesRef.current.filter(\n (message) =>\n stagedInputsRef.current.has(message.id) && !baseIds.has(message.id),\n );\n setStagedMessages(\n remaining.length > 0 ? [...convertedMessages, ...remaining] : null,\n );\n }, [convertedMessages]);\n\n const getStagedRun = (parentId: string | null) => {\n if (!parentId || !stagedInputsRef.current.has(parentId)) return null;\n const staged: {\n message: ThreadMessage;\n input: { message: AppendMessage; runConfig: AppendMessage[\"runConfig\"] };\n }[] = [];\n for (const message of messagesRef.current) {\n const input = stagedInputsRef.current.get(message.id);\n if (input) staged.push({ message, input });\n if (message.id === parentId) break;\n }\n return staged;\n };\n\n const stageUserMessage = (message: AppendMessage) => {\n const threadMessage = fromThreadMessageLike(\n message,\n generateId(),\n USER_STAGED_STATUS,\n );\n stagedInputsRef.current.set(threadMessage.id, {\n message,\n runConfig: message.runConfig,\n });\n const nextMessages = [...messagesRef.current, threadMessage];\n messagesRef.current = nextMessages;\n setStagedMessages(nextMessages);\n };\n\n return useExternalStoreRuntime({\n ...pickExternalStoreSharedOptions(options),\n messages,\n isRunning,\n unstable_enableToolInvocations: true,\n setToolStatuses,\n adapters: {\n attachments: adapters?.attachments ?? runtimeAdapters?.attachments,\n speech: adapters?.speech,\n dictation: adapters?.dictation,\n voice: adapters?.voice,\n feedback: adapters?.feedback,\n },\n onNew: async (message) => {\n if (!(message.startRun ?? message.role === \"user\")) {\n stageUserMessage(message);\n return;\n }\n await agent.send({ message: getEveMessageContent(message) });\n },\n ...(stagedMessages\n ? {\n onReload: async (parentId: string | null) => {\n const stagedRun = getStagedRun(parentId);\n if (!stagedRun)\n throw new Error(\"Runtime does not support reloading messages.\");\n for (const { message: stagedMessage, input } of stagedRun) {\n const previousMessages = messagesRef.current;\n stagedInputsRef.current.delete(stagedMessage.id);\n const nextMessages = previousMessages.filter(\n (message) => message.id !== stagedMessage.id,\n );\n messagesRef.current = nextMessages;\n setStagedMessages(\n stagedInputsRef.current.size > 0 ? nextMessages : null,\n );\n try {\n await agent.send({\n message: getEveMessageContent(input.message),\n });\n } catch (error) {\n stagedInputsRef.current.set(stagedMessage.id, input);\n messagesRef.current = previousMessages;\n setStagedMessages(previousMessages);\n throw error;\n }\n }\n },\n }\n : {}),\n onCancel: () => {\n agent.stop();\n return Promise.resolve();\n },\n onRespondToToolApproval: async (response) => {\n await agent.send({ inputResponses: [toEveInputResponse(response)] });\n },\n });\n};\n"],"mappings":";;;;;;;AAgCA,MAAM,qBAAqB;CACzB,MAAM;CACN,QAAQ;AACV;;;;;;;;AAyBA,MAAa,sBAAsB,UAAqC,CAAC,MAAM;CAC7E,MAAM,EACJ,UACA,YAAY,aACZ,gBAAgB,iBAChB,aAAa,cACb,uBAAuB,wBACvB,GAAG,iBACD;CAMJ,MAAM,QAAQ,YAAY,YAAY;CACtC,MAAM,kBAAkB,mBAAmB;CAC3C,MAAM,CAAC,cAAc,mBAAmB,SAEtC,CAAC,CAAC;CACJ,MAAM,CAAC,gBAAgB,qBAAqB,SAC1C,IACF;CACA,MAAM,0BAA0B,uBAAO,IAAI,IAAkB,CAAC;CAC9D,MAAM,kBAAkB,uBACtB,IAAI,IAGF,CACJ;CAEA,MA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AC7C,CAAC;IACH,SAAS,OAAO;KACd,gBAAgB,QAAQ,IAAI,cAAc,IAAI,KAAK;KACnD,YAAY,UAAU;KACtB,kBAAkB,gBAAgB;KAClC,MAAM;IACR;GACF;EACF,EACF,IACA,CAAC;EACL,gBAAgB;GACd,MAAM,KAAK;GACX,OAAO,QAAQ,QAAQ;EACzB;EACA,yBAAyB,OAAO,aAAa;GAC3C,MAAM,MAAM,KAAK,EAAE,gBAAgB,CAAC,mBAAmB,QAAQ,CAAC,EAAE,CAAC;EACrE;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"useEveAgentRuntime.js","names":[],"sources":["../src/useEveAgentRuntime.ts"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n fromThreadMessageLike,\n generateId,\n pickExternalStoreSharedOptions,\n type AppendMessage,\n type AttachmentAdapter,\n type DictationAdapter,\n type ExternalStoreSharedOptions,\n type FeedbackAdapter,\n type RealtimeVoiceAdapter,\n type SpeechSynthesisAdapter,\n type ThreadMessage,\n type ToolExecutionStatus,\n} from \"@assistant-ui/core\";\nimport {\n useExternalStoreRuntime,\n useRuntimeAdapters,\n} from \"@assistant-ui/core/react\";\nimport {\n useEveAgent,\n type EveMessageData,\n type UseEveAgentOptions,\n} from \"eve/react\";\nimport type { SendTurnPayload } from \"eve/client\";\nimport {\n convertEveMessages,\n getEveMessageContent,\n toEveInputResponse,\n} from \"./convertEveMessages\";\n\nconst USER_STAGED_STATUS = {\n type: \"complete\",\n reason: \"unknown\",\n} as const;\n\nconst hasRunConfig = (\n runConfig: AppendMessage[\"runConfig\"],\n): runConfig is NonNullable<AppendMessage[\"runConfig\"]> =>\n runConfig?.custom !== undefined && Object.keys(runConfig.custom).length > 0;\n\n/**\n * Only the `custom` bag crosses the wire. Eve reads `clientContext` as its own\n * namespace and serializes it into a model-visible context message, so sending\n * the assistant-ui envelope would surface a literal `\"custom\"` key in the\n * prompt and to every eve-side handler.\n */\nconst toEveClientContext = (\n runConfig: AppendMessage[\"runConfig\"],\n): Pick<SendTurnPayload, \"clientContext\"> =>\n hasRunConfig(runConfig)\n ? {\n clientContext: runConfig.custom as NonNullable<\n SendTurnPayload[\"clientContext\"]\n >,\n }\n : {};\n\nexport type UseEveAgentRuntimeOptions = Omit<\n UseEveAgentOptions<EveMessageData>,\n \"reducer\"\n> &\n ExternalStoreSharedOptions & {\n readonly adapters?:\n | {\n readonly attachments?: AttachmentAdapter | undefined;\n readonly speech?: SpeechSynthesisAdapter | undefined;\n readonly dictation?: DictationAdapter | undefined;\n readonly voice?: RealtimeVoiceAdapter | undefined;\n readonly feedback?: FeedbackAdapter | undefined;\n }\n | undefined;\n };\n\n/**\n * Connects Eve's `useEveAgent` hook to assistant-ui's runtime contract.\n *\n * The runtime renders Eve messages, forwards new user messages to the Eve\n * session, supports cancellation, and maps Eve input requests to assistant-ui\n * tool approval UI.\n */\nexport const useEveAgentRuntime = (options: UseEveAgentRuntimeOptions = {}) => {\n const {\n adapters,\n isDisabled: _isDisabled,\n isSendDisabled: _isSendDisabled,\n suggestions: _suggestions,\n unstable_capabilities: _unstable_capabilities,\n ...agentOptions\n } = options;\n true satisfies keyof typeof agentOptions &\n keyof ExternalStoreSharedOptions extends never\n ? true\n : never;\n\n const agent = useEveAgent(agentOptions);\n const runtimeAdapters = useRuntimeAdapters();\n const [toolStatuses, setToolStatuses] = useState<\n Record<string, ToolExecutionStatus>\n >({});\n const [stagedMessages, setStagedMessages] = useState<ThreadMessage[] | null>(\n null,\n );\n const createdAtByMessageIdRef = useRef(new Map<string, Date>());\n const stagedInputsRef = useRef(\n new Map<\n string,\n { message: AppendMessage; runConfig: AppendMessage[\"runConfig\"] }\n >(),\n );\n\n const hasExecutingTools = Object.values(toolStatuses).some(\n (status) => status?.type === \"executing\",\n );\n const isRunning =\n agent.status === \"submitted\" ||\n agent.status === \"streaming\" ||\n hasExecutingTools;\n\n const convertedMessages = useMemo(() => {\n const createdAtByMessageId = createdAtByMessageIdRef.current;\n const messageIds = new Set(\n agent.data.messages.map((message) => message.id),\n );\n for (const messageId of createdAtByMessageId.keys()) {\n if (!messageIds.has(messageId)) createdAtByMessageId.delete(messageId);\n }\n\n return convertEveMessages(agent.data, {\n isRunning,\n error: agent.error,\n getCreatedAt: (message) => {\n const existing = createdAtByMessageId.get(message.id);\n if (existing) return existing;\n\n const createdAt = new Date();\n createdAtByMessageId.set(message.id, createdAt);\n return createdAt;\n },\n });\n }, [agent.data, agent.error, isRunning]);\n\n const messages = stagedMessages ?? convertedMessages;\n const messagesRef = useRef(messages);\n messagesRef.current = messages;\n\n useEffect(() => {\n if (stagedInputsRef.current.size === 0) return;\n const baseIds = new Set(convertedMessages.map((message) => message.id));\n const remaining = messagesRef.current.filter(\n (message) =>\n stagedInputsRef.current.has(message.id) && !baseIds.has(message.id),\n );\n setStagedMessages(\n remaining.length > 0 ? [...convertedMessages, ...remaining] : null,\n );\n }, [convertedMessages]);\n\n const getStagedRun = (parentId: string | null) => {\n if (!parentId || !stagedInputsRef.current.has(parentId)) return null;\n const staged: {\n message: ThreadMessage;\n input: { message: AppendMessage; runConfig: AppendMessage[\"runConfig\"] };\n }[] = [];\n for (const message of messagesRef.current) {\n const input = stagedInputsRef.current.get(message.id);\n if (input) staged.push({ message, input });\n if (message.id === parentId) break;\n }\n return staged;\n };\n\n const stageUserMessage = (message: AppendMessage) => {\n const threadMessage = fromThreadMessageLike(\n message,\n generateId(),\n USER_STAGED_STATUS,\n );\n stagedInputsRef.current.set(threadMessage.id, {\n message,\n runConfig: message.runConfig,\n });\n const nextMessages = [...messagesRef.current, threadMessage];\n messagesRef.current = nextMessages;\n setStagedMessages(nextMessages);\n };\n\n return useExternalStoreRuntime({\n ...pickExternalStoreSharedOptions(options),\n messages,\n isRunning,\n unstable_enableToolInvocations: true,\n setToolStatuses,\n adapters: {\n attachments: adapters?.attachments ?? runtimeAdapters?.attachments,\n speech: adapters?.speech,\n dictation: adapters?.dictation,\n voice: adapters?.voice,\n feedback: adapters?.feedback,\n },\n onNew: async (message) => {\n if (!(message.startRun ?? message.role === \"user\")) {\n stageUserMessage(message);\n return;\n }\n await agent.send({\n message: getEveMessageContent(message),\n ...toEveClientContext(message.runConfig),\n });\n },\n ...(stagedMessages\n ? {\n onReload: async (parentId: string | null, config) => {\n const stagedRun = getStagedRun(parentId);\n if (!stagedRun)\n throw new Error(\"Runtime does not support reloading messages.\");\n for (const { message: stagedMessage, input } of stagedRun) {\n const previousMessages = messagesRef.current;\n stagedInputsRef.current.delete(stagedMessage.id);\n const nextMessages = previousMessages.filter(\n (message) => message.id !== stagedMessage.id,\n );\n messagesRef.current = nextMessages;\n setStagedMessages(\n stagedInputsRef.current.size > 0 ? nextMessages : null,\n );\n // The reload config belongs to the message being reloaded; the\n // drafts promoted ahead of it keep the config they were staged\n // with, or reloading the tail would rewrite their context too.\n const runConfig =\n stagedMessage.id === parentId && hasRunConfig(config.runConfig)\n ? config.runConfig\n : input.runConfig;\n try {\n await agent.send({\n message: getEveMessageContent(input.message),\n ...toEveClientContext(runConfig),\n });\n } catch (error) {\n stagedInputsRef.current.set(stagedMessage.id, input);\n messagesRef.current = previousMessages;\n setStagedMessages(previousMessages);\n throw error;\n }\n }\n },\n }\n : {}),\n onCancel: () => {\n agent.stop();\n return Promise.resolve();\n },\n onRespondToToolApproval: async (response) => {\n await agent.send({ inputResponses: [toEveInputResponse(response)] });\n },\n });\n};\n"],"mappings":";;;;;;;AAiCA,MAAM,qBAAqB;CACzB,MAAM;CACN,QAAQ;AACV;AAEA,MAAM,gBACJ,cAEA,WAAW,WAAW,KAAA,KAAa,OAAO,KAAK,UAAU,MAAM,CAAC,CAAC,SAAS;;;;;;;AAQ5E,MAAM,sBACJ,cAEA,aAAa,SAAS,IAClB,EACE,eAAe,UAAU,OAG3B,IACA,CAAC;;;;;;;;AAyBP,MAAa,sBAAsB,UAAqC,CAAC,MAAM;CAC7E,MAAM,EACJ,UACA,YAAY,aACZ,gBAAgB,iBAChB,aAAa,cACb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M,8CAA8C;GAChE,KAAK,MAAM,EAAE,SAAS,eAAe,WAAW,WAAW;IACzD,MAAM,mBAAmB,YAAY;IACrC,gBAAgB,QAAQ,OAAO,cAAc,EAAE;IAC/C,MAAM,eAAe,iBAAiB,QACnC,YAAY,QAAQ,OAAO,cAAc,EAC5C;IACA,YAAY,UAAU;IACtB,kBACE,gBAAgB,QAAQ,OAAO,IAAI,eAAe,IACpD;IAIA,MAAM,YACJ,cAAc,OAAO,YAAY,aAAa,OAAO,SAAS,IAC1D,OAAO,YACP,MAAM;IACZ,IAAI;KACF,MAAM,MAAM,KAAK;MACf,SAAS,qBAAqB,MAAM,OAAO;MAC3C,GAAG,mBAAmB,SAAS;KACjC,CAAC;IACH,SAAS,OAAO;KACd,gBAAgB,QAAQ,IAAI,cAAc,IAAI,KAAK;KACnD,YAAY,UAAU;KACtB,kBAAkB,gBAAgB;KAClC,MAAM;IACR;GACF;EACF,EACF,IACA,CAAC;EACL,gBAAgB;GACd,MAAM,KAAK;GACX,OAAO,QAAQ,QAAQ;EACzB;EACA,yBAAyB,OAAO,aAAa;GAC3C,MAAM,MAAM,KAAK,EAAE,gBAAgB,CAAC,mBAAmB,QAAQ,CAAC,EAAE,CAAC;EACrE;CACF,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/eve",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Eve runtime adapter for assistant-ui",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eve",
|
|
@@ -27,8 +27,13 @@
|
|
|
27
27
|
"README.md"
|
|
28
28
|
],
|
|
29
29
|
"sideEffects": false,
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "aui-build",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"test:watch": "vitest"
|
|
34
|
+
},
|
|
30
35
|
"dependencies": {
|
|
31
|
-
"@assistant-ui/core": "^0.3.
|
|
36
|
+
"@assistant-ui/core": "^0.3.7"
|
|
32
37
|
},
|
|
33
38
|
"peerDependencies": {
|
|
34
39
|
"@types/react": "*",
|
|
@@ -41,6 +46,7 @@
|
|
|
41
46
|
}
|
|
42
47
|
},
|
|
43
48
|
"devDependencies": {
|
|
49
|
+
"@assistant-ui/x-buildutils": "workspace:*",
|
|
44
50
|
"@testing-library/dom": "^10.4.1",
|
|
45
51
|
"@testing-library/react": "^16.3.2",
|
|
46
52
|
"@types/react": "^19.2.17",
|
|
@@ -48,8 +54,7 @@
|
|
|
48
54
|
"jsdom": "^29.1.1",
|
|
49
55
|
"react": "^19.2.8",
|
|
50
56
|
"react-dom": "^19.2.8",
|
|
51
|
-
"vitest": "^4.1.10"
|
|
52
|
-
"@assistant-ui/x-buildutils": "0.0.21"
|
|
57
|
+
"vitest": "^4.1.10"
|
|
53
58
|
},
|
|
54
59
|
"publishConfig": {
|
|
55
60
|
"access": "public",
|
|
@@ -63,10 +68,5 @@
|
|
|
63
68
|
},
|
|
64
69
|
"bugs": {
|
|
65
70
|
"url": "https://github.com/assistant-ui/assistant-ui/issues"
|
|
66
|
-
},
|
|
67
|
-
"scripts": {
|
|
68
|
-
"build": "aui-build",
|
|
69
|
-
"test": "vitest run",
|
|
70
|
-
"test:watch": "vitest"
|
|
71
71
|
}
|
|
72
|
-
}
|
|
72
|
+
}
|
|
@@ -90,6 +90,180 @@ describe("useEveAgentRuntime status forwarding", () => {
|
|
|
90
90
|
});
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
+
it("forwards runConfig to eve as one-turn client context when sending", async () => {
|
|
94
|
+
const agent = createAgent({
|
|
95
|
+
data: { messages: [] } satisfies EveMessageData,
|
|
96
|
+
});
|
|
97
|
+
mockUseEveAgent.mockReturnValue(agent as never);
|
|
98
|
+
|
|
99
|
+
const { result } = renderHook(() => useEveAgentRuntime());
|
|
100
|
+
|
|
101
|
+
act(() => {
|
|
102
|
+
result.current.thread.append({
|
|
103
|
+
role: "user",
|
|
104
|
+
content: [{ type: "text", text: "hello" }],
|
|
105
|
+
runConfig: { custom: { page: "/pricing" } },
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
await waitFor(() => {
|
|
110
|
+
expect(agent.send).toHaveBeenCalledWith({
|
|
111
|
+
message: "hello",
|
|
112
|
+
clientContext: { page: "/pricing" },
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("omits clientContext when no runConfig is provided", async () => {
|
|
118
|
+
const agent = createAgent({
|
|
119
|
+
data: { messages: [] } satisfies EveMessageData,
|
|
120
|
+
});
|
|
121
|
+
mockUseEveAgent.mockReturnValue(agent as never);
|
|
122
|
+
|
|
123
|
+
const { result } = renderHook(() => useEveAgentRuntime());
|
|
124
|
+
|
|
125
|
+
act(() => {
|
|
126
|
+
result.current.thread.append({
|
|
127
|
+
role: "user",
|
|
128
|
+
content: [{ type: "text", text: "hello" }],
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
await waitFor(() => {
|
|
133
|
+
expect(agent.send).toHaveBeenCalledWith({ message: "hello" });
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("omits clientContext when runConfig.custom is empty", async () => {
|
|
138
|
+
const agent = createAgent({
|
|
139
|
+
data: { messages: [] } satisfies EveMessageData,
|
|
140
|
+
});
|
|
141
|
+
mockUseEveAgent.mockReturnValue(agent as never);
|
|
142
|
+
|
|
143
|
+
const { result } = renderHook(() => useEveAgentRuntime());
|
|
144
|
+
|
|
145
|
+
act(() => {
|
|
146
|
+
result.current.thread.append({
|
|
147
|
+
role: "user",
|
|
148
|
+
content: [{ type: "text", text: "hello" }],
|
|
149
|
+
runConfig: { custom: {} },
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
await waitFor(() => {
|
|
154
|
+
expect(agent.send).toHaveBeenCalledWith({ message: "hello" });
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("prefers the reload-time runConfig over the staged one", async () => {
|
|
159
|
+
const agent = createAgent({
|
|
160
|
+
data: { messages: [] } satisfies EveMessageData,
|
|
161
|
+
});
|
|
162
|
+
mockUseEveAgent.mockReturnValue(agent as never);
|
|
163
|
+
|
|
164
|
+
const { result } = renderHook(() => useEveAgentRuntime());
|
|
165
|
+
|
|
166
|
+
act(() => {
|
|
167
|
+
result.current.thread.append({
|
|
168
|
+
role: "user",
|
|
169
|
+
content: [{ type: "text", text: "hello" }],
|
|
170
|
+
startRun: false,
|
|
171
|
+
runConfig: { custom: { page: "/staged" } },
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
await waitFor(() => {
|
|
176
|
+
expect(result.current.thread.getState().messages.length).toBe(1);
|
|
177
|
+
});
|
|
178
|
+
const stagedId = result.current.thread.getState().messages[0]!.id;
|
|
179
|
+
|
|
180
|
+
act(() => {
|
|
181
|
+
result.current.thread.startRun({
|
|
182
|
+
parentId: stagedId,
|
|
183
|
+
runConfig: { custom: { page: "/reload" } },
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
await waitFor(() => {
|
|
188
|
+
expect(agent.send).toHaveBeenCalledWith({
|
|
189
|
+
message: "hello",
|
|
190
|
+
clientContext: { page: "/reload" },
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("falls back to the staged runConfig when reload passes none", async () => {
|
|
196
|
+
const agent = createAgent({
|
|
197
|
+
data: { messages: [] } satisfies EveMessageData,
|
|
198
|
+
});
|
|
199
|
+
mockUseEveAgent.mockReturnValue(agent as never);
|
|
200
|
+
|
|
201
|
+
const { result } = renderHook(() => useEveAgentRuntime());
|
|
202
|
+
|
|
203
|
+
act(() => {
|
|
204
|
+
result.current.thread.append({
|
|
205
|
+
role: "user",
|
|
206
|
+
content: [{ type: "text", text: "hello" }],
|
|
207
|
+
startRun: false,
|
|
208
|
+
runConfig: { custom: { page: "/staged" } },
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
await waitFor(() => {
|
|
213
|
+
expect(result.current.thread.getState().messages.length).toBe(1);
|
|
214
|
+
});
|
|
215
|
+
const stagedId = result.current.thread.getState().messages[0]!.id;
|
|
216
|
+
|
|
217
|
+
act(() => {
|
|
218
|
+
result.current.thread.startRun({ parentId: stagedId });
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
await waitFor(() => {
|
|
222
|
+
expect(agent.send).toHaveBeenCalledWith({
|
|
223
|
+
message: "hello",
|
|
224
|
+
clientContext: { page: "/staged" },
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// Known limitation: core normalizes an omitted reload runConfig to {}
|
|
230
|
+
// (toStartRunConfig in core/src/runtime/api/thread-runtime.ts), so an
|
|
231
|
+
// explicit empty reload config is indistinguishable from an omitted one at
|
|
232
|
+
// the adapter and cannot clear the staged context.
|
|
233
|
+
it("cannot clear the staged runConfig with an explicit empty reload config", async () => {
|
|
234
|
+
const agent = createAgent({
|
|
235
|
+
data: { messages: [] } satisfies EveMessageData,
|
|
236
|
+
});
|
|
237
|
+
mockUseEveAgent.mockReturnValue(agent as never);
|
|
238
|
+
|
|
239
|
+
const { result } = renderHook(() => useEveAgentRuntime());
|
|
240
|
+
|
|
241
|
+
act(() => {
|
|
242
|
+
result.current.thread.append({
|
|
243
|
+
role: "user",
|
|
244
|
+
content: [{ type: "text", text: "hello" }],
|
|
245
|
+
startRun: false,
|
|
246
|
+
runConfig: { custom: { page: "/staged" } },
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
await waitFor(() => {
|
|
251
|
+
expect(result.current.thread.getState().messages.length).toBe(1);
|
|
252
|
+
});
|
|
253
|
+
const stagedId = result.current.thread.getState().messages[0]!.id;
|
|
254
|
+
|
|
255
|
+
act(() => {
|
|
256
|
+
result.current.thread.startRun({ parentId: stagedId, runConfig: {} });
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
await waitFor(() => {
|
|
260
|
+
expect(agent.send).toHaveBeenCalledWith({
|
|
261
|
+
message: "hello",
|
|
262
|
+
clientContext: { page: "/staged" },
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|
|
93
267
|
it("keeps the last assistant message running while streaming", () => {
|
|
94
268
|
mockUseEveAgent.mockReturnValue(
|
|
95
269
|
createAgent({ status: "streaming" }) as never,
|
|
@@ -284,6 +458,46 @@ describe("useEveAgentRuntime staged messages", () => {
|
|
|
284
458
|
});
|
|
285
459
|
});
|
|
286
460
|
|
|
461
|
+
it("applies the reload runConfig only to the message being reloaded", async () => {
|
|
462
|
+
const agent = createAgent({ data: settledData });
|
|
463
|
+
mockUseEveAgent.mockReturnValue(agent as never);
|
|
464
|
+
const { result } = renderHook(() => useEveAgentRuntime());
|
|
465
|
+
|
|
466
|
+
const stageWithConfig = async (text: string, page: string) => {
|
|
467
|
+
await act(async () => {
|
|
468
|
+
result.current.thread.append({
|
|
469
|
+
role: "user",
|
|
470
|
+
content: [{ type: "text", text }],
|
|
471
|
+
startRun: false,
|
|
472
|
+
runConfig: { custom: { page } },
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
await stageWithConfig("first staged", "/first");
|
|
478
|
+
await stageWithConfig("second staged", "/second");
|
|
479
|
+
|
|
480
|
+
const secondStagedId = result.current.thread.getState().messages[3]!.id;
|
|
481
|
+
await act(async () => {
|
|
482
|
+
await result.current.thread.startRun({
|
|
483
|
+
parentId: secondStagedId,
|
|
484
|
+
sourceId: null,
|
|
485
|
+
runConfig: { custom: { page: "/reloaded" } },
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
// the earlier draft keeps the context it was staged with; only the
|
|
490
|
+
// reloaded message takes the reload-time config
|
|
491
|
+
expect(agent.send).toHaveBeenNthCalledWith(1, {
|
|
492
|
+
message: "first staged",
|
|
493
|
+
clientContext: { page: "/first" },
|
|
494
|
+
});
|
|
495
|
+
expect(agent.send).toHaveBeenNthCalledWith(2, {
|
|
496
|
+
message: "second staged",
|
|
497
|
+
clientContext: { page: "/reloaded" },
|
|
498
|
+
});
|
|
499
|
+
});
|
|
500
|
+
|
|
287
501
|
it("keeps later staged messages visible after promoting one staged parent", async () => {
|
|
288
502
|
const agent = createAgent({ data: settledData });
|
|
289
503
|
mockUseEveAgent.mockReturnValue(agent as never);
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
type EveMessageData,
|
|
25
25
|
type UseEveAgentOptions,
|
|
26
26
|
} from "eve/react";
|
|
27
|
+
import type { SendTurnPayload } from "eve/client";
|
|
27
28
|
import {
|
|
28
29
|
convertEveMessages,
|
|
29
30
|
getEveMessageContent,
|
|
@@ -35,6 +36,28 @@ const USER_STAGED_STATUS = {
|
|
|
35
36
|
reason: "unknown",
|
|
36
37
|
} as const;
|
|
37
38
|
|
|
39
|
+
const hasRunConfig = (
|
|
40
|
+
runConfig: AppendMessage["runConfig"],
|
|
41
|
+
): runConfig is NonNullable<AppendMessage["runConfig"]> =>
|
|
42
|
+
runConfig?.custom !== undefined && Object.keys(runConfig.custom).length > 0;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Only the `custom` bag crosses the wire. Eve reads `clientContext` as its own
|
|
46
|
+
* namespace and serializes it into a model-visible context message, so sending
|
|
47
|
+
* the assistant-ui envelope would surface a literal `"custom"` key in the
|
|
48
|
+
* prompt and to every eve-side handler.
|
|
49
|
+
*/
|
|
50
|
+
const toEveClientContext = (
|
|
51
|
+
runConfig: AppendMessage["runConfig"],
|
|
52
|
+
): Pick<SendTurnPayload, "clientContext"> =>
|
|
53
|
+
hasRunConfig(runConfig)
|
|
54
|
+
? {
|
|
55
|
+
clientContext: runConfig.custom as NonNullable<
|
|
56
|
+
SendTurnPayload["clientContext"]
|
|
57
|
+
>,
|
|
58
|
+
}
|
|
59
|
+
: {};
|
|
60
|
+
|
|
38
61
|
export type UseEveAgentRuntimeOptions = Omit<
|
|
39
62
|
UseEveAgentOptions<EveMessageData>,
|
|
40
63
|
"reducer"
|
|
@@ -182,11 +205,14 @@ export const useEveAgentRuntime = (options: UseEveAgentRuntimeOptions = {}) => {
|
|
|
182
205
|
stageUserMessage(message);
|
|
183
206
|
return;
|
|
184
207
|
}
|
|
185
|
-
await agent.send({
|
|
208
|
+
await agent.send({
|
|
209
|
+
message: getEveMessageContent(message),
|
|
210
|
+
...toEveClientContext(message.runConfig),
|
|
211
|
+
});
|
|
186
212
|
},
|
|
187
213
|
...(stagedMessages
|
|
188
214
|
? {
|
|
189
|
-
onReload: async (parentId: string | null) => {
|
|
215
|
+
onReload: async (parentId: string | null, config) => {
|
|
190
216
|
const stagedRun = getStagedRun(parentId);
|
|
191
217
|
if (!stagedRun)
|
|
192
218
|
throw new Error("Runtime does not support reloading messages.");
|
|
@@ -200,9 +226,17 @@ export const useEveAgentRuntime = (options: UseEveAgentRuntimeOptions = {}) => {
|
|
|
200
226
|
setStagedMessages(
|
|
201
227
|
stagedInputsRef.current.size > 0 ? nextMessages : null,
|
|
202
228
|
);
|
|
229
|
+
// The reload config belongs to the message being reloaded; the
|
|
230
|
+
// drafts promoted ahead of it keep the config they were staged
|
|
231
|
+
// with, or reloading the tail would rewrite their context too.
|
|
232
|
+
const runConfig =
|
|
233
|
+
stagedMessage.id === parentId && hasRunConfig(config.runConfig)
|
|
234
|
+
? config.runConfig
|
|
235
|
+
: input.runConfig;
|
|
203
236
|
try {
|
|
204
237
|
await agent.send({
|
|
205
238
|
message: getEveMessageContent(input.message),
|
|
239
|
+
...toEveClientContext(runConfig),
|
|
206
240
|
});
|
|
207
241
|
} catch (error) {
|
|
208
242
|
stagedInputsRef.current.set(stagedMessage.id, input);
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 AgentbaseAI Inc.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|