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