pi2dsh 0.2.0 → 0.3.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/README.md +44 -19
- package/README.zh.md +44 -19
- package/dist/build-DsGYAgiT.mjs +4416 -0
- package/dist/build-DsGYAgiT.mjs.map +1 -0
- package/dist/cli.mjs +2 -2
- package/dist/compat/pi-ai.d.mts +195 -2435
- package/dist/compat/pi-ai.d.mts.map +1 -1
- package/dist/compat/pi-ai.mjs +3 -4668
- package/dist/compat/pi-coding-agent.d.mts +333 -14
- package/dist/compat/pi-coding-agent.d.mts.map +1 -1
- package/dist/compat/pi-coding-agent.mjs +2 -2
- package/dist/compat/pi-tui.mjs +1 -3620
- package/dist/credentials-oauth.d.mts +27 -0
- package/dist/credentials-oauth.d.mts.map +1 -0
- package/dist/credentials-oauth.mjs +91 -0
- package/dist/credentials-oauth.mjs.map +1 -0
- package/dist/host.mjs +4 -2
- package/dist/host.mjs.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/{mcp-config-jL9w70It.mjs → mcp-config-gqg7GJEE.mjs} +115 -51
- package/dist/mcp-config-gqg7GJEE.mjs.map +1 -0
- package/dist/oauth-bridge-BpPrppjR.mjs +359 -0
- package/dist/oauth-bridge-BpPrppjR.mjs.map +1 -0
- package/dist/pi-ai-CWFlgigJ.mjs +2947 -0
- package/dist/pi-ai-CWFlgigJ.mjs.map +1 -0
- package/dist/pi-coding-agent-Z1hTs61i.mjs +5203 -0
- package/dist/pi-coding-agent-Z1hTs61i.mjs.map +1 -0
- package/dist/pi-tui-5CYLcj-_.mjs +4512 -0
- package/dist/pi-tui-5CYLcj-_.mjs.map +1 -0
- package/dist/pi-types-BLt46jaf.d.mts +2494 -0
- package/dist/pi-types-BLt46jaf.d.mts.map +1 -0
- package/dist/{rolldown-runtime-C2Q2p085.mjs → rolldown-runtime-D-uZhY3_.mjs} +3 -2
- package/dist/{runtime-D84Hv_3m.mjs → runtime-6DefpI6h.mjs} +344 -23
- package/dist/runtime-6DefpI6h.mjs.map +1 -0
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/{source-D7Ir-rPT.mjs → source-0sA5z08z.mjs} +6 -2
- package/dist/source-0sA5z08z.mjs.map +1 -0
- package/package.json +14 -1
- package/dist/compat/pi-ai.mjs.map +0 -1
- package/dist/compat/pi-tui.mjs.map +0 -1
- package/dist/mcp-config-jL9w70It.mjs.map +0 -1
- package/dist/pi-coding-agent-Dsg6_0ua.mjs +0 -2060
- package/dist/pi-coding-agent-Dsg6_0ua.mjs.map +0 -1
- package/dist/pi-tui-utils-CcaVtm-3.mjs +0 -895
- package/dist/pi-tui-utils-CcaVtm-3.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/pi-uuid-Db8ShZsK.mjs +0 -47
- package/dist/pi-uuid-Db8ShZsK.mjs.map +0 -1
- package/dist/runtime-D84Hv_3m.mjs.map +0 -1
- package/dist/source-D7Ir-rPT.mjs.map +0 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
import { t as getAgentDir } from "./pi-config-shim-CZ1wFzqM.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { E as __setSubagentSessionFactory, S as Theme, f as ExtensionRunner } from "./pi-coding-agent-Z1hTs61i.mjs";
|
|
4
|
+
import { a as storedOAuthCredential, i as resolveOAuthApiKey, n as loginPiProvider, r as providerSupportsOAuth, t as FileCredentialStore } from "./oauth-bridge-BpPrppjR.mjs";
|
|
5
|
+
import { r as builtinProviders } from "./pi-ai-CWFlgigJ.mjs";
|
|
4
6
|
import { createRequire } from "node:module";
|
|
5
7
|
import { access, readFile } from "node:fs/promises";
|
|
6
8
|
import { join } from "node:path";
|
|
@@ -277,6 +279,221 @@ var PiSessionBridge = class {
|
|
|
277
279
|
}
|
|
278
280
|
};
|
|
279
281
|
//#endregion
|
|
282
|
+
//#region src/subagent-bridge.ts
|
|
283
|
+
let subagentSerial = 0;
|
|
284
|
+
var PiBridgedAgentSession = class {
|
|
285
|
+
agent = {};
|
|
286
|
+
messages = [];
|
|
287
|
+
#host;
|
|
288
|
+
#handle;
|
|
289
|
+
#session;
|
|
290
|
+
#tools;
|
|
291
|
+
#subscribers = /* @__PURE__ */ new Set();
|
|
292
|
+
#disposers = [];
|
|
293
|
+
#activeToolNames;
|
|
294
|
+
#sessionName = "";
|
|
295
|
+
#turns = 0;
|
|
296
|
+
#aborted = false;
|
|
297
|
+
constructor(host, handle, tools) {
|
|
298
|
+
this.#host = host;
|
|
299
|
+
this.#handle = handle;
|
|
300
|
+
this.#session = handle.agent.session ?? {};
|
|
301
|
+
this.#tools = tools;
|
|
302
|
+
this.#activeToolNames = tools.map((tool) => tool?.name).filter((name) => typeof name === "string");
|
|
303
|
+
const cordis = host.cordis;
|
|
304
|
+
const offEvents = cordis.on("session/event", (session, event) => {
|
|
305
|
+
if (session !== this.#session) return;
|
|
306
|
+
this.#project(event);
|
|
307
|
+
});
|
|
308
|
+
const offPre = cordis.on("tools/pre-execute", async (exec, next) => {
|
|
309
|
+
if (exec.agent !== this.#handle.agent || this.agent.beforeToolCall === void 0) return next();
|
|
310
|
+
const decision = await this.agent.beforeToolCall({ toolCall: {
|
|
311
|
+
name: exec.name,
|
|
312
|
+
id: exec.callId,
|
|
313
|
+
arguments: exec.arguments
|
|
314
|
+
} }, void 0);
|
|
315
|
+
if (decision?.block === true) return {
|
|
316
|
+
kind: "deny",
|
|
317
|
+
reason: decision.reason ?? `Tool "${exec.name}" is not available to this subagent.`
|
|
318
|
+
};
|
|
319
|
+
return next();
|
|
320
|
+
});
|
|
321
|
+
this.#disposers.push(offEvents, offPre);
|
|
322
|
+
}
|
|
323
|
+
#project(event) {
|
|
324
|
+
const type = event.type;
|
|
325
|
+
const emit = (piEvent) => {
|
|
326
|
+
for (const handler of [...this.#subscribers]) try {
|
|
327
|
+
handler(piEvent);
|
|
328
|
+
} catch {}
|
|
329
|
+
};
|
|
330
|
+
if (type === "turn/start") emit({
|
|
331
|
+
type: "turn_start",
|
|
332
|
+
turnIndex: Number(event.data.turn ?? 1) - 1
|
|
333
|
+
});
|
|
334
|
+
if (type === "tool/call") {
|
|
335
|
+
const data = event.data;
|
|
336
|
+
let args = {};
|
|
337
|
+
try {
|
|
338
|
+
args = JSON.parse(String(data.arguments ?? "{}"));
|
|
339
|
+
} catch {
|
|
340
|
+
args = {};
|
|
341
|
+
}
|
|
342
|
+
emit({
|
|
343
|
+
type: "tool_execution_start",
|
|
344
|
+
toolCallId: data.callId,
|
|
345
|
+
toolName: data.name,
|
|
346
|
+
args
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
if (type === "assistant/chunk") {
|
|
350
|
+
const chunk = event.data.chunk ?? {};
|
|
351
|
+
const delta = typeof chunk.text === "string" ? chunk.text : typeof chunk.delta === "string" ? chunk.delta : "";
|
|
352
|
+
emit({
|
|
353
|
+
type: "message_update",
|
|
354
|
+
message: {
|
|
355
|
+
role: "assistant",
|
|
356
|
+
content: [{
|
|
357
|
+
type: "text",
|
|
358
|
+
text: delta
|
|
359
|
+
}]
|
|
360
|
+
},
|
|
361
|
+
assistantMessageEvent: {
|
|
362
|
+
type: "text_delta",
|
|
363
|
+
delta,
|
|
364
|
+
...chunk
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
const message = this.#host.messageFromSessionEvent(event);
|
|
369
|
+
if (message !== void 0) {
|
|
370
|
+
this.messages.push(message);
|
|
371
|
+
emit({
|
|
372
|
+
type: "message_start",
|
|
373
|
+
message
|
|
374
|
+
});
|
|
375
|
+
emit({
|
|
376
|
+
type: "message_end",
|
|
377
|
+
message
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
if (type === "turn/end") {
|
|
381
|
+
this.#turns += 1;
|
|
382
|
+
emit({
|
|
383
|
+
type: "turn_end",
|
|
384
|
+
turnIndex: Number(event.data.turn ?? 1) - 1,
|
|
385
|
+
message: {
|
|
386
|
+
role: "assistant",
|
|
387
|
+
content: []
|
|
388
|
+
},
|
|
389
|
+
toolResults: []
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
subscribe(handler) {
|
|
394
|
+
this.#subscribers.add(handler);
|
|
395
|
+
return () => this.#subscribers.delete(handler);
|
|
396
|
+
}
|
|
397
|
+
async prompt(text) {
|
|
398
|
+
const blocks = await this.#host.piContentToDsh([{
|
|
399
|
+
type: "text",
|
|
400
|
+
text: String(text)
|
|
401
|
+
}]);
|
|
402
|
+
const cordis = this.#host.cordis;
|
|
403
|
+
const completed = new Promise((resolve) => {
|
|
404
|
+
const off = cordis.on("session/event", (session, event) => {
|
|
405
|
+
if (session !== this.#session) return;
|
|
406
|
+
if (event.type === "turn/end") {
|
|
407
|
+
off();
|
|
408
|
+
resolve();
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
this.#disposers.push(off);
|
|
412
|
+
});
|
|
413
|
+
this.#host.deliver(this.#handle.agent, createUserMessage({
|
|
414
|
+
content: blocks,
|
|
415
|
+
source: {
|
|
416
|
+
kind: "plugin",
|
|
417
|
+
plugin: this.#host.messageSource
|
|
418
|
+
}
|
|
419
|
+
}), "followup");
|
|
420
|
+
await completed;
|
|
421
|
+
}
|
|
422
|
+
steer(text) {
|
|
423
|
+
this.#host.piContentToDsh([{
|
|
424
|
+
type: "text",
|
|
425
|
+
text: String(text)
|
|
426
|
+
}]).then((blocks) => {
|
|
427
|
+
this.#host.deliver(this.#handle.agent, createUserMessage({
|
|
428
|
+
content: blocks,
|
|
429
|
+
source: {
|
|
430
|
+
kind: "plugin",
|
|
431
|
+
plugin: this.#host.messageSource
|
|
432
|
+
}
|
|
433
|
+
}), "steer");
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
abort() {
|
|
437
|
+
this.#aborted = true;
|
|
438
|
+
const cancel = this.#handle.agent.cancel;
|
|
439
|
+
cancel?.({
|
|
440
|
+
kind: "hook",
|
|
441
|
+
reason: "pi2dsh subagent abort()"
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
setSessionName(name) {
|
|
445
|
+
this.#sessionName = String(name);
|
|
446
|
+
}
|
|
447
|
+
getSessionName() {
|
|
448
|
+
return this.#sessionName;
|
|
449
|
+
}
|
|
450
|
+
getSessionStats() {
|
|
451
|
+
return {
|
|
452
|
+
turns: this.#turns,
|
|
453
|
+
messages: this.messages.length,
|
|
454
|
+
aborted: this.#aborted
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
getAllTools() {
|
|
458
|
+
return [...this.#tools];
|
|
459
|
+
}
|
|
460
|
+
getActiveToolNames() {
|
|
461
|
+
return [...this.#activeToolNames];
|
|
462
|
+
}
|
|
463
|
+
setActiveToolsByName(names) {
|
|
464
|
+
this.#activeToolNames = names.filter((name) => typeof name === "string");
|
|
465
|
+
}
|
|
466
|
+
async bindExtensions(_bindings = {}) {}
|
|
467
|
+
async dispose() {
|
|
468
|
+
for (const dispose of this.#disposers.splice(0)) try {
|
|
469
|
+
dispose();
|
|
470
|
+
} catch {}
|
|
471
|
+
this.#subscribers.clear();
|
|
472
|
+
await this.#handle.dispose();
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
async function createBridgedAgentSession(host, options) {
|
|
476
|
+
const agents = host.cordis.get("agents");
|
|
477
|
+
if (agents?.create === void 0) throw new Error("pi2dsh: createAgentSession() needs the DSH agent registry in the host composition");
|
|
478
|
+
subagentSerial += 1;
|
|
479
|
+
const sessionId = `pi2dsh-sub-${Date.now().toString(36)}-${subagentSerial}`;
|
|
480
|
+
let handle;
|
|
481
|
+
try {
|
|
482
|
+
handle = await agents.create({
|
|
483
|
+
sessionId,
|
|
484
|
+
meta: {
|
|
485
|
+
cwd: typeof options.cwd === "string" ? options.cwd : host.cwd(),
|
|
486
|
+
origin: "subagent",
|
|
487
|
+
...host.parentSessionId() !== void 0 ? { parentSession: host.parentSessionId() } : {}
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
} catch (error) {
|
|
491
|
+
throw new Error(`pi2dsh: subagent creation needs the DSH host loop (model runtime) to provide the agent factory; this composition cannot run one (${error instanceof Error ? error.message : String(error)})`);
|
|
492
|
+
}
|
|
493
|
+
const tools = [...Array.isArray(options.tools) ? options.tools : [], ...Array.isArray(options.customTools) ? options.customTools : []];
|
|
494
|
+
return { session: new PiBridgedAgentSession(host, handle, tools) };
|
|
495
|
+
}
|
|
496
|
+
//#endregion
|
|
280
497
|
//#region src/runtime.ts
|
|
281
498
|
function logger(ctx) {
|
|
282
499
|
const candidate = ctx.logger;
|
|
@@ -600,6 +817,7 @@ function contextFor(ctx, state, agent, signal, command = false) {
|
|
|
600
817
|
}
|
|
601
818
|
};
|
|
602
819
|
const session = agentSession(agent);
|
|
820
|
+
const providerConfig = (name) => state.providers.get(name);
|
|
603
821
|
const base = {
|
|
604
822
|
ui,
|
|
605
823
|
mode: "rpc",
|
|
@@ -615,12 +833,45 @@ function contextFor(ctx, state, agent, signal, command = false) {
|
|
|
615
833
|
find: (_provider, _modelId) => void 0,
|
|
616
834
|
getError: () => void 0,
|
|
617
835
|
hasConfiguredAuth: (_model) => false,
|
|
618
|
-
getProviderAuthStatus: (
|
|
619
|
-
getProvider: (
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
836
|
+
getProviderAuthStatus: (provider) => providerSupportsOAuth(providerConfig(provider)) ? "oauth" : "none",
|
|
837
|
+
getProvider: (provider) => providerConfig(provider),
|
|
838
|
+
getRegisteredProviderConfig: (provider) => providerConfig(provider),
|
|
839
|
+
getRegisteredProviderIds: () => [...state.providers.keys()],
|
|
840
|
+
getProviderDisplayName: (provider) => {
|
|
841
|
+
const config = providerConfig(provider);
|
|
842
|
+
return typeof config?.name === "string" ? config.name : provider;
|
|
843
|
+
},
|
|
844
|
+
getProviderAuth: async (provider) => {
|
|
845
|
+
const config = providerConfig(provider);
|
|
846
|
+
if (!providerSupportsOAuth(config)) return void 0;
|
|
847
|
+
if (await storedOAuthCredential(oauthStoreOf(state), provider) === void 0) return void 0;
|
|
848
|
+
const apiKey = await resolveOAuthApiKey({
|
|
849
|
+
providerId: provider,
|
|
850
|
+
providerConfig: config,
|
|
851
|
+
store: oauthStoreOf(state)
|
|
852
|
+
});
|
|
853
|
+
if (apiKey === void 0) return void 0;
|
|
854
|
+
return {
|
|
855
|
+
auth: {
|
|
856
|
+
apiKey,
|
|
857
|
+
baseUrl: config.baseUrl
|
|
858
|
+
},
|
|
859
|
+
source: "OAuth"
|
|
860
|
+
};
|
|
861
|
+
},
|
|
862
|
+
getApiKeyForProvider: async (provider) => {
|
|
863
|
+
const config = providerConfig(provider);
|
|
864
|
+
if (!providerSupportsOAuth(config)) return void 0;
|
|
865
|
+
return resolveOAuthApiKey({
|
|
866
|
+
providerId: provider,
|
|
867
|
+
providerConfig: config,
|
|
868
|
+
store: oauthStoreOf(state)
|
|
869
|
+
});
|
|
870
|
+
},
|
|
871
|
+
isUsingOAuth: (model) => {
|
|
872
|
+
const provider = String(model?.provider ?? "");
|
|
873
|
+
return provider.length > 0 && providerSupportsOAuth(providerConfig(provider));
|
|
874
|
+
},
|
|
624
875
|
refresh: async () => ({
|
|
625
876
|
models: [],
|
|
626
877
|
errors: []
|
|
@@ -988,8 +1239,42 @@ function subscribeInterceptors(ctx, state) {
|
|
|
988
1239
|
};
|
|
989
1240
|
});
|
|
990
1241
|
}
|
|
1242
|
+
function oauthStoreOf(state) {
|
|
1243
|
+
state.oauthStore ??= new FileCredentialStore(join(getAgentDir(), "auth.json"));
|
|
1244
|
+
return state.oauthStore;
|
|
1245
|
+
}
|
|
1246
|
+
function ensureLoginCommand(ctx, state) {
|
|
1247
|
+
if (state.loginCommandRegistered === true) return;
|
|
1248
|
+
state.loginCommandRegistered = true;
|
|
1249
|
+
registerCommand(ctx, state, {
|
|
1250
|
+
name: "login",
|
|
1251
|
+
description: "Log in to a Pi provider through its own OAuth flow",
|
|
1252
|
+
argumentHint: "<provider>",
|
|
1253
|
+
async handler(args, commandContext) {
|
|
1254
|
+
const oauthProviders = [...state.providers.entries()].filter(([, config]) => providerSupportsOAuth(config)).map(([name]) => name);
|
|
1255
|
+
if (oauthProviders.length === 0) throw new Error("no registered Pi provider supports OAuth login");
|
|
1256
|
+
const ui = commandContext.ui;
|
|
1257
|
+
let providerId = args.trim().split(/\s+/u)[0] ?? "";
|
|
1258
|
+
if (providerId.length === 0) providerId = oauthProviders.length === 1 ? oauthProviders[0] : String(await ui.select("Log in to which provider?", oauthProviders) ?? "");
|
|
1259
|
+
const config = state.providers.get(providerId);
|
|
1260
|
+
if (config === void 0 || !providerSupportsOAuth(config)) throw new Error(`unknown OAuth provider ${JSON.stringify(providerId)}; available: ${oauthProviders.join(", ")}`);
|
|
1261
|
+
const oauthName = config.oauth?.name ?? providerId;
|
|
1262
|
+
const commandSignal = commandContext.signal;
|
|
1263
|
+
await loginPiProvider({
|
|
1264
|
+
providerId,
|
|
1265
|
+
providerName: oauthName,
|
|
1266
|
+
providerConfig: config,
|
|
1267
|
+
store: oauthStoreOf(state),
|
|
1268
|
+
ui,
|
|
1269
|
+
...commandSignal !== void 0 ? { signal: commandSignal } : {}
|
|
1270
|
+
});
|
|
1271
|
+
ui.notify(`Logged in to ${oauthName}; credential stored in ${oauthStoreOf(state).path}`);
|
|
1272
|
+
return `Logged in to ${oauthName}`;
|
|
1273
|
+
}
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
991
1276
|
function registerTool(ctx, state, tool) {
|
|
992
|
-
if (state.tools.has(tool.name))
|
|
1277
|
+
if (state.tools.has(tool.name)) unregisterTool(state, tool.name);
|
|
993
1278
|
const normalized = normalizeToolSchema(tool.parameters);
|
|
994
1279
|
for (const warning of normalized.warnings) logger(ctx).warn(`[pi2dsh] tool ${tool.name}: ${warning}`);
|
|
995
1280
|
state.tools.set(tool.name, tool);
|
|
@@ -1206,7 +1491,10 @@ function createPiApi(ctx, state) {
|
|
|
1206
1491
|
const name = typeof providerOrName === "string" ? providerOrName : String(providerOrName?.name ?? "unnamed");
|
|
1207
1492
|
const value = typeof providerOrName === "string" ? config ?? {} : providerOrName;
|
|
1208
1493
|
state.providers.set(name, value);
|
|
1209
|
-
|
|
1494
|
+
if (providerSupportsOAuth(value)) {
|
|
1495
|
+
ensureLoginCommand(ctx, state);
|
|
1496
|
+
logger(ctx).info(`[pi2dsh] Pi provider ${JSON.stringify(name)} supports OAuth — log in with /login ${name}`);
|
|
1497
|
+
} else logger(ctx).info(`[pi2dsh] recorded Pi provider ${JSON.stringify(name)}; model calls stay on DSH llm adapters`);
|
|
1210
1498
|
},
|
|
1211
1499
|
unregisterProvider(name) {
|
|
1212
1500
|
state.providers.delete(name);
|
|
@@ -1255,18 +1543,21 @@ function createPiApi(ctx, state) {
|
|
|
1255
1543
|
return executePiCommand(service, cwdOf(currentAgent(state)), command, args, options);
|
|
1256
1544
|
},
|
|
1257
1545
|
getActiveTools: () => getActiveTools(ctx, state),
|
|
1258
|
-
getAllTools: () =>
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1546
|
+
getAllTools: () => {
|
|
1547
|
+
const visiblePiTools = new Set(state.runner.getAllRegisteredTools().map((record) => record.definition?.name).filter((name) => typeof name === "string"));
|
|
1548
|
+
return toolRuntime(ctx, currentAgent(state)).schemas(currentAgent(state)).filter((tool) => !state.tools.has(tool.name) || visiblePiTools.has(tool.name)).map((tool) => ({
|
|
1549
|
+
name: tool.name,
|
|
1550
|
+
description: tool.description ?? "",
|
|
1551
|
+
parameters: tool.parameters ?? {},
|
|
1552
|
+
source: state.tools.has(tool.name) ? "extension" : "builtin",
|
|
1553
|
+
sourceInfo: {
|
|
1554
|
+
path: "",
|
|
1555
|
+
source: state.tools.has(tool.name) ? "pi2dsh" : "dsh",
|
|
1556
|
+
scope: "session",
|
|
1557
|
+
origin: "runtime"
|
|
1558
|
+
}
|
|
1559
|
+
}));
|
|
1560
|
+
},
|
|
1270
1561
|
setActiveTools: (names) => setActiveTools(ctx, state, names),
|
|
1271
1562
|
getCommands: () => [...state.commands.values()].map((command) => ({
|
|
1272
1563
|
name: command.name,
|
|
@@ -1439,9 +1730,20 @@ async function loadExtensions(rootDir, manifest, api, onExtensionError) {
|
|
|
1439
1730
|
async function applyPiPackage(ctx, options) {
|
|
1440
1731
|
if (options.manifest.schemaVersion !== 1) throw new Error(`unsupported pi2dsh manifest version ${String(options.manifest.schemaVersion)}`);
|
|
1441
1732
|
const rootDir = fileURLToPath(options.rootUrl);
|
|
1733
|
+
const runtimeTools = /* @__PURE__ */ new Map();
|
|
1734
|
+
const piToolRecords = () => [...runtimeTools.values()].map((tool) => ({
|
|
1735
|
+
definition: tool,
|
|
1736
|
+
sourceInfo: {
|
|
1737
|
+
path: "",
|
|
1738
|
+
source: "pi2dsh",
|
|
1739
|
+
scope: "session",
|
|
1740
|
+
origin: "package"
|
|
1741
|
+
}
|
|
1742
|
+
}));
|
|
1442
1743
|
const state = {
|
|
1443
1744
|
handlers: /* @__PURE__ */ new Map(),
|
|
1444
|
-
tools:
|
|
1745
|
+
tools: runtimeTools,
|
|
1746
|
+
runner: new ExtensionRunner(piToolRecords),
|
|
1445
1747
|
toolDisposers: /* @__PURE__ */ new Map(),
|
|
1446
1748
|
toolRestrictions: /* @__PURE__ */ new WeakMap(),
|
|
1447
1749
|
commands: /* @__PURE__ */ new Map(),
|
|
@@ -1471,6 +1773,12 @@ async function applyPiPackage(ctx, options) {
|
|
|
1471
1773
|
};
|
|
1472
1774
|
subscribeLifecycle(ctx, state);
|
|
1473
1775
|
subscribeInterceptors(ctx, state);
|
|
1776
|
+
for (const provider of builtinProviders()) state.providers.set(provider.id, {
|
|
1777
|
+
name: provider.name,
|
|
1778
|
+
baseUrl: provider.baseUrl,
|
|
1779
|
+
oauth: provider.auth.oauth
|
|
1780
|
+
});
|
|
1781
|
+
ensureLoginCommand(ctx, state);
|
|
1474
1782
|
if (options.manifest.skillDirs.length > 0) {
|
|
1475
1783
|
if (ctx.get("skills") === void 0) logger(ctx).warn("[pi2dsh] migrated skills were not mounted because this DSH composition has no ctx.skills");
|
|
1476
1784
|
else {
|
|
@@ -1483,6 +1791,19 @@ async function applyPiPackage(ctx, options) {
|
|
|
1483
1791
|
});
|
|
1484
1792
|
}
|
|
1485
1793
|
}
|
|
1794
|
+
__setSubagentSessionFactory((subagentOptions) => createBridgedAgentSession({
|
|
1795
|
+
cordis: ctx,
|
|
1796
|
+
cwd: () => cwdOf(currentAgent(state)),
|
|
1797
|
+
parentSessionId: () => {
|
|
1798
|
+
const session = agentSession(currentAgent(state));
|
|
1799
|
+
return session === void 0 ? void 0 : String(session.id ?? "") || void 0;
|
|
1800
|
+
},
|
|
1801
|
+
piContentToDsh: (content) => piToDshContent(ctx, content),
|
|
1802
|
+
deliver: (agent, message, mode) => deliverAgentMessage(agent, message, mode),
|
|
1803
|
+
messageFromSessionEvent,
|
|
1804
|
+
messageSource: state.messageSource
|
|
1805
|
+
}, subagentOptions));
|
|
1806
|
+
ctx.effect(() => () => __setSubagentSessionFactory(void 0));
|
|
1486
1807
|
await registerPromptCommands(ctx, state, rootDir, options.manifest);
|
|
1487
1808
|
await loadExtensions(rootDir, options.manifest, createPiApi(ctx, state), (failure) => logger(ctx).warn(`[pi2dsh] extension entry failed and was skipped (matching Pi's per-extension error isolation): ${failure}`));
|
|
1488
1809
|
logger(ctx).info(`[pi2dsh] loaded ${options.manifest.package.name}: ${state.tools.size} tools, ${state.commands.size} commands, ${options.manifest.skillDirs.length} skill roots`);
|
|
@@ -1496,4 +1817,4 @@ const runtimeInternals = {
|
|
|
1496
1817
|
//#endregion
|
|
1497
1818
|
export { normalizeToolSchema as n, runtimeInternals as r, applyPiPackage as t };
|
|
1498
1819
|
|
|
1499
|
-
//# sourceMappingURL=runtime-
|
|
1820
|
+
//# sourceMappingURL=runtime-6DefpI6h.mjs.map
|