@opencode/ai 0.0.0-reserved → 2.0.1
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 +879 -2
- 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/alibaba-chat.d.ts +225 -0
- package/dist/protocols/alibaba-chat.js +75 -0
- package/dist/protocols/alibaba-messages.d.ts +350 -0
- package/dist/protocols/alibaba-messages.js +40 -0
- package/dist/protocols/alibaba-responses.d.ts +255 -0
- package/dist/protocols/alibaba-responses.js +80 -0
- package/dist/protocols/anthropic-messages.d.ts +980 -0
- package/dist/protocols/anthropic-messages.js +1460 -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 +356 -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 +25 -0
- package/dist/protocols/open-responses-channel.js +141 -0
- package/dist/protocols/open-responses-continuation.d.ts +16 -0
- package/dist/protocols/open-responses-continuation.js +170 -0
- package/dist/protocols/open-responses.d.ts +1715 -0
- package/dist/protocols/open-responses.js +1228 -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-chat.d.ts +202 -0
- package/dist/protocols/zai-chat.js +49 -0
- package/dist/protocols/zai-images.d.ts +22 -0
- package/dist/protocols/zai-images.js +79 -0
- package/dist/protocols/zai-messages.d.ts +344 -0
- package/dist/protocols/zai-messages.js +27 -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 +15 -0
- package/dist/provider-package.js +1 -0
- package/dist/provider.d.ts +23 -0
- package/dist/provider.js +2 -0
- package/dist/providers/alibaba/chat.d.ts +1 -0
- package/dist/providers/alibaba/chat.js +1 -0
- package/dist/providers/alibaba/messages.d.ts +3 -0
- package/dist/providers/alibaba/messages.js +1 -0
- package/dist/providers/alibaba/responses.d.ts +3 -0
- package/dist/providers/alibaba/responses.js +1 -0
- package/dist/providers/alibaba.d.ts +711 -0
- package/dist/providers/alibaba.js +94 -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 +313 -0
- package/dist/providers/amazon-bedrock-mantle.js +79 -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 +309 -0
- package/dist/providers/anthropic-compatible.js +50 -0
- package/dist/providers/anthropic.d.ts +307 -0
- package/dist/providers/anthropic.js +42 -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 +598 -0
- package/dist/providers/azure.js +115 -0
- package/dist/providers/baseten.d.ts +228 -0
- package/dist/providers/baseten.js +38 -0
- package/dist/providers/cerebras.d.ts +227 -0
- package/dist/providers/cerebras.js +40 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +237 -0
- package/dist/providers/cloudflare-ai-gateway.js +65 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +231 -0
- package/dist/providers/cloudflare-workers-ai.js +51 -0
- package/dist/providers/deepinfra.d.ts +227 -0
- package/dist/providers/deepinfra.js +43 -0
- package/dist/providers/deepseek.d.ts +228 -0
- package/dist/providers/deepseek.js +41 -0
- package/dist/providers/fireworks.d.ts +228 -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 +132 -0
- package/dist/providers/google-vertex-chat.js +55 -0
- package/dist/providers/google-vertex-messages.d.ts +306 -0
- package/dist/providers/google-vertex-messages.js +75 -0
- package/dist/providers/google-vertex-responses.d.ts +197 -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 +72 -0
- package/dist/providers/google-vertex.d.ts +119 -0
- package/dist/providers/google-vertex.js +98 -0
- package/dist/providers/google.d.ts +114 -0
- package/dist/providers/google.js +42 -0
- package/dist/providers/groq.d.ts +314 -0
- package/dist/providers/groq.js +81 -0
- package/dist/providers/index.d.ts +31 -0
- package/dist/providers/index.js +31 -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 +636 -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 +598 -0
- package/dist/providers/minimax.js +89 -0
- package/dist/providers/mistral.d.ts +207 -0
- package/dist/providers/mistral.js +28 -0
- package/dist/providers/moonshot/chat.d.ts +1 -0
- package/dist/providers/moonshot/chat.js +1 -0
- package/dist/providers/moonshot/messages.d.ts +4 -0
- package/dist/providers/moonshot/messages.js +8 -0
- package/dist/providers/moonshot/responses.d.ts +4 -0
- package/dist/providers/moonshot/responses.js +8 -0
- package/dist/providers/moonshot.d.ts +596 -0
- package/dist/providers/moonshot.js +90 -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 +195 -0
- package/dist/providers/openai-compatible-responses.js +32 -0
- package/dist/providers/openai-compatible.d.ts +130 -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 +404 -0
- package/dist/providers/openai.js +82 -0
- package/dist/providers/openrouter.d.ts +563 -0
- package/dist/providers/openrouter.js +114 -0
- package/dist/providers/togetherai.d.ts +227 -0
- package/dist/providers/togetherai.js +40 -0
- package/dist/providers/xai.d.ts +163 -0
- package/dist/providers/xai.js +88 -0
- package/dist/providers/zai/chat.d.ts +1 -0
- package/dist/providers/zai/chat.js +1 -0
- package/dist/providers/zai-coding-plan/chat.d.ts +1 -0
- package/dist/providers/zai-coding-plan/chat.js +1 -0
- package/dist/providers/zai-coding-plan/messages.d.ts +4 -0
- package/dist/providers/zai-coding-plan/messages.js +8 -0
- package/dist/providers/zai-coding-plan/responses.d.ts +4 -0
- package/dist/providers/zai-coding-plan/responses.js +8 -0
- package/dist/providers/zai-coding-plan.d.ts +577 -0
- package/dist/providers/zai-coding-plan.js +63 -0
- package/dist/providers/zai.d.ts +149 -0
- package/dist/providers/zai.js +53 -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 +307 -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 +370 -0
- package/dist/route.d.ts +1 -0
- package/dist/route.js +1 -0
- package/dist/schema/errors.d.ts +170 -0
- package/dist/schema/errors.js +131 -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 +159 -0
- package/dist/schema/options.js +189 -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 +43 -10
package/dist/llm.d.ts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { Effect, JsonSchema, Schema } from "effect";
|
|
2
|
+
import { Service } from "./route/client.js";
|
|
3
|
+
import { GenerationOptions, HttpOptions, AIError, LLMRequest, LLMResponse, Message, LanguageModel, SystemPart, ToolChoice, type ContentPart, type LanguageModelProviderOptions, type ToolEntryInput } from "./schema/index.js";
|
|
4
|
+
import { type ToolSchema } from "./tool.js";
|
|
5
|
+
/** Input accepted by `LLM.request`, normalized into the canonical `LLMRequest` class. */
|
|
6
|
+
export type RequestInput<SelectedLanguageModel extends LanguageModel = LanguageModel> = Omit<ConstructorParameters<typeof LLMRequest>[0], "model" | "system" | "messages" | "tools" | "toolChoice" | "generation" | "http" | "providerOptions"> & {
|
|
7
|
+
readonly model: SelectedLanguageModel;
|
|
8
|
+
readonly system?: string | SystemPart | ReadonlyArray<SystemPart>;
|
|
9
|
+
readonly prompt?: string | ContentPart | ReadonlyArray<ContentPart>;
|
|
10
|
+
readonly messages?: ReadonlyArray<Message | Message.Input>;
|
|
11
|
+
readonly tools?: ReadonlyArray<ToolEntryInput>;
|
|
12
|
+
readonly toolChoice?: ToolChoice.Input;
|
|
13
|
+
readonly generation?: GenerationOptions.Input;
|
|
14
|
+
readonly providerOptions?: NoInfer<LanguageModelProviderOptions<SelectedLanguageModel>>;
|
|
15
|
+
readonly http?: HttpOptions.Input;
|
|
16
|
+
};
|
|
17
|
+
export declare const generate: typeof import("./route/client.js").generate;
|
|
18
|
+
export declare const stream: typeof import("./route/client.js").stream;
|
|
19
|
+
export declare const request: <const SelectedLanguageModel extends LanguageModel>(input: RequestInput<SelectedLanguageModel>) => LLMRequest<SelectedLanguageModel>;
|
|
20
|
+
type GenerateObjectBase<SelectedLanguageModel extends LanguageModel = LanguageModel> = Omit<RequestInput<SelectedLanguageModel>, "tools" | "toolChoice">;
|
|
21
|
+
export declare class GenerateObjectResponse<T> {
|
|
22
|
+
readonly object: T;
|
|
23
|
+
readonly response: LLMResponse;
|
|
24
|
+
constructor(object: T, response: LLMResponse);
|
|
25
|
+
get events(): readonly (({
|
|
26
|
+
readonly type: "compaction";
|
|
27
|
+
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
28
|
+
readonly id?: string | undefined;
|
|
29
|
+
readonly text?: string | null | undefined;
|
|
30
|
+
readonly encrypted?: string | undefined;
|
|
31
|
+
} & ({
|
|
32
|
+
readonly encrypted: string;
|
|
33
|
+
readonly text?: never;
|
|
34
|
+
} | {
|
|
35
|
+
readonly text: string | null;
|
|
36
|
+
readonly encrypted?: never;
|
|
37
|
+
})) | {
|
|
38
|
+
readonly type: "step-start";
|
|
39
|
+
readonly index: number;
|
|
40
|
+
} | {
|
|
41
|
+
readonly id: string;
|
|
42
|
+
readonly type: "text-start";
|
|
43
|
+
readonly providerMetadata?: {
|
|
44
|
+
readonly [x: string]: {
|
|
45
|
+
readonly [x: string]: unknown;
|
|
46
|
+
};
|
|
47
|
+
} | undefined;
|
|
48
|
+
} | {
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly type: "text-delta";
|
|
51
|
+
readonly text: string;
|
|
52
|
+
readonly providerMetadata?: {
|
|
53
|
+
readonly [x: string]: {
|
|
54
|
+
readonly [x: string]: unknown;
|
|
55
|
+
};
|
|
56
|
+
} | undefined;
|
|
57
|
+
} | {
|
|
58
|
+
readonly id: string;
|
|
59
|
+
readonly type: "text-end";
|
|
60
|
+
readonly text?: string | undefined;
|
|
61
|
+
readonly providerMetadata?: {
|
|
62
|
+
readonly [x: string]: {
|
|
63
|
+
readonly [x: string]: unknown;
|
|
64
|
+
};
|
|
65
|
+
} | undefined;
|
|
66
|
+
} | {
|
|
67
|
+
readonly id: string;
|
|
68
|
+
readonly type: "reasoning-start";
|
|
69
|
+
readonly providerMetadata?: {
|
|
70
|
+
readonly [x: string]: {
|
|
71
|
+
readonly [x: string]: unknown;
|
|
72
|
+
};
|
|
73
|
+
} | undefined;
|
|
74
|
+
} | {
|
|
75
|
+
readonly id: string;
|
|
76
|
+
readonly type: "reasoning-delta";
|
|
77
|
+
readonly text: string;
|
|
78
|
+
readonly providerMetadata?: {
|
|
79
|
+
readonly [x: string]: {
|
|
80
|
+
readonly [x: string]: unknown;
|
|
81
|
+
};
|
|
82
|
+
} | undefined;
|
|
83
|
+
} | {
|
|
84
|
+
readonly id: string;
|
|
85
|
+
readonly type: "reasoning-end";
|
|
86
|
+
readonly text?: string | undefined;
|
|
87
|
+
readonly providerMetadata?: {
|
|
88
|
+
readonly [x: string]: {
|
|
89
|
+
readonly [x: string]: unknown;
|
|
90
|
+
};
|
|
91
|
+
} | undefined;
|
|
92
|
+
} | {
|
|
93
|
+
readonly id: string;
|
|
94
|
+
readonly type: "tool-input-start";
|
|
95
|
+
readonly name: string;
|
|
96
|
+
readonly providerMetadata?: {
|
|
97
|
+
readonly [x: string]: {
|
|
98
|
+
readonly [x: string]: unknown;
|
|
99
|
+
};
|
|
100
|
+
} | undefined;
|
|
101
|
+
readonly namespace?: string | undefined;
|
|
102
|
+
readonly providerExecuted?: boolean | undefined;
|
|
103
|
+
} | {
|
|
104
|
+
readonly id: string;
|
|
105
|
+
readonly type: "tool-input-delta";
|
|
106
|
+
readonly name: string;
|
|
107
|
+
readonly text: string;
|
|
108
|
+
readonly input?: unknown;
|
|
109
|
+
readonly namespace?: string | undefined;
|
|
110
|
+
} | {
|
|
111
|
+
readonly id: string;
|
|
112
|
+
readonly type: "tool-input-end";
|
|
113
|
+
readonly name: string;
|
|
114
|
+
readonly providerMetadata?: {
|
|
115
|
+
readonly [x: string]: {
|
|
116
|
+
readonly [x: string]: unknown;
|
|
117
|
+
};
|
|
118
|
+
} | undefined;
|
|
119
|
+
readonly namespace?: string | undefined;
|
|
120
|
+
} | {
|
|
121
|
+
readonly id: string;
|
|
122
|
+
readonly type: "tool-input-error";
|
|
123
|
+
readonly name: string;
|
|
124
|
+
readonly raw: string;
|
|
125
|
+
readonly namespace?: string | undefined;
|
|
126
|
+
} | {
|
|
127
|
+
readonly id: string;
|
|
128
|
+
readonly type: "tool-call";
|
|
129
|
+
readonly name: string;
|
|
130
|
+
readonly input: unknown;
|
|
131
|
+
readonly providerMetadata?: {
|
|
132
|
+
readonly [x: string]: {
|
|
133
|
+
readonly [x: string]: unknown;
|
|
134
|
+
};
|
|
135
|
+
} | undefined;
|
|
136
|
+
readonly namespace?: string | undefined;
|
|
137
|
+
readonly providerExecuted?: boolean | undefined;
|
|
138
|
+
} | {
|
|
139
|
+
readonly id: string;
|
|
140
|
+
readonly type: "tool-result";
|
|
141
|
+
readonly name: string;
|
|
142
|
+
readonly result: {
|
|
143
|
+
readonly type: "json";
|
|
144
|
+
readonly value: unknown;
|
|
145
|
+
} | {
|
|
146
|
+
readonly type: "text";
|
|
147
|
+
readonly value: unknown;
|
|
148
|
+
} | {
|
|
149
|
+
readonly type: "error";
|
|
150
|
+
readonly value: unknown;
|
|
151
|
+
} | {
|
|
152
|
+
readonly type: "content";
|
|
153
|
+
readonly value: readonly ({
|
|
154
|
+
readonly type: "text";
|
|
155
|
+
readonly text: string;
|
|
156
|
+
} | {
|
|
157
|
+
readonly type: "file";
|
|
158
|
+
readonly uri: string;
|
|
159
|
+
readonly mime: string;
|
|
160
|
+
readonly name?: string | undefined;
|
|
161
|
+
})[];
|
|
162
|
+
};
|
|
163
|
+
readonly output?: {
|
|
164
|
+
readonly structured: unknown;
|
|
165
|
+
readonly content: readonly ({
|
|
166
|
+
readonly type: "text";
|
|
167
|
+
readonly text: string;
|
|
168
|
+
} | {
|
|
169
|
+
readonly type: "file";
|
|
170
|
+
readonly uri: string;
|
|
171
|
+
readonly mime: string;
|
|
172
|
+
readonly name?: string | undefined;
|
|
173
|
+
})[];
|
|
174
|
+
} | undefined;
|
|
175
|
+
readonly providerMetadata?: {
|
|
176
|
+
readonly [x: string]: {
|
|
177
|
+
readonly [x: string]: unknown;
|
|
178
|
+
};
|
|
179
|
+
} | undefined;
|
|
180
|
+
readonly namespace?: string | undefined;
|
|
181
|
+
readonly providerExecuted?: boolean | undefined;
|
|
182
|
+
} | {
|
|
183
|
+
readonly id: string;
|
|
184
|
+
readonly type: "tool-error";
|
|
185
|
+
readonly name: string;
|
|
186
|
+
readonly message: string;
|
|
187
|
+
readonly error?: unknown;
|
|
188
|
+
readonly providerMetadata?: {
|
|
189
|
+
readonly [x: string]: {
|
|
190
|
+
readonly [x: string]: unknown;
|
|
191
|
+
};
|
|
192
|
+
} | undefined;
|
|
193
|
+
readonly namespace?: string | undefined;
|
|
194
|
+
} | {
|
|
195
|
+
readonly type: "step-finish";
|
|
196
|
+
readonly reason: {
|
|
197
|
+
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
|
|
198
|
+
readonly raw?: string | undefined;
|
|
199
|
+
};
|
|
200
|
+
readonly index: number;
|
|
201
|
+
readonly providerMetadata?: {
|
|
202
|
+
readonly [x: string]: {
|
|
203
|
+
readonly [x: string]: unknown;
|
|
204
|
+
};
|
|
205
|
+
} | undefined;
|
|
206
|
+
readonly usage?: import("./schema/events.js").Usage | undefined;
|
|
207
|
+
} | {
|
|
208
|
+
readonly type: "finish";
|
|
209
|
+
readonly reason: {
|
|
210
|
+
readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
|
|
211
|
+
readonly raw?: string | undefined;
|
|
212
|
+
};
|
|
213
|
+
readonly providerMetadata?: {
|
|
214
|
+
readonly [x: string]: {
|
|
215
|
+
readonly [x: string]: unknown;
|
|
216
|
+
};
|
|
217
|
+
} | undefined;
|
|
218
|
+
readonly usage?: import("./schema/events.js").Usage | undefined;
|
|
219
|
+
} | {
|
|
220
|
+
readonly type: "provider-error";
|
|
221
|
+
readonly message: string;
|
|
222
|
+
readonly providerMetadata?: {
|
|
223
|
+
readonly [x: string]: {
|
|
224
|
+
readonly [x: string]: unknown;
|
|
225
|
+
};
|
|
226
|
+
} | undefined;
|
|
227
|
+
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
228
|
+
})[];
|
|
229
|
+
get usage(): import("./schema/events.js").Usage | undefined;
|
|
230
|
+
}
|
|
231
|
+
export interface GenerateObjectOptions<S extends ToolSchema<any>, SelectedLanguageModel extends LanguageModel = LanguageModel> extends GenerateObjectBase<SelectedLanguageModel> {
|
|
232
|
+
readonly schema: S;
|
|
233
|
+
}
|
|
234
|
+
export interface GenerateObjectDynamicOptions<SelectedLanguageModel extends LanguageModel = LanguageModel> extends GenerateObjectBase<SelectedLanguageModel> {
|
|
235
|
+
/** Raw JSON Schema object describing the expected output shape. */
|
|
236
|
+
readonly jsonSchema: JsonSchema.JsonSchema;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Run a model and decode its output against `schema`. Works on every protocol
|
|
240
|
+
* because it forces a synthetic tool call internally — provider-native JSON
|
|
241
|
+
* modes are intentionally avoided so behaviour is uniform.
|
|
242
|
+
*
|
|
243
|
+
* Two input modes:
|
|
244
|
+
*
|
|
245
|
+
* 1. `schema: EffectSchema<T>` — `.object` is decoded and typed as `T`.
|
|
246
|
+
* Decode failures surface as `AIError`.
|
|
247
|
+
* 2. `jsonSchema: JsonSchema.JsonSchema` — `.object` is `unknown`. Use when
|
|
248
|
+
* the schema is only available at runtime (MCP, plugin manifests). Caller validates.
|
|
249
|
+
*/
|
|
250
|
+
export declare function generateObject<const SelectedLanguageModel extends LanguageModel, S extends ToolSchema<any>>(options: GenerateObjectOptions<S, SelectedLanguageModel>): Effect.Effect<GenerateObjectResponse<Schema.Schema.Type<S>>, AIError, Service>;
|
|
251
|
+
export declare function generateObject<const SelectedLanguageModel extends LanguageModel>(options: GenerateObjectDynamicOptions<SelectedLanguageModel>): Effect.Effect<GenerateObjectResponse<unknown>, AIError, Service>;
|
|
252
|
+
export {};
|
package/dist/llm.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Effect, JsonSchema, Schema } from "effect";
|
|
2
|
+
import { LLMClient, Service } from "./route/client.js";
|
|
3
|
+
import { GenerationOptions, HttpOptions, InvalidProviderOutputError, AIError, LLMEvent, LLMRequest, LLMResponse, Message, LanguageModel, SystemPart, ToolChoice, ToolEntry, } from "./schema/index.js";
|
|
4
|
+
import { make as makeTool, toDefinitions } from "./tool.js";
|
|
5
|
+
export const generate = LLMClient.generate;
|
|
6
|
+
export const stream = LLMClient.stream;
|
|
7
|
+
export const request = (input) => {
|
|
8
|
+
const { system: requestSystem, prompt, messages, tools, toolChoice: requestToolChoice, generation: requestGeneration, providerOptions: requestProviderOptions, http: requestHttp, ...rest } = input;
|
|
9
|
+
return new LLMRequest({
|
|
10
|
+
...rest,
|
|
11
|
+
system: SystemPart.content(requestSystem),
|
|
12
|
+
messages: [...(messages?.map(Message.make) ?? []), ...(prompt === undefined ? [] : [Message.user(prompt)])],
|
|
13
|
+
tools: tools?.map(ToolEntry.make) ?? [],
|
|
14
|
+
toolChoice: requestToolChoice ? ToolChoice.make(requestToolChoice) : undefined,
|
|
15
|
+
generation: requestGeneration === undefined ? undefined : GenerationOptions.make(requestGeneration),
|
|
16
|
+
providerOptions: requestProviderOptions,
|
|
17
|
+
http: requestHttp === undefined ? undefined : HttpOptions.make(requestHttp),
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const GENERATE_OBJECT_TOOL_NAME = "generate_object";
|
|
21
|
+
const GENERATE_OBJECT_TOOL_DESCRIPTION = "Return the structured result by calling this tool.";
|
|
22
|
+
export class GenerateObjectResponse {
|
|
23
|
+
object;
|
|
24
|
+
response;
|
|
25
|
+
constructor(object, response) {
|
|
26
|
+
this.object = object;
|
|
27
|
+
this.response = response;
|
|
28
|
+
}
|
|
29
|
+
get events() {
|
|
30
|
+
return this.response.events;
|
|
31
|
+
}
|
|
32
|
+
get usage() {
|
|
33
|
+
return this.response.usage;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const runGenerateObject = Effect.fn("LLM.generateObject")(function* (options, tool) {
|
|
37
|
+
const baseRequest = request(options);
|
|
38
|
+
const generateRequest = LLMRequest.update(baseRequest, {
|
|
39
|
+
tools: toDefinitions({ [GENERATE_OBJECT_TOOL_NAME]: tool }),
|
|
40
|
+
toolChoice: ToolChoice.named(GENERATE_OBJECT_TOOL_NAME),
|
|
41
|
+
});
|
|
42
|
+
const response = yield* LLMClient.generate(generateRequest);
|
|
43
|
+
const call = response.toolCalls.find((event) => LLMEvent.is.toolCall(event) && event.name === GENERATE_OBJECT_TOOL_NAME);
|
|
44
|
+
if (!call || !LLMEvent.is.toolCall(call))
|
|
45
|
+
return yield* new AIError({
|
|
46
|
+
reason: new InvalidProviderOutputError({
|
|
47
|
+
message: `generateObject: model did not call the forced \`${GENERATE_OBJECT_TOOL_NAME}\` tool`,
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
const object = yield* tool._decode(call.input).pipe(Effect.mapError((error) => new AIError({
|
|
51
|
+
reason: new InvalidProviderOutputError({
|
|
52
|
+
message: `generateObject: tool input failed schema decode: ${error.message}`,
|
|
53
|
+
cause: error,
|
|
54
|
+
}),
|
|
55
|
+
})));
|
|
56
|
+
return new GenerateObjectResponse(object, response);
|
|
57
|
+
});
|
|
58
|
+
export function generateObject(options) {
|
|
59
|
+
if ("schema" in options) {
|
|
60
|
+
const { schema, ...rest } = options;
|
|
61
|
+
return runGenerateObject(rest, makeTool({
|
|
62
|
+
description: GENERATE_OBJECT_TOOL_DESCRIPTION,
|
|
63
|
+
parameters: schema,
|
|
64
|
+
success: Schema.Unknown,
|
|
65
|
+
execute: () => Effect.void,
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
const { jsonSchema, ...rest } = options;
|
|
69
|
+
return runGenerateObject(rest, makeTool({
|
|
70
|
+
description: GENERATE_OBJECT_TOOL_DESCRIPTION,
|
|
71
|
+
jsonSchema,
|
|
72
|
+
execute: () => Effect.void,
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { Protocol } from "../route/protocol.js";
|
|
3
|
+
import { OpenAIChat } from "./openai-chat.js";
|
|
4
|
+
import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
5
|
+
export type ReasoningEffort = OpenResponsesOptions.ReasoningEffort;
|
|
6
|
+
declare const Options: Schema.Struct<{
|
|
7
|
+
readonly reasoningEffort: Schema.optional<Schema.declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>>;
|
|
8
|
+
readonly enableThinking: Schema.optional<Schema.Boolean>;
|
|
9
|
+
readonly thinkingBudget: Schema.optional<Schema.Int>;
|
|
10
|
+
readonly preserveThinking: Schema.optional<Schema.Boolean>;
|
|
11
|
+
readonly clearThinking: Schema.optional<Schema.Boolean>;
|
|
12
|
+
readonly thinking: Schema.optional<Schema.Struct<{
|
|
13
|
+
readonly type: Schema.declare<"disabled" | (string & {}) | "adaptive", "disabled" | (string & {}) | "adaptive">;
|
|
14
|
+
}>>;
|
|
15
|
+
readonly toolStream: Schema.optional<Schema.Boolean>;
|
|
16
|
+
readonly parallelToolCalls: Schema.optional<Schema.Boolean>;
|
|
17
|
+
readonly repetitionPenalty: Schema.optional<Schema.Number>;
|
|
18
|
+
readonly responseFormat: Schema.optional<Schema.Struct<{
|
|
19
|
+
readonly type: Schema.declare<(string & {}) | "text" | "json_schema" | "json_object", (string & {}) | "text" | "json_schema" | "json_object">;
|
|
20
|
+
readonly json_schema: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
21
|
+
}>>;
|
|
22
|
+
readonly enableSearch: Schema.optional<Schema.Boolean>;
|
|
23
|
+
readonly searchOptions: Schema.optional<Schema.Struct<{
|
|
24
|
+
readonly forced_search: Schema.optional<Schema.Boolean>;
|
|
25
|
+
readonly search_strategy: Schema.optional<Schema.declare<(string & {}) | "agent" | "max" | "turbo" | "agent_max", (string & {}) | "agent" | "max" | "turbo" | "agent_max">>;
|
|
26
|
+
readonly enable_search_extension: Schema.optional<Schema.Boolean>;
|
|
27
|
+
}>>;
|
|
28
|
+
}>;
|
|
29
|
+
export type OptionsInput = typeof Options.Type;
|
|
30
|
+
export declare const compatibility: {
|
|
31
|
+
maxTokensField: "max_completion_tokens";
|
|
32
|
+
supportsStore: false;
|
|
33
|
+
supportsStrictMode: false;
|
|
34
|
+
reasoningField: string;
|
|
35
|
+
zaiToolStream: false;
|
|
36
|
+
};
|
|
37
|
+
export declare const protocol: Protocol<{
|
|
38
|
+
readonly model: string;
|
|
39
|
+
readonly messages: readonly ({
|
|
40
|
+
readonly role: "system";
|
|
41
|
+
readonly content: string | readonly ({
|
|
42
|
+
readonly type: "text";
|
|
43
|
+
readonly text: string;
|
|
44
|
+
readonly cache_control?: {
|
|
45
|
+
readonly type: "ephemeral";
|
|
46
|
+
readonly ttl?: string | undefined;
|
|
47
|
+
} | undefined;
|
|
48
|
+
} | {
|
|
49
|
+
readonly type: "image_url";
|
|
50
|
+
readonly image_url: {
|
|
51
|
+
readonly url: string;
|
|
52
|
+
};
|
|
53
|
+
})[];
|
|
54
|
+
} | {
|
|
55
|
+
readonly role: "user";
|
|
56
|
+
readonly content: string | readonly ({
|
|
57
|
+
readonly type: "text";
|
|
58
|
+
readonly text: string;
|
|
59
|
+
readonly cache_control?: {
|
|
60
|
+
readonly type: "ephemeral";
|
|
61
|
+
readonly ttl?: string | undefined;
|
|
62
|
+
} | undefined;
|
|
63
|
+
} | {
|
|
64
|
+
readonly type: "image_url";
|
|
65
|
+
readonly image_url: {
|
|
66
|
+
readonly url: string;
|
|
67
|
+
};
|
|
68
|
+
})[];
|
|
69
|
+
} | {
|
|
70
|
+
readonly [x: string]: unknown;
|
|
71
|
+
readonly content: string | null;
|
|
72
|
+
readonly role: "assistant";
|
|
73
|
+
readonly reasoning?: string | undefined;
|
|
74
|
+
readonly reasoning_content?: string | undefined;
|
|
75
|
+
readonly reasoning_text?: string | undefined;
|
|
76
|
+
readonly cache_control?: {
|
|
77
|
+
readonly type: "ephemeral";
|
|
78
|
+
readonly ttl?: string | undefined;
|
|
79
|
+
} | undefined;
|
|
80
|
+
readonly tool_calls?: readonly {
|
|
81
|
+
readonly id: string;
|
|
82
|
+
readonly type: "function";
|
|
83
|
+
readonly function: {
|
|
84
|
+
readonly name: string;
|
|
85
|
+
readonly arguments: string;
|
|
86
|
+
};
|
|
87
|
+
}[] | undefined;
|
|
88
|
+
readonly reasoning_details?: unknown;
|
|
89
|
+
} | {
|
|
90
|
+
readonly content: string;
|
|
91
|
+
readonly role: "tool";
|
|
92
|
+
readonly tool_call_id: string;
|
|
93
|
+
readonly cache_control?: {
|
|
94
|
+
readonly type: "ephemeral";
|
|
95
|
+
readonly ttl?: string | undefined;
|
|
96
|
+
} | undefined;
|
|
97
|
+
})[];
|
|
98
|
+
readonly stream: true;
|
|
99
|
+
readonly max_completion_tokens?: number | undefined;
|
|
100
|
+
readonly max_tokens?: number | undefined;
|
|
101
|
+
readonly tools?: readonly {
|
|
102
|
+
readonly function: {
|
|
103
|
+
readonly description: string;
|
|
104
|
+
readonly name: string;
|
|
105
|
+
readonly parameters: {
|
|
106
|
+
readonly [x: string]: unknown;
|
|
107
|
+
};
|
|
108
|
+
readonly strict?: boolean | undefined;
|
|
109
|
+
};
|
|
110
|
+
readonly type: "function";
|
|
111
|
+
readonly cache_control?: {
|
|
112
|
+
readonly type: "ephemeral";
|
|
113
|
+
readonly ttl?: string | undefined;
|
|
114
|
+
} | undefined;
|
|
115
|
+
}[] | undefined;
|
|
116
|
+
readonly stop?: readonly string[] | undefined;
|
|
117
|
+
readonly temperature?: number | undefined;
|
|
118
|
+
readonly seed?: number | undefined;
|
|
119
|
+
readonly thinking?: {
|
|
120
|
+
readonly type: "disabled" | (string & {}) | "adaptive";
|
|
121
|
+
} | undefined;
|
|
122
|
+
readonly tool_choice?: "required" | "auto" | "none" | {
|
|
123
|
+
readonly type: "function";
|
|
124
|
+
readonly function: {
|
|
125
|
+
readonly name: string;
|
|
126
|
+
};
|
|
127
|
+
} | undefined;
|
|
128
|
+
readonly top_p?: number | undefined;
|
|
129
|
+
readonly top_k?: number | undefined;
|
|
130
|
+
readonly frequency_penalty?: number | undefined;
|
|
131
|
+
readonly presence_penalty?: number | undefined;
|
|
132
|
+
readonly prompt_cache_key?: string | undefined;
|
|
133
|
+
readonly parallel_tool_calls?: boolean | undefined;
|
|
134
|
+
readonly reasoning_effort?: OpenResponsesOptions.ReasoningEffort | undefined;
|
|
135
|
+
readonly store?: boolean | undefined;
|
|
136
|
+
readonly stream_options?: {
|
|
137
|
+
readonly include_usage: boolean;
|
|
138
|
+
} | undefined;
|
|
139
|
+
readonly tool_stream?: boolean | undefined;
|
|
140
|
+
readonly enable_thinking?: boolean | undefined;
|
|
141
|
+
readonly thinking_budget?: number | undefined;
|
|
142
|
+
readonly preserve_thinking?: boolean | undefined;
|
|
143
|
+
readonly clear_thinking?: boolean | undefined;
|
|
144
|
+
readonly repetition_penalty?: number | undefined;
|
|
145
|
+
readonly response_format?: {
|
|
146
|
+
readonly type: (string & {}) | "text" | "json_schema" | "json_object";
|
|
147
|
+
readonly json_schema?: {
|
|
148
|
+
readonly [x: string]: unknown;
|
|
149
|
+
} | undefined;
|
|
150
|
+
} | undefined;
|
|
151
|
+
readonly enable_search?: boolean | undefined;
|
|
152
|
+
readonly search_options?: {
|
|
153
|
+
readonly forced_search?: boolean | undefined;
|
|
154
|
+
readonly search_strategy?: (string & {}) | "agent" | "max" | "turbo" | "agent_max" | undefined;
|
|
155
|
+
readonly enable_search_extension?: boolean | undefined;
|
|
156
|
+
} | undefined;
|
|
157
|
+
}, string, "[DONE]" | {
|
|
158
|
+
readonly [x: string]: unknown;
|
|
159
|
+
readonly error?: {
|
|
160
|
+
readonly [x: string]: unknown;
|
|
161
|
+
readonly message: string;
|
|
162
|
+
readonly code?: string | number | null | undefined;
|
|
163
|
+
} | null | undefined;
|
|
164
|
+
readonly usage?: {
|
|
165
|
+
readonly [x: string]: unknown;
|
|
166
|
+
readonly cached_tokens?: number | null | undefined;
|
|
167
|
+
readonly prompt_tokens?: number | null | undefined;
|
|
168
|
+
readonly completion_tokens?: number | null | undefined;
|
|
169
|
+
readonly total_tokens?: number | null | undefined;
|
|
170
|
+
readonly prompt_tokens_details?: {
|
|
171
|
+
readonly [x: string]: unknown;
|
|
172
|
+
readonly cached_tokens?: number | null | undefined;
|
|
173
|
+
readonly cache_write_tokens?: number | null | undefined;
|
|
174
|
+
} | null | undefined;
|
|
175
|
+
readonly prompt_cache_hit_tokens?: number | null | undefined;
|
|
176
|
+
readonly completion_tokens_details?: {
|
|
177
|
+
readonly [x: string]: unknown;
|
|
178
|
+
readonly reasoning_tokens?: number | null | undefined;
|
|
179
|
+
readonly accepted_prediction_tokens?: number | null | undefined;
|
|
180
|
+
readonly rejected_prediction_tokens?: number | null | undefined;
|
|
181
|
+
} | null | undefined;
|
|
182
|
+
} | null | undefined;
|
|
183
|
+
readonly choices?: readonly {
|
|
184
|
+
readonly [x: string]: unknown;
|
|
185
|
+
readonly delta?: {
|
|
186
|
+
readonly [x: string]: unknown;
|
|
187
|
+
readonly reasoning?: string | null | undefined;
|
|
188
|
+
readonly reasoning_content?: string | null | undefined;
|
|
189
|
+
readonly reasoning_text?: string | null | undefined;
|
|
190
|
+
readonly content?: string | null | undefined;
|
|
191
|
+
readonly refusal?: string | null | undefined;
|
|
192
|
+
readonly tool_calls?: readonly {
|
|
193
|
+
readonly function?: {
|
|
194
|
+
readonly name?: string | null | undefined;
|
|
195
|
+
readonly arguments?: string | null | undefined;
|
|
196
|
+
} | null | undefined;
|
|
197
|
+
readonly id?: string | null | undefined;
|
|
198
|
+
readonly index?: number | null | undefined;
|
|
199
|
+
}[] | null | undefined;
|
|
200
|
+
readonly reasoning_details?: unknown;
|
|
201
|
+
} | null | undefined;
|
|
202
|
+
readonly usage?: {
|
|
203
|
+
readonly [x: string]: unknown;
|
|
204
|
+
readonly cached_tokens?: number | null | undefined;
|
|
205
|
+
readonly prompt_tokens?: number | null | undefined;
|
|
206
|
+
readonly completion_tokens?: number | null | undefined;
|
|
207
|
+
readonly total_tokens?: number | null | undefined;
|
|
208
|
+
readonly prompt_tokens_details?: {
|
|
209
|
+
readonly [x: string]: unknown;
|
|
210
|
+
readonly cached_tokens?: number | null | undefined;
|
|
211
|
+
readonly cache_write_tokens?: number | null | undefined;
|
|
212
|
+
} | null | undefined;
|
|
213
|
+
readonly prompt_cache_hit_tokens?: number | null | undefined;
|
|
214
|
+
readonly completion_tokens_details?: {
|
|
215
|
+
readonly [x: string]: unknown;
|
|
216
|
+
readonly reasoning_tokens?: number | null | undefined;
|
|
217
|
+
readonly accepted_prediction_tokens?: number | null | undefined;
|
|
218
|
+
readonly rejected_prediction_tokens?: number | null | undefined;
|
|
219
|
+
} | null | undefined;
|
|
220
|
+
} | null | undefined;
|
|
221
|
+
readonly finish_reason?: string | null | undefined;
|
|
222
|
+
readonly native_finish_reason?: string | null | undefined;
|
|
223
|
+
}[] | null | undefined;
|
|
224
|
+
}, OpenAIChat.ParserState>;
|
|
225
|
+
export * as AlibabaChat from "./alibaba-chat.js";
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Protocol } from "../route/protocol.js";
|
|
3
|
+
import { OpenAIChat } from "./openai-chat.js";
|
|
4
|
+
import { JsonObject, ProviderShared } from "./shared.js";
|
|
5
|
+
import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
6
|
+
const Options = Schema.Struct({
|
|
7
|
+
reasoningEffort: OpenResponsesOptions.Options.fields.reasoningEffort,
|
|
8
|
+
enableThinking: Schema.optional(Schema.Boolean),
|
|
9
|
+
thinkingBudget: Schema.optional(Schema.Int),
|
|
10
|
+
preserveThinking: Schema.optional(Schema.Boolean),
|
|
11
|
+
clearThinking: Schema.optional(Schema.Boolean),
|
|
12
|
+
thinking: Schema.optional(Schema.Struct({
|
|
13
|
+
type: Schema.declare(Schema.is(Schema.String)),
|
|
14
|
+
})),
|
|
15
|
+
toolStream: Schema.optional(Schema.Boolean),
|
|
16
|
+
parallelToolCalls: OpenResponsesOptions.Options.fields.parallelToolCalls,
|
|
17
|
+
repetitionPenalty: Schema.optional(Schema.Number),
|
|
18
|
+
responseFormat: Schema.optional(Schema.Struct({
|
|
19
|
+
type: Schema.declare(Schema.is(Schema.String)),
|
|
20
|
+
json_schema: Schema.optional(JsonObject),
|
|
21
|
+
})),
|
|
22
|
+
enableSearch: Schema.optional(Schema.Boolean),
|
|
23
|
+
searchOptions: Schema.optional(Schema.Struct({
|
|
24
|
+
forced_search: Schema.optional(Schema.Boolean),
|
|
25
|
+
search_strategy: Schema.optional(Schema.declare(Schema.is(Schema.String))),
|
|
26
|
+
enable_search_extension: Schema.optional(Schema.Boolean),
|
|
27
|
+
})),
|
|
28
|
+
});
|
|
29
|
+
export const compatibility = {
|
|
30
|
+
maxTokensField: "max_completion_tokens",
|
|
31
|
+
supportsStore: false,
|
|
32
|
+
supportsStrictMode: false,
|
|
33
|
+
reasoningField: "reasoning_content",
|
|
34
|
+
zaiToolStream: false,
|
|
35
|
+
};
|
|
36
|
+
export const protocol = Protocol.make({
|
|
37
|
+
id: "alibaba-chat",
|
|
38
|
+
body: {
|
|
39
|
+
schema: Schema.Struct({
|
|
40
|
+
...OpenAIChat.bodyFields,
|
|
41
|
+
enable_thinking: Options.fields.enableThinking,
|
|
42
|
+
thinking_budget: Options.fields.thinkingBudget,
|
|
43
|
+
preserve_thinking: Options.fields.preserveThinking,
|
|
44
|
+
clear_thinking: Options.fields.clearThinking,
|
|
45
|
+
thinking: Options.fields.thinking,
|
|
46
|
+
parallel_tool_calls: Options.fields.parallelToolCalls,
|
|
47
|
+
repetition_penalty: Options.fields.repetitionPenalty,
|
|
48
|
+
top_k: Schema.optional(Schema.Int),
|
|
49
|
+
response_format: Options.fields.responseFormat,
|
|
50
|
+
enable_search: Options.fields.enableSearch,
|
|
51
|
+
search_options: Options.fields.searchOptions,
|
|
52
|
+
}),
|
|
53
|
+
from: Effect.fn("AlibabaChat.fromRequest")(function* (req) {
|
|
54
|
+
const opts = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(req.providerOptions ?? {});
|
|
55
|
+
return {
|
|
56
|
+
...(yield* OpenAIChat.protocol.body.from(req)),
|
|
57
|
+
enable_thinking: opts.enableThinking,
|
|
58
|
+
thinking_budget: opts.thinkingBudget,
|
|
59
|
+
preserve_thinking: opts.preserveThinking,
|
|
60
|
+
clear_thinking: opts.clearThinking,
|
|
61
|
+
thinking: opts.thinking,
|
|
62
|
+
tool_stream: opts.toolStream,
|
|
63
|
+
parallel_tool_calls: opts.parallelToolCalls ??
|
|
64
|
+
(req.toolChoice?.disableParallelToolUse === undefined ? undefined : !req.toolChoice.disableParallelToolUse),
|
|
65
|
+
repetition_penalty: opts.repetitionPenalty,
|
|
66
|
+
top_k: req.generation?.topK,
|
|
67
|
+
response_format: opts.responseFormat,
|
|
68
|
+
enable_search: opts.enableSearch,
|
|
69
|
+
search_options: opts.searchOptions,
|
|
70
|
+
};
|
|
71
|
+
}),
|
|
72
|
+
},
|
|
73
|
+
stream: OpenAIChat.protocol.stream,
|
|
74
|
+
});
|
|
75
|
+
export * as AlibabaChat from "./alibaba-chat.js";
|