@gammatech/aijsx 0.6.1-dev.2024-04-17 → 0.6.2-dev.2024-05-02
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +52 -13
- package/dist/index.mjs +52 -13
- package/dist/{jsx-dev-runtime-n4ojN2eR.d.mts → jsx-dev-runtime-6M25UAsb.d.mts} +2 -1
- package/dist/{jsx-dev-runtime-n4ojN2eR.d.ts → jsx-dev-runtime-6M25UAsb.d.ts} +2 -1
- package/dist/jsx-dev-runtime.d.mts +1 -1
- package/dist/jsx-dev-runtime.d.ts +1 -1
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as RenderContext, L as LogImplementation, S as SpanProcessor, C as ContextValues, a as Context, A as AINode, T as Tracer, b as ReadableSpan, c as SpanExporter, d as AIComponent, e as SpanAttributes, E as EvaluatorFn, P as PromptParsed, f as Prompt, N as NotAsyncGenerator, F as FunctionChain, g as StreamChain, h as EvaluatorResult, i as ChatCompletionClientAndProvider, J as JSX } from './jsx-dev-runtime-
|
|
2
|
-
export { I as AIElement, k as AIFragment, o as AssistantMessage, B as BoundLogger, r as ChatCompletionError, s as ChatCompletionRequestPayloads, m as ChatCompletionRole, z as CombinedLogger, y as ConsoleLogger, D as Literal, t as LogChatCompletionRequest, u as LogChatCompletionResponse, v as LogLevel, w as Logger, x as NoopLogImplementation, _ as OutputParser, M as PropsOfAIComponent, G as RenderResult, K as Renderable, p as RenderedConversationMessage, V as Span, O as SpanContext, W as SpanEvent, Q as SpanStatus, n as SystemMessage, Y as TracingContext, X as TracingContextKey, Z as TracingContextManager, U as UserMessage, H as attachedContextSymbol, q as computeUsage, j as createAIElement, l as createContext } from './jsx-dev-runtime-
|
|
1
|
+
import { R as RenderContext, L as LogImplementation, S as SpanProcessor, C as ContextValues, a as Context, A as AINode, T as Tracer, b as ReadableSpan, c as SpanExporter, d as AIComponent, e as SpanAttributes, E as EvaluatorFn, P as PromptParsed, f as Prompt, N as NotAsyncGenerator, F as FunctionChain, g as StreamChain, h as EvaluatorResult, i as ChatCompletionClientAndProvider, J as JSX } from './jsx-dev-runtime-6M25UAsb.mjs';
|
|
2
|
+
export { I as AIElement, k as AIFragment, o as AssistantMessage, B as BoundLogger, r as ChatCompletionError, s as ChatCompletionRequestPayloads, m as ChatCompletionRole, z as CombinedLogger, y as ConsoleLogger, D as Literal, t as LogChatCompletionRequest, u as LogChatCompletionResponse, v as LogLevel, w as Logger, x as NoopLogImplementation, _ as OutputParser, M as PropsOfAIComponent, G as RenderResult, K as Renderable, p as RenderedConversationMessage, V as Span, O as SpanContext, W as SpanEvent, Q as SpanStatus, n as SystemMessage, Y as TracingContext, X as TracingContextKey, Z as TracingContextManager, U as UserMessage, H as attachedContextSymbol, q as computeUsage, j as createAIElement, l as createContext } from './jsx-dev-runtime-6M25UAsb.mjs';
|
|
3
3
|
import { ZodObject, ZodRawShape, ZodTypeAny, ZodString, z } from 'zod';
|
|
4
4
|
import { OpenAI } from 'openai';
|
|
5
5
|
export { OpenAI as OpenAIClient } from 'openai';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as RenderContext, L as LogImplementation, S as SpanProcessor, C as ContextValues, a as Context, A as AINode, T as Tracer, b as ReadableSpan, c as SpanExporter, d as AIComponent, e as SpanAttributes, E as EvaluatorFn, P as PromptParsed, f as Prompt, N as NotAsyncGenerator, F as FunctionChain, g as StreamChain, h as EvaluatorResult, i as ChatCompletionClientAndProvider, J as JSX } from './jsx-dev-runtime-
|
|
2
|
-
export { I as AIElement, k as AIFragment, o as AssistantMessage, B as BoundLogger, r as ChatCompletionError, s as ChatCompletionRequestPayloads, m as ChatCompletionRole, z as CombinedLogger, y as ConsoleLogger, D as Literal, t as LogChatCompletionRequest, u as LogChatCompletionResponse, v as LogLevel, w as Logger, x as NoopLogImplementation, _ as OutputParser, M as PropsOfAIComponent, G as RenderResult, K as Renderable, p as RenderedConversationMessage, V as Span, O as SpanContext, W as SpanEvent, Q as SpanStatus, n as SystemMessage, Y as TracingContext, X as TracingContextKey, Z as TracingContextManager, U as UserMessage, H as attachedContextSymbol, q as computeUsage, j as createAIElement, l as createContext } from './jsx-dev-runtime-
|
|
1
|
+
import { R as RenderContext, L as LogImplementation, S as SpanProcessor, C as ContextValues, a as Context, A as AINode, T as Tracer, b as ReadableSpan, c as SpanExporter, d as AIComponent, e as SpanAttributes, E as EvaluatorFn, P as PromptParsed, f as Prompt, N as NotAsyncGenerator, F as FunctionChain, g as StreamChain, h as EvaluatorResult, i as ChatCompletionClientAndProvider, J as JSX } from './jsx-dev-runtime-6M25UAsb.js';
|
|
2
|
+
export { I as AIElement, k as AIFragment, o as AssistantMessage, B as BoundLogger, r as ChatCompletionError, s as ChatCompletionRequestPayloads, m as ChatCompletionRole, z as CombinedLogger, y as ConsoleLogger, D as Literal, t as LogChatCompletionRequest, u as LogChatCompletionResponse, v as LogLevel, w as Logger, x as NoopLogImplementation, _ as OutputParser, M as PropsOfAIComponent, G as RenderResult, K as Renderable, p as RenderedConversationMessage, V as Span, O as SpanContext, W as SpanEvent, Q as SpanStatus, n as SystemMessage, Y as TracingContext, X as TracingContextKey, Z as TracingContextManager, U as UserMessage, H as attachedContextSymbol, q as computeUsage, j as createAIElement, l as createContext } from './jsx-dev-runtime-6M25UAsb.js';
|
|
3
3
|
import { ZodObject, ZodRawShape, ZodTypeAny, ZodString, z } from 'zod';
|
|
4
4
|
import { OpenAI } from 'openai';
|
|
5
5
|
export { OpenAI as OpenAIClient } from 'openai';
|
package/dist/index.js
CHANGED
|
@@ -96,9 +96,10 @@ var computeUsage = (messages) => {
|
|
|
96
96
|
};
|
|
97
97
|
};
|
|
98
98
|
var ChatCompletionError = class extends Error {
|
|
99
|
-
constructor(message, chatCompletionRequest, shouldRetry4 = false) {
|
|
99
|
+
constructor(message, chatCompletionRequest, status, shouldRetry4 = false) {
|
|
100
100
|
super(message);
|
|
101
101
|
this.chatCompletionRequest = chatCompletionRequest;
|
|
102
|
+
this.status = status;
|
|
102
103
|
this.shouldRetry = shouldRetry4;
|
|
103
104
|
}
|
|
104
105
|
name = "ChatCompletionError";
|
|
@@ -1929,10 +1930,16 @@ async function* OpenAIChatCompletionInner(props, { logger, render, tracer, getCo
|
|
|
1929
1930
|
throw new ChatCompletionError(
|
|
1930
1931
|
`OpenAIClient.APIError: ${ex.message}`,
|
|
1931
1932
|
logRequestData,
|
|
1933
|
+
ex.status,
|
|
1932
1934
|
retry
|
|
1933
1935
|
);
|
|
1934
1936
|
} else if (ex instanceof Error) {
|
|
1935
|
-
throw new ChatCompletionError(
|
|
1937
|
+
throw new ChatCompletionError(
|
|
1938
|
+
ex.message,
|
|
1939
|
+
logRequestData,
|
|
1940
|
+
void 0,
|
|
1941
|
+
retry
|
|
1942
|
+
);
|
|
1936
1943
|
}
|
|
1937
1944
|
throw ex;
|
|
1938
1945
|
}
|
|
@@ -2157,10 +2164,16 @@ async function* OpenAIVisionChatCompletionInner(props, { logger, render, tracer,
|
|
|
2157
2164
|
throw new ChatCompletionError(
|
|
2158
2165
|
`OpenAIClient.APIError: ${ex.message}`,
|
|
2159
2166
|
logRequestData,
|
|
2167
|
+
ex.status,
|
|
2160
2168
|
retry
|
|
2161
2169
|
);
|
|
2162
2170
|
} else if (ex instanceof Error) {
|
|
2163
|
-
throw new ChatCompletionError(
|
|
2171
|
+
throw new ChatCompletionError(
|
|
2172
|
+
ex.message,
|
|
2173
|
+
logRequestData,
|
|
2174
|
+
void 0,
|
|
2175
|
+
retry
|
|
2176
|
+
);
|
|
2164
2177
|
}
|
|
2165
2178
|
throw ex;
|
|
2166
2179
|
}
|
|
@@ -2329,6 +2342,33 @@ function buildAnthropicMessages(childrenXml) {
|
|
|
2329
2342
|
var shouldRetry3 = (error) => {
|
|
2330
2343
|
return error instanceof ChatCompletionError && error.shouldRetry;
|
|
2331
2344
|
};
|
|
2345
|
+
var RE_INTERNAL_SERVER_MESSASGE = /The system encountered an unexpected error during processing/i;
|
|
2346
|
+
var RE_RATE_LIMIT_MESSAGE = /Too many requests, please wait before trying again/;
|
|
2347
|
+
var extractStatusFromError = (error) => {
|
|
2348
|
+
if (typeof error !== "object" || !(error instanceof Error)) {
|
|
2349
|
+
return;
|
|
2350
|
+
}
|
|
2351
|
+
if (error instanceof import_sdk.default.APIError && typeof error.status === "number") {
|
|
2352
|
+
return error.status;
|
|
2353
|
+
}
|
|
2354
|
+
const causeName = error.cause?.name;
|
|
2355
|
+
if (causeName === "ValidationException") {
|
|
2356
|
+
return 400;
|
|
2357
|
+
} else if (causeName === "InternalServerException") {
|
|
2358
|
+
return 500;
|
|
2359
|
+
} else if (causeName === "ModelStreamErrorException") {
|
|
2360
|
+
return 424;
|
|
2361
|
+
} else if (causeName === "ThrottlingException") {
|
|
2362
|
+
return 429;
|
|
2363
|
+
}
|
|
2364
|
+
if (RE_INTERNAL_SERVER_MESSASGE.test(error.message)) {
|
|
2365
|
+
return 500;
|
|
2366
|
+
}
|
|
2367
|
+
if (RE_RATE_LIMIT_MESSAGE.test(error.message)) {
|
|
2368
|
+
return 429;
|
|
2369
|
+
}
|
|
2370
|
+
return void 0;
|
|
2371
|
+
};
|
|
2332
2372
|
function AnthropicChatCompletion(props, ctx) {
|
|
2333
2373
|
const defaultMaxRetries = ctx.getContext(DefaultMaxRetriesContext);
|
|
2334
2374
|
return /* @__PURE__ */ jsx(
|
|
@@ -2407,10 +2447,15 @@ async function* AnthropicChatCompletionInner(props, { render, logger, tracer, ge
|
|
|
2407
2447
|
throw new ChatCompletionError(
|
|
2408
2448
|
`AnthropicClient.APIError: ${err.message}`,
|
|
2409
2449
|
logRequestData,
|
|
2450
|
+
extractStatusFromError(err),
|
|
2410
2451
|
retry
|
|
2411
2452
|
);
|
|
2412
2453
|
} else if (err instanceof Error) {
|
|
2413
|
-
throw new ChatCompletionError(
|
|
2454
|
+
throw new ChatCompletionError(
|
|
2455
|
+
err.message,
|
|
2456
|
+
logRequestData,
|
|
2457
|
+
extractStatusFromError(err)
|
|
2458
|
+
);
|
|
2414
2459
|
}
|
|
2415
2460
|
throw err;
|
|
2416
2461
|
}
|
|
@@ -2434,15 +2479,9 @@ async function* AnthropicChatCompletionInner(props, { render, logger, tracer, ge
|
|
|
2434
2479
|
}
|
|
2435
2480
|
}
|
|
2436
2481
|
} catch (e) {
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
const isValidationExceptionAnthropic = e?.error?.error?.type === "invalid_request_error";
|
|
2441
|
-
retry = !isValidationExceptionAWS && !isValidationExceptionAnthropic;
|
|
2442
|
-
} catch (inner) {
|
|
2443
|
-
console.error(inner);
|
|
2444
|
-
}
|
|
2445
|
-
throw new ChatCompletionError(e.message, logRequestData, retry);
|
|
2482
|
+
const status = extractStatusFromError(e);
|
|
2483
|
+
const retry = status === 429 || status === 500;
|
|
2484
|
+
throw new ChatCompletionError(e.message, logRequestData, status, retry);
|
|
2446
2485
|
}
|
|
2447
2486
|
const outputMessage = {
|
|
2448
2487
|
role: "assistant",
|
package/dist/index.mjs
CHANGED
|
@@ -26,9 +26,10 @@ var computeUsage = (messages) => {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
var ChatCompletionError = class extends Error {
|
|
29
|
-
constructor(message, chatCompletionRequest, shouldRetry4 = false) {
|
|
29
|
+
constructor(message, chatCompletionRequest, status, shouldRetry4 = false) {
|
|
30
30
|
super(message);
|
|
31
31
|
this.chatCompletionRequest = chatCompletionRequest;
|
|
32
|
+
this.status = status;
|
|
32
33
|
this.shouldRetry = shouldRetry4;
|
|
33
34
|
}
|
|
34
35
|
name = "ChatCompletionError";
|
|
@@ -1826,10 +1827,16 @@ async function* OpenAIChatCompletionInner(props, { logger, render, tracer, getCo
|
|
|
1826
1827
|
throw new ChatCompletionError(
|
|
1827
1828
|
`OpenAIClient.APIError: ${ex.message}`,
|
|
1828
1829
|
logRequestData,
|
|
1830
|
+
ex.status,
|
|
1829
1831
|
retry
|
|
1830
1832
|
);
|
|
1831
1833
|
} else if (ex instanceof Error) {
|
|
1832
|
-
throw new ChatCompletionError(
|
|
1834
|
+
throw new ChatCompletionError(
|
|
1835
|
+
ex.message,
|
|
1836
|
+
logRequestData,
|
|
1837
|
+
void 0,
|
|
1838
|
+
retry
|
|
1839
|
+
);
|
|
1833
1840
|
}
|
|
1834
1841
|
throw ex;
|
|
1835
1842
|
}
|
|
@@ -2054,10 +2061,16 @@ async function* OpenAIVisionChatCompletionInner(props, { logger, render, tracer,
|
|
|
2054
2061
|
throw new ChatCompletionError(
|
|
2055
2062
|
`OpenAIClient.APIError: ${ex.message}`,
|
|
2056
2063
|
logRequestData,
|
|
2064
|
+
ex.status,
|
|
2057
2065
|
retry
|
|
2058
2066
|
);
|
|
2059
2067
|
} else if (ex instanceof Error) {
|
|
2060
|
-
throw new ChatCompletionError(
|
|
2068
|
+
throw new ChatCompletionError(
|
|
2069
|
+
ex.message,
|
|
2070
|
+
logRequestData,
|
|
2071
|
+
void 0,
|
|
2072
|
+
retry
|
|
2073
|
+
);
|
|
2061
2074
|
}
|
|
2062
2075
|
throw ex;
|
|
2063
2076
|
}
|
|
@@ -2226,6 +2239,33 @@ function buildAnthropicMessages(childrenXml) {
|
|
|
2226
2239
|
var shouldRetry3 = (error) => {
|
|
2227
2240
|
return error instanceof ChatCompletionError && error.shouldRetry;
|
|
2228
2241
|
};
|
|
2242
|
+
var RE_INTERNAL_SERVER_MESSASGE = /The system encountered an unexpected error during processing/i;
|
|
2243
|
+
var RE_RATE_LIMIT_MESSAGE = /Too many requests, please wait before trying again/;
|
|
2244
|
+
var extractStatusFromError = (error) => {
|
|
2245
|
+
if (typeof error !== "object" || !(error instanceof Error)) {
|
|
2246
|
+
return;
|
|
2247
|
+
}
|
|
2248
|
+
if (error instanceof AnthropicClient.APIError && typeof error.status === "number") {
|
|
2249
|
+
return error.status;
|
|
2250
|
+
}
|
|
2251
|
+
const causeName = error.cause?.name;
|
|
2252
|
+
if (causeName === "ValidationException") {
|
|
2253
|
+
return 400;
|
|
2254
|
+
} else if (causeName === "InternalServerException") {
|
|
2255
|
+
return 500;
|
|
2256
|
+
} else if (causeName === "ModelStreamErrorException") {
|
|
2257
|
+
return 424;
|
|
2258
|
+
} else if (causeName === "ThrottlingException") {
|
|
2259
|
+
return 429;
|
|
2260
|
+
}
|
|
2261
|
+
if (RE_INTERNAL_SERVER_MESSASGE.test(error.message)) {
|
|
2262
|
+
return 500;
|
|
2263
|
+
}
|
|
2264
|
+
if (RE_RATE_LIMIT_MESSAGE.test(error.message)) {
|
|
2265
|
+
return 429;
|
|
2266
|
+
}
|
|
2267
|
+
return void 0;
|
|
2268
|
+
};
|
|
2229
2269
|
function AnthropicChatCompletion(props, ctx) {
|
|
2230
2270
|
const defaultMaxRetries = ctx.getContext(DefaultMaxRetriesContext);
|
|
2231
2271
|
return /* @__PURE__ */ jsx(
|
|
@@ -2304,10 +2344,15 @@ async function* AnthropicChatCompletionInner(props, { render, logger, tracer, ge
|
|
|
2304
2344
|
throw new ChatCompletionError(
|
|
2305
2345
|
`AnthropicClient.APIError: ${err.message}`,
|
|
2306
2346
|
logRequestData,
|
|
2347
|
+
extractStatusFromError(err),
|
|
2307
2348
|
retry
|
|
2308
2349
|
);
|
|
2309
2350
|
} else if (err instanceof Error) {
|
|
2310
|
-
throw new ChatCompletionError(
|
|
2351
|
+
throw new ChatCompletionError(
|
|
2352
|
+
err.message,
|
|
2353
|
+
logRequestData,
|
|
2354
|
+
extractStatusFromError(err)
|
|
2355
|
+
);
|
|
2311
2356
|
}
|
|
2312
2357
|
throw err;
|
|
2313
2358
|
}
|
|
@@ -2331,15 +2376,9 @@ async function* AnthropicChatCompletionInner(props, { render, logger, tracer, ge
|
|
|
2331
2376
|
}
|
|
2332
2377
|
}
|
|
2333
2378
|
} catch (e) {
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
const isValidationExceptionAnthropic = e?.error?.error?.type === "invalid_request_error";
|
|
2338
|
-
retry = !isValidationExceptionAWS && !isValidationExceptionAnthropic;
|
|
2339
|
-
} catch (inner) {
|
|
2340
|
-
console.error(inner);
|
|
2341
|
-
}
|
|
2342
|
-
throw new ChatCompletionError(e.message, logRequestData, retry);
|
|
2379
|
+
const status = extractStatusFromError(e);
|
|
2380
|
+
const retry = status === 429 || status === 500;
|
|
2381
|
+
throw new ChatCompletionError(e.message, logRequestData, status, retry);
|
|
2343
2382
|
}
|
|
2344
2383
|
const outputMessage = {
|
|
2345
2384
|
role: "assistant",
|
|
@@ -314,9 +314,10 @@ declare const computeUsage: (messages: RenderedConversationMessage[]) => {
|
|
|
314
314
|
};
|
|
315
315
|
declare class ChatCompletionError extends Error {
|
|
316
316
|
readonly chatCompletionRequest: LogChatCompletionRequest;
|
|
317
|
+
readonly status: number | undefined;
|
|
317
318
|
readonly shouldRetry: boolean;
|
|
318
319
|
readonly name = "ChatCompletionError";
|
|
319
|
-
constructor(message: string, chatCompletionRequest: LogChatCompletionRequest, shouldRetry?: boolean);
|
|
320
|
+
constructor(message: string, chatCompletionRequest: LogChatCompletionRequest, status: number | undefined, shouldRetry?: boolean);
|
|
320
321
|
}
|
|
321
322
|
|
|
322
323
|
declare function createAIElement<P extends {
|
|
@@ -314,9 +314,10 @@ declare const computeUsage: (messages: RenderedConversationMessage[]) => {
|
|
|
314
314
|
};
|
|
315
315
|
declare class ChatCompletionError extends Error {
|
|
316
316
|
readonly chatCompletionRequest: LogChatCompletionRequest;
|
|
317
|
+
readonly status: number | undefined;
|
|
317
318
|
readonly shouldRetry: boolean;
|
|
318
319
|
readonly name = "ChatCompletionError";
|
|
319
|
-
constructor(message: string, chatCompletionRequest: LogChatCompletionRequest, shouldRetry?: boolean);
|
|
320
|
+
constructor(message: string, chatCompletionRequest: LogChatCompletionRequest, status: number | undefined, shouldRetry?: boolean);
|
|
320
321
|
}
|
|
321
322
|
|
|
322
323
|
declare function createAIElement<P extends {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { a2 as Fragment, J as JSX, $ as jsx, a0 as jsxDEV, a1 as jsxs } from './jsx-dev-runtime-
|
|
1
|
+
export { a2 as Fragment, J as JSX, $ as jsx, a0 as jsxDEV, a1 as jsxs } from './jsx-dev-runtime-6M25UAsb.mjs';
|
|
2
2
|
import 'zod';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { a2 as Fragment, J as JSX, $ as jsx, a0 as jsxDEV, a1 as jsxs } from './jsx-dev-runtime-
|
|
1
|
+
export { a2 as Fragment, J as JSX, $ as jsx, a0 as jsxDEV, a1 as jsxs } from './jsx-dev-runtime-6M25UAsb.js';
|
|
2
2
|
import 'zod';
|
package/dist/jsx-runtime.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { a2 as Fragment, J as JSX, $ as jsx, a0 as jsxDEV, a1 as jsxs } from './jsx-dev-runtime-
|
|
1
|
+
export { a2 as Fragment, J as JSX, $ as jsx, a0 as jsxDEV, a1 as jsxs } from './jsx-dev-runtime-6M25UAsb.mjs';
|
|
2
2
|
import 'zod';
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { a2 as Fragment, J as JSX, $ as jsx, a0 as jsxDEV, a1 as jsxs } from './jsx-dev-runtime-
|
|
1
|
+
export { a2 as Fragment, J as JSX, $ as jsx, a0 as jsxDEV, a1 as jsxs } from './jsx-dev-runtime-6M25UAsb.js';
|
|
2
2
|
import 'zod';
|