@withgateway/sdk 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/index-DnowA8MG.d.mts +447 -0
  2. package/dist/index-DnowA8MG.d.ts +447 -0
  3. package/dist/index.d.mts +6 -1
  4. package/dist/index.d.ts +6 -1
  5. package/dist/index.js +1551 -33
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +1511 -27
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/personas/index.d.mts +102 -0
  10. package/dist/personas/index.d.ts +102 -0
  11. package/dist/personas/index.js +205 -0
  12. package/dist/personas/index.js.map +1 -0
  13. package/dist/personas/index.mjs +180 -0
  14. package/dist/personas/index.mjs.map +1 -0
  15. package/dist/replay/index.d.mts +351 -0
  16. package/dist/replay/index.d.ts +351 -0
  17. package/dist/replay/index.js +1094 -0
  18. package/dist/replay/index.js.map +1 -0
  19. package/dist/replay/index.mjs +1057 -0
  20. package/dist/replay/index.mjs.map +1 -0
  21. package/dist/sessions/index.d.mts +143 -0
  22. package/dist/sessions/index.d.ts +143 -0
  23. package/dist/sessions/index.js +320 -0
  24. package/dist/sessions/index.js.map +1 -0
  25. package/dist/sessions/index.mjs +288 -0
  26. package/dist/sessions/index.mjs.map +1 -0
  27. package/dist/tracing/index.d.mts +3 -1
  28. package/dist/tracing/index.d.ts +3 -1
  29. package/dist/tracing/index.js +277 -31
  30. package/dist/tracing/index.js.map +1 -1
  31. package/dist/tracing/index.mjs +266 -26
  32. package/dist/tracing/index.mjs.map +1 -1
  33. package/dist/users/index.d.mts +81 -0
  34. package/dist/users/index.d.ts +81 -0
  35. package/dist/users/index.js +168 -0
  36. package/dist/users/index.js.map +1 -0
  37. package/dist/users/index.mjs +144 -0
  38. package/dist/users/index.mjs.map +1 -0
  39. package/package.json +21 -1
  40. package/dist/index-yJgb8wh6.d.mts +0 -273
  41. package/dist/index-yJgb8wh6.d.ts +0 -273
@@ -1,273 +0,0 @@
1
- /**
2
- * Types for the tracing module.
3
- */
4
- interface TracingConfig {
5
- /**
6
- * Gateway server URL (e.g., "https://app.gateway.dev").
7
- * Falls back to GATEWAY_HOST or GATEWAY_HOST env var.
8
- */
9
- host?: string;
10
- /**
11
- * Public key for authentication (pk-lf-...).
12
- * Falls back to GATEWAY_PUBLIC_KEY or GATEWAY_PUBLIC_KEY env var.
13
- */
14
- publicKey?: string;
15
- /**
16
- * Secret key for authentication (sk-lf-...).
17
- * Falls back to GATEWAY_SECRET_KEY or GATEWAY_SECRET_KEY env var.
18
- */
19
- secretKey?: string;
20
- /**
21
- * Service name for resource attributes.
22
- * Defaults to "gatewaysdk-tracing".
23
- */
24
- serviceName?: string;
25
- /**
26
- * Environment name (e.g., "production", "staging").
27
- * Sets resource attribute for filtering traces in Gateway.
28
- */
29
- environment?: string;
30
- /**
31
- * Application version (e.g., "1.2.3", git SHA).
32
- * Sets resource attribute for tracking regressions.
33
- */
34
- version?: string;
35
- /**
36
- * Whether to enable debug logging to console.
37
- * Defaults to false.
38
- */
39
- debug?: boolean;
40
- /**
41
- * Whether to automatically add ExperimentSpanProcessor when imported
42
- * from the main entry ("@withgateway/sdk"). Has no effect when imported
43
- * from the subpath ("@withgateway/sdk/tracing") — use customSpanProcessors
44
- * instead.
45
- * Defaults to true.
46
- */
47
- enableExperiments?: boolean;
48
- /**
49
- * Additional span processors to register with the provider.
50
- * These are added before the BatchSpanProcessor (which handles export).
51
- *
52
- * When using the main entry (`import { tracing } from "@withgateway/sdk"`),
53
- * ExperimentSpanProcessor is automatically added unless enableExperiments
54
- * is false. When using the subpath import, pass it here manually:
55
- *
56
- * @example
57
- * ```typescript
58
- * import * as tracing from "@withgateway/sdk/tracing";
59
- * import { ExperimentSpanProcessor } from "@withgateway/sdk/experiments";
60
- *
61
- * tracing.init({ customSpanProcessors: [new ExperimentSpanProcessor()] });
62
- * ```
63
- */
64
- customSpanProcessors?: unknown[];
65
- /**
66
- * Custom OTLP endpoint URL. If not provided, derived from host.
67
- */
68
- endpoint?: string;
69
- /**
70
- * Batch processor configuration.
71
- */
72
- batch?: {
73
- /** Max spans buffered in memory. Default: 2048 */
74
- maxQueueSize?: number;
75
- /** How often to flush spans (ms). Default: 5000 */
76
- scheduledDelayMillis?: number;
77
- /** Max spans per export call. Default: 512 */
78
- maxExportBatchSize?: number;
79
- };
80
- }
81
- interface TracingState {
82
- initialized: boolean;
83
- provider: unknown | null;
84
- }
85
-
86
- /**
87
- * Initialization and lifecycle management for GatewaySDK tracing.
88
- *
89
- * This module provides the core init(), shutdown(), and flush() functions
90
- * for managing the OpenTelemetry TracerProvider lifecycle.
91
- *
92
- * Mirrors the Python SDK's tracing.init() for a consistent developer experience.
93
- */
94
-
95
- /**
96
- * Initialize GatewaySDK tracing with automatic OpenTelemetry configuration.
97
- *
98
- * This function configures OpenTelemetry with a connection to Gateway
99
- * and sets up the ExperimentSpanProcessor for automatic experiment tagging.
100
- *
101
- * @example
102
- * ```typescript
103
- * import { tracing } from "@withgateway/sdk";
104
- *
105
- * // Using environment variables (GATEWAY_HOST, GATEWAY_PUBLIC_KEY, GATEWAY_SECRET_KEY)
106
- * tracing.init();
107
- *
108
- * // Or with explicit configuration
109
- * tracing.init({
110
- * host: "https://app.gateway.dev",
111
- * publicKey: "pk-lf-...",
112
- * secretKey: "sk-lf-...",
113
- * serviceName: "my-agent",
114
- * environment: "production",
115
- * });
116
- * ```
117
- */
118
- declare function init(config?: TracingConfig): void;
119
- /**
120
- * Force flush all pending spans without shutting down.
121
- *
122
- * Useful for ensuring spans are exported at specific points
123
- * (e.g., after completing a batch of work) without ending the tracing session.
124
- *
125
- * @returns Promise that resolves when flush completes
126
- */
127
- declare function flush(): Promise<void>;
128
- /**
129
- * Force flush all pending spans and shutdown the tracer provider.
130
- *
131
- * This function should be called before process exit to ensure all spans
132
- * are exported. It is safe to call multiple times.
133
- *
134
- * @example
135
- * ```typescript
136
- * import { tracing } from "@withgateway/sdk";
137
- *
138
- * tracing.init();
139
- *
140
- * // On shutdown
141
- * process.on("SIGTERM", async () => {
142
- * await tracing.shutdown();
143
- * process.exit(0);
144
- * });
145
- * ```
146
- */
147
- declare function shutdown(): Promise<void>;
148
- /**
149
- * Check if tracing has been initialized.
150
- */
151
- declare function isInitialized(): boolean;
152
- /**
153
- * Check if Gateway is configured via environment variables.
154
- */
155
- declare function isGatewayConfigured(): boolean;
156
-
157
- type ObservationKind = "AGENT" | "CHAIN" | "TOOL" | "LLM" | "RETRIEVER";
158
- interface ObserveOptions {
159
- /** Recorded as input.value on the span (JSON-stringified if not a string). */
160
- input?: unknown;
161
- /** OpenInference span kind. Defaults to "AGENT" for the outer run. */
162
- kind?: ObservationKind;
163
- /**
164
- * When true (default), the callback's return value is recorded as
165
- * output.value. Set false if the return value is large/uninteresting.
166
- */
167
- captureOutput?: boolean;
168
- }
169
- /**
170
- * Run `fn` inside a span named `name`. Anything traced inside (auto-instrumented
171
- * client calls, nested observe() calls) nests under it, forming one trace.
172
- *
173
- * @example
174
- * ```ts
175
- * const result = await observe("my-agent.run", async () => {
176
- * // client.chat.completions.create(...) here becomes a child GENERATION
177
- * return finalText;
178
- * }, { input: prompt });
179
- * ```
180
- */
181
- declare function observe<T>(name: string, fn: () => Promise<T>, options?: ObserveOptions): Promise<T>;
182
-
183
- /**
184
- * Client wrappers that turn an SDK's calls into spans on the Gateway provider.
185
- *
186
- * Node ESM can't retroactively patch a module the app already imported, so — as
187
- * Langfuse does with `observeOpenAI` — the app hands us the client and we
188
- * instrument it explicitly. One SDK call, no OpenTelemetry in the app.
189
- *
190
- * The OpenInference instrumentations are bundled optional deps of this package;
191
- * we load them with require() (the ESM build injects a real createRequire).
192
- */
193
- /**
194
- * Instrument an OpenAI client so its requests become GENERATION spans on the
195
- * Gateway provider. Returns the same client (its class prototype is patched, so
196
- * this and every other instance of that client are traced).
197
- *
198
- * @example
199
- * ```ts
200
- * import OpenAI from "openai";
201
- * import { init, observeOpenAI } from "@withgateway/sdk/tracing";
202
- * init();
203
- * const client = observeOpenAI(new OpenAI());
204
- * ```
205
- */
206
- declare function observeOpenAI<T extends object>(client: T): T;
207
- /**
208
- * Instrument an Anthropic client so its requests become GENERATION spans.
209
- *
210
- * @example
211
- * ```ts
212
- * import Anthropic from "@anthropic-ai/sdk";
213
- * import { init, observeAnthropic } from "@withgateway/sdk/tracing";
214
- * init();
215
- * const client = observeAnthropic(new Anthropic());
216
- * ```
217
- */
218
- declare function observeAnthropic<T extends object>(client: T): T;
219
-
220
- interface ObserveClaudeOptions {
221
- /** Root span name (becomes the trace name). */
222
- name: string;
223
- /** Recorded as input.value on the root span → trace-level input. */
224
- input?: string;
225
- /** Model label for the generation spans. */
226
- model?: string;
227
- }
228
- declare function observeClaude(stream: AsyncIterable<any>, options: ObserveClaudeOptions): AsyncGenerator<any>;
229
-
230
- /**
231
- * Tracing module for GatewaySDK TypeScript SDK.
232
- *
233
- * Provides a simple init() function that configures OpenTelemetry with
234
- * Gateway, mirroring the Python SDK's tracing.init() experience.
235
- *
236
- * @example
237
- * ```typescript
238
- * import { tracing } from "@withgateway/sdk";
239
- *
240
- * // Initialize with environment variables
241
- * tracing.init();
242
- *
243
- * // Or with explicit configuration
244
- * tracing.init({
245
- * host: "https://app.gateway.dev",
246
- * publicKey: "pk-lf-...",
247
- * secretKey: "sk-lf-...",
248
- * });
249
- *
250
- * // Ensure cleanup on shutdown
251
- * process.on("SIGTERM", () => tracing.shutdown());
252
- * ```
253
- */
254
-
255
- type _tracingModule_ObservationKind = ObservationKind;
256
- type _tracingModule_ObserveClaudeOptions = ObserveClaudeOptions;
257
- type _tracingModule_ObserveOptions = ObserveOptions;
258
- type _tracingModule_TracingConfig = TracingConfig;
259
- type _tracingModule_TracingState = TracingState;
260
- declare const _tracingModule_flush: typeof flush;
261
- declare const _tracingModule_init: typeof init;
262
- declare const _tracingModule_isGatewayConfigured: typeof isGatewayConfigured;
263
- declare const _tracingModule_isInitialized: typeof isInitialized;
264
- declare const _tracingModule_observe: typeof observe;
265
- declare const _tracingModule_observeAnthropic: typeof observeAnthropic;
266
- declare const _tracingModule_observeClaude: typeof observeClaude;
267
- declare const _tracingModule_observeOpenAI: typeof observeOpenAI;
268
- declare const _tracingModule_shutdown: typeof shutdown;
269
- declare namespace _tracingModule {
270
- export { type _tracingModule_ObservationKind as ObservationKind, type _tracingModule_ObserveClaudeOptions as ObserveClaudeOptions, type _tracingModule_ObserveOptions as ObserveOptions, type _tracingModule_TracingConfig as TracingConfig, type _tracingModule_TracingState as TracingState, _tracingModule_flush as flush, _tracingModule_init as init, _tracingModule_isGatewayConfigured as isGatewayConfigured, _tracingModule_isInitialized as isInitialized, _tracingModule_observe as observe, _tracingModule_observeAnthropic as observeAnthropic, _tracingModule_observeClaude as observeClaude, _tracingModule_observeOpenAI as observeOpenAI, _tracingModule_shutdown as shutdown };
271
- }
272
-
273
- export { type ObservationKind as O, type TracingConfig as T, _tracingModule as _, type ObserveClaudeOptions as a, type ObserveOptions as b, type TracingState as c, isGatewayConfigured as d, isInitialized as e, flush as f, observeAnthropic as g, observeClaude as h, init as i, observeOpenAI as j, observe as o, shutdown as s };