@agentgov/sdk 0.1.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/dist/client.js ADDED
@@ -0,0 +1,399 @@
1
+ import { FetchClient } from './utils/fetch.js';
2
+ import { wrapOpenAI } from './wrappers/openai.js';
3
+ import { wrapGenerateText, wrapStreamText, wrapGenerateObject, wrapEmbed, wrapEmbedMany } from './wrappers/vercel-ai.js';
4
+ const DEFAULT_BASE_URL = 'https://api.agentgov.co';
5
+ export class AgentGov {
6
+ fetchClient;
7
+ config;
8
+ currentContext = null;
9
+ // Batching
10
+ batchQueue = [];
11
+ batchTimer = null;
12
+ isFlushing = false;
13
+ constructor(config) {
14
+ this.config = {
15
+ baseUrl: DEFAULT_BASE_URL,
16
+ debug: false,
17
+ flushInterval: 5000,
18
+ batchSize: 10,
19
+ maxRetries: 3,
20
+ retryDelay: 1000,
21
+ timeout: 30000,
22
+ ...config
23
+ };
24
+ // Warn about non-HTTPS URLs in production
25
+ const parsedUrl = new URL(this.config.baseUrl);
26
+ const isLocal = parsedUrl.hostname === 'localhost' || parsedUrl.hostname === '127.0.0.1';
27
+ if (parsedUrl.protocol !== 'https:' && !isLocal) {
28
+ console.warn('[AgentGov] WARNING: Using non-HTTPS URL. This is insecure in production.');
29
+ }
30
+ this.fetchClient = new FetchClient({
31
+ baseUrl: this.config.baseUrl,
32
+ apiKey: this.config.apiKey,
33
+ projectId: this.config.projectId,
34
+ debug: this.config.debug,
35
+ maxRetries: this.config.maxRetries,
36
+ retryDelay: this.config.retryDelay,
37
+ timeout: this.config.timeout
38
+ });
39
+ }
40
+ // ============================================
41
+ // OpenAI Integration
42
+ // ============================================
43
+ /**
44
+ * Wrap OpenAI client to automatically trace all calls
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const ag = new AgentGov({ apiKey: 'ag_xxx', projectId: 'xxx' })
49
+ * const openai = ag.wrapOpenAI(new OpenAI())
50
+ *
51
+ * // All calls are now automatically traced (including streaming)
52
+ * const response = await openai.chat.completions.create({
53
+ * model: 'gpt-4o',
54
+ * messages: [{ role: 'user', content: 'Hello!' }]
55
+ * })
56
+ * ```
57
+ */
58
+ wrapOpenAI(client, options) {
59
+ return wrapOpenAI(client, this.fetchClient, () => this.currentContext, {
60
+ ...options,
61
+ debug: options?.debug ?? this.config.debug
62
+ });
63
+ }
64
+ // ============================================
65
+ // Vercel AI SDK Integration
66
+ // ============================================
67
+ /**
68
+ * Wrap Vercel AI SDK's generateText function
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * import { generateText } from 'ai'
73
+ * import { openai } from '@ai-sdk/openai'
74
+ *
75
+ * const ag = new AgentGov({ apiKey: 'ag_xxx', projectId: 'xxx' })
76
+ * const tracedGenerateText = ag.wrapGenerateText(generateText)
77
+ *
78
+ * const { text } = await tracedGenerateText({
79
+ * model: openai('gpt-4o'),
80
+ * prompt: 'Hello!'
81
+ * })
82
+ * ```
83
+ */
84
+ wrapGenerateText(fn, options) {
85
+ return wrapGenerateText(fn, this.fetchClient, () => this.currentContext, {
86
+ ...options,
87
+ debug: options?.debug ?? this.config.debug
88
+ });
89
+ }
90
+ /**
91
+ * Wrap Vercel AI SDK's streamText function
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * import { streamText } from 'ai'
96
+ * import { openai } from '@ai-sdk/openai'
97
+ *
98
+ * const ag = new AgentGov({ apiKey: 'ag_xxx', projectId: 'xxx' })
99
+ * const tracedStreamText = ag.wrapStreamText(streamText)
100
+ *
101
+ * const { textStream } = await tracedStreamText({
102
+ * model: openai('gpt-4o'),
103
+ * prompt: 'Hello!'
104
+ * })
105
+ *
106
+ * for await (const chunk of textStream) {
107
+ * process.stdout.write(chunk)
108
+ * }
109
+ * ```
110
+ */
111
+ wrapStreamText(fn, options) {
112
+ return wrapStreamText(fn, this.fetchClient, () => this.currentContext, {
113
+ ...options,
114
+ debug: options?.debug ?? this.config.debug
115
+ });
116
+ }
117
+ /**
118
+ * Wrap Vercel AI SDK's generateObject function
119
+ */
120
+ wrapGenerateObject(fn, options) {
121
+ return wrapGenerateObject(fn, this.fetchClient, () => this.currentContext, {
122
+ ...options,
123
+ debug: options?.debug ?? this.config.debug
124
+ });
125
+ }
126
+ /**
127
+ * Wrap Vercel AI SDK's embed function
128
+ */
129
+ wrapEmbed(fn, options) {
130
+ return wrapEmbed(fn, this.fetchClient, () => this.currentContext, {
131
+ ...options,
132
+ debug: options?.debug ?? this.config.debug
133
+ });
134
+ }
135
+ /**
136
+ * Wrap Vercel AI SDK's embedMany function
137
+ */
138
+ wrapEmbedMany(fn, options) {
139
+ return wrapEmbedMany(fn, this.fetchClient, () => this.currentContext, {
140
+ ...options,
141
+ debug: options?.debug ?? this.config.debug
142
+ });
143
+ }
144
+ // ============================================
145
+ // Manual Tracing API
146
+ // ============================================
147
+ /**
148
+ * Create a new trace
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const trace = await ag.trace({ name: 'My Agent Run' })
153
+ * // ... do work ...
154
+ * await ag.endTrace(trace.id, { status: 'COMPLETED' })
155
+ * ```
156
+ */
157
+ async trace(input = {}) {
158
+ const trace = await this.fetchClient.createTrace(input);
159
+ this.currentContext = { traceId: trace.id };
160
+ return trace;
161
+ }
162
+ /**
163
+ * End a trace
164
+ */
165
+ async endTrace(traceId, update = {}) {
166
+ const result = await this.fetchClient.updateTrace(traceId, {
167
+ status: update.status || 'COMPLETED',
168
+ output: update.output
169
+ });
170
+ if (this.currentContext?.traceId === traceId) {
171
+ this.currentContext = null;
172
+ }
173
+ return result;
174
+ }
175
+ /**
176
+ * Create a span within current trace
177
+ */
178
+ async span(input) {
179
+ const traceId = input.traceId || this.currentContext?.traceId;
180
+ if (!traceId) {
181
+ throw new Error('No active trace. Call trace() first or provide traceId.');
182
+ }
183
+ const span = await this.fetchClient.createSpan({
184
+ ...input,
185
+ traceId,
186
+ parentId: input.parentId || this.currentContext?.spanId
187
+ });
188
+ return span;
189
+ }
190
+ /**
191
+ * End a span
192
+ */
193
+ async endSpan(spanId, update = {}) {
194
+ return this.fetchClient.updateSpan(spanId, {
195
+ status: update.status || 'COMPLETED',
196
+ ...update
197
+ });
198
+ }
199
+ // ============================================
200
+ // Context Management
201
+ // ============================================
202
+ /**
203
+ * Run a function within a trace context
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * const result = await ag.withTrace({ name: 'My Operation' }, async (ctx) => {
208
+ * // All OpenAI calls within this function are traced
209
+ * const response = await openai.chat.completions.create(...)
210
+ * return response
211
+ * })
212
+ * ```
213
+ */
214
+ async withTrace(input, fn) {
215
+ const trace = await this.trace(input);
216
+ try {
217
+ const result = await fn({ traceId: trace.id });
218
+ await this.endTrace(trace.id, { status: 'COMPLETED' });
219
+ return result;
220
+ }
221
+ catch (error) {
222
+ await this.endTrace(trace.id, { status: 'FAILED' });
223
+ throw error;
224
+ }
225
+ }
226
+ /**
227
+ * Run a function within a span context
228
+ */
229
+ async withSpan(input, fn) {
230
+ const span = await this.span(input);
231
+ const previousSpanId = this.currentContext?.spanId;
232
+ if (this.currentContext) {
233
+ this.currentContext.spanId = span.id;
234
+ }
235
+ try {
236
+ const result = await fn(span);
237
+ await this.endSpan(span.id, { status: 'COMPLETED' });
238
+ return result;
239
+ }
240
+ catch (error) {
241
+ await this.endSpan(span.id, {
242
+ status: 'FAILED',
243
+ error: error instanceof Error ? error.message : String(error)
244
+ });
245
+ throw error;
246
+ }
247
+ finally {
248
+ if (this.currentContext) {
249
+ this.currentContext.spanId = previousSpanId;
250
+ }
251
+ }
252
+ }
253
+ // ============================================
254
+ // Batching API (for high-throughput scenarios)
255
+ // ============================================
256
+ /**
257
+ * Queue a trace creation (batched)
258
+ * Use this for high-throughput scenarios where you don't need immediate response
259
+ */
260
+ queueTrace(input) {
261
+ return new Promise((resolve, reject) => {
262
+ this.batchQueue.push({
263
+ type: 'trace',
264
+ data: input,
265
+ resolve: resolve,
266
+ reject
267
+ });
268
+ this.scheduleBatchFlush();
269
+ });
270
+ }
271
+ /**
272
+ * Queue a span creation (batched)
273
+ */
274
+ queueSpan(input) {
275
+ return new Promise((resolve, reject) => {
276
+ this.batchQueue.push({
277
+ type: 'span',
278
+ data: input,
279
+ resolve: resolve,
280
+ reject
281
+ });
282
+ this.scheduleBatchFlush();
283
+ });
284
+ }
285
+ /**
286
+ * Force flush all queued items
287
+ */
288
+ async flush() {
289
+ if (this.batchTimer) {
290
+ clearTimeout(this.batchTimer);
291
+ this.batchTimer = null;
292
+ }
293
+ await this.processBatch();
294
+ }
295
+ handleFlushError(error, itemCount) {
296
+ const err = error instanceof Error ? error : new Error(String(error));
297
+ if (this.config.onError) {
298
+ this.config.onError(err, { operation: 'batch_flush', itemCount });
299
+ }
300
+ else if (this.config.debug) {
301
+ console.error('[AgentGov] Batch flush failed:', err.message);
302
+ }
303
+ // In non-debug mode without onError callback, errors are silently dropped
304
+ // This is intentional for SDK users who don't want tracing to affect their app
305
+ }
306
+ scheduleBatchFlush() {
307
+ // Immediate flush if batch is full
308
+ if (this.batchQueue.length >= this.config.batchSize) {
309
+ const itemCount = this.batchQueue.length;
310
+ this.flush().catch((error) => this.handleFlushError(error, itemCount));
311
+ return;
312
+ }
313
+ // Schedule flush after interval
314
+ if (!this.batchTimer) {
315
+ this.batchTimer = setTimeout(() => {
316
+ this.batchTimer = null;
317
+ const itemCount = this.batchQueue.length;
318
+ this.flush().catch((error) => this.handleFlushError(error, itemCount));
319
+ }, this.config.flushInterval);
320
+ }
321
+ }
322
+ async processBatch() {
323
+ if (this.isFlushing || this.batchQueue.length === 0)
324
+ return;
325
+ this.isFlushing = true;
326
+ const items = this.batchQueue.splice(0, this.config.batchSize);
327
+ try {
328
+ // Process items in parallel
329
+ await Promise.all(items.map(async (item) => {
330
+ try {
331
+ let result;
332
+ switch (item.type) {
333
+ case 'trace':
334
+ result = await this.fetchClient.createTrace(item.data);
335
+ break;
336
+ case 'span':
337
+ result = await this.fetchClient.createSpan(item.data);
338
+ break;
339
+ case 'traceUpdate': {
340
+ const { id, ...update } = item.data;
341
+ result = await this.fetchClient.updateTrace(id, update);
342
+ break;
343
+ }
344
+ case 'spanUpdate': {
345
+ const { id, ...update } = item.data;
346
+ result = await this.fetchClient.updateSpan(id, update);
347
+ break;
348
+ }
349
+ }
350
+ item.resolve(result);
351
+ }
352
+ catch (error) {
353
+ item.reject(error instanceof Error ? error : new Error(String(error)));
354
+ }
355
+ }));
356
+ }
357
+ finally {
358
+ this.isFlushing = false;
359
+ // Process remaining items if any
360
+ if (this.batchQueue.length > 0) {
361
+ this.scheduleBatchFlush();
362
+ }
363
+ }
364
+ }
365
+ // ============================================
366
+ // Utility Methods
367
+ // ============================================
368
+ /**
369
+ * Get current trace context
370
+ */
371
+ getContext() {
372
+ return this.currentContext;
373
+ }
374
+ /**
375
+ * Set trace context (useful for distributed tracing)
376
+ */
377
+ setContext(context) {
378
+ this.currentContext = context;
379
+ }
380
+ /**
381
+ * Get a trace by ID
382
+ */
383
+ async getTrace(traceId) {
384
+ return this.fetchClient.getTrace(traceId);
385
+ }
386
+ /**
387
+ * Get a span by ID
388
+ */
389
+ async getSpan(spanId) {
390
+ return this.fetchClient.getSpan(spanId);
391
+ }
392
+ /**
393
+ * Shutdown the client, flushing any remaining batched items
394
+ */
395
+ async shutdown() {
396
+ await this.flush();
397
+ }
398
+ }
399
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAA6C,MAAM,sBAAsB,CAAA;AAC5F,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,SAAS,EACT,aAAa,EAOd,MAAM,yBAAyB,CAAA;AAEhC,MAAM,gBAAgB,GAAG,yBAAyB,CAAA;AAalD,MAAM,OAAO,QAAQ;IACX,WAAW,CAAa;IACxB,MAAM,CAAgB;IACtB,cAAc,GAAwB,IAAI,C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C;IAC/C,kBAAkB;IAClB,+CAA+C;IAE/C;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,cAAc,CAAA;IAC5B,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,OAA4B;QACrC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAA;IAC/B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,OAAe;QAC5B,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC3C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,MAAc;QAC1B,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ export { AgentGov } from './client.js';
2
+ export type { AgentGovConfig, TraceContext, TraceInput, Trace, TraceStatus, SpanInput, SpanUpdate, Span, SpanStatus, SpanType } from './types.js';
3
+ export type { WrapOpenAIOptions } from './wrappers/openai.js';
4
+ export type { WrapVercelAIOptions } from './wrappers/vercel-ai.js';
5
+ export { estimateCost, calculateDuration } from './utils/timing.js';
6
+ export { AgentGovAPIError } from './utils/fetch.js';
7
+ export { safeStringify } from './utils/fetch.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAGtC,YAAY,EACV,cAAc,EACd,YAAY,EACZ,UAAU,EACV,KAAK,EACL,WAAW,EACX,SAAS,EACT,UAAU,EACV,IAAI,EACJ,UAAU,EACV,QAAQ,EACT,MAAM,YAAY,CAAA;AAGnB,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAGlE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAGnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAGnD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ // Main client
2
+ export { AgentGov } from './client.js';
3
+ // Utils (for advanced users)
4
+ export { estimateCost, calculateDuration } from './utils/timing.js';
5
+ // Errors
6
+ export { AgentGovAPIError } from './utils/fetch.js';
7
+ // Safety utilities
8
+ export { safeStringify } from './utils/fetch.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAoBtC,6BAA6B;AAC7B,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAEnE,SAAS;AACT,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAEnD,mBAAmB;AACnB,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA"}
@@ -0,0 +1,91 @@
1
+ export interface AgentGovConfig {
2
+ /** API key from AgentGov dashboard (ag_xxx) */
3
+ apiKey: string;
4
+ /** Project ID */
5
+ projectId: string;
6
+ /** API base URL (default: http://localhost:3001) */
7
+ baseUrl?: string;
8
+ /** Enable debug logging */
9
+ debug?: boolean;
10
+ /** Flush interval in ms (default: 5000) */
11
+ flushInterval?: number;
12
+ /** Max batch size before auto-flush (default: 10) */
13
+ batchSize?: number;
14
+ /** Max retry attempts for failed API requests (default: 3) */
15
+ maxRetries?: number;
16
+ /** Base delay in ms for exponential backoff (default: 1000) */
17
+ retryDelay?: number;
18
+ /** Request timeout in ms (default: 30000) */
19
+ timeout?: number;
20
+ /** Callback for batch flush errors (default: logs to console in debug mode) */
21
+ onError?: (error: Error, context: {
22
+ operation: string;
23
+ itemCount?: number;
24
+ }) => void;
25
+ }
26
+ export type TraceStatus = 'RUNNING' | 'COMPLETED' | 'FAILED' | 'CANCELLED';
27
+ export type SpanStatus = 'RUNNING' | 'COMPLETED' | 'FAILED';
28
+ export type SpanType = 'LLM_CALL' | 'TOOL_CALL' | 'AGENT_STEP' | 'RETRIEVAL' | 'EMBEDDING' | 'CUSTOM';
29
+ export interface TraceInput {
30
+ name?: string;
31
+ input?: Record<string, unknown>;
32
+ metadata?: Record<string, unknown>;
33
+ }
34
+ export interface Trace {
35
+ id: string;
36
+ projectId: string;
37
+ name?: string;
38
+ status: TraceStatus;
39
+ startedAt: string;
40
+ endedAt?: string;
41
+ input?: Record<string, unknown>;
42
+ output?: Record<string, unknown>;
43
+ metadata?: Record<string, unknown>;
44
+ totalCost?: number;
45
+ totalTokens?: number;
46
+ totalDuration?: number;
47
+ }
48
+ export interface SpanInput {
49
+ traceId: string;
50
+ parentId?: string;
51
+ name: string;
52
+ type: SpanType;
53
+ input?: Record<string, unknown>;
54
+ metadata?: Record<string, unknown>;
55
+ model?: string;
56
+ toolName?: string;
57
+ toolInput?: Record<string, unknown>;
58
+ }
59
+ export interface SpanUpdate {
60
+ status?: SpanStatus;
61
+ output?: Record<string, unknown>;
62
+ error?: string;
63
+ promptTokens?: number;
64
+ outputTokens?: number;
65
+ cost?: number;
66
+ toolOutput?: Record<string, unknown>;
67
+ metadata?: Record<string, unknown>;
68
+ }
69
+ export interface Span {
70
+ id: string;
71
+ traceId: string;
72
+ parentId?: string;
73
+ name: string;
74
+ type: SpanType;
75
+ status: SpanStatus;
76
+ startedAt: string;
77
+ endedAt?: string;
78
+ duration?: number;
79
+ input?: Record<string, unknown>;
80
+ output?: Record<string, unknown>;
81
+ error?: string;
82
+ model?: string;
83
+ promptTokens?: number;
84
+ outputTokens?: number;
85
+ cost?: number;
86
+ }
87
+ export interface TraceContext {
88
+ traceId: string;
89
+ spanId?: string;
90
+ }
91
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,cAAc;IAC7B,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,2CAA2C;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,+EAA+E;IAC/E,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;CACrF;AAMD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAA;AAC1E,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAA;AAC3D,MAAM,MAAM,QAAQ,GAChB,UAAU,GACV,WAAW,GACX,YAAY,GACZ,WAAW,GACX,WAAW,GACX,QAAQ,CAAA;AAEZ,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,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AAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACnC;AAED,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,QAAQ,CAAA;IACd,MAAM,EAAE,UAAU,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAMD,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB"}
package/dist/types.js ADDED
@@ -0,0 +1,5 @@
1
+ // ============================================
2
+ // Configuration
3
+ // ============================================
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,gBAAgB;AAChB,+CAA+C"}
@@ -0,0 +1,59 @@
1
+ import type { Trace, TraceInput, Span, SpanInput, SpanUpdate } from '../types.js';
2
+ export interface FetchClientConfig {
3
+ baseUrl: string;
4
+ apiKey: string;
5
+ projectId: string;
6
+ debug?: boolean;
7
+ /** Max retry attempts for failed requests (default: 3) */
8
+ maxRetries?: number;
9
+ /** Base delay in ms for exponential backoff (default: 1000) */
10
+ retryDelay?: number;
11
+ /** Request timeout in ms (default: 30000) */
12
+ timeout?: number;
13
+ }
14
+ /** Error thrown when API request fails */
15
+ export declare class AgentGovAPIError extends Error {
16
+ readonly statusCode: number;
17
+ readonly retryable: boolean;
18
+ constructor(message: string, statusCode: number, retryable: boolean);
19
+ }
20
+ /** Safely serialize data, handling circular references */
21
+ export declare function safeStringify(data: unknown): string;
22
+ export declare class FetchClient {
23
+ private baseUrl;
24
+ private headers;
25
+ private projectId;
26
+ private debug;
27
+ private maxRetries;
28
+ private retryDelay;
29
+ private timeout;
30
+ constructor(config: FetchClientConfig);
31
+ /**
32
+ * Sanitize data for logging - removes sensitive fields
33
+ */
34
+ private sanitize;
35
+ private log;
36
+ /**
37
+ * Check if error is retryable based on status code
38
+ */
39
+ private isRetryable;
40
+ /**
41
+ * Calculate delay with exponential backoff and jitter
42
+ */
43
+ private calculateDelay;
44
+ /**
45
+ * Sleep for specified duration
46
+ */
47
+ private sleep;
48
+ private request;
49
+ createTrace(input: TraceInput): Promise<Trace>;
50
+ updateTrace(traceId: string, update: {
51
+ status?: string;
52
+ output?: Record<string, unknown>;
53
+ }): Promise<Trace>;
54
+ getTrace(traceId: string): Promise<Trace>;
55
+ createSpan(input: SpanInput): Promise<Span>;
56
+ updateSpan(spanId: string, update: SpanUpdate): Promise<Span>;
57
+ getSpan(spanId: string): Promise<Span>;
58
+ }
59
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/utils/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,UAAU,EACV,IAAI,EACJ,SAAS,EACT,UAAU,EACX,MAAM,aAAa,CAAA;AAEpB,MAAM,WAAW,iBAAiB;IAChC,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