@librechat/agents 3.1.78 → 3.1.80-dev.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/cjs/llm/anthropic/index.cjs +44 -55
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +33 -21
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +0 -4
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/messages/anthropicToolCache.cjs +48 -15
- package/dist/cjs/messages/anthropicToolCache.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +97 -14
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +10 -2
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +2 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +16 -5
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +9 -4
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +63 -40
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs +14 -16
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalExecutionTools.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
- package/dist/esm/llm/anthropic/index.mjs +43 -54
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +33 -21
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +0 -4
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/messages/anthropicToolCache.mjs +48 -15
- package/dist/esm/messages/anthropicToolCache.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +97 -14
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +10 -2
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +2 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +16 -5
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +9 -4
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +63 -40
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/local/LocalExecutionEngine.mjs +14 -16
- package/dist/esm/tools/local/LocalExecutionEngine.mjs.map +1 -1
- package/dist/esm/tools/local/LocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
- package/dist/types/llm/anthropic/index.d.ts +1 -9
- package/dist/types/messages/anthropicToolCache.d.ts +5 -5
- package/dist/types/types/tools.d.ts +82 -17
- package/package.json +1 -1
- package/src/llm/anthropic/index.ts +55 -64
- package/src/llm/anthropic/llm.spec.ts +585 -0
- package/src/llm/anthropic/utils/message_inputs.ts +36 -21
- package/src/llm/anthropic/utils/message_outputs.ts +0 -4
- package/src/llm/anthropic/utils/server-tool-inputs.test.ts +95 -13
- package/src/messages/__tests__/anthropicToolCache.test.ts +46 -0
- package/src/messages/anthropicToolCache.ts +70 -25
- package/src/messages/format.ts +117 -18
- package/src/messages/formatAgentMessages.test.ts +202 -1
- package/src/scripts/code_exec_multi_session.ts +4 -4
- package/src/specs/summarization.test.ts +3 -3
- package/src/tools/BashExecutor.ts +11 -3
- package/src/tools/BashProgrammaticToolCalling.ts +6 -6
- package/src/tools/CodeExecutor.ts +17 -6
- package/src/tools/ProgrammaticToolCalling.ts +14 -10
- package/src/tools/ToolNode.ts +85 -48
- package/src/tools/__tests__/LocalExecutionRoots.test.ts +8 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +9 -2
- package/src/tools/__tests__/ToolNode.session.test.ts +131 -50
- package/src/tools/local/LocalExecutionEngine.ts +55 -54
- package/src/tools/local/LocalExecutionTools.ts +2 -2
- package/src/tools/local/LocalProgrammaticToolCalling.ts +23 -6
- package/src/types/diff.d.ts +15 -0
- package/src/types/tools.ts +79 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalProgrammaticToolCalling.mjs","sources":["../../../../src/tools/local/LocalProgrammaticToolCalling.ts"],"sourcesContent":["import { randomBytes, randomUUID, timingSafeEqual } from 'crypto';\nimport { createServer } from 'http';\nimport { tool } from '@langchain/core/tools';\nimport type { AddressInfo } from 'net';\nimport type { IncomingMessage, ServerResponse } from 'http';\nimport type { DynamicStructuredTool } from '@langchain/core/tools';\nimport type * as t from '@/types';\nimport { executeHooks } from '@/hooks';\nimport {\n executeTools,\n filterToolsByUsage,\n formatCompletedResponse,\n normalizeToPythonIdentifier,\n ProgrammaticToolCallingName,\n ProgrammaticToolCallingSchema,\n ProgrammaticToolCallingDescription,\n} from '@/tools/ProgrammaticToolCalling';\nimport {\n BashProgrammaticToolCallingSchema,\n BashProgrammaticToolCallingDescription,\n filterBashToolsByUsage,\n normalizeToBashIdentifier,\n} from '@/tools/BashProgrammaticToolCalling';\nimport {\n executeLocalBash,\n executeLocalCode,\n getLocalSessionId,\n shellQuote,\n} from './LocalExecutionEngine';\nimport { Constants } from '@/common';\n\nconst DEFAULT_TIMEOUT = 60000;\nconst LocalProgrammaticToolCallingSchema = {\n ...ProgrammaticToolCallingSchema,\n properties: {\n ...ProgrammaticToolCallingSchema.properties,\n lang: {\n type: 'string',\n enum: ['py', 'python', 'bash', 'sh'],\n default: 'bash',\n description:\n 'Local engine runtime for orchestration code. Defaults to bash; use py/python for Python orchestration.',\n },\n },\n} as const;\n\ntype ToolBridge = {\n url: string;\n token: string;\n close: () => Promise<void>;\n};\n\ntype ToolRequest = {\n id?: string;\n name?: string;\n input?: Record<string, unknown>;\n};\n\nconst BRIDGE_AUTH_HEADER = 'x-librechat-bridge-token';\n\nfunction constantTimeEquals(a: string, b: string): boolean {\n const aBuf = Buffer.from(a, 'utf8');\n const bBuf = Buffer.from(b, 'utf8');\n if (aBuf.length !== bBuf.length) {\n return false;\n }\n return timingSafeEqual(aBuf, bBuf);\n}\n\ntype LocalProgrammaticRuntime = 'python' | 'bash';\n\ntype LocalProgrammaticParams = {\n code: string;\n timeout?: number;\n lang?: string;\n runtime?: string;\n language?: string;\n};\n\ntype ToolFilter = (toolDefs: t.LCTool[], code: string) => t.LCTool[];\n\nfunction resolveRuntime(params: LocalProgrammaticParams): LocalProgrammaticRuntime {\n const rawRuntime = params.lang ?? params.runtime ?? params.language ?? 'bash';\n return rawRuntime === 'py' || rawRuntime === 'python' ? 'python' : 'bash';\n}\n\nfunction toSerializable(value: unknown): unknown {\n if (value === undefined) {\n return null;\n }\n return value;\n}\n\nasync function readRequestBody(req: IncomingMessage): Promise<ToolRequest> {\n const chunks: Buffer[] = [];\n for await (const chunk of req) {\n chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));\n }\n const raw = Buffer.concat(chunks).toString('utf8');\n if (raw === '') {\n return {};\n }\n return JSON.parse(raw) as ToolRequest;\n}\n\nfunction writeJson(res: ServerResponse, status: number, value: unknown): void {\n res.writeHead(status, { 'Content-Type': 'application/json' });\n res.end(JSON.stringify(value));\n}\n\n/**\n * Run the host's `PreToolUse` hook chain for a single bridge call.\n * Returns the (possibly rewritten) input and a `denyReason` if any\n * matcher returned `decision: 'deny'` or `'ask'`. `'ask'` collapses\n * to deny because the bridge can't raise a LangGraph interrupt from\n * inside an HTTP handler — fail-closed matches the rest of the SDK\n * when HITL is unavailable.\n *\n * @internal Exported for tests so the deny / allow / updatedInput /\n * ask branches can be exercised without standing up the full HTTP\n * bridge.\n */\nexport async function applyPreToolUseHooksForBridge(\n hookContext: t.ProgrammaticHookContext,\n toolName: string,\n toolUseId: string,\n toolInput: Record<string, unknown>\n): Promise<{ input: Record<string, unknown>; denyReason?: string }> {\n if (hookContext.registry == null) {\n return { input: toolInput };\n }\n const result = await executeHooks({\n registry: hookContext.registry,\n input: {\n hook_event_name: 'PreToolUse',\n runId: hookContext.runId,\n threadId: hookContext.threadId,\n agentId: hookContext.agentId,\n toolName,\n toolInput,\n toolUseId,\n stepId: '',\n turn: 0,\n },\n sessionId: hookContext.runId,\n matchQuery: toolName,\n }).catch(() => undefined);\n if (result == null) {\n return { input: toolInput };\n }\n const nextInput =\n result.updatedInput != null\n ? (result.updatedInput as Record<string, unknown>)\n : toolInput;\n if (result.decision === 'deny' || result.decision === 'ask') {\n return {\n input: nextInput,\n denyReason:\n result.reason ??\n (result.decision === 'ask'\n ? `Tool \"${toolName}\" requires human approval; bridge cannot raise an interrupt — denying.`\n : `Tool \"${toolName}\" denied by PreToolUse hook.`),\n };\n }\n return { input: nextInput };\n}\n\nasync function createToolBridge(\n toolMap: t.ToolMap,\n hookContext?: t.ProgrammaticHookContext\n): Promise<ToolBridge> {\n const token = randomBytes(32).toString('hex');\n const server = createServer((req, res) => {\n // `?mode=text` returns the already-serialized result as the body\n // (or the error message at non-2xx). Python/Node callers stay on\n // JSON; bash callers using curl can avoid pulling in a JSON\n // parser dependency (Codex P2 #19 — `python3` was a hard\n // requirement for the bash bridge, breaking minimal containers).\n const url = new URL(req.url ?? '/', 'http://127.0.0.1');\n const isTextMode = url.searchParams.get('mode') === 'text';\n if (req.method !== 'POST' || url.pathname !== '/tool') {\n if (isTextMode) {\n res.writeHead(404, { 'Content-Type': 'text/plain' });\n res.end('Not found');\n } else {\n writeJson(res, 404, { error: 'Not found' });\n }\n return;\n }\n\n const presented = req.headers[BRIDGE_AUTH_HEADER];\n const presentedToken = Array.isArray(presented) ? presented[0] : presented;\n if (\n typeof presentedToken !== 'string' ||\n !constantTimeEquals(presentedToken, token)\n ) {\n if (isTextMode) {\n res.writeHead(401, { 'Content-Type': 'text/plain' });\n res.end('Unauthorized');\n } else {\n writeJson(res, 401, { error: 'Unauthorized' });\n }\n return;\n }\n\n readRequestBody(req)\n .then(async (body) => {\n if (typeof body.name !== 'string' || body.name === '') {\n const message = 'Tool request is missing a tool name.';\n if (isTextMode) {\n res.writeHead(400, { 'Content-Type': 'text/plain' });\n res.end(message);\n } else {\n writeJson(res, 400, {\n call_id: body.id ?? 'invalid',\n result: null,\n is_error: true,\n error_message: message,\n });\n }\n return;\n }\n\n const callId = body.id ?? `local_call_${randomUUID()}`;\n let effectiveInput: Record<string, unknown> = body.input ?? {};\n if (hookContext != null) {\n const gate = await applyPreToolUseHooksForBridge(\n hookContext,\n body.name,\n callId,\n effectiveInput\n );\n if (gate.denyReason != null) {\n const denyMsg = gate.denyReason;\n if (isTextMode) {\n res.writeHead(500, { 'Content-Type': 'text/plain' });\n res.end(denyMsg);\n } else {\n writeJson(res, 500, {\n call_id: callId,\n result: null,\n is_error: true,\n error_message: denyMsg,\n });\n }\n return;\n }\n effectiveInput = gate.input;\n }\n\n const [result] = await executeTools(\n [\n {\n id: callId,\n name: body.name,\n input: effectiveInput,\n },\n ],\n toolMap\n );\n\n if (isTextMode) {\n if (result.is_error === true) {\n res.writeHead(500, { 'Content-Type': 'text/plain' });\n res.end(result.error_message ?? `Tool ${body.name} failed`);\n } else {\n const value = toSerializable(result.result);\n const text =\n typeof value === 'string' ? value : JSON.stringify(value);\n res.writeHead(200, { 'Content-Type': 'text/plain' });\n res.end(text);\n }\n return;\n }\n\n writeJson(res, 200, {\n ...result,\n result: toSerializable(result.result),\n });\n })\n .catch((error: Error) => {\n if (isTextMode) {\n res.writeHead(500, { 'Content-Type': 'text/plain' });\n res.end(error.message);\n } else {\n writeJson(res, 500, {\n call_id: 'error',\n result: null,\n is_error: true,\n error_message: error.message,\n });\n }\n });\n });\n\n await new Promise<void>((resolve, reject) => {\n server.once('error', reject);\n server.listen(0, '127.0.0.1', resolve);\n });\n\n const address = server.address() as AddressInfo;\n return {\n url: `http://127.0.0.1:${address.port}/tool`,\n token,\n close: () =>\n new Promise((resolve, reject) => {\n server.close((error) => (error ? reject(error) : resolve()));\n }),\n };\n}\n\nfunction indent(code: string): string {\n return code\n .split('\\n')\n .map((line) => ` ${line}`)\n .join('\\n');\n}\n\nfunction createPythonProgram(\n code: string,\n toolDefs: t.LCTool[],\n bridgeUrl: string,\n bridgeToken: string\n): string {\n const functionDefs = toolDefs\n .map((def) => {\n const pythonName = normalizeToPythonIdentifier(def.name);\n return [\n `async def ${pythonName}(**kwargs):`,\n ` return await __librechat_call_tool(${JSON.stringify(def.name)}, kwargs)`,\n ].join('\\n');\n })\n .join('\\n\\n');\n\n return `\nimport asyncio\nimport json\nimport urllib.request\n\n__LIBRECHAT_TOOL_BRIDGE = ${JSON.stringify(bridgeUrl)}\n__LIBRECHAT_TOOL_TOKEN = ${JSON.stringify(bridgeToken)}\n\nasync def __librechat_call_tool(name, payload):\n body = json.dumps({\"name\": name, \"input\": payload}).encode(\"utf-8\")\n headers = {\n \"Content-Type\": \"application/json\",\n ${JSON.stringify(BRIDGE_AUTH_HEADER)}: __LIBRECHAT_TOOL_TOKEN,\n }\n\n def request():\n req = urllib.request.Request(__LIBRECHAT_TOOL_BRIDGE, data=body, headers=headers, method=\"POST\")\n with urllib.request.urlopen(req, timeout=300) as response:\n return response.read().decode(\"utf-8\")\n\n raw = await asyncio.to_thread(request)\n result = json.loads(raw)\n if result.get(\"is_error\"):\n raise RuntimeError(result.get(\"error_message\") or f\"Tool {name} failed\")\n return result.get(\"result\")\n\n${functionDefs}\n\nasync def __librechat_main():\n${indent(code)}\n\nasyncio.run(__librechat_main())\n`.trimStart();\n}\n\nexport function _createBashProgramForTests(\n code: string,\n toolDefs: t.LCTool[],\n bridgeUrl: string,\n bridgeToken: string\n): string {\n return createBashProgram(code, toolDefs, bridgeUrl, bridgeToken);\n}\n\nfunction createBashProgram(\n code: string,\n toolDefs: t.LCTool[],\n bridgeUrl: string,\n bridgeToken: string\n): string {\n const functions = toolDefs\n .map((def) => {\n const bashName = normalizeToBashIdentifier(def.name);\n return [\n `${bashName}() {`,\n ' local payload=\"${1:-}\"',\n ' if [ -z \"$payload\" ]; then payload=\\'{}\\'; fi',\n ` __librechat_call_tool ${shellQuote(def.name)} \"$payload\"`,\n '}',\n ].join('\\n');\n })\n .join('\\n\\n');\n\n return `\n__LIBRECHAT_TOOL_BRIDGE=${shellQuote(bridgeUrl)}\n__LIBRECHAT_TOOL_HEADER=${shellQuote(BRIDGE_AUTH_HEADER)}\n__LIBRECHAT_TOOL_TOKEN=${shellQuote(bridgeToken)}\n\n# Bridge call helper. Tries curl first (universally available, no\n# JSON parser needed thanks to the bridge's ?mode=text endpoint),\n# falls back to python3 for environments without curl. Codex P2 #19\n# flagged that the prior python3-only path broke minimal containers\n# (and Windows hosts without a python3 binary on PATH). Tool names\n# come from Constants.* and are always safe identifiers, so we can\n# splice them into JSON without an escape pass.\n__librechat_call_tool() {\n local tool_name=\"$1\"\n local payload=\"$2\"\n if command -v curl >/dev/null 2>&1; then\n local body=\"{\\\\\"name\\\\\":\\\\\"$tool_name\\\\\",\\\\\"input\\\\\":$payload}\"\n local response\n local http_code\n response=$(curl -sS -X POST \\\n -H \"Content-Type: application/json\" \\\n -H \"$__LIBRECHAT_TOOL_HEADER: $__LIBRECHAT_TOOL_TOKEN\" \\\n --data-binary \"$body\" \\\n -w '\\\\n__LIBRECHAT_HTTP_CODE_%{http_code}__' \\\n \"$__LIBRECHAT_TOOL_BRIDGE?mode=text\")\n http_code=$(printf '%s' \"$response\" | sed -n 's/.*__LIBRECHAT_HTTP_CODE_\\\\([0-9][0-9]*\\\\)__$/\\\\1/p')\n local body_only\n body_only=$(printf '%s' \"$response\" | sed 's/__LIBRECHAT_HTTP_CODE_[0-9][0-9]*__$//')\n if [ \"$http_code\" = \"200\" ]; then\n printf '%s' \"$body_only\"\n return 0\n fi\n printf '%s\\\\n' \"$body_only\" >&2\n return 1\n elif command -v python3 >/dev/null 2>&1; then\n python3 - \"$__LIBRECHAT_TOOL_BRIDGE\" \"$tool_name\" \"$payload\" \"$__LIBRECHAT_TOOL_HEADER\" \"$__LIBRECHAT_TOOL_TOKEN\" <<'PY'\nimport json\nimport sys\nimport urllib.request\n\nurl, name, payload, header, token = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5]\nbody = json.dumps({\"name\": name, \"input\": json.loads(payload)}).encode(\"utf-8\")\nreq = urllib.request.Request(url, data=body, headers={\"Content-Type\": \"application/json\", header: token}, method=\"POST\")\nwith urllib.request.urlopen(req, timeout=300) as response:\n result = json.loads(response.read().decode(\"utf-8\"))\nif result.get(\"is_error\"):\n print(result.get(\"error_message\") or f\"Tool {name} failed\", file=sys.stderr)\n sys.exit(1)\nvalue = result.get(\"result\")\nif isinstance(value, str):\n print(value)\nelse:\n print(json.dumps(value))\nPY\n else\n printf 'librechat: tool bridge needs either curl or python3 on PATH\\\\n' >&2\n return 1\n fi\n}\n\n${functions}\n\n${code}\n`.trimStart();\n}\n\nfunction getProgrammaticContext(config?: {\n toolCall?: unknown;\n}): Partial<t.ProgrammaticCache> {\n return (config?.toolCall ?? {}) as Partial<t.ProgrammaticCache>;\n}\n\nfunction createEffectiveToolMap(\n toolMap: t.ToolMap,\n toolDefs: t.LCTool[],\n code: string,\n filterTools: ToolFilter\n): { effectiveTools: t.LCTool[]; effectiveMap: t.ToolMap } {\n const effectiveTools = filterTools(toolDefs, code);\n const effectiveMap = new Map<string, t.GenericTool>(\n effectiveTools\n .map((def) => {\n const executable = toolMap.get(def.name);\n return executable == null\n ? undefined\n : ([def.name, executable] as [string, t.GenericTool]);\n })\n .filter((entry): entry is [string, t.GenericTool] => entry != null)\n );\n\n return { effectiveTools, effectiveMap };\n}\n\nasync function runLocalProgrammaticTool(args: {\n params: LocalProgrammaticParams;\n config?: { toolCall?: unknown };\n localConfig: t.LocalExecutionConfig;\n runtime: LocalProgrammaticRuntime;\n}): Promise<[string, t.ProgrammaticExecutionArtifact]> {\n const { toolMap, toolDefs, hookContext } = getProgrammaticContext(args.config);\n\n if (toolMap == null || toolMap.size === 0) {\n throw new Error('No toolMap provided for local programmatic execution.');\n }\n if (toolDefs == null || toolDefs.length === 0) {\n throw new Error('No tool definitions provided for local programmatic execution.');\n }\n\n const { effectiveTools, effectiveMap } = createEffectiveToolMap(\n toolMap,\n toolDefs,\n args.params.code,\n args.runtime === 'bash' ? filterBashToolsByUsage : filterToolsByUsage\n );\n const bridge = await createToolBridge(effectiveMap, hookContext);\n\n try {\n const timeoutMs = args.params.timeout ?? args.localConfig.timeoutMs ?? DEFAULT_TIMEOUT;\n const result =\n args.runtime === 'bash'\n ? await executeLocalBash(\n createBashProgram(args.params.code, effectiveTools, bridge.url, bridge.token),\n { ...args.localConfig, timeoutMs }\n )\n : await executeLocalCode(\n {\n lang: 'py',\n code: createPythonProgram(args.params.code, effectiveTools, bridge.url, bridge.token),\n },\n { ...args.localConfig, timeoutMs }\n );\n\n if (result.exitCode !== 0 || result.timedOut) {\n throw new Error(\n result.stderr !== ''\n ? result.stderr\n : `Local ${args.runtime} programmatic execution exited with code ${\n result.exitCode ?? 'unknown'\n }`\n );\n }\n\n return formatCompletedResponse({\n status: 'completed',\n session_id: getLocalSessionId(args.localConfig),\n stdout: result.stdout,\n stderr: result.stderr,\n files: [],\n });\n } finally {\n await bridge.close();\n }\n}\n\nexport function createLocalProgrammaticToolCallingTool(\n localConfig: t.LocalExecutionConfig = {}\n): DynamicStructuredTool {\n return tool(\n async (rawParams, config) => {\n const params = rawParams as LocalProgrammaticParams;\n return runLocalProgrammaticTool({\n params,\n config,\n localConfig,\n runtime: resolveRuntime(params),\n });\n },\n {\n name: ProgrammaticToolCallingName,\n description: `${ProgrammaticToolCallingDescription}\\n\\nLocal engine: runs bash by default, or Python when \\`lang\\` is \\`py\\` or \\`python\\`, on the host machine and calls tools through an in-process localhost bridge.`,\n schema: LocalProgrammaticToolCallingSchema,\n responseFormat: Constants.CONTENT_AND_ARTIFACT,\n }\n );\n}\n\nexport function createLocalBashProgrammaticToolCallingTool(\n localConfig: t.LocalExecutionConfig = {}\n): DynamicStructuredTool {\n return tool(\n async (rawParams, config) => {\n const params = rawParams as LocalProgrammaticParams;\n return runLocalProgrammaticTool({\n params,\n config,\n localConfig,\n runtime: 'bash',\n });\n },\n {\n name: Constants.BASH_PROGRAMMATIC_TOOL_CALLING,\n description: `${BashProgrammaticToolCallingDescription}\\n\\nLocal engine: runs this bash orchestration code on the host machine and calls tools through an in-process localhost bridge.`,\n schema: BashProgrammaticToolCallingSchema,\n responseFormat: Constants.CONTENT_AND_ARTIFACT,\n }\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;AA+BA,MAAM,eAAe,GAAG,KAAK;AAC7B,MAAM,kCAAkC,GAAG;AACzC,IAAA,GAAG,6BAA6B;AAChC,IAAA,UAAU,EAAE;QACV,GAAG,6BAA6B,CAAC,UAAU;AAC3C,QAAA,IAAI,EAAE;AACJ,YAAA,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC;AACpC,YAAA,OAAO,EAAE,MAAM;AACf,YAAA,WAAW,EACT,wGAAwG;AAC3G,SAAA;AACF,KAAA;CACO;AAcV,MAAM,kBAAkB,GAAG,0BAA0B;AAErD,SAAS,kBAAkB,CAAC,CAAS,EAAE,CAAS,EAAA;IAC9C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC;IACnC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC;IACnC,IAAI,IAAI,CAAC,MAAM,KAAK,IA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AAE,CAAA,EAAG,sCAAsC,CAAA,+HAAA,CAAiI;AACvL,QAAA,MAAM,EAAE,iCAAiC;QACzC,cAAc,EAAE,SAAS,CAAC,oBAAoB;AAC/C,KAAA,CACF;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"LocalProgrammaticToolCalling.mjs","sources":["../../../../src/tools/local/LocalProgrammaticToolCalling.ts"],"sourcesContent":["import { randomBytes, randomUUID, timingSafeEqual } from 'crypto';\nimport { createServer } from 'http';\nimport { tool } from '@langchain/core/tools';\nimport type { AddressInfo } from 'net';\nimport type { IncomingMessage, ServerResponse } from 'http';\nimport type { DynamicStructuredTool } from '@langchain/core/tools';\nimport type * as t from '@/types';\nimport { executeHooks } from '@/hooks';\nimport {\n executeTools,\n filterToolsByUsage,\n formatCompletedResponse,\n normalizeToPythonIdentifier,\n ProgrammaticToolCallingName,\n ProgrammaticToolCallingSchema,\n ProgrammaticToolCallingDescription,\n} from '@/tools/ProgrammaticToolCalling';\nimport {\n BashProgrammaticToolCallingSchema,\n BashProgrammaticToolCallingDescription,\n filterBashToolsByUsage,\n normalizeToBashIdentifier,\n} from '@/tools/BashProgrammaticToolCalling';\nimport {\n executeLocalBash,\n executeLocalCode,\n getLocalSessionId,\n shellQuote,\n} from './LocalExecutionEngine';\nimport { Constants } from '@/common';\n\nconst DEFAULT_TIMEOUT = 60000;\nconst LocalProgrammaticToolCallingSchema = {\n ...ProgrammaticToolCallingSchema,\n properties: {\n ...ProgrammaticToolCallingSchema.properties,\n lang: {\n type: 'string',\n enum: ['py', 'python', 'bash', 'sh'],\n default: 'bash',\n description:\n 'Local engine runtime for orchestration code. Defaults to bash; use py/python for Python orchestration.',\n },\n },\n} as const;\n\ntype ToolBridge = {\n url: string;\n token: string;\n close: () => Promise<void>;\n};\n\ntype ToolRequest = {\n id?: string;\n name?: string;\n input?: Record<string, unknown>;\n};\n\nconst BRIDGE_AUTH_HEADER = 'x-librechat-bridge-token';\n\nfunction constantTimeEquals(a: string, b: string): boolean {\n const aBuf = Buffer.from(a, 'utf8');\n const bBuf = Buffer.from(b, 'utf8');\n if (aBuf.length !== bBuf.length) {\n return false;\n }\n return timingSafeEqual(aBuf, bBuf);\n}\n\ntype LocalProgrammaticRuntime = 'python' | 'bash';\n\ntype LocalProgrammaticParams = {\n code: string;\n timeout?: number;\n lang?: string;\n runtime?: string;\n language?: string;\n};\n\ntype ToolFilter = (toolDefs: t.LCTool[], code: string) => t.LCTool[];\n\nfunction resolveRuntime(\n params: LocalProgrammaticParams\n): LocalProgrammaticRuntime {\n const rawRuntime = params.lang ?? params.runtime ?? params.language ?? 'bash';\n return rawRuntime === 'py' || rawRuntime === 'python' ? 'python' : 'bash';\n}\n\nfunction toSerializable(value: unknown): unknown {\n if (value === undefined) {\n return null;\n }\n return value;\n}\n\nasync function readRequestBody(req: IncomingMessage): Promise<ToolRequest> {\n const chunks: Buffer[] = [];\n for await (const chunk of req) {\n chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));\n }\n const raw = Buffer.concat(chunks).toString('utf8');\n if (raw === '') {\n return {};\n }\n return JSON.parse(raw) as ToolRequest;\n}\n\nfunction writeJson(res: ServerResponse, status: number, value: unknown): void {\n res.writeHead(status, { 'Content-Type': 'application/json' });\n res.end(JSON.stringify(value));\n}\n\n/**\n * Run the host's `PreToolUse` hook chain for a single bridge call.\n * Returns the (possibly rewritten) input and a `denyReason` if any\n * matcher returned `decision: 'deny'` or `'ask'`. `'ask'` collapses\n * to deny because the bridge can't raise a LangGraph interrupt from\n * inside an HTTP handler — fail-closed matches the rest of the SDK\n * when HITL is unavailable.\n *\n * @internal Exported for tests so the deny / allow / updatedInput /\n * ask branches can be exercised without standing up the full HTTP\n * bridge.\n */\nexport async function applyPreToolUseHooksForBridge(\n hookContext: t.ProgrammaticHookContext,\n toolName: string,\n toolUseId: string,\n toolInput: Record<string, unknown>\n): Promise<{ input: Record<string, unknown>; denyReason?: string }> {\n if (hookContext.registry == null) {\n return { input: toolInput };\n }\n const result = await executeHooks({\n registry: hookContext.registry,\n input: {\n hook_event_name: 'PreToolUse',\n runId: hookContext.runId,\n threadId: hookContext.threadId,\n agentId: hookContext.agentId,\n toolName,\n toolInput,\n toolUseId,\n stepId: '',\n turn: 0,\n },\n sessionId: hookContext.runId,\n matchQuery: toolName,\n }).catch(() => undefined);\n if (result == null) {\n return { input: toolInput };\n }\n const nextInput =\n result.updatedInput != null\n ? (result.updatedInput as Record<string, unknown>)\n : toolInput;\n if (result.decision === 'deny' || result.decision === 'ask') {\n return {\n input: nextInput,\n denyReason:\n result.reason ??\n (result.decision === 'ask'\n ? `Tool \"${toolName}\" requires human approval; bridge cannot raise an interrupt — denying.`\n : `Tool \"${toolName}\" denied by PreToolUse hook.`),\n };\n }\n return { input: nextInput };\n}\n\nasync function createToolBridge(\n toolMap: t.ToolMap,\n hookContext?: t.ProgrammaticHookContext\n): Promise<ToolBridge> {\n const token = randomBytes(32).toString('hex');\n const server = createServer((req, res) => {\n // `?mode=text` returns the already-serialized result as the body\n // (or the error message at non-2xx). Python/Node callers stay on\n // JSON; bash callers using curl can avoid pulling in a JSON\n // parser dependency (Codex P2 #19 — `python3` was a hard\n // requirement for the bash bridge, breaking minimal containers).\n const url = new URL(req.url ?? '/', 'http://127.0.0.1');\n const isTextMode = url.searchParams.get('mode') === 'text';\n if (req.method !== 'POST' || url.pathname !== '/tool') {\n if (isTextMode) {\n res.writeHead(404, { 'Content-Type': 'text/plain' });\n res.end('Not found');\n } else {\n writeJson(res, 404, { error: 'Not found' });\n }\n return;\n }\n\n const presented = req.headers[BRIDGE_AUTH_HEADER];\n const presentedToken = Array.isArray(presented) ? presented[0] : presented;\n if (\n typeof presentedToken !== 'string' ||\n !constantTimeEquals(presentedToken, token)\n ) {\n if (isTextMode) {\n res.writeHead(401, { 'Content-Type': 'text/plain' });\n res.end('Unauthorized');\n } else {\n writeJson(res, 401, { error: 'Unauthorized' });\n }\n return;\n }\n\n readRequestBody(req)\n .then(async (body) => {\n if (typeof body.name !== 'string' || body.name === '') {\n const message = 'Tool request is missing a tool name.';\n if (isTextMode) {\n res.writeHead(400, { 'Content-Type': 'text/plain' });\n res.end(message);\n } else {\n writeJson(res, 400, {\n call_id: body.id ?? 'invalid',\n result: null,\n is_error: true,\n error_message: message,\n });\n }\n return;\n }\n\n const callId = body.id ?? `local_call_${randomUUID()}`;\n let effectiveInput: Record<string, unknown> = body.input ?? {};\n if (hookContext != null) {\n const gate = await applyPreToolUseHooksForBridge(\n hookContext,\n body.name,\n callId,\n effectiveInput\n );\n if (gate.denyReason != null) {\n const denyMsg = gate.denyReason;\n if (isTextMode) {\n res.writeHead(500, { 'Content-Type': 'text/plain' });\n res.end(denyMsg);\n } else {\n writeJson(res, 500, {\n call_id: callId,\n result: null,\n is_error: true,\n error_message: denyMsg,\n });\n }\n return;\n }\n effectiveInput = gate.input;\n }\n\n const [result] = await executeTools(\n [\n {\n id: callId,\n name: body.name,\n input: effectiveInput,\n },\n ],\n toolMap\n );\n\n if (isTextMode) {\n if (result.is_error === true) {\n res.writeHead(500, { 'Content-Type': 'text/plain' });\n res.end(result.error_message ?? `Tool ${body.name} failed`);\n } else {\n const value = toSerializable(result.result);\n const text =\n typeof value === 'string' ? value : JSON.stringify(value);\n res.writeHead(200, { 'Content-Type': 'text/plain' });\n res.end(text);\n }\n return;\n }\n\n writeJson(res, 200, {\n ...result,\n result: toSerializable(result.result),\n });\n })\n .catch((error: Error) => {\n if (isTextMode) {\n res.writeHead(500, { 'Content-Type': 'text/plain' });\n res.end(error.message);\n } else {\n writeJson(res, 500, {\n call_id: 'error',\n result: null,\n is_error: true,\n error_message: error.message,\n });\n }\n });\n });\n\n await new Promise<void>((resolve, reject) => {\n server.once('error', reject);\n server.listen(0, '127.0.0.1', resolve);\n });\n\n const address = server.address() as AddressInfo;\n return {\n url: `http://127.0.0.1:${address.port}/tool`,\n token,\n close: () =>\n new Promise((resolve, reject) => {\n server.close((error) => (error ? reject(error) : resolve()));\n }),\n };\n}\n\nfunction indent(code: string): string {\n return code\n .split('\\n')\n .map((line) => ` ${line}`)\n .join('\\n');\n}\n\nfunction createPythonProgram(\n code: string,\n toolDefs: t.LCTool[],\n bridgeUrl: string,\n bridgeToken: string\n): string {\n const functionDefs = toolDefs\n .map((def) => {\n const pythonName = normalizeToPythonIdentifier(def.name);\n return [\n `async def ${pythonName}(**kwargs):`,\n ` return await __librechat_call_tool(${JSON.stringify(def.name)}, kwargs)`,\n ].join('\\n');\n })\n .join('\\n\\n');\n\n return `\nimport asyncio\nimport json\nimport urllib.request\n\n__LIBRECHAT_TOOL_BRIDGE = ${JSON.stringify(bridgeUrl)}\n__LIBRECHAT_TOOL_TOKEN = ${JSON.stringify(bridgeToken)}\n\nasync def __librechat_call_tool(name, payload):\n body = json.dumps({\"name\": name, \"input\": payload}).encode(\"utf-8\")\n headers = {\n \"Content-Type\": \"application/json\",\n ${JSON.stringify(BRIDGE_AUTH_HEADER)}: __LIBRECHAT_TOOL_TOKEN,\n }\n\n def request():\n req = urllib.request.Request(__LIBRECHAT_TOOL_BRIDGE, data=body, headers=headers, method=\"POST\")\n with urllib.request.urlopen(req, timeout=300) as response:\n return response.read().decode(\"utf-8\")\n\n raw = await asyncio.to_thread(request)\n result = json.loads(raw)\n if result.get(\"is_error\"):\n raise RuntimeError(result.get(\"error_message\") or f\"Tool {name} failed\")\n return result.get(\"result\")\n\n${functionDefs}\n\nasync def __librechat_main():\n${indent(code)}\n\nasyncio.run(__librechat_main())\n`.trimStart();\n}\n\nexport function _createBashProgramForTests(\n code: string,\n toolDefs: t.LCTool[],\n bridgeUrl: string,\n bridgeToken: string\n): string {\n return createBashProgram(code, toolDefs, bridgeUrl, bridgeToken);\n}\n\nfunction createBashProgram(\n code: string,\n toolDefs: t.LCTool[],\n bridgeUrl: string,\n bridgeToken: string\n): string {\n const functions = toolDefs\n .map((def) => {\n const bashName = normalizeToBashIdentifier(def.name);\n return [\n `${bashName}() {`,\n ' local payload=\"${1:-}\"',\n ' if [ -z \"$payload\" ]; then payload=\\'{}\\'; fi',\n ` __librechat_call_tool ${shellQuote(def.name)} \"$payload\"`,\n '}',\n ].join('\\n');\n })\n .join('\\n\\n');\n\n return `\n__LIBRECHAT_TOOL_BRIDGE=${shellQuote(bridgeUrl)}\n__LIBRECHAT_TOOL_HEADER=${shellQuote(BRIDGE_AUTH_HEADER)}\n__LIBRECHAT_TOOL_TOKEN=${shellQuote(bridgeToken)}\n\n# Bridge call helper. Tries curl first (universally available, no\n# JSON parser needed thanks to the bridge's ?mode=text endpoint),\n# falls back to python3 for environments without curl. Codex P2 #19\n# flagged that the prior python3-only path broke minimal containers\n# (and Windows hosts without a python3 binary on PATH). Tool names\n# come from Constants.* and are always safe identifiers, so we can\n# splice them into JSON without an escape pass.\n__librechat_call_tool() {\n local tool_name=\"$1\"\n local payload=\"$2\"\n if command -v curl >/dev/null 2>&1; then\n local body=\"{\\\\\"name\\\\\":\\\\\"$tool_name\\\\\",\\\\\"input\\\\\":$payload}\"\n local response\n local http_code\n response=$(curl -sS -X POST \\\n -H \"Content-Type: application/json\" \\\n -H \"$__LIBRECHAT_TOOL_HEADER: $__LIBRECHAT_TOOL_TOKEN\" \\\n --data-binary \"$body\" \\\n -w '\\\\n__LIBRECHAT_HTTP_CODE_%{http_code}__' \\\n \"$__LIBRECHAT_TOOL_BRIDGE?mode=text\")\n http_code=$(printf '%s' \"$response\" | sed -n 's/.*__LIBRECHAT_HTTP_CODE_\\\\([0-9][0-9]*\\\\)__$/\\\\1/p')\n local body_only\n body_only=$(printf '%s' \"$response\" | sed 's/__LIBRECHAT_HTTP_CODE_[0-9][0-9]*__$//')\n if [ \"$http_code\" = \"200\" ]; then\n printf '%s' \"$body_only\"\n return 0\n fi\n printf '%s\\\\n' \"$body_only\" >&2\n return 1\n elif command -v python3 >/dev/null 2>&1; then\n python3 - \"$__LIBRECHAT_TOOL_BRIDGE\" \"$tool_name\" \"$payload\" \"$__LIBRECHAT_TOOL_HEADER\" \"$__LIBRECHAT_TOOL_TOKEN\" <<'PY'\nimport json\nimport sys\nimport urllib.request\n\nurl, name, payload, header, token = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5]\nbody = json.dumps({\"name\": name, \"input\": json.loads(payload)}).encode(\"utf-8\")\nreq = urllib.request.Request(url, data=body, headers={\"Content-Type\": \"application/json\", header: token}, method=\"POST\")\nwith urllib.request.urlopen(req, timeout=300) as response:\n result = json.loads(response.read().decode(\"utf-8\"))\nif result.get(\"is_error\"):\n print(result.get(\"error_message\") or f\"Tool {name} failed\", file=sys.stderr)\n sys.exit(1)\nvalue = result.get(\"result\")\nif isinstance(value, str):\n print(value)\nelse:\n print(json.dumps(value))\nPY\n else\n printf 'librechat: tool bridge needs either curl or python3 on PATH\\\\n' >&2\n return 1\n fi\n}\n\n${functions}\n\n${code}\n`.trimStart();\n}\n\nfunction getProgrammaticContext(config?: {\n toolCall?: unknown;\n}): Partial<t.ProgrammaticCache> {\n return (config?.toolCall ?? {}) as Partial<t.ProgrammaticCache>;\n}\n\nfunction createEffectiveToolMap(\n toolMap: t.ToolMap,\n toolDefs: t.LCTool[],\n code: string,\n filterTools: ToolFilter\n): { effectiveTools: t.LCTool[]; effectiveMap: t.ToolMap } {\n const effectiveTools = filterTools(toolDefs, code);\n const effectiveMap = new Map<string, t.GenericTool>(\n effectiveTools\n .map((def) => {\n const executable = toolMap.get(def.name);\n return executable == null\n ? undefined\n : ([def.name, executable] as [string, t.GenericTool]);\n })\n .filter((entry): entry is [string, t.GenericTool] => entry != null)\n );\n\n return { effectiveTools, effectiveMap };\n}\n\nasync function runLocalProgrammaticTool(args: {\n params: LocalProgrammaticParams;\n config?: { toolCall?: unknown };\n localConfig: t.LocalExecutionConfig;\n runtime: LocalProgrammaticRuntime;\n}): Promise<[string, t.ProgrammaticExecutionArtifact]> {\n const { toolMap, toolDefs, hookContext } = getProgrammaticContext(\n args.config\n );\n\n if (toolMap == null || toolMap.size === 0) {\n throw new Error('No toolMap provided for local programmatic execution.');\n }\n if (toolDefs == null || toolDefs.length === 0) {\n throw new Error(\n 'No tool definitions provided for local programmatic execution.'\n );\n }\n\n const { effectiveTools, effectiveMap } = createEffectiveToolMap(\n toolMap,\n toolDefs,\n args.params.code,\n args.runtime === 'bash' ? filterBashToolsByUsage : filterToolsByUsage\n );\n const bridge = await createToolBridge(effectiveMap, hookContext);\n\n try {\n const timeoutMs =\n args.params.timeout ?? args.localConfig.timeoutMs ?? DEFAULT_TIMEOUT;\n const result =\n args.runtime === 'bash'\n ? await executeLocalBash(\n createBashProgram(\n args.params.code,\n effectiveTools,\n bridge.url,\n bridge.token\n ),\n { ...args.localConfig, timeoutMs }\n )\n : await executeLocalCode(\n {\n lang: 'py',\n code: createPythonProgram(\n args.params.code,\n effectiveTools,\n bridge.url,\n bridge.token\n ),\n },\n { ...args.localConfig, timeoutMs }\n );\n\n if (result.exitCode !== 0 || result.timedOut) {\n throw new Error(\n result.stderr !== ''\n ? result.stderr\n : `Local ${args.runtime} programmatic execution exited with code ${\n result.exitCode ?? 'unknown'\n }`\n );\n }\n\n return formatCompletedResponse({\n status: 'completed',\n session_id: getLocalSessionId(args.localConfig),\n stdout: result.stdout,\n stderr: result.stderr,\n files: [],\n });\n } finally {\n await bridge.close();\n }\n}\n\nexport function createLocalProgrammaticToolCallingTool(\n localConfig: t.LocalExecutionConfig = {}\n): DynamicStructuredTool {\n return tool(\n async (rawParams, config) => {\n const params = rawParams as LocalProgrammaticParams;\n return runLocalProgrammaticTool({\n params,\n config,\n localConfig,\n runtime: resolveRuntime(params),\n });\n },\n {\n name: ProgrammaticToolCallingName,\n description: `${ProgrammaticToolCallingDescription}\\n\\nLocal engine: runs bash by default, or Python when \\`lang\\` is \\`py\\` or \\`python\\`, on the host machine and calls tools through an in-process localhost bridge.`,\n schema: LocalProgrammaticToolCallingSchema,\n responseFormat: Constants.CONTENT_AND_ARTIFACT,\n }\n );\n}\n\nexport function createLocalBashProgrammaticToolCallingTool(\n localConfig: t.LocalExecutionConfig = {}\n): DynamicStructuredTool {\n return tool(\n async (rawParams, config) => {\n const params = rawParams as LocalProgrammaticParams;\n return runLocalProgrammaticTool({\n params,\n config,\n localConfig,\n runtime: 'bash',\n });\n },\n {\n name: Constants.BASH_PROGRAMMATIC_TOOL_CALLING,\n description: `${BashProgrammaticToolCallingDescription}\\n\\nLocal engine: runs this bash orchestration code on the host machine and calls tools through an in-process localhost bridge.`,\n schema: BashProgrammaticToolCallingSchema,\n responseFormat: Constants.CONTENT_AND_ARTIFACT,\n }\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;AA+BA,MAAM,eAAe,GAAG,KAAK;AAC7B,MAAM,kCAAkC,GAAG;AACzC,IAAA,GAAG,6BAA6B;AAChC,IAAA,UAAU,EAAE;QACV,GAAG,6BAA6B,CAAC,UAAU;AAC3C,QAAA,IAAI,EAAE;AACJ,YAAA,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC;AACpC,YAAA,OAAO,EAAE,MAAM;AACf,YAAA,WAAW,EACT,wGAAwG;AAC3G,SAAA;AACF,KAAA;CACO;AAcV,MAAM,kBAAkB,GAAG,0BAA0B;AAErD,SAAS,kBAAkB,CAAC,CAAS,EAAE,CAAS,EAAA;IAC9C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC;IACnC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC;IACnC,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE;AAC/B,QAAA,OAAO,KAAK;IACd;AACA,IAAA,OAAO,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC;AACpC;AAcA,SAAS,cAAc,CACrB,MAA+B,EAAA;AAE/B,IAAA,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM;AAC7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M;YACrB,MAAM,EAAE,MAAM,CAAC,MAAM;AACrB,YAAA,KAAK,EAAE,EAAE;AACV,SAAA,CAAC;IACJ;YAAU;AACR,QAAA,MAAM,MAAM,CAAC,KAAK,EAAE;IACtB;AACF;AAEM,SAAU,sCAAsC,CACpD,WAAA,GAAsC,EAAE,EAAA;IAExC,OAAO,IAAI,CACT,OAAO,SAAS,EAAE,MAAM,KAAI;QAC1B,MAAM,MAAM,GAAG,SAAoC;AACnD,QAAA,OAAO,wBAAwB,CAAC;YAC9B,MAAM;YACN,MAAM;YACN,WAAW;AACX,YAAA,OAAO,EAAE,cAAc,CAAC,MAAM,CAAC;AAChC,SAAA,CAAC;AACJ,IAAA,CAAC,EACD;AACE,QAAA,IAAI,EAAE,2BAA2B;QACjC,WAAW,EAAE,CAAA,EAAG,kCAAkC,CAAA,oKAAA,CAAsK;AACxN,QAAA,MAAM,EAAE,kCAAkC;QAC1C,cAAc,EAAE,SAAS,CAAC,oBAAoB;AAC/C,KAAA,CACF;AACH;AAEM,SAAU,0CAA0C,CACxD,WAAA,GAAsC,EAAE,EAAA;IAExC,OAAO,IAAI,CACT,OAAO,SAAS,EAAE,MAAM,KAAI;QAC1B,MAAM,MAAM,GAAG,SAAoC;AACnD,QAAA,OAAO,wBAAwB,CAAC;YAC9B,MAAM;YACN,MAAM;YACN,WAAW;AACX,YAAA,OAAO,EAAE,MAAM;AAChB,SAAA,CAAC;AACJ,IAAA,CAAC,EACD;QACE,IAAI,EAAE,SAAS,CAAC,8BAA8B;QAC9C,WAAW,EAAE,CAAA,EAAG,sCAAsC,CAAA,+HAAA,CAAiI;AACvL,QAAA,MAAM,EAAE,iCAAiC;QACzC,cAAc,EAAE,SAAS,CAAC,oBAAoB;AAC/C,KAAA,CACF;AACH;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ChatAnthropicMessages } from '@langchain/anthropic';
|
|
2
2
|
import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
3
3
|
import type { BaseChatModelParams } from '@langchain/core/language_models/chat_models';
|
|
4
|
-
import type { BaseMessage
|
|
4
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
5
5
|
import type { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
|
|
6
6
|
import type { AnthropicInput } from '@langchain/anthropic';
|
|
7
7
|
import type { Anthropic } from '@anthropic-ai/sdk';
|
|
@@ -31,10 +31,7 @@ type CustomAnthropicInvocationParams = {
|
|
|
31
31
|
};
|
|
32
32
|
export declare class CustomAnthropic extends ChatAnthropicMessages {
|
|
33
33
|
_lc_stream_delay: number;
|
|
34
|
-
private message_start;
|
|
35
|
-
private message_delta;
|
|
36
34
|
private tools_in_params?;
|
|
37
|
-
private emitted_usage?;
|
|
38
35
|
top_k: number | undefined;
|
|
39
36
|
outputConfig?: AnthropicOutputConfig;
|
|
40
37
|
inferenceGeo?: string;
|
|
@@ -45,11 +42,6 @@ export declare class CustomAnthropic extends ChatAnthropicMessages {
|
|
|
45
42
|
* Get the parameters used to invoke the model
|
|
46
43
|
*/
|
|
47
44
|
invocationParams(options?: this['ParsedCallOptions'] & CustomAnthropicCallOptions): Omit<AnthropicMessageCreateParams | AnthropicStreamingMessageCreateParams, 'messages'> & CustomAnthropicInvocationParams;
|
|
48
|
-
/**
|
|
49
|
-
* Get stream usage as returned by this client's API response.
|
|
50
|
-
* @returns The stream usage object.
|
|
51
|
-
*/
|
|
52
|
-
getStreamUsage(): UsageMetadata | undefined;
|
|
53
45
|
resetTokenEvents(): void;
|
|
54
46
|
setDirectFields(fields?: CustomAnthropicInput): void;
|
|
55
47
|
private createGenerationChunk;
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
* the breakpoint.
|
|
20
20
|
*
|
|
21
21
|
* LangChain's Anthropic adapter passes the marker through via
|
|
22
|
-
* `tool.extras.cache_control`
|
|
23
|
-
*
|
|
24
|
-
* mutating the original tool instance, since callers may share them
|
|
22
|
+
* `tool.extras.cache_control` for custom tools, while Anthropic built-ins
|
|
23
|
+
* require direct `cache_control`. Either way, we stamp a fresh wrapper —
|
|
24
|
+
* never mutating the original tool instance, since callers may share them
|
|
25
25
|
* across runs.
|
|
26
26
|
*/
|
|
27
27
|
import type { GraphTools } from '@/types';
|
|
@@ -45,7 +45,7 @@ export declare function makeIsDeferred(toolDefinitions: ReadonlyArray<{
|
|
|
45
45
|
*
|
|
46
46
|
* The original tool instances are never mutated. The marked entry is a
|
|
47
47
|
* shallow wrapper that preserves the prototype chain so downstream
|
|
48
|
-
* `instanceof` checks still pass. `extras` is merged
|
|
49
|
-
* `providerToolDefinition` / other extras
|
|
48
|
+
* `instanceof` checks still pass. For custom tools, `extras` is merged
|
|
49
|
+
* so any existing `providerToolDefinition` / other extras are kept.
|
|
50
50
|
*/
|
|
51
51
|
export declare function partitionAndMarkAnthropicToolCache(tools: GraphTools | undefined, isDeferred: (toolName: string) => boolean): GraphTools | undefined;
|
|
@@ -125,38 +125,88 @@ export type ToolEndEvent = {
|
|
|
125
125
|
index: number;
|
|
126
126
|
type?: 'tool_call';
|
|
127
127
|
};
|
|
128
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Closed set of resource kinds for sandbox file caching. Defined as a
|
|
130
|
+
* `as const` tuple so the runtime list and the TypeScript union can't
|
|
131
|
+
* drift on future additions — adding a new kind to the tuple updates
|
|
132
|
+
* both at once.
|
|
133
|
+
*
|
|
134
|
+
* - `skill`: shared per skill identity. Cross-user-within-tenant
|
|
135
|
+
* sharing. Codeapi sessionKey omits the user dimension. `version`
|
|
136
|
+
* is required (skill's monotonic counter scopes cache per revision).
|
|
137
|
+
* - `agent`: shared per agent identity. Same sharing semantic as
|
|
138
|
+
* skills.
|
|
139
|
+
* - `user`: user-private. Codeapi sessionKey is keyed by the
|
|
140
|
+
* requesting user from auth context. Used for chat attachments
|
|
141
|
+
* and code-output files.
|
|
142
|
+
*/
|
|
143
|
+
export declare const CODE_ENV_KINDS: readonly ["skill", "agent", "user"];
|
|
144
|
+
export type CodeEnvKind = (typeof CODE_ENV_KINDS)[number];
|
|
145
|
+
type CodeEnvFileBase = {
|
|
146
|
+
/**
|
|
147
|
+
* Resource identity. Semantics depend on `kind`:
|
|
148
|
+
* - `skill`: skill `_id` (sessionKey-meaningful, cross-user shared).
|
|
149
|
+
* - `agent`: agent id (sessionKey-meaningful, cross-user shared).
|
|
150
|
+
* - `user`: informational only — codeapi derives sessionKey from
|
|
151
|
+
* the auth-context user. Kept on the type for shape uniformity;
|
|
152
|
+
* do not rely on it for routing.
|
|
153
|
+
*/
|
|
129
154
|
id: string;
|
|
130
155
|
name: string;
|
|
131
|
-
session_id: string;
|
|
132
156
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* file plus a user attachment in the same call).
|
|
157
|
+
* Storage session — the long-lived bucket where this file's bytes
|
|
158
|
+
* live in object storage. Distinct from the (transient) execution
|
|
159
|
+
* session id that appears at the top level of an execute response;
|
|
160
|
+
* the two used to share the field name `session_id` and the
|
|
161
|
+
* conflation caused real bugs. See codeapi #1455 / agents #148.
|
|
139
162
|
*/
|
|
140
|
-
|
|
163
|
+
storage_session_id: string;
|
|
141
164
|
};
|
|
165
|
+
/**
|
|
166
|
+
* `CodeEnvFile` is a discriminated union on `kind`. `version` is
|
|
167
|
+
* statically required for `kind: 'skill'` and statically forbidden
|
|
168
|
+
* for `agent` / `user` — the constraint holds at compile time on
|
|
169
|
+
* every consumer, not just on codeapi's runtime validator.
|
|
170
|
+
*
|
|
171
|
+
* Codeapi switches on `kind` to derive the sessionKey for cache
|
|
172
|
+
* scoping (`<tenant>:<kind>:<id>[:v:<version>]`). Cross-user sharing
|
|
173
|
+
* for `kind: 'skill'` / `'agent'` is a designed property of the
|
|
174
|
+
* kind switch.
|
|
175
|
+
*/
|
|
176
|
+
export type CodeEnvFile = (CodeEnvFileBase & {
|
|
177
|
+
kind: 'skill';
|
|
178
|
+
version: number;
|
|
179
|
+
}) | (CodeEnvFileBase & {
|
|
180
|
+
kind: 'agent';
|
|
181
|
+
}) | (CodeEnvFileBase & {
|
|
182
|
+
kind: 'user';
|
|
183
|
+
});
|
|
142
184
|
export type CodeExecutionToolParams = undefined | {
|
|
185
|
+
/** Execution session — see `CodeSessionContext.session_id`. */
|
|
143
186
|
session_id?: string;
|
|
144
187
|
user_id?: string;
|
|
145
188
|
files?: CodeEnvFile[];
|
|
146
189
|
};
|
|
147
190
|
export type FileRef = {
|
|
191
|
+
/**
|
|
192
|
+
* Resource identity. Semantics depend on `kind` (when present):
|
|
193
|
+
* - `skill` / `agent`: shared resource id (sessionKey-meaningful).
|
|
194
|
+
* - `user`: informational only — codeapi derives sessionKey from
|
|
195
|
+
* the auth-context user. Do not rely on it for routing.
|
|
196
|
+
*/
|
|
148
197
|
id: string;
|
|
149
198
|
name: string;
|
|
150
199
|
path?: string;
|
|
151
|
-
/** Session ID this file belongs to (for multi-session file tracking) */
|
|
152
|
-
session_id?: string;
|
|
153
200
|
/**
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* `_injected_files` when a subsequent execute references a mix of
|
|
157
|
-
* files uploaded under different entities.
|
|
201
|
+
* Storage session this file lives in. See `CodeEnvFile.storage_session_id`
|
|
202
|
+
* for the full motivation.
|
|
158
203
|
*/
|
|
159
|
-
|
|
204
|
+
storage_session_id?: string;
|
|
205
|
+
/** Resource kind — see `CodeEnvFile.kind`. */
|
|
206
|
+
kind?: CodeEnvKind;
|
|
207
|
+
/** Resource version — see `CodeEnvFile.version`. Only meaningful when
|
|
208
|
+
* `kind === 'skill'`. */
|
|
209
|
+
version?: number;
|
|
160
210
|
/**
|
|
161
211
|
* `true` when the codeapi sandbox echoed this entry as an unchanged
|
|
162
212
|
* passthrough of an input the caller already owns (skill files,
|
|
@@ -169,6 +219,11 @@ export type FileRef = {
|
|
|
169
219
|
};
|
|
170
220
|
export type FileRefs = FileRef[];
|
|
171
221
|
export type ExecuteResult = {
|
|
222
|
+
/**
|
|
223
|
+
* Execution session id — the (transient) sandbox run that produced
|
|
224
|
+
* this output. Distinct from per-file `storage_session_id` on the
|
|
225
|
+
* files array.
|
|
226
|
+
*/
|
|
172
227
|
session_id: string;
|
|
173
228
|
stdout: string;
|
|
174
229
|
stderr: string;
|
|
@@ -224,6 +279,7 @@ export type ToolCallRequest = {
|
|
|
224
279
|
turn?: number;
|
|
225
280
|
/** Code execution session context for session continuity in event-driven mode */
|
|
226
281
|
codeSessionContext?: {
|
|
282
|
+
/** Execution session — see `CodeSessionContext.session_id`. */
|
|
227
283
|
session_id: string;
|
|
228
284
|
files?: CodeEnvFile[];
|
|
229
285
|
};
|
|
@@ -709,6 +765,7 @@ export type PTCToolResult = {
|
|
|
709
765
|
*/
|
|
710
766
|
export type ProgrammaticExecutionResponse = {
|
|
711
767
|
status: 'tool_call_required' | 'completed' | 'error' | unknown;
|
|
768
|
+
/** Execution session — see `CodeSessionContext.session_id`. */
|
|
712
769
|
session_id?: string;
|
|
713
770
|
/** Present when status='tool_call_required' */
|
|
714
771
|
continuation_token?: string;
|
|
@@ -724,6 +781,7 @@ export type ProgrammaticExecutionResponse = {
|
|
|
724
781
|
* Artifact returned by the PTC tool
|
|
725
782
|
*/
|
|
726
783
|
export type ProgrammaticExecutionArtifact = {
|
|
784
|
+
/** Execution session — see `CodeSessionContext.session_id`. */
|
|
727
785
|
session_id?: string;
|
|
728
786
|
files?: FileRefs;
|
|
729
787
|
};
|
|
@@ -749,7 +807,12 @@ export type ProgrammaticToolCallingParams = {
|
|
|
749
807
|
* Stored in Graph.sessions and injected into subsequent tool invocations.
|
|
750
808
|
*/
|
|
751
809
|
export type CodeSessionContext = {
|
|
752
|
-
/**
|
|
810
|
+
/**
|
|
811
|
+
* Execution session id — the (transient) sandbox run id. Used by
|
|
812
|
+
* ToolNode to thread session continuity into the next code-execution
|
|
813
|
+
* tool call. Distinct from per-file `storage_session_id` carried on
|
|
814
|
+
* `files`.
|
|
815
|
+
*/
|
|
753
816
|
session_id: string;
|
|
754
817
|
/** Files generated in this session (for context/tracking) */
|
|
755
818
|
files?: FileRefs;
|
|
@@ -761,6 +824,7 @@ export type CodeSessionContext = {
|
|
|
761
824
|
* Used to extract session context after tool completion.
|
|
762
825
|
*/
|
|
763
826
|
export type CodeExecutionArtifact = {
|
|
827
|
+
/** Execution session — see `CodeSessionContext.session_id`. */
|
|
764
828
|
session_id?: string;
|
|
765
829
|
files?: FileRefs;
|
|
766
830
|
};
|
|
@@ -774,3 +838,4 @@ export type ToolSessionContext = CodeSessionContext;
|
|
|
774
838
|
* Keys are tool constants (e.g., Constants.EXECUTE_CODE, Constants.PROGRAMMATIC_TOOL_CALLING).
|
|
775
839
|
*/
|
|
776
840
|
export type ToolSessionMap = Map<string, ToolSessionContext>;
|
|
841
|
+
export {};
|
package/package.json
CHANGED
|
@@ -4,7 +4,6 @@ import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
|
4
4
|
import type { BaseChatModelParams } from '@langchain/core/language_models/chat_models';
|
|
5
5
|
import type {
|
|
6
6
|
BaseMessage,
|
|
7
|
-
UsageMetadata,
|
|
8
7
|
MessageContentComplex,
|
|
9
8
|
} from '@langchain/core/messages';
|
|
10
9
|
import type { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
|
|
@@ -13,18 +12,13 @@ import type { Anthropic } from '@anthropic-ai/sdk';
|
|
|
13
12
|
import type {
|
|
14
13
|
AnthropicMessageCreateParams,
|
|
15
14
|
AnthropicStreamingMessageCreateParams,
|
|
16
|
-
AnthropicMessageStartEvent,
|
|
17
|
-
AnthropicMessageDeltaEvent,
|
|
18
15
|
AnthropicOutputConfig,
|
|
19
16
|
AnthropicBeta,
|
|
20
17
|
ChatAnthropicToolType,
|
|
21
18
|
AnthropicMCPServerURLDefinition,
|
|
22
19
|
AnthropicContextManagementConfigParam,
|
|
23
20
|
} from '@/llm/anthropic/types';
|
|
24
|
-
import {
|
|
25
|
-
_makeMessageChunkFromAnthropicEvent,
|
|
26
|
-
getAnthropicUsageMetadata,
|
|
27
|
-
} from './utils/message_outputs';
|
|
21
|
+
import { _makeMessageChunkFromAnthropicEvent } from './utils/message_outputs';
|
|
28
22
|
import { _convertMessagesToAnthropicPayload } from './utils/message_inputs';
|
|
29
23
|
import { handleToolChoice } from './utils/tools';
|
|
30
24
|
import { TextStream } from '@/llm/text';
|
|
@@ -53,13 +47,17 @@ export function _documentsInParams(
|
|
|
53
47
|
continue;
|
|
54
48
|
}
|
|
55
49
|
for (const block of message.content) {
|
|
50
|
+
const maybeBlock: unknown = block;
|
|
56
51
|
if (
|
|
57
|
-
typeof
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
typeof maybeBlock === 'object' &&
|
|
53
|
+
maybeBlock !== null &&
|
|
54
|
+
'type' in maybeBlock &&
|
|
55
|
+
maybeBlock.type === 'document' &&
|
|
56
|
+
'citations' in maybeBlock &&
|
|
57
|
+
maybeBlock.citations != null &&
|
|
58
|
+
typeof maybeBlock.citations === 'object' &&
|
|
59
|
+
'enabled' in maybeBlock.citations &&
|
|
60
|
+
maybeBlock.citations.enabled === true
|
|
63
61
|
) {
|
|
64
62
|
return true;
|
|
65
63
|
}
|
|
@@ -307,6 +305,30 @@ function cloneChunk(
|
|
|
307
305
|
return chunk;
|
|
308
306
|
}
|
|
309
307
|
|
|
308
|
+
function withIncrementalMessageDeltaUsage(
|
|
309
|
+
chunk: AIMessageChunk,
|
|
310
|
+
previousOutputTokens: number
|
|
311
|
+
): { chunk: AIMessageChunk; outputTokens: number } {
|
|
312
|
+
const usage = chunk.usage_metadata;
|
|
313
|
+
if (usage == null) {
|
|
314
|
+
return { chunk, outputTokens: previousOutputTokens };
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const outputTokens = Math.max(0, usage.output_tokens - previousOutputTokens);
|
|
318
|
+
return {
|
|
319
|
+
chunk: new AIMessageChunk(
|
|
320
|
+
Object.assign({}, chunk, {
|
|
321
|
+
usage_metadata: {
|
|
322
|
+
...usage,
|
|
323
|
+
output_tokens: outputTokens,
|
|
324
|
+
total_tokens: usage.input_tokens + outputTokens,
|
|
325
|
+
},
|
|
326
|
+
})
|
|
327
|
+
),
|
|
328
|
+
outputTokens: usage.output_tokens,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
310
332
|
export type CustomAnthropicInput = AnthropicInput & {
|
|
311
333
|
_lc_stream_delay?: number;
|
|
312
334
|
outputConfig?: AnthropicOutputConfig;
|
|
@@ -334,10 +356,7 @@ type CustomAnthropicInvocationParams = {
|
|
|
334
356
|
|
|
335
357
|
export class CustomAnthropic extends ChatAnthropicMessages {
|
|
336
358
|
_lc_stream_delay: number;
|
|
337
|
-
private message_start: AnthropicMessageStartEvent | undefined;
|
|
338
|
-
private message_delta: AnthropicMessageDeltaEvent | undefined;
|
|
339
359
|
private tools_in_params?: boolean;
|
|
340
|
-
private emitted_usage?: boolean;
|
|
341
360
|
top_k: number | undefined;
|
|
342
361
|
outputConfig?: AnthropicOutputConfig;
|
|
343
362
|
inferenceGeo?: string;
|
|
@@ -436,33 +455,7 @@ export class CustomAnthropic extends ChatAnthropicMessages {
|
|
|
436
455
|
};
|
|
437
456
|
}
|
|
438
457
|
|
|
439
|
-
/**
|
|
440
|
-
* Get stream usage as returned by this client's API response.
|
|
441
|
-
* @returns The stream usage object.
|
|
442
|
-
*/
|
|
443
|
-
getStreamUsage(): UsageMetadata | undefined {
|
|
444
|
-
if (this.emitted_usage === true) {
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
const inputUsage = this.message_start?.message.usage;
|
|
448
|
-
const outputUsage = this.message_delta?.usage;
|
|
449
|
-
if (!outputUsage) {
|
|
450
|
-
return;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
this.emitted_usage = true;
|
|
454
|
-
return getAnthropicUsageMetadata({
|
|
455
|
-
input_tokens: inputUsage?.input_tokens,
|
|
456
|
-
output_tokens: outputUsage.output_tokens,
|
|
457
|
-
cache_creation_input_tokens: inputUsage?.cache_creation_input_tokens,
|
|
458
|
-
cache_read_input_tokens: inputUsage?.cache_read_input_tokens,
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
|
|
462
458
|
resetTokenEvents(): void {
|
|
463
|
-
this.message_start = undefined;
|
|
464
|
-
this.message_delta = undefined;
|
|
465
|
-
this.emitted_usage = undefined;
|
|
466
459
|
this.tools_in_params = undefined;
|
|
467
460
|
}
|
|
468
461
|
|
|
@@ -484,17 +477,13 @@ export class CustomAnthropic extends ChatAnthropicMessages {
|
|
|
484
477
|
private createGenerationChunk({
|
|
485
478
|
token,
|
|
486
479
|
chunk,
|
|
487
|
-
usageMetadata,
|
|
488
480
|
shouldStreamUsage,
|
|
489
481
|
}: {
|
|
490
482
|
token?: string;
|
|
491
483
|
chunk: AIMessageChunk;
|
|
492
484
|
shouldStreamUsage: boolean;
|
|
493
|
-
usageMetadata?: UsageMetadata;
|
|
494
485
|
}): ChatGenerationChunk {
|
|
495
|
-
const usage_metadata = shouldStreamUsage
|
|
496
|
-
? (usageMetadata ?? chunk.usage_metadata)
|
|
497
|
-
: undefined;
|
|
486
|
+
const usage_metadata = shouldStreamUsage ? chunk.usage_metadata : undefined;
|
|
498
487
|
return new ChatGenerationChunk({
|
|
499
488
|
message: new AIMessageChunk({
|
|
500
489
|
// Just yield chunk as it is and tool_use will be concat by BaseChatModel._generateUncached().
|
|
@@ -534,6 +523,7 @@ export class CustomAnthropic extends ChatAnthropicMessages {
|
|
|
534
523
|
});
|
|
535
524
|
|
|
536
525
|
const shouldStreamUsage = options.streamUsage ?? this.streamUsage;
|
|
526
|
+
let messageDeltaOutputTokens = 0;
|
|
537
527
|
|
|
538
528
|
for await (const data of stream) {
|
|
539
529
|
if (options.signal?.aborted === true) {
|
|
@@ -541,17 +531,6 @@ export class CustomAnthropic extends ChatAnthropicMessages {
|
|
|
541
531
|
throw new Error('AbortError: User aborted the request.');
|
|
542
532
|
}
|
|
543
533
|
|
|
544
|
-
if (data.type === 'message_start') {
|
|
545
|
-
this.message_start = data as AnthropicMessageStartEvent;
|
|
546
|
-
} else if (data.type === 'message_delta') {
|
|
547
|
-
this.message_delta = data as AnthropicMessageDeltaEvent;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
let usageMetadata: UsageMetadata | undefined;
|
|
551
|
-
if (this.tools_in_params !== true && this.emitted_usage !== true) {
|
|
552
|
-
usageMetadata = this.getStreamUsage();
|
|
553
|
-
}
|
|
554
|
-
|
|
555
534
|
const result = _makeMessageChunkFromAnthropicEvent(
|
|
556
535
|
data as Anthropic.Beta.Messages.BetaRawMessageStreamEvent,
|
|
557
536
|
{
|
|
@@ -561,18 +540,25 @@ export class CustomAnthropic extends ChatAnthropicMessages {
|
|
|
561
540
|
);
|
|
562
541
|
if (!result) continue;
|
|
563
542
|
|
|
564
|
-
|
|
543
|
+
let { chunk } = result;
|
|
544
|
+
if (data.type === 'message_delta') {
|
|
545
|
+
const incremental = withIncrementalMessageDeltaUsage(
|
|
546
|
+
chunk,
|
|
547
|
+
messageDeltaOutputTokens
|
|
548
|
+
);
|
|
549
|
+
chunk = incremental.chunk;
|
|
550
|
+
messageDeltaOutputTokens = incremental.outputTokens;
|
|
551
|
+
}
|
|
565
552
|
const [token = '', tokenType] = extractToken(chunk);
|
|
566
553
|
|
|
567
554
|
if (
|
|
568
555
|
!tokenType ||
|
|
569
556
|
tokenType === 'input' ||
|
|
570
|
-
(token === '' && (
|
|
557
|
+
(token === '' && (chunk.usage_metadata != null || chunk.id != null))
|
|
571
558
|
) {
|
|
572
559
|
const generationChunk = this.createGenerationChunk({
|
|
573
560
|
token,
|
|
574
561
|
chunk,
|
|
575
|
-
usageMetadata,
|
|
576
562
|
shouldStreamUsage,
|
|
577
563
|
});
|
|
578
564
|
yield generationChunk;
|
|
@@ -602,15 +588,20 @@ export class CustomAnthropic extends ChatAnthropicMessages {
|
|
|
602
588
|
break;
|
|
603
589
|
}
|
|
604
590
|
const newChunk = cloneChunk(currentToken, tokenType, chunk);
|
|
591
|
+
const chunkForToken =
|
|
592
|
+
emittedUsage && newChunk.usage_metadata != null
|
|
593
|
+
? new AIMessageChunk(
|
|
594
|
+
Object.assign({}, newChunk, { usage_metadata: undefined })
|
|
595
|
+
)
|
|
596
|
+
: newChunk;
|
|
605
597
|
|
|
606
598
|
const generationChunk = this.createGenerationChunk({
|
|
607
599
|
token: currentToken,
|
|
608
|
-
chunk:
|
|
609
|
-
usageMetadata: emittedUsage ? undefined : usageMetadata,
|
|
600
|
+
chunk: chunkForToken,
|
|
610
601
|
shouldStreamUsage,
|
|
611
602
|
});
|
|
612
603
|
|
|
613
|
-
if (
|
|
604
|
+
if (newChunk.usage_metadata != null && !emittedUsage) {
|
|
614
605
|
emittedUsage = true;
|
|
615
606
|
}
|
|
616
607
|
yield generationChunk;
|