@withgateway/sdk 0.1.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 +229 -0
- package/dist/context/index.d.mts +225 -0
- package/dist/context/index.d.ts +225 -0
- package/dist/context/index.js +440 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.mjs +411 -0
- package/dist/context/index.mjs.map +1 -0
- package/dist/experiments/index.d.mts +260 -0
- package/dist/experiments/index.d.ts +260 -0
- package/dist/experiments/index.js +407 -0
- package/dist/experiments/index.js.map +1 -0
- package/dist/experiments/index.mjs +374 -0
- package/dist/experiments/index.mjs.map +1 -0
- package/dist/index-Caw3XVub.d.mts +193 -0
- package/dist/index-Caw3XVub.d.ts +193 -0
- package/dist/index.d.mts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +1476 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1434 -0
- package/dist/index.mjs.map +1 -0
- package/dist/memory/index.d.mts +124 -0
- package/dist/memory/index.d.ts +124 -0
- package/dist/memory/index.js +192 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/index.mjs +164 -0
- package/dist/memory/index.mjs.map +1 -0
- package/dist/security/index.d.mts +114 -0
- package/dist/security/index.d.ts +114 -0
- package/dist/security/index.js +297 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/index.mjs +275 -0
- package/dist/security/index.mjs.map +1 -0
- package/dist/tracing/index.d.mts +1 -0
- package/dist/tracing/index.d.ts +1 -0
- package/dist/tracing/index.js +226 -0
- package/dist/tracing/index.js.map +1 -0
- package/dist/tracing/index.mjs +202 -0
- package/dist/tracing/index.mjs.map +1 -0
- package/package.json +112 -0
|
@@ -0,0 +1,193 @@
|
|
|
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
|
+
/**
|
|
158
|
+
* Tracing module for GatewaySDK TypeScript SDK.
|
|
159
|
+
*
|
|
160
|
+
* Provides a simple init() function that configures OpenTelemetry with
|
|
161
|
+
* Gateway, mirroring the Python SDK's tracing.init() experience.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* import { tracing } from "@withgateway/sdk";
|
|
166
|
+
*
|
|
167
|
+
* // Initialize with environment variables
|
|
168
|
+
* tracing.init();
|
|
169
|
+
*
|
|
170
|
+
* // Or with explicit configuration
|
|
171
|
+
* tracing.init({
|
|
172
|
+
* host: "https://app.gateway.dev",
|
|
173
|
+
* publicKey: "pk-lf-...",
|
|
174
|
+
* secretKey: "sk-lf-...",
|
|
175
|
+
* });
|
|
176
|
+
*
|
|
177
|
+
* // Ensure cleanup on shutdown
|
|
178
|
+
* process.on("SIGTERM", () => tracing.shutdown());
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
|
|
182
|
+
type _tracingModule_TracingConfig = TracingConfig;
|
|
183
|
+
type _tracingModule_TracingState = TracingState;
|
|
184
|
+
declare const _tracingModule_flush: typeof flush;
|
|
185
|
+
declare const _tracingModule_init: typeof init;
|
|
186
|
+
declare const _tracingModule_isGatewayConfigured: typeof isGatewayConfigured;
|
|
187
|
+
declare const _tracingModule_isInitialized: typeof isInitialized;
|
|
188
|
+
declare const _tracingModule_shutdown: typeof shutdown;
|
|
189
|
+
declare namespace _tracingModule {
|
|
190
|
+
export { 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_shutdown as shutdown };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { type TracingConfig as T, _tracingModule as _, type TracingState as a, isGatewayConfigured as b, isInitialized as c, flush as f, init as i, shutdown as s };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { EXPERIMENT_ATTRIBUTES, ExperimentClient, ExperimentClientConfig, ExperimentConfig, ExperimentContext, ExperimentSpanProcessor, Exposure, ExposureLogger, ExposureLoggerConfig, GetVariantResult, RegisterExperimentInput, Variant, addExperimentAttributes, assignVariant, clearExperimentContext, computeHash, experimentContextStorage, experiments, getExperimentContext, runWithExperimentContext, setExperimentContext } from './experiments/index.mjs';
|
|
2
|
+
export { GatewayContext, GatewayContextCommit, GatewayContextConfig, GatewayContextConflictError, GatewayContextError, GatewayContextFileEntry, GatewayContextFileInput, GatewayContextListOptions, GatewayContextListResponse, GatewayContextPullOptions, GatewayContextPushOptions, GatewayContextPushResponse, GatewayContextRepo, GatewayContextRepoKind, GatewayContextRuntimeContext, GatewayContextSnapshot, GatewayContextWritePolicy, GatewayRenderSystemOptions, GatewayResolvedAgentContext, GatewayResolvedContextRef, context, renderAgentSystem } from './context/index.mjs';
|
|
3
|
+
export { GatewayMemory, GatewayMemoryCommit, GatewayMemoryConfig, GatewayMemoryConflictError, GatewayMemoryDeleteOptions, GatewayMemoryError, GatewayMemoryFileEntry, GatewayMemoryPullOptions, GatewayMemoryPushResponse, GatewayMemoryRepo, GatewayMemoryRuntimeContext, GatewayMemorySnapshot, GatewayMemoryWriteOptions, GatewayMemoryWritePolicy, memory } from './memory/index.mjs';
|
|
4
|
+
export { GatewayAgentDescriptor, GatewaySecurity, GatewaySecurityConfig, GatewaySecurityContext, GatewaySecurityError, GatewayToolApprovalRequiredError, GatewayToolBlockedError, GatewayToolCallAuthorizeResponse, GatewayToolDescriptor, GatewayToolsetResolveResponse, SecureToolsOptions, gateway } from './security/index.mjs';
|
|
5
|
+
import { _ as _tracingModule } from './index-Caw3XVub.mjs';
|
|
6
|
+
import 'async_hooks';
|
|
7
|
+
import '@opentelemetry/api';
|
|
8
|
+
import '@opentelemetry/sdk-trace-base';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Tracing module with automatic ExperimentSpanProcessor wiring.
|
|
12
|
+
*
|
|
13
|
+
* When imported from the main entry ("@withgateway/sdk"), init() automatically
|
|
14
|
+
* adds ExperimentSpanProcessor so spans are tagged with experiment context.
|
|
15
|
+
* Both modules share the same bundle, so the AsyncLocalStorage context is
|
|
16
|
+
* shared — no cross-bundle duplication.
|
|
17
|
+
*/
|
|
18
|
+
declare const tracing: typeof _tracingModule;
|
|
19
|
+
|
|
20
|
+
export { tracing };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { EXPERIMENT_ATTRIBUTES, ExperimentClient, ExperimentClientConfig, ExperimentConfig, ExperimentContext, ExperimentSpanProcessor, Exposure, ExposureLogger, ExposureLoggerConfig, GetVariantResult, RegisterExperimentInput, Variant, addExperimentAttributes, assignVariant, clearExperimentContext, computeHash, experimentContextStorage, experiments, getExperimentContext, runWithExperimentContext, setExperimentContext } from './experiments/index.js';
|
|
2
|
+
export { GatewayContext, GatewayContextCommit, GatewayContextConfig, GatewayContextConflictError, GatewayContextError, GatewayContextFileEntry, GatewayContextFileInput, GatewayContextListOptions, GatewayContextListResponse, GatewayContextPullOptions, GatewayContextPushOptions, GatewayContextPushResponse, GatewayContextRepo, GatewayContextRepoKind, GatewayContextRuntimeContext, GatewayContextSnapshot, GatewayContextWritePolicy, GatewayRenderSystemOptions, GatewayResolvedAgentContext, GatewayResolvedContextRef, context, renderAgentSystem } from './context/index.js';
|
|
3
|
+
export { GatewayMemory, GatewayMemoryCommit, GatewayMemoryConfig, GatewayMemoryConflictError, GatewayMemoryDeleteOptions, GatewayMemoryError, GatewayMemoryFileEntry, GatewayMemoryPullOptions, GatewayMemoryPushResponse, GatewayMemoryRepo, GatewayMemoryRuntimeContext, GatewayMemorySnapshot, GatewayMemoryWriteOptions, GatewayMemoryWritePolicy, memory } from './memory/index.js';
|
|
4
|
+
export { GatewayAgentDescriptor, GatewaySecurity, GatewaySecurityConfig, GatewaySecurityContext, GatewaySecurityError, GatewayToolApprovalRequiredError, GatewayToolBlockedError, GatewayToolCallAuthorizeResponse, GatewayToolDescriptor, GatewayToolsetResolveResponse, SecureToolsOptions, gateway } from './security/index.js';
|
|
5
|
+
import { _ as _tracingModule } from './index-Caw3XVub.js';
|
|
6
|
+
import 'async_hooks';
|
|
7
|
+
import '@opentelemetry/api';
|
|
8
|
+
import '@opentelemetry/sdk-trace-base';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Tracing module with automatic ExperimentSpanProcessor wiring.
|
|
12
|
+
*
|
|
13
|
+
* When imported from the main entry ("@withgateway/sdk"), init() automatically
|
|
14
|
+
* adds ExperimentSpanProcessor so spans are tagged with experiment context.
|
|
15
|
+
* Both modules share the same bundle, so the AsyncLocalStorage context is
|
|
16
|
+
* shared — no cross-bundle duplication.
|
|
17
|
+
*/
|
|
18
|
+
declare const tracing: typeof _tracingModule;
|
|
19
|
+
|
|
20
|
+
export { tracing };
|