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.mjs CHANGED
@@ -32,6 +32,7 @@ var LLMProvider = /* @__PURE__ */ ((LLMProvider2) => {
32
32
  LLMProvider2["ANTHROPIC"] = "anthropic";
33
33
  LLMProvider2["GOOGLE"] = "google";
34
34
  LLMProvider2["AMAZON_BEDROCK"] = "amazon_bedrock";
35
+ LLMProvider2["VOYAGE"] = "voyage";
35
36
  return LLMProvider2;
36
37
  })(LLMProvider || {});
37
38
  var SpanKind = /* @__PURE__ */ ((SpanKind2) => {
@@ -42,7 +43,7 @@ var SpanKind = /* @__PURE__ */ ((SpanKind2) => {
42
43
  })(SpanKind || {});
43
44
 
44
45
  // src/client.ts
45
- var SDK_VERSION = "0.4.0";
46
+ var SDK_VERSION = "0.4.2";
46
47
  var DEFAULT_TIMEOUT_MS = 12e4;
47
48
  function mapApiErrorCodeToTraciaErrorCode(apiCode) {
48
49
  const codeMap = {
@@ -316,7 +317,14 @@ var MODEL_TO_PROVIDER = {
316
317
  "text-embedding-004": "google" /* GOOGLE */,
317
318
  // Amazon Bedrock - Embedding models
318
319
  "amazon.titan-embed-text-v2:0": "amazon_bedrock" /* AMAZON_BEDROCK */,
319
- "cohere.embed-english-v3": "amazon_bedrock" /* AMAZON_BEDROCK */
320
+ "cohere.embed-english-v3": "amazon_bedrock" /* AMAZON_BEDROCK */,
321
+ // Voyage - Embedding models
322
+ "voyage-3": "voyage" /* VOYAGE */,
323
+ "voyage-3-large": "voyage" /* VOYAGE */,
324
+ "voyage-3-lite": "voyage" /* VOYAGE */,
325
+ "voyage-code-3": "voyage" /* VOYAGE */,
326
+ "voyage-finance-2": "voyage" /* VOYAGE */,
327
+ "voyage-law-2": "voyage" /* VOYAGE */
320
328
  };
321
329
  function getProviderForModel(modelId) {
322
330
  return MODEL_TO_PROVIDER[modelId];
@@ -451,6 +459,9 @@ function resolveProvider(model, explicitProvider) {
451
459
  if (model.startsWith("gemini-")) {
452
460
  return "google" /* GOOGLE */;
453
461
  }
462
+ if (model.startsWith("voyage-")) {
463
+ return "voyage" /* VOYAGE */;
464
+ }
454
465
  throw new TraciaError(
455
466
  "UNSUPPORTED_MODEL" /* UNSUPPORTED_MODEL */,
456
467
  `Cannot determine provider for model: ${model}. Specify provider explicitly.`
@@ -479,6 +490,11 @@ async function getLanguageModel(provider, model, apiKey) {
479
490
  const bedrock = createAmazonBedrock({ region });
480
491
  return bedrock(applyBedrockRegionPrefix(model, region));
481
492
  }
493
+ case "voyage" /* VOYAGE */:
494
+ throw new TraciaError(
495
+ "UNSUPPORTED_MODEL" /* UNSUPPORTED_MODEL */,
496
+ "Voyage is an embedding-only provider. Use runEmbedding() instead of runLocal()."
497
+ );
482
498
  default:
483
499
  throw new TraciaError(
484
500
  "UNSUPPORTED_MODEL" /* UNSUPPORTED_MODEL */,
@@ -516,10 +532,44 @@ async function getEmbeddingModel(provider, model, apiKey) {
516
532
  );
517
533
  }
518
534
  }
535
+ async function callVoyageEmbedding(input, model, apiKey, timeoutMs) {
536
+ const response = await fetch("https://api.voyageai.com/v1/embeddings", {
537
+ method: "POST",
538
+ headers: {
539
+ "Content-Type": "application/json",
540
+ Authorization: `Bearer ${apiKey}`
541
+ },
542
+ body: JSON.stringify({ input, model }),
543
+ signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : void 0
544
+ });
545
+ if (!response.ok) {
546
+ const body = await response.text();
547
+ throw new TraciaError(
548
+ "PROVIDER_ERROR" /* PROVIDER_ERROR */,
549
+ `Voyage AI API error ${response.status}: ${sanitizeErrorMessage(body)}`
550
+ );
551
+ }
552
+ const data = await response.json();
553
+ const embeddings = data.data.sort((a, b) => a.index - b.index).map((item) => ({ values: item.embedding, index: item.index }));
554
+ return {
555
+ embeddings,
556
+ totalTokens: data.usage?.total_tokens ?? 0,
557
+ provider: "voyage" /* VOYAGE */
558
+ };
559
+ }
519
560
  async function embedText(options) {
520
561
  const provider = resolveProvider(options.model, options.provider);
521
- const embeddingModel = await getEmbeddingModel(provider, options.model, options.apiKey);
522
562
  const inputs = Array.isArray(options.input) ? options.input : [options.input];
563
+ if (provider === "voyage" /* VOYAGE */) {
564
+ if (options.dimensions) {
565
+ throw new TraciaError(
566
+ "UNSUPPORTED_MODEL" /* UNSUPPORTED_MODEL */,
567
+ "Voyage AI does not support custom embedding dimensions"
568
+ );
569
+ }
570
+ return callVoyageEmbedding(inputs, options.model, options.apiKey, options.timeoutMs);
571
+ }
572
+ const embeddingModel = await getEmbeddingModel(provider, options.model, options.apiKey);
523
573
  try {
524
574
  const { embedMany } = await loadAISdk();
525
575
  const providerOptions = {};
@@ -593,6 +643,22 @@ function convertMessages(messages) {
593
643
  if (typeof msg.content === "string") {
594
644
  return { role, content: msg.content };
595
645
  }
646
+ if (role === "user") {
647
+ return {
648
+ role,
649
+ content: msg.content.map((part) => {
650
+ if (part.type === "image") {
651
+ const imagePart = part;
652
+ return {
653
+ type: "image",
654
+ image: imagePart.image,
655
+ ...imagePart.mimeType && { mimeType: imagePart.mimeType }
656
+ };
657
+ }
658
+ return part;
659
+ })
660
+ };
661
+ }
596
662
  return {
597
663
  role,
598
664
  content: msg.content.map((b) => b.type === "text" ? b.text : "").join("")
@@ -1133,7 +1199,8 @@ var ENV_VAR_MAP = {
1133
1199
  ["openai" /* OPENAI */]: "OPENAI_API_KEY",
1134
1200
  ["anthropic" /* ANTHROPIC */]: "ANTHROPIC_API_KEY",
1135
1201
  ["google" /* GOOGLE */]: "GOOGLE_API_KEY",
1136
- ["amazon_bedrock" /* AMAZON_BEDROCK */]: "BEDROCK_API_KEY"
1202
+ ["amazon_bedrock" /* AMAZON_BEDROCK */]: "BEDROCK_API_KEY",
1203
+ ["voyage" /* VOYAGE */]: "VOYAGE_API_KEY"
1137
1204
  };
1138
1205
  function convertResponsesItemToMessage(item) {
1139
1206
  if ("role" in item && (item.role === "developer" || item.role === "user")) {