@nexface/chat 0.1.14 → 0.1.15-alpha.0

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 (129) hide show
  1. package/dist/assistant-attachments.js +17 -60
  2. package/dist/assistant-attachments.js.map +1 -0
  3. package/dist/assistant-components.d.ts +3 -3
  4. package/dist/assistant-components.js +29 -77
  5. package/dist/assistant-components.js.map +1 -0
  6. package/dist/assistant-runtime.d.ts +1 -1
  7. package/dist/assistant-runtime.js +43 -100
  8. package/dist/assistant-runtime.js.map +1 -0
  9. package/dist/attachments.js +15 -36
  10. package/dist/attachments.js.map +1 -0
  11. package/dist/client.js +73 -312
  12. package/dist/client.js.map +1 -0
  13. package/dist/config.d.ts +1 -1
  14. package/dist/config.js +5 -4
  15. package/dist/config.js.map +1 -0
  16. package/dist/default-chat.d.ts +1 -1
  17. package/dist/default-chat.js +728 -2102
  18. package/dist/default-chat.js.map +7 -0
  19. package/dist/errors.js +18 -55
  20. package/dist/errors.js.map +1 -0
  21. package/dist/index.js +1 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/messages.js +1 -0
  24. package/dist/messages.js.map +1 -0
  25. package/dist/page-confirmation.js +4 -3
  26. package/dist/page-confirmation.js.map +1 -0
  27. package/dist/protocol-messages.js +66 -290
  28. package/dist/protocol-messages.js.map +1 -0
  29. package/dist/protocol-response.js +18 -38
  30. package/dist/protocol-response.js.map +1 -0
  31. package/dist/react.js +50 -146
  32. package/dist/react.js.map +1 -0
  33. package/dist/shared/errors.d.ts +1 -1
  34. package/dist/shared/errors.js +1 -0
  35. package/dist/shared/errors.js.map +1 -0
  36. package/dist/shared/runtime-controller.d.ts +0 -1
  37. package/dist/shared/runtime-controller.js +1 -0
  38. package/dist/shared/runtime-controller.js.map +1 -0
  39. package/dist/shared/runtime-execution.js +1 -0
  40. package/dist/shared/runtime-execution.js.map +1 -0
  41. package/dist/shared/schema.js +19 -45
  42. package/dist/shared/schema.js.map +1 -0
  43. package/dist/storage.js +53 -130
  44. package/dist/storage.js.map +1 -0
  45. package/dist/styles.css +20 -99
  46. package/dist/tool-result.js +3 -7
  47. package/dist/tool-result.js.map +1 -0
  48. package/dist/types.js +1 -0
  49. package/dist/types.js.map +1 -0
  50. package/dist/ui/attachment.aui.d.ts +1 -1
  51. package/dist/ui/attachment.aui.js +20 -16
  52. package/dist/ui/attachment.aui.js.map +1 -0
  53. package/dist/ui/avatar.js +1 -0
  54. package/dist/ui/avatar.js.map +1 -0
  55. package/dist/ui/button.js +1 -0
  56. package/dist/ui/button.js.map +1 -0
  57. package/dist/ui/code-block.js +3 -2
  58. package/dist/ui/code-block.js.map +1 -0
  59. package/dist/ui/collapsible.js +3 -2
  60. package/dist/ui/collapsible.js.map +1 -0
  61. package/dist/ui/composer-voice.js +2 -3
  62. package/dist/ui/composer-voice.js.map +1 -0
  63. package/dist/ui/dialog.d.ts +1 -1
  64. package/dist/ui/dialog.js +4 -9
  65. package/dist/ui/dialog.js.map +1 -0
  66. package/dist/ui/dropdown-menu.js +3 -2
  67. package/dist/ui/dropdown-menu.js.map +1 -0
  68. package/dist/ui/home-demo/action-bar.js +1 -0
  69. package/dist/ui/home-demo/action-bar.js.map +1 -0
  70. package/dist/ui/home-demo/composer.js +4 -7
  71. package/dist/ui/home-demo/composer.js.map +1 -0
  72. package/dist/ui/home-demo/greeting.d.ts +1 -1
  73. package/dist/ui/home-demo/greeting.js +2 -1
  74. package/dist/ui/home-demo/greeting.js.map +1 -0
  75. package/dist/ui/home-demo/messages.d.ts +1 -1
  76. package/dist/ui/home-demo/messages.js +5 -4
  77. package/dist/ui/home-demo/messages.js.map +1 -0
  78. package/dist/ui/home-demo/styles.js +1 -0
  79. package/dist/ui/home-demo/styles.js.map +1 -0
  80. package/dist/ui/home-demo/suggestions.d.ts +1 -1
  81. package/dist/ui/home-demo/suggestions.js +3 -5
  82. package/dist/ui/home-demo/suggestions.js.map +1 -0
  83. package/dist/ui/home-demo/surfaces.js +2 -3
  84. package/dist/ui/home-demo/surfaces.js.map +1 -0
  85. package/dist/ui/home-demo/thread.d.ts +1 -1
  86. package/dist/ui/home-demo/thread.js +2 -1
  87. package/dist/ui/home-demo/thread.js.map +1 -0
  88. package/dist/ui/home-demo/trace-line.d.ts +1 -1
  89. package/dist/ui/home-demo/trace-line.js +3 -2
  90. package/dist/ui/home-demo/trace-line.js.map +1 -0
  91. package/dist/ui/home-demo/trace.d.ts +1 -1
  92. package/dist/ui/home-demo/trace.js +9 -28
  93. package/dist/ui/home-demo/trace.js.map +1 -0
  94. package/dist/ui/home-demo/type.js +1 -0
  95. package/dist/ui/home-demo/type.js.map +1 -0
  96. package/dist/ui/input.js +1 -0
  97. package/dist/ui/input.js.map +1 -0
  98. package/dist/ui/markdown-text.js +3 -2
  99. package/dist/ui/markdown-text.js.map +1 -0
  100. package/dist/ui/reasoning.aui.js +3 -2
  101. package/dist/ui/reasoning.aui.js.map +1 -0
  102. package/dist/ui/reasoning.d.ts +1 -1
  103. package/dist/ui/reasoning.js +9 -6
  104. package/dist/ui/reasoning.js.map +1 -0
  105. package/dist/ui/surface.js +8 -27
  106. package/dist/ui/surface.js.map +1 -0
  107. package/dist/ui/thread-list.aui.d.ts +2 -2
  108. package/dist/ui/thread-list.aui.js +12 -18
  109. package/dist/ui/thread-list.aui.js.map +1 -0
  110. package/dist/ui/tool-group.aui.js +3 -2
  111. package/dist/ui/tool-group.aui.js.map +1 -0
  112. package/dist/ui/tooltip-icon-button.js +2 -1
  113. package/dist/ui/tooltip-icon-button.js.map +1 -0
  114. package/dist/ui/tooltip.js +1 -0
  115. package/dist/ui/tooltip.js.map +1 -0
  116. package/dist/ui/use-attachment-src.js +2 -1
  117. package/dist/ui/use-attachment-src.js.map +1 -0
  118. package/dist/ui/use-copy-to-clipboard.d.ts +1 -1
  119. package/dist/ui/use-copy-to-clipboard.js +2 -1
  120. package/dist/ui/use-copy-to-clipboard.js.map +1 -0
  121. package/dist/ui/utils.js +3 -9
  122. package/dist/ui/utils.js.map +1 -0
  123. package/dist/use-next-message.js +4 -7
  124. package/dist/use-next-message.js.map +1 -0
  125. package/dist/voice/types.js +1 -0
  126. package/dist/voice/types.js.map +1 -0
  127. package/dist/voice/use-voice.js +13 -35
  128. package/dist/voice/use-voice.js.map +1 -0
  129. package/package.json +4 -8
@@ -1,22 +1,17 @@
1
1
  export function decodeAgentResponse(messages, snapshot, terminal) {
2
2
  const state = snapshot;
3
3
  const continuation = state?.nexface;
4
- if (!continuation ||
5
- continuation.version !== 3 ||
6
- continuation.threadId !== terminal.threadId ||
7
- !Array.isArray(continuation.timeline)) {
4
+ if (!continuation || continuation.version !== 3 || continuation.threadId !== terminal.threadId || !Array.isArray(continuation.timeline)) {
8
5
  throw new Error("Invalid Agent recovery state or protocol version. Upgrade client and server together and start a new conversation.");
9
6
  }
10
7
  const legacy = new Set(["callAppTool", "getSnapshot", "executeCode", "loadSkill", "finish"]);
11
- if (messages.some((message) => message.role === "assistant" &&
12
- message.toolCalls?.some((call) => legacy.has(call.function.name))) ||
13
- continuation.pending?.calls?.some((call) => legacy.has(call.name)))
8
+ if (messages.some((message) => message.role === "assistant" && message.toolCalls?.some((call) => legacy.has(call.function.name)))
9
+ || continuation.pending?.calls?.some((call) => legacy.has(call.name)))
14
10
  throw new Error("Unsupported legacy tool history. Start a new conversation.");
15
11
  const history = messages.filter((message) => message.role !== "activity" && message.role !== "reasoning");
16
12
  const references = continuation.timeline.flatMap((entry) => {
17
13
  if (entry && "internal" in entry) {
18
- if ("messageId" in entry ||
19
- (entry.internal?.role !== "system" && entry.internal?.role !== "application_context"))
14
+ if ("messageId" in entry || (entry.internal?.role !== "system" && entry.internal?.role !== "application_context"))
20
15
  throw new Error("Invalid internal history reference.");
21
16
  return [];
22
17
  }
@@ -24,9 +19,8 @@ export function decodeAgentResponse(messages, snapshot, terminal) {
24
19
  throw new Error("Invalid Agent history reference.");
25
20
  return [entry.messageId];
26
21
  });
27
- if (new Set(messages.map((message) => message.id)).size !== messages.length ||
28
- references.length !== history.length ||
29
- references.some((id, index) => id !== history[index].id)) {
22
+ if (new Set(messages.map((message) => message.id)).size !== messages.length
23
+ || references.length !== history.length || references.some((id, index) => id !== history[index].id)) {
30
24
  throw new Error("Agent messages and recovery state do not match.");
31
25
  }
32
26
  const outcome = terminal.outcome;
@@ -41,27 +35,18 @@ export function decodeAgentResponse(messages, snapshot, terminal) {
41
35
  const interrupt = outcome.interrupts[0];
42
36
  const extension = interrupt.metadata?.nexface;
43
37
  const call = pending?.calls?.[0];
44
- if (!extension ||
45
- !pending ||
46
- !Array.isArray(pending.calls) ||
47
- !call ||
48
- pending.interruptId !== interrupt.id ||
49
- interrupt.toolCallId !== call.id ||
50
- pending.kind !== extension.kind) {
38
+ if (!extension || !pending || !Array.isArray(pending.calls) || !call
39
+ || pending.interruptId !== interrupt.id || interrupt.toolCallId !== call.id || pending.kind !== extension.kind) {
51
40
  throw new Error("Invalid remote interrupt.");
52
41
  }
53
- const ownerIndex = history.reduce((last, message, index) => (message.role === "assistant" ? index : last), -1);
42
+ const ownerIndex = history.reduce((last, message, index) => message.role === "assistant" ? index : last, -1);
54
43
  const owner = history[ownerIndex];
55
- const calls = owner?.role === "assistant" ? (owner.toolCalls ?? []) : [];
44
+ const calls = owner?.role === "assistant" ? owner.toolCalls ?? [] : [];
56
45
  const first = calls.findIndex((item) => item.id === call.id);
57
- if (first < 0 ||
58
- calls.length - first !== pending.calls.length ||
59
- pending.calls.some((item, index) => item.id !== calls[first + index].id ||
60
- item.name !== calls[first + index].function.name ||
61
- item.arguments !== calls[first + index].function.arguments) ||
62
- history
63
- .slice(ownerIndex + 1)
64
- .some((message) => message.role === "tool" && pending.calls.some((item) => item.id === message.toolCallId))) {
46
+ if (first < 0 || calls.length - first !== pending.calls.length
47
+ || pending.calls.some((item, index) => item.id !== calls[first + index].id
48
+ || item.name !== calls[first + index].function.name || item.arguments !== calls[first + index].function.arguments)
49
+ || history.slice(ownerIndex + 1).some((message) => message.role === "tool" && pending.calls.some((item) => item.id === message.toolCallId))) {
65
50
  throw new Error("Pending calls do not match their assistant message.");
66
51
  }
67
52
  const args = JSON.parse(call.arguments);
@@ -69,21 +54,16 @@ export function decodeAgentResponse(messages, snapshot, terminal) {
69
54
  throw new Error("Invalid pending tool arguments.");
70
55
  const input = args;
71
56
  const name = call.name === "nxf_callAppTool" ? input.name : call.name;
72
- const toolInput = call.name === "nxf_callAppTool"
73
- ? input.input
74
- : Object.fromEntries(Object.entries(input).filter(([key]) => key !== "progressLabel"));
57
+ const toolInput = call.name === "nxf_callAppTool" ? input.input : Object.fromEntries(Object.entries(input).filter(([key]) => key !== "progressLabel"));
75
58
  if (extension.kind !== "client-tool-execution")
76
59
  throw new Error("Unsupported remote interrupt.");
77
60
  const action = extension.action;
78
- if (!action ||
79
- action.toolCallId !== call.id ||
80
- name !== action.definition?.name ||
81
- JSON.stringify(toolInput) !== JSON.stringify(action.input)) {
61
+ if (!action || action.toolCallId !== call.id || name !== action.definition?.name || JSON.stringify(toolInput) !== JSON.stringify(action.input)) {
82
62
  throw new Error("Browser action does not match its original call.");
83
63
  }
84
- if (action.pageDecision !== undefined &&
85
- (action.pageDecision !== true || name !== "nxf_getSnapshot")) {
64
+ if (action.pageDecision !== undefined && (action.pageDecision !== true || name !== "nxf_getSnapshot")) {
86
65
  throw new Error("Invalid page decision observation context.");
87
66
  }
88
67
  return { type: "client-tool-execution", interruptId: interrupt.id, action };
89
68
  }
69
+ //# sourceMappingURL=protocol-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol-response.js","sourceRoot":"","sources":["../src/protocol-response.ts"],"names":[],"mappings":"AAuCA,MAAM,UAAU,mBAAmB,CACjC,QAA4B,EAC5B,QAAiB,EACjB,QAA0B;IAE1B,MAAM,KAAK,GAAG,QAAqC,CAAC;IACpD,MAAM,YAAY,GAAG,KAAK,EAAE,OAAO,CAAC;IACpC,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,OAAO,KAAK,CAAC,IAAI,YAAY,C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,EAAE,CAAC,GAAG,KAAK,eAAe,CAAC,CAAC,CAAC;IACvJ,IAAI,SAAS,CAAC,IAAI,KAAK,uBAAuB;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACjG,MAAM,MAAM,GAAG,SAAS,CAAC,MAAwC,CAAC;IAClE,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,UAAU,KAAK,IAAI,CAAC,EAAE,IAAI,IAAI,KAAK,MAAM,CAAC,UAAU,EAAE,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/I,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,YAAY,KAAK,IAAI,IAAI,IAAI,KAAK,iBAAiB,CAAC,EAAE,CAAC;QACtG,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,uBAAuB,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC;AAC9E,CAAC","sourcesContent":["import type { Message, RunFinishedEvent } from \"@ag-ui/core\";\nimport type { AgentRunResult } from \"@nexface/agent\";\n\nimport type { AgentToolDefinition } from \"@nexface/tools\";\n\nexport interface BrowserToolResult {\n readonly toolCallId: string;\n readonly result?: unknown;\n readonly error?: { readonly code: string; readonly message: string };\n // Approval was handled for this call; this does not imply acceptance.\n readonly confirmed?: boolean;\n}\n\nexport interface AgentBrowserAction {\n readonly toolCallId: string;\n readonly definition: AgentToolDefinition<any, any>;\n readonly input: unknown;\n readonly progressLabel?: string;\n readonly pageDecision?: boolean;\n}\n\n// Only the response fields needed to validate a client handoff belong here.\ninterface ResponseState {\n nexface: {\n version: number;\n threadId: string;\n timeline: Array<{ messageId: string } | { internal: { role: string } }>;\n pending?: {\n kind: string;\n interruptId: string;\n calls: Array<{ id: string; name: string; arguments: string }>;\n };\n };\n}\n\ntype AgentResponse =\n | { type: \"success\"; result: Extract<AgentRunResult, { outcome: { type: \"success\" } }> }\n | { type: \"client-tool-execution\"; interruptId: string; action: AgentBrowserAction };\n\nexport function decodeAgentResponse(\n messages: readonly Message[],\n snapshot: unknown,\n terminal: RunFinishedEvent,\n): AgentResponse {\n const state = snapshot as ResponseState | undefined;\n const continuation = state?.nexface;\n if (!continuation || continuation.version !== 3 || continuation.threadId !== terminal.threadId || !Array.isArray(continuation.timeline)) {\n throw new Error(\"Invalid Agent recovery state or protocol version. Upgrade client and server together and start a new conversation.\");\n }\n const legacy = new Set([\"callAppTool\", \"getSnapshot\", \"executeCode\", \"loadSkill\", \"finish\"]);\n if (messages.some((message) => message.role === \"assistant\" && message.toolCalls?.some((call) => legacy.has(call.function.name)))\n || continuation.pending?.calls?.some((call) => legacy.has(call.name))) throw new Error(\"Unsupported legacy tool history. Start a new conversation.\");\n const history = messages.filter((message) => message.role !== \"activity\" && message.role !== \"reasoning\");\n const references = continuation.timeline.flatMap((entry) => {\n if (entry && \"internal\" in entry) {\n if (\"messageId\" in entry || (entry.internal?.role !== \"system\" && entry.internal?.role !== \"application_context\")) throw new Error(\"Invalid internal history reference.\");\n return [];\n }\n if (!entry || !(\"messageId\" in entry) || typeof entry.messageId !== \"string\") throw new Error(\"Invalid Agent history reference.\");\n return [entry.messageId];\n });\n if (new Set(messages.map((message) => message.id)).size !== messages.length\n || references.length !== history.length || references.some((id, index) => id !== history[index]!.id)) {\n throw new Error(\"Agent messages and recovery state do not match.\");\n }\n const outcome = terminal.outcome;\n const pending = continuation.pending;\n if (outcome?.type === \"success\") {\n if (typeof terminal.result?.output !== \"string\" || pending) throw new Error(\"Invalid completion output or pending state.\");\n return { type: \"success\", result: { outcome, output: terminal.result.output } };\n }\n if (outcome?.type !== \"interrupt\" || outcome.interrupts.length !== 1) throw new Error(\"Invalid remote interrupt.\");\n const interrupt = outcome.interrupts[0]!;\n const extension = interrupt.metadata?.nexface;\n const call = pending?.calls?.[0];\n if (!extension || !pending || !Array.isArray(pending.calls) || !call\n || pending.interruptId !== interrupt.id || interrupt.toolCallId !== call.id || pending.kind !== extension.kind) {\n throw new Error(\"Invalid remote interrupt.\");\n }\n const ownerIndex = history.reduce((last, message, index) => message.role === \"assistant\" ? index : last, -1);\n const owner = history[ownerIndex];\n const calls = owner?.role === \"assistant\" ? owner.toolCalls ?? [] : [];\n const first = calls.findIndex((item) => item.id === call.id);\n if (first < 0 || calls.length - first !== pending.calls.length\n || pending.calls.some((item, index) => item.id !== calls[first + index]!.id\n || item.name !== calls[first + index]!.function.name || item.arguments !== calls[first + index]!.function.arguments)\n || history.slice(ownerIndex + 1).some((message) => message.role === \"tool\" && pending.calls.some((item) => item.id === message.toolCallId))) {\n throw new Error(\"Pending calls do not match their assistant message.\");\n }\n const args: unknown = JSON.parse(call.arguments);\n if (!args || typeof args !== \"object\" || Array.isArray(args)) throw new Error(\"Invalid pending tool arguments.\");\n const input = args as Record<string, unknown>;\n const name = call.name === \"nxf_callAppTool\" ? input.name : call.name;\n const toolInput = call.name === \"nxf_callAppTool\" ? input.input : Object.fromEntries(Object.entries(input).filter(([key]) => key !== \"progressLabel\"));\n if (extension.kind !== \"client-tool-execution\") throw new Error(\"Unsupported remote interrupt.\");\n const action = extension.action as AgentBrowserAction | undefined;\n if (!action || action.toolCallId !== call.id || name !== action.definition?.name || JSON.stringify(toolInput) !== JSON.stringify(action.input)) {\n throw new Error(\"Browser action does not match its original call.\");\n }\n if (action.pageDecision !== undefined && (action.pageDecision !== true || name !== \"nxf_getSnapshot\")) {\n throw new Error(\"Invalid page decision observation context.\");\n }\n return { type: \"client-tool-execution\", interruptId: interrupt.id, action };\n}\n"]}
package/dist/react.js CHANGED
@@ -1,17 +1,14 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext, useContext, useEffect, useLayoutEffect, useRef, useReducer, useCallback, } from "react";
2
+ import { createContext, useContext, useEffect, useLayoutEffect, useRef, useReducer, useCallback } from "react";
3
3
  import { ToolsProvider } from "@nexface/tools";
4
- import { PageConfirmationProvider, } from "./page-confirmation.js";
5
- import { createChatClient, getClientController, ClientError, } from "./client.js";
4
+ import { PageConfirmationProvider } from "./page-confirmation.js";
5
+ import { createChatClient, getClientController, ClientError } from "./client.js";
6
6
  import { attachmentContent } from "./attachments.js";
7
7
  import { projectMessages } from "./protocol-messages.js";
8
8
  import { chatStorageKey, readChatStorage, writeChatStorage } from "./storage.js";
9
9
  export function isChatError(error) {
10
10
  const value = error;
11
- return (!!value &&
12
- value.type === "chat_error" &&
13
- typeof value.code === "string" &&
14
- typeof value.message === "string");
11
+ return !!value && value.type === "chat_error" && typeof value.code === "string" && typeof value.message === "string";
15
12
  }
16
13
  const sendGuards = new WeakMap();
17
14
  // Read the live Store at draft submission, including updates before React commits.
@@ -20,32 +17,21 @@ export function assertChatSendable(chat, sessionId) {
20
17
  }
21
18
  const ChatContext = createContext(null);
22
19
  const createId = () => globalThis.crypto.randomUUID();
23
- const textOf = (message) => message.parts
24
- .filter((part) => part.type === "text")
25
- .map((part) => part.text)
26
- .join("");
20
+ const textOf = (message) => message.parts.filter((part) => part.type === "text").map((part) => part.text).join("");
27
21
  const asError = (error) => {
28
22
  if (isChatError(error))
29
23
  return error;
30
24
  const value = error;
31
- return new ClientError(typeof value?.code === "string"
32
- ? value.code
33
- : typeof value?.name === "string"
34
- ? value.name
35
- : "CHAT_RUN_ERROR", typeof value?.message === "string" ? value.message : String(error));
25
+ return new ClientError(typeof value?.code === "string" ? value.code : typeof value?.name === "string" ? value.name : "CHAT_RUN_ERROR", typeof value?.message === "string" ? value.message : String(error));
36
26
  };
37
27
  export function NexfaceProvider(props) {
38
28
  const { toolRuntime, children, webMcp = true } = props;
39
29
  const onError = useRef(props.onError);
40
- useLayoutEffect(() => {
41
- onError.current = props.onError;
42
- });
30
+ useLayoutEffect(() => { onError.current = props.onError; });
43
31
  const runtime = useRef(toolRuntime);
44
32
  if (runtime.current !== toolRuntime)
45
33
  throw new ClientError("CHAT_RUNTIME_CHANGED", "NexfaceProvider requires a stable ToolRuntime. Remount it to change Runtime.");
46
- if (Boolean(props.agent) === Boolean(props.run) ||
47
- (props.agent &&
48
- ("toolRuntime" in props.agent || "toolBridge" in props.agent || "run" in props.agent)))
34
+ if (Boolean(props.agent) === Boolean(props.run) || (props.agent && ("toolRuntime" in props.agent || "toolBridge" in props.agent || "run" in props.agent)))
49
35
  throw new ClientError("INVALID_INPUT", "Provide exactly one agent configuration or run function.");
50
36
  const pageTools = useRef(new Set());
51
37
  const [, render] = useReducer((n) => n + 1, 0);
@@ -54,57 +40,29 @@ export function NexfaceProvider(props) {
54
40
  const changed = useCallback(() => render(), []);
55
41
  const createSessionValue = useCallback((saved) => {
56
42
  const current = props;
57
- const client = createChatClient({
58
- ...(current.run
59
- ? { toolRuntime, run: current.run }
60
- : { toolRuntime, agent: current.agent }),
61
- onError: (event) => onError.current?.(event),
62
- });
43
+ const client = createChatClient({ ...(current.run ? { toolRuntime, run: current.run } : { toolRuntime, agent: current.agent }), onError: (event) => onError.current?.(event) });
63
44
  const controller = getClientController(client);
64
45
  if (saved)
65
46
  controller.id = saved.id;
66
47
  controller.setPageResolver((name) => pageTools.current.has(name));
67
48
  if (saved)
68
49
  controller.restore(saved.messages);
69
- return {
70
- id: saved?.id ?? controller.id,
71
- client,
72
- ...(saved?.title ? { title: saved.title } : {}),
73
- unsubscribe: client.subscribe(changed),
74
- };
50
+ return { id: saved?.id ?? controller.id, client, ...(saved?.title ? { title: saved.title } : {}), unsubscribe: client.subscribe(changed) };
75
51
  }, [props.agent, props.run, toolRuntime, changed]);
76
52
  if (!storeRef.current) {
77
53
  const first = createSessionValue();
78
- storeRef.current = {
79
- sessions: [first],
80
- activeId: first.id,
81
- loaded: false,
82
- switching: false,
83
- version: { value: null },
84
- };
54
+ storeRef.current = { sessions: [first], activeId: first.id, loaded: false, switching: false, version: { value: null } };
85
55
  }
86
56
  const store = storeRef.current;
87
57
  const active = () => store.sessions.find((session) => session.id === store.activeId);
88
- const find = (id) => {
89
- const session = store.sessions.find((item) => item.id === id);
90
- if (!session)
91
- throw new ClientError("UNKNOWN_SESSION", "Unknown chat session.");
92
- return session;
93
- };
94
- const busy = () => store.switching ||
95
- store.sessions.some((session) => getClientController(session.client).busy && session.client.getStatus() !== "waiting");
96
- const assertIdle = (code = "CHAT_RUN_ACTIVE") => {
97
- if (busy())
98
- throw new ClientError(code, "Wait for the active task to finish.");
99
- };
100
- const release = (session) => {
101
- session.unsubscribe();
102
- session.client.dispose();
103
- };
104
- const cancelWaiting = () => {
105
- if (active().client.getStatus() === "waiting")
106
- active().client.cancel();
107
- };
58
+ const find = (id) => { const session = store.sessions.find((item) => item.id === id); if (!session)
59
+ throw new ClientError("UNKNOWN_SESSION", "Unknown chat session."); return session; };
60
+ const busy = () => store.switching || store.sessions.some((session) => getClientController(session.client).busy && session.client.getStatus() !== "waiting");
61
+ const assertIdle = (code = "CHAT_RUN_ACTIVE") => { if (busy())
62
+ throw new ClientError(code, "Wait for the active task to finish."); };
63
+ const release = (session) => { session.unsubscribe(); session.client.dispose(); };
64
+ const cancelWaiting = () => { if (active().client.getStatus() === "waiting")
65
+ active().client.cancel(); };
108
66
  useEffect(() => {
109
67
  if (store.loaded)
110
68
  return;
@@ -127,17 +85,9 @@ export function NexfaceProvider(props) {
127
85
  const persist = () => {
128
86
  if (store.warning)
129
87
  return;
130
- const stored = {
131
- activeSessionId: store.activeId,
132
- sessions: store.sessions.map((session) => ({
133
- id: session.id,
134
- ...(session.title ? { title: session.title } : {}),
135
- messages: [...projectMessages(session.client.getMessages())],
136
- })),
137
- };
88
+ const stored = { activeSessionId: store.activeId, sessions: store.sessions.map((session) => ({ id: session.id, ...(session.title ? { title: session.title } : {}), messages: [...projectMessages(session.client.getMessages())] })) };
138
89
  if (writeChatStorage(chatStorageKey, stored, store.version) === "conflict") {
139
- store.warning =
140
- "其他标签页已更新历史会话,本页已暂停保存。请先复制本页需要保留的新消息,再刷新以加载最新历史。";
90
+ store.warning = "其他标签页已更新历史会话,本页已暂停保存。请先复制本页需要保留的新消息,再刷新以加载最新历史。";
141
91
  changed();
142
92
  }
143
93
  };
@@ -153,10 +103,8 @@ export function NexfaceProvider(props) {
153
103
  mounted.current = false;
154
104
  window.removeEventListener("pagehide", flush);
155
105
  flush();
156
- queueMicrotask(() => {
157
- if (!mounted.current)
158
- store.sessions.forEach(release);
159
- });
106
+ queueMicrotask(() => { if (!mounted.current)
107
+ store.sessions.forEach(release); });
160
108
  };
161
109
  }, []);
162
110
  const createSession = useCallback(() => {
@@ -204,7 +152,7 @@ export function NexfaceProvider(props) {
204
152
  if (previous.title)
205
153
  session.title = previous.title;
206
154
  release(previous);
207
- store.sessions = store.sessions.map((item) => (item === previous ? session : item));
155
+ store.sessions = store.sessions.map((item) => item === previous ? session : item);
208
156
  if (store.activeId === id)
209
157
  store.activeId = session.id;
210
158
  changed();
@@ -227,14 +175,11 @@ export function NexfaceProvider(props) {
227
175
  const replacement = { ...session, client, unsubscribe: client.subscribe(changed) };
228
176
  previous = session;
229
177
  retainedCount = client.getMessages().length;
230
- store.sessions = store.sessions.map((item) => (item === session ? replacement : item));
178
+ store.sessions = store.sessions.map((item) => item === session ? replacement : item);
231
179
  session = replacement;
232
180
  delete store.completion;
233
181
  }
234
- const parts = [
235
- ...(content ? [{ type: "text", text: content }] : []),
236
- ...attachments.flatMap(attachmentContent),
237
- ];
182
+ const parts = [...(content ? [{ type: "text", text: content }] : []), ...attachments.flatMap(attachmentContent)];
238
183
  try {
239
184
  const messageCount = session.client.getMessages().length;
240
185
  const pending = getClientController(session.client).send(attachments.length ? parts : parts[0]?.type === "text" ? parts[0].text : content, { id: createId(), role: "user", parts: [{ type: "text", text: content }], attachments });
@@ -250,7 +195,7 @@ export function NexfaceProvider(props) {
250
195
  // Keep the original conversation if validation or Runtime acquisition rejected the edit.
251
196
  if (previous && session.client.getMessages().length === retainedCount) {
252
197
  release(session);
253
- store.sessions = store.sessions.map((item) => (item === session ? previous : item));
198
+ store.sessions = store.sessions.map((item) => item === session ? previous : item);
254
199
  previous = undefined;
255
200
  }
256
201
  changed();
@@ -274,69 +219,29 @@ export function NexfaceProvider(props) {
274
219
  const approval = client.getApproval();
275
220
  const error = client.getError();
276
221
  const value = {
277
- sessions: store.sessions
278
- .map((item, index) => {
222
+ sessions: store.sessions.map((item, index) => {
279
223
  const messages = projectMessages(item.client.getMessages());
280
224
  const first = messages.find((message) => message.role === "user");
281
225
  const title = first ? textOf(first).trim() : "";
282
- return {
283
- id: item.id,
284
- title: item.title ||
285
- (title ? (title.length > 24 ? title.slice(0, 24) + "…" : title) : `会话 ${index + 1}`),
286
- messageCount: messages.length,
287
- };
288
- })
289
- .reverse(),
290
- activeSessionId: session.id,
291
- messages: projectMessages(client.getMessages()),
292
- status: store.switching
293
- ? "switching-model"
294
- : controller.cancelling
295
- ? "cancelling"
296
- : client.getStatus(),
226
+ return { id: item.id, title: item.title || (title ? title.length > 24 ? title.slice(0, 24) + "…" : title : `会话 ${index + 1}`), messageCount: messages.length };
227
+ }).reverse(),
228
+ activeSessionId: session.id, messages: projectMessages(client.getMessages()),
229
+ status: store.switching ? "switching-model" : controller.cancelling ? "cancelling" : client.getStatus(),
297
230
  model: controller.agent?.model ?? { provider: "server", model: "server" },
298
- ...(approval ? { interrupt: approval } : {}),
299
- ...(store.warning ? { storageWarning: store.warning } : {}),
231
+ ...(approval ? { interrupt: approval } : {}), ...(store.warning ? { storageWarning: store.warning } : {}),
300
232
  ...(error || store.error ? { error: error ? asError(error) : store.error } : {}),
301
- ...(store.completion?.sessionId === session.id
302
- ? { completed: { id: store.completion.id, result: store.completion.result } }
303
- : {}),
304
- consumeCompletion(id) {
305
- if (store.consumed === id)
306
- return false;
307
- store.consumed = id;
308
- return true;
309
- },
310
- sendMessage,
311
- createSession,
312
- switchSession,
313
- deleteSession,
314
- clearSession,
315
- clearAllSessions() {
316
- assertIdle();
317
- store.sessions.forEach(release);
318
- const first = createSessionValue();
319
- store.sessions = [first];
320
- store.activeId = first.id;
321
- changed();
322
- },
323
- renameSession(id, title) {
324
- if (!title.trim())
325
- throw new ClientError("INVALID_INPUT", "Session title is required.");
326
- find(id).title = title.trim().slice(0, 80);
327
- changed();
328
- },
329
- cancel() {
330
- active().client.cancel();
331
- },
332
- confirmInterrupt() {
333
- if (approval?.mode === "chat")
334
- void client.respondToApproval(approval.id, { approved: true }).catch(() => undefined);
335
- },
336
- rejectInterrupt() {
337
- if (approval?.mode === "chat")
338
- void client.respondToApproval(approval.id, { approved: false }).catch(() => undefined);
339
- },
233
+ ...(store.completion?.sessionId === session.id ? { completed: { id: store.completion.id, result: store.completion.result } } : {}),
234
+ consumeCompletion(id) { if (store.consumed === id)
235
+ return false; store.consumed = id; return true; },
236
+ sendMessage, createSession, switchSession, deleteSession, clearSession,
237
+ clearAllSessions() { assertIdle(); store.sessions.forEach(release); const first = createSessionValue(); store.sessions = [first]; store.activeId = first.id; changed(); },
238
+ renameSession(id, title) { if (!title.trim())
239
+ throw new ClientError("INVALID_INPUT", "Session title is required."); find(id).title = title.trim().slice(0, 80); changed(); },
240
+ cancel() { active().client.cancel(); },
241
+ confirmInterrupt() { if (approval?.mode === "chat")
242
+ void client.respondToApproval(approval.id, { approved: true }).catch(() => undefined); },
243
+ rejectInterrupt() { if (approval?.mode === "chat")
244
+ void client.respondToApproval(approval.id, { approved: false }).catch(() => undefined); },
340
245
  async switchModel(model) {
341
246
  if (busy() || active().client.getApproval())
342
247
  throw new ClientError("CHAT_MODEL_SWITCH_BLOCKED", "The chat is busy.");
@@ -355,12 +260,10 @@ export function NexfaceProvider(props) {
355
260
  }
356
261
  },
357
262
  };
358
- return (_jsx(ChatContext.Provider, { value: value, children: _jsx(ToolsProvider, { toolRuntime: toolRuntime, webMcp: webMcp, children: _jsx(PageConfirmationProvider, { interrupt: approval, onConfirm: () => getClientController(active().client).confirmPage(), onBindingRemoved: () => getClientController(active().client).invalidate("Page confirmation entry was removed."), onBindingRegistration: (name, registered) => {
359
- if (registered)
360
- pageTools.current.add(name);
361
- else
362
- pageTools.current.delete(name);
363
- }, children: children }) }) }));
263
+ return _jsx(ChatContext.Provider, { value: value, children: _jsx(ToolsProvider, { toolRuntime: toolRuntime, webMcp: webMcp, children: _jsx(PageConfirmationProvider, { interrupt: approval, onConfirm: () => getClientController(active().client).confirmPage(), onBindingRemoved: () => getClientController(active().client).invalidate("Page confirmation entry was removed."), onBindingRegistration: (name, registered) => { if (registered)
264
+ pageTools.current.add(name);
265
+ else
266
+ pageTools.current.delete(name); }, children: children }) }) });
364
267
  }
365
268
  export function useChat() {
366
269
  const chat = useContext(ChatContext);
@@ -368,3 +271,4 @@ export function useChat() {
368
271
  throw new Error("useChat must be used inside NexfaceProvider.");
369
272
  return chat;
370
273
  }
274
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAqC,MAAM,OAAO,CAAC;AAElJ,OAAO,EAAE,aAAa,EAAoB,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAwC,MAAM,wBAAwB,CAAC;AACxG,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,WAAW,EAA0C,MAAM,aAAa,CAAC;AAGzH,OAAO,EAAE,iBAAiB,EAAmB,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAKjF,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,MAAM,KAAK,GAAG,KAAkC,CAAC;IACjD,OAA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WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACvC,KAAC,aAAa,IAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YACrD,KAAC,wBAAwB,IAAC,SAAS,EAAE,QAAQ,EAC3C,SAAS,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,EACnE,gBAAgB,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,sCAAsC,CAAC,EAC/G,qBAAqB,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,GAAG,IAAI,UAAU;oBAAE,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;;oBAAM,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YACjI,QAAQ,GACgB,GACb,GACK,CAAC;AAC1B,CAAC;AACD,MAAM,UAAU,OAAO;IACrB,MAAM,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACrC,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAC3E,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { NexfaceErrorEvent } from \"./errors.js\";\nimport { createContext, useContext, useEffect, useLayoutEffect, useRef, useReducer, useCallback, type ReactNode, type ReactElement } from \"react\";\nimport type { AgentInputContent, AgentModelConfig, AgentModelInfo, AgentRunResult, RunAgentInput } from \"@nexface/agent\";\nimport { ToolsProvider, type ToolRuntime } from \"@nexface/tools\";\nimport { PageConfirmationProvider, type ToolApprovalInterruptDescriptor } from \"./page-confirmation.js\";\nimport { createChatClient, getClientController, ClientError, type ChatClient, type ChatClientStatus } from \"./client.js\";\nimport type { NexfaceAgentConfig } from \"./config.js\";\nimport type { ChatRunResult } from \"./types.js\";\nimport { attachmentContent, type Attachment } from \"./attachments.js\";\nimport type { UIMessage } from \"./messages.js\";\nimport { projectMessages } from \"./protocol-messages.js\";\nimport { chatStorageKey, readChatStorage, writeChatStorage } from \"./storage.js\";\nexport type { UIMessage, UIMessagePart } from \"./messages.js\";\n\nexport type ChatCommandErrorCode = \"CHAT_MODEL_SWITCH_BLOCKED\" | \"CHAT_RUNTIME_CHANGED\" | \"CHAT_RUN_ACTIVE\" | \"CHAT_SESSION_CREATE_BLOCKED\" | \"CHAT_SESSION_SWITCH_BLOCKED\" | \"INVALID_INPUT\" | \"UNKNOWN_SESSION\";\nexport interface ChatError { readonly type: \"chat_error\"; readonly code: string; readonly message: string; }\nexport function isChatError(error: unknown): error is ChatError {\n const value = error as Partial<ChatError> | null;\n return !!value && value.type === \"chat_error\" && typeof value.code === \"string\" && typeof value.message === \"string\";\n}\ninterface UseChatResult {\n readonly sessions: readonly { id: string; title: string; messageCount: number }[];\n readonly activeSessionId: string;\n readonly messages: readonly UIMessage[];\n readonly status: ChatClientStatus | \"cancelling\" | \"switching-model\";\n readonly storageWarning?: string;\n readonly error?: ChatError;\n readonly model: AgentModelInfo;\n readonly interrupt?: ToolApprovalInterruptDescriptor;\n readonly completed?: { id: string; result: ChatRunResult };\n consumeCompletion(id: string): boolean;\n sendMessage(text: string, attachments?: Attachment[], revisionOf?: string): Promise<AgentRunResult>;\n renameSession(id: string, title: string): void;\n deleteSession(id: string): void;\n clearSession(id?: string): void;\n clearAllSessions(): void;\n cancel(): void;\n confirmInterrupt(): void;\n rejectInterrupt(): void;\n createSession(): string;\n switchSession(id: string): void;\n switchModel(model: AgentModelConfig): Promise<void>;\n}\nexport type NexfaceProviderProps = { children: ReactNode; toolRuntime: ToolRuntime; webMcp?: boolean; onError?: (event: NexfaceErrorEvent) => void } & (\n | { agent: NexfaceAgentConfig; run?: never }\n | { run: (input: RunAgentInput, options: { signal: AbortSignal }) => Promise<Response>; agent?: never }\n);\ninterface Session { id: string; client: ChatClient; title?: string; unsubscribe(): void; }\ninterface Store {\n sessions: Session[];\n activeId: string;\n loaded: boolean;\n switching: boolean;\n version: { value: string | null };\n warning?: string;\n error?: ChatError;\n completion?: { id: string; sessionId: string; result: ChatRunResult };\n consumed?: string;\n}\nconst sendGuards = new WeakMap<UseChatResult[\"sendMessage\"], (sessionId: string) => void>();\n// Read the live Store at draft submission, including updates before React commits.\nexport function assertChatSendable(chat: UseChatResult, sessionId: string): void {\n sendGuards.get(chat.sendMessage)?.(sessionId);\n}\nconst ChatContext = createContext<UseChatResult | null>(null);\nconst createId = () => globalThis.crypto.randomUUID();\nconst textOf = (message: UIMessage) => message.parts.filter((part) => part.type === \"text\").map((part) => part.text).join(\"\");\nconst asError = (error: unknown): ChatError => {\n if (isChatError(error)) return error;\n const value = error as { code?: unknown; name?: unknown; message?: unknown } | null;\n return new ClientError(typeof value?.code === \"string\" ? value.code : typeof value?.name === \"string\" ? value.name : \"CHAT_RUN_ERROR\", typeof value?.message === \"string\" ? value.message : String(error));\n};\n\nexport function NexfaceProvider(props: NexfaceProviderProps): ReactElement {\n const { toolRuntime, children, webMcp = true } = props;\n const onError = useRef(props.onError);\n useLayoutEffect(() => { onError.current = props.onError; });\n const runtime = useRef(toolRuntime);\n if (runtime.current !== toolRuntime) throw new ClientError(\"CHAT_RUNTIME_CHANGED\", \"NexfaceProvider requires a stable ToolRuntime. Remount it to change Runtime.\");\n if (Boolean(props.agent) === Boolean(props.run) || (props.agent && (\"toolRuntime\" in props.agent || \"toolBridge\" in props.agent || \"run\" in props.agent))) throw new ClientError(\"INVALID_INPUT\", \"Provide exactly one agent configuration or run function.\");\n const pageTools = useRef(new Set<string>());\n const [, render] = useReducer((n: number) => n + 1, 0);\n const mounted = useRef(false);\n const storeRef = useRef<Store | undefined>(undefined);\n const changed = useCallback(() => render(), []);\n const createSessionValue = useCallback((saved?: { id: string; title?: string; messages: UIMessage[] }): Session => {\n const current = props;\n const client = createChatClient({ ...(current.run ? { toolRuntime, run: current.run } : { toolRuntime, agent: current.agent! }), onError: (event) => onError.current?.(event) });\n const controller = getClientController(client);\n if (saved) controller.id = saved.id;\n controller.setPageResolver((name) => pageTools.current.has(name));\n if (saved) controller.restore(saved.messages);\n return { id: saved?.id ?? controller.id, client, ...(saved?.title ? { title: saved.title } : {}), unsubscribe: client.subscribe(changed) };\n }, [props.agent, props.run, toolRuntime, changed]);\n if (!storeRef.current) {\n const first = createSessionValue();\n storeRef.current = { sessions: [first], activeId: first.id, loaded: false, switching: false, version: { value: null } };\n }\n const store = storeRef.current;\n const active = () => store.sessions.find((session) => session.id === store.activeId)!;\n const find = (id: string) => { const session = store.sessions.find((item) => item.id === id); if (!session) throw new ClientError(\"UNKNOWN_SESSION\", \"Unknown chat session.\"); return session; };\n const busy = () => store.switching || store.sessions.some((session) => getClientController(session.client).busy && session.client.getStatus() !== \"waiting\");\n const assertIdle = (code: ChatCommandErrorCode = \"CHAT_RUN_ACTIVE\") => { if (busy()) throw new ClientError(code, \"Wait for the active task to finish.\"); };\n const release = (session: Session) => { session.unsubscribe(); session.client.dispose(); };\n const cancelWaiting = () => { if (active().client.getStatus() === \"waiting\") active().client.cancel(); };\n\n useEffect(() => {\n if (store.loaded) return;\n store.loaded = true;\n const saved = readChatStorage(chatStorageKey, store.version);\n if (!saved) return;\n const restored = saved.sessions.map(createSessionValue);\n const latest = restored.at(-1)!;\n if (latest.client.getMessages().length === 0) {\n store.sessions.forEach(release);\n store.sessions = restored;\n store.activeId = latest.id;\n } else {\n store.sessions = [...restored, ...store.sessions];\n }\n changed();\n }, []);\n const persist = () => {\n if (store.warning) return;\n const stored = { activeSessionId: store.activeId, sessions: store.sessions.map((session) => ({ id: session.id, ...(session.title ? { title: session.title } : {}), messages: [...projectMessages(session.client.getMessages())] })) };\n if (writeChatStorage(chatStorageKey, stored, store.version) === \"conflict\") {\n store.warning = \"其他标签页已更新历史会话,本页已暂停保存。请先复制本页需要保留的新消息,再刷新以加载最新历史。\";\n changed();\n }\n };\n useEffect(() => {\n const timer = setTimeout(persist, busy() ? 250 : 0);\n return () => clearTimeout(timer);\n });\n useEffect(() => {\n mounted.current = true;\n const flush = () => persist();\n window.addEventListener(\"pagehide\", flush);\n return () => {\n mounted.current = false;\n window.removeEventListener(\"pagehide\", flush);\n flush();\n queueMicrotask(() => { if (!mounted.current) store.sessions.forEach(release); });\n };\n }, []);\n\n const createSession = useCallback((): string => {\n assertIdle(\"CHAT_SESSION_CREATE_BLOCKED\"); cancelWaiting();\n const latest = store.sessions.at(-1)!;\n if (latest.client.getMessages().length === 0) {\n store.activeId = latest.id; delete store.error; changed(); return latest.id;\n }\n const session = createSessionValue(); store.sessions.push(session); store.activeId = session.id; delete store.error; changed(); return session.id;\n }, [createSessionValue]);\n const switchSession = (id: string) => {\n assertIdle(\"CHAT_SESSION_SWITCH_BLOCKED\"); find(id);\n if (store.activeId === id) return;\n cancelWaiting(); store.activeId = id; delete store.error; changed();\n };\n const deleteSession = (id: string) => {\n assertIdle(); const session = find(id); release(session);\n store.sessions = store.sessions.filter((item) => item !== session);\n if (!store.sessions.length) store.sessions.push(createSessionValue());\n if (store.activeId === id) store.activeId = store.sessions[0]!.id;\n changed();\n };\n const clearSession = (id = store.activeId) => {\n assertIdle(); const previous = find(id); const session = createSessionValue();\n if (previous.title) session.title = previous.title;\n release(previous); store.sessions = store.sessions.map((item) => item === previous ? session : item);\n if (store.activeId === id) store.activeId = session.id;\n changed();\n };\n const sendMessage = useCallback(async (text: string, attachments: Attachment[] = [], revisionOf?: string): Promise<AgentRunResult> => {\n if (store.switching) throw new ClientError(\"CHAT_RUN_ACTIVE\", \"The model is switching.\");\n let session = active(); const content = text.trim();\n if (!content && !attachments.length) throw new ClientError(\"INVALID_INPUT\", \"Chat message is required.\");\n let previous: Session | undefined;\n let retainedCount = 0;\n if (revisionOf) {\n assertIdle();\n const controller = getClientController(session.client);\n if (controller.busy) throw new ClientError(\"CHAT_RUN_ACTIVE\", \"Wait for the active task to finish.\");\n const client = controller.recreateBefore(revisionOf);\n const replacement = { ...session, client, unsubscribe: client.subscribe(changed) };\n previous = session;\n retainedCount = client.getMessages().length;\n store.sessions = store.sessions.map((item) => item === session ? replacement : item);\n session = replacement;\n delete store.completion;\n }\n const parts: AgentInputContent[] = [ ...(content ? [{ type: \"text\" as const, text: content }] : []), ...attachments.flatMap(attachmentContent) ];\n try {\n const messageCount = session.client.getMessages().length;\n const pending = getClientController(session.client).send(attachments.length ? parts : parts[0]?.type === \"text\" ? parts[0].text : content, { id: createId(), role: \"user\", parts: [{ type: \"text\", text: content }], attachments });\n // Keep the previous completion if validation or Runtime acquisition rejects the task.\n if (session.client.getMessages().length > messageCount) delete store.completion;\n const result = await pending;\n store.completion = { id: createId(), sessionId: session.id, result }; changed(); return result;\n } catch (error) {\n // Keep the original conversation if validation or Runtime acquisition rejected the edit.\n if (previous && session.client.getMessages().length === retainedCount) {\n release(session);\n store.sessions = store.sessions.map((item) => item === session ? previous! : item);\n previous = undefined;\n }\n changed(); throw error;\n } finally { if (previous) release(previous); }\n }, []);\n sendGuards.set(sendMessage, (sessionId) => {\n if (store.activeId !== sessionId) throw new ClientError(\"CHAT_RUN_ACTIVE\", \"会话已切换,请返回原会话重新发送。\");\n if (busy()) throw new ClientError(\"CHAT_RUN_ACTIVE\", \"已有任务正在运行,请稍后重新发送。\");\n getClientController(active().client).assertRecoveryAvailable();\n });\n const session = active();\n const client = session.client;\n const controller = getClientController(client);\n const approval = client.getApproval();\n const error = client.getError();\n const value: UseChatResult = {\n sessions: store.sessions.map((item, index) => {\n const messages = projectMessages(item.client.getMessages()); const first = messages.find((message) => message.role === \"user\");\n const title = first ? textOf(first).trim() : \"\";\n return { id: item.id, title: item.title || (title ? title.length > 24 ? title.slice(0, 24) + \"…\" : title : `会话 ${index + 1}`), messageCount: messages.length };\n }).reverse(),\n activeSessionId: session.id, messages: projectMessages(client.getMessages()),\n status: store.switching ? \"switching-model\" : controller.cancelling ? \"cancelling\" : client.getStatus(),\n model: controller.agent?.model ?? { provider: \"server\", model: \"server\" },\n ...(approval ? { interrupt: approval } : {}), ...(store.warning ? { storageWarning: store.warning } : {}),\n ...(error || store.error ? { error: error ? asError(error) : store.error! } : {}),\n ...(store.completion?.sessionId === session.id ? { completed: { id: store.completion.id, result: store.completion.result } } : {}),\n consumeCompletion(id) { if (store.consumed === id) return false; store.consumed = id; return true; },\n sendMessage, createSession, switchSession, deleteSession, clearSession,\n clearAllSessions() { assertIdle(); store.sessions.forEach(release); const first = createSessionValue(); store.sessions = [first]; store.activeId = first.id; changed(); },\n renameSession(id, title) { if (!title.trim()) throw new ClientError(\"INVALID_INPUT\", \"Session title is required.\"); find(id).title = title.trim().slice(0, 80); changed(); },\n cancel() { active().client.cancel(); },\n confirmInterrupt() { if (approval?.mode === \"chat\") void client.respondToApproval(approval.id, { approved: true }).catch(() => undefined); },\n rejectInterrupt() { if (approval?.mode === \"chat\") void client.respondToApproval(approval.id, { approved: false }).catch(() => undefined); },\n async switchModel(model) {\n if (busy() || active().client.getApproval()) throw new ClientError(\"CHAT_MODEL_SWITCH_BLOCKED\", \"The chat is busy.\");\n store.switching = true; changed();\n try { await getClientController(active().client).switchModel(model); }\n catch (error) { store.error = asError(error); throw error; }\n finally { store.switching = false; changed(); }\n },\n };\n return <ChatContext.Provider value={value}>\n <ToolsProvider toolRuntime={toolRuntime} webMcp={webMcp}>\n <PageConfirmationProvider interrupt={approval}\n onConfirm={() => getClientController(active().client).confirmPage()}\n onBindingRemoved={() => getClientController(active().client).invalidate(\"Page confirmation entry was removed.\")}\n onBindingRegistration={(name, registered) => { if (registered) pageTools.current.add(name); else pageTools.current.delete(name); }}>\n {children}\n </PageConfirmationProvider>\n </ToolsProvider>\n </ChatContext.Provider>;\n}\nexport function useChat(): UseChatResult {\n const chat = useContext(ChatContext);\n if (!chat) throw new Error(\"useChat must be used inside NexfaceProvider.\");\n return chat;\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  export declare const TOOL_ERROR_CODES: readonly ["EXECUTION_OUTCOME_UNKNOWN", "ACTION_IN_FLIGHT", "ACTION_NOT_HANDLED", "ACTION_TARGET_UNAVAILABLE", "BROWSER_EXECUTION_FAILED", "BROWSER_SNAPSHOT_REQUIRED", "BROWSER_TOOLS_UNAVAILABLE", "CONTRACT_MISMATCH", "DUPLICATE_BINDING", "INVALID_INPUT", "INVALID_TOOL_RUNTIME", "OPERATION_BUSY", "TOOL_CANCELLED", "TOOL_CONFIRMATION_INVALIDATED", "TOOL_CONFIRMATION_REJECTED", "TOOL_ERROR", "TOOL_REGISTRATION_TIMEOUT", "TOOL_SKIPPED", "TOOL_UNAVAILABLE", "UNKNOWN_TOOL"];
2
- type AgentToolErrorCode = (typeof TOOL_ERROR_CODES)[number];
2
+ type AgentToolErrorCode = typeof TOOL_ERROR_CODES[number];
3
3
  export declare class AgentToolError extends Error {
4
4
  readonly code: AgentToolErrorCode;
5
5
  readonly details?: unknown | undefined;
@@ -33,3 +33,4 @@ export class AgentToolError extends Error {
33
33
  this.name = "ToolRuntimeError";
34
34
  }
35
35
  }
36
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/shared/errors.ts"],"names":[],"mappings":"AAAA,yDAAyD;AAEzD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,2BAA2B;IAC3B,kBAAkB;IAClB,oBAAoB;IACpB,2BAA2B;IAC3B,0BAA0B;IAC1B,2BAA2B;IAC3B,2BAA2B;IAC3B,mBAAmB;IACnB,mBAAmB;IACnB,eAAe;IACf,sBAAsB;IACtB,gBAAgB;IAChB,gBAAgB;IAChB,+BAA+B;IAC/B,4BAA4B;IAC5B,YAAY;IACZ,2BAA2B;IAC3B,cAAc;IACd,kBAAkB;IAClB,cAAc;CACN,CAAC;AAIX,MAAM,OAAO,cAAe,SAAQ,KAAK;IAK5B;IAEA;IANF,IAAI,GAAG,oBAA6B,CAAC;IACrC,MAAM,GAAG,MAAe,CAAC;IAElC,YACW,IAAwB,EACjC,OAAe,EACN,OAAiB;QAE1B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,SAAI,GAAJ,IAAI,CAAoB;QAExB,YAAO,GAAP,OAAO,CAAU;QAG1B,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF","sourcesContent":["// Generated from shared/errors.ts. Do not edit manually.\n\nexport const TOOL_ERROR_CODES = [\n \"EXECUTION_OUTCOME_UNKNOWN\",\n \"ACTION_IN_FLIGHT\",\n \"ACTION_NOT_HANDLED\",\n \"ACTION_TARGET_UNAVAILABLE\",\n \"BROWSER_EXECUTION_FAILED\",\n \"BROWSER_SNAPSHOT_REQUIRED\",\n \"BROWSER_TOOLS_UNAVAILABLE\",\n \"CONTRACT_MISMATCH\",\n \"DUPLICATE_BINDING\",\n \"INVALID_INPUT\",\n \"INVALID_TOOL_RUNTIME\",\n \"OPERATION_BUSY\",\n \"TOOL_CANCELLED\",\n \"TOOL_CONFIRMATION_INVALIDATED\",\n \"TOOL_CONFIRMATION_REJECTED\",\n \"TOOL_ERROR\",\n \"TOOL_REGISTRATION_TIMEOUT\",\n \"TOOL_SKIPPED\",\n \"TOOL_UNAVAILABLE\",\n \"UNKNOWN_TOOL\",\n] as const;\n\ntype AgentToolErrorCode = typeof TOOL_ERROR_CODES[number];\n\nexport class AgentToolError extends Error {\n readonly type = \"tool_runtime_error\" as const;\n readonly domain = \"tool\" as const;\n\n constructor(\n readonly code: AgentToolErrorCode,\n message: string,\n readonly details?: unknown,\n ) {\n super(message);\n this.name = \"ToolRuntimeError\";\n }\n}\n"]}
@@ -12,7 +12,6 @@ interface OperationSnapshot {
12
12
  readonly taskProgress?: TaskProgress;
13
13
  }
14
14
  export interface RuntimeController {
15
- getRegisteredTools(): ReturnType<ToolRuntime["getTools"]>;
16
15
  beginInternalOperation(options?: {
17
16
  signal?: AbortSignal;
18
17
  onCancel?: () => void;
@@ -8,3 +8,4 @@ export function getRuntimeController(runtime) {
8
8
  }
9
9
  return controller;
10
10
  }
11
+ //# sourceMappingURL=runtime-controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-controller.js","sourceRoot":"","sources":["../../src/shared/runtime-controller.ts"],"names":[],"mappings":"AAAA,qEAAqE;AAGrE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAuB7C,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AAEvF,MAAM,UAAU,oBAAoB,CAAC,OAAoB;IACvD,MAAM,UAAU,GAAI,OAA2E,CAAC,uBAAuB,CAAC,CAAC;IACzH,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,cAAc,CAAC,sBAAsB,EAAE,iGAAiG,CAAC,CAAC;IACtJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["// Generated from shared/runtime-controller.ts. Do not edit manually.\n\nimport type { ToolOperation, ToolRuntime } from \"@nexface/tools\";\nimport { AgentToolError } from \"./errors.js\";\n\nexport type TaskProgress = { readonly phase: \"processing\" } | { readonly phase: \"tool\"; readonly toolCallId: string; readonly progressLabel?: string };\n\ninterface OperationSnapshot {\n readonly id: string;\n readonly status: \"running\" | \"waiting\" | \"cancelling\" | \"ending\";\n readonly taskProgress?: TaskProgress;\n}\n\nexport interface RuntimeController {\n beginInternalOperation(options?: {\n signal?: AbortSignal;\n onCancel?: () => void;\n replaceWaiting?: ToolOperation;\n taskProgress?: TaskProgress;\n }): ToolOperation;\n setOperationWaiting(handle: ToolOperation, waiting: boolean): void;\n setTaskProgress(handle: ToolOperation, progress: TaskProgress): void;\n getOperationSnapshot(): OperationSnapshot | null;\n subscribeOperation(listener: () => void): () => void;\n}\n\nexport const runtimeControllerSymbol = Symbol.for(\"@nexface/tools/runtime-controller\");\n\nexport function getRuntimeController(runtime: ToolRuntime): RuntimeController {\n const controller = (runtime as ToolRuntime & { [runtimeControllerSymbol]?: RuntimeController })[runtimeControllerSymbol];\n if (!controller) {\n throw new AgentToolError(\"INVALID_TOOL_RUNTIME\", \"ToolRuntime does not support internal task coordination. Use matching Nexface package versions.\");\n }\n return controller;\n}\n"]}
@@ -1,2 +1,3 @@
1
1
  // Generated from shared/runtime-execution.ts. Do not edit manually.
2
2
  export const pageDecisionSymbol = Symbol.for("@nexface/tools/page-decision");
3
+ //# sourceMappingURL=runtime-execution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-execution.js","sourceRoot":"","sources":["../../src/shared/runtime-execution.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAIpE,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC","sourcesContent":["// Generated from shared/runtime-execution.ts. Do not edit manually.\n\nimport type { ToolRuntime } from \"@nexface/tools\";\n\nexport const pageDecisionSymbol = Symbol.for(\"@nexface/tools/page-decision\");\n\nexport type InternalExecutionOptions = NonNullable<Parameters<ToolRuntime[\"execute\"]>[2]> & {\n readonly [pageDecisionSymbol]?: boolean;\n};\n"]}