@luketandjung/dedalus-labs 1.0.0
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/dist/index.cjs +1320 -0
- package/dist/index.d.ts +992 -0
- package/dist/index.js +1293 -0
- package/package.json +55 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1293 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
set: (newValue) => all[name] = () => newValue
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// packages/dedalus-labs/src/Generated.ts
|
|
14
|
+
var exports_Generated = {};
|
|
15
|
+
__export(exports_Generated, {
|
|
16
|
+
make: () => make,
|
|
17
|
+
ValidationError: () => ValidationError,
|
|
18
|
+
UrlCitation: () => UrlCitation,
|
|
19
|
+
TopLogprob: () => TopLogprob,
|
|
20
|
+
ToolChoiceEnum: () => ToolChoiceEnum,
|
|
21
|
+
ToolChoice: () => ToolChoice,
|
|
22
|
+
ThinkingConfigEnabled: () => ThinkingConfigEnabled,
|
|
23
|
+
ThinkingConfigDisabled: () => ThinkingConfigDisabled,
|
|
24
|
+
ReasoningSummaryEnum: () => ReasoningSummaryEnum,
|
|
25
|
+
ReasoningGenerateSummaryEnum: () => ReasoningGenerateSummaryEnum,
|
|
26
|
+
ReasoningEffortEnum: () => ReasoningEffortEnum,
|
|
27
|
+
Reasoning: () => Reasoning,
|
|
28
|
+
QueryParams: () => QueryParams,
|
|
29
|
+
PromptTokensDetails: () => PromptTokensDetails,
|
|
30
|
+
Models: () => Models,
|
|
31
|
+
ModelSettingsTruncationEnum: () => ModelSettingsTruncationEnum,
|
|
32
|
+
ModelSettings: () => ModelSettings,
|
|
33
|
+
ModelId: () => ModelId,
|
|
34
|
+
MCPToolChoice: () => MCPToolChoice,
|
|
35
|
+
HeaderParams: () => HeaderParams,
|
|
36
|
+
HTTPValidationError: () => HTTPValidationError,
|
|
37
|
+
FunctionCall: () => FunctionCall,
|
|
38
|
+
Function: () => Function,
|
|
39
|
+
Embedding: () => Embedding,
|
|
40
|
+
DedalusModelChoice: () => DedalusModelChoice,
|
|
41
|
+
DedalusModel: () => DedalusModel,
|
|
42
|
+
Custom: () => Custom,
|
|
43
|
+
CreateEmbeddingResponse: () => CreateEmbeddingResponse,
|
|
44
|
+
CreateEmbeddingRequestModelEnum: () => CreateEmbeddingRequestModelEnum,
|
|
45
|
+
CreateEmbeddingRequestEncodingFormat: () => CreateEmbeddingRequestEncodingFormat,
|
|
46
|
+
CreateEmbeddingRequest: () => CreateEmbeddingRequest,
|
|
47
|
+
CompletionUsage: () => CompletionUsage,
|
|
48
|
+
CompletionTokensDetails: () => CompletionTokensDetails,
|
|
49
|
+
ChoiceLogprobs: () => ChoiceLogprobs,
|
|
50
|
+
ChoiceFinishReasonEnum: () => ChoiceFinishReasonEnum,
|
|
51
|
+
Choice: () => Choice,
|
|
52
|
+
ChatCompletionTokenLogprob: () => ChatCompletionTokenLogprob,
|
|
53
|
+
ChatCompletionServiceTierEnum: () => ChatCompletionServiceTierEnum,
|
|
54
|
+
ChatCompletionResponseMessage: () => ChatCompletionResponseMessage,
|
|
55
|
+
ChatCompletionRequestVerbosityEnum: () => ChatCompletionRequestVerbosityEnum,
|
|
56
|
+
ChatCompletionRequestServiceTierEnum: () => ChatCompletionRequestServiceTierEnum,
|
|
57
|
+
ChatCompletionRequestReasoningEffortEnum: () => ChatCompletionRequestReasoningEffortEnum,
|
|
58
|
+
ChatCompletionRequest: () => ChatCompletionRequest,
|
|
59
|
+
ChatCompletionMessageToolCall: () => ChatCompletionMessageToolCall,
|
|
60
|
+
ChatCompletionMessageCustomToolCall: () => ChatCompletionMessageCustomToolCall,
|
|
61
|
+
ChatCompletion: () => ChatCompletion,
|
|
62
|
+
Audio: () => Audio,
|
|
63
|
+
AnnotationsItem: () => AnnotationsItem
|
|
64
|
+
});
|
|
65
|
+
import * as HttpClientError from "@effect/platform/HttpClientError";
|
|
66
|
+
import * as HttpClientRequest from "@effect/platform/HttpClientRequest";
|
|
67
|
+
import * as HttpClientResponse from "@effect/platform/HttpClientResponse";
|
|
68
|
+
import { AiError } from "@luketandjung/ariadne";
|
|
69
|
+
import * as Effect from "effect/Effect";
|
|
70
|
+
import * as S from "effect/Schema";
|
|
71
|
+
|
|
72
|
+
class ModelId extends S.String {
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
class ToolChoiceEnum extends S.Literal("auto", "required", "none") {
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
class MCPToolChoice extends S.Class("MCPToolChoice")({
|
|
79
|
+
server_label: S.String,
|
|
80
|
+
name: S.String
|
|
81
|
+
}) {
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
class ToolChoice extends S.Union(ToolChoiceEnum, S.String, S.Record({ key: S.String, value: S.Unknown }), MCPToolChoice, S.Null) {
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
class ModelSettingsTruncationEnum extends S.Literal("auto", "disabled") {
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
class ReasoningEffortEnum extends S.Literal("minimal", "low", "medium", "high") {
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
class ReasoningGenerateSummaryEnum extends S.Literal("auto", "concise", "detailed") {
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
class ReasoningSummaryEnum extends S.Literal("auto", "concise", "detailed") {
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
class Reasoning extends S.Class("Reasoning")({
|
|
100
|
+
effort: S.optionalWith(ReasoningEffortEnum, { nullable: true }),
|
|
101
|
+
generate_summary: S.optionalWith(ReasoningGenerateSummaryEnum, {
|
|
102
|
+
nullable: true
|
|
103
|
+
}),
|
|
104
|
+
summary: S.optionalWith(ReasoningSummaryEnum, { nullable: true })
|
|
105
|
+
}) {
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
class QueryParams extends S.Record({
|
|
109
|
+
key: S.String,
|
|
110
|
+
value: S.Unknown
|
|
111
|
+
}) {
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
class HeaderParams extends S.Record({
|
|
115
|
+
key: S.String,
|
|
116
|
+
value: S.Unknown
|
|
117
|
+
}) {
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
class ModelSettings extends S.Class("ModelSettings")({
|
|
121
|
+
temperature: S.optionalWith(S.Number, { nullable: true }),
|
|
122
|
+
top_p: S.optionalWith(S.Number, { nullable: true }),
|
|
123
|
+
frequency_penalty: S.optionalWith(S.Number, { nullable: true }),
|
|
124
|
+
presence_penalty: S.optionalWith(S.Number, { nullable: true }),
|
|
125
|
+
stop: S.optionalWith(S.Union(S.String, S.Array(S.String)), {
|
|
126
|
+
nullable: true
|
|
127
|
+
}),
|
|
128
|
+
seed: S.optionalWith(S.Int, { nullable: true }),
|
|
129
|
+
logit_bias: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), {
|
|
130
|
+
nullable: true
|
|
131
|
+
}),
|
|
132
|
+
logprobs: S.optionalWith(S.Boolean, { nullable: true }),
|
|
133
|
+
top_logprobs: S.optionalWith(S.Int, { nullable: true }),
|
|
134
|
+
n: S.optionalWith(S.Int, { nullable: true }),
|
|
135
|
+
user: S.optionalWith(S.String, { nullable: true }),
|
|
136
|
+
response_format: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
137
|
+
stream: S.optionalWith(S.Boolean, { nullable: true }),
|
|
138
|
+
stream_options: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
139
|
+
audio: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), {
|
|
140
|
+
nullable: true
|
|
141
|
+
}),
|
|
142
|
+
service_tier: S.optionalWith(S.String, { nullable: true }),
|
|
143
|
+
prediction: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), {
|
|
144
|
+
nullable: true
|
|
145
|
+
}),
|
|
146
|
+
tool_choice: S.optionalWith(ToolChoice, { nullable: true }),
|
|
147
|
+
parallel_tool_calls: S.optionalWith(S.Boolean, { nullable: true }),
|
|
148
|
+
truncation: S.optionalWith(ModelSettingsTruncationEnum, { nullable: true }),
|
|
149
|
+
max_tokens: S.optionalWith(S.Int, { nullable: true }),
|
|
150
|
+
max_completion_tokens: S.optionalWith(S.Int, { nullable: true }),
|
|
151
|
+
reasoning: S.optionalWith(Reasoning, { nullable: true }),
|
|
152
|
+
reasoning_effort: S.optionalWith(S.String, { nullable: true }),
|
|
153
|
+
metadata: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), {
|
|
154
|
+
nullable: true
|
|
155
|
+
}),
|
|
156
|
+
store: S.optionalWith(S.Boolean, { nullable: true }),
|
|
157
|
+
include_usage: S.optionalWith(S.Boolean, { nullable: true }),
|
|
158
|
+
timeout: S.optionalWith(S.Number, { nullable: true }),
|
|
159
|
+
prompt_cache_key: S.optionalWith(S.String, { nullable: true }),
|
|
160
|
+
safety_identifier: S.optionalWith(S.String, { nullable: true }),
|
|
161
|
+
verbosity: S.optionalWith(S.String, { nullable: true }),
|
|
162
|
+
web_search_options: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
163
|
+
response_include: S.optionalWith(S.Array(S.Literal("code_interpreter_call.outputs", "computer_call_output.output.image_url", "file_search_call.results", "message.input_image.image_url", "message.output_text.logprobs", "reasoning.encrypted_content")), { nullable: true }),
|
|
164
|
+
use_responses: S.optionalWith(S.Boolean, {
|
|
165
|
+
nullable: true,
|
|
166
|
+
default: () => false
|
|
167
|
+
}),
|
|
168
|
+
extra_query: S.optionalWith(QueryParams, { nullable: true }),
|
|
169
|
+
extra_headers: S.optionalWith(HeaderParams, { nullable: true }),
|
|
170
|
+
extra_args: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), {
|
|
171
|
+
nullable: true
|
|
172
|
+
}),
|
|
173
|
+
attributes: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), {
|
|
174
|
+
nullable: true
|
|
175
|
+
}),
|
|
176
|
+
voice: S.optionalWith(S.String, { nullable: true }),
|
|
177
|
+
modalities: S.optionalWith(S.Array(S.String), { nullable: true }),
|
|
178
|
+
input_audio_format: S.optionalWith(S.String, { nullable: true }),
|
|
179
|
+
output_audio_format: S.optionalWith(S.String, { nullable: true }),
|
|
180
|
+
input_audio_transcription: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
181
|
+
turn_detection: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
182
|
+
thinking: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), {
|
|
183
|
+
nullable: true
|
|
184
|
+
}),
|
|
185
|
+
top_k: S.optionalWith(S.Int, { nullable: true }),
|
|
186
|
+
generation_config: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
187
|
+
system_instruction: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
188
|
+
safety_settings: S.optionalWith(S.Array(S.Record({ key: S.String, value: S.Unknown })), { nullable: true }),
|
|
189
|
+
tool_config: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), {
|
|
190
|
+
nullable: true
|
|
191
|
+
}),
|
|
192
|
+
disable_automatic_function_calling: S.optionalWith(S.Boolean, {
|
|
193
|
+
nullable: true,
|
|
194
|
+
default: () => true
|
|
195
|
+
}),
|
|
196
|
+
search_parameters: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
197
|
+
deferred: S.optionalWith(S.Boolean, { nullable: true })
|
|
198
|
+
}) {
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
class DedalusModel extends S.Class("DedalusModel")({
|
|
202
|
+
model: S.String,
|
|
203
|
+
settings: S.optionalWith(ModelSettings, { nullable: true })
|
|
204
|
+
}) {
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
class DedalusModelChoice extends S.Union(ModelId, DedalusModel) {
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
class Models extends S.Array(DedalusModelChoice) {
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
class ThinkingConfigDisabled extends S.Class("ThinkingConfigDisabled")({
|
|
214
|
+
type: S.Literal("disabled")
|
|
215
|
+
}) {
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
class ThinkingConfigEnabled extends S.Class("ThinkingConfigEnabled")({
|
|
219
|
+
budget_tokens: S.Int.pipe(S.greaterThanOrEqualTo(1024)),
|
|
220
|
+
type: S.Literal("enabled")
|
|
221
|
+
}) {
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
class ChatCompletionRequestReasoningEffortEnum extends S.Literal("low", "medium", "high") {
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
class ChatCompletionRequestServiceTierEnum extends S.Literal("auto", "default") {
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
class ChatCompletionRequestVerbosityEnum extends S.Literal("low", "medium", "high") {
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
class ChatCompletionRequest extends S.Class("ChatCompletionRequest")({
|
|
234
|
+
model: S.Union(DedalusModelChoice, Models),
|
|
235
|
+
messages: S.Union(S.Array(S.Record({ key: S.String, value: S.Unknown })), S.String),
|
|
236
|
+
input: S.optionalWith(S.Union(S.Array(S.Record({ key: S.String, value: S.Unknown })), S.String), { nullable: true }),
|
|
237
|
+
temperature: S.optionalWith(S.Number.pipe(S.greaterThanOrEqualTo(0), S.lessThanOrEqualTo(2)), { nullable: true }),
|
|
238
|
+
top_p: S.optionalWith(S.Number.pipe(S.greaterThanOrEqualTo(0), S.lessThanOrEqualTo(1)), { nullable: true }),
|
|
239
|
+
max_tokens: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(1)), {
|
|
240
|
+
nullable: true
|
|
241
|
+
}),
|
|
242
|
+
presence_penalty: S.optionalWith(S.Number.pipe(S.greaterThanOrEqualTo(-2), S.lessThanOrEqualTo(2)), { nullable: true }),
|
|
243
|
+
frequency_penalty: S.optionalWith(S.Number.pipe(S.greaterThanOrEqualTo(-2), S.lessThanOrEqualTo(2)), { nullable: true }),
|
|
244
|
+
logit_bias: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), {
|
|
245
|
+
nullable: true
|
|
246
|
+
}),
|
|
247
|
+
stop: S.optionalWith(S.Array(S.String), { nullable: true }),
|
|
248
|
+
thinking: S.optionalWith(S.Union(ThinkingConfigDisabled, ThinkingConfigEnabled), { nullable: true }),
|
|
249
|
+
top_k: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0)), {
|
|
250
|
+
nullable: true
|
|
251
|
+
}),
|
|
252
|
+
system: S.optionalWith(S.Union(S.String, S.Array(S.Record({ key: S.String, value: S.Unknown }))), { nullable: true }),
|
|
253
|
+
instructions: S.optionalWith(S.Union(S.String, S.Array(S.Record({ key: S.String, value: S.Unknown }))), { nullable: true }),
|
|
254
|
+
generation_config: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
255
|
+
safety_settings: S.optionalWith(S.Array(S.Record({ key: S.String, value: S.Unknown })), { nullable: true }),
|
|
256
|
+
tool_config: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), {
|
|
257
|
+
nullable: true
|
|
258
|
+
}),
|
|
259
|
+
disable_automatic_function_calling: S.optionalWith(S.Boolean, {
|
|
260
|
+
nullable: true
|
|
261
|
+
}),
|
|
262
|
+
seed: S.optionalWith(S.Int, { nullable: true }),
|
|
263
|
+
user: S.optionalWith(S.String, { nullable: true }),
|
|
264
|
+
n: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(1), S.lessThanOrEqualTo(128)), { nullable: true }),
|
|
265
|
+
stream: S.optionalWith(S.Boolean, {
|
|
266
|
+
nullable: true,
|
|
267
|
+
default: () => false
|
|
268
|
+
}),
|
|
269
|
+
stream_options: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
270
|
+
response_format: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
271
|
+
tools: S.optionalWith(S.Array(S.Record({ key: S.String, value: S.Unknown })), { nullable: true }),
|
|
272
|
+
tool_choice: S.optionalWith(S.Union(S.String, S.Record({ key: S.String, value: S.Unknown })), { nullable: true }),
|
|
273
|
+
parallel_tool_calls: S.optionalWith(S.Boolean, { nullable: true }),
|
|
274
|
+
functions: S.optionalWith(S.Array(S.Record({ key: S.String, value: S.Unknown })), { nullable: true }),
|
|
275
|
+
function_call: S.optionalWith(S.Union(S.String, S.Record({ key: S.String, value: S.Unknown })), { nullable: true }),
|
|
276
|
+
logprobs: S.optionalWith(S.Boolean, { nullable: true }),
|
|
277
|
+
top_logprobs: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(0), S.lessThanOrEqualTo(20)), { nullable: true }),
|
|
278
|
+
max_completion_tokens: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(1)), {
|
|
279
|
+
nullable: true
|
|
280
|
+
}),
|
|
281
|
+
reasoning_effort: S.optionalWith(ChatCompletionRequestReasoningEffortEnum, {
|
|
282
|
+
nullable: true
|
|
283
|
+
}),
|
|
284
|
+
audio: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), {
|
|
285
|
+
nullable: true
|
|
286
|
+
}),
|
|
287
|
+
modalities: S.optionalWith(S.Array(S.String), { nullable: true }),
|
|
288
|
+
prediction: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), {
|
|
289
|
+
nullable: true
|
|
290
|
+
}),
|
|
291
|
+
metadata: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), {
|
|
292
|
+
nullable: true
|
|
293
|
+
}),
|
|
294
|
+
store: S.optionalWith(S.Boolean, { nullable: true }),
|
|
295
|
+
service_tier: S.optionalWith(ChatCompletionRequestServiceTierEnum, {
|
|
296
|
+
nullable: true
|
|
297
|
+
}),
|
|
298
|
+
prompt_cache_key: S.optionalWith(S.String, { nullable: true }),
|
|
299
|
+
safety_identifier: S.optionalWith(S.String, { nullable: true }),
|
|
300
|
+
verbosity: S.optionalWith(ChatCompletionRequestVerbosityEnum, {
|
|
301
|
+
nullable: true
|
|
302
|
+
}),
|
|
303
|
+
web_search_options: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
304
|
+
search_parameters: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
305
|
+
deferred: S.optionalWith(S.Boolean, { nullable: true }),
|
|
306
|
+
mcp_servers: S.optionalWith(S.Union(S.String, S.Array(S.String)), {
|
|
307
|
+
nullable: true
|
|
308
|
+
}),
|
|
309
|
+
guardrails: S.optionalWith(S.Array(S.Record({ key: S.String, value: S.Unknown })), { nullable: true }),
|
|
310
|
+
handoff_config: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
311
|
+
model_attributes: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
312
|
+
agent_attributes: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true }),
|
|
313
|
+
max_turns: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(1), S.lessThanOrEqualTo(100)), { nullable: true }),
|
|
314
|
+
auto_execute_tools: S.optionalWith(S.Boolean, {
|
|
315
|
+
nullable: true,
|
|
316
|
+
default: () => true
|
|
317
|
+
})
|
|
318
|
+
}) {
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
class ChoiceFinishReasonEnum extends S.Literal("stop", "length", "tool_calls", "content_filter", "function_call") {
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
class Function extends S.Class("Function")({
|
|
325
|
+
name: S.String,
|
|
326
|
+
arguments: S.String
|
|
327
|
+
}) {
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
class ChatCompletionMessageToolCall extends S.Class("ChatCompletionMessageToolCall")({
|
|
331
|
+
id: S.String,
|
|
332
|
+
type: S.Literal("function"),
|
|
333
|
+
function: Function
|
|
334
|
+
}) {
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
class Custom extends S.Class("Custom")({
|
|
338
|
+
name: S.String,
|
|
339
|
+
input: S.String
|
|
340
|
+
}) {
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
class ChatCompletionMessageCustomToolCall extends S.Class("ChatCompletionMessageCustomToolCall")({
|
|
344
|
+
id: S.String,
|
|
345
|
+
type: S.Literal("custom"),
|
|
346
|
+
custom: Custom
|
|
347
|
+
}) {
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
class UrlCitation extends S.Class("UrlCitation")({
|
|
351
|
+
end_index: S.Int,
|
|
352
|
+
start_index: S.Int,
|
|
353
|
+
url: S.String,
|
|
354
|
+
title: S.String
|
|
355
|
+
}) {
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
class AnnotationsItem extends S.Class("AnnotationsItem")({
|
|
359
|
+
type: S.Literal("url_citation"),
|
|
360
|
+
url_citation: UrlCitation
|
|
361
|
+
}) {
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
class FunctionCall extends S.Class("FunctionCall")({
|
|
365
|
+
arguments: S.String,
|
|
366
|
+
name: S.String
|
|
367
|
+
}) {
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
class Audio extends S.Class("Audio")({
|
|
371
|
+
id: S.String,
|
|
372
|
+
expires_at: S.Int,
|
|
373
|
+
data: S.String,
|
|
374
|
+
transcript: S.String
|
|
375
|
+
}) {
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
class ChatCompletionResponseMessage extends S.Class("ChatCompletionResponseMessage")({
|
|
379
|
+
content: S.NullOr(S.String),
|
|
380
|
+
refusal: S.optionalWith(S.NullOr(S.String), { nullable: true }),
|
|
381
|
+
tool_calls: S.optionalWith(S.Array(S.Union(ChatCompletionMessageToolCall, ChatCompletionMessageCustomToolCall)), { nullable: true }),
|
|
382
|
+
annotations: S.optionalWith(S.Array(AnnotationsItem), { nullable: true }),
|
|
383
|
+
role: S.Literal("assistant"),
|
|
384
|
+
function_call: S.optionalWith(FunctionCall, { nullable: true }),
|
|
385
|
+
audio: S.optionalWith(Audio, { nullable: true })
|
|
386
|
+
}) {
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
class TopLogprob extends S.Class("TopLogprob")({
|
|
390
|
+
token: S.String,
|
|
391
|
+
logprob: S.Number,
|
|
392
|
+
bytes: S.NullOr(S.Array(S.Int))
|
|
393
|
+
}) {
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
class ChatCompletionTokenLogprob extends S.Class("ChatCompletionTokenLogprob")({
|
|
397
|
+
token: S.String,
|
|
398
|
+
logprob: S.Number,
|
|
399
|
+
bytes: S.NullOr(S.Array(S.Int)),
|
|
400
|
+
top_logprobs: S.Array(TopLogprob)
|
|
401
|
+
}) {
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
class ChoiceLogprobs extends S.Class("ChoiceLogprobs")({
|
|
405
|
+
content: S.optionalWith(S.Array(ChatCompletionTokenLogprob), {
|
|
406
|
+
nullable: true
|
|
407
|
+
}),
|
|
408
|
+
refusal: S.optionalWith(S.Array(ChatCompletionTokenLogprob), {
|
|
409
|
+
nullable: true
|
|
410
|
+
})
|
|
411
|
+
}) {
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
class Choice extends S.Class("Choice")({
|
|
415
|
+
finish_reason: S.optionalWith(ChoiceFinishReasonEnum, { nullable: true }),
|
|
416
|
+
index: S.Int,
|
|
417
|
+
message: ChatCompletionResponseMessage,
|
|
418
|
+
logprobs: S.optionalWith(ChoiceLogprobs, { nullable: true })
|
|
419
|
+
}) {
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
class ChatCompletionServiceTierEnum extends S.Literal("auto", "default", "flex", "scale", "priority") {
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
class CompletionTokensDetails extends S.Class("CompletionTokensDetails")({
|
|
426
|
+
accepted_prediction_tokens: S.optionalWith(S.Int, {
|
|
427
|
+
nullable: true,
|
|
428
|
+
default: () => 0
|
|
429
|
+
}),
|
|
430
|
+
audio_tokens: S.optionalWith(S.Int, {
|
|
431
|
+
nullable: true,
|
|
432
|
+
default: () => 0
|
|
433
|
+
}),
|
|
434
|
+
reasoning_tokens: S.optionalWith(S.Int, {
|
|
435
|
+
nullable: true,
|
|
436
|
+
default: () => 0
|
|
437
|
+
}),
|
|
438
|
+
rejected_prediction_tokens: S.optionalWith(S.Int, {
|
|
439
|
+
nullable: true,
|
|
440
|
+
default: () => 0
|
|
441
|
+
})
|
|
442
|
+
}) {
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
class PromptTokensDetails extends S.Class("PromptTokensDetails")({
|
|
446
|
+
audio_tokens: S.optionalWith(S.Int, {
|
|
447
|
+
nullable: true,
|
|
448
|
+
default: () => 0
|
|
449
|
+
}),
|
|
450
|
+
cached_tokens: S.optionalWith(S.Int, {
|
|
451
|
+
nullable: true,
|
|
452
|
+
default: () => 0
|
|
453
|
+
})
|
|
454
|
+
}) {
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
class CompletionUsage extends S.Class("CompletionUsage")({
|
|
458
|
+
completion_tokens: S.Int,
|
|
459
|
+
prompt_tokens: S.Int,
|
|
460
|
+
total_tokens: S.Int,
|
|
461
|
+
completion_tokens_details: S.optionalWith(CompletionTokensDetails, {
|
|
462
|
+
nullable: true
|
|
463
|
+
}),
|
|
464
|
+
prompt_tokens_details: S.optionalWith(PromptTokensDetails, {
|
|
465
|
+
nullable: true
|
|
466
|
+
})
|
|
467
|
+
}) {
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
class ChatCompletion extends S.Class("ChatCompletion")({
|
|
471
|
+
id: S.String,
|
|
472
|
+
choices: S.Array(Choice),
|
|
473
|
+
created: S.Int,
|
|
474
|
+
model: S.String,
|
|
475
|
+
service_tier: S.optionalWith(ChatCompletionServiceTierEnum, {
|
|
476
|
+
nullable: true
|
|
477
|
+
}),
|
|
478
|
+
system_fingerprint: S.optionalWith(S.String, { nullable: true }),
|
|
479
|
+
object: S.Literal("chat.completion"),
|
|
480
|
+
usage: S.optionalWith(CompletionUsage, { nullable: true }),
|
|
481
|
+
tools_executed: S.optionalWith(S.Array(S.String), { nullable: true }),
|
|
482
|
+
mcp_server_errors: S.optionalWith(S.Record({ key: S.String, value: S.Unknown }), { nullable: true })
|
|
483
|
+
}) {
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
class ValidationError extends S.Class("ValidationError")({
|
|
487
|
+
loc: S.Array(S.Union(S.String, S.Int)),
|
|
488
|
+
msg: S.String,
|
|
489
|
+
type: S.String
|
|
490
|
+
}) {
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
class HTTPValidationError extends S.Class("HTTPValidationError")({
|
|
494
|
+
detail: S.optionalWith(S.Array(ValidationError), { nullable: true })
|
|
495
|
+
}) {
|
|
496
|
+
}
|
|
497
|
+
var make = (httpClient, options = {}) => {
|
|
498
|
+
const unexpectedStatus = (response) => Effect.flatMap(Effect.orElseSucceed(response.json, () => "Unexpected status code"), (description) => Effect.fail(new HttpClientError.ResponseError({
|
|
499
|
+
request: response.request,
|
|
500
|
+
response,
|
|
501
|
+
reason: "StatusCode",
|
|
502
|
+
description: typeof description === "string" ? description : JSON.stringify(description)
|
|
503
|
+
})));
|
|
504
|
+
const withResponse = options.transformClient ? (f) => (request) => Effect.flatMap(Effect.flatMap(options.transformClient(httpClient), (client) => client.execute(request)), f) : (f) => (request) => Effect.flatMap(httpClient.execute(request), f);
|
|
505
|
+
const decodeSuccess = (schema) => (response) => HttpClientResponse.schemaBodyJson(schema)(response);
|
|
506
|
+
const decodeValidationError = (response) => Effect.flatMap(HttpClientResponse.schemaBodyJson(HTTPValidationError)(response), (cause) => Effect.fail(new AiError.MalformedInput({
|
|
507
|
+
module: "DedalusClient",
|
|
508
|
+
method: response.request.url,
|
|
509
|
+
description: cause.detail?.map((v) => `${v.loc.join(".")}: ${v.msg}`).join("; ")
|
|
510
|
+
})));
|
|
511
|
+
return {
|
|
512
|
+
httpClient,
|
|
513
|
+
createChatCompletionV1ChatCompletionsPost: (options2) => HttpClientRequest.post(`/v1/chat/completions`).pipe(HttpClientRequest.bodyUnsafeJson(options2), withResponse(HttpClientResponse.matchStatus({
|
|
514
|
+
"2xx": decodeSuccess(ChatCompletion),
|
|
515
|
+
"422": decodeValidationError,
|
|
516
|
+
orElse: unexpectedStatus
|
|
517
|
+
}))),
|
|
518
|
+
createEmbeddingsV1EmbeddingsPost: (options2) => HttpClientRequest.post(`/v1/embeddings`).pipe(HttpClientRequest.bodyUnsafeJson(options2), withResponse(HttpClientResponse.matchStatus({
|
|
519
|
+
"2xx": decodeSuccess(CreateEmbeddingResponse),
|
|
520
|
+
"422": decodeValidationError,
|
|
521
|
+
orElse: unexpectedStatus
|
|
522
|
+
})))
|
|
523
|
+
};
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
class CreateEmbeddingRequestModelEnum extends S.Literal("openai/text-embedding-ada-002", "openai/text-embedding-3-small", "openai/text-embedding-3-large", "google/text-embedding-004") {
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
class CreateEmbeddingRequestEncodingFormat extends S.Literal("float", "base64") {
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
class CreateEmbeddingRequest extends S.Class("CreateEmbeddingRequest")({
|
|
533
|
+
input: S.Union(S.String, S.NonEmptyArray(S.String).pipe(S.minItems(1), S.maxItems(2048)), S.NonEmptyArray(S.Int).pipe(S.minItems(1), S.maxItems(2048)), S.NonEmptyArray(S.NonEmptyArray(S.Int).pipe(S.minItems(1))).pipe(S.minItems(1), S.maxItems(2048))),
|
|
534
|
+
model: S.Union(S.String, CreateEmbeddingRequestModelEnum),
|
|
535
|
+
encoding_format: S.optionalWith(CreateEmbeddingRequestEncodingFormat, {
|
|
536
|
+
nullable: true,
|
|
537
|
+
default: () => "float"
|
|
538
|
+
}),
|
|
539
|
+
dimensions: S.optionalWith(S.Int.pipe(S.greaterThanOrEqualTo(1)), {
|
|
540
|
+
nullable: true
|
|
541
|
+
}),
|
|
542
|
+
user: S.optionalWith(S.String, { nullable: true })
|
|
543
|
+
}) {
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
class Embedding extends S.Class("Embedding")({
|
|
547
|
+
object: S.optionalWith(S.Literal("embedding"), {
|
|
548
|
+
nullable: true,
|
|
549
|
+
default: () => "embedding"
|
|
550
|
+
}),
|
|
551
|
+
embedding: S.Union(S.Array(S.Number), S.String),
|
|
552
|
+
index: S.Int
|
|
553
|
+
}) {
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
class CreateEmbeddingResponse extends S.Class("CreateEmbeddingResponse")({
|
|
557
|
+
object: S.optionalWith(S.Literal("list"), {
|
|
558
|
+
nullable: true,
|
|
559
|
+
default: () => "list"
|
|
560
|
+
}),
|
|
561
|
+
data: S.Array(Embedding),
|
|
562
|
+
model: S.String,
|
|
563
|
+
usage: S.Record({ key: S.String, value: S.Unknown })
|
|
564
|
+
}) {
|
|
565
|
+
}
|
|
566
|
+
// packages/dedalus-labs/src/DedalusClient.ts
|
|
567
|
+
var exports_DedalusClient = {};
|
|
568
|
+
__export(exports_DedalusClient, {
|
|
569
|
+
make: () => make2,
|
|
570
|
+
layerConfig: () => layerConfig,
|
|
571
|
+
layer: () => layer,
|
|
572
|
+
DedalusClient: () => DedalusClient,
|
|
573
|
+
ChatCompletionChunkDelta: () => ChatCompletionChunkDelta,
|
|
574
|
+
ChatCompletionChunkChoice: () => ChatCompletionChunkChoice,
|
|
575
|
+
ChatCompletionChunk: () => ChatCompletionChunk
|
|
576
|
+
});
|
|
577
|
+
import * as Sse from "@effect/experimental/Sse";
|
|
578
|
+
import * as HttpBody from "@effect/platform/HttpBody";
|
|
579
|
+
import * as HttpClient from "@effect/platform/HttpClient";
|
|
580
|
+
import * as HttpClientRequest2 from "@effect/platform/HttpClientRequest";
|
|
581
|
+
import { AiError as AiError2 } from "@luketandjung/ariadne";
|
|
582
|
+
import * as Config from "effect/Config";
|
|
583
|
+
import * as Context2 from "effect/Context";
|
|
584
|
+
import * as Effect3 from "effect/Effect";
|
|
585
|
+
import { identity } from "effect/Function";
|
|
586
|
+
import * as Layer from "effect/Layer";
|
|
587
|
+
import * as Redacted from "effect/Redacted";
|
|
588
|
+
import * as Schema from "effect/Schema";
|
|
589
|
+
import * as Stream from "effect/Stream";
|
|
590
|
+
|
|
591
|
+
// packages/dedalus-labs/src/DedalusConfig.ts
|
|
592
|
+
var exports_DedalusConfig = {};
|
|
593
|
+
__export(exports_DedalusConfig, {
|
|
594
|
+
withClientTransform: () => withClientTransform,
|
|
595
|
+
DedalusConfig: () => DedalusConfig
|
|
596
|
+
});
|
|
597
|
+
import * as Context from "effect/Context";
|
|
598
|
+
import * as Effect2 from "effect/Effect";
|
|
599
|
+
import { dual } from "effect/Function";
|
|
600
|
+
|
|
601
|
+
class DedalusConfig extends Context.Tag("@dedalus-labs/DedalusConfig")() {
|
|
602
|
+
static getOrUndefined = Effect2.map(Effect2.context(), (context2) => context2.unsafeMap.get(DedalusConfig.key));
|
|
603
|
+
}
|
|
604
|
+
var withClientTransform = dual(2, (self, transformClient) => Effect2.flatMap(DedalusConfig.getOrUndefined, (config) => Effect2.provideService(self, DedalusConfig, {
|
|
605
|
+
...config,
|
|
606
|
+
transformClient
|
|
607
|
+
})));
|
|
608
|
+
|
|
609
|
+
// packages/dedalus-labs/src/internal/utilities.ts
|
|
610
|
+
var uuid4 = function() {
|
|
611
|
+
const { crypto } = globalThis;
|
|
612
|
+
if (crypto?.randomUUID) {
|
|
613
|
+
uuid4 = crypto.randomUUID.bind(crypto);
|
|
614
|
+
return crypto.randomUUID();
|
|
615
|
+
}
|
|
616
|
+
const u8 = new Uint8Array(1);
|
|
617
|
+
const randomByte = crypto ? () => crypto.getRandomValues(u8)[0] : () => Math.random() * 255 & 255;
|
|
618
|
+
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) => (+c ^ randomByte() & 15 >> +c / 4).toString(16));
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
// packages/dedalus-labs/src/DedalusClient.ts
|
|
622
|
+
class DedalusClient extends Context2.Tag("@dedalus-labs/DedalusClient")() {
|
|
623
|
+
}
|
|
624
|
+
var make2 = (options) => Effect3.gen(function* () {
|
|
625
|
+
const baseUrl = options.apiUrl ?? ((options.environment ?? "production") === "production" ? "https://api.dedaluslabs.ai" : "http://localhost:8080");
|
|
626
|
+
const httpClient = (yield* HttpClient.HttpClient).pipe(HttpClient.mapRequest((request) => {
|
|
627
|
+
const headers = {
|
|
628
|
+
"User-Agent": "Dedalus/JS 1.0.0",
|
|
629
|
+
"X-SDK-Version": "1.0.0"
|
|
630
|
+
};
|
|
631
|
+
if (options.provider) {
|
|
632
|
+
headers["X-Provider"] = options.provider;
|
|
633
|
+
}
|
|
634
|
+
if (options.providerKey) {
|
|
635
|
+
headers["X-Provider-Key"] = Redacted.value(options.providerKey);
|
|
636
|
+
}
|
|
637
|
+
if (request.method !== "GET") {
|
|
638
|
+
headers["Idempotency-Key"] = `stainless-node-retry-${uuid4()}`;
|
|
639
|
+
}
|
|
640
|
+
return request.pipe(HttpClientRequest2.prependUrl(baseUrl), options.apiKey ? HttpClientRequest2.bearerToken(options.apiKey) : options.xApiKey ? HttpClientRequest2.setHeader("x-api-key", Redacted.value(options.xApiKey)) : identity, HttpClientRequest2.setHeaders(headers), HttpClientRequest2.acceptJson);
|
|
641
|
+
}), options.transformClient ?? identity);
|
|
642
|
+
const httpClientOk = HttpClient.filterStatusOk(httpClient);
|
|
643
|
+
const client = make(httpClient, {
|
|
644
|
+
transformClient: (client2) => DedalusConfig.getOrUndefined.pipe(Effect3.map((config) => config?.transformClient ? config.transformClient(client2) : client2))
|
|
645
|
+
});
|
|
646
|
+
const createChatCompletion = (options2) => client.createChatCompletionV1ChatCompletionsPost(options2).pipe(Effect3.catchTags({
|
|
647
|
+
RequestError: (error) => AiError2.HttpRequestError.fromRequestError({
|
|
648
|
+
module: "DedalusClient",
|
|
649
|
+
method: "createChatCompletion",
|
|
650
|
+
error
|
|
651
|
+
}),
|
|
652
|
+
ResponseError: (error) => AiError2.HttpResponseError.fromResponseError({
|
|
653
|
+
module: "DedalusClient",
|
|
654
|
+
method: "createChatCompletion",
|
|
655
|
+
error
|
|
656
|
+
}),
|
|
657
|
+
ParseError: (error) => AiError2.MalformedOutput.fromParseError({
|
|
658
|
+
module: "DedalusClient",
|
|
659
|
+
method: "createChatCompletion",
|
|
660
|
+
error
|
|
661
|
+
})
|
|
662
|
+
}));
|
|
663
|
+
const createChatCompletionStream = (options2) => {
|
|
664
|
+
const request = HttpClientRequest2.post("/v1/chat/completions", {
|
|
665
|
+
body: HttpBody.unsafeJson({ ...options2, stream: true })
|
|
666
|
+
});
|
|
667
|
+
const decodeChunk = Schema.decode(Schema.parseJson(ChatCompletionChunk));
|
|
668
|
+
return httpClientOk.execute(request).pipe(Effect3.map((r) => r.stream), Stream.unwrapScoped, Stream.decodeText(), Stream.pipeThroughChannel(Sse.makeChannel()), Stream.mapEffect((event) => decodeChunk(event.data)), Stream.takeUntil((chunk) => chunk.choices.some((choice) => choice.finish_reason !== null)), Stream.catchTags({
|
|
669
|
+
RequestError: (error) => AiError2.HttpRequestError.fromRequestError({
|
|
670
|
+
module: "DedalusClient",
|
|
671
|
+
method: "createChatCompletionStream",
|
|
672
|
+
error
|
|
673
|
+
}),
|
|
674
|
+
ResponseError: (error) => AiError2.HttpResponseError.fromResponseError({
|
|
675
|
+
module: "DedalusClient",
|
|
676
|
+
method: "createChatCompletionStream",
|
|
677
|
+
error
|
|
678
|
+
}),
|
|
679
|
+
ParseError: (error) => AiError2.MalformedOutput.fromParseError({
|
|
680
|
+
module: "DedalusClient",
|
|
681
|
+
method: "createChatCompletionStream",
|
|
682
|
+
error
|
|
683
|
+
})
|
|
684
|
+
}));
|
|
685
|
+
};
|
|
686
|
+
const createEmbedding = (options2) => client.createEmbeddingsV1EmbeddingsPost(options2).pipe(Effect3.catchTags({
|
|
687
|
+
RequestError: (error) => AiError2.HttpRequestError.fromRequestError({
|
|
688
|
+
module: "DedalusClient",
|
|
689
|
+
method: "createEmbedding",
|
|
690
|
+
error
|
|
691
|
+
}),
|
|
692
|
+
ResponseError: (error) => AiError2.HttpResponseError.fromResponseError({
|
|
693
|
+
module: "DedalusClient",
|
|
694
|
+
method: "createEmbedding",
|
|
695
|
+
error
|
|
696
|
+
}),
|
|
697
|
+
ParseError: (error) => AiError2.MalformedOutput.fromParseError({
|
|
698
|
+
module: "DedalusClient",
|
|
699
|
+
method: "createEmbedding",
|
|
700
|
+
error
|
|
701
|
+
})
|
|
702
|
+
}));
|
|
703
|
+
return DedalusClient.of({
|
|
704
|
+
client,
|
|
705
|
+
createChatCompletion,
|
|
706
|
+
createChatCompletionStream,
|
|
707
|
+
createEmbedding
|
|
708
|
+
});
|
|
709
|
+
});
|
|
710
|
+
var layer = (options) => Layer.scoped(DedalusClient, make2(options));
|
|
711
|
+
var layerConfig = (options) => {
|
|
712
|
+
const { transformClient, ...configs } = options;
|
|
713
|
+
return Config.all(configs).pipe(Effect3.flatMap((configs2) => make2({ ...configs2, transformClient })), Layer.scoped(DedalusClient));
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
class ChatCompletionChunkDelta extends Schema.Class("@dedalus-labs/ChatCompletionChunkDelta")({
|
|
717
|
+
role: Schema.optional(Schema.Literal("developer", "system", "user", "assistant", "tool")),
|
|
718
|
+
content: Schema.optional(Schema.NullOr(Schema.String)),
|
|
719
|
+
refusal: Schema.optional(Schema.NullOr(Schema.String)),
|
|
720
|
+
tool_calls: Schema.optional(Schema.Array(Schema.Struct({
|
|
721
|
+
index: Schema.Int,
|
|
722
|
+
id: Schema.optional(Schema.String),
|
|
723
|
+
type: Schema.optional(Schema.Literal("function")),
|
|
724
|
+
function: Schema.optional(Schema.Struct({
|
|
725
|
+
name: Schema.optional(Schema.String),
|
|
726
|
+
arguments: Schema.optional(Schema.String)
|
|
727
|
+
}))
|
|
728
|
+
})))
|
|
729
|
+
}) {
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
class ChatCompletionChunkChoice extends Schema.Class("@dedalus-labs/ChatCompletionChunkChoice")({
|
|
733
|
+
index: Schema.Int,
|
|
734
|
+
delta: ChatCompletionChunkDelta,
|
|
735
|
+
logprobs: Schema.optional(Schema.NullOr(ChoiceLogprobs)),
|
|
736
|
+
finish_reason: Schema.NullOr(ChoiceFinishReasonEnum)
|
|
737
|
+
}) {
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
class ChatCompletionChunk extends Schema.Class("@dedalus-labs/ChatCompletionChunk")({
|
|
741
|
+
id: Schema.String,
|
|
742
|
+
object: Schema.Literal("chat.completion.chunk"),
|
|
743
|
+
created: Schema.Int,
|
|
744
|
+
model: Schema.String,
|
|
745
|
+
system_fingerprint: Schema.optional(Schema.NullOr(Schema.String)),
|
|
746
|
+
choices: Schema.Array(ChatCompletionChunkChoice),
|
|
747
|
+
usage: Schema.optional(Schema.NullOr(CompletionUsage)),
|
|
748
|
+
service_tier: Schema.optional(Schema.NullOr(ChatCompletionServiceTierEnum))
|
|
749
|
+
}) {
|
|
750
|
+
}
|
|
751
|
+
// packages/dedalus-labs/src/DedalusEmbeddingModel.ts
|
|
752
|
+
var exports_DedalusEmbeddingModel = {};
|
|
753
|
+
__export(exports_DedalusEmbeddingModel, {
|
|
754
|
+
withConfigOverride: () => withConfigOverride,
|
|
755
|
+
model: () => model,
|
|
756
|
+
makeDataLoader: () => makeDataLoader,
|
|
757
|
+
layerDataLoader: () => layerDataLoader,
|
|
758
|
+
layerBatched: () => layerBatched,
|
|
759
|
+
Config: () => Config2
|
|
760
|
+
});
|
|
761
|
+
import { Model as AiModel, EmbeddingModel } from "@luketandjung/ariadne";
|
|
762
|
+
import * as Context3 from "effect/Context";
|
|
763
|
+
import * as Effect4 from "effect/Effect";
|
|
764
|
+
import { dual as dual2 } from "effect/Function";
|
|
765
|
+
import * as Layer2 from "effect/Layer";
|
|
766
|
+
class Config2 extends Context3.Tag("@dedalus-labs/DedalusEmbeddingModel/Config")() {
|
|
767
|
+
static getOrUndefined = Effect4.map(Effect4.context(), (context3) => context3.unsafeMap.get(Config2.key));
|
|
768
|
+
}
|
|
769
|
+
var model = (model2, {
|
|
770
|
+
mode,
|
|
771
|
+
...config
|
|
772
|
+
}) => {
|
|
773
|
+
return AiModel.make("dedalus-labs", mode === "batched" ? layerBatched({ model: model2, config }) : layerDataLoader({ model: model2, config }));
|
|
774
|
+
};
|
|
775
|
+
var makeBatched = Effect4.fnUntraced(function* (options) {
|
|
776
|
+
const client = yield* DedalusClient;
|
|
777
|
+
const { config = {}, model: model2 } = options;
|
|
778
|
+
const { cache, maxBatchSize = 2048, ...globalConfig } = config;
|
|
779
|
+
const makeRequest = Effect4.fnUntraced(function* (input) {
|
|
780
|
+
const context3 = yield* Effect4.context();
|
|
781
|
+
const requestConfig = context3.unsafeMap.get(Config2.key);
|
|
782
|
+
const request = {
|
|
783
|
+
model: model2,
|
|
784
|
+
...globalConfig,
|
|
785
|
+
...requestConfig,
|
|
786
|
+
input
|
|
787
|
+
};
|
|
788
|
+
return request;
|
|
789
|
+
});
|
|
790
|
+
return yield* EmbeddingModel.make({
|
|
791
|
+
cache,
|
|
792
|
+
maxBatchSize,
|
|
793
|
+
embedMany: Effect4.fnUntraced(function* (input) {
|
|
794
|
+
const request = yield* makeRequest(input);
|
|
795
|
+
const response = yield* client.createEmbedding(request);
|
|
796
|
+
return makeResults(response);
|
|
797
|
+
})
|
|
798
|
+
});
|
|
799
|
+
});
|
|
800
|
+
var makeDataLoader = Effect4.fnUntraced(function* (options) {
|
|
801
|
+
const client = yield* DedalusClient;
|
|
802
|
+
const { config, model: model2 } = options;
|
|
803
|
+
const { maxBatchSize = 2048, window, ...globalConfig } = config;
|
|
804
|
+
const makeRequest = Effect4.fnUntraced(function* (input) {
|
|
805
|
+
const context3 = yield* Effect4.context();
|
|
806
|
+
const requestConfig = context3.unsafeMap.get(Config2.key);
|
|
807
|
+
const request = {
|
|
808
|
+
model: model2,
|
|
809
|
+
...globalConfig,
|
|
810
|
+
...requestConfig,
|
|
811
|
+
input
|
|
812
|
+
};
|
|
813
|
+
return request;
|
|
814
|
+
});
|
|
815
|
+
return yield* EmbeddingModel.makeDataLoader({
|
|
816
|
+
window,
|
|
817
|
+
maxBatchSize,
|
|
818
|
+
embedMany: Effect4.fnUntraced(function* (input) {
|
|
819
|
+
const request = yield* makeRequest(input);
|
|
820
|
+
const response = yield* client.createEmbedding(request);
|
|
821
|
+
return makeResults(response);
|
|
822
|
+
})
|
|
823
|
+
});
|
|
824
|
+
});
|
|
825
|
+
var layerBatched = (options) => Layer2.effect(EmbeddingModel.EmbeddingModel, makeBatched(options));
|
|
826
|
+
var layerDataLoader = (options) => Layer2.scoped(EmbeddingModel.EmbeddingModel, makeDataLoader(options));
|
|
827
|
+
var withConfigOverride = dual2(2, (self, overrides) => Effect4.flatMap(Config2.getOrUndefined, (config) => Effect4.provideService(self, Config2, { ...config, ...overrides })));
|
|
828
|
+
var makeResults = (response) => response.data.map(({ embedding, index }) => ({
|
|
829
|
+
embeddings: embedding,
|
|
830
|
+
index
|
|
831
|
+
}));
|
|
832
|
+
// packages/dedalus-labs/src/DedalusLanguageModel.ts
|
|
833
|
+
var exports_DedalusLanguageModel = {};
|
|
834
|
+
__export(exports_DedalusLanguageModel, {
|
|
835
|
+
withConfigOverride: () => withConfigOverride2,
|
|
836
|
+
model: () => model2,
|
|
837
|
+
make: () => make3,
|
|
838
|
+
layer: () => layer2,
|
|
839
|
+
Config: () => Config3
|
|
840
|
+
});
|
|
841
|
+
import {
|
|
842
|
+
AiError as AiError3,
|
|
843
|
+
Model as AiModel2,
|
|
844
|
+
IdGenerator,
|
|
845
|
+
LanguageModel,
|
|
846
|
+
McpRegistry,
|
|
847
|
+
Tool
|
|
848
|
+
} from "@luketandjung/ariadne";
|
|
849
|
+
import * as Context4 from "effect/Context";
|
|
850
|
+
import * as DateTime from "effect/DateTime";
|
|
851
|
+
import * as Effect5 from "effect/Effect";
|
|
852
|
+
import { dual as dual3 } from "effect/Function";
|
|
853
|
+
import * as Layer3 from "effect/Layer";
|
|
854
|
+
import * as Stream2 from "effect/Stream";
|
|
855
|
+
class Config3 extends Context4.Tag("@dedalus-labs/DedalusLanguageModel/Config")() {
|
|
856
|
+
static getOrUndefined = Effect5.map(Effect5.context(), (context4) => context4.unsafeMap.get(Config3.key));
|
|
857
|
+
}
|
|
858
|
+
var model2 = (model3, config) => AiModel2.make("dedalus-labs", layer2({ model: model3, config }));
|
|
859
|
+
var make3 = Effect5.fnUntraced(function* (options) {
|
|
860
|
+
const client = yield* DedalusClient;
|
|
861
|
+
const makeRequest = Effect5.fnUntraced(function* (providerOptions) {
|
|
862
|
+
const context4 = yield* Effect5.context();
|
|
863
|
+
const config = {
|
|
864
|
+
model: options.model,
|
|
865
|
+
...options.config,
|
|
866
|
+
...context4.unsafeMap.get(Config3.key)
|
|
867
|
+
};
|
|
868
|
+
const messages = yield* prepareMessages(providerOptions);
|
|
869
|
+
const { toolChoice, tools } = yield* prepareTools(providerOptions);
|
|
870
|
+
const responseFormat = prepareResponseFormat(providerOptions);
|
|
871
|
+
const request = {
|
|
872
|
+
...config,
|
|
873
|
+
messages,
|
|
874
|
+
tools,
|
|
875
|
+
tool_choice: toolChoice,
|
|
876
|
+
response_format: responseFormat,
|
|
877
|
+
mcp_servers: providerOptions.mcpServers.length > 0 ? McpRegistry.toApiFormat(providerOptions.mcpServers) : undefined
|
|
878
|
+
};
|
|
879
|
+
return request;
|
|
880
|
+
});
|
|
881
|
+
return yield* LanguageModel.make({
|
|
882
|
+
generateText: Effect5.fnUntraced(function* (options2) {
|
|
883
|
+
const request = yield* makeRequest(options2);
|
|
884
|
+
const rawResponse = yield* client.createChatCompletion(request);
|
|
885
|
+
return yield* makeResponse(rawResponse, options2);
|
|
886
|
+
}),
|
|
887
|
+
streamText: Effect5.fnUntraced(function* (options2) {
|
|
888
|
+
const request = yield* makeRequest(options2);
|
|
889
|
+
return client.createChatCompletionStream(request);
|
|
890
|
+
}, (effect3, options2) => effect3.pipe(Effect5.flatMap((stream) => makeStreamResponse(stream, options2)), Stream2.unwrap))
|
|
891
|
+
});
|
|
892
|
+
});
|
|
893
|
+
var layer2 = (options) => Layer3.effect(LanguageModel.LanguageModel, make3({ model: options.model, config: options.config }));
|
|
894
|
+
var withConfigOverride2 = dual3(2, (self, overrides) => Effect5.flatMap(Config3.getOrUndefined, (config) => Effect5.provideService(self, Config3, { ...config, ...overrides })));
|
|
895
|
+
var prepareMessages = (options) => Effect5.gen(function* () {
|
|
896
|
+
const messages = [];
|
|
897
|
+
for (const message of options.prompt.content) {
|
|
898
|
+
switch (message.role) {
|
|
899
|
+
case "system": {
|
|
900
|
+
messages.push({
|
|
901
|
+
role: "system",
|
|
902
|
+
content: message.content
|
|
903
|
+
});
|
|
904
|
+
break;
|
|
905
|
+
}
|
|
906
|
+
case "user": {
|
|
907
|
+
const textParts = [];
|
|
908
|
+
for (const part of message.content) {
|
|
909
|
+
switch (part.type) {
|
|
910
|
+
case "text": {
|
|
911
|
+
textParts.push(part.text);
|
|
912
|
+
break;
|
|
913
|
+
}
|
|
914
|
+
case "file": {
|
|
915
|
+
return yield* new AiError3.MalformedInput({
|
|
916
|
+
module: "DedalusLanguageModel",
|
|
917
|
+
method: "prepareMessages",
|
|
918
|
+
description: `File attachments are not yet supported. Received file with media type: '${part.mediaType}'`
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
messages.push({
|
|
924
|
+
role: "user",
|
|
925
|
+
content: textParts.join(`
|
|
926
|
+
`)
|
|
927
|
+
});
|
|
928
|
+
break;
|
|
929
|
+
}
|
|
930
|
+
case "assistant": {
|
|
931
|
+
const textParts = [];
|
|
932
|
+
const toolCalls = [];
|
|
933
|
+
for (const part of message.content) {
|
|
934
|
+
switch (part.type) {
|
|
935
|
+
case "text": {
|
|
936
|
+
textParts.push(part.text);
|
|
937
|
+
break;
|
|
938
|
+
}
|
|
939
|
+
case "tool-call": {
|
|
940
|
+
if (!part.providerExecuted) {
|
|
941
|
+
toolCalls.push({
|
|
942
|
+
id: part.id,
|
|
943
|
+
type: "function",
|
|
944
|
+
function: {
|
|
945
|
+
name: part.name,
|
|
946
|
+
arguments: JSON.stringify(part.params)
|
|
947
|
+
}
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
break;
|
|
951
|
+
}
|
|
952
|
+
case "reasoning": {
|
|
953
|
+
break;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
const content = textParts.length > 0 ? textParts.join(`
|
|
958
|
+
`) : null;
|
|
959
|
+
if (toolCalls.length > 0) {
|
|
960
|
+
messages.push({
|
|
961
|
+
role: "assistant",
|
|
962
|
+
content,
|
|
963
|
+
tool_calls: toolCalls
|
|
964
|
+
});
|
|
965
|
+
} else if (content !== null) {
|
|
966
|
+
messages.push({
|
|
967
|
+
role: "assistant",
|
|
968
|
+
content
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
break;
|
|
972
|
+
}
|
|
973
|
+
case "tool": {
|
|
974
|
+
for (const part of message.content) {
|
|
975
|
+
messages.push({
|
|
976
|
+
role: "tool",
|
|
977
|
+
tool_call_id: part.id,
|
|
978
|
+
content: JSON.stringify(part.result)
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
break;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
return messages;
|
|
986
|
+
});
|
|
987
|
+
var makeResponse = Effect5.fnUntraced(function* (response, _options) {
|
|
988
|
+
const idGenerator = yield* IdGenerator.IdGenerator;
|
|
989
|
+
const parts = [];
|
|
990
|
+
const createdAt = new Date(response.created * 1000);
|
|
991
|
+
parts.push({
|
|
992
|
+
type: "response-metadata",
|
|
993
|
+
id: response.id,
|
|
994
|
+
modelId: response.model,
|
|
995
|
+
timestamp: DateTime.formatIso(DateTime.unsafeFromDate(createdAt))
|
|
996
|
+
});
|
|
997
|
+
const choice = response.choices[0];
|
|
998
|
+
if (choice) {
|
|
999
|
+
const message = choice.message;
|
|
1000
|
+
if (message.content !== null && message.content !== undefined) {
|
|
1001
|
+
parts.push({
|
|
1002
|
+
type: "text",
|
|
1003
|
+
text: message.content
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
if (message.refusal !== null && message.refusal !== undefined) {
|
|
1007
|
+
parts.push({
|
|
1008
|
+
type: "text",
|
|
1009
|
+
text: "",
|
|
1010
|
+
metadata: { dedalus: { refusal: message.refusal } }
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
if (message.annotations) {
|
|
1014
|
+
for (const annotation of message.annotations) {
|
|
1015
|
+
if (annotation.type === "url_citation") {
|
|
1016
|
+
parts.push({
|
|
1017
|
+
type: "source",
|
|
1018
|
+
sourceType: "url",
|
|
1019
|
+
id: yield* idGenerator.generateId(),
|
|
1020
|
+
url: annotation.url_citation.url,
|
|
1021
|
+
title: annotation.url_citation.title,
|
|
1022
|
+
metadata: {
|
|
1023
|
+
dedalus: {
|
|
1024
|
+
startIndex: annotation.url_citation.start_index,
|
|
1025
|
+
endIndex: annotation.url_citation.end_index
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
if (message.tool_calls) {
|
|
1033
|
+
for (const toolCall of message.tool_calls) {
|
|
1034
|
+
if (toolCall.type === "function") {
|
|
1035
|
+
const toolName = toolCall.function.name;
|
|
1036
|
+
const toolParams = toolCall.function.arguments;
|
|
1037
|
+
const params = yield* Effect5.try({
|
|
1038
|
+
try: () => Tool.unsafeSecureJsonParse(toolParams),
|
|
1039
|
+
catch: (cause) => new AiError3.MalformedOutput({
|
|
1040
|
+
module: "DedalusLanguageModel",
|
|
1041
|
+
method: "makeResponse",
|
|
1042
|
+
description: "Failed to securely parse tool call parameters " + `for tool '${toolName}':
|
|
1043
|
+
Parameters: ${toolParams}`,
|
|
1044
|
+
cause
|
|
1045
|
+
})
|
|
1046
|
+
});
|
|
1047
|
+
parts.push({
|
|
1048
|
+
type: "tool-call",
|
|
1049
|
+
id: toolCall.id,
|
|
1050
|
+
name: toolName,
|
|
1051
|
+
params
|
|
1052
|
+
});
|
|
1053
|
+
} else if (toolCall.type === "custom") {
|
|
1054
|
+
const toolName = toolCall.custom.name;
|
|
1055
|
+
const toolInput = toolCall.custom.input;
|
|
1056
|
+
const params = yield* Effect5.try({
|
|
1057
|
+
try: () => Tool.unsafeSecureJsonParse(toolInput),
|
|
1058
|
+
catch: (cause) => new AiError3.MalformedOutput({
|
|
1059
|
+
module: "DedalusLanguageModel",
|
|
1060
|
+
method: "makeResponse",
|
|
1061
|
+
description: "Failed to securely parse custom tool call input " + `for tool '${toolName}':
|
|
1062
|
+
Input: ${toolInput}`,
|
|
1063
|
+
cause
|
|
1064
|
+
})
|
|
1065
|
+
});
|
|
1066
|
+
parts.push({
|
|
1067
|
+
type: "tool-call",
|
|
1068
|
+
id: toolCall.id,
|
|
1069
|
+
name: toolName,
|
|
1070
|
+
params
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
const hasToolCalls = (message.tool_calls?.length ?? 0) > 0;
|
|
1076
|
+
const finishReason = resolveFinishReason(choice.finish_reason, hasToolCalls);
|
|
1077
|
+
parts.push({
|
|
1078
|
+
type: "finish",
|
|
1079
|
+
reason: finishReason,
|
|
1080
|
+
usage: {
|
|
1081
|
+
inputTokens: response.usage?.prompt_tokens,
|
|
1082
|
+
outputTokens: response.usage?.completion_tokens,
|
|
1083
|
+
totalTokens: response.usage?.total_tokens,
|
|
1084
|
+
reasoningTokens: response.usage?.completion_tokens_details?.reasoning_tokens,
|
|
1085
|
+
cachedInputTokens: response.usage?.prompt_tokens_details?.cached_tokens
|
|
1086
|
+
},
|
|
1087
|
+
metadata: {
|
|
1088
|
+
dedalus: {
|
|
1089
|
+
serviceTier: response.service_tier,
|
|
1090
|
+
toolsExecuted: response.tools_executed,
|
|
1091
|
+
mcpServerErrors: response.mcp_server_errors
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
if (response.tools_executed && response.tools_executed.length > 0) {
|
|
1097
|
+
for (const toolName of response.tools_executed) {
|
|
1098
|
+
parts.push({
|
|
1099
|
+
type: "tool-call",
|
|
1100
|
+
id: yield* idGenerator.generateId(),
|
|
1101
|
+
name: toolName,
|
|
1102
|
+
params: {},
|
|
1103
|
+
providerExecuted: true
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
return parts;
|
|
1108
|
+
});
|
|
1109
|
+
var makeStreamResponse = (stream, _options) => Effect5.gen(function* () {
|
|
1110
|
+
const activeToolCalls = new Map;
|
|
1111
|
+
let hasEmittedMetadata = false;
|
|
1112
|
+
let hasToolCalls = false;
|
|
1113
|
+
return stream.pipe(Stream2.mapEffect(Effect5.fnUntraced(function* (chunk) {
|
|
1114
|
+
const parts = [];
|
|
1115
|
+
if (!hasEmittedMetadata) {
|
|
1116
|
+
const createdAt = new Date(chunk.created * 1000);
|
|
1117
|
+
parts.push({
|
|
1118
|
+
type: "response-metadata",
|
|
1119
|
+
id: chunk.id,
|
|
1120
|
+
modelId: chunk.model,
|
|
1121
|
+
timestamp: DateTime.formatIso(DateTime.unsafeFromDate(createdAt))
|
|
1122
|
+
});
|
|
1123
|
+
hasEmittedMetadata = true;
|
|
1124
|
+
}
|
|
1125
|
+
const choice = chunk.choices[0];
|
|
1126
|
+
if (choice) {
|
|
1127
|
+
const delta = choice.delta;
|
|
1128
|
+
if (delta.content !== null && delta.content !== undefined) {
|
|
1129
|
+
parts.push({
|
|
1130
|
+
type: "text-delta",
|
|
1131
|
+
id: chunk.id,
|
|
1132
|
+
delta: delta.content
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
if (delta.tool_calls) {
|
|
1136
|
+
for (const toolCallDelta of delta.tool_calls) {
|
|
1137
|
+
const index = toolCallDelta.index;
|
|
1138
|
+
if (toolCallDelta.id) {
|
|
1139
|
+
activeToolCalls.set(index, {
|
|
1140
|
+
id: toolCallDelta.id,
|
|
1141
|
+
name: toolCallDelta.function?.name ?? "",
|
|
1142
|
+
arguments: ""
|
|
1143
|
+
});
|
|
1144
|
+
parts.push({
|
|
1145
|
+
type: "tool-params-start",
|
|
1146
|
+
id: toolCallDelta.id,
|
|
1147
|
+
name: toolCallDelta.function?.name ?? ""
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
const toolCall = activeToolCalls.get(index);
|
|
1151
|
+
if (toolCall) {
|
|
1152
|
+
if (toolCallDelta.function?.name) {
|
|
1153
|
+
toolCall.name = toolCallDelta.function.name;
|
|
1154
|
+
}
|
|
1155
|
+
if (toolCallDelta.function?.arguments) {
|
|
1156
|
+
toolCall.arguments += toolCallDelta.function.arguments;
|
|
1157
|
+
parts.push({
|
|
1158
|
+
type: "tool-params-delta",
|
|
1159
|
+
id: toolCall.id,
|
|
1160
|
+
delta: toolCallDelta.function.arguments
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
if (choice.finish_reason !== null) {
|
|
1167
|
+
for (const [_index, toolCall] of activeToolCalls) {
|
|
1168
|
+
hasToolCalls = true;
|
|
1169
|
+
const params = yield* Effect5.try({
|
|
1170
|
+
try: () => Tool.unsafeSecureJsonParse(toolCall.arguments),
|
|
1171
|
+
catch: (cause) => new AiError3.MalformedOutput({
|
|
1172
|
+
module: "DedalusLanguageModel",
|
|
1173
|
+
method: "makeStreamResponse",
|
|
1174
|
+
description: "Failed to securely parse tool call parameters " + `for tool '${toolCall.name}':
|
|
1175
|
+
Parameters: ${toolCall.arguments}`,
|
|
1176
|
+
cause
|
|
1177
|
+
})
|
|
1178
|
+
});
|
|
1179
|
+
parts.push({
|
|
1180
|
+
type: "tool-params-end",
|
|
1181
|
+
id: toolCall.id
|
|
1182
|
+
});
|
|
1183
|
+
parts.push({
|
|
1184
|
+
type: "tool-call",
|
|
1185
|
+
id: toolCall.id,
|
|
1186
|
+
name: toolCall.name,
|
|
1187
|
+
params
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
activeToolCalls.clear();
|
|
1191
|
+
const finishReason = resolveFinishReason(choice.finish_reason, hasToolCalls);
|
|
1192
|
+
parts.push({
|
|
1193
|
+
type: "finish",
|
|
1194
|
+
reason: finishReason,
|
|
1195
|
+
usage: {
|
|
1196
|
+
inputTokens: chunk.usage?.prompt_tokens,
|
|
1197
|
+
outputTokens: chunk.usage?.completion_tokens,
|
|
1198
|
+
totalTokens: chunk.usage?.total_tokens,
|
|
1199
|
+
reasoningTokens: chunk.usage?.completion_tokens_details?.reasoning_tokens,
|
|
1200
|
+
cachedInputTokens: chunk.usage?.prompt_tokens_details?.cached_tokens
|
|
1201
|
+
},
|
|
1202
|
+
metadata: {
|
|
1203
|
+
dedalus: { serviceTier: chunk.service_tier }
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
return parts;
|
|
1209
|
+
})), Stream2.flattenIterables);
|
|
1210
|
+
});
|
|
1211
|
+
var resolveFinishReason = (finishReason, hasToolCalls) => {
|
|
1212
|
+
if (hasToolCalls)
|
|
1213
|
+
return "tool-calls";
|
|
1214
|
+
switch (finishReason) {
|
|
1215
|
+
case "stop":
|
|
1216
|
+
return "stop";
|
|
1217
|
+
case "length":
|
|
1218
|
+
return "length";
|
|
1219
|
+
case "content_filter":
|
|
1220
|
+
return "content-filter";
|
|
1221
|
+
case "tool_calls":
|
|
1222
|
+
case "function_call":
|
|
1223
|
+
return "tool-calls";
|
|
1224
|
+
default:
|
|
1225
|
+
return finishReason ? "unknown" : "stop";
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
var prepareTools = Effect5.fnUntraced(function* (options) {
|
|
1229
|
+
if (options.tools.length === 0) {
|
|
1230
|
+
return { tools: undefined, toolChoice: undefined };
|
|
1231
|
+
}
|
|
1232
|
+
const tools = [];
|
|
1233
|
+
let toolChoice = undefined;
|
|
1234
|
+
let allowedTools = options.tools;
|
|
1235
|
+
if (typeof options.toolChoice === "object" && "oneOf" in options.toolChoice) {
|
|
1236
|
+
const allowedToolNames = new Set(options.toolChoice.oneOf);
|
|
1237
|
+
allowedTools = options.tools.filter((tool) => allowedToolNames.has(tool.name));
|
|
1238
|
+
toolChoice = options.toolChoice.mode === "required" ? "required" : "auto";
|
|
1239
|
+
}
|
|
1240
|
+
for (const tool of allowedTools) {
|
|
1241
|
+
if (Tool.isUserDefined(tool)) {
|
|
1242
|
+
tools.push({
|
|
1243
|
+
type: "function",
|
|
1244
|
+
function: {
|
|
1245
|
+
name: tool.name,
|
|
1246
|
+
description: tool.description ?? Tool.getDescriptionFromSchemaAst(tool.parametersSchema.ast),
|
|
1247
|
+
parameters: Tool.getJsonSchemaFromSchemaAst(tool.parametersSchema.ast),
|
|
1248
|
+
strict: true
|
|
1249
|
+
}
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
if (Tool.isProviderDefined(tool)) {
|
|
1253
|
+
return yield* new AiError3.MalformedInput({
|
|
1254
|
+
module: "DedalusLanguageModel",
|
|
1255
|
+
method: "prepareTools",
|
|
1256
|
+
description: `Provider-defined tools are not supported. Received: '${tool.name}'`
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
if (options.toolChoice === "none" || options.toolChoice === "required") {
|
|
1261
|
+
toolChoice = options.toolChoice;
|
|
1262
|
+
}
|
|
1263
|
+
if (typeof options.toolChoice === "object" && "tool" in options.toolChoice) {
|
|
1264
|
+
toolChoice = {
|
|
1265
|
+
type: "function",
|
|
1266
|
+
function: { name: options.toolChoice.tool }
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
return { tools, toolChoice };
|
|
1270
|
+
});
|
|
1271
|
+
var prepareResponseFormat = (options) => {
|
|
1272
|
+
if (options.responseFormat.type === "json") {
|
|
1273
|
+
const name = options.responseFormat.objectName;
|
|
1274
|
+
const schema = options.responseFormat.schema;
|
|
1275
|
+
return {
|
|
1276
|
+
type: "json_schema",
|
|
1277
|
+
json_schema: {
|
|
1278
|
+
name,
|
|
1279
|
+
description: Tool.getDescriptionFromSchemaAst(schema.ast) ?? "Response with a JSON object",
|
|
1280
|
+
schema: Tool.getJsonSchemaFromSchemaAst(schema.ast),
|
|
1281
|
+
strict: true
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
return;
|
|
1286
|
+
};
|
|
1287
|
+
export {
|
|
1288
|
+
exports_Generated as Generated,
|
|
1289
|
+
exports_DedalusLanguageModel as DedalusLanguageModel,
|
|
1290
|
+
exports_DedalusEmbeddingModel as DedalusEmbeddingModel,
|
|
1291
|
+
exports_DedalusConfig as DedalusConfig,
|
|
1292
|
+
exports_DedalusClient as DedalusClient
|
|
1293
|
+
};
|