@livekit/agents 1.0.14 → 1.0.15
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/llm/tool_context.cjs +3 -2
- package/dist/llm/tool_context.cjs.map +1 -1
- package/dist/llm/tool_context.d.cts +37 -11
- package/dist/llm/tool_context.d.ts +37 -11
- package/dist/llm/tool_context.d.ts.map +1 -1
- package/dist/llm/tool_context.js +4 -3
- package/dist/llm/tool_context.js.map +1 -1
- package/dist/llm/tool_context.test.cjs +197 -0
- package/dist/llm/tool_context.test.cjs.map +1 -1
- package/dist/llm/tool_context.test.js +175 -0
- package/dist/llm/tool_context.test.js.map +1 -1
- package/dist/llm/utils.cjs +17 -11
- package/dist/llm/utils.cjs.map +1 -1
- package/dist/llm/utils.d.cts +1 -2
- package/dist/llm/utils.d.ts +1 -2
- package/dist/llm/utils.d.ts.map +1 -1
- package/dist/llm/utils.js +17 -11
- package/dist/llm/utils.js.map +1 -1
- package/dist/llm/zod-utils.cjs +99 -0
- package/dist/llm/zod-utils.cjs.map +1 -0
- package/dist/llm/zod-utils.d.cts +65 -0
- package/dist/llm/zod-utils.d.ts +65 -0
- package/dist/llm/zod-utils.d.ts.map +1 -0
- package/dist/llm/zod-utils.js +61 -0
- package/dist/llm/zod-utils.js.map +1 -0
- package/dist/llm/zod-utils.test.cjs +389 -0
- package/dist/llm/zod-utils.test.cjs.map +1 -0
- package/dist/llm/zod-utils.test.js +372 -0
- package/dist/llm/zod-utils.test.js.map +1 -0
- package/dist/vad.cjs +16 -0
- package/dist/vad.cjs.map +1 -1
- package/dist/vad.d.cts +6 -0
- package/dist/vad.d.ts +6 -0
- package/dist/vad.d.ts.map +1 -1
- package/dist/vad.js +16 -0
- package/dist/vad.js.map +1 -1
- package/dist/voice/generation.cjs +8 -3
- package/dist/voice/generation.cjs.map +1 -1
- package/dist/voice/generation.d.ts.map +1 -1
- package/dist/voice/generation.js +8 -3
- package/dist/voice/generation.js.map +1 -1
- package/package.json +5 -4
- package/src/llm/__snapshots__/zod-utils.test.ts.snap +341 -0
- package/src/llm/tool_context.test.ts +210 -1
- package/src/llm/tool_context.ts +57 -17
- package/src/llm/utils.ts +18 -15
- package/src/llm/zod-utils.test.ts +476 -0
- package/src/llm/zod-utils.ts +144 -0
- package/src/vad.ts +18 -0
- package/src/voice/generation.ts +8 -3
|
@@ -29,6 +29,7 @@ __export(tool_context_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(tool_context_exports);
|
|
31
31
|
var import_zod = require("zod");
|
|
32
|
+
var import_zod_utils = require("./zod-utils.cjs");
|
|
32
33
|
const TOOL_SYMBOL = Symbol("tool");
|
|
33
34
|
const FUNCTION_TOOL_SYMBOL = Symbol("function_tool");
|
|
34
35
|
const PROVIDER_DEFINED_TOOL_SYMBOL = Symbol("provider_defined_tool");
|
|
@@ -52,10 +53,10 @@ function handoff(options) {
|
|
|
52
53
|
function tool(tool2) {
|
|
53
54
|
if (tool2.execute !== void 0) {
|
|
54
55
|
const parameters = tool2.parameters ?? import_zod.z.object({});
|
|
55
|
-
if (
|
|
56
|
+
if ((0, import_zod_utils.isZodSchema)(parameters) && !(0, import_zod_utils.isZodObjectSchema)(parameters)) {
|
|
56
57
|
throw new Error("Tool parameters must be a Zod object schema (z.object(...))");
|
|
57
58
|
}
|
|
58
|
-
if (!(
|
|
59
|
+
if (!(0, import_zod_utils.isZodSchema)(parameters) && !(typeof parameters === "object")) {
|
|
59
60
|
throw new Error("Tool parameters must be a Zod object schema or a raw JSON schema");
|
|
60
61
|
}
|
|
61
62
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/llm/tool_context.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { JSONSchema7 } from 'json-schema';\nimport { ZodObject, ZodType, z } from 'zod';\nimport type { Agent } from '../voice/agent.js';\nimport type { RunContext, UnknownUserData } from '../voice/run_context.js';\n\n// heavily inspired by Vercel AI's `tool()`:\n// https://github.com/vercel/ai/blob/3b0983b/packages/ai/core/tool/tool.ts\n\nconst TOOL_SYMBOL = Symbol('tool');\nconst FUNCTION_TOOL_SYMBOL = Symbol('function_tool');\nconst PROVIDER_DEFINED_TOOL_SYMBOL = Symbol('provider_defined_tool');\nconst TOOL_ERROR_SYMBOL = Symbol('tool_error');\nconst HANDOFF_SYMBOL = Symbol('handoff');\n\nexport type JSONValue = null | string | number | boolean | JSONObject | JSONArray;\n\nexport type JSONArray = JSONValue[];\n\nexport type JSONObject = {\n [key: string]: JSONValue;\n};\n\n// TODO(AJS-111): support Zod cross-version compatibility, raw JSON schema, both strict and non-strict versions\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ToolInputSchema<T extends JSONObject> = ZodObject<any, any, any, T, T> | JSONSchema7;\n\nexport type ToolType = 'function' | 'provider-defined';\n\nexport type ToolChoice =\n | 'auto'\n | 'none'\n | 'required'\n | {\n type: 'function';\n function: {\n name: string;\n };\n };\n\nexport class ToolError extends Error {\n constructor(message: string) {\n super(message);\n\n Object.defineProperty(this, TOOL_ERROR_SYMBOL, {\n value: true,\n });\n }\n}\n\nexport interface AgentHandoff {\n /**\n * The agent to handoff to.\n */\n agent: Agent;\n\n /**\n * The return value of the tool.\n */\n returns?: any; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n [HANDOFF_SYMBOL]: true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function handoff(options: { agent: Agent; returns?: any }): AgentHandoff {\n return {\n agent: options.agent,\n returns: options.returns,\n [HANDOFF_SYMBOL]: true,\n };\n}\n\nexport interface ToolOptions<UserData = UnknownUserData> {\n /**\n * RunContext for the current agent session.\n */\n ctx: RunContext<UserData>;\n\n /**\n * The ID of the tool call.\n */\n toolCallId: string;\n\n /**\n * An optional abort signal that indicates that the overall operation should be aborted.\n */\n abortSignal?: AbortSignal;\n}\n\nexport type ToolExecuteFunction<\n Parameters extends JSONObject,\n UserData = UnknownUserData,\n Result = unknown,\n> = (args: Parameters, opts: ToolOptions<UserData>) => Promise<Result>;\n\nexport interface Tool {\n /**\n * The type of the tool.\n * @internal Either user-defined core tool or provider-defined tool.\n */\n type: ToolType;\n\n [TOOL_SYMBOL]: true;\n}\n\n// TODO(AJS-112): support provider-defined tools\nexport interface ProviderDefinedTool extends Tool {\n type: 'provider-defined';\n\n /**\n * The ID of the tool.\n */\n id: string;\n\n /**\n * The configuration of the tool.\n */\n config: Record<string, unknown>;\n\n [PROVIDER_DEFINED_TOOL_SYMBOL]: true;\n}\n\nexport interface FunctionTool<\n Parameters extends JSONObject,\n UserData = UnknownUserData,\n Result = unknown,\n> extends Tool {\n type: 'function';\n\n /**\n * The description of the tool. Will be used by the language model to decide whether to use the tool.\n */\n description: string;\n\n /**\n * The schema of the input that the tool expects. The language model will use this to generate the input.\n * It is also used to validate the output of the language model.\n * Use descriptions to make the input understandable for the language model.\n */\n parameters: ToolInputSchema<Parameters>;\n\n /**\n * An async function that is called with the arguments from the tool call and produces a result.\n * It also carries context about current session, user-defined data, and the tool call id, etc.\n */\n execute: ToolExecuteFunction<Parameters, UserData, Result>;\n\n [FUNCTION_TOOL_SYMBOL]: true;\n}\n\n// TODO(AJS-112): support provider-defined tools in the future)\nexport type ToolContext<UserData = UnknownUserData> = {\n [name: string]: FunctionTool<any, UserData, any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n};\n\n/**\n * Create a function tool.\n *\n * @param description - The description of the tool.\n * @param parameters - The schema of the input that the tool expects. If not provided, defaults to z.object({}).\n * @param execute - The function that is called with the arguments from the tool call and produces a result.\n */\nexport function tool<\n Parameters extends JSONObject = Record<string, never>,\n UserData = UnknownUserData,\n Result = unknown,\n>({\n description,\n parameters,\n execute,\n}: {\n description: string;\n parameters?: ToolInputSchema<Parameters>;\n execute: ToolExecuteFunction<Parameters, UserData, Result>;\n}): FunctionTool<Parameters, UserData, Result>;\n\n/**\n * Create a provider-defined tool.\n *\n * @param id - The ID of the tool.\n * @param config - The configuration of the tool.\n */\nexport function tool({\n id,\n config,\n}: {\n id: string;\n config: Record<string, unknown>;\n}): ProviderDefinedTool;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function tool(tool: any): any {\n if (tool.execute !== undefined) {\n // Default parameters to z.object({}) if not provided\n const parameters = tool.parameters ?? z.object({});\n\n // if parameters is not zod object, throw an error\n if (parameters instanceof ZodType && parameters._def.typeName !== 'ZodObject') {\n throw new Error('Tool parameters must be a Zod object schema (z.object(...))');\n }\n\n if (!(parameters instanceof ZodObject) && !(typeof parameters === 'object')) {\n throw new Error('Tool parameters must be a Zod object schema or a raw JSON schema');\n }\n\n return {\n type: 'function',\n description: tool.description,\n parameters,\n execute: tool.execute,\n [TOOL_SYMBOL]: true,\n [FUNCTION_TOOL_SYMBOL]: true,\n };\n }\n\n if (tool.config !== undefined && tool.id !== undefined) {\n return {\n type: 'provider-defined',\n id: tool.id,\n config: tool.config,\n [TOOL_SYMBOL]: true,\n [PROVIDER_DEFINED_TOOL_SYMBOL]: true,\n };\n }\n\n throw new Error('Invalid tool');\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isTool(tool: any): tool is Tool {\n return tool && tool[TOOL_SYMBOL] === true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isFunctionTool(tool: any): tool is FunctionTool<any, any, any> {\n const isTool = tool && tool[TOOL_SYMBOL] === true;\n const isFunctionTool = tool[FUNCTION_TOOL_SYMBOL] === true;\n return isTool && isFunctionTool;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isProviderDefinedTool(tool: any): tool is ProviderDefinedTool {\n const isTool = tool && tool[TOOL_SYMBOL] === true;\n const isProviderDefinedTool = tool[PROVIDER_DEFINED_TOOL_SYMBOL] === true;\n return isTool && isProviderDefinedTool;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isToolError(error: any): error is ToolError {\n return error && error[TOOL_ERROR_SYMBOL] === true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isAgentHandoff(handoff: any): handoff is AgentHandoff {\n return handoff && handoff[HANDOFF_SYMBOL] === true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,iBAAsC;AAOtC,MAAM,cAAc,OAAO,MAAM;AACjC,MAAM,uBAAuB,OAAO,eAAe;AACnD,MAAM,+BAA+B,OAAO,uBAAuB;AACnE,MAAM,oBAAoB,OAAO,YAAY;AAC7C,MAAM,iBAAiB,OAAO,SAAS;AA2BhC,MAAM,kBAAkB,MAAM;AAAA,EACnC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AAEb,WAAO,eAAe,MAAM,mBAAmB;AAAA,MAC7C,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF;AAiBO,SAAS,QAAQ,SAAwD;AAC9E,SAAO;AAAA,IACL,OAAO,QAAQ;AAAA,IACf,SAAS,QAAQ;AAAA,IACjB,CAAC,cAAc,GAAG;AAAA,EACpB;AACF;AAyHO,SAAS,KAAKA,OAAgB;AACnC,MAAIA,MAAK,YAAY,QAAW;AAE9B,UAAM,aAAaA,MAAK,cAAc,aAAE,OAAO,CAAC,CAAC;AAGjD,QAAI,sBAAsB,sBAAW,WAAW,KAAK,aAAa,aAAa;AAC7E,YAAM,IAAI,MAAM,6DAA6D;AAAA,IAC/E;AAEA,QAAI,EAAE,sBAAsB,yBAAc,EAAE,OAAO,eAAe,WAAW;AAC3E,YAAM,IAAI,MAAM,kEAAkE;AAAA,IACpF;AAEA,WAAO;AAAA,MACL,MAAM;AAAA,MACN,aAAaA,MAAK;AAAA,MAClB;AAAA,MACA,SAASA,MAAK;AAAA,MACd,CAAC,WAAW,GAAG;AAAA,MACf,CAAC,oBAAoB,GAAG;AAAA,IAC1B;AAAA,EACF;AAEA,MAAIA,MAAK,WAAW,UAAaA,MAAK,OAAO,QAAW;AACtD,WAAO;AAAA,MACL,MAAM;AAAA,MACN,IAAIA,MAAK;AAAA,MACT,QAAQA,MAAK;AAAA,MACb,CAAC,WAAW,GAAG;AAAA,MACf,CAAC,4BAA4B,GAAG;AAAA,IAClC;AAAA,EACF;AAEA,QAAM,IAAI,MAAM,cAAc;AAChC;AAGO,SAAS,OAAOA,OAAyB;AAC9C,SAAOA,SAAQA,MAAK,WAAW,MAAM;AACvC;AAGO,SAAS,eAAeA,OAAgD;AAC7E,QAAMC,UAASD,SAAQA,MAAK,WAAW,MAAM;AAC7C,QAAME,kBAAiBF,MAAK,oBAAoB,MAAM;AACtD,SAAOC,WAAUC;AACnB;AAGO,SAAS,sBAAsBF,OAAwC;AAC5E,QAAMC,UAASD,SAAQA,MAAK,WAAW,MAAM;AAC7C,QAAMG,yBAAwBH,MAAK,4BAA4B,MAAM;AACrE,SAAOC,WAAUE;AACnB;AAGO,SAAS,YAAY,OAAgC;AAC1D,SAAO,SAAS,MAAM,iBAAiB,MAAM;AAC/C;AAGO,SAAS,eAAeC,UAAuC;AACpE,SAAOA,YAAWA,SAAQ,cAAc,MAAM;AAChD;","names":["tool","isTool","isFunctionTool","isProviderDefinedTool","handoff"]}
|
|
1
|
+
{"version":3,"sources":["../../src/llm/tool_context.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { JSONSchema7 } from 'json-schema';\nimport { z } from 'zod';\nimport type { Agent } from '../voice/agent.js';\nimport type { RunContext, UnknownUserData } from '../voice/run_context.js';\nimport { isZodObjectSchema, isZodSchema } from './zod-utils.js';\n\n// heavily inspired by Vercel AI's `tool()`:\n// https://github.com/vercel/ai/blob/3b0983b/packages/ai/core/tool/tool.ts\n\nconst TOOL_SYMBOL = Symbol('tool');\nconst FUNCTION_TOOL_SYMBOL = Symbol('function_tool');\nconst PROVIDER_DEFINED_TOOL_SYMBOL = Symbol('provider_defined_tool');\nconst TOOL_ERROR_SYMBOL = Symbol('tool_error');\nconst HANDOFF_SYMBOL = Symbol('handoff');\n\nexport type JSONValue = null | string | number | boolean | JSONObject | JSONArray;\n\nexport type JSONArray = JSONValue[];\n\nexport type JSONObject = {\n [key: string]: JSONValue;\n};\n\n// Supports both Zod v3 and v4 schemas, as well as raw JSON schema\n// Adapted from Vercel AI SDK's FlexibleSchema approach\n// Source: https://github.com/vercel/ai/blob/main/packages/provider-utils/src/schema.ts#L67-L70\n//\n// Vercel uses StandardSchemaV1 from @standard-schema/spec package.\n// We use a simpler approach by directly checking for schema properties:\n// - Zod v3: Has `_output` property\n// - Zod v4: Implements Standard Schema spec with `~standard` property\n// - JSON Schema: Plain object fallback\nexport type ToolInputSchema<T = JSONObject> =\n | {\n // Zod v3 schema - has _output property for type inference\n _output: T;\n }\n | {\n // Zod v4 schema (Standard Schema) - has ~standard property\n '~standard': {\n types?: { output: T };\n };\n }\n | JSONSchema7;\n\n/**\n * Infer the output type from a ToolInputSchema.\n * Adapted from Vercel AI SDK's InferSchema type.\n * Source: https://github.com/vercel/ai/blob/main/packages/provider-utils/src/schema.ts#L72-L79\n */\nexport type InferToolInput<T> = T extends { _output: infer O }\n ? O\n : T extends { '~standard': { types?: { output: infer O } } }\n ? O\n : any; // eslint-disable-line @typescript-eslint/no-explicit-any -- Fallback type for JSON Schema objects without type inference\n\nexport type ToolType = 'function' | 'provider-defined';\n\nexport type ToolChoice =\n | 'auto'\n | 'none'\n | 'required'\n | {\n type: 'function';\n function: {\n name: string;\n };\n };\n\nexport class ToolError extends Error {\n constructor(message: string) {\n super(message);\n\n Object.defineProperty(this, TOOL_ERROR_SYMBOL, {\n value: true,\n });\n }\n}\n\nexport interface AgentHandoff {\n /**\n * The agent to handoff to.\n */\n agent: Agent;\n\n /**\n * The return value of the tool.\n */\n returns?: any; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n [HANDOFF_SYMBOL]: true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function handoff(options: { agent: Agent; returns?: any }): AgentHandoff {\n return {\n agent: options.agent,\n returns: options.returns,\n [HANDOFF_SYMBOL]: true,\n };\n}\n\nexport interface ToolOptions<UserData = UnknownUserData> {\n /**\n * RunContext for the current agent session.\n */\n ctx: RunContext<UserData>;\n\n /**\n * The ID of the tool call.\n */\n toolCallId: string;\n\n /**\n * An optional abort signal that indicates that the overall operation should be aborted.\n */\n abortSignal?: AbortSignal;\n}\n\nexport type ToolExecuteFunction<\n Parameters extends JSONObject,\n UserData = UnknownUserData,\n Result = unknown,\n> = (args: Parameters, opts: ToolOptions<UserData>) => Promise<Result>;\n\nexport interface Tool {\n /**\n * The type of the tool.\n * @internal Either user-defined core tool or provider-defined tool.\n */\n type: ToolType;\n\n [TOOL_SYMBOL]: true;\n}\n\n// TODO(AJS-112): support provider-defined tools\nexport interface ProviderDefinedTool extends Tool {\n type: 'provider-defined';\n\n /**\n * The ID of the tool.\n */\n id: string;\n\n /**\n * The configuration of the tool.\n */\n config: Record<string, unknown>;\n\n [PROVIDER_DEFINED_TOOL_SYMBOL]: true;\n}\n\nexport interface FunctionTool<\n Parameters extends JSONObject,\n UserData = UnknownUserData,\n Result = unknown,\n> extends Tool {\n type: 'function';\n\n /**\n * The description of the tool. Will be used by the language model to decide whether to use the tool.\n */\n description: string;\n\n /**\n * The schema of the input that the tool expects. The language model will use this to generate the input.\n * It is also used to validate the output of the language model.\n * Use descriptions to make the input understandable for the language model.\n */\n parameters: ToolInputSchema<Parameters>;\n\n /**\n * An async function that is called with the arguments from the tool call and produces a result.\n * It also carries context about current session, user-defined data, and the tool call id, etc.\n */\n execute: ToolExecuteFunction<Parameters, UserData, Result>;\n\n [FUNCTION_TOOL_SYMBOL]: true;\n}\n\n// TODO(AJS-112): support provider-defined tools in the future)\nexport type ToolContext<UserData = UnknownUserData> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Generic tool registry needs to accept any parameter/result types\n [name: string]: FunctionTool<any, UserData, any>;\n};\n\n/**\n * Create a function tool with inferred parameters from the schema.\n */\nexport function tool<\n Schema extends ToolInputSchema<any>, // eslint-disable-line @typescript-eslint/no-explicit-any -- Generic constraint needs to accept any JSONObject type\n UserData = UnknownUserData,\n Result = unknown,\n>({\n description,\n parameters,\n execute,\n}: {\n description: string;\n parameters: Schema;\n execute: ToolExecuteFunction<InferToolInput<Schema>, UserData, Result>;\n}): FunctionTool<InferToolInput<Schema>, UserData, Result>;\n\n/**\n * Create a function tool without parameters.\n */\nexport function tool<UserData = UnknownUserData, Result = unknown>({\n description,\n execute,\n}: {\n description: string;\n parameters?: never;\n execute: ToolExecuteFunction<Record<string, never>, UserData, Result>;\n}): FunctionTool<Record<string, never>, UserData, Result>;\n\n/**\n * Create a provider-defined tool.\n *\n * @param id - The ID of the tool.\n * @param config - The configuration of the tool.\n */\nexport function tool({\n id,\n config,\n}: {\n id: string;\n config: Record<string, unknown>;\n}): ProviderDefinedTool;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function tool(tool: any): any {\n if (tool.execute !== undefined) {\n // Default parameters to z.object({}) if not provided\n const parameters = tool.parameters ?? z.object({});\n\n // if parameters is a Zod schema, ensure it's an object schema\n if (isZodSchema(parameters) && !isZodObjectSchema(parameters)) {\n throw new Error('Tool parameters must be a Zod object schema (z.object(...))');\n }\n\n // Ensure parameters is either a Zod schema or a plain object (JSON schema)\n if (!isZodSchema(parameters) && !(typeof parameters === 'object')) {\n throw new Error('Tool parameters must be a Zod object schema or a raw JSON schema');\n }\n\n return {\n type: 'function',\n description: tool.description,\n parameters,\n execute: tool.execute,\n [TOOL_SYMBOL]: true,\n [FUNCTION_TOOL_SYMBOL]: true,\n };\n }\n\n if (tool.config !== undefined && tool.id !== undefined) {\n return {\n type: 'provider-defined',\n id: tool.id,\n config: tool.config,\n [TOOL_SYMBOL]: true,\n [PROVIDER_DEFINED_TOOL_SYMBOL]: true,\n };\n }\n\n throw new Error('Invalid tool');\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isTool(tool: any): tool is Tool {\n return tool && tool[TOOL_SYMBOL] === true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isFunctionTool(tool: any): tool is FunctionTool<any, any, any> {\n const isTool = tool && tool[TOOL_SYMBOL] === true;\n const isFunctionTool = tool[FUNCTION_TOOL_SYMBOL] === true;\n return isTool && isFunctionTool;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isProviderDefinedTool(tool: any): tool is ProviderDefinedTool {\n const isTool = tool && tool[TOOL_SYMBOL] === true;\n const isProviderDefinedTool = tool[PROVIDER_DEFINED_TOOL_SYMBOL] === true;\n return isTool && isProviderDefinedTool;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isToolError(error: any): error is ToolError {\n return error && error[TOOL_ERROR_SYMBOL] === true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isAgentHandoff(handoff: any): handoff is AgentHandoff {\n return handoff && handoff[HANDOFF_SYMBOL] === true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,iBAAkB;AAGlB,uBAA+C;AAK/C,MAAM,cAAc,OAAO,MAAM;AACjC,MAAM,uBAAuB,OAAO,eAAe;AACnD,MAAM,+BAA+B,OAAO,uBAAuB;AACnE,MAAM,oBAAoB,OAAO,YAAY;AAC7C,MAAM,iBAAiB,OAAO,SAAS;AAwDhC,MAAM,kBAAkB,MAAM;AAAA,EACnC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AAEb,WAAO,eAAe,MAAM,mBAAmB;AAAA,MAC7C,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF;AAiBO,SAAS,QAAQ,SAAwD;AAC9E,SAAO;AAAA,IACL,OAAO,QAAQ;AAAA,IACf,SAAS,QAAQ;AAAA,IAC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eC,UAAuC;AACpE,SAAOA,YAAWA,SAAQ,cAAc,MAAM;AAChD;","names":["tool","isTool","isFunctionTool","isProviderDefinedTool","handoff"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
-
import { ZodObject } from 'zod';
|
|
3
2
|
import type { Agent } from '../voice/agent.js';
|
|
4
3
|
import type { RunContext, UnknownUserData } from '../voice/run_context.js';
|
|
5
4
|
declare const TOOL_SYMBOL: unique symbol;
|
|
@@ -11,7 +10,29 @@ export type JSONArray = JSONValue[];
|
|
|
11
10
|
export type JSONObject = {
|
|
12
11
|
[key: string]: JSONValue;
|
|
13
12
|
};
|
|
14
|
-
export type ToolInputSchema<T
|
|
13
|
+
export type ToolInputSchema<T = JSONObject> = {
|
|
14
|
+
_output: T;
|
|
15
|
+
} | {
|
|
16
|
+
'~standard': {
|
|
17
|
+
types?: {
|
|
18
|
+
output: T;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
} | JSONSchema7;
|
|
22
|
+
/**
|
|
23
|
+
* Infer the output type from a ToolInputSchema.
|
|
24
|
+
* Adapted from Vercel AI SDK's InferSchema type.
|
|
25
|
+
* Source: https://github.com/vercel/ai/blob/main/packages/provider-utils/src/schema.ts#L72-L79
|
|
26
|
+
*/
|
|
27
|
+
export type InferToolInput<T> = T extends {
|
|
28
|
+
_output: infer O;
|
|
29
|
+
} ? O : T extends {
|
|
30
|
+
'~standard': {
|
|
31
|
+
types?: {
|
|
32
|
+
output: infer O;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
} ? O : any;
|
|
15
36
|
export type ToolType = 'function' | 'provider-defined';
|
|
16
37
|
export type ToolChoice = 'auto' | 'none' | 'required' | {
|
|
17
38
|
type: 'function';
|
|
@@ -95,17 +116,22 @@ export type ToolContext<UserData = UnknownUserData> = {
|
|
|
95
116
|
[name: string]: FunctionTool<any, UserData, any>;
|
|
96
117
|
};
|
|
97
118
|
/**
|
|
98
|
-
* Create a function tool.
|
|
99
|
-
*
|
|
100
|
-
* @param description - The description of the tool.
|
|
101
|
-
* @param parameters - The schema of the input that the tool expects. If not provided, defaults to z.object({}).
|
|
102
|
-
* @param execute - The function that is called with the arguments from the tool call and produces a result.
|
|
119
|
+
* Create a function tool with inferred parameters from the schema.
|
|
103
120
|
*/
|
|
104
|
-
export declare function tool<
|
|
121
|
+
export declare function tool<Schema extends ToolInputSchema<any>, // eslint-disable-line @typescript-eslint/no-explicit-any -- Generic constraint needs to accept any JSONObject type
|
|
122
|
+
UserData = UnknownUserData, Result = unknown>({ description, parameters, execute, }: {
|
|
105
123
|
description: string;
|
|
106
|
-
parameters
|
|
107
|
-
execute: ToolExecuteFunction<
|
|
108
|
-
}): FunctionTool<
|
|
124
|
+
parameters: Schema;
|
|
125
|
+
execute: ToolExecuteFunction<InferToolInput<Schema>, UserData, Result>;
|
|
126
|
+
}): FunctionTool<InferToolInput<Schema>, UserData, Result>;
|
|
127
|
+
/**
|
|
128
|
+
* Create a function tool without parameters.
|
|
129
|
+
*/
|
|
130
|
+
export declare function tool<UserData = UnknownUserData, Result = unknown>({ description, execute, }: {
|
|
131
|
+
description: string;
|
|
132
|
+
parameters?: never;
|
|
133
|
+
execute: ToolExecuteFunction<Record<string, never>, UserData, Result>;
|
|
134
|
+
}): FunctionTool<Record<string, never>, UserData, Result>;
|
|
109
135
|
/**
|
|
110
136
|
* Create a provider-defined tool.
|
|
111
137
|
*
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
-
import { ZodObject } from 'zod';
|
|
3
2
|
import type { Agent } from '../voice/agent.js';
|
|
4
3
|
import type { RunContext, UnknownUserData } from '../voice/run_context.js';
|
|
5
4
|
declare const TOOL_SYMBOL: unique symbol;
|
|
@@ -11,7 +10,29 @@ export type JSONArray = JSONValue[];
|
|
|
11
10
|
export type JSONObject = {
|
|
12
11
|
[key: string]: JSONValue;
|
|
13
12
|
};
|
|
14
|
-
export type ToolInputSchema<T
|
|
13
|
+
export type ToolInputSchema<T = JSONObject> = {
|
|
14
|
+
_output: T;
|
|
15
|
+
} | {
|
|
16
|
+
'~standard': {
|
|
17
|
+
types?: {
|
|
18
|
+
output: T;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
} | JSONSchema7;
|
|
22
|
+
/**
|
|
23
|
+
* Infer the output type from a ToolInputSchema.
|
|
24
|
+
* Adapted from Vercel AI SDK's InferSchema type.
|
|
25
|
+
* Source: https://github.com/vercel/ai/blob/main/packages/provider-utils/src/schema.ts#L72-L79
|
|
26
|
+
*/
|
|
27
|
+
export type InferToolInput<T> = T extends {
|
|
28
|
+
_output: infer O;
|
|
29
|
+
} ? O : T extends {
|
|
30
|
+
'~standard': {
|
|
31
|
+
types?: {
|
|
32
|
+
output: infer O;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
} ? O : any;
|
|
15
36
|
export type ToolType = 'function' | 'provider-defined';
|
|
16
37
|
export type ToolChoice = 'auto' | 'none' | 'required' | {
|
|
17
38
|
type: 'function';
|
|
@@ -95,17 +116,22 @@ export type ToolContext<UserData = UnknownUserData> = {
|
|
|
95
116
|
[name: string]: FunctionTool<any, UserData, any>;
|
|
96
117
|
};
|
|
97
118
|
/**
|
|
98
|
-
* Create a function tool.
|
|
99
|
-
*
|
|
100
|
-
* @param description - The description of the tool.
|
|
101
|
-
* @param parameters - The schema of the input that the tool expects. If not provided, defaults to z.object({}).
|
|
102
|
-
* @param execute - The function that is called with the arguments from the tool call and produces a result.
|
|
119
|
+
* Create a function tool with inferred parameters from the schema.
|
|
103
120
|
*/
|
|
104
|
-
export declare function tool<
|
|
121
|
+
export declare function tool<Schema extends ToolInputSchema<any>, // eslint-disable-line @typescript-eslint/no-explicit-any -- Generic constraint needs to accept any JSONObject type
|
|
122
|
+
UserData = UnknownUserData, Result = unknown>({ description, parameters, execute, }: {
|
|
105
123
|
description: string;
|
|
106
|
-
parameters
|
|
107
|
-
execute: ToolExecuteFunction<
|
|
108
|
-
}): FunctionTool<
|
|
124
|
+
parameters: Schema;
|
|
125
|
+
execute: ToolExecuteFunction<InferToolInput<Schema>, UserData, Result>;
|
|
126
|
+
}): FunctionTool<InferToolInput<Schema>, UserData, Result>;
|
|
127
|
+
/**
|
|
128
|
+
* Create a function tool without parameters.
|
|
129
|
+
*/
|
|
130
|
+
export declare function tool<UserData = UnknownUserData, Result = unknown>({ description, execute, }: {
|
|
131
|
+
description: string;
|
|
132
|
+
parameters?: never;
|
|
133
|
+
execute: ToolExecuteFunction<Record<string, never>, UserData, Result>;
|
|
134
|
+
}): FunctionTool<Record<string, never>, UserData, Result>;
|
|
109
135
|
/**
|
|
110
136
|
* Create a provider-defined tool.
|
|
111
137
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool_context.d.ts","sourceRoot":"","sources":["../../src/llm/tool_context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"tool_context.d.ts","sourceRoot":"","sources":["../../src/llm/tool_context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAM3E,QAAA,MAAM,WAAW,eAAiB,CAAC;AACnC,QAAA,MAAM,oBAAoB,eAA0B,CAAC;AACrD,QAAA,MAAM,4BAA4B,eAAkC,CAAC;AAErE,QAAA,MAAM,cAAc,eAAoB,CAAC;AAEzC,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,CAAC;AAElF,MAAM,MAAM,SAAS,GAAG,SAAS,EAAE,CAAC;AAEpC,MAAM,MAAM,UAAU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BAAqB,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,IAAI,mBAAmB,CAI5E;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,SAAS,CAE1D;AAGD,wBAAgB,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,IAAI,YAAY,CAEpE"}
|
package/dist/llm/tool_context.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { isZodObjectSchema, isZodSchema } from "./zod-utils.js";
|
|
2
3
|
const TOOL_SYMBOL = Symbol("tool");
|
|
3
4
|
const FUNCTION_TOOL_SYMBOL = Symbol("function_tool");
|
|
4
5
|
const PROVIDER_DEFINED_TOOL_SYMBOL = Symbol("provider_defined_tool");
|
|
@@ -22,10 +23,10 @@ function handoff(options) {
|
|
|
22
23
|
function tool(tool2) {
|
|
23
24
|
if (tool2.execute !== void 0) {
|
|
24
25
|
const parameters = tool2.parameters ?? z.object({});
|
|
25
|
-
if (parameters
|
|
26
|
+
if (isZodSchema(parameters) && !isZodObjectSchema(parameters)) {
|
|
26
27
|
throw new Error("Tool parameters must be a Zod object schema (z.object(...))");
|
|
27
28
|
}
|
|
28
|
-
if (!(parameters
|
|
29
|
+
if (!isZodSchema(parameters) && !(typeof parameters === "object")) {
|
|
29
30
|
throw new Error("Tool parameters must be a Zod object schema or a raw JSON schema");
|
|
30
31
|
}
|
|
31
32
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/llm/tool_context.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { JSONSchema7 } from 'json-schema';\nimport { ZodObject, ZodType, z } from 'zod';\nimport type { Agent } from '../voice/agent.js';\nimport type { RunContext, UnknownUserData } from '../voice/run_context.js';\n\n// heavily inspired by Vercel AI's `tool()`:\n// https://github.com/vercel/ai/blob/3b0983b/packages/ai/core/tool/tool.ts\n\nconst TOOL_SYMBOL = Symbol('tool');\nconst FUNCTION_TOOL_SYMBOL = Symbol('function_tool');\nconst PROVIDER_DEFINED_TOOL_SYMBOL = Symbol('provider_defined_tool');\nconst TOOL_ERROR_SYMBOL = Symbol('tool_error');\nconst HANDOFF_SYMBOL = Symbol('handoff');\n\nexport type JSONValue = null | string | number | boolean | JSONObject | JSONArray;\n\nexport type JSONArray = JSONValue[];\n\nexport type JSONObject = {\n [key: string]: JSONValue;\n};\n\n// TODO(AJS-111): support Zod cross-version compatibility, raw JSON schema, both strict and non-strict versions\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ToolInputSchema<T extends JSONObject> = ZodObject<any, any, any, T, T> | JSONSchema7;\n\nexport type ToolType = 'function' | 'provider-defined';\n\nexport type ToolChoice =\n | 'auto'\n | 'none'\n | 'required'\n | {\n type: 'function';\n function: {\n name: string;\n };\n };\n\nexport class ToolError extends Error {\n constructor(message: string) {\n super(message);\n\n Object.defineProperty(this, TOOL_ERROR_SYMBOL, {\n value: true,\n });\n }\n}\n\nexport interface AgentHandoff {\n /**\n * The agent to handoff to.\n */\n agent: Agent;\n\n /**\n * The return value of the tool.\n */\n returns?: any; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n [HANDOFF_SYMBOL]: true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function handoff(options: { agent: Agent; returns?: any }): AgentHandoff {\n return {\n agent: options.agent,\n returns: options.returns,\n [HANDOFF_SYMBOL]: true,\n };\n}\n\nexport interface ToolOptions<UserData = UnknownUserData> {\n /**\n * RunContext for the current agent session.\n */\n ctx: RunContext<UserData>;\n\n /**\n * The ID of the tool call.\n */\n toolCallId: string;\n\n /**\n * An optional abort signal that indicates that the overall operation should be aborted.\n */\n abortSignal?: AbortSignal;\n}\n\nexport type ToolExecuteFunction<\n Parameters extends JSONObject,\n UserData = UnknownUserData,\n Result = unknown,\n> = (args: Parameters, opts: ToolOptions<UserData>) => Promise<Result>;\n\nexport interface Tool {\n /**\n * The type of the tool.\n * @internal Either user-defined core tool or provider-defined tool.\n */\n type: ToolType;\n\n [TOOL_SYMBOL]: true;\n}\n\n// TODO(AJS-112): support provider-defined tools\nexport interface ProviderDefinedTool extends Tool {\n type: 'provider-defined';\n\n /**\n * The ID of the tool.\n */\n id: string;\n\n /**\n * The configuration of the tool.\n */\n config: Record<string, unknown>;\n\n [PROVIDER_DEFINED_TOOL_SYMBOL]: true;\n}\n\nexport interface FunctionTool<\n Parameters extends JSONObject,\n UserData = UnknownUserData,\n Result = unknown,\n> extends Tool {\n type: 'function';\n\n /**\n * The description of the tool. Will be used by the language model to decide whether to use the tool.\n */\n description: string;\n\n /**\n * The schema of the input that the tool expects. The language model will use this to generate the input.\n * It is also used to validate the output of the language model.\n * Use descriptions to make the input understandable for the language model.\n */\n parameters: ToolInputSchema<Parameters>;\n\n /**\n * An async function that is called with the arguments from the tool call and produces a result.\n * It also carries context about current session, user-defined data, and the tool call id, etc.\n */\n execute: ToolExecuteFunction<Parameters, UserData, Result>;\n\n [FUNCTION_TOOL_SYMBOL]: true;\n}\n\n// TODO(AJS-112): support provider-defined tools in the future)\nexport type ToolContext<UserData = UnknownUserData> = {\n [name: string]: FunctionTool<any, UserData, any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n};\n\n/**\n * Create a function tool.\n *\n * @param description - The description of the tool.\n * @param parameters - The schema of the input that the tool expects. If not provided, defaults to z.object({}).\n * @param execute - The function that is called with the arguments from the tool call and produces a result.\n */\nexport function tool<\n Parameters extends JSONObject = Record<string, never>,\n UserData = UnknownUserData,\n Result = unknown,\n>({\n description,\n parameters,\n execute,\n}: {\n description: string;\n parameters?: ToolInputSchema<Parameters>;\n execute: ToolExecuteFunction<Parameters, UserData, Result>;\n}): FunctionTool<Parameters, UserData, Result>;\n\n/**\n * Create a provider-defined tool.\n *\n * @param id - The ID of the tool.\n * @param config - The configuration of the tool.\n */\nexport function tool({\n id,\n config,\n}: {\n id: string;\n config: Record<string, unknown>;\n}): ProviderDefinedTool;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function tool(tool: any): any {\n if (tool.execute !== undefined) {\n // Default parameters to z.object({}) if not provided\n const parameters = tool.parameters ?? z.object({});\n\n // if parameters is not zod object, throw an error\n if (parameters instanceof ZodType && parameters._def.typeName !== 'ZodObject') {\n throw new Error('Tool parameters must be a Zod object schema (z.object(...))');\n }\n\n if (!(parameters instanceof ZodObject) && !(typeof parameters === 'object')) {\n throw new Error('Tool parameters must be a Zod object schema or a raw JSON schema');\n }\n\n return {\n type: 'function',\n description: tool.description,\n parameters,\n execute: tool.execute,\n [TOOL_SYMBOL]: true,\n [FUNCTION_TOOL_SYMBOL]: true,\n };\n }\n\n if (tool.config !== undefined && tool.id !== undefined) {\n return {\n type: 'provider-defined',\n id: tool.id,\n config: tool.config,\n [TOOL_SYMBOL]: true,\n [PROVIDER_DEFINED_TOOL_SYMBOL]: true,\n };\n }\n\n throw new Error('Invalid tool');\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isTool(tool: any): tool is Tool {\n return tool && tool[TOOL_SYMBOL] === true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isFunctionTool(tool: any): tool is FunctionTool<any, any, any> {\n const isTool = tool && tool[TOOL_SYMBOL] === true;\n const isFunctionTool = tool[FUNCTION_TOOL_SYMBOL] === true;\n return isTool && isFunctionTool;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isProviderDefinedTool(tool: any): tool is ProviderDefinedTool {\n const isTool = tool && tool[TOOL_SYMBOL] === true;\n const isProviderDefinedTool = tool[PROVIDER_DEFINED_TOOL_SYMBOL] === true;\n return isTool && isProviderDefinedTool;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isToolError(error: any): error is ToolError {\n return error && error[TOOL_ERROR_SYMBOL] === true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isAgentHandoff(handoff: any): handoff is AgentHandoff {\n return handoff && handoff[HANDOFF_SYMBOL] === true;\n}\n"],"mappings":"AAIA,SAAS,WAAW,SAAS,SAAS;AAOtC,MAAM,cAAc,OAAO,MAAM;AACjC,MAAM,uBAAuB,OAAO,eAAe;AACnD,MAAM,+BAA+B,OAAO,uBAAuB;AACnE,MAAM,oBAAoB,OAAO,YAAY;AAC7C,MAAM,iBAAiB,OAAO,SAAS;AA2BhC,MAAM,kBAAkB,MAAM;AAAA,EACnC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AAEb,WAAO,eAAe,MAAM,mBAAmB;AAAA,MAC7C,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF;AAiBO,SAAS,QAAQ,SAAwD;AAC9E,SAAO;AAAA,IACL,OAAO,QAAQ;AAAA,IACf,SAAS,QAAQ;AAAA,IACjB,CAAC,cAAc,GAAG;AAAA,EACpB;AACF;AAyHO,SAAS,KAAKA,OAAgB;AACnC,MAAIA,MAAK,YAAY,QAAW;AAE9B,UAAM,aAAaA,MAAK,cAAc,EAAE,OAAO,CAAC,CAAC;AAGjD,QAAI,sBAAsB,WAAW,WAAW,KAAK,aAAa,aAAa;AAC7E,YAAM,IAAI,MAAM,6DAA6D;AAAA,IAC/E;AAEA,QAAI,EAAE,sBAAsB,cAAc,EAAE,OAAO,eAAe,WAAW;AAC3E,YAAM,IAAI,MAAM,kEAAkE;AAAA,IACpF;AAEA,WAAO;AAAA,MACL,MAAM;AAAA,MACN,aAAaA,MAAK;AAAA,MAClB;AAAA,MACA,SAASA,MAAK;AAAA,MACd,CAAC,WAAW,GAAG;AAAA,MACf,CAAC,oBAAoB,GAAG;AAAA,IAC1B;AAAA,EACF;AAEA,MAAIA,MAAK,WAAW,UAAaA,MAAK,OAAO,QAAW;AACtD,WAAO;AAAA,MACL,MAAM;AAAA,MACN,IAAIA,MAAK;AAAA,MACT,QAAQA,MAAK;AAAA,MACb,CAAC,WAAW,GAAG;AAAA,MACf,CAAC,4BAA4B,GAAG;AAAA,IAClC;AAAA,EACF;AAEA,QAAM,IAAI,MAAM,cAAc;AAChC;AAGO,SAAS,OAAOA,OAAyB;AAC9C,SAAOA,SAAQA,MAAK,WAAW,MAAM;AACvC;AAGO,SAAS,eAAeA,OAAgD;AAC7E,QAAMC,UAASD,SAAQA,MAAK,WAAW,MAAM;AAC7C,QAAME,kBAAiBF,MAAK,oBAAoB,MAAM;AACtD,SAAOC,WAAUC;AACnB;AAGO,SAAS,sBAAsBF,OAAwC;AAC5E,QAAMC,UAASD,SAAQA,MAAK,WAAW,MAAM;AAC7C,QAAMG,yBAAwBH,MAAK,4BAA4B,MAAM;AACrE,SAAOC,WAAUE;AACnB;AAGO,SAAS,YAAY,OAAgC;AAC1D,SAAO,SAAS,MAAM,iBAAiB,MAAM;AAC/C;AAGO,SAAS,eAAeC,UAAuC;AACpE,SAAOA,YAAWA,SAAQ,cAAc,MAAM;AAChD;","names":["tool","isTool","isFunctionTool","isProviderDefinedTool","handoff"]}
|
|
1
|
+
{"version":3,"sources":["../../src/llm/tool_context.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { JSONSchema7 } from 'json-schema';\nimport { z } from 'zod';\nimport type { Agent } from '../voice/agent.js';\nimport type { RunContext, UnknownUserData } from '../voice/run_context.js';\nimport { isZodObjectSchema, isZodSchema } from './zod-utils.js';\n\n// heavily inspired by Vercel AI's `tool()`:\n// https://github.com/vercel/ai/blob/3b0983b/packages/ai/core/tool/tool.ts\n\nconst TOOL_SYMBOL = Symbol('tool');\nconst FUNCTION_TOOL_SYMBOL = Symbol('function_tool');\nconst PROVIDER_DEFINED_TOOL_SYMBOL = Symbol('provider_defined_tool');\nconst TOOL_ERROR_SYMBOL = Symbol('tool_error');\nconst HANDOFF_SYMBOL = Symbol('handoff');\n\nexport type JSONValue = null | string | number | boolean | JSONObject | JSONArray;\n\nexport type JSONArray = JSONValue[];\n\nexport type JSONObject = {\n [key: string]: JSONValue;\n};\n\n// Supports both Zod v3 and v4 schemas, as well as raw JSON schema\n// Adapted from Vercel AI SDK's FlexibleSchema approach\n// Source: https://github.com/vercel/ai/blob/main/packages/provider-utils/src/schema.ts#L67-L70\n//\n// Vercel uses StandardSchemaV1 from @standard-schema/spec package.\n// We use a simpler approach by directly checking for schema properties:\n// - Zod v3: Has `_output` property\n// - Zod v4: Implements Standard Schema spec with `~standard` property\n// - JSON Schema: Plain object fallback\nexport type ToolInputSchema<T = JSONObject> =\n | {\n // Zod v3 schema - has _output property for type inference\n _output: T;\n }\n | {\n // Zod v4 schema (Standard Schema) - has ~standard property\n '~standard': {\n types?: { output: T };\n };\n }\n | JSONSchema7;\n\n/**\n * Infer the output type from a ToolInputSchema.\n * Adapted from Vercel AI SDK's InferSchema type.\n * Source: https://github.com/vercel/ai/blob/main/packages/provider-utils/src/schema.ts#L72-L79\n */\nexport type InferToolInput<T> = T extends { _output: infer O }\n ? O\n : T extends { '~standard': { types?: { output: infer O } } }\n ? O\n : any; // eslint-disable-line @typescript-eslint/no-explicit-any -- Fallback type for JSON Schema objects without type inference\n\nexport type ToolType = 'function' | 'provider-defined';\n\nexport type ToolChoice =\n | 'auto'\n | 'none'\n | 'required'\n | {\n type: 'function';\n function: {\n name: string;\n };\n };\n\nexport class ToolError extends Error {\n constructor(message: string) {\n super(message);\n\n Object.defineProperty(this, TOOL_ERROR_SYMBOL, {\n value: true,\n });\n }\n}\n\nexport interface AgentHandoff {\n /**\n * The agent to handoff to.\n */\n agent: Agent;\n\n /**\n * The return value of the tool.\n */\n returns?: any; // eslint-disable-line @typescript-eslint/no-explicit-any\n\n [HANDOFF_SYMBOL]: true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function handoff(options: { agent: Agent; returns?: any }): AgentHandoff {\n return {\n agent: options.agent,\n returns: options.returns,\n [HANDOFF_SYMBOL]: true,\n };\n}\n\nexport interface ToolOptions<UserData = UnknownUserData> {\n /**\n * RunContext for the current agent session.\n */\n ctx: RunContext<UserData>;\n\n /**\n * The ID of the tool call.\n */\n toolCallId: string;\n\n /**\n * An optional abort signal that indicates that the overall operation should be aborted.\n */\n abortSignal?: AbortSignal;\n}\n\nexport type ToolExecuteFunction<\n Parameters extends JSONObject,\n UserData = UnknownUserData,\n Result = unknown,\n> = (args: Parameters, opts: ToolOptions<UserData>) => Promise<Result>;\n\nexport interface Tool {\n /**\n * The type of the tool.\n * @internal Either user-defined core tool or provider-defined tool.\n */\n type: ToolType;\n\n [TOOL_SYMBOL]: true;\n}\n\n// TODO(AJS-112): support provider-defined tools\nexport interface ProviderDefinedTool extends Tool {\n type: 'provider-defined';\n\n /**\n * The ID of the tool.\n */\n id: string;\n\n /**\n * The configuration of the tool.\n */\n config: Record<string, unknown>;\n\n [PROVIDER_DEFINED_TOOL_SYMBOL]: true;\n}\n\nexport interface FunctionTool<\n Parameters extends JSONObject,\n UserData = UnknownUserData,\n Result = unknown,\n> extends Tool {\n type: 'function';\n\n /**\n * The description of the tool. Will be used by the language model to decide whether to use the tool.\n */\n description: string;\n\n /**\n * The schema of the input that the tool expects. The language model will use this to generate the input.\n * It is also used to validate the output of the language model.\n * Use descriptions to make the input understandable for the language model.\n */\n parameters: ToolInputSchema<Parameters>;\n\n /**\n * An async function that is called with the arguments from the tool call and produces a result.\n * It also carries context about current session, user-defined data, and the tool call id, etc.\n */\n execute: ToolExecuteFunction<Parameters, UserData, Result>;\n\n [FUNCTION_TOOL_SYMBOL]: true;\n}\n\n// TODO(AJS-112): support provider-defined tools in the future)\nexport type ToolContext<UserData = UnknownUserData> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Generic tool registry needs to accept any parameter/result types\n [name: string]: FunctionTool<any, UserData, any>;\n};\n\n/**\n * Create a function tool with inferred parameters from the schema.\n */\nexport function tool<\n Schema extends ToolInputSchema<any>, // eslint-disable-line @typescript-eslint/no-explicit-any -- Generic constraint needs to accept any JSONObject type\n UserData = UnknownUserData,\n Result = unknown,\n>({\n description,\n parameters,\n execute,\n}: {\n description: string;\n parameters: Schema;\n execute: ToolExecuteFunction<InferToolInput<Schema>, UserData, Result>;\n}): FunctionTool<InferToolInput<Schema>, UserData, Result>;\n\n/**\n * Create a function tool without parameters.\n */\nexport function tool<UserData = UnknownUserData, Result = unknown>({\n description,\n execute,\n}: {\n description: string;\n parameters?: never;\n execute: ToolExecuteFunction<Record<string, never>, UserData, Result>;\n}): FunctionTool<Record<string, never>, UserData, Result>;\n\n/**\n * Create a provider-defined tool.\n *\n * @param id - The ID of the tool.\n * @param config - The configuration of the tool.\n */\nexport function tool({\n id,\n config,\n}: {\n id: string;\n config: Record<string, unknown>;\n}): ProviderDefinedTool;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function tool(tool: any): any {\n if (tool.execute !== undefined) {\n // Default parameters to z.object({}) if not provided\n const parameters = tool.parameters ?? z.object({});\n\n // if parameters is a Zod schema, ensure it's an object schema\n if (isZodSchema(parameters) && !isZodObjectSchema(parameters)) {\n throw new Error('Tool parameters must be a Zod object schema (z.object(...))');\n }\n\n // Ensure parameters is either a Zod schema or a plain object (JSON schema)\n if (!isZodSchema(parameters) && !(typeof parameters === 'object')) {\n throw new Error('Tool parameters must be a Zod object schema or a raw JSON schema');\n }\n\n return {\n type: 'function',\n description: tool.description,\n parameters,\n execute: tool.execute,\n [TOOL_SYMBOL]: true,\n [FUNCTION_TOOL_SYMBOL]: true,\n };\n }\n\n if (tool.config !== undefined && tool.id !== undefined) {\n return {\n type: 'provider-defined',\n id: tool.id,\n config: tool.config,\n [TOOL_SYMBOL]: true,\n [PROVIDER_DEFINED_TOOL_SYMBOL]: true,\n };\n }\n\n throw new Error('Invalid tool');\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isTool(tool: any): tool is Tool {\n return tool && tool[TOOL_SYMBOL] === true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isFunctionTool(tool: any): tool is FunctionTool<any, any, any> {\n const isTool = tool && tool[TOOL_SYMBOL] === true;\n const isFunctionTool = tool[FUNCTION_TOOL_SYMBOL] === true;\n return isTool && isFunctionTool;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isProviderDefinedTool(tool: any): tool is ProviderDefinedTool {\n const isTool = tool && tool[TOOL_SYMBOL] === true;\n const isProviderDefinedTool = tool[PROVIDER_DEFINED_TOOL_SYMBOL] === true;\n return isTool && isProviderDefinedTool;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isToolError(error: any): error is ToolError {\n return error && error[TOOL_ERROR_SYMBOL] === true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isAgentHandoff(handoff: any): handoff is AgentHandoff {\n return handoff && handoff[HANDOFF_SYMBOL] === true;\n}\n"],"mappings":"AAIA,SAAS,SAAS;AAGlB,SAAS,mBAAmB,mBAAmB;AAK/C,MAAM,cAAc,OAAO,MAAM;AACjC,MAAM,uBAAuB,OAAO,eAAe;AACnD,MAAM,+BAA+B,OAAO,uBAAuB;AACnE,MAAM,oBAAoB,OAAO,YAAY;AAC7C,MAAM,iBAAiB,OAAO,SAAS;AAwDhC,MAAM,kBAAkB,MAAM;AAAA,EACnC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AAEb,WAAO,eAAe,MAAM,mBAAmB;AAAA,MAC7C,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF;AAiBO,SAAS,QAAQ,SAAwD;AAC9E,SAAO;AAAA,IACL,OAAO,QAAQ;AAAA,IACf,SAAS,QAAQ;AAAA,IACjB,CAAC,cAAc,GAAG;AAAA,EACpB;AACF;AAkIO,SAAS,KAAKA,OAAgB;AACnC,MAAIA,MAAK,YAAY,QAAW;AAE9B,UAAM,aAAaA,MAAK,cAAc,EAAE,OAAO,CAAC,CAAC;AAGjD,QAAI,YAAY,UAAU,KAAK,CAAC,kBAAkB,UAAU,GAAG;AAC7D,YAAM,IAAI,MAAM,6DAA6D;AAAA,IAC/E;AAGA,QAAI,CAAC,YAAY,UAAU,KAAK,EAAE,OAAO,eAAe,WAAW;AACjE,YAAM,IAAI,MAAM,kEAAkE;AAAA,IACpF;AAEA,WAAO;AAAA,MACL,MAAM;AAAA,MACN,aAAaA,MAAK;AAAA,MAClB;AAAA,MACA,SAASA,MAAK;AAAA,MACd,CAAC,WAAW,GAAG;AAAA,MACf,CAAC,oBAAoB,GAAG;AAAA,IAC1B;AAAA,EACF;AAEA,MAAIA,MAAK,WAAW,UAAaA,MAAK,OAAO,QAAW;AACtD,WAAO;AAAA,MACL,MAAM;AAAA,MACN,IAAIA,MAAK;AAAA,MACT,QAAQA,MAAK;AAAA,MACb,CAAC,WAAW,GAAG;AAAA,MACf,CAAC,4BAA4B,GAAG;AAAA,IAClC;AAAA,EACF;AAEA,QAAM,IAAI,MAAM,cAAc;AAChC;AAGO,SAAS,OAAOA,OAAyB;AAC9C,SAAOA,SAAQA,MAAK,WAAW,MAAM;AACvC;AAGO,SAAS,eAAeA,OAAgD;AAC7E,QAAMC,UAASD,SAAQA,MAAK,WAAW,MAAM;AAC7C,QAAME,kBAAiBF,MAAK,oBAAoB,MAAM;AACtD,SAAOC,WAAUC;AACnB;AAGO,SAAS,sBAAsBF,OAAwC;AAC5E,QAAMC,UAASD,SAAQA,MAAK,WAAW,MAAM;AAC7C,QAAMG,yBAAwBH,MAAK,4BAA4B,MAAM;AACrE,SAAOC,WAAUE;AACnB;AAGO,SAAS,YAAY,OAAgC;AAC1D,SAAO,SAAS,MAAM,iBAAiB,MAAM;AAC/C;AAGO,SAAS,eAAeC,UAAuC;AACpE,SAAOA,YAAWA,SAAQ,cAAc,MAAM;AAChD;","names":["tool","isTool","isFunctionTool","isProviderDefinedTool","handoff"]}
|
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
2
24
|
var import_vitest = require("vitest");
|
|
3
25
|
var import_zod = require("zod");
|
|
26
|
+
var z3 = __toESM(require("zod/v3"), 1);
|
|
27
|
+
var z4 = __toESM(require("zod/v4"), 1);
|
|
4
28
|
var import_tool_context = require("./tool_context.cjs");
|
|
5
29
|
var import_utils = require("./utils.cjs");
|
|
6
30
|
(0, import_vitest.describe)("Tool Context", () => {
|
|
@@ -136,6 +160,31 @@ var import_utils = require("./utils.cjs");
|
|
|
136
160
|
const result = await simpleAction.execute({}, (0, import_utils.createToolOptions)("123"));
|
|
137
161
|
(0, import_vitest.expect)(result).toBe("Action performed");
|
|
138
162
|
});
|
|
163
|
+
(0, import_vitest.it)("should support .optional() fields in tool parameters", async () => {
|
|
164
|
+
const weatherTool = (0, import_tool_context.tool)({
|
|
165
|
+
description: "Get weather information",
|
|
166
|
+
parameters: import_zod.z.object({
|
|
167
|
+
location: import_zod.z.string().describe("The city or location").optional(),
|
|
168
|
+
units: import_zod.z.enum(["celsius", "fahrenheit"]).describe("Temperature units").optional()
|
|
169
|
+
}),
|
|
170
|
+
execute: async ({ location, units }) => {
|
|
171
|
+
const loc = location ?? "Unknown";
|
|
172
|
+
const unit = units ?? "celsius";
|
|
173
|
+
return `Weather in ${loc} (${unit})`;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
(0, import_vitest.expect)(weatherTool.type).toBe("function");
|
|
177
|
+
(0, import_vitest.expect)(weatherTool.description).toBe("Get weather information");
|
|
178
|
+
const result1 = await weatherTool.execute(
|
|
179
|
+
{ location: "London", units: "celsius" },
|
|
180
|
+
(0, import_utils.createToolOptions)("123")
|
|
181
|
+
);
|
|
182
|
+
(0, import_vitest.expect)(result1).toBe("Weather in London (celsius)");
|
|
183
|
+
const result2 = await weatherTool.execute({}, (0, import_utils.createToolOptions)("123"));
|
|
184
|
+
(0, import_vitest.expect)(result2).toBe("Weather in Unknown (celsius)");
|
|
185
|
+
const result3 = await weatherTool.execute({ location: "Paris" }, (0, import_utils.createToolOptions)("123"));
|
|
186
|
+
(0, import_vitest.expect)(result3).toBe("Weather in Paris (celsius)");
|
|
187
|
+
});
|
|
139
188
|
(0, import_vitest.it)("should handle tools with context but no parameters", async () => {
|
|
140
189
|
const greetUser = (0, import_tool_context.tool)({
|
|
141
190
|
description: "Greet the current user",
|
|
@@ -157,6 +206,154 @@ var import_utils = require("./utils.cjs");
|
|
|
157
206
|
(0, import_vitest.expect)(result).toBe("Tool call ID: test-id-456");
|
|
158
207
|
});
|
|
159
208
|
});
|
|
209
|
+
(0, import_vitest.describe)("Zod v3 and v4 compatibility", () => {
|
|
210
|
+
(0, import_vitest.it)("should work with Zod v3 schemas", async () => {
|
|
211
|
+
const v3Tool = (0, import_tool_context.tool)({
|
|
212
|
+
description: "A tool using Zod v3 schema",
|
|
213
|
+
parameters: z3.object({
|
|
214
|
+
name: z3.string(),
|
|
215
|
+
count: z3.number()
|
|
216
|
+
}),
|
|
217
|
+
execute: async ({ name, count }) => {
|
|
218
|
+
return `${name}: ${count}`;
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
const result = await v3Tool.execute(
|
|
222
|
+
{ name: "Test", count: 42 },
|
|
223
|
+
(0, import_utils.createToolOptions)("v3-test")
|
|
224
|
+
);
|
|
225
|
+
(0, import_vitest.expect)(result).toBe("Test: 42");
|
|
226
|
+
});
|
|
227
|
+
(0, import_vitest.it)("should work with Zod v4 schemas", async () => {
|
|
228
|
+
const v4Tool = (0, import_tool_context.tool)({
|
|
229
|
+
description: "A tool using Zod v4 schema",
|
|
230
|
+
parameters: z4.object({
|
|
231
|
+
name: z4.string(),
|
|
232
|
+
count: z4.number()
|
|
233
|
+
}),
|
|
234
|
+
execute: async ({ name, count }) => {
|
|
235
|
+
return `${name}: ${count}`;
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
const result = await v4Tool.execute(
|
|
239
|
+
{ name: "Test", count: 42 },
|
|
240
|
+
(0, import_utils.createToolOptions)("v4-test")
|
|
241
|
+
);
|
|
242
|
+
(0, import_vitest.expect)(result).toBe("Test: 42");
|
|
243
|
+
});
|
|
244
|
+
(0, import_vitest.it)("should handle v4 schemas with optional fields", async () => {
|
|
245
|
+
const v4Tool = (0, import_tool_context.tool)({
|
|
246
|
+
description: "Tool with optional field using v4",
|
|
247
|
+
parameters: z4.object({
|
|
248
|
+
required: z4.string(),
|
|
249
|
+
optional: z4.string().optional()
|
|
250
|
+
}),
|
|
251
|
+
execute: async ({ required, optional }) => {
|
|
252
|
+
return optional ? `${required} - ${optional}` : required;
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
const result1 = await v4Tool.execute({ required: "Hello" }, (0, import_utils.createToolOptions)("test-1"));
|
|
256
|
+
(0, import_vitest.expect)(result1).toBe("Hello");
|
|
257
|
+
const result2 = await v4Tool.execute(
|
|
258
|
+
{ required: "Hello", optional: "World" },
|
|
259
|
+
(0, import_utils.createToolOptions)("test-2")
|
|
260
|
+
);
|
|
261
|
+
(0, import_vitest.expect)(result2).toBe("Hello - World");
|
|
262
|
+
});
|
|
263
|
+
(0, import_vitest.it)("should handle v4 enum schemas", async () => {
|
|
264
|
+
const v4Tool = (0, import_tool_context.tool)({
|
|
265
|
+
description: "Tool with enum using v4",
|
|
266
|
+
parameters: z4.object({
|
|
267
|
+
color: z4.enum(["red", "blue", "green"])
|
|
268
|
+
}),
|
|
269
|
+
execute: async ({ color }) => {
|
|
270
|
+
return `Selected color: ${color}`;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
const result = await v4Tool.execute({ color: "blue" }, (0, import_utils.createToolOptions)("test-enum"));
|
|
274
|
+
(0, import_vitest.expect)(result).toBe("Selected color: blue");
|
|
275
|
+
});
|
|
276
|
+
(0, import_vitest.it)("should handle v4 array schemas", async () => {
|
|
277
|
+
const v4Tool = (0, import_tool_context.tool)({
|
|
278
|
+
description: "Tool with array using v4",
|
|
279
|
+
parameters: z4.object({
|
|
280
|
+
tags: z4.array(z4.string())
|
|
281
|
+
}),
|
|
282
|
+
execute: async ({ tags }) => {
|
|
283
|
+
return `Tags: ${tags.join(", ")}`;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
const result = await v4Tool.execute(
|
|
287
|
+
{ tags: ["nodejs", "typescript", "testing"] },
|
|
288
|
+
(0, import_utils.createToolOptions)("test-array")
|
|
289
|
+
);
|
|
290
|
+
(0, import_vitest.expect)(result).toBe("Tags: nodejs, typescript, testing");
|
|
291
|
+
});
|
|
292
|
+
(0, import_vitest.it)("should handle v4 nested object schemas", async () => {
|
|
293
|
+
const v4Tool = (0, import_tool_context.tool)({
|
|
294
|
+
description: "Tool with nested object using v4",
|
|
295
|
+
parameters: z4.object({
|
|
296
|
+
user: z4.object({
|
|
297
|
+
name: z4.string(),
|
|
298
|
+
email: z4.string()
|
|
299
|
+
})
|
|
300
|
+
}),
|
|
301
|
+
execute: async ({ user }) => {
|
|
302
|
+
return `${user.name} (${user.email})`;
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
const result = await v4Tool.execute(
|
|
306
|
+
{ user: { name: "John Doe", email: "john@example.com" } },
|
|
307
|
+
(0, import_utils.createToolOptions)("test-nested")
|
|
308
|
+
);
|
|
309
|
+
(0, import_vitest.expect)(result).toBe("John Doe (john@example.com)");
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
(0, import_vitest.describe)("oaiParams with v4 schemas", () => {
|
|
313
|
+
(0, import_vitest.it)("should convert v4 basic object schema", () => {
|
|
314
|
+
const schema = z4.object({
|
|
315
|
+
name: z4.string().describe("User name"),
|
|
316
|
+
age: z4.number().describe("User age")
|
|
317
|
+
});
|
|
318
|
+
const result = (0, import_utils.oaiParams)(schema);
|
|
319
|
+
(0, import_vitest.expect)(result.type).toBe("object");
|
|
320
|
+
(0, import_vitest.expect)(result.properties).toHaveProperty("name");
|
|
321
|
+
(0, import_vitest.expect)(result.properties).toHaveProperty("age");
|
|
322
|
+
(0, import_vitest.expect)(result.required).toContain("name");
|
|
323
|
+
(0, import_vitest.expect)(result.required).toContain("age");
|
|
324
|
+
});
|
|
325
|
+
(0, import_vitest.it)("should handle v4 optional fields", () => {
|
|
326
|
+
const schema = z4.object({
|
|
327
|
+
required: z4.string(),
|
|
328
|
+
optional: z4.string().optional()
|
|
329
|
+
});
|
|
330
|
+
const result = (0, import_utils.oaiParams)(schema);
|
|
331
|
+
(0, import_vitest.expect)(result.required).toContain("required");
|
|
332
|
+
(0, import_vitest.expect)(result.required).not.toContain("optional");
|
|
333
|
+
});
|
|
334
|
+
(0, import_vitest.it)("should handle v4 enum fields", () => {
|
|
335
|
+
var _a;
|
|
336
|
+
const schema = z4.object({
|
|
337
|
+
status: z4.enum(["pending", "approved", "rejected"])
|
|
338
|
+
});
|
|
339
|
+
const result = (0, import_utils.oaiParams)(schema);
|
|
340
|
+
const properties = result.properties;
|
|
341
|
+
(0, import_vitest.expect)((_a = properties.status) == null ? void 0 : _a.enum).toEqual(["pending", "approved", "rejected"]);
|
|
342
|
+
});
|
|
343
|
+
(0, import_vitest.it)("should handle v4 array fields", () => {
|
|
344
|
+
const schema = z4.object({
|
|
345
|
+
items: z4.array(z4.string())
|
|
346
|
+
});
|
|
347
|
+
const result = (0, import_utils.oaiParams)(schema);
|
|
348
|
+
const properties = result.properties;
|
|
349
|
+
(0, import_vitest.expect)(
|
|
350
|
+
properties.items && typeof properties.items === "object" ? properties.items.type : void 0
|
|
351
|
+
).toBe("array");
|
|
352
|
+
(0, import_vitest.expect)(
|
|
353
|
+
properties.items && properties.items.items && typeof properties.items.items === "object" ? properties.items.items.type : void 0
|
|
354
|
+
).toBe("string");
|
|
355
|
+
});
|
|
356
|
+
});
|
|
160
357
|
});
|
|
161
358
|
});
|
|
162
359
|
//# sourceMappingURL=tool_context.test.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/llm/tool_context.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { describe, expect, it } from 'vitest';\nimport { z } from 'zod';\nimport { type ToolOptions, tool } from './tool_context.js';\nimport { createToolOptions, oaiParams } from './utils.js';\n\ndescribe('Tool Context', () => {\n describe('oaiParams', () => {\n it('should handle basic object schema', () => {\n const schema = z.object({\n name: z.string().describe('The user name'),\n age: z.number().describe('The user age'),\n });\n\n const result = oaiParams(schema);\n\n expect(result).toMatchSnapshot();\n });\n\n it('should handle enum fields', () => {\n const schema = z.object({\n color: z.enum(['red', 'blue', 'green']).describe('Choose a color'),\n });\n\n const result = oaiParams(schema);\n\n expect(result).toMatchSnapshot();\n });\n\n it('should handle array fields', () => {\n const schema = z.object({\n tags: z.array(z.string()).describe('List of tags'),\n });\n\n const result = oaiParams(schema);\n\n expect(result).toMatchSnapshot();\n });\n\n it('should handle array of enums', () => {\n const schema = z.object({\n colors: z.array(z.enum(['red', 'blue', 'green'])).describe('List of colors'),\n });\n\n const result = oaiParams(schema);\n\n expect(result).toMatchSnapshot();\n });\n\n it('should handle optional fields', () => {\n const schema = z.object({\n name: z.string().describe('The user name'),\n age: z.number().optional().describe('The user age'),\n });\n\n const result = oaiParams(schema);\n\n expect(result).toMatchSnapshot();\n });\n\n it('should handle fields without descriptions', () => {\n const schema = z.object({\n name: z.string(),\n age: z.number(),\n });\n\n const result = oaiParams(schema);\n\n expect(result).toMatchSnapshot();\n });\n });\n\n describe('tool', () => {\n it('should create and execute a basic core tool', async () => {\n const getWeather = tool({\n description: 'Get the weather for a given location',\n parameters: z.object({\n location: z.string(),\n }),\n execute: async ({ location }, { ctx }: ToolOptions<{ name: string }>) => {\n return `The weather in ${location} is sunny, ${ctx.userData.name}`;\n },\n });\n\n const result = await getWeather.execute(\n { location: 'San Francisco' },\n createToolOptions('123', { name: 'John' }),\n );\n expect(result).toBe('The weather in San Francisco is sunny, John');\n });\n\n it('should properly type a callable function', async () => {\n const testFunction = tool({\n description: 'Test function',\n parameters: z.object({\n name: z.string().describe('The user name'),\n age: z.number().describe('The user age'),\n }),\n execute: async (args) => {\n return `${args.name} is ${args.age} years old`;\n },\n });\n\n const result = await testFunction.execute(\n { name: 'John', age: 30 },\n createToolOptions('123'),\n );\n expect(result).toBe('John is 30 years old');\n });\n\n it('should handle async execution', async () => {\n const testFunction = tool({\n description: 'Async test function',\n parameters: z.object({\n delay: z.number().describe('Delay in milliseconds'),\n }),\n execute: async (args) => {\n await new Promise((resolve) => setTimeout(resolve, args.delay));\n return args.delay;\n },\n });\n\n const start = Date.now();\n const result = await testFunction.execute({ delay: 100 }, createToolOptions('123'));\n const duration = Date.now() - start;\n\n expect(result).toBe(100);\n expect(duration).toBeGreaterThanOrEqual(95); // Allow for small timing variations\n });\n\n describe('nested array support', () => {\n it('should handle nested array fields', () => {\n const schema = z.object({\n items: z.array(\n z.object({\n name: z.string().describe('the item name'),\n modifiers: z\n .array(\n z.object({\n modifier_name: z.string(),\n modifier_value: z.string(),\n }),\n )\n .describe('list of the modifiers applied on this item, such as size'),\n }),\n ),\n });\n const result = oaiParams(schema);\n expect(result).toMatchSnapshot();\n });\n });\n\n describe('optional parameters', () => {\n it('should create a tool without parameters', async () => {\n const simpleAction = tool({\n description: 'Perform a simple action',\n execute: async () => {\n return 'Action performed';\n },\n });\n\n expect(simpleAction.type).toBe('function');\n expect(simpleAction.description).toBe('Perform a simple action');\n expect(simpleAction.parameters).toBeDefined();\n expect(simpleAction.parameters._def.typeName).toBe('ZodObject');\n\n const result = await simpleAction.execute({}, createToolOptions('123'));\n expect(result).toBe('Action performed');\n });\n\n it('should handle tools with context but no parameters', async () => {\n const greetUser = tool({\n description: 'Greet the current user',\n execute: async (_, { ctx }: ToolOptions<{ username: string }>) => {\n return `Hello, ${ctx.userData.username}!`;\n },\n });\n\n const result = await greetUser.execute({}, createToolOptions('123', { username: 'Alice' }));\n expect(result).toBe('Hello, Alice!');\n });\n\n it('should create a tool that accesses tool call id without parameters', async () => {\n const getCallId = tool({\n description: 'Get the current tool call ID',\n execute: async (_, { toolCallId }) => {\n return `Tool call ID: ${toolCallId}`;\n },\n });\n\n const result = await getCallId.execute({}, createToolOptions('test-id-456'));\n expect(result).toBe('Tool call ID: test-id-456');\n });\n });\n });\n});\n"],"mappings":";AAGA,oBAAqC;AACrC,iBAAkB;AAClB,0BAAuC;AACvC,mBAA6C;AAAA,IAE7C,wBAAS,gBAAgB,MAAM;AAC7B,8BAAS,aAAa,MAAM;AAC1B,0BAAG,qCAAqC,MAAM;AAC5C,YAAM,SAAS,aAAE,OAAO;AAAA,QACtB,MAAM,aAAE,OAAO,EAAE,SAAS,eAAe;AAAA,QACzC,KAAK,aAAE,OAAO,EAAE,SAAS,cAAc;AAAA,MACzC,CAAC;AAED,YAAM,aAAS,wBAAU,MAAM;AAE/B,gCAAO,MAAM,E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B,KAAK,CAAC;AACtE,kCAAO,MAAM,EAAE,KAAK,kBAAkB;AAAA,MACxC,CAAC;AAED,4BAAG,sDAAsD,YAAY;AACnE,cAAM,gBAAY,0BAAK;AAAA,UACrB,aAAa;AAAA,UACb,SAAS,OAAO,GAAG,EAAE,IAAI,MAAyC;AAChE,mBAAO,UAAU,IAAI,SAAS,QAAQ;AAAA,UACxC;AAAA,QACF,CAAC;AAED,cAAM,SAAS,MAAM,UAAU,QAAQ,CAAC,OAAG,gCAAkB,OAAO,EAAE,UAAU,QAAQ,CAAC,CAAC;AAC1F,kCAAO,MAAM,EAAE,KAAK,eAAe;AAAA,MACrC,CAAC;AAED,4BAAG,sEAAsE,YAAY;AACnF,cAAM,gBAAY,0BAAK;AAAA,UACrB,aAAa;AAAA,UACb,SAAS,OAAO,GAAG,EAAE,WAAW,MAAM;AACpC,mBAAO,iBAAiB,UAAU;AAAA,UACpC;AAAA,QACF,CAAC;AAED,cAAM,SAAS,MAAM,UAAU,QAAQ,CAAC,OAAG,gCAAkB,aAAa,CAAC;AAC3E,kCAAO,MAAM,EAAE,KAAK,2BAA2B;AAAA,MACjD,CAAC;AAAA,IACH,CAAC;AAAA,EACH,CAAC;AACH,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/llm/tool_context.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { describe, expect, it } from 'vitest';\nimport { z } from 'zod';\nimport * as z3 from 'zod/v3';\nimport * as z4 from 'zod/v4';\nimport { type ToolOptions, tool } from './tool_context.js';\nimport { createToolOptions, oaiParams } from './utils.js';\n\ndescribe('Tool Context', () => {\n describe('oaiParams', () => {\n it('should handle basic object schema', () => {\n const schema = z.object({\n name: z.string().describe('The user name'),\n age: z.number().describe('The user age'),\n });\n\n const result = oaiParams(schema);\n\n expect(result).toMatchSnapshot();\n });\n\n it('should handle enum fields', () => {\n const schema = z.object({\n color: z.enum(['red', 'blue', 'green']).describe('Choose a color'),\n });\n\n const result = oaiParams(schema);\n\n expect(result).toMatchSnapshot();\n });\n\n it('should handle array fields', () => {\n const schema = z.object({\n tags: z.array(z.string()).describe('List of tags'),\n });\n\n const result = oaiParams(schema);\n\n expect(result).toMatchSnapshot();\n });\n\n it('should handle array of enums', () => {\n const schema = z.object({\n colors: z.array(z.enum(['red', 'blue', 'green'])).describe('List of colors'),\n });\n\n const result = oaiParams(schema);\n\n expect(result).toMatchSnapshot();\n });\n\n it('should handle optional fields', () => {\n const schema = z.object({\n name: z.string().describe('The user name'),\n age: z.number().optional().describe('The user age'),\n });\n\n const result = oaiParams(schema);\n\n expect(result).toMatchSnapshot();\n });\n\n it('should handle fields without descriptions', () => {\n const schema = z.object({\n name: z.string(),\n age: z.number(),\n });\n\n const result = oaiParams(schema);\n\n expect(result).toMatchSnapshot();\n });\n });\n\n describe('tool', () => {\n it('should create and execute a basic core tool', async () => {\n const getWeather = tool({\n description: 'Get the weather for a given location',\n parameters: z.object({\n location: z.string(),\n }),\n execute: async ({ location }, { ctx }: ToolOptions<{ name: string }>) => {\n return `The weather in ${location} is sunny, ${ctx.userData.name}`;\n },\n });\n\n const result = await getWeather.execute(\n { location: 'San Francisco' },\n createToolOptions('123', { name: 'John' }),\n );\n expect(result).toBe('The weather in San Francisco is sunny, John');\n });\n\n it('should properly type a callable function', async () => {\n const testFunction = tool({\n description: 'Test function',\n parameters: z.object({\n name: z.string().describe('The user name'),\n age: z.number().describe('The user age'),\n }),\n execute: async (args) => {\n return `${args.name} is ${args.age} years old`;\n },\n });\n\n const result = await testFunction.execute(\n { name: 'John', age: 30 },\n createToolOptions('123'),\n );\n expect(result).toBe('John is 30 years old');\n });\n\n it('should handle async execution', async () => {\n const testFunction = tool({\n description: 'Async test function',\n parameters: z.object({\n delay: z.number().describe('Delay in milliseconds'),\n }),\n execute: async (args) => {\n await new Promise((resolve) => setTimeout(resolve, args.delay));\n return args.delay;\n },\n });\n\n const start = Date.now();\n const result = await testFunction.execute({ delay: 100 }, createToolOptions('123'));\n const duration = Date.now() - start;\n\n expect(result).toBe(100);\n expect(duration).toBeGreaterThanOrEqual(95); // Allow for small timing variations\n });\n\n describe('nested array support', () => {\n it('should handle nested array fields', () => {\n const schema = z.object({\n items: z.array(\n z.object({\n name: z.string().describe('the item name'),\n modifiers: z\n .array(\n z.object({\n modifier_name: z.string(),\n modifier_value: z.string(),\n }),\n )\n .describe('list of the modifiers applied on this item, such as size'),\n }),\n ),\n });\n const result = oaiParams(schema);\n expect(result).toMatchSnapshot();\n });\n });\n\n describe('optional parameters', () => {\n it('should create a tool without parameters', async () => {\n const simpleAction = tool({\n description: 'Perform a simple action',\n execute: async () => {\n return 'Action performed';\n },\n });\n\n expect(simpleAction.type).toBe('function');\n expect(simpleAction.description).toBe('Perform a simple action');\n expect(simpleAction.parameters).toBeDefined();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n expect((simpleAction.parameters as any)._def.typeName).toBe('ZodObject');\n\n const result = await simpleAction.execute({}, createToolOptions('123'));\n expect(result).toBe('Action performed');\n });\n\n it('should support .optional() fields in tool parameters', async () => {\n const weatherTool = tool({\n description: 'Get weather information',\n parameters: z.object({\n location: z.string().describe('The city or location').optional(),\n units: z.enum(['celsius', 'fahrenheit']).describe('Temperature units').optional(),\n }),\n execute: async ({ location, units }) => {\n const loc = location ?? 'Unknown';\n const unit = units ?? 'celsius';\n return `Weather in ${loc} (${unit})`;\n },\n });\n\n expect(weatherTool.type).toBe('function');\n expect(weatherTool.description).toBe('Get weather information');\n\n const result1 = await weatherTool.execute(\n { location: 'London', units: 'celsius' },\n createToolOptions('123'),\n );\n expect(result1).toBe('Weather in London (celsius)');\n\n const result2 = await weatherTool.execute({}, createToolOptions('123'));\n expect(result2).toBe('Weather in Unknown (celsius)');\n\n const result3 = await weatherTool.execute({ location: 'Paris' }, createToolOptions('123'));\n expect(result3).toBe('Weather in Paris (celsius)');\n });\n\n it('should handle tools with context but no parameters', async () => {\n const greetUser = tool({\n description: 'Greet the current user',\n execute: async (_, { ctx }: ToolOptions<{ username: string }>) => {\n return `Hello, ${ctx.userData.username}!`;\n },\n });\n\n const result = await greetUser.execute({}, createToolOptions('123', { username: 'Alice' }));\n expect(result).toBe('Hello, Alice!');\n });\n\n it('should create a tool that accesses tool call id without parameters', async () => {\n const getCallId = tool({\n description: 'Get the current tool call ID',\n execute: async (_, { toolCallId }) => {\n return `Tool call ID: ${toolCallId}`;\n },\n });\n\n const result = await getCallId.execute({}, createToolOptions('test-id-456'));\n expect(result).toBe('Tool call ID: test-id-456');\n });\n });\n\n describe('Zod v3 and v4 compatibility', () => {\n it('should work with Zod v3 schemas', async () => {\n const v3Tool = tool({\n description: 'A tool using Zod v3 schema',\n parameters: z3.object({\n name: z3.string(),\n count: z3.number(),\n }),\n execute: async ({ name, count }) => {\n return `${name}: ${count}`;\n },\n });\n\n const result = await v3Tool.execute(\n { name: 'Test', count: 42 },\n createToolOptions('v3-test'),\n );\n expect(result).toBe('Test: 42');\n });\n\n it('should work with Zod v4 schemas', async () => {\n const v4Tool = tool({\n description: 'A tool using Zod v4 schema',\n parameters: z4.object({\n name: z4.string(),\n count: z4.number(),\n }),\n execute: async ({ name, count }) => {\n return `${name}: ${count}`;\n },\n });\n\n const result = await v4Tool.execute(\n { name: 'Test', count: 42 },\n createToolOptions('v4-test'),\n );\n expect(result).toBe('Test: 42');\n });\n\n it('should handle v4 schemas with optional fields', async () => {\n const v4Tool = tool({\n description: 'Tool with optional field using v4',\n parameters: z4.object({\n required: z4.string(),\n optional: z4.string().optional(),\n }),\n execute: async ({ required, optional }) => {\n return optional ? `${required} - ${optional}` : required;\n },\n });\n\n const result1 = await v4Tool.execute({ required: 'Hello' }, createToolOptions('test-1'));\n expect(result1).toBe('Hello');\n\n const result2 = await v4Tool.execute(\n { required: 'Hello', optional: 'World' },\n createToolOptions('test-2'),\n );\n expect(result2).toBe('Hello - World');\n });\n\n it('should handle v4 enum schemas', async () => {\n const v4Tool = tool({\n description: 'Tool with enum using v4',\n parameters: z4.object({\n color: z4.enum(['red', 'blue', 'green']),\n }),\n execute: async ({ color }) => {\n return `Selected color: ${color}`;\n },\n });\n\n const result = await v4Tool.execute({ color: 'blue' }, createToolOptions('test-enum'));\n expect(result).toBe('Selected color: blue');\n });\n\n it('should handle v4 array schemas', async () => {\n const v4Tool = tool({\n description: 'Tool with array using v4',\n parameters: z4.object({\n tags: z4.array(z4.string()),\n }),\n execute: async ({ tags }) => {\n return `Tags: ${tags.join(', ')}`;\n },\n });\n\n const result = await v4Tool.execute(\n { tags: ['nodejs', 'typescript', 'testing'] },\n createToolOptions('test-array'),\n );\n expect(result).toBe('Tags: nodejs, typescript, testing');\n });\n\n it('should handle v4 nested object schemas', async () => {\n const v4Tool = tool({\n description: 'Tool with nested object using v4',\n parameters: z4.object({\n user: z4.object({\n name: z4.string(),\n email: z4.string(),\n }),\n }),\n execute: async ({ user }) => {\n return `${user.name} (${user.email})`;\n },\n });\n\n const result = await v4Tool.execute(\n { user: { name: 'John Doe', email: 'john@example.com' } },\n createToolOptions('test-nested'),\n );\n expect(result).toBe('John Doe (john@example.com)');\n });\n });\n\n describe('oaiParams with v4 schemas', () => {\n it('should convert v4 basic object schema', () => {\n const schema = z4.object({\n name: z4.string().describe('User name'),\n age: z4.number().describe('User age'),\n });\n\n const result = oaiParams(schema);\n\n expect(result.type).toBe('object');\n expect(result.properties).toHaveProperty('name');\n expect(result.properties).toHaveProperty('age');\n expect(result.required).toContain('name');\n expect(result.required).toContain('age');\n });\n\n it('should handle v4 optional fields', () => {\n const schema = z4.object({\n required: z4.string(),\n optional: z4.string().optional(),\n });\n\n const result = oaiParams(schema);\n\n expect(result.required).toContain('required');\n expect(result.required).not.toContain('optional');\n });\n\n it('should handle v4 enum fields', () => {\n const schema = z4.object({\n status: z4.enum(['pending', 'approved', 'rejected']),\n });\n\n const result = oaiParams(schema);\n\n const properties = result.properties as Record<string, Record<string, unknown>>;\n expect(properties.status?.enum).toEqual(['pending', 'approved', 'rejected']);\n });\n\n it('should handle v4 array fields', () => {\n const schema = z4.object({\n items: z4.array(z4.string()),\n });\n\n const result = oaiParams(schema);\n\n const properties = result.properties as Record<string, any>;\n expect(\n properties.items && typeof properties.items === 'object'\n ? properties.items.type\n : undefined,\n ).toBe('array');\n expect(\n properties.items && properties.items.items && typeof properties.items.items === 'object'\n ? properties.items.items.type\n : undefined,\n ).toBe('string');\n });\n });\n });\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGA,oBAAqC;AACrC,iBAAkB;AAClB,SAAoB;AACpB,SAAoB;AACpB,0BAAuC;AACvC,mBAA6C;AAAA,IAE7C,wBAAS,gBAAgB,MAAM;AAC7B,8BAAS,aAAa,MAAM;AAC1B,0BAAG,qCAAqC,MAAM;AAC5C,YAAM,SAAS,aAAE,OAAO;AAAA,QACtB,MAAM,aAAE,OAAO,EAAE,SAAS,eAAe;AAAA,QACzC,KAAK,aAAE,OAAO,EAAE,SAAS,cAAc;AAAA,MACzC,CAAC;AAED,YAAM,aAAS,wBAAU,MAAM;AAE/B,gCAAO,MAAM,EAAE,gBAAgB;AAAA,IACjC,CAAC;AAED,0BAAG,6BAA6B,MAAM;AACpC,YAAM,SAAS,aAAE,OAAO;AAAA,QACtB,OAAO,aAAE,KAAK,CAAC,OAAO,QAAQ,OAAO,CAAC,EAAE,SAAS,gBAAgB;AAAA,MACnE,CAAC;AAED,YAAM,aAAS,wBAAU,MAAM;AAE/B,gCAAO,MAAM,EAAE,gBAAgB;AAAA,IACjC,CAAC;AAED,0BAAG,8BAA8B,MAAM;AACrC,YAAM,SAAS,aAAE,OAAO;AAAA,QACtB,MAAM,aAAE,MAAM,aAAE,OAAO,CAAC,EAAE,SAAS,cAAc;AAAA,MACnD,CAAC;AAED,YAAM,aAAS,wBAAU,MAAM;AAE/B,gCAAO,MAAM,EAAE,gBAAgB;AAAA,IACjC,CAAC;AAED,0BAAG,gCAAgC,MAAM;AACvC,YAAM,SAAS,aAAE,OAAO;A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