@lanefoundry/gatelane-sdk 0.0.0-canary-b3f6165

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 (47) hide show
  1. package/LICENSE +190 -0
  2. package/dist/candidate.d.ts +26 -0
  3. package/dist/candidate.d.ts.map +1 -0
  4. package/dist/candidate.js +41 -0
  5. package/dist/candidate.js.map +1 -0
  6. package/dist/capture.d.ts +105 -0
  7. package/dist/capture.d.ts.map +1 -0
  8. package/dist/capture.js +78 -0
  9. package/dist/capture.js.map +1 -0
  10. package/dist/dataset.d.ts +56 -0
  11. package/dist/dataset.d.ts.map +1 -0
  12. package/dist/dataset.js +35 -0
  13. package/dist/dataset.js.map +1 -0
  14. package/dist/gate.d.ts +81 -0
  15. package/dist/gate.d.ts.map +1 -0
  16. package/dist/gate.js +82 -0
  17. package/dist/gate.js.map +1 -0
  18. package/dist/index.d.ts +16 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +16 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/promotion.d.ts +82 -0
  23. package/dist/promotion.d.ts.map +1 -0
  24. package/dist/promotion.js +14 -0
  25. package/dist/promotion.js.map +1 -0
  26. package/dist/storage-fs.d.ts +27 -0
  27. package/dist/storage-fs.d.ts.map +1 -0
  28. package/dist/storage-fs.js +68 -0
  29. package/dist/storage-fs.js.map +1 -0
  30. package/dist/storage-http.d.ts +43 -0
  31. package/dist/storage-http.d.ts.map +1 -0
  32. package/dist/storage-http.js +112 -0
  33. package/dist/storage-http.js.map +1 -0
  34. package/dist/storage.d.ts +76 -0
  35. package/dist/storage.d.ts.map +1 -0
  36. package/dist/storage.js +52 -0
  37. package/dist/storage.js.map +1 -0
  38. package/package.json +69 -0
  39. package/src/candidate.ts +76 -0
  40. package/src/capture.ts +153 -0
  41. package/src/dataset.ts +85 -0
  42. package/src/gate.ts +162 -0
  43. package/src/index.ts +16 -0
  44. package/src/promotion.ts +98 -0
  45. package/src/storage-fs.ts +76 -0
  46. package/src/storage-http.ts +143 -0
  47. package/src/storage.ts +97 -0
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Lanefoundry
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -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,GA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,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;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC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C5B,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"}
@@ -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,UAA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;;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,CA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IACvC,KAAK,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;CACpC,GAAG,OAAO,CAAC,aAAa,CAAC,CAazB"}
@@ -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":["../src/dataset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA0CH,6EAA6E;AAC7E,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,WAA8B,EAC9B,UAAkB,EAClB,UAAkB;IAElB,MAAM,IAAI,GAAG,IAAI,WAAW,EAA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
@@ -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;IACv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