@howaboua/pi-durable-code 0.0.0-stage → 0.10.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/LICENSE +21 -0
- package/NOTICE +251 -0
- package/README.md +93 -2
- package/dist/activation.js +4759 -0
- package/dist/code/src/activation.d.ts +5 -0
- package/dist/code/src/binary.d.ts +6 -0
- package/dist/code/src/cell-output.d.ts +33 -0
- package/dist/code/src/engine.d.ts +16 -0
- package/dist/code/src/history.d.ts +6 -0
- package/dist/code/src/host-assets.d.ts +4 -0
- package/dist/code/src/host-connection.d.ts +29 -0
- package/dist/code/src/host-process.d.ts +21 -0
- package/dist/code/src/host-protocol.d.ts +54 -0
- package/dist/code/src/host-runtime.d.ts +21 -0
- package/dist/code/src/host-session.d.ts +24 -0
- package/dist/code/src/index.d.ts +32 -0
- package/dist/code/src/install-host.d.ts +7 -0
- package/dist/code/src/presentation.d.ts +22 -0
- package/dist/code/src/result.d.ts +4 -0
- package/dist/code/src/runtime-contract.d.ts +24 -0
- package/dist/code/src/runtime-response.d.ts +2 -0
- package/dist/code/src/runtime-tools.d.ts +7 -0
- package/dist/execution/src/cell-contract.d.ts +49 -0
- package/dist/execution/src/cell-observation.d.ts +7 -0
- package/dist/execution/src/cell-progress.d.ts +4 -0
- package/dist/execution/src/cell-task.d.ts +17 -0
- package/dist/execution/src/cell-tools.d.ts +8 -0
- package/dist/execution/src/cells.d.ts +14 -0
- package/dist/execution/src/command-backend.d.ts +22 -0
- package/dist/execution/src/controls.d.ts +3 -0
- package/dist/execution/src/custom-command-config.d.ts +21 -0
- package/dist/execution/src/custom-commands.d.ts +62 -0
- package/dist/execution/src/exec-source.d.ts +21 -0
- package/dist/execution/src/forwarded-tools.d.ts +21 -0
- package/dist/execution/src/forwarding-hook.d.ts +6 -0
- package/dist/execution/src/forwarding.d.ts +15 -0
- package/dist/execution/src/history.d.ts +14 -0
- package/dist/execution/src/index.d.ts +6 -0
- package/dist/execution/src/invocation-state.d.ts +26 -0
- package/dist/execution/src/invocation.d.ts +35 -0
- package/dist/execution/src/native-tools.d.ts +11 -0
- package/dist/execution/src/nested-call.d.ts +26 -0
- package/dist/execution/src/nested-result.d.ts +8 -0
- package/dist/execution/src/nested.d.ts +3 -0
- package/dist/execution/src/output.d.ts +48 -0
- package/dist/execution/src/presentation.d.ts +59 -0
- package/dist/execution/src/progress.d.ts +23 -0
- package/dist/execution/src/projection.d.ts +5 -0
- package/dist/execution/src/shell/backend.d.ts +28 -0
- package/dist/execution/src/shell/format.d.ts +2 -0
- package/dist/execution/src/shell/node-backend.d.ts +9 -0
- package/dist/execution/src/shell/output.d.ts +19 -0
- package/dist/execution/src/shell/process-session.d.ts +50 -0
- package/dist/execution/src/shell/results.d.ts +14 -0
- package/dist/execution/src/shell/session-manager.d.ts +46 -0
- package/dist/execution/src/shell/session-store.d.ts +53 -0
- package/dist/execution/src/shell/shell-args.d.ts +4 -0
- package/dist/execution/src/shell/shell.d.ts +14 -0
- package/dist/execution/src/shell/wait.d.ts +7 -0
- package/dist/execution/src/shell.d.ts +14 -0
- package/dist/execution/src/tool-contract.d.ts +34 -0
- package/dist/execution/src/tool-origin.d.ts +11 -0
- package/dist/execution/src/tool-source.d.ts +6 -0
- package/dist/execution/src/tool-value.d.ts +3 -0
- package/dist/execution/src/wait-session.d.ts +6 -0
- package/dist/history.js +315 -0
- package/dist/index.js +5063 -0
- package/dist/presentation.js +198 -0
- package/package.json +77 -5
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// packages/execution/src/presentation.ts
|
|
2
|
+
function object(value) {
|
|
3
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)
|
|
4
|
+
throw new TypeError("Expected execution presentation object");
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
function string(value) {
|
|
8
|
+
if (typeof value !== "string")
|
|
9
|
+
throw new TypeError("Expected string");
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
function json(value, ancestors = new Set) {
|
|
13
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
14
|
+
return value;
|
|
15
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
16
|
+
return value;
|
|
17
|
+
if (typeof value !== "object" || ancestors.has(value))
|
|
18
|
+
throw new TypeError("Expected finite, acyclic JSON details");
|
|
19
|
+
ancestors.add(value);
|
|
20
|
+
try {
|
|
21
|
+
if (!Array.isArray(value))
|
|
22
|
+
object(value);
|
|
23
|
+
return Array.isArray(value) ? value.map((item) => json(item, ancestors)) : Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
24
|
+
key,
|
|
25
|
+
json(item, ancestors)
|
|
26
|
+
]));
|
|
27
|
+
} finally {
|
|
28
|
+
ancestors.delete(value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function cell(value) {
|
|
32
|
+
if (value === null)
|
|
33
|
+
return null;
|
|
34
|
+
const fields = object(value);
|
|
35
|
+
const id = string(fields["id"]);
|
|
36
|
+
if (!/^[1-9][0-9]*$/.test(id) || !Number.isSafeInteger(Number(id)))
|
|
37
|
+
throw new TypeError("Invalid execution cell ID");
|
|
38
|
+
const status = fields["status"];
|
|
39
|
+
if (status !== "running" && status !== "completed" && status !== "failed" && status !== "aborted" && status !== "interrupted")
|
|
40
|
+
throw new TypeError("Invalid execution cell status");
|
|
41
|
+
return { id, status };
|
|
42
|
+
}
|
|
43
|
+
function parseExecutionResultReceipt(value) {
|
|
44
|
+
if (value === null)
|
|
45
|
+
return null;
|
|
46
|
+
const fields = object(value);
|
|
47
|
+
const content = fields["content"] === undefined ? [] : fields["content"];
|
|
48
|
+
const diagnostics = fields["diagnostics"] === undefined ? [] : fields["diagnostics"];
|
|
49
|
+
const isError = fields["isError"] === undefined ? false : fields["isError"];
|
|
50
|
+
if (!Array.isArray(content) || !Array.isArray(diagnostics) || typeof isError !== "boolean")
|
|
51
|
+
throw new TypeError("Invalid execution result receipt");
|
|
52
|
+
return {
|
|
53
|
+
content: content.map((value) => {
|
|
54
|
+
const item = object(value);
|
|
55
|
+
if (item["type"] === "text")
|
|
56
|
+
return { type: "text", text: string(item["text"]) };
|
|
57
|
+
if (item["type"] === "image") {
|
|
58
|
+
const mimeType = string(item["mimeType"]);
|
|
59
|
+
const data = string(item["data"]);
|
|
60
|
+
if (!/^image\/[A-Za-z0-9][A-Za-z0-9.+-]*$/.test(mimeType) || data.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(data))
|
|
61
|
+
throw new TypeError("Invalid execution image");
|
|
62
|
+
return { type: "image", data, mimeType };
|
|
63
|
+
}
|
|
64
|
+
throw new TypeError("Invalid execution content type");
|
|
65
|
+
}),
|
|
66
|
+
isError,
|
|
67
|
+
details: json(fields["details"] ?? null),
|
|
68
|
+
diagnostics: diagnostics.map((value) => {
|
|
69
|
+
const item = object(value);
|
|
70
|
+
const severity = item["severity"];
|
|
71
|
+
if (severity !== "info" && severity !== "warn" && severity !== "error")
|
|
72
|
+
throw new TypeError("Invalid execution diagnostic severity");
|
|
73
|
+
return {
|
|
74
|
+
severity,
|
|
75
|
+
message: string(item["message"]),
|
|
76
|
+
...item["code"] === undefined ? {} : { code: string(item["code"]) }
|
|
77
|
+
};
|
|
78
|
+
})
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function parseExecutionPresentationState(value) {
|
|
82
|
+
const fields = object(value);
|
|
83
|
+
return {
|
|
84
|
+
cell: cell(fields["cell"]),
|
|
85
|
+
result: parseExecutionResultReceipt(fields["result"])
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function executionCapability(id, actions) {
|
|
89
|
+
return {
|
|
90
|
+
id,
|
|
91
|
+
version: 1,
|
|
92
|
+
actions,
|
|
93
|
+
streams: ["results"],
|
|
94
|
+
presentations: ["summary", "detail"],
|
|
95
|
+
parseState: parseExecutionPresentationState
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function executionSummary(title) {
|
|
99
|
+
return {
|
|
100
|
+
id: "summary",
|
|
101
|
+
select: (state) => ({
|
|
102
|
+
title,
|
|
103
|
+
cell: state.cell,
|
|
104
|
+
hasResult: state.result !== null,
|
|
105
|
+
isError: state.result?.isError ?? null
|
|
106
|
+
}),
|
|
107
|
+
requests: ["detail"]
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
var executionDetail = {
|
|
111
|
+
id: "detail",
|
|
112
|
+
select: (state) => state,
|
|
113
|
+
requests: []
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// packages/execution/src/forwarded-tools.ts
|
|
117
|
+
function object2(value) {
|
|
118
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)
|
|
119
|
+
throw new TypeError("Invalid forwarded tool calls object");
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
function string2(value) {
|
|
123
|
+
if (typeof value !== "string" || !value)
|
|
124
|
+
throw new TypeError("Invalid forwarded tool identity");
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
function json2(value, ancestors = new Set) {
|
|
128
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
129
|
+
return value;
|
|
130
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
131
|
+
return value;
|
|
132
|
+
if (!value || typeof value !== "object" || ancestors.has(value))
|
|
133
|
+
throw new TypeError("Invalid forwarded tool JSON");
|
|
134
|
+
ancestors.add(value);
|
|
135
|
+
try {
|
|
136
|
+
return Array.isArray(value) ? value.map((item) => json2(item, ancestors)) : Object.fromEntries(Object.entries(object2(value)).map(([key, item]) => [
|
|
137
|
+
key,
|
|
138
|
+
json2(item, ancestors)
|
|
139
|
+
]));
|
|
140
|
+
} finally {
|
|
141
|
+
ancestors.delete(value);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function parseForwardedToolCalls(details) {
|
|
145
|
+
if (!details || typeof details !== "object" || !("forwardedToolCalls" in details))
|
|
146
|
+
return null;
|
|
147
|
+
const fields = object2(details.forwardedToolCalls);
|
|
148
|
+
if (fields["version"] !== 1)
|
|
149
|
+
throw new TypeError("Unsupported forwarded tool calls version");
|
|
150
|
+
const cellId = string2(fields["cellId"]);
|
|
151
|
+
if (!/^[1-9][0-9]*$/.test(cellId) || !Number.isSafeInteger(Number(cellId)))
|
|
152
|
+
throw new TypeError("Invalid forwarded cell ID");
|
|
153
|
+
const omittedCalls = fields["omittedCalls"];
|
|
154
|
+
if (typeof omittedCalls !== "number" || !Number.isSafeInteger(omittedCalls) || omittedCalls < 0 || !Array.isArray(fields["calls"]))
|
|
155
|
+
throw new TypeError("Invalid forwarded tool call list");
|
|
156
|
+
const ids = new Set;
|
|
157
|
+
const calls = fields["calls"].map((value) => {
|
|
158
|
+
const call = object2(value);
|
|
159
|
+
const callId = string2(call["callId"]);
|
|
160
|
+
if (ids.has(callId))
|
|
161
|
+
throw new TypeError("Duplicate forwarded tool call ID");
|
|
162
|
+
ids.add(callId);
|
|
163
|
+
const status = call["status"];
|
|
164
|
+
if (status !== "pending" && status !== "running" && status !== "completed" && status !== "failed" && status !== "aborted" && status !== "interrupted")
|
|
165
|
+
throw new TypeError("Invalid forwarded tool status");
|
|
166
|
+
const omitted = call["omittedFields"];
|
|
167
|
+
if (!Array.isArray(omitted) || omitted.some((field) => field !== "arguments" && field !== "result") || new Set(omitted).size !== omitted.length)
|
|
168
|
+
throw new TypeError("Invalid forwarded omitted fields");
|
|
169
|
+
const omittedFields = omitted.map((field) => {
|
|
170
|
+
if (field === "arguments" || field === "result")
|
|
171
|
+
return field;
|
|
172
|
+
throw new TypeError("Invalid forwarded omitted field");
|
|
173
|
+
});
|
|
174
|
+
if (!("arguments" in call) !== omittedFields.includes("arguments") || omittedFields.includes("result") && call["result"] !== null)
|
|
175
|
+
throw new TypeError("Inconsistent forwarded omitted fields");
|
|
176
|
+
return {
|
|
177
|
+
callId,
|
|
178
|
+
parentCallId: string2(call["parentCallId"]),
|
|
179
|
+
name: string2(call["name"]),
|
|
180
|
+
...omittedFields.includes("arguments") ? {} : { arguments: json2(call["arguments"]) },
|
|
181
|
+
status,
|
|
182
|
+
result: parseExecutionResultReceipt(json2(call["result"])),
|
|
183
|
+
omittedFields
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
return { version: 1, cellId, calls, omittedCalls };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// packages/code/src/presentation.ts
|
|
190
|
+
var codeCapability = executionCapability("code", ["exec", "wait"]);
|
|
191
|
+
var codeSummary = executionSummary("Code");
|
|
192
|
+
var codeDetail = executionDetail;
|
|
193
|
+
export {
|
|
194
|
+
codeCapability,
|
|
195
|
+
codeDetail,
|
|
196
|
+
codeSummary,
|
|
197
|
+
parseForwardedToolCalls
|
|
198
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,78 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@howaboua/pi-durable-code",
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "Code execution and shell tools for Pi Durable",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/IgorWarzocha/pi-durable-components.git",
|
|
10
|
+
"directory": "packages/code"
|
|
11
|
+
},
|
|
12
|
+
"author": "Igor Warzocha",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22.19.0"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/code/src/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
"./history": {
|
|
20
|
+
"types": "./dist/code/src/history.d.ts",
|
|
21
|
+
"import": "./dist/history.js"
|
|
22
|
+
},
|
|
23
|
+
"./presentation": {
|
|
24
|
+
"types": "./dist/code/src/presentation.d.ts",
|
|
25
|
+
"import": "./dist/presentation.js"
|
|
26
|
+
},
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/code/src/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./component": {
|
|
32
|
+
"types": "./dist/code/src/activation.d.ts",
|
|
33
|
+
"import": "./dist/activation.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md",
|
|
39
|
+
"NOTICE",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
],
|
|
42
|
+
"sideEffects": false,
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"node-pty": "1.1.0",
|
|
45
|
+
"smol-toml": "1.9.0",
|
|
46
|
+
"proxy-from-env": "2.1.0",
|
|
47
|
+
"undici": "8.10.2",
|
|
48
|
+
"typebox": "1.3.27",
|
|
49
|
+
"@howaboua/pi-durable-components": "0.10.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@earendil-works/chord": "1.4.0",
|
|
53
|
+
"@earendil-works/pi-ai": "1.4.0",
|
|
54
|
+
"@earendil-works/pi-durable": "1.4.0",
|
|
55
|
+
"@modelcontextprotocol/sdk": ">=1.25.2 <2"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
},
|
|
60
|
+
"durable": {
|
|
61
|
+
"schemaVersion": 1,
|
|
62
|
+
"kind": "extension",
|
|
63
|
+
"entry": "./component",
|
|
64
|
+
"runtimes": [
|
|
65
|
+
"node"
|
|
66
|
+
],
|
|
67
|
+
"requires": [
|
|
68
|
+
"durable.node-execution.v1",
|
|
69
|
+
"durable.state.v1"
|
|
70
|
+
],
|
|
71
|
+
"permissions": [
|
|
72
|
+
"filesystem",
|
|
73
|
+
"process",
|
|
74
|
+
"network"
|
|
75
|
+
],
|
|
76
|
+
"selectionGroup": "execution"
|
|
77
|
+
}
|
|
78
|
+
}
|