@reeprov/client 0.0.0-stage → 0.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
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 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 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 those 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
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2024-present Reeprov Contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,94 @@
1
- # Temporary Holding Version
1
+ # @reeprov/client
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > Official TypeScript client SDK for [Reeprov](https://github.com/RaulMermans/Reeprov) — local-first debugging and reproducibility infrastructure for AI agents.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@reeprov/client.svg)](https://www.npmjs.com/package/@reeprov/client)
6
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
7
+
8
+ ---
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @reeprov/client
14
+ ```
15
+
16
+ Requires Node.js `>=20`.
17
+
18
+ ---
19
+
20
+ ## Quick Start
21
+
22
+ ```typescript
23
+ import { ReeprovClient } from "@reeprov/client";
24
+
25
+ // Initialize client with project credentials
26
+ const reeprov = new ReeprovClient({
27
+ url: process.env.REEPROV_URL ?? "http://127.0.0.1:3000",
28
+ ingestKey: process.env.REEPROV_INGEST_KEY!, // Project-scoped ingest key
29
+ projectId: "customer-support",
30
+ workflowId: "refund-flow-v1",
31
+ });
32
+
33
+ // 1. Start execution run
34
+ const run = await reeprov.startRun({
35
+ summary: "Evaluate refund request for user #1042",
36
+ });
37
+
38
+ // 2. Record model calls & token usage
39
+ await reeprov.modelCallCompleted({
40
+ run_id: run.run_id,
41
+ model: "claude-sonnet-4-6",
42
+ provider: "anthropic",
43
+ prompt: "Analyze the user refund request...",
44
+ response: { decision: "approved", confidence: 0.98 },
45
+ input_tokens: 340,
46
+ output_tokens: 95,
47
+ cost_usd: 0.0024,
48
+ });
49
+
50
+ // 3. Record tool invocations
51
+ await reeprov.toolCallCompleted({
52
+ run_id: run.run_id,
53
+ tool_name: "stripe.refund",
54
+ arguments: { charge_id: "ch_12345", amount: 2500 },
55
+ output: { status: "succeeded", refund_id: "re_9876" },
56
+ permission_class: "external_side_effect",
57
+ });
58
+
59
+ // 4. Complete the run
60
+ await reeprov.completeRun({
61
+ run_id: run.run_id,
62
+ summary: "Refund processed successfully.",
63
+ });
64
+ ```
65
+
66
+ ---
67
+
68
+ ## Environment Variables
69
+
70
+ The client can automatically configure itself from standard environment variables (with legacy `REEPROV_*` fallbacks during migration):
71
+
72
+ | Variable | Description |
73
+ |---|---|
74
+ | `REEPROV_URL` | Base URL of the Reeprov instance (e.g. `http://127.0.0.1:3000`) |
75
+ | `REEPROV_INGEST_KEY` | Project-scoped ingest key (`ree_live_...`) |
76
+ | `REEPROV_PROJECT_ID` | Default project identifier |
77
+ | `REEPROV_WORKFLOW_ID` | Default workflow identifier |
78
+ | `REEPROV_FAIL_OPEN` | Set to `"false"` to throw on telemetry errors (default: `"true"`) |
79
+ | `REEPROV_ENABLED` | Set to `"false"` to disable telemetry entirely |
80
+
81
+ ---
82
+
83
+ ## Reliability & Failure Isolation
84
+
85
+ - **Zero Runtime Dependencies:** Built strictly on standard platform APIs (`fetch`, `AbortController`).
86
+ - **Fail-Open Posture:** By default, telemetry delivery failures log warnings and do not crash your primary agent loop.
87
+ - **Fast-Fail on Auth:** 401/403 responses fail immediately without wasteful retries.
88
+ - **Bounded Exponential Backoff:** Transient 5xx server errors retry up to 2 times with jitter.
89
+
90
+ ---
91
+
92
+ ## License
93
+
94
+ Apache-2.0
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @reeprov/client — ReeprovClient
3
+ *
4
+ * Standalone TypeScript HTTP client for Reeprov.
5
+ * Communicates strictly over standard HTTP APIs.
6
+ */
7
+ import type { ArtifactCreatedInput, BoundaryCaptureInput, CheckpointSavedInput, CompleteRunInput, EvalCompletedInput, FailRunInput, ModelCallInput, ReeprovClientOptions, StartRunInput, StartRunResult, ToolCallInput, TraceEvent } from "./types.js";
8
+ export declare class ReeprovError extends Error {
9
+ readonly status?: number | undefined;
10
+ readonly isRetryable: boolean;
11
+ constructor(message: string, status?: number | undefined, isRetryable?: boolean);
12
+ }
13
+ /** Legacy alias */
14
+ export declare const AgentPulseError: typeof ReeprovError;
15
+ export declare class ReeprovClient {
16
+ private readonly endpoint;
17
+ private readonly apiKey;
18
+ private readonly defaultProjectId;
19
+ private readonly defaultProjectName;
20
+ private readonly defaultWorkflowId;
21
+ private readonly timeoutMs;
22
+ private readonly maxRetries;
23
+ private readonly failOpen;
24
+ private readonly enabled;
25
+ constructor(options?: ReeprovClientOptions);
26
+ get isEnabled(): boolean;
27
+ startRun(input: StartRunInput): Promise<StartRunResult>;
28
+ completeRun(input: CompleteRunInput): Promise<void>;
29
+ failRun(input: FailRunInput): Promise<void>;
30
+ emitTraceEvent(event: TraceEvent): Promise<void>;
31
+ emitTraceEvents(events: TraceEvent[]): Promise<void>;
32
+ modelCallCompleted(input: ModelCallInput): Promise<void>;
33
+ toolCallCompleted(input: ToolCallInput): Promise<void>;
34
+ evalCompleted(input: EvalCompletedInput): Promise<void>;
35
+ artifactCreated(input: ArtifactCreatedInput): Promise<void>;
36
+ checkpointSaved(input: CheckpointSavedInput): Promise<void>;
37
+ captureBoundary(runId: string, boundary: BoundaryCaptureInput): Promise<void>;
38
+ private post;
39
+ }
40
+ /** Legacy alias */
41
+ export declare const AgentPulseClient: typeof ReeprovClient;
package/dist/client.js ADDED
@@ -0,0 +1,355 @@
1
+ /**
2
+ * @reeprov/client — ReeprovClient
3
+ *
4
+ * Standalone TypeScript HTTP client for Reeprov.
5
+ * Communicates strictly over standard HTTP APIs.
6
+ */
7
+ export class ReeprovError extends Error {
8
+ status;
9
+ isRetryable;
10
+ constructor(message, status, isRetryable = false) {
11
+ super(message);
12
+ this.status = status;
13
+ this.isRetryable = isRetryable;
14
+ this.name = "ReeprovError";
15
+ }
16
+ }
17
+ /** Legacy alias */
18
+ export const AgentPulseError = ReeprovError;
19
+ function getEnv(key) {
20
+ if (typeof process !== "undefined" && process?.env) {
21
+ return process.env[key];
22
+ }
23
+ return undefined;
24
+ }
25
+ export class ReeprovClient {
26
+ endpoint;
27
+ apiKey;
28
+ defaultProjectId;
29
+ defaultProjectName;
30
+ defaultWorkflowId;
31
+ timeoutMs;
32
+ maxRetries;
33
+ failOpen;
34
+ enabled;
35
+ constructor(options = {}) {
36
+ const rawEndpoint = options.url ||
37
+ options.endpoint ||
38
+ getEnv("REEPROV_URL") ||
39
+ getEnv("AGENTPULSE_URL") ||
40
+ "http://127.0.0.1:3000";
41
+ this.endpoint = rawEndpoint.replace(/\/+$/, "");
42
+ this.apiKey =
43
+ options.ingestKey ||
44
+ options.apiKey ||
45
+ getEnv("REEPROV_INGEST_KEY") ||
46
+ getEnv("AGENTPULSE_INGEST_KEY") ||
47
+ "";
48
+ this.defaultProjectId =
49
+ options.projectId ||
50
+ getEnv("REEPROV_PROJECT_ID") ||
51
+ getEnv("AGENTPULSE_PROJECT_ID") ||
52
+ "default-project";
53
+ this.defaultProjectName =
54
+ options.projectName ||
55
+ getEnv("REEPROV_PROJECT_NAME") ||
56
+ getEnv("AGENTPULSE_PROJECT_NAME") ||
57
+ "Default Project";
58
+ this.defaultWorkflowId =
59
+ options.workflowId ||
60
+ getEnv("REEPROV_WORKFLOW_ID") ||
61
+ getEnv("AGENTPULSE_WORKFLOW_ID") ||
62
+ "default-workflow";
63
+ this.timeoutMs = options.timeoutMs ?? 10_000;
64
+ this.maxRetries = options.maxRetries ?? 2;
65
+ this.failOpen =
66
+ options.failOpen ??
67
+ ((getEnv("REEPROV_FAIL_OPEN") ?? getEnv("AGENTPULSE_FAIL_OPEN")) !== "false");
68
+ if (options.enabled !== undefined) {
69
+ this.enabled = options.enabled;
70
+ }
71
+ else {
72
+ const envEnabled = getEnv("REEPROV_ENABLED") ?? getEnv("AGENTPULSE_ENABLED");
73
+ if (envEnabled !== undefined) {
74
+ this.enabled = envEnabled.toLowerCase() === "true";
75
+ }
76
+ else {
77
+ this.enabled = Boolean(this.apiKey);
78
+ }
79
+ }
80
+ }
81
+ get isEnabled() {
82
+ return this.enabled;
83
+ }
84
+ // ── Run Lifecycle ────────────────────────────────────────────────────────────
85
+ async startRun(input) {
86
+ if (!this.enabled) {
87
+ const noopId = input.run_id || `noop-${Math.random().toString(36).slice(2, 10)}`;
88
+ return {
89
+ run_id: noopId,
90
+ workflow_id: input.workflowId ?? this.defaultWorkflowId,
91
+ project_id: input.projectId ?? this.defaultProjectId,
92
+ project_name: input.projectName ?? this.defaultProjectName,
93
+ status: "running",
94
+ started_at: new Date().toISOString(),
95
+ summary: input.summary,
96
+ };
97
+ }
98
+ const payload = {
99
+ project_id: input.projectId ?? this.defaultProjectId,
100
+ project_name: input.projectName ?? this.defaultProjectName,
101
+ workflow_id: input.workflowId ?? this.defaultWorkflowId,
102
+ summary: input.summary,
103
+ ...(input.run_id ? { run_id: input.run_id } : {}),
104
+ ...(input.metadata ? { metadata: input.metadata } : {}),
105
+ };
106
+ return this.post("/api/runs/start", payload);
107
+ }
108
+ async completeRun(input) {
109
+ if (!this.enabled)
110
+ return;
111
+ await this.post("/api/runs/complete", input);
112
+ }
113
+ async failRun(input) {
114
+ if (!this.enabled)
115
+ return;
116
+ await this.post("/api/runs/fail", input);
117
+ }
118
+ // ── Trace Events ─────────────────────────────────────────────────────────────
119
+ async emitTraceEvent(event) {
120
+ await this.emitTraceEvents([event]);
121
+ }
122
+ async emitTraceEvents(events) {
123
+ if (!this.enabled || events.length === 0) {
124
+ return;
125
+ }
126
+ await this.post("/api/traces/events", { events });
127
+ }
128
+ // ── Semantic Helpers ─────────────────────────────────────────────────────────
129
+ async modelCallCompleted(input) {
130
+ if (!this.enabled)
131
+ return;
132
+ const now = new Date().toISOString();
133
+ const event = {
134
+ event_id: `evt-${Math.random().toString(36).slice(2, 10)}`,
135
+ run_id: input.run_id,
136
+ workflow_id: this.defaultWorkflowId,
137
+ timestamp: now,
138
+ event_type: "model_call_completed",
139
+ status: "completed",
140
+ node_id: input.node_id,
141
+ cost_usd: input.cost_usd,
142
+ duration_ms: input.duration_ms,
143
+ input_summary: input.prompt ? input.prompt.slice(0, 500) : undefined,
144
+ metadata: {
145
+ model: input.model,
146
+ provider: input.provider,
147
+ input_tokens: input.input_tokens,
148
+ output_tokens: input.output_tokens,
149
+ ...input.metadata,
150
+ },
151
+ };
152
+ await this.emitTraceEvent(event);
153
+ await this.captureBoundary(input.run_id, {
154
+ boundaryType: "model_call",
155
+ name: `${input.provider}/${input.model}`,
156
+ nodeId: input.node_id,
157
+ stepId: input.step_id,
158
+ durationMs: input.duration_ms,
159
+ input: {
160
+ model: input.model,
161
+ provider: input.provider,
162
+ prompt: input.prompt,
163
+ messages: input.messages,
164
+ },
165
+ output: input.response,
166
+ declaredSideEffectClass: "read_only",
167
+ metadata: input.metadata,
168
+ });
169
+ }
170
+ async toolCallCompleted(input) {
171
+ if (!this.enabled)
172
+ return;
173
+ const now = new Date().toISOString();
174
+ const event = {
175
+ event_id: `evt-${Math.random().toString(36).slice(2, 10)}`,
176
+ run_id: input.run_id,
177
+ workflow_id: this.defaultWorkflowId,
178
+ timestamp: now,
179
+ event_type: "tool_call_completed",
180
+ status: input.error ? "failed" : "completed",
181
+ node_id: input.node_id,
182
+ duration_ms: input.duration_ms,
183
+ error_message: input.error,
184
+ metadata: {
185
+ tool_name: input.tool_name,
186
+ permission_class: input.permission_class ?? "read_only",
187
+ ...input.metadata,
188
+ },
189
+ };
190
+ await this.emitTraceEvent(event);
191
+ await this.captureBoundary(input.run_id, {
192
+ boundaryType: "tool_call",
193
+ name: input.tool_name,
194
+ nodeId: input.node_id,
195
+ stepId: input.step_id,
196
+ durationMs: input.duration_ms,
197
+ input: input.arguments,
198
+ output: input.output,
199
+ error: input.error ? { message: input.error } : undefined,
200
+ declaredSideEffectClass: input.permission_class ?? "read_only",
201
+ metadata: input.metadata,
202
+ });
203
+ }
204
+ async evalCompleted(input) {
205
+ if (!this.enabled)
206
+ return;
207
+ const now = new Date().toISOString();
208
+ const event = {
209
+ event_id: `evt-${Math.random().toString(36).slice(2, 10)}`,
210
+ run_id: input.run_id,
211
+ workflow_id: this.defaultWorkflowId,
212
+ timestamp: now,
213
+ event_type: "eval_completed",
214
+ status: input.passed ? "completed" : "failed",
215
+ node_id: input.node_id,
216
+ metadata: {
217
+ eval_name: input.eval_name,
218
+ passed: input.passed,
219
+ score: input.score,
220
+ reason: input.reason,
221
+ ...input.metadata,
222
+ },
223
+ };
224
+ await this.emitTraceEvent(event);
225
+ }
226
+ async artifactCreated(input) {
227
+ if (!this.enabled)
228
+ return;
229
+ const now = new Date().toISOString();
230
+ const event = {
231
+ event_id: `evt-${Math.random().toString(36).slice(2, 10)}`,
232
+ run_id: input.run_id,
233
+ workflow_id: this.defaultWorkflowId,
234
+ timestamp: now,
235
+ event_type: "artifact_created",
236
+ status: "completed",
237
+ node_id: input.node_id,
238
+ output_summary: input.summary,
239
+ metadata: {
240
+ artifact_ref: input.artifact_ref,
241
+ artifact_type: input.artifact_type,
242
+ ...input.metadata,
243
+ },
244
+ };
245
+ await this.emitTraceEvent(event);
246
+ }
247
+ async checkpointSaved(input) {
248
+ if (!this.enabled)
249
+ return;
250
+ await this.captureBoundary(input.run_id, {
251
+ boundaryType: "checkpoint",
252
+ name: `checkpoint:${input.checkpoint_id}`,
253
+ nodeId: input.node_id,
254
+ stepId: input.step_id,
255
+ output: input.state,
256
+ declaredSideEffectClass: "read_only",
257
+ metadata: {
258
+ checkpoint_id: input.checkpoint_id,
259
+ ...input.metadata,
260
+ },
261
+ });
262
+ }
263
+ // ── Replay-Grade Boundary Capture ──────────────────────────────────────────
264
+ async captureBoundary(runId, boundary) {
265
+ if (!this.enabled)
266
+ return;
267
+ const payload = {
268
+ boundaries: [
269
+ {
270
+ runId,
271
+ startedAt: new Date().toISOString(),
272
+ ...boundary,
273
+ },
274
+ ],
275
+ };
276
+ try {
277
+ await this.post("/api/traces/boundaries", payload);
278
+ }
279
+ catch (err) {
280
+ if (this.failOpen) {
281
+ console.warn(`[Reeprov] Non-fatal boundary capture error: ${err.message}`);
282
+ }
283
+ else {
284
+ throw err;
285
+ }
286
+ }
287
+ }
288
+ // ── HTTP Ingest Transport ──────────────────────────────────────────────────
289
+ async post(path, body) {
290
+ const url = `${this.endpoint}${path}`;
291
+ const payload = JSON.stringify(body);
292
+ let lastError = null;
293
+ for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
294
+ const controller = new AbortController();
295
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
296
+ try {
297
+ const response = await fetch(url, {
298
+ method: "POST",
299
+ headers: {
300
+ "Content-Type": "application/json",
301
+ "x-reeprov-key": this.apiKey,
302
+ },
303
+ body: payload,
304
+ signal: controller.signal,
305
+ });
306
+ clearTimeout(timer);
307
+ if (response.ok) {
308
+ const contentType = response.headers.get("content-type");
309
+ if (contentType && contentType.includes("application/json")) {
310
+ return (await response.json());
311
+ }
312
+ return {};
313
+ }
314
+ // Fast-fail non-retryable 4xx errors
315
+ if (response.status === 401 || response.status === 403 || (response.status >= 400 && response.status < 500)) {
316
+ let errDetail = `${response.status} ${response.statusText}`;
317
+ try {
318
+ const errData = (await response.json());
319
+ if (errData?.message)
320
+ errDetail = errData.message;
321
+ }
322
+ catch {
323
+ // ignore json parse error
324
+ }
325
+ const fastFailErr = new ReeprovError(`Reeprov API Error (${response.status}): ${errDetail}`, response.status, false);
326
+ if (this.failOpen) {
327
+ console.warn(`[Reeprov] Non-retryable error: ${fastFailErr.message}`);
328
+ return undefined;
329
+ }
330
+ throw fastFailErr;
331
+ }
332
+ // 5xx transient server error
333
+ lastError = new ReeprovError(`Reeprov API Error: ${response.status} ${response.statusText}`, response.status, true);
334
+ }
335
+ catch (err) {
336
+ clearTimeout(timer);
337
+ if (err instanceof ReeprovError && !err.isRetryable) {
338
+ throw err;
339
+ }
340
+ lastError = err;
341
+ }
342
+ if (attempt < this.maxRetries) {
343
+ const backoffMs = 50 * Math.pow(2, attempt);
344
+ await new Promise((r) => setTimeout(r, backoffMs));
345
+ }
346
+ }
347
+ if (this.failOpen) {
348
+ console.warn(`[Reeprov] Telemetry request to ${path} failed after retries: ${lastError?.message}`);
349
+ return undefined;
350
+ }
351
+ throw lastError || new ReeprovError(`Reeprov request failed: ${path}`);
352
+ }
353
+ }
354
+ /** Legacy alias */
355
+ export const AgentPulseClient = ReeprovClient;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @reeprov/client
3
+ *
4
+ * Official TypeScript client SDK for Reeprov — local-first debugging
5
+ * and reproducibility for AI agents.
6
+ */
7
+ export { ReeprovClient, ReeprovError, AgentPulseClient, AgentPulseError } from "./client.js";
8
+ export type { ReeprovClientOptions, AgentPulseClientOptions, ArtifactCreatedInput, BoundaryCaptureInput, CheckpointSavedInput, CompleteRunInput, EmitEventsResult, EvalCompletedInput, EventStatus, FailRunInput, ModelCallInput, PermissionClass, StartRunInput, StartRunResult, ToolCallInput, TraceEvent, } from "./types.js";
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @reeprov/client
3
+ *
4
+ * Official TypeScript client SDK for Reeprov — local-first debugging
5
+ * and reproducibility for AI agents.
6
+ */
7
+ export { ReeprovClient, ReeprovError, AgentPulseClient, AgentPulseError } from "./client.js";
@@ -0,0 +1,160 @@
1
+ /**
2
+ * @reeprov/client — Canonical Type Definitions
3
+ *
4
+ * Standalone interfaces for Reeprov trace ingestion and execution boundary capture.
5
+ */
6
+ export type PermissionClass = "read_only" | "write_draft" | "external_side_effect" | "destructive" | "sensitive_data";
7
+ export type EventStatus = "pending" | "running" | "completed" | "failed" | "cancelled";
8
+ export interface TraceEvent {
9
+ event_id: string;
10
+ run_id: string;
11
+ workflow_id: string;
12
+ timestamp: string;
13
+ event_type: string;
14
+ status: EventStatus | string;
15
+ node_id?: string;
16
+ parent_event_id?: string;
17
+ cost_usd?: number;
18
+ duration_ms?: number;
19
+ input_summary?: string;
20
+ output_summary?: string;
21
+ metadata?: Record<string, unknown>;
22
+ error_message?: string;
23
+ }
24
+ export interface ReeprovClientOptions {
25
+ /** Base URL of the Reeprov instance, e.g. "http://127.0.0.1:3000" */
26
+ url?: string;
27
+ /** Backwards-compatible alias for url */
28
+ endpoint?: string;
29
+ /** Project-scoped ingest API key (or global ingest key) */
30
+ ingestKey?: string;
31
+ /** Backwards-compatible alias for ingestKey */
32
+ apiKey?: string;
33
+ /** Stable project identifier (e.g. "my-agent-service") */
34
+ projectId?: string;
35
+ /** Human-readable project display name */
36
+ projectName?: string;
37
+ /** Default workflow identifier */
38
+ workflowId?: string;
39
+ /** Request timeout in milliseconds (default: 10,000ms) */
40
+ timeoutMs?: number;
41
+ /** Maximum retry attempts for transient 5xx server errors (default: 2) */
42
+ maxRetries?: number;
43
+ /** Fail-open posture: log telemetry warnings instead of throwing (default: true) */
44
+ failOpen?: boolean;
45
+ /** Explicit enable flag: defaults to true if endpoint and ingestKey are provided */
46
+ enabled?: boolean;
47
+ }
48
+ export type AgentPulseClientOptions = ReeprovClientOptions;
49
+ export interface StartRunInput {
50
+ /** Brief human summary describing the run's goal or trigger */
51
+ summary: string;
52
+ /** Optional client-supplied run ID. Server generates a UUID if omitted */
53
+ run_id?: string;
54
+ /** Override project ID for this specific run */
55
+ projectId?: string;
56
+ /** Override project name for this specific run */
57
+ projectName?: string;
58
+ /** Override workflow ID for this specific run */
59
+ workflowId?: string;
60
+ /** Arbitrary metadata attached to the run */
61
+ metadata?: Record<string, unknown>;
62
+ }
63
+ export interface StartRunResult {
64
+ run_id: string;
65
+ workflow_id: string;
66
+ project_id: string;
67
+ project_name: string;
68
+ status: string;
69
+ started_at: string;
70
+ summary: string;
71
+ }
72
+ export interface CompleteRunInput {
73
+ run_id: string;
74
+ summary?: string;
75
+ total_cost_usd?: number;
76
+ total_duration_ms?: number;
77
+ artifact_refs?: string[];
78
+ metrics?: Record<string, number>;
79
+ }
80
+ export interface FailRunInput {
81
+ run_id: string;
82
+ error_summary: string;
83
+ total_cost_usd?: number;
84
+ total_duration_ms?: number;
85
+ }
86
+ export interface EmitEventsResult {
87
+ accepted: number;
88
+ rejected: number;
89
+ errors?: Array<{
90
+ event_id: string;
91
+ message: string;
92
+ }>;
93
+ }
94
+ export interface BoundaryCaptureInput {
95
+ boundaryType: "model_call" | "tool_call" | "retrieval_service" | "memory_read" | "memory_write" | "checkpoint" | string;
96
+ name: string;
97
+ stepId?: string;
98
+ nodeId?: string;
99
+ durationMs?: number;
100
+ input?: unknown;
101
+ output?: unknown;
102
+ error?: {
103
+ message: string;
104
+ stack?: string;
105
+ };
106
+ declaredSideEffectClass?: PermissionClass;
107
+ metadata?: Record<string, unknown>;
108
+ }
109
+ export interface ModelCallInput {
110
+ run_id: string;
111
+ model: string;
112
+ provider: string;
113
+ response: unknown;
114
+ prompt?: string;
115
+ messages?: unknown[];
116
+ node_id?: string;
117
+ step_id?: string;
118
+ duration_ms?: number;
119
+ cost_usd?: number;
120
+ input_tokens?: number;
121
+ output_tokens?: number;
122
+ metadata?: Record<string, unknown>;
123
+ }
124
+ export interface ToolCallInput {
125
+ run_id: string;
126
+ tool_name: string;
127
+ arguments: unknown;
128
+ output?: unknown;
129
+ error?: string;
130
+ permission_class?: PermissionClass;
131
+ node_id?: string;
132
+ step_id?: string;
133
+ duration_ms?: number;
134
+ metadata?: Record<string, unknown>;
135
+ }
136
+ export interface EvalCompletedInput {
137
+ run_id: string;
138
+ eval_name: string;
139
+ passed: boolean;
140
+ score?: number;
141
+ reason?: string;
142
+ node_id?: string;
143
+ metadata?: Record<string, unknown>;
144
+ }
145
+ export interface ArtifactCreatedInput {
146
+ run_id: string;
147
+ artifact_ref: string;
148
+ artifact_type: string;
149
+ summary?: string;
150
+ node_id?: string;
151
+ metadata?: Record<string, unknown>;
152
+ }
153
+ export interface CheckpointSavedInput {
154
+ run_id: string;
155
+ checkpoint_id: string;
156
+ state: unknown;
157
+ node_id?: string;
158
+ step_id?: string;
159
+ metadata?: Record<string, unknown>;
160
+ }
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @reeprov/client — Canonical Type Definitions
3
+ *
4
+ * Standalone interfaces for Reeprov trace ingestion and execution boundary capture.
5
+ */
6
+ export {};
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@reeprov/client",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-beta.1",
4
+ "description": "TypeScript client SDK for Reeprov — local-first debugging and reproducibility for AI agents.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "test": "node --test dist/test-runner.js 2>/dev/null || tsc --noEmit",
24
+ "prepublishOnly": "npm run build"
25
+ },
26
+ "engines": {
27
+ "node": ">=20"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/RaulMermans/Reeprov.git",
32
+ "directory": "packages/client-typescript"
33
+ },
34
+ "keywords": [
35
+ "reeprov",
36
+ "ai-agents",
37
+ "debugging",
38
+ "reproducibility",
39
+ "tracing",
40
+ "telemetry",
41
+ "evals"
42
+ ],
43
+ "author": "Reeprov Contributors",
44
+ "devDependencies": {
45
+ "typescript": "^5.8.0 || ^6.0.0"
46
+ }
47
+ }