@averyyy/pi-coding-agent 1.0.4-piclient.2 → 1.1.0-piclient.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/dist/bundle/chunks/{anthropic-messages-K2IO6UO3.js → anthropic-messages-VWV2LQLU.js} +1 -1
- package/dist/bundle/chunks/anthropic.js +1 -1
- package/dist/bundle/chunks/{azure-openai-responses-NHLW5JRZ.js → azure-openai-responses-TJZBTKRM.js} +1 -1
- package/dist/bundle/chunks/bedrock-converse-stream.js +2 -2
- package/dist/bundle/chunks/{chunk-AEYCEUYN.js → chunk-2DXGY63V.js} +3 -3
- package/dist/bundle/chunks/{chunk-CSX55THN.js → chunk-4QEUO5LF.js} +3 -3
- package/dist/bundle/chunks/{chunk-EJGEBBJH.js → chunk-ATAYHPRT.js} +74 -66
- package/dist/bundle/chunks/chunk-G7JAXKAE.js +11 -0
- package/dist/bundle/chunks/{chunk-44C62PJ2.js → chunk-IHNTZDOC.js} +1 -1
- package/dist/bundle/chunks/{chunk-O33PDY7S.js → chunk-JPAIS7JS.js} +1 -1
- package/dist/bundle/chunks/{chunk-T5R6KALE.js → chunk-KE3SIIQZ.js} +1 -1
- package/dist/bundle/chunks/{chunk-5JWYRNJY.js → chunk-L2QJRZTO.js} +1 -1
- package/dist/bundle/chunks/chunk-LPXNMA2W.js +2 -0
- package/dist/bundle/chunks/chunk-LQELYOUU.js +2 -0
- package/dist/bundle/chunks/chunk-M6HKFBHF.js +2 -0
- package/dist/bundle/chunks/chunk-MFRJR46A.js +2 -0
- package/dist/bundle/chunks/{chunk-LD2P6SFZ.js → chunk-PMRZO46Y.js} +1 -1
- package/dist/bundle/chunks/chunk-QEAD7ZDM.js +82 -0
- package/dist/bundle/chunks/{chunk-BASBVYQV.js → chunk-SJAIFNJC.js} +1 -1
- package/dist/bundle/chunks/{chunk-S6UOZSLC.js → chunk-WMAKGH2U.js} +3 -3
- package/dist/bundle/chunks/{chunk-2AJMIBDW.js → chunk-XJNJKWWG.js} +3 -3
- package/dist/bundle/chunks/{cli-OLBSEIG4.js → cli-G46DCMLG.js} +2 -2
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-TXNQKF7U.js +2 -0
- package/dist/bundle/chunks/codemode-worker.js +2 -2
- package/dist/bundle/chunks/devin-runtime.js +1 -1
- package/dist/bundle/chunks/{easter-egg-3d-XLWVR7B5.js → easter-egg-3d-VPOZMPG6.js} +1 -1
- package/dist/bundle/chunks/{execute-JUL3TNKC.js → execute-W7LFAU5T.js} +11 -5
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/{google-generative-ai-RDSM3DET.js → google-generative-ai-MU3HY65Y.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-IAA22EFU.js → google-vertex-4KLEFGPG.js} +1 -1
- package/dist/bundle/chunks/image-resize-worker.js +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-XT44PI3C.js → llama-cpp-classify-FYN623RH.js} +2 -2
- package/dist/bundle/chunks/{mistral-conversations-ZP3T32V3.js → mistral-conversations-QSGGIXSP.js} +2 -2
- package/dist/bundle/chunks/openai-chatgpt.js +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-SNUYQ3OP.js → openai-codex-responses-XHPOB5DF.js} +2 -2
- package/dist/bundle/chunks/openai-codex.js +1 -1
- package/dist/bundle/chunks/{openai-completions-PZGVLXR5.js → openai-completions-IIJZEEG4.js} +1 -1
- package/dist/bundle/chunks/openai-decisions-7HAB4DS5.js +5 -0
- package/dist/bundle/chunks/{openai-responses-VIKEOSVV.js → openai-responses-27B2XLS7.js} +1 -1
- package/dist/bundle/chunks/{openrouter-images-ZVXWCSIM.js → openrouter-images-DUPG5DZO.js} +1 -1
- package/dist/bundle/chunks/{pi-messages-TM5SOOIW.js → pi-messages-YHKPQIHC.js} +1 -1
- package/dist/bundle/chunks/{runtime-BBIT3FW5.js → runtime-PVOHGROZ.js} +1 -1
- package/dist/bundle/chunks/typesafe-system-one-JIF5KZZR.js +2 -0
- package/dist/bundle/chunks/{virtual-modules-YOBUQRP7.js → virtual-modules-6AQQJ6OW.js} +1 -1
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/args.d.ts +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +13 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-session.d.ts +7 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +12 -7
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +40 -45
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +2 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/types.d.ts +11 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +2 -1
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/nested-tool-calls.d.ts +1 -0
- package/dist/core/nested-tool-calls.d.ts.map +1 -1
- package/dist/core/nested-tool-calls.js +1 -0
- package/dist/core/nested-tool-calls.js.map +1 -1
- package/dist/core/pi-server-client.d.ts +2 -4
- package/dist/core/pi-server-client.d.ts.map +1 -1
- package/dist/core/pi-server-client.js +2 -13
- package/dist/core/pi-server-client.js.map +1 -1
- package/dist/core/sdk.d.ts +4 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +17 -5
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +13 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +37 -13
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +8 -3
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/renderers/bash.d.ts.map +1 -1
- package/dist/core/tools/renderers/bash.js +8 -3
- package/dist/core/tools/renderers/bash.js.map +1 -1
- package/dist/core/tools/renderers/edit.d.ts.map +1 -1
- package/dist/core/tools/renderers/edit.js +5 -4
- package/dist/core/tools/renderers/edit.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +63 -7
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/codemode/tool.js +2 -2
- package/dist/extensions/codemode/tool.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +34 -11
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/extensions/mcp/cli.js +17 -23
- package/dist/extensions/mcp/cli.js.map +1 -1
- package/dist/extensions/mcp/index.d.ts.map +1 -1
- package/dist/extensions/mcp/index.js +165 -64
- package/dist/extensions/mcp/index.js.map +1 -1
- package/dist/extensions/mcp/oauth.d.ts +5 -3
- package/dist/extensions/mcp/oauth.d.ts.map +1 -1
- package/dist/extensions/mcp/oauth.js +36 -10
- package/dist/extensions/mcp/oauth.js.map +1 -1
- package/dist/extensions/mcp/ui.d.ts +3 -3
- package/dist/extensions/mcp/ui.d.ts.map +1 -1
- package/dist/extensions/mcp/ui.js +10 -2
- package/dist/extensions/mcp/ui.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +5 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +17 -14
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts +2 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.js +5 -2
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +2 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.js +5 -2
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/custom-entry.d.ts +3 -1
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-entry.js +8 -2
- package/dist/modes/interactive/components/custom-entry.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +1 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +1 -1
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +2 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.js +5 -2
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +5 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +10 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +2 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +50 -29
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/program-status-reporter.d.ts +34 -0
- package/dist/modes/interactive/program-status-reporter.d.ts.map +1 -0
- package/dist/modes/interactive/program-status-reporter.js +110 -0
- package/dist/modes/interactive/program-status-reporter.js.map +1 -0
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +24 -0
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/ansi.d.ts +8 -0
- package/dist/utils/ansi.d.ts.map +1 -1
- package/dist/utils/ansi.js +30 -11
- package/dist/utils/ansi.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +12 -11
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/image-resize-core.d.ts +12 -0
- package/dist/utils/image-resize-core.d.ts.map +1 -1
- package/dist/utils/image-resize-core.js +5 -0
- package/dist/utils/image-resize-core.js.map +1 -1
- package/dist/utils/image-resize-worker.js +3 -2
- package/dist/utils/image-resize-worker.js.map +1 -1
- package/dist/utils/image-resize.d.ts.map +1 -1
- package/dist/utils/image-resize.js +9 -10
- package/dist/utils/image-resize.js.map +1 -1
- package/docs/cli.md +4 -4
- package/docs/codemode.md +23 -3
- package/docs/environment-variables.md +1 -0
- package/docs/json.md +3 -3
- package/docs/llama-cpp.md +8 -1
- package/docs/message-types.md +22 -4
- package/docs/models.md +4 -1
- package/docs/providers.md +27 -0
- package/docs/settings.md +3 -3
- package/docs/terminal-setup.md +14 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +12 -12
- package/dist/bundle/chunks/chunk-A3JYRWB6.js +0 -2
- package/dist/bundle/chunks/chunk-CQ233VQM.js +0 -82
- package/dist/bundle/chunks/chunk-J43OEKXQ.js +0 -2
- package/dist/bundle/chunks/chunk-RUCGJH5V.js +0 -11
- package/dist/bundle/chunks/chunk-XBLMUBBW.js +0 -2
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-L4GFVN6I.js +0 -2
- package/dist/bundle/chunks/typesafe-system-one-ZZ2PGRBM.js +0 -2
|
@@ -1 +1 @@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ACd,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,gBAAgB,EAAE,QAAQ;SAC1B,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,iFAAiF;IACjF,UAAU,CAAC,UAAkB;QAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC/B,IAAI,CAAC,KAAK;YAAE,OAAO,SAAS,CAAC;QAC7B,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IAC/E,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACD","sourcesContent":["/**\n * Tool calls that a tool makes while it runs (`ctx.executeTool()`), for example from codemode\n * scripts. The agent loop does not know about them: the session runs each one through the agent's\n * tool pipeline (`runToolCall`) with its own hooks, emits `tool_execution_*` events with\n * `parentToolCallId`, and records the calls and their usage on the model-issued call's tool result\n * message.\n *\n * Nothing here runs until a tool calls `ctx.executeTool()`.\n */\n\nimport type {\n\tAgentTool,\n\tAgentToolCall,\n\tAgentToolCallOutcome,\n\tAgentToolResult,\n\tAgentToolUpdateCallback,\n} from \"@earendil-works/pi-agent-core\";\nimport type { JsonObject, NestedToolCallRecord, NestedToolCalls, TextContent, Usage } from \"@earendil-works/pi-ai\";\nimport { combineUsage } from \"./usage-totals.ts\";\n\n/**\n * Limits of the nested-call record on a tool result: arguments\n * over the per-call or total size are omitted, calls beyond the count are dropped, and the record\n * is marked incomplete when any of that happens.\n */\nexport const NESTED_CALL_LIMITS = {\n\tmaxCalls: 256,\n\tmaxArgumentBytesPerCall: 8 * 1024,\n\tmaxArgumentBytesTotal: 32 * 1024,\n\tmaxErrorChars: 500,\n} as const;\n\nconst encoder = new TextEncoder();\n\n/** What the nested calls of one model-issued tool call leave on its tool result message. */\nexport interface NestedCallSummary {\n\t/** Becomes `nestedCalls`. Undefined when no nested call was made. */\n\tcalls: NestedToolCalls | undefined;\n\t/** Summed `usage` of the nested results, added to the message's `usage`. */\n\tusage: Usage | undefined;\n}\n\n/**\n * Collects the nested calls of one model-issued tool call, including calls made by nested tools.\n * The snapshot becomes `nestedCalls` on the tool result message.\n */\nexport class NestedCallRecorder {\n\tprivate readonly calls: NestedToolCallRecord[] = [];\n\tprivate readonly startedAt = new Map<NestedToolCallRecord, number>();\n\tprivate complete = true;\n\tprivate argumentBytes = 0;\n\t/** Summed usage of every nested result, including calls dropped from the record. */\n\tprivate usage: Usage | undefined;\n\n\t/** Record a call as it starts. Returns undefined when the call is dropped. */\n\tstart(toolCall: AgentToolCall): NestedToolCallRecord | undefined {\n\t\tif (this.calls.length >= NESTED_CALL_LIMITS.maxCalls) {\n\t\t\tthis.complete = false;\n\t\t\treturn undefined;\n\t\t}\n\t\tconst record: NestedToolCallRecord = { id: toolCall.id, name: toolCall.name, status: \"unfinished\" };\n\t\tconst json = JSON.stringify(toolCall.arguments ?? {});\n\t\tconst bytes = encoder.encode(json).length;\n\t\tif (\n\t\t\tbytes > NESTED_CALL_LIMITS.maxArgumentBytesPerCall ||\n\t\t\tthis.argumentBytes + bytes > NESTED_CALL_LIMITS.maxArgumentBytesTotal\n\t\t) {\n\t\t\trecord.argumentsBytes = bytes;\n\t\t\tthis.complete = false;\n\t\t} else {\n\t\t\trecord.arguments = JSON.parse(json) as JsonObject;\n\t\t\tthis.argumentBytes += bytes;\n\t\t}\n\t\tthis.calls.push(record);\n\t\tthis.startedAt.set(record, performance.now());\n\t\treturn record;\n\t}\n\n\tfinish(record: NestedToolCallRecord | undefined, isError: boolean, errorText: string): void {\n\t\tif (!record) return;\n\t\trecord.status = isError ? \"error\" : \"ok\";\n\t\trecord.durationMs = Math.round(performance.now() - (this.startedAt.get(record) ?? performance.now()));\n\t\tthis.startedAt.delete(record);\n\t\tif (isError && errorText) record.error = errorText.slice(0, NESTED_CALL_LIMITS.maxErrorChars);\n\t}\n\n\taddUsage(usage: Usage): void {\n\t\tthis.usage = this.usage ? combineUsage(this.usage, usage) : usage;\n\t}\n\n\tget totalUsage(): Usage | undefined {\n\t\treturn this.usage;\n\t}\n\n\t/** Copy of the record so far, or undefined when no nested call was made. */\n\tsnapshot(): NestedToolCalls | undefined {\n\t\tif (this.calls.length === 0 && this.complete) return undefined;\n\t\tconst calls = this.calls.map((call) => ({ ...call }));\n\t\treturn { calls, complete: this.complete && calls.every((call) => call.status !== \"unfinished\") };\n\t}\n}\n\nexport interface NestedToolCallOptions {\n\t/** Defaults to the calling tool's signal. */\n\tsignal?: AbortSignal;\n\t/** Receives partial results of the nested tool, in addition to `tool_execution_update` events. */\n\tonUpdate?: AgentToolUpdateCallback;\n}\n\n/** `tool_execution_*` events of nested calls. */\nexport type NestedToolExecutionEvent =\n\t| { type: \"tool_execution_start\"; toolCallId: string; toolName: string; args: unknown; parentToolCallId: string }\n\t| {\n\t\t\ttype: \"tool_execution_update\";\n\t\t\ttoolCallId: string;\n\t\t\ttoolName: string;\n\t\t\targs: unknown;\n\t\t\tpartialResult: AgentToolResult<unknown>;\n\t\t\tparentToolCallId: string;\n\t }\n\t| {\n\t\t\ttype: \"tool_execution_end\";\n\t\t\ttoolCallId: string;\n\t\t\ttoolName: string;\n\t\t\tresult: AgentToolResult<unknown>;\n\t\t\tisError: boolean;\n\t\t\tparentToolCallId: string;\n\t };\n\nexport interface NestedToolCallHost {\n\t/** Tools nested calls resolve against. */\n\tgetTools(): readonly AgentTool[];\n\t/** Whether every nested call runs exclusively, as when the agent executes tool calls sequentially. */\n\tisSequential(): boolean;\n\t/** Run the call through the tool pipeline, with hooks that report `parentToolCallId`. */\n\trunToolCall(\n\t\ttoolCall: AgentToolCall,\n\t\tparentToolCallId: string,\n\t\tsignal: AbortSignal | undefined,\n\t\tonUpdate: (partialResult: AgentToolResult<unknown>) => Promise<void>,\n\t): Promise<AgentToolCallOutcome>;\n\temit(event: NestedToolExecutionEvent): Promise<void>;\n}\n\n/** Calls below one model-issued call share its recorder. */\ninterface CallScope {\n\trecorder: NestedCallRecorder;\n\tnextId: number;\n\t/** Set inside a call that holds the exclusive queue, so its own nested calls do not wait on it. */\n\tholdsQueue: boolean;\n}\n\nfunction textOf(result: AgentToolResult<unknown>): string {\n\treturn (result.content ?? [])\n\t\t.filter((block): block is TextContent => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(\"\\n\");\n}\n\nexport class NestedToolCallRunner {\n\tprivate readonly host: NestedToolCallHost;\n\t/** Scopes by the id of the calling tool call. */\n\tprivate readonly scopes = new Map<string, CallScope>();\n\t/** Serializes nested calls that must not run concurrently. */\n\tprivate queueTail: Promise<void> = Promise.resolve();\n\n\tconstructor(host: NestedToolCallHost) {\n\t\tthis.host = host;\n\t}\n\n\t/**\n\t * Run `name` on behalf of the call `callerId`. The nested call gets the id `<callerId>/<n>`.\n\t * Never rejects for tool failures: they come back as `isError: true`.\n\t */\n\tasync execute(\n\t\tcallerId: string,\n\t\tname: string,\n\t\targs: unknown,\n\t\toptions: NestedToolCallOptions = {},\n\t): Promise<AgentToolCallOutcome> {\n\t\tlet scope = this.scopes.get(callerId);\n\t\tif (!scope) {\n\t\t\tscope = { recorder: new NestedCallRecorder(), nextId: 1, holdsQueue: false };\n\t\t\tthis.scopes.set(callerId, scope);\n\t\t}\n\t\tconst toolCall: AgentToolCall = {\n\t\t\ttype: \"toolCall\",\n\t\t\tid: `${callerId}/${scope.nextId++}`,\n\t\t\tname,\n\t\t\targuments: (args ?? {}) as AgentToolCall[\"arguments\"],\n\t\t};\n\t\tconst record = scope.recorder.start(toolCall);\n\t\tawait this.host.emit({\n\t\t\ttype: \"tool_execution_start\",\n\t\t\ttoolCallId: toolCall.id,\n\t\t\ttoolName: name,\n\t\t\targs: toolCall.arguments,\n\t\t\tparentToolCallId: callerId,\n\t\t});\n\n\t\tconst exclusive =\n\t\t\t!scope.holdsQueue &&\n\t\t\t(this.host.isSequential() ||\n\t\t\t\tthis.host.getTools().find((tool) => tool.name === name)?.executionMode === \"sequential\");\n\t\tlet release: (() => void) | undefined;\n\t\tif (exclusive) {\n\t\t\tconst previous = this.queueTail;\n\t\t\tthis.queueTail = new Promise((resolve) => {\n\t\t\t\trelease = resolve;\n\t\t\t});\n\t\t\tawait previous;\n\t\t}\n\t\tthis.scopes.set(toolCall.id, {\n\t\t\trecorder: scope.recorder,\n\t\t\tnextId: 1,\n\t\t\tholdsQueue: scope.holdsQueue || exclusive,\n\t\t});\n\t\tlet outcome: AgentToolCallOutcome;\n\t\ttry {\n\t\t\toutcome = await this.host.runToolCall(toolCall, callerId, options.signal, async (partialResult) => {\n\t\t\t\toptions.onUpdate?.(partialResult);\n\t\t\t\tawait this.host.emit({\n\t\t\t\t\ttype: \"tool_execution_update\",\n\t\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\t\ttoolName: name,\n\t\t\t\t\targs: toolCall.arguments,\n\t\t\t\t\tpartialResult,\n\t\t\t\t\tparentToolCallId: callerId,\n\t\t\t\t});\n\t\t\t});\n\t\t} finally {\n\t\t\tthis.scopes.delete(toolCall.id);\n\t\t\trelease?.();\n\t\t}\n\n\t\tscope.recorder.finish(record, outcome.isError, textOf(outcome.result));\n\t\t// Nested results are not persisted, so their usage is only counted through the recorder.\n\t\tif (outcome.result.usage) scope.recorder.addUsage(outcome.result.usage);\n\t\tawait this.host.emit({\n\t\t\ttype: \"tool_execution_end\",\n\t\t\ttoolCallId: toolCall.id,\n\t\t\ttoolName: name,\n\t\t\tresult: outcome.result,\n\t\t\tisError: outcome.isError,\n\t\t\tparentToolCallId: callerId,\n\t\t});\n\t\treturn outcome;\n\t}\n\n\t/** Remove and return the record of the nested calls a model-issued call made. */\n\ttakeRecord(toolCallId: string): NestedCallSummary | undefined {\n\t\tconst scope = this.scopes.get(toolCallId);\n\t\tthis.scopes.delete(toolCallId);\n\t\tif (!scope) return undefined;\n\t\treturn { calls: scope.recorder.snapshot(), usage: scope.recorder.totalUsage };\n\t}\n\n\tclear(): void {\n\t\tthis.scopes.clear();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"nested-tool-calls.js","sourceRoot":"","sources":["../../src/core/nested-tool-calls.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAUH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IACjC,QAAQ,EAAE,GAAG;IACb,uBAAuB,EAAE,CAAC,GAAG,IAAI;IACjC,qBAAqB,EAAE,EAAE,GAAG,IAAI;IAChC,aAAa,EAAE,GAAG;CACT,CAAC;AAEX,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAUlC;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IACb,KAAK,GAA2B,EAAE,CAAC;IACnC,SAAS,GAAG,IAAI,GAAG,EAAgC,CAAC;IAC7D,QAAQ,GAAG,IAAI,CAAC;IAChB,aAAa,GAAG,CAAC,CAAC;IAC1B,oFAAoF;IAC5E,KAAK,CAAoB;IAEjC,8EAA8E;IAC9E,KAAK,CAAC,QAAuB;QAC5B,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,kBAAkB,CAAC,QAAQ,EAAE,CAAC;YACtD,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;YACtB,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,MAAM,MAAM,GAAyB,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;QACpG,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;QACtD,MAAM,KAAK,GAAG,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AAC,KAAK,CAAC,CAAC;QACxE,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACpB,IAAI,EAAE,oBAAoB;YAC1B,UAAU,EAAE,QAAQ,CAAC,EAAE;YACvB,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,GAAG,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;YAC/E,gBAAgB,EAAE,QAAQ;SAC1B,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,iFAAiF;IACjF,UAAU,CAAC,UAAkB;QAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC/B,IAAI,CAAC,KAAK;YAAE,OAAO,SAAS,CAAC;QAC7B,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IAC/E,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACD","sourcesContent":["/**\n * Tool calls that a tool makes while it runs (`ctx.executeTool()`), for example from codemode\n * scripts. The agent loop does not know about them: the session runs each one through the agent's\n * tool pipeline (`runToolCall`) with its own hooks, emits `tool_execution_*` events with\n * `parentToolCallId`, and records the calls and their usage on the model-issued call's tool result\n * message.\n *\n * Nothing here runs until a tool calls `ctx.executeTool()`.\n */\n\nimport type {\n\tAgentTool,\n\tAgentToolCall,\n\tAgentToolCallOutcome,\n\tAgentToolResult,\n\tAgentToolUpdateCallback,\n} from \"@earendil-works/pi-agent-core\";\nimport type { JsonObject, NestedToolCallRecord, NestedToolCalls, TextContent, Usage } from \"@earendil-works/pi-ai\";\nimport { combineUsage } from \"./usage-totals.ts\";\n\n/**\n * Limits of the nested-call record on a tool result: arguments\n * over the per-call or total size are omitted, calls beyond the count are dropped, and the record\n * is marked incomplete when any of that happens.\n */\nexport const NESTED_CALL_LIMITS = {\n\tmaxCalls: 256,\n\tmaxArgumentBytesPerCall: 8 * 1024,\n\tmaxArgumentBytesTotal: 32 * 1024,\n\tmaxErrorChars: 500,\n} as const;\n\nconst encoder = new TextEncoder();\n\n/** What the nested calls of one model-issued tool call leave on its tool result message. */\nexport interface NestedCallSummary {\n\t/** Becomes `nestedCalls`. Undefined when no nested call was made. */\n\tcalls: NestedToolCalls | undefined;\n\t/** Summed `usage` of the nested results, added to the message's `usage`. */\n\tusage: Usage | undefined;\n}\n\n/**\n * Collects the nested calls of one model-issued tool call, including calls made by nested tools.\n * The snapshot becomes `nestedCalls` on the tool result message.\n */\nexport class NestedCallRecorder {\n\tprivate readonly calls: NestedToolCallRecord[] = [];\n\tprivate readonly startedAt = new Map<NestedToolCallRecord, number>();\n\tprivate complete = true;\n\tprivate argumentBytes = 0;\n\t/** Summed usage of every nested result, including calls dropped from the record. */\n\tprivate usage: Usage | undefined;\n\n\t/** Record a call as it starts. Returns undefined when the call is dropped. */\n\tstart(toolCall: AgentToolCall): NestedToolCallRecord | undefined {\n\t\tif (this.calls.length >= NESTED_CALL_LIMITS.maxCalls) {\n\t\t\tthis.complete = false;\n\t\t\treturn undefined;\n\t\t}\n\t\tconst record: NestedToolCallRecord = { id: toolCall.id, name: toolCall.name, status: \"unfinished\" };\n\t\tconst json = JSON.stringify(toolCall.arguments ?? {});\n\t\tconst bytes = encoder.encode(json).length;\n\t\tif (\n\t\t\tbytes > NESTED_CALL_LIMITS.maxArgumentBytesPerCall ||\n\t\t\tthis.argumentBytes + bytes > NESTED_CALL_LIMITS.maxArgumentBytesTotal\n\t\t) {\n\t\t\trecord.argumentsBytes = bytes;\n\t\t\tthis.complete = false;\n\t\t} else {\n\t\t\trecord.arguments = JSON.parse(json) as JsonObject;\n\t\t\tthis.argumentBytes += bytes;\n\t\t}\n\t\tthis.calls.push(record);\n\t\tthis.startedAt.set(record, performance.now());\n\t\treturn record;\n\t}\n\n\tfinish(record: NestedToolCallRecord | undefined, isError: boolean, errorText: string): void {\n\t\tif (!record) return;\n\t\trecord.status = isError ? \"error\" : \"ok\";\n\t\trecord.durationMs = Math.round(performance.now() - (this.startedAt.get(record) ?? performance.now()));\n\t\tthis.startedAt.delete(record);\n\t\tif (isError && errorText) record.error = errorText.slice(0, NESTED_CALL_LIMITS.maxErrorChars);\n\t}\n\n\taddUsage(usage: Usage): void {\n\t\tthis.usage = this.usage ? combineUsage(this.usage, usage) : usage;\n\t}\n\n\tget totalUsage(): Usage | undefined {\n\t\treturn this.usage;\n\t}\n\n\t/** Copy of the record so far, or undefined when no nested call was made. */\n\tsnapshot(): NestedToolCalls | undefined {\n\t\tif (this.calls.length === 0 && this.complete) return undefined;\n\t\tconst calls = this.calls.map((call) => ({ ...call }));\n\t\treturn { calls, complete: this.complete && calls.every((call) => call.status !== \"unfinished\") };\n\t}\n}\n\nexport interface NestedToolCallOptions {\n\t/** Defaults to the calling tool's signal. */\n\tsignal?: AbortSignal;\n\t/** Receives partial results of the nested tool, in addition to `tool_execution_update` events. */\n\tonUpdate?: AgentToolUpdateCallback;\n}\n\n/** `tool_execution_*` events of nested calls. */\nexport type NestedToolExecutionEvent =\n\t| { type: \"tool_execution_start\"; toolCallId: string; toolName: string; args: unknown; parentToolCallId: string }\n\t| {\n\t\t\ttype: \"tool_execution_update\";\n\t\t\ttoolCallId: string;\n\t\t\ttoolName: string;\n\t\t\targs: unknown;\n\t\t\tpartialResult: AgentToolResult<unknown>;\n\t\t\tparentToolCallId: string;\n\t }\n\t| {\n\t\t\ttype: \"tool_execution_end\";\n\t\t\ttoolCallId: string;\n\t\t\ttoolName: string;\n\t\t\tresult: AgentToolResult<unknown>;\n\t\t\tisError: boolean;\n\t\t\tdurationMs?: number;\n\t\t\tparentToolCallId: string;\n\t };\n\nexport interface NestedToolCallHost {\n\t/** Tools nested calls resolve against. */\n\tgetTools(): readonly AgentTool[];\n\t/** Whether every nested call runs exclusively, as when the agent executes tool calls sequentially. */\n\tisSequential(): boolean;\n\t/** Run the call through the tool pipeline, with hooks that report `parentToolCallId`. */\n\trunToolCall(\n\t\ttoolCall: AgentToolCall,\n\t\tparentToolCallId: string,\n\t\tsignal: AbortSignal | undefined,\n\t\tonUpdate: (partialResult: AgentToolResult<unknown>) => Promise<void>,\n\t): Promise<AgentToolCallOutcome>;\n\temit(event: NestedToolExecutionEvent): Promise<void>;\n}\n\n/** Calls below one model-issued call share its recorder. */\ninterface CallScope {\n\trecorder: NestedCallRecorder;\n\tnextId: number;\n\t/** Set inside a call that holds the exclusive queue, so its own nested calls do not wait on it. */\n\tholdsQueue: boolean;\n}\n\nfunction textOf(result: AgentToolResult<unknown>): string {\n\treturn (result.content ?? [])\n\t\t.filter((block): block is TextContent => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(\"\\n\");\n}\n\nexport class NestedToolCallRunner {\n\tprivate readonly host: NestedToolCallHost;\n\t/** Scopes by the id of the calling tool call. */\n\tprivate readonly scopes = new Map<string, CallScope>();\n\t/** Serializes nested calls that must not run concurrently. */\n\tprivate queueTail: Promise<void> = Promise.resolve();\n\n\tconstructor(host: NestedToolCallHost) {\n\t\tthis.host = host;\n\t}\n\n\t/**\n\t * Run `name` on behalf of the call `callerId`. The nested call gets the id `<callerId>/<n>`.\n\t * Never rejects for tool failures: they come back as `isError: true`.\n\t */\n\tasync execute(\n\t\tcallerId: string,\n\t\tname: string,\n\t\targs: unknown,\n\t\toptions: NestedToolCallOptions = {},\n\t): Promise<AgentToolCallOutcome> {\n\t\tlet scope = this.scopes.get(callerId);\n\t\tif (!scope) {\n\t\t\tscope = { recorder: new NestedCallRecorder(), nextId: 1, holdsQueue: false };\n\t\t\tthis.scopes.set(callerId, scope);\n\t\t}\n\t\tconst toolCall: AgentToolCall = {\n\t\t\ttype: \"toolCall\",\n\t\t\tid: `${callerId}/${scope.nextId++}`,\n\t\t\tname,\n\t\t\targuments: (args ?? {}) as AgentToolCall[\"arguments\"],\n\t\t};\n\t\tconst record = scope.recorder.start(toolCall);\n\t\tawait this.host.emit({\n\t\t\ttype: \"tool_execution_start\",\n\t\t\ttoolCallId: toolCall.id,\n\t\t\ttoolName: name,\n\t\t\targs: toolCall.arguments,\n\t\t\tparentToolCallId: callerId,\n\t\t});\n\n\t\tconst exclusive =\n\t\t\t!scope.holdsQueue &&\n\t\t\t(this.host.isSequential() ||\n\t\t\t\tthis.host.getTools().find((tool) => tool.name === name)?.executionMode === \"sequential\");\n\t\tlet release: (() => void) | undefined;\n\t\tif (exclusive) {\n\t\t\tconst previous = this.queueTail;\n\t\t\tthis.queueTail = new Promise((resolve) => {\n\t\t\t\trelease = resolve;\n\t\t\t});\n\t\t\tawait previous;\n\t\t}\n\t\tthis.scopes.set(toolCall.id, {\n\t\t\trecorder: scope.recorder,\n\t\t\tnextId: 1,\n\t\t\tholdsQueue: scope.holdsQueue || exclusive,\n\t\t});\n\t\tlet outcome: AgentToolCallOutcome;\n\t\ttry {\n\t\t\toutcome = await this.host.runToolCall(toolCall, callerId, options.signal, async (partialResult) => {\n\t\t\t\toptions.onUpdate?.(partialResult);\n\t\t\t\tawait this.host.emit({\n\t\t\t\t\ttype: \"tool_execution_update\",\n\t\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\t\ttoolName: name,\n\t\t\t\t\targs: toolCall.arguments,\n\t\t\t\t\tpartialResult,\n\t\t\t\t\tparentToolCallId: callerId,\n\t\t\t\t});\n\t\t\t});\n\t\t} finally {\n\t\t\tthis.scopes.delete(toolCall.id);\n\t\t\trelease?.();\n\t\t}\n\n\t\tscope.recorder.finish(record, outcome.isError, textOf(outcome.result));\n\t\t// Nested results are not persisted, so their usage is only counted through the recorder.\n\t\tif (outcome.result.usage) scope.recorder.addUsage(outcome.result.usage);\n\t\tawait this.host.emit({\n\t\t\ttype: \"tool_execution_end\",\n\t\t\ttoolCallId: toolCall.id,\n\t\t\ttoolName: name,\n\t\t\tresult: outcome.result,\n\t\t\tisError: outcome.isError,\n\t\t\t...(outcome.durationMs === undefined ? {} : { durationMs: outcome.durationMs }),\n\t\t\tparentToolCallId: callerId,\n\t\t});\n\t\treturn outcome;\n\t}\n\n\t/** Remove and return the record of the nested calls a model-issued call made. */\n\ttakeRecord(toolCallId: string): NestedCallSummary | undefined {\n\t\tconst scope = this.scopes.get(toolCallId);\n\t\tthis.scopes.delete(toolCallId);\n\t\tif (!scope) return undefined;\n\t\treturn { calls: scope.recorder.snapshot(), usage: scope.recorder.totalUsage };\n\t}\n\n\tclear(): void {\n\t\tthis.scopes.clear();\n\t}\n}\n"]}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { CompactionPreparationOptions, LegacyCompactResult, SessionTreeEntry } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import { type AnyModel, type AssistantImages, type
|
|
3
|
-
|
|
4
|
-
constructor();
|
|
5
|
-
}
|
|
2
|
+
import { type AnyModel, type AssistantImages, type AssistantMessageEventStream, type AuthOperationOptions, type CacheRetention, type ClassifierApi, type ClassifierContext, type ClassifierModel, type ClassifierOptions, type ClassifierResult, type Context, type DeferredCancelOptions, type DeferredFetchOptions, type DeferredHandle, type ImageApi, type ImageModel, type ImagesContext, type ImagesOptions, type Message, type Model, type ModelsApiStreamOptions, type SimpleStreamOptions, type StreamOptions } from "@earendil-works/pi-ai";
|
|
3
|
+
type PiServerEventStream = AssistantMessageEventStream;
|
|
6
4
|
declare function getServerUrl(): string;
|
|
7
5
|
declare function getAuthToken(): string;
|
|
8
6
|
export declare function hashStaticContext(ctx: Context): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-server-client.d.ts","sourceRoot":"","sources":["../../src/core/pi-server-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,4BAA4B,EAC5B,mBAAmB,EAEnB,gBAAgB,EAChB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,KAAK,QAAQ,EACb,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"pi-server-client.d.ts","sourceRoot":"","sources":["../../src/core/pi-server-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,4BAA4B,EAC5B,mBAAmB,EAEnB,gBAAgB,EAChB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,KAAK,QAAQ,EACb,KAAK,eAAe,EAGpB,KAAK,2BAA2B,EAChC,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,OAAO,EAEZ,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,cAAc,EAEnB,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,sBAAsB,EAI3B,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,MAAM,uBAAuB,CAAC;AAU/B,KAAK,mBAAmB,GAAG,2BAA2B,CAAC;AAEvD,iBAAS,YAAY,IAAI,MAAM,CAE9B;AAED,iBAAS,YAAY,IAAI,MAAM,CAE9B;AAwCD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAEtD;AAuBD,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAM5D;AAED,wBAAgB,uBAAuB,IAAI,IAAI,CAO9C;AAsFD,6GAA6G;AAC7G,wBAAsB,wBAAwB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKpF;AAaD,MAAM,WAAW,oBAAoB;IACpC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eAAe,CACpC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,sBAAsB,GAC9B,OAAO,CAAC,wBAAwB,CAAC,CA6FnC;AAED,wBAAsB,cAAc,CACnC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC7B,OAAO,CAAC,mBAAmB,CAAC,CAmS9B;AAiGD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;AAetC,MAAM,WAAW,oBAAoB;IACpC,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,SAAS,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;CAC7E;AAED,wBAAsB,mBAAmB,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAGvG;AAED,wBAAsB,sBAAsB,CAC3C,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC3B,OAAO,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,aAAa,GACrB,OAAO,CAAC,eAAe,CAAC,CAoB1B;AAED,wBAAsB,gBAAgB,CACrC,KAAK,EAAE,eAAe,CAAC,aAAa,CAAC,EACrC,OAAO,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,iBAAiB,GACzB,OAAO,CAAC,gBAAgB,CAAC,CAoB3B"}
|
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
3
|
-
import {
|
|
3
|
+
import { createAssistantMessageEventStream, getModelType, parseStreamingJson, } from "@earendil-works/pi-ai";
|
|
4
4
|
import { raceWithAbortSignal } from "../utils/abort.js";
|
|
5
5
|
import { buildPiServerTreePrefixHashes, hashPiServerSessionEntries, hashPiServerStaticContext, } from "./pi-server-protocol.js";
|
|
6
6
|
import { ChunkRequest } from "./pi-server-request.js";
|
|
7
|
-
class PiServerEventStream extends EventStream {
|
|
8
|
-
constructor() {
|
|
9
|
-
super((event) => event.type === "done" || event.type === "error", (event) => {
|
|
10
|
-
if (event.type === "done")
|
|
11
|
-
return event.message;
|
|
12
|
-
if (event.type === "error")
|
|
13
|
-
return event.error;
|
|
14
|
-
throw new Error("Unexpected event type");
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
7
|
function getServerUrl() {
|
|
19
8
|
return process.env.PI_SERVER_URL ?? "http://127.0.0.1:4217";
|
|
20
9
|
}
|
|
@@ -775,7 +764,7 @@ export async function streamPiServer(model, context, options) {
|
|
|
775
764
|
const runId = randomUUID();
|
|
776
765
|
const isEphemeralSession = options?.sessionId === undefined;
|
|
777
766
|
const operation = registerPiServerOperation(options?.ownerSessionId ?? sessionId, sessionId, runId, options?.signal);
|
|
778
|
-
const stream =
|
|
767
|
+
const stream = createAssistantMessageEventStream();
|
|
779
768
|
const partial = {
|
|
780
769
|
role: "assistant",
|
|
781
770
|
stopReason: "stop",
|