@opencode/ai 0.0.0-dev-20546 → 0.0.0-dev-20549
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 +35 -0
- package/dist/protocols/openai-chat.d.ts +396 -0
- package/dist/protocols/openai-chat.js +11 -9
- package/dist/protocols/venice-chat.d.ts +280 -0
- package/dist/protocols/venice-chat.js +283 -0
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.js +1 -0
- package/dist/providers/venice.d.ts +183 -0
- package/dist/providers/venice.js +38 -0
- package/package.json +3 -3
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { Protocol } from "../route/protocol.js";
|
|
3
|
+
import { OpenAIChat } from "./openai-chat.js";
|
|
4
|
+
export type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | (string & {});
|
|
5
|
+
declare const Parameters: Schema.Struct<{
|
|
6
|
+
readonly enableWebSearch: Schema.optional<Schema.String>;
|
|
7
|
+
readonly enableWebScraping: Schema.optional<Schema.Boolean>;
|
|
8
|
+
readonly enableWebCitations: Schema.optional<Schema.Boolean>;
|
|
9
|
+
readonly enableXSearch: Schema.optional<Schema.Boolean>;
|
|
10
|
+
readonly stripThinkingResponse: Schema.optional<Schema.Boolean>;
|
|
11
|
+
readonly disableThinking: Schema.optional<Schema.Boolean>;
|
|
12
|
+
readonly includeVeniceSystemPrompt: Schema.optional<Schema.Boolean>;
|
|
13
|
+
readonly characterSlug: Schema.optional<Schema.String>;
|
|
14
|
+
readonly includeSearchResultsInStream: Schema.optional<Schema.Boolean>;
|
|
15
|
+
readonly returnSearchResultsAsDocuments: Schema.optional<Schema.Boolean>;
|
|
16
|
+
}>;
|
|
17
|
+
export type OptionsInput = {
|
|
18
|
+
readonly reasoningEffort?: ReasoningEffort;
|
|
19
|
+
readonly reasoning?: {
|
|
20
|
+
readonly effort?: ReasoningEffort;
|
|
21
|
+
readonly enabled?: boolean;
|
|
22
|
+
readonly summary?: "auto" | "concise" | "detailed" | (string & {});
|
|
23
|
+
};
|
|
24
|
+
readonly veniceParameters?: Omit<typeof Parameters.Type, "enableWebSearch"> & {
|
|
25
|
+
readonly enableWebSearch?: "off" | "on" | "auto" | (string & {});
|
|
26
|
+
};
|
|
27
|
+
readonly promptCacheKey?: string;
|
|
28
|
+
readonly promptCacheRetention?: "default" | "extended" | "24h" | (string & {});
|
|
29
|
+
readonly parallelToolCalls?: boolean;
|
|
30
|
+
readonly maxCompletionTokens?: number;
|
|
31
|
+
readonly maxTokens?: number;
|
|
32
|
+
readonly minP?: number;
|
|
33
|
+
readonly repetitionPenalty?: number;
|
|
34
|
+
readonly stopTokenIds?: readonly number[];
|
|
35
|
+
readonly logprobs?: boolean;
|
|
36
|
+
readonly topLogprobs?: number;
|
|
37
|
+
readonly maxTemp?: number;
|
|
38
|
+
readonly minTemp?: number;
|
|
39
|
+
readonly responseFormat?: Readonly<Record<string, unknown>>;
|
|
40
|
+
readonly user?: string;
|
|
41
|
+
};
|
|
42
|
+
interface State {
|
|
43
|
+
readonly shared: OpenAIChat.ParserState;
|
|
44
|
+
readonly pending: string;
|
|
45
|
+
readonly reasoning: string;
|
|
46
|
+
readonly encrypted: boolean;
|
|
47
|
+
readonly signature?: string;
|
|
48
|
+
readonly tools: Readonly<Record<string, string>>;
|
|
49
|
+
}
|
|
50
|
+
export declare const compatibility: {
|
|
51
|
+
maxTokensField: "max_completion_tokens";
|
|
52
|
+
supportsStore: false;
|
|
53
|
+
supportsPromptCacheKey: true;
|
|
54
|
+
};
|
|
55
|
+
export declare const protocol: Protocol<{
|
|
56
|
+
readonly model: string;
|
|
57
|
+
readonly messages: readonly ({
|
|
58
|
+
readonly role: "system";
|
|
59
|
+
readonly content: string | readonly ({
|
|
60
|
+
readonly type: "text";
|
|
61
|
+
readonly text: string;
|
|
62
|
+
readonly cache_control?: {
|
|
63
|
+
readonly type: "ephemeral";
|
|
64
|
+
readonly ttl?: string | undefined;
|
|
65
|
+
} | undefined;
|
|
66
|
+
} | {
|
|
67
|
+
readonly type: "image_url";
|
|
68
|
+
readonly image_url: {
|
|
69
|
+
readonly url: string;
|
|
70
|
+
};
|
|
71
|
+
} | {
|
|
72
|
+
readonly type: "file";
|
|
73
|
+
readonly file: {
|
|
74
|
+
readonly filename: string;
|
|
75
|
+
readonly file_data: string;
|
|
76
|
+
};
|
|
77
|
+
})[];
|
|
78
|
+
} | {
|
|
79
|
+
readonly role: "user";
|
|
80
|
+
readonly content: string | readonly ({
|
|
81
|
+
readonly type: "text";
|
|
82
|
+
readonly text: string;
|
|
83
|
+
readonly cache_control?: {
|
|
84
|
+
readonly type: "ephemeral";
|
|
85
|
+
readonly ttl?: string | undefined;
|
|
86
|
+
} | undefined;
|
|
87
|
+
} | {
|
|
88
|
+
readonly type: "image_url";
|
|
89
|
+
readonly image_url: {
|
|
90
|
+
readonly url: string;
|
|
91
|
+
};
|
|
92
|
+
} | {
|
|
93
|
+
readonly type: "file";
|
|
94
|
+
readonly file: {
|
|
95
|
+
readonly filename: string;
|
|
96
|
+
readonly file_data: string;
|
|
97
|
+
};
|
|
98
|
+
})[];
|
|
99
|
+
} | {
|
|
100
|
+
readonly role: "tool";
|
|
101
|
+
readonly tool_call_id: string;
|
|
102
|
+
readonly content: string | readonly {
|
|
103
|
+
readonly type: "text";
|
|
104
|
+
readonly text: string;
|
|
105
|
+
readonly cache_control?: {
|
|
106
|
+
readonly type: "ephemeral";
|
|
107
|
+
readonly ttl?: string | undefined;
|
|
108
|
+
} | undefined;
|
|
109
|
+
}[];
|
|
110
|
+
} | {
|
|
111
|
+
readonly [x: string]: unknown;
|
|
112
|
+
readonly content: string | readonly {
|
|
113
|
+
readonly type: "text";
|
|
114
|
+
readonly text: string;
|
|
115
|
+
readonly cache_control?: {
|
|
116
|
+
readonly type: "ephemeral";
|
|
117
|
+
readonly ttl?: string | undefined;
|
|
118
|
+
} | undefined;
|
|
119
|
+
}[] | null;
|
|
120
|
+
readonly role: "assistant";
|
|
121
|
+
readonly reasoning?: string | undefined;
|
|
122
|
+
readonly reasoning_content?: string | undefined;
|
|
123
|
+
readonly reasoning_text?: string | undefined;
|
|
124
|
+
readonly tool_calls?: readonly {
|
|
125
|
+
readonly function: {
|
|
126
|
+
readonly name: string;
|
|
127
|
+
readonly arguments: string;
|
|
128
|
+
};
|
|
129
|
+
readonly id: string;
|
|
130
|
+
readonly type: "function";
|
|
131
|
+
readonly thought_signature?: string | undefined;
|
|
132
|
+
readonly extra_content?: {
|
|
133
|
+
readonly google: {
|
|
134
|
+
readonly thought_signature: string;
|
|
135
|
+
};
|
|
136
|
+
} | undefined;
|
|
137
|
+
}[] | undefined;
|
|
138
|
+
readonly thought_signature?: string | undefined;
|
|
139
|
+
readonly reasoning_details?: unknown;
|
|
140
|
+
})[];
|
|
141
|
+
readonly stream: true;
|
|
142
|
+
readonly venice_parameters: {
|
|
143
|
+
readonly [x: string]: string | boolean;
|
|
144
|
+
};
|
|
145
|
+
readonly reasoning?: {
|
|
146
|
+
readonly enabled?: boolean | undefined;
|
|
147
|
+
readonly summary?: string | undefined;
|
|
148
|
+
readonly effort?: string | undefined;
|
|
149
|
+
} | undefined;
|
|
150
|
+
readonly max_completion_tokens?: number | undefined;
|
|
151
|
+
readonly max_tokens?: number | undefined;
|
|
152
|
+
readonly tools?: readonly {
|
|
153
|
+
readonly function: {
|
|
154
|
+
readonly description: string;
|
|
155
|
+
readonly name: string;
|
|
156
|
+
readonly parameters: {
|
|
157
|
+
readonly [x: string]: unknown;
|
|
158
|
+
};
|
|
159
|
+
readonly strict?: boolean | undefined;
|
|
160
|
+
};
|
|
161
|
+
readonly type: "function";
|
|
162
|
+
readonly cache_control?: {
|
|
163
|
+
readonly type: "ephemeral";
|
|
164
|
+
readonly ttl?: string | undefined;
|
|
165
|
+
} | undefined;
|
|
166
|
+
}[] | undefined;
|
|
167
|
+
readonly stop?: readonly string[] | undefined;
|
|
168
|
+
readonly user?: string | undefined;
|
|
169
|
+
readonly temperature?: number | undefined;
|
|
170
|
+
readonly seed?: number | undefined;
|
|
171
|
+
readonly tool_choice?: "required" | "auto" | "none" | {
|
|
172
|
+
readonly type: "function";
|
|
173
|
+
readonly function: {
|
|
174
|
+
readonly name: string;
|
|
175
|
+
};
|
|
176
|
+
} | undefined;
|
|
177
|
+
readonly top_p?: number | undefined;
|
|
178
|
+
readonly top_k?: number | undefined;
|
|
179
|
+
readonly frequency_penalty?: number | undefined;
|
|
180
|
+
readonly presence_penalty?: number | undefined;
|
|
181
|
+
readonly store?: boolean | undefined;
|
|
182
|
+
readonly prompt_cache_key?: string | undefined;
|
|
183
|
+
readonly parallel_tool_calls?: boolean | undefined;
|
|
184
|
+
readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
185
|
+
readonly stream_options?: {
|
|
186
|
+
readonly include_usage: boolean;
|
|
187
|
+
} | undefined;
|
|
188
|
+
readonly tool_stream?: boolean | undefined;
|
|
189
|
+
readonly top_logprobs?: number | undefined;
|
|
190
|
+
readonly prompt_cache_retention?: string | undefined;
|
|
191
|
+
readonly repetition_penalty?: number | undefined;
|
|
192
|
+
readonly response_format?: {
|
|
193
|
+
readonly [x: string]: unknown;
|
|
194
|
+
} | undefined;
|
|
195
|
+
readonly logprobs?: boolean | undefined;
|
|
196
|
+
readonly min_p?: number | undefined;
|
|
197
|
+
readonly stop_token_ids?: readonly number[] | undefined;
|
|
198
|
+
readonly max_temp?: number | undefined;
|
|
199
|
+
readonly min_temp?: number | undefined;
|
|
200
|
+
}, string, "[DONE]" | {
|
|
201
|
+
readonly [x: string]: unknown;
|
|
202
|
+
readonly error?: string | {
|
|
203
|
+
readonly [x: string]: unknown;
|
|
204
|
+
readonly message: string;
|
|
205
|
+
readonly code?: string | number | null | undefined;
|
|
206
|
+
} | null | undefined;
|
|
207
|
+
readonly usage?: {
|
|
208
|
+
readonly [x: string]: unknown;
|
|
209
|
+
readonly cache_read_input_tokens?: number | null | undefined;
|
|
210
|
+
readonly cached_tokens?: number | null | undefined;
|
|
211
|
+
readonly total_tokens?: number | null | undefined;
|
|
212
|
+
readonly prompt_tokens?: number | null | undefined;
|
|
213
|
+
readonly completion_tokens?: number | null | undefined;
|
|
214
|
+
readonly prompt_tokens_details?: {
|
|
215
|
+
readonly [x: string]: unknown;
|
|
216
|
+
readonly cache_creation_input_tokens?: number | null | undefined;
|
|
217
|
+
readonly cached_tokens?: number | null | undefined;
|
|
218
|
+
readonly cache_write_tokens?: number | null | undefined;
|
|
219
|
+
} | null | undefined;
|
|
220
|
+
readonly prompt_cache_hit_tokens?: number | null | undefined;
|
|
221
|
+
readonly cache_created_input_tokens?: number | null | undefined;
|
|
222
|
+
readonly completion_tokens_details?: {
|
|
223
|
+
readonly [x: string]: unknown;
|
|
224
|
+
readonly reasoning_tokens?: number | null | undefined;
|
|
225
|
+
readonly accepted_prediction_tokens?: number | null | undefined;
|
|
226
|
+
readonly rejected_prediction_tokens?: number | null | undefined;
|
|
227
|
+
} | null | undefined;
|
|
228
|
+
} | null | undefined;
|
|
229
|
+
readonly choices?: readonly {
|
|
230
|
+
readonly [x: string]: unknown;
|
|
231
|
+
readonly delta?: {
|
|
232
|
+
readonly [x: string]: unknown;
|
|
233
|
+
readonly reasoning?: string | null | undefined;
|
|
234
|
+
readonly reasoning_content?: string | null | undefined;
|
|
235
|
+
readonly reasoning_text?: string | null | undefined;
|
|
236
|
+
readonly content?: string | null | undefined;
|
|
237
|
+
readonly refusal?: string | null | undefined;
|
|
238
|
+
readonly tool_calls?: readonly {
|
|
239
|
+
readonly function?: {
|
|
240
|
+
readonly name?: string | null | undefined;
|
|
241
|
+
readonly arguments?: string | null | undefined;
|
|
242
|
+
} | null | undefined;
|
|
243
|
+
readonly id?: string | null | undefined;
|
|
244
|
+
readonly index?: number | null | undefined;
|
|
245
|
+
readonly thought_signature?: string | null | undefined;
|
|
246
|
+
readonly extra_content?: unknown;
|
|
247
|
+
}[] | null | undefined;
|
|
248
|
+
readonly thought_signature?: string | null | undefined;
|
|
249
|
+
readonly reasoning_details?: unknown;
|
|
250
|
+
} | null | undefined;
|
|
251
|
+
readonly usage?: {
|
|
252
|
+
readonly [x: string]: unknown;
|
|
253
|
+
readonly cache_read_input_tokens?: number | null | undefined;
|
|
254
|
+
readonly cached_tokens?: number | null | undefined;
|
|
255
|
+
readonly total_tokens?: number | null | undefined;
|
|
256
|
+
readonly prompt_tokens?: number | null | undefined;
|
|
257
|
+
readonly completion_tokens?: number | null | undefined;
|
|
258
|
+
readonly prompt_tokens_details?: {
|
|
259
|
+
readonly [x: string]: unknown;
|
|
260
|
+
readonly cached_tokens?: number | null | undefined;
|
|
261
|
+
readonly cache_write_tokens?: number | null | undefined;
|
|
262
|
+
} | null | undefined;
|
|
263
|
+
readonly prompt_cache_hit_tokens?: number | null | undefined;
|
|
264
|
+
readonly cache_created_input_tokens?: number | null | undefined;
|
|
265
|
+
readonly completion_tokens_details?: {
|
|
266
|
+
readonly [x: string]: unknown;
|
|
267
|
+
readonly reasoning_tokens?: number | null | undefined;
|
|
268
|
+
readonly accepted_prediction_tokens?: number | null | undefined;
|
|
269
|
+
readonly rejected_prediction_tokens?: number | null | undefined;
|
|
270
|
+
} | null | undefined;
|
|
271
|
+
} | null | undefined;
|
|
272
|
+
readonly finish_reason?: string | null | undefined;
|
|
273
|
+
readonly native_finish_reason?: string | null | undefined;
|
|
274
|
+
}[] | null | undefined;
|
|
275
|
+
readonly issues?: readonly {
|
|
276
|
+
readonly message: string;
|
|
277
|
+
readonly path?: readonly (string | number)[] | undefined;
|
|
278
|
+
}[] | undefined;
|
|
279
|
+
}, State>;
|
|
280
|
+
export * as VeniceChat from "./venice-chat.js";
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Protocol } from "../route/protocol.js";
|
|
3
|
+
import { AIError, LLMEvent } from "../schema/index.js";
|
|
4
|
+
import { classifyProviderFailure } from "../provider-error.js";
|
|
5
|
+
import { OpenAIChat } from "./openai-chat.js";
|
|
6
|
+
import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js";
|
|
7
|
+
import { cacheControl } from "./utils/cache.js";
|
|
8
|
+
const Parameters = Schema.Struct({
|
|
9
|
+
enableWebSearch: Schema.optional(Schema.String),
|
|
10
|
+
enableWebScraping: Schema.optional(Schema.Boolean),
|
|
11
|
+
enableWebCitations: Schema.optional(Schema.Boolean),
|
|
12
|
+
enableXSearch: Schema.optional(Schema.Boolean),
|
|
13
|
+
stripThinkingResponse: Schema.optional(Schema.Boolean),
|
|
14
|
+
disableThinking: Schema.optional(Schema.Boolean),
|
|
15
|
+
includeVeniceSystemPrompt: Schema.optional(Schema.Boolean),
|
|
16
|
+
characterSlug: Schema.optional(Schema.String),
|
|
17
|
+
includeSearchResultsInStream: Schema.optional(Schema.Boolean),
|
|
18
|
+
returnSearchResultsAsDocuments: Schema.optional(Schema.Boolean),
|
|
19
|
+
});
|
|
20
|
+
const Reasoning = Schema.Struct({
|
|
21
|
+
effort: Schema.optional(Schema.String),
|
|
22
|
+
enabled: Schema.optional(Schema.Boolean),
|
|
23
|
+
summary: Schema.optional(Schema.String),
|
|
24
|
+
});
|
|
25
|
+
const Options = Schema.Struct({
|
|
26
|
+
reasoningEffort: Schema.optional(Schema.String),
|
|
27
|
+
reasoning: Schema.optional(Reasoning),
|
|
28
|
+
veniceParameters: Schema.optional(Parameters),
|
|
29
|
+
promptCacheKey: Schema.optional(Schema.String),
|
|
30
|
+
promptCacheRetention: Schema.optional(Schema.String),
|
|
31
|
+
parallelToolCalls: Schema.optional(Schema.Boolean),
|
|
32
|
+
maxCompletionTokens: Schema.optional(Schema.Number),
|
|
33
|
+
maxTokens: Schema.optional(Schema.Number),
|
|
34
|
+
minP: Schema.optional(Schema.Number),
|
|
35
|
+
repetitionPenalty: Schema.optional(Schema.Number),
|
|
36
|
+
stopTokenIds: Schema.optional(Schema.Array(Schema.Number)),
|
|
37
|
+
logprobs: Schema.optional(Schema.Boolean),
|
|
38
|
+
topLogprobs: Schema.optional(Schema.Number),
|
|
39
|
+
maxTemp: Schema.optional(Schema.Number),
|
|
40
|
+
minTemp: Schema.optional(Schema.Number),
|
|
41
|
+
responseFormat: Schema.optional(JsonObject),
|
|
42
|
+
user: Schema.optional(Schema.String),
|
|
43
|
+
});
|
|
44
|
+
const ToolCall = Schema.Struct({
|
|
45
|
+
...OpenAIChat.OpenAIChatAssistantToolCall.fields,
|
|
46
|
+
thought_signature: Schema.optional(Schema.String),
|
|
47
|
+
});
|
|
48
|
+
const Assistant = Schema.StructWithRest(Schema.Struct({
|
|
49
|
+
...OpenAIChat.OpenAIChatMessage.cases.assistant.schema.fields,
|
|
50
|
+
tool_calls: optionalArray(ToolCall),
|
|
51
|
+
thought_signature: Schema.optional(Schema.String),
|
|
52
|
+
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
53
|
+
const Messages = Schema.Array(Schema.Union([
|
|
54
|
+
OpenAIChat.OpenAIChatMessage.cases.system,
|
|
55
|
+
OpenAIChat.OpenAIChatMessage.cases.user,
|
|
56
|
+
Assistant,
|
|
57
|
+
OpenAIChat.OpenAIChatMessage.cases.tool,
|
|
58
|
+
]));
|
|
59
|
+
const Body = Schema.Struct({
|
|
60
|
+
...OpenAIChat.bodyFields,
|
|
61
|
+
messages: Messages,
|
|
62
|
+
reasoning: Schema.optional(Reasoning),
|
|
63
|
+
venice_parameters: Schema.Record(Schema.String, Schema.Union([Schema.String, Schema.Boolean])),
|
|
64
|
+
prompt_cache_retention: Options.fields.promptCacheRetention,
|
|
65
|
+
parallel_tool_calls: Options.fields.parallelToolCalls,
|
|
66
|
+
min_p: Options.fields.minP,
|
|
67
|
+
top_k: Schema.optional(Schema.Number),
|
|
68
|
+
repetition_penalty: Options.fields.repetitionPenalty,
|
|
69
|
+
stop_token_ids: Options.fields.stopTokenIds,
|
|
70
|
+
logprobs: Options.fields.logprobs,
|
|
71
|
+
top_logprobs: Options.fields.topLogprobs,
|
|
72
|
+
max_temp: Options.fields.maxTemp,
|
|
73
|
+
min_temp: Options.fields.minTemp,
|
|
74
|
+
response_format: Options.fields.responseFormat,
|
|
75
|
+
user: Options.fields.user,
|
|
76
|
+
});
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// Streaming schemas and state
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
const ToolDelta = Schema.Struct({
|
|
81
|
+
...OpenAIChat.OpenAIChatToolCallDelta.fields,
|
|
82
|
+
thought_signature: optionalNull(Schema.String),
|
|
83
|
+
});
|
|
84
|
+
const Delta = Schema.StructWithRest(Schema.Struct({
|
|
85
|
+
...OpenAIChat.OpenAIChatDelta.schema.fields,
|
|
86
|
+
tool_calls: optionalNull(Schema.Array(ToolDelta)),
|
|
87
|
+
thought_signature: optionalNull(Schema.String),
|
|
88
|
+
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
89
|
+
const Choice = Schema.StructWithRest(Schema.Struct({ ...OpenAIChat.OpenAIChatChoice.schema.fields, delta: optionalNull(Delta) }), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
90
|
+
const Usage = Schema.StructWithRest(Schema.Struct({
|
|
91
|
+
...OpenAIChat.OpenAIChatUsage.schema.fields,
|
|
92
|
+
prompt_tokens_details: optionalNull(Schema.StructWithRest(Schema.Struct({
|
|
93
|
+
cached_tokens: optionalNull(Schema.Number),
|
|
94
|
+
cache_write_tokens: optionalNull(Schema.Number),
|
|
95
|
+
cache_creation_input_tokens: optionalNull(Schema.Number),
|
|
96
|
+
}), [Schema.Record(Schema.String, Schema.Unknown)])),
|
|
97
|
+
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
98
|
+
const Event = Schema.StructWithRest(Schema.Struct({
|
|
99
|
+
...OpenAIChat.OpenAIChatEvent.schema.fields,
|
|
100
|
+
choices: optionalNull(Schema.Array(Choice)),
|
|
101
|
+
usage: optionalNull(Usage),
|
|
102
|
+
error: optionalNull(Schema.Union([Schema.String, OpenAIChat.OpenAIChatEvent.schema.fields.error.schema])),
|
|
103
|
+
issues: optionalArray(Schema.Struct({
|
|
104
|
+
message: Schema.String,
|
|
105
|
+
path: Schema.optional(Schema.Array(Schema.Union([Schema.String, Schema.Number]))),
|
|
106
|
+
})),
|
|
107
|
+
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
108
|
+
const MARKER = "__ENCRYPTED_REASONING__";
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
// Request lowering
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
const fromRequest = Effect.fn("VeniceChat.fromRequest")(function* (request) {
|
|
113
|
+
const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(request.providerOptions ?? {});
|
|
114
|
+
const body = yield* OpenAIChat.fromRequest(request, {
|
|
115
|
+
cacheControl: cacheControl(),
|
|
116
|
+
assistant: (source, message) => {
|
|
117
|
+
if (message.role !== "assistant")
|
|
118
|
+
return message;
|
|
119
|
+
const parts = source.content.filter((part) => part.type === "text" || part.type === "reasoning" || part.type === "tool-call");
|
|
120
|
+
const calls = source.content.filter((part) => part.type === "tool-call");
|
|
121
|
+
const signature = parts
|
|
122
|
+
.map((part) => part.providerMetadata?.venice?.messageThoughtSignature)
|
|
123
|
+
.find((value) => typeof value === "string");
|
|
124
|
+
const raw = parts
|
|
125
|
+
.map((part) => part.providerMetadata?.venice?.encryptedReasoningContent)
|
|
126
|
+
.find((value) => typeof value === "string");
|
|
127
|
+
return {
|
|
128
|
+
...message,
|
|
129
|
+
...(signature === undefined ? {} : { thought_signature: signature }),
|
|
130
|
+
...(raw === undefined ? {} : { reasoning_content: raw }),
|
|
131
|
+
tool_calls: message.tool_calls?.map((call, index) => {
|
|
132
|
+
const signature = calls[index]?.providerMetadata?.venice?.thoughtSignature;
|
|
133
|
+
return { ...call, ...(typeof signature === "string" ? { thought_signature: signature } : {}) };
|
|
134
|
+
}),
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
return {
|
|
139
|
+
...body,
|
|
140
|
+
max_completion_tokens: options.maxCompletionTokens ?? options.maxTokens ?? request.generation?.maxTokens,
|
|
141
|
+
reasoning_effort: undefined,
|
|
142
|
+
reasoning: options.reasoningEffort === undefined
|
|
143
|
+
? options.reasoning
|
|
144
|
+
: { ...options.reasoning, effort: options.reasoningEffort },
|
|
145
|
+
// Match the previous Venice SDK default, not the gateway's added prompt.
|
|
146
|
+
venice_parameters: Object.fromEntries(Object.entries({
|
|
147
|
+
...options.veniceParameters,
|
|
148
|
+
includeVeniceSystemPrompt: options.veniceParameters?.includeVeniceSystemPrompt ?? false,
|
|
149
|
+
})
|
|
150
|
+
.filter(([, value]) => value !== undefined)
|
|
151
|
+
.map(([key, value]) => [key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`), value])),
|
|
152
|
+
prompt_cache_retention: options.promptCacheRetention,
|
|
153
|
+
parallel_tool_calls: options.parallelToolCalls,
|
|
154
|
+
min_p: options.minP,
|
|
155
|
+
top_k: request.generation?.topK,
|
|
156
|
+
repetition_penalty: options.repetitionPenalty,
|
|
157
|
+
stop_token_ids: options.stopTokenIds,
|
|
158
|
+
logprobs: options.logprobs,
|
|
159
|
+
top_logprobs: options.topLogprobs,
|
|
160
|
+
max_temp: options.maxTemp,
|
|
161
|
+
min_temp: options.minTemp,
|
|
162
|
+
response_format: options.responseFormat,
|
|
163
|
+
user: options.user,
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
// Venice normalization around the shared Chat state machine
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
const step = Effect.fn("VeniceChat.step")(function* (state, event) {
|
|
170
|
+
if (typeof event.error === "string")
|
|
171
|
+
return yield* new AIError({
|
|
172
|
+
reason: classifyProviderFailure({
|
|
173
|
+
message: [
|
|
174
|
+
event.error,
|
|
175
|
+
...(event.issues ?? []).map((issue) => `${issue.path?.length ? `${issue.path.join(".")}: ` : ""}${issue.message}`),
|
|
176
|
+
].join("; "),
|
|
177
|
+
rawBody: ProviderShared.encodeJson(event),
|
|
178
|
+
}),
|
|
179
|
+
});
|
|
180
|
+
const delta = event.choices?.[0]?.delta;
|
|
181
|
+
const scalar = delta?.reasoning_content ?? "";
|
|
182
|
+
const text = state.pending + scalar;
|
|
183
|
+
const marker = text.indexOf(MARKER);
|
|
184
|
+
const pending = marker >= 0 || state.encrypted
|
|
185
|
+
? 0
|
|
186
|
+
: (Array.from({ length: Math.min(text.length, MARKER.length - 1) }, (_, index) => index + 1)
|
|
187
|
+
.filter((length) => text.endsWith(MARKER.slice(0, length)))
|
|
188
|
+
.at(-1) ?? 0);
|
|
189
|
+
const visible = state.encrypted ? "" : marker >= 0 ? text.slice(0, marker) : text.slice(0, text.length - pending);
|
|
190
|
+
const result = yield* OpenAIChat.protocol.stream.step(state.shared, {
|
|
191
|
+
...event,
|
|
192
|
+
error: event.error,
|
|
193
|
+
usage: event.usage
|
|
194
|
+
? {
|
|
195
|
+
...event.usage,
|
|
196
|
+
prompt_tokens_details: event.usage.prompt_tokens_details
|
|
197
|
+
? {
|
|
198
|
+
...event.usage.prompt_tokens_details,
|
|
199
|
+
cache_write_tokens: event.usage.prompt_tokens_details.cache_write_tokens ??
|
|
200
|
+
event.usage.prompt_tokens_details.cache_creation_input_tokens,
|
|
201
|
+
}
|
|
202
|
+
: event.usage.prompt_tokens_details,
|
|
203
|
+
}
|
|
204
|
+
: event.usage,
|
|
205
|
+
choices: event.choices?.map((choice, index) => index === 0 && choice.delta
|
|
206
|
+
? {
|
|
207
|
+
...choice,
|
|
208
|
+
delta: {
|
|
209
|
+
...choice.delta,
|
|
210
|
+
reasoning_content: visible || undefined,
|
|
211
|
+
// Opaque-only scalar reasoning still needs a canonical part for replay.
|
|
212
|
+
reasoning_details: choice.delta.reasoning_details ?? (marker >= 0 ? [] : undefined),
|
|
213
|
+
},
|
|
214
|
+
}
|
|
215
|
+
: choice),
|
|
216
|
+
});
|
|
217
|
+
const tools = { ...state.tools };
|
|
218
|
+
for (const call of delta?.tool_calls ?? []) {
|
|
219
|
+
if (!call.thought_signature)
|
|
220
|
+
continue;
|
|
221
|
+
const index = call.index ?? result[0].latestToolIndex;
|
|
222
|
+
const id = call.id ?? (index === undefined ? undefined : (result[0].tools[index]?.id ?? result[0].pendingTools[index]?.id));
|
|
223
|
+
if (id)
|
|
224
|
+
tools[id] = call.thought_signature;
|
|
225
|
+
}
|
|
226
|
+
return [
|
|
227
|
+
{
|
|
228
|
+
shared: result[0],
|
|
229
|
+
pending: pending ? text.slice(-pending) : "",
|
|
230
|
+
reasoning: state.reasoning + scalar,
|
|
231
|
+
encrypted: state.encrypted || marker >= 0,
|
|
232
|
+
signature: delta?.thought_signature ?? state.signature,
|
|
233
|
+
tools,
|
|
234
|
+
},
|
|
235
|
+
result[1],
|
|
236
|
+
];
|
|
237
|
+
});
|
|
238
|
+
const onHalt = Effect.fn("VeniceChat.onHalt")(function* (state) {
|
|
239
|
+
const events = yield* OpenAIChat.finishEvents(state.shared);
|
|
240
|
+
return events.flatMap((event) => {
|
|
241
|
+
if (event.type !== "reasoning-end" &&
|
|
242
|
+
event.type !== "text-end" &&
|
|
243
|
+
event.type !== "tool-call" &&
|
|
244
|
+
event.type !== "tool-input-end")
|
|
245
|
+
return [event];
|
|
246
|
+
const signature = event.type === "tool-call" || event.type === "tool-input-end" ? state.tools[event.id] : undefined;
|
|
247
|
+
const providerMetadata = {
|
|
248
|
+
...event.providerMetadata,
|
|
249
|
+
venice: {
|
|
250
|
+
...event.providerMetadata?.venice,
|
|
251
|
+
...(state.signature ? { messageThoughtSignature: state.signature } : {}),
|
|
252
|
+
...(signature ? { thoughtSignature: signature } : {}),
|
|
253
|
+
...(event.type === "reasoning-end" && state.encrypted ? { encryptedReasoningContent: state.reasoning } : {}),
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
if (event.type === "reasoning-end" && state.pending)
|
|
257
|
+
return [LLMEvent.reasoningDelta({ id: event.id, text: state.pending }), { ...event, providerMetadata }];
|
|
258
|
+
return [{ ...event, providerMetadata }];
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
export const compatibility = {
|
|
262
|
+
maxTokensField: "max_completion_tokens",
|
|
263
|
+
supportsStore: false,
|
|
264
|
+
supportsPromptCacheKey: true,
|
|
265
|
+
};
|
|
266
|
+
export const protocol = Protocol.make({
|
|
267
|
+
id: "venice-chat",
|
|
268
|
+
body: { schema: Body, from: fromRequest },
|
|
269
|
+
stream: {
|
|
270
|
+
event: Schema.Union([Schema.Literal("[DONE]"), Protocol.jsonEvent(Event)]),
|
|
271
|
+
initial: (request) => ({
|
|
272
|
+
shared: OpenAIChat.protocol.stream.initial(request),
|
|
273
|
+
pending: "",
|
|
274
|
+
reasoning: "",
|
|
275
|
+
encrypted: false,
|
|
276
|
+
tools: {},
|
|
277
|
+
}),
|
|
278
|
+
step: (state, event) => (event === "[DONE]" ? Effect.succeed([state, []]) : step(state, event)),
|
|
279
|
+
terminal: (event) => event === "[DONE]",
|
|
280
|
+
onHalt,
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
export * as VeniceChat from "./venice-chat.js";
|
|
@@ -40,6 +40,7 @@ export * as Stability from "./stability.js";
|
|
|
40
40
|
export * as TogetherAI from "./togetherai.js";
|
|
41
41
|
export * as TypeSafeAI from "./typesafe-ai.js";
|
|
42
42
|
export * as VercelAIGateway from "./vercel-ai-gateway.js";
|
|
43
|
+
export * as Venice from "./venice.js";
|
|
43
44
|
export * as XAI from "./xai.js";
|
|
44
45
|
export * as ZAI from "./zai.js";
|
|
45
46
|
export * as ZAICodingPlan from "./zai-coding-plan.js";
|
package/dist/providers/index.js
CHANGED
|
@@ -40,6 +40,7 @@ export * as Stability from "./stability.js";
|
|
|
40
40
|
export * as TogetherAI from "./togetherai.js";
|
|
41
41
|
export * as TypeSafeAI from "./typesafe-ai.js";
|
|
42
42
|
export * as VercelAIGateway from "./vercel-ai-gateway.js";
|
|
43
|
+
export * as Venice from "./venice.js";
|
|
43
44
|
export * as XAI from "./xai.js";
|
|
44
45
|
export * as ZAI from "./zai.js";
|
|
45
46
|
export * as ZAICodingPlan from "./zai-coding-plan.js";
|