@gammatech/aijsx 0.6.3-dev.2024-05-14 → 0.7.0-dev.2024-05-14

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
@@ -27,6 +27,13 @@ type RetryProps = {
27
27
  };
28
28
  declare function Retry({ shouldRetry, retries, maxRetries, children }: RetryProps, ctx: RenderContext): AsyncGenerator<string, void, unknown>;
29
29
 
30
+ type FallbackProps = {
31
+ fallback: AINode;
32
+ shouldFallback: (error: Error) => boolean;
33
+ children: AINode;
34
+ };
35
+ declare function Fallback({ shouldFallback, fallback, children }: FallbackProps, ctx: RenderContext): AsyncGenerator<string, void, unknown>;
36
+
30
37
  declare class AITraceAPI {
31
38
  private static _instance?;
32
39
  private enabled;
@@ -145,7 +152,7 @@ declare module '@gammatech/aijsx' {
145
152
  openai: OpenAIChatCompletionRequest;
146
153
  }
147
154
  }
148
- type ValidOpenAIChatModel = 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo' | 'gpt-4o' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-4-1106-preview' | 'gpt-4-0125-preview' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-16k-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125';
155
+ type ValidOpenAIChatModel = 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-4-1106-preview' | 'gpt-4-0125-preview' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-16k-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125';
149
156
  declare const OpenAIClientContext: Context<() => ChatCompletionClientAndProvider<OpenAI>>;
150
157
  type OpenAIChatCompletionProps = {
151
158
  model: ValidOpenAIChatModel;
@@ -226,4 +233,4 @@ type ClaudeImageBlockUrl = {
226
233
  type ClaudeImageBlockProps = ClaudeImageBlockBase64 | ClaudeImageBlockUrl;
227
234
  declare const ClaudeImageBlock: (props: ClaudeImageBlockProps) => Promise<JSX.Element>;
228
235
 
229
- export { AIComponent, AINode, AISpanProcessor, AnthropicChatCompletion, AnthropicChatCompletionInner, type AnthropicChatCompletionRequest, AnthropicClientContext, ChatCompletionClientAndProvider, ClaudeImageBlock, ContentTypeImage, Context, type CostFn, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, FunctionChain, LogImplementation, NotAsyncGenerator, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, OpenAIVisionChatCompletionInner, ParseVariablesError, Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, StreamChain, Trace, Tracer, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createFunctionChain, createPrompt, createRenderContext, createStreamChain, evaluatePrompt, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer, tracing };
236
+ export { AIComponent, AINode, AISpanProcessor, AnthropicChatCompletion, AnthropicChatCompletionInner, type AnthropicChatCompletionRequest, AnthropicClientContext, ChatCompletionClientAndProvider, ClaudeImageBlock, ContentTypeImage, Context, type CostFn, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, Fallback, FunctionChain, LogImplementation, NotAsyncGenerator, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, OpenAIVisionChatCompletionInner, ParseVariablesError, Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, StreamChain, Trace, Tracer, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createFunctionChain, createPrompt, createRenderContext, createStreamChain, evaluatePrompt, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer, tracing };
package/dist/index.d.ts CHANGED
@@ -27,6 +27,13 @@ type RetryProps = {
27
27
  };
28
28
  declare function Retry({ shouldRetry, retries, maxRetries, children }: RetryProps, ctx: RenderContext): AsyncGenerator<string, void, unknown>;
29
29
 
30
+ type FallbackProps = {
31
+ fallback: AINode;
32
+ shouldFallback: (error: Error) => boolean;
33
+ children: AINode;
34
+ };
35
+ declare function Fallback({ shouldFallback, fallback, children }: FallbackProps, ctx: RenderContext): AsyncGenerator<string, void, unknown>;
36
+
30
37
  declare class AITraceAPI {
31
38
  private static _instance?;
32
39
  private enabled;
@@ -145,7 +152,7 @@ declare module '@gammatech/aijsx' {
145
152
  openai: OpenAIChatCompletionRequest;
146
153
  }
147
154
  }
148
- type ValidOpenAIChatModel = 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo' | 'gpt-4o' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-4-1106-preview' | 'gpt-4-0125-preview' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-16k-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125';
155
+ type ValidOpenAIChatModel = 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-4-1106-preview' | 'gpt-4-0125-preview' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-16k-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125';
149
156
  declare const OpenAIClientContext: Context<() => ChatCompletionClientAndProvider<OpenAI>>;
150
157
  type OpenAIChatCompletionProps = {
151
158
  model: ValidOpenAIChatModel;
@@ -226,4 +233,4 @@ type ClaudeImageBlockUrl = {
226
233
  type ClaudeImageBlockProps = ClaudeImageBlockBase64 | ClaudeImageBlockUrl;
227
234
  declare const ClaudeImageBlock: (props: ClaudeImageBlockProps) => Promise<JSX.Element>;
228
235
 
229
- export { AIComponent, AINode, AISpanProcessor, AnthropicChatCompletion, AnthropicChatCompletionInner, type AnthropicChatCompletionRequest, AnthropicClientContext, ChatCompletionClientAndProvider, ClaudeImageBlock, ContentTypeImage, Context, type CostFn, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, FunctionChain, LogImplementation, NotAsyncGenerator, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, OpenAIVisionChatCompletionInner, ParseVariablesError, Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, StreamChain, Trace, Tracer, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createFunctionChain, createPrompt, createRenderContext, createStreamChain, evaluatePrompt, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer, tracing };
236
+ export { AIComponent, AINode, AISpanProcessor, AnthropicChatCompletion, AnthropicChatCompletionInner, type AnthropicChatCompletionRequest, AnthropicClientContext, ChatCompletionClientAndProvider, ClaudeImageBlock, ContentTypeImage, Context, type CostFn, DefaultMaxRetriesContext, EnrichingSpanProcessor, EvaluatorFn, EvaluatorResult, Fallback, FunctionChain, LogImplementation, NotAsyncGenerator, OpenAIChatCompletion, type OpenAIChatCompletionRequest, type OpenAIChatMessage, OpenAIClientContext, OpenAIVisionChatCompletion, OpenAIVisionChatCompletionInner, ParseVariablesError, Prompt, PromptInvalidOutputError, PromptParsed, ReadableSpan, RenderContext, Retry, RetryCountContext, SpanAttributes, SpanExporter, SpanProcessor, StreamChain, Trace, Tracer, type ValidAnthropicChatModel, type ValidOpenAIChatModel, type ValidOpenAIVisionModel, createFunctionChain, createPrompt, createRenderContext, createStreamChain, evaluatePrompt, tokenCountForOpenAIMessage, tokenCountForOpenAIVisionMessage, tokenLimitForChatModel, tokenizer, tracing };
package/dist/index.js CHANGED
@@ -44,6 +44,7 @@ __export(src_exports, {
44
44
  ContentTypeImage: () => ContentTypeImage,
45
45
  DefaultMaxRetriesContext: () => DefaultMaxRetriesContext,
46
46
  EnrichingSpanProcessor: () => EnrichingSpanProcessor,
47
+ Fallback: () => Fallback,
47
48
  LogImplementation: () => LogImplementation,
48
49
  NoopLogImplementation: () => NoopLogImplementation,
49
50
  OpenAIChatCompletion: () => OpenAIChatCompletion,
@@ -1470,6 +1471,24 @@ async function* Retry({ shouldRetry: shouldRetry4, retries = 0, maxRetries = 3,
1470
1471
  }
1471
1472
  }
1472
1473
 
1474
+ // src/fallback.tsx
1475
+ async function* Fallback({ shouldFallback, fallback, children }, ctx) {
1476
+ const { render } = ctx;
1477
+ let hasYieldedData = false;
1478
+ try {
1479
+ const result = render(children);
1480
+ for await (const value of result) {
1481
+ hasYieldedData = true;
1482
+ yield value;
1483
+ }
1484
+ } catch (e) {
1485
+ if (hasYieldedData || !shouldFallback(e)) {
1486
+ throw e;
1487
+ }
1488
+ yield* render(fallback);
1489
+ }
1490
+ }
1491
+
1473
1492
  // src/prompt/evaluatePrompt.ts
1474
1493
  async function evaluatePrompt(prompt, variables, result) {
1475
1494
  const { error, parsedVariables } = parseVariables(prompt.schema, variables);
@@ -2646,6 +2665,7 @@ var import_tokenizer4 = require("@anthropic-ai/tokenizer");
2646
2665
  ContentTypeImage,
2647
2666
  DefaultMaxRetriesContext,
2648
2667
  EnrichingSpanProcessor,
2668
+ Fallback,
2649
2669
  LogImplementation,
2650
2670
  NoopLogImplementation,
2651
2671
  OpenAIChatCompletion,
package/dist/index.mjs CHANGED
@@ -1367,6 +1367,24 @@ async function* Retry({ shouldRetry: shouldRetry4, retries = 0, maxRetries = 3,
1367
1367
  }
1368
1368
  }
1369
1369
 
1370
+ // src/fallback.tsx
1371
+ async function* Fallback({ shouldFallback, fallback, children }, ctx) {
1372
+ const { render } = ctx;
1373
+ let hasYieldedData = false;
1374
+ try {
1375
+ const result = render(children);
1376
+ for await (const value of result) {
1377
+ hasYieldedData = true;
1378
+ yield value;
1379
+ }
1380
+ } catch (e) {
1381
+ if (hasYieldedData || !shouldFallback(e)) {
1382
+ throw e;
1383
+ }
1384
+ yield* render(fallback);
1385
+ }
1386
+ }
1387
+
1370
1388
  // src/prompt/evaluatePrompt.ts
1371
1389
  async function evaluatePrompt(prompt, variables, result) {
1372
1390
  const { error, parsedVariables } = parseVariables(prompt.schema, variables);
@@ -2542,6 +2560,7 @@ export {
2542
2560
  ContentTypeImage,
2543
2561
  DefaultMaxRetriesContext,
2544
2562
  EnrichingSpanProcessor,
2563
+ Fallback,
2545
2564
  LogImplementation,
2546
2565
  NoopLogImplementation,
2547
2566
  OpenAIChatCompletion,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gammatech/aijsx",
3
- "version": "0.6.3-dev.2024-05-14",
3
+ "version": "0.7.0-dev.2024-05-14",
4
4
  "description": "Rewrite of aijsx",
5
5
  "author": "Jordan Garcia",
6
6
  "license": "MIT",