@full-self-browsing/lattice 1.4.0 → 1.5.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/dist/agent-run-C6miAzwI.d.ts +45 -0
- package/dist/agent-run-C6miAzwI.d.ts.map +1 -0
- package/dist/agent-run-CgPVFl0Z.js +47 -0
- package/dist/agent-run-CgPVFl0Z.js.map +1 -0
- package/dist/agents.d.ts +5 -0
- package/dist/agents.js +6 -0
- package/dist/artifact-Bg6mJGnm.d.ts +125 -0
- package/dist/artifact-Bg6mJGnm.d.ts.map +1 -0
- package/dist/artifact-DOfpeXLb.js +140 -0
- package/dist/artifact-DOfpeXLb.js.map +1 -0
- package/dist/artifacts.d.ts +2 -0
- package/dist/artifacts.js +2 -0
- package/dist/audit.d.ts +3 -0
- package/dist/audit.js +4 -0
- package/dist/catalog-CAfYwB_-.js +91 -0
- package/dist/catalog-CAfYwB_-.js.map +1 -0
- package/dist/context-pack-Bz3GXmjv.js +99 -0
- package/dist/context-pack-Bz3GXmjv.js.map +1 -0
- package/dist/context.d.ts +2 -0
- package/dist/context.js +2 -0
- package/dist/contract-S3oJGlc9.d.ts +74 -0
- package/dist/contract-S3oJGlc9.d.ts.map +1 -0
- package/dist/core.d.ts +48 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +95 -0
- package/dist/core.js.map +1 -0
- package/dist/errors-eEuEIx6X.js +407 -0
- package/dist/errors-eEuEIx6X.js.map +1 -0
- package/dist/eval.d.ts +2 -0
- package/dist/eval.js +2 -0
- package/dist/fingerprint-DodDbQKN.js +34 -0
- package/dist/fingerprint-DodDbQKN.js.map +1 -0
- package/dist/index-DpnHGHVL.d.ts +53 -0
- package/dist/index-DpnHGHVL.d.ts.map +1 -0
- package/dist/index.d.ts +90 -3533
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -15968
- package/dist/index.js.map +1 -1
- package/dist/infer-DLqp5QIM.d.ts +96 -0
- package/dist/infer-DLqp5QIM.d.ts.map +1 -0
- package/dist/lineage-DBgoPWAZ.js +137 -0
- package/dist/lineage-DBgoPWAZ.js.map +1 -0
- package/dist/local-CXOGPJ1f.js +139 -0
- package/dist/local-CXOGPJ1f.js.map +1 -0
- package/dist/local-Dy--7peL.d.ts +10 -0
- package/dist/local-Dy--7peL.d.ts.map +1 -0
- package/dist/memory-CkQEW6m5.js +62 -0
- package/dist/memory-CkQEW6m5.js.map +1 -0
- package/dist/memory-DRig5EHV.d.ts +10 -0
- package/dist/memory-DRig5EHV.d.ts.map +1 -0
- package/dist/negotiate-ClD88hkc.js +10967 -0
- package/dist/negotiate-ClD88hkc.js.map +1 -0
- package/dist/otel-BgM4e55_.d.ts +421 -0
- package/dist/otel-BgM4e55_.d.ts.map +1 -0
- package/dist/permission-context-CUKMo79F.js +134 -0
- package/dist/permission-context-CUKMo79F.js.map +1 -0
- package/dist/plan-DFm8Llep.js +125 -0
- package/dist/plan-DFm8Llep.js.map +1 -0
- package/dist/preflight-DNHWuJ46.d.ts +64 -0
- package/dist/preflight-DNHWuJ46.d.ts.map +1 -0
- package/dist/provider-C2IfKsvz.d.ts +1178 -0
- package/dist/provider-C2IfKsvz.d.ts.map +1 -0
- package/dist/providers.d.ts +4 -0
- package/dist/providers.js +4 -0
- package/dist/rate-limit-group-nDsBJqSu.d.ts +235 -0
- package/dist/rate-limit-group-nDsBJqSu.d.ts.map +1 -0
- package/dist/receipt-FYouoPHv.js +205 -0
- package/dist/receipt-FYouoPHv.js.map +1 -0
- package/dist/replay-CtIhpLek.js +964 -0
- package/dist/replay-CtIhpLek.js.map +1 -0
- package/dist/result-DLEx2WvU.d.ts +38 -0
- package/dist/result-DLEx2WvU.d.ts.map +1 -0
- package/dist/router-DU4Z3pTd.js +314 -0
- package/dist/router-DU4Z3pTd.js.map +1 -0
- package/dist/router-Yo1-aDOv.d.ts +42 -0
- package/dist/router-Yo1-aDOv.d.ts.map +1 -0
- package/dist/routing.d.ts +6 -0
- package/dist/routing.js +4 -0
- package/dist/{run-crew-CKdBjh5P.js → run-crew-B2fQLmgB.js} +7 -136
- package/dist/run-crew-B2fQLmgB.js.map +1 -0
- package/dist/run-crew-Bnve5dyI.d.ts +721 -0
- package/dist/run-crew-Bnve5dyI.d.ts.map +1 -0
- package/dist/{runtime-D25ehzCj.js → runtime-Dxiet5YS.js} +98 -641
- package/dist/runtime-Dxiet5YS.js.map +1 -0
- package/dist/scaffolds-DKQrCRqh.d.ts +535 -0
- package/dist/scaffolds-DKQrCRqh.d.ts.map +1 -0
- package/dist/scaffolds-ekPIlBeU.js +3139 -0
- package/dist/scaffolds-ekPIlBeU.js.map +1 -0
- package/dist/schema-CNfa_VEy.d.ts +15 -0
- package/dist/schema-CNfa_VEy.d.ts.map +1 -0
- package/dist/storage-DJKmsaEI.d.ts +26 -0
- package/dist/storage-DJKmsaEI.d.ts.map +1 -0
- package/dist/storage.d.ts +10 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +4 -0
- package/dist/tool-call-validation-BFoXkwbf.js +107 -0
- package/dist/tool-call-validation-BFoXkwbf.js.map +1 -0
- package/dist/tools-C4wHgGKQ.js +49 -0
- package/dist/tools-C4wHgGKQ.js.map +1 -0
- package/dist/tools.d.ts +46 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +106 -0
- package/dist/tools.js.map +1 -0
- package/dist/validate-c7EL5uuH.js +224 -0
- package/dist/validate-c7EL5uuH.js.map +1 -0
- package/package.json +99 -2
- package/dist/run-crew-CKdBjh5P.js.map +0 -1
- package/dist/runtime-D25ehzCj.js.map +0 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { r as toArtifactRef } from "./artifact-DOfpeXLb.js";
|
|
2
|
+
//#region src/context/context-pack.ts
|
|
3
|
+
function buildContextPack(input) {
|
|
4
|
+
const routeBudget = input.route?.estimates.inputTokens ?? input.route?.inputModalities.length ?? 0;
|
|
5
|
+
const tokenBudget = input.tokenBudget ?? Math.max(512, Math.min(input.route?.estimates.inputTokens ?? 4e3, 16e3));
|
|
6
|
+
const remainingBudget = Math.max(512, tokenBudget - estimateTokens(input.task) - routeBudget);
|
|
7
|
+
const included = [];
|
|
8
|
+
const summarized = [];
|
|
9
|
+
const archived = [];
|
|
10
|
+
const omitted = [];
|
|
11
|
+
const warnings = [];
|
|
12
|
+
let usedTokens = 0;
|
|
13
|
+
for (const artifact of input.artifacts) {
|
|
14
|
+
const artifactTokens = estimateArtifactTokens(artifact);
|
|
15
|
+
const item = {
|
|
16
|
+
artifactId: artifact.id,
|
|
17
|
+
reason: "Run artifact included for provider consideration.",
|
|
18
|
+
estimatedTokens: artifactTokens,
|
|
19
|
+
trust: trustForArtifact(artifact)
|
|
20
|
+
};
|
|
21
|
+
if (usedTokens + artifactTokens <= remainingBudget) {
|
|
22
|
+
included.push(item);
|
|
23
|
+
usedTokens += artifactTokens;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (artifact.kind === "text" || artifact.kind === "document" || artifact.kind === "json") {
|
|
27
|
+
summarized.push({
|
|
28
|
+
...item,
|
|
29
|
+
reason: "Artifact exceeded live context budget and needs summary packaging."
|
|
30
|
+
});
|
|
31
|
+
usedTokens += Math.min(artifactTokens, 256);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
omitted.push({
|
|
35
|
+
...item,
|
|
36
|
+
reason: "Artifact exceeded context budget and cannot be summarized by the default packer."
|
|
37
|
+
});
|
|
38
|
+
warnings.push(`Artifact ${artifact.id} omitted from live context budget.`);
|
|
39
|
+
}
|
|
40
|
+
for (const turn of input.session?.turns ?? []) {
|
|
41
|
+
const turnTokens = estimateTokens(turn.task);
|
|
42
|
+
const item = {
|
|
43
|
+
sessionTurnId: turn.id,
|
|
44
|
+
reason: "Prior session turn retained for continuity.",
|
|
45
|
+
estimatedTokens: turnTokens,
|
|
46
|
+
trust: "user"
|
|
47
|
+
};
|
|
48
|
+
if (usedTokens + turnTokens <= remainingBudget) {
|
|
49
|
+
included.push(item);
|
|
50
|
+
usedTokens += turnTokens;
|
|
51
|
+
} else archived.push({
|
|
52
|
+
...item,
|
|
53
|
+
reason: "Prior session turn archived because the run budget was exhausted."
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
id: createContextPackId(),
|
|
58
|
+
kind: "context-pack",
|
|
59
|
+
tokenBudget,
|
|
60
|
+
estimatedTokens: usedTokens,
|
|
61
|
+
included,
|
|
62
|
+
summarized,
|
|
63
|
+
archived,
|
|
64
|
+
omitted,
|
|
65
|
+
warnings
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function estimateArtifactTokens(artifact) {
|
|
69
|
+
if (artifact.size?.characters !== void 0) return estimateTokensFromCharacters(artifact.size.characters);
|
|
70
|
+
if (artifact.size?.bytes !== void 0) return estimateTokensFromCharacters(Math.ceil(artifact.size.bytes / 2));
|
|
71
|
+
if ("value" in artifact && typeof artifact.value === "string") return estimateTokens(artifact.value);
|
|
72
|
+
if ("value" in artifact && artifact.value !== void 0) {
|
|
73
|
+
const serialized = JSON.stringify(artifact.value);
|
|
74
|
+
return serialized === void 0 ? 64 : estimateTokens(serialized);
|
|
75
|
+
}
|
|
76
|
+
return 64;
|
|
77
|
+
}
|
|
78
|
+
function estimateTokens(value) {
|
|
79
|
+
return Math.max(1, estimateTokensFromCharacters(value.length));
|
|
80
|
+
}
|
|
81
|
+
function toContextArtifactRefs(artifacts) {
|
|
82
|
+
return artifacts.map(toArtifactRef);
|
|
83
|
+
}
|
|
84
|
+
function estimateTokensFromCharacters(characters) {
|
|
85
|
+
return Math.ceil(characters / 4);
|
|
86
|
+
}
|
|
87
|
+
function trustForArtifact(artifact) {
|
|
88
|
+
if (artifact.source === "tool") return "tool";
|
|
89
|
+
if (artifact.source === "generated") return "model-summary";
|
|
90
|
+
return "user";
|
|
91
|
+
}
|
|
92
|
+
function createContextPackId() {
|
|
93
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return `context-pack:${crypto.randomUUID()}`;
|
|
94
|
+
return `context-pack:${Date.now()}:${Math.random().toString(16).slice(2)}`;
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
export { toContextArtifactRefs as i, estimateArtifactTokens as n, estimateTokens as r, buildContextPack as t };
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=context-pack-Bz3GXmjv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-pack-Bz3GXmjv.js","names":[],"sources":["../src/context/context-pack.ts"],"sourcesContent":["import type { ArtifactInput, ArtifactRef } from \"../artifacts/artifact.js\";\nimport { toArtifactRef } from \"../artifacts/artifact.js\";\nimport type {\n ContextPackItemPlan,\n ContextPackPlan,\n SelectedRoute,\n} from \"../plan/plan.js\";\nimport type { SessionRecord } from \"../sessions/session.js\";\n\nexport type TrustLabel = \"developer\" | \"user\" | \"tool\" | \"model-summary\";\n\nexport interface ContextPack extends ContextPackPlan {\n readonly kind: \"context-pack\";\n}\n\nexport interface BuildContextPackInput {\n readonly task: string;\n readonly artifacts: readonly ArtifactInput[];\n readonly route?: SelectedRoute;\n readonly session?: SessionRecord;\n readonly tokenBudget?: number;\n}\n\nexport interface ContextSummarizer {\n summarize(input: {\n readonly artifacts: readonly ArtifactRef[];\n readonly budgetTokens: number;\n }): Promise<readonly ArtifactRef[]> | readonly ArtifactRef[];\n}\n\nexport function buildContextPack(input: BuildContextPackInput): ContextPack {\n const routeBudget =\n input.route?.estimates.inputTokens ?? input.route?.inputModalities.length ?? 0;\n const tokenBudget =\n input.tokenBudget ?? Math.max(512, Math.min(input.route?.estimates.inputTokens ?? 4_000, 16_000));\n const remainingBudget = Math.max(512, tokenBudget - estimateTokens(input.task) - routeBudget);\n const included: ContextPackItemPlan[] = [];\n const summarized: ContextPackItemPlan[] = [];\n const archived: ContextPackItemPlan[] = [];\n const omitted: ContextPackItemPlan[] = [];\n const warnings: string[] = [];\n let usedTokens = 0;\n\n for (const artifact of input.artifacts) {\n const artifactTokens = estimateArtifactTokens(artifact);\n const item: ContextPackItemPlan = {\n artifactId: artifact.id,\n reason: \"Run artifact included for provider consideration.\",\n estimatedTokens: artifactTokens,\n trust: trustForArtifact(artifact),\n };\n\n if (usedTokens + artifactTokens <= remainingBudget) {\n included.push(item);\n usedTokens += artifactTokens;\n continue;\n }\n\n if (artifact.kind === \"text\" || artifact.kind === \"document\" || artifact.kind === \"json\") {\n summarized.push({\n ...item,\n reason: \"Artifact exceeded live context budget and needs summary packaging.\",\n });\n usedTokens += Math.min(artifactTokens, 256);\n continue;\n }\n\n omitted.push({\n ...item,\n reason: \"Artifact exceeded context budget and cannot be summarized by the default packer.\",\n });\n warnings.push(`Artifact ${artifact.id} omitted from live context budget.`);\n }\n\n for (const turn of input.session?.turns ?? []) {\n const turnTokens = estimateTokens(turn.task);\n const item: ContextPackItemPlan = {\n sessionTurnId: turn.id,\n reason: \"Prior session turn retained for continuity.\",\n estimatedTokens: turnTokens,\n trust: \"user\",\n };\n\n if (usedTokens + turnTokens <= remainingBudget) {\n included.push(item);\n usedTokens += turnTokens;\n } else {\n archived.push({\n ...item,\n reason: \"Prior session turn archived because the run budget was exhausted.\",\n });\n }\n }\n\n return {\n id: createContextPackId(),\n kind: \"context-pack\",\n tokenBudget,\n estimatedTokens: usedTokens,\n included,\n summarized,\n archived,\n omitted,\n warnings,\n };\n}\n\nexport function estimateArtifactTokens(artifact: ArtifactInput | ArtifactRef): number {\n if (artifact.size?.characters !== undefined) {\n return estimateTokensFromCharacters(artifact.size.characters);\n }\n\n if (artifact.size?.bytes !== undefined) {\n return estimateTokensFromCharacters(Math.ceil(artifact.size.bytes / 2));\n }\n\n if (\"value\" in artifact && typeof artifact.value === \"string\") {\n return estimateTokens(artifact.value);\n }\n\n if (\"value\" in artifact && artifact.value !== undefined) {\n const serialized = JSON.stringify(artifact.value);\n\n return serialized === undefined ? 64 : estimateTokens(serialized);\n }\n\n return 64;\n}\n\nexport function estimateTokens(value: string): number {\n return Math.max(1, estimateTokensFromCharacters(value.length));\n}\n\nexport function toContextArtifactRefs(\n artifacts: readonly ArtifactInput[],\n): readonly ArtifactRef[] {\n return artifacts.map(toArtifactRef);\n}\n\nfunction estimateTokensFromCharacters(characters: number): number {\n return Math.ceil(characters / 4);\n}\n\nfunction trustForArtifact(artifact: ArtifactRef): TrustLabel {\n if (artifact.source === \"tool\") {\n return \"tool\";\n }\n\n if (artifact.source === \"generated\") {\n return \"model-summary\";\n }\n\n return \"user\";\n}\n\nfunction createContextPackId(): string {\n if (typeof crypto !== \"undefined\" && typeof crypto.randomUUID === \"function\") {\n return `context-pack:${crypto.randomUUID()}`;\n }\n\n return `context-pack:${Date.now()}:${Math.random().toString(16).slice(2)}`;\n}\n"],"mappings":";;AA8BA,SAAgB,iBAAiB,OAA2C;CAC1E,MAAM,cACJ,MAAM,OAAO,UAAU,eAAe,MAAM,OAAO,gBAAgB,UAAU;CAC/E,MAAM,cACJ,MAAM,eAAe,KAAK,IAAI,KAAK,KAAK,IAAI,MAAM,OAAO,UAAU,eAAe,KAAO,KAAO,CAAC;CACnG,MAAM,kBAAkB,KAAK,IAAI,KAAK,cAAc,eAAe,MAAM,KAAK,GAAG,YAAY;CAC7F,MAAM,WAAkC,EAAE;CAC1C,MAAM,aAAoC,EAAE;CAC5C,MAAM,WAAkC,EAAE;CAC1C,MAAM,UAAiC,EAAE;CACzC,MAAM,WAAqB,EAAE;CAC7B,IAAI,aAAa;AAEjB,MAAK,MAAM,YAAY,MAAM,WAAW;EACtC,MAAM,iBAAiB,uBAAuB,SAAS;EACvD,MAAM,OAA4B;GAChC,YAAY,SAAS;GACrB,QAAQ;GACR,iBAAiB;GACjB,OAAO,iBAAiB,SAAS;GAClC;AAED,MAAI,aAAa,kBAAkB,iBAAiB;AAClD,YAAS,KAAK,KAAK;AACnB,iBAAc;AACd;;AAGF,MAAI,SAAS,SAAS,UAAU,SAAS,SAAS,cAAc,SAAS,SAAS,QAAQ;AACxF,cAAW,KAAK;IACd,GAAG;IACH,QAAQ;IACT,CAAC;AACF,iBAAc,KAAK,IAAI,gBAAgB,IAAI;AAC3C;;AAGF,UAAQ,KAAK;GACX,GAAG;GACH,QAAQ;GACT,CAAC;AACF,WAAS,KAAK,YAAY,SAAS,GAAG,oCAAoC;;AAG5E,MAAK,MAAM,QAAQ,MAAM,SAAS,SAAS,EAAE,EAAE;EAC7C,MAAM,aAAa,eAAe,KAAK,KAAK;EAC5C,MAAM,OAA4B;GAChC,eAAe,KAAK;GACpB,QAAQ;GACR,iBAAiB;GACjB,OAAO;GACR;AAED,MAAI,aAAa,cAAc,iBAAiB;AAC9C,YAAS,KAAK,KAAK;AACnB,iBAAc;QAEd,UAAS,KAAK;GACZ,GAAG;GACH,QAAQ;GACT,CAAC;;AAIN,QAAO;EACL,IAAI,qBAAqB;EACzB,MAAM;EACN;EACA,iBAAiB;EACjB;EACA;EACA;EACA;EACA;EACD;;AAGH,SAAgB,uBAAuB,UAA+C;AACpF,KAAI,SAAS,MAAM,eAAe,KAAA,EAChC,QAAO,6BAA6B,SAAS,KAAK,WAAW;AAG/D,KAAI,SAAS,MAAM,UAAU,KAAA,EAC3B,QAAO,6BAA6B,KAAK,KAAK,SAAS,KAAK,QAAQ,EAAE,CAAC;AAGzE,KAAI,WAAW,YAAY,OAAO,SAAS,UAAU,SACnD,QAAO,eAAe,SAAS,MAAM;AAGvC,KAAI,WAAW,YAAY,SAAS,UAAU,KAAA,GAAW;EACvD,MAAM,aAAa,KAAK,UAAU,SAAS,MAAM;AAEjD,SAAO,eAAe,KAAA,IAAY,KAAK,eAAe,WAAW;;AAGnE,QAAO;;AAGT,SAAgB,eAAe,OAAuB;AACpD,QAAO,KAAK,IAAI,GAAG,6BAA6B,MAAM,OAAO,CAAC;;AAGhE,SAAgB,sBACd,WACwB;AACxB,QAAO,UAAU,IAAI,cAAc;;AAGrC,SAAS,6BAA6B,YAA4B;AAChE,QAAO,KAAK,KAAK,aAAa,EAAE;;AAGlC,SAAS,iBAAiB,UAAmC;AAC3D,KAAI,SAAS,WAAW,OACtB,QAAO;AAGT,KAAI,SAAS,WAAW,YACtB,QAAO;AAGT,QAAO;;AAGT,SAAS,sBAA8B;AACrC,KAAI,OAAO,WAAW,eAAe,OAAO,OAAO,eAAe,WAChE,QAAO,gBAAgB,OAAO,YAAY;AAG5C,QAAO,gBAAgB,KAAK,KAAK,CAAC,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Bt as ContextSummarizer, Gt as toContextArtifactRefs, Ht as buildContextPack, Rt as BuildContextPackInput, Ut as estimateArtifactTokens, Vt as TrustLabel, Wt as estimateTokens, Xt as ContextPackItemPlan, Zt as ContextPackPlan, zt as ContextPack } from "./provider-C2IfKsvz.js";
|
|
2
|
+
export { type BuildContextPackInput, type ContextPack, type ContextPackItemPlan, type ContextPackPlan, type ContextSummarizer, type TrustLabel, buildContextPack, estimateArtifactTokens, estimateTokens, toContextArtifactRefs };
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Mt as InvariantDeclaration, t as CapabilityModality } from "./provider-C2IfKsvz.js";
|
|
2
|
+
|
|
3
|
+
//#region src/contract/contract.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Budget invariant declaration attached to a CapabilityContract.
|
|
6
|
+
*
|
|
7
|
+
* Phase 7 implements `maxCostUsd` enforcement at pre-flight. The
|
|
8
|
+
* `p95LatencyMs` field is declared per CONTRACT-02 but is informational
|
|
9
|
+
* only in Phase 7 — latency observations are wired in a later phase.
|
|
10
|
+
*
|
|
11
|
+
* Phase 19 (v1.2) adds `maxIterations` and `maxWallTimeMs` for the agent
|
|
12
|
+
* runtime. Both are additive and optional; non-agent callers ignore them.
|
|
13
|
+
* `maxIterations` caps the number of `runAgent` iterations; `maxWallTimeMs`
|
|
14
|
+
* caps wall-clock duration per `runAgent` invocation. Both are enforced
|
|
15
|
+
* pre-iteration in the agent loop.
|
|
16
|
+
*/
|
|
17
|
+
interface BudgetInvariant {
|
|
18
|
+
readonly maxCostUsd?: number;
|
|
19
|
+
readonly maxIterations?: number;
|
|
20
|
+
readonly maxWallTimeMs?: number;
|
|
21
|
+
readonly p95LatencyMs?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Quality-floor invariant.
|
|
25
|
+
*
|
|
26
|
+
* `suite` is a fixture-directory path string; `minScore` is in 0..1.
|
|
27
|
+
* Phase 7 forwards this into the pre-flight evaluator but only enforces
|
|
28
|
+
* capability-side rejects. Full enforcement lives in Phase 12 (`lattice eval`).
|
|
29
|
+
*/
|
|
30
|
+
interface QualityFloorInvariant {
|
|
31
|
+
readonly suite: string;
|
|
32
|
+
readonly minScore: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The full Capability Contract attached to `RunIntent.contract`.
|
|
36
|
+
*
|
|
37
|
+
* All fields are optional. v1.0 callers compile and run unchanged when
|
|
38
|
+
* the field is omitted entirely. PROJECT.md explicitly rejects mandatory
|
|
39
|
+
* contracts.
|
|
40
|
+
*/
|
|
41
|
+
interface CapabilityContract {
|
|
42
|
+
readonly kind: "capability-contract";
|
|
43
|
+
readonly budget?: BudgetInvariant;
|
|
44
|
+
readonly invariants?: readonly InvariantDeclaration[];
|
|
45
|
+
readonly qualityFloor?: QualityFloorInvariant;
|
|
46
|
+
readonly requiredModalities?: readonly CapabilityModality[];
|
|
47
|
+
readonly requiredPrivacy?: "standard" | "sensitive" | "restricted";
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Reject-reason taxonomy added to `RouteRejectReason.code` by Phase 7's
|
|
51
|
+
* pre-flight evaluator. Closed four-value union per the locked decisions
|
|
52
|
+
* in 07-CONTEXT.md.
|
|
53
|
+
*/
|
|
54
|
+
type ContractRejectReasonCode = "contract-budget-exceeded" | "contract-quality-floor" | "contract-modality-missing" | "contract-privacy-mismatch";
|
|
55
|
+
/** Input shape accepted by `contract()`. Mirrors `CapabilityContract` minus `kind`. */
|
|
56
|
+
interface CapabilityContractInput {
|
|
57
|
+
readonly budget?: BudgetInvariant;
|
|
58
|
+
readonly invariants?: readonly InvariantDeclaration[];
|
|
59
|
+
readonly qualityFloor?: QualityFloorInvariant;
|
|
60
|
+
readonly requiredModalities?: readonly CapabilityModality[];
|
|
61
|
+
readonly requiredPrivacy?: "standard" | "sensitive" | "restricted";
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Factory for `CapabilityContract` values.
|
|
65
|
+
*
|
|
66
|
+
* Mirrors the `output()` and adapter factory style — exact-optional safe
|
|
67
|
+
* (does not emit `field: undefined` properties under `exactOptionalPropertyTypes`).
|
|
68
|
+
* Returns a frozen value with frozen nested objects so downstream code can
|
|
69
|
+
* rely on structural immutability when canonicalizing in Phase 9.
|
|
70
|
+
*/
|
|
71
|
+
declare function contract(input?: CapabilityContractInput): CapabilityContract;
|
|
72
|
+
//#endregion
|
|
73
|
+
export { QualityFloorInvariant as a, ContractRejectReasonCode as i, CapabilityContract as n, contract as o, CapabilityContractInput as r, BudgetInvariant as t };
|
|
74
|
+
//# sourceMappingURL=contract-S3oJGlc9.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-S3oJGlc9.d.ts","names":[],"sources":["../src/contract/contract.ts"],"mappings":";;;AA2BA;;;;;;;;;;AAcA;;;AAdA,UAAiB,eAAA;EAAA,SACN,UAAA;EAAA,SACA,aAAA;EAAA,SACA,aAAA;EAAA,SACA,YAAA;AAAA;;;;;;;;UAUM,qBAAA;EAAA,SACN,KAAA;EAAA,SACA,QAAA;AAAA;;;;;;;AAwBX;UAdiB,kBAAA;EAAA,SACN,IAAA;EAAA,SACA,MAAA,GAAS,eAAA;EAAA,SACT,UAAA,YAAsB,oBAAA;EAAA,SACtB,YAAA,GAAe,qBAAA;EAAA,SACf,kBAAA,YAA8B,kBAAA;EAAA,SAC9B,eAAA;AAAA;;;;;;KAQC,wBAAA;;UAOK,uBAAA;EAAA,SACN,MAAA,GAAS,eAAA;EAAA,SACT,UAAA,YAAsB,oBAAA;EAAA,SACtB,YAAA,GAAe,qBAAA;EAAA,SACf,kBAAA,YAA8B,kBAAA;EAAA,SAC9B,eAAA;AAAA;;;AAWX;;;;;;iBAAgB,QAAA,CAAS,KAAA,GAAO,uBAAA,GAA+B,kBAAA"}
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { At as defaultPiiDetectors, Bt as ContextSummarizer, Ct as ValidationIssue, Dt as evaluateTripwires, Et as TripwireResult, Ft as MustCiteInvariant, Gt as toContextArtifactRefs, Ht as buildContextPack, It as NoPiiInvariant, Kt as SessionRecord, Lt as inv, Mt as InvariantDeclaration, Nt as InvariantOptions, Ot as PiiDetector, Pt as MatchesInvariant, Qt as ExecutionPlan, Rt as BuildContextPackInput, St as ValidationError, T as Usage, Tt as TripwireEvidence, Ut as estimateArtifactTokens, Vt as TrustLabel, Wt as estimateTokens, _ as ProviderStreamOutputChunk, _n as output, _t as NoContractMatchError, an as RouteDecision, b as ProviderStreamUsageChunk, bt as TimeoutError, c as ProviderPricingHint, cn as SelectedRoute, d as ProviderRunRequest, dn as CitationRef, en as FallbackRoute, f as ProviderRunResponse, fn as CitationsOutputContract, g as ProviderStreamGatewayChunk, gn as TextOutputContract, gt as LatticeRunError, h as ProviderStreamCompleteChunk, hn as SchemaOutputContract, i as ProviderDataPolicyHints, in as RouteCandidate, jt as FieldFromTableInvariant, kt as PiiDetectorResult, l as ProviderRef, ln as UsageRecord, m as ProviderStreamChunk, mn as OutputContractMap, mt as ToolUseRequest, n as ModelCapability, nn as ProviderPackagingPlan, o as ProviderGatewayMetadata, on as RouteEstimates, p as ProviderStream, pn as OutputContract, r as ProviderAdapter, s as ProviderLatencyClass, sn as RouteRejectReason, t as CapabilityModality, tn as ProviderAttemptRecord, u as ProviderRegistryInput, un as ArtifactRefsOutputContract, v as ProviderStreamTextDeltaChunk, vt as NoRouteError, w as ProviderTransportMode, wt as isTerminal, xt as TripwireViolationError, y as ProviderStreamToolCallChunk, yt as ProviderExecutionError, zt as ContextPack } from "./provider-C2IfKsvz.js";
|
|
2
|
+
import { S as mergePolicy, _ as ArtifactTransformDescriptor, a as ArtifactOptions, b as GatewayPolicy, c as ArtifactSize, d as ArtifactToolResultOptions, f as artifact, g as ArtifactParentRef, h as ArtifactLineage, i as ArtifactKind, l as ArtifactSource, m as toArtifactRef, n as ArtifactFingerprint, o as ArtifactPrivacy, p as isArtifactRef, r as ArtifactInput, s as ArtifactRef, t as ArtifactDerivedOptions, u as ArtifactStorageRef, v as ArtifactTransformKind, x as PolicySpec, y as GatewayMetadataValue } from "./artifact-Bg6mJGnm.js";
|
|
3
|
+
import { n as InferOutputMap, t as InferOutput } from "./infer-DLqp5QIM.js";
|
|
4
|
+
import { i as StoredArtifactPayloadDescriptor, n as StorageLike, r as StoredArtifactEnvelope, t as ArtifactStore } from "./storage-DJKmsaEI.js";
|
|
5
|
+
import { a as QualityFloorInvariant, i as ContractRejectReasonCode, n as CapabilityContract, o as contract, r as CapabilityContractInput, t as BudgetInvariant } from "./contract-S3oJGlc9.js";
|
|
6
|
+
import { n as RunResult, r as RunSuccess, t as RunFailure } from "./result-DLEx2WvU.js";
|
|
7
|
+
import { a as createCapabilityCatalog, c as modalRank, i as DEFAULT_CATALOG_VERSION, n as routeDeterministically, o as defaultCapabilityForProvider, r as CapabilityCatalog, s as effectivePer1kPricing, t as RouteRequest } from "./router-Yo1-aDOv.js";
|
|
8
|
+
import { a as evaluateContractAgainstRoute, i as estimateRouteCost, n as EstimateRouteCostInput, r as EvaluateContractInput, t as ContractPreflightResult } from "./preflight-DNHWuJ46.js";
|
|
9
|
+
import { n as createMemoryArtifactStore, t as MemoryArtifactStoreOptions } from "./memory-DRig5EHV.js";
|
|
10
|
+
|
|
11
|
+
//#region src/core/standalone.d.ts
|
|
12
|
+
interface PrepareCoreRunInput<TOutputs extends OutputContractMap = OutputContractMap> {
|
|
13
|
+
readonly task: string;
|
|
14
|
+
readonly artifacts?: readonly ArtifactInput[];
|
|
15
|
+
readonly outputs: TOutputs;
|
|
16
|
+
readonly catalog?: CapabilityCatalog;
|
|
17
|
+
readonly policy?: PolicySpec;
|
|
18
|
+
readonly provider?: string;
|
|
19
|
+
readonly model?: string;
|
|
20
|
+
readonly contract?: CapabilityContract;
|
|
21
|
+
readonly session?: SessionRecord;
|
|
22
|
+
readonly tokenBudget?: number;
|
|
23
|
+
readonly storage?: ArtifactStore;
|
|
24
|
+
readonly metadata?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
interface PreparedCoreArtifact {
|
|
27
|
+
readonly ref: ArtifactRef;
|
|
28
|
+
readonly stored: boolean;
|
|
29
|
+
readonly inputHash?: string;
|
|
30
|
+
}
|
|
31
|
+
interface PreparedCoreRun<TOutputs extends OutputContractMap = OutputContractMap> {
|
|
32
|
+
readonly kind: "prepared-core-run";
|
|
33
|
+
readonly version: 1;
|
|
34
|
+
readonly createdAt: string;
|
|
35
|
+
readonly task: string;
|
|
36
|
+
readonly outputNames: readonly (keyof TOutputs & string)[];
|
|
37
|
+
readonly artifacts: readonly PreparedCoreArtifact[];
|
|
38
|
+
readonly artifactRefs: readonly ArtifactRef[];
|
|
39
|
+
readonly context: ContextPack;
|
|
40
|
+
readonly route: RouteDecision;
|
|
41
|
+
readonly plan: ExecutionPlan;
|
|
42
|
+
readonly inputHashes: readonly string[];
|
|
43
|
+
readonly warnings: readonly string[];
|
|
44
|
+
}
|
|
45
|
+
declare function prepareCoreRun<TOutputs extends OutputContractMap>(input: PrepareCoreRunInput<TOutputs>): Promise<PreparedCoreRun<TOutputs>>;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { type ArtifactDerivedOptions, type ArtifactFingerprint, type ArtifactInput, type ArtifactKind, type ArtifactLineage, type ArtifactOptions, type ArtifactParentRef, type ArtifactPrivacy, type ArtifactRef, type ArtifactRefsOutputContract, type ArtifactSize, type ArtifactSource, type ArtifactStorageRef, type ArtifactStore, type ArtifactToolResultOptions, type ArtifactTransformDescriptor, type ArtifactTransformKind, type BudgetInvariant, type BuildContextPackInput, type CapabilityCatalog, type CapabilityContract, type CapabilityContractInput, type CapabilityModality, type CitationRef, type CitationsOutputContract, type ContextPack, type ContextSummarizer, type ContractPreflightResult, type ContractRejectReasonCode, DEFAULT_CATALOG_VERSION, type EstimateRouteCostInput, type EvaluateContractInput, type ExecutionPlan, type FallbackRoute, type FieldFromTableInvariant, type GatewayMetadataValue, type GatewayPolicy, type InferOutput, type InferOutputMap, type InvariantDeclaration, type InvariantOptions, type LatticeRunError, type MatchesInvariant, type MemoryArtifactStoreOptions, type ModelCapability, type MustCiteInvariant, type NoContractMatchError, type NoPiiInvariant, type NoRouteError, type OutputContract, type OutputContractMap, type PiiDetector, type PiiDetectorResult, type PolicySpec, type PrepareCoreRunInput, type PreparedCoreArtifact, type PreparedCoreRun, type ProviderAdapter, type ProviderAttemptRecord, type ProviderDataPolicyHints, type ProviderExecutionError, type ProviderGatewayMetadata, type ProviderLatencyClass, type ProviderPackagingPlan, type ProviderPricingHint, type ProviderRef, type ProviderRegistryInput, type ProviderRunRequest, type ProviderRunResponse, type ProviderStream, type ProviderStreamChunk, type ProviderStreamCompleteChunk, type ProviderStreamGatewayChunk, type ProviderStreamOutputChunk, type ProviderStreamTextDeltaChunk, type ProviderStreamToolCallChunk, type ProviderStreamUsageChunk, type ProviderTransportMode, type QualityFloorInvariant, type RouteCandidate, type RouteDecision, type RouteEstimates, type RouteRejectReason, type RouteRequest, type RunFailure, type RunResult, type RunSuccess, type SchemaOutputContract, type SelectedRoute, type StorageLike, type StoredArtifactEnvelope, type StoredArtifactPayloadDescriptor, type TextOutputContract, type TimeoutError, type ToolUseRequest, type TripwireEvidence, type TripwireResult, type TripwireViolationError, type TrustLabel, type Usage, type UsageRecord, type ValidationError, type ValidationIssue, artifact, buildContextPack, contract, createCapabilityCatalog, createMemoryArtifactStore, defaultCapabilityForProvider, defaultPiiDetectors, effectivePer1kPricing, estimateArtifactTokens, estimateRouteCost, estimateTokens, evaluateContractAgainstRoute, evaluateTripwires, inv, isArtifactRef, isTerminal, mergePolicy, modalRank, output, prepareCoreRun, routeDeterministically, toArtifactRef, toContextArtifactRefs };
|
|
48
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","names":[],"sources":["../src/core/standalone.ts"],"mappings":";;;;;;;;;;;UAeiB,mBAAA,kBAAqC,iBAAA,GAAoB,iBAAA;EAAA,SAC/D,IAAA;EAAA,SACA,SAAA,YAAqB,aAAA;EAAA,SACrB,OAAA,EAAS,QAAA;EAAA,SACT,OAAA,GAAU,iBAAA;EAAA,SACV,MAAA,GAAS,UAAA;EAAA,SACT,QAAA;EAAA,SACA,KAAA;EAAA,SACA,QAAA,GAAW,kBAAA;EAAA,SACX,OAAA,GAAU,aAAA;EAAA,SACV,WAAA;EAAA,SACA,OAAA,GAAU,aAAA;EAAA,SACV,QAAA,GAAW,MAAA;AAAA;AAAA,UAGL,oBAAA;EAAA,SACN,GAAA,EAAK,WAAA;EAAA,SACL,MAAA;EAAA,SACA,SAAA;AAAA;AAAA,UAGM,eAAA,kBAAiC,iBAAA,GAAoB,iBAAA;EAAA,SAC3D,IAAA;EAAA,SACA,OAAA;EAAA,SACA,SAAA;EAAA,SACA,IAAA;EAAA,SACA,WAAA,kBAA6B,QAAA;EAAA,SAC7B,SAAA,WAAoB,oBAAA;EAAA,SACpB,YAAA,WAAuB,WAAA;EAAA,SACvB,OAAA,EAAS,WAAA;EAAA,SACT,KAAA,EAAO,aAAA;EAAA,SACP,IAAA,EAAM,aAAA;EAAA,SACN,WAAA;EAAA,SACA,QAAA;AAAA;AAAA,iBAQW,cAAA,kBAAgC,iBAAA,CAAA,CACpD,KAAA,EAAO,mBAAA,CAAoB,QAAA,IAC1B,OAAA,CAAQ,eAAA,CAAgB,QAAA"}
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { n as isArtifactRef, r as toArtifactRef, t as artifact } from "./artifact-DOfpeXLb.js";
|
|
2
|
+
import { a as inv, i as defaultPiiDetectors, n as output, o as contract, r as evaluateTripwires, t as isTerminal } from "./errors-eEuEIx6X.js";
|
|
3
|
+
import { a as modalRank, i as effectivePer1kPricing, n as createCapabilityCatalog, r as defaultCapabilityForProvider, t as DEFAULT_CATALOG_VERSION } from "./catalog-CAfYwB_-.js";
|
|
4
|
+
import { i as evaluateContractAgainstRoute, n as mergePolicy, r as estimateRouteCost, t as routeDeterministically } from "./router-DU4Z3pTd.js";
|
|
5
|
+
import { t as createExecutionPlan } from "./plan-DFm8Llep.js";
|
|
6
|
+
import { t as fingerprintArtifactValue } from "./fingerprint-DodDbQKN.js";
|
|
7
|
+
import { i as toContextArtifactRefs, n as estimateArtifactTokens, r as estimateTokens, t as buildContextPack } from "./context-pack-Bz3GXmjv.js";
|
|
8
|
+
import { t as createMemoryArtifactStore } from "./memory-CkQEW6m5.js";
|
|
9
|
+
//#region src/core/standalone.ts
|
|
10
|
+
const EMPTY_STANDALONE_CATALOG = {
|
|
11
|
+
version: "standalone-empty",
|
|
12
|
+
models: []
|
|
13
|
+
};
|
|
14
|
+
async function prepareCoreRun(input) {
|
|
15
|
+
const preparedArtifacts = await Promise.all((input.artifacts ?? []).map((artifact) => prepareArtifact(artifact, input.storage)));
|
|
16
|
+
const preparedInputs = preparedArtifacts.map((prepared) => prepared.input);
|
|
17
|
+
const artifactRefs = preparedArtifacts.map((prepared) => prepared.artifact.ref);
|
|
18
|
+
const route = routeDeterministically(input.catalog ?? EMPTY_STANDALONE_CATALOG, {
|
|
19
|
+
task: input.task,
|
|
20
|
+
artifacts: preparedInputs,
|
|
21
|
+
outputs: input.outputs,
|
|
22
|
+
...input.policy !== void 0 ? { policy: input.policy } : {},
|
|
23
|
+
...input.provider !== void 0 ? { provider: input.provider } : {},
|
|
24
|
+
...input.model !== void 0 ? { model: input.model } : {},
|
|
25
|
+
...input.contract !== void 0 ? { contract: input.contract } : {}
|
|
26
|
+
});
|
|
27
|
+
const context = buildContextPack({
|
|
28
|
+
task: input.task,
|
|
29
|
+
artifacts: preparedInputs,
|
|
30
|
+
...route.selected !== void 0 ? { route: route.selected } : {},
|
|
31
|
+
...input.session !== void 0 ? { session: input.session } : {},
|
|
32
|
+
...input.tokenBudget !== void 0 ? { tokenBudget: input.tokenBudget } : {}
|
|
33
|
+
});
|
|
34
|
+
const outputNames = Object.keys(input.outputs);
|
|
35
|
+
const plan = createExecutionPlan({
|
|
36
|
+
task: input.task,
|
|
37
|
+
artifacts: artifactRefs,
|
|
38
|
+
outputs: input.outputs,
|
|
39
|
+
route,
|
|
40
|
+
context,
|
|
41
|
+
metadata: {
|
|
42
|
+
...input.metadata,
|
|
43
|
+
standaloneCore: true
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const artifacts = preparedArtifacts.map((prepared) => prepared.artifact);
|
|
47
|
+
return {
|
|
48
|
+
kind: "prepared-core-run",
|
|
49
|
+
version: 1,
|
|
50
|
+
createdAt: plan.createdAt,
|
|
51
|
+
task: input.task,
|
|
52
|
+
outputNames,
|
|
53
|
+
artifacts,
|
|
54
|
+
artifactRefs,
|
|
55
|
+
context,
|
|
56
|
+
route,
|
|
57
|
+
plan,
|
|
58
|
+
inputHashes: artifacts.flatMap((artifact) => artifact.inputHash === void 0 ? [] : [artifact.inputHash]),
|
|
59
|
+
warnings: plan.warnings
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async function prepareArtifact(input, storage) {
|
|
63
|
+
if (storage !== void 0) {
|
|
64
|
+
const ref = await storage.put(input);
|
|
65
|
+
const inputHash = ref.fingerprint?.value ?? input.fingerprint?.value ?? (await fingerprintArtifactValue(input.value))?.value;
|
|
66
|
+
return {
|
|
67
|
+
input: {
|
|
68
|
+
...input,
|
|
69
|
+
...ref
|
|
70
|
+
},
|
|
71
|
+
artifact: {
|
|
72
|
+
ref,
|
|
73
|
+
stored: true,
|
|
74
|
+
...inputHash !== void 0 ? { inputHash } : {}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const fingerprint = input.fingerprint ?? await fingerprintArtifactValue(input.value);
|
|
79
|
+
const preparedInput = {
|
|
80
|
+
...input,
|
|
81
|
+
...fingerprint !== void 0 ? { fingerprint } : {}
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
input: preparedInput,
|
|
85
|
+
artifact: {
|
|
86
|
+
ref: toArtifactRef(preparedInput),
|
|
87
|
+
stored: false,
|
|
88
|
+
...fingerprint?.value !== void 0 ? { inputHash: fingerprint.value } : {}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
export { DEFAULT_CATALOG_VERSION, artifact, buildContextPack, contract, createCapabilityCatalog, createMemoryArtifactStore, defaultCapabilityForProvider, defaultPiiDetectors, effectivePer1kPricing, estimateArtifactTokens, estimateRouteCost, estimateTokens, evaluateContractAgainstRoute, evaluateTripwires, inv, isArtifactRef, isTerminal, mergePolicy, modalRank, output, prepareCoreRun, routeDeterministically, toArtifactRef, toContextArtifactRefs };
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","names":[],"sources":["../src/core/standalone.ts"],"sourcesContent":["import type { ArtifactInput, ArtifactRef } from \"../artifacts/artifact.js\";\nimport { toArtifactRef } from \"../artifacts/artifact.js\";\nimport type { CapabilityContract } from \"../contract/contract.js\";\nimport type { BuildContextPackInput, ContextPack } from \"../context/context-pack.js\";\nimport { buildContextPack } from \"../context/context-pack.js\";\nimport type { OutputContractMap } from \"../outputs/contracts.js\";\nimport type { ExecutionPlan, RouteDecision } from \"../plan/plan.js\";\nimport { createExecutionPlan } from \"../plan/plan.js\";\nimport type { PolicySpec } from \"../policy/policy.js\";\nimport type { CapabilityCatalog } from \"../routing/catalog.js\";\nimport { routeDeterministically } from \"../routing/router.js\";\nimport type { SessionRecord } from \"../sessions/session.js\";\nimport { fingerprintArtifactValue } from \"../storage/fingerprint.js\";\nimport type { ArtifactStore } from \"../storage/storage.js\";\n\nexport interface PrepareCoreRunInput<TOutputs extends OutputContractMap = OutputContractMap> {\n readonly task: string;\n readonly artifacts?: readonly ArtifactInput[];\n readonly outputs: TOutputs;\n readonly catalog?: CapabilityCatalog;\n readonly policy?: PolicySpec;\n readonly provider?: string;\n readonly model?: string;\n readonly contract?: CapabilityContract;\n readonly session?: SessionRecord;\n readonly tokenBudget?: number;\n readonly storage?: ArtifactStore;\n readonly metadata?: Record<string, unknown>;\n}\n\nexport interface PreparedCoreArtifact {\n readonly ref: ArtifactRef;\n readonly stored: boolean;\n readonly inputHash?: string;\n}\n\nexport interface PreparedCoreRun<TOutputs extends OutputContractMap = OutputContractMap> {\n readonly kind: \"prepared-core-run\";\n readonly version: 1;\n readonly createdAt: string;\n readonly task: string;\n readonly outputNames: readonly (keyof TOutputs & string)[];\n readonly artifacts: readonly PreparedCoreArtifact[];\n readonly artifactRefs: readonly ArtifactRef[];\n readonly context: ContextPack;\n readonly route: RouteDecision;\n readonly plan: ExecutionPlan;\n readonly inputHashes: readonly string[];\n readonly warnings: readonly string[];\n}\n\nconst EMPTY_STANDALONE_CATALOG: CapabilityCatalog = {\n version: \"standalone-empty\",\n models: [],\n};\n\nexport async function prepareCoreRun<TOutputs extends OutputContractMap>(\n input: PrepareCoreRunInput<TOutputs>,\n): Promise<PreparedCoreRun<TOutputs>> {\n const preparedArtifacts = await Promise.all(\n (input.artifacts ?? []).map((artifact) => prepareArtifact(artifact, input.storage)),\n );\n const preparedInputs = preparedArtifacts.map((prepared) => prepared.input);\n const artifactRefs = preparedArtifacts.map((prepared) => prepared.artifact.ref);\n const catalog = input.catalog ?? EMPTY_STANDALONE_CATALOG;\n const route = routeDeterministically(catalog, {\n task: input.task,\n artifacts: preparedInputs,\n outputs: input.outputs,\n ...(input.policy !== undefined ? { policy: input.policy } : {}),\n ...(input.provider !== undefined ? { provider: input.provider } : {}),\n ...(input.model !== undefined ? { model: input.model } : {}),\n ...(input.contract !== undefined ? { contract: input.contract } : {}),\n });\n const contextInput: BuildContextPackInput = {\n task: input.task,\n artifacts: preparedInputs,\n ...(route.selected !== undefined ? { route: route.selected } : {}),\n ...(input.session !== undefined ? { session: input.session } : {}),\n ...(input.tokenBudget !== undefined ? { tokenBudget: input.tokenBudget } : {}),\n };\n const context = buildContextPack(contextInput);\n const outputNames = Object.keys(input.outputs) as readonly (keyof TOutputs & string)[];\n const plan = createExecutionPlan({\n task: input.task,\n artifacts: artifactRefs,\n outputs: input.outputs,\n route,\n context,\n metadata: {\n ...input.metadata,\n standaloneCore: true,\n },\n });\n const artifacts = preparedArtifacts.map((prepared) => prepared.artifact);\n\n return {\n kind: \"prepared-core-run\",\n version: 1,\n createdAt: plan.createdAt,\n task: input.task,\n outputNames,\n artifacts,\n artifactRefs,\n context,\n route,\n plan,\n inputHashes: artifacts.flatMap((artifact) =>\n artifact.inputHash === undefined ? [] : [artifact.inputHash],\n ),\n warnings: plan.warnings,\n };\n}\n\ninterface PreparedArtifactInternal {\n readonly input: ArtifactInput;\n readonly artifact: PreparedCoreArtifact;\n}\n\nasync function prepareArtifact(\n input: ArtifactInput,\n storage: ArtifactStore | undefined,\n): Promise<PreparedArtifactInternal> {\n if (storage !== undefined) {\n const ref = await storage.put(input);\n const inputHash =\n ref.fingerprint?.value ??\n input.fingerprint?.value ??\n (await fingerprintArtifactValue(input.value))?.value;\n const preparedInput: ArtifactInput = {\n ...input,\n ...ref,\n };\n\n return {\n input: preparedInput,\n artifact: {\n ref,\n stored: true,\n ...(inputHash !== undefined ? { inputHash } : {}),\n },\n };\n }\n\n const fingerprint = input.fingerprint ?? await fingerprintArtifactValue(input.value);\n const preparedInput: ArtifactInput = {\n ...input,\n ...(fingerprint !== undefined ? { fingerprint } : {}),\n };\n const ref = toArtifactRef(preparedInput);\n\n return {\n input: preparedInput,\n artifact: {\n ref,\n stored: false,\n ...(fingerprint?.value !== undefined ? { inputHash: fingerprint.value } : {}),\n },\n };\n}\n"],"mappings":";;;;;;;;;AAmDA,MAAM,2BAA8C;CAClD,SAAS;CACT,QAAQ,EAAE;CACX;AAED,eAAsB,eACpB,OACoC;CACpC,MAAM,oBAAoB,MAAM,QAAQ,KACrC,MAAM,aAAa,EAAE,EAAE,KAAK,aAAa,gBAAgB,UAAU,MAAM,QAAQ,CAAC,CACpF;CACD,MAAM,iBAAiB,kBAAkB,KAAK,aAAa,SAAS,MAAM;CAC1E,MAAM,eAAe,kBAAkB,KAAK,aAAa,SAAS,SAAS,IAAI;CAE/E,MAAM,QAAQ,uBADE,MAAM,WAAW,0BACa;EAC5C,MAAM,MAAM;EACZ,WAAW;EACX,SAAS,MAAM;EACf,GAAI,MAAM,WAAW,KAAA,IAAY,EAAE,QAAQ,MAAM,QAAQ,GAAG,EAAE;EAC9D,GAAI,MAAM,aAAa,KAAA,IAAY,EAAE,UAAU,MAAM,UAAU,GAAG,EAAE;EACpE,GAAI,MAAM,UAAU,KAAA,IAAY,EAAE,OAAO,MAAM,OAAO,GAAG,EAAE;EAC3D,GAAI,MAAM,aAAa,KAAA,IAAY,EAAE,UAAU,MAAM,UAAU,GAAG,EAAE;EACrE,CAAC;CAQF,MAAM,UAAU,iBAP4B;EAC1C,MAAM,MAAM;EACZ,WAAW;EACX,GAAI,MAAM,aAAa,KAAA,IAAY,EAAE,OAAO,MAAM,UAAU,GAAG,EAAE;EACjE,GAAI,MAAM,YAAY,KAAA,IAAY,EAAE,SAAS,MAAM,SAAS,GAAG,EAAE;EACjE,GAAI,MAAM,gBAAgB,KAAA,IAAY,EAAE,aAAa,MAAM,aAAa,GAAG,EAAE;EAC9E,CAC6C;CAC9C,MAAM,cAAc,OAAO,KAAK,MAAM,QAAQ;CAC9C,MAAM,OAAO,oBAAoB;EAC/B,MAAM,MAAM;EACZ,WAAW;EACX,SAAS,MAAM;EACf;EACA;EACA,UAAU;GACR,GAAG,MAAM;GACT,gBAAgB;GACjB;EACF,CAAC;CACF,MAAM,YAAY,kBAAkB,KAAK,aAAa,SAAS,SAAS;AAExE,QAAO;EACL,MAAM;EACN,SAAS;EACT,WAAW,KAAK;EAChB,MAAM,MAAM;EACZ;EACA;EACA;EACA;EACA;EACA;EACA,aAAa,UAAU,SAAS,aAC9B,SAAS,cAAc,KAAA,IAAY,EAAE,GAAG,CAAC,SAAS,UAAU,CAC7D;EACD,UAAU,KAAK;EAChB;;AAQH,eAAe,gBACb,OACA,SACmC;AACnC,KAAI,YAAY,KAAA,GAAW;EACzB,MAAM,MAAM,MAAM,QAAQ,IAAI,MAAM;EACpC,MAAM,YACJ,IAAI,aAAa,SACjB,MAAM,aAAa,UAClB,MAAM,yBAAyB,MAAM,MAAM,GAAG;AAMjD,SAAO;GACL,OANmC;IACnC,GAAG;IACH,GAAG;IACJ;GAIC,UAAU;IACR;IACA,QAAQ;IACR,GAAI,cAAc,KAAA,IAAY,EAAE,WAAW,GAAG,EAAE;IACjD;GACF;;CAGH,MAAM,cAAc,MAAM,eAAe,MAAM,yBAAyB,MAAM,MAAM;CACpF,MAAM,gBAA+B;EACnC,GAAG;EACH,GAAI,gBAAgB,KAAA,IAAY,EAAE,aAAa,GAAG,EAAE;EACrD;AAGD,QAAO;EACL,OAAO;EACP,UAAU;GACR,KALQ,cAAc,cAAc;GAMpC,QAAQ;GACR,GAAI,aAAa,UAAU,KAAA,IAAY,EAAE,WAAW,YAAY,OAAO,GAAG,EAAE;GAC7E;EACF"}
|