@synova-cloud/sdk 1.7.0 → 1.8.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.d.cts CHANGED
@@ -178,6 +178,8 @@ interface ISynovaExecuteOptions {
178
178
  parameters?: Record<string, unknown>;
179
179
  /** JSON Schema for structured output */
180
180
  responseSchema?: IJsonSchema;
181
+ /** Session ID for trace grouping (enables multi-call trace view in observability) */
182
+ sessionId?: string;
181
183
  }
182
184
  interface ISynovaExecutionUsage {
183
185
  /** Usage type: 'tokens' for LLM, 'images' for image generation, 'time' for time-based billing */
@@ -210,8 +212,10 @@ interface ISynovaExecutionErrorDetails {
210
212
  promptId?: string;
211
213
  /** Prompt version (if execution was via prompt) */
212
214
  promptVersion?: string;
213
- /** Execution log ID for debugging */
215
+ /** @deprecated Use spanDataId instead */
214
216
  executionLogId?: string;
217
+ /** SpanData ID for debugging */
218
+ spanDataId?: string;
215
219
  /** Input tokens count (for CONTEXT_TOO_LONG errors) */
216
220
  inputTokens?: number;
217
221
  /** Model context window limit (for CONTEXT_TOO_LONG errors) */
@@ -260,6 +264,14 @@ interface ISynovaExecuteResponse {
260
264
  error?: ISynovaExecutionError;
261
265
  /** Execution usage statistics (tokens, images, or time-based) */
262
266
  executionUsage?: ISynovaExecutionUsage;
267
+ /** @deprecated Use spanDataId instead */
268
+ executionId?: string;
269
+ /** SpanData ID (contains execution details: messages, response, usage) */
270
+ spanDataId?: string;
271
+ /** Trace ID (for observability - grouping multiple calls) */
272
+ traceId?: string;
273
+ /** Span ID (for observability - individual call within trace) */
274
+ spanId?: string;
263
275
  }
264
276
  interface ISynovaModelCapabilities {
265
277
  text_generation?: boolean;
@@ -334,6 +346,81 @@ interface ISynovaUploadOptions {
334
346
  /** Project ID to associate files with */
335
347
  projectId: string;
336
348
  }
349
+ type TSynovaSpanType = 'generation' | 'tool' | 'retriever' | 'embedding' | 'custom';
350
+ type TSynovaSpanStatus = 'pending' | 'completed' | 'error';
351
+ type TSynovaSpanLevel = 'default' | 'debug' | 'warning' | 'error';
352
+ interface ISynovaCreateSpanOptions {
353
+ /** Span type */
354
+ type: TSynovaSpanType;
355
+ /** Parent span ID (for nested spans) */
356
+ parentSpanId?: string;
357
+ /** Span name (defaults to toolName for tool spans) */
358
+ name?: string;
359
+ /** Input data (for custom/retriever/embedding spans) */
360
+ input?: unknown;
361
+ /** Tool name (for tool spans) */
362
+ toolName?: string;
363
+ /** Tool arguments (for tool spans) */
364
+ toolArguments?: Record<string, unknown>;
365
+ /** Custom metadata */
366
+ metadata?: Record<string, string>;
367
+ }
368
+ interface ISynovaEndSpanOptions {
369
+ /** Span completion status */
370
+ status?: TSynovaSpanStatus;
371
+ /** Span level (for filtering/highlighting) */
372
+ level?: TSynovaSpanLevel;
373
+ /** Status message (e.g., error message) */
374
+ statusMessage?: string;
375
+ /** Output data (for custom/retriever/embedding spans) */
376
+ output?: unknown;
377
+ /** Tool execution result (for tool spans) */
378
+ toolResult?: unknown;
379
+ /** Duration in milliseconds (auto-calculated if not provided) */
380
+ durationMs?: number;
381
+ }
382
+ interface ISynovaSpanData {
383
+ id: string;
384
+ type: TSynovaSpanType;
385
+ toolName?: string;
386
+ toolArguments?: unknown;
387
+ toolResult?: unknown;
388
+ input?: unknown;
389
+ output?: unknown;
390
+ messages?: ISynovaMessage[];
391
+ response?: {
392
+ type: TSynovaResponseType;
393
+ content?: string;
394
+ object?: unknown;
395
+ toolCalls?: ISynovaToolCall[];
396
+ };
397
+ usage?: ISynovaExecutionUsage;
398
+ provider?: string;
399
+ model?: string;
400
+ executionTimeMs?: number;
401
+ errorMessage?: string;
402
+ metadata?: Record<string, string>;
403
+ createdAt: string;
404
+ }
405
+ interface ISynovaSpan {
406
+ id: string;
407
+ traceId: string;
408
+ parentSpanId?: string;
409
+ type: TSynovaSpanType;
410
+ name?: string;
411
+ status: TSynovaSpanStatus;
412
+ level: TSynovaSpanLevel;
413
+ statusMessage?: string;
414
+ startTime: string;
415
+ endTime?: string;
416
+ durationMs?: number;
417
+ provider?: string;
418
+ model?: string;
419
+ metadata?: Record<string, string>;
420
+ createdAt: string;
421
+ /** SpanData (included when fetching span details) */
422
+ spanData?: ISynovaSpanData;
423
+ }
337
424
  interface IApiErrorResponse {
338
425
  code: string;
339
426
  httpCode: number;
@@ -361,7 +448,7 @@ interface IHttpClientConfig {
361
448
  logger: ISynovaLogger;
362
449
  }
363
450
  interface IRequestOptions {
364
- method: 'GET' | 'POST' | 'PUT' | 'DELETE';
451
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
365
452
  path: string;
366
453
  body?: unknown;
367
454
  query?: Record<string, string | undefined>;
@@ -556,6 +643,120 @@ declare class FilesResource {
556
643
  upload(files: (File | Blob)[], options: ISynovaUploadOptions): Promise<ISynovaUploadResponse>;
557
644
  }
558
645
 
646
+ /**
647
+ * Options for wrapping a function with span tracking
648
+ */
649
+ interface ISynovaWrapOptions {
650
+ /** Trace ID */
651
+ traceId: string;
652
+ /** Span type */
653
+ type: TSynovaSpanType;
654
+ /** Span name */
655
+ name?: string;
656
+ /** Parent span ID */
657
+ parentSpanId?: string;
658
+ /** Custom metadata */
659
+ metadata?: Record<string, string>;
660
+ }
661
+ /**
662
+ * Options for wrapping a tool function
663
+ */
664
+ interface ISynovaWrapToolOptions {
665
+ /** Trace ID */
666
+ traceId: string;
667
+ /** Tool name */
668
+ toolName: string;
669
+ /** Parent span ID */
670
+ parentSpanId?: string;
671
+ /** Custom metadata */
672
+ metadata?: Record<string, string>;
673
+ }
674
+ /**
675
+ * Spans resource for observability
676
+ *
677
+ * @example
678
+ * ```ts
679
+ * // Manual: create and end span
680
+ * const span = await client.spans.create('trc_123', {
681
+ * type: 'tool',
682
+ * toolName: 'fetch_weather',
683
+ * toolArguments: { city: 'NYC' },
684
+ * });
685
+ * const result = await fetchWeather('NYC');
686
+ * await client.spans.end(span.id, { status: 'completed', toolResult: result });
687
+ *
688
+ * // Wrapper: automatic span lifecycle
689
+ * const weather = await client.spans.wrapTool(
690
+ * { traceId: 'trc_123', toolName: 'fetch_weather' },
691
+ * { city: 'NYC' },
692
+ * (args) => fetchWeather(args.city),
693
+ * );
694
+ *
695
+ * // Generic wrapper for custom spans
696
+ * const result = await client.spans.wrap(
697
+ * { traceId: 'trc_123', type: 'custom', name: 'validate' },
698
+ * { input: data },
699
+ * async () => validateData(data),
700
+ * );
701
+ * ```
702
+ */
703
+ declare class SpansResource {
704
+ private readonly http;
705
+ constructor(http: HttpClient);
706
+ /**
707
+ * Create a new span within a trace
708
+ *
709
+ * @param traceId - The trace ID to create span in
710
+ * @param options - Span creation options
711
+ * @returns Created span
712
+ */
713
+ create(traceId: string, options: ISynovaCreateSpanOptions): Promise<ISynovaSpan>;
714
+ /**
715
+ * End/complete a span
716
+ *
717
+ * @param spanId - The span ID to end
718
+ * @param options - Span end options
719
+ * @returns Updated span
720
+ */
721
+ end(spanId: string, options?: ISynovaEndSpanOptions): Promise<ISynovaSpan>;
722
+ /**
723
+ * Wrap an async function with automatic span tracking
724
+ *
725
+ * @param options - Span options (traceId, type, name, etc.)
726
+ * @param input - Input data to record in span
727
+ * @param fn - Async function to execute
728
+ * @returns Result of the function
729
+ *
730
+ * @example
731
+ * ```ts
732
+ * const result = await client.spans.wrap(
733
+ * { traceId: 'trc_123', type: 'retriever', name: 'vector_search' },
734
+ * { query: 'how to...', topK: 5 },
735
+ * async () => vectorDb.search(query),
736
+ * );
737
+ * ```
738
+ */
739
+ wrap<T>(options: ISynovaWrapOptions, input: unknown, fn: () => Promise<T>): Promise<T>;
740
+ /**
741
+ * Wrap a tool function with automatic span tracking
742
+ *
743
+ * @param options - Tool span options (traceId, toolName, etc.)
744
+ * @param args - Tool arguments to record
745
+ * @param fn - Tool function to execute
746
+ * @returns Result of the tool
747
+ *
748
+ * @example
749
+ * ```ts
750
+ * const weather = await client.spans.wrapTool(
751
+ * { traceId: 'trc_123', toolName: 'fetch_weather', parentSpanId: 'spn_abc' },
752
+ * { city: 'NYC' },
753
+ * async (args) => fetchWeather(args.city),
754
+ * );
755
+ * ```
756
+ */
757
+ wrapTool<TArgs extends Record<string, unknown>, TResult>(options: ISynovaWrapToolOptions, args: TArgs, fn: (args: TArgs) => Promise<TResult>): Promise<TResult>;
758
+ }
759
+
559
760
  /**
560
761
  * Synova Cloud SDK client
561
762
  *
@@ -605,6 +806,7 @@ declare class SynovaCloudSdk {
605
806
  readonly prompts: PromptsResource;
606
807
  readonly models: ModelsResource;
607
808
  readonly files: FilesResource;
809
+ readonly spans: SpansResource;
608
810
  private readonly http;
609
811
  /**
610
812
  * Create a new Synova Cloud SDK client
@@ -1007,4 +1209,4 @@ declare function SchemaUniqueItems(): PropertyDecorator;
1007
1209
  */
1008
1210
  declare function SchemaEnum(values: (string | number | boolean | null)[]): PropertyDecorator;
1009
1211
 
1010
- export { ApiSynovaError, ArrayItems, AuthSynovaError, ClassSchema, Default, Description, Example, ExclusiveMax, ExclusiveMin, ExecutionSynovaError, Format, type IGenerateSchemaOptions, type IJsonSchema, type ISynovaConfig, type ISynovaExecuteOptions, type ISynovaExecuteResponse, type ISynovaExecuteTypedOptions, type ISynovaExecutionError, type ISynovaExecutionErrorDetails, type ISynovaExecutionUsage, type ISynovaFileAttachment, type ISynovaFileThumbnails, type ISynovaGetPromptOptions, type ISynovaListModelsOptions, type ISynovaLogger, type ISynovaMessage, type ISynovaModel, type ISynovaModelCapabilities, type ISynovaModelLimits, type ISynovaModelPricing, type ISynovaModelsResponse, type ISynovaPrompt, type ISynovaPromptVariable, type ISynovaProvider, type ISynovaProviderResponse, type ISynovaRetryConfig, type ISynovaToolCall, type ISynovaToolResult, type ISynovaUploadOptions, type ISynovaUploadResponse, type ISynovaUploadedFile, type IValidationViolation, MultipleOf, NetworkSynovaError, NotFoundSynovaError, Nullable, RateLimitSynovaError, SCHEMA_METADATA_KEYS, SchemaEnum, SchemaMax, SchemaMaxItems, SchemaMaxLength, SchemaMin, SchemaMinItems, SchemaMinLength, SchemaPattern, SchemaUniqueItems, ServerSynovaError, SynovaCloudSdk, SynovaError, type TClassConstructor, type TJsonSchemaFormat, type TJsonSchemaType, type TSynovaMessageRole, type TSynovaModelType, type TSynovaResponseType, type TSynovaRetryStrategy, type TSynovaUsageType, TimeoutSynovaError, ValidationSynovaError };
1212
+ export { ApiSynovaError, ArrayItems, AuthSynovaError, ClassSchema, Default, Description, Example, ExclusiveMax, ExclusiveMin, ExecutionSynovaError, Format, type IGenerateSchemaOptions, type IJsonSchema, type ISynovaConfig, type ISynovaCreateSpanOptions, type ISynovaEndSpanOptions, type ISynovaExecuteOptions, type ISynovaExecuteResponse, type ISynovaExecuteTypedOptions, type ISynovaExecutionError, type ISynovaExecutionErrorDetails, type ISynovaExecutionUsage, type ISynovaFileAttachment, type ISynovaFileThumbnails, type ISynovaGetPromptOptions, type ISynovaListModelsOptions, type ISynovaLogger, type ISynovaMessage, type ISynovaModel, type ISynovaModelCapabilities, type ISynovaModelLimits, type ISynovaModelPricing, type ISynovaModelsResponse, type ISynovaPrompt, type ISynovaPromptVariable, type ISynovaProvider, type ISynovaProviderResponse, type ISynovaRetryConfig, type ISynovaSpan, type ISynovaSpanData, type ISynovaToolCall, type ISynovaToolResult, type ISynovaUploadOptions, type ISynovaUploadResponse, type ISynovaUploadedFile, type ISynovaWrapOptions, type ISynovaWrapToolOptions, type IValidationViolation, MultipleOf, NetworkSynovaError, NotFoundSynovaError, Nullable, RateLimitSynovaError, SCHEMA_METADATA_KEYS, SchemaEnum, SchemaMax, SchemaMaxItems, SchemaMaxLength, SchemaMin, SchemaMinItems, SchemaMinLength, SchemaPattern, SchemaUniqueItems, ServerSynovaError, SynovaCloudSdk, SynovaError, type TClassConstructor, type TJsonSchemaFormat, type TJsonSchemaType, type TSynovaMessageRole, type TSynovaModelType, type TSynovaResponseType, type TSynovaRetryStrategy, type TSynovaSpanLevel, type TSynovaSpanStatus, type TSynovaSpanType, type TSynovaUsageType, TimeoutSynovaError, ValidationSynovaError };
package/dist/index.d.ts CHANGED
@@ -178,6 +178,8 @@ interface ISynovaExecuteOptions {
178
178
  parameters?: Record<string, unknown>;
179
179
  /** JSON Schema for structured output */
180
180
  responseSchema?: IJsonSchema;
181
+ /** Session ID for trace grouping (enables multi-call trace view in observability) */
182
+ sessionId?: string;
181
183
  }
182
184
  interface ISynovaExecutionUsage {
183
185
  /** Usage type: 'tokens' for LLM, 'images' for image generation, 'time' for time-based billing */
@@ -210,8 +212,10 @@ interface ISynovaExecutionErrorDetails {
210
212
  promptId?: string;
211
213
  /** Prompt version (if execution was via prompt) */
212
214
  promptVersion?: string;
213
- /** Execution log ID for debugging */
215
+ /** @deprecated Use spanDataId instead */
214
216
  executionLogId?: string;
217
+ /** SpanData ID for debugging */
218
+ spanDataId?: string;
215
219
  /** Input tokens count (for CONTEXT_TOO_LONG errors) */
216
220
  inputTokens?: number;
217
221
  /** Model context window limit (for CONTEXT_TOO_LONG errors) */
@@ -260,6 +264,14 @@ interface ISynovaExecuteResponse {
260
264
  error?: ISynovaExecutionError;
261
265
  /** Execution usage statistics (tokens, images, or time-based) */
262
266
  executionUsage?: ISynovaExecutionUsage;
267
+ /** @deprecated Use spanDataId instead */
268
+ executionId?: string;
269
+ /** SpanData ID (contains execution details: messages, response, usage) */
270
+ spanDataId?: string;
271
+ /** Trace ID (for observability - grouping multiple calls) */
272
+ traceId?: string;
273
+ /** Span ID (for observability - individual call within trace) */
274
+ spanId?: string;
263
275
  }
264
276
  interface ISynovaModelCapabilities {
265
277
  text_generation?: boolean;
@@ -334,6 +346,81 @@ interface ISynovaUploadOptions {
334
346
  /** Project ID to associate files with */
335
347
  projectId: string;
336
348
  }
349
+ type TSynovaSpanType = 'generation' | 'tool' | 'retriever' | 'embedding' | 'custom';
350
+ type TSynovaSpanStatus = 'pending' | 'completed' | 'error';
351
+ type TSynovaSpanLevel = 'default' | 'debug' | 'warning' | 'error';
352
+ interface ISynovaCreateSpanOptions {
353
+ /** Span type */
354
+ type: TSynovaSpanType;
355
+ /** Parent span ID (for nested spans) */
356
+ parentSpanId?: string;
357
+ /** Span name (defaults to toolName for tool spans) */
358
+ name?: string;
359
+ /** Input data (for custom/retriever/embedding spans) */
360
+ input?: unknown;
361
+ /** Tool name (for tool spans) */
362
+ toolName?: string;
363
+ /** Tool arguments (for tool spans) */
364
+ toolArguments?: Record<string, unknown>;
365
+ /** Custom metadata */
366
+ metadata?: Record<string, string>;
367
+ }
368
+ interface ISynovaEndSpanOptions {
369
+ /** Span completion status */
370
+ status?: TSynovaSpanStatus;
371
+ /** Span level (for filtering/highlighting) */
372
+ level?: TSynovaSpanLevel;
373
+ /** Status message (e.g., error message) */
374
+ statusMessage?: string;
375
+ /** Output data (for custom/retriever/embedding spans) */
376
+ output?: unknown;
377
+ /** Tool execution result (for tool spans) */
378
+ toolResult?: unknown;
379
+ /** Duration in milliseconds (auto-calculated if not provided) */
380
+ durationMs?: number;
381
+ }
382
+ interface ISynovaSpanData {
383
+ id: string;
384
+ type: TSynovaSpanType;
385
+ toolName?: string;
386
+ toolArguments?: unknown;
387
+ toolResult?: unknown;
388
+ input?: unknown;
389
+ output?: unknown;
390
+ messages?: ISynovaMessage[];
391
+ response?: {
392
+ type: TSynovaResponseType;
393
+ content?: string;
394
+ object?: unknown;
395
+ toolCalls?: ISynovaToolCall[];
396
+ };
397
+ usage?: ISynovaExecutionUsage;
398
+ provider?: string;
399
+ model?: string;
400
+ executionTimeMs?: number;
401
+ errorMessage?: string;
402
+ metadata?: Record<string, string>;
403
+ createdAt: string;
404
+ }
405
+ interface ISynovaSpan {
406
+ id: string;
407
+ traceId: string;
408
+ parentSpanId?: string;
409
+ type: TSynovaSpanType;
410
+ name?: string;
411
+ status: TSynovaSpanStatus;
412
+ level: TSynovaSpanLevel;
413
+ statusMessage?: string;
414
+ startTime: string;
415
+ endTime?: string;
416
+ durationMs?: number;
417
+ provider?: string;
418
+ model?: string;
419
+ metadata?: Record<string, string>;
420
+ createdAt: string;
421
+ /** SpanData (included when fetching span details) */
422
+ spanData?: ISynovaSpanData;
423
+ }
337
424
  interface IApiErrorResponse {
338
425
  code: string;
339
426
  httpCode: number;
@@ -361,7 +448,7 @@ interface IHttpClientConfig {
361
448
  logger: ISynovaLogger;
362
449
  }
363
450
  interface IRequestOptions {
364
- method: 'GET' | 'POST' | 'PUT' | 'DELETE';
451
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
365
452
  path: string;
366
453
  body?: unknown;
367
454
  query?: Record<string, string | undefined>;
@@ -556,6 +643,120 @@ declare class FilesResource {
556
643
  upload(files: (File | Blob)[], options: ISynovaUploadOptions): Promise<ISynovaUploadResponse>;
557
644
  }
558
645
 
646
+ /**
647
+ * Options for wrapping a function with span tracking
648
+ */
649
+ interface ISynovaWrapOptions {
650
+ /** Trace ID */
651
+ traceId: string;
652
+ /** Span type */
653
+ type: TSynovaSpanType;
654
+ /** Span name */
655
+ name?: string;
656
+ /** Parent span ID */
657
+ parentSpanId?: string;
658
+ /** Custom metadata */
659
+ metadata?: Record<string, string>;
660
+ }
661
+ /**
662
+ * Options for wrapping a tool function
663
+ */
664
+ interface ISynovaWrapToolOptions {
665
+ /** Trace ID */
666
+ traceId: string;
667
+ /** Tool name */
668
+ toolName: string;
669
+ /** Parent span ID */
670
+ parentSpanId?: string;
671
+ /** Custom metadata */
672
+ metadata?: Record<string, string>;
673
+ }
674
+ /**
675
+ * Spans resource for observability
676
+ *
677
+ * @example
678
+ * ```ts
679
+ * // Manual: create and end span
680
+ * const span = await client.spans.create('trc_123', {
681
+ * type: 'tool',
682
+ * toolName: 'fetch_weather',
683
+ * toolArguments: { city: 'NYC' },
684
+ * });
685
+ * const result = await fetchWeather('NYC');
686
+ * await client.spans.end(span.id, { status: 'completed', toolResult: result });
687
+ *
688
+ * // Wrapper: automatic span lifecycle
689
+ * const weather = await client.spans.wrapTool(
690
+ * { traceId: 'trc_123', toolName: 'fetch_weather' },
691
+ * { city: 'NYC' },
692
+ * (args) => fetchWeather(args.city),
693
+ * );
694
+ *
695
+ * // Generic wrapper for custom spans
696
+ * const result = await client.spans.wrap(
697
+ * { traceId: 'trc_123', type: 'custom', name: 'validate' },
698
+ * { input: data },
699
+ * async () => validateData(data),
700
+ * );
701
+ * ```
702
+ */
703
+ declare class SpansResource {
704
+ private readonly http;
705
+ constructor(http: HttpClient);
706
+ /**
707
+ * Create a new span within a trace
708
+ *
709
+ * @param traceId - The trace ID to create span in
710
+ * @param options - Span creation options
711
+ * @returns Created span
712
+ */
713
+ create(traceId: string, options: ISynovaCreateSpanOptions): Promise<ISynovaSpan>;
714
+ /**
715
+ * End/complete a span
716
+ *
717
+ * @param spanId - The span ID to end
718
+ * @param options - Span end options
719
+ * @returns Updated span
720
+ */
721
+ end(spanId: string, options?: ISynovaEndSpanOptions): Promise<ISynovaSpan>;
722
+ /**
723
+ * Wrap an async function with automatic span tracking
724
+ *
725
+ * @param options - Span options (traceId, type, name, etc.)
726
+ * @param input - Input data to record in span
727
+ * @param fn - Async function to execute
728
+ * @returns Result of the function
729
+ *
730
+ * @example
731
+ * ```ts
732
+ * const result = await client.spans.wrap(
733
+ * { traceId: 'trc_123', type: 'retriever', name: 'vector_search' },
734
+ * { query: 'how to...', topK: 5 },
735
+ * async () => vectorDb.search(query),
736
+ * );
737
+ * ```
738
+ */
739
+ wrap<T>(options: ISynovaWrapOptions, input: unknown, fn: () => Promise<T>): Promise<T>;
740
+ /**
741
+ * Wrap a tool function with automatic span tracking
742
+ *
743
+ * @param options - Tool span options (traceId, toolName, etc.)
744
+ * @param args - Tool arguments to record
745
+ * @param fn - Tool function to execute
746
+ * @returns Result of the tool
747
+ *
748
+ * @example
749
+ * ```ts
750
+ * const weather = await client.spans.wrapTool(
751
+ * { traceId: 'trc_123', toolName: 'fetch_weather', parentSpanId: 'spn_abc' },
752
+ * { city: 'NYC' },
753
+ * async (args) => fetchWeather(args.city),
754
+ * );
755
+ * ```
756
+ */
757
+ wrapTool<TArgs extends Record<string, unknown>, TResult>(options: ISynovaWrapToolOptions, args: TArgs, fn: (args: TArgs) => Promise<TResult>): Promise<TResult>;
758
+ }
759
+
559
760
  /**
560
761
  * Synova Cloud SDK client
561
762
  *
@@ -605,6 +806,7 @@ declare class SynovaCloudSdk {
605
806
  readonly prompts: PromptsResource;
606
807
  readonly models: ModelsResource;
607
808
  readonly files: FilesResource;
809
+ readonly spans: SpansResource;
608
810
  private readonly http;
609
811
  /**
610
812
  * Create a new Synova Cloud SDK client
@@ -1007,4 +1209,4 @@ declare function SchemaUniqueItems(): PropertyDecorator;
1007
1209
  */
1008
1210
  declare function SchemaEnum(values: (string | number | boolean | null)[]): PropertyDecorator;
1009
1211
 
1010
- export { ApiSynovaError, ArrayItems, AuthSynovaError, ClassSchema, Default, Description, Example, ExclusiveMax, ExclusiveMin, ExecutionSynovaError, Format, type IGenerateSchemaOptions, type IJsonSchema, type ISynovaConfig, type ISynovaExecuteOptions, type ISynovaExecuteResponse, type ISynovaExecuteTypedOptions, type ISynovaExecutionError, type ISynovaExecutionErrorDetails, type ISynovaExecutionUsage, type ISynovaFileAttachment, type ISynovaFileThumbnails, type ISynovaGetPromptOptions, type ISynovaListModelsOptions, type ISynovaLogger, type ISynovaMessage, type ISynovaModel, type ISynovaModelCapabilities, type ISynovaModelLimits, type ISynovaModelPricing, type ISynovaModelsResponse, type ISynovaPrompt, type ISynovaPromptVariable, type ISynovaProvider, type ISynovaProviderResponse, type ISynovaRetryConfig, type ISynovaToolCall, type ISynovaToolResult, type ISynovaUploadOptions, type ISynovaUploadResponse, type ISynovaUploadedFile, type IValidationViolation, MultipleOf, NetworkSynovaError, NotFoundSynovaError, Nullable, RateLimitSynovaError, SCHEMA_METADATA_KEYS, SchemaEnum, SchemaMax, SchemaMaxItems, SchemaMaxLength, SchemaMin, SchemaMinItems, SchemaMinLength, SchemaPattern, SchemaUniqueItems, ServerSynovaError, SynovaCloudSdk, SynovaError, type TClassConstructor, type TJsonSchemaFormat, type TJsonSchemaType, type TSynovaMessageRole, type TSynovaModelType, type TSynovaResponseType, type TSynovaRetryStrategy, type TSynovaUsageType, TimeoutSynovaError, ValidationSynovaError };
1212
+ export { ApiSynovaError, ArrayItems, AuthSynovaError, ClassSchema, Default, Description, Example, ExclusiveMax, ExclusiveMin, ExecutionSynovaError, Format, type IGenerateSchemaOptions, type IJsonSchema, type ISynovaConfig, type ISynovaCreateSpanOptions, type ISynovaEndSpanOptions, type ISynovaExecuteOptions, type ISynovaExecuteResponse, type ISynovaExecuteTypedOptions, type ISynovaExecutionError, type ISynovaExecutionErrorDetails, type ISynovaExecutionUsage, type ISynovaFileAttachment, type ISynovaFileThumbnails, type ISynovaGetPromptOptions, type ISynovaListModelsOptions, type ISynovaLogger, type ISynovaMessage, type ISynovaModel, type ISynovaModelCapabilities, type ISynovaModelLimits, type ISynovaModelPricing, type ISynovaModelsResponse, type ISynovaPrompt, type ISynovaPromptVariable, type ISynovaProvider, type ISynovaProviderResponse, type ISynovaRetryConfig, type ISynovaSpan, type ISynovaSpanData, type ISynovaToolCall, type ISynovaToolResult, type ISynovaUploadOptions, type ISynovaUploadResponse, type ISynovaUploadedFile, type ISynovaWrapOptions, type ISynovaWrapToolOptions, type IValidationViolation, MultipleOf, NetworkSynovaError, NotFoundSynovaError, Nullable, RateLimitSynovaError, SCHEMA_METADATA_KEYS, SchemaEnum, SchemaMax, SchemaMaxItems, SchemaMaxLength, SchemaMin, SchemaMinItems, SchemaMinLength, SchemaPattern, SchemaUniqueItems, ServerSynovaError, SynovaCloudSdk, SynovaError, type TClassConstructor, type TJsonSchemaFormat, type TJsonSchemaType, type TSynovaMessageRole, type TSynovaModelType, type TSynovaResponseType, type TSynovaRetryStrategy, type TSynovaSpanLevel, type TSynovaSpanStatus, type TSynovaSpanType, type TSynovaUsageType, TimeoutSynovaError, ValidationSynovaError };
package/dist/index.js CHANGED
@@ -105,7 +105,7 @@ var ValidationSynovaError = class extends SynovaError {
105
105
  };
106
106
 
107
107
  // src/version.ts
108
- var SDK_VERSION = "1.7.0" ;
108
+ var SDK_VERSION = "1.8.0" ;
109
109
 
110
110
  // src/utils/http.ts
111
111
  var HttpClient = class {
@@ -818,6 +818,7 @@ var PromptsResource = class {
818
818
  if (options.metadata !== void 0) body.metadata = options.metadata;
819
819
  if (options.parameters !== void 0) body.parameters = options.parameters;
820
820
  if (options.responseSchema !== void 0) body.responseSchema = options.responseSchema;
821
+ if (options.sessionId !== void 0) body.sessionId = options.sessionId;
821
822
  const response = await this.http.request({
822
823
  method: "POST",
823
824
  path: `/api/v1/prompts/${promptId}/run`,
@@ -1002,6 +1003,137 @@ var FilesResource = class {
1002
1003
  }
1003
1004
  };
1004
1005
 
1006
+ // src/resources/spans.ts
1007
+ var SpansResource = class {
1008
+ constructor(http) {
1009
+ this.http = http;
1010
+ }
1011
+ /**
1012
+ * Create a new span within a trace
1013
+ *
1014
+ * @param traceId - The trace ID to create span in
1015
+ * @param options - Span creation options
1016
+ * @returns Created span
1017
+ */
1018
+ async create(traceId, options) {
1019
+ const body = {
1020
+ type: options.type
1021
+ };
1022
+ if (options.parentSpanId !== void 0) body.parentSpanId = options.parentSpanId;
1023
+ if (options.name !== void 0) body.name = options.name;
1024
+ if (options.input !== void 0) body.input = options.input;
1025
+ if (options.toolName !== void 0) body.toolName = options.toolName;
1026
+ if (options.toolArguments !== void 0) body.toolArguments = options.toolArguments;
1027
+ if (options.metadata !== void 0) body.metadata = options.metadata;
1028
+ return this.http.request({
1029
+ method: "POST",
1030
+ path: `/api/v1/traces/${traceId}/spans`,
1031
+ body
1032
+ });
1033
+ }
1034
+ /**
1035
+ * End/complete a span
1036
+ *
1037
+ * @param spanId - The span ID to end
1038
+ * @param options - Span end options
1039
+ * @returns Updated span
1040
+ */
1041
+ async end(spanId, options) {
1042
+ const body = {};
1043
+ if (options?.status !== void 0) body.status = options.status;
1044
+ if (options?.level !== void 0) body.level = options.level;
1045
+ if (options?.statusMessage !== void 0) body.statusMessage = options.statusMessage;
1046
+ if (options?.output !== void 0) body.output = options.output;
1047
+ if (options?.toolResult !== void 0) body.toolResult = options.toolResult;
1048
+ if (options?.durationMs !== void 0) body.durationMs = options.durationMs;
1049
+ return this.http.request({
1050
+ method: "PATCH",
1051
+ path: `/api/v1/spans/${spanId}`,
1052
+ body
1053
+ });
1054
+ }
1055
+ /**
1056
+ * Wrap an async function with automatic span tracking
1057
+ *
1058
+ * @param options - Span options (traceId, type, name, etc.)
1059
+ * @param input - Input data to record in span
1060
+ * @param fn - Async function to execute
1061
+ * @returns Result of the function
1062
+ *
1063
+ * @example
1064
+ * ```ts
1065
+ * const result = await client.spans.wrap(
1066
+ * { traceId: 'trc_123', type: 'retriever', name: 'vector_search' },
1067
+ * { query: 'how to...', topK: 5 },
1068
+ * async () => vectorDb.search(query),
1069
+ * );
1070
+ * ```
1071
+ */
1072
+ async wrap(options, input, fn) {
1073
+ const span = await this.create(options.traceId, {
1074
+ type: options.type,
1075
+ name: options.name,
1076
+ parentSpanId: options.parentSpanId,
1077
+ input,
1078
+ metadata: options.metadata
1079
+ });
1080
+ try {
1081
+ const result = await fn();
1082
+ await this.end(span.id, {
1083
+ status: "completed",
1084
+ output: result
1085
+ });
1086
+ return result;
1087
+ } catch (error) {
1088
+ await this.end(span.id, {
1089
+ status: "error",
1090
+ statusMessage: error instanceof Error ? error.message : String(error)
1091
+ });
1092
+ throw error;
1093
+ }
1094
+ }
1095
+ /**
1096
+ * Wrap a tool function with automatic span tracking
1097
+ *
1098
+ * @param options - Tool span options (traceId, toolName, etc.)
1099
+ * @param args - Tool arguments to record
1100
+ * @param fn - Tool function to execute
1101
+ * @returns Result of the tool
1102
+ *
1103
+ * @example
1104
+ * ```ts
1105
+ * const weather = await client.spans.wrapTool(
1106
+ * { traceId: 'trc_123', toolName: 'fetch_weather', parentSpanId: 'spn_abc' },
1107
+ * { city: 'NYC' },
1108
+ * async (args) => fetchWeather(args.city),
1109
+ * );
1110
+ * ```
1111
+ */
1112
+ async wrapTool(options, args, fn) {
1113
+ const span = await this.create(options.traceId, {
1114
+ type: "tool",
1115
+ toolName: options.toolName,
1116
+ toolArguments: args,
1117
+ parentSpanId: options.parentSpanId,
1118
+ metadata: options.metadata
1119
+ });
1120
+ try {
1121
+ const result = await fn(args);
1122
+ await this.end(span.id, {
1123
+ status: "completed",
1124
+ toolResult: result
1125
+ });
1126
+ return result;
1127
+ } catch (error) {
1128
+ await this.end(span.id, {
1129
+ status: "error",
1130
+ statusMessage: error instanceof Error ? error.message : String(error)
1131
+ });
1132
+ throw error;
1133
+ }
1134
+ }
1135
+ };
1136
+
1005
1137
  // src/client.ts
1006
1138
  var DEFAULT_BASE_URL = "https://api.synova.cloud";
1007
1139
  var DEFAULT_TIMEOUT = 3e4;
@@ -1022,6 +1154,7 @@ var SynovaCloudSdk = class {
1022
1154
  prompts;
1023
1155
  models;
1024
1156
  files;
1157
+ spans;
1025
1158
  http;
1026
1159
  /**
1027
1160
  * Create a new Synova Cloud SDK client
@@ -1050,6 +1183,7 @@ var SynovaCloudSdk = class {
1050
1183
  this.prompts = new PromptsResource(this.http);
1051
1184
  this.models = new ModelsResource(this.http);
1052
1185
  this.files = new FilesResource(this.http);
1186
+ this.spans = new SpansResource(this.http);
1053
1187
  }
1054
1188
  };
1055
1189