@lanefoundry/gatelane-sdk 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/candidate.d.ts +26 -0
- package/dist/candidate.d.ts.map +1 -0
- package/dist/candidate.js +41 -0
- package/dist/candidate.js.map +1 -0
- package/dist/capture.d.ts +105 -0
- package/dist/capture.d.ts.map +1 -0
- package/dist/capture.js +78 -0
- package/dist/capture.js.map +1 -0
- package/dist/dataset.d.ts +56 -0
- package/dist/dataset.d.ts.map +1 -0
- package/dist/dataset.js +35 -0
- package/dist/dataset.js.map +1 -0
- package/dist/gate.d.ts +81 -0
- package/dist/gate.d.ts.map +1 -0
- package/dist/gate.js +82 -0
- package/dist/gate.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/promotion.d.ts +82 -0
- package/dist/promotion.d.ts.map +1 -0
- package/dist/promotion.js +14 -0
- package/dist/promotion.js.map +1 -0
- package/dist/storage-fs.d.ts +27 -0
- package/dist/storage-fs.d.ts.map +1 -0
- package/dist/storage-fs.js +68 -0
- package/dist/storage-fs.js.map +1 -0
- package/dist/storage-http.d.ts +43 -0
- package/dist/storage-http.d.ts.map +1 -0
- package/dist/storage-http.js +112 -0
- package/dist/storage-http.js.map +1 -0
- package/dist/storage.d.ts +76 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +52 -0
- package/dist/storage.js.map +1 -0
- package/package.json +115 -4
- package/src/candidate.ts +76 -0
- package/src/capture.ts +153 -0
- package/src/dataset.ts +85 -0
- package/src/gate.ts +162 -0
- package/src/index.ts +16 -0
- package/src/promotion.ts +98 -0
- package/src/storage-fs.ts +76 -0
- package/src/storage-http.ts +143 -0
- package/src/storage.ts +97 -0
- package/README.md +0 -3
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Candidate types — any component swap in the agent's context that can be attacked.
|
|
3
|
+
*
|
|
4
|
+
* gatelane's gate treats all 10 as first-class. The GateReport
|
|
5
|
+
* carries the SHA of every candidate.
|
|
6
|
+
*
|
|
7
|
+
* @see docs/prd.md §5.3 — Candidate types table
|
|
8
|
+
*/
|
|
9
|
+
export type CandidateRef = {
|
|
10
|
+
/** Discriminator + identifier. Format: `<type>:<id>[@<version>]`. */
|
|
11
|
+
readonly ref: string;
|
|
12
|
+
/** SHA captured in the GateReport. */
|
|
13
|
+
readonly sha: string;
|
|
14
|
+
/** Optional human-readable label for reports. */
|
|
15
|
+
readonly label?: string;
|
|
16
|
+
};
|
|
17
|
+
export type CandidateType = 'model' | 'prompt' | 'skill' | 'config' | 'tool' | 'eval' | 'kb' | 'memory' | 'dispatcher' | 'guardrail';
|
|
18
|
+
/** Parse a candidate ref string like `tool:mcp-server-foo@1.2.0` into type + id + version. */
|
|
19
|
+
export declare function parseCandidateRef(ref: string): {
|
|
20
|
+
type: CandidateType;
|
|
21
|
+
id: string;
|
|
22
|
+
version?: string;
|
|
23
|
+
};
|
|
24
|
+
/** Compute a placeholder SHA for a candidate ref. Stub: SHA-256 of the ref string. */
|
|
25
|
+
export declare function shaOfCandidateRef(ref: string): Promise<string>;
|
|
26
|
+
//# sourceMappingURL=candidate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"candidate.d.ts","sourceRoot":"","sources":["../src/candidate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,qEAAqE;IACrE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,iDAAiD;IACjD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,aAAa,GACrB,OAAO,GACP,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,MAAM,GACN,MAAM,GACN,IAAI,GACJ,QAAQ,GACR,YAAY,GACZ,WAAW,CAAC;AAEhB,8FAA8F;AAC9F,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG;IAC9C,IAAI,EAAE,aAAa,CAAC;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CA6BA;AAED,sFAAsF;AACtF,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CASpE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Parse a candidate ref string like `tool:mcp-server-foo@1.2.0` into type + id + version. */
|
|
2
|
+
export function parseCandidateRef(ref) {
|
|
3
|
+
const colonIdx = ref.indexOf(':');
|
|
4
|
+
if (colonIdx < 0) {
|
|
5
|
+
throw new Error(`invalid candidate ref: ${ref} (expected <type>:<id>[@<version>])`);
|
|
6
|
+
}
|
|
7
|
+
const type = ref.slice(0, colonIdx);
|
|
8
|
+
const rest = ref.slice(colonIdx + 1);
|
|
9
|
+
const valid = [
|
|
10
|
+
'model',
|
|
11
|
+
'prompt',
|
|
12
|
+
'skill',
|
|
13
|
+
'config',
|
|
14
|
+
'tool',
|
|
15
|
+
'eval',
|
|
16
|
+
'kb',
|
|
17
|
+
'memory',
|
|
18
|
+
'dispatcher',
|
|
19
|
+
'guardrail',
|
|
20
|
+
];
|
|
21
|
+
if (!valid.includes(type)) {
|
|
22
|
+
throw new Error(`invalid candidate type: ${type} (expected one of ${valid.join(', ')})`);
|
|
23
|
+
}
|
|
24
|
+
const atIdx = rest.lastIndexOf('@');
|
|
25
|
+
if (atIdx < 0) {
|
|
26
|
+
return { type, id: rest };
|
|
27
|
+
}
|
|
28
|
+
return { type, id: rest.slice(0, atIdx), version: rest.slice(atIdx + 1) };
|
|
29
|
+
}
|
|
30
|
+
/** Compute a placeholder SHA for a candidate ref. Stub: SHA-256 of the ref string. */
|
|
31
|
+
export async function shaOfCandidateRef(ref) {
|
|
32
|
+
// v0.0.0-dev stub: deterministic placeholder so reports are reproducible.
|
|
33
|
+
// Real implementation in W2 will hash the actual artifact content.
|
|
34
|
+
const data = new TextEncoder().encode(ref);
|
|
35
|
+
const digest = await crypto.subtle.digest('SHA-256', data);
|
|
36
|
+
const hex = Array.from(new Uint8Array(digest))
|
|
37
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
38
|
+
.join('');
|
|
39
|
+
return `sha256:${hex}`;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=candidate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"candidate.js","sourceRoot":"","sources":["../src/candidate.ts"],"names":[],"mappings":"AA6BA,8FAA8F;AAC9F,MAAM,UAAU,iBAAiB,CAAC,GAAW;IAK3C,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,0BAA0B,GAAG,qCAAqC,CAAC,CAAC;IACtF,CAAC;IACD,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAkB,CAAC;IACrD,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;IACrC,MAAM,KAAK,GAAoB;QAC7B,OAAO;QACP,QAAQ;QACR,OAAO;QACP,QAAQ;QACR,MAAM;QACN,MAAM;QACN,IAAI;QACJ,QAAQ;QACR,YAAY;QACZ,WAAW;KACZ,CAAC;IACF,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,2BAA2B,IAAI,qBAAqB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACxE,CAAC;IACJ,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACpC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACd,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IAC5B,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;AAC5E,CAAC;AAED,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,GAAW;IACjD,0EAA0E;IAC1E,mEAAmE;IACnE,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC3D,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;SAC3C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAC3C,IAAI,CAAC,EAAE,CAAC,CAAC;IACZ,OAAO,UAAU,GAAG,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capture SDK — one-line instrumentation for agent calls.
|
|
3
|
+
*
|
|
4
|
+
* Wraps an LLM/tool/judge call so gatelane can observe (and later replay) it.
|
|
5
|
+
* Records go through the active StorageAdapter (in-memory by default; HTTP via
|
|
6
|
+
* HttpStorage for production; filesystem via FilesystemStorage for local dev).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { capture, setStorage, HttpStorage } from "@lanefoundry/gatelane-sdk";
|
|
11
|
+
*
|
|
12
|
+
* // One-time setup: point capture at the production Worker.
|
|
13
|
+
* setStorage(new HttpStorage({
|
|
14
|
+
* endpoint: process.env.GATELANE_ENDPOINT!,
|
|
15
|
+
* token: process.env.GATELANE_CAPTURE_TOKEN!,
|
|
16
|
+
* }));
|
|
17
|
+
*
|
|
18
|
+
* // Now every call site uses the same wrapper.
|
|
19
|
+
* const response = await capture({
|
|
20
|
+
* prompt: [{ role: "user", content: userInput }],
|
|
21
|
+
* model: "gpt-4o",
|
|
22
|
+
* metadata: { traceId: "...", agentVersion: "..." },
|
|
23
|
+
* }, async () => openai.chat.completions.create({ ... }));
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @see docs/prd.md §5.6 — SDK & API surface
|
|
27
|
+
*/
|
|
28
|
+
import type { DatasetSourceKind } from './dataset.js';
|
|
29
|
+
export type CaptureMetadata = {
|
|
30
|
+
readonly traceId?: string;
|
|
31
|
+
readonly agentVersion?: string;
|
|
32
|
+
readonly dataset?: string;
|
|
33
|
+
readonly source_kind?: DatasetSourceKind;
|
|
34
|
+
/** Free-form metadata. */
|
|
35
|
+
readonly [key: string]: unknown;
|
|
36
|
+
};
|
|
37
|
+
export type CaptureInput = {
|
|
38
|
+
readonly prompt: ReadonlyArray<{
|
|
39
|
+
role: string;
|
|
40
|
+
content: string;
|
|
41
|
+
}>;
|
|
42
|
+
readonly model?: string;
|
|
43
|
+
readonly metadata?: CaptureMetadata;
|
|
44
|
+
};
|
|
45
|
+
/** What the capture SDK stores per call. */
|
|
46
|
+
export type CapturedCall = {
|
|
47
|
+
readonly id: string;
|
|
48
|
+
readonly input: CaptureInput;
|
|
49
|
+
readonly output: unknown;
|
|
50
|
+
readonly started_at: string;
|
|
51
|
+
readonly completed_at: string;
|
|
52
|
+
readonly cost_usd: number;
|
|
53
|
+
readonly latency_ms: number;
|
|
54
|
+
/** Span kind: gate.replay, gate.compare, gate.promote, scan.attack, scan.judge. */
|
|
55
|
+
readonly span_kind?: string;
|
|
56
|
+
};
|
|
57
|
+
/** A single step in a multi-turn agent trace (user/assistant/tool). */
|
|
58
|
+
export type Turn = {
|
|
59
|
+
readonly role: 'system' | 'user' | 'assistant' | 'tool';
|
|
60
|
+
readonly content: string | null;
|
|
61
|
+
readonly tool_call_id?: string;
|
|
62
|
+
readonly name?: string;
|
|
63
|
+
readonly tool_calls?: ReadonlyArray<{
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
arguments: string;
|
|
67
|
+
}>;
|
|
68
|
+
readonly status?: 'ok' | 'error' | 'timeout';
|
|
69
|
+
readonly error?: {
|
|
70
|
+
type: string;
|
|
71
|
+
message: string;
|
|
72
|
+
stack?: string;
|
|
73
|
+
};
|
|
74
|
+
readonly span_kind?: string;
|
|
75
|
+
readonly span_id?: string;
|
|
76
|
+
readonly parent_span_id?: string;
|
|
77
|
+
readonly model?: string;
|
|
78
|
+
readonly started_at?: string;
|
|
79
|
+
readonly completed_at?: string;
|
|
80
|
+
readonly cost_usd?: number;
|
|
81
|
+
readonly latency_ms?: number;
|
|
82
|
+
readonly tokens_in?: number;
|
|
83
|
+
readonly tokens_out?: number;
|
|
84
|
+
};
|
|
85
|
+
export type CaptureOptions = {
|
|
86
|
+
readonly span_kind?: string;
|
|
87
|
+
/** If true, observe without writing. Used for SDK validation in prod. */
|
|
88
|
+
readonly dry_run?: boolean;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Wrap an LLM/tool/judge call so gatelane captures it.
|
|
92
|
+
*
|
|
93
|
+
* Production behavior: writes the record to the active StorageAdapter (HTTP → Worker → R2/D1).
|
|
94
|
+
* Tests: in-memory adapter keeps everything in process.
|
|
95
|
+
* Local dev without Worker: filesystem adapter.
|
|
96
|
+
*/
|
|
97
|
+
export declare function capture<T>(input: CaptureInput, call: () => Promise<T>, options?: CaptureOptions): Promise<T>;
|
|
98
|
+
/**
|
|
99
|
+
* Wrap an existing agent function so every call is captured.
|
|
100
|
+
* Sugar over {@link capture} for the common case.
|
|
101
|
+
*/
|
|
102
|
+
export declare function withCapture<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => Promise<TReturn>, options?: {
|
|
103
|
+
span_kind?: string;
|
|
104
|
+
}): (...args: TArgs) => Promise<TReturn>;
|
|
105
|
+
//# sourceMappingURL=capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEtD,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,iBAAiB,CAAC;IACzC,0BAA0B;IAC1B,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAC;CACrC,CAAC;AAEF,4CAA4C;AAC5C,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC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,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,yEAAyE;IACzE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACtB,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,CAAC,CAAC,CAkCZ;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,SAAS,OAAO,EAAE,EAAE,OAAO,EAC1D,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,EACxC,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACnC,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,CAWtC"}
|
package/dist/capture.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capture SDK — one-line instrumentation for agent calls.
|
|
3
|
+
*
|
|
4
|
+
* Wraps an LLM/tool/judge call so gatelane can observe (and later replay) it.
|
|
5
|
+
* Records go through the active StorageAdapter (in-memory by default; HTTP via
|
|
6
|
+
* HttpStorage for production; filesystem via FilesystemStorage for local dev).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { capture, setStorage, HttpStorage } from "@lanefoundry/gatelane-sdk";
|
|
11
|
+
*
|
|
12
|
+
* // One-time setup: point capture at the production Worker.
|
|
13
|
+
* setStorage(new HttpStorage({
|
|
14
|
+
* endpoint: process.env.GATELANE_ENDPOINT!,
|
|
15
|
+
* token: process.env.GATELANE_CAPTURE_TOKEN!,
|
|
16
|
+
* }));
|
|
17
|
+
*
|
|
18
|
+
* // Now every call site uses the same wrapper.
|
|
19
|
+
* const response = await capture({
|
|
20
|
+
* prompt: [{ role: "user", content: userInput }],
|
|
21
|
+
* model: "gpt-4o",
|
|
22
|
+
* metadata: { traceId: "...", agentVersion: "..." },
|
|
23
|
+
* }, async () => openai.chat.completions.create({ ... }));
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @see docs/prd.md §5.6 — SDK & API surface
|
|
27
|
+
*/
|
|
28
|
+
import { getStorage } from './storage.js';
|
|
29
|
+
/**
|
|
30
|
+
* Wrap an LLM/tool/judge call so gatelane captures it.
|
|
31
|
+
*
|
|
32
|
+
* Production behavior: writes the record to the active StorageAdapter (HTTP → Worker → R2/D1).
|
|
33
|
+
* Tests: in-memory adapter keeps everything in process.
|
|
34
|
+
* Local dev without Worker: filesystem adapter.
|
|
35
|
+
*/
|
|
36
|
+
export async function capture(input, call, options = {}) {
|
|
37
|
+
const started_at = new Date().toISOString();
|
|
38
|
+
const start = performance.now();
|
|
39
|
+
const output = await call();
|
|
40
|
+
const latency_ms = performance.now() - start;
|
|
41
|
+
const completed_at = new Date().toISOString();
|
|
42
|
+
if (options.dry_run) {
|
|
43
|
+
return output;
|
|
44
|
+
}
|
|
45
|
+
const record = {
|
|
46
|
+
id: crypto.randomUUID(),
|
|
47
|
+
input,
|
|
48
|
+
output,
|
|
49
|
+
started_at,
|
|
50
|
+
completed_at,
|
|
51
|
+
cost_usd: 0, // placeholder; real impl reads from model registry
|
|
52
|
+
latency_ms,
|
|
53
|
+
...(options.span_kind !== undefined ? { span_kind: options.span_kind } : {}),
|
|
54
|
+
};
|
|
55
|
+
// Fire-and-await: a capture write failure must not break the user's call.
|
|
56
|
+
// The Worker is the source of truth; SDK surfaces the error to stderr but
|
|
57
|
+
// does NOT throw, so a flaky network does not turn into a broken agent.
|
|
58
|
+
try {
|
|
59
|
+
await getStorage().write(record);
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
process.stderr.write(`[gatelane] capture write failed (record id=${record.id}): ${err instanceof Error ? err.message : String(err)}\n`);
|
|
63
|
+
}
|
|
64
|
+
return output;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Wrap an existing agent function so every call is captured.
|
|
68
|
+
* Sugar over {@link capture} for the common case.
|
|
69
|
+
*/
|
|
70
|
+
export function withCapture(fn, options = {}) {
|
|
71
|
+
return async (...args) => {
|
|
72
|
+
return capture({
|
|
73
|
+
prompt: [],
|
|
74
|
+
metadata: { args: args.length },
|
|
75
|
+
}, () => fn(...args), options);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.js","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AA2D1C;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,KAAmB,EACnB,IAAsB,EACtB,UAA0B,EAAE;IAE5B,MAAM,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC5C,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;IAC5B,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IAC7C,MAAM,YAAY,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAE9C,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,MAAM,GAAiB;QAC3B,EAAE,EAAE,MAAM,CAAC,UAAU,EAAE;QACvB,KAAK;QACL,MAAM;QACN,UAAU;QACV,YAAY;QACZ,QAAQ,EAAE,CAAC,EAAE,mDAAmD;QAChE,UAAU;QACV,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7E,CAAC;IAEF,0EAA0E;IAC1E,0EAA0E;IAC1E,wEAAwE;IACxE,IAAI,CAAC;QACH,MAAM,UAAU,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,8CAA8C,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAClH,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CACzB,EAAwC,EACxC,UAAkC,EAAE;IAEpC,OAAO,KAAK,EAAE,GAAG,IAAW,EAAoB,EAAE;QAChD,OAAO,OAAO,CACZ;YACE,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;SAChC,EACD,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EACjB,OAAO,CACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frozen dataset — content-addressed, immutable, versioned.
|
|
3
|
+
*
|
|
4
|
+
* A dataset is the input to a gate run. Three sources:
|
|
5
|
+
* - `scan` — curated attacks from garak / PyRIT / Promptfoo / DeepTeam
|
|
6
|
+
* - `prod` — frozen production slice from capture SDK
|
|
7
|
+
* - `compliance` — curated cases mapped to NIST / AI Basic Act / EU AI Act
|
|
8
|
+
*
|
|
9
|
+
* @see docs/prd.md §5.2 — Three dataset sources
|
|
10
|
+
*/
|
|
11
|
+
export type DatasetSourceKind = 'scan' | 'prod' | 'compliance';
|
|
12
|
+
export type FrozenDataset = {
|
|
13
|
+
/** Content hash of the dataset. */
|
|
14
|
+
readonly content_hash: string;
|
|
15
|
+
/** Schema version. */
|
|
16
|
+
readonly version: string;
|
|
17
|
+
/** Where this dataset came from. */
|
|
18
|
+
readonly source_kind: DatasetSourceKind;
|
|
19
|
+
/** Free-form reference to the upstream source (e.g. "garak@0.14.0+owasp-agentic-v1"). */
|
|
20
|
+
readonly source_ref: string;
|
|
21
|
+
/** Optional slice filter (time range, user cohort, etc.). */
|
|
22
|
+
readonly slice_filter?: Record<string, unknown>;
|
|
23
|
+
/** When the dataset was frozen. ISO 8601 timestamp. */
|
|
24
|
+
readonly frozen_at: string;
|
|
25
|
+
/** Number of items in the dataset. */
|
|
26
|
+
readonly item_count: number;
|
|
27
|
+
/** Items themselves (lazy-loaded). */
|
|
28
|
+
readonly items?: ReadonlyArray<DatasetItem>;
|
|
29
|
+
};
|
|
30
|
+
import type { Turn } from './capture.js';
|
|
31
|
+
export type DatasetItem = {
|
|
32
|
+
readonly id: string;
|
|
33
|
+
/** For red-team: the attack payload. For prod: the captured user input. For compliance: the test case. */
|
|
34
|
+
readonly input: unknown;
|
|
35
|
+
/** Optional expected outcome (for compliance / eval datasets). */
|
|
36
|
+
readonly expected?: unknown;
|
|
37
|
+
/** Full multi-turn agent trace from the original capture, when available.
|
|
38
|
+
* Includes tool calls, tool results, and intermediate assistant turns. */
|
|
39
|
+
readonly turns?: ReadonlyArray<Turn>;
|
|
40
|
+
/** Metadata from the original capture (model, cost, latency, etc.). */
|
|
41
|
+
readonly metadata?: Record<string, unknown>;
|
|
42
|
+
/** OWASP Agentic Top 10 mapping, if known. */
|
|
43
|
+
readonly mapped_asi?: 'ASI01' | 'ASI02' | 'ASI03' | 'ASI04' | 'ASI05' | 'ASI06' | 'ASI07' | 'ASI08' | 'ASI09' | 'ASI10';
|
|
44
|
+
/** MITRE ATLAS technique ID, if known. */
|
|
45
|
+
readonly mapped_atlas?: string;
|
|
46
|
+
};
|
|
47
|
+
/** Compute a placeholder content hash from item count + source ref. Stub. */
|
|
48
|
+
export declare function hashDataset(source_kind: DatasetSourceKind, source_ref: string, item_count: number): Promise<string>;
|
|
49
|
+
/** Build a stub FrozenDataset. Items optional. */
|
|
50
|
+
export declare function freezeDataset(args: {
|
|
51
|
+
source_kind: DatasetSourceKind;
|
|
52
|
+
source_ref: string;
|
|
53
|
+
slice_filter?: Record<string, unknown>;
|
|
54
|
+
items?: ReadonlyArray<DatasetItem>;
|
|
55
|
+
}): Promise<FrozenDataset>;
|
|
56
|
+
//# sourceMappingURL=dataset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset.d.ts","sourceRoot":"","sources":["../src/dataset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC;AAE/D,MAAM,MAAM,aAAa,GAAG;IAC1B,mCAAmC;IACnC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,sBAAsB;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,oCAAoC;IACpC,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAC;IACxC,yFAAyF;IACzF,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,6DAA6D;IAC7D,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChD,uDAAuD;IACvD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sCAAsC;IACtC,QAAQ,CAAC,UAAU,EAAE,M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set.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frozen dataset — content-addressed, immutable, versioned.
|
|
3
|
+
*
|
|
4
|
+
* A dataset is the input to a gate run. Three sources:
|
|
5
|
+
* - `scan` — curated attacks from garak / PyRIT / Promptfoo / DeepTeam
|
|
6
|
+
* - `prod` — frozen production slice from capture SDK
|
|
7
|
+
* - `compliance` — curated cases mapped to NIST / AI Basic Act / EU AI Act
|
|
8
|
+
*
|
|
9
|
+
* @see docs/prd.md §5.2 — Three dataset sources
|
|
10
|
+
*/
|
|
11
|
+
/** Compute a placeholder content hash from item count + source ref. Stub. */
|
|
12
|
+
export async function hashDataset(source_kind, source_ref, item_count) {
|
|
13
|
+
const data = new TextEncoder().encode(`${source_kind}|${source_ref}|${item_count}`);
|
|
14
|
+
const digest = await crypto.subtle.digest('SHA-256', data);
|
|
15
|
+
const hex = Array.from(new Uint8Array(digest))
|
|
16
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
17
|
+
.join('');
|
|
18
|
+
return `sha256:${hex}`;
|
|
19
|
+
}
|
|
20
|
+
/** Build a stub FrozenDataset. Items optional. */
|
|
21
|
+
export async function freezeDataset(args) {
|
|
22
|
+
const item_count = args.items?.length ?? 0;
|
|
23
|
+
const content_hash = await hashDataset(args.source_kind, args.source_ref, item_count);
|
|
24
|
+
return {
|
|
25
|
+
content_hash,
|
|
26
|
+
version: '0.0.0-dev',
|
|
27
|
+
source_kind: args.source_kind,
|
|
28
|
+
source_ref: args.source_ref,
|
|
29
|
+
...(args.slice_filter !== undefined ? { slice_filter: args.slice_filter } : {}),
|
|
30
|
+
frozen_at: new Date().toISOString(),
|
|
31
|
+
item_count,
|
|
32
|
+
...(args.items !== undefined ? { items: args.items } : {}),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=dataset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset.js","sourceRoot":"","sources":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ACV,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC3D,CAAC;AACJ,CAAC"}
|
package/dist/gate.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gate runner registry — the SDK defines the shape, the engine plugs in the impl.
|
|
3
|
+
*
|
|
4
|
+
* The default export is a stub that produces a deterministic mock. Production
|
|
5
|
+
* installs the engine package and calls {@link setGateRunner} once at process
|
|
6
|
+
* startup; subsequent {@link runGate} calls delegate to the engine.
|
|
7
|
+
*
|
|
8
|
+
* Decoupling: SDK doesn't depend on engine (engine depends on SDK). Test code
|
|
9
|
+
* can install a fake runner for deterministic gate outputs.
|
|
10
|
+
*
|
|
11
|
+
* @see docs/prd.md §5.1 — The gate
|
|
12
|
+
*/
|
|
13
|
+
import type { FrozenDataset } from './dataset.js';
|
|
14
|
+
import { type GateDecision, type GatePolicy, type GateReport } from './promotion.js';
|
|
15
|
+
export type GateRunArgs = {
|
|
16
|
+
readonly candidates: ReadonlyArray<string>;
|
|
17
|
+
readonly dataset: FrozenDataset;
|
|
18
|
+
readonly judges: ReadonlyArray<string>;
|
|
19
|
+
readonly baseline?: string;
|
|
20
|
+
readonly policy?: GatePolicy;
|
|
21
|
+
readonly approver?: string;
|
|
22
|
+
};
|
|
23
|
+
/** Lightweight replay row shape (mirrors engine's ReplayRow without importing it). */
|
|
24
|
+
export type GateReplayRow = {
|
|
25
|
+
readonly item_id: string;
|
|
26
|
+
readonly candidate_ref: string;
|
|
27
|
+
readonly response: {
|
|
28
|
+
readonly content: string;
|
|
29
|
+
readonly cost_usd: number;
|
|
30
|
+
readonly latency_ms: number;
|
|
31
|
+
readonly tokens_in?: number;
|
|
32
|
+
readonly tokens_out?: number;
|
|
33
|
+
readonly finish_reason?: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/** Lightweight judge verdict shape (mirrors engine's JudgeVerdict). */
|
|
37
|
+
export type GateJudgeVerdict = {
|
|
38
|
+
readonly candidate_ref: string;
|
|
39
|
+
readonly judge_ref: string;
|
|
40
|
+
readonly item_id: string;
|
|
41
|
+
readonly outcome: 'pass' | 'fail';
|
|
42
|
+
readonly score: number;
|
|
43
|
+
readonly reasoning?: string;
|
|
44
|
+
readonly cost_usd: number;
|
|
45
|
+
readonly latency_ms: number;
|
|
46
|
+
};
|
|
47
|
+
/** Lightweight per-candidate metric shape (mirrors engine's CandidateMetric). */
|
|
48
|
+
export type GateCandidateMetric = {
|
|
49
|
+
readonly mean_score: number;
|
|
50
|
+
readonly pass_rate: number;
|
|
51
|
+
readonly n_items: number;
|
|
52
|
+
readonly total_cost_usd: number;
|
|
53
|
+
readonly mean_latency_ms: number;
|
|
54
|
+
readonly aggregate_delta: number;
|
|
55
|
+
readonly cost_delta: number;
|
|
56
|
+
readonly latency_delta: number;
|
|
57
|
+
};
|
|
58
|
+
export type GateRunResult = {
|
|
59
|
+
readonly report: GateReport;
|
|
60
|
+
readonly decision: GateDecision;
|
|
61
|
+
/** Per-item replay outputs for every (candidate, item) pair. */
|
|
62
|
+
readonly replay_rows?: ReadonlyArray<GateReplayRow>;
|
|
63
|
+
/** Per-item judge verdicts with scores and reasoning. */
|
|
64
|
+
readonly verdicts?: ReadonlyArray<GateJudgeVerdict>;
|
|
65
|
+
/** Per-candidate aggregate metrics (mean_score, pass_rate, cost, latency, deltas). */
|
|
66
|
+
readonly candidate_metrics?: Readonly<Record<string, GateCandidateMetric>>;
|
|
67
|
+
};
|
|
68
|
+
/** Runner interface. The engine implements this and registers it. */
|
|
69
|
+
export type GateRunner = (args: GateRunArgs) => Promise<GateRunResult>;
|
|
70
|
+
/** Install the real engine runner. Idempotent; subsequent calls overwrite. */
|
|
71
|
+
export declare function setGateRunner(runner: GateRunner): void;
|
|
72
|
+
/** Reset to the stub runner. Tests use this. */
|
|
73
|
+
export declare function resetGateRunner(): void;
|
|
74
|
+
/**
|
|
75
|
+
* Run the gate. If an engine runner is installed, delegates to it.
|
|
76
|
+
* Otherwise produces a deterministic mock report (W1 behavior).
|
|
77
|
+
*/
|
|
78
|
+
export declare function runGate(args: GateRunArgs): Promise<GateRunResult>;
|
|
79
|
+
/** v0.0.0-dev stub — kept for SDK consumers that don't load the engine yet. */
|
|
80
|
+
export declare function stubRunGate(args: GateRunArgs): Promise<GateRunResult>;
|
|
81
|
+
//# sourceMappingURL=gate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../src/gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,UAAU,EAChB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC3C,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACvC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,sFAAsF;AACtF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE;QACjB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,UA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,CAAC;IACpD,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;IACpD,sFAAsF;IACtF,QAAQ,CAAC,iBAAiB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC;CAC5E,CAAC;AAEF,qEAAqE;AACrE,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;AAIvE,8EAA8E;AAC9E,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAEtD;AAED,gDAAgD;AAChD,wBAAgB,eAAe,IAAI,IAAI,CAEtC;AAED;;;GAGG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAKvE;AAED,+EAA+E;AAC/E,wBAAsB,WAAW,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAsD3E"}
|
package/dist/gate.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gate runner registry — the SDK defines the shape, the engine plugs in the impl.
|
|
3
|
+
*
|
|
4
|
+
* The default export is a stub that produces a deterministic mock. Production
|
|
5
|
+
* installs the engine package and calls {@link setGateRunner} once at process
|
|
6
|
+
* startup; subsequent {@link runGate} calls delegate to the engine.
|
|
7
|
+
*
|
|
8
|
+
* Decoupling: SDK doesn't depend on engine (engine depends on SDK). Test code
|
|
9
|
+
* can install a fake runner for deterministic gate outputs.
|
|
10
|
+
*
|
|
11
|
+
* @see docs/prd.md §5.1 — The gate
|
|
12
|
+
*/
|
|
13
|
+
import { shaOfCandidateRef } from './candidate.js';
|
|
14
|
+
import { DEFAULT_POLICY, } from './promotion.js';
|
|
15
|
+
let registeredRunner = null;
|
|
16
|
+
/** Install the real engine runner. Idempotent; subsequent calls overwrite. */
|
|
17
|
+
export function setGateRunner(runner) {
|
|
18
|
+
registeredRunner = runner;
|
|
19
|
+
}
|
|
20
|
+
/** Reset to the stub runner. Tests use this. */
|
|
21
|
+
export function resetGateRunner() {
|
|
22
|
+
registeredRunner = null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Run the gate. If an engine runner is installed, delegates to it.
|
|
26
|
+
* Otherwise produces a deterministic mock report (W1 behavior).
|
|
27
|
+
*/
|
|
28
|
+
export async function runGate(args) {
|
|
29
|
+
if (registeredRunner !== null) {
|
|
30
|
+
return registeredRunner(args);
|
|
31
|
+
}
|
|
32
|
+
return stubRunGate(args);
|
|
33
|
+
}
|
|
34
|
+
/** v0.0.0-dev stub — kept for SDK consumers that don't load the engine yet. */
|
|
35
|
+
export async function stubRunGate(args) {
|
|
36
|
+
const policy = args.policy ?? DEFAULT_POLICY;
|
|
37
|
+
const baseline = args.baseline ?? 'model:baseline';
|
|
38
|
+
const runId = crypto.randomUUID();
|
|
39
|
+
const reportId = crypto.randomUUID();
|
|
40
|
+
const candidate_shas = {};
|
|
41
|
+
for (const ref of args.candidates) {
|
|
42
|
+
candidate_shas[ref] = await shaOfCandidateRef(ref);
|
|
43
|
+
}
|
|
44
|
+
const judge_shas = {};
|
|
45
|
+
for (const judge of args.judges) {
|
|
46
|
+
judge_shas[judge] = await shaOfCandidateRef(judge);
|
|
47
|
+
}
|
|
48
|
+
const report = {
|
|
49
|
+
id: reportId,
|
|
50
|
+
gate_run_id: runId,
|
|
51
|
+
dataset_content_hash: args.dataset.content_hash,
|
|
52
|
+
dataset_version: args.dataset.version,
|
|
53
|
+
candidate_shas,
|
|
54
|
+
judge_shas,
|
|
55
|
+
scorer_code_sha: await shaOfCandidateRef('gatelane-sdk:scorer:v0.0.0-dev'),
|
|
56
|
+
baseline_metrics: { primary_score: 0.7 },
|
|
57
|
+
candidate_metrics: Object.fromEntries(args.candidates.map((ref) => [
|
|
58
|
+
ref,
|
|
59
|
+
{ aggregate_delta: 0.05, cost_delta: 0.02, latency_delta: 0.03 },
|
|
60
|
+
])),
|
|
61
|
+
judge_matrix: {
|
|
62
|
+
candidates: args.candidates,
|
|
63
|
+
judges: args.judges,
|
|
64
|
+
winners_by_judge: Object.fromEntries(args.candidates.map((ref) => [ref, args.judges.length])),
|
|
65
|
+
consensus_winners: args.candidates,
|
|
66
|
+
},
|
|
67
|
+
policy,
|
|
68
|
+
...(args.approver !== undefined ? { approver: args.approver } : {}),
|
|
69
|
+
timestamp: new Date().toISOString(),
|
|
70
|
+
signature: 'stub:unsigned',
|
|
71
|
+
};
|
|
72
|
+
const winner = args.candidates[0] ?? baseline;
|
|
73
|
+
const decision = policy.approval_required
|
|
74
|
+
? { action: 'hold_for_review', reason: 'approval_required' }
|
|
75
|
+
: {
|
|
76
|
+
action: 'pass',
|
|
77
|
+
winner,
|
|
78
|
+
reason: `stub: all candidates passed policy (min_delta=${policy.min_delta})`,
|
|
79
|
+
};
|
|
80
|
+
return { report, decision, replay_rows: [], verdicts: [], candidate_metrics: {} };
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=gate.js.map
|
package/dist/gate.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate.js","sourceRoot":"","sources":["../src/gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EACL,cAAc,GAIf,MAAM,gBAAgB,CAAC;AA+DxB,IAAI,gBAAgB,GAAsB,IAAI,CAAC;AAE/C,8EAA8E;AAC9E,MAAM,UAAU,aAAa,CAAC,MAAkB;IAC9C,gBAAgB,GAAG,MAAM,CAAC;AAC5B,CAAC;AAED,gDAAgD;AAChD,MAAM,UAAU,eAAe;IAC7B,gBAAgB,GAAG,IAAI,CAAC;AAC1B,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,IAAiB;IAC7C,IAAI,gBAAg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|
|
4
|
+
* Public API for v0.0.1-dev. Engine wires up across W1–W6 per docs/roadmap.md.
|
|
5
|
+
*
|
|
6
|
+
* @see docs/prd.md §5.6 — SDK & API surface
|
|
7
|
+
*/
|
|
8
|
+
export * from './capture.js';
|
|
9
|
+
export * from './candidate.js';
|
|
10
|
+
export * from './dataset.js';
|
|
11
|
+
export * from './gate.js';
|
|
12
|
+
export * from './promotion.js';
|
|
13
|
+
export * from './storage.js';
|
|
14
|
+
export * from './storage-fs.js';
|
|
15
|
+
export * from './storage-http.js';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lanefoundry/gatelane-sdk — promotion gate SDK.
|
|
3
|
+
*
|
|
4
|
+
* Public API for v0.0.1-dev. Engine wires up across W1–W6 per docs/roadmap.md.
|
|
5
|
+
*
|
|
6
|
+
* @see docs/prd.md §5.6 — SDK & API surface
|
|
7
|
+
*/
|
|
8
|
+
export * from './capture.js';
|
|
9
|
+
export * from './candidate.js';
|
|
10
|
+
export * from './dataset.js';
|
|
11
|
+
export * from './gate.js';
|
|
12
|
+
export * from './promotion.js';
|
|
13
|
+
export * from './storage.js';
|
|
14
|
+
export * from './storage-fs.js';
|
|
15
|
+
export * from './storage-http.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
|