pi-fabric 0.92.13 → 0.92.15
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 +2 -0
- package/dist/agents/service-provider.d.ts.map +1 -1
- package/dist/agents/service-types.d.ts +3 -1
- package/dist/agents/service-types.d.ts.map +1 -1
- package/dist/agents/service.d.ts +2 -0
- package/dist/agents/service.d.ts.map +1 -1
- package/dist/agents.js +8 -2
- package/dist/agents.js.map +2 -2
- package/dist/audit/projection.d.ts.map +1 -1
- package/dist/chunks/{chunk-OAXSWVOB.js → chunk-2PZWDVJB.js} +7 -1
- package/dist/chunks/chunk-2PZWDVJB.js.map +7 -0
- package/dist/chunks/chunk-3MEHEH6B.js +41 -0
- package/dist/chunks/chunk-3MEHEH6B.js.map +7 -0
- package/dist/chunks/{chunk-BSGA3KSB.js → chunk-3WIGAX56.js} +2 -2
- package/dist/chunks/{chunk-FRONVGLX.js → chunk-7A6NVHB5.js} +2 -2
- package/dist/chunks/{chunk-T3UYWHLT.js → chunk-D5WKZONW.js} +10 -289
- package/dist/chunks/chunk-D5WKZONW.js.map +7 -0
- package/dist/chunks/chunk-G4LADAYY.js +287 -0
- package/dist/chunks/chunk-G4LADAYY.js.map +7 -0
- package/dist/chunks/{chunk-CQLOEDQZ.js → chunk-IWH6PCMK.js} +2 -2
- package/dist/chunks/chunk-LUX7VAM2.js +373 -0
- package/dist/chunks/chunk-LUX7VAM2.js.map +7 -0
- package/dist/chunks/{chunk-KNBPIZF7.js → chunk-MGDLRV2R.js} +2 -2
- package/dist/chunks/{chunk-WBDM7CH4.js → chunk-N5GUXC6F.js} +4 -4
- package/dist/chunks/{chunk-WBDM7CH4.js.map → chunk-N5GUXC6F.js.map} +2 -2
- package/dist/chunks/{chunk-WTGFGQ2K.js → chunk-NIUOPHLB.js} +5 -373
- package/dist/chunks/chunk-NIUOPHLB.js.map +7 -0
- package/dist/chunks/chunk-OX7BU3RX.js +590 -0
- package/dist/chunks/chunk-OX7BU3RX.js.map +7 -0
- package/dist/chunks/{chunk-UNN5OJQB.js → chunk-P7UQ5TWL.js} +3 -3
- package/dist/chunks/chunk-PSNXUZMY.js +218 -0
- package/dist/chunks/chunk-PSNXUZMY.js.map +7 -0
- package/dist/chunks/{chunk-RLFQHZ7K.js → chunk-QLJ5P7HV.js} +2 -2
- package/dist/chunks/{chunk-6ELA5OWI.js → chunk-RNOPHITP.js} +7 -5
- package/dist/chunks/{chunk-6ELA5OWI.js.map → chunk-RNOPHITP.js.map} +1 -1
- package/dist/chunks/chunk-T3A5GNCW.js +19 -0
- package/dist/chunks/chunk-T3A5GNCW.js.map +7 -0
- package/dist/chunks/chunk-TPLMVELH.js +118 -0
- package/dist/chunks/chunk-TPLMVELH.js.map +7 -0
- package/dist/chunks/{chunk-HUCNOAKK.js → chunk-U4NSXDRO.js} +2 -2
- package/dist/chunks/{chunk-EZ7YLET5.js → chunk-UDFDF7IY.js} +10 -4
- package/dist/chunks/chunk-UDFDF7IY.js.map +7 -0
- package/dist/chunks/{chunk-6GT4YJT2.js → chunk-UQ4LTUH4.js} +4 -4
- package/dist/chunks/{chunk-QJUDWDPL.js → chunk-VHEO26TE.js} +24 -204
- package/dist/chunks/chunk-VHEO26TE.js.map +7 -0
- package/dist/chunks/{chunk-DLYYHK6Z.js → chunk-VQMPHVLC.js} +6 -6
- package/dist/chunks/{chunk-R4AZTYXC.js → chunk-WMS5SDKD.js} +3 -3
- package/dist/chunks/{chunk-VJJFD42F.js → chunk-XT4346N7.js} +2 -2
- package/dist/chunks/{chunk-YVPUATQT.js → chunk-Y7KNRAFL.js} +36 -15
- package/dist/chunks/chunk-Y7KNRAFL.js.map +7 -0
- package/dist/chunks/{chunk-4VVD63BA.js → chunk-YSXGVO2N.js} +2 -1
- package/dist/chunks/{chunk-4VVD63BA.js.map → chunk-YSXGVO2N.js.map} +2 -2
- package/dist/chunks/{chunk-X45GMLON.js → chunk-ZDNGXLEC.js} +2 -2
- package/dist/chunks/{chunk-FN6Q4R4M.js → chunk-ZG3ELJHX.js} +47 -1
- package/dist/chunks/chunk-ZG3ELJHX.js.map +7 -0
- package/dist/compaction/hook.js +5 -4
- package/dist/components/provider-component.d.ts +1 -1
- package/dist/components/provider-component.d.ts.map +1 -1
- package/dist/config.d.ts +3 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/core/action-registry.js +4 -2
- package/dist/entropy/index.js +7 -6
- package/dist/fabric-runtime-state.d.ts.map +1 -1
- package/dist/fabric-runtime-state.js +96 -43
- package/dist/fabric-runtime-state.js.map +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -36
- package/dist/index.js.map +2 -2
- package/dist/jev/auth.d.ts +5 -0
- package/dist/jev/auth.d.ts.map +1 -0
- package/dist/jev/browser.d.ts +37 -0
- package/dist/jev/browser.d.ts.map +1 -0
- package/dist/jev/browser.js +13 -0
- package/dist/jev/browser.js.map +7 -0
- package/dist/jev/client.d.ts +29 -0
- package/dist/jev/client.d.ts.map +1 -0
- package/dist/jev/config.d.ts +17 -0
- package/dist/jev/config.d.ts.map +1 -0
- package/dist/jev/guest-types.d.ts +2 -0
- package/dist/jev/guest-types.d.ts.map +1 -0
- package/dist/jev/manager.d.ts +32 -0
- package/dist/jev/manager.d.ts.map +1 -0
- package/dist/jev/types.d.ts +95 -0
- package/dist/jev/types.d.ts.map +1 -0
- package/dist/jev/validation.d.ts +8 -0
- package/dist/jev/validation.d.ts.map +1 -0
- package/dist/jev.d.ts +8 -0
- package/dist/jev.d.ts.map +1 -0
- package/dist/jev.js +39 -0
- package/dist/jev.js.map +7 -0
- package/dist/memory/discovery.js +5 -4
- package/dist/memory/normalize.js +4 -3
- package/dist/memory/search.js +5 -4
- package/dist/memory.js +7 -6
- package/dist/memory.js.map +1 -1
- package/dist/providers/agents-actions.d.ts.map +1 -1
- package/dist/providers/agents-provider.d.ts.map +1 -1
- package/dist/providers/jev-provider.d.ts +55 -0
- package/dist/providers/jev-provider.d.ts.map +1 -0
- package/dist/providers/jev-provider.js +21 -0
- package/dist/providers/jev-provider.js.map +7 -0
- package/dist/providers/memory-provider.js +7 -6
- package/dist/residency/host.js +10 -8
- package/dist/residency/pi-entry.js +10 -8
- package/dist/residency/pi-entry.js.map +1 -1
- package/dist/runtime/core-override-guest-types.js +2 -2
- package/dist/runtime/guest-types.d.ts +1 -1
- package/dist/runtime/guest-types.d.ts.map +1 -1
- package/dist/runtime/guest-types.js +1 -1
- package/dist/runtime/kernel.d.ts +3 -0
- package/dist/runtime/kernel.d.ts.map +1 -1
- package/dist/runtime/monty-runtime.js +3 -2
- package/dist/runtime/monty-runtime.js.map +1 -1
- package/dist/runtime/node-process-runtime.js +3 -3
- package/dist/runtime/orchestration.d.ts.map +1 -1
- package/dist/runtime/quickjs-runtime.d.ts.map +1 -1
- package/dist/runtime/quickjs-runtime.js +2 -2
- package/dist/runtime/type-checker.d.ts +1 -1
- package/dist/runtime/type-checker.d.ts.map +1 -1
- package/dist/runtime/type-checker.js +1 -1
- package/dist/runtime/typescript-kernel.d.ts +1 -1
- package/dist/runtime/typescript-kernel.d.ts.map +1 -1
- package/dist/runtime/typescript-kernel.js +10 -10
- package/dist/runtime/typescript-kernel.js.map +2 -2
- package/dist/runtime-state-builtins.d.ts.map +1 -1
- package/dist/ui/dashboard.js +1 -1
- package/dist/ui/fabric-render.d.ts.map +1 -1
- package/dist/ui/settings.js +3 -2
- package/dist/ui/settings.js.map +1 -1
- package/docs/agents.md +2 -0
- package/docs/components.md +1 -0
- package/docs/configuration.md +6 -0
- package/docs/jev.md +212 -0
- package/docs/skills.md +3 -2
- package/package.json +8 -2
- package/skillsets/python/fabric-exec/SKILL.md +10 -0
- package/skillsets/python/fabric-exec/references/agents.md +2 -0
- package/skillsets/python/fabric-guide/SKILL.md +3 -2
- package/skillsets/python/fabric-jev/SKILL.md +107 -0
- package/skillsets/typescript/fabric-exec/SKILL.md +15 -0
- package/skillsets/typescript/fabric-exec/references/agents.md +2 -0
- package/skillsets/typescript/fabric-guide/SKILL.md +3 -2
- package/skillsets/typescript/fabric-jev/SKILL.md +107 -0
- package/dist/chunks/chunk-EZ7YLET5.js.map +0 -7
- package/dist/chunks/chunk-FN6Q4R4M.js.map +0 -7
- package/dist/chunks/chunk-OAXSWVOB.js.map +0 -7
- package/dist/chunks/chunk-QJUDWDPL.js.map +0 -7
- package/dist/chunks/chunk-T3UYWHLT.js.map +0 -7
- package/dist/chunks/chunk-WTGFGQ2K.js.map +0 -7
- package/dist/chunks/chunk-YVPUATQT.js.map +0 -7
- /package/dist/chunks/{chunk-BSGA3KSB.js.map → chunk-3WIGAX56.js.map} +0 -0
- /package/dist/chunks/{chunk-FRONVGLX.js.map → chunk-7A6NVHB5.js.map} +0 -0
- /package/dist/chunks/{chunk-CQLOEDQZ.js.map → chunk-IWH6PCMK.js.map} +0 -0
- /package/dist/chunks/{chunk-KNBPIZF7.js.map → chunk-MGDLRV2R.js.map} +0 -0
- /package/dist/chunks/{chunk-UNN5OJQB.js.map → chunk-P7UQ5TWL.js.map} +0 -0
- /package/dist/chunks/{chunk-RLFQHZ7K.js.map → chunk-QLJ5P7HV.js.map} +0 -0
- /package/dist/chunks/{chunk-HUCNOAKK.js.map → chunk-U4NSXDRO.js.map} +0 -0
- /package/dist/chunks/{chunk-6GT4YJT2.js.map → chunk-UQ4LTUH4.js.map} +0 -0
- /package/dist/chunks/{chunk-DLYYHK6Z.js.map → chunk-VQMPHVLC.js.map} +0 -0
- /package/dist/chunks/{chunk-R4AZTYXC.js.map → chunk-WMS5SDKD.js.map} +0 -0
- /package/dist/chunks/{chunk-VJJFD42F.js.map → chunk-XT4346N7.js.map} +0 -0
- /package/dist/chunks/{chunk-X45GMLON.js.map → chunk-ZDNGXLEC.js.map} +0 -0
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApprovalController,
|
|
3
|
+
FabricSessionApprovals
|
|
4
|
+
} from "./chunk-LUX7VAM2.js";
|
|
5
|
+
import {
|
|
6
|
+
validationMessage
|
|
7
|
+
} from "./chunk-PSNXUZMY.js";
|
|
8
|
+
import {
|
|
9
|
+
runAbortable
|
|
10
|
+
} from "./chunk-7TB7NXSL.js";
|
|
11
|
+
|
|
12
|
+
// src/providers/jev-provider.ts
|
|
13
|
+
import { Type } from "typebox";
|
|
14
|
+
|
|
15
|
+
// src/jev/client.ts
|
|
16
|
+
import { execFile } from "node:child_process";
|
|
17
|
+
|
|
18
|
+
// src/jev/validation.ts
|
|
19
|
+
import { Value } from "typebox/value";
|
|
20
|
+
function jsonText(value, maxBytes, label) {
|
|
21
|
+
let nodes = 0;
|
|
22
|
+
const visit = (v, depth) => {
|
|
23
|
+
if (++nodes > 1e5 || depth > 32) throw new Error(`${label} exceeds JSON complexity limits`);
|
|
24
|
+
if (v === null || typeof v === "string" || typeof v === "boolean") return;
|
|
25
|
+
if (typeof v === "number" && Number.isFinite(v)) return;
|
|
26
|
+
if (Array.isArray(v)) {
|
|
27
|
+
for (const item of v) visit(item, depth + 1);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (typeof v === "object" && v !== null && Object.getPrototypeOf(v) === Object.prototype) {
|
|
31
|
+
for (const item of Object.values(v)) visit(item, depth + 1);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
throw new Error(`${label} must contain only finite JSON values`);
|
|
35
|
+
};
|
|
36
|
+
visit(value, 0);
|
|
37
|
+
const text = JSON.stringify(value);
|
|
38
|
+
if (Buffer.byteLength(text) > maxBytes) throw new Error(`${label} exceeds ${maxBytes} bytes`);
|
|
39
|
+
return text;
|
|
40
|
+
}
|
|
41
|
+
var object = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
42
|
+
var description = (v) => typeof v === "string" || object(v) || Array.isArray(v);
|
|
43
|
+
var keysOnly = (v, keys) => Object.keys(v).every((k) => keys.includes(k));
|
|
44
|
+
function checkRequest(value, maxBytes) {
|
|
45
|
+
jsonText(value, maxBytes, "Jev request");
|
|
46
|
+
if (!object(value) || !keysOnly(value, ["state", "questions", "model"]) || !description(value.state) || !object(value.questions) || Object.keys(value.questions).length < 1 || Object.keys(value.questions).length > 128 || value.model !== void 0 && (typeof value.model !== "string" || !/^[a-zA-Z0-9._-]{1,128}$/.test(value.model))) {
|
|
47
|
+
throw new Error("Invalid Jev request: provide state, 1\u2013128 questions, and an optional model ID");
|
|
48
|
+
}
|
|
49
|
+
for (const [id, q] of Object.entries(value.questions)) {
|
|
50
|
+
if (!id || id.length > 128 || !object(q) || !keysOnly(q, ["type", "instructions", "criteria"]) || !description(q.instructions))
|
|
51
|
+
throw new Error("Invalid Jev question: each question needs a type and complete instructions");
|
|
52
|
+
if (q.type === "choice") {
|
|
53
|
+
if (!object(q.criteria) || Object.keys(q.criteria).length < 1 || Object.keys(q.criteria).length > 255 || !Object.entries(q.criteria).every(([key, v]) => key.length > 0 && key.length <= 256 && (v === null || description(v))))
|
|
54
|
+
throw new Error("Choice requires 1\u2013255 named options with descriptions or null");
|
|
55
|
+
} else if (q.type === "score") {
|
|
56
|
+
if (!Array.isArray(q.criteria) || q.criteria.length < 2 || q.criteria.length > 10 || !q.criteria.every(description))
|
|
57
|
+
throw new Error("Score requires 2\u201310 ordered descriptive levels");
|
|
58
|
+
} else if (q.type === "noul") {
|
|
59
|
+
if (q.criteria !== void 0 && (!object(q.criteria) || !keysOnly(q.criteria, ["true", "false"]) || !Object.values(q.criteria).every(description)))
|
|
60
|
+
throw new Error("Noul criteria may describe true and false only");
|
|
61
|
+
} else throw new Error("Jev supports choice, score, and noul\u2014not free-text generation");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
var probability = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 && v <= 1;
|
|
65
|
+
function checkResponse(value, request) {
|
|
66
|
+
const invalid = () => {
|
|
67
|
+
throw new Error("TypeSafe returned an invalid typed response");
|
|
68
|
+
};
|
|
69
|
+
if (!object(value) || typeof value.model !== "string" || value.model.length > 128 || !object(value.answers) || !object(value.usage)) return invalid();
|
|
70
|
+
const usage = value.usage;
|
|
71
|
+
if (![usage.input_tokens, usage.output_tokens].every((v) => Number.isSafeInteger(v) && v >= 0)) return invalid();
|
|
72
|
+
if (Object.keys(value.answers).length !== Object.keys(request.questions).length) return invalid();
|
|
73
|
+
const entries = [];
|
|
74
|
+
for (const [id, question2] of Object.entries(request.questions)) {
|
|
75
|
+
const a = Object.hasOwn(value.answers, id) ? value.answers[id] : void 0;
|
|
76
|
+
if (!object(a) || a.type !== question2.type) return invalid();
|
|
77
|
+
if (question2.type === "noul") {
|
|
78
|
+
if (!probability(a.noul)) return invalid();
|
|
79
|
+
entries.push([id, { type: "noul", noul: a.noul }]);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const keys = question2.type === "choice" ? Object.keys(question2.criteria) : question2.criteria.map((_, i) => String(i));
|
|
83
|
+
const p = a.probabilities;
|
|
84
|
+
if (!probability(a.confidence) || !object(p) || Object.keys(p).length !== keys.length || !keys.every((k) => Object.hasOwn(p, k) && probability(p[k])) || Math.abs(Object.values(p).reduce((sum, v) => sum + v, 0) - 1) > 0.02) return invalid();
|
|
85
|
+
const probabilities = Object.fromEntries(keys.map((k) => [k, p[k]]));
|
|
86
|
+
if (question2.type === "choice") {
|
|
87
|
+
if (typeof a.choice !== "string" || !Object.hasOwn(question2.criteria, a.choice)) return invalid();
|
|
88
|
+
entries.push([id, { type: "choice", choice: a.choice, confidence: a.confidence, probabilities }]);
|
|
89
|
+
} else {
|
|
90
|
+
if (typeof a.score !== "number" || !Number.isFinite(a.score) || a.score < 0 || a.score > keys.length - 1) return invalid();
|
|
91
|
+
const legend = Object.fromEntries(question2.criteria.map((level, i) => [String(i), level]));
|
|
92
|
+
entries.push([id, { type: "score", score: a.score, confidence: a.confidence, probabilities, legend }]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { model: value.model, answers: Object.fromEntries(entries), usage: {
|
|
96
|
+
input_tokens: usage.input_tokens,
|
|
97
|
+
output_tokens: usage.output_tokens
|
|
98
|
+
} };
|
|
99
|
+
}
|
|
100
|
+
var schemaKeys = /* @__PURE__ */ new Set(["type", "properties", "required", "additionalProperties", "items", "enum", "const", "anyOf", "oneOf", "allOf", "minimum", "maximum", "minLength", "maxLength", "minItems", "maxItems", "minProperties", "maxProperties", "description", "title"]);
|
|
101
|
+
function checkSchema(schema) {
|
|
102
|
+
jsonText(schema, 16384, "Program schema");
|
|
103
|
+
let nodes = 0;
|
|
104
|
+
const visit = (s, depth) => {
|
|
105
|
+
if (!object(s) || ++nodes > 128 || depth > 12 || Object.keys(s).some((k) => !schemaKeys.has(k)))
|
|
106
|
+
throw new Error("Unsupported program schema; use the documented bounded JSON Schema subset (no references or regexes)");
|
|
107
|
+
if (s.type !== void 0 && !["object", "array", "string", "number", "integer", "boolean", "null"].includes(s.type)) throw new Error("Invalid schema type");
|
|
108
|
+
if (s.properties !== void 0) {
|
|
109
|
+
if (!object(s.properties)) throw new Error("Schema properties must be an object");
|
|
110
|
+
Object.values(s.properties).forEach((v) => visit(v, depth + 1));
|
|
111
|
+
}
|
|
112
|
+
if (s.required !== void 0 && (!Array.isArray(s.required) || !s.required.every((v) => typeof v === "string"))) throw new Error("Schema required must be a string array");
|
|
113
|
+
if (s.additionalProperties !== void 0 && typeof s.additionalProperties !== "boolean") visit(s.additionalProperties, depth + 1);
|
|
114
|
+
if (s.items !== void 0) visit(s.items, depth + 1);
|
|
115
|
+
for (const k of ["anyOf", "oneOf", "allOf"]) if (s[k] !== void 0) {
|
|
116
|
+
if (!Array.isArray(s[k]) || s[k].length < 1 || s[k].length > 16) throw new Error("Invalid schema alternatives");
|
|
117
|
+
s[k].forEach((v) => visit(v, depth + 1));
|
|
118
|
+
}
|
|
119
|
+
for (const k of ["minimum", "maximum", "minLength", "maxLength", "minItems", "maxItems", "minProperties", "maxProperties"])
|
|
120
|
+
if (s[k] !== void 0 && (typeof s[k] !== "number" || !Number.isFinite(s[k]) || !["minimum", "maximum"].includes(k) && (!Number.isSafeInteger(s[k]) || s[k] < 0))) throw new Error("Invalid schema bound");
|
|
121
|
+
if (s.enum !== void 0 && (!Array.isArray(s.enum) || s.enum.length === 0 || s.enum.length > 256)) throw new Error("Invalid schema enum");
|
|
122
|
+
};
|
|
123
|
+
visit(schema, 0);
|
|
124
|
+
}
|
|
125
|
+
function checkValue(schema, value, label) {
|
|
126
|
+
jsonText(value, 32768, label);
|
|
127
|
+
if (!Value.Check(schema, value)) throw new Error(`${label} does not match its declared schema`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/jev/client.ts
|
|
131
|
+
var JevCredentials = class {
|
|
132
|
+
constructor(command, env = process.env, providerAuth) {
|
|
133
|
+
this.command = command;
|
|
134
|
+
this.env = env;
|
|
135
|
+
this.providerAuth = providerAuth;
|
|
136
|
+
}
|
|
137
|
+
#cached;
|
|
138
|
+
status() {
|
|
139
|
+
const source = this.providerAuth?.configured() ? "pi" : this.env.TYPESAFE_API_KEY?.trim() ? "environment" : this.command.length ? "command" : "missing";
|
|
140
|
+
return { configured: source !== "missing", source, verified: false };
|
|
141
|
+
}
|
|
142
|
+
async resolve(signal) {
|
|
143
|
+
signal.throwIfAborted();
|
|
144
|
+
if (this.providerAuth) {
|
|
145
|
+
try {
|
|
146
|
+
const key = await this.providerAuth.resolve(signal);
|
|
147
|
+
signal.throwIfAborted();
|
|
148
|
+
if (key?.trim()) return key.trim();
|
|
149
|
+
} catch {
|
|
150
|
+
throw new Error("Jev Pi credential resolution failed");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const env = this.env.TYPESAFE_API_KEY?.trim();
|
|
154
|
+
if (env) return env;
|
|
155
|
+
if (this.#cached) return this.#cached;
|
|
156
|
+
const [file, ...args] = this.command;
|
|
157
|
+
if (!file) throw new Error("Jev credentials unavailable: set TYPESAFE_API_KEY or configure jev.credentialCommand");
|
|
158
|
+
const secret = await new Promise((resolve, reject) => {
|
|
159
|
+
execFile(file, args, { encoding: "utf8", timeout: 5e3, maxBuffer: 16384, signal, windowsHide: true }, (error, stdout) => {
|
|
160
|
+
if (error) reject(new Error("Jev credential resolver failed"));
|
|
161
|
+
else resolve(stdout.trim());
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
signal.throwIfAborted();
|
|
165
|
+
if (!secret || /[\r\n]/.test(secret)) throw new Error("Jev credential resolver returned an invalid credential");
|
|
166
|
+
this.#cached = secret;
|
|
167
|
+
return secret;
|
|
168
|
+
}
|
|
169
|
+
clear() {
|
|
170
|
+
this.#cached = void 0;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
var JevClient = class {
|
|
174
|
+
constructor(config, fetcher = fetch, credentials) {
|
|
175
|
+
this.config = config;
|
|
176
|
+
this.fetcher = fetcher;
|
|
177
|
+
this.credentials = credentials ?? new JevCredentials(config.credentialCommand);
|
|
178
|
+
}
|
|
179
|
+
credentials;
|
|
180
|
+
async evaluate(request, signal) {
|
|
181
|
+
checkRequest(request, this.config.maxRequestBytes);
|
|
182
|
+
const timedSignal = AbortSignal.any([signal, AbortSignal.timeout(this.config.requestTimeoutMs)]);
|
|
183
|
+
const key = await runAbortable(timedSignal, () => this.credentials.resolve(timedSignal));
|
|
184
|
+
const body = jsonText({ ...request, model: request.model ?? this.config.model }, this.config.maxRequestBytes, "Jev request");
|
|
185
|
+
let response;
|
|
186
|
+
try {
|
|
187
|
+
response = await runAbortable(timedSignal, () => this.fetcher("https://api.typesafe.ai/v1/systemone", {
|
|
188
|
+
method: "POST",
|
|
189
|
+
redirect: "error",
|
|
190
|
+
signal: timedSignal,
|
|
191
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${key}` },
|
|
192
|
+
body
|
|
193
|
+
}));
|
|
194
|
+
} catch {
|
|
195
|
+
throw new Error(timedSignal.aborted ? "Jev request cancelled or timed out" : "Jev network request failed");
|
|
196
|
+
}
|
|
197
|
+
if (!response.ok) {
|
|
198
|
+
await response.body?.cancel();
|
|
199
|
+
throw new Error(`TypeSafe HTTP ${response.status}${[429, 529].includes(response.status) ? ": rate limited; back off before retrying" : ""}`);
|
|
200
|
+
}
|
|
201
|
+
const reader = response.body?.getReader();
|
|
202
|
+
if (!reader) throw new Error("TypeSafe returned an empty response");
|
|
203
|
+
const chunks = [];
|
|
204
|
+
let bytes = 0;
|
|
205
|
+
try {
|
|
206
|
+
for (; ; ) {
|
|
207
|
+
const { value, done } = await runAbortable(timedSignal, () => reader.read());
|
|
208
|
+
if (done) break;
|
|
209
|
+
bytes += value.byteLength;
|
|
210
|
+
if (bytes > 1048576) throw new Error("oversize");
|
|
211
|
+
chunks.push(value);
|
|
212
|
+
}
|
|
213
|
+
return checkResponse(JSON.parse(Buffer.concat(chunks).toString("utf8")), request);
|
|
214
|
+
} catch {
|
|
215
|
+
throw new Error(timedSignal.aborted ? "Jev response cancelled or timed out" : "TypeSafe returned an invalid or oversized typed response");
|
|
216
|
+
} finally {
|
|
217
|
+
await reader.cancel().catch(() => void 0);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
close() {
|
|
221
|
+
this.credentials.clear();
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// src/jev/manager.ts
|
|
226
|
+
import { randomUUID } from "node:crypto";
|
|
227
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
228
|
+
var prelude = `const input = JSON.parse(\u03C0.__jevInput);
|
|
229
|
+
const program = Object.freeze({
|
|
230
|
+
sleep: (ms: number): Promise<unknown> => tools.call({ ref: "jev.$sleep", args: { ms } }),
|
|
231
|
+
emit: (value: unknown): Promise<unknown> => tools.call({ ref: "jev.$emit", args: { value } }),
|
|
232
|
+
});
|
|
233
|
+
`;
|
|
234
|
+
var JevProgramManager = class {
|
|
235
|
+
constructor(options) {
|
|
236
|
+
this.options = options;
|
|
237
|
+
}
|
|
238
|
+
#runs = /* @__PURE__ */ new Map();
|
|
239
|
+
#approvals = new FabricSessionApprovals();
|
|
240
|
+
#closed = false;
|
|
241
|
+
#starting = 0;
|
|
242
|
+
list() {
|
|
243
|
+
return [...this.#runs.values()].map(({ info }) => ({
|
|
244
|
+
id: info.id,
|
|
245
|
+
name: info.name,
|
|
246
|
+
state: info.state,
|
|
247
|
+
background: info.background,
|
|
248
|
+
startedAt: info.startedAt,
|
|
249
|
+
evaluations: info.evaluations,
|
|
250
|
+
toolCalls: info.toolCalls
|
|
251
|
+
}));
|
|
252
|
+
}
|
|
253
|
+
#get(id) {
|
|
254
|
+
const run = this.#runs.get(id);
|
|
255
|
+
if (!run) throw new Error("Unknown or expired Jev run ID");
|
|
256
|
+
return run;
|
|
257
|
+
}
|
|
258
|
+
status(id, after = 0) {
|
|
259
|
+
const info = this.#get(id).info;
|
|
260
|
+
return structuredClone({ ...info, events: info.events.filter((e) => e.sequence > after) });
|
|
261
|
+
}
|
|
262
|
+
async wait(id, signal) {
|
|
263
|
+
return structuredClone(await runAbortable(signal, () => this.#get(id).done));
|
|
264
|
+
}
|
|
265
|
+
/** Alias for wait. */
|
|
266
|
+
join(id, signal) {
|
|
267
|
+
return this.wait(id, signal);
|
|
268
|
+
}
|
|
269
|
+
async stop(id) {
|
|
270
|
+
const run = this.#get(id);
|
|
271
|
+
if (run.info.state === "running") run.controller.abort(new Error("Jev run stopped"));
|
|
272
|
+
return structuredClone(await run.done);
|
|
273
|
+
}
|
|
274
|
+
async launch(request, context, background) {
|
|
275
|
+
const { config, registry } = this.options;
|
|
276
|
+
if (this.#closed) throw new Error("Jev program manager is closed");
|
|
277
|
+
if (this.#starting + [...this.#runs.values()].filter((r) => r.info.state === "running").length >= config.jev.maxConcurrentRuns)
|
|
278
|
+
throw new Error("Jev concurrent run limit reached");
|
|
279
|
+
context.signal?.throwIfAborted();
|
|
280
|
+
this.#starting++;
|
|
281
|
+
let lease;
|
|
282
|
+
let starting = true;
|
|
283
|
+
try {
|
|
284
|
+
const { program: definition, input } = structuredClone(request);
|
|
285
|
+
checkSchema(definition.inputSchema);
|
|
286
|
+
checkSchema(definition.outputSchema);
|
|
287
|
+
checkValue(definition.inputSchema, input, "Program input");
|
|
288
|
+
const requires = [...new Set(definition.requires)];
|
|
289
|
+
for (const ref of requires) {
|
|
290
|
+
if (!/^[a-z][a-z0-9_-]*\.[a-zA-Z0-9_.$-]+$/.test(ref) || ref.startsWith("jev.") && ref !== "jev.evaluate")
|
|
291
|
+
throw new Error("Programs require exact action refs; recursive Jev lifecycle calls are not allowed");
|
|
292
|
+
if (context.capabilityView && !Object.hasOwn(context.capabilityView.bindings, ref))
|
|
293
|
+
throw new Error(`Jev program cannot widen its caller's capabilities: ${ref}`);
|
|
294
|
+
if (!config.fullCodeMode && (ref.startsWith("pi.") || ref.startsWith("extensions.")))
|
|
295
|
+
throw new Error("Full-code tool access is disabled");
|
|
296
|
+
}
|
|
297
|
+
lease = await registry.acquireCapabilityView(requires, context);
|
|
298
|
+
if (!lease.satisfied || !lease.view) throw new Error(`Missing Jev program capabilities: ${lease.missing.join(", ")}`);
|
|
299
|
+
if (context.capabilityView) for (const ref of requires) {
|
|
300
|
+
const before = context.capabilityView.bindings[ref];
|
|
301
|
+
const after = lease.view.bindings[ref];
|
|
302
|
+
if (before.providerBindingId !== after.providerBindingId || before.descriptorHash !== after.descriptorHash)
|
|
303
|
+
throw new Error("Caller capability generation changed; relaunch with a fresh commitment");
|
|
304
|
+
}
|
|
305
|
+
const { TypeScriptKernelRuntime } = await import("../runtime/typescript-kernel.js");
|
|
306
|
+
const runtime = new TypeScriptKernelRuntime("quickjs");
|
|
307
|
+
const sources = await registry.guestTypeSources({ ...context, capabilityView: lease.view });
|
|
308
|
+
const { code, checked } = runtime.prepare(prelude + definition.code, true, [], sources, [], true);
|
|
309
|
+
if (checked.errors.length) throw new Error(`Jev program typecheck failed: ${checked.errors.map((e) => e.message).join("; ").slice(0, 2e3)}`);
|
|
310
|
+
if (this.#closed) throw new Error("Jev program manager is closed");
|
|
311
|
+
context.signal?.throwIfAborted();
|
|
312
|
+
const limits = definition.limits ?? {};
|
|
313
|
+
const bounded = (value, fallback, ceiling) => Math.min(value ?? fallback, ceiling);
|
|
314
|
+
const timeoutMs = bounded(limits.timeoutMs, 6e4, config.jev.maxDurationMs);
|
|
315
|
+
const maxEvaluations = bounded(limits.maxEvaluations, 100, config.jev.maxEvaluations);
|
|
316
|
+
const maxToolCalls = bounded(limits.maxToolCalls, 1e3, config.jev.maxToolCalls);
|
|
317
|
+
const maxTokens = bounded(limits.maxTokens, 1e5, config.jev.maxTokens);
|
|
318
|
+
const id = randomUUID();
|
|
319
|
+
const controller = new AbortController();
|
|
320
|
+
const info = {
|
|
321
|
+
id,
|
|
322
|
+
name: definition.name,
|
|
323
|
+
state: "running",
|
|
324
|
+
background,
|
|
325
|
+
startedAt: Date.now(),
|
|
326
|
+
evaluations: 0,
|
|
327
|
+
toolCalls: 0,
|
|
328
|
+
usage: { input_tokens: 0, output_tokens: 0 },
|
|
329
|
+
events: [],
|
|
330
|
+
nextSequence: 1,
|
|
331
|
+
logs: []
|
|
332
|
+
};
|
|
333
|
+
let budgetFailure;
|
|
334
|
+
const failBudget = (message) => {
|
|
335
|
+
budgetFailure = message;
|
|
336
|
+
queueMicrotask(() => controller.abort(new Error(message)));
|
|
337
|
+
throw new Error(message);
|
|
338
|
+
};
|
|
339
|
+
const approval = new ApprovalController(config.approvals, context.extensionContext, this.#approvals);
|
|
340
|
+
const runLease = lease;
|
|
341
|
+
lease = void 0;
|
|
342
|
+
const abort = () => controller.abort(new Error("Foreground caller cancelled"));
|
|
343
|
+
if (!background) context.signal?.addEventListener("abort", abort, { once: true });
|
|
344
|
+
let timedOut = false;
|
|
345
|
+
const timer = setTimeout(() => {
|
|
346
|
+
timedOut = true;
|
|
347
|
+
controller.abort(new Error("Jev deadline exceeded"));
|
|
348
|
+
}, timeoutMs);
|
|
349
|
+
let evaluating = false;
|
|
350
|
+
const audits = [];
|
|
351
|
+
const emit = (value) => {
|
|
352
|
+
jsonText(value, 4096, "Program event");
|
|
353
|
+
info.events.push({ sequence: info.nextSequence++, at: Date.now(), value });
|
|
354
|
+
if (info.events.length > 64) info.events.shift();
|
|
355
|
+
};
|
|
356
|
+
const run = { info, controller, done: void 0 };
|
|
357
|
+
this.#runs.set(id, run);
|
|
358
|
+
this.#starting--;
|
|
359
|
+
starting = false;
|
|
360
|
+
this.#prune();
|
|
361
|
+
run.done = (async () => {
|
|
362
|
+
try {
|
|
363
|
+
await delay(0, void 0, { signal: controller.signal });
|
|
364
|
+
const result = await runtime.execute(code, async (rawRef, rawArgs, signal) => {
|
|
365
|
+
signal.throwIfAborted();
|
|
366
|
+
controller.signal.throwIfAborted();
|
|
367
|
+
if (budgetFailure) throw new Error(budgetFailure);
|
|
368
|
+
if (++info.toolCalls > maxToolCalls) return failBudget("Jev tool-call budget exhausted");
|
|
369
|
+
const ref = rawRef === "fabric.$call" ? rawArgs.ref : rawRef;
|
|
370
|
+
const args = rawRef === "fabric.$call" ? rawArgs.args ?? {} : rawArgs;
|
|
371
|
+
if (typeof ref !== "string" || !object(args)) throw new Error("Invalid Jev program tool call");
|
|
372
|
+
if (ref === "jev.$sleep") {
|
|
373
|
+
if (typeof args.ms !== "number" || !Number.isFinite(args.ms) || args.ms < 0 || args.ms > timeoutMs) throw new Error("Invalid program.sleep duration");
|
|
374
|
+
await delay(args.ms, void 0, { signal });
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
if (ref === "jev.$emit") {
|
|
378
|
+
emit(args.value);
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
if (!Object.hasOwn(runLease.view.bindings, ref)) throw new Error(`Capability not granted to Jev program: ${ref}`);
|
|
382
|
+
if (ref === "jev.evaluate") {
|
|
383
|
+
if (evaluating) throw new Error("One Jev evaluation may be in flight per program; batch independent questions in one request");
|
|
384
|
+
if (info.evaluations >= maxEvaluations || info.usage.input_tokens + info.usage.output_tokens >= maxTokens)
|
|
385
|
+
return failBudget("Jev inference budget exhausted");
|
|
386
|
+
info.evaluations++;
|
|
387
|
+
evaluating = true;
|
|
388
|
+
}
|
|
389
|
+
try {
|
|
390
|
+
const value = await registry.invoke(ref, args, {
|
|
391
|
+
cwd: context.cwd,
|
|
392
|
+
extensionContext: context.extensionContext,
|
|
393
|
+
signal,
|
|
394
|
+
capabilityView: runLease.view,
|
|
395
|
+
...context.effectPolicy ? { effectPolicy: context.effectPolicy } : {},
|
|
396
|
+
parentToolCallId: `jev:${id}`,
|
|
397
|
+
nestedToolCallId: `jev:${id}:${info.toolCalls}`,
|
|
398
|
+
update() {
|
|
399
|
+
},
|
|
400
|
+
activity() {
|
|
401
|
+
},
|
|
402
|
+
attachMedia() {
|
|
403
|
+
},
|
|
404
|
+
attachPreview() {
|
|
405
|
+
},
|
|
406
|
+
authorize: async (action) => {
|
|
407
|
+
await this.options.authorize?.(action.ref, `jev:${id}`);
|
|
408
|
+
},
|
|
409
|
+
approve: async (action, prepared) => {
|
|
410
|
+
if (action.ref === "schema.commit") {
|
|
411
|
+
await approval.approve({ ...action, risk: "write" }, prepared);
|
|
412
|
+
await approval.approve({ ...action, risk: "execute" }, prepared);
|
|
413
|
+
} else await approval.approve(action, prepared);
|
|
414
|
+
},
|
|
415
|
+
audits,
|
|
416
|
+
maxResultChars: ref === "jev.evaluate" ? 1048576 : config.executor.maxNestedResultChars
|
|
417
|
+
});
|
|
418
|
+
if (ref === "jev.evaluate") {
|
|
419
|
+
const response = value;
|
|
420
|
+
info.usage.input_tokens += response.usage.input_tokens;
|
|
421
|
+
info.usage.output_tokens += response.usage.output_tokens;
|
|
422
|
+
if (info.usage.input_tokens + info.usage.output_tokens > maxTokens)
|
|
423
|
+
return failBudget("Jev reported-token budget exhausted");
|
|
424
|
+
}
|
|
425
|
+
return value;
|
|
426
|
+
} finally {
|
|
427
|
+
if (ref === "jev.evaluate") evaluating = false;
|
|
428
|
+
if (audits.length > 64) audits.splice(0, audits.length - 64);
|
|
429
|
+
}
|
|
430
|
+
}, {
|
|
431
|
+
timeoutMs,
|
|
432
|
+
memoryLimitBytes: Math.min(config.executor.memoryLimitBytes, 64 * 1024 * 1024),
|
|
433
|
+
maxCpuSliceMs: 100,
|
|
434
|
+
maxPendingTimers: 128,
|
|
435
|
+
maxLogChars: 4096,
|
|
436
|
+
strings: { __jevInput: JSON.stringify(input) },
|
|
437
|
+
signal: controller.signal
|
|
438
|
+
});
|
|
439
|
+
info.logs = result.logs;
|
|
440
|
+
if (budgetFailure) {
|
|
441
|
+
info.state = "failed";
|
|
442
|
+
info.error = budgetFailure;
|
|
443
|
+
} else if (timedOut || result.terminationReason === "timed_out") {
|
|
444
|
+
info.state = "timed_out";
|
|
445
|
+
info.error = result.error ?? "Jev deadline exceeded";
|
|
446
|
+
} else if (controller.signal.aborted || result.terminationReason === "aborted") {
|
|
447
|
+
info.state = "cancelled";
|
|
448
|
+
} else if (result.terminationReason !== "completed") {
|
|
449
|
+
info.state = "failed";
|
|
450
|
+
info.error = result.error ?? "Jev program failed";
|
|
451
|
+
} else {
|
|
452
|
+
checkValue(definition.outputSchema, result.value, "Program output");
|
|
453
|
+
info.result = result.value;
|
|
454
|
+
info.state = "completed";
|
|
455
|
+
}
|
|
456
|
+
} catch (error) {
|
|
457
|
+
info.state = budgetFailure ? "failed" : timedOut ? "timed_out" : controller.signal.aborted ? "cancelled" : "failed";
|
|
458
|
+
info.error = (budgetFailure ?? (error instanceof Error ? error.message : "Jev program failed")).slice(0, 2e3);
|
|
459
|
+
} finally {
|
|
460
|
+
clearTimeout(timer);
|
|
461
|
+
context.signal?.removeEventListener("abort", abort);
|
|
462
|
+
await runLease.release();
|
|
463
|
+
info.endedAt = Date.now();
|
|
464
|
+
this.#prune();
|
|
465
|
+
}
|
|
466
|
+
return info;
|
|
467
|
+
})();
|
|
468
|
+
return background ? this.status(id) : structuredClone(await run.done);
|
|
469
|
+
} finally {
|
|
470
|
+
if (starting) this.#starting--;
|
|
471
|
+
await lease?.release();
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
#prune() {
|
|
475
|
+
for (const [id, run] of this.#runs) {
|
|
476
|
+
if (this.#runs.size <= this.options.config.jev.maxRetainedRuns) break;
|
|
477
|
+
if (run.info.state !== "running") this.#runs.delete(id);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
stopAll() {
|
|
481
|
+
for (const run of this.#runs.values()) if (run.info.state === "running") run.controller.abort(new Error("Jev provider closed"));
|
|
482
|
+
}
|
|
483
|
+
async close() {
|
|
484
|
+
this.#closed = true;
|
|
485
|
+
const running = [...this.#runs.values()].filter((r) => r.info.state === "running");
|
|
486
|
+
this.stopAll();
|
|
487
|
+
await Promise.all(running.map((r) => r.done));
|
|
488
|
+
this.#runs.clear();
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
// src/providers/jev-provider.ts
|
|
493
|
+
var description2 = Type.Union([Type.String(), Type.Array(Type.Unknown()), Type.Record(Type.String(), Type.Unknown())]);
|
|
494
|
+
var question = Type.Union([
|
|
495
|
+
Type.Object({ type: Type.Literal("noul"), instructions: description2, criteria: Type.Optional(Type.Object({ true: Type.Optional(description2), false: Type.Optional(description2) }, { additionalProperties: false })) }, { additionalProperties: false }),
|
|
496
|
+
Type.Object({ type: Type.Literal("choice"), instructions: description2, criteria: Type.Record(Type.String(), Type.Union([description2, Type.Null()]), { minProperties: 1, maxProperties: 255 }) }, { additionalProperties: false }),
|
|
497
|
+
Type.Object({ type: Type.Literal("score"), instructions: description2, criteria: Type.Array(description2, { minItems: 2, maxItems: 10 }) }, { additionalProperties: false })
|
|
498
|
+
]);
|
|
499
|
+
var jevRequestSchema = Type.Object({
|
|
500
|
+
state: description2,
|
|
501
|
+
questions: Type.Record(Type.String(), question, { minProperties: 1, maxProperties: 128 }),
|
|
502
|
+
model: Type.Optional(Type.String({ minLength: 1, maxLength: 128 }))
|
|
503
|
+
}, { additionalProperties: false });
|
|
504
|
+
var jevLaunchSchema = Type.Object({
|
|
505
|
+
program: Type.Object({
|
|
506
|
+
name: Type.String({ minLength: 1, maxLength: 128 }),
|
|
507
|
+
code: Type.String({ minLength: 1, maxLength: 65536 }),
|
|
508
|
+
inputSchema: Type.Record(Type.String(), Type.Unknown()),
|
|
509
|
+
outputSchema: Type.Record(Type.String(), Type.Unknown()),
|
|
510
|
+
requires: Type.Array(Type.String({ minLength: 3, maxLength: 256 }), { maxItems: 64, uniqueItems: true }),
|
|
511
|
+
limits: Type.Optional(Type.Object({
|
|
512
|
+
timeoutMs: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
513
|
+
maxEvaluations: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
514
|
+
maxToolCalls: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
515
|
+
maxTokens: Type.Optional(Type.Integer({ minimum: 1 }))
|
|
516
|
+
}, { additionalProperties: false }))
|
|
517
|
+
}, { additionalProperties: false }),
|
|
518
|
+
input: Type.Unknown()
|
|
519
|
+
}, { additionalProperties: false });
|
|
520
|
+
var idSchema = Type.Object({ id: Type.String({ minLength: 1, maxLength: 128 }) }, { additionalProperties: false });
|
|
521
|
+
var statusSchema = Type.Object({
|
|
522
|
+
id: Type.Optional(Type.String({ minLength: 1, maxLength: 128 })),
|
|
523
|
+
after: Type.Optional(Type.Integer({ minimum: 0 }))
|
|
524
|
+
}, { additionalProperties: false });
|
|
525
|
+
var JEV_ACTION_DESCRIPTORS = [
|
|
526
|
+
{ name: "evaluate", description: "Ask Jev typed Choice, Noul (probability of yes), and Score questions over shared state. No generated text. Batch independent questions. Sends state to TypeSafe and consumes API credits; no automatic retries.", inputSchema: jevRequestSchema, risk: "network", effect: { kind: "emission", resources: ["typesafe:inference"], ordering: "unknown" } },
|
|
527
|
+
{ name: "run", description: "Run an isolated TypeScript System One program in the foreground. Returns a terminal run envelope with schema-validated result or error. Globals: input, jev.evaluate, program.sleep(ms), program.emit(value), and Fabric tools restricted to exact requires. Loops are supported; no host imports or secrets.", inputSchema: jevLaunchSchema, risk: "execute" },
|
|
528
|
+
{ name: "spawn", description: "Launch the same Jev program in the background and return its run ID. Session-owned, not restart-durable. Poll status for bounded events or join for completion; stop cancels future actions, not past effects.", inputSchema: jevLaunchSchema, risk: "execute" },
|
|
529
|
+
{ name: "status", description: "Without id: credential configuration status (never retrieves secrets) and run summaries. With id: state, usage, bounded events after sequence, logs, result/error. Retains at most 64 events; nextSequence allows detecting gaps.", inputSchema: statusSchema, risk: "read" },
|
|
530
|
+
{ name: "wait", description: "Wait for a background Jev program's terminal run envelope. Cancelling the wait does not cancel the program.", inputSchema: idSchema, risk: "read" },
|
|
531
|
+
{ name: "join", description: "Alias for jev.wait: wait for a background Jev program's terminal run envelope without cancelling the program when the wait is cancelled.", inputSchema: idSchema, risk: "read" },
|
|
532
|
+
{ name: "stop", description: "Cancel a Jev program and await sandbox cleanup. Idempotent for retained terminal runs; already-issued external effects cannot be undone.", inputSchema: idSchema, risk: "execute" }
|
|
533
|
+
];
|
|
534
|
+
var JevProvider = class {
|
|
535
|
+
name = "jev";
|
|
536
|
+
description = "TypeSafe System One judgments and foreground/background reactive TypeScript programs";
|
|
537
|
+
manager;
|
|
538
|
+
client;
|
|
539
|
+
constructor(options, client) {
|
|
540
|
+
this.manager = new JevProgramManager(options);
|
|
541
|
+
this.client = client ?? new JevClient(options.config.jev, void 0, new JevCredentials(options.config.jev.credentialCommand, process.env, options.credentialSource));
|
|
542
|
+
}
|
|
543
|
+
async list(request) {
|
|
544
|
+
const query = request.query?.toLowerCase();
|
|
545
|
+
return JEV_ACTION_DESCRIPTORS.filter((d) => !query || `${d.name} ${d.description}`.toLowerCase().includes(query));
|
|
546
|
+
}
|
|
547
|
+
async describe(name) {
|
|
548
|
+
return JEV_ACTION_DESCRIPTORS.find((d) => d.name === name);
|
|
549
|
+
}
|
|
550
|
+
async invoke(name, args, context) {
|
|
551
|
+
const descriptor = await this.describe(name);
|
|
552
|
+
if (!descriptor) throw new Error(`Unknown Jev action: ${name}`);
|
|
553
|
+
const invalid = validationMessage(descriptor.inputSchema, args);
|
|
554
|
+
if (invalid) throw new Error(`Invalid jev.${name} arguments: ${invalid}`);
|
|
555
|
+
switch (name) {
|
|
556
|
+
case "evaluate":
|
|
557
|
+
return this.client.evaluate(args, context.signal ?? new AbortController().signal);
|
|
558
|
+
case "run":
|
|
559
|
+
return this.manager.launch(args, context, false);
|
|
560
|
+
case "spawn":
|
|
561
|
+
return this.manager.launch(args, context, true);
|
|
562
|
+
case "status":
|
|
563
|
+
return typeof args.id === "string" ? this.manager.status(args.id, args.after) : {
|
|
564
|
+
credentials: this.client.credentials.status(),
|
|
565
|
+
model: this.client.config.model,
|
|
566
|
+
runs: this.manager.list()
|
|
567
|
+
};
|
|
568
|
+
case "join":
|
|
569
|
+
case "wait":
|
|
570
|
+
return this.manager.wait(args.id, context.signal);
|
|
571
|
+
case "stop":
|
|
572
|
+
return this.manager.stop(args.id);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
async close() {
|
|
576
|
+
await this.manager.close();
|
|
577
|
+
this.client.close();
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
export {
|
|
582
|
+
JevCredentials,
|
|
583
|
+
JevClient,
|
|
584
|
+
JevProgramManager,
|
|
585
|
+
jevRequestSchema,
|
|
586
|
+
jevLaunchSchema,
|
|
587
|
+
JEV_ACTION_DESCRIPTORS,
|
|
588
|
+
JevProvider
|
|
589
|
+
};
|
|
590
|
+
//# sourceMappingURL=chunk-OX7BU3RX.js.map
|