@nexface/chat 0.1.15-alpha.1 → 0.1.15-alpha.3

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 (130) 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 +309 -77
  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.d.ts +1 -0
  12. package/dist/errors.js +69 -18
  13. package/dist/index.js +0 -1
  14. package/dist/messages.js +0 -1
  15. package/dist/page-confirmation.js +3 -4
  16. package/dist/protocol-messages.js +290 -66
  17. package/dist/protocol-response.js +38 -18
  18. package/dist/react.d.ts +1 -1
  19. package/dist/react.js +147 -50
  20. package/dist/shared/errors.d.ts +1 -1
  21. package/dist/shared/errors.js +0 -1
  22. package/dist/shared/runtime-controller.d.ts +1 -0
  23. package/dist/shared/runtime-controller.js +0 -1
  24. package/dist/shared/runtime-execution.js +0 -1
  25. package/dist/shared/schema.js +45 -19
  26. package/dist/storage.js +130 -53
  27. package/dist/styles.css +99 -20
  28. package/dist/tool-result.js +7 -3
  29. package/dist/types.js +0 -1
  30. package/dist/ui/attachment.aui.d.ts +1 -1
  31. package/dist/ui/attachment.aui.js +16 -20
  32. package/dist/ui/avatar.js +0 -1
  33. package/dist/ui/button.js +0 -1
  34. package/dist/ui/code-block.js +2 -3
  35. package/dist/ui/collapsible.js +2 -3
  36. package/dist/ui/composer-voice.js +3 -2
  37. package/dist/ui/dialog.d.ts +1 -1
  38. package/dist/ui/dialog.js +9 -4
  39. package/dist/ui/dropdown-menu.js +2 -3
  40. package/dist/ui/home-demo/action-bar.js +0 -1
  41. package/dist/ui/home-demo/composer.js +7 -4
  42. package/dist/ui/home-demo/greeting.d.ts +1 -1
  43. package/dist/ui/home-demo/greeting.js +1 -2
  44. package/dist/ui/home-demo/messages.d.ts +1 -1
  45. package/dist/ui/home-demo/messages.js +4 -5
  46. package/dist/ui/home-demo/styles.js +0 -1
  47. package/dist/ui/home-demo/suggestions.d.ts +1 -1
  48. package/dist/ui/home-demo/suggestions.js +5 -3
  49. package/dist/ui/home-demo/surfaces.js +3 -2
  50. package/dist/ui/home-demo/thread.d.ts +1 -1
  51. package/dist/ui/home-demo/thread.js +1 -2
  52. package/dist/ui/home-demo/trace-line.d.ts +1 -1
  53. package/dist/ui/home-demo/trace-line.js +2 -3
  54. package/dist/ui/home-demo/trace.d.ts +1 -1
  55. package/dist/ui/home-demo/trace.js +28 -9
  56. package/dist/ui/home-demo/type.js +0 -1
  57. package/dist/ui/input.js +0 -1
  58. package/dist/ui/markdown-text.js +2 -3
  59. package/dist/ui/reasoning.aui.js +2 -3
  60. package/dist/ui/reasoning.d.ts +1 -1
  61. package/dist/ui/reasoning.js +6 -9
  62. package/dist/ui/surface.js +27 -8
  63. package/dist/ui/thread-list.aui.d.ts +2 -2
  64. package/dist/ui/thread-list.aui.js +18 -12
  65. package/dist/ui/tool-group.aui.js +2 -3
  66. package/dist/ui/tooltip-icon-button.js +1 -2
  67. package/dist/ui/tooltip.js +0 -1
  68. package/dist/ui/use-attachment-src.js +1 -2
  69. package/dist/ui/use-copy-to-clipboard.d.ts +1 -1
  70. package/dist/ui/use-copy-to-clipboard.js +1 -2
  71. package/dist/ui/utils.js +9 -3
  72. package/dist/use-next-message.js +7 -4
  73. package/dist/voice/types.js +0 -1
  74. package/dist/voice/use-voice.js +35 -13
  75. package/package.json +8 -4
  76. package/dist/assistant-attachments.js.map +0 -1
  77. package/dist/assistant-components.js.map +0 -1
  78. package/dist/assistant-runtime.js.map +0 -1
  79. package/dist/attachments.js.map +0 -1
  80. package/dist/client.js.map +0 -1
  81. package/dist/config.js.map +0 -1
  82. package/dist/default-chat.js.map +0 -7
  83. package/dist/errors.js.map +0 -1
  84. package/dist/index.js.map +0 -1
  85. package/dist/messages.js.map +0 -1
  86. package/dist/page-confirmation.js.map +0 -1
  87. package/dist/protocol-messages.js.map +0 -1
  88. package/dist/protocol-response.js.map +0 -1
  89. package/dist/react.js.map +0 -1
  90. package/dist/shared/errors.js.map +0 -1
  91. package/dist/shared/runtime-controller.js.map +0 -1
  92. package/dist/shared/runtime-execution.js.map +0 -1
  93. package/dist/shared/schema.js.map +0 -1
  94. package/dist/storage.js.map +0 -1
  95. package/dist/tool-result.js.map +0 -1
  96. package/dist/types.js.map +0 -1
  97. package/dist/ui/attachment.aui.js.map +0 -1
  98. package/dist/ui/avatar.js.map +0 -1
  99. package/dist/ui/button.js.map +0 -1
  100. package/dist/ui/code-block.js.map +0 -1
  101. package/dist/ui/collapsible.js.map +0 -1
  102. package/dist/ui/composer-voice.js.map +0 -1
  103. package/dist/ui/dialog.js.map +0 -1
  104. package/dist/ui/dropdown-menu.js.map +0 -1
  105. package/dist/ui/home-demo/action-bar.js.map +0 -1
  106. package/dist/ui/home-demo/composer.js.map +0 -1
  107. package/dist/ui/home-demo/greeting.js.map +0 -1
  108. package/dist/ui/home-demo/messages.js.map +0 -1
  109. package/dist/ui/home-demo/styles.js.map +0 -1
  110. package/dist/ui/home-demo/suggestions.js.map +0 -1
  111. package/dist/ui/home-demo/surfaces.js.map +0 -1
  112. package/dist/ui/home-demo/thread.js.map +0 -1
  113. package/dist/ui/home-demo/trace-line.js.map +0 -1
  114. package/dist/ui/home-demo/trace.js.map +0 -1
  115. package/dist/ui/home-demo/type.js.map +0 -1
  116. package/dist/ui/input.js.map +0 -1
  117. package/dist/ui/markdown-text.js.map +0 -1
  118. package/dist/ui/reasoning.aui.js.map +0 -1
  119. package/dist/ui/reasoning.js.map +0 -1
  120. package/dist/ui/surface.js.map +0 -1
  121. package/dist/ui/thread-list.aui.js.map +0 -1
  122. package/dist/ui/tool-group.aui.js.map +0 -1
  123. package/dist/ui/tooltip-icon-button.js.map +0 -1
  124. package/dist/ui/tooltip.js.map +0 -1
  125. package/dist/ui/use-attachment-src.js.map +0 -1
  126. package/dist/ui/use-copy-to-clipboard.js.map +0 -1
  127. package/dist/ui/utils.js.map +0 -1
  128. package/dist/use-next-message.js.map +0 -1
  129. package/dist/voice/types.js.map +0 -1
  130. package/dist/voice/use-voice.js.map +0 -1
package/dist/errors.d.ts CHANGED
@@ -18,6 +18,7 @@ export interface NexfaceErrorEvent {
18
18
  /** Available local exception or serialized remote diagnostic; never persisted by Chat. */
19
19
  readonly cause: unknown;
20
20
  }
21
+ export declare function reportError(event: NexfaceErrorEvent, onError?: (event: NexfaceErrorEvent) => void): void;
21
22
  export type ToolState = "failed" | "unknown" | "not_started" | "cancelled" | "rejected";
22
23
  export declare function runError(id: string, cause: unknown, unknownTools?: boolean): NexfaceError;
23
24
  export declare function toolError(id: string, toolCallId: string, content: string, parentErrorId?: string, outcomeUnknown?: boolean, toolName?: string): {
package/dist/errors.js CHANGED
@@ -1,12 +1,32 @@
1
+ export function reportError(event, onError) {
2
+ try {
3
+ if (onError) {
4
+ // Also contain rejected promises from async diagnostic callbacks.
5
+ void Promise.resolve(onError(event)).catch(() => undefined);
6
+ }
7
+ else {
8
+ console.error("[Nexface]", event.cause, event);
9
+ }
10
+ }
11
+ catch {
12
+ /* Diagnostics must not affect task execution. */
13
+ }
14
+ }
1
15
  function errorCode(cause) {
2
- return cause && typeof cause === "object" && "code" in cause && typeof cause.code === "string" ? cause.code : undefined;
16
+ return cause && typeof cause === "object" && "code" in cause && typeof cause.code === "string"
17
+ ? cause.code
18
+ : undefined;
3
19
  }
4
20
  export function runError(id, cause, unknownTools = false) {
5
21
  const code = errorCode(cause) ?? "CHAT_RUN_ERROR";
6
- const userMessage = unknownTools ? "Some results are missing. Check whether the actions completed."
7
- : code === "CHAT_REQUEST_FAILED" ? "Request failed. Please try again later."
8
- : code === "CHAT_STREAM_INCOMPLETE" ? "The response ended before it was complete."
9
- : code === "CHAT_RECOVERY_UNAVAILABLE" ? "This chat cannot continue. Check the action results, then start a new chat."
22
+ const userMessage = unknownTools
23
+ ? "Some results are missing. Check whether the actions completed."
24
+ : code === "CHAT_REQUEST_FAILED"
25
+ ? "Request failed. Please try again later."
26
+ : code === "CHAT_STREAM_INCOMPLETE"
27
+ ? "The response ended before it was complete."
28
+ : code === "CHAT_RECOVERY_UNAVAILABLE"
29
+ ? "This chat cannot continue. Check the action results, then start a new chat."
10
30
  : "Something went wrong.";
11
31
  return { id, scope: "run", code, userMessage };
12
32
  }
@@ -15,7 +35,10 @@ export function toolError(id, toolCallId, content, parentErrorId, outcomeUnknown
15
35
  try {
16
36
  const payload = JSON.parse(content);
17
37
  cause = payload?.error;
18
- if (!cause && toolName && ["nxf_executeAction", "nxf_applyAction", "nxf_getSnapshot"].includes(toolName) && payload?.result?.ok === false)
38
+ if (!cause &&
39
+ toolName &&
40
+ ["nxf_executeAction", "nxf_applyAction", "nxf_getSnapshot"].includes(toolName) &&
41
+ payload?.result?.ok === false)
19
42
  cause = payload.result.error;
20
43
  }
21
44
  catch {
@@ -23,31 +46,60 @@ export function toolError(id, toolCallId, content, parentErrorId, outcomeUnknown
23
46
  }
24
47
  if (!cause)
25
48
  return {};
26
- const code = outcomeUnknown ? "EXECUTION_OUTCOME_UNKNOWN" : errorCode(cause) ?? "TOOL_ERROR";
49
+ const code = outcomeUnknown ? "EXECUTION_OUTCOME_UNKNOWN" : (errorCode(cause) ?? "TOOL_ERROR");
27
50
  if (code === "TOOL_CONFIRMATION_REJECTED")
28
51
  return { toolState: "rejected" };
29
52
  if (code === "TOOL_SKIPPED")
30
53
  return { toolState: "not_started" };
31
54
  if (code === "TOOL_CANCELLED")
32
55
  return { toolState: "cancelled" };
33
- const execution = code === "EXECUTION_OUTCOME_UNKNOWN" ? "unknown"
34
- : ["INVALID_INPUT", "UNKNOWN_TOOL", "TOOL_UNAVAILABLE", "TOOL_CONFIRMATION_UNAVAILABLE", "TOOL_CONFIRMATION_INVALIDATED", "TOOL_REGISTRATION_TIMEOUT"].includes(code) ? "not_started" : "failed";
35
- return { toolState: execution, cause, error: {
36
- id, scope: "tool", code, toolCallId, execution,
37
- userMessage: execution === "unknown" ? "No result was received. Check whether the action completed." : execution === "not_started" ? "The action could not start." : "The action failed.",
56
+ const execution = code === "EXECUTION_OUTCOME_UNKNOWN"
57
+ ? "unknown"
58
+ : [
59
+ "INVALID_INPUT",
60
+ "UNKNOWN_TOOL",
61
+ "TOOL_UNAVAILABLE",
62
+ "TOOL_CONFIRMATION_UNAVAILABLE",
63
+ "TOOL_CONFIRMATION_INVALIDATED",
64
+ "TOOL_REGISTRATION_TIMEOUT",
65
+ ].includes(code)
66
+ ? "not_started"
67
+ : "failed";
68
+ return {
69
+ toolState: execution,
70
+ cause,
71
+ error: {
72
+ id,
73
+ scope: "tool",
74
+ code,
75
+ toolCallId,
76
+ execution,
77
+ userMessage: execution === "unknown"
78
+ ? "No result was received. Check whether the action completed."
79
+ : execution === "not_started"
80
+ ? "The action could not start."
81
+ : "The action failed.",
38
82
  ...(parentErrorId ? { parentErrorId } : {}),
39
- } };
83
+ },
84
+ };
40
85
  }
41
86
  export function isNexfaceError(value) {
42
87
  if (!value || typeof value !== "object")
43
88
  return false;
44
89
  const error = value;
45
- return typeof error.id === "string" && typeof error.code === "string" && typeof error.userMessage === "string"
46
- && (error.parentErrorId === undefined || typeof error.parentErrorId === "string")
47
- && (error.scope === "run" || error.scope === "tool" && typeof error.toolCallId === "string" && ["not_started", "failed", "unknown"].includes(String(error.execution)));
90
+ return (typeof error.id === "string" &&
91
+ typeof error.code === "string" &&
92
+ typeof error.userMessage === "string" &&
93
+ (error.parentErrorId === undefined || typeof error.parentErrorId === "string") &&
94
+ (error.scope === "run" ||
95
+ (error.scope === "tool" &&
96
+ typeof error.toolCallId === "string" &&
97
+ ["not_started", "failed", "unknown"].includes(String(error.execution)))));
48
98
  }
49
99
  const presentedFailures = new WeakSet();
50
- export function markErrorPresented(error) { presentedFailures.add(error); }
100
+ export function markErrorPresented(error) {
101
+ presentedFailures.add(error);
102
+ }
51
103
  export function sendErrorNotice(error) {
52
104
  if (error instanceof Error && presentedFailures.has(error))
53
105
  return "";
@@ -58,4 +110,3 @@ export function sendErrorNotice(error) {
58
110
  return "Check your message and send it again.";
59
111
  return runError("send", error).userMessage;
60
112
  }
61
- //# sourceMappingURL=errors.js.map
package/dist/index.js CHANGED
@@ -3,4 +3,3 @@ import "./styles.css";
3
3
  export { Chat } from "./default-chat.js";
4
4
  export { NexfaceProvider } from "./react.js";
5
5
  export { usePageConfirmation } from "./page-confirmation.js";
6
- //# sourceMappingURL=index.js.map
package/dist/messages.js CHANGED
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=messages.js.map
@@ -40,9 +40,9 @@ export function PageConfirmationProvider({ interrupt, onConfirm, onBindingRemove
40
40
  if (resumingRef.current.has(binding))
41
41
  return true;
42
42
  const pending = interruptRef.current;
43
- if (pending?.mode !== "page"
44
- || pending.toolName !== binding.toolName
45
- || bindingsRef.current.get(binding.toolName) !== binding) {
43
+ if (pending?.mode !== "page" ||
44
+ pending.toolName !== binding.toolName ||
45
+ bindingsRef.current.get(binding.toolName) !== binding) {
46
46
  return false;
47
47
  }
48
48
  resumingRef.current.add(binding);
@@ -86,4 +86,3 @@ export function usePageConfirmation(binding, fallback) {
86
86
  return fallbackRef.current(...args);
87
87
  }, [binding, context]);
88
88
  }
89
- //# sourceMappingURL=page-confirmation.js.map