@smazzinni/sdk 0.4.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/README.md +167 -0
- package/dist/cjs/config.d.ts +27 -0
- package/dist/cjs/config.d.ts.map +1 -0
- package/dist/cjs/config.js +118 -0
- package/dist/cjs/config.js.map +1 -0
- package/dist/cjs/context.d.ts +16 -0
- package/dist/cjs/context.d.ts.map +1 -0
- package/dist/cjs/context.js +159 -0
- package/dist/cjs/context.js.map +1 -0
- package/dist/cjs/cost.d.ts +25 -0
- package/dist/cjs/cost.d.ts.map +1 -0
- package/dist/cjs/cost.js +49 -0
- package/dist/cjs/cost.js.map +1 -0
- package/dist/cjs/index.d.ts +32 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +50 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/redact.d.ts +12 -0
- package/dist/cjs/redact.d.ts.map +1 -0
- package/dist/cjs/redact.js +64 -0
- package/dist/cjs/redact.js.map +1 -0
- package/dist/cjs/session.d.ts +32 -0
- package/dist/cjs/session.d.ts.map +1 -0
- package/dist/cjs/session.js +65 -0
- package/dist/cjs/session.js.map +1 -0
- package/dist/cjs/steps.d.ts +12 -0
- package/dist/cjs/steps.d.ts.map +1 -0
- package/dist/cjs/steps.js +60 -0
- package/dist/cjs/steps.js.map +1 -0
- package/dist/cjs/store.d.ts +38 -0
- package/dist/cjs/store.d.ts.map +1 -0
- package/dist/cjs/store.js +125 -0
- package/dist/cjs/store.js.map +1 -0
- package/dist/cjs/types.d.ts +124 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +6 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/config.d.ts +27 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +110 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +16 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +153 -0
- package/dist/context.js.map +1 -0
- package/dist/cost.d.ts +25 -0
- package/dist/cost.d.ts.map +1 -0
- package/dist/cost.js +43 -0
- package/dist/cost.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/redact.d.ts +12 -0
- package/dist/redact.d.ts.map +1 -0
- package/dist/redact.js +59 -0
- package/dist/redact.js.map +1 -0
- package/dist/session.d.ts +32 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +61 -0
- package/dist/session.js.map +1 -0
- package/dist/steps.d.ts +12 -0
- package/dist/steps.d.ts.map +1 -0
- package/dist/steps.js +56 -0
- package/dist/steps.js.map +1 -0
- package/dist/store.d.ts +38 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +118 -0
- package/dist/store.js.map +1 -0
- package/dist/types.d.ts +124 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ReplayAI TypeScript SDK — shared types.
|
|
3
|
+
// Mirrors the API shape defined in src/app/api/sessions/route.ts and
|
|
4
|
+
// src/lib/replay-data.ts so what the SDK POSTs matches what the API expects.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,qEAAqE;AACrE,6EAA6E"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ConfigOptions } from "./types.js";
|
|
2
|
+
/** Default redaction patterns. Applied to every step's input/output. */
|
|
3
|
+
export declare const DEFAULT_REDACT_PATTERNS: RegExp[];
|
|
4
|
+
export type StorageMode = "local" | "cloud" | "both";
|
|
5
|
+
export interface ResolvedConfig {
|
|
6
|
+
project?: string;
|
|
7
|
+
token?: string;
|
|
8
|
+
storage: StorageMode;
|
|
9
|
+
storagePath: string;
|
|
10
|
+
apiUrl: string;
|
|
11
|
+
dashboardUrl: string;
|
|
12
|
+
sampleRate: number;
|
|
13
|
+
strict: boolean;
|
|
14
|
+
redactPatterns: RegExp[];
|
|
15
|
+
}
|
|
16
|
+
/** Resolve the active config from env vars + programmatic overrides. */
|
|
17
|
+
export declare function resolveConfig(): ResolvedConfig;
|
|
18
|
+
/** Update SDK config programmatically. Only supplied keys are changed. */
|
|
19
|
+
export declare function configure(opts: ConfigOptions): ResolvedConfig;
|
|
20
|
+
/** Get the active config (re-resolves if `configure()` was called). */
|
|
21
|
+
export declare function getConfig(): ResolvedConfig;
|
|
22
|
+
/** Reset to env-only config. Useful for tests. */
|
|
23
|
+
export declare function resetConfig(): void;
|
|
24
|
+
/** Module-level strict flag, mirrored from config.strict (parity with Python SDK). */
|
|
25
|
+
export declare let strict_mode: boolean;
|
|
26
|
+
export declare function _syncStrictFlag(): void;
|
|
27
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,wEAAwE;AACxE,eAAO,MAAM,uBAAuB,EAAE,MAAM,EAK3C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AAErD,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,WAAW,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AA4CD,wEAAwE;AACxE,wBAAgB,aAAa,IAAI,cAAc,CA8B9C;AAUD,0EAA0E;AAC1E,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,cAAc,CAI7D;AAED,uEAAuE;AACvE,wBAAgB,SAAS,IAAI,cAAc,CAE1C;AAED,kDAAkD;AAClD,wBAAgB,WAAW,IAAI,IAAI,CAGlC;AAED,sFAAsF;AACtF,eAAO,IAAI,WAAW,EAAE,OAAgC,CAAC;AAEzD,wBAAgB,eAAe,IAAI,IAAI,CAGtC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// ReplayAI TypeScript SDK — configuration.
|
|
2
|
+
// Reads env vars on first access; `configure()` overrides programmatically.
|
|
3
|
+
/** Default redaction patterns. Applied to every step's input/output. */
|
|
4
|
+
export const DEFAULT_REDACT_PATTERNS = [
|
|
5
|
+
/sk-[a-zA-Z0-9]{20,}/g, // OpenAI-style API keys
|
|
6
|
+
/Bearer\s+[a-zA-Z0-9._\-]+/g, // Authorization header tokens
|
|
7
|
+
/password=[^\s&]+/gi, // password=... in URLs / form bodies
|
|
8
|
+
/["']?api[_-]?key["']?\s*[:=]\s*["']?[a-zA-Z0-9]{20,}/gi, // api_key=...
|
|
9
|
+
];
|
|
10
|
+
function envString(name, fallback) {
|
|
11
|
+
const v = process.env[name];
|
|
12
|
+
return v === undefined || v === "" ? fallback : v;
|
|
13
|
+
}
|
|
14
|
+
function envNumber(name, fallback) {
|
|
15
|
+
const v = process.env[name];
|
|
16
|
+
if (v === undefined || v === "")
|
|
17
|
+
return fallback;
|
|
18
|
+
const n = Number(v);
|
|
19
|
+
return Number.isFinite(n) ? n : fallback;
|
|
20
|
+
}
|
|
21
|
+
function envBool(name, fallback) {
|
|
22
|
+
const v = process.env[name];
|
|
23
|
+
if (v === undefined || v === "")
|
|
24
|
+
return fallback;
|
|
25
|
+
return v === "1" || v.toLowerCase() === "true" || v.toLowerCase() === "yes" || v.toLowerCase() === "on";
|
|
26
|
+
}
|
|
27
|
+
function parseRedactPatterns(raw) {
|
|
28
|
+
if (!raw || raw.trim() === "")
|
|
29
|
+
return null;
|
|
30
|
+
const out = [];
|
|
31
|
+
for (const piece of raw.split(",")) {
|
|
32
|
+
const p = piece.trim();
|
|
33
|
+
if (!p)
|
|
34
|
+
continue;
|
|
35
|
+
try {
|
|
36
|
+
out.push(new RegExp(p, "g"));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// If the user supplied a malformed regex, escape it and try again.
|
|
40
|
+
const escaped = p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
41
|
+
try {
|
|
42
|
+
out.push(new RegExp(escaped, "g"));
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
/* skip unparseable */
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return out.length > 0 ? out : null;
|
|
50
|
+
}
|
|
51
|
+
let cached = null;
|
|
52
|
+
let overrides = {};
|
|
53
|
+
/** Resolve the active config from env vars + programmatic overrides. */
|
|
54
|
+
export function resolveConfig() {
|
|
55
|
+
if (cached)
|
|
56
|
+
return cached;
|
|
57
|
+
const storageRaw = overrides.storage ?? envString("REPLAYAI_STORAGE") ?? "cloud";
|
|
58
|
+
const storage = storageRaw === "local" || storageRaw === "cloud" || storageRaw === "both"
|
|
59
|
+
? storageRaw
|
|
60
|
+
: "cloud";
|
|
61
|
+
let redactPatterns = null;
|
|
62
|
+
if (overrides.redactPatterns) {
|
|
63
|
+
redactPatterns = overrides.redactPatterns.map((p) => typeof p === "string" ? safeRegex(p) : p);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
redactPatterns = parseRedactPatterns(envString("REPLAYAI_REDACT_PATTERNS"));
|
|
67
|
+
}
|
|
68
|
+
cached = {
|
|
69
|
+
project: overrides.project ?? envString("REPLAYAI_PROJECT"),
|
|
70
|
+
token: overrides.token ?? envString("REPLAYAI_TOKEN"),
|
|
71
|
+
storage,
|
|
72
|
+
storagePath: overrides.storagePath ?? envString("REPLAYAI_STORAGE_PATH") ?? "./replays",
|
|
73
|
+
apiUrl: (overrides.apiUrl ?? envString("REPLAYAI_API_URL") ?? "http://localhost:3000").replace(/\/$/, ""),
|
|
74
|
+
dashboardUrl: overrides.dashboardUrl ?? envString("REPLAYAI_DASHBOARD_URL") ?? "http://localhost:3000",
|
|
75
|
+
sampleRate: overrides.sampleRate ?? envNumber("REPLAYAI_SAMPLE_RATE", 1.0),
|
|
76
|
+
strict: overrides.strict ?? envBool("REPLAYAI_STRICT", false),
|
|
77
|
+
redactPatterns: redactPatterns ?? [...DEFAULT_REDACT_PATTERNS],
|
|
78
|
+
};
|
|
79
|
+
return cached;
|
|
80
|
+
}
|
|
81
|
+
function safeRegex(s) {
|
|
82
|
+
try {
|
|
83
|
+
return new RegExp(s, "g");
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return new RegExp(s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Update SDK config programmatically. Only supplied keys are changed. */
|
|
90
|
+
export function configure(opts) {
|
|
91
|
+
overrides = { ...overrides, ...opts };
|
|
92
|
+
cached = null; // force re-resolve on next read
|
|
93
|
+
return resolveConfig();
|
|
94
|
+
}
|
|
95
|
+
/** Get the active config (re-resolves if `configure()` was called). */
|
|
96
|
+
export function getConfig() {
|
|
97
|
+
return resolveConfig();
|
|
98
|
+
}
|
|
99
|
+
/** Reset to env-only config. Useful for tests. */
|
|
100
|
+
export function resetConfig() {
|
|
101
|
+
overrides = {};
|
|
102
|
+
cached = null;
|
|
103
|
+
}
|
|
104
|
+
/** Module-level strict flag, mirrored from config.strict (parity with Python SDK). */
|
|
105
|
+
export let strict_mode = resolveConfig().strict;
|
|
106
|
+
export function _syncStrictFlag() {
|
|
107
|
+
// Re-import trick: reassign the exported let.
|
|
108
|
+
// (Called by configure via _sync below.)
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,4EAA4E;AAI5E,wEAAwE;AACxE,MAAM,CAAC,MAAM,uBAAuB,GAAa;IAC/C,sBAAsB,EAAE,wBAAwB;IAChD,4BAA4B,EAAE,8BAA8B;IAC5D,oBAAoB,EAAE,qCAAqC;IAC3D,wDAAwD,EAAE,cAAc;CACzE,CAAC;AAgBF,SAAS,SAAS,CAAC,IAAY,EAAE,QAAiB;IAChD,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,OAAO,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,SAAS,CAAC,IAAY,EAAE,QAAgB;IAC/C,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,EAAE;QAAE,OAAO,QAAQ,CAAC;IACjD,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACpB,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC3C,CAAC;AAED,SAAS,OAAO,CAAC,IAAY,EAAE,QAAiB;IAC9C,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,EAAE;QAAE,OAAO,QAAQ,CAAC;IACjD,OAAO,CA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,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,SAAS,CAAC,CAAS;IAC1B,IAAI,CAAC;QACH,OAAO,IAAI,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,SAAS,CAAC,IAAmB;IAC3C,SAAS,GAAG,EAAE,GAAG,SAAS,EAAE,GAAG,IAAI,EAAE,CAAC;IACtC,MAAM,GAAG,IAAI,CAAC,CAAC,gCAAgC;IAC/C,OAAO,aAAa,EAAE,CAAC;AACzB,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,SAAS;IACvB,OAAO,aAAa,EAAE,CAAC;AACzB,CAAC;AAED,kDAAkD;AAClD,MAAM,UAAU,WAAW;IACzB,SAAS,GAAG,EAAE,CAAC;IACf,MAAM,GAAG,IAAI,CAAC;AAChB,CAAC;AAED,sFAAsF;AACtF,MAAM,CAAC,IAAI,WAAW,GAAY,aAAa,EAAE,CAAC,MAAM,CAAC;AAEzD,MAAM,UAAU,eAAe;IAC7B,8CAA8C;IAC9C,yCAAyC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { InternalSession, SessionStep, TraceOptions } from "./types.js";
|
|
2
|
+
/** Return the innermost active recording session, if any. */
|
|
3
|
+
export declare function currentSession(): InternalSession | undefined;
|
|
4
|
+
/** Append a normalized step to the current session. No-op if no session. */
|
|
5
|
+
export declare function appendStep(step: SessionStep): void;
|
|
6
|
+
/**
|
|
7
|
+
* `withTrace` — async context manager. Wraps a function body in a recorded
|
|
8
|
+
* session; on exit computes duration/tokens/cost/status and POSTs to the API.
|
|
9
|
+
*
|
|
10
|
+
* Errors from the wrapped function are re-thrown as-is; recording failures
|
|
11
|
+
* are swallowed unless `strict` mode is on.
|
|
12
|
+
*/
|
|
13
|
+
export declare function withTrace<T>(name: string, opts: TraceOptions | undefined, fn: () => T | Promise<T>): Promise<T>;
|
|
14
|
+
/** `trace` — higher-order function. Returns a wrapped fn with the same signature. */
|
|
15
|
+
export declare function trace<T extends (...args: never[]) => unknown>(name: string, opts: TraceOptions | undefined, fn: T): T;
|
|
16
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,eAAe,EAEf,WAAW,EACX,YAAY,EACb,MAAM,YAAY,CAAC;AAOpB,6DAA6D;AAC7D,wBAAgB,cAAc,IAAI,eAAe,GAAG,SAAS,CAE5D;AA6BD,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAWlD;AAkDD;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,YAAY,GAAG,SAAS,EAC9B,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACvB,OAAO,CAAC,CAAC,CAAC,CA+BZ;AAED,qFAAqF;AACrF,wBAAgB,KAAK,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,EAC3D,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,YAAY,GAAG,SAAS,EAC9B,EAAE,EAAE,CAAC,GACJ,CAAC,CAOH"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// ReplayAI TypeScript SDK — context.
|
|
2
|
+
// AsyncLocalStorage-based current-session tracking. `withTrace()` is the
|
|
3
|
+
// context manager; `trace()` is the higher-order wrapper.
|
|
4
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { getConfig } from "./config.js";
|
|
7
|
+
import { estimateCost } from "./cost.js";
|
|
8
|
+
import { flushSession } from "./store.js";
|
|
9
|
+
const storage = new AsyncLocalStorage();
|
|
10
|
+
/** Return the innermost active recording session, if any. */
|
|
11
|
+
export function currentSession() {
|
|
12
|
+
return storage.getStore();
|
|
13
|
+
}
|
|
14
|
+
function nowMs() {
|
|
15
|
+
return Date.now();
|
|
16
|
+
}
|
|
17
|
+
function shouldSample(rate) {
|
|
18
|
+
if (rate >= 1)
|
|
19
|
+
return true;
|
|
20
|
+
if (rate <= 0)
|
|
21
|
+
return false;
|
|
22
|
+
return Math.random() < rate;
|
|
23
|
+
}
|
|
24
|
+
function startSession(name, opts) {
|
|
25
|
+
const cfg = getConfig();
|
|
26
|
+
const startedAt = opts?.startedAt ?? new Date();
|
|
27
|
+
return {
|
|
28
|
+
id: randomUUID(),
|
|
29
|
+
name,
|
|
30
|
+
agent: opts?.agent ?? name,
|
|
31
|
+
project: opts?.project ?? cfg.project,
|
|
32
|
+
framework: opts?.framework ?? "Custom",
|
|
33
|
+
tags: opts?.tags ? [...opts.tags] : [],
|
|
34
|
+
startedAt,
|
|
35
|
+
__startMs: startedAt.getTime(),
|
|
36
|
+
steps: [],
|
|
37
|
+
status: "running",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Append a normalized step to the current session. No-op if no session. */
|
|
41
|
+
export function appendStep(step) {
|
|
42
|
+
const s = currentSession();
|
|
43
|
+
if (!s)
|
|
44
|
+
return;
|
|
45
|
+
// Infer offset from session start if missing.
|
|
46
|
+
if (step.t === undefined && step.offsetMs === undefined) {
|
|
47
|
+
step.t = Math.max(0, nowMs() - s.__startMs);
|
|
48
|
+
}
|
|
49
|
+
if (step.offsetMs === undefined && step.t !== undefined)
|
|
50
|
+
step.offsetMs = step.t;
|
|
51
|
+
if (step.t === undefined && step.offsetMs !== undefined)
|
|
52
|
+
step.t = step.offsetMs;
|
|
53
|
+
if (step.durationMs === undefined)
|
|
54
|
+
step.durationMs = 0;
|
|
55
|
+
s.steps.push(step);
|
|
56
|
+
}
|
|
57
|
+
/** Compute final totals + status and POST the session to the API. */
|
|
58
|
+
async function endAndFlush(session) {
|
|
59
|
+
session.endAt = new Date();
|
|
60
|
+
const wallClockDuration = session.endAt.getTime() - session.startedAt.getTime();
|
|
61
|
+
// Session duration = max(wall-clock, latest step end).
|
|
62
|
+
let stepEndMax = 0;
|
|
63
|
+
for (const s of session.steps) {
|
|
64
|
+
const t = s.offsetMs ?? s.t ?? 0;
|
|
65
|
+
const d = s.durationMs ?? 0;
|
|
66
|
+
stepEndMax = Math.max(stepEndMax, t + d);
|
|
67
|
+
}
|
|
68
|
+
const durationMs = Math.max(wallClockDuration, stepEndMax);
|
|
69
|
+
// Derive status.
|
|
70
|
+
let status = session.status;
|
|
71
|
+
if (session.error !== undefined) {
|
|
72
|
+
status = "failed";
|
|
73
|
+
}
|
|
74
|
+
else if (session.steps.some((s) => s.status === "failed")) {
|
|
75
|
+
status = "failed";
|
|
76
|
+
}
|
|
77
|
+
else if (session.steps.length > 0) {
|
|
78
|
+
status = "success";
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
status = "success";
|
|
82
|
+
}
|
|
83
|
+
const tokenTotal = session.steps.reduce((a, s) => a + (s.tokensIn ?? 0) + (s.tokensOut ?? 0), 0);
|
|
84
|
+
const costUsd = estimateCost(session.steps);
|
|
85
|
+
await flushSession({
|
|
86
|
+
sessionId: session.id,
|
|
87
|
+
name: session.name,
|
|
88
|
+
agent: session.agent,
|
|
89
|
+
project: session.project,
|
|
90
|
+
framework: session.framework,
|
|
91
|
+
tags: session.tags,
|
|
92
|
+
startedAt: session.startedAt,
|
|
93
|
+
durationMs,
|
|
94
|
+
status,
|
|
95
|
+
tokenTotal,
|
|
96
|
+
costUsd,
|
|
97
|
+
steps: session.steps,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* `withTrace` — async context manager. Wraps a function body in a recorded
|
|
102
|
+
* session; on exit computes duration/tokens/cost/status and POSTs to the API.
|
|
103
|
+
*
|
|
104
|
+
* Errors from the wrapped function are re-thrown as-is; recording failures
|
|
105
|
+
* are swallowed unless `strict` mode is on.
|
|
106
|
+
*/
|
|
107
|
+
export async function withTrace(name, opts, fn) {
|
|
108
|
+
const cfg = getConfig();
|
|
109
|
+
const rate = opts?.sampleRate ?? cfg.sampleRate;
|
|
110
|
+
if (!shouldSample(rate)) {
|
|
111
|
+
// Not sampled: run the fn without tracing.
|
|
112
|
+
return await fn();
|
|
113
|
+
}
|
|
114
|
+
const session = startSession(name, opts);
|
|
115
|
+
return await storage.run(session, async () => {
|
|
116
|
+
let result;
|
|
117
|
+
try {
|
|
118
|
+
result = await fn();
|
|
119
|
+
if (session.status === "running")
|
|
120
|
+
session.status = "success";
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
session.status = "failed";
|
|
124
|
+
session.error = err;
|
|
125
|
+
try {
|
|
126
|
+
await endAndFlush(session);
|
|
127
|
+
}
|
|
128
|
+
catch (flushErr) {
|
|
129
|
+
if (cfg.strict)
|
|
130
|
+
throw flushErr;
|
|
131
|
+
}
|
|
132
|
+
throw err;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
await endAndFlush(session);
|
|
136
|
+
}
|
|
137
|
+
catch (flushErr) {
|
|
138
|
+
if (cfg.strict)
|
|
139
|
+
throw flushErr;
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/** `trace` — higher-order function. Returns a wrapped fn with the same signature. */
|
|
145
|
+
export function trace(name, opts, fn) {
|
|
146
|
+
const wrapped = (...args) => {
|
|
147
|
+
return withTrace(name, opts, () => fn(...args));
|
|
148
|
+
};
|
|
149
|
+
// Preserve name/length for nicer stack traces / introspection.
|
|
150
|
+
Object.defineProperty(wrapped, "name", { value: fn.name || "trace", configurable: true });
|
|
151
|
+
return wrapped;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAmB,CAAC;AAEzD,6DAA6D;AAC7D,MAAM,UAAU,cAAc;IAC5B,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;AAC5B,CAAC;AAED,SAAS,KAAK;IACZ,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;AACpB,CAAC;AAED,SAAS,YAAY,CAAC,IAAY;IAChC,IAAI,IAAI,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3B,IAAI,IAAI,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5B,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;AAC9B,CAAC;AAED,SAAS,YAAY,CAAC,IAAY,EAAE,IAA8B;IAChE,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;IACxB,MAAM,SAAS,GAAG,IAAI,EAAE,SAAS,IAAI,IAAI,IAAI,EAAE,CAAC;IAChD,OAAO;QACL,EAAE,EAAE,UAAU,EAAE;QAChB,IAAI;QACJ,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,IAAI;QAC1B,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,GAAG,CAAC,OAAO;QACrC,SAAS,EAAE,IAA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CAAC,CAAC;YAC7B,CAAC;YAAC,OAAO,QAAQ,EAAE,CAAC;gBAClB,IAAI,GAAG,CAAC,MAAM;oBAAE,MAAM,QAAQ,CAAC;YACjC,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;QACD,IAAI,CAAC;YACH,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QAAC,OAAO,QAAQ,EAAE,CAAC;YAClB,IAAI,GAAG,CAAC,MAAM;gBAAE,MAAM,QAAQ,CAAC;QACjC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,KAAK,CACnB,IAAY,EACZ,IAA8B,EAC9B,EAAK;IAEL,MAAM,OAAO,GAAG,CAAC,GAAG,IAAmB,EAAmC,EAAE;QAC1E,OAAO,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAoC,CAAC;IACrF,CAAC,CAAC;IACF,+DAA+D;IAC/D,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,IAAI,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1F,OAAO,OAAuB,CAAC;AACjC,CAAC"}
|
package/dist/cost.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SessionStep } from "./types.js";
|
|
2
|
+
interface Rate {
|
|
3
|
+
in: number;
|
|
4
|
+
out: number;
|
|
5
|
+
}
|
|
6
|
+
/** Per-1M-token USD rates for common models. */
|
|
7
|
+
export declare const DEFAULT_RATES: Record<string, Rate>;
|
|
8
|
+
/** Fallback rate used when a model isn't in the table. Matches the API. */
|
|
9
|
+
export declare const FALLBACK_RATE: Rate;
|
|
10
|
+
/**
|
|
11
|
+
* Estimate total USD cost across a list of steps.
|
|
12
|
+
* Steps without a model use the fallback rate; steps without tokens
|
|
13
|
+
* contribute zero.
|
|
14
|
+
*/
|
|
15
|
+
export declare function estimateCost(steps: Array<SessionStep | {
|
|
16
|
+
model?: string | null;
|
|
17
|
+
tokensIn?: number | null;
|
|
18
|
+
tokensOut?: number | null;
|
|
19
|
+
}>): number;
|
|
20
|
+
/** Estimate cost for a single step. */
|
|
21
|
+
export declare function estimateStepCost(model: string | null | undefined, tokensIn?: number, tokensOut?: number): number;
|
|
22
|
+
/** Read-only copy of the rate table. */
|
|
23
|
+
export declare function getModelRates(): Record<string, Rate>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=cost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../src/cost.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,UAAU,IAAI;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACb;AAED,gDAAgD;AAChD,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAW9C,CAAC;AAEF,2EAA2E;AAC3E,eAAO,MAAM,aAAa,EAAE,IAA8B,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,GAAG,MAAM,CAW/I;AAED,uCAAuC;AACvC,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,QAAQ,SAAI,EACZ,SAAS,SAAI,GACZ,MAAM,CAER;AAED,wCAAwC;AACxC,wBAAgB,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAEpD"}
|
package/dist/cost.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// ReplayAI TypeScript SDK — per-model cost estimation.
|
|
2
|
+
// Rates are per 1,000,000 tokens in USD, matching the API's estimator.
|
|
3
|
+
/** Per-1M-token USD rates for common models. */
|
|
4
|
+
export const DEFAULT_RATES = {
|
|
5
|
+
"gpt-4o": { in: 2.5, out: 10.0 },
|
|
6
|
+
"gpt-4o-mini": { in: 0.15, out: 0.6 },
|
|
7
|
+
"gpt-4-turbo": { in: 10.0, out: 30.0 },
|
|
8
|
+
"gpt-3.5-turbo": { in: 0.5, out: 1.5 },
|
|
9
|
+
"claude-3.5-sonnet": { in: 3.0, out: 15.0 },
|
|
10
|
+
"claude-3-5-haiku": { in: 0.8, out: 4.0 },
|
|
11
|
+
"claude-3-opus": { in: 15.0, out: 75.0 },
|
|
12
|
+
"gemini-1.5-pro": { in: 1.25, out: 5.0 },
|
|
13
|
+
"gemini-1.5-flash": { in: 0.075, out: 0.3 },
|
|
14
|
+
"llama-3.1-70b": { in: 0.59, out: 0.79 },
|
|
15
|
+
};
|
|
16
|
+
/** Fallback rate used when a model isn't in the table. Matches the API. */
|
|
17
|
+
export const FALLBACK_RATE = DEFAULT_RATES["gpt-4o"];
|
|
18
|
+
/**
|
|
19
|
+
* Estimate total USD cost across a list of steps.
|
|
20
|
+
* Steps without a model use the fallback rate; steps without tokens
|
|
21
|
+
* contribute zero.
|
|
22
|
+
*/
|
|
23
|
+
export function estimateCost(steps) {
|
|
24
|
+
let total = 0;
|
|
25
|
+
for (const s of steps) {
|
|
26
|
+
const model = s.model ?? undefined;
|
|
27
|
+
const rate = model && DEFAULT_RATES[model] ? DEFAULT_RATES[model] : FALLBACK_RATE;
|
|
28
|
+
const tokensIn = s.tokensIn ?? 0;
|
|
29
|
+
const tokensOut = s.tokensOut ?? 0;
|
|
30
|
+
total += (tokensIn / 1_000_000) * rate.in;
|
|
31
|
+
total += (tokensOut / 1_000_000) * rate.out;
|
|
32
|
+
}
|
|
33
|
+
return Math.round(total * 1_000_000) / 1_000_000;
|
|
34
|
+
}
|
|
35
|
+
/** Estimate cost for a single step. */
|
|
36
|
+
export function estimateStepCost(model, tokensIn = 0, tokensOut = 0) {
|
|
37
|
+
return estimateCost([{ model, tokensIn, tokensOut }]);
|
|
38
|
+
}
|
|
39
|
+
/** Read-only copy of the rate table. */
|
|
40
|
+
export function getModelRates() {
|
|
41
|
+
return { ...DEFAULT_RATES };
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=cost.js.map
|
package/dist/cost.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost.js","sourceRoot":"","sources":["../src/cost.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,uEAAuE;AASvE,gDAAgD;AAChD,MAAM,CAAC,MAAM,aAAa,GAAyB;IACjD,QAAQ,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE;IAChC,aAAa,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE;IACrC,aAAa,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE;IACtC,eAAe,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;IACtC,mBAAmB,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE;IAC3C,kBAAkB,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;IACzC,eAAe,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE;IACxC,gBAAgB,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE;IACxC,kBAAkB,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE;IAC3C,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
+
import { configure, getConfig, resetConfig } from "./config.js";
|
|
2
|
+
import { currentSession, trace, withTrace } from "./context.js";
|
|
3
|
+
import { recordStep, recordStepSync } from "./steps.js";
|
|
4
|
+
import { ReplaySession } from "./session.js";
|
|
5
|
+
import { flushSession, getLastFlushResult } from "./store.js";
|
|
6
|
+
import { estimateCost, estimateStepCost } from "./cost.js";
|
|
7
|
+
import { redactText, redactOptional } from "./redact.js";
|
|
8
|
+
import type { AgentProject, AgentSession, ConfigOptions, ExportLang, InternalSession, RecordStepInput, ReplaySessionOptions, RunOptions, SessionStatus, SessionStep, StepStatus, StepType, Trace, TraceOptions } from "./types.js";
|
|
9
|
+
/** SDK version. */
|
|
10
|
+
export declare const VERSION = "0.4.1";
|
|
11
|
+
export { trace, withTrace, recordStep, recordStepSync, configure, getConfig, resetConfig, currentSession, ReplaySession, flushSession, getLastFlushResult, estimateCost, estimateStepCost, redactText, redactOptional, };
|
|
12
|
+
export type { AgentProject, AgentSession, ConfigOptions, ExportLang, InternalSession, RecordStepInput, ReplaySessionOptions, RunOptions, SessionStatus, SessionStep, StepStatus, StepType, Trace, TraceOptions, };
|
|
13
|
+
declare const replayai: {
|
|
14
|
+
VERSION: string;
|
|
15
|
+
trace: typeof trace;
|
|
16
|
+
withTrace: typeof withTrace;
|
|
17
|
+
recordStep: typeof recordStep;
|
|
18
|
+
recordStepSync: typeof recordStepSync;
|
|
19
|
+
configure: typeof configure;
|
|
20
|
+
getConfig: typeof getConfig;
|
|
21
|
+
resetConfig: typeof resetConfig;
|
|
22
|
+
currentSession: typeof currentSession;
|
|
23
|
+
ReplaySession: typeof ReplaySession;
|
|
24
|
+
flushSession: typeof flushSession;
|
|
25
|
+
getLastFlushResult: typeof getLastFlushResult;
|
|
26
|
+
estimateCost: typeof estimateCost;
|
|
27
|
+
estimateStepCost: typeof estimateStepCost;
|
|
28
|
+
redactText: typeof redactText;
|
|
29
|
+
redactOptional: typeof redactOptional;
|
|
30
|
+
};
|
|
31
|
+
export default replayai;
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,UAAU,EACV,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,UAAU,EACV,aAAa,EACb,WAAW,EACX,UAAU,EACV,QAAQ,EACR,KAAK,EACL,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,mBAAmB;AACnB,eAAO,MAAM,OAAO,UAAU,CAAC;AAE/B,OAAO,EACL,KAAK,EACL,SAAS,EACT,UAAU,EACV,cAAc,EACd,SAAS,EACT,SAAS,EACT,WAAW,EACX,cAAc,EACd,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,cAAc,GACf,CAAC;AAEF,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,UAAU,EACV,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,UAAU,EACV,aAAa,EACb,WAAW,EACX,UAAU,EACV,QAAQ,EACR,KAAK,EACL,YAAY,GACb,CAAC;AAIF,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;;;CAiBb,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// ReplayAI TypeScript SDK — public entry point.
|
|
2
|
+
import { configure, getConfig, resetConfig } from "./config.js";
|
|
3
|
+
import { currentSession, trace, withTrace } from "./context.js";
|
|
4
|
+
import { recordStep, recordStepSync } from "./steps.js";
|
|
5
|
+
import { ReplaySession } from "./session.js";
|
|
6
|
+
import { flushSession, getLastFlushResult } from "./store.js";
|
|
7
|
+
import { estimateCost, estimateStepCost } from "./cost.js";
|
|
8
|
+
import { redactText, redactOptional } from "./redact.js";
|
|
9
|
+
/** SDK version. */
|
|
10
|
+
export const VERSION = "0.4.1";
|
|
11
|
+
export { trace, withTrace, recordStep, recordStepSync, configure, getConfig, resetConfig, currentSession, ReplaySession, flushSession, getLastFlushResult, estimateCost, estimateStepCost, redactText, redactOptional, };
|
|
12
|
+
// Default export is a namespace object — handy for CJS consumers and as a
|
|
13
|
+
// single `import replayai from "@replayai/sdk"` import.
|
|
14
|
+
const replayai = {
|
|
15
|
+
VERSION,
|
|
16
|
+
trace,
|
|
17
|
+
withTrace,
|
|
18
|
+
recordStep,
|
|
19
|
+
recordStepSync,
|
|
20
|
+
configure,
|
|
21
|
+
getConfig,
|
|
22
|
+
resetConfig,
|
|
23
|
+
currentSession,
|
|
24
|
+
ReplaySession,
|
|
25
|
+
flushSession,
|
|
26
|
+
getLastFlushResult,
|
|
27
|
+
estimateCost,
|
|
28
|
+
estimateStepCost,
|
|
29
|
+
redactText,
|
|
30
|
+
redactOptional,
|
|
31
|
+
};
|
|
32
|
+
export default replayai;
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAEhD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAkBzD,mBAAmB;AACnB,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,OAAO,EACL,KAAK,EACL,SAAS,EACT,UAAU,EACV,cAAc,EACd,SAAS,EACT,SAAS,EACT,WAAW,EACX,cAAc,EACd,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,cAAc,GACf,CAAC;AAmBF,0EAA0E;AAC1E,wDAAwD;AACxD,MAAM,QAAQ,GAAG;IACf,OAAO;IACP,KAAK;IACL,SAAS;IACT,UAAU;IACV,cAAc;IACd,SAAS;IACT,SAAS;IACT,WAAW;IACX,cAAc;IACd,aAAa;IACb,YAAY;IACZ,kBAAkB;IAClB,YAAY;IACZ,gBAAgB;IAChB,UAAU;IACV,cAAc;CACf,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
package/dist/redact.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const REDACTED = "[REDACTED]";
|
|
2
|
+
/**
|
|
3
|
+
* Redact secrets from any value, returning a string.
|
|
4
|
+
*
|
|
5
|
+
* Non-string inputs are first stringified (JSON for objects) so nested
|
|
6
|
+
* secrets are scanned too. Each configured regex pattern is applied in
|
|
7
|
+
* order; matches are replaced with `[REDACTED]`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function redactText(value: unknown): string;
|
|
10
|
+
/** Redact an optional string. `null`/`undefined` pass through unchanged. */
|
|
11
|
+
export declare function redactOptional(value: string | null | undefined): string | null;
|
|
12
|
+
//# sourceMappingURL=redact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ,eAAe,CAAC;AAsBrC;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAejD;AAED,4EAA4E;AAC5E,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAG9E"}
|
package/dist/redact.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// ReplayAI TypeScript SDK — redaction.
|
|
2
|
+
// Secrets are scrubbed from step input/output before they're persisted.
|
|
3
|
+
import { getConfig } from "./config.js";
|
|
4
|
+
export const REDACTED = "[REDACTED]";
|
|
5
|
+
function stringify(value) {
|
|
6
|
+
if (value === null || value === undefined)
|
|
7
|
+
return "";
|
|
8
|
+
if (typeof value === "string")
|
|
9
|
+
return value;
|
|
10
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
11
|
+
return String(value);
|
|
12
|
+
}
|
|
13
|
+
if (typeof value === "object") {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.stringify(value);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
try {
|
|
19
|
+
return String(value);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return "[unserializable]";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return String(value);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Redact secrets from any value, returning a string.
|
|
30
|
+
*
|
|
31
|
+
* Non-string inputs are first stringified (JSON for objects) so nested
|
|
32
|
+
* secrets are scanned too. Each configured regex pattern is applied in
|
|
33
|
+
* order; matches are replaced with `[REDACTED]`.
|
|
34
|
+
*/
|
|
35
|
+
export function redactText(value) {
|
|
36
|
+
let text = stringify(value);
|
|
37
|
+
if (!text)
|
|
38
|
+
return "";
|
|
39
|
+
const cfg = getConfig();
|
|
40
|
+
for (const re of cfg.redactPatterns) {
|
|
41
|
+
// Each call needs a fresh lastIndex since these regexes have the `g` flag.
|
|
42
|
+
re.lastIndex = 0;
|
|
43
|
+
try {
|
|
44
|
+
text = text.replace(re, REDACTED);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Malformed user-supplied patterns shouldn't crash the agent.
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return text;
|
|
52
|
+
}
|
|
53
|
+
/** Redact an optional string. `null`/`undefined` pass through unchanged. */
|
|
54
|
+
export function redactOptional(value) {
|
|
55
|
+
if (value === null || value === undefined)
|
|
56
|
+
return null;
|
|
57
|
+
return redactText(value);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=redact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact.js","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,wEAAwE;AAExE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAY,CAAC;AAErC,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACzF,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC;gBACH,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,kBAAkB,CAAC;YAC5B,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,IAAI,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAC5B,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;IACxB,KAAK,MAAM,EAAE,IAAI,GAAG,CAAC,cAAc,EAAE,CAAC;QACpC,2EAA2E;QAC3E,EAAE,CAAC,SAAS,GAAG,CAAC,CAAC;QACjB,IAAI,CAAC;YACH,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;QACpC,CAAC;QAAC,MAAM,CAAC;YACP,8DAA8D;YAC9D,SAAS;QACX,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,cAAc,CAAC,KAAgC;IAC7D,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACvD,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ExportLang, ReplaySessionOptions, RunOptions, Trace } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* ReplaySession — load a previously-recorded session from the API and either
|
|
4
|
+
* re-run it (returning a `Trace`) or export it as a pytest/jest test.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* const replay = new ReplaySession("ses_8fa1", { liveLlm: false });
|
|
8
|
+
* replay.mock("issue_refund", JSON.stringify({ refund_id: "ref_3391" }));
|
|
9
|
+
* const trace = await replay.run({ agent: "support-agent-v3", framework: "LangChain" });
|
|
10
|
+
* console.log(trace.stepCount, trace.status);
|
|
11
|
+
* const code = await replay.export("pytest");
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare class ReplaySession {
|
|
15
|
+
readonly sessionId: string;
|
|
16
|
+
readonly liveLlm: boolean;
|
|
17
|
+
/** fnName → canned response (JSON string). */
|
|
18
|
+
readonly mocks: Record<string, string>;
|
|
19
|
+
constructor(sessionId: string, opts?: ReplaySessionOptions);
|
|
20
|
+
/** Register a canned response for a mocked function call. */
|
|
21
|
+
mock(fnName: string, response: string | object): void;
|
|
22
|
+
/**
|
|
23
|
+
* Fetch the session and return a `Trace` view of it.
|
|
24
|
+
*
|
|
25
|
+
* The `agent`/`framework` opts are accepted for API parity with the Python
|
|
26
|
+
* SDK; the session's stored agent/framework take precedence.
|
|
27
|
+
*/
|
|
28
|
+
run(opts: RunOptions): Promise<Trace>;
|
|
29
|
+
/** Fetch the session exported as a pytest or jest test source string. */
|
|
30
|
+
export(lang?: ExportLang): Promise<string>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,UAAU,EACV,oBAAoB,EACpB,UAAU,EAGV,KAAK,EACN,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;GAWG;AACH,qBAAa,aAAa;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,8CAA8C;IAC9C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;gBAEhC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,oBAAoB;IAK1D,6DAA6D;IAC7D,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIrD;;;;;OAKG;IACG,GAAG,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC;IAwB3C,yEAAyE;IACnE,MAAM,CAAC,IAAI,GAAE,UAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;CAG3D"}
|