@opencode/ai 0.0.0-beta-19275
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/README.md +682 -0
- package/dist/cache-policy.d.ts +2 -0
- package/dist/cache-policy.js +129 -0
- package/dist/image-client.d.ts +19 -0
- package/dist/image-client.js +28 -0
- package/dist/image.d.ts +110 -0
- package/dist/image.js +103 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +12 -0
- package/dist/llm.d.ts +252 -0
- package/dist/llm.js +74 -0
- package/dist/protocols/anthropic-messages.d.ts +957 -0
- package/dist/protocols/anthropic-messages.js +1414 -0
- package/dist/protocols/bedrock-converse.d.ts +499 -0
- package/dist/protocols/bedrock-converse.js +643 -0
- package/dist/protocols/bedrock-event-stream.d.ts +9 -0
- package/dist/protocols/bedrock-event-stream.js +97 -0
- package/dist/protocols/gemini.d.ts +285 -0
- package/dist/protocols/gemini.js +671 -0
- package/dist/protocols/google-images.d.ts +30 -0
- package/dist/protocols/google-images.js +181 -0
- package/dist/protocols/index.d.ts +12 -0
- package/dist/protocols/index.js +12 -0
- package/dist/protocols/meta-images.d.ts +26 -0
- package/dist/protocols/meta-images.js +89 -0
- package/dist/protocols/meta-messages.d.ts +350 -0
- package/dist/protocols/meta-messages.js +41 -0
- package/dist/protocols/meta-responses.d.ts +473 -0
- package/dist/protocols/meta-responses.js +173 -0
- package/dist/protocols/mistral-chat.d.ts +540 -0
- package/dist/protocols/mistral-chat.js +624 -0
- package/dist/protocols/open-responses-channel.d.ts +23 -0
- package/dist/protocols/open-responses-channel.js +141 -0
- package/dist/protocols/open-responses-continuation.d.ts +12 -0
- package/dist/protocols/open-responses-continuation.js +161 -0
- package/dist/protocols/open-responses.d.ts +1583 -0
- package/dist/protocols/open-responses.js +1206 -0
- package/dist/protocols/openai-chat.d.ts +860 -0
- package/dist/protocols/openai-chat.js +966 -0
- package/dist/protocols/openai-compatible-chat.d.ts +109 -0
- package/dist/protocols/openai-compatible-chat.js +19 -0
- package/dist/protocols/openai-compatible-responses.d.ts +172 -0
- package/dist/protocols/openai-compatible-responses.js +18 -0
- package/dist/protocols/openai-images.d.ts +32 -0
- package/dist/protocols/openai-images.js +183 -0
- package/dist/protocols/openai-responses.d.ts +1389 -0
- package/dist/protocols/openai-responses.js +260 -0
- package/dist/protocols/shared.d.ts +193 -0
- package/dist/protocols/shared.js +290 -0
- package/dist/protocols/utils/bedrock-auth.d.ts +60 -0
- package/dist/protocols/utils/bedrock-auth.js +85 -0
- package/dist/protocols/utils/bedrock-cache.d.ts +19 -0
- package/dist/protocols/utils/bedrock-cache.js +49 -0
- package/dist/protocols/utils/bedrock-media.d.ts +55 -0
- package/dist/protocols/utils/bedrock-media.js +73 -0
- package/dist/protocols/utils/cache.d.ts +6 -0
- package/dist/protocols/utils/cache.js +5 -0
- package/dist/protocols/utils/gemini-tool-schema.d.ts +2 -0
- package/dist/protocols/utils/gemini-tool-schema.js +103 -0
- package/dist/protocols/utils/image-input.d.ts +21 -0
- package/dist/protocols/utils/image-input.js +20 -0
- package/dist/protocols/utils/lifecycle.d.ts +24 -0
- package/dist/protocols/utils/lifecycle.js +72 -0
- package/dist/protocols/utils/meta-image.d.ts +2 -0
- package/dist/protocols/utils/meta-image.js +13 -0
- package/dist/protocols/utils/open-responses-options.d.ts +56 -0
- package/dist/protocols/utils/open-responses-options.js +61 -0
- package/dist/protocols/utils/openai-image.d.ts +5 -0
- package/dist/protocols/utils/openai-image.js +18 -0
- package/dist/protocols/utils/openai-options.d.ts +16 -0
- package/dist/protocols/utils/openai-options.js +14 -0
- package/dist/protocols/utils/partial-json-options.d.ts +62 -0
- package/dist/protocols/utils/partial-json-options.js +52 -0
- package/dist/protocols/utils/partial-json.d.ts +8 -0
- package/dist/protocols/utils/partial-json.js +279 -0
- package/dist/protocols/utils/responses-checkpoint.d.ts +4 -0
- package/dist/protocols/utils/responses-checkpoint.js +107 -0
- package/dist/protocols/utils/responses-compaction.d.ts +4 -0
- package/dist/protocols/utils/responses-compaction.js +129 -0
- package/dist/protocols/utils/responses-hosted-tools.d.ts +26 -0
- package/dist/protocols/utils/responses-hosted-tools.js +32 -0
- package/dist/protocols/utils/tool-schema.d.ts +8 -0
- package/dist/protocols/utils/tool-schema.js +54 -0
- package/dist/protocols/utils/tool-stream.d.ts +710 -0
- package/dist/protocols/utils/tool-stream.js +155 -0
- package/dist/protocols/xai-images.d.ts +26 -0
- package/dist/protocols/xai-images.js +106 -0
- package/dist/protocols/xai-responses.d.ts +250 -0
- package/dist/protocols/xai-responses.js +81 -0
- package/dist/protocols/zai-images.d.ts +22 -0
- package/dist/protocols/zai-images.js +79 -0
- package/dist/protocols.d.ts +1 -0
- package/dist/protocols.js +1 -0
- package/dist/provider-error.d.ts +15 -0
- package/dist/provider-error.js +125 -0
- package/dist/provider-package.d.ts +11 -0
- package/dist/provider-package.js +1 -0
- package/dist/provider.d.ts +23 -0
- package/dist/provider.js +2 -0
- package/dist/providers/amazon-bedrock/mantle/chat.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle/chat.js +1 -0
- package/dist/providers/amazon-bedrock/mantle/responses.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle/responses.js +1 -0
- package/dist/providers/amazon-bedrock/mantle.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle.js +1 -0
- package/dist/providers/amazon-bedrock-mantle.d.ts +371 -0
- package/dist/providers/amazon-bedrock-mantle.js +76 -0
- package/dist/providers/amazon-bedrock.d.ts +173 -0
- package/dist/providers/amazon-bedrock.js +41 -0
- package/dist/providers/anthropic-compatible.d.ts +304 -0
- package/dist/providers/anthropic-compatible.js +44 -0
- package/dist/providers/anthropic.d.ts +302 -0
- package/dist/providers/anthropic.js +39 -0
- package/dist/providers/azure/chat.d.ts +2 -0
- package/dist/providers/azure/chat.js +1 -0
- package/dist/providers/azure/responses.d.ts +2 -0
- package/dist/providers/azure/responses.js +1 -0
- package/dist/providers/azure.d.ts +599 -0
- package/dist/providers/azure.js +115 -0
- package/dist/providers/baseten.d.ts +229 -0
- package/dist/providers/baseten.js +38 -0
- package/dist/providers/cerebras.d.ts +228 -0
- package/dist/providers/cerebras.js +40 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +238 -0
- package/dist/providers/cloudflare-ai-gateway.js +59 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +232 -0
- package/dist/providers/cloudflare-workers-ai.js +45 -0
- package/dist/providers/deepinfra.d.ts +228 -0
- package/dist/providers/deepinfra.js +43 -0
- package/dist/providers/deepseek.d.ts +229 -0
- package/dist/providers/deepseek.js +41 -0
- package/dist/providers/fireworks.d.ts +229 -0
- package/dist/providers/fireworks.js +38 -0
- package/dist/providers/google-vertex/chat.d.ts +2 -0
- package/dist/providers/google-vertex/chat.js +1 -0
- package/dist/providers/google-vertex/gemini.d.ts +2 -0
- package/dist/providers/google-vertex/gemini.js +1 -0
- package/dist/providers/google-vertex/messages.d.ts +2 -0
- package/dist/providers/google-vertex/messages.js +1 -0
- package/dist/providers/google-vertex/responses.d.ts +2 -0
- package/dist/providers/google-vertex/responses.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +133 -0
- package/dist/providers/google-vertex-chat.js +55 -0
- package/dist/providers/google-vertex-messages.d.ts +301 -0
- package/dist/providers/google-vertex-messages.js +75 -0
- package/dist/providers/google-vertex-responses.d.ts +198 -0
- package/dist/providers/google-vertex-responses.js +56 -0
- package/dist/providers/google-vertex-shared.d.ts +22 -0
- package/dist/providers/google-vertex-shared.js +61 -0
- package/dist/providers/google-vertex.d.ts +120 -0
- package/dist/providers/google-vertex.js +92 -0
- package/dist/providers/google.d.ts +115 -0
- package/dist/providers/google.js +42 -0
- package/dist/providers/groq.d.ts +315 -0
- package/dist/providers/groq.js +81 -0
- package/dist/providers/index.d.ts +28 -0
- package/dist/providers/index.js +28 -0
- package/dist/providers/meta/chat.d.ts +2 -0
- package/dist/providers/meta/chat.js +1 -0
- package/dist/providers/meta/messages.d.ts +2 -0
- package/dist/providers/meta/messages.js +1 -0
- package/dist/providers/meta/responses.d.ts +2 -0
- package/dist/providers/meta/responses.js +1 -0
- package/dist/providers/meta.d.ts +631 -0
- package/dist/providers/meta.js +113 -0
- package/dist/providers/minimax/chat.d.ts +4 -0
- package/dist/providers/minimax/chat.js +8 -0
- package/dist/providers/minimax/messages.d.ts +1 -0
- package/dist/providers/minimax/messages.js +1 -0
- package/dist/providers/minimax/responses.d.ts +4 -0
- package/dist/providers/minimax/responses.js +8 -0
- package/dist/providers/minimax.d.ts +593 -0
- package/dist/providers/minimax.js +89 -0
- package/dist/providers/mistral.d.ts +208 -0
- package/dist/providers/mistral.js +28 -0
- package/dist/providers/open-responses-options.d.ts +6 -0
- package/dist/providers/open-responses-options.js +1 -0
- package/dist/providers/openai/chat.d.ts +2 -0
- package/dist/providers/openai/chat.js +1 -0
- package/dist/providers/openai/responses.d.ts +2 -0
- package/dist/providers/openai/responses.js +1 -0
- package/dist/providers/openai-compatible/responses.d.ts +1 -0
- package/dist/providers/openai-compatible/responses.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +196 -0
- package/dist/providers/openai-compatible-responses.js +32 -0
- package/dist/providers/openai-compatible.d.ts +131 -0
- package/dist/providers/openai-compatible.js +33 -0
- package/dist/providers/openai-options.d.ts +26 -0
- package/dist/providers/openai-options.js +41 -0
- package/dist/providers/openai.d.ts +405 -0
- package/dist/providers/openai.js +82 -0
- package/dist/providers/openrouter.d.ts +564 -0
- package/dist/providers/openrouter.js +114 -0
- package/dist/providers/togetherai.d.ts +228 -0
- package/dist/providers/togetherai.js +40 -0
- package/dist/providers/xai.d.ts +164 -0
- package/dist/providers/xai.js +84 -0
- package/dist/providers/zai.d.ts +24 -0
- package/dist/providers/zai.js +21 -0
- package/dist/providers.d.ts +1 -0
- package/dist/providers.js +1 -0
- package/dist/route/auth-options.d.ts +34 -0
- package/dist/route/auth-options.js +14 -0
- package/dist/route/auth.d.ts +51 -0
- package/dist/route/auth.js +87 -0
- package/dist/route/client.d.ts +430 -0
- package/dist/route/client.js +304 -0
- package/dist/route/endpoint.d.ts +28 -0
- package/dist/route/endpoint.js +21 -0
- package/dist/route/executor.d.ts +27 -0
- package/dist/route/executor.js +183 -0
- package/dist/route/framing.d.ts +29 -0
- package/dist/route/framing.js +14 -0
- package/dist/route/index.d.ts +16 -0
- package/dist/route/index.js +9 -0
- package/dist/route/protocol.d.ts +76 -0
- package/dist/route/protocol.js +16 -0
- package/dist/route/transport/http.d.ts +34 -0
- package/dist/route/transport/http.js +68 -0
- package/dist/route/transport/index.d.ts +41 -0
- package/dist/route/transport/index.js +4 -0
- package/dist/route/transport/websocket-channel.d.ts +57 -0
- package/dist/route/transport/websocket-channel.js +1 -0
- package/dist/route/transport/websocket.d.ts +56 -0
- package/dist/route/transport/websocket.js +366 -0
- package/dist/route.d.ts +1 -0
- package/dist/route.js +1 -0
- package/dist/schema/errors.d.ts +158 -0
- package/dist/schema/errors.js +120 -0
- package/dist/schema/events.d.ts +8123 -0
- package/dist/schema/events.js +550 -0
- package/dist/schema/ids.d.ts +17 -0
- package/dist/schema/ids.js +10 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/messages.d.ts +646 -0
- package/dist/schema/messages.js +301 -0
- package/dist/schema/options.d.ts +157 -0
- package/dist/schema/options.js +187 -0
- package/dist/testing.d.ts +1693 -0
- package/dist/testing.js +129 -0
- package/dist/tool-history.d.ts +2 -0
- package/dist/tool-history.js +84 -0
- package/dist/tool-runtime.d.ts +15 -0
- package/dist/tool-runtime.js +62 -0
- package/dist/tool.d.ts +136 -0
- package/dist/tool.js +66 -0
- package/dist/utils/record.d.ts +2 -0
- package/dist/utils/record.js +2 -0
- package/dist/utils/sanitize.d.ts +1 -0
- package/dist/utils/sanitize.js +12 -0
- package/package.json +48 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Headers, HttpClientRequest } from "effect/unstable/http";
|
|
3
|
+
import { GeneratedImage, ImageModel, ImageResponse } from "../image.js";
|
|
4
|
+
import { Auth } from "../route/auth.js";
|
|
5
|
+
import { mergeHttpOptions, mergeJsonRecords } from "../schema/index.js";
|
|
6
|
+
import { ProviderShared } from "./shared.js";
|
|
7
|
+
import { ImageInputs } from "./utils/image-input.js";
|
|
8
|
+
const ADAPTER = "zai-images";
|
|
9
|
+
export const DEFAULT_BASE_URL = "https://api.z.ai/api/paas/v4";
|
|
10
|
+
export const PATH = "/images/generations";
|
|
11
|
+
const ZAIImageResponse = Schema.Struct({
|
|
12
|
+
created: Schema.optional(Schema.Int),
|
|
13
|
+
id: Schema.optional(Schema.String),
|
|
14
|
+
request_id: Schema.optional(Schema.String),
|
|
15
|
+
data: Schema.Array(Schema.Struct({ url: Schema.String })),
|
|
16
|
+
content_filter: Schema.optional(Schema.Array(Schema.Struct({
|
|
17
|
+
role: Schema.optional(Schema.String),
|
|
18
|
+
level: Schema.optional(Schema.Number),
|
|
19
|
+
}))),
|
|
20
|
+
});
|
|
21
|
+
const nativeOptions = (options) => {
|
|
22
|
+
if (!options)
|
|
23
|
+
return undefined;
|
|
24
|
+
const { userID, ...native } = options;
|
|
25
|
+
return {
|
|
26
|
+
user_id: userID,
|
|
27
|
+
...native,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const applyQuery = (url, query) => {
|
|
31
|
+
if (!query)
|
|
32
|
+
return url;
|
|
33
|
+
const next = new URL(url);
|
|
34
|
+
Object.entries(query).forEach(([key, value]) => next.searchParams.set(key, value));
|
|
35
|
+
return next.toString();
|
|
36
|
+
};
|
|
37
|
+
export const model = (input) => {
|
|
38
|
+
const route = {
|
|
39
|
+
id: ADAPTER,
|
|
40
|
+
generate: Effect.fn("ZAIImages.generate")(function* (request, execute) {
|
|
41
|
+
if ((request.images?.length ?? 0) > 0)
|
|
42
|
+
return yield* ImageInputs.invalid("Z.ai hosted image generation does not support image inputs");
|
|
43
|
+
const http = mergeHttpOptions(request.model.http, request.http);
|
|
44
|
+
const requestBody = mergeJsonRecords({ model: request.model.id, prompt: request.prompt }, nativeOptions(request.options), http?.body);
|
|
45
|
+
const text = ProviderShared.encodeJson(requestBody);
|
|
46
|
+
const url = applyQuery(`${(input.baseURL ?? DEFAULT_BASE_URL).replace(/\/$/, "")}${PATH}`, http?.query);
|
|
47
|
+
const headers = yield* Auth.toEffect(input.auth)({
|
|
48
|
+
request,
|
|
49
|
+
method: "POST",
|
|
50
|
+
url,
|
|
51
|
+
body: text,
|
|
52
|
+
headers: Headers.fromInput({ ...input.headers, ...http?.headers }),
|
|
53
|
+
});
|
|
54
|
+
const response = yield* execute(HttpClientRequest.post(url).pipe(HttpClientRequest.setHeaders(headers), HttpClientRequest.bodyText(text, "application/json")));
|
|
55
|
+
const output = yield* ProviderShared.imageResponse(ADAPTER, "Z.ai Images", response);
|
|
56
|
+
const decoded = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(ZAIImageResponse))(output.body).pipe(Effect.mapError((cause) => output.invalid("Z.ai Images returned an invalid response", cause)));
|
|
57
|
+
if (decoded.data.length === 0)
|
|
58
|
+
return yield* output.invalid("Z.ai Images returned no images");
|
|
59
|
+
return new ImageResponse({
|
|
60
|
+
images: decoded.data.map((item) => new GeneratedImage({
|
|
61
|
+
mediaType: "application/octet-stream",
|
|
62
|
+
data: item.url,
|
|
63
|
+
})),
|
|
64
|
+
providerMetadata: {
|
|
65
|
+
zai: {
|
|
66
|
+
created: decoded.created,
|
|
67
|
+
id: decoded.id,
|
|
68
|
+
requestID: decoded.request_id,
|
|
69
|
+
contentFilter: decoded.content_filter,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}),
|
|
74
|
+
};
|
|
75
|
+
return ImageModel.make({ id: input.id, provider: "zai", route, http: input.http });
|
|
76
|
+
};
|
|
77
|
+
export const ZAIImages = {
|
|
78
|
+
model,
|
|
79
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./protocols/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./protocols/index.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AIError, type HttpContext, type HttpRateLimitDetails } from "./schema/index.js";
|
|
2
|
+
export declare const isContextOverflow: (message: string) => boolean;
|
|
3
|
+
export declare const isPayloadTooLarge: (message: string) => boolean;
|
|
4
|
+
export declare const isContextOverflowFailure: (failure: unknown) => boolean;
|
|
5
|
+
export interface ProviderFailure {
|
|
6
|
+
readonly message: string;
|
|
7
|
+
readonly status?: number | undefined;
|
|
8
|
+
readonly rawBody?: string | undefined;
|
|
9
|
+
readonly data?: unknown;
|
|
10
|
+
readonly http?: HttpContext | undefined;
|
|
11
|
+
readonly cause?: unknown;
|
|
12
|
+
readonly retryAfterMs?: number | undefined;
|
|
13
|
+
readonly rateLimit?: HttpRateLimitDetails | undefined;
|
|
14
|
+
}
|
|
15
|
+
export declare function classifyProviderFailure(input: ProviderFailure): AIError["reason"];
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Option, Schema } from "effect";
|
|
2
|
+
import { AuthenticationError, ContentPolicyError, InvalidRequestError, AIError, ProviderErrorEvent, ProviderInternalError, QuotaExceededError, RateLimitError, UnknownProviderError, } from "./schema/index.js";
|
|
3
|
+
const patterns = [
|
|
4
|
+
/prompt is too long/i,
|
|
5
|
+
/input is too long for requested model/i,
|
|
6
|
+
/exceeds the context window/i,
|
|
7
|
+
/exceeds (?:the )?(?:model'?s )?maximum context length(?: of [\d,]+ tokens?|\s*\([\d,]+\))/i,
|
|
8
|
+
/input token count.*exceeds the maximum/i,
|
|
9
|
+
/tokens in request more than max tokens allowed/i,
|
|
10
|
+
/maximum prompt length is \d+/i,
|
|
11
|
+
/reduce the length of the messages/i,
|
|
12
|
+
/maximum context length is \d+ tokens/i,
|
|
13
|
+
/exceeds (?:the )?maximum allowed input length of [\d,]+ tokens?/i,
|
|
14
|
+
/input \(\d+ tokens\) is longer than the model'?s context length \(\d+ tokens\)/i,
|
|
15
|
+
/exceeds the limit of \d+/i,
|
|
16
|
+
/exceeds the available context size/i,
|
|
17
|
+
/greater than the context length/i,
|
|
18
|
+
/context window exceeds limit/i,
|
|
19
|
+
/exceeded model token limit/i,
|
|
20
|
+
/context[_ ]length[_ ]exceeded/i,
|
|
21
|
+
/context length is only \d+ tokens/i,
|
|
22
|
+
/input length.*exceeds.*context length/i,
|
|
23
|
+
/prompt too long; exceeded (?:max )?context length/i,
|
|
24
|
+
/too large for model with \d+ maximum context length/i,
|
|
25
|
+
/prompt has [\d,]+ tokens?, but the configured context size is [\d,]+ tokens?/i,
|
|
26
|
+
/model_context_window_exceeded/i,
|
|
27
|
+
/range of input length should be/i,
|
|
28
|
+
/too many tokens/i,
|
|
29
|
+
/token limit exceeded/i,
|
|
30
|
+
/request_too_large/i,
|
|
31
|
+
];
|
|
32
|
+
const payloadPatterns = [/request entity too large/i, /payload too large/i, /request too large/i];
|
|
33
|
+
const exclusions = [/^(throttling error|service unavailable):/i, /rate limit/i, /too many requests/i];
|
|
34
|
+
export const isContextOverflow = (message) => !exclusions.some((pattern) => pattern.test(message)) &&
|
|
35
|
+
(patterns.some((pattern) => pattern.test(message)) || /^4(?:00|13)\s*(status code)?\s*\(no body\)/i.test(message));
|
|
36
|
+
export const isPayloadTooLarge = (message) => payloadPatterns.some((pattern) => pattern.test(message));
|
|
37
|
+
export const isContextOverflowFailure = (failure) => failure instanceof AIError
|
|
38
|
+
? failure.reason._tag === "InvalidRequest" && failure.reason.classification === "context-overflow"
|
|
39
|
+
: Schema.is(ProviderErrorEvent)(failure) && failure.classification === "context-overflow";
|
|
40
|
+
const decodeJson = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
|
|
41
|
+
const QUOTA_CODES = new Set(["insufficient_quota", "usage_not_included", "billing_error"]);
|
|
42
|
+
const AUTH_CODES = new Set(["authentication_error", "permission_error"]);
|
|
43
|
+
const SERVER_CODES = new Set([
|
|
44
|
+
"api_error",
|
|
45
|
+
"internal_error",
|
|
46
|
+
"internalserverexception",
|
|
47
|
+
"modelstreamerrorexception",
|
|
48
|
+
"overloaded_error",
|
|
49
|
+
"server_error",
|
|
50
|
+
"server_is_overloaded",
|
|
51
|
+
"slow_down",
|
|
52
|
+
"serviceunavailableexception",
|
|
53
|
+
]);
|
|
54
|
+
const INVALID_REQUEST_CODES = new Set(["invalid_prompt", "invalid_request_error", "validationexception"]);
|
|
55
|
+
const RATE_LIMIT_TEXT = /rate increased too quickly|rate[-_\s]?limit|too[_\s]?many[_\s]?requests/i;
|
|
56
|
+
const QUOTA_TEXT = /insufficient[-_\s]?quota|quota[-_\s]?exceeded/i;
|
|
57
|
+
const CONTENT_POLICY_TEXT = /content[-_\s]?policy|content_filter|safety/i;
|
|
58
|
+
const SERVER_ERROR_TEXT = /\b(?:try again|(?:please |you can )?retry (?:the |this |your )?request|try (?:the |this |your )?request again|(?:currently |temporarily )?at capacity|overloaded|temporarily unavailable|service[-_\s]?unavailable|(?:server|internal)[-_\s]?error|server (?:is )?busy|provider returned (?:an )?error|resource[-_\s]?exhausted|upstream (?:connect|connection|request)|request buffer limit while retrying upstream)\b/i;
|
|
59
|
+
// Classification records affirmative evidence about a failure. Deterministic
|
|
60
|
+
// failures need positive identification (a 4xx status, quota/auth/policy
|
|
61
|
+
// signals); anything unrecognized stays UnknownProvider, which the session
|
|
62
|
+
// retry policy treats as retry-eligible because transient failures arrive in
|
|
63
|
+
// unpredictable shapes while deterministic rejections almost always carry a
|
|
64
|
+
// status or known code.
|
|
65
|
+
export function classifyProviderFailure(input) {
|
|
66
|
+
const details = { message: input.message, body: input.rawBody, http: input.http, cause: input.cause };
|
|
67
|
+
const body = input.rawBody ?? "";
|
|
68
|
+
const codes = [...providerCodes(input.data), ...providerCodes(body), ...providerCodes(input.message)].map((code) => code.toLowerCase());
|
|
69
|
+
// Scan the raw payload too so signals missing from the summary message
|
|
70
|
+
// (e.g. overflow phrases nested in a JSON error body) still classify.
|
|
71
|
+
const text = [input.message, body].filter((value) => value.length > 0).join("\n");
|
|
72
|
+
const clientScoped = input.status === undefined || (input.status >= 400 && input.status < 500);
|
|
73
|
+
if (clientScoped &&
|
|
74
|
+
(codes.includes("context_length_exceeded") ||
|
|
75
|
+
codes.includes("model_context_window_exceeded") ||
|
|
76
|
+
codes.includes("request_too_large") ||
|
|
77
|
+
isContextOverflow(text)))
|
|
78
|
+
return new InvalidRequestError({ ...details, classification: "context-overflow" });
|
|
79
|
+
if (input.status === 413 || isPayloadTooLarge(text))
|
|
80
|
+
return new InvalidRequestError({ ...details, classification: "payload-too-large" });
|
|
81
|
+
if (CONTENT_POLICY_TEXT.test(text))
|
|
82
|
+
return new ContentPolicyError(details);
|
|
83
|
+
if (codes.some((code) => QUOTA_CODES.has(code)) || (input.status === 429 && QUOTA_TEXT.test(text)))
|
|
84
|
+
return new QuotaExceededError(details);
|
|
85
|
+
if (input.status === 401 || input.status === 403 || codes.some((code) => AUTH_CODES.has(code)))
|
|
86
|
+
return new AuthenticationError(details);
|
|
87
|
+
if (input.status === 429 ||
|
|
88
|
+
codes.some((code) => code.includes("rate_limit") || code === "too_many_requests" || code === "throttlingexception") ||
|
|
89
|
+
RATE_LIMIT_TEXT.test(text))
|
|
90
|
+
return new RateLimitError({
|
|
91
|
+
...details,
|
|
92
|
+
retryAfterMs: input.retryAfterMs,
|
|
93
|
+
rateLimit: input.rateLimit,
|
|
94
|
+
});
|
|
95
|
+
if (input.status === 408 ||
|
|
96
|
+
input.status === 409 ||
|
|
97
|
+
(input.status !== undefined && input.status >= 500) ||
|
|
98
|
+
((input.status === undefined || input.status < 400) &&
|
|
99
|
+
!codes.some((code) => INVALID_REQUEST_CODES.has(code)) &&
|
|
100
|
+
SERVER_ERROR_TEXT.test(text)) ||
|
|
101
|
+
codes.some((code) => SERVER_CODES.has(code) || code.includes("exhausted") || code.includes("unavailable")))
|
|
102
|
+
return new ProviderInternalError({
|
|
103
|
+
...details,
|
|
104
|
+
retryAfterMs: input.retryAfterMs,
|
|
105
|
+
});
|
|
106
|
+
if (codes.some((code) => INVALID_REQUEST_CODES.has(code)))
|
|
107
|
+
return new InvalidRequestError(details);
|
|
108
|
+
// Any remaining 4xx is a deterministic rejection of this request.
|
|
109
|
+
if (input.status !== undefined && input.status >= 400 && input.status < 500)
|
|
110
|
+
return new InvalidRequestError(details);
|
|
111
|
+
return new UnknownProviderError(details);
|
|
112
|
+
}
|
|
113
|
+
function providerCodes(value) {
|
|
114
|
+
const decoded = typeof value === "string" ? Option.getOrUndefined(decodeJson(value)) : value;
|
|
115
|
+
if (!isRecord(decoded))
|
|
116
|
+
return [];
|
|
117
|
+
const error = isRecord(decoded.error) ? decoded.error : undefined;
|
|
118
|
+
const response = isRecord(decoded.response) ? decoded.response : undefined;
|
|
119
|
+
const responseError = response && isRecord(response.error) ? response.error : undefined;
|
|
120
|
+
const exception = isRecord(decoded.exception) ? decoded.exception : undefined;
|
|
121
|
+
return [decoded.code, error?.code, error?.type, error?.status, responseError?.code, exception?.type].filter((value) => typeof value === "string");
|
|
122
|
+
}
|
|
123
|
+
function isRecord(value) {
|
|
124
|
+
return typeof value === "object" && value !== null;
|
|
125
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LanguageModel, ProviderOptions } from "./schema/index.js";
|
|
2
|
+
import type { CompactionOperations } from "./route/client.js";
|
|
3
|
+
export interface Settings extends Readonly<Record<string, unknown>> {
|
|
4
|
+
readonly baseURL?: string;
|
|
5
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
6
|
+
readonly body?: Readonly<Record<string, unknown>>;
|
|
7
|
+
}
|
|
8
|
+
export interface Definition<ProviderSettings extends Settings = Settings, Options extends ProviderOptions = ProviderOptions, Compact extends CompactionOperations | undefined = CompactionOperations | undefined> {
|
|
9
|
+
readonly model: (modelID: string, settings: ProviderSettings) => LanguageModel<Options, Compact>;
|
|
10
|
+
}
|
|
11
|
+
export * as ProviderPackage from "./provider-package.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as ProviderPackage from "./provider-package.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { LanguageModel, ModelID, ProviderID } from "./schema/index.js";
|
|
2
|
+
export type LanguageModelOptions = Pick<LanguageModel.Input, "defaults" | "compatibility">;
|
|
3
|
+
/**
|
|
4
|
+
* Advanced structural provider definition helper. Built-in providers should
|
|
5
|
+
* prefer explicit `configure(options).model(id)` facades so deployment config is
|
|
6
|
+
* chosen before model selection. The optional `apis` map remains for external
|
|
7
|
+
* structural providers that expose multiple route selectors behind one provider.
|
|
8
|
+
*/
|
|
9
|
+
export type LanguageModelFactory<Options extends LanguageModelOptions = LanguageModelOptions> = (id: string | ModelID, options?: Options) => LanguageModel;
|
|
10
|
+
type AnyLanguageModelFactory = (...args: never[]) => LanguageModel;
|
|
11
|
+
export interface Definition<Factory extends AnyLanguageModelFactory = LanguageModelFactory> {
|
|
12
|
+
readonly id: ProviderID;
|
|
13
|
+
readonly model: Factory;
|
|
14
|
+
readonly apis?: Record<string, AnyLanguageModelFactory>;
|
|
15
|
+
}
|
|
16
|
+
type DefinitionShape = {
|
|
17
|
+
readonly id: ProviderID;
|
|
18
|
+
readonly model: (...args: never[]) => LanguageModel;
|
|
19
|
+
readonly apis?: Record<string, (...args: never[]) => LanguageModel>;
|
|
20
|
+
};
|
|
21
|
+
type NoExtraFields<Input, Shape> = Input & Record<Exclude<keyof Input, keyof Shape>, never>;
|
|
22
|
+
export declare const make: <DefinitionType extends DefinitionShape>(definition: NoExtraFields<DefinitionType, DefinitionShape>) => NoExtraFields<DefinitionType, DefinitionShape>;
|
|
23
|
+
export * as Provider from "./provider.js";
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { chatModel as model } from "../../amazon-bedrock-mantle.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { responsesModel as model } from "../../amazon-bedrock-mantle.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { responsesModel as model } from "../amazon-bedrock-mantle.js";
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { Route, type RouteDefaultsInput } from "../route/client.js";
|
|
2
|
+
import type { ProviderPackage } from "../provider-package.js";
|
|
3
|
+
import { type Credentials } from "../protocols/utils/bedrock-auth.js";
|
|
4
|
+
import { type ModelID } from "../schema/index.js";
|
|
5
|
+
import { type OpenAIProviderOptionsInput } from "./openai-options.js";
|
|
6
|
+
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
7
|
+
export type Config = RouteDefaultsInput & {
|
|
8
|
+
/** Bedrock API key. Falls back to `AWS_BEARER_TOKEN_BEDROCK`; bearer auth takes precedence over SigV4. */
|
|
9
|
+
readonly apiKey?: string;
|
|
10
|
+
/** `sigv4` ignores `apiKey` fallbacks from the environment; `bearer` requires a token. */
|
|
11
|
+
readonly auth?: "bearer" | "sigv4";
|
|
12
|
+
readonly baseURL?: string;
|
|
13
|
+
/** Static SigV4 credentials. When omitted the AWS default credential chain resolves them per request. */
|
|
14
|
+
readonly credentials?: Credentials;
|
|
15
|
+
/** Shared config profile for the default credential chain. */
|
|
16
|
+
readonly profile?: string;
|
|
17
|
+
readonly region?: string;
|
|
18
|
+
readonly providerOptions?: OpenAIProviderOptionsInput;
|
|
19
|
+
};
|
|
20
|
+
export interface Settings extends ProviderPackage.Settings {
|
|
21
|
+
readonly apiKey?: string;
|
|
22
|
+
readonly auth?: "bearer" | "sigv4";
|
|
23
|
+
readonly baseURL?: string;
|
|
24
|
+
readonly credentials?: Credentials;
|
|
25
|
+
readonly profile?: string;
|
|
26
|
+
readonly region?: string;
|
|
27
|
+
readonly topP?: number;
|
|
28
|
+
readonly providerOptions?: OpenAIProviderOptionsInput;
|
|
29
|
+
}
|
|
30
|
+
export declare const routes: (Route<{
|
|
31
|
+
readonly model: string;
|
|
32
|
+
readonly messages: readonly ({
|
|
33
|
+
readonly role: "system";
|
|
34
|
+
readonly content: string | readonly ({
|
|
35
|
+
readonly type: "text";
|
|
36
|
+
readonly text: string;
|
|
37
|
+
readonly cache_control?: {
|
|
38
|
+
readonly type: "ephemeral";
|
|
39
|
+
readonly ttl?: string | undefined;
|
|
40
|
+
} | undefined;
|
|
41
|
+
} | {
|
|
42
|
+
readonly type: "image_url";
|
|
43
|
+
readonly image_url: {
|
|
44
|
+
readonly url: string;
|
|
45
|
+
};
|
|
46
|
+
})[];
|
|
47
|
+
} | {
|
|
48
|
+
readonly role: "user";
|
|
49
|
+
readonly content: string | readonly ({
|
|
50
|
+
readonly type: "text";
|
|
51
|
+
readonly text: string;
|
|
52
|
+
readonly cache_control?: {
|
|
53
|
+
readonly type: "ephemeral";
|
|
54
|
+
readonly ttl?: string | undefined;
|
|
55
|
+
} | undefined;
|
|
56
|
+
} | {
|
|
57
|
+
readonly type: "image_url";
|
|
58
|
+
readonly image_url: {
|
|
59
|
+
readonly url: string;
|
|
60
|
+
};
|
|
61
|
+
})[];
|
|
62
|
+
} | {
|
|
63
|
+
readonly [x: string]: unknown;
|
|
64
|
+
readonly content: string | null;
|
|
65
|
+
readonly role: "assistant";
|
|
66
|
+
readonly reasoning?: string | undefined;
|
|
67
|
+
readonly reasoning_content?: string | undefined;
|
|
68
|
+
readonly reasoning_text?: string | undefined;
|
|
69
|
+
readonly cache_control?: {
|
|
70
|
+
readonly type: "ephemeral";
|
|
71
|
+
readonly ttl?: string | undefined;
|
|
72
|
+
} | undefined;
|
|
73
|
+
readonly tool_calls?: readonly {
|
|
74
|
+
readonly id: string;
|
|
75
|
+
readonly type: "function";
|
|
76
|
+
readonly function: {
|
|
77
|
+
readonly name: string;
|
|
78
|
+
readonly arguments: string;
|
|
79
|
+
};
|
|
80
|
+
}[] | undefined;
|
|
81
|
+
readonly reasoning_details?: unknown;
|
|
82
|
+
} | {
|
|
83
|
+
readonly content: string;
|
|
84
|
+
readonly role: "tool";
|
|
85
|
+
readonly tool_call_id: string;
|
|
86
|
+
readonly cache_control?: {
|
|
87
|
+
readonly type: "ephemeral";
|
|
88
|
+
readonly ttl?: string | undefined;
|
|
89
|
+
} | undefined;
|
|
90
|
+
})[];
|
|
91
|
+
readonly stream: true;
|
|
92
|
+
readonly max_completion_tokens?: number | undefined;
|
|
93
|
+
readonly max_tokens?: number | undefined;
|
|
94
|
+
readonly tools?: readonly {
|
|
95
|
+
readonly function: {
|
|
96
|
+
readonly description: string;
|
|
97
|
+
readonly name: string;
|
|
98
|
+
readonly parameters: {
|
|
99
|
+
readonly [x: string]: unknown;
|
|
100
|
+
};
|
|
101
|
+
readonly strict?: boolean | undefined;
|
|
102
|
+
};
|
|
103
|
+
readonly type: "function";
|
|
104
|
+
readonly cache_control?: {
|
|
105
|
+
readonly type: "ephemeral";
|
|
106
|
+
readonly ttl?: string | undefined;
|
|
107
|
+
} | undefined;
|
|
108
|
+
}[] | undefined;
|
|
109
|
+
readonly stop?: readonly string[] | undefined;
|
|
110
|
+
readonly temperature?: number | undefined;
|
|
111
|
+
readonly seed?: number | undefined;
|
|
112
|
+
readonly tool_choice?: "required" | "auto" | "none" | {
|
|
113
|
+
readonly type: "function";
|
|
114
|
+
readonly function: {
|
|
115
|
+
readonly name: string;
|
|
116
|
+
};
|
|
117
|
+
} | undefined;
|
|
118
|
+
readonly top_p?: number | undefined;
|
|
119
|
+
readonly frequency_penalty?: number | undefined;
|
|
120
|
+
readonly presence_penalty?: number | undefined;
|
|
121
|
+
readonly prompt_cache_key?: string | undefined;
|
|
122
|
+
readonly reasoning_effort?: import("../protocols/utils/open-responses-options.js").ReasoningEffort | undefined;
|
|
123
|
+
readonly store?: boolean | undefined;
|
|
124
|
+
readonly stream_options?: {
|
|
125
|
+
readonly include_usage: boolean;
|
|
126
|
+
} | undefined;
|
|
127
|
+
readonly tool_stream?: boolean | undefined;
|
|
128
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined> | Route<{
|
|
129
|
+
readonly input: readonly ({
|
|
130
|
+
readonly [x: string]: unknown;
|
|
131
|
+
readonly id: string;
|
|
132
|
+
readonly type: "web_search_call";
|
|
133
|
+
readonly status?: string | undefined;
|
|
134
|
+
readonly action?: {
|
|
135
|
+
readonly [x: string]: unknown;
|
|
136
|
+
} | null | undefined;
|
|
137
|
+
} | {
|
|
138
|
+
readonly [x: string]: unknown;
|
|
139
|
+
readonly id: string;
|
|
140
|
+
readonly type: "file_search_call";
|
|
141
|
+
readonly status?: string | undefined;
|
|
142
|
+
readonly queries?: readonly string[] | undefined;
|
|
143
|
+
readonly results?: readonly {
|
|
144
|
+
readonly [x: string]: unknown;
|
|
145
|
+
}[] | null | undefined;
|
|
146
|
+
} | {
|
|
147
|
+
readonly [x: string]: unknown;
|
|
148
|
+
readonly id: string;
|
|
149
|
+
readonly type: "code_interpreter_call";
|
|
150
|
+
readonly status?: string | undefined;
|
|
151
|
+
readonly code?: string | null | undefined;
|
|
152
|
+
readonly container_id?: string | null | undefined;
|
|
153
|
+
readonly outputs?: readonly {
|
|
154
|
+
readonly [x: string]: unknown;
|
|
155
|
+
}[] | null | undefined;
|
|
156
|
+
} | {
|
|
157
|
+
readonly [x: string]: unknown;
|
|
158
|
+
readonly id: string;
|
|
159
|
+
readonly type: "mcp_call";
|
|
160
|
+
readonly status?: string | undefined;
|
|
161
|
+
readonly name?: string | undefined;
|
|
162
|
+
readonly output?: string | null | undefined;
|
|
163
|
+
readonly error?: unknown;
|
|
164
|
+
readonly arguments?: string | undefined;
|
|
165
|
+
readonly server_label?: string | undefined;
|
|
166
|
+
} | {
|
|
167
|
+
readonly type: "reasoning";
|
|
168
|
+
readonly summary: readonly {
|
|
169
|
+
readonly type: "summary_text";
|
|
170
|
+
readonly text: string;
|
|
171
|
+
}[];
|
|
172
|
+
readonly id?: string | undefined;
|
|
173
|
+
readonly encrypted_content?: string | null | undefined;
|
|
174
|
+
} | {
|
|
175
|
+
readonly type: "compaction";
|
|
176
|
+
readonly encrypted_content: string;
|
|
177
|
+
readonly id?: string | null | undefined;
|
|
178
|
+
} | {
|
|
179
|
+
readonly role: "system";
|
|
180
|
+
readonly content: string;
|
|
181
|
+
} | {
|
|
182
|
+
readonly role: "developer";
|
|
183
|
+
readonly content: string;
|
|
184
|
+
} | {
|
|
185
|
+
readonly content: readonly ({
|
|
186
|
+
readonly type: "input_image";
|
|
187
|
+
readonly image_url: string;
|
|
188
|
+
readonly detail?: string | undefined;
|
|
189
|
+
} | {
|
|
190
|
+
readonly type: "input_file";
|
|
191
|
+
readonly filename: string;
|
|
192
|
+
readonly detail?: string | undefined;
|
|
193
|
+
readonly file_data?: string | undefined;
|
|
194
|
+
readonly file_url?: string | undefined;
|
|
195
|
+
} | {
|
|
196
|
+
readonly type: "input_text";
|
|
197
|
+
readonly text: string;
|
|
198
|
+
})[];
|
|
199
|
+
readonly role: "user";
|
|
200
|
+
readonly id?: string | undefined;
|
|
201
|
+
readonly type?: "message" | undefined;
|
|
202
|
+
readonly status?: string | undefined;
|
|
203
|
+
} | {
|
|
204
|
+
readonly type: "message";
|
|
205
|
+
readonly content: readonly {
|
|
206
|
+
readonly type: "output_text";
|
|
207
|
+
readonly text: string;
|
|
208
|
+
}[];
|
|
209
|
+
readonly role: "assistant";
|
|
210
|
+
readonly id?: string | undefined;
|
|
211
|
+
readonly status?: string | undefined;
|
|
212
|
+
readonly phase?: "commentary" | "final_answer" | null | undefined;
|
|
213
|
+
} | {
|
|
214
|
+
readonly type: "function_call";
|
|
215
|
+
readonly name: string;
|
|
216
|
+
readonly arguments: string;
|
|
217
|
+
readonly call_id: string;
|
|
218
|
+
readonly id?: string | undefined;
|
|
219
|
+
readonly namespace?: string | undefined;
|
|
220
|
+
} | {
|
|
221
|
+
readonly type: "function_call_output";
|
|
222
|
+
readonly call_id: string;
|
|
223
|
+
readonly output: string | readonly ({
|
|
224
|
+
readonly type: "input_image";
|
|
225
|
+
readonly image_url: string;
|
|
226
|
+
readonly detail?: string | undefined;
|
|
227
|
+
} | {
|
|
228
|
+
readonly type: "input_file";
|
|
229
|
+
readonly filename: string;
|
|
230
|
+
readonly detail?: string | undefined;
|
|
231
|
+
readonly file_data?: string | undefined;
|
|
232
|
+
readonly file_url?: string | undefined;
|
|
233
|
+
} | {
|
|
234
|
+
readonly type: "input_text";
|
|
235
|
+
readonly text: string;
|
|
236
|
+
} | {
|
|
237
|
+
readonly type: "input_video";
|
|
238
|
+
readonly video_url: string;
|
|
239
|
+
})[];
|
|
240
|
+
} | {
|
|
241
|
+
readonly [x: string]: unknown;
|
|
242
|
+
readonly id: string;
|
|
243
|
+
readonly type: "computer_call";
|
|
244
|
+
readonly status?: string | undefined;
|
|
245
|
+
readonly action?: {
|
|
246
|
+
readonly [x: string]: unknown;
|
|
247
|
+
} | null | undefined;
|
|
248
|
+
readonly call_id?: string | undefined;
|
|
249
|
+
readonly pending_safety_checks?: readonly {
|
|
250
|
+
readonly [x: string]: unknown;
|
|
251
|
+
}[] | undefined;
|
|
252
|
+
} | {
|
|
253
|
+
readonly [x: string]: unknown;
|
|
254
|
+
readonly id: string;
|
|
255
|
+
readonly type: "web_search_preview_call";
|
|
256
|
+
readonly status?: string | undefined;
|
|
257
|
+
readonly action?: {
|
|
258
|
+
readonly [x: string]: unknown;
|
|
259
|
+
} | null | undefined;
|
|
260
|
+
} | {
|
|
261
|
+
readonly [x: string]: unknown;
|
|
262
|
+
readonly id: string;
|
|
263
|
+
readonly type: "image_generation_call";
|
|
264
|
+
readonly status?: string | undefined;
|
|
265
|
+
readonly result?: string | null | undefined;
|
|
266
|
+
readonly revised_prompt?: string | null | undefined;
|
|
267
|
+
readonly output_format?: "png" | "jpeg" | "webp" | undefined;
|
|
268
|
+
})[];
|
|
269
|
+
readonly model: string;
|
|
270
|
+
readonly stream: true;
|
|
271
|
+
readonly metadata?: {
|
|
272
|
+
readonly [x: string]: string;
|
|
273
|
+
} | undefined;
|
|
274
|
+
readonly instructions?: string | undefined;
|
|
275
|
+
readonly reasoning?: {
|
|
276
|
+
readonly summary?: "auto" | "concise" | "detailed" | undefined;
|
|
277
|
+
readonly effort?: import("../protocols/utils/open-responses-options.js").ReasoningEffort | undefined;
|
|
278
|
+
} | undefined;
|
|
279
|
+
readonly tools?: readonly ({
|
|
280
|
+
readonly type: "function";
|
|
281
|
+
readonly description: string;
|
|
282
|
+
readonly name: string;
|
|
283
|
+
readonly parameters: {
|
|
284
|
+
readonly [x: string]: unknown;
|
|
285
|
+
};
|
|
286
|
+
readonly strict?: boolean | undefined;
|
|
287
|
+
} | {
|
|
288
|
+
readonly type: "image_generation";
|
|
289
|
+
readonly size?: string | undefined;
|
|
290
|
+
readonly action?: "generate" | "auto" | "edit" | undefined;
|
|
291
|
+
readonly output_format?: "png" | "jpeg" | "webp" | undefined;
|
|
292
|
+
readonly quality?: "auto" | "low" | "medium" | "high" | undefined;
|
|
293
|
+
readonly background?: "auto" | "opaque" | "transparent" | undefined;
|
|
294
|
+
readonly output_compression?: number | undefined;
|
|
295
|
+
readonly input_fidelity?: "low" | "high" | undefined;
|
|
296
|
+
readonly partial_images?: number | undefined;
|
|
297
|
+
} | {
|
|
298
|
+
readonly type: "namespace";
|
|
299
|
+
readonly name: string;
|
|
300
|
+
readonly description: string;
|
|
301
|
+
readonly tools: readonly {
|
|
302
|
+
readonly type: "function";
|
|
303
|
+
readonly description: string;
|
|
304
|
+
readonly name: string;
|
|
305
|
+
readonly parameters: {
|
|
306
|
+
readonly [x: string]: unknown;
|
|
307
|
+
};
|
|
308
|
+
readonly strict?: boolean | undefined;
|
|
309
|
+
}[];
|
|
310
|
+
})[] | undefined;
|
|
311
|
+
readonly text?: {
|
|
312
|
+
readonly verbosity?: import("../protocols/utils/open-responses-options.js").TextVerbosity | undefined;
|
|
313
|
+
} | undefined;
|
|
314
|
+
readonly temperature?: number | undefined;
|
|
315
|
+
readonly service_tier?: import("../protocols/utils/open-responses-options.js").ServiceTier | undefined;
|
|
316
|
+
readonly context_management?: readonly {
|
|
317
|
+
readonly type: "compaction";
|
|
318
|
+
readonly compact_threshold?: number | undefined;
|
|
319
|
+
}[] | undefined;
|
|
320
|
+
readonly tool_choice?: "required" | "auto" | "none" | {
|
|
321
|
+
readonly type: "function";
|
|
322
|
+
readonly name: string;
|
|
323
|
+
} | {
|
|
324
|
+
readonly type: "allowed_tools";
|
|
325
|
+
readonly mode: "required" | "auto" | "none";
|
|
326
|
+
readonly tools: readonly {
|
|
327
|
+
readonly type: "function";
|
|
328
|
+
readonly name: string;
|
|
329
|
+
}[];
|
|
330
|
+
} | {
|
|
331
|
+
readonly type: "image_generation";
|
|
332
|
+
} | undefined;
|
|
333
|
+
readonly top_p?: number | undefined;
|
|
334
|
+
readonly frequency_penalty?: number | undefined;
|
|
335
|
+
readonly presence_penalty?: number | undefined;
|
|
336
|
+
readonly prompt_cache_key?: string | undefined;
|
|
337
|
+
readonly parallel_tool_calls?: boolean | undefined;
|
|
338
|
+
readonly store?: boolean | undefined;
|
|
339
|
+
readonly include?: readonly import("../protocols/utils/open-responses-options.js").ResponseIncludable[] | undefined;
|
|
340
|
+
readonly truncation?: "auto" | "disabled" | undefined;
|
|
341
|
+
readonly stream_options?: {
|
|
342
|
+
readonly include_obfuscation?: boolean | undefined;
|
|
343
|
+
} | undefined;
|
|
344
|
+
readonly safety_identifier?: string | undefined;
|
|
345
|
+
readonly top_logprobs?: number | undefined;
|
|
346
|
+
readonly max_output_tokens?: number | undefined;
|
|
347
|
+
readonly max_tool_calls?: number | undefined;
|
|
348
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>)[];
|
|
349
|
+
export declare const configure: (input?: Config) => {
|
|
350
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
351
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
352
|
+
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
353
|
+
responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
354
|
+
configure: (input?: Config) => /*elided*/ any;
|
|
355
|
+
};
|
|
356
|
+
export declare const provider: {
|
|
357
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
358
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
359
|
+
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
360
|
+
responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
361
|
+
configure: (input?: Config) => {
|
|
362
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
363
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
364
|
+
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
365
|
+
responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
366
|
+
configure: /*elided*/ any;
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
export declare const chatModel: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"];
|
|
370
|
+
export declare const responsesModel: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"];
|
|
371
|
+
export declare const model: (modelID: string, settings: Settings) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|