@gammatech/aijsx 0.10.0-dev.2024-06-04.2 → 0.10.1-dev.2024-06-07

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
@@ -87,7 +87,6 @@ declare const tracing: AITraceAPI;
87
87
 
88
88
  declare class SpanTree {
89
89
  roots: SpanTreeNode[];
90
- findSpan: any;
91
90
  addSpan(span: ReadableSpan): boolean;
92
91
  findNode(id: string): SpanTreeNode | null;
93
92
  }
package/dist/index.d.ts CHANGED
@@ -87,7 +87,6 @@ declare const tracing: AITraceAPI;
87
87
 
88
88
  declare class SpanTree {
89
89
  roots: SpanTreeNode[];
90
- findSpan: any;
91
90
  addSpan(span: ReadableSpan): boolean;
92
91
  findNode(id: string): SpanTreeNode | null;
93
92
  }
package/dist/index.js CHANGED
@@ -1587,7 +1587,6 @@ async function* Fallback({ shouldFallback = () => true, fallback, children }, ct
1587
1587
  // src/tracing/SpanTree.ts
1588
1588
  var SpanTree = class {
1589
1589
  roots = [];
1590
- findSpan;
1591
1590
  addSpan(span) {
1592
1591
  const parentId = span.parentSpanId;
1593
1592
  if (!parentId) {
@@ -2574,6 +2573,33 @@ var import_sdk2 = __toESM(require("@anthropic-ai/sdk"));
2574
2573
 
2575
2574
  // src/lib/google/Google.tsx
2576
2575
  var import_vertexai = require("@google-cloud/vertexai");
2576
+
2577
+ // src/lib/google/errors.ts
2578
+ var extractStatusFromMessage = (message) => {
2579
+ const RE_STATUS = /status: (\d{3})/;
2580
+ const matchStatus = message.match(RE_STATUS);
2581
+ if (matchStatus !== null) {
2582
+ return parseInt(matchStatus[1]);
2583
+ }
2584
+ const RE_GOOGLE_GENERATIVE_AI_ERROR = /\[VertexAI.GoogleGenerativeAIError\]/;
2585
+ const matchErrorName = message.match(RE_GOOGLE_GENERATIVE_AI_ERROR);
2586
+ if (matchErrorName !== null) {
2587
+ return 500;
2588
+ }
2589
+ return 500;
2590
+ };
2591
+ var errorToChatCompletionError = (error, requestData) => {
2592
+ const status = extractStatusFromMessage(error.message);
2593
+ const shouldRetry4 = status !== 400;
2594
+ return new ChatCompletionError(
2595
+ error.message,
2596
+ requestData,
2597
+ status,
2598
+ shouldRetry4
2599
+ );
2600
+ };
2601
+
2602
+ // src/lib/google/Google.tsx
2577
2603
  var SAFETY_SETTINGS = [
2578
2604
  {
2579
2605
  category: import_vertexai.HarmCategory.HARM_CATEGORY_HATE_SPEECH,
@@ -2734,20 +2760,7 @@ async function* GoogleChatCompletionInner(props, ctx) {
2734
2760
  try {
2735
2761
  response = await model.generateContentStream(googleCompletionRequest);
2736
2762
  } catch (err) {
2737
- if (err instanceof import_vertexai.GoogleGenerativeAIError) {
2738
- throw new ChatCompletionError(
2739
- err.message,
2740
- logRequestData,
2741
- void 0,
2742
- // always retry on GoogleGenerativeAIError errors, they represent non 4xx error cases
2743
- true
2744
- );
2745
- } else if (err instanceof Error) {
2746
- const status = void 0;
2747
- const retry = false;
2748
- throw new ChatCompletionError(err.message, logRequestData, status, retry);
2749
- }
2750
- throw err;
2763
+ throw errorToChatCompletionError(err, logRequestData);
2751
2764
  }
2752
2765
  let content = "";
2753
2766
  let outputUsage = 0;
@@ -2793,20 +2806,7 @@ async function* GoogleChatCompletionInner(props, ctx) {
2793
2806
  }
2794
2807
  }
2795
2808
  } catch (err) {
2796
- if (err instanceof import_vertexai.GoogleGenerativeAIError) {
2797
- throw new ChatCompletionError(
2798
- err.message,
2799
- logRequestData,
2800
- void 0,
2801
- // always retry these errors they represent non 4xx error cases
2802
- true
2803
- );
2804
- } else if (err instanceof Error) {
2805
- const status = void 0;
2806
- const retry = false;
2807
- throw new ChatCompletionError(err.message, logRequestData, status, retry);
2808
- }
2809
- throw err;
2809
+ throw errorToChatCompletionError(err, logRequestData);
2810
2810
  }
2811
2811
  const outputMessage = {
2812
2812
  role: "assistant",
package/dist/index.mjs CHANGED
@@ -1487,7 +1487,6 @@ async function* Fallback({ shouldFallback = () => true, fallback, children }, ct
1487
1487
  // src/tracing/SpanTree.ts
1488
1488
  var SpanTree = class {
1489
1489
  roots = [];
1490
- findSpan;
1491
1490
  addSpan(span) {
1492
1491
  const parentId = span.parentSpanId;
1493
1492
  if (!parentId) {
@@ -2475,10 +2474,36 @@ import AnthropicClient2 from "@anthropic-ai/sdk";
2475
2474
  // src/lib/google/Google.tsx
2476
2475
  import {
2477
2476
  VertexAI,
2478
- GoogleGenerativeAIError,
2479
2477
  HarmCategory,
2480
2478
  HarmBlockThreshold
2481
2479
  } from "@google-cloud/vertexai";
2480
+
2481
+ // src/lib/google/errors.ts
2482
+ var extractStatusFromMessage = (message) => {
2483
+ const RE_STATUS = /status: (\d{3})/;
2484
+ const matchStatus = message.match(RE_STATUS);
2485
+ if (matchStatus !== null) {
2486
+ return parseInt(matchStatus[1]);
2487
+ }
2488
+ const RE_GOOGLE_GENERATIVE_AI_ERROR = /\[VertexAI.GoogleGenerativeAIError\]/;
2489
+ const matchErrorName = message.match(RE_GOOGLE_GENERATIVE_AI_ERROR);
2490
+ if (matchErrorName !== null) {
2491
+ return 500;
2492
+ }
2493
+ return 500;
2494
+ };
2495
+ var errorToChatCompletionError = (error, requestData) => {
2496
+ const status = extractStatusFromMessage(error.message);
2497
+ const shouldRetry4 = status !== 400;
2498
+ return new ChatCompletionError(
2499
+ error.message,
2500
+ requestData,
2501
+ status,
2502
+ shouldRetry4
2503
+ );
2504
+ };
2505
+
2506
+ // src/lib/google/Google.tsx
2482
2507
  var SAFETY_SETTINGS = [
2483
2508
  {
2484
2509
  category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
@@ -2639,20 +2664,7 @@ async function* GoogleChatCompletionInner(props, ctx) {
2639
2664
  try {
2640
2665
  response = await model.generateContentStream(googleCompletionRequest);
2641
2666
  } catch (err) {
2642
- if (err instanceof GoogleGenerativeAIError) {
2643
- throw new ChatCompletionError(
2644
- err.message,
2645
- logRequestData,
2646
- void 0,
2647
- // always retry on GoogleGenerativeAIError errors, they represent non 4xx error cases
2648
- true
2649
- );
2650
- } else if (err instanceof Error) {
2651
- const status = void 0;
2652
- const retry = false;
2653
- throw new ChatCompletionError(err.message, logRequestData, status, retry);
2654
- }
2655
- throw err;
2667
+ throw errorToChatCompletionError(err, logRequestData);
2656
2668
  }
2657
2669
  let content = "";
2658
2670
  let outputUsage = 0;
@@ -2698,20 +2710,7 @@ async function* GoogleChatCompletionInner(props, ctx) {
2698
2710
  }
2699
2711
  }
2700
2712
  } catch (err) {
2701
- if (err instanceof GoogleGenerativeAIError) {
2702
- throw new ChatCompletionError(
2703
- err.message,
2704
- logRequestData,
2705
- void 0,
2706
- // always retry these errors they represent non 4xx error cases
2707
- true
2708
- );
2709
- } else if (err instanceof Error) {
2710
- const status = void 0;
2711
- const retry = false;
2712
- throw new ChatCompletionError(err.message, logRequestData, status, retry);
2713
- }
2714
- throw err;
2713
+ throw errorToChatCompletionError(err, logRequestData);
2715
2714
  }
2716
2715
  const outputMessage = {
2717
2716
  role: "assistant",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gammatech/aijsx",
3
- "version": "0.10.0-dev.2024-06-04.2",
3
+ "version": "0.10.1-dev.2024-06-07",
4
4
  "description": "Rewrite of aijsx",
5
5
  "author": "Jordan Garcia",
6
6
  "license": "MIT",