@tracehatch/sdk 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';var chunkU5REKR34_cjs=require('./chunk-U5REKR34.cjs');Object.defineProperty(exports,"TraceHandle",{enumerable:true,get:function(){return chunkU5REKR34_cjs.b}});Object.defineProperty(exports,"Tracehatch",{enumerable:true,get:function(){return chunkU5REKR34_cjs.l}});Object.defineProperty(exports,"addTags",{enumerable:true,get:function(){return chunkU5REKR34_cjs.g}});Object.defineProperty(exports,"flush",{enumerable:true,get:function(){return chunkU5REKR34_cjs.n}});Object.defineProperty(exports,"flushWithResult",{enumerable:true,get:function(){return chunkU5REKR34_cjs.o}});Object.defineProperty(exports,"init",{enumerable:true,get:function(){return chunkU5REKR34_cjs.m}});Object.defineProperty(exports,"score",{enumerable:true,get:function(){return chunkU5REKR34_cjs.i}});Object.defineProperty(exports,"setMetadata",{enumerable:true,get:function(){return chunkU5REKR34_cjs.h}});Object.defineProperty(exports,"setSession",{enumerable:true,get:function(){return chunkU5REKR34_cjs.f}});Object.defineProperty(exports,"setUser",{enumerable:true,get:function(){return chunkU5REKR34_cjs.e}});Object.defineProperty(exports,"shutdown",{enumerable:true,get:function(){return chunkU5REKR34_cjs.p}});Object.defineProperty(exports,"span",{enumerable:true,get:function(){return chunkU5REKR34_cjs.j}});Object.defineProperty(exports,"startTrace",{enumerable:true,get:function(){return chunkU5REKR34_cjs.c}});Object.defineProperty(exports,"tool",{enumerable:true,get:function(){return chunkU5REKR34_cjs.k}});Object.defineProperty(exports,"trace",{enumerable:true,get:function(){return chunkU5REKR34_cjs.d}});//# sourceMappingURL=index.cjs.map
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
@@ -0,0 +1,243 @@
1
+ type Attributes = { [x: string]: string | number | boolean | string[]; }
2
+
3
+ type SpanWire = { id: string; trace_id: string; name: string; kind: "agent" | "generation" | "tool" | "retrieval" | "embedding" | "guardrail" | "custom"; status: "error" | "ok" | "cancelled"; started_at: string; ended_at: string; attempt: number; parent_id?: string | null | undefined; error?: { type?: string | undefined; message?: string | undefined; stack?: string | undefined; } | undefined; attributes?: Record<string, string | number | boolean | string[]> | undefined; input?: unknown; output?: unknown; messages?: unknown; events?: { ts: string; level: "debug" | "info" | "warn" | "error"; name: string; attributes?: Record<string, string | number | boolean | string[]> | undefined; }[] | undefined; input_bytes?: number | undefined; output_bytes?: number | undefined; messages_bytes?: number | undefined; input_truncated?: boolean | undefined; output_truncated?: boolean | undefined; messages_truncated?: boolean | undefined; }
4
+
5
+ type TraceEnvelopeWire = { id: string; name: string; status: "error" | "ok" | "cancelled" | "pending"; started_at: string; agent?: string | undefined; session_id?: string | undefined; user?: { id: string; name?: string | undefined; email?: string | undefined; } | undefined; release?: string | undefined; tags?: string[] | undefined; metadata?: Record<string, unknown> | undefined; ended_at?: string | undefined; root_span_id?: string | undefined; expected_span_count?: number | undefined; input?: unknown; output?: unknown; scores?: { id: string; name: string; value: string | number; comment?: string | undefined; span_id?: string | undefined; }[] | undefined; }
6
+
7
+ type SpanEventLevel = "debug" | "info" | "warn" | "error"
8
+
9
+ /** What a span did (`spans.kind`, scope 02). */
10
+ declare const SPAN_KIND: readonly ["agent", "generation", "tool", "retrieval", "embedding", "guardrail", "custom"];
11
+ type SpanKind = (typeof SPAN_KIND)[number];
12
+
13
+ /** Platform-neutral redaction, also bundled into the SDK. */
14
+ interface RedactionOptions {
15
+ /** Built-in detectors and credential-key filtering are enabled by default. */
16
+ builtIns?: boolean;
17
+ /** Additional expressions are applied globally without mutating their lastIndex. */
18
+ rules?: readonly {
19
+ name: string;
20
+ pattern: RegExp;
21
+ }[];
22
+ }
23
+
24
+ type User = NonNullable<TraceEnvelopeWire["user"]>;
25
+ type Outcome = "ok" | "error" | "cancelled";
26
+ /** Delivery counters cover this client lifetime; acceptance is not persistence. */
27
+ interface FlushResult {
28
+ status: "disabled" | "empty" | "accepted" | "timeout" | "failed";
29
+ acceptedSpans: number;
30
+ droppedSpans: number;
31
+ pendingSpans: number;
32
+ /** A safe SDK/API code, never request details or arbitrary server text. */
33
+ lastError?: {
34
+ code: string;
35
+ httpStatus?: number;
36
+ };
37
+ }
38
+ interface ScoreOptions {
39
+ name: string;
40
+ value: number | string;
41
+ comment?: string;
42
+ /** Omit to score the trace; set an existing span handle's id to score that span. */
43
+ spanId?: string;
44
+ }
45
+ interface InitOptions {
46
+ apiKey?: string;
47
+ /** Trusted API origin or base; required with an API key, here or via TRACEHATCH_BASE_URL. */
48
+ baseUrl?: string;
49
+ release?: string;
50
+ agent?: string;
51
+ captureBodies?: boolean;
52
+ redact?: false | RedactionOptions;
53
+ sampling?: {
54
+ rate: number;
55
+ };
56
+ debug?: boolean;
57
+ flushOnExit?: boolean;
58
+ }
59
+ interface SpanOptions {
60
+ input?: unknown;
61
+ attributes?: Attributes;
62
+ signal?: AbortSignal;
63
+ }
64
+ interface TraceOptions {
65
+ agent?: string;
66
+ rootName?: string;
67
+ input?: unknown;
68
+ tags?: string[];
69
+ metadata?: Record<string, unknown>;
70
+ sessionId?: string;
71
+ user?: User;
72
+ signal?: AbortSignal;
73
+ }
74
+ interface SpanHandle {
75
+ readonly id: string;
76
+ setOutput(value: unknown): void;
77
+ setAttributes(attributes: Attributes): void;
78
+ addEvent(name: string, attributes?: Attributes, level?: SpanEventLevel): void;
79
+ }
80
+ interface ToolOptions extends SpanOptions {
81
+ /** Extra attempts after the initial call; 0 by default, at most 999. */
82
+ retries?: number;
83
+ backoffMs?: number;
84
+ }
85
+ interface EndOptions {
86
+ status?: Outcome;
87
+ output?: unknown;
88
+ error?: unknown;
89
+ /** Wall-clock end (ISO) for steps recorded after they happened. */
90
+ endedAt?: string;
91
+ }
92
+
93
+ interface ExporterStats {
94
+ queuedSpans: number;
95
+ queuedBytes: number;
96
+ inFlightBatches: number;
97
+ droppedSpans: number;
98
+ }
99
+
100
+ declare class Tracehatch {
101
+ readonly options: {
102
+ captureBodies: boolean;
103
+ redact: false | RedactionOptions;
104
+ release?: string;
105
+ agent?: string;
106
+ };
107
+ private exporter?;
108
+ private enabled;
109
+ private rate;
110
+ private onExit?;
111
+ private closing?;
112
+ constructor(options: InitOptions);
113
+ get isEnabled(): boolean;
114
+ samples(id: string): boolean;
115
+ enqueue(span: SpanWire, trace: TraceEnvelopeWire): void;
116
+ flush(timeoutMs?: number): Promise<void>;
117
+ /** Inspect delivery during setup without making ordinary flush() reject. */
118
+ flushWithResult(timeoutMs?: number): Promise<FlushResult>;
119
+ shutdown(): Promise<void>;
120
+ stats(): ExporterStats;
121
+ }
122
+ /**
123
+ * Configure once per process. With an API key, every provider call made
124
+ * through `fetch`, every inbound HTTP request with a model call, and every
125
+ * explicit `trace`/`span`/`tool` is recorded. Agent and release default to
126
+ * the package name and the deployment's commit.
127
+ */
128
+ declare function init(options?: InitOptions): Tracehatch;
129
+ declare function flush(timeoutMs?: number): Promise<void>;
130
+ declare function flushWithResult(timeoutMs?: number): Promise<FlushResult>;
131
+ declare function shutdown(): Promise<void>;
132
+
133
+ /** Timing the SDK's own capture paths supply for steps that already happened. */
134
+ interface InternalSpanOptions {
135
+ startedAt?: string;
136
+ }
137
+ declare class RecordingSpan implements SpanHandle {
138
+ readonly trace: TraceHandle | undefined;
139
+ readonly parent?: RecordingSpan | undefined;
140
+ readonly id: string;
141
+ private ended;
142
+ private outputSet;
143
+ private removeAbort?;
144
+ private data;
145
+ private readonly isTool;
146
+ private toolCallId?;
147
+ constructor(trace: TraceHandle | undefined, name: string, kind: SpanKind, options?: SpanOptions, parent?: RecordingSpan | undefined, rootId?: string, internal?: InternalSpanOptions);
148
+ get isRecording(): boolean;
149
+ get isEnded(): boolean;
150
+ get hasOutput(): boolean;
151
+ private sanitize;
152
+ run<T>(fn: () => T): T;
153
+ setInput(value: unknown): void;
154
+ setOutput(value: unknown): void;
155
+ /** Size-only stream capture must never retain the generated content. */
156
+ setOutputBytes(bytes: number): void;
157
+ /** A stream assembler can truncate before the generic body size limit. */
158
+ markOutputTruncated(): void;
159
+ setMessages(value: unknown): void;
160
+ setAttributes(attributes: Attributes): void;
161
+ addEvent(name: string, attributes?: Attributes, level?: SpanEventLevel): void;
162
+ setAttempt(attempt: number): void;
163
+ end(options?: EndOptions): void;
164
+ }
165
+ declare function span<T>(name: string, kind: SpanKind, fn: (handle: SpanHandle) => T, options?: SpanOptions): Promise<Awaited<T>>;
166
+ declare function tool<T>(name: string, fn: (handle: SpanHandle) => T, options?: ToolOptions): Promise<Awaited<T>>;
167
+
168
+ /** Behaviour only the SDK's own capture paths need. */
169
+ interface InternalTraceOptions {
170
+ /** End without sending anything when no span other than the root was recorded. */
171
+ discardIfEmpty?: boolean;
172
+ /** Only SDK-created runs derive transcript content from their provider calls. */
173
+ inferProviderBodies?: boolean;
174
+ }
175
+ interface EndTraceOptions {
176
+ outcome?: Outcome;
177
+ output?: unknown;
178
+ error?: unknown;
179
+ /** Wall-clock end (ISO) when the run ended earlier than the call, e.g. an automatic run. */
180
+ endedAt?: string;
181
+ }
182
+ declare class TraceHandle {
183
+ readonly client: Tracehatch;
184
+ private readonly internal;
185
+ readonly id: `run_${string}`;
186
+ readonly root: RecordingSpan;
187
+ private sampled;
188
+ private ended;
189
+ private ending;
190
+ private outputSet;
191
+ private inputSet;
192
+ private inferredInputSet;
193
+ private readonly activeSpans;
194
+ private readonly captures;
195
+ private readonly recordedToolCalls;
196
+ private expectedSpanCount;
197
+ private data;
198
+ private removeAbort?;
199
+ constructor(client: Tracehatch, name: string, options?: TraceOptions, internal?: InternalTraceOptions);
200
+ get isRecording(): boolean;
201
+ get isEnded(): boolean;
202
+ get hasOutput(): boolean;
203
+ /** True once a span other than the root was recorded. */
204
+ get hasChildren(): boolean;
205
+ registerSpan(span: RecordingSpan): void;
206
+ unregisterSpan(span: RecordingSpan): void;
207
+ /** Exact provider call identity lets explicit tool instrumentation take precedence. */
208
+ rememberToolCall(callId: string): void;
209
+ hasRecordedToolCall(callId: string): boolean;
210
+ /** A provider response still being read from its clone; `end()` waits for it. */
211
+ track(capture: Promise<unknown>): void;
212
+ private settle;
213
+ private sanitize;
214
+ snapshot(): TraceEnvelopeWire;
215
+ run<T>(fn: (handle: TraceHandle) => T): T;
216
+ setInput(value: unknown): void;
217
+ setOutput(value: unknown): void;
218
+ /** Capture internals only: explicit application values always take precedence. */
219
+ captureProviderInput(value: unknown): void;
220
+ captureProviderOutput(value: unknown): void;
221
+ setUser(user: User): void;
222
+ setSession(id: string): void;
223
+ addTags(...tags: string[]): void;
224
+ setMetadata(metadata: Record<string, unknown>): void;
225
+ /** Scores travel with subsequent completed spans, including the final root. */
226
+ score(options: ScoreOptions): void;
227
+ /**
228
+ * End the run. A provider response still being read (a stream the caller
229
+ * consumes after the run's callback returned, or a body parsed in parallel
230
+ * with the caller) delays the end until it finishes, bounded by
231
+ * `captureSettleMs`, so the generation is recorded instead of cancelled.
232
+ */
233
+ end(options?: EndTraceOptions): void;
234
+ }
235
+ declare function startTrace(name: string, options?: TraceOptions): TraceHandle;
236
+ declare function trace<T>(name: string, fn: (handle: TraceHandle) => T, options?: TraceOptions): Promise<Awaited<T>>;
237
+ declare function setUser(user: User): void;
238
+ declare function setSession(id: string): void;
239
+ declare function addTags(...tags: string[]): void;
240
+ declare function setMetadata(metadata: Record<string, unknown>): void;
241
+ declare function score(options: ScoreOptions): void;
242
+
243
+ export { type Attributes, type FlushResult, type InitOptions, type Outcome, type RedactionOptions, type ScoreOptions, type SpanHandle, type SpanKind, type SpanOptions, type ToolOptions, TraceHandle, type TraceOptions, Tracehatch, type User, addTags, flush, flushWithResult, init, score, setMetadata, setSession, setUser, shutdown, span, startTrace, tool, trace };
@@ -0,0 +1,243 @@
1
+ type Attributes = { [x: string]: string | number | boolean | string[]; }
2
+
3
+ type SpanWire = { id: string; trace_id: string; name: string; kind: "agent" | "generation" | "tool" | "retrieval" | "embedding" | "guardrail" | "custom"; status: "error" | "ok" | "cancelled"; started_at: string; ended_at: string; attempt: number; parent_id?: string | null | undefined; error?: { type?: string | undefined; message?: string | undefined; stack?: string | undefined; } | undefined; attributes?: Record<string, string | number | boolean | string[]> | undefined; input?: unknown; output?: unknown; messages?: unknown; events?: { ts: string; level: "debug" | "info" | "warn" | "error"; name: string; attributes?: Record<string, string | number | boolean | string[]> | undefined; }[] | undefined; input_bytes?: number | undefined; output_bytes?: number | undefined; messages_bytes?: number | undefined; input_truncated?: boolean | undefined; output_truncated?: boolean | undefined; messages_truncated?: boolean | undefined; }
4
+
5
+ type TraceEnvelopeWire = { id: string; name: string; status: "error" | "ok" | "cancelled" | "pending"; started_at: string; agent?: string | undefined; session_id?: string | undefined; user?: { id: string; name?: string | undefined; email?: string | undefined; } | undefined; release?: string | undefined; tags?: string[] | undefined; metadata?: Record<string, unknown> | undefined; ended_at?: string | undefined; root_span_id?: string | undefined; expected_span_count?: number | undefined; input?: unknown; output?: unknown; scores?: { id: string; name: string; value: string | number; comment?: string | undefined; span_id?: string | undefined; }[] | undefined; }
6
+
7
+ type SpanEventLevel = "debug" | "info" | "warn" | "error"
8
+
9
+ /** What a span did (`spans.kind`, scope 02). */
10
+ declare const SPAN_KIND: readonly ["agent", "generation", "tool", "retrieval", "embedding", "guardrail", "custom"];
11
+ type SpanKind = (typeof SPAN_KIND)[number];
12
+
13
+ /** Platform-neutral redaction, also bundled into the SDK. */
14
+ interface RedactionOptions {
15
+ /** Built-in detectors and credential-key filtering are enabled by default. */
16
+ builtIns?: boolean;
17
+ /** Additional expressions are applied globally without mutating their lastIndex. */
18
+ rules?: readonly {
19
+ name: string;
20
+ pattern: RegExp;
21
+ }[];
22
+ }
23
+
24
+ type User = NonNullable<TraceEnvelopeWire["user"]>;
25
+ type Outcome = "ok" | "error" | "cancelled";
26
+ /** Delivery counters cover this client lifetime; acceptance is not persistence. */
27
+ interface FlushResult {
28
+ status: "disabled" | "empty" | "accepted" | "timeout" | "failed";
29
+ acceptedSpans: number;
30
+ droppedSpans: number;
31
+ pendingSpans: number;
32
+ /** A safe SDK/API code, never request details or arbitrary server text. */
33
+ lastError?: {
34
+ code: string;
35
+ httpStatus?: number;
36
+ };
37
+ }
38
+ interface ScoreOptions {
39
+ name: string;
40
+ value: number | string;
41
+ comment?: string;
42
+ /** Omit to score the trace; set an existing span handle's id to score that span. */
43
+ spanId?: string;
44
+ }
45
+ interface InitOptions {
46
+ apiKey?: string;
47
+ /** Trusted API origin or base; required with an API key, here or via TRACEHATCH_BASE_URL. */
48
+ baseUrl?: string;
49
+ release?: string;
50
+ agent?: string;
51
+ captureBodies?: boolean;
52
+ redact?: false | RedactionOptions;
53
+ sampling?: {
54
+ rate: number;
55
+ };
56
+ debug?: boolean;
57
+ flushOnExit?: boolean;
58
+ }
59
+ interface SpanOptions {
60
+ input?: unknown;
61
+ attributes?: Attributes;
62
+ signal?: AbortSignal;
63
+ }
64
+ interface TraceOptions {
65
+ agent?: string;
66
+ rootName?: string;
67
+ input?: unknown;
68
+ tags?: string[];
69
+ metadata?: Record<string, unknown>;
70
+ sessionId?: string;
71
+ user?: User;
72
+ signal?: AbortSignal;
73
+ }
74
+ interface SpanHandle {
75
+ readonly id: string;
76
+ setOutput(value: unknown): void;
77
+ setAttributes(attributes: Attributes): void;
78
+ addEvent(name: string, attributes?: Attributes, level?: SpanEventLevel): void;
79
+ }
80
+ interface ToolOptions extends SpanOptions {
81
+ /** Extra attempts after the initial call; 0 by default, at most 999. */
82
+ retries?: number;
83
+ backoffMs?: number;
84
+ }
85
+ interface EndOptions {
86
+ status?: Outcome;
87
+ output?: unknown;
88
+ error?: unknown;
89
+ /** Wall-clock end (ISO) for steps recorded after they happened. */
90
+ endedAt?: string;
91
+ }
92
+
93
+ interface ExporterStats {
94
+ queuedSpans: number;
95
+ queuedBytes: number;
96
+ inFlightBatches: number;
97
+ droppedSpans: number;
98
+ }
99
+
100
+ declare class Tracehatch {
101
+ readonly options: {
102
+ captureBodies: boolean;
103
+ redact: false | RedactionOptions;
104
+ release?: string;
105
+ agent?: string;
106
+ };
107
+ private exporter?;
108
+ private enabled;
109
+ private rate;
110
+ private onExit?;
111
+ private closing?;
112
+ constructor(options: InitOptions);
113
+ get isEnabled(): boolean;
114
+ samples(id: string): boolean;
115
+ enqueue(span: SpanWire, trace: TraceEnvelopeWire): void;
116
+ flush(timeoutMs?: number): Promise<void>;
117
+ /** Inspect delivery during setup without making ordinary flush() reject. */
118
+ flushWithResult(timeoutMs?: number): Promise<FlushResult>;
119
+ shutdown(): Promise<void>;
120
+ stats(): ExporterStats;
121
+ }
122
+ /**
123
+ * Configure once per process. With an API key, every provider call made
124
+ * through `fetch`, every inbound HTTP request with a model call, and every
125
+ * explicit `trace`/`span`/`tool` is recorded. Agent and release default to
126
+ * the package name and the deployment's commit.
127
+ */
128
+ declare function init(options?: InitOptions): Tracehatch;
129
+ declare function flush(timeoutMs?: number): Promise<void>;
130
+ declare function flushWithResult(timeoutMs?: number): Promise<FlushResult>;
131
+ declare function shutdown(): Promise<void>;
132
+
133
+ /** Timing the SDK's own capture paths supply for steps that already happened. */
134
+ interface InternalSpanOptions {
135
+ startedAt?: string;
136
+ }
137
+ declare class RecordingSpan implements SpanHandle {
138
+ readonly trace: TraceHandle | undefined;
139
+ readonly parent?: RecordingSpan | undefined;
140
+ readonly id: string;
141
+ private ended;
142
+ private outputSet;
143
+ private removeAbort?;
144
+ private data;
145
+ private readonly isTool;
146
+ private toolCallId?;
147
+ constructor(trace: TraceHandle | undefined, name: string, kind: SpanKind, options?: SpanOptions, parent?: RecordingSpan | undefined, rootId?: string, internal?: InternalSpanOptions);
148
+ get isRecording(): boolean;
149
+ get isEnded(): boolean;
150
+ get hasOutput(): boolean;
151
+ private sanitize;
152
+ run<T>(fn: () => T): T;
153
+ setInput(value: unknown): void;
154
+ setOutput(value: unknown): void;
155
+ /** Size-only stream capture must never retain the generated content. */
156
+ setOutputBytes(bytes: number): void;
157
+ /** A stream assembler can truncate before the generic body size limit. */
158
+ markOutputTruncated(): void;
159
+ setMessages(value: unknown): void;
160
+ setAttributes(attributes: Attributes): void;
161
+ addEvent(name: string, attributes?: Attributes, level?: SpanEventLevel): void;
162
+ setAttempt(attempt: number): void;
163
+ end(options?: EndOptions): void;
164
+ }
165
+ declare function span<T>(name: string, kind: SpanKind, fn: (handle: SpanHandle) => T, options?: SpanOptions): Promise<Awaited<T>>;
166
+ declare function tool<T>(name: string, fn: (handle: SpanHandle) => T, options?: ToolOptions): Promise<Awaited<T>>;
167
+
168
+ /** Behaviour only the SDK's own capture paths need. */
169
+ interface InternalTraceOptions {
170
+ /** End without sending anything when no span other than the root was recorded. */
171
+ discardIfEmpty?: boolean;
172
+ /** Only SDK-created runs derive transcript content from their provider calls. */
173
+ inferProviderBodies?: boolean;
174
+ }
175
+ interface EndTraceOptions {
176
+ outcome?: Outcome;
177
+ output?: unknown;
178
+ error?: unknown;
179
+ /** Wall-clock end (ISO) when the run ended earlier than the call, e.g. an automatic run. */
180
+ endedAt?: string;
181
+ }
182
+ declare class TraceHandle {
183
+ readonly client: Tracehatch;
184
+ private readonly internal;
185
+ readonly id: `run_${string}`;
186
+ readonly root: RecordingSpan;
187
+ private sampled;
188
+ private ended;
189
+ private ending;
190
+ private outputSet;
191
+ private inputSet;
192
+ private inferredInputSet;
193
+ private readonly activeSpans;
194
+ private readonly captures;
195
+ private readonly recordedToolCalls;
196
+ private expectedSpanCount;
197
+ private data;
198
+ private removeAbort?;
199
+ constructor(client: Tracehatch, name: string, options?: TraceOptions, internal?: InternalTraceOptions);
200
+ get isRecording(): boolean;
201
+ get isEnded(): boolean;
202
+ get hasOutput(): boolean;
203
+ /** True once a span other than the root was recorded. */
204
+ get hasChildren(): boolean;
205
+ registerSpan(span: RecordingSpan): void;
206
+ unregisterSpan(span: RecordingSpan): void;
207
+ /** Exact provider call identity lets explicit tool instrumentation take precedence. */
208
+ rememberToolCall(callId: string): void;
209
+ hasRecordedToolCall(callId: string): boolean;
210
+ /** A provider response still being read from its clone; `end()` waits for it. */
211
+ track(capture: Promise<unknown>): void;
212
+ private settle;
213
+ private sanitize;
214
+ snapshot(): TraceEnvelopeWire;
215
+ run<T>(fn: (handle: TraceHandle) => T): T;
216
+ setInput(value: unknown): void;
217
+ setOutput(value: unknown): void;
218
+ /** Capture internals only: explicit application values always take precedence. */
219
+ captureProviderInput(value: unknown): void;
220
+ captureProviderOutput(value: unknown): void;
221
+ setUser(user: User): void;
222
+ setSession(id: string): void;
223
+ addTags(...tags: string[]): void;
224
+ setMetadata(metadata: Record<string, unknown>): void;
225
+ /** Scores travel with subsequent completed spans, including the final root. */
226
+ score(options: ScoreOptions): void;
227
+ /**
228
+ * End the run. A provider response still being read (a stream the caller
229
+ * consumes after the run's callback returned, or a body parsed in parallel
230
+ * with the caller) delays the end until it finishes, bounded by
231
+ * `captureSettleMs`, so the generation is recorded instead of cancelled.
232
+ */
233
+ end(options?: EndTraceOptions): void;
234
+ }
235
+ declare function startTrace(name: string, options?: TraceOptions): TraceHandle;
236
+ declare function trace<T>(name: string, fn: (handle: TraceHandle) => T, options?: TraceOptions): Promise<Awaited<T>>;
237
+ declare function setUser(user: User): void;
238
+ declare function setSession(id: string): void;
239
+ declare function addTags(...tags: string[]): void;
240
+ declare function setMetadata(metadata: Record<string, unknown>): void;
241
+ declare function score(options: ScoreOptions): void;
242
+
243
+ export { type Attributes, type FlushResult, type InitOptions, type Outcome, type RedactionOptions, type ScoreOptions, type SpanHandle, type SpanKind, type SpanOptions, type ToolOptions, TraceHandle, type TraceOptions, Tracehatch, type User, addTags, flush, flushWithResult, init, score, setMetadata, setSession, setUser, shutdown, span, startTrace, tool, trace };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export{b as TraceHandle,l as Tracehatch,g as addTags,n as flush,o as flushWithResult,m as init,i as score,h as setMetadata,f as setSession,e as setUser,p as shutdown,j as span,c as startTrace,k as tool,d as trace}from'./chunk-KHVJY566.js';//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@tracehatch/sdk",
3
+ "version": "0.3.0",
4
+ "description": "Record AI agent runs, model calls, sessions and tools in Node.js with one import.",
5
+ "license": "MIT",
6
+ "homepage": "https://tracehatch.com",
7
+ "keywords": [
8
+ "ai",
9
+ "observability",
10
+ "tracing",
11
+ "agents",
12
+ "llm",
13
+ "openai",
14
+ "anthropic",
15
+ "sessions"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/salmandotweb/unravel.git",
20
+ "directory": "packages/sdk"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public",
24
+ "registry": "https://registry.npmjs.org/"
25
+ },
26
+ "type": "module",
27
+ "sideEffects": [
28
+ "./dist/auto.js",
29
+ "./dist/auto.cjs"
30
+ ],
31
+ "main": "./dist/index.cjs",
32
+ "module": "./dist/index.js",
33
+ "types": "./dist/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "import": {
37
+ "types": "./dist/index.d.ts",
38
+ "default": "./dist/index.js"
39
+ },
40
+ "require": {
41
+ "types": "./dist/index.d.cts",
42
+ "default": "./dist/index.cjs"
43
+ }
44
+ },
45
+ "./auto": {
46
+ "import": {
47
+ "types": "./dist/auto.d.ts",
48
+ "default": "./dist/auto.js"
49
+ },
50
+ "require": {
51
+ "types": "./dist/auto.d.cts",
52
+ "default": "./dist/auto.cjs"
53
+ }
54
+ }
55
+ },
56
+ "files": [
57
+ "dist",
58
+ "README.md",
59
+ "GUIDE.md",
60
+ "LICENSE",
61
+ "CHANGELOG.md"
62
+ ],
63
+ "engines": {
64
+ "node": ">=18"
65
+ },
66
+ "tracehatch": {
67
+ "minApi": "1"
68
+ }
69
+ }