tracia 0.4.0 → 0.4.2

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.mts CHANGED
@@ -64,7 +64,8 @@ declare enum LLMProvider {
64
64
  OPENAI = "openai",
65
65
  ANTHROPIC = "anthropic",
66
66
  GOOGLE = "google",
67
- AMAZON_BEDROCK = "amazon_bedrock"
67
+ AMAZON_BEDROCK = "amazon_bedrock",
68
+ VOYAGE = "voyage"
68
69
  }
69
70
  declare enum SpanKind {
70
71
  ROOT = "ROOT",
@@ -242,7 +243,15 @@ interface ToolCallPart {
242
243
  name: string;
243
244
  arguments: Record<string, unknown>;
244
245
  }
245
- type ContentPart = TextPart | ToolCallPart;
246
+ /**
247
+ * Image part in user messages.
248
+ */
249
+ interface ImagePart {
250
+ type: 'image';
251
+ image: string | Buffer | ArrayBuffer | Uint8Array;
252
+ mimeType?: string;
253
+ }
254
+ type ContentPart = TextPart | ToolCallPart | ImagePart;
246
255
  /**
247
256
  * Message format for LLM conversations.
248
257
  *
@@ -959,4 +968,4 @@ declare class Tracia {
959
968
  private getProviderApiKey;
960
969
  }
961
970
 
962
- export { type ContentPart, type CreatePromptOptions, type CreateSpanPayload, type CreateSpanResult, type CreateTracePayload, type CreateTraceResult, type EmbeddingUsage, type EmbeddingVector, Eval, type EvaluateOptions, type EvaluateResult, type FinishReason, type JsonSchemaProperty, LLMProvider, type ListSpansOptions, type ListSpansResult, type ListTracesOptions, type ListTracesResult, type LocalPromptMessage, type LocalStream, type MessageRole, type Prompt, type PromptListItem, type PromptMessage, type ResponsesEvent, type ResponsesInputItem, type ResponsesOutputItem, type ResponsesStream, type RunEmbeddingInput, type RunEmbeddingResult, type RunLocalInput, type RunLocalResult, type RunOptions, type RunResponsesInput, type RunResponsesResult, type RunResult, type RunVariables, type SessionRunEmbeddingInput, type SessionRunLocalInput, type SessionRunResponsesInput, type Span, SpanKind, type SpanListItem, type SpanStatus, type StreamResult, type TextPart, type TokenUsage, type ToolCall, type ToolCallPart, type ToolChoice, type ToolDefinition, type ToolParameters, type Trace, type TraceListItem, type TraceStatus, Tracia, TraciaError, TraciaErrorCode, type TraciaOptions, TraciaSession, type UpdatePromptOptions };
971
+ export { type ContentPart, type CreatePromptOptions, type CreateSpanPayload, type CreateSpanResult, type CreateTracePayload, type CreateTraceResult, type EmbeddingUsage, type EmbeddingVector, Eval, type EvaluateOptions, type EvaluateResult, type FinishReason, type ImagePart, type JsonSchemaProperty, LLMProvider, type ListSpansOptions, type ListSpansResult, type ListTracesOptions, type ListTracesResult, type LocalPromptMessage, type LocalStream, type MessageRole, type Prompt, type PromptListItem, type PromptMessage, type ResponsesEvent, type ResponsesInputItem, type ResponsesOutputItem, type ResponsesStream, type RunEmbeddingInput, type RunEmbeddingResult, type RunLocalInput, type RunLocalResult, type RunOptions, type RunResponsesInput, type RunResponsesResult, type RunResult, type RunVariables, type SessionRunEmbeddingInput, type SessionRunLocalInput, type SessionRunResponsesInput, type Span, SpanKind, type SpanListItem, type SpanStatus, type StreamResult, type TextPart, type TokenUsage, type ToolCall, type ToolCallPart, type ToolChoice, type ToolDefinition, type ToolParameters, type Trace, type TraceListItem, type TraceStatus, Tracia, TraciaError, TraciaErrorCode, type TraciaOptions, TraciaSession, type UpdatePromptOptions };
package/dist/index.d.ts CHANGED
@@ -64,7 +64,8 @@ declare enum LLMProvider {
64
64
  OPENAI = "openai",
65
65
  ANTHROPIC = "anthropic",
66
66
  GOOGLE = "google",
67
- AMAZON_BEDROCK = "amazon_bedrock"
67
+ AMAZON_BEDROCK = "amazon_bedrock",
68
+ VOYAGE = "voyage"
68
69
  }
69
70
  declare enum SpanKind {
70
71
  ROOT = "ROOT",
@@ -242,7 +243,15 @@ interface ToolCallPart {
242
243
  name: string;
243
244
  arguments: Record<string, unknown>;
244
245
  }
245
- type ContentPart = TextPart | ToolCallPart;
246
+ /**
247
+ * Image part in user messages.
248
+ */
249
+ interface ImagePart {
250
+ type: 'image';
251
+ image: string | Buffer | ArrayBuffer | Uint8Array;
252
+ mimeType?: string;
253
+ }
254
+ type ContentPart = TextPart | ToolCallPart | ImagePart;
246
255
  /**
247
256
  * Message format for LLM conversations.
248
257
  *
@@ -959,4 +968,4 @@ declare class Tracia {
959
968
  private getProviderApiKey;
960
969
  }
961
970
 
962
- export { type ContentPart, type CreatePromptOptions, type CreateSpanPayload, type CreateSpanResult, type CreateTracePayload, type CreateTraceResult, type EmbeddingUsage, type EmbeddingVector, Eval, type EvaluateOptions, type EvaluateResult, type FinishReason, type JsonSchemaProperty, LLMProvider, type ListSpansOptions, type ListSpansResult, type ListTracesOptions, type ListTracesResult, type LocalPromptMessage, type LocalStream, type MessageRole, type Prompt, type PromptListItem, type PromptMessage, type ResponsesEvent, type ResponsesInputItem, type ResponsesOutputItem, type ResponsesStream, type RunEmbeddingInput, type RunEmbeddingResult, type RunLocalInput, type RunLocalResult, type RunOptions, type RunResponsesInput, type RunResponsesResult, type RunResult, type RunVariables, type SessionRunEmbeddingInput, type SessionRunLocalInput, type SessionRunResponsesInput, type Span, SpanKind, type SpanListItem, type SpanStatus, type StreamResult, type TextPart, type TokenUsage, type ToolCall, type ToolCallPart, type ToolChoice, type ToolDefinition, type ToolParameters, type Trace, type TraceListItem, type TraceStatus, Tracia, TraciaError, TraciaErrorCode, type TraciaOptions, TraciaSession, type UpdatePromptOptions };
971
+ export { type ContentPart, type CreatePromptOptions, type CreateSpanPayload, type CreateSpanResult, type CreateTracePayload, type CreateTraceResult, type EmbeddingUsage, type EmbeddingVector, Eval, type EvaluateOptions, type EvaluateResult, type FinishReason, type ImagePart, type JsonSchemaProperty, LLMProvider, type ListSpansOptions, type ListSpansResult, type ListTracesOptions, type ListTracesResult, type LocalPromptMessage, type LocalStream, type MessageRole, type Prompt, type PromptListItem, type PromptMessage, type ResponsesEvent, type ResponsesInputItem, type ResponsesOutputItem, type ResponsesStream, type RunEmbeddingInput, type RunEmbeddingResult, type RunLocalInput, type RunLocalResult, type RunOptions, type RunResponsesInput, type RunResponsesResult, type RunResult, type RunVariables, type SessionRunEmbeddingInput, type SessionRunLocalInput, type SessionRunResponsesInput, type Span, SpanKind, type SpanListItem, type SpanStatus, type StreamResult, type TextPart, type TokenUsage, type ToolCall, type ToolCallPart, type ToolChoice, type ToolDefinition, type ToolParameters, type Trace, type TraceListItem, type TraceStatus, Tracia, TraciaError, TraciaErrorCode, type TraciaOptions, TraciaSession, type UpdatePromptOptions };
package/dist/index.js CHANGED
@@ -74,6 +74,7 @@ var LLMProvider = /* @__PURE__ */ ((LLMProvider2) => {
74
74
  LLMProvider2["ANTHROPIC"] = "anthropic";
75
75
  LLMProvider2["GOOGLE"] = "google";
76
76
  LLMProvider2["AMAZON_BEDROCK"] = "amazon_bedrock";
77
+ LLMProvider2["VOYAGE"] = "voyage";
77
78
  return LLMProvider2;
78
79
  })(LLMProvider || {});
79
80
  var SpanKind = /* @__PURE__ */ ((SpanKind2) => {
@@ -84,7 +85,7 @@ var SpanKind = /* @__PURE__ */ ((SpanKind2) => {
84
85
  })(SpanKind || {});
85
86
 
86
87
  // src/client.ts
87
- var SDK_VERSION = "0.4.0";
88
+ var SDK_VERSION = "0.4.2";
88
89
  var DEFAULT_TIMEOUT_MS = 12e4;
89
90
  function mapApiErrorCodeToTraciaErrorCode(apiCode) {
90
91
  const codeMap = {
@@ -358,7 +359,14 @@ var MODEL_TO_PROVIDER = {
358
359
  "text-embedding-004": "google" /* GOOGLE */,
359
360
  // Amazon Bedrock - Embedding models
360
361
  "amazon.titan-embed-text-v2:0": "amazon_bedrock" /* AMAZON_BEDROCK */,
361
- "cohere.embed-english-v3": "amazon_bedrock" /* AMAZON_BEDROCK */
362
+ "cohere.embed-english-v3": "amazon_bedrock" /* AMAZON_BEDROCK */,
363
+ // Voyage - Embedding models
364
+ "voyage-3": "voyage" /* VOYAGE */,
365
+ "voyage-3-large": "voyage" /* VOYAGE */,
366
+ "voyage-3-lite": "voyage" /* VOYAGE */,
367
+ "voyage-code-3": "voyage" /* VOYAGE */,
368
+ "voyage-finance-2": "voyage" /* VOYAGE */,
369
+ "voyage-law-2": "voyage" /* VOYAGE */
362
370
  };
363
371
  function getProviderForModel(modelId) {
364
372
  return MODEL_TO_PROVIDER[modelId];
@@ -493,6 +501,9 @@ function resolveProvider(model, explicitProvider) {
493
501
  if (model.startsWith("gemini-")) {
494
502
  return "google" /* GOOGLE */;
495
503
  }
504
+ if (model.startsWith("voyage-")) {
505
+ return "voyage" /* VOYAGE */;
506
+ }
496
507
  throw new TraciaError(
497
508
  "UNSUPPORTED_MODEL" /* UNSUPPORTED_MODEL */,
498
509
  `Cannot determine provider for model: ${model}. Specify provider explicitly.`
@@ -521,6 +532,11 @@ async function getLanguageModel(provider, model, apiKey) {
521
532
  const bedrock = createAmazonBedrock({ region });
522
533
  return bedrock(applyBedrockRegionPrefix(model, region));
523
534
  }
535
+ case "voyage" /* VOYAGE */:
536
+ throw new TraciaError(
537
+ "UNSUPPORTED_MODEL" /* UNSUPPORTED_MODEL */,
538
+ "Voyage is an embedding-only provider. Use runEmbedding() instead of runLocal()."
539
+ );
524
540
  default:
525
541
  throw new TraciaError(
526
542
  "UNSUPPORTED_MODEL" /* UNSUPPORTED_MODEL */,
@@ -558,10 +574,44 @@ async function getEmbeddingModel(provider, model, apiKey) {
558
574
  );
559
575
  }
560
576
  }
577
+ async function callVoyageEmbedding(input, model, apiKey, timeoutMs) {
578
+ const response = await fetch("https://api.voyageai.com/v1/embeddings", {
579
+ method: "POST",
580
+ headers: {
581
+ "Content-Type": "application/json",
582
+ Authorization: `Bearer ${apiKey}`
583
+ },
584
+ body: JSON.stringify({ input, model }),
585
+ signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : void 0
586
+ });
587
+ if (!response.ok) {
588
+ const body = await response.text();
589
+ throw new TraciaError(
590
+ "PROVIDER_ERROR" /* PROVIDER_ERROR */,
591
+ `Voyage AI API error ${response.status}: ${sanitizeErrorMessage(body)}`
592
+ );
593
+ }
594
+ const data = await response.json();
595
+ const embeddings = data.data.sort((a, b) => a.index - b.index).map((item) => ({ values: item.embedding, index: item.index }));
596
+ return {
597
+ embeddings,
598
+ totalTokens: data.usage?.total_tokens ?? 0,
599
+ provider: "voyage" /* VOYAGE */
600
+ };
601
+ }
561
602
  async function embedText(options) {
562
603
  const provider = resolveProvider(options.model, options.provider);
563
- const embeddingModel = await getEmbeddingModel(provider, options.model, options.apiKey);
564
604
  const inputs = Array.isArray(options.input) ? options.input : [options.input];
605
+ if (provider === "voyage" /* VOYAGE */) {
606
+ if (options.dimensions) {
607
+ throw new TraciaError(
608
+ "UNSUPPORTED_MODEL" /* UNSUPPORTED_MODEL */,
609
+ "Voyage AI does not support custom embedding dimensions"
610
+ );
611
+ }
612
+ return callVoyageEmbedding(inputs, options.model, options.apiKey, options.timeoutMs);
613
+ }
614
+ const embeddingModel = await getEmbeddingModel(provider, options.model, options.apiKey);
565
615
  try {
566
616
  const { embedMany } = await loadAISdk();
567
617
  const providerOptions = {};
@@ -635,6 +685,22 @@ function convertMessages(messages) {
635
685
  if (typeof msg.content === "string") {
636
686
  return { role, content: msg.content };
637
687
  }
688
+ if (role === "user") {
689
+ return {
690
+ role,
691
+ content: msg.content.map((part) => {
692
+ if (part.type === "image") {
693
+ const imagePart = part;
694
+ return {
695
+ type: "image",
696
+ image: imagePart.image,
697
+ ...imagePart.mimeType && { mimeType: imagePart.mimeType }
698
+ };
699
+ }
700
+ return part;
701
+ })
702
+ };
703
+ }
638
704
  return {
639
705
  role,
640
706
  content: msg.content.map((b) => b.type === "text" ? b.text : "").join("")
@@ -1175,7 +1241,8 @@ var ENV_VAR_MAP = {
1175
1241
  ["openai" /* OPENAI */]: "OPENAI_API_KEY",
1176
1242
  ["anthropic" /* ANTHROPIC */]: "ANTHROPIC_API_KEY",
1177
1243
  ["google" /* GOOGLE */]: "GOOGLE_API_KEY",
1178
- ["amazon_bedrock" /* AMAZON_BEDROCK */]: "BEDROCK_API_KEY"
1244
+ ["amazon_bedrock" /* AMAZON_BEDROCK */]: "BEDROCK_API_KEY",
1245
+ ["voyage" /* VOYAGE */]: "VOYAGE_API_KEY"
1179
1246
  };
1180
1247
  function convertResponsesItemToMessage(item) {
1181
1248
  if ("role" in item && (item.role === "developer" || item.role === "user")) {