@zespan/sdk 1.0.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/README.md +327 -0
- package/dist/index.d.mts +588 -0
- package/dist/index.d.ts +588 -0
- package/dist/index.js +20 -0
- package/dist/index.mjs +20 -0
- package/package.json +80 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
import * as _opentelemetry_api from '@opentelemetry/api';
|
|
2
|
+
import { SpanKind, Tracer, Span, Context } from '@opentelemetry/api';
|
|
3
|
+
export { SpanKind, SpanStatusCode } from '@opentelemetry/api';
|
|
4
|
+
import { ZespanEvent, SpanKind as SpanKind$1, ToolDefinition } from '@zespan/shared';
|
|
5
|
+
export { AgentDelegation, ToolDefinition, SpanKind as ZespanSpanKind } from '@zespan/shared';
|
|
6
|
+
import OpenAI from 'openai';
|
|
7
|
+
import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
8
|
+
import { Serialized } from '@langchain/core/load/serializable';
|
|
9
|
+
import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
10
|
+
|
|
11
|
+
interface ZespanOptions {
|
|
12
|
+
apiKey: string;
|
|
13
|
+
endpoint?: string;
|
|
14
|
+
baseURL?: string;
|
|
15
|
+
environment?: string;
|
|
16
|
+
storePrompts?: boolean;
|
|
17
|
+
redactKeys?: string[];
|
|
18
|
+
sampleRate?: number;
|
|
19
|
+
debug?: boolean;
|
|
20
|
+
batchSize?: number;
|
|
21
|
+
flushInterval?: number;
|
|
22
|
+
enableOTel?: boolean;
|
|
23
|
+
otelEndpoint?: string;
|
|
24
|
+
otelServiceName?: string;
|
|
25
|
+
enableZespanPilot?: boolean;
|
|
26
|
+
projectId?: string;
|
|
27
|
+
autopatch?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface OTelConfig {
|
|
31
|
+
endpoint?: string;
|
|
32
|
+
serviceName?: string;
|
|
33
|
+
sampleRate?: number;
|
|
34
|
+
apiKey?: string;
|
|
35
|
+
environment?: string;
|
|
36
|
+
}
|
|
37
|
+
declare function initOTel(config: OTelConfig): {
|
|
38
|
+
tracer: _opentelemetry_api.Tracer;
|
|
39
|
+
provider: any;
|
|
40
|
+
};
|
|
41
|
+
declare function getTracer(): _opentelemetry_api.Tracer;
|
|
42
|
+
declare function createSpan(options: {
|
|
43
|
+
name: string;
|
|
44
|
+
kind?: SpanKind;
|
|
45
|
+
attributes?: Record<string, string | number | boolean | string[]>;
|
|
46
|
+
}): _opentelemetry_api.Span;
|
|
47
|
+
declare function withSpan<T>(name: string, fn: (span: any) => Promise<T>, options?: {
|
|
48
|
+
kind?: SpanKind;
|
|
49
|
+
attributes?: Record<string, string | number | boolean | string[]>;
|
|
50
|
+
}): Promise<T>;
|
|
51
|
+
|
|
52
|
+
interface PromptOptions {
|
|
53
|
+
version?: number;
|
|
54
|
+
label?: string;
|
|
55
|
+
cache?: boolean;
|
|
56
|
+
}
|
|
57
|
+
interface Prompt {
|
|
58
|
+
id: string;
|
|
59
|
+
name: string;
|
|
60
|
+
version: number;
|
|
61
|
+
type: "text" | "chat";
|
|
62
|
+
prompt: any;
|
|
63
|
+
config: any;
|
|
64
|
+
labels: string[];
|
|
65
|
+
tags: string[];
|
|
66
|
+
variables: string[];
|
|
67
|
+
createdAt: string;
|
|
68
|
+
updatedAt: string;
|
|
69
|
+
promptHash: string;
|
|
70
|
+
}
|
|
71
|
+
declare class PromptClient {
|
|
72
|
+
private client;
|
|
73
|
+
private cache;
|
|
74
|
+
private cacheTTL;
|
|
75
|
+
constructor(client: ZespanClient);
|
|
76
|
+
/**
|
|
77
|
+
* Get a prompt by name, version, or label
|
|
78
|
+
*/
|
|
79
|
+
get(name: string, options?: PromptOptions): Promise<Prompt>;
|
|
80
|
+
/**
|
|
81
|
+
* List all prompts for the current project
|
|
82
|
+
*/
|
|
83
|
+
list(nameFilter?: string): Promise<Prompt[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Create a new prompt version
|
|
86
|
+
*/
|
|
87
|
+
create(params: {
|
|
88
|
+
name: string;
|
|
89
|
+
type: "text" | "chat";
|
|
90
|
+
prompt: any;
|
|
91
|
+
config?: any;
|
|
92
|
+
labels?: string[];
|
|
93
|
+
tags?: string[];
|
|
94
|
+
commitMessage?: string;
|
|
95
|
+
}): Promise<Prompt>;
|
|
96
|
+
/**
|
|
97
|
+
* Update labels for a specific prompt version
|
|
98
|
+
*/
|
|
99
|
+
updateLabels(name: string, version: number, labels: string[]): Promise<Prompt>;
|
|
100
|
+
/**
|
|
101
|
+
* Compile a prompt with variables
|
|
102
|
+
*/
|
|
103
|
+
compile(prompt: Prompt, variables: Record<string, string>): string;
|
|
104
|
+
/**
|
|
105
|
+
* Clear cache for a specific prompt or all prompts
|
|
106
|
+
*/
|
|
107
|
+
clearCache(name?: string): void;
|
|
108
|
+
private getCacheKey;
|
|
109
|
+
private invalidateCache;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* SDK ConfigClient — zero-infra runtime configuration client.
|
|
114
|
+
*
|
|
115
|
+
* Piggybacks on ingest response `cv` field to detect config staleness.
|
|
116
|
+
* Fetches full config snapshot from `/v1/sdk/config` only when stale.
|
|
117
|
+
* No polling, no SSE, no resources requiring cleanup.
|
|
118
|
+
*/
|
|
119
|
+
interface CacheSettings {
|
|
120
|
+
enabled: boolean;
|
|
121
|
+
ttlSeconds: number;
|
|
122
|
+
similarityThreshold: number;
|
|
123
|
+
}
|
|
124
|
+
interface RateLimitSettings {
|
|
125
|
+
maxRequests: number;
|
|
126
|
+
windowSeconds: number;
|
|
127
|
+
}
|
|
128
|
+
interface FallbackSettings {
|
|
129
|
+
model: string;
|
|
130
|
+
conditions: string[];
|
|
131
|
+
}
|
|
132
|
+
interface RetrySettings {
|
|
133
|
+
enabled: boolean;
|
|
134
|
+
maxRetries: number;
|
|
135
|
+
backoffMultiplier: number;
|
|
136
|
+
retryOnStatusCodes: number[];
|
|
137
|
+
}
|
|
138
|
+
interface TimeoutSettings {
|
|
139
|
+
timeoutMs: number;
|
|
140
|
+
}
|
|
141
|
+
interface AbTestSettings {
|
|
142
|
+
candidateModel: string;
|
|
143
|
+
splitPercentage: number;
|
|
144
|
+
}
|
|
145
|
+
interface RuntimeConfig {
|
|
146
|
+
modelOverrides: Map<string, string>;
|
|
147
|
+
cacheConfig: Map<string, CacheSettings>;
|
|
148
|
+
rateLimits: Map<string, RateLimitSettings>;
|
|
149
|
+
guardrailOverrides: Map<string, boolean>;
|
|
150
|
+
samplingRate: number;
|
|
151
|
+
promptVersions: Map<string, number>;
|
|
152
|
+
fallbacks: Map<string, FallbackSettings>;
|
|
153
|
+
retryPolicies: Map<string, RetrySettings>;
|
|
154
|
+
timeouts: Map<string, TimeoutSettings>;
|
|
155
|
+
concurrencyLimits: Map<string, number>;
|
|
156
|
+
abTests: Map<string, AbTestSettings>;
|
|
157
|
+
}
|
|
158
|
+
type ConfigEventListener = (data: any) => void;
|
|
159
|
+
declare class ConfigClient {
|
|
160
|
+
private localVersion;
|
|
161
|
+
private config;
|
|
162
|
+
private listeners;
|
|
163
|
+
private fetching;
|
|
164
|
+
private baseUrl;
|
|
165
|
+
private apiKey;
|
|
166
|
+
private projectId;
|
|
167
|
+
constructor(opts: {
|
|
168
|
+
baseUrl: string;
|
|
169
|
+
apiKey: string;
|
|
170
|
+
projectId: string;
|
|
171
|
+
});
|
|
172
|
+
checkVersion(serverVersion: number): void;
|
|
173
|
+
getModel(operation: string, defaultModel: string): string;
|
|
174
|
+
getCacheConfig(operation: string): CacheSettings | null;
|
|
175
|
+
getSamplingRate(): number;
|
|
176
|
+
getRuntimeConfig(): RuntimeConfig;
|
|
177
|
+
getLocalVersion(): number;
|
|
178
|
+
getFallback(operation: string): FallbackSettings | null;
|
|
179
|
+
getRetryPolicy(operation: string): RetrySettings | null;
|
|
180
|
+
getTimeout(operation: string): TimeoutSettings | null;
|
|
181
|
+
getConcurrencyLimit(operation: string): number | null;
|
|
182
|
+
getAbTest(operation: string): AbTestSettings | null;
|
|
183
|
+
on(event: string, fn: ConfigEventListener): void;
|
|
184
|
+
private emit;
|
|
185
|
+
private fetchConfig;
|
|
186
|
+
applyFullConfig(snapshot: Record<string, any>): void;
|
|
187
|
+
private parseSnapshot;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
type GuardrailPhase = "pre" | "post";
|
|
191
|
+
interface GuardrailCheckInput {
|
|
192
|
+
text: string;
|
|
193
|
+
phase: GuardrailPhase;
|
|
194
|
+
traceId?: string;
|
|
195
|
+
spanId?: string;
|
|
196
|
+
model?: string;
|
|
197
|
+
operation?: string;
|
|
198
|
+
estimatedCost?: number;
|
|
199
|
+
inputTokens?: number;
|
|
200
|
+
agentName?: string;
|
|
201
|
+
toolName?: string;
|
|
202
|
+
recentToolCalls?: Array<{
|
|
203
|
+
toolName: string;
|
|
204
|
+
args?: string;
|
|
205
|
+
}>;
|
|
206
|
+
}
|
|
207
|
+
interface GuardrailResult {
|
|
208
|
+
guardrailSlug: string;
|
|
209
|
+
passed: boolean;
|
|
210
|
+
action: "allowed" | "blocked" | "redacted" | "warned";
|
|
211
|
+
reason: string | null;
|
|
212
|
+
modifiedText: string | null;
|
|
213
|
+
latencyMs: number;
|
|
214
|
+
}
|
|
215
|
+
interface GuardrailCheckResponse {
|
|
216
|
+
allowed: boolean;
|
|
217
|
+
results: GuardrailResult[];
|
|
218
|
+
modifiedText: string | null;
|
|
219
|
+
}
|
|
220
|
+
type WrapperGuardrailsSettings = boolean | {
|
|
221
|
+
pre?: boolean;
|
|
222
|
+
post?: boolean;
|
|
223
|
+
failClosed?: boolean;
|
|
224
|
+
operation?: string;
|
|
225
|
+
};
|
|
226
|
+
interface WrapperGuardrailsOptions {
|
|
227
|
+
guardrails?: WrapperGuardrailsSettings;
|
|
228
|
+
}
|
|
229
|
+
interface ResolvedWrapperGuardrailsSettings {
|
|
230
|
+
pre: boolean;
|
|
231
|
+
post: boolean;
|
|
232
|
+
failClosed: boolean;
|
|
233
|
+
operation?: string;
|
|
234
|
+
}
|
|
235
|
+
declare class GuardrailBlockedError extends Error {
|
|
236
|
+
readonly phase: GuardrailPhase;
|
|
237
|
+
readonly results: GuardrailResult[];
|
|
238
|
+
constructor(phase: GuardrailPhase, results: GuardrailResult[]);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
declare class ZespanClient {
|
|
242
|
+
readonly apiKey: string;
|
|
243
|
+
readonly endpoint: string;
|
|
244
|
+
readonly baseURL: string;
|
|
245
|
+
readonly environment: string;
|
|
246
|
+
readonly storePrompts: boolean;
|
|
247
|
+
readonly redactKeys: string[];
|
|
248
|
+
readonly sampleRate: number;
|
|
249
|
+
readonly debug: boolean;
|
|
250
|
+
readonly enableOTel: boolean;
|
|
251
|
+
readonly prompts: PromptClient;
|
|
252
|
+
readonly configClient: ConfigClient | null;
|
|
253
|
+
readonly projectId: string | undefined;
|
|
254
|
+
private batch;
|
|
255
|
+
private readonly _storePromptsDefault;
|
|
256
|
+
private _promptWarningShown;
|
|
257
|
+
constructor(opts: ZespanOptions);
|
|
258
|
+
enqueue(event: ZespanEvent): void;
|
|
259
|
+
redactForStorage(value: unknown): string;
|
|
260
|
+
private resolveGuardrailsUrl;
|
|
261
|
+
checkGuardrails(input: GuardrailCheckInput): Promise<GuardrailCheckResponse>;
|
|
262
|
+
flush(): Promise<void>;
|
|
263
|
+
createSpan(options: {
|
|
264
|
+
name: string;
|
|
265
|
+
kind?: SpanKind;
|
|
266
|
+
attributes?: Record<string, string | number | boolean | string[]>;
|
|
267
|
+
}): _opentelemetry_api.Span;
|
|
268
|
+
withSpan<T>(name: string, fn: (span: unknown) => Promise<T>, options?: {
|
|
269
|
+
kind?: SpanKind;
|
|
270
|
+
attributes?: Record<string, string | number | boolean | string[]>;
|
|
271
|
+
}): Promise<T>;
|
|
272
|
+
}
|
|
273
|
+
declare const initZespan: (o: ZespanOptions) => void;
|
|
274
|
+
declare const getZespanClient: () => ZespanClient;
|
|
275
|
+
|
|
276
|
+
declare const init: (o: ZespanOptions) => void;
|
|
277
|
+
declare const getLumiqClient: () => ZespanClient;
|
|
278
|
+
|
|
279
|
+
declare function wrapOpenAI<T extends any>(client: T, options?: WrapperGuardrailsOptions): T;
|
|
280
|
+
|
|
281
|
+
declare function wrapAnthropic<T extends any>(client: T, options?: WrapperGuardrailsOptions): T;
|
|
282
|
+
|
|
283
|
+
declare function wrapGoogle<T extends any>(client: T, options?: WrapperGuardrailsOptions): T;
|
|
284
|
+
|
|
285
|
+
declare function wrapOpenRouter(baseClient: OpenAI, options?: WrapperGuardrailsOptions): OpenAI;
|
|
286
|
+
|
|
287
|
+
interface WrapBedrockOptions extends WrapperGuardrailsOptions {
|
|
288
|
+
operation?: string;
|
|
289
|
+
}
|
|
290
|
+
declare function wrapBedrock<T extends any>(client: T, options?: WrapBedrockOptions): T;
|
|
291
|
+
|
|
292
|
+
interface WrapMistralOptions extends WrapperGuardrailsOptions {
|
|
293
|
+
operation?: string;
|
|
294
|
+
}
|
|
295
|
+
declare function wrapMistral<T extends any>(client: T, options?: WrapMistralOptions): T;
|
|
296
|
+
|
|
297
|
+
interface WrapGroqOptions {
|
|
298
|
+
operation?: string;
|
|
299
|
+
}
|
|
300
|
+
declare function wrapGroq<T extends any>(client: T, options?: WrapGroqOptions): T;
|
|
301
|
+
|
|
302
|
+
interface LiteLLMOptions {
|
|
303
|
+
baseURL: string;
|
|
304
|
+
apiKey?: string;
|
|
305
|
+
operation?: string;
|
|
306
|
+
}
|
|
307
|
+
declare function wrapLiteLLM(opts: LiteLLMOptions, guardrailOptions?: WrapperGuardrailsOptions): OpenAI;
|
|
308
|
+
|
|
309
|
+
declare class ZespanCallbackHandler extends BaseCallbackHandler {
|
|
310
|
+
name: string;
|
|
311
|
+
private guardrailSettings;
|
|
312
|
+
private runs;
|
|
313
|
+
constructor(options?: WrapperGuardrailsOptions);
|
|
314
|
+
private detectProvider;
|
|
315
|
+
private extractToolCalls;
|
|
316
|
+
private detectConversationInfo;
|
|
317
|
+
private detectAgentFromPrompts;
|
|
318
|
+
private detectPlanning;
|
|
319
|
+
private extractCompletion;
|
|
320
|
+
handleChatModelStart(llm: Serialized, messages: any[][], runId: string, parentRunId?: string, extraParams?: any, _tags?: string[], _metadata?: Record<string, unknown>, _runName?: string): Promise<void>;
|
|
321
|
+
handleLLMStart(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: any): Promise<void>;
|
|
322
|
+
handleLLMNewToken(_token: string, _idx: any, runId: string): Promise<void>;
|
|
323
|
+
handleLLMEnd(output: any, runId: string): Promise<void>;
|
|
324
|
+
handleLLMError(err: any, runId: string): Promise<void>;
|
|
325
|
+
handleChainStart(serialized: Serialized, inputs: Record<string, unknown>, runId: string, parentRunId?: string): Promise<void>;
|
|
326
|
+
handleChainEnd(outputs: Record<string, unknown>, runId: string): Promise<void>;
|
|
327
|
+
handleChainError(err: any, runId: string): Promise<void>;
|
|
328
|
+
handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string): Promise<void>;
|
|
329
|
+
handleToolEnd(output: string, runId: string): Promise<void>;
|
|
330
|
+
handleToolError(err: any, runId: string): Promise<void>;
|
|
331
|
+
handleAgentAction(action: any, runId: string): Promise<void>;
|
|
332
|
+
handleRetrieverStart(_retriever: Serialized, query: string, runId: string, parentRunId?: string): Promise<void>;
|
|
333
|
+
handleRetrieverEnd(documents: any[], runId: string): Promise<void>;
|
|
334
|
+
handleRetrieverError(err: any, runId: string): Promise<void>;
|
|
335
|
+
}
|
|
336
|
+
declare const LumiqCallbackHandler: typeof ZespanCallbackHandler;
|
|
337
|
+
|
|
338
|
+
declare class ZespanADKCallbackHandler {
|
|
339
|
+
private agentStates;
|
|
340
|
+
private pendingModelCalls;
|
|
341
|
+
private toolCallStates;
|
|
342
|
+
private agentKey;
|
|
343
|
+
private getParentAgentState;
|
|
344
|
+
beforeAgentCallback: (context: any) => undefined;
|
|
345
|
+
afterAgentCallback: (context: any) => undefined;
|
|
346
|
+
beforeModelCallback: ({ context, request: _request }: any) => undefined;
|
|
347
|
+
afterModelCallback: ({ context, response }: any) => undefined;
|
|
348
|
+
beforeToolCallback: ({ tool, args, context }: any) => undefined;
|
|
349
|
+
afterToolCallback: ({ tool: _tool, args: _args, context, response }: any) => undefined;
|
|
350
|
+
/** Spread into LlmAgent config to wire up all callbacks */
|
|
351
|
+
get callbacks(): {
|
|
352
|
+
beforeAgentCallback: (context: any) => undefined;
|
|
353
|
+
afterAgentCallback: (context: any) => undefined;
|
|
354
|
+
beforeModelCallback: ({ context, request: _request }: any) => undefined;
|
|
355
|
+
afterModelCallback: ({ context, response }: any) => undefined;
|
|
356
|
+
beforeToolCallback: ({ tool, args, context }: any) => undefined;
|
|
357
|
+
afterToolCallback: ({ tool: _tool, args: _args, context, response }: any) => undefined;
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
interface ADKAgentOptions extends WrapperGuardrailsOptions {
|
|
362
|
+
/** Display name for this agent in traces (defaults to agent.name) */
|
|
363
|
+
agentName?: string;
|
|
364
|
+
/** Role label: "coordinator" | "specialist" | "planner" etc. */
|
|
365
|
+
agentRole?: string;
|
|
366
|
+
/** Recursively wrap subAgents array on the coordinator (default: true) */
|
|
367
|
+
traceSubAgents?: boolean;
|
|
368
|
+
/** Session ID for grouping related traces together */
|
|
369
|
+
sessionId?: string;
|
|
370
|
+
}
|
|
371
|
+
interface ADKRunnerOptions {
|
|
372
|
+
/** Name of the root coordinator agent */
|
|
373
|
+
agentName?: string;
|
|
374
|
+
/** Role label for the root agent (default: "coordinator") */
|
|
375
|
+
agentRole?: string;
|
|
376
|
+
/** Gemini model override — use if ADK doesn't expose model on events */
|
|
377
|
+
model?: string;
|
|
378
|
+
/** Session ID for grouping related traces together */
|
|
379
|
+
sessionId?: string;
|
|
380
|
+
}
|
|
381
|
+
interface InstrumentADKOptions extends ADKAgentOptions, ADKRunnerOptions {
|
|
382
|
+
coordinator: any;
|
|
383
|
+
runner: any;
|
|
384
|
+
}
|
|
385
|
+
declare function wrapADKAgent<T>(agent: T, options?: ADKAgentOptions): T;
|
|
386
|
+
declare function wrapADKRunner<T>(runner: T, options?: ADKRunnerOptions): T;
|
|
387
|
+
declare function instrumentADK(options: InstrumentADKOptions): {
|
|
388
|
+
coordinator: any;
|
|
389
|
+
runner: any;
|
|
390
|
+
};
|
|
391
|
+
declare const wrapZespanADKAgent: typeof wrapADKAgent;
|
|
392
|
+
|
|
393
|
+
interface TelemetrySettings {
|
|
394
|
+
isEnabled: boolean;
|
|
395
|
+
tracer: Tracer;
|
|
396
|
+
}
|
|
397
|
+
declare function instrumentVercelAI(): {
|
|
398
|
+
tracer: Tracer;
|
|
399
|
+
telemetry: TelemetrySettings;
|
|
400
|
+
};
|
|
401
|
+
declare function getLumiqVercelTelemetry(): TelemetrySettings;
|
|
402
|
+
|
|
403
|
+
declare class LumiqLlamaIndexHandler {
|
|
404
|
+
private runs;
|
|
405
|
+
private guardrailSettings;
|
|
406
|
+
constructor(options?: WrapperGuardrailsOptions);
|
|
407
|
+
private _onLLMStart;
|
|
408
|
+
private _onLLMEnd;
|
|
409
|
+
private _onLLMStream;
|
|
410
|
+
private _onToolCall;
|
|
411
|
+
private _onToolResult;
|
|
412
|
+
private _onAgentStart;
|
|
413
|
+
private _onAgentEnd;
|
|
414
|
+
attach(callbackManager: any): void;
|
|
415
|
+
detach(callbackManager: any): void;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
declare function startSpan(opts: {
|
|
419
|
+
name: string;
|
|
420
|
+
model?: string;
|
|
421
|
+
provider?: string;
|
|
422
|
+
span_kind?: SpanKind$1;
|
|
423
|
+
}): {
|
|
424
|
+
span: {
|
|
425
|
+
setEvalScore(name: string, score: number): void;
|
|
426
|
+
end(endOpts: {
|
|
427
|
+
status: "success" | "error" | "timeout" | "rate_limited" | "cancelled";
|
|
428
|
+
input_tokens?: number;
|
|
429
|
+
output_tokens?: number;
|
|
430
|
+
cost_usd?: number;
|
|
431
|
+
error_message?: string;
|
|
432
|
+
}): Promise<void>;
|
|
433
|
+
};
|
|
434
|
+
run: <T>(fn: () => T) => T;
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
interface ZespanContextOptions {
|
|
438
|
+
traceId?: string;
|
|
439
|
+
userId?: string;
|
|
440
|
+
sessionId?: string;
|
|
441
|
+
tags?: Record<string, string>;
|
|
442
|
+
agentId?: string;
|
|
443
|
+
agentName?: string;
|
|
444
|
+
agentRole?: string;
|
|
445
|
+
agentFramework?: string;
|
|
446
|
+
}
|
|
447
|
+
declare function withZespanContext<T>(options: ZespanContextOptions, fn: () => T | Promise<T>): T | Promise<T>;
|
|
448
|
+
declare function withZespanTrace<T>(fn: () => T | Promise<T>, options?: ZespanContextOptions): T | Promise<T>;
|
|
449
|
+
declare const withZespan: typeof withZespanTrace;
|
|
450
|
+
type LumiqContextOptions = ZespanContextOptions;
|
|
451
|
+
declare const withLumiqContext: typeof withZespanContext;
|
|
452
|
+
|
|
453
|
+
interface AgentOptions {
|
|
454
|
+
name: string;
|
|
455
|
+
role?: string;
|
|
456
|
+
framework?: string;
|
|
457
|
+
tools?: ToolDefinition[];
|
|
458
|
+
metadata?: Record<string, unknown>;
|
|
459
|
+
}
|
|
460
|
+
declare class AgentContext {
|
|
461
|
+
readonly agentId: string;
|
|
462
|
+
readonly name: string;
|
|
463
|
+
readonly role: string;
|
|
464
|
+
readonly framework: string;
|
|
465
|
+
readonly tools: ToolDefinition[];
|
|
466
|
+
constructor(agentId: string, options: AgentOptions);
|
|
467
|
+
logPlan(steps: string[]): void;
|
|
468
|
+
traceTool<T>(toolName: string, args: Record<string, unknown>, fn: () => T | Promise<T>): Promise<T>;
|
|
469
|
+
delegateTo(targetAgentName: string, reason?: string): void;
|
|
470
|
+
}
|
|
471
|
+
declare function withAgent<T>(options: AgentOptions, fn: (agent: AgentContext) => T | Promise<T>): T | Promise<T>;
|
|
472
|
+
|
|
473
|
+
declare function markFrameworkActive(spanId: string): void;
|
|
474
|
+
declare function markFrameworkInactive(spanId: string): void;
|
|
475
|
+
/**
|
|
476
|
+
* Auto-patch all detected AI provider prototypes.
|
|
477
|
+
* Called automatically from initZespan() unless autopatch: false.
|
|
478
|
+
* Safe to call multiple times — guarded by module-level flags.
|
|
479
|
+
*
|
|
480
|
+
* Patches are also applied eagerly when this module is first loaded
|
|
481
|
+
* (via an async IIFE that resolves before test code runs). Calling
|
|
482
|
+
* autopatch() explicitly is a no-op if already patched.
|
|
483
|
+
*
|
|
484
|
+
* Frameworks (LangChain, ADK) are NOT auto-patched here — they use their
|
|
485
|
+
* native callback/event APIs (ZespanCallbackHandler, instrumentADK).
|
|
486
|
+
* Those handlers call markFrameworkActive/markFrameworkInactive to suppress
|
|
487
|
+
* this patcher while a framework trace is running, preventing double-events.
|
|
488
|
+
*/
|
|
489
|
+
declare function autopatch(): void;
|
|
490
|
+
|
|
491
|
+
declare class BaggageSpanProcessor implements SpanProcessor {
|
|
492
|
+
onStart(span: Span, parentContext: Context): void;
|
|
493
|
+
onEnd(): void;
|
|
494
|
+
shutdown(): Promise<void>;
|
|
495
|
+
forceFlush(): Promise<void>;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Inject W3C trace context + agent delegation metadata into outgoing HTTP headers.
|
|
500
|
+
* Call this before making an HTTP request to a downstream agent.
|
|
501
|
+
*/
|
|
502
|
+
declare function injectAgentContext(headers: Record<string, string>, delegationReason?: string, taskDescription?: string): void;
|
|
503
|
+
/**
|
|
504
|
+
* Extract W3C trace context from incoming HTTP headers on the receiving agent side.
|
|
505
|
+
* Pass the returned context to tracer.startSpan() via the third argument.
|
|
506
|
+
*/
|
|
507
|
+
declare function extractAgentContext(headers: Record<string, string>): Context;
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* CrewAI context bridge for Zespan.
|
|
511
|
+
*
|
|
512
|
+
* Python-side: use openinference-instrumentation-crewai (PyPI).
|
|
513
|
+
* When a CrewAI agent makes an HTTP call to a Node.js service,
|
|
514
|
+
* the downstream service uses extractAgentContext() to continue the trace.
|
|
515
|
+
*
|
|
516
|
+
* Usage in the receiving Node.js service:
|
|
517
|
+
* import { extractAgentContext } from '@zespan/sdk';
|
|
518
|
+
* const ctx = extractAgentContext(req.headers);
|
|
519
|
+
* const span = tracer.startSpan('invoke_agent SubAgent', undefined, ctx);
|
|
520
|
+
*/
|
|
521
|
+
declare const CREWAI_OTEL_ENV: {
|
|
522
|
+
readonly OTEL_EXPORTER_OTLP_ENDPOINT: "http://localhost:4318";
|
|
523
|
+
readonly OTEL_SERVICE_NAME: "crewai-agent";
|
|
524
|
+
};
|
|
525
|
+
/**
|
|
526
|
+
* Configuration guide for CrewAI Python instrumentation.
|
|
527
|
+
*/
|
|
528
|
+
declare function getCrewAIInstrumentationGuide(): string;
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Attach trace context to an AutoGen message payload.
|
|
532
|
+
* Call before sending a message to another AutoGen agent over HTTP.
|
|
533
|
+
*/
|
|
534
|
+
declare function attachTraceToAutoGenMessage<T extends Record<string, unknown>>(message: T, delegationReason?: string): T & {
|
|
535
|
+
_lumiq_trace: Record<string, string>;
|
|
536
|
+
};
|
|
537
|
+
/**
|
|
538
|
+
* Extract trace context from an incoming AutoGen message.
|
|
539
|
+
*/
|
|
540
|
+
declare function extractTraceFromAutoGenMessage(message: Record<string, unknown>): _opentelemetry_api.Context;
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Pydantic AI / Logfire context bridge for Zespan.
|
|
544
|
+
*
|
|
545
|
+
* Pydantic AI uses Logfire (OTel-native) for instrumentation.
|
|
546
|
+
* Configure the OTLP exporter to point at Zespan's ingest endpoint.
|
|
547
|
+
*
|
|
548
|
+
* In your Python environment:
|
|
549
|
+
* OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
|
|
550
|
+
* OTEL_SERVICE_NAME=pydantic-ai-agent
|
|
551
|
+
*
|
|
552
|
+
* Pydantic AI auto-instruments with:
|
|
553
|
+
* import logfire
|
|
554
|
+
* logfire.configure(send_to_logfire=False) # OTel only, no Logfire cloud
|
|
555
|
+
*/
|
|
556
|
+
declare function getPydanticAIConfig(otlpEndpoint: string): Record<string, string>;
|
|
557
|
+
|
|
558
|
+
declare const zespan: {
|
|
559
|
+
init: (o: ZespanOptions) => void;
|
|
560
|
+
getClient: () => ZespanClient;
|
|
561
|
+
getZespanClient: () => ZespanClient;
|
|
562
|
+
wrapOpenAI: typeof wrapOpenAI;
|
|
563
|
+
wrapAnthropic: typeof wrapAnthropic;
|
|
564
|
+
wrapGoogle: typeof wrapGoogle;
|
|
565
|
+
wrapOpenRouter: typeof wrapOpenRouter;
|
|
566
|
+
wrapADKAgent: typeof wrapADKAgent;
|
|
567
|
+
wrapADKRunner: typeof wrapADKRunner;
|
|
568
|
+
instrumentADK: typeof instrumentADK;
|
|
569
|
+
startSpan: typeof startSpan;
|
|
570
|
+
withContext: typeof withZespanContext;
|
|
571
|
+
withTrace: typeof withZespanTrace;
|
|
572
|
+
withAgent: typeof withAgent;
|
|
573
|
+
initOTel: typeof initOTel;
|
|
574
|
+
getTracer: typeof getTracer;
|
|
575
|
+
createSpan: typeof createSpan;
|
|
576
|
+
withSpan: typeof withSpan;
|
|
577
|
+
PromptClient: typeof PromptClient;
|
|
578
|
+
CallbackHandler: typeof ZespanCallbackHandler;
|
|
579
|
+
ADKCallbackHandler: typeof ZespanADKCallbackHandler;
|
|
580
|
+
autopatch: typeof autopatch;
|
|
581
|
+
markFrameworkActive: typeof markFrameworkActive;
|
|
582
|
+
markFrameworkInactive: typeof markFrameworkInactive;
|
|
583
|
+
instrumentVercelAI: typeof instrumentVercelAI;
|
|
584
|
+
getLumiqVercelTelemetry: typeof getLumiqVercelTelemetry;
|
|
585
|
+
LumiqLlamaIndexHandler: typeof LumiqLlamaIndexHandler;
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
export { type ADKAgentOptions, type ADKRunnerOptions, AgentContext, type AgentOptions, BaggageSpanProcessor, CREWAI_OTEL_ENV, GuardrailBlockedError, type GuardrailCheckInput, type GuardrailCheckResponse, type GuardrailResult, type InstrumentADKOptions, LumiqCallbackHandler, ZespanClient as LumiqClient, type LumiqContextOptions, LumiqLlamaIndexHandler, type OTelConfig, type Prompt, PromptClient, type PromptOptions, type ResolvedWrapperGuardrailsSettings, type WrapperGuardrailsOptions, type WrapperGuardrailsSettings, ZespanADKCallbackHandler, ZespanCallbackHandler, ZespanClient, type ZespanContextOptions, attachTraceToAutoGenMessage, autopatch, createSpan, extractAgentContext, extractAgentContext as extractAutoGenContext, extractTraceFromAutoGenMessage, getCrewAIInstrumentationGuide, getLumiqClient, getLumiqVercelTelemetry, getPydanticAIConfig, getTracer, getZespanClient, init, initOTel, initZespan, injectAgentContext, injectAgentContext as injectAutoGenContext, instrumentADK, instrumentVercelAI, markFrameworkActive, markFrameworkInactive, startSpan, withAgent, withLumiqContext, withSpan, withZespan, withZespanContext, withZespanTrace, wrapADKAgent, wrapADKRunner, wrapAnthropic, wrapBedrock, wrapGoogle, wrapGroq, wrapLiteLLM, wrapMistral, wrapOpenAI, wrapOpenRouter, wrapZespanADKAgent, zespan };
|