@nexface/chat 0.1.12-alpha.0 → 0.1.13-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.
- package/dist/client.js +14 -12
- package/dist/client.js.map +1 -1
- package/dist/default-chat.js.map +1 -1
- package/dist/page-confirmation.d.ts +2 -2
- package/dist/page-confirmation.js.map +1 -1
- package/dist/protocol-response.d.ts +1 -0
- package/dist/protocol-response.js +3 -0
- package/dist/protocol-response.js.map +1 -1
- package/dist/shared/errors.d.ts +10 -0
- package/dist/shared/errors.js +36 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/shared/runtime-controller.d.ts +28 -0
- package/dist/shared/runtime-controller.js +11 -0
- package/dist/shared/runtime-controller.js.map +1 -0
- package/dist/shared/runtime-execution.d.ts +5 -0
- package/dist/shared/runtime-execution.js +3 -0
- package/dist/shared/runtime-execution.js.map +1 -0
- package/dist/shared/schema.d.ts +3 -0
- package/dist/shared/schema.js +200 -0
- package/dist/shared/schema.js.map +1 -0
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ReactNode, type ReactElement } from "react";
|
|
2
2
|
import type { ToolApprovalInterruptDescriptor } from "@nexface/agent";
|
|
3
|
-
import type {
|
|
3
|
+
import type { AgentToolBinding } from "@nexface/tools";
|
|
4
4
|
export type { ToolApprovalInterruptDescriptor } from "@nexface/agent";
|
|
5
5
|
export declare function PageConfirmationProvider({ interrupt, onConfirm, onBindingRemoved, onBindingRegistration, children, }: {
|
|
6
6
|
interrupt?: ToolApprovalInterruptDescriptor | undefined;
|
|
@@ -13,4 +13,4 @@ export declare function PageConfirmationProvider({ interrupt, onConfirm, onBindi
|
|
|
13
13
|
* @experimental Human-in-the-loop Page confirmation may change in future releases.
|
|
14
14
|
* @beta
|
|
15
15
|
*/
|
|
16
|
-
export declare function usePageConfirmation<TArgs extends unknown[], TResult>(binding:
|
|
16
|
+
export declare function usePageConfirmation<TArgs extends unknown[], TResult>(binding: AgentToolBinding, fallback: (...args: TArgs) => TResult): (...args: TArgs) => TResult | void;
|
|
@@ -1 +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,
|
|
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,MA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AC;YACd,CAAC;YACD,KAAK,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC;iBAC/B,OAAO,CAAC,GAAG,EAAE;gBACZ,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACtC,CAAC,CAAC;iBACD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YAC1B,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC,EAAE,EAAE,CAAC,CAAC;IACR,OAAO,CACL,KAAC,uBAAuB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAC3C,QAAQ,GACwB,CACpC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAIjC,OAAyB,EACzB,QAAqC;IAErC,MAAM,OAAO,GAAG,UAAU,CAAC,uBAAuB,CAAC,CAAC;IACpD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IACD,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACrC,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC;IAC/B,eAAe,CACb,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,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"]}
|
|
@@ -61,6 +61,9 @@ export function decodeAgentResponse(messages, snapshot, terminal) {
|
|
|
61
61
|
if (!action || action.toolCallId !== call.id || name !== action.definition?.name || JSON.stringify(toolInput) !== JSON.stringify(action.input)) {
|
|
62
62
|
throw new Error("Browser action does not match its original call.");
|
|
63
63
|
}
|
|
64
|
+
if (action.pageDecision !== undefined && (action.pageDecision !== true || name !== "nxf_getSnapshot")) {
|
|
65
|
+
throw new Error("Invalid page decision observation context.");
|
|
66
|
+
}
|
|
64
67
|
return { type: "client-tool-execution", interruptId: interrupt.id, action };
|
|
65
68
|
}
|
|
66
69
|
//# sourceMappingURL=protocol-response.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol-response.js","sourceRoot":"","sources":["../src/prot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AAC,CAAC,IAAI,CAAC,IAAI,CAAC;IACtE,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,KAAK,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,eAAe,CAAC,CAAC,CAAC;IACvJ,IAAI,SAAS,CAAC,IAAI,KAAK,uBAAuB;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACjG,MAAM,MAAM,GAAG,SAAS,CAAC,MAAwC,CAAC;IAClE,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,UAAU,KAAK,IAAI,CAAC,EAAE,IAAI,IAAI,KAAK,MAAM,CAAC,UAAU,EAAE,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/I,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,uBAAuB,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC;AAC9E,CAAC","sourcesContent":["import type { Message, RunFinishedEvent } from \"@ag-ui/core\";\nimport type { AgentRunResult } from \"@nexface/agent\";\n\nimport type { AgentToolDefinition } from \"@nexface/tools\";\n\nexport interface BrowserToolResult {\n readonly toolCallId: string;\n readonly result?: unknown;\n readonly error?: { readonly code: string; readonly message: string };\n // Approval was handled for this call; this does not imply acceptance.\n readonly confirmed?: boolean;\n}\n\nexport interface AgentBrowserAction {\n readonly toolCallId: string;\n readonly definition: AgentToolDefinition<any, any>;\n readonly input: unknown;\n readonly progressLabel?: string;\n}\n\n// Only the response fields needed to validate a client handoff belong here.\ninterface ResponseState {\n nexface: {\n version: number;\n threadId: string;\n timeline: Array<{ messageId: string } | { internal: { role: string } }>;\n pending?: {\n kind: string;\n interruptId: string;\n calls: Array<{ id: string; name: string; arguments: string }>;\n };\n };\n}\n\ntype AgentResponse =\n | { type: \"success\"; result: Extract<AgentRunResult, { outcome: { type: \"success\" } }> }\n | { type: \"client-tool-execution\"; interruptId: string; action: AgentBrowserAction };\n\nexport function decodeAgentResponse(\n messages: readonly Message[],\n snapshot: unknown,\n terminal: RunFinishedEvent,\n): AgentResponse {\n const state = snapshot as ResponseState | undefined;\n const continuation = state?.nexface;\n if (!continuation || continuation.version !== 3 || continuation.threadId !== terminal.threadId || !Array.isArray(continuation.timeline)) {\n throw new Error(\"Invalid Agent recovery state or protocol version. Upgrade client and server together and start a new conversation.\");\n }\n const legacy = new Set([\"callAppTool\", \"getSnapshot\", \"executeCode\", \"loadSkill\", \"finish\"]);\n if (messages.some((message) => message.role === \"assistant\" && message.toolCalls?.some((call) => legacy.has(call.function.name)))\n || continuation.pending?.calls?.some((call) => legacy.has(call.name))) throw new Error(\"Unsupported legacy tool history. Start a new conversation.\");\n const history = messages.filter((message) => message.role !== \"activity\" && message.role !== \"reasoning\");\n const references = continuation.timeline.flatMap((entry) => {\n if (entry && \"internal\" in entry) {\n if (\"messageId\" in entry || (entry.internal?.role !== \"system\" && entry.internal?.role !== \"application_context\")) throw new Error(\"Invalid internal history reference.\");\n return [];\n }\n if (!entry || !(\"messageId\" in entry) || typeof entry.messageId !== \"string\") throw new Error(\"Invalid Agent history reference.\");\n return [entry.messageId];\n });\n if (new Set(messages.map((message) => message.id)).size !== messages.length\n || references.length !== history.length || references.some((id, index) => id !== history[index]!.id)) {\n throw new Error(\"Agent messages and recovery state do not match.\");\n }\n const outcome = terminal.outcome;\n const pending = continuation.pending;\n if (outcome?.type === \"success\") {\n if (typeof terminal.result?.output !== \"string\" || pending) throw new Error(\"Invalid completion output or pending state.\");\n return { type: \"success\", result: { outcome, output: terminal.result.output } };\n }\n if (outcome?.type !== \"interrupt\" || outcome.interrupts.length !== 1) throw new Error(\"Invalid remote interrupt.\");\n const interrupt = outcome.interrupts[0]!;\n const extension = interrupt.metadata?.nexface;\n const call = pending?.calls?.[0];\n if (!extension || !pending || !Array.isArray(pending.calls) || !call\n || pending.interruptId !== interrupt.id || interrupt.toolCallId !== call.id || pending.kind !== extension.kind) {\n throw new Error(\"Invalid remote interrupt.\");\n }\n const ownerIndex = history.reduce((last, message, index) => message.role === \"assistant\" ? index : last, -1);\n const owner = history[ownerIndex];\n const calls = owner?.role === \"assistant\" ? owner.toolCalls ?? [] : [];\n const first = calls.findIndex((item) => item.id === call.id);\n if (first < 0 || calls.length - first !== pending.calls.length\n || pending.calls.some((item, index) => item.id !== calls[first + index]!.id\n || item.name !== calls[first + index]!.function.name || item.arguments !== calls[first + index]!.function.arguments)\n || history.slice(ownerIndex + 1).some((message) => message.role === \"tool\" && pending.calls.some((item) => item.id === message.toolCallId))) {\n throw new Error(\"Pending calls do not match their assistant message.\");\n }\n const args: unknown = JSON.parse(call.arguments);\n if (!args || typeof args !== \"object\" || Array.isArray(args)) throw new Error(\"Invalid pending tool arguments.\");\n const input = args as Record<string, unknown>;\n const name = call.name === \"nxf_callAppTool\" ? input.name : call.name;\n const toolInput = call.name === \"nxf_callAppTool\" ? input.input : Object.fromEntries(Object.entries(input).filter(([key]) => key !== \"progressLabel\"));\n if (extension.kind !== \"client-tool-execution\") throw new Error(\"Unsupported remote interrupt.\");\n const action = extension.action as AgentBrowserAction | undefined;\n if (!action || action.toolCallId !== call.id || name !== action.definition?.name || JSON.stringify(toolInput) !== JSON.stringify(action.input)) {\n throw new Error(\"Browser action does not match its original call.\");\n }\n return { type: \"client-tool-execution\", interruptId: interrupt.id, action };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"protocol-response.js","sourceRoot":"","sources":["../src/protocol-response.ts"],"names":[],"mappings":"AAuCA,MAAM,UAAU,mBAAmB,CACjC,QAA4B,EAC5B,QAAiB,EACjB,QAA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B,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,eAAe,CAAC,CAAC,CAAC;IACvJ,IAAI,SAAS,CAAC,IAAI,KAAK,uBAAuB;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACjG,MAAM,MAAM,GAAG,SAAS,CAAC,MAAwC,CAAC;IAClE,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,UAAU,KAAK,IAAI,CAAC,EAAE,IAAI,IAAI,KAAK,MAAM,CAAC,UAAU,EAAE,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/I,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,YAAY,KAAK,IAAI,IAAI,IAAI,KAAK,iBAAiB,CAAC,EAAE,CAAC;QACtG,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,uBAAuB,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC;AAC9E,CAAC","sourcesContent":["import type { Message, RunFinishedEvent } from \"@ag-ui/core\";\nimport type { AgentRunResult } from \"@nexface/agent\";\n\nimport type { AgentToolDefinition } from \"@nexface/tools\";\n\nexport interface BrowserToolResult {\n readonly toolCallId: string;\n readonly result?: unknown;\n readonly error?: { readonly code: string; readonly message: string };\n // Approval was handled for this call; this does not imply acceptance.\n readonly confirmed?: boolean;\n}\n\nexport interface AgentBrowserAction {\n readonly toolCallId: string;\n readonly definition: AgentToolDefinition<any, any>;\n readonly input: unknown;\n readonly progressLabel?: string;\n readonly pageDecision?: boolean;\n}\n\n// Only the response fields needed to validate a client handoff belong here.\ninterface ResponseState {\n nexface: {\n version: number;\n threadId: string;\n timeline: Array<{ messageId: string } | { internal: { role: string } }>;\n pending?: {\n kind: string;\n interruptId: string;\n calls: Array<{ id: string; name: string; arguments: string }>;\n };\n };\n}\n\ntype AgentResponse =\n | { type: \"success\"; result: Extract<AgentRunResult, { outcome: { type: \"success\" } }> }\n | { type: \"client-tool-execution\"; interruptId: string; action: AgentBrowserAction };\n\nexport function decodeAgentResponse(\n messages: readonly Message[],\n snapshot: unknown,\n terminal: RunFinishedEvent,\n): AgentResponse {\n const state = snapshot as ResponseState | undefined;\n const continuation = state?.nexface;\n if (!continuation || continuation.version !== 3 || continuation.threadId !== terminal.threadId || !Array.isArray(continuation.timeline)) {\n throw new Error(\"Invalid Agent recovery state or protocol version. Upgrade client and server together and start a new conversation.\");\n }\n const legacy = new Set([\"callAppTool\", \"getSnapshot\", \"executeCode\", \"loadSkill\", \"finish\"]);\n if (messages.some((message) => message.role === \"assistant\" && message.toolCalls?.some((call) => legacy.has(call.function.name)))\n || continuation.pending?.calls?.some((call) => legacy.has(call.name))) throw new Error(\"Unsupported legacy tool history. Start a new conversation.\");\n const history = messages.filter((message) => message.role !== \"activity\" && message.role !== \"reasoning\");\n const references = continuation.timeline.flatMap((entry) => {\n if (entry && \"internal\" in entry) {\n if (\"messageId\" in entry || (entry.internal?.role !== \"system\" && entry.internal?.role !== \"application_context\")) throw new Error(\"Invalid internal history reference.\");\n return [];\n }\n if (!entry || !(\"messageId\" in entry) || typeof entry.messageId !== \"string\") throw new Error(\"Invalid Agent history reference.\");\n return [entry.messageId];\n });\n if (new Set(messages.map((message) => message.id)).size !== messages.length\n || references.length !== history.length || references.some((id, index) => id !== history[index]!.id)) {\n throw new Error(\"Agent messages and recovery state do not match.\");\n }\n const outcome = terminal.outcome;\n const pending = continuation.pending;\n if (outcome?.type === \"success\") {\n if (typeof terminal.result?.output !== \"string\" || pending) throw new Error(\"Invalid completion output or pending state.\");\n return { type: \"success\", result: { outcome, output: terminal.result.output } };\n }\n if (outcome?.type !== \"interrupt\" || outcome.interrupts.length !== 1) throw new Error(\"Invalid remote interrupt.\");\n const interrupt = outcome.interrupts[0]!;\n const extension = interrupt.metadata?.nexface;\n const call = pending?.calls?.[0];\n if (!extension || !pending || !Array.isArray(pending.calls) || !call\n || pending.interruptId !== interrupt.id || interrupt.toolCallId !== call.id || pending.kind !== extension.kind) {\n throw new Error(\"Invalid remote interrupt.\");\n }\n const ownerIndex = history.reduce((last, message, index) => message.role === \"assistant\" ? index : last, -1);\n const owner = history[ownerIndex];\n const calls = owner?.role === \"assistant\" ? owner.toolCalls ?? [] : [];\n const first = calls.findIndex((item) => item.id === call.id);\n if (first < 0 || calls.length - first !== pending.calls.length\n || pending.calls.some((item, index) => item.id !== calls[first + index]!.id\n || item.name !== calls[first + index]!.function.name || item.arguments !== calls[first + index]!.function.arguments)\n || history.slice(ownerIndex + 1).some((message) => message.role === \"tool\" && pending.calls.some((item) => item.id === message.toolCallId))) {\n throw new Error(\"Pending calls do not match their assistant message.\");\n }\n const args: unknown = JSON.parse(call.arguments);\n if (!args || typeof args !== \"object\" || Array.isArray(args)) throw new Error(\"Invalid pending tool arguments.\");\n const input = args as Record<string, unknown>;\n const name = call.name === \"nxf_callAppTool\" ? input.name : call.name;\n const toolInput = call.name === \"nxf_callAppTool\" ? input.input : Object.fromEntries(Object.entries(input).filter(([key]) => key !== \"progressLabel\"));\n if (extension.kind !== \"client-tool-execution\") throw new Error(\"Unsupported remote interrupt.\");\n const action = extension.action as AgentBrowserAction | undefined;\n if (!action || action.toolCallId !== call.id || name !== action.definition?.name || JSON.stringify(toolInput) !== JSON.stringify(action.input)) {\n throw new Error(\"Browser action does not match its original call.\");\n }\n if (action.pageDecision !== undefined && (action.pageDecision !== true || name !== \"nxf_getSnapshot\")) {\n throw new Error(\"Invalid page decision observation context.\");\n }\n return { type: \"client-tool-execution\", interruptId: interrupt.id, action };\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
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];
|
|
3
|
+
export declare class AgentToolError extends Error {
|
|
4
|
+
readonly code: AgentToolErrorCode;
|
|
5
|
+
readonly details?: unknown | undefined;
|
|
6
|
+
readonly type: "tool_runtime_error";
|
|
7
|
+
readonly domain: "tool";
|
|
8
|
+
constructor(code: AgentToolErrorCode, message: string, details?: unknown | undefined);
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Generated from shared/errors.ts. Do not edit manually.
|
|
2
|
+
export const TOOL_ERROR_CODES = [
|
|
3
|
+
"EXECUTION_OUTCOME_UNKNOWN",
|
|
4
|
+
"ACTION_IN_FLIGHT",
|
|
5
|
+
"ACTION_NOT_HANDLED",
|
|
6
|
+
"ACTION_TARGET_UNAVAILABLE",
|
|
7
|
+
"BROWSER_EXECUTION_FAILED",
|
|
8
|
+
"BROWSER_SNAPSHOT_REQUIRED",
|
|
9
|
+
"BROWSER_TOOLS_UNAVAILABLE",
|
|
10
|
+
"CONTRACT_MISMATCH",
|
|
11
|
+
"DUPLICATE_BINDING",
|
|
12
|
+
"INVALID_INPUT",
|
|
13
|
+
"INVALID_TOOL_RUNTIME",
|
|
14
|
+
"OPERATION_BUSY",
|
|
15
|
+
"TOOL_CANCELLED",
|
|
16
|
+
"TOOL_CONFIRMATION_INVALIDATED",
|
|
17
|
+
"TOOL_CONFIRMATION_REJECTED",
|
|
18
|
+
"TOOL_ERROR",
|
|
19
|
+
"TOOL_REGISTRATION_TIMEOUT",
|
|
20
|
+
"TOOL_SKIPPED",
|
|
21
|
+
"TOOL_UNAVAILABLE",
|
|
22
|
+
"UNKNOWN_TOOL",
|
|
23
|
+
];
|
|
24
|
+
export class AgentToolError extends Error {
|
|
25
|
+
code;
|
|
26
|
+
details;
|
|
27
|
+
type = "tool_runtime_error";
|
|
28
|
+
domain = "tool";
|
|
29
|
+
constructor(code, message, details) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.code = code;
|
|
32
|
+
this.details = details;
|
|
33
|
+
this.name = "ToolRuntimeError";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/shared/errors.ts"],"names":[],"mappings":"AAAA,yDAAyD;AAEzD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,2BAA2B;IAC3B,kBAAkB;IAClB,oBAAoB;IACpB,2BAA2B;IAC3B,0BAA0B;IAC1B,2BAA2B;IAC3B,2BAA2B;IAC3B,mBAAmB;IACnB,mBAAmB;IACnB,eAAe;IACf,sBAAsB;IACtB,gBAAgB;IAChB,gBAAgB;IAChB,+BAA+B;IAC/B,4BAA4B;IAC5B,YAAY;IACZ,2BAA2B;IAC3B,cAAc;IACd,kBAAkB;IAClB,cAAc;CACN,CAAC;AAIX,MAAM,OAAO,cAAe,SAAQ,KAAK;IAK5B;IAEA;IANF,IAAI,GAAG,oBAA6B,CAAC;IACrC,MAAM,GAAG,MAAe,CAAC;IAElC,YACW,IAAwB,EACjC,OAAe,EACN,OAAiB;QAE1B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,SAAI,GAAJ,IAAI,CAAoB;QAExB,YAAO,GAAP,OAAO,CAAU;QAG1B,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF","sourcesContent":["// Generated from shared/errors.ts. Do not edit manually.\n\nexport const TOOL_ERROR_CODES = [\n \"EXECUTION_OUTCOME_UNKNOWN\",\n \"ACTION_IN_FLIGHT\",\n \"ACTION_NOT_HANDLED\",\n \"ACTION_TARGET_UNAVAILABLE\",\n \"BROWSER_EXECUTION_FAILED\",\n \"BROWSER_SNAPSHOT_REQUIRED\",\n \"BROWSER_TOOLS_UNAVAILABLE\",\n \"CONTRACT_MISMATCH\",\n \"DUPLICATE_BINDING\",\n \"INVALID_INPUT\",\n \"INVALID_TOOL_RUNTIME\",\n \"OPERATION_BUSY\",\n \"TOOL_CANCELLED\",\n \"TOOL_CONFIRMATION_INVALIDATED\",\n \"TOOL_CONFIRMATION_REJECTED\",\n \"TOOL_ERROR\",\n \"TOOL_REGISTRATION_TIMEOUT\",\n \"TOOL_SKIPPED\",\n \"TOOL_UNAVAILABLE\",\n \"UNKNOWN_TOOL\",\n] as const;\n\ntype AgentToolErrorCode = typeof TOOL_ERROR_CODES[number];\n\nexport class AgentToolError extends Error {\n readonly type = \"tool_runtime_error\" as const;\n readonly domain = \"tool\" as const;\n\n constructor(\n readonly code: AgentToolErrorCode,\n message: string,\n readonly details?: unknown,\n ) {\n super(message);\n this.name = \"ToolRuntimeError\";\n }\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ToolOperation, ToolRuntime } from "@nexface/tools";
|
|
2
|
+
export type TaskProgress = {
|
|
3
|
+
readonly phase: "processing";
|
|
4
|
+
} | {
|
|
5
|
+
readonly phase: "tool";
|
|
6
|
+
readonly toolCallId: string;
|
|
7
|
+
readonly progressLabel?: string;
|
|
8
|
+
};
|
|
9
|
+
interface OperationSnapshot {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly status: "running" | "waiting" | "cancelling" | "ending";
|
|
12
|
+
readonly taskProgress?: TaskProgress;
|
|
13
|
+
}
|
|
14
|
+
export interface RuntimeController {
|
|
15
|
+
beginInternalOperation(options?: {
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
onCancel?: () => void;
|
|
18
|
+
replaceWaiting?: ToolOperation;
|
|
19
|
+
taskProgress?: TaskProgress;
|
|
20
|
+
}): ToolOperation;
|
|
21
|
+
setOperationWaiting(handle: ToolOperation, waiting: boolean): void;
|
|
22
|
+
setTaskProgress(handle: ToolOperation, progress: TaskProgress): void;
|
|
23
|
+
getOperationSnapshot(): OperationSnapshot | null;
|
|
24
|
+
subscribeOperation(listener: () => void): () => void;
|
|
25
|
+
}
|
|
26
|
+
export declare const runtimeControllerSymbol: unique symbol;
|
|
27
|
+
export declare function getRuntimeController(runtime: ToolRuntime): RuntimeController;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Generated from shared/runtime-controller.ts. Do not edit manually.
|
|
2
|
+
import { AgentToolError } from "./errors.js";
|
|
3
|
+
export const runtimeControllerSymbol = Symbol.for("@nexface/tools/runtime-controller");
|
|
4
|
+
export function getRuntimeController(runtime) {
|
|
5
|
+
const controller = runtime[runtimeControllerSymbol];
|
|
6
|
+
if (!controller) {
|
|
7
|
+
throw new AgentToolError("INVALID_TOOL_RUNTIME", "ToolRuntime does not support internal task coordination. Use matching Nexface package versions.");
|
|
8
|
+
}
|
|
9
|
+
return controller;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=runtime-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-controller.js","sourceRoot":"","sources":["../../src/shared/runtime-controller.ts"],"names":[],"mappings":"AAAA,qEAAqE;AAGrE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAuB7C,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AAEvF,MAAM,UAAU,oBAAoB,CAAC,OAAoB;IACvD,MAAM,UAAU,GAAI,OAA2E,CAAC,uBAAuB,CAAC,CAAC;IACzH,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,cAAc,CAAC,sBAAsB,EAAE,iGAAiG,CAAC,CAAC;IACtJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["// Generated from shared/runtime-controller.ts. Do not edit manually.\n\nimport type { ToolOperation, ToolRuntime } from \"@nexface/tools\";\nimport { AgentToolError } from \"./errors.js\";\n\nexport type TaskProgress = { readonly phase: \"processing\" } | { readonly phase: \"tool\"; readonly toolCallId: string; readonly progressLabel?: string };\n\ninterface OperationSnapshot {\n readonly id: string;\n readonly status: \"running\" | \"waiting\" | \"cancelling\" | \"ending\";\n readonly taskProgress?: TaskProgress;\n}\n\nexport interface RuntimeController {\n beginInternalOperation(options?: {\n signal?: AbortSignal;\n onCancel?: () => void;\n replaceWaiting?: ToolOperation;\n taskProgress?: TaskProgress;\n }): ToolOperation;\n setOperationWaiting(handle: ToolOperation, waiting: boolean): void;\n setTaskProgress(handle: ToolOperation, progress: TaskProgress): void;\n getOperationSnapshot(): OperationSnapshot | null;\n subscribeOperation(listener: () => void): () => void;\n}\n\nexport const runtimeControllerSymbol = Symbol.for(\"@nexface/tools/runtime-controller\");\n\nexport function getRuntimeController(runtime: ToolRuntime): RuntimeController {\n const controller = (runtime as ToolRuntime & { [runtimeControllerSymbol]?: RuntimeController })[runtimeControllerSymbol];\n if (!controller) {\n throw new AgentToolError(\"INVALID_TOOL_RUNTIME\", \"ToolRuntime does not support internal task coordination. Use matching Nexface package versions.\");\n }\n return controller;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-execution.js","sourceRoot":"","sources":["../../src/shared/runtime-execution.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAIpE,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC","sourcesContent":["// Generated from shared/runtime-execution.ts. Do not edit manually.\n\nimport type { ToolRuntime } from \"@nexface/tools\";\n\nexport const pageDecisionSymbol = Symbol.for(\"@nexface/tools/page-decision\");\n\nexport type InternalExecutionOptions = NonNullable<Parameters<ToolRuntime[\"execute\"]>[2]> & {\n readonly [pageDecisionSymbol]?: boolean;\n};\n"]}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// Generated from shared/schema.ts. Do not edit manually.
|
|
2
|
+
const types = new Set(["object", "array", "string", "number", "integer", "boolean", "null"]);
|
|
3
|
+
const counts = ["minLength", "maxLength", "minItems", "maxItems"];
|
|
4
|
+
const bounds = ["minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum"];
|
|
5
|
+
const keywords = new Set([
|
|
6
|
+
"type", "description", "properties", "required", "items", "enum", "additionalProperties",
|
|
7
|
+
...counts, ...bounds, "pattern", "uniqueItems",
|
|
8
|
+
]);
|
|
9
|
+
const checkedSchemas = new WeakSet();
|
|
10
|
+
const patterns = new WeakMap();
|
|
11
|
+
function invalid(path, message) {
|
|
12
|
+
throw new TypeError(`${path} ${message}`);
|
|
13
|
+
}
|
|
14
|
+
function isRecord(value) {
|
|
15
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
// Only deeply frozen, JSON-compatible values can safely share validation results.
|
|
18
|
+
function assertJson(value, path, ancestors = new Set()) {
|
|
19
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
20
|
+
return true;
|
|
21
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
22
|
+
return true;
|
|
23
|
+
if (typeof value !== "object" || value === null)
|
|
24
|
+
invalid(path, "must be JSON-compatible.");
|
|
25
|
+
if (ancestors.has(value))
|
|
26
|
+
invalid(path, "must not contain circular references.");
|
|
27
|
+
if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
|
|
28
|
+
invalid(path, "must be a plain JSON object.");
|
|
29
|
+
}
|
|
30
|
+
if (Object.getOwnPropertySymbols(value).length)
|
|
31
|
+
invalid(path, "must not contain symbol properties.");
|
|
32
|
+
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
|
|
33
|
+
if (!descriptor.enumerable && !(Array.isArray(value) && key === "length"))
|
|
34
|
+
invalid(`${path}.${key}`, "must be enumerable.");
|
|
35
|
+
if (descriptor.get || descriptor.set)
|
|
36
|
+
invalid(`${path}.${key}`, "must be a data property.");
|
|
37
|
+
}
|
|
38
|
+
if (Array.isArray(value)) {
|
|
39
|
+
for (let index = 0; index < value.length; index++) {
|
|
40
|
+
if (!Object.hasOwn(value, index))
|
|
41
|
+
invalid(`${path}[${index}]`, "must not be a sparse array slot.");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
ancestors.add(value);
|
|
45
|
+
let frozen = Object.isFrozen(value);
|
|
46
|
+
for (const [key, child] of Object.entries(value)) {
|
|
47
|
+
const childFrozen = assertJson(child, `${path}.${key}`, ancestors);
|
|
48
|
+
frozen = frozen && childFrozen;
|
|
49
|
+
}
|
|
50
|
+
ancestors.delete(value);
|
|
51
|
+
return frozen;
|
|
52
|
+
}
|
|
53
|
+
function patternFor(schema, path) {
|
|
54
|
+
const source = schema.pattern;
|
|
55
|
+
const cached = patterns.get(schema);
|
|
56
|
+
if (cached?.source === source)
|
|
57
|
+
return cached.regex;
|
|
58
|
+
let regex;
|
|
59
|
+
try {
|
|
60
|
+
regex = new RegExp(source, "u");
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
invalid(`${path}.pattern`, "must be a valid Unicode regular expression.");
|
|
64
|
+
}
|
|
65
|
+
patterns.set(schema, { source, regex });
|
|
66
|
+
return regex;
|
|
67
|
+
}
|
|
68
|
+
function assertSchema(value, path) {
|
|
69
|
+
if (!isRecord(value))
|
|
70
|
+
invalid(path, "must be an object.");
|
|
71
|
+
const unexpected = Object.keys(value).filter((key) => !keywords.has(key));
|
|
72
|
+
if (unexpected.length)
|
|
73
|
+
invalid(path, `has unsupported fields: ${unexpected.join(", ")}.`);
|
|
74
|
+
if (value.type !== undefined && (typeof value.type !== "string" || !types.has(value.type)))
|
|
75
|
+
invalid(`${path}.type`, "is not supported.");
|
|
76
|
+
if (value.description !== undefined && typeof value.description !== "string")
|
|
77
|
+
invalid(`${path}.description`, "must be a string.");
|
|
78
|
+
for (const key of ["additionalProperties", "uniqueItems"]) {
|
|
79
|
+
if (value[key] !== undefined && typeof value[key] !== "boolean")
|
|
80
|
+
invalid(`${path}.${key}`, "must be a boolean.");
|
|
81
|
+
}
|
|
82
|
+
for (const key of counts) {
|
|
83
|
+
const count = value[key];
|
|
84
|
+
if (count !== undefined && (typeof count !== "number" || !Number.isInteger(count) || count < 0))
|
|
85
|
+
invalid(`${path}.${key}`, "must be a non-negative integer.");
|
|
86
|
+
}
|
|
87
|
+
for (const key of bounds) {
|
|
88
|
+
if (value[key] !== undefined && (typeof value[key] !== "number" || !Number.isFinite(value[key])))
|
|
89
|
+
invalid(`${path}.${key}`, "must be a finite number.");
|
|
90
|
+
}
|
|
91
|
+
if (value.pattern !== undefined) {
|
|
92
|
+
if (typeof value.pattern !== "string")
|
|
93
|
+
invalid(`${path}.pattern`, "must be a string.");
|
|
94
|
+
patternFor(value, path);
|
|
95
|
+
}
|
|
96
|
+
if (value.enum !== undefined && (!Array.isArray(value.enum) || value.enum.length === 0))
|
|
97
|
+
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))))
|
|
99
|
+
invalid(`${path}.enum`, "must contain unique values.");
|
|
100
|
+
if (value.properties !== undefined) {
|
|
101
|
+
if (value.type !== "object" || !isRecord(value.properties))
|
|
102
|
+
invalid(`${path}.properties`, "requires an object schema.");
|
|
103
|
+
for (const [name, property] of Object.entries(value.properties))
|
|
104
|
+
assertSchema(property, `${path}.properties.${name}`);
|
|
105
|
+
}
|
|
106
|
+
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)
|
|
108
|
+
invalid(`${path}.required`, "must contain unique property names.");
|
|
109
|
+
const properties = value.properties;
|
|
110
|
+
if (value.required.some((name) => !properties || !Object.hasOwn(properties, name)))
|
|
111
|
+
invalid(`${path}.required`, "must reference declared properties.");
|
|
112
|
+
}
|
|
113
|
+
if (value.items !== undefined) {
|
|
114
|
+
if (value.type !== "array")
|
|
115
|
+
invalid(`${path}.items`, "requires an array schema.");
|
|
116
|
+
assertSchema(value.items, `${path}.items`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export function assertAgentToolInputSchema(value, path = "inputSchema") {
|
|
120
|
+
if (!isRecord(value) || value.type !== "object")
|
|
121
|
+
invalid(path, 'root type must be object.');
|
|
122
|
+
if (checkedSchemas.has(value))
|
|
123
|
+
return;
|
|
124
|
+
const frozen = assertJson(value, path);
|
|
125
|
+
assertSchema(value, path);
|
|
126
|
+
if (frozen)
|
|
127
|
+
checkedSchemas.add(value);
|
|
128
|
+
}
|
|
129
|
+
function jsonEqual(left, right) {
|
|
130
|
+
if (left === right)
|
|
131
|
+
return true;
|
|
132
|
+
if (Array.isArray(left) && Array.isArray(right))
|
|
133
|
+
return left.length === right.length && left.every((item, index) => jsonEqual(item, right[index]));
|
|
134
|
+
if (!isRecord(left) || !isRecord(right))
|
|
135
|
+
return false;
|
|
136
|
+
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]));
|
|
138
|
+
}
|
|
139
|
+
function typeMatches(schema, value) {
|
|
140
|
+
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;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export function validateAgentToolInput(schema, value, path = "input") {
|
|
151
|
+
if (!typeMatches(schema, value))
|
|
152
|
+
return [`${path} must be ${schema.type}.`];
|
|
153
|
+
const errors = [];
|
|
154
|
+
if (schema.enum && !schema.enum.some((item) => jsonEqual(item, value)))
|
|
155
|
+
errors.push(`${path} must be one of the declared enum values.`);
|
|
156
|
+
if (typeof value === "string") {
|
|
157
|
+
const length = Array.from(value).length;
|
|
158
|
+
if (schema.minLength !== undefined && length < schema.minLength)
|
|
159
|
+
errors.push(`${path} must have at least ${schema.minLength} characters.`);
|
|
160
|
+
if (schema.maxLength !== undefined && length > schema.maxLength)
|
|
161
|
+
errors.push(`${path} must have at most ${schema.maxLength} characters.`);
|
|
162
|
+
if (schema.pattern !== undefined && !patternFor(schema, path).test(value))
|
|
163
|
+
errors.push(`${path} must match pattern ${schema.pattern}.`);
|
|
164
|
+
}
|
|
165
|
+
if (typeof value === "number") {
|
|
166
|
+
if (schema.minimum !== undefined && value < schema.minimum)
|
|
167
|
+
errors.push(`${path} must be >= ${schema.minimum}.`);
|
|
168
|
+
if (schema.maximum !== undefined && value > schema.maximum)
|
|
169
|
+
errors.push(`${path} must be <= ${schema.maximum}.`);
|
|
170
|
+
if (schema.exclusiveMinimum !== undefined && value <= schema.exclusiveMinimum)
|
|
171
|
+
errors.push(`${path} must be > ${schema.exclusiveMinimum}.`);
|
|
172
|
+
if (schema.exclusiveMaximum !== undefined && value >= schema.exclusiveMaximum)
|
|
173
|
+
errors.push(`${path} must be < ${schema.exclusiveMaximum}.`);
|
|
174
|
+
}
|
|
175
|
+
if (Array.isArray(value)) {
|
|
176
|
+
if (schema.minItems !== undefined && value.length < schema.minItems)
|
|
177
|
+
errors.push(`${path} must have at least ${schema.minItems} items.`);
|
|
178
|
+
if (schema.maxItems !== undefined && value.length > schema.maxItems)
|
|
179
|
+
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))))
|
|
181
|
+
errors.push(`${path} must contain unique items.`);
|
|
182
|
+
if (schema.items)
|
|
183
|
+
value.forEach((item, index) => errors.push(...validateAgentToolInput(schema.items, item, `${path}[${index}]`)));
|
|
184
|
+
}
|
|
185
|
+
if (isRecord(value)) {
|
|
186
|
+
for (const key of schema.required ?? []) {
|
|
187
|
+
if (!Object.hasOwn(value, key))
|
|
188
|
+
errors.push(`${path}.${key} is required.`);
|
|
189
|
+
}
|
|
190
|
+
for (const [key, item] of Object.entries(value)) {
|
|
191
|
+
const property = schema.properties && Object.hasOwn(schema.properties, key) ? schema.properties[key] : undefined;
|
|
192
|
+
if (property)
|
|
193
|
+
errors.push(...validateAgentToolInput(property, item, `${path}.${key}`));
|
|
194
|
+
else if (schema.additionalProperties === false)
|
|
195
|
+
errors.push(`${path}.${key} is not allowed.`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return errors;
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/shared/schema.ts"],"names":[],"mappings":"AAAA,yDAAyD;AAIzD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;AAC7F,MAAM,MAAM,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,CAAU,CAAC;AAC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AC;QAC7E,CAAC;QACD,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAChD,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YACjH,IAAI,QAAQ;gBAAE,MAAM,CAAC,IAAI,CAAC,GAAG,sBAAsB,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC;iBAClF,IAAI,MAAM,CAAC,oBAAoB,KAAK,KAAK;gBAAE,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,GAAG,kBAAkB,CAAC,CAAC;QAChG,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Generated from shared/schema.ts. Do not edit manually.\n\nimport type { JsonSchema } from \"@nexface/tools\";\n\nconst types = new Set([\"object\", \"array\", \"string\", \"number\", \"integer\", \"boolean\", \"null\"]);\nconst counts = [\"minLength\", \"maxLength\", \"minItems\", \"maxItems\"] as const;\nconst bounds = [\"minimum\", \"maximum\", \"exclusiveMinimum\", \"exclusiveMaximum\"] as const;\nconst keywords = new Set([\n \"type\", \"description\", \"properties\", \"required\", \"items\", \"enum\", \"additionalProperties\",\n ...counts, ...bounds, \"pattern\", \"uniqueItems\",\n]);\nconst checkedSchemas = new WeakSet<object>();\nconst patterns = new WeakMap<object, { source: string; regex: RegExp }>();\n\nfunction invalid(path: string, message: string): never {\n throw new TypeError(`${path} ${message}`);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\n// Only deeply frozen, JSON-compatible values can safely share validation results.\nfunction assertJson(value: unknown, path: string, ancestors = new Set<object>()): boolean {\n if (value === null || typeof value === \"string\" || typeof value === \"boolean\") return true;\n if (typeof value === \"number\" && Number.isFinite(value)) return true;\n if (typeof value !== \"object\" || value === null) invalid(path, \"must be JSON-compatible.\");\n if (ancestors.has(value)) invalid(path, \"must not contain circular references.\");\n if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {\n invalid(path, \"must be a plain JSON object.\");\n }\n if (Object.getOwnPropertySymbols(value).length) invalid(path, \"must not contain symbol properties.\");\n for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {\n if (!descriptor.enumerable && !(Array.isArray(value) && key === \"length\")) invalid(`${path}.${key}`, \"must be enumerable.\");\n if (descriptor.get || descriptor.set) invalid(`${path}.${key}`, \"must be a data property.\");\n }\n if (Array.isArray(value)) {\n for (let index = 0; index < value.length; index++) {\n if (!Object.hasOwn(value, index)) invalid(`${path}[${index}]`, \"must not be a sparse array slot.\");\n }\n }\n ancestors.add(value);\n let frozen = Object.isFrozen(value);\n for (const [key, child] of Object.entries(value)) {\n const childFrozen = assertJson(child, `${path}.${key}`, ancestors);\n frozen = frozen && childFrozen;\n }\n ancestors.delete(value);\n return frozen;\n}\n\nfunction patternFor(schema: JsonSchema, path: string): RegExp {\n const source = schema.pattern!;\n const cached = patterns.get(schema);\n if (cached?.source === source) return cached.regex;\n let regex: RegExp;\n try {\n regex = new RegExp(source, \"u\");\n } catch {\n invalid(`${path}.pattern`, \"must be a valid Unicode regular expression.\");\n }\n patterns.set(schema, { source, regex });\n return regex;\n}\n\nfunction assertSchema(value: unknown, path: string): void {\n if (!isRecord(value)) invalid(path, \"must be an object.\");\n const unexpected = Object.keys(value).filter((key) => !keywords.has(key));\n if (unexpected.length) invalid(path, `has unsupported fields: ${unexpected.join(\", \")}.`);\n if (value.type !== undefined && (typeof value.type !== \"string\" || !types.has(value.type))) invalid(`${path}.type`, \"is not supported.\");\n if (value.description !== undefined && typeof value.description !== \"string\") invalid(`${path}.description`, \"must be a string.\");\n for (const key of [\"additionalProperties\", \"uniqueItems\"] as const) {\n if (value[key] !== undefined && typeof value[key] !== \"boolean\") invalid(`${path}.${key}`, \"must be a boolean.\");\n }\n for (const key of counts) {\n const count = value[key];\n if (count !== undefined && (typeof count !== \"number\" || !Number.isInteger(count) || count < 0)) invalid(`${path}.${key}`, \"must be a non-negative integer.\");\n }\n for (const key of bounds) {\n if (value[key] !== undefined && (typeof value[key] !== \"number\" || !Number.isFinite(value[key]))) invalid(`${path}.${key}`, \"must be a finite number.\");\n }\n if (value.pattern !== undefined) {\n if (typeof value.pattern !== \"string\") invalid(`${path}.pattern`, \"must be a string.\");\n patternFor(value as JsonSchema, path);\n }\n if (value.enum !== undefined && (!Array.isArray(value.enum) || value.enum.length === 0)) invalid(`${path}.enum`, \"must be a non-empty array.\");\n if (Array.isArray(value.enum) && value.enum.some((item, index, entries) => entries.slice(0, index).some((other) => jsonEqual(item, other)))) invalid(`${path}.enum`, \"must contain unique values.\");\n if (value.properties !== undefined) {\n if (value.type !== \"object\" || !isRecord(value.properties)) invalid(`${path}.properties`, \"requires an object schema.\");\n for (const [name, property] of Object.entries(value.properties)) assertSchema(property, `${path}.properties.${name}`);\n }\n if (value.required !== undefined) {\n if (value.type !== \"object\" || !Array.isArray(value.required) || value.required.some((name) => typeof name !== \"string\") || new Set(value.required).size !== value.required.length) invalid(`${path}.required`, \"must contain unique property names.\");\n const properties = value.properties as Record<string, unknown> | undefined;\n if (value.required.some((name) => !properties || !Object.hasOwn(properties, name))) invalid(`${path}.required`, \"must reference declared properties.\");\n }\n if (value.items !== undefined) {\n if (value.type !== \"array\") invalid(`${path}.items`, \"requires an array schema.\");\n assertSchema(value.items, `${path}.items`);\n }\n}\n\nexport function assertAgentToolInputSchema(value: unknown, path = \"inputSchema\"): void {\n if (!isRecord(value) || value.type !== \"object\") invalid(path, 'root type must be object.');\n if (checkedSchemas.has(value)) return;\n const frozen = assertJson(value, path);\n assertSchema(value, path);\n if (frozen) checkedSchemas.add(value);\n}\n\nfunction jsonEqual(left: unknown, right: unknown): boolean {\n if (left === right) return true;\n if (Array.isArray(left) && Array.isArray(right)) return left.length === right.length && left.every((item, index) => jsonEqual(item, right[index]));\n if (!isRecord(left) || !isRecord(right)) return false;\n const keys = Object.keys(left);\n return keys.length === Object.keys(right).length && keys.every((key) => Object.hasOwn(right, key) && jsonEqual(left[key], right[key]));\n}\n\nfunction typeMatches(schema: JsonSchema, value: unknown): boolean {\n switch (schema.type) {\n case undefined: return true;\n case \"null\": return value === null;\n case \"array\": return Array.isArray(value);\n case \"object\": return isRecord(value);\n case \"integer\": return typeof value === \"number\" && Number.isInteger(value);\n case \"number\": return typeof value === \"number\" && Number.isFinite(value);\n default: return typeof value === schema.type;\n }\n}\n\nexport function validateAgentToolInput(schema: JsonSchema, value: unknown, path = \"input\"): string[] {\n if (!typeMatches(schema, value)) return [`${path} must be ${schema.type}.`];\n const errors: string[] = [];\n if (schema.enum && !schema.enum.some((item) => jsonEqual(item, value))) errors.push(`${path} must be one of the declared enum values.`);\n if (typeof value === \"string\") {\n const length = Array.from(value).length;\n if (schema.minLength !== undefined && length < schema.minLength) errors.push(`${path} must have at least ${schema.minLength} characters.`);\n if (schema.maxLength !== undefined && length > schema.maxLength) errors.push(`${path} must have at most ${schema.maxLength} characters.`);\n if (schema.pattern !== undefined && !patternFor(schema, path).test(value)) errors.push(`${path} must match pattern ${schema.pattern}.`);\n }\n if (typeof value === \"number\") {\n if (schema.minimum !== undefined && value < schema.minimum) errors.push(`${path} must be >= ${schema.minimum}.`);\n if (schema.maximum !== undefined && value > schema.maximum) errors.push(`${path} must be <= ${schema.maximum}.`);\n if (schema.exclusiveMinimum !== undefined && value <= schema.exclusiveMinimum) errors.push(`${path} must be > ${schema.exclusiveMinimum}.`);\n if (schema.exclusiveMaximum !== undefined && value >= schema.exclusiveMaximum) errors.push(`${path} must be < ${schema.exclusiveMaximum}.`);\n }\n if (Array.isArray(value)) {\n if (schema.minItems !== undefined && value.length < schema.minItems) errors.push(`${path} must have at least ${schema.minItems} items.`);\n if (schema.maxItems !== undefined && value.length > schema.maxItems) errors.push(`${path} must have at most ${schema.maxItems} items.`);\n if (schema.uniqueItems && value.some((item, index) => value.slice(0, index).some((other) => jsonEqual(item, other)))) errors.push(`${path} must contain unique items.`);\n if (schema.items) value.forEach((item, index) => errors.push(...validateAgentToolInput(schema.items!, item, `${path}[${index}]`)));\n }\n if (isRecord(value)) {\n for (const key of schema.required ?? []) {\n if (!Object.hasOwn(value, key)) errors.push(`${path}.${key} is required.`);\n }\n for (const [key, item] of Object.entries(value)) {\n const property = schema.properties && Object.hasOwn(schema.properties, key) ? schema.properties[key] : undefined;\n if (property) errors.push(...validateAgentToolInput(property, item, `${path}.${key}`));\n else if (schema.additionalProperties === false) errors.push(`${path}.${key} is not allowed.`);\n }\n }\n return errors;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexface/chat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"./dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@ag-ui/core": "0.0.59",
|
|
21
|
-
"@nexface/agent": "0.1.
|
|
21
|
+
"@nexface/agent": "0.1.13-alpha.0",
|
|
22
22
|
"class-variance-authority": "0.7.1",
|
|
23
23
|
"clsx": "2.1.1",
|
|
24
24
|
"fast-json-patch": "3.1.1",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"use-sync-external-store": "1.7.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@nexface/tools": "0.1.
|
|
30
|
+
"@nexface/tools": "0.1.13-alpha.0",
|
|
31
31
|
"react": ">=17",
|
|
32
32
|
"react-dom": ">=17"
|
|
33
33
|
},
|