retrace-sdk 0.13.1 → 0.13.3
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/README.md +7 -7
- package/dist/config.js +5 -4
- package/dist/errors.js +1 -1
- package/dist/telemetry.d.ts +1 -0
- package/dist/telemetry.js +51 -0
- package/dist/transport.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Requires Node.js 20+. ESM-only package.
|
|
|
15
15
|
```typescript
|
|
16
16
|
import { configure, trace } from "retrace-sdk";
|
|
17
17
|
|
|
18
|
-
configure({ apiKey: "
|
|
18
|
+
configure({ apiKey: "rt_..." }); // Get your key at retraceai.tech/settings
|
|
19
19
|
|
|
20
20
|
const myAgent = trace(async (prompt: string) => {
|
|
21
21
|
const response = await openai.chat.completions.create({
|
|
@@ -44,8 +44,8 @@ No extra setup needed. Install the provider SDK alongside `retrace-sdk`.
|
|
|
44
44
|
import { configure } from "retrace-sdk";
|
|
45
45
|
|
|
46
46
|
configure({
|
|
47
|
-
apiKey: "
|
|
48
|
-
baseUrl: "https://api
|
|
47
|
+
apiKey: "rt_...", // or RETRACE_API_KEY env var
|
|
48
|
+
baseUrl: "https://api.retraceai.tech",
|
|
49
49
|
projectId: "...", // or RETRACE_PROJECT_ID env var
|
|
50
50
|
});
|
|
51
51
|
```
|
|
@@ -74,7 +74,7 @@ Mark a function as resumable to enable full cascade replay from the dashboard:
|
|
|
74
74
|
```typescript
|
|
75
75
|
import { configure, trace } from "retrace-sdk";
|
|
76
76
|
|
|
77
|
-
configure({ apiKey: "
|
|
77
|
+
configure({ apiKey: "rt_..." });
|
|
78
78
|
|
|
79
79
|
const myAgent = trace(async (prompt: string) => {
|
|
80
80
|
const plan = await planner(prompt);
|
|
@@ -101,7 +101,7 @@ Hard ceilings that stop a runaway agent before the next call. Local limits are e
|
|
|
101
101
|
import { configure, RetraceEnforcementError } from "retrace-sdk";
|
|
102
102
|
|
|
103
103
|
configure({
|
|
104
|
-
apiKey: "
|
|
104
|
+
apiKey: "rt_...",
|
|
105
105
|
maxStepsPerRun: 50,
|
|
106
106
|
maxUsdPerRun: 2.0,
|
|
107
107
|
serverEnforcement: true, // optional: also consult server policies
|
|
@@ -141,7 +141,7 @@ writeGoldenCassette("golden.json", { recorder });
|
|
|
141
141
|
## Sampling
|
|
142
142
|
|
|
143
143
|
```typescript
|
|
144
|
-
configure({ apiKey: "
|
|
144
|
+
configure({ apiKey: "rt_...", sampleRate: 0.1 }); // Record 10% of traces
|
|
145
145
|
```
|
|
146
146
|
|
|
147
147
|
## Changelog
|
|
@@ -183,6 +183,6 @@ configure({ apiKey: "rt_live_...", sampleRate: 0.1 }); // Record 10% of traces
|
|
|
183
183
|
|
|
184
184
|
## Links
|
|
185
185
|
|
|
186
|
-
- [Documentation](https://
|
|
186
|
+
- [Documentation](https://retraceai.tech/docs)
|
|
187
187
|
- [GitHub](https://github.com/yash1511-bogam/retrace)
|
|
188
188
|
- [npm](https://www.npmjs.com/package/retrace-sdk)
|
package/dist/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const config = {
|
|
2
2
|
apiKey: process.env.RETRACE_API_KEY || "",
|
|
3
|
-
baseUrl: process.env.RETRACE_BASE_URL || "https://api
|
|
3
|
+
baseUrl: process.env.RETRACE_BASE_URL || "https://api.retraceai.tech",
|
|
4
4
|
wsUrl: "",
|
|
5
5
|
projectId: process.env.RETRACE_PROJECT_ID || undefined,
|
|
6
6
|
enabled: !["false", "0"].includes((process.env.RETRACE_ENABLED || "true").toLowerCase()),
|
|
@@ -16,8 +16,8 @@ const config = {
|
|
|
16
16
|
};
|
|
17
17
|
config.wsUrl = config.baseUrl.replace("https://", "wss://").replace("http://", "ws://");
|
|
18
18
|
export function configure(opts) {
|
|
19
|
-
if (opts.apiKey && !opts.apiKey.startsWith("rt_live_")) {
|
|
20
|
-
throw new Error("Invalid Retrace API key. Keys must start with '
|
|
19
|
+
if (opts.apiKey && (!opts.apiKey.startsWith("rt_") || opts.apiKey.startsWith("rt_live_") || opts.apiKey.startsWith("rt_test_"))) {
|
|
20
|
+
throw new Error("Invalid Retrace API key. Keys must start with 'rt_'. Get yours at https://retraceai.tech/settings");
|
|
21
21
|
}
|
|
22
22
|
Object.assign(config, opts);
|
|
23
23
|
if (opts.baseUrl && !opts.wsUrl) {
|
|
@@ -30,11 +30,12 @@ export function configure(opts) {
|
|
|
30
30
|
if (config.enabled) {
|
|
31
31
|
void import("./interceptors/install.js").then((m) => m.ensureInterceptorsInstalled()).catch(() => { });
|
|
32
32
|
}
|
|
33
|
+
void import("./telemetry.js").then((m) => m.track("configure")).catch(() => { });
|
|
33
34
|
return config;
|
|
34
35
|
}
|
|
35
36
|
export function requireApiKey() {
|
|
36
37
|
if (!config.apiKey) {
|
|
37
|
-
throw new Error("Retrace API key required. Call configure({ apiKey: '
|
|
38
|
+
throw new Error("Retrace API key required. Call configure({ apiKey: 'rt_...' }) or set RETRACE_API_KEY. Get yours at https://retraceai.tech/settings");
|
|
38
39
|
}
|
|
39
40
|
return config.apiKey;
|
|
40
41
|
}
|
package/dist/errors.js
CHANGED
|
@@ -5,7 +5,7 @@ export class RetraceAuthError extends RetraceError {
|
|
|
5
5
|
constructor(message = "Invalid or missing API key") { super(message); this.name = "RetraceAuthError"; }
|
|
6
6
|
}
|
|
7
7
|
export class RetraceCreditsExhaustedError extends RetraceError {
|
|
8
|
-
constructor(message = "Monthly trace limit reached. Upgrade at
|
|
8
|
+
constructor(message = "Monthly trace limit reached. Upgrade at retraceai.tech/pricing") { super(message); this.name = "RetraceCreditsExhaustedError"; }
|
|
9
9
|
}
|
|
10
10
|
export class RetraceConnectionError extends RetraceError {
|
|
11
11
|
constructor(message = "Failed to connect to Retrace API") { super(message); this.name = "RetraceConnectionError"; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function track(event: string, fields?: Record<string, string | number | boolean>): void;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anonymous, opt-out diagnostic telemetry.
|
|
3
|
+
*
|
|
4
|
+
* Sends NO user code, API keys, prompts, responses, or personal information — only the SDK version,
|
|
5
|
+
* the runtime/OS family, an anonymous per-process id, and event/error *categories* — to the Retrace
|
|
6
|
+
* API's internal log ingest (forwarded to the centralized logging platform under
|
|
7
|
+
* service="sdk-typescript"). Fire-and-forget; never blocks, never throws.
|
|
8
|
+
*
|
|
9
|
+
* Disable entirely with RETRACE_TELEMETRY=0 (also accepts false/no/off).
|
|
10
|
+
*/
|
|
11
|
+
import os from "node:os";
|
|
12
|
+
import { getConfig } from "./config.js";
|
|
13
|
+
// Per-process random id — anonymous, not linked to any account, user, or machine identity.
|
|
14
|
+
const ANON_ID = Math.random().toString(16).slice(2, 18);
|
|
15
|
+
const DISABLED = new Set(["0", "false", "no", "off"]);
|
|
16
|
+
// Keep in sync with package.json version.
|
|
17
|
+
const SDK_VERSION = "0.13.3";
|
|
18
|
+
function enabled() {
|
|
19
|
+
return !DISABLED.has((process.env.RETRACE_TELEMETRY ?? "1").trim().toLowerCase());
|
|
20
|
+
}
|
|
21
|
+
export function track(event, fields = {}) {
|
|
22
|
+
if (!enabled())
|
|
23
|
+
return;
|
|
24
|
+
try {
|
|
25
|
+
const base = (getConfig().baseUrl || "https://api.retraceai.tech").replace(/\/$/, "");
|
|
26
|
+
const body = JSON.stringify({
|
|
27
|
+
service: "sdk-typescript",
|
|
28
|
+
events: [
|
|
29
|
+
{
|
|
30
|
+
level: "info",
|
|
31
|
+
message: `sdk-typescript ${event}`,
|
|
32
|
+
event,
|
|
33
|
+
sdk_version: SDK_VERSION,
|
|
34
|
+
node: process.version,
|
|
35
|
+
os: os.platform(),
|
|
36
|
+
anon_id: ANON_ID,
|
|
37
|
+
...fields,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
// Fire-and-forget; never block or throw.
|
|
42
|
+
void fetch(`${base}/api/v1/internal/logs`, {
|
|
43
|
+
method: "POST",
|
|
44
|
+
headers: { "Content-Type": "application/json" },
|
|
45
|
+
body,
|
|
46
|
+
}).catch(() => { });
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
/* telemetry must never affect the user's program */
|
|
50
|
+
}
|
|
51
|
+
}
|
package/dist/transport.js
CHANGED
|
@@ -3,7 +3,7 @@ import { getConfig } from "./config.js";
|
|
|
3
3
|
import { classifyServerSignal } from "./errors.js";
|
|
4
4
|
// Client identifier sent on every request so the backend can attribute SDK usage/version.
|
|
5
5
|
// Keep in sync with package.json on release.
|
|
6
|
-
const CLIENT_ID = "typescript-sdk/0.13.
|
|
6
|
+
const CLIENT_ID = "typescript-sdk/0.13.2";
|
|
7
7
|
export class WSTransport {
|
|
8
8
|
ws = null;
|
|
9
9
|
connected = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "retrace-sdk",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.3",
|
|
4
4
|
"description": "The execution replay engine for AI agents. Record, replay, fork, and share agent executions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"url": "https://github.com/yash1511-bogam/retrace-sdk",
|
|
32
32
|
"directory": "packages/sdk-typescript"
|
|
33
33
|
},
|
|
34
|
-
"homepage": "https://
|
|
34
|
+
"homepage": "https://retraceai.tech/docs/sdk-typescript",
|
|
35
35
|
"keywords": [
|
|
36
36
|
"ai",
|
|
37
37
|
"agent",
|