@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
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
|
+
}
|