@deepstrike/sdk 0.2.69 → 0.2.70
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/index.d.ts +6 -1
- package/dist/index.js +2 -0
- package/dist/kernel.d.ts +7 -4
- package/dist/memory/protocols.d.ts +2 -2
- package/dist/providers/anthropic-adapter.d.ts +2 -2
- package/dist/providers/anthropic.d.ts +9 -5
- package/dist/providers/anthropic.js +20 -5
- package/dist/providers/base.d.ts +5 -5
- package/dist/providers/content-normalization.d.ts +4 -4
- package/dist/providers/gemini-adapter.d.ts +2 -2
- package/dist/providers/gemini.d.ts +8 -4
- package/dist/providers/gemini.js +20 -7
- package/dist/providers/ollama-adapter.d.ts +2 -2
- package/dist/providers/ollama.d.ts +6 -3
- package/dist/providers/ollama.js +14 -3
- package/dist/providers/openai-chat.d.ts +4 -4
- package/dist/providers/openai-responses-adapter.d.ts +2 -2
- package/dist/providers/openai-responses-adapter.js +1 -1
- package/dist/providers/openai-responses.d.ts +7 -3
- package/dist/providers/openai-responses.js +19 -6
- package/dist/providers/openai.d.ts +8 -5
- package/dist/providers/openai.js +14 -3
- package/dist/providers/prepared-request.d.ts +4 -0
- package/dist/providers/prepared-request.js +78 -0
- package/dist/providers/protocol-adapter.d.ts +2 -2
- package/dist/providers/replay-validator.d.ts +3 -3
- package/dist/providers/request-plan.d.ts +8 -1
- package/dist/providers/request-plan.js +4 -3
- package/dist/runtime/archive.d.ts +7 -7
- package/dist/runtime/canonical-kernel-step.d.ts +4 -3
- package/dist/runtime/canonical-kernel-step.js +17 -8
- package/dist/runtime/context.d.ts +28 -0
- package/dist/runtime/context.js +16 -0
- package/dist/runtime/eval.d.ts +2 -2
- package/dist/runtime/evolution.d.ts +195 -0
- package/dist/runtime/evolution.js +34 -0
- package/dist/runtime/execution-plane.d.ts +1 -1
- package/dist/runtime/kernel-step.d.ts +7 -6
- package/dist/runtime/provider-replay.d.ts +2 -2
- package/dist/runtime/provider-replay.js +1 -1
- package/dist/runtime/replay-fixture.d.ts +5 -5
- package/dist/runtime/replay-fixture.js +3 -3
- package/dist/runtime/replay-provider.d.ts +4 -4
- package/dist/runtime/replay-provider.js +1 -1
- package/dist/runtime/runner.d.ts +8 -6
- package/dist/runtime/runner.js +23 -6
- package/dist/runtime/session-log.d.ts +9 -4
- package/dist/runtime/session-log.js +3 -2
- package/dist/runtime/session-repair.d.ts +3 -4
- package/dist/runtime/session-repair.js +1 -4
- package/dist/runtime/verifiable-report.d.ts +2 -2
- package/dist/runtime/verifiable-report.js +2 -2
- package/dist/skills/loader.d.ts +1 -1
- package/dist/tools/index.d.ts +2 -2
- package/dist/types/agent.d.ts +5 -5
- package/dist/types.d.ts +20 -11
- package/package.json +2 -2
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { materialOptions } from "./request-plan.js";
|
|
2
|
+
/** JSON value snapshots sever aliases to mutable provider replay and continuation state. */
|
|
3
|
+
export function requestSnapshot(value) {
|
|
4
|
+
return value === undefined ? value : JSON.parse(JSON.stringify(value));
|
|
5
|
+
}
|
|
6
|
+
/** A fallback can freeze only JSON state without silently discarding execution semantics. */
|
|
7
|
+
function assertJsonRunState(state) {
|
|
8
|
+
if (state === undefined)
|
|
9
|
+
return;
|
|
10
|
+
const seen = new WeakSet();
|
|
11
|
+
const reject = (path) => {
|
|
12
|
+
throw new TypeError(`Custom provider state at ${path} is not losslessly JSON representable; implement prepareRequest() for opaque state`);
|
|
13
|
+
};
|
|
14
|
+
const visit = (value, path) => {
|
|
15
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
16
|
+
return;
|
|
17
|
+
if (typeof value === "number") {
|
|
18
|
+
if (!Number.isFinite(value) || Object.is(value, -0))
|
|
19
|
+
reject(path);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (typeof value !== "object")
|
|
23
|
+
reject(path);
|
|
24
|
+
const object = value;
|
|
25
|
+
if (seen.has(object))
|
|
26
|
+
reject(path);
|
|
27
|
+
seen.add(object);
|
|
28
|
+
const array = Array.isArray(object);
|
|
29
|
+
if (!array && Object.getPrototypeOf(object) !== Object.prototype && Object.getPrototypeOf(object) !== null)
|
|
30
|
+
reject(path);
|
|
31
|
+
if (Object.getOwnPropertySymbols(object).length)
|
|
32
|
+
reject(path);
|
|
33
|
+
const descriptors = Object.getOwnPropertyDescriptors(object);
|
|
34
|
+
if (array) {
|
|
35
|
+
const values = object;
|
|
36
|
+
for (let index = 0; index < values.length; index++) {
|
|
37
|
+
if (!Object.hasOwn(descriptors, String(index)))
|
|
38
|
+
reject(`${path}[${index}]`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
42
|
+
if (array && key === "length")
|
|
43
|
+
continue;
|
|
44
|
+
if (array && (!/^(0|[1-9]\d*)$/.test(key) || Number(key) >= object.length))
|
|
45
|
+
reject(`${path}.${key}`);
|
|
46
|
+
if (!descriptor.enumerable || !("value" in descriptor))
|
|
47
|
+
reject(`${path}.${key}`);
|
|
48
|
+
visit(descriptor.value, `${path}.${key}`);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
visit(state, "state");
|
|
52
|
+
}
|
|
53
|
+
export function prepareProviderRequest(provider, context, tools, options, state) {
|
|
54
|
+
if (provider.prepareRequest)
|
|
55
|
+
return provider.prepareRequest(context, tools, options, state);
|
|
56
|
+
assertJsonRunState(state);
|
|
57
|
+
const input = requestSnapshot({ context, tools, options, state });
|
|
58
|
+
const replay = context.turns.map(message => provider.peekProviderReplay?.(message) ?? null);
|
|
59
|
+
const frozenState = input.state;
|
|
60
|
+
return {
|
|
61
|
+
scope: "adapter_input",
|
|
62
|
+
request: requestSnapshot({ context: input.context, tools: input.tools, options: materialOptions(input.options ?? {}), replay }),
|
|
63
|
+
state: requestSnapshot(frozenState ?? null),
|
|
64
|
+
...(provider.countTokens ? { countTokens: () => {
|
|
65
|
+
const counted = requestSnapshot(input);
|
|
66
|
+
return provider.countTokens(counted.context, counted.tools, counted.options, counted.state);
|
|
67
|
+
} } : {}),
|
|
68
|
+
async *stream(signal) {
|
|
69
|
+
// Keep the run-state object's identity while restoring the frozen preflight input.
|
|
70
|
+
if (state && frozenState && typeof state === "object" && typeof frozenState === "object") {
|
|
71
|
+
for (const key of Object.keys(state))
|
|
72
|
+
delete state[key];
|
|
73
|
+
Object.assign(state, requestSnapshot(frozenState));
|
|
74
|
+
}
|
|
75
|
+
yield* provider.stream(input.context, input.tools, input.options, state ?? frozenState, signal);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProviderMessage, ProviderReplay, ProviderRunState, ProviderUsage, StreamEvent } from "../types.js";
|
|
2
2
|
import type { CanonicalAdapterInput } from "./content-normalization.js";
|
|
3
3
|
import type { GenerationProtocol, ProtocolRuntimeCapabilities } from "./protocol-capabilities.js";
|
|
4
4
|
export { GEMINI_PROTOCOL_CAPABILITIES, OLLAMA_PROTOCOL_CAPABILITIES, } from "./protocol-capabilities.js";
|
|
@@ -19,7 +19,7 @@ export interface ProtocolAdapter<TRequest, TCompleteResponse, TStreamChunk, TStr
|
|
|
19
19
|
readonly protocolCapabilities: ProtocolRuntimeCapabilities;
|
|
20
20
|
buildRequest(input: CanonicalAdapterInput): TRequest;
|
|
21
21
|
decodeComplete(raw: TCompleteResponse, input: AdapterDecodeInput): {
|
|
22
|
-
message:
|
|
22
|
+
message: ProviderMessage;
|
|
23
23
|
replay?: ProviderReplay;
|
|
24
24
|
};
|
|
25
25
|
createStreamState(input: AdapterStreamInput): TStreamState;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProviderMessage, ProviderDescriptor, ProviderReplay, RenderedContext, ReplayabilityAssessment } from "../types.js";
|
|
2
2
|
export type { ReplayabilityAssessment };
|
|
3
3
|
export declare class ProviderReplayValidationError extends Error {
|
|
4
4
|
constructor(message: string);
|
|
@@ -20,7 +20,7 @@ export interface OpenAIChatReplayValidationOptions {
|
|
|
20
20
|
* rather than fail outright.
|
|
21
21
|
*/
|
|
22
22
|
degradeMissingReasoning?: boolean;
|
|
23
|
-
replayForAssistant?: (message: Pick<
|
|
23
|
+
replayForAssistant?: (message: Pick<ProviderMessage, "content" | "toolCalls">) => ProviderReplay | Record<string, unknown> | undefined;
|
|
24
24
|
}
|
|
25
25
|
export declare function validateOpenAIChatReplay(context: RenderedContext, options?: OpenAIChatReplayValidationOptions): void;
|
|
26
26
|
/**
|
|
@@ -29,4 +29,4 @@ export declare function validateOpenAIChatReplay(context: RenderedContext, optio
|
|
|
29
29
|
* embedder decide per-candidate whether to keep thinking on, disable it, or
|
|
30
30
|
* skip the candidate — before sending.
|
|
31
31
|
*/
|
|
32
|
-
export declare function assessReasoningReplay(turns:
|
|
32
|
+
export declare function assessReasoningReplay(turns: ProviderMessage[], options: Pick<OpenAIChatReplayValidationOptions, "replayForAssistant">): ReplayabilityAssessment;
|
|
@@ -7,6 +7,11 @@ export interface ProviderRequestEndpoint {
|
|
|
7
7
|
}
|
|
8
8
|
/** One provider-visible request, deliberately excluding credentials and transport-only retries. */
|
|
9
9
|
export interface ProviderRequestPlan {
|
|
10
|
+
execution?: {
|
|
11
|
+
scope: "encoded_body" | "adapter_input";
|
|
12
|
+
request: unknown;
|
|
13
|
+
state: unknown;
|
|
14
|
+
};
|
|
10
15
|
providerId: string;
|
|
11
16
|
modelId: string;
|
|
12
17
|
endpoint: ProviderRequestEndpoint;
|
|
@@ -79,7 +84,7 @@ export declare function createProviderRequestPlanForProvider(provider: {
|
|
|
79
84
|
baseURL?: string;
|
|
80
85
|
};
|
|
81
86
|
};
|
|
82
|
-
}, context: RenderedContext, tools: ToolSchema[], options?: Record<string, unknown
|
|
87
|
+
}, context: RenderedContext, tools: ToolSchema[], options?: Record<string, unknown>, execution?: ProviderRequestPlan["execution"]): ProviderRequestPlan;
|
|
83
88
|
/**
|
|
84
89
|
* P4 §1.3: the resolved route one provider execution is pinned to. Content-addressed
|
|
85
90
|
* (`routeId` = stable hash of every field except `capabilitiesRef`); the capability table's
|
|
@@ -87,6 +92,7 @@ export declare function createProviderRequestPlanForProvider(provider: {
|
|
|
87
92
|
* never a copy.
|
|
88
93
|
*/
|
|
89
94
|
export interface ResolvedProviderRoute {
|
|
95
|
+
request_fingerprint_scope?: "encoded_body" | "adapter_input";
|
|
90
96
|
routeId: string;
|
|
91
97
|
provider: string;
|
|
92
98
|
protocol: GenerationProtocol;
|
|
@@ -127,3 +133,4 @@ export declare function measurementForPlan(plan: Pick<ProviderRequestPlan, "fing
|
|
|
127
133
|
export declare function normalizeProviderUsage(usage: ProviderUsage): NormalizedProviderUsage;
|
|
128
134
|
/** Cost is derived only from an explicit, time-valid host snapshot; otherwise it stays unknown. */
|
|
129
135
|
export declare function priceProviderUsage(usage: NormalizedProviderUsage, snapshot: PricingSnapshot, observedAt?: string | Date): CostObservation;
|
|
136
|
+
export declare function materialOptions(options: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -13,6 +13,7 @@ export function createProviderRequestPlan(input) {
|
|
|
13
13
|
context: clone(input.context),
|
|
14
14
|
tools: clone(input.tools),
|
|
15
15
|
options,
|
|
16
|
+
...(input.execution ? { execution: clone(input.execution) } : {}),
|
|
16
17
|
};
|
|
17
18
|
const stablePrefix = {
|
|
18
19
|
providerId: plan.providerId,
|
|
@@ -29,7 +30,7 @@ export function createProviderRequestPlan(input) {
|
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
32
|
/** Build the plan from a resolved provider when the runner only has the public provider object. */
|
|
32
|
-
export function createProviderRequestPlanForProvider(provider, context, tools, options) {
|
|
33
|
+
export function createProviderRequestPlanForProvider(provider, context, tools, options, execution) {
|
|
33
34
|
const descriptor = provider.descriptor?.() ?? { provider: "unknown", protocol: "unknown", model: "unknown" };
|
|
34
35
|
const identity = provider.requestPlanIdentity?.();
|
|
35
36
|
return createProviderRequestPlan({
|
|
@@ -42,7 +43,7 @@ export function createProviderRequestPlanForProvider(provider, context, tools, o
|
|
|
42
43
|
},
|
|
43
44
|
context,
|
|
44
45
|
tools,
|
|
45
|
-
options,
|
|
46
|
+
options, execution,
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
49
|
const KNOWN_GENERATION_PROTOCOLS = new Set([
|
|
@@ -184,7 +185,7 @@ export function priceProviderUsage(usage, snapshot, observedAt = new Date()) {
|
|
|
184
185
|
+ (usage.reasoningTokens ?? 0) * (rates.reasoning ?? 0)) / 1_000_000;
|
|
185
186
|
return { source: "snapshot", currency: snapshot.currency, amount, pricingVersion: snapshot.version };
|
|
186
187
|
}
|
|
187
|
-
function materialOptions(options) {
|
|
188
|
+
export function materialOptions(options) {
|
|
188
189
|
return sanitizeMaterialValue(options);
|
|
189
190
|
}
|
|
190
191
|
function sanitizeEndpoint(endpoint) {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProviderMessage } from "../types.js";
|
|
2
2
|
export interface ArchiveStore {
|
|
3
|
-
write(sessionId: string, seq: number, messages:
|
|
4
|
-
read(archiveRef: string): Promise<
|
|
3
|
+
write(sessionId: string, seq: number, messages: ProviderMessage[]): Promise<string>;
|
|
4
|
+
read(archiveRef: string): Promise<ProviderMessage[]>;
|
|
5
5
|
}
|
|
6
6
|
export declare class NullArchiveStore implements ArchiveStore {
|
|
7
|
-
write(_sessionId: string, _seq: number, _messages:
|
|
8
|
-
read(_archiveRef: string): Promise<
|
|
7
|
+
write(_sessionId: string, _seq: number, _messages: ProviderMessage[]): Promise<string>;
|
|
8
|
+
read(_archiveRef: string): Promise<ProviderMessage[]>;
|
|
9
9
|
}
|
|
10
10
|
export declare class FileArchiveStore implements ArchiveStore {
|
|
11
11
|
private readonly root;
|
|
12
12
|
constructor(root: string);
|
|
13
|
-
write(sessionId: string, seq: number, messages:
|
|
14
|
-
read(archiveRef: string): Promise<
|
|
13
|
+
write(sessionId: string, seq: number, messages: ProviderMessage[]): Promise<string>;
|
|
14
|
+
read(archiveRef: string): Promise<ProviderMessage[]>;
|
|
15
15
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CanonicalKernelInstance, CanonicalRestoreCost } from "../kernel.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ProviderMessage } from "../types.js";
|
|
3
3
|
import { type InstalledCheckpoint, type KernelJournal } from "./kernel-journal.js";
|
|
4
4
|
import { type KernelObservation, type KernelRunnerAction } from "./kernel-step.js";
|
|
5
5
|
export declare const MAX_CHAIN_POSITION = 1000000000000;
|
|
@@ -37,7 +37,7 @@ export interface CanonicalTransition {
|
|
|
37
37
|
replayed: boolean;
|
|
38
38
|
}
|
|
39
39
|
export declare function canonicalUnsupportedEffectResolution(effectId: string, effectKind: string): CanonicalKernelInput;
|
|
40
|
-
/** Adapt the
|
|
40
|
+
/** Adapt the core-owned KernelProjection JSON into the Node action surface. */
|
|
41
41
|
export declare function canonicalActionFromProjectionJson(raw: string): KernelRunnerAction | null;
|
|
42
42
|
export declare class CanonicalKernelRejectedError extends Error {
|
|
43
43
|
readonly fault: Record<string, unknown>;
|
|
@@ -85,6 +85,7 @@ export interface CanonicalRunnerRuntimeOptions {
|
|
|
85
85
|
maxTurns?: number;
|
|
86
86
|
maxTotalTokens?: number;
|
|
87
87
|
maxWallMs?: number;
|
|
88
|
+
artifactSetDigest?: string;
|
|
88
89
|
memoryBindingId?: string;
|
|
89
90
|
persistPayload?: (callId: string, content: string, previewBytes: number) => Promise<{
|
|
90
91
|
payloadRef: string;
|
|
@@ -119,7 +120,7 @@ export declare class CanonicalRunnerRuntime {
|
|
|
119
120
|
isTerminal(): boolean;
|
|
120
121
|
recoveryContentBytes(): number;
|
|
121
122
|
preservedRefs(): string[];
|
|
122
|
-
drainNewMessages():
|
|
123
|
+
drainNewMessages(): ProviderMessage[];
|
|
123
124
|
drainHostObservations(): KernelObservationLike[];
|
|
124
125
|
terminal(): Record<string, unknown> | undefined;
|
|
125
126
|
localSubagentsSpawned(): number;
|
|
@@ -40,7 +40,7 @@ export function canonicalUnsupportedEffectResolution(effectId, effectKind) {
|
|
|
40
40
|
},
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
-
/** The only ABI
|
|
43
|
+
/** The only ABI planned-step → Node host-action projection. */
|
|
44
44
|
function canonicalDoneFromTerminal(terminal) {
|
|
45
45
|
const usage = asObject(terminal.usage);
|
|
46
46
|
let termination = String(terminal.kind ?? "failed");
|
|
@@ -80,7 +80,7 @@ function canonicalDoneFromTerminal(terminal) {
|
|
|
80
80
|
termination = asObject(terminal.failure).code === "provider_recovery_exhausted" ? "context_overflow" : "error";
|
|
81
81
|
return { kind: "done", effectId: "", result: { termination, turnsUsed, totalTokensUsed: totalUsageTokens(terminal) } };
|
|
82
82
|
}
|
|
83
|
-
/** Adapt the
|
|
83
|
+
/** Adapt the core-owned KernelProjection JSON into the Node action surface. */
|
|
84
84
|
export function canonicalActionFromProjectionJson(raw) {
|
|
85
85
|
const projection = asObject(JSON.parse(raw));
|
|
86
86
|
const state = String(projection.state ?? "idle");
|
|
@@ -120,6 +120,7 @@ export function canonicalActionFromProjectionJson(raw) {
|
|
|
120
120
|
kind: "call_provider",
|
|
121
121
|
effectId,
|
|
122
122
|
context: renderedContextToSdk(context),
|
|
123
|
+
contextEffect: payload,
|
|
123
124
|
tools: (Array.isArray(payload.tools) ? payload.tools : []).map(raw => {
|
|
124
125
|
const tool = asObject(raw);
|
|
125
126
|
return {
|
|
@@ -682,6 +683,9 @@ export class CanonicalRunnerRuntime {
|
|
|
682
683
|
this.host = new CanonicalKernelHost(kernel, journal, operationId);
|
|
683
684
|
this.memoryBindingId = options.memoryBindingId ?? "node-memory";
|
|
684
685
|
this.config = {
|
|
686
|
+
...(options.artifactSetDigest
|
|
687
|
+
? { artifact_set_binding: { artifact_set_digest: options.artifactSetDigest } }
|
|
688
|
+
: {}),
|
|
685
689
|
execution_policy: {
|
|
686
690
|
max_context_tokens: options.maxContextTokens,
|
|
687
691
|
...(options.maxTurns !== undefined ? { max_turns: options.maxTurns } : {}),
|
|
@@ -856,12 +860,16 @@ export class CanonicalRunnerRuntime {
|
|
|
856
860
|
}
|
|
857
861
|
case "tool_results": {
|
|
858
862
|
const results = [];
|
|
863
|
+
const measurements = [];
|
|
859
864
|
for (const value of Array.isArray(event.results) ? event.results : []) {
|
|
860
865
|
const result = asObject(value);
|
|
861
866
|
const callId = String(result.call_id ?? "");
|
|
862
867
|
const output = String(result.output ?? "");
|
|
863
868
|
const isError = Boolean(result.is_error);
|
|
864
869
|
const disposition = result.is_fatal ? "fatal" : "recoverable";
|
|
870
|
+
if (result.token_count !== null && result.token_count !== undefined) {
|
|
871
|
+
measurements.push({ call_id: callId, tokens: Number(result.token_count) });
|
|
872
|
+
}
|
|
865
873
|
const bytes = Buffer.byteLength(output, "utf8");
|
|
866
874
|
if (bytes > this.payloadInlineThreshold && this.options.persistPayload) {
|
|
867
875
|
const persisted = await this.options.persistPayload(callId, output, this.payloadPreviewBytes);
|
|
@@ -884,15 +892,16 @@ export class CanonicalRunnerRuntime {
|
|
|
884
892
|
output,
|
|
885
893
|
...(isError ? { is_error: true } : {}),
|
|
886
894
|
disposition,
|
|
887
|
-
...(result.token_count !== null && result.token_count !== undefined
|
|
888
|
-
? { tokens: Number(result.token_count) }
|
|
889
|
-
: {}),
|
|
890
895
|
},
|
|
891
896
|
});
|
|
892
897
|
}
|
|
893
898
|
this.newMessages.push({ role: "tool", content: output, toolCalls: [] });
|
|
894
899
|
}
|
|
895
|
-
input = this.succeededEffect(event, {
|
|
900
|
+
input = this.succeededEffect(event, {
|
|
901
|
+
kind: "tools",
|
|
902
|
+
results,
|
|
903
|
+
...(measurements.length > 0 ? { measurements } : {}),
|
|
904
|
+
});
|
|
896
905
|
break;
|
|
897
906
|
}
|
|
898
907
|
case "approval_result":
|
|
@@ -1086,7 +1095,7 @@ export class CanonicalRunnerRuntime {
|
|
|
1086
1095
|
input = { kind: "host_control", command: this.canonicalCapabilityCommand(asObject(event.command)) };
|
|
1087
1096
|
break;
|
|
1088
1097
|
case "add_history_message":
|
|
1089
|
-
throw new Error("running ABI
|
|
1098
|
+
throw new Error("running ABI operations accept history only through effects or external events");
|
|
1090
1099
|
default:
|
|
1091
1100
|
throw new Error(`Node host fact has no canonical ABI input: ${String(event.kind)}`);
|
|
1092
1101
|
}
|
|
@@ -1156,7 +1165,7 @@ export class CanonicalRunnerRuntime {
|
|
|
1156
1165
|
}
|
|
1157
1166
|
}
|
|
1158
1167
|
currentAction() {
|
|
1159
|
-
return canonicalActionFromProjectionJson(this.host.kernel.
|
|
1168
|
+
return canonicalActionFromProjectionJson(this.host.kernel.projectionJson());
|
|
1160
1169
|
}
|
|
1161
1170
|
pendingEffects() {
|
|
1162
1171
|
return JSON.parse(this.host.kernel.pendingEffectsJson());
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RecordedPromptMeasurement, ResolvedProviderRoute } from "../providers/request-plan.js";
|
|
2
|
+
import type { ContextExecutionInput, ContextPlan, ContextState, EvaluationContextBinding } from "./evolution.js";
|
|
3
|
+
/** Host evidence completing the kernel's immutable context candidate. */
|
|
4
|
+
export interface ContextProviderPreparationRequest {
|
|
5
|
+
readonly effect: Record<string, unknown>;
|
|
6
|
+
readonly request_fingerprint: string;
|
|
7
|
+
readonly provider_route: ResolvedProviderRoute;
|
|
8
|
+
readonly prompt_measurement: RecordedPromptMeasurement;
|
|
9
|
+
}
|
|
10
|
+
export interface ContextPrepared {
|
|
11
|
+
readonly state: ContextState;
|
|
12
|
+
readonly provider_route: ResolvedProviderRoute;
|
|
13
|
+
readonly prompt_measurement: RecordedPromptMeasurement;
|
|
14
|
+
readonly execution_input: ContextExecutionInput;
|
|
15
|
+
readonly plan: ContextPlan;
|
|
16
|
+
readonly binding: EvaluationContextBinding;
|
|
17
|
+
}
|
|
18
|
+
export type ContextPrepareJson = (request: string) => string;
|
|
19
|
+
export type ContextVerifyJson = (request: string) => string;
|
|
20
|
+
/** All validation and content addressing are delegated to the Rust authority. */
|
|
21
|
+
export declare function createContextPreparationAdapter(prepareJson: ContextPrepareJson, verifyJson: ContextVerifyJson): {
|
|
22
|
+
verify(effect: Record<string, unknown>, preparation: ContextPrepared): boolean;
|
|
23
|
+
prepare(request: ContextProviderPreparationRequest): ContextPrepared;
|
|
24
|
+
};
|
|
25
|
+
export declare function createNativeContextPreparationAdapter(): {
|
|
26
|
+
verify(effect: Record<string, unknown>, preparation: ContextPrepared): boolean;
|
|
27
|
+
prepare(request: ContextProviderPreparationRequest): ContextPrepared;
|
|
28
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getKernel } from "../kernel.js";
|
|
2
|
+
/** All validation and content addressing are delegated to the Rust authority. */
|
|
3
|
+
export function createContextPreparationAdapter(prepareJson, verifyJson) {
|
|
4
|
+
return {
|
|
5
|
+
verify(effect, preparation) {
|
|
6
|
+
return JSON.parse(verifyJson(JSON.stringify({ effect, preparation })));
|
|
7
|
+
},
|
|
8
|
+
prepare(request) {
|
|
9
|
+
return JSON.parse(prepareJson(JSON.stringify(request)));
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function createNativeContextPreparationAdapter() {
|
|
14
|
+
const kernel = getKernel();
|
|
15
|
+
return createContextPreparationAdapter(kernel.contextPrepareJson, kernel.contextVerifyJson);
|
|
16
|
+
}
|
package/dist/runtime/eval.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* The judge is a single LLM call: build the eval prompt → stream → parse verdict. No retry loop,
|
|
10
10
|
* no skill extraction, no loop state. Use `AttemptLoop` if you want the retry/refine flow.
|
|
11
11
|
*/
|
|
12
|
-
import type { LLMProvider,
|
|
12
|
+
import type { LLMProvider, ProviderMessage } from "../types.js";
|
|
13
13
|
export interface Criterion {
|
|
14
14
|
/** The criterion text the judge evaluates against. */
|
|
15
15
|
text: string;
|
|
@@ -52,7 +52,7 @@ export interface JudgeArgs {
|
|
|
52
52
|
* Exposed in case a caller wants to render the prompt without calling the LLM (e.g., dry-run cost
|
|
53
53
|
* estimation, fixture generation). For the common case, use `judge()`.
|
|
54
54
|
*/
|
|
55
|
-
export declare function buildEvalMessages(goal: string, criteria: Criterion[], result: string):
|
|
55
|
+
export declare function buildEvalMessages(goal: string, criteria: Criterion[], result: string): ProviderMessage[];
|
|
56
56
|
/** Parse a Verdict from raw judge-LLM text. Throws on schema mismatch. */
|
|
57
57
|
export declare function parseVerdict(text: string): Verdict;
|
|
58
58
|
/** The JSON Schema the kernel expects judge output to conform to. */
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/** Canonical artifact kinds accepted by the 0.2.70 Evolution Runtime. */
|
|
2
|
+
export type ArtifactKind = "runtime" | "skill" | "prompt" | "policy" | "toolset" | "bundle";
|
|
3
|
+
export interface ArtifactRef {
|
|
4
|
+
readonly kind: ArtifactKind;
|
|
5
|
+
readonly digest: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ArtifactManifest {
|
|
8
|
+
readonly kind: ArtifactKind;
|
|
9
|
+
readonly payload_digest: string;
|
|
10
|
+
readonly parents: readonly string[];
|
|
11
|
+
readonly toolchain_digest: string;
|
|
12
|
+
readonly scope: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ArtifactVersion {
|
|
15
|
+
readonly digest: string;
|
|
16
|
+
readonly manifest: ArtifactManifest;
|
|
17
|
+
}
|
|
18
|
+
export interface ArtifactSet {
|
|
19
|
+
readonly digest: string;
|
|
20
|
+
readonly artifacts: readonly ArtifactRef[];
|
|
21
|
+
}
|
|
22
|
+
export interface EvolutionProposal {
|
|
23
|
+
readonly digest: string;
|
|
24
|
+
readonly base_artifact_set: string;
|
|
25
|
+
readonly candidate_artifact_set: string;
|
|
26
|
+
readonly objective: string;
|
|
27
|
+
readonly change_manifest: string;
|
|
28
|
+
readonly proposer: string;
|
|
29
|
+
readonly constraints: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
export interface EvaluationContextBinding {
|
|
32
|
+
readonly digest: string;
|
|
33
|
+
readonly operation_id: string;
|
|
34
|
+
readonly execution_input: string;
|
|
35
|
+
readonly context_state: string;
|
|
36
|
+
readonly context_policy: string;
|
|
37
|
+
readonly context_plan: string;
|
|
38
|
+
readonly rendered_snapshot: string;
|
|
39
|
+
readonly prompt_measurement: string;
|
|
40
|
+
readonly provider_route: string;
|
|
41
|
+
readonly cache_prefix?: string;
|
|
42
|
+
}
|
|
43
|
+
export type ContextEntrySource = "system" | "knowledge" | "history" | "state" | "signal";
|
|
44
|
+
export type ContextPlanAction = "include" | "excerpt" | "collapse" | "page_out" | "omit";
|
|
45
|
+
export interface ContextEntryRef {
|
|
46
|
+
readonly entry_id: string;
|
|
47
|
+
readonly content_digest: string;
|
|
48
|
+
readonly source: ContextEntrySource;
|
|
49
|
+
readonly ordinal: number;
|
|
50
|
+
}
|
|
51
|
+
export interface ContextState {
|
|
52
|
+
readonly schema: "context/v1";
|
|
53
|
+
readonly generation: number;
|
|
54
|
+
readonly system: readonly ContextEntryRef[];
|
|
55
|
+
readonly knowledge: readonly ContextEntryRef[];
|
|
56
|
+
readonly history: readonly ContextEntryRef[];
|
|
57
|
+
readonly state: readonly ContextEntryRef[];
|
|
58
|
+
readonly task_state: string;
|
|
59
|
+
readonly signals: readonly string[];
|
|
60
|
+
readonly digest: string;
|
|
61
|
+
}
|
|
62
|
+
export interface ContextSelection {
|
|
63
|
+
readonly entry_id: string;
|
|
64
|
+
readonly action: ContextPlanAction;
|
|
65
|
+
readonly reason: string;
|
|
66
|
+
}
|
|
67
|
+
export interface ContextPlan {
|
|
68
|
+
readonly schema: "context/v1";
|
|
69
|
+
readonly plan_id: string;
|
|
70
|
+
readonly operation_id: string;
|
|
71
|
+
readonly step_id: string;
|
|
72
|
+
readonly state_digest: string;
|
|
73
|
+
readonly state_generation: number;
|
|
74
|
+
readonly runtime_inputs: string;
|
|
75
|
+
readonly policy_digest: string;
|
|
76
|
+
readonly provider_profile_digest: string;
|
|
77
|
+
readonly measurement_fingerprints: readonly string[];
|
|
78
|
+
readonly selections: readonly ContextSelection[];
|
|
79
|
+
readonly input_budget_tokens: number;
|
|
80
|
+
readonly projected_tokens: number;
|
|
81
|
+
readonly pressure_ppm: number;
|
|
82
|
+
readonly cache_prefix: {
|
|
83
|
+
readonly digest: string;
|
|
84
|
+
readonly entries: number;
|
|
85
|
+
} | null;
|
|
86
|
+
}
|
|
87
|
+
export interface ContextExecutionInput {
|
|
88
|
+
readonly schema: "context/v1";
|
|
89
|
+
readonly input_digest: string;
|
|
90
|
+
readonly operation_id: string;
|
|
91
|
+
readonly step_id: string;
|
|
92
|
+
readonly input_sequence: number;
|
|
93
|
+
readonly state_digest: string;
|
|
94
|
+
readonly policy_digest: string;
|
|
95
|
+
readonly plan_digest: string;
|
|
96
|
+
readonly rendered_snapshot: string;
|
|
97
|
+
readonly prompt_measurement: string;
|
|
98
|
+
readonly provider_route: string;
|
|
99
|
+
readonly cache_prefix: {
|
|
100
|
+
readonly digest: string;
|
|
101
|
+
readonly entries: number;
|
|
102
|
+
} | null;
|
|
103
|
+
}
|
|
104
|
+
export interface ContextPreparationRequest {
|
|
105
|
+
readonly operation_id: string;
|
|
106
|
+
readonly step_id: string;
|
|
107
|
+
readonly input_sequence: number;
|
|
108
|
+
readonly policy_digest: string;
|
|
109
|
+
readonly prompt_measurement: string;
|
|
110
|
+
readonly provider_route: string;
|
|
111
|
+
}
|
|
112
|
+
export interface EvaluationRun {
|
|
113
|
+
readonly digest: string;
|
|
114
|
+
readonly proposal: string;
|
|
115
|
+
readonly baseline_artifact_set: string;
|
|
116
|
+
readonly candidate_artifact_set: string;
|
|
117
|
+
readonly evaluator: string;
|
|
118
|
+
readonly dataset: string;
|
|
119
|
+
readonly operation_ids: readonly string[];
|
|
120
|
+
readonly contexts: readonly EvaluationContextBinding[];
|
|
121
|
+
readonly evidence_refs: readonly string[];
|
|
122
|
+
}
|
|
123
|
+
export interface EvaluationMetric {
|
|
124
|
+
readonly name: string;
|
|
125
|
+
readonly baseline: string;
|
|
126
|
+
readonly candidate: string;
|
|
127
|
+
readonly improved: boolean;
|
|
128
|
+
}
|
|
129
|
+
export interface EvaluationGate {
|
|
130
|
+
readonly name: string;
|
|
131
|
+
readonly required: boolean;
|
|
132
|
+
readonly passed: boolean;
|
|
133
|
+
}
|
|
134
|
+
export interface EvaluationFact {
|
|
135
|
+
readonly digest: string;
|
|
136
|
+
readonly evaluation: string;
|
|
137
|
+
readonly metrics: readonly EvaluationMetric[];
|
|
138
|
+
readonly gates: readonly EvaluationGate[];
|
|
139
|
+
readonly replay_passed: boolean;
|
|
140
|
+
}
|
|
141
|
+
export type PromotionOutcome = "promote" | "reject" | "hold";
|
|
142
|
+
export interface PromotionDecision {
|
|
143
|
+
readonly digest: string;
|
|
144
|
+
readonly proposal: string;
|
|
145
|
+
readonly evaluation_facts: readonly string[];
|
|
146
|
+
readonly policy: string;
|
|
147
|
+
readonly outcome: PromotionOutcome;
|
|
148
|
+
readonly selected_artifact_set: string;
|
|
149
|
+
}
|
|
150
|
+
export interface ActivationBinding {
|
|
151
|
+
readonly digest: string;
|
|
152
|
+
readonly operation_id: string;
|
|
153
|
+
readonly artifact_set: string;
|
|
154
|
+
readonly promotion_decision: string;
|
|
155
|
+
}
|
|
156
|
+
export interface EvolutionBundle {
|
|
157
|
+
readonly artifacts: readonly ArtifactVersion[];
|
|
158
|
+
readonly artifact_sets: readonly ArtifactSet[];
|
|
159
|
+
readonly proposals: readonly EvolutionProposal[];
|
|
160
|
+
readonly evaluations: readonly EvaluationRun[];
|
|
161
|
+
readonly facts: readonly EvaluationFact[];
|
|
162
|
+
readonly decisions: readonly PromotionDecision[];
|
|
163
|
+
readonly activations: readonly ActivationBinding[];
|
|
164
|
+
}
|
|
165
|
+
export type EvolutionVerdict = "pass" | "fail" | "unavailable";
|
|
166
|
+
export interface EvolutionViolation {
|
|
167
|
+
readonly code: string;
|
|
168
|
+
readonly detail: string;
|
|
169
|
+
}
|
|
170
|
+
export interface EvolutionReport {
|
|
171
|
+
readonly schema: "evolution-report/v1";
|
|
172
|
+
readonly verdict: EvolutionVerdict;
|
|
173
|
+
readonly violations: readonly EvolutionViolation[];
|
|
174
|
+
}
|
|
175
|
+
export type EvolutionValidateJson = (request: string) => string;
|
|
176
|
+
/** Host-owned persistence boundary. Implementations may use a CAS, database, or object store. */
|
|
177
|
+
export interface EvolutionStore {
|
|
178
|
+
loadBundle(): Promise<EvolutionBundle> | EvolutionBundle;
|
|
179
|
+
}
|
|
180
|
+
/** Create the SDK adapter backed by the Rust core E1–E8 validator. */
|
|
181
|
+
export declare function createEvolutionRuntimeAdapter(validateJson: EvolutionValidateJson): {
|
|
182
|
+
validate(bundle: EvolutionBundle): EvolutionReport;
|
|
183
|
+
};
|
|
184
|
+
/** Create the adapter from the native Rust binding. */
|
|
185
|
+
export declare function createNativeEvolutionRuntimeAdapter(): {
|
|
186
|
+
validate(bundle: EvolutionBundle): EvolutionReport;
|
|
187
|
+
};
|
|
188
|
+
/** Storage-neutral evolution handle. Artifact and ledger persistence remain host-owned. */
|
|
189
|
+
export declare class EvolutionRuntime {
|
|
190
|
+
private readonly adapter;
|
|
191
|
+
constructor(adapter: ReturnType<typeof createEvolutionRuntimeAdapter>);
|
|
192
|
+
validate(bundle: EvolutionBundle): EvolutionReport;
|
|
193
|
+
validateStore(store: EvolutionStore): Promise<EvolutionReport>;
|
|
194
|
+
activate(bundle: EvolutionBundle, operationId: string): ActivationBinding;
|
|
195
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getKernel } from "../kernel.js";
|
|
2
|
+
/** Create the SDK adapter backed by the Rust core E1–E8 validator. */
|
|
3
|
+
export function createEvolutionRuntimeAdapter(validateJson) {
|
|
4
|
+
return {
|
|
5
|
+
validate(bundle) {
|
|
6
|
+
return JSON.parse(validateJson(JSON.stringify(bundle)));
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/** Create the adapter from the native Rust binding. */
|
|
11
|
+
export function createNativeEvolutionRuntimeAdapter() {
|
|
12
|
+
return createEvolutionRuntimeAdapter(getKernel().evolutionValidateJson);
|
|
13
|
+
}
|
|
14
|
+
/** Storage-neutral evolution handle. Artifact and ledger persistence remain host-owned. */
|
|
15
|
+
export class EvolutionRuntime {
|
|
16
|
+
adapter;
|
|
17
|
+
constructor(adapter) {
|
|
18
|
+
this.adapter = adapter;
|
|
19
|
+
}
|
|
20
|
+
validate(bundle) { return this.adapter.validate(bundle); }
|
|
21
|
+
async validateStore(store) {
|
|
22
|
+
return this.validate(await store.loadBundle());
|
|
23
|
+
}
|
|
24
|
+
activate(bundle, operationId) {
|
|
25
|
+
const report = this.validate(bundle);
|
|
26
|
+
if (report.verdict !== "pass") {
|
|
27
|
+
throw new Error(`evolution bundle is not activatable: ${report.violations.map(v => v.code).join(", ")}`);
|
|
28
|
+
}
|
|
29
|
+
const activation = bundle.activations.find(value => value.operation_id === operationId);
|
|
30
|
+
if (!activation)
|
|
31
|
+
throw new Error(`no verified activation binding for operation ${operationId}`);
|
|
32
|
+
return activation;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -26,7 +26,7 @@ export interface ExecutionPlane {
|
|
|
26
26
|
/**
|
|
27
27
|
* Execute a batch of calls. Yields StreamEvents during execution.
|
|
28
28
|
* Guarantees exactly one `tool_result` event per call in `calls`.
|
|
29
|
-
* The runner collects those events to build
|
|
29
|
+
* The runner collects those events to build ToolExecutionResult[] for the kernel.
|
|
30
30
|
*/
|
|
31
31
|
executeAll(calls: ToolCall[], ctx: RunContext): AsyncIterable<StreamEvent>;
|
|
32
32
|
}
|