@parcha/agentrun-dsl 0.1.0-beta.28 → 0.1.0-beta.281
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/NOTICE +2 -0
- package/README.md +22 -17
- package/dist/author-references.d.ts +2 -2
- package/dist/author-references.js +2 -2
- package/dist/author.d.ts +0 -2
- package/dist/author.js +12 -7
- package/dist/authoring.js +3 -2
- package/dist/cli.js +13 -12
- package/dist/code-exec.d.ts +19 -0
- package/dist/code-exec.js +54 -5
- package/dist/decision-provider.d.ts +166 -0
- package/dist/decision-provider.js +238 -0
- package/dist/decision-receipts.d.ts +60 -2
- package/dist/decision-receipts.js +13 -3
- package/dist/dry-run.d.ts +31 -1
- package/dist/dry-run.js +120 -14
- package/dist/edit.d.ts +158 -0
- package/dist/edit.js +1486 -0
- package/dist/evidence.d.ts +19 -0
- package/dist/evidence.js +63 -0
- package/dist/graph.d.ts +17 -0
- package/dist/graph.js +71 -6
- package/dist/index.d.ts +17 -12
- package/dist/index.js +16 -10
- package/dist/inspection.d.ts +5 -0
- package/dist/inspection.js +14 -1
- package/dist/pattern-screen.d.ts +14 -0
- package/dist/pattern-screen.js +451 -0
- package/dist/pointer-warning.d.ts +14 -0
- package/dist/pointer-warning.js +22 -0
- package/dist/predicates.d.ts +32 -2
- package/dist/predicates.js +66 -6
- package/dist/record.d.ts +4 -0
- package/dist/record.js +6 -0
- package/dist/recovery/binding.js +2 -1
- package/dist/recovery/call-key.d.ts +0 -4
- package/dist/recovery/call-key.js +0 -7
- package/dist/recovery/driver.d.ts +48 -20
- package/dist/recovery/driver.js +150 -41
- package/dist/recovery/frozen-snapshot.d.ts +30 -1
- package/dist/recovery/frozen-snapshot.js +26 -8
- package/dist/recovery/handoff-receipts.d.ts +0 -35
- package/dist/recovery/handoff-receipts.js +2 -44
- package/dist/recovery/index.d.ts +4 -8
- package/dist/recovery/index.js +4 -7
- package/dist/recovery/item-state.d.ts +2 -1
- package/dist/recovery/item-state.js +7 -13
- package/dist/recovery/with-recovery.d.ts +9 -3
- package/dist/recovery/with-recovery.js +72 -15
- package/dist/submit-envelope.d.ts +2 -1
- package/dist/submit-envelope.js +12 -5
- package/dist/system-one.d.ts +21 -2
- package/dist/system-one.js +96 -18
- package/dist/testing/decision-provider.d.ts +32 -0
- package/dist/testing/decision-provider.js +183 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.js +2 -0
- package/dist/vocabulary.d.ts +16 -3
- package/dist/vocabulary.js +22 -7
- package/dist/workflow-shape.js +4 -2
- package/dist/workflow.d.ts +131 -15
- package/dist/workflow.js +807 -233
- package/dist/zod-json-contract.js +6 -8
- package/package.json +12 -4
- package/schema/workflow.schema.json +346 -1
- package/skills/author/references/jev-decisions.md +50 -5
- package/skills/author/references/language.md +14 -9
- package/dist/recovery/effect-failure.d.ts +0 -34
- package/dist/recovery/effect-failure.js +0 -62
- package/dist/recovery/handoff-block.d.ts +0 -36
- package/dist/recovery/handoff-block.js +0 -148
- package/dist/recovery/handoff-digest.d.ts +0 -58
- package/dist/recovery/handoff-digest.js +0 -195
- package/dist/recovery/handoff-files.d.ts +0 -54
- package/dist/recovery/handoff-files.js +0 -162
- package/dist/recovery/handoff-redact.d.ts +0 -12
- package/dist/recovery/handoff-redact.js +0 -44
- package/dist/recovery/handoff.d.ts +0 -44
- package/dist/recovery/handoff.js +0 -46
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type DecisionEvidence, type DecisionProvider } from "../decision-provider.js";
|
|
2
|
+
/** What the kit's fake transport answers one call with. An `answer` carries answers in the DSL's shape (and, for a
|
|
3
|
+
* provider with evidence, sources), which the kit sends in the provider's own wire format. `lost` is a connection that
|
|
4
|
+
* drops after the request was sent: whether it was served is not known. */
|
|
5
|
+
export type KitReply = {
|
|
6
|
+
kind: "answer";
|
|
7
|
+
answers: Record<string, unknown>;
|
|
8
|
+
evidence?: DecisionEvidence[];
|
|
9
|
+
} | {
|
|
10
|
+
kind: "status";
|
|
11
|
+
status: number;
|
|
12
|
+
} | {
|
|
13
|
+
kind: "malformed";
|
|
14
|
+
} | {
|
|
15
|
+
kind: "lost";
|
|
16
|
+
} | {
|
|
17
|
+
kind: "hang";
|
|
18
|
+
};
|
|
19
|
+
export interface DecisionProviderKit {
|
|
20
|
+
/** A new provider under test whose transport answers each call with the next of `replies` (the last repeats), and
|
|
21
|
+
* the number of calls its transport has taken. Retry delays should be short: the suite waits for them. */
|
|
22
|
+
build(replies: KitReply[]): {
|
|
23
|
+
provider: DecisionProvider;
|
|
24
|
+
calls(): number;
|
|
25
|
+
};
|
|
26
|
+
/** The key the kit configures the provider with: it must never appear in a result or an error. */
|
|
27
|
+
canary: string;
|
|
28
|
+
/** Whether the provider's wire format can carry a refusal. */
|
|
29
|
+
refuses: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** Registers the suite as `node:test` tests named under `name`. */
|
|
32
|
+
export declare function registerDecisionProviderConformance(name: string, kit: DecisionProviderKit): void;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// The DecisionProvider conformance suite: what a provider must hold for a decision workflow to rest on it. A provider
|
|
2
|
+
// package registers it in its own tests with a kit that builds the provider over a fake transport.
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { test } from "node:test";
|
|
5
|
+
import { DecisionProviderError } from "../decision-provider.js";
|
|
6
|
+
import { completeConfidence, validateAnswers } from "../system-one.js";
|
|
7
|
+
const QUESTIONS = {
|
|
8
|
+
holds: { type: "noul", instructions: "Does the statement hold?" },
|
|
9
|
+
pick: { type: "choice", instructions: "Which option fits?", criteria: { first: "the first", second: "the second" } },
|
|
10
|
+
level: { type: "score", instructions: "How strong is it?", criteria: ["weak", "middling", "strong"] },
|
|
11
|
+
};
|
|
12
|
+
const ANSWERS = {
|
|
13
|
+
holds: { type: "noul", noul: 0.8 },
|
|
14
|
+
pick: { type: "choice", choice: "first", probabilities: { first: 0.75, second: 0.25 }, confidence: 0.5 },
|
|
15
|
+
level: { type: "score", score: 1.5, legend: { 0: "weak", 1: "middling", 2: "strong" }, probabilities: { 0: 0, 1: 0.5, 2: 0.5 }, confidence: 0.25 },
|
|
16
|
+
};
|
|
17
|
+
const EVIDENCE = [{ url: "https://example.org/a", title: "A source", excerpts: ["a passage"], scope: "call" }];
|
|
18
|
+
const BASES = ["reported", "estimate", "unknown"];
|
|
19
|
+
/** The smallest PNG: a 1x1 transparent pixel. */
|
|
20
|
+
const PNG = Uint8Array.from(Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=", "base64"));
|
|
21
|
+
/** Registers the suite as `node:test` tests named under `name`. */
|
|
22
|
+
export function registerDecisionProviderConformance(name, kit) {
|
|
23
|
+
const it = (title, body, options = {}) => test(`${name}: ${title}`, { skip: options.skip ?? false, timeout: 20_000 }, body);
|
|
24
|
+
/** The questions of each type the provider answers, with answers to them. */
|
|
25
|
+
const asked = (provider) => {
|
|
26
|
+
const ids = Object.keys(QUESTIONS).filter((id) => provider.capabilities.types.includes(QUESTIONS[id].type));
|
|
27
|
+
return { questions: Object.fromEntries(ids.map((id) => [id, QUESTIONS[id]])), answers: Object.fromEntries(ids.map((id) => [id, structuredClone(ANSWERS[id])])) };
|
|
28
|
+
};
|
|
29
|
+
const request = (questions, state = { case: "conformance" }) => ({ label: "conformance", kind: "judge", state, questions });
|
|
30
|
+
const ctx = (over = {}) => ({ decisionId: "conformance-decision", signal: over.signal ?? new AbortController().signal, deadlineMs: over.deadlineMs === undefined ? 5_000 : over.deadlineMs });
|
|
31
|
+
/** One decision on a provider whose transport gives `replies`. */
|
|
32
|
+
const decideOn = async (replies, questions, context = ctx()) => {
|
|
33
|
+
const { provider } = kit.build(replies);
|
|
34
|
+
return provider.decide(request(questions ?? asked(provider).questions), context);
|
|
35
|
+
};
|
|
36
|
+
const answerReply = (provider, extra = {}) => ({ kind: "answer", answers: asked(provider).answers, ...extra });
|
|
37
|
+
const probe = () => kit.build([{ kind: "hang" }]).provider;
|
|
38
|
+
/** `promise`, or a failure once `ms` pass: the referenced timer also keeps the process up while a request hangs. */
|
|
39
|
+
const within = (ms, promise) => {
|
|
40
|
+
let timer;
|
|
41
|
+
const late = new Promise((_, reject) => { timer = setTimeout(() => reject(new Error(`still pending after ${ms} ms`)), ms); });
|
|
42
|
+
return Promise.race([promise, late]).finally(() => clearTimeout(timer));
|
|
43
|
+
};
|
|
44
|
+
const failsWith = (expected) => (error) => {
|
|
45
|
+
assert.ok(error instanceof DecisionProviderError, `a provider fails with a DecisionProviderError, got ${String(error)}`);
|
|
46
|
+
assert.equal(error.code, expected);
|
|
47
|
+
return true;
|
|
48
|
+
};
|
|
49
|
+
it("it answers exactly the questions asked, each in its declared type", async () => {
|
|
50
|
+
const { questions } = asked(probe());
|
|
51
|
+
const outcome = await decideOn([answerReply(probe())]);
|
|
52
|
+
assert.deepEqual(Object.keys(outcome.answers).sort(), Object.keys(questions).sort());
|
|
53
|
+
const { answers } = completeConfidence(questions, outcome.answers);
|
|
54
|
+
validateAnswers(questions, answers);
|
|
55
|
+
});
|
|
56
|
+
it("an answer to a question not asked, or none for one asked, is invalid_response", async () => {
|
|
57
|
+
const { answers } = asked(probe());
|
|
58
|
+
await assert.rejects(decideOn([{ kind: "answer", answers: { ...answers, unasked: { type: "noul", noul: 0.5 } } }]), failsWith("invalid_response"));
|
|
59
|
+
const [first, ...rest] = Object.keys(answers);
|
|
60
|
+
assert.ok(first && rest.length, "the provider answers at least two of noul, choice and score");
|
|
61
|
+
await assert.rejects(decideOn([{ kind: "answer", answers: Object.fromEntries(rest.map((id) => [id, answers[id]])) }]), failsWith("invalid_response"));
|
|
62
|
+
});
|
|
63
|
+
it("a cost it does not know is null, never 0, and cost_basis says how it was reached", async () => {
|
|
64
|
+
const outcome = await decideOn([answerReply(probe())]);
|
|
65
|
+
assert.ok(BASES.includes(outcome.cost_basis), `cost_basis is one of ${BASES.join(", ")}, got ${String(outcome.cost_basis)}`);
|
|
66
|
+
assert.equal(outcome.cost_usd === null, outcome.cost_basis === "unknown", `an unknown cost is null and a known one is not: ${outcome.cost_usd} (${outcome.cost_basis})`);
|
|
67
|
+
if (outcome.cost_usd !== null)
|
|
68
|
+
assert.ok(Number.isFinite(outcome.cost_usd) && outcome.cost_usd >= 0);
|
|
69
|
+
if (outcome.usage !== null)
|
|
70
|
+
assert.ok(Number.isSafeInteger(outcome.usage.input_tokens) && Number.isSafeInteger(outcome.usage.output_tokens));
|
|
71
|
+
});
|
|
72
|
+
it("401 and 403 are auth errors", async () => {
|
|
73
|
+
await assert.rejects(decideOn([{ kind: "status", status: 401 }]), failsWith("auth"));
|
|
74
|
+
await assert.rejects(decideOn([{ kind: "status", status: 403 }]), failsWith("auth"));
|
|
75
|
+
});
|
|
76
|
+
it("422 is invalid_request", async () => {
|
|
77
|
+
await assert.rejects(decideOn([{ kind: "status", status: 422 }]), failsWith("invalid_request"));
|
|
78
|
+
});
|
|
79
|
+
it("429 is rate_limited once its retries are spent", async () => {
|
|
80
|
+
await assert.rejects(decideOn([{ kind: "status", status: 429 }]), failsWith("rate_limited"));
|
|
81
|
+
});
|
|
82
|
+
it("a 5xx is outcome_unknown for a provider that cannot replay, and an http error for one that dedupes", async () => {
|
|
83
|
+
const code = probe().capabilities.replay === "never" ? "outcome_unknown" : "http";
|
|
84
|
+
for (const status of [500, 503])
|
|
85
|
+
await assert.rejects(decideOn([{ kind: "status", status }]), failsWith(code));
|
|
86
|
+
});
|
|
87
|
+
it("a provider that cannot replay never retries a failure after the request was sent", async () => {
|
|
88
|
+
if (probe().capabilities.replay !== "never")
|
|
89
|
+
return;
|
|
90
|
+
for (const reply of [{ kind: "status", status: 500 }, { kind: "status", status: 503 }, { kind: "status", status: 408 }, { kind: "lost" }]) {
|
|
91
|
+
const { provider, calls } = kit.build([reply, answerReply(probe())]);
|
|
92
|
+
await assert.rejects(provider.decide(request(asked(provider).questions), ctx()), failsWith("outcome_unknown"));
|
|
93
|
+
assert.equal(calls(), 1, `${JSON.stringify(reply)} was sent ${calls()} times`);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
it("a malformed body is invalid_response", async () => {
|
|
97
|
+
await assert.rejects(decideOn([{ kind: "malformed" }]), failsWith("invalid_response"));
|
|
98
|
+
});
|
|
99
|
+
it("an abort stops a request in flight as aborted", async () => {
|
|
100
|
+
const controller = new AbortController();
|
|
101
|
+
setTimeout(() => controller.abort(), 20);
|
|
102
|
+
await assert.rejects(within(2_000, decideOn([{ kind: "hang" }], undefined, ctx({ signal: controller.signal, deadlineMs: 10_000 }))), failsWith("aborted"));
|
|
103
|
+
});
|
|
104
|
+
it("a request in flight past its deadline is outcome_unknown for a provider that cannot replay, and timeout for one that dedupes", async () => {
|
|
105
|
+
const code = probe().capabilities.replay === "never" ? "outcome_unknown" : "timeout";
|
|
106
|
+
await assert.rejects(within(3_000, decideOn([{ kind: "hang" }], undefined, ctx({ deadlineMs: 50 }))), failsWith(code));
|
|
107
|
+
});
|
|
108
|
+
it("no key appears in a result or an error", async () => {
|
|
109
|
+
const seen = [JSON.stringify(await decideOn([answerReply(probe(), { evidence: EVIDENCE })]))];
|
|
110
|
+
for (const reply of [{ kind: "status", status: 401 }, { kind: "status", status: 422 }, { kind: "status", status: 429 }, { kind: "status", status: 500 }, { kind: "malformed" }]) {
|
|
111
|
+
try {
|
|
112
|
+
await decideOn([reply]);
|
|
113
|
+
seen.push("no error");
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
seen.push(String(error), error?.stack ?? "", JSON.stringify(error));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (const text of seen)
|
|
120
|
+
assert.ok(!text.includes(kit.canary), "the key appears in what the provider returned or threw");
|
|
121
|
+
});
|
|
122
|
+
it("a request beyond its declared capabilities is refused before anything is sent", async () => {
|
|
123
|
+
const { provider, calls } = kit.build([answerReply(probe())]);
|
|
124
|
+
const { maxQuestions, maxStateBytes, types } = provider.capabilities;
|
|
125
|
+
const over = [];
|
|
126
|
+
if (maxQuestions !== null)
|
|
127
|
+
over.push(request(Object.fromEntries(Array.from({ length: maxQuestions + 1 }, (_, i) => [`q${i}`, { type: "noul", instructions: `Question ${i}?` }]))));
|
|
128
|
+
if (!types.includes("box"))
|
|
129
|
+
over.push(request({ spot: { type: "box", instructions: "Where is it?" } }));
|
|
130
|
+
if (maxStateBytes !== null)
|
|
131
|
+
over.push(request(asked(provider).questions, { text: "x".repeat(maxStateBytes + 1) }));
|
|
132
|
+
if (provider.capabilities.models)
|
|
133
|
+
over.push({ ...request(asked(provider).questions), model: "a-model-it-does-not-declare" });
|
|
134
|
+
for (const each of over)
|
|
135
|
+
await assert.rejects(provider.decide(each, ctx()), failsWith("invalid_request"));
|
|
136
|
+
assert.equal(calls(), 0, "nothing was sent");
|
|
137
|
+
});
|
|
138
|
+
it("a refusal comes back as a refusal", async () => {
|
|
139
|
+
const { answers } = asked(probe());
|
|
140
|
+
const outcome = await decideOn([{ kind: "answer", answers: { ...answers, holds: { type: "refusal" } } }]);
|
|
141
|
+
assert.deepEqual(outcome.answers.holds, { type: "refusal" });
|
|
142
|
+
}, { skip: kit.refuses ? false : "the provider's wire format carries no refusal" });
|
|
143
|
+
it("evidence is a list of sources, and the request id a string or null", async () => {
|
|
144
|
+
const provider = probe();
|
|
145
|
+
const outcome = await decideOn([answerReply(provider, { evidence: EVIDENCE })]);
|
|
146
|
+
assert.ok(Array.isArray(outcome.evidence), "evidence is a list");
|
|
147
|
+
for (const source of outcome.evidence) {
|
|
148
|
+
assert.equal(typeof source.url, "string");
|
|
149
|
+
assert.ok(source.title === null || typeof source.title === "string");
|
|
150
|
+
assert.ok(Array.isArray(source.excerpts) && source.excerpts.every((excerpt) => typeof excerpt === "string"));
|
|
151
|
+
assert.equal(typeof source.scope, "string");
|
|
152
|
+
}
|
|
153
|
+
if (provider.capabilities.evidence === "none")
|
|
154
|
+
assert.equal(outcome.evidence.length, 0, "a provider with no evidence returns none");
|
|
155
|
+
else
|
|
156
|
+
assert.ok(outcome.evidence.length > 0, "a provider with evidence returns the sources it was given");
|
|
157
|
+
assert.ok(outcome.provider_request_id === null || typeof outcome.provider_request_id === "string");
|
|
158
|
+
});
|
|
159
|
+
it("it declares only what the seam can send: noul, choice and score questions, from text, JSON, a URL or an image", async () => {
|
|
160
|
+
// A box question has no node that asks it, and the seam carries no PDF: a provider that declares either cannot be
|
|
161
|
+
// asked for it through judgeFromProvider.
|
|
162
|
+
const { capabilities } = probe();
|
|
163
|
+
for (const type of capabilities.types)
|
|
164
|
+
assert.ok(["noul", "choice", "score"].includes(type), `it declares ${type} questions, which the seam cannot send`);
|
|
165
|
+
for (const input of capabilities.inputs)
|
|
166
|
+
assert.ok(["text", "json", "url", "image"].includes(input), `it declares ${input} input, which the seam cannot carry`);
|
|
167
|
+
});
|
|
168
|
+
it("a provider that takes images answers a request that carries one, named in its state", async () => {
|
|
169
|
+
const { questions, answers } = asked(probe());
|
|
170
|
+
const { provider, calls } = kit.build([{ kind: "answer", answers }]);
|
|
171
|
+
const images = { "<page>": { bytes: PNG, mime: "image/png", ref: "pages/conformance/1.png" } };
|
|
172
|
+
const outcome = await provider.decide({ ...request(questions, { page: "<page>", note: "the page is <page>" }), images }, ctx());
|
|
173
|
+
assert.deepEqual(Object.keys(outcome.answers).sort(), Object.keys(questions).sort());
|
|
174
|
+
assert.equal(calls(), 1);
|
|
175
|
+
}, { skip: kit.build([{ kind: "hang" }]).provider.capabilities.inputs.includes("image") ? false : "the provider takes no image input" });
|
|
176
|
+
it("needs names environment variables, never their values", async () => {
|
|
177
|
+
const { needs } = probe();
|
|
178
|
+
for (const variable of needs) {
|
|
179
|
+
assert.match(variable, /^[A-Z][A-Z0-9_]*$/);
|
|
180
|
+
assert.ok(!variable.includes(kit.canary));
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { registerDecisionProviderConformance, type DecisionProviderKit, type KitReply } from "./decision-provider.js";
|
package/dist/vocabulary.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ export declare const WORKFLOW_NODE_KINDS: readonly ["chain", "code", "agent", "d
|
|
|
2
2
|
export type WorkflowNodeKind = typeof WORKFLOW_NODE_KINDS[number];
|
|
3
3
|
/** Generative kinds: one adapter session each, answering against a schema. */
|
|
4
4
|
export declare const GENERATIVE_NODE_KINDS: readonly ["agent", "decide", "extract", "report"];
|
|
5
|
+
/** What a decision node or an `ask` predicate may say about its provider: which one, a pinned model, the evidence it
|
|
6
|
+
* needs, its own time bound, and the images it sends (token -> image reference). */
|
|
7
|
+
export declare const DECISION_NODE_FIELDS: readonly ["provider", "model", "evidence", "timeoutMs", "images"];
|
|
8
|
+
/** The longest a decision node may give its provider, in milliseconds. A node only ever shortens its provider's own deadline. */
|
|
9
|
+
export declare const DECISION_TIMEOUT_MAX_MS = 120000;
|
|
5
10
|
/** Typed-question kinds: one judge request each, no tools and no session. */
|
|
6
11
|
export declare const JUDGMENT_NODE_KINDS: readonly ["judge", "pick", "sift", "route"];
|
|
7
12
|
/** The fields each node kind accepts. Any other key is an authoring error. */
|
|
@@ -15,15 +20,18 @@ export declare const HOST_NODE_FIELDS: readonly ["metadata"];
|
|
|
15
20
|
export declare const IGNORED_NODE_FIELDS: {
|
|
16
21
|
readonly [Kind in WorkflowNodeKind]?: readonly string[];
|
|
17
22
|
};
|
|
18
|
-
/** Predicates that read a state value. `poll` accepts only these. */
|
|
19
|
-
export declare const MECHANICAL_PREDICATES: readonly ["field_equals", "field_true", "in", "count_gte", "gte", "lt", "empty", "no_new_items"];
|
|
23
|
+
/** Predicates that read a state value. `poll` accepts only these, and `not` holds only one of these. */
|
|
24
|
+
export declare const MECHANICAL_PREDICATES: readonly ["field_equals", "field_true", "in", "count_gte", "gte", "lt", "empty", "no_new_items", "field_type", "quote_missing", "not"];
|
|
20
25
|
/** Every predicate `loop.until` and `escalate.when` accept: the mechanical set plus `ask`, a yes/no judge question. */
|
|
21
|
-
export declare const WORKFLOW_PREDICATES: readonly ["field_equals", "field_true", "in", "count_gte", "gte", "lt", "empty", "no_new_items", "ask"];
|
|
26
|
+
export declare const WORKFLOW_PREDICATES: readonly ["field_equals", "field_true", "in", "count_gte", "gte", "lt", "empty", "no_new_items", "field_type", "quote_missing", "not", "ask"];
|
|
22
27
|
export type WorkflowPredicateName = typeof WORKFLOW_PREDICATES[number];
|
|
23
28
|
/** The fields each predicate takes. */
|
|
24
29
|
export declare const PREDICATE_FIELDS: {
|
|
25
30
|
readonly [Name in WorkflowPredicateName]: readonly string[];
|
|
26
31
|
};
|
|
32
|
+
/** The JSON types `field_type` names. A number is a finite one: NaN and the infinities are no JSON value. */
|
|
33
|
+
export declare const FIELD_TYPES: readonly ["number", "string", "boolean", "array", "object", "null"];
|
|
34
|
+
export type FieldType = typeof FIELD_TYPES[number];
|
|
27
35
|
export declare const EFFORT_LEVELS: readonly ["minimal", "low", "medium", "high"];
|
|
28
36
|
/** There is no "off": every generative node thinks. */
|
|
29
37
|
export declare const THINKING_LEVELS: readonly ["low", "medium", "high"];
|
|
@@ -40,3 +48,8 @@ export declare const CALL_RETRY_CLASSES: readonly ["timeout", "http_5xx", "http_
|
|
|
40
48
|
export declare const EFFECT_FAILURE_CODES: readonly ["effect_timeout", "effect_exit", "effect_transport", "effect_not_granted", "effect_produces_missing", "effect_path_escape", "effect_code_unsafe", "output_invalid", "state_invalid", "effect_unknown_transport"];
|
|
41
49
|
/** Artifact types the engine itself treats as prose (the report writer). Every other type names a file. */
|
|
42
50
|
export declare const PROSE_ARTIFACT_TYPES: readonly ["markdown", "report"];
|
|
51
|
+
/** Whether `name` is one an object's prototype has (`constructor`, `toString`, `__proto__` and the rest of
|
|
52
|
+
* `Object.prototype`'s own names), or `prototype`. As a label, an `as`, a `failedAs` or a route branch, a read of one that
|
|
53
|
+
* nothing wrote would find the prototype's value: the editor refuses to write such a name (edit.ts), and the validator
|
|
54
|
+
* refuses a document that has one (workflow.ts). */
|
|
55
|
+
export declare const isPrototypeName: (name: string) => boolean;
|
package/dist/vocabulary.js
CHANGED
|
@@ -6,6 +6,11 @@ export const WORKFLOW_NODE_KINDS = [
|
|
|
6
6
|
];
|
|
7
7
|
/** Generative kinds: one adapter session each, answering against a schema. */
|
|
8
8
|
export const GENERATIVE_NODE_KINDS = ["agent", "decide", "extract", "report"];
|
|
9
|
+
/** What a decision node or an `ask` predicate may say about its provider: which one, a pinned model, the evidence it
|
|
10
|
+
* needs, its own time bound, and the images it sends (token -> image reference). */
|
|
11
|
+
export const DECISION_NODE_FIELDS = ["provider", "model", "evidence", "timeoutMs", "images"];
|
|
12
|
+
/** The longest a decision node may give its provider, in milliseconds. A node only ever shortens its provider's own deadline. */
|
|
13
|
+
export const DECISION_TIMEOUT_MAX_MS = 120_000;
|
|
9
14
|
/** Typed-question kinds: one judge request each, no tools and no session. */
|
|
10
15
|
export const JUDGMENT_NODE_KINDS = ["judge", "pick", "sift", "route"];
|
|
11
16
|
const GENERATIVE_FIELDS = ["node", "label", "state", "instructions", "sopSection", "out", "as", "requires", "tools", "effort", "thinking", "verify", "tier"];
|
|
@@ -24,10 +29,10 @@ export const NODE_FIELDS = {
|
|
|
24
29
|
escalate: ["node", "label", "when", "kind", "stage", "summary"],
|
|
25
30
|
call: ["node", "label", "via", "tool", "args", "code", "input", "command", "env", "where", "out", "as", "produces", "deadline_s", "retry", "poll", "requires"],
|
|
26
31
|
workflow: ["node", "label", "workflow", "input", "out", "as"],
|
|
27
|
-
judge: ["node", "label", "state", "out", "as", "requires"],
|
|
28
|
-
pick: ["node", "label", "itemsPath", "describe", "instructions", "state", "allowNone", "as", "requires"],
|
|
29
|
-
sift: ["node", "label", "itemsPath", "describe", "state", "out", "as", "keep", "requires"],
|
|
30
|
-
route: ["node", "label", "state", "instructions", "branches", "unsure", "valuePath", "otherwise", "as", "requires"],
|
|
32
|
+
judge: ["node", "label", "state", "out", "as", "requires", ...DECISION_NODE_FIELDS],
|
|
33
|
+
pick: ["node", "label", "itemsPath", "describe", "instructions", "state", "allowNone", "as", "requires", ...DECISION_NODE_FIELDS],
|
|
34
|
+
sift: ["node", "label", "itemsPath", "describe", "state", "out", "as", "keep", "requires", ...DECISION_NODE_FIELDS],
|
|
35
|
+
route: ["node", "label", "state", "instructions", "branches", "unsure", "valuePath", "otherwise", "as", "requires", ...DECISION_NODE_FIELDS],
|
|
31
36
|
};
|
|
32
37
|
/** Fields every node kind accepts in addition to its own. `metadata` is the host's: an optional object of
|
|
33
38
|
* host markers the engine admits, carries and hashes with the document, and never reads. */
|
|
@@ -37,8 +42,8 @@ export const IGNORED_NODE_FIELDS = {
|
|
|
37
42
|
agent: ["budget"],
|
|
38
43
|
decide: ["samples", "voteField"],
|
|
39
44
|
};
|
|
40
|
-
/** Predicates that read a state value. `poll` accepts only these. */
|
|
41
|
-
export const MECHANICAL_PREDICATES = ["field_equals", "field_true", "in", "count_gte", "gte", "lt", "empty", "no_new_items"];
|
|
45
|
+
/** Predicates that read a state value. `poll` accepts only these, and `not` holds only one of these. */
|
|
46
|
+
export const MECHANICAL_PREDICATES = ["field_equals", "field_true", "in", "count_gte", "gte", "lt", "empty", "no_new_items", "field_type", "quote_missing", "not"];
|
|
42
47
|
/** Every predicate `loop.until` and `escalate.when` accept: the mechanical set plus `ask`, a yes/no judge question. */
|
|
43
48
|
export const WORKFLOW_PREDICATES = [...MECHANICAL_PREDICATES, "ask"];
|
|
44
49
|
/** The fields each predicate takes. */
|
|
@@ -51,8 +56,13 @@ export const PREDICATE_FIELDS = {
|
|
|
51
56
|
lt: ["path", "n"],
|
|
52
57
|
empty: ["path"],
|
|
53
58
|
no_new_items: ["key"],
|
|
54
|
-
|
|
59
|
+
field_type: ["path", "type"],
|
|
60
|
+
quote_missing: ["path", "field", "pages"],
|
|
61
|
+
not: ["of"],
|
|
62
|
+
ask: ["instructions", "state", "criteria", "gte", ...DECISION_NODE_FIELDS],
|
|
55
63
|
};
|
|
64
|
+
/** The JSON types `field_type` names. A number is a finite one: NaN and the infinities are no JSON value. */
|
|
65
|
+
export const FIELD_TYPES = ["number", "string", "boolean", "array", "object", "null"];
|
|
56
66
|
export const EFFORT_LEVELS = ["minimal", "low", "medium", "high"];
|
|
57
67
|
/** There is no "off": every generative node thinks. */
|
|
58
68
|
export const THINKING_LEVELS = ["low", "medium", "high"];
|
|
@@ -72,3 +82,8 @@ export const EFFECT_FAILURE_CODES = [
|
|
|
72
82
|
];
|
|
73
83
|
/** Artifact types the engine itself treats as prose (the report writer). Every other type names a file. */
|
|
74
84
|
export const PROSE_ARTIFACT_TYPES = ["markdown", "report"];
|
|
85
|
+
/** Whether `name` is one an object's prototype has (`constructor`, `toString`, `__proto__` and the rest of
|
|
86
|
+
* `Object.prototype`'s own names), or `prototype`. As a label, an `as`, a `failedAs` or a route branch, a read of one that
|
|
87
|
+
* nothing wrote would find the prototype's value: the editor refuses to write such a name (edit.ts), and the validator
|
|
88
|
+
* refuses a document that has one (workflow.ts). */
|
|
89
|
+
export const isPrototypeName = (name) => name === "prototype" || Object.hasOwn(Object.prototype, name);
|
package/dist/workflow-shape.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { Compile } from "typebox/compile";
|
|
3
|
-
|
|
3
|
+
import { isRecord } from "./record.js";
|
|
4
|
+
// A named require lets deployment tracers retain the schema beside this package.
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
const documentSchema = require("../schema/workflow.schema.json");
|
|
4
7
|
const fullValidator = Compile(documentSchema);
|
|
5
|
-
const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
6
8
|
// Diagnostics only: the full validator below remains the acceptance authority.
|
|
7
9
|
// Its union errors can fill the entire error limit with unrelated node kinds.
|
|
8
10
|
// Select the declared discriminator's schema, checking nested nodes separately so
|