pi-ptc-subagents 5.0.1 → 6.0.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 +69 -264
- package/dist/index.js +5565 -67
- package/dist/worker.js +158 -4
- package/package.json +19 -54
- package/CHANGELOG.md +0 -1265
- package/THIRD_PARTY_NOTICES.md +0 -59
- package/dist/index.d.ts +0 -1892
- package/dist/protocol-CfOgxz3u.js +0 -2
- package/dist/worker.d.ts +0 -1
package/dist/worker.js
CHANGED
|
@@ -1,4 +1,158 @@
|
|
|
1
|
-
import{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { stripTypeScriptTypes } from "node:module";
|
|
2
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
3
|
+
import { inspect } from "node:util";
|
|
4
|
+
// ../ptc/src/compile.ts
|
|
5
|
+
function compileProgram(source) {
|
|
6
|
+
const stripped = stripTypeScriptTypes(`async function __ptcProgram() {\n${source}\n}`, { mode: "strip" });
|
|
7
|
+
return new Function(`"use strict";\n${stripped}\nreturn __ptcProgram;`)();
|
|
8
|
+
}
|
|
9
|
+
// ../ptc/src/workflow-helpers.ts
|
|
10
|
+
function createWorkflowHelpers(emit) {
|
|
11
|
+
return {
|
|
12
|
+
log: (...args) => emit(args.map((a) => typeof a === "string" ? a : JSON.stringify(a)).join(" ")),
|
|
13
|
+
phase: (name) => emit(`— phase: ${name} —`),
|
|
14
|
+
parallel: (items) => Promise.all(items.map((run) => run())),
|
|
15
|
+
pipeline: (items, step) => {
|
|
16
|
+
const results = [];
|
|
17
|
+
return items.reduce((chain, item, index) => chain.then(async () => {
|
|
18
|
+
results.push(await step(item, index));
|
|
19
|
+
}), Promise.resolve()).then(() => results);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// ../ptc/src/worker-main.ts
|
|
24
|
+
function workerMain(deps) {
|
|
25
|
+
let tools = {};
|
|
26
|
+
let pending = /* @__PURE__ */ new Map();
|
|
27
|
+
let nextCallId = 1;
|
|
28
|
+
let currentRunId = null;
|
|
29
|
+
let logs = [];
|
|
30
|
+
const globalBaseline = /* @__PURE__ */ new Set();
|
|
31
|
+
const consoleBaseline = { ...console };
|
|
32
|
+
deps.onFrame((frame) => {
|
|
33
|
+
if (frame.kind === "init") {
|
|
34
|
+
for (const name of Object.getOwnPropertyNames(globalThis)) globalBaseline.add(name);
|
|
35
|
+
tools = Object.freeze(Object.fromEntries(frame.bindingNames.map((name) => [name, (args) => {
|
|
36
|
+
if (currentRunId === null) return Promise.reject(/* @__PURE__ */ new Error("run 已结束:reset 后不再接受工具调用"));
|
|
37
|
+
const call = new Promise((resolve, reject) => {
|
|
38
|
+
const callId = nextCallId++;
|
|
39
|
+
pending.set(callId, {
|
|
40
|
+
resolve,
|
|
41
|
+
reject
|
|
42
|
+
});
|
|
43
|
+
deps.post({
|
|
44
|
+
kind: "call",
|
|
45
|
+
runId: currentRunId ?? "",
|
|
46
|
+
callId,
|
|
47
|
+
name,
|
|
48
|
+
args
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
call.catch(() => {});
|
|
52
|
+
return call;
|
|
53
|
+
}])));
|
|
54
|
+
defineGlobal("tools", tools);
|
|
55
|
+
if (frame.surface === "workflow") defineGlobal("workflow", createWorkflowHelpers((text) => {
|
|
56
|
+
logs.push(text);
|
|
57
|
+
deps.post({
|
|
58
|
+
kind: "log",
|
|
59
|
+
runId: currentRunId ?? "",
|
|
60
|
+
level: "log",
|
|
61
|
+
text
|
|
62
|
+
});
|
|
63
|
+
}));
|
|
64
|
+
deps.post({ kind: "ready" });
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (frame.kind === "reset") {
|
|
68
|
+
currentRunId = null;
|
|
69
|
+
for (const { reject } of pending.values()) reject(/* @__PURE__ */ new Error("run reset:worker 被复用"));
|
|
70
|
+
pending = /* @__PURE__ */ new Map();
|
|
71
|
+
for (const name of Object.getOwnPropertyNames(globalThis)) if (!globalBaseline.has(name)) delete globalThis[name];
|
|
72
|
+
Object.assign(console, consoleBaseline);
|
|
73
|
+
deps.post({ kind: "ready" });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (frame.kind === "result") {
|
|
77
|
+
const entry = pending.get(frame.callId);
|
|
78
|
+
if (!entry) return;
|
|
79
|
+
pending.delete(frame.callId);
|
|
80
|
+
if (frame.ok) entry.resolve(frame.value);
|
|
81
|
+
else entry.reject(new Error(frame.error));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (frame.kind === "cancel") return;
|
|
85
|
+
run(frame.code, frame.id, frame.args);
|
|
86
|
+
});
|
|
87
|
+
function defineGlobal(name, value) {
|
|
88
|
+
Object.defineProperty(globalThis, name, {
|
|
89
|
+
value,
|
|
90
|
+
writable: false,
|
|
91
|
+
configurable: true
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async function run(code, runId, args) {
|
|
95
|
+
currentRunId = runId;
|
|
96
|
+
logs = [];
|
|
97
|
+
defineGlobal("args", args ?? {});
|
|
98
|
+
installConsole((level, text) => {
|
|
99
|
+
logs.push(text);
|
|
100
|
+
deps.post({
|
|
101
|
+
kind: "log",
|
|
102
|
+
runId,
|
|
103
|
+
level,
|
|
104
|
+
text
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
const outcome = await execute(code);
|
|
108
|
+
deps.post({
|
|
109
|
+
kind: "settled",
|
|
110
|
+
runId,
|
|
111
|
+
outcome
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async function execute(code) {
|
|
115
|
+
try {
|
|
116
|
+
const value = await compileProgram(code).call({ tools });
|
|
117
|
+
if (value === void 0) return {
|
|
118
|
+
status: "fulfilled",
|
|
119
|
+
value: { $void: true },
|
|
120
|
+
logs
|
|
121
|
+
};
|
|
122
|
+
const json = JSON.stringify(value);
|
|
123
|
+
if (json === void 0) return {
|
|
124
|
+
status: "rejected",
|
|
125
|
+
error: "程序返回值不可序列化",
|
|
126
|
+
logs
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
status: "fulfilled",
|
|
130
|
+
value: JSON.parse(json),
|
|
131
|
+
logs
|
|
132
|
+
};
|
|
133
|
+
} catch (error) {
|
|
134
|
+
return {
|
|
135
|
+
status: "rejected",
|
|
136
|
+
error: error instanceof Error ? error.message : String(error),
|
|
137
|
+
logs
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function installConsole(emit) {
|
|
143
|
+
for (const level of [
|
|
144
|
+
"log",
|
|
145
|
+
"info",
|
|
146
|
+
"warn",
|
|
147
|
+
"error",
|
|
148
|
+
"debug"
|
|
149
|
+
]) console[level] = (...args) => emit(level, args.map((a) => typeof a === "string" ? a : inspect(a)).join(" "));
|
|
150
|
+
}
|
|
151
|
+
// ../ptc/src/worker-entry.ts
|
|
152
|
+
if (!parentPort) throw new Error("worker-entry 只能在 worker 线程里加载");
|
|
153
|
+
Object.freeze(workerData);
|
|
154
|
+
workerMain({
|
|
155
|
+
post: (frame) => parentPort.postMessage(frame),
|
|
156
|
+
onFrame: (handler) => parentPort.on("message", (frame) => handler(frame))
|
|
157
|
+
});
|
|
158
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ptc-subagents",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Programmable tool calling (PTC) and subagent fan-out for pi
|
|
3
|
+
"version": "6.0.0",
|
|
4
|
+
"description": "Programmable tool calling (PTC) and subagent fan-out for pi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi",
|
|
7
7
|
"pi-package",
|
|
8
|
-
"
|
|
9
|
-
"ptc"
|
|
8
|
+
"programmable-tool-calling",
|
|
9
|
+
"ptc",
|
|
10
|
+
"subagents"
|
|
10
11
|
],
|
|
11
|
-
"homepage": "https://
|
|
12
|
+
"homepage": "https://github.com/a1121611810/pi-ptc-subagents",
|
|
12
13
|
"bugs": {
|
|
13
14
|
"url": "https://github.com/a1121611810/pi-ptc-subagents/issues"
|
|
14
15
|
},
|
|
@@ -19,78 +20,42 @@
|
|
|
19
20
|
},
|
|
20
21
|
"files": [
|
|
21
22
|
"dist/**/*.js",
|
|
22
|
-
"dist/**/*.d.ts",
|
|
23
23
|
"README.md",
|
|
24
|
-
"LICENSE"
|
|
25
|
-
"THIRD_PARTY_NOTICES.md",
|
|
26
|
-
"CHANGELOG.md"
|
|
24
|
+
"LICENSE"
|
|
27
25
|
],
|
|
28
26
|
"type": "module",
|
|
29
27
|
"main": "./dist/index.js",
|
|
30
|
-
"types": "./dist/index.d.ts",
|
|
31
28
|
"exports": {
|
|
32
|
-
".":
|
|
33
|
-
"types": "./dist/index.d.ts",
|
|
34
|
-
"import": "./dist/index.js"
|
|
35
|
-
}
|
|
29
|
+
".": "./dist/index.js"
|
|
36
30
|
},
|
|
37
31
|
"scripts": {
|
|
38
|
-
"build": "
|
|
39
|
-
"
|
|
32
|
+
"build": "pnpm -r run build",
|
|
33
|
+
"prepack": "pnpm run build && rm -rf dist && cp -R packages/entry/dist dist",
|
|
34
|
+
"check": "pnpm -r run check",
|
|
40
35
|
"lint": "oxlint",
|
|
41
|
-
"lint:fix": "oxlint --fix",
|
|
42
36
|
"fmt": "oxfmt",
|
|
43
|
-
"fmt:check": "oxfmt --check"
|
|
44
|
-
"compat:pi": "node scripts/pi-compat-matrix.mjs",
|
|
45
|
-
"test": "pnpm exec vp test --run --coverage",
|
|
46
|
-
"test:watch": "pnpm exec vp test",
|
|
47
|
-
"test:ui": "pnpm exec vp test --ui",
|
|
48
|
-
"verify:dist": "node scripts/verify-dist-render.mjs",
|
|
49
|
-
"prepublishOnly": "npm run typecheck && npm run lint && npm run fmt:check && npm run build && npm run test && npm run verify:dist"
|
|
50
|
-
},
|
|
51
|
-
"dependencies": {
|
|
52
|
-
"minimatch": "^10.2.6"
|
|
37
|
+
"fmt:check": "oxfmt --check"
|
|
53
38
|
},
|
|
54
39
|
"devDependencies": {
|
|
55
|
-
"@earendil-works/pi-
|
|
56
|
-
"@earendil-works/pi-coding-agent": "^1.3.0",
|
|
57
|
-
"@earendil-works/pi-tui": "^1.3.0",
|
|
40
|
+
"@earendil-works/pi-coding-agent": "^1.4.0",
|
|
58
41
|
"@types/node": "^26.6.5",
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"rolldown": "^1.2.14",
|
|
64
|
-
"rolldown-plugin-dts": "^0.28.8",
|
|
65
|
-
"typebox": "^1.3.34",
|
|
66
|
-
"typescript": "^7.0.2",
|
|
67
|
-
"vite-plus": "1.3.0",
|
|
68
|
-
"vitest": "^5.0.5"
|
|
42
|
+
"oxfmt": "^0.74.0",
|
|
43
|
+
"oxlint": "^1.89.0",
|
|
44
|
+
"rolldown": "^1.2.15",
|
|
45
|
+
"tsrs": "0.18.0-ts7.1.0-dev.20260929"
|
|
69
46
|
},
|
|
70
47
|
"peerDependencies": {
|
|
71
|
-
"@earendil-works/pi-
|
|
72
|
-
"@earendil-works/pi-coding-agent": ">=0.86.0",
|
|
73
|
-
"@earendil-works/pi-tui": "*",
|
|
74
|
-
"typebox": "*"
|
|
48
|
+
"@earendil-works/pi-coding-agent": ">=0.86.0"
|
|
75
49
|
},
|
|
76
50
|
"peerDependenciesMeta": {
|
|
77
51
|
"@earendil-works/pi-coding-agent": {
|
|
78
52
|
"optional": true
|
|
79
|
-
},
|
|
80
|
-
"@earendil-works/pi-tui": {
|
|
81
|
-
"optional": true
|
|
82
|
-
},
|
|
83
|
-
"@earendil-works/pi-ai": {
|
|
84
|
-
"optional": true
|
|
85
|
-
},
|
|
86
|
-
"typebox": {
|
|
87
|
-
"optional": true
|
|
88
53
|
}
|
|
89
54
|
},
|
|
90
55
|
"engines": {
|
|
91
56
|
"node": ">=22.19.0"
|
|
92
57
|
},
|
|
93
|
-
"packageManager": "pnpm@12.
|
|
58
|
+
"packageManager": "pnpm@12.15.0",
|
|
94
59
|
"pi": {
|
|
95
60
|
"extensions": [
|
|
96
61
|
"./dist/index.js"
|