pi-ptc-subagents 6.0.1 → 6.0.3

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.
Files changed (2) hide show
  1. package/dist/index.js +32 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4890,7 +4890,9 @@ function createPtcRunCodeTool(options) {
4890
4890
  description: TOOLS$1.ptc_run_code.description(options.surface ?? "full_ptc"),
4891
4891
  parameters: RUN_CODE_PARAMETERS,
4892
4892
  renderResult: renderPtcResult("run_code"),
4893
- execute: async (_id, args, _signal, _onUpdate, ctx) => {
4893
+ execute: async (...rawArgs) => {
4894
+ const args = rawArgs[1];
4895
+ const ctx = rawArgs.find((value) => typeof value?.executeTool === "function");
4894
4896
  options.onToolContext?.(ctx);
4895
4897
  const outcome = await runPtcProgram({
4896
4898
  code: args.code,
@@ -4937,7 +4939,9 @@ function createPtcWorkflowTool(options) {
4937
4939
  description: TOOLS$1.ptc_workflow.description(options.surface ?? "full_ptc"),
4938
4940
  parameters: WORKFLOW_PARAMETERS,
4939
4941
  renderResult: renderPtcResult("workflow"),
4940
- execute: async (_id, params, _signal, _onUpdate, ctx) => {
4942
+ execute: async (...rawArgs) => {
4943
+ const params = rawArgs[1];
4944
+ const ctx = rawArgs.find((value) => typeof value?.executeTool === "function");
4941
4945
  options.onToolContext?.(ctx);
4942
4946
  try {
4943
4947
  validateWorkflowArgs(params.args);
@@ -5119,10 +5123,11 @@ const ROUTE_INDEX_LEAD = {
5119
5123
  codemode_ptc: "编排写 codemode 脚本;批量派活经脚本内的 pi_task_codemode;要查/停任务用任务面三工具。"
5120
5124
  };
5121
5125
  function renderRouteIndex(surface, detailBase, nudge = true) {
5122
- const lines = ROUTES.map((route) => `- ${route.name} — ${route.when}。这面怎么走:${route.how[surface]}。细节:${detailBase ? join(detailBase, route.detail.split("/").pop()) : route.detail}`);
5126
+ const lines = ROUTES.map((route) => `- ${route.name} — ${route.when}。这面怎么走:${route.how[surface]}。细节:${detailBase ? route.detail.split("/").pop() : route.detail}`);
5123
5127
  let index = [
5124
5128
  `<ptc>`,
5125
5129
  ...nudge ? [ROUTE_INDEX_LEAD[surface]] : [],
5130
+ ...detailBase ? [`详情目录:${detailBase}`] : [],
5126
5131
  "路由表(一条一行,详情按需 read):",
5127
5132
  ...lines,
5128
5133
  `</ptc>`
@@ -5308,7 +5313,7 @@ function piPtcEntry(pi) {
5308
5313
  modeEnabled = rest !== "off";
5309
5314
  applyMode();
5310
5315
  }
5311
- cmdCtx.ui.notify(`/ptc:dispatchEnabled=${dispatchEnabled},mode=${modeActive ? "on(收窄中)" : "off"},whyEnabled=${whyEnabledOverride ?? whyEnabledPersisted}(在飞任务不受影响)`, "info");
5316
+ cmdCtx.ui.notify(`/ptc:dispatchEnabled=${dispatchEnabled},mode=${modeActive ? "on(引导层)" : "off"},whyEnabled=${whyEnabledOverride ?? whyEnabledPersisted}(在飞任务不受影响)`, "info");
5312
5317
  }
5313
5318
  });
5314
5319
  pi.on("session_shutdown", () => {
@@ -5342,9 +5347,9 @@ function piPtcEntry(pi) {
5342
5347
  registerTaskFace(registerTracked, session, surface);
5343
5348
  applyTaskFaceVisibility(pi, session);
5344
5349
  let toolContext;
5345
- const bindings = createBindingTable(pi, session, () => toolContext);
5350
+ const getBindings = () => createBindingTable(pi, session, () => toolContext);
5346
5351
  registerPtcTools(registerTracked, {
5347
- getBindings: () => bindings,
5352
+ getBindings,
5348
5353
  cwd: process.cwd(),
5349
5354
  surface,
5350
5355
  getPool: () => pool,
@@ -5450,18 +5455,36 @@ function registerChildToolsOnly(pi) {
5450
5455
  })
5451
5456
  });
5452
5457
  }
5458
+ function normalizeToolValue(value) {
5459
+ if (typeof value === "string") return value;
5460
+ if (Array.isArray(value)) return value.map((block) => {
5461
+ if (typeof block === "string") return block;
5462
+ const obj = block;
5463
+ if (obj.type === "image") return "[image]";
5464
+ return obj.text ?? JSON.stringify(block);
5465
+ }).join("\n");
5466
+ if (value && typeof value === "object") {
5467
+ const obj = value;
5468
+ if (typeof obj.content === "string") return obj.content;
5469
+ if (typeof obj.text === "string") return obj.text;
5470
+ if (obj.type === "image") return typeof obj.note === "string" ? obj.note : "[image]";
5471
+ }
5472
+ return value;
5473
+ }
5453
5474
  function createBindingTable(pi, session, getToolContext) {
5454
- const names = resolveBindingNames(pi.getActiveTools());
5475
+ const active = pi.getActiveTools();
5476
+ const known = new Set(KNOWN_BINDING_NAMES);
5477
+ const names = resolveBindingNames(!getToolContext() && !active.some((name) => known.has(name)) ? pi.getAllTools().map((tool) => tool.name) : active);
5455
5478
  const table = Object.fromEntries(names.map((name) => [name, async (args, callCtx) => {
5456
5479
  const ctx = getToolContext();
5457
- if (!ctx?.executeTool) throw new Error(`此 pi 版本不支持程序内工具调用(executeTool 不可用,binding: ${name})`);
5480
+ if (!ctx?.executeTool) throw new Error(`此 pi 版本没有程序内调用工具的通道(需 pi ≥ 0.99,binding: ${name})`);
5458
5481
  const outcome = await ctx.executeTool(name, args, { signal: callCtx.signal });
5459
5482
  for (const block of outcome.result.content) if (block.type === "image") callCtx.emitImage(block);
5460
5483
  if (outcome.isError) {
5461
5484
  const text = outcome.result.content.map((block) => block.type === "text" ? block.text : `[${block.type}]`).join("\n");
5462
5485
  throw new Error(text || `工具 ${name} 执行失败`);
5463
5486
  }
5464
- return outcome.result.structuredContent ?? outcome.result.content;
5487
+ return normalizeToolValue(outcome.result.structuredContent ?? outcome.result.content);
5465
5488
  }]));
5466
5489
  const taskBinding = createTaskBinding(session);
5467
5490
  table[TASK_BINDING_NAME] = (args) => taskBinding.execute(args);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-ptc-subagents",
3
- "version": "6.0.1",
3
+ "version": "6.0.3",
4
4
  "description": "Programmable tool calling (PTC) and subagent fan-out for pi",
5
5
  "keywords": [
6
6
  "pi",