@opencode-ai/ai 0.0.0-bootstrap.0 → 0.0.0-dev-17472
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 +390 -1
- package/dist/cache-policy.d.ts +2 -0
- package/dist/cache-policy.js +121 -0
- package/dist/image-client.d.ts +19 -0
- package/dist/image-client.js +19 -0
- package/dist/image.d.ts +110 -0
- package/dist/image.js +102 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +12 -0
- package/dist/llm.d.ts +230 -0
- package/dist/llm.js +77 -0
- package/dist/protocols/anthropic-messages.d.ts +633 -0
- package/dist/protocols/anthropic-messages.js +860 -0
- package/dist/protocols/bedrock-converse.d.ts +533 -0
- package/dist/protocols/bedrock-converse.js +584 -0
- package/dist/protocols/bedrock-event-stream.d.ts +9 -0
- package/dist/protocols/bedrock-event-stream.js +73 -0
- package/dist/protocols/gemini.d.ts +300 -0
- package/dist/protocols/gemini.js +512 -0
- package/dist/protocols/google-images.d.ts +30 -0
- package/dist/protocols/google-images.js +191 -0
- package/dist/protocols/index.d.ts +10 -0
- package/dist/protocols/index.js +10 -0
- package/dist/protocols/open-responses-channel.d.ts +26 -0
- package/dist/protocols/open-responses-channel.js +120 -0
- package/dist/protocols/open-responses.d.ts +951 -0
- package/dist/protocols/open-responses.js +873 -0
- package/dist/protocols/openai-chat.d.ts +795 -0
- package/dist/protocols/openai-chat.js +718 -0
- package/dist/protocols/openai-compatible-chat.d.ts +107 -0
- package/dist/protocols/openai-compatible-chat.js +20 -0
- package/dist/protocols/openai-compatible-responses.d.ts +96 -0
- package/dist/protocols/openai-compatible-responses.js +17 -0
- package/dist/protocols/openai-images.d.ts +32 -0
- package/dist/protocols/openai-images.js +188 -0
- package/dist/protocols/openai-responses-channel.d.ts +12 -0
- package/dist/protocols/openai-responses-channel.js +142 -0
- package/dist/protocols/openai-responses.d.ts +596 -0
- package/dist/protocols/openai-responses.js +208 -0
- package/dist/protocols/shared.d.ts +194 -0
- package/dist/protocols/shared.js +238 -0
- package/dist/protocols/utils/bedrock-auth.d.ts +21 -0
- package/dist/protocols/utils/bedrock-auth.js +43 -0
- package/dist/protocols/utils/bedrock-cache.d.ts +15 -0
- package/dist/protocols/utils/bedrock-cache.js +29 -0
- package/dist/protocols/utils/bedrock-media.d.ts +49 -0
- package/dist/protocols/utils/bedrock-media.js +70 -0
- package/dist/protocols/utils/cache.d.ts +6 -0
- package/dist/protocols/utils/cache.js +8 -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 +22 -0
- package/dist/protocols/utils/lifecycle.d.ts +20 -0
- package/dist/protocols/utils/lifecycle.js +68 -0
- package/dist/protocols/utils/open-responses-options.d.ts +21 -0
- package/dist/protocols/utils/open-responses-options.js +41 -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 +14 -0
- package/dist/protocols/utils/openai-options.js +14 -0
- package/dist/protocols/utils/tool-schema.d.ts +8 -0
- package/dist/protocols/utils/tool-schema.js +81 -0
- package/dist/protocols/utils/tool-stream.d.ts +639 -0
- package/dist/protocols/utils/tool-stream.js +141 -0
- package/dist/protocols/xai-images.d.ts +26 -0
- package/dist/protocols/xai-images.js +111 -0
- package/dist/protocols/zai-images.d.ts +22 -0
- package/dist/protocols/zai-images.js +84 -0
- package/dist/protocols.d.ts +1 -0
- package/dist/protocols.js +1 -0
- package/dist/provider-error.d.ts +14 -0
- package/dist/provider-error.js +130 -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/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 +247 -0
- package/dist/providers/amazon-bedrock-mantle.js +68 -0
- package/dist/providers/amazon-bedrock.d.ts +172 -0
- package/dist/providers/amazon-bedrock.js +41 -0
- package/dist/providers/anthropic-compatible.d.ts +218 -0
- package/dist/providers/anthropic-compatible.js +45 -0
- package/dist/providers/anthropic.d.ts +216 -0
- package/dist/providers/anthropic.js +40 -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 +248 -0
- package/dist/providers/azure.js +90 -0
- package/dist/providers/cloudflare.d.ts +338 -0
- package/dist/providers/cloudflare.js +87 -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 +131 -0
- package/dist/providers/google-vertex-chat.js +50 -0
- package/dist/providers/google-vertex-messages.d.ts +215 -0
- package/dist/providers/google-vertex-messages.js +75 -0
- package/dist/providers/google-vertex-responses.d.ts +122 -0
- package/dist/providers/google-vertex-responses.js +51 -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 +115 -0
- package/dist/providers/google-vertex.js +64 -0
- package/dist/providers/google.d.ts +112 -0
- package/dist/providers/google.js +43 -0
- package/dist/providers/index.d.ts +18 -0
- package/dist/providers/index.js +18 -0
- package/dist/providers/open-responses-options.d.ts +16 -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-profile.d.ts +43 -0
- package/dist/providers/openai-compatible-profile.js +12 -0
- package/dist/providers/openai-compatible-responses.d.ts +120 -0
- package/dist/providers/openai-compatible-responses.js +33 -0
- package/dist/providers/openai-compatible.d.ts +167 -0
- package/dist/providers/openai-compatible.js +55 -0
- package/dist/providers/openai-options.d.ts +21 -0
- package/dist/providers/openai-options.js +41 -0
- package/dist/providers/openai.d.ts +264 -0
- package/dist/providers/openai.js +83 -0
- package/dist/providers/openrouter.d.ts +537 -0
- package/dist/providers/openrouter.js +117 -0
- package/dist/providers/xai.d.ts +249 -0
- package/dist/providers/xai.js +79 -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 +89 -0
- package/dist/route/client.d.ts +348 -0
- package/dist/route/client.js +214 -0
- package/dist/route/endpoint.d.ts +28 -0
- package/dist/route/endpoint.js +21 -0
- package/dist/route/executor.d.ts +23 -0
- package/dist/route/executor.js +227 -0
- package/dist/route/framing.d.ts +23 -0
- package/dist/route/framing.js +4 -0
- package/dist/route/index.d.ts +16 -0
- package/dist/route/index.js +9 -0
- package/dist/route/protocol.d.ts +77 -0
- package/dist/route/protocol.js +17 -0
- package/dist/route/transport/http.d.ts +34 -0
- package/dist/route/transport/http.js +63 -0
- package/dist/route/transport/index.d.ts +39 -0
- package/dist/route/transport/index.js +4 -0
- package/dist/route/transport/websocket-channel.d.ts +56 -0
- package/dist/route/transport/websocket-channel.js +1 -0
- package/dist/route/transport/websocket.d.ts +55 -0
- package/dist/route/transport/websocket.js +326 -0
- package/dist/route.d.ts +1 -0
- package/dist/route.js +1 -0
- package/dist/schema/errors.d.ts +159 -0
- package/dist/schema/errors.js +155 -0
- package/dist/schema/events.d.ts +4587 -0
- package/dist/schema/events.js +492 -0
- package/dist/schema/ids.d.ts +30 -0
- package/dist/schema/ids.js +19 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/messages.d.ts +402 -0
- package/dist/schema/messages.js +244 -0
- package/dist/schema/options.d.ts +159 -0
- package/dist/schema/options.js +202 -0
- package/dist/testing.d.ts +1493 -0
- package/dist/testing.js +88 -0
- package/dist/tool-runtime.d.ts +15 -0
- package/dist/tool-runtime.js +54 -0
- package/dist/tool.d.ts +135 -0
- package/dist/tool.js +66 -0
- package/dist/utils/record.d.ts +2 -0
- package/dist/utils/record.js +2 -0
- package/package.json +40 -9
- package/index.js +0 -1
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { Tool } from "@opencode-ai/schema/tool";
|
|
3
|
+
import { CacheHint, GenerationOptions, HttpOptions } from "./options.js";
|
|
4
|
+
declare const systemPartSchema: Schema.Struct<{
|
|
5
|
+
readonly type: Schema.Literal<"text">;
|
|
6
|
+
readonly text: Schema.String;
|
|
7
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
8
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
9
|
+
}>;
|
|
10
|
+
export type SystemPart = Schema.Schema.Type<typeof systemPartSchema>;
|
|
11
|
+
export declare const SystemPart: Schema.Struct<{
|
|
12
|
+
readonly type: Schema.Literal<"text">;
|
|
13
|
+
readonly text: Schema.String;
|
|
14
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
15
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
16
|
+
}> & {
|
|
17
|
+
make: (text: string) => SystemPart;
|
|
18
|
+
content: (input?: string | SystemPart | ReadonlyArray<SystemPart>) => any[];
|
|
19
|
+
};
|
|
20
|
+
export declare const TextPart: Schema.Struct<{
|
|
21
|
+
readonly type: Schema.Literal<"text">;
|
|
22
|
+
readonly text: Schema.String;
|
|
23
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
24
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
25
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
26
|
+
}>;
|
|
27
|
+
export type TextPart = Schema.Schema.Type<typeof TextPart>;
|
|
28
|
+
export declare const MediaPart: Schema.Struct<{
|
|
29
|
+
readonly type: Schema.Literal<"media">;
|
|
30
|
+
readonly mediaType: Schema.String;
|
|
31
|
+
readonly data: Schema.Union<readonly [Schema.String, Schema.Uint8Array]>;
|
|
32
|
+
readonly filename: Schema.optional<Schema.String>;
|
|
33
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
34
|
+
}>;
|
|
35
|
+
export type MediaPart = Schema.Schema.Type<typeof MediaPart>;
|
|
36
|
+
declare const toolResultValueSchema: Schema.Union<readonly [Schema.Struct<{
|
|
37
|
+
readonly type: Schema.Literal<"json">;
|
|
38
|
+
readonly value: Schema.Unknown;
|
|
39
|
+
}>, Schema.Struct<{
|
|
40
|
+
readonly type: Schema.Literal<"text">;
|
|
41
|
+
readonly value: Schema.Unknown;
|
|
42
|
+
}>, Schema.Struct<{
|
|
43
|
+
readonly type: Schema.Literal<"error">;
|
|
44
|
+
readonly value: Schema.Unknown;
|
|
45
|
+
}>, Schema.Struct<{
|
|
46
|
+
readonly type: Schema.Literal<"content">;
|
|
47
|
+
readonly value: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
48
|
+
readonly type: Schema.Literal<"text">;
|
|
49
|
+
readonly text: Schema.String;
|
|
50
|
+
}>, Schema.Struct<{
|
|
51
|
+
readonly type: Schema.Literal<"file">;
|
|
52
|
+
readonly uri: Schema.String;
|
|
53
|
+
readonly mime: Schema.String;
|
|
54
|
+
readonly name: Schema.optional<Schema.String>;
|
|
55
|
+
}>]>>;
|
|
56
|
+
}>]>;
|
|
57
|
+
export type ToolResultValue = Schema.Schema.Type<typeof toolResultValueSchema>;
|
|
58
|
+
export declare const ToolResultValue: Schema.Union<readonly [Schema.Struct<{
|
|
59
|
+
readonly type: Schema.Literal<"json">;
|
|
60
|
+
readonly value: Schema.Unknown;
|
|
61
|
+
}>, Schema.Struct<{
|
|
62
|
+
readonly type: Schema.Literal<"text">;
|
|
63
|
+
readonly value: Schema.Unknown;
|
|
64
|
+
}>, Schema.Struct<{
|
|
65
|
+
readonly type: Schema.Literal<"error">;
|
|
66
|
+
readonly value: Schema.Unknown;
|
|
67
|
+
}>, Schema.Struct<{
|
|
68
|
+
readonly type: Schema.Literal<"content">;
|
|
69
|
+
readonly value: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
70
|
+
readonly type: Schema.Literal<"text">;
|
|
71
|
+
readonly text: Schema.String;
|
|
72
|
+
}>, Schema.Struct<{
|
|
73
|
+
readonly type: Schema.Literal<"file">;
|
|
74
|
+
readonly uri: Schema.String;
|
|
75
|
+
readonly mime: Schema.String;
|
|
76
|
+
readonly name: Schema.optional<Schema.String>;
|
|
77
|
+
}>]>>;
|
|
78
|
+
}>]> & {
|
|
79
|
+
is: (value: unknown) => value is ToolResultValue;
|
|
80
|
+
make: (value: unknown, type?: ToolResultValue["type"]) => ToolResultValue;
|
|
81
|
+
};
|
|
82
|
+
export interface ToolOutput {
|
|
83
|
+
readonly structured: unknown;
|
|
84
|
+
readonly content: ReadonlyArray<Tool.Content>;
|
|
85
|
+
}
|
|
86
|
+
export declare const ToolOutput: Schema.Struct<{
|
|
87
|
+
readonly structured: Schema.Unknown;
|
|
88
|
+
readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
89
|
+
readonly type: Schema.Literal<"text">;
|
|
90
|
+
readonly text: Schema.String;
|
|
91
|
+
}>, Schema.Struct<{
|
|
92
|
+
readonly type: Schema.Literal<"file">;
|
|
93
|
+
readonly uri: Schema.String;
|
|
94
|
+
readonly mime: Schema.String;
|
|
95
|
+
readonly name: Schema.optional<Schema.String>;
|
|
96
|
+
}>]>>;
|
|
97
|
+
}> & {
|
|
98
|
+
make: (structured: unknown, content?: ReadonlyArray<Tool.Content>) => ToolOutput;
|
|
99
|
+
fromResultValue: (result: ToolResultValue) => ToolOutput | undefined;
|
|
100
|
+
toResultValue: (output: ToolOutput) => ToolResultValue;
|
|
101
|
+
};
|
|
102
|
+
export declare const ToolCallPart: Schema.Struct<{
|
|
103
|
+
readonly type: Schema.Literal<"tool-call">;
|
|
104
|
+
readonly id: Schema.String;
|
|
105
|
+
readonly name: Schema.String;
|
|
106
|
+
readonly input: Schema.Unknown;
|
|
107
|
+
readonly providerExecuted: Schema.optional<Schema.Boolean>;
|
|
108
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
109
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
110
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
111
|
+
}> & {
|
|
112
|
+
make: (input: Omit<ToolCallPart, "type">) => ToolCallPart;
|
|
113
|
+
};
|
|
114
|
+
export type ToolCallPart = Schema.Schema.Type<typeof ToolCallPart>;
|
|
115
|
+
export declare const ToolResultPart: Schema.Struct<{
|
|
116
|
+
readonly type: Schema.Literal<"tool-result">;
|
|
117
|
+
readonly id: Schema.String;
|
|
118
|
+
readonly name: Schema.String;
|
|
119
|
+
readonly result: Schema.Union<readonly [Schema.Struct<{
|
|
120
|
+
readonly type: Schema.Literal<"json">;
|
|
121
|
+
readonly value: Schema.Unknown;
|
|
122
|
+
}>, Schema.Struct<{
|
|
123
|
+
readonly type: Schema.Literal<"text">;
|
|
124
|
+
readonly value: Schema.Unknown;
|
|
125
|
+
}>, Schema.Struct<{
|
|
126
|
+
readonly type: Schema.Literal<"error">;
|
|
127
|
+
readonly value: Schema.Unknown;
|
|
128
|
+
}>, Schema.Struct<{
|
|
129
|
+
readonly type: Schema.Literal<"content">;
|
|
130
|
+
readonly value: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
131
|
+
readonly type: Schema.Literal<"text">;
|
|
132
|
+
readonly text: Schema.String;
|
|
133
|
+
}>, Schema.Struct<{
|
|
134
|
+
readonly type: Schema.Literal<"file">;
|
|
135
|
+
readonly uri: Schema.String;
|
|
136
|
+
readonly mime: Schema.String;
|
|
137
|
+
readonly name: Schema.optional<Schema.String>;
|
|
138
|
+
}>]>>;
|
|
139
|
+
}>]> & {
|
|
140
|
+
is: (value: unknown) => value is ToolResultValue;
|
|
141
|
+
make: (value: unknown, type?: ToolResultValue["type"]) => ToolResultValue;
|
|
142
|
+
};
|
|
143
|
+
readonly providerExecuted: Schema.optional<Schema.Boolean>;
|
|
144
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
145
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
146
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
147
|
+
}> & {
|
|
148
|
+
make: (input: Omit<ToolResultPart, "type" | "result"> & {
|
|
149
|
+
readonly result: unknown;
|
|
150
|
+
readonly resultType?: ToolResultValue["type"];
|
|
151
|
+
}) => ToolResultPart;
|
|
152
|
+
};
|
|
153
|
+
export type ToolResultPart = Schema.Schema.Type<typeof ToolResultPart>;
|
|
154
|
+
export declare const ReasoningPart: Schema.Struct<{
|
|
155
|
+
readonly type: Schema.Literal<"reasoning">;
|
|
156
|
+
readonly text: Schema.String;
|
|
157
|
+
readonly encrypted: Schema.optional<Schema.String>;
|
|
158
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
159
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
160
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
161
|
+
}>;
|
|
162
|
+
export type ReasoningPart = Schema.Schema.Type<typeof ReasoningPart>;
|
|
163
|
+
export declare const ContentPart: Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
164
|
+
readonly type: Schema.Literal<"text">;
|
|
165
|
+
readonly text: Schema.String;
|
|
166
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
167
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
168
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
169
|
+
}>, Schema.Struct<{
|
|
170
|
+
readonly type: Schema.Literal<"media">;
|
|
171
|
+
readonly mediaType: Schema.String;
|
|
172
|
+
readonly data: Schema.Union<readonly [Schema.String, Schema.Uint8Array]>;
|
|
173
|
+
readonly filename: Schema.optional<Schema.String>;
|
|
174
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
175
|
+
}>, Schema.Struct<{
|
|
176
|
+
readonly type: Schema.Literal<"tool-call">;
|
|
177
|
+
readonly id: Schema.String;
|
|
178
|
+
readonly name: Schema.String;
|
|
179
|
+
readonly input: Schema.Unknown;
|
|
180
|
+
readonly providerExecuted: Schema.optional<Schema.Boolean>;
|
|
181
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
182
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
183
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
184
|
+
}> & {
|
|
185
|
+
make: (input: Omit<ToolCallPart, "type">) => ToolCallPart;
|
|
186
|
+
}, Schema.Struct<{
|
|
187
|
+
readonly type: Schema.Literal<"tool-result">;
|
|
188
|
+
readonly id: Schema.String;
|
|
189
|
+
readonly name: Schema.String;
|
|
190
|
+
readonly result: Schema.Union<readonly [Schema.Struct<{
|
|
191
|
+
readonly type: Schema.Literal<"json">;
|
|
192
|
+
readonly value: Schema.Unknown;
|
|
193
|
+
}>, Schema.Struct<{
|
|
194
|
+
readonly type: Schema.Literal<"text">;
|
|
195
|
+
readonly value: Schema.Unknown;
|
|
196
|
+
}>, Schema.Struct<{
|
|
197
|
+
readonly type: Schema.Literal<"error">;
|
|
198
|
+
readonly value: Schema.Unknown;
|
|
199
|
+
}>, Schema.Struct<{
|
|
200
|
+
readonly type: Schema.Literal<"content">;
|
|
201
|
+
readonly value: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
202
|
+
readonly type: Schema.Literal<"text">;
|
|
203
|
+
readonly text: Schema.String;
|
|
204
|
+
}>, Schema.Struct<{
|
|
205
|
+
readonly type: Schema.Literal<"file">;
|
|
206
|
+
readonly uri: Schema.String;
|
|
207
|
+
readonly mime: Schema.String;
|
|
208
|
+
readonly name: Schema.optional<Schema.String>;
|
|
209
|
+
}>]>>;
|
|
210
|
+
}>]> & {
|
|
211
|
+
is: (value: unknown) => value is ToolResultValue;
|
|
212
|
+
make: (value: unknown, type?: ToolResultValue["type"]) => ToolResultValue;
|
|
213
|
+
};
|
|
214
|
+
readonly providerExecuted: Schema.optional<Schema.Boolean>;
|
|
215
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
216
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
217
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
218
|
+
}> & {
|
|
219
|
+
make: (input: Omit<ToolResultPart, "type" | "result"> & {
|
|
220
|
+
readonly result: unknown;
|
|
221
|
+
readonly resultType?: ToolResultValue["type"];
|
|
222
|
+
}) => ToolResultPart;
|
|
223
|
+
}, Schema.Struct<{
|
|
224
|
+
readonly type: Schema.Literal<"reasoning">;
|
|
225
|
+
readonly text: Schema.String;
|
|
226
|
+
readonly encrypted: Schema.optional<Schema.String>;
|
|
227
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
228
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
229
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
230
|
+
}>]>;
|
|
231
|
+
export type ContentPart = Schema.Schema.Type<typeof ContentPart>;
|
|
232
|
+
declare const Message_base: Schema.Class<Message, Schema.Struct<{
|
|
233
|
+
readonly id: Schema.optional<Schema.String>;
|
|
234
|
+
readonly role: Schema.Literals<readonly ["system", "user", "assistant", "tool"]>;
|
|
235
|
+
readonly content: Schema.$Array<Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
236
|
+
readonly type: Schema.Literal<"text">;
|
|
237
|
+
readonly text: Schema.String;
|
|
238
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
239
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
240
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
241
|
+
}>, Schema.Struct<{
|
|
242
|
+
readonly type: Schema.Literal<"media">;
|
|
243
|
+
readonly mediaType: Schema.String;
|
|
244
|
+
readonly data: Schema.Union<readonly [Schema.String, Schema.Uint8Array]>;
|
|
245
|
+
readonly filename: Schema.optional<Schema.String>;
|
|
246
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
247
|
+
}>, Schema.Struct<{
|
|
248
|
+
readonly type: Schema.Literal<"tool-call">;
|
|
249
|
+
readonly id: Schema.String;
|
|
250
|
+
readonly name: Schema.String;
|
|
251
|
+
readonly input: Schema.Unknown;
|
|
252
|
+
readonly providerExecuted: Schema.optional<Schema.Boolean>;
|
|
253
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
254
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
255
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
256
|
+
}> & {
|
|
257
|
+
make: (input: Omit<ToolCallPart, "type">) => ToolCallPart;
|
|
258
|
+
}, Schema.Struct<{
|
|
259
|
+
readonly type: Schema.Literal<"tool-result">;
|
|
260
|
+
readonly id: Schema.String;
|
|
261
|
+
readonly name: Schema.String;
|
|
262
|
+
readonly result: Schema.Union<readonly [Schema.Struct<{
|
|
263
|
+
readonly type: Schema.Literal<"json">;
|
|
264
|
+
readonly value: Schema.Unknown;
|
|
265
|
+
}>, Schema.Struct<{
|
|
266
|
+
readonly type: Schema.Literal<"text">;
|
|
267
|
+
readonly value: Schema.Unknown;
|
|
268
|
+
}>, Schema.Struct<{
|
|
269
|
+
readonly type: Schema.Literal<"error">;
|
|
270
|
+
readonly value: Schema.Unknown;
|
|
271
|
+
}>, Schema.Struct<{
|
|
272
|
+
readonly type: Schema.Literal<"content">;
|
|
273
|
+
readonly value: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
274
|
+
readonly type: Schema.Literal<"text">;
|
|
275
|
+
readonly text: Schema.String;
|
|
276
|
+
}>, Schema.Struct<{
|
|
277
|
+
readonly type: Schema.Literal<"file">;
|
|
278
|
+
readonly uri: Schema.String;
|
|
279
|
+
readonly mime: Schema.String;
|
|
280
|
+
readonly name: Schema.optional<Schema.String>;
|
|
281
|
+
}>]>>;
|
|
282
|
+
}>]> & {
|
|
283
|
+
is: (value: unknown) => value is ToolResultValue;
|
|
284
|
+
make: (value: unknown, type?: ToolResultValue["type"]) => ToolResultValue;
|
|
285
|
+
};
|
|
286
|
+
readonly providerExecuted: Schema.optional<Schema.Boolean>;
|
|
287
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
288
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
289
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
290
|
+
}> & {
|
|
291
|
+
make: (input: Omit<ToolResultPart, "type" | "result"> & {
|
|
292
|
+
readonly result: unknown;
|
|
293
|
+
readonly resultType?: ToolResultValue["type"];
|
|
294
|
+
}) => ToolResultPart;
|
|
295
|
+
}, Schema.Struct<{
|
|
296
|
+
readonly type: Schema.Literal<"reasoning">;
|
|
297
|
+
readonly text: Schema.String;
|
|
298
|
+
readonly encrypted: Schema.optional<Schema.String>;
|
|
299
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
300
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
301
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
302
|
+
}>]>>;
|
|
303
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
304
|
+
readonly native: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
305
|
+
}>, {}>;
|
|
306
|
+
export declare class Message extends Message_base {
|
|
307
|
+
}
|
|
308
|
+
export declare namespace Message {
|
|
309
|
+
type ContentInput = string | ContentPart | ReadonlyArray<ContentPart>;
|
|
310
|
+
type SystemContentInput = string | TextPart | ReadonlyArray<TextPart>;
|
|
311
|
+
type Input = Omit<ConstructorParameters<typeof Message>[0], "content"> & {
|
|
312
|
+
readonly content: ContentInput;
|
|
313
|
+
};
|
|
314
|
+
const text: (value: string) => ContentPart;
|
|
315
|
+
const content: (input: ContentInput) => any[];
|
|
316
|
+
const make: (input: Message | Input) => Message;
|
|
317
|
+
const user: (content: ContentInput) => Message;
|
|
318
|
+
const assistant: (content: ContentInput) => Message;
|
|
319
|
+
/**
|
|
320
|
+
* Add an operator-authored instruction at this chronological point in the
|
|
321
|
+
* conversation. This is distinct from the initial `LLMRequest.system`
|
|
322
|
+
* prompt. Keep raw retrieved, tool, and web content out of privileged system
|
|
323
|
+
* updates; pass that untrusted content through ordinary user/tool channels.
|
|
324
|
+
*/
|
|
325
|
+
const system: (content: SystemContentInput) => Message;
|
|
326
|
+
const tool: (result: ToolResultPart | Parameters<typeof ToolResultPart.make>[0]) => Message;
|
|
327
|
+
}
|
|
328
|
+
declare const ToolDefinition_base: Schema.Class<ToolDefinition, Schema.Struct<{
|
|
329
|
+
readonly name: Schema.String;
|
|
330
|
+
readonly description: Schema.String;
|
|
331
|
+
readonly inputSchema: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
332
|
+
readonly outputSchema: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
333
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
334
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
335
|
+
readonly native: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
336
|
+
}>, {}>;
|
|
337
|
+
export declare class ToolDefinition extends ToolDefinition_base {
|
|
338
|
+
}
|
|
339
|
+
export declare namespace ToolDefinition {
|
|
340
|
+
type Input = ToolDefinition | ConstructorParameters<typeof ToolDefinition>[0];
|
|
341
|
+
/** Normalize tool definition input into the canonical `ToolDefinition` class. */
|
|
342
|
+
const make: (input: Input) => ToolDefinition;
|
|
343
|
+
}
|
|
344
|
+
declare const ToolChoice_base: Schema.Class<ToolChoice, Schema.Struct<{
|
|
345
|
+
readonly type: Schema.Literals<readonly ["auto", "none", "required", "tool"]>;
|
|
346
|
+
readonly name: Schema.optional<Schema.String>;
|
|
347
|
+
}>, {}>;
|
|
348
|
+
export declare class ToolChoice extends ToolChoice_base {
|
|
349
|
+
}
|
|
350
|
+
export declare namespace ToolChoice {
|
|
351
|
+
type Mode = Exclude<ToolChoice["type"], "tool">;
|
|
352
|
+
type Input = ToolChoice | ConstructorParameters<typeof ToolChoice>[0] | ToolDefinition | string;
|
|
353
|
+
/** Select a specific named tool. */
|
|
354
|
+
const named: (value: string) => ToolChoice;
|
|
355
|
+
/** Normalize ergonomic tool-choice inputs into the canonical `ToolChoice` class. */
|
|
356
|
+
const make: (input: Input) => ToolChoice;
|
|
357
|
+
}
|
|
358
|
+
declare const LLMRequest_base: Schema.Class<LLMRequest, Schema.Struct<{
|
|
359
|
+
readonly id: Schema.optional<Schema.String>;
|
|
360
|
+
readonly model: Schema.declare<import("./options.js").LanguageModel<{
|
|
361
|
+
readonly [x: string]: {
|
|
362
|
+
readonly [x: string]: unknown;
|
|
363
|
+
};
|
|
364
|
+
}>, import("./options.js").LanguageModel<{
|
|
365
|
+
readonly [x: string]: {
|
|
366
|
+
readonly [x: string]: unknown;
|
|
367
|
+
};
|
|
368
|
+
}>>;
|
|
369
|
+
readonly system: Schema.$Array<Schema.Struct<{
|
|
370
|
+
readonly type: Schema.Literal<"text">;
|
|
371
|
+
readonly text: Schema.String;
|
|
372
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
373
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
374
|
+
}> & {
|
|
375
|
+
make: (text: string) => SystemPart;
|
|
376
|
+
content: (input?: string | SystemPart | ReadonlyArray<SystemPart>) => any[];
|
|
377
|
+
}>;
|
|
378
|
+
readonly messages: Schema.$Array<typeof Message>;
|
|
379
|
+
readonly tools: Schema.$Array<typeof ToolDefinition>;
|
|
380
|
+
readonly toolChoice: Schema.optional<typeof ToolChoice>;
|
|
381
|
+
readonly generation: Schema.optional<typeof GenerationOptions>;
|
|
382
|
+
readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
383
|
+
readonly http: Schema.optional<typeof HttpOptions>;
|
|
384
|
+
readonly cache: Schema.optional<Schema.Union<readonly [Schema.Literal<"auto">, Schema.Literal<"none">, Schema.Struct<{
|
|
385
|
+
readonly tools: Schema.optional<Schema.Boolean>;
|
|
386
|
+
readonly system: Schema.optional<Schema.Boolean>;
|
|
387
|
+
readonly messages: Schema.optional<Schema.Union<readonly [Schema.Literal<"latest-user-message">, Schema.Literal<"latest-assistant">, Schema.Struct<{
|
|
388
|
+
readonly tail: Schema.Number;
|
|
389
|
+
}>]>>;
|
|
390
|
+
readonly ttlSeconds: Schema.optional<Schema.Number>;
|
|
391
|
+
}>]>>;
|
|
392
|
+
readonly promptCacheKey: Schema.optional<Schema.String>;
|
|
393
|
+
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
394
|
+
}>, {}>;
|
|
395
|
+
export declare class LLMRequest extends LLMRequest_base {
|
|
396
|
+
}
|
|
397
|
+
export declare namespace LLMRequest {
|
|
398
|
+
type Input = ConstructorParameters<typeof LLMRequest>[0];
|
|
399
|
+
const input: (request: LLMRequest) => Input;
|
|
400
|
+
const update: (request: LLMRequest, patch: Partial<Input>) => LLMRequest;
|
|
401
|
+
}
|
|
402
|
+
export {};
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { Tool } from "@opencode-ai/schema/tool";
|
|
3
|
+
import { JsonSchema, MessageRole, ProviderMetadata } from "./ids.js";
|
|
4
|
+
import { CacheHint, CachePolicy, GenerationOptions, HttpOptions, LanguageModelSchema, ProviderOptions, } from "./options.js";
|
|
5
|
+
import { isRecord } from "../utils/record.js";
|
|
6
|
+
const systemPartSchema = Schema.Struct({
|
|
7
|
+
type: Schema.Literal("text"),
|
|
8
|
+
text: Schema.String,
|
|
9
|
+
cache: Schema.optional(CacheHint),
|
|
10
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
11
|
+
}).annotate({ identifier: "LLM.SystemPart" });
|
|
12
|
+
const makeSystemPart = (text) => ({ type: "text", text });
|
|
13
|
+
export const SystemPart = Object.assign(systemPartSchema, {
|
|
14
|
+
make: makeSystemPart,
|
|
15
|
+
content: (input) => {
|
|
16
|
+
if (input === undefined)
|
|
17
|
+
return [];
|
|
18
|
+
return typeof input === "string" ? [makeSystemPart(input)] : Array.isArray(input) ? [...input] : [input];
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
export const TextPart = Schema.Struct({
|
|
22
|
+
type: Schema.Literal("text"),
|
|
23
|
+
text: Schema.String,
|
|
24
|
+
cache: Schema.optional(CacheHint),
|
|
25
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
26
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
27
|
+
}).annotate({ identifier: "LLM.Content.Text" });
|
|
28
|
+
export const MediaPart = Schema.Struct({
|
|
29
|
+
type: Schema.Literal("media"),
|
|
30
|
+
mediaType: Schema.String,
|
|
31
|
+
data: Schema.Union([Schema.String, Schema.Uint8Array]),
|
|
32
|
+
filename: Schema.optional(Schema.String),
|
|
33
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
34
|
+
}).annotate({ identifier: "LLM.Content.Media" });
|
|
35
|
+
const isToolResultValue = (value) => isRecord(value) &&
|
|
36
|
+
(value.type === "text" || value.type === "json" || value.type === "error" || value.type === "content") &&
|
|
37
|
+
"value" in value;
|
|
38
|
+
const toolResultValueSchema = Schema.Union([
|
|
39
|
+
Schema.Struct({
|
|
40
|
+
type: Schema.Literal("json"),
|
|
41
|
+
value: Schema.Unknown,
|
|
42
|
+
}),
|
|
43
|
+
Schema.Struct({
|
|
44
|
+
type: Schema.Literal("text"),
|
|
45
|
+
value: Schema.Unknown,
|
|
46
|
+
}),
|
|
47
|
+
Schema.Struct({
|
|
48
|
+
type: Schema.Literal("error"),
|
|
49
|
+
value: Schema.Unknown,
|
|
50
|
+
}),
|
|
51
|
+
Schema.Struct({
|
|
52
|
+
type: Schema.Literal("content"),
|
|
53
|
+
value: Schema.Array(Tool.Content),
|
|
54
|
+
}),
|
|
55
|
+
]).annotate({ identifier: "LLM.ToolResult" });
|
|
56
|
+
export const ToolResultValue = Object.assign(toolResultValueSchema, {
|
|
57
|
+
is: isToolResultValue,
|
|
58
|
+
make: (value, type = "json") => {
|
|
59
|
+
if (isToolResultValue(value))
|
|
60
|
+
return value;
|
|
61
|
+
if (type === "content")
|
|
62
|
+
return { type, value: Array.isArray(value) ? value : [] };
|
|
63
|
+
return { type, value };
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
export const ToolOutput = Object.assign(Schema.Struct({
|
|
67
|
+
structured: Schema.Unknown,
|
|
68
|
+
content: Schema.Array(Tool.Content),
|
|
69
|
+
}).annotate({ identifier: "LLM.ToolOutput" }), {
|
|
70
|
+
make: (structured, content = []) => ({ structured, content }),
|
|
71
|
+
fromResultValue: (result) => {
|
|
72
|
+
switch (result.type) {
|
|
73
|
+
case "json":
|
|
74
|
+
return { structured: result.value, content: [] };
|
|
75
|
+
case "text":
|
|
76
|
+
return { structured: {}, content: [{ type: "text", text: toolResultText(result.value) }] };
|
|
77
|
+
case "content":
|
|
78
|
+
return { structured: {}, content: result.value };
|
|
79
|
+
case "error":
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
toResultValue: (output) => {
|
|
84
|
+
if (output.content.length === 0)
|
|
85
|
+
return { type: "json", value: output.structured };
|
|
86
|
+
if (output.content.length === 1 && output.content[0]?.type === "text")
|
|
87
|
+
return { type: "text", value: output.content[0].text };
|
|
88
|
+
return { type: "content", value: output.content };
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
const toolResultText = (value) => {
|
|
92
|
+
if (typeof value === "string")
|
|
93
|
+
return value;
|
|
94
|
+
try {
|
|
95
|
+
return JSON.stringify(value) ?? String(value);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return String(value);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
export const ToolCallPart = Object.assign(Schema.Struct({
|
|
102
|
+
type: Schema.Literal("tool-call"),
|
|
103
|
+
id: Schema.String,
|
|
104
|
+
name: Schema.String,
|
|
105
|
+
input: Schema.Unknown,
|
|
106
|
+
providerExecuted: Schema.optional(Schema.Boolean),
|
|
107
|
+
cache: Schema.optional(CacheHint),
|
|
108
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
109
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
110
|
+
}).annotate({ identifier: "LLM.Content.ToolCall" }), {
|
|
111
|
+
make: (input) => ({ type: "tool-call", ...input }),
|
|
112
|
+
});
|
|
113
|
+
export const ToolResultPart = Object.assign(Schema.Struct({
|
|
114
|
+
type: Schema.Literal("tool-result"),
|
|
115
|
+
id: Schema.String,
|
|
116
|
+
name: Schema.String,
|
|
117
|
+
result: ToolResultValue,
|
|
118
|
+
providerExecuted: Schema.optional(Schema.Boolean),
|
|
119
|
+
cache: Schema.optional(CacheHint),
|
|
120
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
121
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
122
|
+
}).annotate({ identifier: "LLM.Content.ToolResult" }), {
|
|
123
|
+
make: (input) => ({
|
|
124
|
+
type: "tool-result",
|
|
125
|
+
id: input.id,
|
|
126
|
+
name: input.name,
|
|
127
|
+
result: ToolResultValue.make(input.result, input.resultType),
|
|
128
|
+
providerExecuted: input.providerExecuted,
|
|
129
|
+
cache: input.cache,
|
|
130
|
+
metadata: input.metadata,
|
|
131
|
+
providerMetadata: input.providerMetadata,
|
|
132
|
+
}),
|
|
133
|
+
});
|
|
134
|
+
export const ReasoningPart = Schema.Struct({
|
|
135
|
+
type: Schema.Literal("reasoning"),
|
|
136
|
+
text: Schema.String,
|
|
137
|
+
encrypted: Schema.optional(Schema.String),
|
|
138
|
+
cache: Schema.optional(CacheHint),
|
|
139
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
140
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
141
|
+
}).annotate({ identifier: "LLM.Content.Reasoning" });
|
|
142
|
+
export const ContentPart = Schema.Union([TextPart, MediaPart, ToolCallPart, ToolResultPart, ReasoningPart]).pipe(Schema.toTaggedUnion("type"));
|
|
143
|
+
export class Message extends Schema.Class("LLM.Message")({
|
|
144
|
+
id: Schema.optional(Schema.String),
|
|
145
|
+
role: MessageRole,
|
|
146
|
+
content: Schema.Array(ContentPart),
|
|
147
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
148
|
+
native: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
149
|
+
}) {
|
|
150
|
+
}
|
|
151
|
+
(function (Message) {
|
|
152
|
+
Message.text = (value) => ({ type: "text", text: value });
|
|
153
|
+
Message.content = (input) => typeof input === "string" ? [Message.text(input)] : Array.isArray(input) ? [...input] : [input];
|
|
154
|
+
Message.make = (input) => {
|
|
155
|
+
if (input instanceof Message)
|
|
156
|
+
return input;
|
|
157
|
+
return new Message({ ...input, content: Message.content(input.content) });
|
|
158
|
+
};
|
|
159
|
+
Message.user = (content) => Message.make({ role: "user", content });
|
|
160
|
+
Message.assistant = (content) => Message.make({ role: "assistant", content });
|
|
161
|
+
/**
|
|
162
|
+
* Add an operator-authored instruction at this chronological point in the
|
|
163
|
+
* conversation. This is distinct from the initial `LLMRequest.system`
|
|
164
|
+
* prompt. Keep raw retrieved, tool, and web content out of privileged system
|
|
165
|
+
* updates; pass that untrusted content through ordinary user/tool channels.
|
|
166
|
+
*/
|
|
167
|
+
Message.system = (content) => Message.make({ role: "system", content });
|
|
168
|
+
Message.tool = (result) => Message.make({ role: "tool", content: ["type" in result ? result : ToolResultPart.make(result)] });
|
|
169
|
+
})(Message || (Message = {}));
|
|
170
|
+
export class ToolDefinition extends Schema.Class("LLM.ToolDefinition")({
|
|
171
|
+
name: Schema.String,
|
|
172
|
+
description: Schema.String,
|
|
173
|
+
inputSchema: JsonSchema,
|
|
174
|
+
outputSchema: Schema.optional(JsonSchema),
|
|
175
|
+
cache: Schema.optional(CacheHint),
|
|
176
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
177
|
+
native: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
178
|
+
}) {
|
|
179
|
+
}
|
|
180
|
+
(function (ToolDefinition) {
|
|
181
|
+
/** Normalize tool definition input into the canonical `ToolDefinition` class. */
|
|
182
|
+
ToolDefinition.make = (input) => (input instanceof ToolDefinition ? input : new ToolDefinition(input));
|
|
183
|
+
})(ToolDefinition || (ToolDefinition = {}));
|
|
184
|
+
export class ToolChoice extends Schema.Class("LLM.ToolChoice")({
|
|
185
|
+
type: Schema.Literals(["auto", "none", "required", "tool"]),
|
|
186
|
+
name: Schema.optional(Schema.String),
|
|
187
|
+
}) {
|
|
188
|
+
}
|
|
189
|
+
(function (ToolChoice) {
|
|
190
|
+
const isMode = (value) => value === "auto" || value === "none" || value === "required";
|
|
191
|
+
/** Select a specific named tool. */
|
|
192
|
+
ToolChoice.named = (value) => new ToolChoice({ type: "tool", name: value });
|
|
193
|
+
/** Normalize ergonomic tool-choice inputs into the canonical `ToolChoice` class. */
|
|
194
|
+
ToolChoice.make = (input) => {
|
|
195
|
+
if (input instanceof ToolChoice)
|
|
196
|
+
return input;
|
|
197
|
+
if (input instanceof ToolDefinition)
|
|
198
|
+
return ToolChoice.named(input.name);
|
|
199
|
+
if (typeof input === "string")
|
|
200
|
+
return isMode(input) ? new ToolChoice({ type: input }) : ToolChoice.named(input);
|
|
201
|
+
return new ToolChoice(input);
|
|
202
|
+
};
|
|
203
|
+
})(ToolChoice || (ToolChoice = {}));
|
|
204
|
+
export class LLMRequest extends Schema.Class("LLM.Request")({
|
|
205
|
+
id: Schema.optional(Schema.String),
|
|
206
|
+
model: LanguageModelSchema,
|
|
207
|
+
system: Schema.Array(SystemPart),
|
|
208
|
+
messages: Schema.Array(Message),
|
|
209
|
+
tools: Schema.Array(ToolDefinition),
|
|
210
|
+
toolChoice: Schema.optional(ToolChoice),
|
|
211
|
+
generation: Schema.optional(GenerationOptions),
|
|
212
|
+
providerOptions: Schema.optional(ProviderOptions),
|
|
213
|
+
http: Schema.optional(HttpOptions),
|
|
214
|
+
cache: Schema.optional(CachePolicy),
|
|
215
|
+
// Stable cache affinity for protocols that support provider-managed prompt caching.
|
|
216
|
+
promptCacheKey: Schema.optional(Schema.String),
|
|
217
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
218
|
+
}) {
|
|
219
|
+
}
|
|
220
|
+
(function (LLMRequest) {
|
|
221
|
+
LLMRequest.input = (request) => ({
|
|
222
|
+
id: request.id,
|
|
223
|
+
model: request.model,
|
|
224
|
+
system: request.system,
|
|
225
|
+
messages: request.messages,
|
|
226
|
+
tools: request.tools,
|
|
227
|
+
toolChoice: request.toolChoice,
|
|
228
|
+
generation: request.generation,
|
|
229
|
+
providerOptions: request.providerOptions,
|
|
230
|
+
http: request.http,
|
|
231
|
+
cache: request.cache,
|
|
232
|
+
promptCacheKey: request.promptCacheKey,
|
|
233
|
+
metadata: request.metadata,
|
|
234
|
+
});
|
|
235
|
+
LLMRequest.update = (request, patch) => {
|
|
236
|
+
if (Object.keys(patch).length === 0)
|
|
237
|
+
return request;
|
|
238
|
+
return new LLMRequest({
|
|
239
|
+
...LLMRequest.input(request),
|
|
240
|
+
...patch,
|
|
241
|
+
model: patch.model ?? request.model,
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
})(LLMRequest || (LLMRequest = {}));
|