@agenticprimitives/orchestration 0.0.0-alpha.1 → 0.0.0-alpha.11

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.
Files changed (114) hide show
  1. package/README.md +2 -0
  2. package/dist/admission.d.ts +127 -0
  3. package/dist/admission.d.ts.map +1 -0
  4. package/dist/admission.js +355 -0
  5. package/dist/admission.js.map +1 -0
  6. package/dist/answer-quality.d.ts +80 -0
  7. package/dist/answer-quality.d.ts.map +1 -0
  8. package/dist/answer-quality.js +97 -0
  9. package/dist/answer-quality.js.map +1 -0
  10. package/dist/artifacts.d.ts +137 -0
  11. package/dist/artifacts.d.ts.map +1 -0
  12. package/dist/artifacts.js +232 -0
  13. package/dist/artifacts.js.map +1 -0
  14. package/dist/authority.d.ts +465 -0
  15. package/dist/authority.d.ts.map +1 -0
  16. package/dist/authority.js +2 -0
  17. package/dist/authority.js.map +1 -0
  18. package/dist/conformance.d.ts +66 -0
  19. package/dist/conformance.d.ts.map +1 -0
  20. package/dist/conformance.js +140 -0
  21. package/dist/conformance.js.map +1 -0
  22. package/dist/derivation.d.ts +21 -0
  23. package/dist/derivation.d.ts.map +1 -0
  24. package/dist/derivation.js +31 -0
  25. package/dist/derivation.js.map +1 -0
  26. package/dist/durable.d.ts +44 -0
  27. package/dist/durable.d.ts.map +1 -0
  28. package/dist/durable.js +15 -0
  29. package/dist/durable.js.map +1 -0
  30. package/dist/export-port.d.ts +13 -0
  31. package/dist/export-port.d.ts.map +1 -0
  32. package/dist/export-port.js +2 -0
  33. package/dist/export-port.js.map +1 -0
  34. package/dist/flow-trace.d.ts +105 -0
  35. package/dist/flow-trace.d.ts.map +1 -0
  36. package/dist/flow-trace.js +60 -0
  37. package/dist/flow-trace.js.map +1 -0
  38. package/dist/index.d.ts +37 -4
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +44 -3
  41. package/dist/index.js.map +1 -1
  42. package/dist/input.d.ts +165 -0
  43. package/dist/input.d.ts.map +1 -0
  44. package/dist/input.js +33 -0
  45. package/dist/input.js.map +1 -0
  46. package/dist/intent.d.ts +37 -0
  47. package/dist/intent.d.ts.map +1 -0
  48. package/dist/intent.js +46 -0
  49. package/dist/intent.js.map +1 -0
  50. package/dist/judgment.d.ts +131 -0
  51. package/dist/judgment.d.ts.map +1 -0
  52. package/dist/judgment.js +249 -0
  53. package/dist/judgment.js.map +1 -0
  54. package/dist/loop.d.ts +155 -6
  55. package/dist/loop.d.ts.map +1 -1
  56. package/dist/loop.js +905 -32
  57. package/dist/loop.js.map +1 -1
  58. package/dist/metrics.d.ts +35 -0
  59. package/dist/metrics.d.ts.map +1 -0
  60. package/dist/metrics.js +98 -0
  61. package/dist/metrics.js.map +1 -0
  62. package/dist/outcome.d.ts +223 -0
  63. package/dist/outcome.d.ts.map +1 -0
  64. package/dist/outcome.js +325 -0
  65. package/dist/outcome.js.map +1 -0
  66. package/dist/plan-digest.d.ts +6 -0
  67. package/dist/plan-digest.d.ts.map +1 -0
  68. package/dist/plan-digest.js +35 -0
  69. package/dist/plan-digest.js.map +1 -0
  70. package/dist/planner-wire.d.ts +11 -0
  71. package/dist/planner-wire.d.ts.map +1 -0
  72. package/dist/planner-wire.js +53 -0
  73. package/dist/planner-wire.js.map +1 -0
  74. package/dist/planner.d.ts +51 -0
  75. package/dist/planner.d.ts.map +1 -1
  76. package/dist/planner.js +74 -0
  77. package/dist/planner.js.map +1 -1
  78. package/dist/reconcile.d.ts +41 -0
  79. package/dist/reconcile.d.ts.map +1 -0
  80. package/dist/reconcile.js +20 -0
  81. package/dist/reconcile.js.map +1 -0
  82. package/dist/record.d.ts +238 -0
  83. package/dist/record.d.ts.map +1 -0
  84. package/dist/record.js +116 -0
  85. package/dist/record.js.map +1 -0
  86. package/dist/regression.d.ts +109 -0
  87. package/dist/regression.d.ts.map +1 -0
  88. package/dist/regression.js +97 -0
  89. package/dist/regression.js.map +1 -0
  90. package/dist/selection.d.ts +334 -0
  91. package/dist/selection.d.ts.map +1 -0
  92. package/dist/selection.js +481 -0
  93. package/dist/selection.js.map +1 -0
  94. package/dist/spans.d.ts +262 -0
  95. package/dist/spans.d.ts.map +1 -0
  96. package/dist/spans.js +589 -0
  97. package/dist/spans.js.map +1 -0
  98. package/dist/tool-invoker.d.ts +61 -3
  99. package/dist/tool-invoker.d.ts.map +1 -1
  100. package/dist/tool-invoker.js +26 -1
  101. package/dist/tool-invoker.js.map +1 -1
  102. package/dist/trace-context.d.ts +26 -0
  103. package/dist/trace-context.d.ts.map +1 -0
  104. package/dist/trace-context.js +59 -0
  105. package/dist/trace-context.js.map +1 -0
  106. package/dist/trace-facts.d.ts +84 -0
  107. package/dist/trace-facts.d.ts.map +1 -0
  108. package/dist/trace-facts.js +82 -0
  109. package/dist/trace-facts.js.map +1 -0
  110. package/dist/types.d.ts +265 -3
  111. package/dist/types.d.ts.map +1 -1
  112. package/dist/types.js +4 -0
  113. package/dist/types.js.map +1 -1
  114. package/package.json +19 -7
@@ -0,0 +1,97 @@
1
+ // ANSWER QUALITY, JUDGED — spec 416 §4h. An instruction skill's answer is scored by typed yes-no questions (J9) over one
2
+ // frozen state — the request, the skill's ontology card, the answer — so a faster or cheaper way of answering can be
3
+ // traded against quality with evidence, not taste. Numbers only leave (J7): the per-question probabilities and their
4
+ // mean. Evidence, never authority (J1): nothing reads the score to permit or refuse anything.
5
+ import { judgeQuestions, judgeQuestionsAveraged, structuredCallDecisionModel } from './judgment.js';
6
+ export const ANSWER_QUALITY_JUDGE = { name: 'ap.answer-quality-judge.v1', kind: 'model' };
7
+ /** The rubric: each a statement the judge gives P(true) for. Stable ids — a changed rubric is a new judge name (J5). */
8
+ export const ANSWER_QUALITY_RUBRIC = [
9
+ { id: 'answers', statement: 'The answer addresses what the request actually asks for, not a neighbouring task.' },
10
+ { id: 'method', statement: 'The answer follows the skill\'s method and produces what the skill says it produces.' },
11
+ { id: 'grounded', statement: 'The answer states no specific facts about the organization (names, figures, dates) that the request did not give, or marks each such fact as a placeholder to confirm.' },
12
+ { id: 'asks', statement: 'Where the request lacks information the skill needs, the answer says what is needed instead of inventing it (true if nothing was missing).' },
13
+ { id: 'usable', statement: 'A person could act on this answer as it stands, without rewriting it.' },
14
+ ];
15
+ /** Judge one answer. The answer is truncated to `maxChars` (the judge reads a bounded state). */
16
+ export async function judgeAnswerQuality(input, call) {
17
+ const t0 = Date.now();
18
+ const max = input.maxChars ?? 8000;
19
+ const answer = input.answer.length > max ? `${input.answer.slice(0, max)}\n…(truncated)` : input.answer;
20
+ const questions = ANSWER_QUALITY_RUBRIC.map((q) => ({ id: q.id, kind: 'yes-no', statement: q.statement }));
21
+ const j = await judgeQuestions(`The skill: ${input.skillCard}\n\nThe request:\n${input.request}\n\nThe answer:\n${answer}`, questions, structuredCallDecisionModel(call, { name: ANSWER_QUALITY_JUDGE.name, stablePrefix: true }));
22
+ const scores = Object.fromEntries(Object.entries(j.answers).map(([id, a]) => [id, Number((a.distribution['true'] ?? 0).toFixed(4))]));
23
+ const vals = Object.values(scores);
24
+ return { judge: ANSWER_QUALITY_JUDGE, scores, score: vals.length ? Number((vals.reduce((a, b) => a + b, 0) / vals.length).toFixed(4)) : 0, ms: Date.now() - t0, ...(j.error !== undefined ? { error: j.error } : {}) };
25
+ }
26
+ // ── PAIRWISE PREFERENCE — a rubric scored in isolation saturates (0.97–1.00 for everything, 2026-09-27); two answers to
27
+ // the same request, judged side by side in BOTH orders under neutral labels and averaged (position bias cancelled), is
28
+ // the comparison that discriminates. Numbers only: P(first better), P(second better), P(no real difference).
29
+ export const ANSWER_PREFERENCE_JUDGE = { name: 'ap.answer-preference-judge.v1', kind: 'model' };
30
+ export async function judgeAnswerPreference(input, call) {
31
+ const t0 = Date.now();
32
+ const max = input.maxChars ?? 6000;
33
+ const cut = (a) => (a.length > max ? `${a.slice(0, max)}\n…(truncated)` : a);
34
+ const q = { id: 'better', kind: 'choice', question: 'Which answer better serves this request under this skill — more correct, more complete, better grounded, more usable?', options: Object.entries(input.answers).map(([id, a]) => ({ id, describe: cut(a).replace(/\s+/g, ' ') })), alsoOutcomes: [{ id: 'tie', describe: 'No real difference in quality.' }] };
35
+ const j = await judgeQuestionsAveraged(`The skill: ${input.skillCard}\n\nThe request:\n${input.request}`, [q], structuredCallDecisionModel(call, { name: ANSWER_PREFERENCE_JUDGE.name }), { permutations: 2 });
36
+ const a = j.answers['better'];
37
+ return { judge: ANSWER_PREFERENCE_JUDGE, preference: a ? { ...a.distribution } : {}, permutations: j.permutations, ms: Date.now() - t0, ...(j.error !== undefined ? { error: j.error } : {}) };
38
+ }
39
+ // ── THE OUTCOME CHECK — spec 418 / gap register A2. Not "was the right skill chosen" but "did the answer DELIVER what the
40
+ // request asked for". The ontology says what each skill PRODUCES; the request says WHICH of those it wants. So one call asks,
41
+ // per candidate class of the terminal skill, "does the request ask for a <class>?" and, per class, "does the answer deliver
42
+ // it — or, where the request lacks the facts it needs, its structure with the missing facts named?". Intermediate artifacts
43
+ // the plan was built on are always required. The score is delivery over the REQUESTED classes (those asked with P ≥ 0.5;
44
+ // the most-asked one when none is). v2 (2026-09-28): v1 required every product, and scored a correct letter of inquiry
45
+ // 0.24 because the drafter also produces proposals, and a structured pipeline with its gaps named ~0.
46
+ // v3 (2026-10-02) — ALTERNATIVE OUTPUTS ARE SCORED ONCE. A skill can produce EITHER one class OR another (the drafter: a
47
+ // Letter of Inquiry or a Grant Proposal, two entries to one application; its body picks one). v2 still asked about each
48
+ // and, when a request read as asking for both, averaged in the one the skill was never meant to write: on chain panels
49
+ // 1–4 (3 repeats, Claude Haiku judging) 51 of 68 grant runs delivered exactly one and lost about a third of the score.
50
+ // The ontology now says which produced classes are alternatives (`alternative`, a group name from the data graph's
51
+ // `skills:alternativeGroup`), and the score counts UNITS: an ungrouped class is its own unit, exactly as in v2; a group
52
+ // is one unit, requested = the most-asked member, delivered = the best-delivered member, required if any member is. The
53
+ // per-class `classes` / `requested` maps keep their shape; `units` says what was scored.
54
+ // Numbers only; evidence, never authority (J1).
55
+ export const OUTCOME_CHECK_JUDGE = { name: 'ap.outcome-check-judge.v3', kind: 'model' };
56
+ export async function judgeOutcomeDelivered(input, call) {
57
+ const t0 = Date.now();
58
+ const max = input.maxChars ?? 9000;
59
+ const answer = input.answer.length > max ? `${input.answer.slice(0, max)}\n…(truncated)` : input.answer;
60
+ const cands = input.expected.slice(0, 8);
61
+ if (!cands.length)
62
+ return { judge: OUTCOME_CHECK_JUDGE, classes: {}, requested: {}, score: 0, ms: 0, error: 'no expected classes' };
63
+ const qs = [
64
+ // Two plain questions per class, never one compound one: a judge reading "X, or else Y" anchored on X and scored a
65
+ // correct template-with-gaps 0.02 (validation, 2026-09-28). Delivered = the higher of the two.
66
+ ...cands.map((c, i) => ({ id: `d${i + 1}`, kind: 'yes-no', statement: `The answer contains a complete ${c.label}.` })),
67
+ ...cands.map((c, i) => ({ id: `s${i + 1}`, kind: 'yes-no', statement: `The answer lays out a ${c.label}'s full structure, filled in wherever the request gave the facts, and names the facts still needed to finish it.` })),
68
+ ...cands.flatMap((c, i) => (c.required ? [] : [{ id: `r${i + 1}`, kind: 'yes-no', statement: `The request asks for a ${c.label}.` }])),
69
+ ];
70
+ const j = await judgeQuestions(`The request:\n${input.request}\n\nThe answer:\n${answer}`, qs, structuredCallDecisionModel(call, { name: OUTCOME_CHECK_JUDGE.name, stablePrefix: true }));
71
+ const p = (id) => Number((j.answers[id]?.distribution['true'] ?? 0).toFixed(4));
72
+ const classes = Object.fromEntries(cands.map((c, i) => [c.iri, Math.max(p(`d${i + 1}`), p(`s${i + 1}`))]));
73
+ const requested = Object.fromEntries(cands.map((c, i) => [c.iri, c.required ? 1 : p(`r${i + 1}`)]));
74
+ // Fold each alternative group into ONE unit (v3); an ungrouped class is its own unit, so v2's arithmetic is unchanged.
75
+ const byId = new Map();
76
+ for (const c of cands) {
77
+ const id = c.alternative ? `alternative:${c.alternative}` : c.iri;
78
+ const u = byId.get(id) ?? (byId.set(id, { id, members: [], requested: 0, delivered: 0, counted: false }).get(id));
79
+ u.members.push(c.iri);
80
+ u.requested = Math.max(u.requested, requested[c.iri]);
81
+ u.delivered = Math.max(u.delivered, classes[c.iri]);
82
+ if (c.required)
83
+ u.required = true;
84
+ }
85
+ const units = [...byId.values()];
86
+ let counted = units.filter((u) => u.requested >= 0.5);
87
+ if (!counted.some((u) => !u.required)) {
88
+ const optional = units.filter((u) => !u.required).sort((a, b) => b.requested - a.requested);
89
+ if (optional[0])
90
+ counted = [...counted, optional[0]];
91
+ }
92
+ for (const u of counted)
93
+ u.counted = true;
94
+ const vals = counted.map((u) => u.delivered);
95
+ return { judge: OUTCOME_CHECK_JUDGE, classes, requested, units, score: vals.length ? Number((vals.reduce((a, b) => a + b, 0) / vals.length).toFixed(4)) : 0, ms: Date.now() - t0, ...(j.error !== undefined ? { error: j.error } : {}) };
96
+ }
97
+ //# sourceMappingURL=answer-quality.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answer-quality.js","sourceRoot":"","sources":["../src/answer-quality.ts"],"names":[],"mappings":"AAAA,yHAAyH;AACzH,qHAAqH;AACrH,qHAAqH;AACrH,8FAA8F;AAC9F,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,2BAA2B,EAA2B,MAAM,eAAe,CAAC;AAG7H,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,IAAI,EAAE,4BAA4B,EAAE,IAAI,EAAE,OAAgB,EAAE,CAAC;AAEnG,wHAAwH;AACxH,MAAM,CAAC,MAAM,qBAAqB,GAAqD;IACrF,EAAE,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,mFAAmF,EAAE;IACjH,EAAE,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,sFAAsF,EAAE;IACnH,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,wKAAwK,EAAE;IACvM,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,4IAA4I,EAAE;IACvK,EAAE,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,uEAAuE,E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CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAC3O,CAAC"}
@@ -0,0 +1,137 @@
1
+ import type { StepObservation, PlanStep } from './types.js';
2
+ import type { RunResult } from './types.js';
3
+ export declare const ARTIFACT_REF_TYPE: "ap.artifact-ref.v1";
4
+ /** A result whose canonical JSON is longer than this is offloaded when a store is bound. A deployment setting. */
5
+ export declare const OFFLOAD_THRESHOLD_CHARS = 8000;
6
+ /** The most a summary may run to — a shape, never a body. */
7
+ export declare const SUMMARY_MAX_CHARS = 600;
8
+ /** The stand-in for an offloaded result: where the body is, what it is, and its shape. */
9
+ export interface ArtifactRefV1 {
10
+ $artifact: typeof ARTIFACT_REF_TYPE;
11
+ /** The agent whose vault holds it (the acting agent — the run's addressee). */
12
+ agent: string;
13
+ /** The vault record key: `run.artifact:<runRef>:<stepRef>`. */
14
+ recordType: string;
15
+ /** sha256 of the canonical JSON of the body — the same bytes the receipt's outputDigest commits to. */
16
+ digest: string;
17
+ bytes: number;
18
+ toolId: string;
19
+ summary: string;
20
+ /** The few top-level FACTS the run's record and spans read off a result (a chain tx hash, a routed step's
21
+ * `via`, a count) — kept on the reference so offloading a body loses no evidence. Names from a fixed list. */
22
+ retained?: Record<string, unknown>;
23
+ }
24
+ /** Top-level result keys retained on a reference: what the record, the spans and the graph cite. */
25
+ export declare const RETAINED_RESULT_KEYS: readonly ["txHash", "via", "count", "total", "ok", "outcome"];
26
+ /** The facts of a result whether it is whole or a reference — what a projection reads. */
27
+ export declare function resultFactsOf(result: unknown): Record<string, unknown> | undefined;
28
+ export declare const RUN_ARTIFACT_RECORD_PREFIX: "run.artifact:";
29
+ export declare const runArtifactRecordKey: (runRef: string, stepRef: string) => string;
30
+ /** The vault record an offloaded result becomes. */
31
+ export interface RunArtifactRecordV1 {
32
+ type: 'ap.run-artifact.v1';
33
+ runRef: string;
34
+ stepRef: string;
35
+ toolId: string;
36
+ digest: string;
37
+ bytes: number;
38
+ at: number;
39
+ result: unknown;
40
+ }
41
+ export declare function isArtifactRef(v: unknown): v is ArtifactRefV1;
42
+ /** Canonical JSON: keys sorted, bigints as strings — the same bytes the receipt digests. */
43
+ export declare const canonicalJson: (v: unknown) => string;
44
+ /**
45
+ * A DETERMINISTIC summary of a result: its kind and top-level shape, the length of every array, the
46
+ * first three items' title-like field, a count when the result declares one. Bounded, never a body,
47
+ * never a model's words. Two runs over the same result produce the same string.
48
+ */
49
+ export declare function summarizeResult(result: unknown): string;
50
+ /** The port the app binds to the acting agent's vault door. Failures throw — an artifact that could not be
51
+ * written is a step whose result stays in the record whole, and the caller says so (never a silent drop). */
52
+ export interface ArtifactStore {
53
+ put(record: RunArtifactRecordV1, agent: string): Promise<{
54
+ ok: true;
55
+ } | {
56
+ ok: false;
57
+ error: string;
58
+ }>;
59
+ get(ref: ArtifactRefV1): Promise<RunArtifactRecordV1 | null>;
60
+ }
61
+ export interface OffloadReport {
62
+ stepRef: string;
63
+ toolId: string;
64
+ bytes: number;
65
+ recordType: string;
66
+ ok: boolean;
67
+ error?: string;
68
+ }
69
+ /**
70
+ * The record / checkpoint form of a run's observations: every result whose canonical JSON exceeds the
71
+ * threshold is written to the store and replaced by its reference. The receipts are untouched (their
72
+ * digests already commit to the full output). A write that fails leaves the result whole and is reported.
73
+ */
74
+ export declare function offloadObservations(steps: ReadonlyArray<StepObservation>, opts: {
75
+ runRef: string;
76
+ agent: string;
77
+ store: ArtifactStore;
78
+ threshold?: number;
79
+ now?: number;
80
+ }): Promise<{
81
+ steps: StepObservation[];
82
+ offloaded: OffloadReport[];
83
+ }>;
84
+ /** The record form of a whole RunResult (steps offloaded; everything else as it was). */
85
+ export declare function offloadRunResult<T extends Pick<RunResult, 'steps'>>(result: T, opts: Parameters<typeof offloadObservations>[1]): Promise<{
86
+ result: T;
87
+ offloaded: OffloadReport[];
88
+ }>;
89
+ /** The step references a plan's remaining steps reach through `$ref` (`{ $ref: 'name.path' }` — the name is
90
+ * the producing step's `ref` or `id`). */
91
+ export declare function refsReachedBy(steps: ReadonlyArray<PlanStep>): Set<string>;
92
+ /**
93
+ * The inverse, on a resume: a completed step whose result is a reference gets its body back from the store
94
+ * ONLY when a remaining step's `$ref` reaches it (by the step's `ref`, `id` or stepRef). A body nobody will
95
+ * read stays a reference. A missing artifact is an error the caller surfaces — a resume that guessed a
96
+ * result would be a resume that lied.
97
+ */
98
+ export declare function rehydrateObservations<T extends {
99
+ stepRef: string;
100
+ result?: unknown;
101
+ }>(completed: ReadonlyArray<T>, plan: {
102
+ steps: ReadonlyArray<PlanStep>;
103
+ }, store: ArtifactStore): Promise<{
104
+ completed: T[];
105
+ rehydrated: string[];
106
+ }>;
107
+ /**
108
+ * Spec 391 W2 — what a RE-PLAN sees of prior observations: a body over the threshold becomes its summary (a
109
+ * reference keeps its own). A planner deciding what comes next needs what a step was and how big, not 40 KB
110
+ * of it in the prompt.
111
+ */
112
+ export declare function compactObservations(observations: ReadonlyArray<StepObservation>, threshold?: number): StepObservation[];
113
+ export interface EvidenceItemV1 {
114
+ tool: string;
115
+ result: unknown; /** A summary stood in for the body. */
116
+ summarized?: boolean;
117
+ }
118
+ export interface FittedEvidenceV1 {
119
+ items: EvidenceItemV1[];
120
+ /** Characters of the fitted evidence, and of the whole. */
121
+ chars: number;
122
+ of: number;
123
+ /** Every step whose body was replaced by its summary, in order — for the trace and the governor. */
124
+ dropped: Array<{
125
+ tool: string;
126
+ stepRef?: string;
127
+ bytes: number;
128
+ }>;
129
+ }
130
+ /**
131
+ * The composer's evidence, FITTED to a budget instead of sliced: successful observations in order; a
132
+ * reference contributes its summary; a body that fits is kept whole; a body that would push the whole
133
+ * past the cap is replaced by its summary and recorded as dropped. The first item is always kept whole
134
+ * when it fits alone — an answer with no evidence is not an answer.
135
+ */
136
+ export declare function fitEvidence(observations: ReadonlyArray<StepObservation>, cap: number): FittedEvidenceV1;
137
+ //# sourceMappingURL=artifacts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifacts.d.ts","sourceRoot":"","sources":["../src/art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EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACnE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,aAAa,CAAC,eAAe,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAgBvG"}
@@ -0,0 +1,232 @@
1
+ export const ARTIFACT_REF_TYPE = 'ap.artifact-ref.v1';
2
+ /** A result whose canonical JSON is longer than this is offloaded when a store is bound. A deployment setting. */
3
+ export const OFFLOAD_THRESHOLD_CHARS = 8_000;
4
+ /** The most a summary may run to — a shape, never a body. */
5
+ export const SUMMARY_MAX_CHARS = 600;
6
+ /** Top-level result keys retained on a reference: what the record, the spans and the graph cite. */
7
+ export const RETAINED_RESULT_KEYS = ['txHash', 'via', 'count', 'total', 'ok', 'outcome'];
8
+ /** The facts of a result whether it is whole or a reference — what a projection reads. */
9
+ export function resultFactsOf(result) {
10
+ if (isArtifactRef(result))
11
+ return result.retained;
12
+ return result && typeof result === 'object' && !Array.isArray(result) ? result : undefined;
13
+ }
14
+ export const RUN_ARTIFACT_RECORD_PREFIX = 'run.artifact:';
15
+ export const runArtifactRecordKey = (runRef, stepRef) => `${RUN_ARTIFACT_RECORD_PREFIX}${runRef}:${stepRef}`;
16
+ export function isArtifactRef(v) {
17
+ return !!v && typeof v === 'object' && v.$artifact === ARTIFACT_REF_TYPE && typeof v.recordType === 'string';
18
+ }
19
+ /** Canonical JSON: keys sorted, bigints as strings — the same bytes the receipt digests. */
20
+ export const canonicalJson = (v) => JSON.stringify(v, (_k, x) => (typeof x === 'bigint' ? x.toString() : x && typeof x === 'object' && !Array.isArray(x) ? Object.keys(x).sort().reduce((o, k) => { o[k] = x[k]; return o; }, {}) : x)) ?? 'null';
21
+ const sha256 = async (s) => {
22
+ const bytes = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(s)));
23
+ return `0x${Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('')}`;
24
+ };
25
+ const TITLE_KEYS = ['title', 'name', 'id', 'label', 'handle'];
26
+ const COUNT_KEYS = ['count', 'total', 'length', 'size'];
27
+ const short = (s, n) => (s.length > n ? `${s.slice(0, n - 1)}…` : s);
28
+ /**
29
+ * A DETERMINISTIC summary of a result: its kind and top-level shape, the length of every array, the
30
+ * first three items' title-like field, a count when the result declares one. Bounded, never a body,
31
+ * never a model's words. Two runs over the same result produce the same string.
32
+ */
33
+ export function summarizeResult(result) {
34
+ const parts = [];
35
+ const firstTitles = (items) => items.slice(0, 3).map((it) => {
36
+ if (it && typeof it === 'object') {
37
+ for (const k of TITLE_KEYS) {
38
+ const v = it[k];
39
+ if (typeof v === 'string' && v.trim())
40
+ return short(v.trim(), 60);
41
+ }
42
+ // No title-like key (a query's rows, say): the first short string field names the item better than `{…}`.
43
+ for (const [k, v] of Object.entries(it))
44
+ if (typeof v === 'string' && v.trim() && v.length <= 80 && !/^0x[0-9a-fA-F]{40,}$/.test(v))
45
+ return `${k}=${short(v.trim(), 40)}`;
46
+ return '{…}';
47
+ }
48
+ return typeof it === 'string' ? short(it, 40) : String(it);
49
+ }).join(' · ');
50
+ if (Array.isArray(result)) {
51
+ parts.push(`array of ${result.length}`);
52
+ if (result.length)
53
+ parts.push(`first: ${firstTitles(result)}`);
54
+ }
55
+ else if (result && typeof result === 'object') {
56
+ const o = result;
57
+ const keys = Object.keys(o).sort();
58
+ parts.push(`object{${keys.slice(0, 12).join(',')}${keys.length > 12 ? ',…' : ''}}`);
59
+ for (const k of COUNT_KEYS)
60
+ if (typeof o[k] === 'number') {
61
+ parts.push(`${k}=${o[k]}`);
62
+ break;
63
+ }
64
+ for (const k of keys) {
65
+ const v = o[k];
66
+ if (Array.isArray(v)) {
67
+ parts.push(`${k}[${v.length}]${v.length ? `: ${firstTitles(v)}` : ''}`);
68
+ if (parts.join('; ').length > SUMMARY_MAX_CHARS)
69
+ break;
70
+ }
71
+ }
72
+ }
73
+ else if (typeof result === 'string') {
74
+ parts.push(`string of ${result.length} chars`);
75
+ }
76
+ else {
77
+ parts.push(String(result));
78
+ }
79
+ return short(parts.join('; '), SUMMARY_MAX_CHARS);
80
+ }
81
+ /**
82
+ * The record / checkpoint form of a run's observations: every result whose canonical JSON exceeds the
83
+ * threshold is written to the store and replaced by its reference. The receipts are untouched (their
84
+ * digests already commit to the full output). A write that fails leaves the result whole and is reported.
85
+ */
86
+ export async function offloadObservations(steps, opts) {
87
+ const threshold = opts.threshold ?? OFFLOAD_THRESHOLD_CHARS;
88
+ const offloaded = [];
89
+ const out = [];
90
+ for (const [i, o] of steps.entries()) {
91
+ if (o.result === undefined || isArtifactRef(o.result)) {
92
+ out.push(o);
93
+ continue;
94
+ }
95
+ const json = canonicalJson(o.result);
96
+ if (json.length <= threshold) {
97
+ out.push(o);
98
+ continue;
99
+ }
100
+ const stepRef = o.stepRef ?? o.step.id ?? `s${i}`;
101
+ const recordType = runArtifactRecordKey(opts.runRef, stepRef);
102
+ const digest = await sha256(json);
103
+ const record = { type: 'ap.run-artifact.v1', runRef: opts.runRef, stepRef, toolId: o.step.toolId, digest, bytes: json.length, at: opts.now ?? Date.now(), result: o.result };
104
+ const wrote = await opts.store.put(record, opts.agent).catch((e) => ({ ok: false, error: e instanceof Error ? e.message : String(e) }));
105
+ if (!wrote.ok) {
106
+ offloaded.push({ stepRef, toolId: o.step.toolId, bytes: json.length, recordType, ok: false, error: wrote.error });
107
+ out.push(o);
108
+ continue;
109
+ }
110
+ const retained = {};
111
+ if (o.result && typeof o.result === 'object' && !Array.isArray(o.result))
112
+ for (const k of RETAINED_RESULT_KEYS) {
113
+ const v = o.result[k];
114
+ if (v !== undefined && canonicalJson(v).length <= 400)
115
+ retained[k] = v;
116
+ }
117
+ const ref = { $artifact: ARTIFACT_REF_TYPE, agent: opts.agent.toLowerCase(), recordType, digest, bytes: json.length, toolId: o.step.toolId, summary: summarizeResult(o.result), ...(Object.keys(retained).length ? { retained } : {}) };
118
+ offloaded.push({ stepRef, toolId: o.step.toolId, bytes: json.length, recordType, ok: true });
119
+ out.push({ ...o, result: ref });
120
+ }
121
+ return { steps: out, offloaded };
122
+ }
123
+ /** The record form of a whole RunResult (steps offloaded; everything else as it was). */
124
+ export async function offloadRunResult(result, opts) {
125
+ const { steps, offloaded } = await offloadObservations(result.steps, opts);
126
+ return { result: { ...result, steps }, offloaded };
127
+ }
128
+ /** The step references a plan's remaining steps reach through `$ref` (`{ $ref: 'name.path' }` — the name is
129
+ * the producing step's `ref` or `id`). */
130
+ export function refsReachedBy(steps) {
131
+ const names = new Set();
132
+ const walk = (v) => {
133
+ if (!v || typeof v !== 'object')
134
+ return;
135
+ const r = v.$ref;
136
+ if (typeof r === 'string') {
137
+ names.add(r.split('.')[0]);
138
+ return;
139
+ }
140
+ for (const x of Object.values(v))
141
+ walk(x);
142
+ };
143
+ for (const s of steps)
144
+ walk(s.args);
145
+ return names;
146
+ }
147
+ /**
148
+ * The inverse, on a resume: a completed step whose result is a reference gets its body back from the store
149
+ * ONLY when a remaining step's `$ref` reaches it (by the step's `ref`, `id` or stepRef). A body nobody will
150
+ * read stays a reference. A missing artifact is an error the caller surfaces — a resume that guessed a
151
+ * result would be a resume that lied.
152
+ */
153
+ export async function rehydrateObservations(completed, plan, store) {
154
+ const reached = refsReachedBy(plan.steps);
155
+ const nameOf = new Map();
156
+ for (const [i, s] of plan.steps.entries()) {
157
+ const ref = `s${i}`;
158
+ if (s.ref)
159
+ nameOf.set(s.ref, ref);
160
+ if (s.id)
161
+ nameOf.set(s.id, s.id);
162
+ }
163
+ const rehydrated = [];
164
+ const out = [];
165
+ for (const c of completed) {
166
+ if (!isArtifactRef(c.result)) {
167
+ out.push(c);
168
+ continue;
169
+ }
170
+ const wanted = [...reached].some((n) => n === c.stepRef || nameOf.get(n) === c.stepRef || plan.steps.some((s) => (s.ref === n || s.id === n) && (s.id === c.stepRef || s.ref === c.stepRef)));
171
+ if (!wanted) {
172
+ out.push(c);
173
+ continue;
174
+ }
175
+ const rec = await store.get(c.result);
176
+ if (!rec)
177
+ throw new Error(`artifact ${c.result.recordType} is not in the vault — the resume cannot restore step ${c.stepRef}'s result`);
178
+ rehydrated.push(c.stepRef);
179
+ out.push({ ...c, result: rec.result });
180
+ }
181
+ return { completed: out, rehydrated };
182
+ }
183
+ /**
184
+ * Spec 391 W2 — what a RE-PLAN sees of prior observations: a body over the threshold becomes its summary (a
185
+ * reference keeps its own). A planner deciding what comes next needs what a step was and how big, not 40 KB
186
+ * of it in the prompt.
187
+ */
188
+ export function compactObservations(observations, threshold = OFFLOAD_THRESHOLD_CHARS) {
189
+ return observations.map((o) => {
190
+ if (o.result === undefined)
191
+ return o;
192
+ if (isArtifactRef(o.result))
193
+ return { ...o, result: `[offloaded: ${o.result.summary}]` };
194
+ const json = canonicalJson(o.result);
195
+ return json.length <= threshold ? o : { ...o, result: `[summary: ${summarizeResult(o.result)}]` };
196
+ });
197
+ }
198
+ /**
199
+ * The composer's evidence, FITTED to a budget instead of sliced: successful observations in order; a
200
+ * reference contributes its summary; a body that fits is kept whole; a body that would push the whole
201
+ * past the cap is replaced by its summary and recorded as dropped. The first item is always kept whole
202
+ * when it fits alone — an answer with no evidence is not an answer.
203
+ */
204
+ export function fitEvidence(observations, cap) {
205
+ const ok = observations.filter((o) => o.ok);
206
+ const whole = ok.map((o) => ({ o, json: isArtifactRef(o.result) ? null : canonicalJson(o.result ?? null) }));
207
+ const of = whole.reduce((n, w) => n + (w.json !== null ? w.json.length : w.o.result.summary.length), 0);
208
+ const items = [];
209
+ const dropped = [];
210
+ let chars = 0;
211
+ for (const { o, json } of whole) {
212
+ const tool = o.step.toolId;
213
+ if (json === null) {
214
+ const ref = o.result;
215
+ const s = `[offloaded: ${ref.summary}]`;
216
+ items.push({ tool, result: s, summarized: true });
217
+ chars += s.length;
218
+ continue;
219
+ }
220
+ if (chars + json.length <= cap) {
221
+ items.push({ tool, result: o.result });
222
+ chars += json.length;
223
+ continue;
224
+ }
225
+ const s = `[summary: ${summarizeResult(o.result)}]`;
226
+ items.push({ tool, result: s, summarized: true });
227
+ chars += s.length;
228
+ dropped.push({ tool, ...(o.stepRef ? { stepRef: o.stepRef } : {}), bytes: json.length });
229
+ }
230
+ return { items, chars, of, dropped };
231
+ }
232
+ //# sourceMappingURL=artifacts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifacts.js","sourceRoot":"","sources":["../src/artifacts.ts"],"names":[],"mappings":"AAsBA,MAAM,CAAC,MAAM,iBAAiB,GAAG,oBAA6B,CAAC;AAC/D,kHAAkH;AAClH,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,CAAC;AAC7C,6DAA6D;AAC7D,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAmBrC,oGAAoG;AACpG,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,CAAU,CAAC;AAElG,0FAA0F;AAC1F,MAAM,UAAU,aAAa,CAAC,MAAe;IAC3C,IAAI,aAAa,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC,QAAQ,CAAC;IAClD,OAAO,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAE,MAAkC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1H,CAAC;AAED,MAAM,CAAC,MAAM,0BAA0B,GAAG,eAAwB,CAAC;AACnE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,MAAc,EAAE,OAAe,EAAU,EAAE,CAAC,GAAG,0BAA0B,GAAG,MAAM,IAAI,OAAO,EAAE,CAAC;AAcrI,MAAM,UAAU,aAAa,CAAC,CAAU;IACtC,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAK,CAA6B,CAAC,SAAS,KAAK,iBAAiB,IAAI,OAAQ,CAA8B,CAAC,UAAU,KAA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