pi2dsh 0.27.0 → 0.28.0-next.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/README.md +28 -19
- package/README.zh.md +25 -17
- package/dist/abort-signals-CDYLHHiA.mjs +37 -0
- package/dist/abort-signals-CDYLHHiA.mjs.map +1 -0
- package/dist/{analyzer-BCHAvJ70.mjs → analyzer-CbazPvsH.mjs} +2 -2
- package/dist/{analyzer-BCHAvJ70.mjs.map → analyzer-CbazPvsH.mjs.map} +1 -1
- package/dist/anthropic-messages-CsLWC2zy.mjs +14356 -0
- package/dist/anthropic-messages-CsLWC2zy.mjs.map +1 -0
- package/dist/{azure-openai-responses-HKWkzl2m.mjs → azure-openai-responses-CKiLKs74.mjs} +92 -60
- package/dist/azure-openai-responses-CKiLKs74.mjs.map +1 -0
- package/dist/cli.mjs +2 -2
- package/dist/compat/pi-ai.d.mts +3 -3
- package/dist/compat/pi-ai.mjs +2 -2
- package/dist/compat/pi-coding-agent.d.mts +2 -2
- package/dist/compat/pi-coding-agent.mjs +2 -2
- package/dist/{compatibility-B1F_96JT.mjs → compatibility-D9brV-tx.mjs} +64 -19
- package/dist/compatibility-D9brV-tx.mjs.map +1 -0
- package/dist/credentials-oauth.mjs +3 -3
- package/dist/{diagnostics-BqYkodgB.mjs → diagnostics-DyfZGsqs.mjs} +2 -2
- package/dist/diagnostics-DyfZGsqs.mjs.map +1 -0
- package/dist/{error-body-DKA3lknR.mjs → error-body-B-itCA3G.mjs} +2 -2
- package/dist/error-body-B-itCA3G.mjs.map +1 -0
- package/dist/{github-copilot-headers-CZo2QHrt.mjs → github-copilot-headers-B67Lngyc.mjs} +2 -2
- package/dist/github-copilot-headers-B67Lngyc.mjs.map +1 -0
- package/dist/{google-generative-ai-DYSbNJT7.mjs → google-generative-ai-UEe7ZUpj.mjs} +39 -67
- package/dist/google-generative-ai-UEe7ZUpj.mjs.map +1 -0
- package/dist/{google-shared-LEpwok5n.mjs → google-shared-DKjLxEcj.mjs} +6523 -2131
- package/dist/google-shared-DKjLxEcj.mjs.map +1 -0
- package/dist/{google-vertex-BgGRE4WU.mjs → google-vertex-CC6lrIWD.mjs} +43 -69
- package/dist/google-vertex-CC6lrIWD.mjs.map +1 -0
- package/dist/{hash-Dbggamac.mjs → hash-CXI-VEdF.mjs} +2 -2
- package/dist/hash-CXI-VEdF.mjs.map +1 -0
- package/dist/headers-CswFYkly.mjs +178 -0
- package/dist/headers-CswFYkly.mjs.map +1 -0
- package/dist/host.mjs +1 -1
- package/dist/index-DxlLszV4.d.mts +104073 -0
- package/dist/index-DxlLszV4.d.mts.map +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/{json-parse-CZ0U0sj_.mjs → json-parse-LYZk8Fqp.mjs} +25 -5
- package/dist/json-parse-LYZk8Fqp.mjs.map +1 -0
- package/dist/mistral-conversations-DJMivlmW.mjs +698 -0
- package/dist/mistral-conversations-DJMivlmW.mjs.map +1 -0
- package/dist/node-CC3TdZay.mjs +26 -0
- package/dist/node-CC3TdZay.mjs.map +1 -0
- package/dist/node-k7DsCSPx.mjs +2482 -0
- package/dist/node-k7DsCSPx.mjs.map +1 -0
- package/dist/{oauth-bridge-C_MAPMGA.mjs → oauth-bridge-DX_dQrUi.mjs} +2 -8
- package/dist/oauth-bridge-DX_dQrUi.mjs.map +1 -0
- package/dist/openai-DvyoQMiQ.mjs +17360 -0
- package/dist/openai-DvyoQMiQ.mjs.map +1 -0
- package/dist/{openai-codex-responses-DedxQjNG.mjs → openai-codex-responses-Dm9bvM-A.mjs} +152 -129
- package/dist/openai-codex-responses-Dm9bvM-A.mjs.map +1 -0
- package/dist/{openai-completions-DrjrWRdX.mjs → openai-completions-PObJoYfy.mjs} +211 -161
- package/dist/openai-completions-PObJoYfy.mjs.map +1 -0
- package/dist/openai-prompt-cache-BDWtZRKh.mjs.map +1 -1
- package/dist/openai-responses-shared-1MJr-fTV.mjs +653 -0
- package/dist/openai-responses-shared-1MJr-fTV.mjs.map +1 -0
- package/dist/{pi-ai-Cy_BRMmd.mjs → pi-ai-Tj3CLsui.mjs} +437 -93
- package/dist/pi-ai-Tj3CLsui.mjs.map +1 -0
- package/dist/pi-ai-y7AT7IWk.d.mts +491 -0
- package/dist/pi-ai-y7AT7IWk.d.mts.map +1 -0
- package/dist/{pi-coding-agent-Cas0oHSx.d.mts → pi-coding-agent-80MGCLmc.d.mts} +198 -28
- package/dist/pi-coding-agent-80MGCLmc.d.mts.map +1 -0
- package/dist/{pi-coding-agent-lcNs9Wos.mjs → pi-coding-agent-B4r4F-Qv.mjs} +0 -0
- package/dist/pi-coding-agent-B4r4F-Qv.mjs.map +1 -0
- package/dist/pi-config-shim-CZ1wFzqM.mjs.map +1 -1
- package/dist/{pi-messages-D61G2tgs.mjs → pi-messages-Dh1fdlA4.mjs} +15 -14
- package/dist/pi-messages-Dh1fdlA4.mjs.map +1 -0
- package/dist/{provider-env-C72pF4vP.mjs → provider-env-DCR5DPaM.mjs} +2 -2
- package/dist/provider-env-DCR5DPaM.mjs.map +1 -0
- package/dist/{provider-retry-Cw6YJ4cr.mjs → provider-retry-DZHtmXkj.mjs} +6 -4
- package/dist/provider-retry-DZHtmXkj.mjs.map +1 -0
- package/dist/{runtime-BFJsumJX.mjs → runtime-Dq4Y535P.mjs} +560 -138
- package/dist/runtime-Dq4Y535P.mjs.map +1 -0
- package/dist/runtime.d.mts +12 -44
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/simple-options-XDC-jFyb.mjs +722 -0
- package/dist/simple-options-XDC-jFyb.mjs.map +1 -0
- package/package.json +45 -44
- package/dist/anthropic-messages-CaYTgvLF.mjs +0 -6436
- package/dist/anthropic-messages-CaYTgvLF.mjs.map +0 -1
- package/dist/azure-openai-responses-HKWkzl2m.mjs.map +0 -1
- package/dist/compatibility-B1F_96JT.mjs.map +0 -1
- package/dist/deferred-tools-BD4g5QUx.mjs +0 -32
- package/dist/deferred-tools-BD4g5QUx.mjs.map +0 -1
- package/dist/diagnostics-BqYkodgB.mjs.map +0 -1
- package/dist/error-body-DKA3lknR.mjs.map +0 -1
- package/dist/event-stream-QxN1yvIF.mjs +0 -64
- package/dist/event-stream-QxN1yvIF.mjs.map +0 -1
- package/dist/github-copilot-headers-CZo2QHrt.mjs.map +0 -1
- package/dist/google-generative-ai-DYSbNJT7.mjs.map +0 -1
- package/dist/google-shared-LEpwok5n.mjs.map +0 -1
- package/dist/google-vertex-BgGRE4WU.mjs.map +0 -1
- package/dist/hash-Dbggamac.mjs.map +0 -1
- package/dist/headers-CPzZhJQn.mjs +0 -17
- package/dist/headers-CPzZhJQn.mjs.map +0 -1
- package/dist/json-parse-CZ0U0sj_.mjs.map +0 -1
- package/dist/mistral-conversations-D-Kf38nj.mjs +0 -42005
- package/dist/mistral-conversations-D-Kf38nj.mjs.map +0 -1
- package/dist/oauth-bridge-C_MAPMGA.mjs.map +0 -1
- package/dist/openai-DkzRh5_G.mjs +0 -6732
- package/dist/openai-DkzRh5_G.mjs.map +0 -1
- package/dist/openai-codex-responses-DedxQjNG.mjs.map +0 -1
- package/dist/openai-completions-DrjrWRdX.mjs.map +0 -1
- package/dist/openai-responses-shared-BmnSvdKL.mjs +0 -570
- package/dist/openai-responses-shared-BmnSvdKL.mjs.map +0 -1
- package/dist/otel-EL651-JR.mjs +0 -24935
- package/dist/otel-EL651-JR.mjs.map +0 -1
- package/dist/pi-ai-BHgA3JWd.d.mts +0 -2686
- package/dist/pi-ai-BHgA3JWd.d.mts.map +0 -1
- package/dist/pi-ai-Cy_BRMmd.mjs.map +0 -1
- package/dist/pi-coding-agent-Cas0oHSx.d.mts.map +0 -1
- package/dist/pi-coding-agent-lcNs9Wos.mjs.map +0 -1
- package/dist/pi-messages-D61G2tgs.mjs.map +0 -1
- package/dist/pi-types-KazmR2O5.d.mts +0 -62
- package/dist/pi-types-KazmR2O5.d.mts.map +0 -1
- package/dist/provider-env-C72pF4vP.mjs.map +0 -1
- package/dist/provider-retry-Cw6YJ4cr.mjs.map +0 -1
- package/dist/runtime-BFJsumJX.mjs.map +0 -1
- package/dist/simple-options-B_GO8FDE.mjs +0 -456
- package/dist/simple-options-B_GO8FDE.mjs.map +0 -1
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
2
|
+
import { An as validateMcpServerConfig, F as generateBranchSummary, Mn as PiCapabilityError, On as McpServerRegistry, b as Theme, d as ExtensionRunner, dn as buildSessionProjection, jn as CapabilityLedger, kn as mcpNamespace, pn as getDefaultSessionDir, w as __runWithSubagentSessionFactory } from "./pi-coding-agent-B4r4F-Qv.mjs";
|
|
3
|
+
import { C as getSupportedThinkingLevels, Ct as renderSystemMessageUpdate, Et as imageErrorResult, St as getSystemMessageText, _t as normalizeContext, c as builtinProviders, dt as getCurrentTools, et as AssistantMessageEventStream, o as __runWithPiAiRuntime, r as __createPiAiRuntimeRegistry, tt as isContextOverflow, wt as classifierErrorResult } from "./pi-ai-Tj3CLsui.mjs";
|
|
3
4
|
import { t as getAgentDir } from "./pi-config-shim-CZ1wFzqM.mjs";
|
|
4
|
-
import { C as getSupportedThinkingLevels, c as builtinProviders, nt as isContextOverflow, o as __runWithPiAiRuntime, r as __createPiAiRuntimeRegistry, tt as AssistantMessageEventStream } from "./pi-ai-Cy_BRMmd.mjs";
|
|
5
5
|
import { W as getKeybindings, _t as stripTerminalSequences } from "./pi-tui-DruSeKmd.mjs";
|
|
6
6
|
import { r as piMcpConfigPaths, t as collectPiMcpServers } from "./mcp-config-C1K-IzzB.mjs";
|
|
7
|
-
import { c as resolvePiProviderAuth, i as oauthCredentialRef, l as storedOAuthCredential, n as joinSignals, o as providerSupportsOAuth, r as loginPiProvider, t as FileCredentialStore } from "./oauth-bridge-
|
|
7
|
+
import { c as resolvePiProviderAuth, i as oauthCredentialRef, l as storedOAuthCredential, n as joinSignals, o as providerSupportsOAuth, r as loginPiProvider, t as FileCredentialStore } from "./oauth-bridge-DX_dQrUi.mjs";
|
|
8
8
|
import { createRequire } from "node:module";
|
|
9
9
|
import { access, chmod, mkdir, mkdtemp, readFile, realpath, rm, stat, writeFile } from "node:fs/promises";
|
|
10
10
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
11
11
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
12
12
|
import { fileURLToPath } from "node:url";
|
|
13
|
+
import * as llm from "@deepseek-ai/dsh-llm";
|
|
14
|
+
import { CONTEXT_WINDOW_EXCEEDED_CODE, EMPTY_RESPONSE_CODE, LlmAdapter, LlmError, QUOTA_EXCEEDED_CODE, ToolCallId, createSystemMessage, createToolResultMessage, createUserMessage, isContextWindowExceededError, isQuotaExceededError } from "@deepseek-ai/dsh-llm";
|
|
15
|
+
import { ToolExecutionPipeline } from "@deepseek-ai/dsh-tools/pipeline";
|
|
13
16
|
import { createServer } from "node:net";
|
|
14
17
|
import { randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
15
18
|
import { homedir, tmpdir } from "node:os";
|
|
16
19
|
import { EventEmitter } from "node:events";
|
|
17
20
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
18
21
|
import { createJiti } from "jiti";
|
|
19
|
-
import * as llm from "@deepseek-ai/dsh-llm";
|
|
20
|
-
import { CONTEXT_WINDOW_EXCEEDED_CODE, EMPTY_RESPONSE_CODE, LlmAdapter, LlmError, QUOTA_EXCEEDED_CODE, ToolCallId, createToolResultMessage, createUserMessage, isContextWindowExceededError, isQuotaExceededError } from "@deepseek-ai/dsh-llm";
|
|
21
22
|
import { scopeOf } from "@deepseek-ai/dsh-scope";
|
|
22
23
|
import { renderPrompt } from "@deepseek-ai/dsh-system-prompt";
|
|
23
24
|
import { foldSurface } from "@deepseek-ai/dsh-session";
|
|
@@ -45,6 +46,184 @@ function isPiEphemeralSession(session) {
|
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
//#endregion
|
|
49
|
+
//#region src/agent-model.ts
|
|
50
|
+
function modelSurface(agent) {
|
|
51
|
+
const surface = agent?.model;
|
|
52
|
+
return surface !== void 0 && typeof surface.current === "function" && typeof surface.select === "function" ? surface : void 0;
|
|
53
|
+
}
|
|
54
|
+
function readAgentModel(agent) {
|
|
55
|
+
const selected = modelSurface(agent)?.current();
|
|
56
|
+
if (selected === void 0) return void 0;
|
|
57
|
+
return {
|
|
58
|
+
provider: selected.provider,
|
|
59
|
+
model: selected.model,
|
|
60
|
+
...selected.reasoningEffort === void 0 ? {} : { reasoningEffort: selected.reasoningEffort }
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function selectAgentModel(agent, selection) {
|
|
64
|
+
const surface = modelSurface(agent);
|
|
65
|
+
if (surface === void 0) throw new PiCapabilityError({
|
|
66
|
+
capability: "pi.setModel",
|
|
67
|
+
reason: "The active Agent has no public model-selection service.",
|
|
68
|
+
guidance: "Run this extension in a DSH 0.2.2 Agent composition."
|
|
69
|
+
});
|
|
70
|
+
surface.select({
|
|
71
|
+
provider: selection.provider,
|
|
72
|
+
model: selection.model,
|
|
73
|
+
...selection.reasoningEffort === void 0 ? {} : { reasoningEffort: selection.reasoningEffort }
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/mcp-registration.ts
|
|
78
|
+
const registries = /* @__PURE__ */ new WeakMap();
|
|
79
|
+
const mcpRegistrationChanged = Symbol("pi2dsh.mcpRegistrationChanged");
|
|
80
|
+
function mcpRegistrations(bus) {
|
|
81
|
+
let registry = registries.get(bus);
|
|
82
|
+
if (registry === void 0) {
|
|
83
|
+
registry = new McpServerRegistry();
|
|
84
|
+
const current = registry;
|
|
85
|
+
current.setChangeListener(() => bus.emit(mcpRegistrationChanged, current.list()));
|
|
86
|
+
registries.set(bus, current);
|
|
87
|
+
}
|
|
88
|
+
return registry;
|
|
89
|
+
}
|
|
90
|
+
/** Pi loader ownership and namespace checks, before changing the shared ledger. */
|
|
91
|
+
function registerMcpServer(bus, owner, name, config) {
|
|
92
|
+
const validated = validateMcpServerConfig(name, config);
|
|
93
|
+
if (typeof validated === "string") throw new Error(`Invalid MCP server registered by extension "${owner}": ${validated}`);
|
|
94
|
+
const registry = mcpRegistrations(bus);
|
|
95
|
+
const existingOwner = registry.get(name)?.extensionPath;
|
|
96
|
+
if (existingOwner !== void 0 && existingOwner !== owner) throw new Error(`MCP server "${name}" is already registered by extension "${existingOwner}"`);
|
|
97
|
+
const clash = registry.list().find((server) => server.name !== name && mcpNamespace(server.name) === mcpNamespace(name));
|
|
98
|
+
if (clash !== void 0) throw new Error(`MCP server "${name}" conflicts with registered server "${clash.name}"`);
|
|
99
|
+
registry.register({
|
|
100
|
+
name,
|
|
101
|
+
config: structuredClone(validated),
|
|
102
|
+
extensionPath: owner
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/nested-tools.ts
|
|
107
|
+
const identities = /* @__PURE__ */ new Map();
|
|
108
|
+
const updates = /* @__PURE__ */ new Map();
|
|
109
|
+
function parentPiToolCallId(exec) {
|
|
110
|
+
return exec.parent === void 0 ? void 0 : identities.get(exec.parent);
|
|
111
|
+
}
|
|
112
|
+
function publishNestedToolUpdate(exec, value) {
|
|
113
|
+
updates.get(exec.token)?.(value);
|
|
114
|
+
}
|
|
115
|
+
/** Keep correlation scoped to the real host execution, including concurrent nested calls. */
|
|
116
|
+
async function withPiToolIdentity(exec, run) {
|
|
117
|
+
identities.set(exec.token, String(exec.callId));
|
|
118
|
+
try {
|
|
119
|
+
return await run();
|
|
120
|
+
} finally {
|
|
121
|
+
identities.delete(exec.token);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** Pi nested calls run through DSH's public policy/validation/settlement pipeline. */
|
|
125
|
+
function nestedToolCaller(ctx, parent, projectContent, projectArguments) {
|
|
126
|
+
let index = 0;
|
|
127
|
+
return async (name, args, options = {}) => {
|
|
128
|
+
const id = `${parent.callId}/${++index}`;
|
|
129
|
+
const toolCall = {
|
|
130
|
+
type: "toolCall",
|
|
131
|
+
id,
|
|
132
|
+
name,
|
|
133
|
+
arguments: args
|
|
134
|
+
};
|
|
135
|
+
try {
|
|
136
|
+
const signal = options.signal === void 0 ? parent.signal : AbortSignal.any([parent.signal, options.signal]);
|
|
137
|
+
const pipeline = new ToolExecutionPipeline(ctx);
|
|
138
|
+
const prepared = await pipeline.prepare({
|
|
139
|
+
callId: ToolCallId(id),
|
|
140
|
+
rootCallId: parent.rootCallId,
|
|
141
|
+
parent: parent.token,
|
|
142
|
+
name,
|
|
143
|
+
arguments: projectArguments(name, args),
|
|
144
|
+
signal,
|
|
145
|
+
...parent.agent === void 0 ? {} : { agent: parent.agent },
|
|
146
|
+
...parent.toolSet === void 0 ? {} : { toolSet: parent.toolSet }
|
|
147
|
+
});
|
|
148
|
+
if (options.onUpdate !== void 0) updates.set(prepared.exec.token, options.onUpdate);
|
|
149
|
+
try {
|
|
150
|
+
const outcome = prepared.kind === "dispatch" ? await pipeline.dispatch(prepared.exec) : prepared;
|
|
151
|
+
const result = await pipeline.complete(prepared.exec, outcome);
|
|
152
|
+
for (const context of result.additionalContexts ?? []) parent.deferContext(context);
|
|
153
|
+
if (!result.isError && result.concludesTurn) parent.concludeTurn();
|
|
154
|
+
const value = !result.isError && typeof result.value === "object" && result.value !== null ? result.value : void 0;
|
|
155
|
+
return {
|
|
156
|
+
toolCall,
|
|
157
|
+
isError: result.isError,
|
|
158
|
+
result: {
|
|
159
|
+
content: await projectContent(result.content),
|
|
160
|
+
details: result.meta,
|
|
161
|
+
...value?.structuredContent === void 0 ? {} : { structuredContent: value.structuredContent },
|
|
162
|
+
...result.isError ? { isError: true } : {}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
} finally {
|
|
166
|
+
updates.delete(prepared.exec.token);
|
|
167
|
+
}
|
|
168
|
+
} catch (error) {
|
|
169
|
+
return {
|
|
170
|
+
toolCall,
|
|
171
|
+
isError: true,
|
|
172
|
+
result: {
|
|
173
|
+
content: [{
|
|
174
|
+
type: "text",
|
|
175
|
+
text: error instanceof Error ? error.message : String(error)
|
|
176
|
+
}],
|
|
177
|
+
details: void 0,
|
|
178
|
+
isError: true
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/ui-prompt-lifecycle.ts
|
|
186
|
+
const uiPromptChanged = Symbol("pi2dsh.uiPromptChanged");
|
|
187
|
+
const prompts = /* @__PURE__ */ new WeakMap();
|
|
188
|
+
/** Pi 1.4 runner semantics: one start/end pair around overlapping blocking prompts. */
|
|
189
|
+
function withUiPrompt(bus, kind, title, run) {
|
|
190
|
+
let state = prompts.get(bus);
|
|
191
|
+
if (state === void 0) {
|
|
192
|
+
state = { depth: 0 };
|
|
193
|
+
prompts.set(bus, state);
|
|
194
|
+
}
|
|
195
|
+
const current = state;
|
|
196
|
+
if (current.depth++ === 0) {
|
|
197
|
+
current.active = {
|
|
198
|
+
kind,
|
|
199
|
+
...title ? { title } : {}
|
|
200
|
+
};
|
|
201
|
+
const event = {
|
|
202
|
+
type: "ui_prompt_start",
|
|
203
|
+
reason: "ui_prompt",
|
|
204
|
+
...current.active
|
|
205
|
+
};
|
|
206
|
+
queueMicrotask(() => bus.emit(uiPromptChanged, event));
|
|
207
|
+
}
|
|
208
|
+
const finish = () => {
|
|
209
|
+
if (--current.depth > 0) return;
|
|
210
|
+
current.depth = 0;
|
|
211
|
+
const event = {
|
|
212
|
+
type: "ui_prompt_end",
|
|
213
|
+
reason: "ui_prompt",
|
|
214
|
+
...current.active
|
|
215
|
+
};
|
|
216
|
+
delete current.active;
|
|
217
|
+
queueMicrotask(() => bus.emit(uiPromptChanged, event));
|
|
218
|
+
};
|
|
219
|
+
try {
|
|
220
|
+
return run().finally(finish);
|
|
221
|
+
} catch (error) {
|
|
222
|
+
finish();
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
//#endregion
|
|
48
227
|
//#region src/pi-cli-bridge.ts
|
|
49
228
|
async function parsePiPrintArgs(args, cwd) {
|
|
50
229
|
const parsed = {
|
|
@@ -697,7 +876,7 @@ var PiSessionBridge = class {
|
|
|
697
876
|
}
|
|
698
877
|
return entries;
|
|
699
878
|
}
|
|
700
|
-
/**
|
|
879
|
+
/** Read-only Pi session methods over the host-authoritative visible surface. */
|
|
701
880
|
readonlySessionManager(session, cwd) {
|
|
702
881
|
const entriesOf = () => this.projectEntries(session);
|
|
703
882
|
const leafOf = () => entriesOf().at(-1);
|
|
@@ -716,6 +895,19 @@ var PiSessionBridge = class {
|
|
|
716
895
|
const index = entries.findIndex((entry) => entry.id === fromId);
|
|
717
896
|
return index === -1 ? [] : entries.slice(0, index + 1);
|
|
718
897
|
},
|
|
898
|
+
buildSessionProjection: () => {
|
|
899
|
+
const projection = buildSessionProjection(entriesOf());
|
|
900
|
+
const visible = this.visibleSeqs(session);
|
|
901
|
+
const entries = projection.entries.filter((item) => {
|
|
902
|
+
const seq = entrySeq(item.sourceEntry.id);
|
|
903
|
+
return seq === void 0 || visible === void 0 || visible.has(seq);
|
|
904
|
+
});
|
|
905
|
+
return {
|
|
906
|
+
...projection,
|
|
907
|
+
entries,
|
|
908
|
+
messages: entries.flatMap((entry) => entry.messages)
|
|
909
|
+
};
|
|
910
|
+
},
|
|
719
911
|
buildContextEntries: () => {
|
|
720
912
|
const visible = this.visibleSeqs(session);
|
|
721
913
|
return entriesOf().filter((entry) => {
|
|
@@ -2472,8 +2664,19 @@ function dshBlocksFromPiContent(content) {
|
|
|
2472
2664
|
*/
|
|
2473
2665
|
function piRequestToDshMessages(context) {
|
|
2474
2666
|
const messages = [];
|
|
2475
|
-
const source =
|
|
2476
|
-
|
|
2667
|
+
const source = normalizeContext({
|
|
2668
|
+
messages: Array.isArray(context.messages) ? context.messages : [],
|
|
2669
|
+
...typeof context.systemPrompt === "string" ? { systemPrompt: context.systemPrompt } : {},
|
|
2670
|
+
...Array.isArray(context.tools) ? { tools: context.tools } : {}
|
|
2671
|
+
}).messages;
|
|
2672
|
+
let system;
|
|
2673
|
+
for (const message of source) if (message.role === "system") {
|
|
2674
|
+
if (message === source[0]) system = getSystemMessageText(message) || void 0;
|
|
2675
|
+
else {
|
|
2676
|
+
if (Array.isArray(message.toolsAdded) && message.toolsAdded.length > 0 || Array.isArray(message.toolsRemoved) && message.toolsRemoved.length > 0) throw new LlmError("pi2dsh: standalone Pi calls with in-history tool changes are not supported", "UNSUPPORTED_CONTENT");
|
|
2677
|
+
messages.push(createSystemMessage(renderSystemMessageUpdate(message)));
|
|
2678
|
+
}
|
|
2679
|
+
} else if (message.role === "user") messages.push({
|
|
2477
2680
|
role: "user",
|
|
2478
2681
|
content: dshBlocksFromPiContent(message.content),
|
|
2479
2682
|
source: { kind: "user" }
|
|
@@ -2492,10 +2695,15 @@ function piRequestToDshMessages(context) {
|
|
|
2492
2695
|
content: dshBlocksFromPiContent(message.content),
|
|
2493
2696
|
isError: message.isError === true
|
|
2494
2697
|
}));
|
|
2495
|
-
const
|
|
2698
|
+
const tools = getCurrentTools(source).map((tool) => ({
|
|
2699
|
+
name: tool.name,
|
|
2700
|
+
description: tool.description,
|
|
2701
|
+
parameters: tool.parameters
|
|
2702
|
+
}));
|
|
2496
2703
|
return {
|
|
2497
2704
|
...system === void 0 ? {} : { system },
|
|
2498
|
-
messages
|
|
2705
|
+
messages,
|
|
2706
|
+
...tools.length === 0 ? {} : { tools }
|
|
2499
2707
|
};
|
|
2500
2708
|
}
|
|
2501
2709
|
function piUsageFromDsh(usage) {
|
|
@@ -2535,7 +2743,7 @@ function streamViaDshLlm(llm, request) {
|
|
|
2535
2743
|
const stream = new AssistantMessageEventStream();
|
|
2536
2744
|
const provider = String(request.model.provider ?? "");
|
|
2537
2745
|
const modelId = String(request.model.id ?? "");
|
|
2538
|
-
const { system, messages } = piRequestToDshMessages({
|
|
2746
|
+
const { system, messages, tools } = piRequestToDshMessages({
|
|
2539
2747
|
...request.context,
|
|
2540
2748
|
provider,
|
|
2541
2749
|
model: modelId
|
|
@@ -2546,7 +2754,7 @@ function streamViaDshLlm(llm, request) {
|
|
|
2546
2754
|
model: modelId,
|
|
2547
2755
|
messages,
|
|
2548
2756
|
...system === void 0 ? {} : { system },
|
|
2549
|
-
...
|
|
2757
|
+
...tools === void 0 ? {} : { tools: normalizeToolSchemas(tools) },
|
|
2550
2758
|
...typeof options.maxTokens === "number" ? { maxTokens: options.maxTokens } : {},
|
|
2551
2759
|
...typeof options.temperature === "number" ? { temperature: options.temperature } : {},
|
|
2552
2760
|
...typeof options.reasoning === "string" ? { reasoningEffort: options.reasoning } : {},
|
|
@@ -2769,9 +2977,42 @@ async function dshRequestToPiContext(options, attachments) {
|
|
|
2769
2977
|
}
|
|
2770
2978
|
for (const message of history) {
|
|
2771
2979
|
const content = Array.isArray(message.content) ? message.content : [];
|
|
2772
|
-
if (message.role === "system")
|
|
2773
|
-
|
|
2774
|
-
|
|
2980
|
+
if (message.role === "system") {
|
|
2981
|
+
if (content.some((block) => block.type !== "text")) throw new LlmError("pi2dsh: Pi system messages require text content", "UNSUPPORTED_CONTENT");
|
|
2982
|
+
piMessages.push({
|
|
2983
|
+
role: "system",
|
|
2984
|
+
content: content.map((block) => ({
|
|
2985
|
+
type: "text",
|
|
2986
|
+
text: block.text
|
|
2987
|
+
})),
|
|
2988
|
+
timestamp: 0
|
|
2989
|
+
});
|
|
2990
|
+
} else if (message.role === "developer") {
|
|
2991
|
+
const text = [];
|
|
2992
|
+
const toolsAdded = [];
|
|
2993
|
+
const toolsRemoved = [];
|
|
2994
|
+
for (const block of content) if (block.type === "text") text.push({
|
|
2995
|
+
type: "text",
|
|
2996
|
+
text: block.text
|
|
2997
|
+
});
|
|
2998
|
+
else if (block.type === "tool-removal") toolsRemoved.push({ name: block.toolName });
|
|
2999
|
+
else if (block.type === "tool-addition") {
|
|
3000
|
+
const tool = options.tools?.find((tool) => tool.name === block.toolName);
|
|
3001
|
+
if (tool === void 0) throw new LlmError(`pi2dsh: undeclared tool in update: ${String(block.toolName)}`, "INVALID_REQUEST");
|
|
3002
|
+
toolsAdded.push({
|
|
3003
|
+
name: tool.name,
|
|
3004
|
+
description: tool.description,
|
|
3005
|
+
parameters: tool.parameters
|
|
3006
|
+
});
|
|
3007
|
+
} else throw new LlmError(`pi2dsh: unsupported developer content ${String(block.type)}`, "UNSUPPORTED_CONTENT");
|
|
3008
|
+
piMessages.push({
|
|
3009
|
+
role: "system",
|
|
3010
|
+
content: text,
|
|
3011
|
+
timestamp: 0,
|
|
3012
|
+
...toolsAdded.length === 0 ? {} : { toolsAdded },
|
|
3013
|
+
...toolsRemoved.length === 0 ? {} : { toolsRemoved }
|
|
3014
|
+
});
|
|
3015
|
+
} else if (message.role === "tool") {
|
|
2775
3016
|
const toolCallId = String(message.toolCallId ?? "");
|
|
2776
3017
|
const toolName = toolNamesById.get(toolCallId);
|
|
2777
3018
|
piMessages.push({
|
|
@@ -2790,11 +3031,11 @@ async function dshRequestToPiContext(options, attachments) {
|
|
|
2790
3031
|
content: await piContentFromDshBlocks(content, attachments)
|
|
2791
3032
|
});
|
|
2792
3033
|
}
|
|
2793
|
-
return {
|
|
3034
|
+
return normalizeContext({
|
|
2794
3035
|
...systemPrompt !== void 0 && systemPrompt.length > 0 ? { systemPrompt } : {},
|
|
2795
3036
|
messages: piMessages,
|
|
2796
3037
|
...Array.isArray(options.tools) ? { tools: options.tools } : {}
|
|
2797
|
-
};
|
|
3038
|
+
});
|
|
2798
3039
|
}
|
|
2799
3040
|
/** Whether any block in this content — including inside a tool result — is an image. */
|
|
2800
3041
|
function blocksContainImage(blocks) {
|
|
@@ -3104,7 +3345,7 @@ function providerCarriesTransport(value) {
|
|
|
3104
3345
|
function providerModels(provider) {
|
|
3105
3346
|
try {
|
|
3106
3347
|
const models = typeof provider.getModels === "function" ? provider.getModels() : provider.models;
|
|
3107
|
-
return Array.isArray(models) ? models : [];
|
|
3348
|
+
return Array.isArray(models) ? models.filter((model) => model.type === void 0 || model.type === "chat") : [];
|
|
3108
3349
|
} catch {
|
|
3109
3350
|
return [];
|
|
3110
3351
|
}
|
|
@@ -3263,6 +3504,12 @@ function piProviderDshAdapter(providerId, provider, host) {
|
|
|
3263
3504
|
...typeof options.sessionId === "string" ? { sessionId: options.sessionId } : {},
|
|
3264
3505
|
...options.signal instanceof AbortSignal ? { signal: options.signal } : {}
|
|
3265
3506
|
}) },
|
|
3507
|
+
...host.onProviderStreamEvent === void 0 ? {} : { onProviderStreamEvent: (data, streamedModel) => host.onProviderStreamEvent(data, {
|
|
3508
|
+
provider: providerId,
|
|
3509
|
+
model: streamedModel ?? model,
|
|
3510
|
+
...typeof options.sessionId === "string" ? { sessionId: options.sessionId } : {},
|
|
3511
|
+
...options.signal instanceof AbortSignal ? { signal: options.signal } : {}
|
|
3512
|
+
}) },
|
|
3266
3513
|
...effort === void 0 || effort === "off" ? {} : { reasoning: effort }
|
|
3267
3514
|
};
|
|
3268
3515
|
const contextWindow = typeof model.contextWindow === "number" ? model.contextWindow : void 0;
|
|
@@ -4238,6 +4485,7 @@ function normalizeToolResult(result) {
|
|
|
4238
4485
|
return {
|
|
4239
4486
|
content: textBlocks(record.content),
|
|
4240
4487
|
details: jsonValue(record.details),
|
|
4488
|
+
...record.structuredContent === void 0 ? {} : { structuredContent: jsonValue(record.structuredContent) },
|
|
4241
4489
|
...record.isError === true ? { isError: true } : {},
|
|
4242
4490
|
...record.usage !== void 0 ? { usage: jsonValue(record.usage) } : {},
|
|
4243
4491
|
...record.terminate === true ? { terminate: true } : {}
|
|
@@ -4299,6 +4547,7 @@ async function normalizeToolResultForDsh(ctx, result) {
|
|
|
4299
4547
|
return {
|
|
4300
4548
|
content: await piToDshContent(ctx, record.content),
|
|
4301
4549
|
details: jsonValue(record.details),
|
|
4550
|
+
...record.structuredContent === void 0 ? {} : { structuredContent: jsonValue(record.structuredContent) },
|
|
4302
4551
|
...record.isError === true ? { isError: true } : {},
|
|
4303
4552
|
...record.usage !== void 0 ? { usage: jsonValue(record.usage) } : {},
|
|
4304
4553
|
...record.terminate === true ? { terminate: true } : {}
|
|
@@ -4435,13 +4684,12 @@ function isSubagentOrigin(subject) {
|
|
|
4435
4684
|
return header?.origin === "subagent" || (header?.meta)?.origin === "subagent" || (session?.meta)?.origin === "subagent";
|
|
4436
4685
|
}
|
|
4437
4686
|
function currentPiModel(state, agent) {
|
|
4438
|
-
const
|
|
4687
|
+
const selection = readAgentModel(agent);
|
|
4439
4688
|
const options = agent.options;
|
|
4440
|
-
const
|
|
4441
|
-
const selectedProvider = String(override?.provider ?? durable?.provider ?? options?.provider ?? "");
|
|
4689
|
+
const selectedProvider = String(selection?.provider ?? options?.provider ?? "");
|
|
4442
4690
|
const provider = state.companionRoutes.get(selectedProvider) ?? selectedProvider;
|
|
4443
|
-
const id = String(
|
|
4444
|
-
if (id.length === 0) return
|
|
4691
|
+
const id = String(selection?.model ?? options?.model ?? "");
|
|
4692
|
+
if (id.length === 0) return void 0;
|
|
4445
4693
|
return (provider.length > 0 ? state.modelCatalog?.find(provider, id) : void 0) ?? {
|
|
4446
4694
|
id,
|
|
4447
4695
|
name: id,
|
|
@@ -4451,44 +4699,6 @@ function currentPiModel(state, agent) {
|
|
|
4451
4699
|
reasoning: false
|
|
4452
4700
|
};
|
|
4453
4701
|
}
|
|
4454
|
-
/**
|
|
4455
|
-
* The provider/model of a session's LAST model request, read off the durable
|
|
4456
|
-
* log's request/header — the authority on what the caller is ACTUALLY running.
|
|
4457
|
-
* A UI/`/model` switch never touches the creation-time AgentOptions snapshot,
|
|
4458
|
-
* so a child inheriting the snapshot runs on a stale route (the exact
|
|
4459
|
-
* inheritance bug DSH's own subagent line reports); the durable header is
|
|
4460
|
-
* where the live truth lands, in either of its two observed nestings.
|
|
4461
|
-
*/
|
|
4462
|
-
function lastRequestRouteOf(session) {
|
|
4463
|
-
if (session === void 0) return void 0;
|
|
4464
|
-
const events = eventsOf(session);
|
|
4465
|
-
for (let i = events.length - 1; i >= 0; i -= 1) {
|
|
4466
|
-
const event = events[i];
|
|
4467
|
-
if (event.type !== "request/header") continue;
|
|
4468
|
-
const data = event.data ?? {};
|
|
4469
|
-
const header = data.header ?? {};
|
|
4470
|
-
for (const shape of [
|
|
4471
|
-
data.config,
|
|
4472
|
-
header.config,
|
|
4473
|
-
header,
|
|
4474
|
-
data
|
|
4475
|
-
]) if (typeof shape?.model === "string" && shape.model.length > 0) return {
|
|
4476
|
-
model: shape.model,
|
|
4477
|
-
...typeof shape.provider === "string" && shape.provider.length > 0 ? { provider: shape.provider } : {}
|
|
4478
|
-
};
|
|
4479
|
-
return;
|
|
4480
|
-
}
|
|
4481
|
-
}
|
|
4482
|
-
/**
|
|
4483
|
-
* The route a spawned child inherits, by authority: an explicit Pi
|
|
4484
|
-
* ctx.setModel() override wins, then the caller's last durable request
|
|
4485
|
-
* (UI/`/model` switches land there), then the creation-time snapshot.
|
|
4486
|
-
*/
|
|
4487
|
-
function resolveCallerRoute(override, durable, snapshot) {
|
|
4488
|
-
const pick = override ?? durable ?? snapshot;
|
|
4489
|
-
if (typeof pick?.model !== "string" || pick.model.length === 0) return void 0;
|
|
4490
|
-
return pick;
|
|
4491
|
-
}
|
|
4492
4702
|
/** A session's durable events, whether the store exposes them as value or method. */
|
|
4493
4703
|
function eventsOf(session) {
|
|
4494
4704
|
return readSessionEvents(session);
|
|
@@ -4512,11 +4722,21 @@ function putSurface(ctx, state, agent, key, value) {
|
|
|
4512
4722
|
surfaces.setSurface(sessionIdOf(state, agent), state.packageName, key, value, state.theme);
|
|
4513
4723
|
}
|
|
4514
4724
|
function thinkingLevelOf(state, agent) {
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4725
|
+
return readAgentModel(agent)?.reasoningEffort ?? state.globalThinkingLevel;
|
|
4726
|
+
}
|
|
4727
|
+
function selectThinkingLevel(state, agent, level) {
|
|
4728
|
+
const selection = readAgentModel(agent);
|
|
4729
|
+
if (selection === void 0) throw new PiCapabilityError({
|
|
4730
|
+
capability: "pi.setThinkingLevel",
|
|
4731
|
+
reason: "No model is selected for this Agent.",
|
|
4732
|
+
guidance: "Select a model in DSH before choosing its reasoning effort."
|
|
4733
|
+
});
|
|
4734
|
+
const omitOff = level === "off" && (currentPiModel(state, agent)?.thinkingLevelMap)?.off === null;
|
|
4735
|
+
selectAgentModel(agent, {
|
|
4736
|
+
provider: selection.provider,
|
|
4737
|
+
model: selection.model,
|
|
4738
|
+
...omitOff ? {} : { reasoningEffort: level }
|
|
4739
|
+
});
|
|
4520
4740
|
}
|
|
4521
4741
|
function durableSeqOf(entryId) {
|
|
4522
4742
|
const match = /^dsh-(\d+)$/.exec(entryId);
|
|
@@ -4744,6 +4964,16 @@ function contextFor(ctx, state, agent, signal, command = false, sessionOverride,
|
|
|
4744
4964
|
}
|
|
4745
4965
|
};
|
|
4746
4966
|
const session = sessionOverride ?? agentSession(agent);
|
|
4967
|
+
if (!headlessUi && (state.tuiSurfaces !== void 0 || humanAnswererAvailable(userQuestions, agent, state.shared))) for (const kind of [
|
|
4968
|
+
"select",
|
|
4969
|
+
"confirm",
|
|
4970
|
+
"input",
|
|
4971
|
+
"editor",
|
|
4972
|
+
"custom"
|
|
4973
|
+
]) {
|
|
4974
|
+
const original = ui[kind];
|
|
4975
|
+
ui[kind] = (...args) => withUiPrompt(state.eventBus, kind, kind === "custom" ? void 0 : String(args[0] ?? ""), () => original(...args));
|
|
4976
|
+
}
|
|
4747
4977
|
const providerConfig = (name) => state.providers.get(name);
|
|
4748
4978
|
const catalog = state.modelCatalog;
|
|
4749
4979
|
const piNativeEntry = (provider, id) => {
|
|
@@ -4768,6 +4998,11 @@ function contextFor(ctx, state, agent, signal, command = false, sessionOverride,
|
|
|
4768
4998
|
};
|
|
4769
4999
|
const allModels = () => (catalog?.all() ?? []).map(restorePiShape);
|
|
4770
5000
|
const dshRoutedStream = (model, context, options) => {
|
|
5001
|
+
if (model.type !== void 0 && model.type !== "chat") throw new PiCapabilityError({
|
|
5002
|
+
capability: "modelRegistry.stream",
|
|
5003
|
+
reason: "The selected model is not a chat model.",
|
|
5004
|
+
guidance: "Choose a chat model from the DSH model directory."
|
|
5005
|
+
});
|
|
4771
5006
|
const llm = llmOf(ctx);
|
|
4772
5007
|
if (llm === void 0) throw new Error("pi2dsh: model calls need a DSH llm service; this composition mounts none");
|
|
4773
5008
|
return streamViaDshLlm(llm, {
|
|
@@ -4776,14 +5011,58 @@ function contextFor(ctx, state, agent, signal, command = false, sessionOverride,
|
|
|
4776
5011
|
options
|
|
4777
5012
|
});
|
|
4778
5013
|
};
|
|
5014
|
+
const nonChatResult = async (operation, model, options) => {
|
|
5015
|
+
const gap = {
|
|
5016
|
+
capability: `modelRegistry.${operation}`,
|
|
5017
|
+
packageName: state.packageName,
|
|
5018
|
+
reason: "DSH has no native non-chat model operation service.",
|
|
5019
|
+
guidance: "This model operation is unavailable; ordinary chat and independently implemented image tools are unaffected."
|
|
5020
|
+
};
|
|
5021
|
+
capabilityLedgerOf(ctx, state).reportDegraded(gap);
|
|
5022
|
+
const error = new PiCapabilityError(gap);
|
|
5023
|
+
const aborted = options?.signal instanceof AbortSignal && options.signal.aborted;
|
|
5024
|
+
return operation === "generateImages" ? imageErrorResult(model, error, aborted) : classifierErrorResult(model, error, aborted);
|
|
5025
|
+
};
|
|
5026
|
+
const dshRoutedSimpleStream = (model, context, options) => {
|
|
5027
|
+
const offSupported = model.thinkingLevelMap?.off !== null;
|
|
5028
|
+
return dshRoutedStream(model, context, options?.reasoning === void 0 && model.reasoning === true && offSupported ? {
|
|
5029
|
+
...options,
|
|
5030
|
+
reasoning: "off"
|
|
5031
|
+
} : options);
|
|
5032
|
+
};
|
|
4779
5033
|
const dshRoutedPiProvider = (base, providerId) => ({
|
|
4780
5034
|
...base,
|
|
4781
5035
|
id: providerId,
|
|
4782
5036
|
getModels: () => allModels().filter((model) => model.provider === providerId),
|
|
5037
|
+
getAllModels: () => allModels().filter((model) => model.provider === providerId),
|
|
4783
5038
|
stream: dshRoutedStream,
|
|
4784
|
-
streamSimple:
|
|
5039
|
+
streamSimple: dshRoutedSimpleStream,
|
|
5040
|
+
generateImages: (model, _context, options) => nonChatResult("generateImages", model, options),
|
|
5041
|
+
classify: (model, _context, options) => nonChatResult("classify", model, options)
|
|
4785
5042
|
});
|
|
4786
5043
|
const modelRegistry = {
|
|
5044
|
+
stream: dshRoutedStream,
|
|
5045
|
+
streamSimple: dshRoutedSimpleStream,
|
|
5046
|
+
getModelsOfType: (type, provider) => type === "chat" ? allModels().filter((model) => provider === void 0 || model.provider === provider) : [],
|
|
5047
|
+
getAvailableOfType: async (type, provider, options) => {
|
|
5048
|
+
options?.signal?.throwIfAborted();
|
|
5049
|
+
return type === "chat" ? allModels().filter((model) => provider === void 0 || model.provider === provider) : [];
|
|
5050
|
+
},
|
|
5051
|
+
getModelOfType: (type, provider, id) => type === "chat" ? allModels().find((model) => model.provider === provider && model.id === id) : void 0,
|
|
5052
|
+
findOfType: (type, provider, id) => type === "chat" ? allModels().find((model) => model.provider === provider && model.id === id) : void 0,
|
|
5053
|
+
registerVirtualModel: () => {
|
|
5054
|
+
const gap = {
|
|
5055
|
+
capability: "registerVirtualModel",
|
|
5056
|
+
packageName: state.packageName,
|
|
5057
|
+
reason: "Virtual selection, physical routing and branch-persistent router state have not been mapped.",
|
|
5058
|
+
guidance: "Select a physical model from the DSH directory instead."
|
|
5059
|
+
};
|
|
5060
|
+
capabilityLedgerOf(ctx, state).reportDegraded(gap);
|
|
5061
|
+
throw new PiCapabilityError(gap);
|
|
5062
|
+
},
|
|
5063
|
+
unregisterVirtualModel: () => {},
|
|
5064
|
+
generateImages: (model, _context, options) => nonChatResult("generateImages", model, options),
|
|
5065
|
+
classify: (model, _context, options) => nonChatResult("classify", model, options),
|
|
4787
5066
|
getAll: () => allModels(),
|
|
4788
5067
|
getAvailable: () => allModels(),
|
|
4789
5068
|
find: (provider, modelId) => {
|
|
@@ -4815,10 +5094,10 @@ function contextFor(ctx, state, agent, signal, command = false, sessionOverride,
|
|
|
4815
5094
|
}
|
|
4816
5095
|
return resolveHostModelAuth(ctx, provider);
|
|
4817
5096
|
},
|
|
4818
|
-
getProviderAuthStatus: (provider) =>
|
|
5097
|
+
getProviderAuthStatus: (provider) => ({ configured: (catalog?.all() ?? []).some((entry) => entry.provider === provider) }),
|
|
4819
5098
|
getProvider: (provider) => {
|
|
4820
5099
|
const base = providerConfig(provider);
|
|
4821
|
-
if (base !== void 0) return
|
|
5100
|
+
if (base !== void 0) return dshRoutedPiProvider(base, provider);
|
|
4822
5101
|
if ((catalog?.all() ?? []).some((entry) => entry.provider === provider)) return dshRoutedPiProvider({
|
|
4823
5102
|
id: provider,
|
|
4824
5103
|
name: provider
|
|
@@ -4989,11 +5268,7 @@ function contextFor(ctx, state, agent, signal, command = false, sessionOverride,
|
|
|
4989
5268
|
});
|
|
4990
5269
|
return { cancelled: true };
|
|
4991
5270
|
}
|
|
4992
|
-
const
|
|
4993
|
-
const created = sessions.create(void 0, { meta: {
|
|
4994
|
-
cwd: cwdOf(agent),
|
|
4995
|
-
...parent?.id === void 0 ? {} : { parentSession: parent.id }
|
|
4996
|
-
} });
|
|
5271
|
+
const created = sessions.create(void 0, { meta: { cwd: cwdOf(agent) } });
|
|
4997
5272
|
const withSession = options?.withSession;
|
|
4998
5273
|
await withSession?.(contextFor(ctx, state, agent, signal, true, created));
|
|
4999
5274
|
capabilityLedgerOf(ctx, state).reportHostDecision({
|
|
@@ -5022,10 +5297,14 @@ function contextFor(ctx, state, agent, signal, command = false, sessionOverride,
|
|
|
5022
5297
|
const events = readSessionEvents(source);
|
|
5023
5298
|
const requested = Math.min(position === "at" ? seq : seq - 1, events.length - 1);
|
|
5024
5299
|
const boundary = requested < 0 ? -1 : shrinkToTurnBoundary(events, requested);
|
|
5025
|
-
const child = boundary < 0 ? sessions.create(void 0, {
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5300
|
+
const child = boundary < 0 ? sessions.create(void 0, {
|
|
5301
|
+
seed: [],
|
|
5302
|
+
inheritedEventCount: 0,
|
|
5303
|
+
meta: {
|
|
5304
|
+
cwd: cwdOf(agent),
|
|
5305
|
+
isSeeded: true
|
|
5306
|
+
}
|
|
5307
|
+
}) : sessions.fork(source, boundary);
|
|
5029
5308
|
const withSession = options?.withSession;
|
|
5030
5309
|
await withSession?.(contextFor(ctx, state, agent, signal, true, child));
|
|
5031
5310
|
capabilityLedgerOf(ctx, state).reportHostDecision({
|
|
@@ -5053,10 +5332,14 @@ function contextFor(ctx, state, agent, signal, command = false, sessionOverride,
|
|
|
5053
5332
|
const events = readSessionEvents(source);
|
|
5054
5333
|
const capped = Math.min(seq, events.length - 1);
|
|
5055
5334
|
const boundary = capped < 0 ? -1 : shrinkToTurnBoundary(events, capped);
|
|
5056
|
-
const child = boundary < 0 ? sessions.create(void 0, {
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5335
|
+
const child = boundary < 0 ? sessions.create(void 0, {
|
|
5336
|
+
seed: [],
|
|
5337
|
+
inheritedEventCount: 0,
|
|
5338
|
+
meta: {
|
|
5339
|
+
cwd: cwdOf(agent),
|
|
5340
|
+
isSeeded: true
|
|
5341
|
+
}
|
|
5342
|
+
}) : sessions.fork(source, boundary);
|
|
5060
5343
|
if (options?.summarize === true) {
|
|
5061
5344
|
const summary = await summarizeAbandonedBranch(ctx, state, agent, events, boundary, options);
|
|
5062
5345
|
if (summary !== void 0) state.bridge.appendBranchSummary(String(child.id), summary, String(targetId));
|
|
@@ -5117,7 +5400,7 @@ function contextFor(ctx, state, agent, signal, command = false, sessionOverride,
|
|
|
5117
5400
|
async function dispatch(state, eventName, event, eventContext) {
|
|
5118
5401
|
const results = [];
|
|
5119
5402
|
const agent = eventContext.__agent;
|
|
5120
|
-
for (const handler of state.handlers.get(eventName) ?? []) results.push(await runInPiRuntime(state, agent, () => handler(event, eventContext)));
|
|
5403
|
+
for (const handler of [...state.handlers.get(eventName) ?? []]) results.push(await runInPiRuntime(state, agent, () => handler(event, eventContext)));
|
|
5121
5404
|
return results;
|
|
5122
5405
|
}
|
|
5123
5406
|
function shutdownPiSession(ctx, state, agent, reason, signal) {
|
|
@@ -5157,7 +5440,7 @@ async function dispatchBeforeProviderRequest(ctx, state, payload, request) {
|
|
|
5157
5440
|
...request.model,
|
|
5158
5441
|
provider: request.provider
|
|
5159
5442
|
};
|
|
5160
|
-
for (const handler of state.handlers.get("before_provider_request") ?? []) try {
|
|
5443
|
+
for (const handler of [...state.handlers.get("before_provider_request") ?? []]) try {
|
|
5161
5444
|
const result = await runInPiRuntime(state, agent, () => handler({
|
|
5162
5445
|
type: "before_provider_request",
|
|
5163
5446
|
payload: current
|
|
@@ -5635,7 +5918,10 @@ function subscribeLifecycle(ctx, state) {
|
|
|
5635
5918
|
type: "agent_end",
|
|
5636
5919
|
messages: []
|
|
5637
5920
|
}, eventContext);
|
|
5638
|
-
await dispatch(state, "agent_settled", {
|
|
5921
|
+
await dispatch(state, "agent_settled", {
|
|
5922
|
+
type: "agent_settled",
|
|
5923
|
+
aborted: (event.data?.reason)?.kind === "aborted"
|
|
5924
|
+
}, eventContext);
|
|
5639
5925
|
}).catch((error) => warn("turn end lifecycle", error));
|
|
5640
5926
|
};
|
|
5641
5927
|
state.projectSessionEvent = projectSessionEvent;
|
|
@@ -5646,20 +5932,6 @@ function subscribeLifecycle(ctx, state) {
|
|
|
5646
5932
|
if (ownedSession !== void 0 && state.sessionEventsLive !== true) return;
|
|
5647
5933
|
projectSessionEvent(session, event);
|
|
5648
5934
|
});
|
|
5649
|
-
cordis.on("agent/request", async (payload, next) => {
|
|
5650
|
-
const config = await next();
|
|
5651
|
-
const agent = payload.agent;
|
|
5652
|
-
if (agent === void 0 || !acceptsAgent(state, agent)) return config;
|
|
5653
|
-
const override = state.modelOverrides.get(agent);
|
|
5654
|
-
const thinking = state.thinkingLevels.get(agent);
|
|
5655
|
-
if (override === void 0 && thinking === void 0) return config;
|
|
5656
|
-
return {
|
|
5657
|
-
...config,
|
|
5658
|
-
...override?.provider === void 0 ? {} : { provider: override.provider },
|
|
5659
|
-
...override?.model === void 0 ? {} : { model: override.model },
|
|
5660
|
-
...thinking === void 0 || thinking === "off" && (currentPiModel(state, agent)?.thinkingLevelMap)?.off === null ? {} : { reasoningEffort: thinking }
|
|
5661
|
-
};
|
|
5662
|
-
});
|
|
5663
5935
|
cordis.effect(() => async () => {
|
|
5664
5936
|
await state.projection;
|
|
5665
5937
|
const agent = state.hostAgent;
|
|
@@ -5878,6 +6150,16 @@ function piViewOfToolArguments(state, name, args) {
|
|
|
5878
6150
|
}
|
|
5879
6151
|
function subscribeInterceptors(ctx, state) {
|
|
5880
6152
|
const cordis = ctx;
|
|
6153
|
+
cordis.on("tools/execute", async (exec, next) => {
|
|
6154
|
+
if (exec.parent !== void 0 && acceptsAgent(state, exec.agent)) await dispatch(state, "tool_execution_start", {
|
|
6155
|
+
type: "tool_execution_start",
|
|
6156
|
+
toolCallId: exec.callId,
|
|
6157
|
+
toolName: exec.name,
|
|
6158
|
+
args: piViewOfToolArguments(state, exec.name, exec.arguments),
|
|
6159
|
+
parentToolCallId: parentPiToolCallId(exec)
|
|
6160
|
+
}, contextFor(ctx, state, exec.agent, exec.signal));
|
|
6161
|
+
return next();
|
|
6162
|
+
});
|
|
5881
6163
|
cordis.on("tools/pre-execute", async (exec, next) => {
|
|
5882
6164
|
if (!acceptsAgent(state, exec.agent)) return next();
|
|
5883
6165
|
const original = piViewOfToolArguments(state, exec.name, exec.arguments);
|
|
@@ -5886,7 +6168,8 @@ function subscribeInterceptors(ctx, state) {
|
|
|
5886
6168
|
type: "tool_call",
|
|
5887
6169
|
toolName: exec.name,
|
|
5888
6170
|
toolCallId: exec.callId,
|
|
5889
|
-
input
|
|
6171
|
+
input,
|
|
6172
|
+
...parentPiToolCallId(exec) === void 0 ? {} : { parentToolCallId: parentPiToolCallId(exec) }
|
|
5890
6173
|
};
|
|
5891
6174
|
const results = await dispatch(state, "tool_call", event, contextFor(ctx, state, exec.agent, exec.signal));
|
|
5892
6175
|
if (!jsonEqual(event.input, original)) {
|
|
@@ -5922,6 +6205,7 @@ function subscribeInterceptors(ctx, state) {
|
|
|
5922
6205
|
const downstream = await next();
|
|
5923
6206
|
await dispatch(state, "tool_execution_end", {
|
|
5924
6207
|
type: "tool_execution_end",
|
|
6208
|
+
...parentPiToolCallId(exec) === void 0 ? {} : { parentToolCallId: parentPiToolCallId(exec) },
|
|
5925
6209
|
toolCallId: exec.callId,
|
|
5926
6210
|
toolName: exec.name,
|
|
5927
6211
|
result: {
|
|
@@ -5933,6 +6217,7 @@ function subscribeInterceptors(ctx, state) {
|
|
|
5933
6217
|
if (downstream.kind === "block") return downstream;
|
|
5934
6218
|
const event = {
|
|
5935
6219
|
type: "tool_result",
|
|
6220
|
+
...parentPiToolCallId(exec) === void 0 ? {} : { parentToolCallId: parentPiToolCallId(exec) },
|
|
5936
6221
|
toolName: exec.name,
|
|
5937
6222
|
toolCallId: exec.callId,
|
|
5938
6223
|
input: piViewOfToolArguments(state, exec.name, exec.arguments),
|
|
@@ -6019,6 +6304,7 @@ function subscribeInterceptors(ctx, state) {
|
|
|
6019
6304
|
if ((state.handlers.get("before_agent_start")?.length ?? 0) === 0) return downstream;
|
|
6020
6305
|
const event = {
|
|
6021
6306
|
type: "before_agent_start",
|
|
6307
|
+
messageType: "user",
|
|
6022
6308
|
prompt: "",
|
|
6023
6309
|
systemPrompt: original,
|
|
6024
6310
|
systemPromptOptions: {}
|
|
@@ -6065,16 +6351,26 @@ async function runBeforeAgentStart(ctx, state, agent, signal, assembled) {
|
|
|
6065
6351
|
const userMessages = claimed.map((entry) => entry.message).filter((message) => (message.source?.kind ?? "user") === "user");
|
|
6066
6352
|
const prompt = userMessages.flatMap((message) => textBlocks(message.content)).map((block) => block.text).join("\n");
|
|
6067
6353
|
const images = await collectPiImages(ctx, userMessages);
|
|
6354
|
+
const firstMessage = claimed[0].message;
|
|
6068
6355
|
const event = {
|
|
6069
6356
|
type: "before_agent_start",
|
|
6070
|
-
|
|
6071
|
-
|
|
6357
|
+
...typeof firstMessage.source?.piCustomType === "string" ? {
|
|
6358
|
+
messageType: "custom",
|
|
6359
|
+
message: {
|
|
6360
|
+
...await piShapeOfPending(ctx, firstMessage),
|
|
6361
|
+
display: false
|
|
6362
|
+
}
|
|
6363
|
+
} : {
|
|
6364
|
+
messageType: "user",
|
|
6365
|
+
prompt,
|
|
6366
|
+
...images.length > 0 ? { images } : {}
|
|
6367
|
+
},
|
|
6072
6368
|
systemPrompt: assembled,
|
|
6073
6369
|
systemPromptOptions: await piSystemPromptOptions(ctx, state, agent, claimed.map((entry) => entry.message))
|
|
6074
6370
|
};
|
|
6075
6371
|
const eventContext = contextFor(ctx, state, agent, signal);
|
|
6076
6372
|
const results = [];
|
|
6077
|
-
for (const handler of state.handlers.get("before_agent_start") ?? []) {
|
|
6373
|
+
for (const handler of [...state.handlers.get("before_agent_start") ?? []]) {
|
|
6078
6374
|
const result = await runInPiRuntime(state, agent, () => handler(event, eventContext));
|
|
6079
6375
|
results.push(result);
|
|
6080
6376
|
if (typeof result === "object" && result !== null && typeof result.systemPrompt === "string") event.systemPrompt = result.systemPrompt;
|
|
@@ -7089,7 +7385,43 @@ function registerLoginCommand(ctx, state) {
|
|
|
7089
7385
|
}
|
|
7090
7386
|
});
|
|
7091
7387
|
}
|
|
7388
|
+
function toolContextFor(ctx, state, exec) {
|
|
7389
|
+
const agent = exec.agent;
|
|
7390
|
+
const executeTool = nestedToolCaller(ctx, exec, (content) => dshToPiContent(ctx, content), (name, args) => {
|
|
7391
|
+
const peers = state.shared.runtimeStatesBySession.get(sessionIdOf(state, agent));
|
|
7392
|
+
const mapping = state.tools.has(name) || [...peers ?? []].some((peer) => peer.tools.has(name)) ? void 0 : HOST_TOOL_ARGUMENT_PROJECTION[name];
|
|
7393
|
+
if (mapping === void 0 || typeof args !== "object" || args === null || Array.isArray(args)) return cloneJson(args);
|
|
7394
|
+
const inverse = Object.fromEntries(Object.entries(mapping).map(([native, pi]) => [pi, native]));
|
|
7395
|
+
return Object.fromEntries(Object.entries(args).map(([key, value]) => [inverse[key] ?? key, cloneJson(value)]));
|
|
7396
|
+
});
|
|
7397
|
+
return {
|
|
7398
|
+
...contextFor(ctx, state, agent, exec.signal),
|
|
7399
|
+
executeTool,
|
|
7400
|
+
get tools() {
|
|
7401
|
+
return ctx.tools.definitions(exec.agent, exec.toolSet).map((tool) => ({
|
|
7402
|
+
name: tool.name,
|
|
7403
|
+
label: tool.name,
|
|
7404
|
+
description: tool.description,
|
|
7405
|
+
parameters: cloneJson(tool.parameters),
|
|
7406
|
+
execute: async (_id, args, signal, onUpdate) => (await executeTool(tool.name, args, {
|
|
7407
|
+
...signal === void 0 ? {} : { signal },
|
|
7408
|
+
...onUpdate === void 0 ? {} : { onUpdate }
|
|
7409
|
+
})).result
|
|
7410
|
+
}));
|
|
7411
|
+
}
|
|
7412
|
+
};
|
|
7413
|
+
}
|
|
7092
7414
|
function registerTool(ctx, state, tool) {
|
|
7415
|
+
if (tool.exposure === "codemode" || tool.exposure === "model-only" || tool.prepareLoadout !== void 0) {
|
|
7416
|
+
const gap = {
|
|
7417
|
+
capability: "registerTool.loadout",
|
|
7418
|
+
packageName: state.packageName,
|
|
7419
|
+
reason: "Pi separates nested-tool reachability from model declarations; this bridge does not yet translate that loadout contract.",
|
|
7420
|
+
guidance: "Use a directly exposed tool; this loadout is refused rather than changing which tools the model may call."
|
|
7421
|
+
};
|
|
7422
|
+
capabilityLedgerOf(ctx, state).reportDegraded(gap);
|
|
7423
|
+
throw new PiCapabilityError(gap);
|
|
7424
|
+
}
|
|
7093
7425
|
if (state.tools.has(tool.name)) {
|
|
7094
7426
|
const previous = state.tools.get(tool.name);
|
|
7095
7427
|
state.tools.set(tool.name, tool);
|
|
@@ -7108,7 +7440,11 @@ function registerTool(ctx, state, tool) {
|
|
|
7108
7440
|
description: tool.description,
|
|
7109
7441
|
parameters: normalized.schema,
|
|
7110
7442
|
output: {
|
|
7111
|
-
schema: {}
|
|
7443
|
+
schema: tool.outputSchema === void 0 ? {} : {
|
|
7444
|
+
type: "object",
|
|
7445
|
+
properties: { structuredContent: tool.outputSchema },
|
|
7446
|
+
required: ["structuredContent"]
|
|
7447
|
+
},
|
|
7112
7448
|
render: (_args, value) => value.content,
|
|
7113
7449
|
presentationMeta: (_args, value) => jsonValue(value.details)
|
|
7114
7450
|
},
|
|
@@ -7127,15 +7463,17 @@ function registerTool(ctx, state, tool) {
|
|
|
7127
7463
|
name: live.name,
|
|
7128
7464
|
arguments: live.prepareArguments?.(cloneJson(effective)) ?? effective
|
|
7129
7465
|
});
|
|
7130
|
-
const result = await normalizeToolResultForDsh(ctx, await runInPiRuntime(state, agent, () => live.execute(String(exec.callId), prepared, exec.signal, (update) => {
|
|
7466
|
+
const result = await normalizeToolResultForDsh(ctx, await withPiToolIdentity(exec, () => runInPiRuntime(state, agent, () => live.execute(String(exec.callId), prepared, exec.signal, (update) => {
|
|
7467
|
+
publishNestedToolUpdate(exec, update);
|
|
7131
7468
|
dispatch(state, "tool_execution_update", {
|
|
7132
7469
|
type: "tool_execution_update",
|
|
7470
|
+
...parentPiToolCallId(exec) === void 0 ? {} : { parentToolCallId: parentPiToolCallId(exec) },
|
|
7133
7471
|
toolCallId: String(exec.callId),
|
|
7134
7472
|
toolName: tool.name,
|
|
7135
7473
|
args: prepared,
|
|
7136
7474
|
partialResult: jsonValue(update)
|
|
7137
7475
|
}, contextFor(ctx, state, agent, exec.signal)).catch((error) => logger(ctx).warn(`[pi2dsh] tool_execution_update handler failed: ${String(error)}`));
|
|
7138
|
-
},
|
|
7476
|
+
}, toolContextFor(ctx, state, exec)))));
|
|
7139
7477
|
if (result.terminate === true) exec.concludeTurn();
|
|
7140
7478
|
if (result.isError === true) {
|
|
7141
7479
|
const message = textBlocks(result.content).map((block) => block.text).filter(Boolean).join("\n");
|
|
@@ -7144,7 +7482,8 @@ function registerTool(ctx, state, tool) {
|
|
|
7144
7482
|
return result;
|
|
7145
7483
|
}
|
|
7146
7484
|
};
|
|
7147
|
-
const
|
|
7485
|
+
const conditional = tool.defaultActive === false || tool.exposure === "hidden" || tool.exposure === "deferred";
|
|
7486
|
+
const dispose = ctx.tools.register(definition, conditional ? { when: () => tool.exposure !== "hidden" && state.pendingActiveTools?.includes(tool.name) === true } : void 0);
|
|
7148
7487
|
state.toolDisposers.set(tool.name, dispose);
|
|
7149
7488
|
if (isKnownImageTool(state.packageName, tool.name)) state.shared.browserSurfaces?.registerImageTool(tool.name);
|
|
7150
7489
|
}
|
|
@@ -7181,7 +7520,7 @@ function registerChildPiTool(childCtx, state, tool) {
|
|
|
7181
7520
|
name: tool.name,
|
|
7182
7521
|
arguments: tool.prepareArguments?.(cloneJson(args)) ?? args
|
|
7183
7522
|
});
|
|
7184
|
-
const result = await normalizeToolResultForDsh(childCtx, await runInPiRuntime(state, agent, () => tool.execute(String(exec.callId), prepared, exec.signal, () =>
|
|
7523
|
+
const result = await normalizeToolResultForDsh(childCtx, await withPiToolIdentity(exec, () => runInPiRuntime(state, agent, () => tool.execute(String(exec.callId), prepared, exec.signal, (update) => publishNestedToolUpdate(exec, update), toolContextFor(childCtx, state, exec)))));
|
|
7185
7524
|
if (result.terminate === true) exec.concludeTurn();
|
|
7186
7525
|
if (result.isError === true) {
|
|
7187
7526
|
const message = textBlocks(result.content).map((block) => block.text).filter(Boolean).join("\n");
|
|
@@ -7245,7 +7584,13 @@ function piToolPromptContribution(ctx, state) {
|
|
|
7245
7584
|
}
|
|
7246
7585
|
function getActiveTools(ctx, state) {
|
|
7247
7586
|
const agent = currentAgent(state);
|
|
7248
|
-
|
|
7587
|
+
const names = new Set(toolRuntime(ctx, agent).schemas(agent).map((tool) => tool.name));
|
|
7588
|
+
for (const [name, tool] of state.tools) if (tool.exposure === "hidden") names.delete(name);
|
|
7589
|
+
else if (tool.defaultActive === false || tool.exposure === "deferred") {
|
|
7590
|
+
if (state.pendingActiveTools?.includes(name)) names.add(name);
|
|
7591
|
+
else names.delete(name);
|
|
7592
|
+
}
|
|
7593
|
+
return [...names];
|
|
7249
7594
|
}
|
|
7250
7595
|
/**
|
|
7251
7596
|
* Pi's `setActiveTools`, on DSH's restriction seam.
|
|
@@ -7614,6 +7959,20 @@ function registerSharedProviderRoute(ctx, state, name, value) {
|
|
|
7614
7959
|
await discoverProviderModels(ctx, state, name, canonical);
|
|
7615
7960
|
},
|
|
7616
7961
|
warn: (message) => logger(ctx).warn(message),
|
|
7962
|
+
onProviderStreamEvent: async (data, request) => {
|
|
7963
|
+
const peers = request.sessionId === void 0 ? void 0 : shared.runtimeStatesBySession.get(request.sessionId);
|
|
7964
|
+
for (const peer of peers === void 0 || peers.size === 0 ? [state] : [...peers]) try {
|
|
7965
|
+
await dispatch(peer, "provider_stream_event", {
|
|
7966
|
+
type: "provider_stream_event",
|
|
7967
|
+
provider: request.provider,
|
|
7968
|
+
api: request.model.api,
|
|
7969
|
+
model: request.model.id,
|
|
7970
|
+
data
|
|
7971
|
+
}, contextFor(ctx, peer, currentAgent(peer), request.signal));
|
|
7972
|
+
} catch (error) {
|
|
7973
|
+
logger(ctx).warn(`[pi2dsh] provider stream observer failed: ${String(error)}`);
|
|
7974
|
+
}
|
|
7975
|
+
},
|
|
7617
7976
|
beforeProviderRequest: (payload, request) => dispatchHostProviderRequest(ctx, shared, state, payload, request),
|
|
7618
7977
|
resolveAttachments: () => optionalService(ctx, "attachments")
|
|
7619
7978
|
}
|
|
@@ -7741,12 +8100,59 @@ function unregisterPiProvider(ctx, state, name) {
|
|
|
7741
8100
|
if (restored !== void 0) registerSharedProviderRoute(ctx, state, name, restored);
|
|
7742
8101
|
}
|
|
7743
8102
|
}
|
|
7744
|
-
function createPiApi(ctx, state) {
|
|
8103
|
+
function createPiApi(ctx, state, extensionPath = state.packageName) {
|
|
8104
|
+
state.mcpOwners.add(extensionPath);
|
|
8105
|
+
const unavailable = (capability, reason) => {
|
|
8106
|
+
const gap = {
|
|
8107
|
+
capability,
|
|
8108
|
+
reason,
|
|
8109
|
+
packageName: state.packageName,
|
|
8110
|
+
guidance: "This capability is unavailable in this bridge; configure the supported behavior through DSH."
|
|
8111
|
+
};
|
|
8112
|
+
capabilityLedgerOf(ctx, state).reportDegraded(gap);
|
|
8113
|
+
throw new PiCapabilityError(gap);
|
|
8114
|
+
};
|
|
7745
8115
|
return {
|
|
8116
|
+
getSettings: () => {
|
|
8117
|
+
const defaults = optionalService(ctx, "agentDefaultModel")?.currentSelection();
|
|
8118
|
+
if (defaults === void 0) return {};
|
|
8119
|
+
const level = defaults.reasoningEffort;
|
|
8120
|
+
return {
|
|
8121
|
+
defaultProvider: defaults.provider,
|
|
8122
|
+
defaultModel: defaults.model,
|
|
8123
|
+
...level !== void 0 && [
|
|
8124
|
+
"off",
|
|
8125
|
+
"minimal",
|
|
8126
|
+
"low",
|
|
8127
|
+
"medium",
|
|
8128
|
+
"high",
|
|
8129
|
+
"xhigh",
|
|
8130
|
+
"max"
|
|
8131
|
+
].includes(level) ? { defaultThinkingLevel: level } : {}
|
|
8132
|
+
};
|
|
8133
|
+
},
|
|
8134
|
+
registerVirtualModel: () => unavailable("registerVirtualModel", "Pi virtual selection and physical request routing require a pre-request routing decision and branch-persistent router state, not a second provider runtime."),
|
|
8135
|
+
unregisterVirtualModel: () => {},
|
|
8136
|
+
registerToolRenderer: (_resolver) => {
|
|
8137
|
+
capabilityLedgerOf(ctx, state).reportHostDecision({
|
|
8138
|
+
capability: "registerToolRenderer",
|
|
8139
|
+
packageName: state.packageName,
|
|
8140
|
+
reason: "Tool drawing is owned by the DSH surface; Pi renderer resolvers are not consumed.",
|
|
8141
|
+
guidance: ""
|
|
8142
|
+
});
|
|
8143
|
+
},
|
|
8144
|
+
registerMcpServer: (name, config) => registerMcpServer(state.eventBus, extensionPath, name, config),
|
|
8145
|
+
unregisterMcpServer: (name) => mcpRegistrations(state.eventBus).unregister(name, extensionPath),
|
|
8146
|
+
getMcpServers: () => mcpRegistrations(state.eventBus).list(),
|
|
7746
8147
|
on(event, handler) {
|
|
7747
8148
|
const list = state.handlers.get(event) ?? [];
|
|
7748
|
-
|
|
8149
|
+
const registered = (event, context) => handler(event, context);
|
|
8150
|
+
list.push(registered);
|
|
7749
8151
|
state.handlers.set(event, list);
|
|
8152
|
+
return () => {
|
|
8153
|
+
const index = list.indexOf(registered);
|
|
8154
|
+
if (index !== -1) list.splice(index, 1);
|
|
8155
|
+
};
|
|
7750
8156
|
},
|
|
7751
8157
|
registerTool: (tool) => registerTool(ctx, state, tool),
|
|
7752
8158
|
unregisterTool: (name) => unregisterTool(state, name),
|
|
@@ -7861,7 +8267,14 @@ function createPiApi(ctx, state) {
|
|
|
7861
8267
|
};
|
|
7862
8268
|
if (override.model === void 0) return false;
|
|
7863
8269
|
const previousModel = currentPiModel(state, agent);
|
|
7864
|
-
|
|
8270
|
+
const current = readAgentModel(agent);
|
|
8271
|
+
const provider = override.provider ?? current?.provider;
|
|
8272
|
+
if (provider === void 0) return false;
|
|
8273
|
+
selectAgentModel(agent, {
|
|
8274
|
+
provider,
|
|
8275
|
+
model: override.model,
|
|
8276
|
+
...current?.reasoningEffort === void 0 ? {} : { reasoningEffort: current.reasoningEffort }
|
|
8277
|
+
});
|
|
7865
8278
|
dispatch(state, "model_select", {
|
|
7866
8279
|
type: "model_select",
|
|
7867
8280
|
model,
|
|
@@ -7875,7 +8288,7 @@ function createPiApi(ctx, state) {
|
|
|
7875
8288
|
const agent = currentAgent(state);
|
|
7876
8289
|
const previousLevel = thinkingLevelOf(state, agent);
|
|
7877
8290
|
if (agent === void 0) state.globalThinkingLevel = String(level);
|
|
7878
|
-
else state
|
|
8291
|
+
else selectThinkingLevel(state, agent, String(level));
|
|
7879
8292
|
dispatch(state, "thinking_level_select", {
|
|
7880
8293
|
type: "thinking_level_select",
|
|
7881
8294
|
level: String(level),
|
|
@@ -8031,7 +8444,7 @@ async function loadExtensions(rootDir, manifest, api, onExtensionError, onCapabi
|
|
|
8031
8444
|
const loaded = await jiti.import(join(rootDir, extension));
|
|
8032
8445
|
const candidate = typeof loaded === "object" && loaded !== null && "default" in loaded ? loaded.default : loaded;
|
|
8033
8446
|
if (typeof candidate !== "function") throw new TypeError(`Pi extension ${extension} has no default factory function`);
|
|
8034
|
-
await candidate(api);
|
|
8447
|
+
await candidate(api(join(rootDir, extension)));
|
|
8035
8448
|
mounted += 1;
|
|
8036
8449
|
} catch (error) {
|
|
8037
8450
|
if (error instanceof PiCapabilityError || error instanceof Error && error.name === "PiCapabilityError") onCapabilityGap?.(error, extension);
|
|
@@ -8066,6 +8479,7 @@ async function applyPiPackage(ctx, options) {
|
|
|
8066
8479
|
const state = {
|
|
8067
8480
|
shared,
|
|
8068
8481
|
packageName: options.manifest.package.name,
|
|
8482
|
+
mcpOwners: /* @__PURE__ */ new Set(),
|
|
8069
8483
|
ownerAgent,
|
|
8070
8484
|
hostAnchor: options.hostAnchor === true,
|
|
8071
8485
|
handlers: /* @__PURE__ */ new Map(),
|
|
@@ -8112,8 +8526,6 @@ async function applyPiPackage(ctx, options) {
|
|
|
8112
8526
|
autocompleteProviders: [],
|
|
8113
8527
|
editorBuffers: /* @__PURE__ */ new WeakMap(),
|
|
8114
8528
|
toolsExpanded: false,
|
|
8115
|
-
modelOverrides: /* @__PURE__ */ new WeakMap(),
|
|
8116
|
-
thinkingLevels: /* @__PURE__ */ new WeakMap(),
|
|
8117
8529
|
childAgents: /* @__PURE__ */ new WeakSet(),
|
|
8118
8530
|
turnSystemPromptOverrides: /* @__PURE__ */ new WeakMap(),
|
|
8119
8531
|
projection: Promise.resolve(),
|
|
@@ -8144,6 +8556,33 @@ async function applyPiPackage(ctx, options) {
|
|
|
8144
8556
|
}, surfaceInstanceKey);
|
|
8145
8557
|
subscribeLifecycle(ctx, state);
|
|
8146
8558
|
subscribeInterceptors(ctx, state);
|
|
8559
|
+
const onMcpChange = (servers) => {
|
|
8560
|
+
const agent = currentAgent(state);
|
|
8561
|
+
if (!state.extensionsReady || agent === void 0 || state.hostAnchor) return;
|
|
8562
|
+
state.projection = state.projection.then(async () => {
|
|
8563
|
+
await dispatch(state, "mcp_servers_change", {
|
|
8564
|
+
type: "mcp_servers_change",
|
|
8565
|
+
servers
|
|
8566
|
+
}, contextFor(ctx, state, agent, void 0));
|
|
8567
|
+
}).catch((error) => logger(ctx).warn(`[pi2dsh] mcp_servers_change handler failed: ${String(error)}`));
|
|
8568
|
+
};
|
|
8569
|
+
state.eventBus.on(mcpRegistrationChanged, onMcpChange);
|
|
8570
|
+
const onUiPrompt = (event) => {
|
|
8571
|
+
const agent = currentAgent(state);
|
|
8572
|
+
if (!state.extensionsReady || agent === void 0 || state.hostAnchor) return;
|
|
8573
|
+
dispatch(state, String(event.type), event, contextFor(ctx, state, agent, void 0)).catch((error) => logger(ctx).warn(`[pi2dsh] UI prompt observer failed: ${String(error)}`));
|
|
8574
|
+
};
|
|
8575
|
+
state.eventBus.on(uiPromptChanged, onUiPrompt);
|
|
8576
|
+
const clearOwnedMcp = () => {
|
|
8577
|
+
const registry = mcpRegistrations(state.eventBus);
|
|
8578
|
+
for (const server of registry.list()) if (state.mcpOwners.has(server.extensionPath)) registry.unregister(server.name, server.extensionPath);
|
|
8579
|
+
state.mcpOwners.clear();
|
|
8580
|
+
};
|
|
8581
|
+
ctx.effect(() => () => {
|
|
8582
|
+
state.eventBus.off(mcpRegistrationChanged, onMcpChange);
|
|
8583
|
+
state.eventBus.off(uiPromptChanged, onUiPrompt);
|
|
8584
|
+
clearOwnedMcp();
|
|
8585
|
+
});
|
|
8147
8586
|
shared.providerBuiltins ??= /* @__PURE__ */ new Map();
|
|
8148
8587
|
for (const provider of builtinProviders()) {
|
|
8149
8588
|
const config = {
|
|
@@ -8527,28 +8966,12 @@ async function applyPiPackage(ctx, options) {
|
|
|
8527
8966
|
parentModelRoute: () => {
|
|
8528
8967
|
const parent = currentAgent(state);
|
|
8529
8968
|
if (parent === void 0) return void 0;
|
|
8530
|
-
|
|
8531
|
-
return resolveCallerRoute(state.modelOverrides.get(parent), lastRequestRouteOf(agentSession(parent)), typeof options?.model === "string" ? {
|
|
8532
|
-
model: options.model,
|
|
8533
|
-
...typeof options.provider === "string" ? { provider: options.provider } : {}
|
|
8534
|
-
} : void 0);
|
|
8969
|
+
return readAgentModel(parent);
|
|
8535
8970
|
},
|
|
8536
8971
|
adoptChildAgent: (child, thinkingLevel) => {
|
|
8537
8972
|
if (typeof child !== "object" || child === null) return;
|
|
8538
8973
|
state.childAgents.add(child);
|
|
8539
|
-
if (typeof thinkingLevel === "string" && thinkingLevel.length > 0)
|
|
8540
|
-
state.thinkingLevels.set(child, thinkingLevel);
|
|
8541
|
-
child.ctx?.on?.("agent/request", async (payload, next) => {
|
|
8542
|
-
const config = await next();
|
|
8543
|
-
if (payload.agent !== child) return config;
|
|
8544
|
-
const level = state.thinkingLevels.get(child);
|
|
8545
|
-
if (level === void 0 || level === "off" && (currentPiModel(state, child)?.thinkingLevelMap)?.off === null) return config;
|
|
8546
|
-
return {
|
|
8547
|
-
...config,
|
|
8548
|
-
reasoningEffort: level
|
|
8549
|
-
};
|
|
8550
|
-
});
|
|
8551
|
-
}
|
|
8974
|
+
if (typeof thinkingLevel === "string" && thinkingLevel.length > 0) selectThinkingLevel(state, child, thinkingLevel);
|
|
8552
8975
|
}
|
|
8553
8976
|
});
|
|
8554
8977
|
await registerPromptCommands(ctx, state, rootDir, options.manifest);
|
|
@@ -8565,7 +8988,7 @@ async function applyPiPackage(ctx, options) {
|
|
|
8565
8988
|
guidance: "",
|
|
8566
8989
|
packageName: state.packageName
|
|
8567
8990
|
});
|
|
8568
|
-
const mountExtensions = () => runInPiRuntime(state, currentAgent(state), () => loadExtensions(rootDir, options.manifest, createPiApi(ctx, state), onExtensionError, onCapabilityGap, onHostInfraReference));
|
|
8991
|
+
const mountExtensions = () => runInPiRuntime(state, currentAgent(state), () => loadExtensions(rootDir, options.manifest, (extensionPath) => createPiApi(ctx, state, extensionPath), onExtensionError, onCapabilityGap, onHostInfraReference));
|
|
8569
8992
|
await mountExtensions();
|
|
8570
8993
|
await flushPendingSessionStarts(ctx, state);
|
|
8571
8994
|
const remounts = packageRemountsOf(ctx, shared);
|
|
@@ -8578,6 +9001,7 @@ async function applyPiPackage(ctx, options) {
|
|
|
8578
9001
|
state.shutdownTasks.delete(previousAgent);
|
|
8579
9002
|
}
|
|
8580
9003
|
state.extensionsReady = false;
|
|
9004
|
+
clearOwnedMcp();
|
|
8581
9005
|
state.handlers.clear();
|
|
8582
9006
|
for (const off of state.eventBusOffs.splice(0)) off();
|
|
8583
9007
|
try {
|
|
@@ -8620,8 +9044,6 @@ const runtimeInternals = {
|
|
|
8620
9044
|
compactionReason,
|
|
8621
9045
|
resolveOfferedChoice,
|
|
8622
9046
|
currentPiModel,
|
|
8623
|
-
lastRequestRouteOf,
|
|
8624
|
-
resolveCallerRoute,
|
|
8625
9047
|
resolveChildExtensionPackages,
|
|
8626
9048
|
dshToPiContent,
|
|
8627
9049
|
expandPrompt,
|
|
@@ -8635,4 +9057,4 @@ const runtimeInternals = {
|
|
|
8635
9057
|
//#endregion
|
|
8636
9058
|
export { overlayProviderConfig as a, runtimeInternals as c, normalizeToolSchema as i, getSharedChildExtensionCatalog as n, registerChildExtensionCatalog as o, mergeProviderRegistration as r, registerVisionCompanions as s, applyPiPackage as t };
|
|
8637
9059
|
|
|
8638
|
-
//# sourceMappingURL=runtime-
|
|
9060
|
+
//# sourceMappingURL=runtime-Dq4Y535P.mjs.map
|