@tangle-network/agent-runtime 0.196.0 → 0.198.1

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 (102) hide show
  1. package/README.md +1 -2
  2. package/dist/{activation-BxMZybuo.js → activation-CwdO0ml2.js} +2 -2
  3. package/dist/{activation-BxMZybuo.js.map → activation-CwdO0ml2.js.map} +1 -1
  4. package/dist/{improve-DZs0KXhK.d.ts → activation-DFRTurvU.d.ts} +99 -5
  5. package/dist/agent.d.ts +1 -1
  6. package/dist/agent.js +2 -2
  7. package/dist/candidate-execution/index.d.ts +370 -2
  8. package/dist/candidate-execution/index.js +828 -4
  9. package/dist/candidate-execution/index.js.map +1 -0
  10. package/dist/{coordination-driver-zkCrfEbS.js → coordination-driver-Cf638-6q.js} +2 -5
  11. package/dist/{coordination-driver-zkCrfEbS.js.map → coordination-driver-Cf638-6q.js.map} +1 -1
  12. package/dist/{delegate-D7sonS78.js → delegate-Bez07Dlh.js} +2 -2
  13. package/dist/{delegate-D7sonS78.js.map → delegate-Bez07Dlh.js.map} +1 -1
  14. package/dist/durable.d.ts +110 -6
  15. package/dist/durable.js +404 -47
  16. package/dist/durable.js.map +1 -1
  17. package/dist/{graph-BuS-NxXD.js → graph-DBk3Unto.js} +3 -3
  18. package/dist/{graph-BuS-NxXD.js.map → graph-DBk3Unto.js.map} +1 -1
  19. package/dist/{improvement-cycle-Tw5nYT5R.js → improvement-cycle-Bma8TJs-.js} +8 -10
  20. package/dist/{improvement-cycle-Tw5nYT5R.js.map → improvement-cycle-Bma8TJs-.js.map} +1 -1
  21. package/dist/{index-CYOJsxSg.d.ts → index-D8LWK3Ha.d.ts} +6 -7
  22. package/dist/index.d.ts +694 -16
  23. package/dist/index.js +1780 -17
  24. package/dist/index.js.map +1 -1
  25. package/dist/intelligence.d.ts +3 -7
  26. package/dist/intelligence.js +5 -6
  27. package/dist/intelligence.js.map +1 -1
  28. package/dist/kernel.d.ts +2 -5
  29. package/dist/kernel.js +8 -10
  30. package/dist/{loop-runner-bin-XKMc3Ld-.js → loop-runner-bin-Bd3dHQuw.js} +3 -3
  31. package/dist/{loop-runner-bin-XKMc3Ld-.js.map → loop-runner-bin-Bd3dHQuw.js.map} +1 -1
  32. package/dist/{loop-runner-bin-DwrSB04m.d.ts → loop-runner-bin-Bn-0o_4k.d.ts} +3 -3
  33. package/dist/loop-runner-bin.d.ts +1 -1
  34. package/dist/loop-runner-bin.js +1 -1
  35. package/dist/mcp/bin.js +3 -3
  36. package/dist/mcp/index.d.ts +2 -3
  37. package/dist/mcp/index.js +4 -5
  38. package/dist/mcp/index.js.map +1 -1
  39. package/dist/{prepare-DDGp0-rW.js → prepare-CAO1yXov.js} +2407 -2407
  40. package/dist/prepare-CAO1yXov.js.map +1 -0
  41. package/dist/{protected-model-port-DxFN8DLS.js → protected-model-port-B5avcRiQ.js} +2 -2
  42. package/dist/{protected-model-port-DxFN8DLS.js.map → protected-model-port-B5avcRiQ.js.map} +1 -1
  43. package/dist/{provision-supervisor-CpMMShE_.js → provision-supervisor-C97q5NN_.js} +3 -6
  44. package/dist/{provision-supervisor-CpMMShE_.js.map → provision-supervisor-C97q5NN_.js.map} +1 -1
  45. package/dist/{redact-Cbl2O-4N.js → redact-CVyxp2AU.js} +5232 -2525
  46. package/dist/redact-CVyxp2AU.js.map +1 -0
  47. package/dist/{runtime-DqRieJ6e.js → runtime-BrTBBSfC.js} +427 -23
  48. package/dist/runtime-BrTBBSfC.js.map +1 -0
  49. package/dist/{server-BjB6ay4N.js → server-CO4bvAwe.js} +4 -4
  50. package/dist/{server-BjB6ay4N.js.map → server-CO4bvAwe.js.map} +1 -1
  51. package/dist/{types-DFLZMaeh.d.ts → stream-agent-turn-CLOQr497.d.ts} +1986 -6
  52. package/dist/{structural-rollout-DPbZWgEm.js → structural-rollout-D__lmWXe.js} +1101 -8
  53. package/dist/structural-rollout-D__lmWXe.js.map +1 -0
  54. package/dist/{supervise-D9aNi8_f.js → supervise-KSe4JEcg.js} +30 -7
  55. package/dist/supervise-KSe4JEcg.js.map +1 -0
  56. package/dist/testing.d.ts +2 -2
  57. package/dist/testing.js +13 -13
  58. package/dist/tui/index.d.ts +1 -1
  59. package/dist/tui/index.js +1 -1
  60. package/dist/{workspace-archive-Ybomp7AN.js → workspace-archive-BMOnloFf.js} +3 -3
  61. package/dist/{workspace-archive-Ybomp7AN.js.map → workspace-archive-BMOnloFf.js.map} +1 -1
  62. package/package.json +4 -31
  63. package/dist/activation-DyWB0K6E.d.ts +0 -98
  64. package/dist/authored-code-URmkdgjv.js +0 -37
  65. package/dist/authored-code-URmkdgjv.js.map +0 -1
  66. package/dist/candidate-execution-nvqVIMyS.js +0 -829
  67. package/dist/candidate-execution-nvqVIMyS.js.map +0 -1
  68. package/dist/conversation-BxJ0SIBM.js +0 -1363
  69. package/dist/conversation-BxJ0SIBM.js.map +0 -1
  70. package/dist/conversation.d.ts +0 -2
  71. package/dist/conversation.js +0 -2
  72. package/dist/environment-provider-1fKZh2zl.js +0 -2281
  73. package/dist/environment-provider-1fKZh2zl.js.map +0 -1
  74. package/dist/environment-provider-B-I2jlQy.d.ts +0 -143
  75. package/dist/environment-provider.d.ts +0 -2
  76. package/dist/environment-provider.js +0 -2
  77. package/dist/graph.d.ts +0 -753
  78. package/dist/graph.js +0 -2111
  79. package/dist/graph.js.map +0 -1
  80. package/dist/index-CUosKU4N.d.ts +0 -372
  81. package/dist/index-D9mb6fn2.d.ts +0 -691
  82. package/dist/index-ZnxSe6iK.d.ts +0 -138
  83. package/dist/jsonl-file-BEpaEYjT.js +0 -141
  84. package/dist/jsonl-file-BEpaEYjT.js.map +0 -1
  85. package/dist/knowledge-CPzT_Ve7.js +0 -428
  86. package/dist/knowledge-CPzT_Ve7.js.map +0 -1
  87. package/dist/knowledge.d.ts +0 -2
  88. package/dist/knowledge.js +0 -2
  89. package/dist/materialization-Cy0oM8tb.js +0 -672
  90. package/dist/materialization-Cy0oM8tb.js.map +0 -1
  91. package/dist/prepare-DDGp0-rW.js.map +0 -1
  92. package/dist/primeintellect/index.d.ts +0 -218
  93. package/dist/primeintellect/index.js +0 -739
  94. package/dist/primeintellect/index.js.map +0 -1
  95. package/dist/redact-Cbl2O-4N.js.map +0 -1
  96. package/dist/runtime-0xNaV6TJ.d.ts +0 -1699
  97. package/dist/runtime-DqRieJ6e.js.map +0 -1
  98. package/dist/stream-agent-turn-Dt5mZpc3.js +0 -1103
  99. package/dist/stream-agent-turn-Dt5mZpc3.js.map +0 -1
  100. package/dist/stream-agent-turn-urHpmO_Z.d.ts +0 -160
  101. package/dist/structural-rollout-DPbZWgEm.js.map +0 -1
  102. package/dist/supervise-D9aNi8_f.js.map +0 -1
@@ -1,138 +0,0 @@
1
- import { ps as SupervisorProfile, qp as DeliverableSpec, zo as SuperviseOptions } from "./index-CYOJsxSg.js";
2
- import { Z as SupervisedResult, i as Budget } from "./types-DFLZMaeh.js";
3
- import { c as ExecutorConfig } from "./runtime-0xNaV6TJ.js";
4
- import { y as AgentCandidateOutputArtifactPort } from "./types-1s_29INY.js";
5
- import { i as AgentImprovementActivationTransition, n as AgentImprovementActivationResultStore, t as AgentImprovementActivationReconciliation } from "./activation-DyWB0K6E.js";
6
- import { AgentCandidateBundle, AgentCandidateCapturedArtifact, AgentCandidateKnowledge } from "@tangle-network/agent-interface";
7
- import { BuildEvalKnowledgeBundleOptions, KnowledgeBaseQualityOptions, KnowledgeImprovementOptions, KnowledgeImprovementResult, KnowledgeReadinessSpec, PromoteKnowledgeCandidateOptions, RagKnowledgeUpdateResult } from "@tangle-network/agent-knowledge";
8
- //#region src/knowledge/activation.d.ts
9
- interface CreateKnowledgeImprovementActivationExecutorOptions extends Omit<PromoteKnowledgeCandidateOptions, 'root' | 'candidate'> {
10
- root: string;
11
- identity: string;
12
- results: AgentImprovementActivationResultStore;
13
- }
14
- interface KnowledgeImprovementActivationExecutor {
15
- transition: AgentImprovementActivationTransition;
16
- reconcile: AgentImprovementActivationReconciliation;
17
- }
18
- /** Apply or restore one local knowledge candidate through the shared activation contract. */
19
- declare function createKnowledgeImprovementActivationExecutor(options: CreateKnowledgeImprovementActivationExecutorOptions): KnowledgeImprovementActivationExecutor;
20
- //#endregion
21
- //#region src/knowledge/supervised-update.d.ts
22
- /** Standing prompt for a supervisor that grows a shared knowledge base through spawned researchers. */
23
- declare const RESEARCH_SUPERVISOR_SYSTEM_PROMPT: string;
24
- interface KnowledgeReadinessCheckInput {
25
- root: string;
26
- goal: string;
27
- readinessSpecs?: readonly unknown[];
28
- readinessTaskId?: string;
29
- readiness?: unknown;
30
- }
31
- type KnowledgeReadinessCheckResult = boolean | {
32
- ready: boolean;
33
- summary?: string;
34
- metadata?: Record<string, unknown>;
35
- };
36
- type KnowledgeReadinessCheck = (input: KnowledgeReadinessCheckInput) => Promise<KnowledgeReadinessCheckResult> | KnowledgeReadinessCheckResult;
37
- interface SupervisedKnowledgeUpdateInput {
38
- goal?: string;
39
- root?: string;
40
- candidateRoot?: string;
41
- findings?: readonly unknown[];
42
- metadata?: Record<string, unknown>;
43
- }
44
- interface SupervisedKnowledgeUpdateResult {
45
- applied: boolean;
46
- summary: string;
47
- supervised: SupervisedResult<unknown>;
48
- metadata: NonNullable<RagKnowledgeUpdateResult['metadata']>;
49
- }
50
- interface SupervisedKnowledgeUpdateOptions {
51
- root: string;
52
- goal: string;
53
- readiness: KnowledgeReadinessCheck;
54
- readinessSpecs?: readonly unknown[];
55
- readinessTaskId?: string;
56
- readinessOptions?: unknown;
57
- findings?: readonly unknown[];
58
- metadata?: Record<string, unknown>;
59
- budget: Budget;
60
- backend?: ExecutorConfig;
61
- makeWorkerAgent?: SuperviseOptions['makeWorkerAgent'];
62
- /** Caller-owned exact supervisor harness/provider/model identity. */
63
- supervisorProfile: SupervisorProfile;
64
- superviseOptions?: Partial<Omit<SuperviseOptions, 'budget' | 'backend' | 'deliverable' | 'makeWorkerAgent' | 'allowedModels'>>;
65
- allowedModels?: readonly string[];
66
- runSupervised?: (profile: SupervisorProfile, task: unknown, opts: SuperviseOptions) => Promise<SupervisedResult<unknown>>;
67
- }
68
- type SupervisedKnowledgeUpdater = (input: SupervisedKnowledgeUpdateInput) => Promise<SupervisedKnowledgeUpdateResult>;
69
- /** Build the completion check a supervised KB update uses to stop only when the KB is ready. */
70
- declare function knowledgeReadinessDeliverable(options: Pick<SupervisedKnowledgeUpdateOptions, 'root' | 'goal' | 'readiness' | 'readinessSpecs' | 'readinessTaskId' | 'readinessOptions'>): DeliverableSpec<unknown>;
71
- /** Create an `improveKnowledgeBase` update callback backed by runtime supervision. */
72
- declare function createSupervisedKnowledgeUpdater(options: SupervisedKnowledgeUpdateOptions): SupervisedKnowledgeUpdater;
73
- /** Run a runtime supervisor that updates one candidate knowledge base and stops on readiness. */
74
- declare function runSupervisedKnowledgeUpdate(options: SupervisedKnowledgeUpdateOptions): Promise<SupervisedKnowledgeUpdateResult>;
75
- /** Format the supervisor task with the KB root, readiness requirements, current findings, and metadata. */
76
- declare function formatSupervisedKnowledgeTask(options: Pick<SupervisedKnowledgeUpdateOptions, 'root' | 'goal' | 'readinessSpecs' | 'readinessTaskId' | 'findings' | 'metadata'>): string;
77
- //#endregion
78
- //#region src/knowledge/improvement-job.d.ts
79
- interface RunKnowledgeImprovementJobOptions extends Omit<KnowledgeImprovementOptions, 'updateKnowledge'> {
80
- budget: Budget;
81
- readinessCheck?: KnowledgeReadinessCheck;
82
- backend?: ExecutorConfig;
83
- makeWorkerAgent?: SuperviseOptions['makeWorkerAgent'];
84
- supervisorProfile: SupervisorProfile;
85
- superviseOptions?: Partial<Omit<SuperviseOptions, 'budget' | 'backend' | 'deliverable' | 'makeWorkerAgent' | 'allowedModels'>>;
86
- allowedModels?: readonly string[];
87
- runSupervised?: (profile: SupervisorProfile, task: unknown, opts: SuperviseOptions) => Promise<SupervisedResult<unknown>>;
88
- candidateArtifacts?: AgentCandidateOutputArtifactPort;
89
- onMeasurement?: (measurement: KnowledgeImprovementJobMeasurement) => Promise<void> | void;
90
- }
91
- interface KnowledgeImprovementJobMeasurement {
92
- startedAt: string;
93
- finishedAt: string;
94
- durationMs: number;
95
- updateCalls: number;
96
- updateDurationMs: number;
97
- supervisedSpent: {
98
- iterations: number;
99
- inputTokens: number;
100
- outputTokens: number;
101
- usdKnown: boolean;
102
- usd: number;
103
- ms: number;
104
- };
105
- }
106
- interface KnowledgeImprovementJobResult {
107
- improvement: KnowledgeImprovementResult;
108
- knowledge?: KnowledgeImprovementCandidatePair;
109
- measurement: KnowledgeImprovementJobMeasurement;
110
- blocked: boolean;
111
- }
112
- interface KnowledgeImprovementCandidatePair {
113
- reference: AgentCandidateKnowledge['candidate'];
114
- evaluation: AgentCandidateCapturedArtifact;
115
- baseline: AgentCandidateKnowledge['snapshot'];
116
- candidate: AgentCandidateKnowledge['snapshot'];
117
- }
118
- interface KnowledgeImprovementExperimentBundles {
119
- baseline: AgentCandidateBundle;
120
- candidate: AgentCandidateBundle;
121
- }
122
- interface AgentKnowledgeReadinessCheckOptions {
123
- goal: string;
124
- readinessSpecs?: readonly KnowledgeReadinessSpec[];
125
- readinessTaskId?: string;
126
- readiness?: Omit<BuildEvalKnowledgeBundleOptions, 'taskId' | 'index' | 'specs'>;
127
- strict?: boolean;
128
- kbQuality?: KnowledgeBaseQualityOptions;
129
- }
130
- /** Build the default readiness check backed by `@tangle-network/agent-knowledge` validation and scoring. */
131
- declare function createAgentKnowledgeReadinessCheck(options: AgentKnowledgeReadinessCheckOptions): KnowledgeReadinessCheck;
132
- /** Produce a frozen KB candidate while leaving live knowledge content unchanged. */
133
- declare function runKnowledgeImprovementJob(options: RunKnowledgeImprovementJobOptions): Promise<KnowledgeImprovementJobResult>;
134
- /** Attach both frozen knowledge inputs to one otherwise-identical bundle pair. */
135
- declare function buildKnowledgeImprovementExperimentBundles(bundle: AgentCandidateBundle, knowledge: KnowledgeImprovementCandidatePair): KnowledgeImprovementExperimentBundles;
136
- //#endregion
137
- export { KnowledgeImprovementActivationExecutor as C, CreateKnowledgeImprovementActivationExecutorOptions as S, SupervisedKnowledgeUpdater as _, KnowledgeImprovementJobResult as a, knowledgeReadinessDeliverable as b, createAgentKnowledgeReadinessCheck as c, KnowledgeReadinessCheckInput as d, KnowledgeReadinessCheckResult as f, SupervisedKnowledgeUpdateResult as g, SupervisedKnowledgeUpdateOptions as h, KnowledgeImprovementJobMeasurement as i, runKnowledgeImprovementJob as l, SupervisedKnowledgeUpdateInput as m, KnowledgeImprovementCandidatePair as n, RunKnowledgeImprovementJobOptions as o, RESEARCH_SUPERVISOR_SYSTEM_PROMPT as p, KnowledgeImprovementExperimentBundles as r, buildKnowledgeImprovementExperimentBundles as s, AgentKnowledgeReadinessCheckOptions as t, KnowledgeReadinessCheck as u, createSupervisedKnowledgeUpdater as v, createKnowledgeImprovementActivationExecutor as w, runSupervisedKnowledgeUpdate as x, formatSupervisedKnowledgeTask as y };
138
- //# sourceMappingURL=index-ZnxSe6iK.d.ts.map
@@ -1,141 +0,0 @@
1
- import { D as detachedSnapshot } from "./materialization-Cy0oM8tb.js";
2
- import { t as assertExecutableAgentProfile } from "./model-policy-DKDyr-fc.js";
3
- import { agentProfileSchema } from "@tangle-network/agent-interface";
4
- //#region src/runtime/sandbox-outcome.ts
5
- /** Map the public Sandbox outcome to Runtime's stream and verdict vocabulary. */
6
- function projectSandboxOutcome(outcome) {
7
- if (outcome.status === "success") return {
8
- status: "completed",
9
- reason: "turn completed",
10
- verdict: {
11
- valid: true,
12
- score: 1
13
- }
14
- };
15
- const reason = outcome.error ?? "Sandbox agent run failed";
16
- if (outcome.status === "failed") return {
17
- status: "failed",
18
- reason,
19
- verdict: {
20
- valid: false,
21
- score: 0
22
- },
23
- error: {
24
- kind: "backend",
25
- message: reason
26
- }
27
- };
28
- return {
29
- status: "blocked",
30
- reason,
31
- verdict: {
32
- valid: false,
33
- score: 0
34
- }
35
- };
36
- }
37
- /** Read an outcome that Runtime attached to one of its own executor artifacts. */
38
- function readSandboxOutcome(value) {
39
- if (!value || typeof value !== "object") return void 0;
40
- const outcome = value.outcome;
41
- if (!outcome || typeof outcome !== "object") return void 0;
42
- return outcome;
43
- }
44
- //#endregion
45
- //#region src/runtime/supervise/executable-spec.ts
46
- /**
47
- * Parse one untrusted profile into the exact immutable value execution may consume.
48
- *
49
- * Snapshotting before schema parsing reads caller-owned fields once. Snapshotting the parsed
50
- * result prevents downstream custom code from changing any identity or authority field.
51
- */
52
- function executableAgentProfileSnapshot(raw, context) {
53
- const profile = authoredAgentProfileSnapshot(raw, context);
54
- assertExecutableAgentProfile(profile, context);
55
- return profile;
56
- }
57
- /**
58
- * Parse and seal a profile as authored, without requiring it to select a harness and model.
59
- *
60
- * This is the intake for a leaf whose behavior is code the caller already built: a verbatim
61
- * `AgentSpec.executor`. Such an executor receives only the task and a signal, so no registry,
62
- * harness, or backend reads the profile after intake, and there is no ambient fill to refuse. The
63
- * profile still parses and still digests into the node's identity; it is simply not obliged to
64
- * claim a model that nothing runs. A graph script node is the canonical case.
65
- */
66
- function authoredAgentProfileSnapshot(raw, context) {
67
- const input = detachedSnapshot(raw, `${context}: AgentProfile input`);
68
- return detachedSnapshot(agentProfileSchema.parse(input), `${context}: parsed AgentProfile`);
69
- }
70
- /** Snapshot an executable spec while retaining trusted callbacks by reference. */
71
- function executableAgentSpecSnapshot(raw, context) {
72
- const { profile: rawProfile, harness, execution: rawExecution, ...runtimeExtensions } = raw;
73
- const profile = raw.executor === void 0 ? executableAgentProfileSnapshot(rawProfile, context) : authoredAgentProfileSnapshot(rawProfile, context);
74
- const execution = rawExecution === void 0 ? void 0 : detachedSnapshot(rawExecution, `${context}: execution attribution`);
75
- return Object.freeze({
76
- ...runtimeExtensions,
77
- profile,
78
- harness,
79
- ...execution === void 0 ? {} : { execution }
80
- });
81
- }
82
- //#endregion
83
- //#region src/durable/jsonl-file.ts
84
- /** Parse an append-only JSONL file without treating a torn final write as committed data.
85
- * A malformed newline-terminated or non-final record is corruption and fails loud. */
86
- function parseCommittedJsonLines(text, source) {
87
- const lines = text.split("\n");
88
- const finalIndex = lines.length - 1;
89
- const records = [];
90
- for (const [index, line] of lines.entries()) {
91
- if (line.length === 0) continue;
92
- try {
93
- records.push(JSON.parse(line));
94
- } catch (cause) {
95
- if (index === finalIndex && !text.endsWith("\n")) break;
96
- throw new Error(`${source}: malformed JSONL record at line ${index + 1}`, { cause });
97
- }
98
- }
99
- return records;
100
- }
101
- /** FileHandle.write may legally make a short write. Loop until every byte is appended. */
102
- async function writeAllBytes(handle, value) {
103
- const bytes = typeof value === "string" ? Buffer.from(value) : Buffer.from(value);
104
- let offset = 0;
105
- while (offset < bytes.byteLength) {
106
- const { bytesWritten } = await handle.write(bytes, offset, bytes.byteLength - offset, null);
107
- if (bytesWritten <= 0) throw new Error(`append-only file write made no progress at byte ${offset}`);
108
- offset += bytesWritten;
109
- }
110
- }
111
- /** Prepare a recovered JSONL file for its next append. A valid unterminated final value is retained
112
- * and needs a separator; an invalid unterminated tail was never committed and is truncated. */
113
- async function prepareJsonlAppend(path) {
114
- const fs = await import("node:fs/promises");
115
- let bytes;
116
- try {
117
- bytes = await fs.readFile(path);
118
- } catch (error) {
119
- if (isNoEntError(error)) return false;
120
- throw error;
121
- }
122
- if (bytes.byteLength === 0 || bytes[bytes.byteLength - 1] === 10) return false;
123
- const lastNewline = bytes.lastIndexOf(10);
124
- const tail = bytes.subarray(lastNewline + 1).toString("utf8");
125
- try {
126
- JSON.parse(tail);
127
- return true;
128
- } catch {
129
- await fs.truncate(path, lastNewline + 1);
130
- return false;
131
- }
132
- }
133
- /** True for a filesystem error meaning "the file is not there yet" — the one condition an
134
- * append-only reader treats as an empty log rather than a fault. */
135
- function isNoEntError(error) {
136
- return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
137
- }
138
- //#endregion
139
- export { executableAgentProfileSnapshot as a, readSandboxOutcome as c, writeAllBytes as i, parseCommittedJsonLines as n, executableAgentSpecSnapshot as o, prepareJsonlAppend as r, projectSandboxOutcome as s, isNoEntError as t };
140
-
141
- //# sourceMappingURL=jsonl-file-BEpaEYjT.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsonl-file-BEpaEYjT.js","names":[],"sources":["../src/runtime/sandbox-outcome.ts","../src/runtime/supervise/executable-spec.ts","../src/durable/jsonl-file.ts"],"sourcesContent":["import type { AgentRunOutcome } from '@tangle-network/sandbox/runtime'\nimport type { AgentTaskStatus, BackendErrorDetail } from '../types'\nimport type { DefaultVerdict } from './supervise/types'\n\n/** The outcome carried by Runtime-owned Sandbox artifacts. */\nexport interface SandboxOutcomeCarrier {\n outcome?: AgentRunOutcome\n}\n\n/** Runtime's terminal projection of the public Sandbox outcome contract. */\nexport interface SandboxOutcomeProjection {\n status: AgentTaskStatus\n reason: string\n verdict: DefaultVerdict\n error?: BackendErrorDetail\n}\n\n/** Map the public Sandbox outcome to Runtime's stream and verdict vocabulary. */\nexport function projectSandboxOutcome(outcome: AgentRunOutcome): SandboxOutcomeProjection {\n if (outcome.status === 'success') {\n return {\n status: 'completed',\n reason: 'turn completed',\n verdict: { valid: true, score: 1 },\n }\n }\n\n const reason = outcome.error ?? 'Sandbox agent run failed'\n if (outcome.status === 'failed') {\n return {\n status: 'failed',\n reason,\n verdict: { valid: false, score: 0 },\n error: { kind: 'backend', message: reason },\n }\n }\n\n return {\n status: 'blocked',\n reason,\n verdict: { valid: false, score: 0 },\n }\n}\n\n/** Read an outcome that Runtime attached to one of its own executor artifacts. */\nexport function readSandboxOutcome(value: unknown): AgentRunOutcome | undefined {\n if (!value || typeof value !== 'object') return undefined\n const outcome = (value as SandboxOutcomeCarrier).outcome\n if (!outcome || typeof outcome !== 'object') return undefined\n return outcome\n}\n","import { type AgentProfile, agentProfileSchema } from '@tangle-network/agent-interface'\nimport { assertExecutableAgentProfile } from './model-policy'\nimport { detachedSnapshot } from './snapshot'\nimport type { AgentSpec } from './types'\n\n/**\n * Parse one untrusted profile into the exact immutable value execution may consume.\n *\n * Snapshotting before schema parsing reads caller-owned fields once. Snapshotting the parsed\n * result prevents downstream custom code from changing any identity or authority field.\n */\nexport function executableAgentProfileSnapshot(raw: unknown, context: string): AgentProfile {\n const profile = authoredAgentProfileSnapshot(raw, context)\n assertExecutableAgentProfile(profile, context)\n return profile\n}\n\n/**\n * Parse and seal a profile as authored, without requiring it to select a harness and model.\n *\n * This is the intake for a leaf whose behavior is code the caller already built: a verbatim\n * `AgentSpec.executor`. Such an executor receives only the task and a signal, so no registry,\n * harness, or backend reads the profile after intake, and there is no ambient fill to refuse. The\n * profile still parses and still digests into the node's identity; it is simply not obliged to\n * claim a model that nothing runs. A graph script node is the canonical case.\n */\nexport function authoredAgentProfileSnapshot(raw: unknown, context: string): AgentProfile {\n const input = detachedSnapshot(raw, `${context}: AgentProfile input`)\n const profile = agentProfileSchema.parse(input)\n return detachedSnapshot(profile, `${context}: parsed AgentProfile`)\n}\n\n/** Snapshot an executable spec while retaining trusted callbacks by reference. */\nexport function executableAgentSpecSnapshot(raw: AgentSpec, context: string): AgentSpec {\n const {\n profile: rawProfile,\n harness,\n execution: rawExecution,\n ...runtimeExtensions\n } = raw as AgentSpec & Readonly<Record<string, unknown>>\n // Only a spec the kernel must resolve (a factory, a harness, or the router) needs an executable\n // identity; see `authoredAgentProfileSnapshot` for why a verbatim executor does not.\n const profile =\n raw.executor === undefined\n ? executableAgentProfileSnapshot(rawProfile, context)\n : authoredAgentProfileSnapshot(rawProfile, context)\n const execution =\n rawExecution === undefined\n ? undefined\n : detachedSnapshot(rawExecution, `${context}: execution attribution`)\n return Object.freeze({\n ...runtimeExtensions,\n profile,\n harness,\n ...(execution === undefined ? {} : { execution }),\n }) as AgentSpec\n}\n","import type { FileHandle } from 'node:fs/promises'\n\n/** Parse an append-only JSONL file without treating a torn final write as committed data.\n * A malformed newline-terminated or non-final record is corruption and fails loud. */\nexport function parseCommittedJsonLines<T>(text: string, source: string): T[] {\n const lines = text.split('\\n')\n const finalIndex = lines.length - 1\n const records: T[] = []\n\n for (const [index, line] of lines.entries()) {\n if (line.length === 0) continue\n try {\n records.push(JSON.parse(line) as T)\n } catch (cause) {\n const isInvalidUnterminatedTail = index === finalIndex && !text.endsWith('\\n')\n if (isInvalidUnterminatedTail) break\n throw new Error(`${source}: malformed JSONL record at line ${index + 1}`, { cause })\n }\n }\n\n return records\n}\n\n/** FileHandle.write may legally make a short write. Loop until every byte is appended. */\nexport async function writeAllBytes(\n handle: Pick<FileHandle, 'write'>,\n value: string | Uint8Array,\n): Promise<void> {\n const bytes = typeof value === 'string' ? Buffer.from(value) : Buffer.from(value)\n let offset = 0\n while (offset < bytes.byteLength) {\n const { bytesWritten } = await handle.write(bytes, offset, bytes.byteLength - offset, null)\n if (bytesWritten <= 0) {\n throw new Error(`append-only file write made no progress at byte ${offset}`)\n }\n offset += bytesWritten\n }\n}\n\n/** Prepare a recovered JSONL file for its next append. A valid unterminated final value is retained\n * and needs a separator; an invalid unterminated tail was never committed and is truncated. */\nexport async function prepareJsonlAppend(path: string): Promise<boolean> {\n const fs = await import('node:fs/promises')\n let bytes: Buffer\n try {\n bytes = await fs.readFile(path)\n } catch (error) {\n if (isNoEntError(error)) return false\n throw error\n }\n if (bytes.byteLength === 0 || bytes[bytes.byteLength - 1] === 0x0a) return false\n\n const lastNewline = bytes.lastIndexOf(0x0a)\n const tail = bytes.subarray(lastNewline + 1).toString('utf8')\n try {\n JSON.parse(tail)\n return true\n } catch {\n await fs.truncate(path, lastNewline + 1)\n return false\n }\n}\n\n/** True for a filesystem error meaning \"the file is not there yet\" — the one condition an\n * append-only reader treats as an empty log rather than a fault. */\nexport function isNoEntError(error: unknown): boolean {\n return (\n typeof error === 'object' &&\n error !== null &&\n 'code' in error &&\n (error as { code: unknown }).code === 'ENOENT'\n )\n}\n"],"mappings":";;;;;AAkBA,SAAgB,sBAAsB,SAAoD;CACxF,IAAI,QAAQ,WAAW,WACrB,OAAO;EACL,QAAQ;EACR,QAAQ;EACR,SAAS;GAAE,OAAO;GAAM,OAAO;EAAE;CACnC;CAGF,MAAM,SAAS,QAAQ,SAAS;CAChC,IAAI,Q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