@nexface/chat 0.1.14 → 0.1.15-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assistant-attachments.js +17 -60
- package/dist/assistant-attachments.js.map +1 -0
- package/dist/assistant-components.d.ts +3 -3
- package/dist/assistant-components.js +29 -77
- package/dist/assistant-components.js.map +1 -0
- package/dist/assistant-runtime.d.ts +1 -1
- package/dist/assistant-runtime.js +43 -100
- package/dist/assistant-runtime.js.map +1 -0
- package/dist/attachments.js +15 -36
- package/dist/attachments.js.map +1 -0
- package/dist/client.js +73 -312
- package/dist/client.js.map +1 -0
- package/dist/config.js +5 -4
- package/dist/config.js.map +1 -0
- package/dist/default-chat.d.ts +1 -1
- package/dist/default-chat.js +728 -2102
- package/dist/default-chat.js.map +7 -0
- package/dist/errors.js +18 -55
- package/dist/errors.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/messages.js +1 -0
- package/dist/messages.js.map +1 -0
- package/dist/page-confirmation.js +4 -3
- package/dist/page-confirmation.js.map +1 -0
- package/dist/protocol-messages.js +66 -290
- package/dist/protocol-messages.js.map +1 -0
- package/dist/protocol-response.js +18 -38
- package/dist/protocol-response.js.map +1 -0
- package/dist/react.js +50 -146
- package/dist/react.js.map +1 -0
- package/dist/shared/errors.d.ts +1 -1
- package/dist/shared/errors.js +1 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/shared/runtime-controller.d.ts +0 -1
- package/dist/shared/runtime-controller.js +1 -0
- package/dist/shared/runtime-controller.js.map +1 -0
- package/dist/shared/runtime-execution.js +1 -0
- package/dist/shared/runtime-execution.js.map +1 -0
- package/dist/shared/schema.js +19 -45
- package/dist/shared/schema.js.map +1 -0
- package/dist/storage.js +53 -130
- package/dist/storage.js.map +1 -0
- package/dist/styles.css +20 -99
- package/dist/tool-result.js +3 -7
- package/dist/tool-result.js.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/attachment.aui.d.ts +1 -1
- package/dist/ui/attachment.aui.js +20 -16
- package/dist/ui/attachment.aui.js.map +1 -0
- package/dist/ui/avatar.js +1 -0
- package/dist/ui/avatar.js.map +1 -0
- package/dist/ui/button.js +1 -0
- package/dist/ui/button.js.map +1 -0
- package/dist/ui/code-block.js +3 -2
- package/dist/ui/code-block.js.map +1 -0
- package/dist/ui/collapsible.js +3 -2
- package/dist/ui/collapsible.js.map +1 -0
- package/dist/ui/composer-voice.js +2 -3
- package/dist/ui/composer-voice.js.map +1 -0
- package/dist/ui/dialog.d.ts +1 -1
- package/dist/ui/dialog.js +4 -9
- package/dist/ui/dialog.js.map +1 -0
- package/dist/ui/dropdown-menu.js +3 -2
- package/dist/ui/dropdown-menu.js.map +1 -0
- package/dist/ui/home-demo/action-bar.js +1 -0
- package/dist/ui/home-demo/action-bar.js.map +1 -0
- package/dist/ui/home-demo/composer.js +4 -7
- package/dist/ui/home-demo/composer.js.map +1 -0
- package/dist/ui/home-demo/greeting.d.ts +1 -1
- package/dist/ui/home-demo/greeting.js +2 -1
- package/dist/ui/home-demo/greeting.js.map +1 -0
- package/dist/ui/home-demo/messages.d.ts +1 -1
- package/dist/ui/home-demo/messages.js +5 -4
- package/dist/ui/home-demo/messages.js.map +1 -0
- package/dist/ui/home-demo/styles.js +1 -0
- package/dist/ui/home-demo/styles.js.map +1 -0
- package/dist/ui/home-demo/suggestions.d.ts +1 -1
- package/dist/ui/home-demo/suggestions.js +3 -5
- package/dist/ui/home-demo/suggestions.js.map +1 -0
- package/dist/ui/home-demo/surfaces.js +2 -3
- package/dist/ui/home-demo/surfaces.js.map +1 -0
- package/dist/ui/home-demo/thread.d.ts +1 -1
- package/dist/ui/home-demo/thread.js +2 -1
- package/dist/ui/home-demo/thread.js.map +1 -0
- package/dist/ui/home-demo/trace-line.d.ts +1 -1
- package/dist/ui/home-demo/trace-line.js +3 -2
- package/dist/ui/home-demo/trace-line.js.map +1 -0
- package/dist/ui/home-demo/trace.d.ts +1 -1
- package/dist/ui/home-demo/trace.js +9 -28
- package/dist/ui/home-demo/trace.js.map +1 -0
- package/dist/ui/home-demo/type.js +1 -0
- package/dist/ui/home-demo/type.js.map +1 -0
- package/dist/ui/input.js +1 -0
- package/dist/ui/input.js.map +1 -0
- package/dist/ui/markdown-text.js +3 -2
- package/dist/ui/markdown-text.js.map +1 -0
- package/dist/ui/reasoning.aui.js +3 -2
- package/dist/ui/reasoning.aui.js.map +1 -0
- package/dist/ui/reasoning.d.ts +1 -1
- package/dist/ui/reasoning.js +9 -6
- package/dist/ui/reasoning.js.map +1 -0
- package/dist/ui/surface.js +8 -27
- package/dist/ui/surface.js.map +1 -0
- package/dist/ui/thread-list.aui.d.ts +2 -2
- package/dist/ui/thread-list.aui.js +12 -18
- package/dist/ui/thread-list.aui.js.map +1 -0
- package/dist/ui/tool-group.aui.js +3 -2
- package/dist/ui/tool-group.aui.js.map +1 -0
- package/dist/ui/tooltip-icon-button.js +2 -1
- package/dist/ui/tooltip-icon-button.js.map +1 -0
- package/dist/ui/tooltip.js +1 -0
- package/dist/ui/tooltip.js.map +1 -0
- package/dist/ui/use-attachment-src.js +2 -1
- package/dist/ui/use-attachment-src.js.map +1 -0
- package/dist/ui/use-copy-to-clipboard.d.ts +1 -1
- package/dist/ui/use-copy-to-clipboard.js +2 -1
- package/dist/ui/use-copy-to-clipboard.js.map +1 -0
- package/dist/ui/utils.js +3 -9
- package/dist/ui/utils.js.map +1 -0
- package/dist/use-next-message.js +4 -7
- package/dist/use-next-message.js.map +1 -0
- package/dist/voice/types.js +1 -0
- package/dist/voice/types.js.map +1 -0
- package/dist/voice/use-voice.js +13 -35
- package/dist/voice/use-voice.js.map +1 -0
- package/package.json +4 -8
package/dist/errors.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
function errorCode(cause) {
|
|
2
|
-
return cause && typeof cause === "object" && "code" in cause && typeof cause.code === "string"
|
|
3
|
-
? cause.code
|
|
4
|
-
: undefined;
|
|
2
|
+
return cause && typeof cause === "object" && "code" in cause && typeof cause.code === "string" ? cause.code : undefined;
|
|
5
3
|
}
|
|
6
4
|
export function runError(id, cause, unknownTools = false) {
|
|
7
5
|
const code = errorCode(cause) ?? "CHAT_RUN_ERROR";
|
|
8
|
-
const userMessage = unknownTools
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
: code === "CHAT_STREAM_INCOMPLETE"
|
|
13
|
-
? "The response ended before it was complete."
|
|
14
|
-
: code === "CHAT_RECOVERY_UNAVAILABLE"
|
|
15
|
-
? "This chat cannot continue. Check the action results, then start a new chat."
|
|
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."
|
|
16
10
|
: "Something went wrong.";
|
|
17
11
|
return { id, scope: "run", code, userMessage };
|
|
18
12
|
}
|
|
@@ -21,10 +15,7 @@ export function toolError(id, toolCallId, content, parentErrorId, outcomeUnknown
|
|
|
21
15
|
try {
|
|
22
16
|
const payload = JSON.parse(content);
|
|
23
17
|
cause = payload?.error;
|
|
24
|
-
if (!cause &&
|
|
25
|
-
toolName &&
|
|
26
|
-
["nxf_executeAction", "nxf_applyAction", "nxf_getSnapshot"].includes(toolName) &&
|
|
27
|
-
payload?.result?.ok === false)
|
|
18
|
+
if (!cause && toolName && ["nxf_executeAction", "nxf_applyAction", "nxf_getSnapshot"].includes(toolName) && payload?.result?.ok === false)
|
|
28
19
|
cause = payload.result.error;
|
|
29
20
|
}
|
|
30
21
|
catch {
|
|
@@ -32,60 +23,31 @@ export function toolError(id, toolCallId, content, parentErrorId, outcomeUnknown
|
|
|
32
23
|
}
|
|
33
24
|
if (!cause)
|
|
34
25
|
return {};
|
|
35
|
-
const code = outcomeUnknown ? "EXECUTION_OUTCOME_UNKNOWN" :
|
|
26
|
+
const code = outcomeUnknown ? "EXECUTION_OUTCOME_UNKNOWN" : errorCode(cause) ?? "TOOL_ERROR";
|
|
36
27
|
if (code === "TOOL_CONFIRMATION_REJECTED")
|
|
37
28
|
return { toolState: "rejected" };
|
|
38
29
|
if (code === "TOOL_SKIPPED")
|
|
39
30
|
return { toolState: "not_started" };
|
|
40
31
|
if (code === "TOOL_CANCELLED")
|
|
41
32
|
return { toolState: "cancelled" };
|
|
42
|
-
const execution = code === "EXECUTION_OUTCOME_UNKNOWN"
|
|
43
|
-
? "
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"TOOL_UNAVAILABLE",
|
|
48
|
-
"TOOL_CONFIRMATION_UNAVAILABLE",
|
|
49
|
-
"TOOL_CONFIRMATION_INVALIDATED",
|
|
50
|
-
"TOOL_REGISTRATION_TIMEOUT",
|
|
51
|
-
].includes(code)
|
|
52
|
-
? "not_started"
|
|
53
|
-
: "failed";
|
|
54
|
-
return {
|
|
55
|
-
toolState: execution,
|
|
56
|
-
cause,
|
|
57
|
-
error: {
|
|
58
|
-
id,
|
|
59
|
-
scope: "tool",
|
|
60
|
-
code,
|
|
61
|
-
toolCallId,
|
|
62
|
-
execution,
|
|
63
|
-
userMessage: execution === "unknown"
|
|
64
|
-
? "No result was received. Check whether the action completed."
|
|
65
|
-
: execution === "not_started"
|
|
66
|
-
? "The action could not start."
|
|
67
|
-
: "The action failed.",
|
|
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.",
|
|
68
38
|
...(parentErrorId ? { parentErrorId } : {}),
|
|
69
|
-
}
|
|
70
|
-
};
|
|
39
|
+
} };
|
|
71
40
|
}
|
|
72
41
|
export function isNexfaceError(value) {
|
|
73
42
|
if (!value || typeof value !== "object")
|
|
74
43
|
return false;
|
|
75
44
|
const error = value;
|
|
76
|
-
return
|
|
77
|
-
typeof error.
|
|
78
|
-
typeof error.
|
|
79
|
-
(error.parentErrorId === undefined || typeof error.parentErrorId === "string") &&
|
|
80
|
-
(error.scope === "run" ||
|
|
81
|
-
(error.scope === "tool" &&
|
|
82
|
-
typeof error.toolCallId === "string" &&
|
|
83
|
-
["not_started", "failed", "unknown"].includes(String(error.execution)))));
|
|
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)));
|
|
84
48
|
}
|
|
85
49
|
const presentedFailures = new WeakSet();
|
|
86
|
-
export function markErrorPresented(error) {
|
|
87
|
-
presentedFailures.add(error);
|
|
88
|
-
}
|
|
50
|
+
export function markErrorPresented(error) { presentedFailures.add(error); }
|
|
89
51
|
export function sendErrorNotice(error) {
|
|
90
52
|
if (error instanceof Error && presentedFailures.has(error))
|
|
91
53
|
return "";
|
|
@@ -96,3 +58,4 @@ export function sendErrorNotice(error) {
|
|
|
96
58
|
return "Check your message and send it again.";
|
|
97
59
|
return runError("send", error).userMessage;
|
|
98
60
|
}
|
|
61
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAqBA,SAAS,SAAS,CAAC,KA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O,KAAK,CAAC;IACtD,MAAM,KAAK,GAAG,KAAgC,CAAC;IAC/C,OAAO,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,WAAW,KAAK,QAAQ;WACzG,CAAC,KAAK,CAAC,aAAa,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,aAAa,KAAK,QAAQ,CAAC;WAC9E,CAAC,KAAK,CAAC,KAAK,KAAK,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,MAAM,IAAI,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ,IAAI,CAAC,aAAa,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC3K,CAAC;AAED,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAAS,CAAC;AAC/C,MAAM,UAAU,kBAAkB,CAAC,KAAY,IAAU,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxF,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,KAAK,YAAY,KAAK,IAAI,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACtE,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,IAAI,KAAK,iBAAiB;QAAE,OAAO,qEAAqE,CAAC;IAC7G,IAAI,IAAI,KAAK,eAAe;QAAE,OAAO,uCAAuC,CAAC;IAC7E,OAAO,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,WAAW,CAAC;AAC7C,CAAC","sourcesContent":["export type NexfaceError = Readonly<{\n id: string;\n code: string;\n userMessage: string;\n parentErrorId?: string;\n} & ({ scope: \"run\" } | {\n scope: \"tool\";\n toolCallId: string;\n execution: \"not_started\" | \"failed\" | \"unknown\";\n})>;\n\nexport interface NexfaceErrorEvent {\n readonly code?: string;\n readonly toolCallId?: string;\n readonly sessionId: string;\n readonly runId?: string;\n /** Available local exception or serialized remote diagnostic; never persisted by Chat. */\n readonly cause: unknown;\n}\nexport type ToolState = \"failed\" | \"unknown\" | \"not_started\" | \"cancelled\" | \"rejected\";\n\nfunction errorCode(cause: unknown): string | undefined {\n return cause && typeof cause === \"object\" && \"code\" in cause && typeof cause.code === \"string\" ? cause.code : undefined;\n}\n\nexport function runError(id: string, cause: unknown, unknownTools = false): NexfaceError {\n const code = errorCode(cause) ?? \"CHAT_RUN_ERROR\";\n const userMessage = unknownTools ? \"Some results are missing. Check whether the actions completed.\"\n : code === \"CHAT_REQUEST_FAILED\" ? \"Request failed. Please try again later.\"\n : code === \"CHAT_STREAM_INCOMPLETE\" ? \"The response ended before it was complete.\"\n : code === \"CHAT_RECOVERY_UNAVAILABLE\" ? \"This chat cannot continue. Check the action results, then start a new chat.\"\n : \"Something went wrong.\";\n return { id, scope: \"run\", code, userMessage };\n}\n\nexport function toolError(id: string, toolCallId: string, content: string, parentErrorId?: string, outcomeUnknown = false, toolName?: string): { error?: NexfaceError; toolState?: ToolState; cause?: unknown } {\n let cause: unknown;\n try {\n const payload = JSON.parse(content);\n cause = payload?.error;\n if (!cause && toolName && [\"nxf_executeAction\", \"nxf_applyAction\", \"nxf_getSnapshot\"].includes(toolName) && payload?.result?.ok === false) cause = payload.result.error;\n } catch { return {}; }\n if (!cause) return {};\n const code = outcomeUnknown ? \"EXECUTION_OUTCOME_UNKNOWN\" : errorCode(cause) ?? \"TOOL_ERROR\";\n if (code === \"TOOL_CONFIRMATION_REJECTED\") return { toolState: \"rejected\" };\n if (code === \"TOOL_SKIPPED\") return { toolState: \"not_started\" };\n if (code === \"TOOL_CANCELLED\") return { toolState: \"cancelled\" };\n const execution = code === \"EXECUTION_OUTCOME_UNKNOWN\" ? \"unknown\"\n : [\"INVALID_INPUT\", \"UNKNOWN_TOOL\", \"TOOL_UNAVAILABLE\", \"TOOL_CONFIRMATION_UNAVAILABLE\", \"TOOL_CONFIRMATION_INVALIDATED\", \"TOOL_REGISTRATION_TIMEOUT\"].includes(code) ? \"not_started\" : \"failed\";\n return { toolState: execution, cause, error: {\n id, scope: \"tool\", code, toolCallId, execution,\n userMessage: execution === \"unknown\" ? \"No result was received. Check whether the action completed.\" : execution === \"not_started\" ? \"The action could not start.\" : \"The action failed.\",\n ...(parentErrorId ? { parentErrorId } : {}),\n } };\n}\n\nexport function isNexfaceError(value: unknown): value is NexfaceError {\n if (!value || typeof value !== \"object\") return false;\n const error = value as Record<string, unknown>;\n return typeof error.id === \"string\" && typeof error.code === \"string\" && typeof error.userMessage === \"string\"\n && (error.parentErrorId === undefined || typeof error.parentErrorId === \"string\")\n && (error.scope === \"run\" || error.scope === \"tool\" && typeof error.toolCallId === \"string\" && [\"not_started\", \"failed\", \"unknown\"].includes(String(error.execution)));\n}\n\nconst presentedFailures = new WeakSet<Error>();\nexport function markErrorPresented(error: Error): void { presentedFailures.add(error); }\nexport function sendErrorNotice(error: unknown): string {\n if (error instanceof Error && presentedFailures.has(error)) return \"\";\n const code = errorCode(error);\n if (code === \"CHAT_RUN_ACTIVE\") return \"Wait for the current task to finish before sending another message.\";\n if (code === \"INVALID_INPUT\") return \"Check your message and send it again.\";\n return runError(\"send\", error).userMessage;\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,cAAc,CAAC;AAEtB,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["\"use client\";\n\nimport \"./styles.css\";\n\nexport { Chat } from \"./default-chat.js\";\nexport { NexfaceProvider } from \"./react.js\";\nexport type { NexfaceProviderProps } from \"./react.js\";\nexport { usePageConfirmation } from \"./page-confirmation.js\";\nexport type { NexfaceAgentConfig, NexfaceModelConfig } from \"./config.js\";\nexport type { ChatProps, ChatRunResult, ChatSuggestion, ChatAttachmentOptions } from \"./types.js\";\n\nexport type { NexfaceErrorEvent } from \"./errors.js\";\n"]}
|
package/dist/messages.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"","sourcesContent":["import type { NexfaceError, ToolState } from \"./errors.js\";\nimport type { Attachment } from \"./attachments.js\";\nexport type UIMessagePart =\n | { type: \"text\"; text: string }\n | { type: \"reasoning\"; text: string }\n | {\n type: \"tool\";\n toolCallId: string;\n name: string;\n arguments: string;\n input?: unknown;\n parseError?: string;\n result?: string;\n isError?: boolean;\n errorMessage?: string;\n error?: NexfaceError;\n toolState?: ToolState;\n };\n\nexport interface UIMessage {\n id: string;\n role: \"user\" | \"assistant\";\n parts: UIMessagePart[];\n attachments?: Attachment[];\n revisionOf?: string;\n state?: \"running\" | \"success\" | \"error\" | \"cancelled\";\n error?: NexfaceError;\n}\n"]}
|
|
@@ -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,3 +86,4 @@ export function usePageConfirmation(binding, fallback) {
|
|
|
86
86
|
return fallbackRef.current(...args);
|
|
87
87
|
}, [binding, context]);
|
|
88
88
|
}
|
|
89
|
+
//# sourceMappingURL=page-confirmation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-confirmation.js","sourceRoot":"","sources":["../src/page-confirmation.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EACb,WAAW,EACX,UAAU,EACV,eAAe,EACf,OAAO,EACP,MAAM,GAGP,MAAM,OAAO,CAAC;AAWf,MAAM,uBAAuB,GAAG,aAAa,CAAsC,IAAI,CAAC,CAAC;AAEzF,MAAM,UAAU,wBAAwB,CAAC,EACvC,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EACrB,QAAQ,GAOT;IACC,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IACvC,YAAY,CAAC,OAAO,GAAG,SAAS,CAAC;IACjC,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IACvC,YAAY,CAAC,OAAO,GAAG,SAAS,CAAC;IACjC,MAAM,mBAAmB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;IACrD,mBAAmB,CAAC,OAAO,GAAG,gBAAgB,CAAC;IAC/C,MAAM,wBAAwB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;IAC/D,wBAAwB,CAAC,OAAO,GAAG,qBAAqB,CAAC;IACzD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,GAAG,EAA4B,CAAC,CAAC;IAChE,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,GAAG,EAAoB,CAAC,CAAC;IACxD,MAAM,KAAK,GAAG,OAAO,CAA+B,GAAG,EAAE,CAAC,CAAC;QACzD,QAAQ,CAAC,OAAO;YACd,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC3D,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,IAAI,KAAK,CACb,wDAAwD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AQ,CAAC,OAAO,CAAC,EAC/B,CAAC,OAAO,EAAE,OAAO,CAAC,CACnB,CAAC;IACF,OAAO,WAAW,CAAC,CAAC,GAAG,IAAW,EAAE,EAAE;QACpC,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;YAAE,OAAO,SAAS,CAAC;QAC9C,OAAO,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IACtC,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import {\n createContext,\n useCallback,\n useContext,\n useLayoutEffect,\n useMemo,\n useRef,\n type ReactNode,\n type ReactElement,\n} from \"react\";\nimport type { ToolApprovalInterruptDescriptor } from \"@nexface/agent\";\nimport type { AgentToolBinding } from \"@nexface/tools\";\n\nexport type { ToolApprovalInterruptDescriptor } from \"@nexface/agent\";\n\ninterface PageConfirmationContextValue {\n register(binding: AgentToolBinding): () => void;\n invoke(binding: AgentToolBinding): boolean;\n}\n\nconst PageConfirmationContext = createContext<PageConfirmationContextValue | null>(null);\n\nexport function PageConfirmationProvider({\n interrupt,\n onConfirm,\n onBindingRemoved,\n onBindingRegistration,\n children,\n}: {\n interrupt?: ToolApprovalInterruptDescriptor | undefined;\n onConfirm(): Promise<unknown> | unknown;\n onBindingRemoved(): void;\n onBindingRegistration(toolName: string, registered: boolean): void;\n children: ReactNode;\n}): ReactElement {\n const interruptRef = useRef(interrupt);\n interruptRef.current = interrupt;\n const onConfirmRef = useRef(onConfirm);\n onConfirmRef.current = onConfirm;\n const onBindingRemovedRef = useRef(onBindingRemoved);\n onBindingRemovedRef.current = onBindingRemoved;\n const onBindingRegistrationRef = useRef(onBindingRegistration);\n onBindingRegistrationRef.current = onBindingRegistration;\n const bindingsRef = useRef(new Map<string, AgentToolBinding>());\n const resumingRef = useRef(new Set<AgentToolBinding>());\n const value = useMemo<PageConfirmationContextValue>(() => ({\n register(binding) {\n const existing = bindingsRef.current.get(binding.toolName);\n if (existing) {\n throw new Error(\n `Only one usePageConfirmation Hook may register Tool \"${binding.toolName}\".`,\n );\n }\n bindingsRef.current.set(binding.toolName, binding);\n onBindingRegistrationRef.current(binding.toolName, true);\n let registered = true;\n return () => {\n if (!registered) return;\n registered = false;\n if (bindingsRef.current.get(binding.toolName) !== binding) return;\n bindingsRef.current.delete(binding.toolName);\n onBindingRegistrationRef.current(binding.toolName, false);\n resumingRef.current.delete(binding);\n const pending = interruptRef.current;\n if (pending?.mode === \"page\" && pending.toolName === binding.toolName) {\n onBindingRemovedRef.current();\n }\n };\n },\n invoke(binding) {\n if (resumingRef.current.has(binding)) return true;\n const pending = interruptRef.current;\n if (\n pending?.mode !== \"page\"\n || pending.toolName !== binding.toolName\n || bindingsRef.current.get(binding.toolName) !== binding\n ) {\n return false;\n }\n resumingRef.current.add(binding);\n let confirmation: Promise<unknown> | unknown;\n try {\n confirmation = onConfirmRef.current();\n } catch (error) {\n resumingRef.current.delete(binding);\n throw error;\n }\n if (confirmation === undefined) {\n resumingRef.current.delete(binding);\n return true;\n }\n void Promise.resolve(confirmation)\n .finally(() => {\n resumingRef.current.delete(binding);\n })\n .catch(() => undefined);\n return true;\n },\n }), []);\n return (\n <PageConfirmationContext.Provider value={value}>\n {children}\n </PageConfirmationContext.Provider>\n );\n}\n\n/**\n * @experimental Human-in-the-loop Page confirmation may change in future releases.\n * @beta\n */\nexport function usePageConfirmation<\n TArgs extends unknown[],\n TResult,\n>(\n binding: AgentToolBinding,\n fallback: (...args: TArgs) => TResult,\n): (...args: TArgs) => TResult | void {\n const context = useContext(PageConfirmationContext);\n if (!context) {\n throw new Error(\"usePageConfirmation must be used within NexfaceProvider.\");\n }\n const fallbackRef = useRef(fallback);\n fallbackRef.current = fallback;\n useLayoutEffect(\n () => context.register(binding),\n [binding, context],\n );\n return useCallback((...args: TArgs) => {\n if (context.invoke(binding)) return undefined;\n return fallbackRef.current(...args);\n }, [binding, context]);\n}\n"]}
|