pi-ptc-subagents 6.0.1 → 6.0.2

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 +23 -7
  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);
@@ -5342,9 +5346,9 @@ function piPtcEntry(pi) {
5342
5346
  registerTaskFace(registerTracked, session, surface);
5343
5347
  applyTaskFaceVisibility(pi, session);
5344
5348
  let toolContext;
5345
- const bindings = createBindingTable(pi, session, () => toolContext);
5349
+ const getBindings = () => createBindingTable(pi, session, () => toolContext);
5346
5350
  registerPtcTools(registerTracked, {
5347
- getBindings: () => bindings,
5351
+ getBindings,
5348
5352
  cwd: process.cwd(),
5349
5353
  surface,
5350
5354
  getPool: () => pool,
@@ -5450,18 +5454,30 @@ function registerChildToolsOnly(pi) {
5450
5454
  })
5451
5455
  });
5452
5456
  }
5457
+ function normalizeToolValue(value) {
5458
+ if (typeof value === "string") return value;
5459
+ if (Array.isArray(value)) return value.map((block) => typeof block === "string" ? block : block?.text ?? JSON.stringify(block)).join("\n");
5460
+ if (value && typeof value === "object") {
5461
+ const obj = value;
5462
+ if (typeof obj.content === "string") return obj.content;
5463
+ if (typeof obj.text === "string") return obj.text;
5464
+ }
5465
+ return value;
5466
+ }
5453
5467
  function createBindingTable(pi, session, getToolContext) {
5454
- const names = resolveBindingNames(pi.getActiveTools());
5468
+ const active = pi.getActiveTools();
5469
+ const known = new Set(KNOWN_BINDING_NAMES);
5470
+ const names = resolveBindingNames(active.some((name) => known.has(name)) ? active : pi.getAllTools().map((tool) => tool.name));
5455
5471
  const table = Object.fromEntries(names.map((name) => [name, async (args, callCtx) => {
5456
5472
  const ctx = getToolContext();
5457
- if (!ctx?.executeTool) throw new Error(`此 pi 版本不支持程序内工具调用(executeTool 不可用,binding: ${name})`);
5473
+ if (!ctx?.executeTool) throw new Error(`此 pi 版本没有程序内调用工具的通道(需 pi ≥ 0.99,binding: ${name})`);
5458
5474
  const outcome = await ctx.executeTool(name, args, { signal: callCtx.signal });
5459
5475
  for (const block of outcome.result.content) if (block.type === "image") callCtx.emitImage(block);
5460
5476
  if (outcome.isError) {
5461
5477
  const text = outcome.result.content.map((block) => block.type === "text" ? block.text : `[${block.type}]`).join("\n");
5462
5478
  throw new Error(text || `工具 ${name} 执行失败`);
5463
5479
  }
5464
- return outcome.result.structuredContent ?? outcome.result.content;
5480
+ return normalizeToolValue(outcome.result.structuredContent ?? outcome.result.content);
5465
5481
  }]));
5466
5482
  const taskBinding = createTaskBinding(session);
5467
5483
  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.2",
4
4
  "description": "Programmable tool calling (PTC) and subagent fan-out for pi",
5
5
  "keywords": [
6
6
  "pi",