@nexface/chat 0.1.20 → 0.1.21-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 (38) hide show
  1. package/dist/assistant-components.d.ts +2 -1
  2. package/dist/assistant-components.js +22 -10
  3. package/dist/assistant-runtime.js +1 -0
  4. package/dist/client.d.ts +3 -1
  5. package/dist/client.js +136 -42
  6. package/dist/config.d.ts +1 -1
  7. package/dist/default-chat.d.ts +1 -1
  8. package/dist/default-chat.js +26370 -26035
  9. package/dist/fonts/Inter-OFL.txt +93 -0
  10. package/dist/fonts/inter-medium.ttf +0 -0
  11. package/dist/protocol-messages.js +15 -16
  12. package/dist/protocol-response.js +10 -3
  13. package/dist/react.d.ts +7 -1
  14. package/dist/react.js +124 -12
  15. package/dist/shared/errors.d.ts +1 -1
  16. package/dist/shared/errors.js +2 -0
  17. package/dist/shared/tool-presentation.d.ts +17 -0
  18. package/dist/shared/tool-presentation.js +5 -0
  19. package/dist/shared/tool-proxy.d.ts +6 -0
  20. package/dist/shared/tool-proxy.js +25 -0
  21. package/dist/storage.d.ts +1 -0
  22. package/dist/storage.js +4 -1
  23. package/dist/styles.css +1491 -676
  24. package/dist/tool-confirmation-card.d.ts +5 -0
  25. package/dist/tool-confirmation-card.js +33 -0
  26. package/dist/tool-confirmation.d.ts +23 -0
  27. package/dist/tool-confirmation.js +25 -0
  28. package/dist/tool-presentation.d.ts +6 -0
  29. package/dist/tool-presentation.js +132 -0
  30. package/dist/tool-result.d.ts +5 -0
  31. package/dist/tool-result.js +31 -0
  32. package/dist/types.d.ts +3 -1
  33. package/dist/ui/home-demo/greeting.d.ts +3 -1
  34. package/dist/ui/home-demo/greeting.js +2 -2
  35. package/dist/ui/home-demo/suggestions.d.ts +2 -4
  36. package/dist/ui/home-demo/suggestions.js +5 -4
  37. package/dist/ui/home-demo/trace.js +2 -3
  38. package/package.json +3 -3
@@ -0,0 +1,93 @@
1
+ Copyright 2020 The Inter Project Authors (https://github.com/rsms/inter)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ https://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file
@@ -1,3 +1,4 @@
1
+ import { decodeToolProxy } from "./shared/tool-proxy.js";
1
2
  import { toolError, isNexfaceError } from "./errors.js";
2
3
  import { EventType, mergeMetadata } from "@ag-ui/core";
3
4
  import { getToolResultError } from "./tool-result.js";
@@ -349,14 +350,16 @@ export function projectMessages(messages) {
349
350
  if (message.role === "reasoning" && assistantIds.has(metadata?.reasoningOwnerId))
350
351
  return [];
351
352
  const parts = [];
352
- const text = typeof metadata?.reasoningText === "string"
353
- ? metadata.reasoningText
354
- : typeof message.content === "string"
355
- ? message.content
356
- : (message.content ?? [])
357
- .filter((part) => part.type === "text")
358
- .map((part) => part.text)
359
- .join("");
353
+ const text = typeof metadata?.stoppedText === "string"
354
+ ? metadata.stoppedText
355
+ : typeof metadata?.reasoningText === "string"
356
+ ? metadata.reasoningText
357
+ : typeof message.content === "string"
358
+ ? message.content
359
+ : (message.content ?? [])
360
+ .filter((part) => part.type === "text")
361
+ .map((part) => part.text)
362
+ .join("");
360
363
  const reasoning = ownedReasoning.get(message.id) ?? [];
361
364
  let offset = 0;
362
365
  for (const entry of reasoning) {
@@ -376,6 +379,7 @@ export function projectMessages(messages) {
376
379
  if (message.role === "reasoning" && !text)
377
380
  return [];
378
381
  if (typeof metadata?.reasoningText === "string" &&
382
+ typeof metadata?.stoppedText !== "string" &&
379
383
  typeof message.content === "string" &&
380
384
  message.content !== text) {
381
385
  parts.push({ type: "text", text: message.content });
@@ -389,9 +393,9 @@ export function projectMessages(messages) {
389
393
  let name = call.function.name, args = call.function.arguments;
390
394
  if (name === "nxf_callAppTool")
391
395
  try {
392
- const parsed = JSON.parse(args);
396
+ const parsed = decodeToolProxy(JSON.parse(args));
393
397
  name = parsed.name;
394
- args = JSON.stringify(parsed.input);
398
+ args = JSON.stringify(parsed.arguments);
395
399
  }
396
400
  catch {
397
401
  /* Incomplete arguments remain visible. */
@@ -413,12 +417,7 @@ export function projectMessages(messages) {
413
417
  arguments: args,
414
418
  ...(result?.role === "tool"
415
419
  ? {
416
- result: result.content.length > 4000
417
- ? JSON.stringify({
418
- contentOmitted: true,
419
- preview: result.content.slice(0, 4000),
420
- })
421
- : result.content,
420
+ result: result.content,
422
421
  isError,
423
422
  }
424
423
  : {}),
@@ -1,3 +1,4 @@
1
+ import { decodeToolProxy } from "./shared/tool-proxy.js";
1
2
  export function decodeAgentResponse(messages, snapshot, terminal) {
2
3
  const state = snapshot;
3
4
  const continuation = state?.nexface;
@@ -68,10 +69,13 @@ export function decodeAgentResponse(messages, snapshot, terminal) {
68
69
  if (!args || typeof args !== "object" || Array.isArray(args))
69
70
  throw new Error("Invalid pending tool arguments.");
70
71
  const input = args;
71
- const name = call.name === "nxf_callAppTool" ? input.name : call.name;
72
+ const proxy = call.name === "nxf_callAppTool" ? decodeToolProxy(input) : undefined;
73
+ const name = proxy ? proxy.name : call.name;
72
74
  const toolInput = call.name === "nxf_callAppTool"
73
- ? input.input
74
- : Object.fromEntries(Object.entries(input).filter(([key]) => key !== "progressLabel"));
75
+ ? proxy.arguments
76
+ : actionIsNative(call.name)
77
+ ? Object.fromEntries(Object.entries(input).filter(([key]) => key !== "progressLabel"))
78
+ : input;
75
79
  if (extension.kind !== "client-tool-execution")
76
80
  throw new Error("Unsupported remote interrupt.");
77
81
  const action = extension.action;
@@ -87,3 +91,6 @@ export function decodeAgentResponse(messages, snapshot, terminal) {
87
91
  }
88
92
  return { type: "client-tool-execution", interruptId: interrupt.id, action };
89
93
  }
94
+ function actionIsNative(name) {
95
+ return ["nxf_getSnapshot", "nxf_executeAction", "nxf_applyAction"].includes(name);
96
+ }
package/dist/react.d.ts CHANGED
@@ -8,6 +8,7 @@ import type { NexfaceAgentConfig } from "./config.js";
8
8
  import type { ChatRunResult } from "./types.js";
9
9
  import { type Attachment } from "./attachments.js";
10
10
  import type { UIMessage } from "./messages.js";
11
+ import { type ToolPresentationController } from "./shared/tool-presentation.js";
11
12
  export type { UIMessage, UIMessagePart } from "./messages.js";
12
13
  export type ChatCommandErrorCode = "CHAT_MODEL_SWITCH_BLOCKED" | "CHAT_RUNTIME_CHANGED" | "CHAT_RUN_ACTIVE" | "CHAT_SESSION_CREATE_BLOCKED" | "CHAT_SESSION_SWITCH_BLOCKED" | "INVALID_INPUT" | "UNKNOWN_SESSION";
13
14
  export interface ChatError {
@@ -25,7 +26,6 @@ interface UseChatResult {
25
26
  readonly activeSessionId: string;
26
27
  readonly messages: readonly UIMessage[];
27
28
  readonly status: ChatClientStatus | "cancelling" | "switching-model";
28
- readonly storageWarning?: string;
29
29
  readonly error?: ChatError;
30
30
  readonly model: AgentModelInfo;
31
31
  readonly interrupt?: ToolApprovalInterruptDescriptor;
@@ -60,6 +60,12 @@ export type NexfaceProviderProps = {
60
60
  }) => Promise<Response>;
61
61
  agent?: never;
62
62
  });
63
+ export declare function isChatRecoveryUnavailable(chat: UseChatResult): boolean;
64
+ export declare function canEditChatSession(chat: UseChatResult, sessionId: string): boolean;
63
65
  export declare function assertChatSendable(chat: UseChatResult, sessionId: string): void;
66
+ export declare function useToolPresentations(): {
67
+ controller: ToolPresentationController | undefined;
68
+ report(cause: unknown, sessionId: string, toolCallId: string): void;
69
+ } | null;
64
70
  export declare function NexfaceProvider(props: NexfaceProviderProps): ReactElement;
65
71
  export declare function useChat(): UseChatResult;
package/dist/react.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { confirmationControllers, confirmationRequest, } from "./tool-confirmation.js";
2
3
  import { reportError } from "./errors.js";
3
4
  import { createContext, useContext, useEffect, useLayoutEffect, useRef, useReducer, useCallback, } from "react";
4
5
  import { ToolsProvider } from "@nexface/tools";
@@ -7,6 +8,7 @@ import { createChatClient, getClientController, ClientError, } from "./client.js
7
8
  import { attachmentContent } from "./attachments.js";
8
9
  import { projectMessages } from "./protocol-messages.js";
9
10
  import { chatStorageKey, readChatStorage, writeChatStorage } from "./storage.js";
11
+ import { getToolPresentationController, } from "./shared/tool-presentation.js";
10
12
  export function isChatError(error) {
11
13
  const value = error;
12
14
  return (!!value &&
@@ -15,11 +17,33 @@ export function isChatError(error) {
15
17
  typeof value.message === "string");
16
18
  }
17
19
  const sendGuards = new WeakMap();
20
+ const appendOnlySessions = new WeakMap();
21
+ const chatsWithoutRecovery = new WeakSet();
22
+ export function isChatRecoveryUnavailable(chat) {
23
+ return chatsWithoutRecovery.has(chat);
24
+ }
25
+ export function canEditChatSession(chat, sessionId) {
26
+ return !appendOnlySessions.get(chat)?.has(sessionId);
27
+ }
18
28
  // Read the live Store at draft submission, including updates before React commits.
19
29
  export function assertChatSendable(chat, sessionId) {
20
30
  sendGuards.get(chat.sendMessage)?.(sessionId);
21
31
  }
22
32
  const ChatContext = createContext(null);
33
+ const ToolPresentationContext = createContext(null);
34
+ function ToolPresentationProvider({ controller, report, children, }) {
35
+ const [, changed] = useReducer((revision) => revision + 1, 0);
36
+ useLayoutEffect(() => {
37
+ const unsubscribe = controller?.subscribe(changed);
38
+ // Child bindings may have registered before this provider's layout effect.
39
+ changed();
40
+ return unsubscribe;
41
+ }, [controller]);
42
+ return (_jsx(ToolPresentationContext.Provider, { value: { controller, report }, children: children }));
43
+ }
44
+ export function useToolPresentations() {
45
+ return useContext(ToolPresentationContext);
46
+ }
23
47
  const createId = () => globalThis.crypto.randomUUID();
24
48
  const textOf = (message) => message.parts
25
49
  .filter((part) => part.type === "text")
@@ -66,8 +90,12 @@ export function NexfaceProvider(props) {
66
90
  controller.id = saved.id;
67
91
  controller.setPageResolver((name) => pageTools.current.has(name));
68
92
  if (saved)
69
- controller.restore(saved.messages);
93
+ controller.restore(saved.messages, saved.appendOnly);
70
94
  return {
95
+ confirmations: {
96
+ restored: new Set(saved?.messages.flatMap((message) => message.parts.flatMap((part) => (part.type === "tool" ? [part.toolCallId] : []))) ?? []),
97
+ decisions: new Map(),
98
+ },
71
99
  id: saved?.id ?? controller.id,
72
100
  client,
73
101
  ...(saved?.title ? { title: saved.title } : {}),
@@ -126,20 +154,19 @@ export function NexfaceProvider(props) {
126
154
  changed();
127
155
  }, []);
128
156
  const persist = () => {
129
- if (store.warning)
157
+ if (store.storageConflict)
130
158
  return;
131
159
  const stored = {
132
160
  activeSessionId: store.activeId,
133
161
  sessions: store.sessions.map((session) => ({
134
162
  id: session.id,
135
163
  ...(session.title ? { title: session.title } : {}),
164
+ ...(getClientController(session.client).appendOnly ? { appendOnly: true } : {}),
136
165
  messages: [...projectMessages(session.client.getMessages())],
137
166
  })),
138
167
  };
139
168
  if (writeChatStorage(chatStorageKey, stored, store.version) === "conflict") {
140
- store.warning =
141
- "Chat history was updated in another tab. Saving is paused in this tab. Copy any new messages you want to keep, then refresh to load the latest history.";
142
- changed();
169
+ store.storageConflict = true;
143
170
  }
144
171
  };
145
172
  useEffect(() => {
@@ -269,6 +296,82 @@ export function NexfaceProvider(props) {
269
296
  throw new ClientError("CHAT_RUN_ACTIVE", "A task is already running. Try sending again later.");
270
297
  getClientController(active().client).assertRecoveryAvailable();
271
298
  });
299
+ const confirmationState = (sessionId, request) => {
300
+ const session = store.sessions.find((item) => item.id === sessionId);
301
+ if (!session)
302
+ return "expired";
303
+ const decided = session.confirmations.decisions.get(request.toolCallId);
304
+ if (decided)
305
+ return decided;
306
+ if (session.confirmations.restored.has(request.toolCallId))
307
+ return "expired";
308
+ const messages = projectMessages(session.client.getMessages());
309
+ const lastUser = messages.reduce((last, message, index) => (message.role === "user" ? index : last), -1);
310
+ const owner = messages.findIndex((message) => message.parts.some((part) => {
311
+ const actual = confirmationRequest(part);
312
+ return (actual?.toolCallId === request.toolCallId &&
313
+ actual.requestId === request.requestId &&
314
+ actual.toolName === request.toolName);
315
+ }));
316
+ for (const message of messages)
317
+ for (const part of message.parts) {
318
+ if (part.type !== "tool" || part.name !== request.toolName)
319
+ continue;
320
+ try {
321
+ const decision = JSON.parse(part.arguments)?.confirmation;
322
+ if (decision?.requestId === request.requestId && typeof decision.approved === "boolean")
323
+ return decision.approved ? "approved" : "rejected";
324
+ }
325
+ catch {
326
+ /* Streaming arguments may be incomplete. */
327
+ }
328
+ }
329
+ return owner > lastUser && store.activeId === sessionId ? "pending" : "expired";
330
+ };
331
+ confirmationControllers.set(sendMessage, {
332
+ state: confirmationState,
333
+ async respond(sessionId, request, approved) {
334
+ sendGuards.get(sendMessage)?.(sessionId);
335
+ if (confirmationState(sessionId, request) !== "pending")
336
+ throw new ClientError("INVALID_INPUT", "This confirmation is no longer available.");
337
+ const session = active();
338
+ const controller = getClientController(session.client);
339
+ const messageId = createId();
340
+ session.confirmations.decisions.set(request.toolCallId, "sending");
341
+ changed();
342
+ try {
343
+ const decision = approved ? "确认" : "拒绝";
344
+ const pending = controller.send(JSON.stringify({
345
+ userDecision: {
346
+ toolName: request.toolName,
347
+ toolCallId: request.toolCallId,
348
+ requestId: request.requestId,
349
+ approved,
350
+ },
351
+ message: `${decision}:${request.message}`,
352
+ }), {
353
+ id: messageId,
354
+ role: "user",
355
+ parts: [{ type: "text", text: `${decision}此操作` }],
356
+ });
357
+ if (controller.getMessages().some((message) => message.id === messageId)) {
358
+ session.confirmations.decisions.set(request.toolCallId, approved ? "approved" : "rejected");
359
+ delete store.completion;
360
+ changed();
361
+ }
362
+ const result = await pending;
363
+ store.completion = { id: createId(), sessionId, result };
364
+ }
365
+ finally {
366
+ // An admitted reply remains answered even if the following model run fails.
367
+ if (controller.getMessages().some((message) => message.id === messageId))
368
+ session.confirmations.decisions.set(request.toolCallId, approved ? "approved" : "rejected");
369
+ else
370
+ session.confirmations.decisions.delete(request.toolCallId);
371
+ changed();
372
+ }
373
+ },
374
+ });
272
375
  const session = active();
273
376
  const client = session.client;
274
377
  const controller = getClientController(client);
@@ -297,7 +400,6 @@ export function NexfaceProvider(props) {
297
400
  : client.getStatus(),
298
401
  model: controller.agent?.model ?? { provider: "server", model: "server" },
299
402
  ...(approval ? { interrupt: approval } : {}),
300
- ...(store.warning ? { storageWarning: store.warning } : {}),
301
403
  ...(error || store.error ? { error: error ? asError(error) : store.error } : {}),
302
404
  ...(store.completion?.sessionId === session.id
303
405
  ? { completed: { id: store.completion.id, result: store.completion.result } }
@@ -356,12 +458,22 @@ export function NexfaceProvider(props) {
356
458
  }
357
459
  },
358
460
  };
359
- 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) => {
360
- if (registered)
361
- pageTools.current.add(name);
362
- else
363
- pageTools.current.delete(name);
364
- }, children: children }) }) }));
461
+ if (controller.recoveryUnavailable)
462
+ chatsWithoutRecovery.add(value);
463
+ appendOnlySessions.set(value, new Set(store.sessions
464
+ .filter(({ client }) => getClientController(client).appendOnly)
465
+ .map(({ id }) => id)));
466
+ return (_jsx(ChatContext.Provider, { value: value, children: _jsx(ToolPresentationProvider, { controller: getToolPresentationController(toolRuntime), report: (cause, sessionId, toolCallId) => reportError({
467
+ cause,
468
+ sessionId,
469
+ toolCallId,
470
+ code: "CHAT_TOOL_RENDER_FAILED",
471
+ }, onError.current), 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) => {
472
+ if (registered)
473
+ pageTools.current.add(name);
474
+ else
475
+ pageTools.current.delete(name);
476
+ }, children: children }) }) }) }));
365
477
  }
366
478
  export function useChat() {
367
479
  const chat = useContext(ChatContext);
@@ -1,4 +1,4 @@
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"];
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_CONFIRMATION_RESULT", "TOOL_CONFIRMATION_LIMIT", "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
2
  type AgentToolErrorCode = (typeof TOOL_ERROR_CODES)[number];
3
3
  export declare class AgentToolError extends Error {
4
4
  readonly code: AgentToolErrorCode;
@@ -10,6 +10,8 @@ export const TOOL_ERROR_CODES = [
10
10
  "CONTRACT_MISMATCH",
11
11
  "DUPLICATE_BINDING",
12
12
  "INVALID_INPUT",
13
+ "INVALID_CONFIRMATION_RESULT",
14
+ "TOOL_CONFIRMATION_LIMIT",
13
15
  "INVALID_TOOL_RUNTIME",
14
16
  "OPERATION_BUSY",
15
17
  "TOOL_CANCELLED",
@@ -0,0 +1,17 @@
1
+ import type { ToolRuntime } from "@nexface/tools";
2
+ export interface ToolRenderContext<TInput = unknown, TResult = unknown> {
3
+ input: TInput;
4
+ status: "running" | "success" | "error" | "cancelled";
5
+ result?: TResult;
6
+ }
7
+ export interface ToolPresentation {
8
+ definition: ReturnType<ToolRuntime["getTools"]>[number]["definition"];
9
+ confirmationProtocol?: true;
10
+ render(context: ToolRenderContext): unknown;
11
+ }
12
+ export interface ToolPresentationController {
13
+ get(name: string): ToolPresentation | undefined;
14
+ subscribe(listener: () => void): () => void;
15
+ }
16
+ export declare const toolPresentationSymbol: unique symbol;
17
+ export declare function getToolPresentationController(runtime: ToolRuntime): ToolPresentationController | undefined;
@@ -0,0 +1,5 @@
1
+ // Generated from shared/tool-presentation.ts. Do not edit manually.
2
+ export const toolPresentationSymbol = Symbol.for("@nexface/tools/tool-presentation");
3
+ export function getToolPresentationController(runtime) {
4
+ return runtime[toolPresentationSymbol];
5
+ }
@@ -0,0 +1,6 @@
1
+ /** Decode the proxy envelope without changing business arguments. */
2
+ export declare function decodeToolProxy(value: Record<string, unknown>): {
3
+ name: string;
4
+ arguments: Record<string, unknown>;
5
+ progressLabel?: string;
6
+ };
@@ -0,0 +1,25 @@
1
+ // Generated from shared/tool-proxy.ts. Do not edit manually.
2
+ /** Decode the proxy envelope without changing business arguments. */
3
+ export function decodeToolProxy(value) {
4
+ if (typeof value.name !== "string" || !value.name.trim())
5
+ throw new Error("nxf_callAppTool needs a non-empty string name.");
6
+ const keys = Object.keys(value).filter((key) => !["name", "arguments", "input", "progressLabel"].includes(key));
7
+ if (keys.length)
8
+ throw new Error(`nxf_callAppTool received unexpected fields: ${keys.join(", ")}.`);
9
+ const modern = Object.hasOwn(value, "arguments");
10
+ const legacy = Object.hasOwn(value, "input");
11
+ if (modern === legacy)
12
+ throw new Error("nxf_callAppTool requires exactly one of arguments or legacy input.");
13
+ const args = modern ? value.arguments : value.input;
14
+ if (!args || typeof args !== "object" || Array.isArray(args))
15
+ throw new Error(`nxf_callAppTool arguments for "${value.name}" must be an object.`);
16
+ if (value.progressLabel !== undefined && typeof value.progressLabel !== "string")
17
+ throw new Error("nxf_callAppTool progressLabel must be a string.");
18
+ return {
19
+ name: value.name,
20
+ arguments: args,
21
+ ...(typeof value.progressLabel === "string" && value.progressLabel.trim()
22
+ ? { progressLabel: value.progressLabel.trim() }
23
+ : {}),
24
+ };
25
+ }
package/dist/storage.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare const chatStorageKey = "nexface:chat:sessions:v3";
4
4
  interface StoredSession {
5
5
  id: string;
6
6
  title?: string;
7
+ appendOnly?: boolean;
7
8
  messages: UIMessage[];
8
9
  }
9
10
  interface StoredChat {
package/dist/storage.js CHANGED
@@ -176,6 +176,7 @@ export function readChatStorage(key, version) {
176
176
  typeof session.id !== "string" ||
177
177
  !session.id ||
178
178
  (session.title !== undefined && typeof session.title !== "string") ||
179
+ (session.appendOnly !== undefined && typeof session.appendOnly !== "boolean") ||
179
180
  !Array.isArray(session.messages) ||
180
181
  !session.messages.every(isMessage) ||
181
182
  sessions.some((existing) => existing.id === session.id))
@@ -183,6 +184,7 @@ export function readChatStorage(key, version) {
183
184
  sessions.push({
184
185
  id: session.id,
185
186
  ...(session.title ? { title: session.title } : {}),
187
+ ...(session.appendOnly ? { appendOnly: true } : {}),
186
188
  messages: migratePageTaskResults(withoutReasoning(session.messages)).map(restoreMessage),
187
189
  });
188
190
  }
@@ -198,9 +200,10 @@ export function writeChatStorage(key, state, version) {
198
200
  const next = JSON.stringify({
199
201
  version: 3,
200
202
  activeSessionId: state.activeSessionId,
201
- sessions: state.sessions.map(({ id, title, messages }) => ({
203
+ sessions: state.sessions.map(({ id, title, appendOnly, messages }) => ({
202
204
  id,
203
205
  title,
206
+ ...(appendOnly ? { appendOnly } : {}),
204
207
  messages: withoutReasoning(messages).map((message) => ({
205
208
  ...message,
206
209
  parts: message.parts.map((part) => part.type === "tool" && part.error