@gammatech/aijsx 0.10.0-dev.2024-06-04 → 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
  }
@@ -223,6 +222,7 @@ declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>
223
222
  evaluators?: EvaluatorFn<z.infer<I>, string>[];
224
223
  metadata?: Record<string, any>;
225
224
  }): Prompt<z.infer<I>>;
225
+ declare function isPromptParsed<V extends Record<string, any>>(prompt: Prompt<V>): prompt is PromptParsed<any, any>;
226
226
 
227
227
  declare class ParseVariablesError extends Error {
228
228
  }
@@ -302,4 +302,4 @@ type GoogleChatCompletionProps = {
302
302
  };
303
303
  declare function GoogleChatCompletion(props: GoogleChatCompletionProps, ctx: RenderContext): JSX.Element;
304
304
 
305
- export { AIComponent, AINode, AISpanAttributes, AISpanProcessor, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, AssistantMessage, type ChatCompletionClientAndProvider, ChatCompletionError, type ChatCompletionRequestPayloads, ChatMessage, Context, type CostFn, DebugMessage, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, Fallback, GoogleChatCompletion, type GoogleChatCompletionRequest, GoogleClientContext, LogChatCompletionRequest, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, ParseVariablesError, ProcessedAISpanAttributes, type Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, SystemMessage, type TokenizerFn, Trace, Tracer, UserMessage, type ValidAnthropicChatModel, type ValidGoogleChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, anthropicTokenizer, computeUsage, createPrompt, createRenderContext, evaluatePrompt, openaiTokenizer, tracing };
305
+ export { AIComponent, AINode, AISpanAttributes, AISpanProcessor, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, AssistantMessage, type ChatCompletionClientAndProvider, ChatCompletionError, type ChatCompletionRequestPayloads, ChatMessage, Context, type CostFn, DebugMessage, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, Fallback, GoogleChatCompletion, type GoogleChatCompletionRequest, GoogleClientContext, LogChatCompletionRequest, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, ParseVariablesError, ProcessedAISpanAttributes, type Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, SystemMessage, type TokenizerFn, Trace, Tracer, UserMessage, type ValidAnthropicChatModel, type ValidGoogleChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, anthropicTokenizer, computeUsage, createPrompt, createRenderContext, evaluatePrompt, isPromptParsed, openaiTokenizer, tracing };
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
  }
@@ -223,6 +222,7 @@ declare function createPrompt<K extends string, I extends ZodObject<ZodRawShape>
223
222
  evaluators?: EvaluatorFn<z.infer<I>, string>[];
224
223
  metadata?: Record<string, any>;
225
224
  }): Prompt<z.infer<I>>;
225
+ declare function isPromptParsed<V extends Record<string, any>>(prompt: Prompt<V>): prompt is PromptParsed<any, any>;
226
226
 
227
227
  declare class ParseVariablesError extends Error {
228
228
  }
@@ -302,4 +302,4 @@ type GoogleChatCompletionProps = {
302
302
  };
303
303
  declare function GoogleChatCompletion(props: GoogleChatCompletionProps, ctx: RenderContext): JSX.Element;
304
304
 
305
- export { AIComponent, AINode, AISpanAttributes, AISpanProcessor, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, AssistantMessage, type ChatCompletionClientAndProvider, ChatCompletionError, type ChatCompletionRequestPayloads, ChatMessage, Context, type CostFn, DebugMessage, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, Fallback, GoogleChatCompletion, type GoogleChatCompletionRequest, GoogleClientContext, LogChatCompletionRequest, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, ParseVariablesError, ProcessedAISpanAttributes, type Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, SystemMessage, type TokenizerFn, Trace, Tracer, UserMessage, type ValidAnthropicChatModel, type ValidGoogleChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, anthropicTokenizer, computeUsage, createPrompt, createRenderContext, evaluatePrompt, openaiTokenizer, tracing };
305
+ export { AIComponent, AINode, AISpanAttributes, AISpanProcessor, AnthropicChatCompletion, type AnthropicChatCompletionRequest, AnthropicClientContext, AssistantMessage, type ChatCompletionClientAndProvider, ChatCompletionError, type ChatCompletionRequestPayloads, ChatMessage, Context, type CostFn, DebugMessage, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, Fallback, GoogleChatCompletion, type GoogleChatCompletionRequest, GoogleClientContext, LogChatCompletionRequest, LogImplementation, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, ParseVariablesError, ProcessedAISpanAttributes, type Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, SystemMessage, type TokenizerFn, Trace, Tracer, UserMessage, type ValidAnthropicChatModel, type ValidGoogleChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, anthropicTokenizer, computeUsage, createPrompt, createRenderContext, evaluatePrompt, isPromptParsed, openaiTokenizer, tracing };
package/dist/index.js CHANGED
@@ -66,6 +66,7 @@ __export(src_exports, {
66
66
  createPrompt: () => createPrompt,
67
67
  createRenderContext: () => createRenderContext,
68
68
  evaluatePrompt: () => evaluatePrompt,
69
+ isPromptParsed: () => isPromptParsed2,
69
70
  openaiTokenizer: () => openaiTokenizer,
70
71
  toDebugMessage: () => toDebugMessage,
71
72
  tracing: () => tracing
@@ -1586,7 +1587,6 @@ async function* Fallback({ shouldFallback = () => true, fallback, children }, ct
1586
1587
  // src/tracing/SpanTree.ts
1587
1588
  var SpanTree = class {
1588
1589
  roots = [];
1589
- findSpan;
1590
1590
  addSpan(span) {
1591
1591
  const parentId = span.parentSpanId;
1592
1592
  if (!parentId) {
@@ -1894,6 +1894,9 @@ function createPrompt(config) {
1894
1894
  outputSchema: import_zod.z.string()
1895
1895
  };
1896
1896
  }
1897
+ function isPromptParsed2(prompt) {
1898
+ return "parse" in prompt;
1899
+ }
1897
1900
 
1898
1901
  // src/lib/openai/OpenAI.tsx
1899
1902
  var import_openai2 = require("openai");
@@ -2570,6 +2573,33 @@ var import_sdk2 = __toESM(require("@anthropic-ai/sdk"));
2570
2573
 
2571
2574
  // src/lib/google/Google.tsx
2572
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
2573
2603
  var SAFETY_SETTINGS = [
2574
2604
  {
2575
2605
  category: import_vertexai.HarmCategory.HARM_CATEGORY_HATE_SPEECH,
@@ -2730,20 +2760,7 @@ async function* GoogleChatCompletionInner(props, ctx) {
2730
2760
  try {
2731
2761
  response = await model.generateContentStream(googleCompletionRequest);
2732
2762
  } catch (err) {
2733
- if (err instanceof import_vertexai.GoogleGenerativeAIError) {
2734
- throw new ChatCompletionError(
2735
- err.message,
2736
- logRequestData,
2737
- void 0,
2738
- // always retry on GoogleGenerativeAIError errors, they represent non 4xx error cases
2739
- true
2740
- );
2741
- } else if (err instanceof Error) {
2742
- const status = void 0;
2743
- const retry = false;
2744
- throw new ChatCompletionError(err.message, logRequestData, status, retry);
2745
- }
2746
- throw err;
2763
+ throw errorToChatCompletionError(err, logRequestData);
2747
2764
  }
2748
2765
  let content = "";
2749
2766
  let outputUsage = 0;
@@ -2789,20 +2806,7 @@ async function* GoogleChatCompletionInner(props, ctx) {
2789
2806
  }
2790
2807
  }
2791
2808
  } catch (err) {
2792
- if (err instanceof import_vertexai.GoogleGenerativeAIError) {
2793
- throw new ChatCompletionError(
2794
- err.message,
2795
- logRequestData,
2796
- void 0,
2797
- // always retry these errors they represent non 4xx error cases
2798
- true
2799
- );
2800
- } else if (err instanceof Error) {
2801
- const status = void 0;
2802
- const retry = false;
2803
- throw new ChatCompletionError(err.message, logRequestData, status, retry);
2804
- }
2805
- throw err;
2809
+ throw errorToChatCompletionError(err, logRequestData);
2806
2810
  }
2807
2811
  const outputMessage = {
2808
2812
  role: "assistant",
@@ -2900,6 +2904,7 @@ var import_vertexai2 = require("@google-cloud/vertexai");
2900
2904
  createPrompt,
2901
2905
  createRenderContext,
2902
2906
  evaluatePrompt,
2907
+ isPromptParsed,
2903
2908
  openaiTokenizer,
2904
2909
  toDebugMessage,
2905
2910
  tracing
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) {
@@ -1795,6 +1794,9 @@ function createPrompt(config) {
1795
1794
  outputSchema: z.string()
1796
1795
  };
1797
1796
  }
1797
+ function isPromptParsed2(prompt) {
1798
+ return "parse" in prompt;
1799
+ }
1798
1800
 
1799
1801
  // src/lib/openai/OpenAI.tsx
1800
1802
  import { OpenAI as OpenAIClient2 } from "openai";
@@ -2472,10 +2474,36 @@ import AnthropicClient2 from "@anthropic-ai/sdk";
2472
2474
  // src/lib/google/Google.tsx
2473
2475
  import {
2474
2476
  VertexAI,
2475
- GoogleGenerativeAIError,
2476
2477
  HarmCategory,
2477
2478
  HarmBlockThreshold
2478
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
2479
2507
  var SAFETY_SETTINGS = [
2480
2508
  {
2481
2509
  category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
@@ -2636,20 +2664,7 @@ async function* GoogleChatCompletionInner(props, ctx) {
2636
2664
  try {
2637
2665
  response = await model.generateContentStream(googleCompletionRequest);
2638
2666
  } catch (err) {
2639
- if (err instanceof GoogleGenerativeAIError) {
2640
- throw new ChatCompletionError(
2641
- err.message,
2642
- logRequestData,
2643
- void 0,
2644
- // always retry on GoogleGenerativeAIError errors, they represent non 4xx error cases
2645
- true
2646
- );
2647
- } else if (err instanceof Error) {
2648
- const status = void 0;
2649
- const retry = false;
2650
- throw new ChatCompletionError(err.message, logRequestData, status, retry);
2651
- }
2652
- throw err;
2667
+ throw errorToChatCompletionError(err, logRequestData);
2653
2668
  }
2654
2669
  let content = "";
2655
2670
  let outputUsage = 0;
@@ -2695,20 +2710,7 @@ async function* GoogleChatCompletionInner(props, ctx) {
2695
2710
  }
2696
2711
  }
2697
2712
  } catch (err) {
2698
- if (err instanceof GoogleGenerativeAIError) {
2699
- throw new ChatCompletionError(
2700
- err.message,
2701
- logRequestData,
2702
- void 0,
2703
- // always retry these errors they represent non 4xx error cases
2704
- true
2705
- );
2706
- } else if (err instanceof Error) {
2707
- const status = void 0;
2708
- const retry = false;
2709
- throw new ChatCompletionError(err.message, logRequestData, status, retry);
2710
- }
2711
- throw err;
2713
+ throw errorToChatCompletionError(err, logRequestData);
2712
2714
  }
2713
2715
  const outputMessage = {
2714
2716
  role: "assistant",
@@ -2805,6 +2807,7 @@ export {
2805
2807
  createPrompt,
2806
2808
  createRenderContext,
2807
2809
  evaluatePrompt,
2810
+ isPromptParsed2 as isPromptParsed,
2808
2811
  openaiTokenizer,
2809
2812
  toDebugMessage,
2810
2813
  tracing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gammatech/aijsx",
3
- "version": "0.10.0-dev.2024-06-04",
3
+ "version": "0.10.1-dev.2024-06-07",
4
4
  "description": "Rewrite of aijsx",
5
5
  "author": "Jordan Garcia",
6
6
  "license": "MIT",