@nexface/chat 0.1.13 → 0.1.14

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 (128) hide show
  1. package/dist/assistant-attachments.js +60 -17
  2. package/dist/assistant-components.d.ts +3 -3
  3. package/dist/assistant-components.js +77 -29
  4. package/dist/assistant-runtime.d.ts +1 -1
  5. package/dist/assistant-runtime.js +100 -43
  6. package/dist/attachments.js +36 -15
  7. package/dist/client.js +312 -73
  8. package/dist/config.js +4 -5
  9. package/dist/default-chat.d.ts +1 -1
  10. package/dist/default-chat.js +2102 -728
  11. package/dist/errors.js +55 -18
  12. package/dist/index.js +0 -1
  13. package/dist/messages.js +0 -1
  14. package/dist/page-confirmation.js +3 -4
  15. package/dist/protocol-messages.js +290 -66
  16. package/dist/protocol-response.js +38 -18
  17. package/dist/react.js +146 -50
  18. package/dist/shared/errors.d.ts +1 -1
  19. package/dist/shared/errors.js +0 -1
  20. package/dist/shared/runtime-controller.d.ts +1 -0
  21. package/dist/shared/runtime-controller.js +0 -1
  22. package/dist/shared/runtime-execution.js +0 -1
  23. package/dist/shared/schema.js +45 -19
  24. package/dist/storage.js +130 -53
  25. package/dist/styles.css +99 -20
  26. package/dist/tool-result.js +7 -3
  27. package/dist/types.js +0 -1
  28. package/dist/ui/attachment.aui.d.ts +1 -1
  29. package/dist/ui/attachment.aui.js +16 -20
  30. package/dist/ui/avatar.js +0 -1
  31. package/dist/ui/button.js +0 -1
  32. package/dist/ui/code-block.js +2 -3
  33. package/dist/ui/collapsible.js +2 -3
  34. package/dist/ui/composer-voice.js +3 -2
  35. package/dist/ui/dialog.d.ts +1 -1
  36. package/dist/ui/dialog.js +9 -4
  37. package/dist/ui/dropdown-menu.js +2 -3
  38. package/dist/ui/home-demo/action-bar.js +0 -1
  39. package/dist/ui/home-demo/composer.js +7 -4
  40. package/dist/ui/home-demo/greeting.d.ts +1 -1
  41. package/dist/ui/home-demo/greeting.js +1 -2
  42. package/dist/ui/home-demo/messages.d.ts +1 -1
  43. package/dist/ui/home-demo/messages.js +4 -5
  44. package/dist/ui/home-demo/styles.js +0 -1
  45. package/dist/ui/home-demo/suggestions.d.ts +1 -1
  46. package/dist/ui/home-demo/suggestions.js +5 -3
  47. package/dist/ui/home-demo/surfaces.js +3 -2
  48. package/dist/ui/home-demo/thread.d.ts +1 -1
  49. package/dist/ui/home-demo/thread.js +1 -2
  50. package/dist/ui/home-demo/trace-line.d.ts +1 -1
  51. package/dist/ui/home-demo/trace-line.js +2 -3
  52. package/dist/ui/home-demo/trace.d.ts +1 -1
  53. package/dist/ui/home-demo/trace.js +28 -9
  54. package/dist/ui/home-demo/type.js +0 -1
  55. package/dist/ui/input.js +0 -1
  56. package/dist/ui/markdown-text.js +2 -3
  57. package/dist/ui/reasoning.aui.js +2 -3
  58. package/dist/ui/reasoning.d.ts +1 -1
  59. package/dist/ui/reasoning.js +6 -9
  60. package/dist/ui/surface.js +27 -8
  61. package/dist/ui/thread-list.aui.d.ts +2 -2
  62. package/dist/ui/thread-list.aui.js +18 -12
  63. package/dist/ui/tool-group.aui.js +2 -3
  64. package/dist/ui/tooltip-icon-button.js +1 -2
  65. package/dist/ui/tooltip.js +0 -1
  66. package/dist/ui/use-attachment-src.js +1 -2
  67. package/dist/ui/use-copy-to-clipboard.d.ts +1 -1
  68. package/dist/ui/use-copy-to-clipboard.js +1 -2
  69. package/dist/ui/utils.js +9 -3
  70. package/dist/use-next-message.js +7 -4
  71. package/dist/voice/types.js +0 -1
  72. package/dist/voice/use-voice.js +35 -13
  73. package/package.json +8 -4
  74. package/dist/assistant-attachments.js.map +0 -1
  75. package/dist/assistant-components.js.map +0 -1
  76. package/dist/assistant-runtime.js.map +0 -1
  77. package/dist/attachments.js.map +0 -1
  78. package/dist/client.js.map +0 -1
  79. package/dist/config.js.map +0 -1
  80. package/dist/default-chat.js.map +0 -7
  81. package/dist/errors.js.map +0 -1
  82. package/dist/index.js.map +0 -1
  83. package/dist/messages.js.map +0 -1
  84. package/dist/page-confirmation.js.map +0 -1
  85. package/dist/protocol-messages.js.map +0 -1
  86. package/dist/protocol-response.js.map +0 -1
  87. package/dist/react.js.map +0 -1
  88. package/dist/shared/errors.js.map +0 -1
  89. package/dist/shared/runtime-controller.js.map +0 -1
  90. package/dist/shared/runtime-execution.js.map +0 -1
  91. package/dist/shared/schema.js.map +0 -1
  92. package/dist/storage.js.map +0 -1
  93. package/dist/tool-result.js.map +0 -1
  94. package/dist/types.js.map +0 -1
  95. package/dist/ui/attachment.aui.js.map +0 -1
  96. package/dist/ui/avatar.js.map +0 -1
  97. package/dist/ui/button.js.map +0 -1
  98. package/dist/ui/code-block.js.map +0 -1
  99. package/dist/ui/collapsible.js.map +0 -1
  100. package/dist/ui/composer-voice.js.map +0 -1
  101. package/dist/ui/dialog.js.map +0 -1
  102. package/dist/ui/dropdown-menu.js.map +0 -1
  103. package/dist/ui/home-demo/action-bar.js.map +0 -1
  104. package/dist/ui/home-demo/composer.js.map +0 -1
  105. package/dist/ui/home-demo/greeting.js.map +0 -1
  106. package/dist/ui/home-demo/messages.js.map +0 -1
  107. package/dist/ui/home-demo/styles.js.map +0 -1
  108. package/dist/ui/home-demo/suggestions.js.map +0 -1
  109. package/dist/ui/home-demo/surfaces.js.map +0 -1
  110. package/dist/ui/home-demo/thread.js.map +0 -1
  111. package/dist/ui/home-demo/trace-line.js.map +0 -1
  112. package/dist/ui/home-demo/trace.js.map +0 -1
  113. package/dist/ui/home-demo/type.js.map +0 -1
  114. package/dist/ui/input.js.map +0 -1
  115. package/dist/ui/markdown-text.js.map +0 -1
  116. package/dist/ui/reasoning.aui.js.map +0 -1
  117. package/dist/ui/reasoning.js.map +0 -1
  118. package/dist/ui/surface.js.map +0 -1
  119. package/dist/ui/thread-list.aui.js.map +0 -1
  120. package/dist/ui/tool-group.aui.js.map +0 -1
  121. package/dist/ui/tooltip-icon-button.js.map +0 -1
  122. package/dist/ui/tooltip.js.map +0 -1
  123. package/dist/ui/use-attachment-src.js.map +0 -1
  124. package/dist/ui/use-copy-to-clipboard.js.map +0 -1
  125. package/dist/ui/utils.js.map +0 -1
  126. package/dist/use-next-message.js.map +0 -1
  127. package/dist/voice/types.js.map +0 -1
  128. package/dist/voice/use-voice.js.map +0 -1
@@ -1,17 +1,22 @@
1
1
  export function decodeAgentResponse(messages, snapshot, terminal) {
2
2
  const state = snapshot;
3
3
  const continuation = state?.nexface;
4
- if (!continuation || continuation.version !== 3 || continuation.threadId !== terminal.threadId || !Array.isArray(continuation.timeline)) {
4
+ if (!continuation ||
5
+ continuation.version !== 3 ||
6
+ continuation.threadId !== terminal.threadId ||
7
+ !Array.isArray(continuation.timeline)) {
5
8
  throw new Error("Invalid Agent recovery state or protocol version. Upgrade client and server together and start a new conversation.");
6
9
  }
7
10
  const legacy = new Set(["callAppTool", "getSnapshot", "executeCode", "loadSkill", "finish"]);
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)))
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)))
10
14
  throw new Error("Unsupported legacy tool history. Start a new conversation.");
11
15
  const history = messages.filter((message) => message.role !== "activity" && message.role !== "reasoning");
12
16
  const references = continuation.timeline.flatMap((entry) => {
13
17
  if (entry && "internal" in entry) {
14
- if ("messageId" in entry || (entry.internal?.role !== "system" && entry.internal?.role !== "application_context"))
18
+ if ("messageId" in entry ||
19
+ (entry.internal?.role !== "system" && entry.internal?.role !== "application_context"))
15
20
  throw new Error("Invalid internal history reference.");
16
21
  return [];
17
22
  }
@@ -19,8 +24,9 @@ export function decodeAgentResponse(messages, snapshot, terminal) {
19
24
  throw new Error("Invalid Agent history reference.");
20
25
  return [entry.messageId];
21
26
  });
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)) {
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)) {
24
30
  throw new Error("Agent messages and recovery state do not match.");
25
31
  }
26
32
  const outcome = terminal.outcome;
@@ -35,18 +41,27 @@ export function decodeAgentResponse(messages, snapshot, terminal) {
35
41
  const interrupt = outcome.interrupts[0];
36
42
  const extension = interrupt.metadata?.nexface;
37
43
  const call = pending?.calls?.[0];
38
- if (!extension || !pending || !Array.isArray(pending.calls) || !call
39
- || pending.interruptId !== interrupt.id || interrupt.toolCallId !== call.id || pending.kind !== extension.kind) {
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) {
40
51
  throw new Error("Invalid remote interrupt.");
41
52
  }
42
- const ownerIndex = history.reduce((last, message, index) => message.role === "assistant" ? index : last, -1);
53
+ const ownerIndex = history.reduce((last, message, index) => (message.role === "assistant" ? index : last), -1);
43
54
  const owner = history[ownerIndex];
44
- const calls = owner?.role === "assistant" ? owner.toolCalls ?? [] : [];
55
+ const calls = owner?.role === "assistant" ? (owner.toolCalls ?? []) : [];
45
56
  const first = calls.findIndex((item) => item.id === call.id);
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))) {
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))) {
50
65
  throw new Error("Pending calls do not match their assistant message.");
51
66
  }
52
67
  const args = JSON.parse(call.arguments);
@@ -54,16 +69,21 @@ export function decodeAgentResponse(messages, snapshot, terminal) {
54
69
  throw new Error("Invalid pending tool arguments.");
55
70
  const input = args;
56
71
  const name = call.name === "nxf_callAppTool" ? input.name : call.name;
57
- const toolInput = call.name === "nxf_callAppTool" ? input.input : Object.fromEntries(Object.entries(input).filter(([key]) => key !== "progressLabel"));
72
+ const toolInput = call.name === "nxf_callAppTool"
73
+ ? input.input
74
+ : Object.fromEntries(Object.entries(input).filter(([key]) => key !== "progressLabel"));
58
75
  if (extension.kind !== "client-tool-execution")
59
76
  throw new Error("Unsupported remote interrupt.");
60
77
  const action = extension.action;
61
- if (!action || action.toolCallId !== call.id || name !== action.definition?.name || JSON.stringify(toolInput) !== JSON.stringify(action.input)) {
78
+ if (!action ||
79
+ action.toolCallId !== call.id ||
80
+ name !== action.definition?.name ||
81
+ JSON.stringify(toolInput) !== JSON.stringify(action.input)) {
62
82
  throw new Error("Browser action does not match its original call.");
63
83
  }
64
- if (action.pageDecision !== undefined && (action.pageDecision !== true || name !== "nxf_getSnapshot")) {
84
+ if (action.pageDecision !== undefined &&
85
+ (action.pageDecision !== true || name !== "nxf_getSnapshot")) {
65
86
  throw new Error("Invalid page decision observation context.");
66
87
  }
67
88
  return { type: "client-tool-execution", interruptId: interrupt.id, action };
68
89
  }
69
- //# sourceMappingURL=protocol-response.js.map
package/dist/react.js CHANGED
@@ -1,14 +1,17 @@
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 && value.type === "chat_error" && typeof value.code === "string" && typeof value.message === "string";
11
+ return (!!value &&
12
+ value.type === "chat_error" &&
13
+ typeof value.code === "string" &&
14
+ typeof value.message === "string");
12
15
  }
13
16
  const sendGuards = new WeakMap();
14
17
  // Read the live Store at draft submission, including updates before React commits.
@@ -17,21 +20,32 @@ export function assertChatSendable(chat, sessionId) {
17
20
  }
18
21
  const ChatContext = createContext(null);
19
22
  const createId = () => globalThis.crypto.randomUUID();
20
- const textOf = (message) => message.parts.filter((part) => part.type === "text").map((part) => part.text).join("");
23
+ const textOf = (message) => message.parts
24
+ .filter((part) => part.type === "text")
25
+ .map((part) => part.text)
26
+ .join("");
21
27
  const asError = (error) => {
22
28
  if (isChatError(error))
23
29
  return error;
24
30
  const value = 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));
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));
26
36
  };
27
37
  export function NexfaceProvider(props) {
28
38
  const { toolRuntime, children, webMcp = true } = props;
29
39
  const onError = useRef(props.onError);
30
- useLayoutEffect(() => { onError.current = props.onError; });
40
+ useLayoutEffect(() => {
41
+ onError.current = props.onError;
42
+ });
31
43
  const runtime = useRef(toolRuntime);
32
44
  if (runtime.current !== toolRuntime)
33
45
  throw new ClientError("CHAT_RUNTIME_CHANGED", "NexfaceProvider requires a stable ToolRuntime. Remount it to change Runtime.");
34
- if (Boolean(props.agent) === Boolean(props.run) || (props.agent && ("toolRuntime" in props.agent || "toolBridge" in props.agent || "run" in props.agent)))
46
+ if (Boolean(props.agent) === Boolean(props.run) ||
47
+ (props.agent &&
48
+ ("toolRuntime" in props.agent || "toolBridge" in props.agent || "run" in props.agent)))
35
49
  throw new ClientError("INVALID_INPUT", "Provide exactly one agent configuration or run function.");
36
50
  const pageTools = useRef(new Set());
37
51
  const [, render] = useReducer((n) => n + 1, 0);
@@ -40,29 +54,57 @@ export function NexfaceProvider(props) {
40
54
  const changed = useCallback(() => render(), []);
41
55
  const createSessionValue = useCallback((saved) => {
42
56
  const current = props;
43
- const client = createChatClient({ ...(current.run ? { toolRuntime, run: current.run } : { toolRuntime, agent: current.agent }), onError: (event) => onError.current?.(event) });
57
+ const client = createChatClient({
58
+ ...(current.run
59
+ ? { toolRuntime, run: current.run }
60
+ : { toolRuntime, agent: current.agent }),
61
+ onError: (event) => onError.current?.(event),
62
+ });
44
63
  const controller = getClientController(client);
45
64
  if (saved)
46
65
  controller.id = saved.id;
47
66
  controller.setPageResolver((name) => pageTools.current.has(name));
48
67
  if (saved)
49
68
  controller.restore(saved.messages);
50
- return { id: saved?.id ?? controller.id, client, ...(saved?.title ? { title: saved.title } : {}), unsubscribe: client.subscribe(changed) };
69
+ return {
70
+ id: saved?.id ?? controller.id,
71
+ client,
72
+ ...(saved?.title ? { title: saved.title } : {}),
73
+ unsubscribe: client.subscribe(changed),
74
+ };
51
75
  }, [props.agent, props.run, toolRuntime, changed]);
52
76
  if (!storeRef.current) {
53
77
  const first = createSessionValue();
54
- storeRef.current = { sessions: [first], activeId: first.id, loaded: false, switching: false, version: { value: null } };
78
+ storeRef.current = {
79
+ sessions: [first],
80
+ activeId: first.id,
81
+ loaded: false,
82
+ switching: false,
83
+ version: { value: null },
84
+ };
55
85
  }
56
86
  const store = storeRef.current;
57
87
  const active = () => store.sessions.find((session) => session.id === store.activeId);
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(); };
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
+ };
66
108
  useEffect(() => {
67
109
  if (store.loaded)
68
110
  return;
@@ -85,9 +127,17 @@ export function NexfaceProvider(props) {
85
127
  const persist = () => {
86
128
  if (store.warning)
87
129
  return;
88
- const stored = { activeSessionId: store.activeId, sessions: store.sessions.map((session) => ({ id: session.id, ...(session.title ? { title: session.title } : {}), messages: [...projectMessages(session.client.getMessages())] })) };
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
+ };
89
138
  if (writeChatStorage(chatStorageKey, stored, store.version) === "conflict") {
90
- store.warning = "其他标签页已更新历史会话,本页已暂停保存。请先复制本页需要保留的新消息,再刷新以加载最新历史。";
139
+ store.warning =
140
+ "其他标签页已更新历史会话,本页已暂停保存。请先复制本页需要保留的新消息,再刷新以加载最新历史。";
91
141
  changed();
92
142
  }
93
143
  };
@@ -103,8 +153,10 @@ export function NexfaceProvider(props) {
103
153
  mounted.current = false;
104
154
  window.removeEventListener("pagehide", flush);
105
155
  flush();
106
- queueMicrotask(() => { if (!mounted.current)
107
- store.sessions.forEach(release); });
156
+ queueMicrotask(() => {
157
+ if (!mounted.current)
158
+ store.sessions.forEach(release);
159
+ });
108
160
  };
109
161
  }, []);
110
162
  const createSession = useCallback(() => {
@@ -152,7 +204,7 @@ export function NexfaceProvider(props) {
152
204
  if (previous.title)
153
205
  session.title = previous.title;
154
206
  release(previous);
155
- store.sessions = store.sessions.map((item) => item === previous ? session : item);
207
+ store.sessions = store.sessions.map((item) => (item === previous ? session : item));
156
208
  if (store.activeId === id)
157
209
  store.activeId = session.id;
158
210
  changed();
@@ -175,11 +227,14 @@ export function NexfaceProvider(props) {
175
227
  const replacement = { ...session, client, unsubscribe: client.subscribe(changed) };
176
228
  previous = session;
177
229
  retainedCount = client.getMessages().length;
178
- store.sessions = store.sessions.map((item) => item === session ? replacement : item);
230
+ store.sessions = store.sessions.map((item) => (item === session ? replacement : item));
179
231
  session = replacement;
180
232
  delete store.completion;
181
233
  }
182
- const parts = [...(content ? [{ type: "text", text: content }] : []), ...attachments.flatMap(attachmentContent)];
234
+ const parts = [
235
+ ...(content ? [{ type: "text", text: content }] : []),
236
+ ...attachments.flatMap(attachmentContent),
237
+ ];
183
238
  try {
184
239
  const messageCount = session.client.getMessages().length;
185
240
  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 });
@@ -195,7 +250,7 @@ export function NexfaceProvider(props) {
195
250
  // Keep the original conversation if validation or Runtime acquisition rejected the edit.
196
251
  if (previous && session.client.getMessages().length === retainedCount) {
197
252
  release(session);
198
- store.sessions = store.sessions.map((item) => item === session ? previous : item);
253
+ store.sessions = store.sessions.map((item) => (item === session ? previous : item));
199
254
  previous = undefined;
200
255
  }
201
256
  changed();
@@ -219,29 +274,69 @@ export function NexfaceProvider(props) {
219
274
  const approval = client.getApproval();
220
275
  const error = client.getError();
221
276
  const value = {
222
- sessions: store.sessions.map((item, index) => {
277
+ sessions: store.sessions
278
+ .map((item, index) => {
223
279
  const messages = projectMessages(item.client.getMessages());
224
280
  const first = messages.find((message) => message.role === "user");
225
281
  const title = first ? textOf(first).trim() : "";
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(),
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(),
230
297
  model: controller.agent?.model ?? { provider: "server", model: "server" },
231
- ...(approval ? { interrupt: approval } : {}), ...(store.warning ? { storageWarning: store.warning } : {}),
298
+ ...(approval ? { interrupt: approval } : {}),
299
+ ...(store.warning ? { storageWarning: store.warning } : {}),
232
300
  ...(error || store.error ? { error: error ? asError(error) : store.error } : {}),
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); },
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
+ },
245
340
  async switchModel(model) {
246
341
  if (busy() || active().client.getApproval())
247
342
  throw new ClientError("CHAT_MODEL_SWITCH_BLOCKED", "The chat is busy.");
@@ -260,10 +355,12 @@ export function NexfaceProvider(props) {
260
355
  }
261
356
  },
262
357
  };
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 }) }) });
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 }) }) }));
267
364
  }
268
365
  export function useChat() {
269
366
  const chat = useContext(ChatContext);
@@ -271,4 +368,3 @@ export function useChat() {
271
368
  throw new Error("useChat must be used inside NexfaceProvider.");
272
369
  return chat;
273
370
  }
274
- //# sourceMappingURL=react.js.map
@@ -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,4 +33,3 @@ export class AgentToolError extends Error {
33
33
  this.name = "ToolRuntimeError";
34
34
  }
35
35
  }
36
- //# sourceMappingURL=errors.js.map
@@ -12,6 +12,7 @@ interface OperationSnapshot {
12
12
  readonly taskProgress?: TaskProgress;
13
13
  }
14
14
  export interface RuntimeController {
15
+ getRegisteredTools(): ReturnType<ToolRuntime["getTools"]>;
15
16
  beginInternalOperation(options?: {
16
17
  signal?: AbortSignal;
17
18
  onCancel?: () => void;
@@ -8,4 +8,3 @@ export function getRuntimeController(runtime) {
8
8
  }
9
9
  return controller;
10
10
  }
11
- //# sourceMappingURL=runtime-controller.js.map
@@ -1,3 +1,2 @@
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
@@ -3,8 +3,17 @@ const types = new Set(["object", "array", "string", "number", "integer", "boolea
3
3
  const counts = ["minLength", "maxLength", "minItems", "maxItems"];
4
4
  const bounds = ["minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum"];
5
5
  const keywords = new Set([
6
- "type", "description", "properties", "required", "items", "enum", "additionalProperties",
7
- ...counts, ...bounds, "pattern", "uniqueItems",
6
+ "type",
7
+ "description",
8
+ "properties",
9
+ "required",
10
+ "items",
11
+ "enum",
12
+ "additionalProperties",
13
+ ...counts,
14
+ ...bounds,
15
+ "pattern",
16
+ "uniqueItems",
8
17
  ]);
9
18
  const checkedSchemas = new WeakSet();
10
19
  const patterns = new WeakMap();
@@ -24,7 +33,9 @@ function assertJson(value, path, ancestors = new Set()) {
24
33
  invalid(path, "must be JSON-compatible.");
25
34
  if (ancestors.has(value))
26
35
  invalid(path, "must not contain circular references.");
27
- if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
36
+ if (!Array.isArray(value) &&
37
+ Object.getPrototypeOf(value) !== Object.prototype &&
38
+ Object.getPrototypeOf(value) !== null) {
28
39
  invalid(path, "must be a plain JSON object.");
29
40
  }
30
41
  if (Object.getOwnPropertySymbols(value).length)
@@ -85,7 +96,8 @@ function assertSchema(value, path) {
85
96
  invalid(`${path}.${key}`, "must be a non-negative integer.");
86
97
  }
87
98
  for (const key of bounds) {
88
- if (value[key] !== undefined && (typeof value[key] !== "number" || !Number.isFinite(value[key])))
99
+ if (value[key] !== undefined &&
100
+ (typeof value[key] !== "number" || !Number.isFinite(value[key])))
89
101
  invalid(`${path}.${key}`, "must be a finite number.");
90
102
  }
91
103
  if (value.pattern !== undefined) {
@@ -95,7 +107,8 @@ function assertSchema(value, path) {
95
107
  }
96
108
  if (value.enum !== undefined && (!Array.isArray(value.enum) || value.enum.length === 0))
97
109
  invalid(`${path}.enum`, "must be a non-empty array.");
98
- if (Array.isArray(value.enum) && value.enum.some((item, index, entries) => entries.slice(0, index).some((other) => jsonEqual(item, other))))
110
+ if (Array.isArray(value.enum) &&
111
+ value.enum.some((item, index, entries) => entries.slice(0, index).some((other) => jsonEqual(item, other))))
99
112
  invalid(`${path}.enum`, "must contain unique values.");
100
113
  if (value.properties !== undefined) {
101
114
  if (value.type !== "object" || !isRecord(value.properties))
@@ -104,7 +117,10 @@ function assertSchema(value, path) {
104
117
  assertSchema(property, `${path}.properties.${name}`);
105
118
  }
106
119
  if (value.required !== undefined) {
107
- if (value.type !== "object" || !Array.isArray(value.required) || value.required.some((name) => typeof name !== "string") || new Set(value.required).size !== value.required.length)
120
+ if (value.type !== "object" ||
121
+ !Array.isArray(value.required) ||
122
+ value.required.some((name) => typeof name !== "string") ||
123
+ new Set(value.required).size !== value.required.length)
108
124
  invalid(`${path}.required`, "must contain unique property names.");
109
125
  const properties = value.properties;
110
126
  if (value.required.some((name) => !properties || !Object.hasOwn(properties, name)))
@@ -118,7 +134,7 @@ function assertSchema(value, path) {
118
134
  }
119
135
  export function assertAgentToolInputSchema(value, path = "inputSchema") {
120
136
  if (!isRecord(value) || value.type !== "object")
121
- invalid(path, 'root type must be object.');
137
+ invalid(path, "root type must be object.");
122
138
  if (checkedSchemas.has(value))
123
139
  return;
124
140
  const frozen = assertJson(value, path);
@@ -130,21 +146,29 @@ function jsonEqual(left, right) {
130
146
  if (left === right)
131
147
  return true;
132
148
  if (Array.isArray(left) && Array.isArray(right))
133
- return left.length === right.length && left.every((item, index) => jsonEqual(item, right[index]));
149
+ return (left.length === right.length && left.every((item, index) => jsonEqual(item, right[index])));
134
150
  if (!isRecord(left) || !isRecord(right))
135
151
  return false;
136
152
  const keys = Object.keys(left);
137
- return keys.length === Object.keys(right).length && keys.every((key) => Object.hasOwn(right, key) && jsonEqual(left[key], right[key]));
153
+ return (keys.length === Object.keys(right).length &&
154
+ keys.every((key) => Object.hasOwn(right, key) && jsonEqual(left[key], right[key])));
138
155
  }
139
156
  function typeMatches(schema, value) {
140
157
  switch (schema.type) {
141
- case undefined: return true;
142
- case "null": return value === null;
143
- case "array": return Array.isArray(value);
144
- case "object": return isRecord(value);
145
- case "integer": return typeof value === "number" && Number.isInteger(value);
146
- case "number": return typeof value === "number" && Number.isFinite(value);
147
- default: return typeof value === schema.type;
158
+ case undefined:
159
+ return true;
160
+ case "null":
161
+ return value === null;
162
+ case "array":
163
+ return Array.isArray(value);
164
+ case "object":
165
+ return isRecord(value);
166
+ case "integer":
167
+ return typeof value === "number" && Number.isInteger(value);
168
+ case "number":
169
+ return typeof value === "number" && Number.isFinite(value);
170
+ default:
171
+ return typeof value === schema.type;
148
172
  }
149
173
  }
150
174
  export function validateAgentToolInput(schema, value, path = "input") {
@@ -177,7 +201,8 @@ export function validateAgentToolInput(schema, value, path = "input") {
177
201
  errors.push(`${path} must have at least ${schema.minItems} items.`);
178
202
  if (schema.maxItems !== undefined && value.length > schema.maxItems)
179
203
  errors.push(`${path} must have at most ${schema.maxItems} items.`);
180
- if (schema.uniqueItems && value.some((item, index) => value.slice(0, index).some((other) => jsonEqual(item, other))))
204
+ if (schema.uniqueItems &&
205
+ value.some((item, index) => value.slice(0, index).some((other) => jsonEqual(item, other))))
181
206
  errors.push(`${path} must contain unique items.`);
182
207
  if (schema.items)
183
208
  value.forEach((item, index) => errors.push(...validateAgentToolInput(schema.items, item, `${path}[${index}]`)));
@@ -188,7 +213,9 @@ export function validateAgentToolInput(schema, value, path = "input") {
188
213
  errors.push(`${path}.${key} is required.`);
189
214
  }
190
215
  for (const [key, item] of Object.entries(value)) {
191
- const property = schema.properties && Object.hasOwn(schema.properties, key) ? schema.properties[key] : undefined;
216
+ const property = schema.properties && Object.hasOwn(schema.properties, key)
217
+ ? schema.properties[key]
218
+ : undefined;
192
219
  if (property)
193
220
  errors.push(...validateAgentToolInput(property, item, `${path}.${key}`));
194
221
  else if (schema.additionalProperties === false)
@@ -197,4 +224,3 @@ export function validateAgentToolInput(schema, value, path = "input") {
197
224
  }
198
225
  return errors;
199
226
  }
200
- //# sourceMappingURL=schema.js.map