@mozaik-ai/core 3.13.0 → 3.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +188 -128
- package/dist/index.d.mts +84 -574
- package/dist/index.d.ts +84 -574
- package/dist/index.js +972 -1218
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +972 -1201
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
- package/tests/README.md +0 -31
package/dist/index.js
CHANGED
|
@@ -32,33 +32,16 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
AgenticEnvironment: () => AgenticEnvironment,
|
|
34
34
|
AgenticError: () => AgenticError,
|
|
35
|
-
AnthropicMessages: () => AnthropicMessages,
|
|
36
35
|
BaseParticipant: () => BaseParticipant,
|
|
37
|
-
ClaudeHaiku45: () => ClaudeHaiku45,
|
|
38
|
-
ClaudeOpus47: () => ClaudeOpus47,
|
|
39
|
-
ClaudeOpus48: () => ClaudeOpus48,
|
|
40
|
-
ClaudeSonnet46: () => ClaudeSonnet46,
|
|
41
36
|
ContextItem: () => ContextItem,
|
|
42
|
-
DeepSeekV4Flash: () => DeepSeekV4Flash,
|
|
43
|
-
DeepSeekV4Pro: () => DeepSeekV4Pro,
|
|
44
37
|
DeveloperMessageItem: () => DeveloperMessageItem,
|
|
45
38
|
FunctionCallItem: () => FunctionCallItem,
|
|
46
39
|
FunctionCallOutputItem: () => FunctionCallOutputItem,
|
|
47
|
-
Gemini31Pro: () => Gemini31Pro,
|
|
48
|
-
Gemini35Flash: () => Gemini35Flash,
|
|
49
|
-
GeminiGenerateContent: () => GeminiGenerateContent,
|
|
50
|
-
Gpt54: () => Gpt54,
|
|
51
|
-
Gpt54Mini: () => Gpt54Mini,
|
|
52
|
-
Gpt54Nano: () => Gpt54Nano,
|
|
53
|
-
Gpt55: () => Gpt55,
|
|
54
40
|
InMemoryModelContextRepository: () => InMemoryModelContextRepository,
|
|
55
|
-
InferenceRequest: () => InferenceRequest,
|
|
56
41
|
InferenceResponse: () => InferenceResponse,
|
|
57
42
|
InputTokenDetails: () => InputTokenDetails,
|
|
58
43
|
ModelContext: () => ModelContext,
|
|
59
44
|
ModelMessageItem: () => ModelMessageItem,
|
|
60
|
-
OpenAIChatCompletions: () => OpenAIChatCompletions,
|
|
61
|
-
OpenAIResponses: () => OpenAIResponses,
|
|
62
45
|
OutputTokenDetails: () => OutputTokenDetails,
|
|
63
46
|
Participant: () => Participant,
|
|
64
47
|
ReasoningItem: () => ReasoningItem,
|
|
@@ -109,9 +92,6 @@ var ModelContext = class _ModelContext {
|
|
|
109
92
|
static rehydrate(data) {
|
|
110
93
|
return new _ModelContext(data.id, data.projectId, data.items);
|
|
111
94
|
}
|
|
112
|
-
toJSON() {
|
|
113
|
-
return this.items.map((item) => item.toJSON());
|
|
114
|
-
}
|
|
115
95
|
};
|
|
116
96
|
|
|
117
97
|
// src/domain/model-context/context-item/context-item.ts
|
|
@@ -138,14 +118,6 @@ var InputText = class _InputText extends ItemContent {
|
|
|
138
118
|
static rehydrate(data) {
|
|
139
119
|
return new _InputText(data.text);
|
|
140
120
|
}
|
|
141
|
-
toJSON() {
|
|
142
|
-
return [
|
|
143
|
-
{
|
|
144
|
-
type: this.type,
|
|
145
|
-
text: this.text
|
|
146
|
-
}
|
|
147
|
-
];
|
|
148
|
-
}
|
|
149
121
|
};
|
|
150
122
|
|
|
151
123
|
// src/domain/model-context/context-item/client-item/user-message.ts
|
|
@@ -164,13 +136,6 @@ var UserMessageItem = class _UserMessageItem extends ContextItem {
|
|
|
164
136
|
const content = InputText.rehydrate(data);
|
|
165
137
|
return new _UserMessageItem(content);
|
|
166
138
|
}
|
|
167
|
-
toJSON() {
|
|
168
|
-
return {
|
|
169
|
-
type: this.type,
|
|
170
|
-
role: this.role,
|
|
171
|
-
content: this.content.toJSON()
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
139
|
};
|
|
175
140
|
|
|
176
141
|
// src/domain/model-context/context-item/client-item/developer-message.ts
|
|
@@ -181,13 +146,6 @@ var DeveloperMessageItem = class _DeveloperMessageItem extends ContextItem {
|
|
|
181
146
|
this.role = "developer";
|
|
182
147
|
this.content = content;
|
|
183
148
|
}
|
|
184
|
-
toJSON() {
|
|
185
|
-
return {
|
|
186
|
-
type: this.type,
|
|
187
|
-
role: this.role,
|
|
188
|
-
content: this.content.toJSON()
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
149
|
static create(text) {
|
|
192
150
|
const content = InputText.create(text);
|
|
193
151
|
return new _DeveloperMessageItem(content);
|
|
@@ -208,14 +166,6 @@ var OutputText = class _OutputText extends ItemContent {
|
|
|
208
166
|
static rehydrate(data) {
|
|
209
167
|
return new _OutputText(data.text);
|
|
210
168
|
}
|
|
211
|
-
toJSON() {
|
|
212
|
-
return [
|
|
213
|
-
{
|
|
214
|
-
type: this.type,
|
|
215
|
-
text: this.text
|
|
216
|
-
}
|
|
217
|
-
];
|
|
218
|
-
}
|
|
219
169
|
};
|
|
220
170
|
|
|
221
171
|
// src/domain/model-context/context-item/model-item/model-message.ts
|
|
@@ -230,13 +180,6 @@ var ModelMessageItem = class _ModelMessageItem extends ContextItem {
|
|
|
230
180
|
const content = OutputText.rehydrate(data);
|
|
231
181
|
return new _ModelMessageItem(content);
|
|
232
182
|
}
|
|
233
|
-
toJSON() {
|
|
234
|
-
return {
|
|
235
|
-
type: this.type,
|
|
236
|
-
role: this.role,
|
|
237
|
-
content: this.content.toJSON()
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
183
|
};
|
|
241
184
|
|
|
242
185
|
// src/domain/model-context/context-item/model-item/function-call.ts
|
|
@@ -251,14 +194,6 @@ var FunctionCallItem = class _FunctionCallItem extends ContextItem {
|
|
|
251
194
|
static rehydrate(data) {
|
|
252
195
|
return new _FunctionCallItem(data.callId, data.name, data.args);
|
|
253
196
|
}
|
|
254
|
-
toJSON() {
|
|
255
|
-
return {
|
|
256
|
-
type: this.type,
|
|
257
|
-
call_id: this.callId,
|
|
258
|
-
name: this.name,
|
|
259
|
-
arguments: this.args
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
197
|
};
|
|
263
198
|
|
|
264
199
|
// src/domain/model-context/context-item/model-item/reasoning.ts
|
|
@@ -273,14 +208,18 @@ var ReasoningItem = class _ReasoningItem extends ContextItem {
|
|
|
273
208
|
static rehydrate(data) {
|
|
274
209
|
return new _ReasoningItem(data.content, data.encryptedContent, data.summary);
|
|
275
210
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/domain/generative-model/request-validation/structured-output.ts
|
|
214
|
+
var StructuredOutputValidation = class {
|
|
215
|
+
constructor() {
|
|
216
|
+
this.name = "structured-output";
|
|
217
|
+
}
|
|
218
|
+
isValid(inferenceParams, model) {
|
|
219
|
+
if (inferenceParams.structuredOutput === void 0) {
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
return model.supportsStructuredOutput;
|
|
284
223
|
}
|
|
285
224
|
};
|
|
286
225
|
|
|
@@ -299,179 +238,6 @@ var FunctionCallOutputItem = class _FunctionCallOutputItem extends ContextItem {
|
|
|
299
238
|
static rehydrate(data) {
|
|
300
239
|
return new _FunctionCallOutputItem(data.callId, data.output);
|
|
301
240
|
}
|
|
302
|
-
toJSON() {
|
|
303
|
-
return {
|
|
304
|
-
type: this.type,
|
|
305
|
-
call_id: this.callId,
|
|
306
|
-
output: this.output.toJSON()
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
// src/infrastructure/providers/openai/reasoning-effort.ts
|
|
312
|
-
var OpenAIReasoningEffort = class {
|
|
313
|
-
constructor(reasoningEffort) {
|
|
314
|
-
this.reasoningEffort = reasoningEffort;
|
|
315
|
-
}
|
|
316
|
-
setReasoningEffort(effort) {
|
|
317
|
-
this.reasoningEffort = effort;
|
|
318
|
-
}
|
|
319
|
-
getReasoningEffort() {
|
|
320
|
-
if (!this.reasoningEffort) {
|
|
321
|
-
throw new Error("Reasoning effort not supported");
|
|
322
|
-
}
|
|
323
|
-
return this.reasoningEffort;
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
// src/infrastructure/providers/openai/models/gpt-5-4-nano.ts
|
|
328
|
-
var Gpt54Nano = class {
|
|
329
|
-
constructor() {
|
|
330
|
-
this.specification = {
|
|
331
|
-
name: "gpt-5.4-nano",
|
|
332
|
-
provider: "openai",
|
|
333
|
-
supportReasoningEffort: true,
|
|
334
|
-
defaultReasoningEffort: "none",
|
|
335
|
-
supportStreaming: true,
|
|
336
|
-
contextWindowSize: 4e5,
|
|
337
|
-
maxOutputTokens: 128e3,
|
|
338
|
-
supportFunctionCalling: true,
|
|
339
|
-
supportStructuredOutput: true
|
|
340
|
-
};
|
|
341
|
-
this.tools = [];
|
|
342
|
-
this.streaming = false;
|
|
343
|
-
this.structuredOutput = void 0;
|
|
344
|
-
this.effort = new OpenAIReasoningEffort(
|
|
345
|
-
this.specification.defaultReasoningEffort
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
setStreaming(streaming) {
|
|
349
|
-
this.streaming = streaming;
|
|
350
|
-
}
|
|
351
|
-
getStreaming() {
|
|
352
|
-
return this.streaming;
|
|
353
|
-
}
|
|
354
|
-
setTools(tools) {
|
|
355
|
-
this.tools = tools;
|
|
356
|
-
}
|
|
357
|
-
getTools() {
|
|
358
|
-
return this.tools;
|
|
359
|
-
}
|
|
360
|
-
setReasoningEffort(effort) {
|
|
361
|
-
this.effort.setReasoningEffort(effort);
|
|
362
|
-
}
|
|
363
|
-
getReasoningEffort() {
|
|
364
|
-
return this.effort.getReasoningEffort();
|
|
365
|
-
}
|
|
366
|
-
setStructuredOutput(format) {
|
|
367
|
-
this.structuredOutput = format;
|
|
368
|
-
}
|
|
369
|
-
getStructuredOutput() {
|
|
370
|
-
return this.structuredOutput;
|
|
371
|
-
}
|
|
372
|
-
hasStructuredOutput() {
|
|
373
|
-
return this.structuredOutput !== void 0;
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
// src/infrastructure/providers/openai/models/gpt-5-4.ts
|
|
378
|
-
var Gpt54 = class {
|
|
379
|
-
constructor() {
|
|
380
|
-
this.specification = {
|
|
381
|
-
name: "gpt-5.4",
|
|
382
|
-
provider: "openai",
|
|
383
|
-
supportReasoningEffort: true,
|
|
384
|
-
defaultReasoningEffort: "none",
|
|
385
|
-
supportStreaming: true,
|
|
386
|
-
contextWindowSize: 105e4,
|
|
387
|
-
maxOutputTokens: 128e3,
|
|
388
|
-
supportFunctionCalling: true,
|
|
389
|
-
supportStructuredOutput: true
|
|
390
|
-
};
|
|
391
|
-
this.tools = [];
|
|
392
|
-
this.streaming = false;
|
|
393
|
-
this.structuredOutput = void 0;
|
|
394
|
-
this.effort = new OpenAIReasoningEffort(
|
|
395
|
-
this.specification.defaultReasoningEffort
|
|
396
|
-
);
|
|
397
|
-
}
|
|
398
|
-
setStreaming(streaming) {
|
|
399
|
-
this.streaming = streaming;
|
|
400
|
-
}
|
|
401
|
-
getStreaming() {
|
|
402
|
-
return this.streaming;
|
|
403
|
-
}
|
|
404
|
-
setTools(tools) {
|
|
405
|
-
this.tools = tools;
|
|
406
|
-
}
|
|
407
|
-
getTools() {
|
|
408
|
-
return this.tools;
|
|
409
|
-
}
|
|
410
|
-
setReasoningEffort(effort) {
|
|
411
|
-
this.effort.setReasoningEffort(effort);
|
|
412
|
-
}
|
|
413
|
-
getReasoningEffort() {
|
|
414
|
-
return this.effort.getReasoningEffort();
|
|
415
|
-
}
|
|
416
|
-
setStructuredOutput(format) {
|
|
417
|
-
this.structuredOutput = format;
|
|
418
|
-
}
|
|
419
|
-
getStructuredOutput() {
|
|
420
|
-
return this.structuredOutput;
|
|
421
|
-
}
|
|
422
|
-
hasStructuredOutput() {
|
|
423
|
-
return this.structuredOutput !== void 0;
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
// src/infrastructure/providers/openai/models/gpt-5-4-mini.ts
|
|
428
|
-
var Gpt54Mini = class {
|
|
429
|
-
constructor() {
|
|
430
|
-
this.specification = {
|
|
431
|
-
name: "gpt-5.4-mini",
|
|
432
|
-
provider: "openai",
|
|
433
|
-
supportReasoningEffort: true,
|
|
434
|
-
defaultReasoningEffort: "none",
|
|
435
|
-
supportStreaming: true,
|
|
436
|
-
contextWindowSize: 4e5,
|
|
437
|
-
maxOutputTokens: 128e3,
|
|
438
|
-
supportFunctionCalling: true,
|
|
439
|
-
supportStructuredOutput: true
|
|
440
|
-
};
|
|
441
|
-
this.tools = [];
|
|
442
|
-
this.streaming = false;
|
|
443
|
-
this.structuredOutput = void 0;
|
|
444
|
-
this.effort = new OpenAIReasoningEffort(
|
|
445
|
-
this.specification.defaultReasoningEffort
|
|
446
|
-
);
|
|
447
|
-
}
|
|
448
|
-
setStreaming(streaming) {
|
|
449
|
-
this.streaming = streaming;
|
|
450
|
-
}
|
|
451
|
-
getStreaming() {
|
|
452
|
-
return this.streaming;
|
|
453
|
-
}
|
|
454
|
-
setReasoningEffort(effort) {
|
|
455
|
-
this.effort.setReasoningEffort(effort);
|
|
456
|
-
}
|
|
457
|
-
getReasoningEffort() {
|
|
458
|
-
return this.effort.getReasoningEffort();
|
|
459
|
-
}
|
|
460
|
-
setTools(tools) {
|
|
461
|
-
this.tools = tools;
|
|
462
|
-
}
|
|
463
|
-
getTools() {
|
|
464
|
-
return this.tools;
|
|
465
|
-
}
|
|
466
|
-
setStructuredOutput(format) {
|
|
467
|
-
this.structuredOutput = format;
|
|
468
|
-
}
|
|
469
|
-
getStructuredOutput() {
|
|
470
|
-
return this.structuredOutput;
|
|
471
|
-
}
|
|
472
|
-
hasStructuredOutput() {
|
|
473
|
-
return this.structuredOutput !== void 0;
|
|
474
|
-
}
|
|
475
241
|
};
|
|
476
242
|
|
|
477
243
|
// src/domain/generative-model/token-usage.ts
|
|
@@ -545,13 +311,6 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
|
|
|
545
311
|
this.role = "system";
|
|
546
312
|
this.content = content;
|
|
547
313
|
}
|
|
548
|
-
toJSON() {
|
|
549
|
-
return {
|
|
550
|
-
type: this.type,
|
|
551
|
-
role: this.role,
|
|
552
|
-
content: this.content.toJSON()
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
314
|
static create(text) {
|
|
556
315
|
const content = InputText.create(text);
|
|
557
316
|
return new _SystemMessageItem(content);
|
|
@@ -698,8 +457,10 @@ var AgenticEnvironment = class {
|
|
|
698
457
|
src.onError(error);
|
|
699
458
|
} catch (error2) {
|
|
700
459
|
if (this.showLogs) {
|
|
701
|
-
console.warn(
|
|
702
|
-
|
|
460
|
+
console.warn(
|
|
461
|
+
`[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
|
|
462
|
+
${JSON.stringify({ error: error2 }, null, 2)}`
|
|
463
|
+
);
|
|
703
464
|
}
|
|
704
465
|
} finally {
|
|
705
466
|
src.markInactive(this);
|
|
@@ -710,8 +471,10 @@ var AgenticEnvironment = class {
|
|
|
710
471
|
sub.onParticipantError(source, error);
|
|
711
472
|
} catch (error2) {
|
|
712
473
|
if (this.showLogs) {
|
|
713
|
-
console.warn(
|
|
714
|
-
|
|
474
|
+
console.warn(
|
|
475
|
+
`[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
|
|
476
|
+
${JSON.stringify({ error: error2 }, null, 2)}`
|
|
477
|
+
);
|
|
715
478
|
}
|
|
716
479
|
}
|
|
717
480
|
}
|
|
@@ -754,56 +517,6 @@ var AgenticEnvironment = class {
|
|
|
754
517
|
}
|
|
755
518
|
};
|
|
756
519
|
|
|
757
|
-
// src/infrastructure/providers/openai/models/gpt-5-5.ts
|
|
758
|
-
var Gpt55 = class {
|
|
759
|
-
constructor() {
|
|
760
|
-
this.specification = {
|
|
761
|
-
name: "gpt-5.5",
|
|
762
|
-
provider: "openai",
|
|
763
|
-
supportReasoningEffort: true,
|
|
764
|
-
defaultReasoningEffort: "none",
|
|
765
|
-
supportStreaming: true,
|
|
766
|
-
contextWindowSize: 105e4,
|
|
767
|
-
maxOutputTokens: 128e3,
|
|
768
|
-
supportFunctionCalling: true,
|
|
769
|
-
supportStructuredOutput: true
|
|
770
|
-
};
|
|
771
|
-
this.tools = [];
|
|
772
|
-
this.streaming = false;
|
|
773
|
-
this.structuredOutput = void 0;
|
|
774
|
-
this.effort = new OpenAIReasoningEffort(
|
|
775
|
-
this.specification.defaultReasoningEffort
|
|
776
|
-
);
|
|
777
|
-
}
|
|
778
|
-
setStreaming(streaming) {
|
|
779
|
-
this.streaming = streaming;
|
|
780
|
-
}
|
|
781
|
-
getStreaming() {
|
|
782
|
-
return this.streaming;
|
|
783
|
-
}
|
|
784
|
-
setTools(tools) {
|
|
785
|
-
this.tools = tools;
|
|
786
|
-
}
|
|
787
|
-
getTools() {
|
|
788
|
-
return this.tools;
|
|
789
|
-
}
|
|
790
|
-
setReasoningEffort(effort) {
|
|
791
|
-
this.effort.setReasoningEffort(effort);
|
|
792
|
-
}
|
|
793
|
-
getReasoningEffort() {
|
|
794
|
-
return this.effort.getReasoningEffort();
|
|
795
|
-
}
|
|
796
|
-
setStructuredOutput(format) {
|
|
797
|
-
this.structuredOutput = format;
|
|
798
|
-
}
|
|
799
|
-
getStructuredOutput() {
|
|
800
|
-
return this.structuredOutput;
|
|
801
|
-
}
|
|
802
|
-
hasStructuredOutput() {
|
|
803
|
-
return this.structuredOutput !== void 0;
|
|
804
|
-
}
|
|
805
|
-
};
|
|
806
|
-
|
|
807
520
|
// src/domain/model-context/semantic-event/semantic-event.ts
|
|
808
521
|
var SemanticEvent = class {
|
|
809
522
|
constructor(type, data) {
|
|
@@ -815,14 +528,6 @@ var SemanticEvent = class {
|
|
|
815
528
|
}
|
|
816
529
|
};
|
|
817
530
|
|
|
818
|
-
// src/domain/agentic-environment/inference/request.ts
|
|
819
|
-
var InferenceRequest = class {
|
|
820
|
-
constructor(model, context) {
|
|
821
|
-
this.model = model;
|
|
822
|
-
this.context = context;
|
|
823
|
-
}
|
|
824
|
-
};
|
|
825
|
-
|
|
826
531
|
// src/domain/agentic-environment/inference/response.ts
|
|
827
532
|
var InferenceResponse = class {
|
|
828
533
|
constructor(contextItems, tokenUsage) {
|
|
@@ -831,199 +536,204 @@ var InferenceResponse = class {
|
|
|
831
536
|
}
|
|
832
537
|
};
|
|
833
538
|
|
|
834
|
-
// src/
|
|
835
|
-
var
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
async infer(inferenceRequest) {
|
|
841
|
-
const request = this.buildRequest(inferenceRequest);
|
|
842
|
-
const response = await this.client.responses.create(request);
|
|
843
|
-
const contextItems = this.extractContextItems(response);
|
|
844
|
-
const tokenUsage = this.extractTokenUsage(response);
|
|
845
|
-
return new InferenceResponse(contextItems, tokenUsage);
|
|
846
|
-
}
|
|
847
|
-
async *stream(inferenceRequest, signal) {
|
|
848
|
-
const specification = inferenceRequest.model.specification;
|
|
849
|
-
if (!specification.supportStreaming) {
|
|
850
|
-
throw new Error("Streaming is not supported for this model");
|
|
851
|
-
}
|
|
852
|
-
const request = { ...this.buildRequest(inferenceRequest), stream: true };
|
|
853
|
-
const response = await this.client.responses.create(request);
|
|
854
|
-
for await (const event of response) {
|
|
855
|
-
if (signal == null ? void 0 : signal.aborted) {
|
|
856
|
-
break;
|
|
857
|
-
}
|
|
858
|
-
yield new SemanticEvent(event.type, event);
|
|
539
|
+
// src/application/services/inference-runner.ts
|
|
540
|
+
var StreamingInference = class {
|
|
541
|
+
async *run(request, endpoint) {
|
|
542
|
+
var _a;
|
|
543
|
+
if ((_a = request.signal) == null ? void 0 : _a.aborted) {
|
|
544
|
+
return;
|
|
859
545
|
}
|
|
546
|
+
yield* endpoint.stream(request, request.signal);
|
|
860
547
|
}
|
|
861
|
-
|
|
548
|
+
};
|
|
549
|
+
var NonStreamingInference = class {
|
|
550
|
+
async *run(request, endpoint) {
|
|
862
551
|
var _a, _b;
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
const request = {
|
|
866
|
-
model: specification.name,
|
|
867
|
-
input
|
|
868
|
-
};
|
|
869
|
-
if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
|
|
870
|
-
request.tools = inferenceRequest.model.getTools().map((tool) => {
|
|
871
|
-
return {
|
|
872
|
-
type: tool.type,
|
|
873
|
-
name: tool.name,
|
|
874
|
-
description: tool.description,
|
|
875
|
-
parameters: tool.parameters
|
|
876
|
-
};
|
|
877
|
-
});
|
|
878
|
-
}
|
|
879
|
-
if (specification.supportReasoningEffort) {
|
|
880
|
-
request.reasoning = {
|
|
881
|
-
effort: inferenceRequest.model.getReasoningEffort()
|
|
882
|
-
};
|
|
552
|
+
if ((_a = request.signal) == null ? void 0 : _a.aborted) {
|
|
553
|
+
return;
|
|
883
554
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
555
|
+
const response = await endpoint.infer(request);
|
|
556
|
+
for (const item of response.contextItems) {
|
|
557
|
+
if ((_b = request.signal) == null ? void 0 : _b.aborted) {
|
|
558
|
+
break;
|
|
887
559
|
}
|
|
888
|
-
|
|
889
|
-
request.text = {
|
|
890
|
-
format: {
|
|
891
|
-
type: "json_schema",
|
|
892
|
-
name: (_a = format.name) != null ? _a : "response",
|
|
893
|
-
schema: format.schema,
|
|
894
|
-
strict: (_b = format.strict) != null ? _b : true
|
|
895
|
-
}
|
|
896
|
-
};
|
|
897
|
-
}
|
|
898
|
-
return request;
|
|
899
|
-
}
|
|
900
|
-
extractTokenUsage(response) {
|
|
901
|
-
if (!response.usage) {
|
|
902
|
-
return void 0;
|
|
560
|
+
yield item;
|
|
903
561
|
}
|
|
904
|
-
return new TokenUsage(
|
|
905
|
-
response.usage.input_tokens,
|
|
906
|
-
response.usage.output_tokens,
|
|
907
|
-
response.usage.total_tokens,
|
|
908
|
-
new InputTokenDetails(response.usage.input_tokens_details.cached_tokens),
|
|
909
|
-
new OutputTokenDetails(response.usage.output_tokens_details.reasoning_tokens)
|
|
910
|
-
);
|
|
911
|
-
}
|
|
912
|
-
mapContextToRequest(context) {
|
|
913
|
-
return context.getItems().map((item) => item.toJSON());
|
|
914
|
-
}
|
|
915
|
-
extractContextItems(response) {
|
|
916
|
-
return response.output.map((item) => {
|
|
917
|
-
if (item.type === "message" && item.role === "assistant") {
|
|
918
|
-
return ModelMessageItem.rehydrate(item.content[0]);
|
|
919
|
-
}
|
|
920
|
-
if (item.type === "function_call") {
|
|
921
|
-
return FunctionCallItem.rehydrate({
|
|
922
|
-
callId: item.call_id,
|
|
923
|
-
name: item.name,
|
|
924
|
-
args: item.arguments
|
|
925
|
-
});
|
|
926
|
-
}
|
|
927
|
-
if (item.type === "reasoning") {
|
|
928
|
-
return ReasoningItem.rehydrate(item);
|
|
929
|
-
}
|
|
930
|
-
});
|
|
931
562
|
}
|
|
932
563
|
};
|
|
933
564
|
|
|
934
|
-
// src/
|
|
935
|
-
var
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
this.
|
|
939
|
-
}
|
|
940
|
-
async infer(inferenceRequest) {
|
|
941
|
-
const response = await this.client.messages.create(this.buildRequest(inferenceRequest));
|
|
942
|
-
const contextItems = this.extractContextItems(response);
|
|
943
|
-
const tokenUsage = this.extractTokenUsage(response);
|
|
944
|
-
return new InferenceResponse(contextItems, tokenUsage);
|
|
565
|
+
// src/application/use-cases/run-inference.ts
|
|
566
|
+
var RunInference = class {
|
|
567
|
+
constructor(generativeModelRepository2, requestValidator) {
|
|
568
|
+
this.generativeModelRepository = generativeModelRepository2;
|
|
569
|
+
this.requestValidator = requestValidator;
|
|
945
570
|
}
|
|
946
|
-
async
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
571
|
+
async execute(inferenceParams) {
|
|
572
|
+
var _a;
|
|
573
|
+
const { caller, environment, signal } = inferenceParams;
|
|
574
|
+
const generativeModel = await this.generativeModelRepository.getByModelName(inferenceParams.model);
|
|
575
|
+
this.requestValidator.validate(inferenceParams, generativeModel.specification);
|
|
576
|
+
const resolvedParams = {
|
|
577
|
+
...inferenceParams,
|
|
578
|
+
maxOutputTokens: (_a = inferenceParams.maxOutputTokens) != null ? _a : generativeModel.specification.maxOutputTokens
|
|
579
|
+
};
|
|
580
|
+
const inferenceRunner = inferenceParams.streaming ? new StreamingInference() : new NonStreamingInference();
|
|
581
|
+
const result = inferenceRunner.run(resolvedParams, generativeModel.endpoint);
|
|
582
|
+
for await (const item of result) {
|
|
952
583
|
if (signal == null ? void 0 : signal.aborted) {
|
|
953
584
|
break;
|
|
954
585
|
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
max_tokens: specification.maxOutputTokens,
|
|
964
|
-
messages
|
|
965
|
-
};
|
|
966
|
-
if (system) {
|
|
967
|
-
request.system = system;
|
|
968
|
-
}
|
|
969
|
-
if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
|
|
970
|
-
request.tools = inferenceRequest.model.getTools().map((tool) => {
|
|
971
|
-
return {
|
|
972
|
-
name: tool.name,
|
|
973
|
-
description: tool.description,
|
|
974
|
-
input_schema: tool.parameters
|
|
975
|
-
};
|
|
976
|
-
});
|
|
977
|
-
}
|
|
978
|
-
if (specification.supportReasoningEffort) {
|
|
979
|
-
const effort = inferenceRequest.model.getReasoningEffort();
|
|
980
|
-
const budgets = { low: 1024, medium: 4096, high: 8192 };
|
|
981
|
-
const budget = budgets[effort];
|
|
982
|
-
if (budget !== void 0) {
|
|
983
|
-
request.thinking = {
|
|
984
|
-
type: "enabled",
|
|
985
|
-
budget_tokens: Math.min(budget, specification.maxOutputTokens - 1)
|
|
986
|
-
};
|
|
586
|
+
if (item instanceof ReasoningItem) {
|
|
587
|
+
environment.deliverReasoning(caller, item);
|
|
588
|
+
} else if (item instanceof FunctionCallItem) {
|
|
589
|
+
environment.deliverFunctionCall(caller, item);
|
|
590
|
+
} else if (item instanceof ModelMessageItem) {
|
|
591
|
+
environment.deliverModelMessage(caller, item);
|
|
592
|
+
} else if (item instanceof SemanticEvent) {
|
|
593
|
+
environment.deliverSemanticEvent(caller, item);
|
|
987
594
|
}
|
|
988
595
|
}
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
// src/application/use-cases/execute-function-call.ts
|
|
600
|
+
var ExecuteFunctionCall = class {
|
|
601
|
+
constructor(functionCallRunner) {
|
|
602
|
+
this.functionCallRunner = functionCallRunner;
|
|
603
|
+
}
|
|
604
|
+
async execute(environment, functionCallItem, tool, caller, signal) {
|
|
605
|
+
const stream = this.functionCallRunner.run(functionCallItem, tool, signal);
|
|
606
|
+
for await (const item of stream) {
|
|
607
|
+
environment.deliverFunctionCallOutput(caller, item);
|
|
1000
608
|
}
|
|
1001
|
-
return request;
|
|
1002
609
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
// src/application/services/function-call-runner.ts
|
|
613
|
+
var FunctionCallRunner = class {
|
|
614
|
+
async *run(call, tool, signal) {
|
|
615
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
616
|
+
return;
|
|
1007
617
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
response.usage.input_tokens + response.usage.output_tokens,
|
|
1012
|
-
new InputTokenDetails(
|
|
1013
|
-
((_a = response.usage.cache_creation_input_tokens) != null ? _a : 0) + ((_b = response.usage.cache_read_input_tokens) != null ? _b : 0)
|
|
1014
|
-
),
|
|
1015
|
-
new OutputTokenDetails(0)
|
|
1016
|
-
);
|
|
618
|
+
if (!tool) throw new Error(`Unknown tool: ${call.name}`);
|
|
619
|
+
const result = await tool.invoke(JSON.parse(call.args));
|
|
620
|
+
yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
|
|
1017
621
|
}
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
// src/application/participants/participant.ts
|
|
625
|
+
var BaseParticipant = class extends Participant {
|
|
626
|
+
onFunctionCall(item) {
|
|
627
|
+
}
|
|
628
|
+
onExternalFunctionCall(source, item) {
|
|
629
|
+
}
|
|
630
|
+
onFunctionCallOutput(item) {
|
|
631
|
+
}
|
|
632
|
+
onExternalFunctionCallOutput(source, item) {
|
|
633
|
+
}
|
|
634
|
+
onReasoning(item) {
|
|
635
|
+
}
|
|
636
|
+
onExternalReasoning(source, item) {
|
|
637
|
+
}
|
|
638
|
+
onModelMessage(item) {
|
|
639
|
+
}
|
|
640
|
+
onExternalModelMessage(source, item) {
|
|
641
|
+
}
|
|
642
|
+
onMessage(message) {
|
|
643
|
+
}
|
|
644
|
+
onJoined() {
|
|
645
|
+
}
|
|
646
|
+
onLeft() {
|
|
647
|
+
}
|
|
648
|
+
onParticipantJoined(participant) {
|
|
649
|
+
}
|
|
650
|
+
onParticipantLeft(participant) {
|
|
651
|
+
}
|
|
652
|
+
onInternalEvent(item) {
|
|
653
|
+
}
|
|
654
|
+
onExternalEvent(source, item) {
|
|
655
|
+
}
|
|
656
|
+
onError(error) {
|
|
657
|
+
}
|
|
658
|
+
onParticipantError(source, error) {
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
// src/application/use-cases/send-message.ts
|
|
663
|
+
var SendMessage = class {
|
|
664
|
+
async execute(environment, message, caller) {
|
|
665
|
+
if (!caller.isJoinedTo(environment)) {
|
|
666
|
+
throw new Error("Not joined to environment");
|
|
667
|
+
}
|
|
668
|
+
environment.deliverMessage(caller, message);
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
// src/infrastructure/providers/anthropic/endpoints/anthropic-messages-mapper.ts
|
|
673
|
+
var AnthropicMessagesMapper = class {
|
|
674
|
+
toRequest(inferenceParams) {
|
|
675
|
+
const { messages, system } = this.mapContextItems(inferenceParams);
|
|
676
|
+
const outputConfig = {};
|
|
677
|
+
const request = {
|
|
678
|
+
model: inferenceParams.model,
|
|
679
|
+
messages
|
|
680
|
+
};
|
|
681
|
+
request.max_tokens = inferenceParams.maxOutputTokens;
|
|
682
|
+
if (system) {
|
|
683
|
+
request.system = system;
|
|
684
|
+
}
|
|
685
|
+
if (inferenceParams.tools && inferenceParams.tools.length > 0) {
|
|
686
|
+
request.tools = inferenceParams.tools.map((tool) => ({
|
|
687
|
+
name: tool.name,
|
|
688
|
+
description: tool.description,
|
|
689
|
+
input_schema: tool.parameters
|
|
690
|
+
}));
|
|
691
|
+
}
|
|
692
|
+
if (inferenceParams.structuredOutput) {
|
|
693
|
+
outputConfig.format = {
|
|
694
|
+
type: "json_schema",
|
|
695
|
+
json_schema: inferenceParams.structuredOutput.schema
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
if (inferenceParams.reasoningEffort) {
|
|
699
|
+
request.thinking = { type: "adaptive" };
|
|
700
|
+
outputConfig.effort = inferenceParams.reasoningEffort;
|
|
701
|
+
}
|
|
702
|
+
if (Object.keys(outputConfig).length > 0) {
|
|
703
|
+
request.output_config = outputConfig;
|
|
704
|
+
}
|
|
705
|
+
if (inferenceParams.streaming) {
|
|
706
|
+
request.stream = inferenceParams.streaming;
|
|
707
|
+
}
|
|
708
|
+
return request;
|
|
709
|
+
}
|
|
710
|
+
toResponse(response) {
|
|
711
|
+
const contextItems = this.extractContextItems(response);
|
|
712
|
+
const tokenUsage = this.extractTokenUsage(response);
|
|
713
|
+
return new InferenceResponse(contextItems, tokenUsage);
|
|
714
|
+
}
|
|
715
|
+
addContentBlock(messages, role, block) {
|
|
716
|
+
const lastMessage = messages[messages.length - 1];
|
|
717
|
+
if ((lastMessage == null ? void 0 : lastMessage.role) === role) {
|
|
718
|
+
lastMessage.content.push(block);
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
messages.push({
|
|
722
|
+
role,
|
|
723
|
+
content: [block]
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
mapContextItems(inferenceParams) {
|
|
727
|
+
var _a, _b, _c;
|
|
728
|
+
const context = inferenceParams.context;
|
|
729
|
+
const messages = [];
|
|
730
|
+
const system = [];
|
|
731
|
+
for (const item of context.getItems()) {
|
|
732
|
+
if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
|
|
733
|
+
system.push(item.content.text);
|
|
734
|
+
continue;
|
|
735
|
+
}
|
|
736
|
+
if (item instanceof UserMessageItem) {
|
|
1027
737
|
this.addContentBlock(messages, "user", { type: "text", text: item.content.text });
|
|
1028
738
|
continue;
|
|
1029
739
|
}
|
|
@@ -1031,6 +741,14 @@ var AnthropicMessages = class {
|
|
|
1031
741
|
this.addContentBlock(messages, "assistant", { type: "text", text: item.content.text });
|
|
1032
742
|
continue;
|
|
1033
743
|
}
|
|
744
|
+
if (item instanceof ReasoningItem) {
|
|
745
|
+
this.addContentBlock(messages, "assistant", {
|
|
746
|
+
type: "thinking",
|
|
747
|
+
thinking: (_b = (_a = item.content) == null ? void 0 : _a.text) != null ? _b : "",
|
|
748
|
+
signature: (_c = item.encryptedContent) != null ? _c : ""
|
|
749
|
+
});
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
1034
752
|
if (item instanceof FunctionCallItem) {
|
|
1035
753
|
let input;
|
|
1036
754
|
try {
|
|
@@ -1059,6 +777,21 @@ var AnthropicMessages = class {
|
|
|
1059
777
|
system: system.length > 0 ? system.join("\n\n") : void 0
|
|
1060
778
|
};
|
|
1061
779
|
}
|
|
780
|
+
extractTokenUsage(response) {
|
|
781
|
+
var _a, _b;
|
|
782
|
+
if (!response.usage) {
|
|
783
|
+
return void 0;
|
|
784
|
+
}
|
|
785
|
+
return new TokenUsage(
|
|
786
|
+
response.usage.input_tokens,
|
|
787
|
+
response.usage.output_tokens,
|
|
788
|
+
response.usage.input_tokens + response.usage.output_tokens,
|
|
789
|
+
new InputTokenDetails(
|
|
790
|
+
((_a = response.usage.cache_creation_input_tokens) != null ? _a : 0) + ((_b = response.usage.cache_read_input_tokens) != null ? _b : 0)
|
|
791
|
+
),
|
|
792
|
+
new OutputTokenDetails(0)
|
|
793
|
+
);
|
|
794
|
+
}
|
|
1062
795
|
extractContextItems(response) {
|
|
1063
796
|
var _a;
|
|
1064
797
|
const items = [];
|
|
@@ -1081,7 +814,7 @@ var AnthropicMessages = class {
|
|
|
1081
814
|
items.push(
|
|
1082
815
|
ReasoningItem.rehydrate({
|
|
1083
816
|
content: block.thinking ? InputText.rehydrate({ text: block.thinking }) : void 0,
|
|
1084
|
-
encryptedContent:
|
|
817
|
+
encryptedContent: block.signature,
|
|
1085
818
|
summary: []
|
|
1086
819
|
})
|
|
1087
820
|
);
|
|
@@ -1089,423 +822,261 @@ var AnthropicMessages = class {
|
|
|
1089
822
|
}
|
|
1090
823
|
return items;
|
|
1091
824
|
}
|
|
1092
|
-
addContentBlock(messages, role, block) {
|
|
1093
|
-
const lastMessage = messages[messages.length - 1];
|
|
1094
|
-
if ((lastMessage == null ? void 0 : lastMessage.role) === role) {
|
|
1095
|
-
lastMessage.content.push(block);
|
|
1096
|
-
return;
|
|
1097
|
-
}
|
|
1098
|
-
messages.push({
|
|
1099
|
-
role,
|
|
1100
|
-
content: [block]
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
825
|
};
|
|
1104
826
|
|
|
1105
|
-
// src/infrastructure/providers/anthropic/
|
|
1106
|
-
var
|
|
1107
|
-
|
|
1108
|
-
|
|
827
|
+
// src/infrastructure/providers/anthropic/endpoints/anthropic-messages.ts
|
|
828
|
+
var import_sdk = __toESM(require("@anthropic-ai/sdk"));
|
|
829
|
+
var AnthropicMessages = class {
|
|
830
|
+
constructor(endpointMapper = new AnthropicMessagesMapper()) {
|
|
831
|
+
this.endpointMapper = endpointMapper;
|
|
832
|
+
this.client = new import_sdk.default();
|
|
1109
833
|
}
|
|
1110
|
-
|
|
1111
|
-
|
|
834
|
+
async infer(inferenceParams) {
|
|
835
|
+
const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
|
|
836
|
+
const response = await this.client.messages.create(inferenceRequest);
|
|
837
|
+
return this.endpointMapper.toResponse(response);
|
|
1112
838
|
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
839
|
+
async *stream(inferenceParams, signal) {
|
|
840
|
+
const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
|
|
841
|
+
const stream = await this.client.messages.create(inferenceRequest);
|
|
842
|
+
for await (const event of stream) {
|
|
843
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
844
|
+
break;
|
|
845
|
+
}
|
|
846
|
+
yield new SemanticEvent(event.type, event);
|
|
1116
847
|
}
|
|
1117
|
-
return this.reasoningEffort;
|
|
1118
|
-
}
|
|
1119
|
-
};
|
|
1120
|
-
|
|
1121
|
-
// src/infrastructure/providers/anthropic/models/claude-4-8-opus.ts
|
|
1122
|
-
var ClaudeOpus48 = class {
|
|
1123
|
-
constructor() {
|
|
1124
|
-
this.specification = {
|
|
1125
|
-
name: "claude-opus-4-8",
|
|
1126
|
-
provider: "anthropic",
|
|
1127
|
-
supportReasoningEffort: true,
|
|
1128
|
-
defaultReasoningEffort: "none",
|
|
1129
|
-
supportStreaming: true,
|
|
1130
|
-
contextWindowSize: 2e5,
|
|
1131
|
-
maxOutputTokens: 32e3,
|
|
1132
|
-
supportFunctionCalling: true,
|
|
1133
|
-
supportStructuredOutput: true
|
|
1134
|
-
};
|
|
1135
|
-
this.tools = [];
|
|
1136
|
-
this.streaming = false;
|
|
1137
|
-
this.structuredOutput = void 0;
|
|
1138
|
-
this.effort = new AnthropicReasoningEffort(
|
|
1139
|
-
this.specification.defaultReasoningEffort
|
|
1140
|
-
);
|
|
1141
|
-
}
|
|
1142
|
-
setStreaming(streaming) {
|
|
1143
|
-
this.streaming = streaming;
|
|
1144
|
-
}
|
|
1145
|
-
getStreaming() {
|
|
1146
|
-
return this.streaming;
|
|
1147
|
-
}
|
|
1148
|
-
setTools(tools) {
|
|
1149
|
-
this.tools = tools;
|
|
1150
|
-
}
|
|
1151
|
-
getTools() {
|
|
1152
|
-
return this.tools;
|
|
1153
|
-
}
|
|
1154
|
-
setReasoningEffort(effort) {
|
|
1155
|
-
this.effort.setReasoningEffort(effort);
|
|
1156
|
-
}
|
|
1157
|
-
getReasoningEffort() {
|
|
1158
|
-
return this.effort.getReasoningEffort();
|
|
1159
|
-
}
|
|
1160
|
-
setStructuredOutput(format) {
|
|
1161
|
-
this.structuredOutput = format;
|
|
1162
|
-
}
|
|
1163
|
-
getStructuredOutput() {
|
|
1164
|
-
return this.structuredOutput;
|
|
1165
|
-
}
|
|
1166
|
-
hasStructuredOutput() {
|
|
1167
|
-
return this.structuredOutput !== void 0;
|
|
1168
848
|
}
|
|
1169
849
|
};
|
|
1170
850
|
|
|
1171
|
-
// src/infrastructure/providers/
|
|
1172
|
-
var
|
|
1173
|
-
constructor() {
|
|
1174
|
-
this.specification = {
|
|
1175
|
-
name: "claude-opus-4-7",
|
|
1176
|
-
provider: "anthropic",
|
|
1177
|
-
supportReasoningEffort: true,
|
|
1178
|
-
defaultReasoningEffort: "none",
|
|
1179
|
-
supportStreaming: true,
|
|
1180
|
-
contextWindowSize: 2e5,
|
|
1181
|
-
maxOutputTokens: 32e3,
|
|
1182
|
-
supportFunctionCalling: true,
|
|
1183
|
-
supportStructuredOutput: true
|
|
1184
|
-
};
|
|
1185
|
-
this.tools = [];
|
|
1186
|
-
this.streaming = false;
|
|
1187
|
-
this.structuredOutput = void 0;
|
|
1188
|
-
this.effort = new AnthropicReasoningEffort(
|
|
1189
|
-
this.specification.defaultReasoningEffort
|
|
1190
|
-
);
|
|
1191
|
-
}
|
|
1192
|
-
setStreaming(streaming) {
|
|
1193
|
-
this.streaming = streaming;
|
|
1194
|
-
}
|
|
1195
|
-
getStreaming() {
|
|
1196
|
-
return this.streaming;
|
|
1197
|
-
}
|
|
1198
|
-
setTools(tools) {
|
|
1199
|
-
this.tools = tools;
|
|
1200
|
-
}
|
|
1201
|
-
getTools() {
|
|
1202
|
-
return this.tools;
|
|
1203
|
-
}
|
|
1204
|
-
setReasoningEffort(effort) {
|
|
1205
|
-
this.effort.setReasoningEffort(effort);
|
|
1206
|
-
}
|
|
1207
|
-
getReasoningEffort() {
|
|
1208
|
-
return this.effort.getReasoningEffort();
|
|
1209
|
-
}
|
|
1210
|
-
setStructuredOutput(format) {
|
|
1211
|
-
this.structuredOutput = format;
|
|
1212
|
-
}
|
|
1213
|
-
getStructuredOutput() {
|
|
1214
|
-
return this.structuredOutput;
|
|
1215
|
-
}
|
|
1216
|
-
hasStructuredOutput() {
|
|
1217
|
-
return this.structuredOutput !== void 0;
|
|
1218
|
-
}
|
|
1219
|
-
};
|
|
851
|
+
// src/infrastructure/providers/openai/endpoints/openai-responses.ts
|
|
852
|
+
var import_openai = __toESM(require("openai"));
|
|
1220
853
|
|
|
1221
|
-
// src/
|
|
1222
|
-
var
|
|
1223
|
-
constructor() {
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
supportReasoningEffort: true,
|
|
1228
|
-
defaultReasoningEffort: "none",
|
|
1229
|
-
supportStreaming: true,
|
|
1230
|
-
contextWindowSize: 2e5,
|
|
1231
|
-
maxOutputTokens: 64e3,
|
|
1232
|
-
supportFunctionCalling: true,
|
|
1233
|
-
supportStructuredOutput: true
|
|
1234
|
-
};
|
|
1235
|
-
this.tools = [];
|
|
1236
|
-
this.streaming = false;
|
|
1237
|
-
this.structuredOutput = void 0;
|
|
1238
|
-
this.effort = new AnthropicReasoningEffort(
|
|
1239
|
-
this.specification.defaultReasoningEffort
|
|
1240
|
-
);
|
|
1241
|
-
}
|
|
1242
|
-
setStreaming(streaming) {
|
|
1243
|
-
this.streaming = streaming;
|
|
1244
|
-
}
|
|
1245
|
-
getStreaming() {
|
|
1246
|
-
return this.streaming;
|
|
1247
|
-
}
|
|
1248
|
-
setTools(tools) {
|
|
1249
|
-
this.tools = tools;
|
|
1250
|
-
}
|
|
1251
|
-
getTools() {
|
|
1252
|
-
return this.tools;
|
|
1253
|
-
}
|
|
1254
|
-
setReasoningEffort(effort) {
|
|
1255
|
-
this.effort.setReasoningEffort(effort);
|
|
1256
|
-
}
|
|
1257
|
-
getReasoningEffort() {
|
|
1258
|
-
return this.effort.getReasoningEffort();
|
|
1259
|
-
}
|
|
1260
|
-
setStructuredOutput(format) {
|
|
1261
|
-
this.structuredOutput = format;
|
|
1262
|
-
}
|
|
1263
|
-
getStructuredOutput() {
|
|
1264
|
-
return this.structuredOutput;
|
|
854
|
+
// src/domain/model-context/context-item/item-content/summary-text.ts
|
|
855
|
+
var SummaryText = class _SummaryText extends ItemContent {
|
|
856
|
+
constructor(text) {
|
|
857
|
+
super();
|
|
858
|
+
this.text = text;
|
|
859
|
+
this.type = "summary_text";
|
|
1265
860
|
}
|
|
1266
|
-
|
|
1267
|
-
return
|
|
861
|
+
static rehydrate(data) {
|
|
862
|
+
return new _SummaryText(data.text);
|
|
1268
863
|
}
|
|
1269
864
|
};
|
|
1270
865
|
|
|
1271
|
-
// src/infrastructure/providers/
|
|
1272
|
-
var
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
defaultReasoningEffort: "none",
|
|
1279
|
-
supportStreaming: true,
|
|
1280
|
-
contextWindowSize: 2e5,
|
|
1281
|
-
maxOutputTokens: 64e3,
|
|
1282
|
-
supportFunctionCalling: true,
|
|
1283
|
-
supportStructuredOutput: true
|
|
866
|
+
// src/infrastructure/providers/openai/endpoints/openai-responses-mapper.ts
|
|
867
|
+
var OpenAIResponsesMapper = class {
|
|
868
|
+
toRequest(inferenceParams) {
|
|
869
|
+
var _a, _b;
|
|
870
|
+
const request = {
|
|
871
|
+
model: inferenceParams.model,
|
|
872
|
+
input: this.mapContextItems(inferenceParams)
|
|
1284
873
|
};
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
setStreaming(streaming) {
|
|
1293
|
-
this.streaming = streaming;
|
|
1294
|
-
}
|
|
1295
|
-
getStreaming() {
|
|
1296
|
-
return this.streaming;
|
|
1297
|
-
}
|
|
1298
|
-
setTools(tools) {
|
|
1299
|
-
this.tools = tools;
|
|
1300
|
-
}
|
|
1301
|
-
getTools() {
|
|
1302
|
-
return this.tools;
|
|
1303
|
-
}
|
|
1304
|
-
setReasoningEffort(effort) {
|
|
1305
|
-
this.effort.setReasoningEffort(effort);
|
|
1306
|
-
}
|
|
1307
|
-
getReasoningEffort() {
|
|
1308
|
-
return this.effort.getReasoningEffort();
|
|
1309
|
-
}
|
|
1310
|
-
setStructuredOutput(format) {
|
|
1311
|
-
this.structuredOutput = format;
|
|
1312
|
-
}
|
|
1313
|
-
getStructuredOutput() {
|
|
1314
|
-
return this.structuredOutput;
|
|
1315
|
-
}
|
|
1316
|
-
hasStructuredOutput() {
|
|
1317
|
-
return this.structuredOutput !== void 0;
|
|
1318
|
-
}
|
|
1319
|
-
};
|
|
1320
|
-
|
|
1321
|
-
// src/infrastructure/providers/deepseek/reasoning-effort.ts
|
|
1322
|
-
var DeepSeekReasoningEffort = class {
|
|
1323
|
-
constructor(reasoningEffort) {
|
|
1324
|
-
this.reasoningEffort = reasoningEffort;
|
|
1325
|
-
}
|
|
1326
|
-
setReasoningEffort(effort) {
|
|
1327
|
-
this.reasoningEffort = effort;
|
|
1328
|
-
}
|
|
1329
|
-
getReasoningEffort() {
|
|
1330
|
-
if (!this.reasoningEffort) {
|
|
1331
|
-
throw new Error("Reasoning effort not supported");
|
|
874
|
+
if (inferenceParams.tools && inferenceParams.tools.length > 0) {
|
|
875
|
+
request.tools = inferenceParams.tools.map((tool) => ({
|
|
876
|
+
type: tool.type,
|
|
877
|
+
name: tool.name,
|
|
878
|
+
description: tool.description,
|
|
879
|
+
parameters: tool.parameters
|
|
880
|
+
}));
|
|
1332
881
|
}
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
this.structuredOutput = void 0;
|
|
1354
|
-
this.effort = new DeepSeekReasoningEffort(
|
|
1355
|
-
this.specification.defaultReasoningEffort
|
|
1356
|
-
);
|
|
1357
|
-
}
|
|
1358
|
-
setStreaming(streaming) {
|
|
1359
|
-
this.streaming = streaming;
|
|
1360
|
-
}
|
|
1361
|
-
getStreaming() {
|
|
1362
|
-
return this.streaming;
|
|
1363
|
-
}
|
|
1364
|
-
setTools(tools) {
|
|
1365
|
-
this.tools = tools;
|
|
1366
|
-
}
|
|
1367
|
-
getTools() {
|
|
1368
|
-
return this.tools;
|
|
1369
|
-
}
|
|
1370
|
-
setReasoningEffort(effort) {
|
|
1371
|
-
this.effort.setReasoningEffort(effort);
|
|
1372
|
-
}
|
|
1373
|
-
getReasoningEffort() {
|
|
1374
|
-
return this.effort.getReasoningEffort();
|
|
1375
|
-
}
|
|
1376
|
-
setStructuredOutput(format) {
|
|
1377
|
-
this.structuredOutput = format;
|
|
882
|
+
if (inferenceParams.reasoningEffort) {
|
|
883
|
+
request.reasoning = {
|
|
884
|
+
effort: inferenceParams.reasoningEffort
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
if (inferenceParams.structuredOutput) {
|
|
888
|
+
const format = inferenceParams.structuredOutput;
|
|
889
|
+
request.text = {
|
|
890
|
+
format: {
|
|
891
|
+
type: "json_schema",
|
|
892
|
+
name: (_a = format.name) != null ? _a : "response",
|
|
893
|
+
schema: format.schema,
|
|
894
|
+
strict: (_b = format.strict) != null ? _b : true
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
if (inferenceParams.streaming) {
|
|
899
|
+
request.stream = inferenceParams.streaming;
|
|
900
|
+
}
|
|
901
|
+
return request;
|
|
1378
902
|
}
|
|
1379
|
-
|
|
1380
|
-
|
|
903
|
+
toResponse(response) {
|
|
904
|
+
const contextItems = this.extractContextItems(response);
|
|
905
|
+
const tokenUsage = this.extractTokenUsage(response);
|
|
906
|
+
return new InferenceResponse(contextItems, tokenUsage);
|
|
1381
907
|
}
|
|
1382
|
-
|
|
1383
|
-
|
|
908
|
+
mapContextItems(inferenceParams) {
|
|
909
|
+
const input = [];
|
|
910
|
+
for (const item of inferenceParams.context.getItems()) {
|
|
911
|
+
if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem || item instanceof UserMessageItem) {
|
|
912
|
+
input.push({
|
|
913
|
+
type: item.type,
|
|
914
|
+
role: item.role,
|
|
915
|
+
content: [{ type: "input_text", text: item.content.text }]
|
|
916
|
+
});
|
|
917
|
+
continue;
|
|
918
|
+
}
|
|
919
|
+
if (item instanceof ModelMessageItem) {
|
|
920
|
+
input.push({
|
|
921
|
+
type: item.type,
|
|
922
|
+
role: item.role,
|
|
923
|
+
content: [{ type: "output_text", text: item.content.text }]
|
|
924
|
+
});
|
|
925
|
+
continue;
|
|
926
|
+
}
|
|
927
|
+
if (item instanceof FunctionCallItem) {
|
|
928
|
+
input.push({
|
|
929
|
+
type: item.type,
|
|
930
|
+
call_id: item.callId,
|
|
931
|
+
name: item.name,
|
|
932
|
+
arguments: item.args
|
|
933
|
+
});
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
936
|
+
if (item instanceof FunctionCallOutputItem) {
|
|
937
|
+
input.push({
|
|
938
|
+
type: item.type,
|
|
939
|
+
call_id: item.callId,
|
|
940
|
+
output: [{ type: "input_text", text: item.output.text }]
|
|
941
|
+
});
|
|
942
|
+
continue;
|
|
943
|
+
}
|
|
944
|
+
if (item instanceof ReasoningItem) {
|
|
945
|
+
const reasoningInput = {
|
|
946
|
+
type: item.type,
|
|
947
|
+
summary: item.summary.map((summary) => ({ type: "summary_text", text: summary.text }))
|
|
948
|
+
};
|
|
949
|
+
if (item.encryptedContent !== void 0) {
|
|
950
|
+
reasoningInput.encrypted_content = item.encryptedContent;
|
|
951
|
+
}
|
|
952
|
+
input.push(reasoningInput);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
return input;
|
|
1384
956
|
}
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
contextWindowSize: 1e6,
|
|
1397
|
-
maxOutputTokens: 384e3,
|
|
1398
|
-
supportFunctionCalling: true,
|
|
1399
|
-
supportStructuredOutput: false
|
|
1400
|
-
};
|
|
1401
|
-
this.tools = [];
|
|
1402
|
-
this.streaming = false;
|
|
1403
|
-
this.structuredOutput = void 0;
|
|
1404
|
-
this.effort = new DeepSeekReasoningEffort(
|
|
1405
|
-
this.specification.defaultReasoningEffort
|
|
957
|
+
extractTokenUsage(response) {
|
|
958
|
+
var _a, _b, _c, _d;
|
|
959
|
+
if (!response.usage) {
|
|
960
|
+
return void 0;
|
|
961
|
+
}
|
|
962
|
+
return new TokenUsage(
|
|
963
|
+
response.usage.input_tokens,
|
|
964
|
+
response.usage.output_tokens,
|
|
965
|
+
response.usage.total_tokens,
|
|
966
|
+
new InputTokenDetails((_b = (_a = response.usage.input_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
|
|
967
|
+
new OutputTokenDetails((_d = (_c = response.usage.output_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
|
|
1406
968
|
);
|
|
1407
969
|
}
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
970
|
+
extractContextItems(response) {
|
|
971
|
+
var _a, _b, _c;
|
|
972
|
+
const items = [];
|
|
973
|
+
for (const item of (_a = response.output) != null ? _a : []) {
|
|
974
|
+
if (item.type === "message" && item.role === "assistant") {
|
|
975
|
+
const firstContent = (_b = item.content) == null ? void 0 : _b[0];
|
|
976
|
+
if (firstContent) {
|
|
977
|
+
items.push(ModelMessageItem.rehydrate(firstContent));
|
|
978
|
+
}
|
|
979
|
+
continue;
|
|
980
|
+
}
|
|
981
|
+
if (item.type === "function_call") {
|
|
982
|
+
items.push(
|
|
983
|
+
FunctionCallItem.rehydrate({
|
|
984
|
+
callId: item.call_id,
|
|
985
|
+
name: item.name,
|
|
986
|
+
args: item.arguments
|
|
987
|
+
})
|
|
988
|
+
);
|
|
989
|
+
continue;
|
|
990
|
+
}
|
|
991
|
+
if (item.type === "reasoning") {
|
|
992
|
+
items.push(
|
|
993
|
+
ReasoningItem.rehydrate({
|
|
994
|
+
content: void 0,
|
|
995
|
+
encryptedContent: item.encrypted_content,
|
|
996
|
+
summary: ((_c = item.summary) != null ? _c : []).map(
|
|
997
|
+
(summary) => SummaryText.rehydrate({ text: summary.text })
|
|
998
|
+
)
|
|
999
|
+
})
|
|
1000
|
+
);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
return items;
|
|
1434
1004
|
}
|
|
1435
1005
|
};
|
|
1436
1006
|
|
|
1437
|
-
// src/infrastructure/providers/
|
|
1438
|
-
var
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
this.client = new
|
|
1007
|
+
// src/infrastructure/providers/openai/endpoints/openai-responses.ts
|
|
1008
|
+
var OpenAIResponses = class {
|
|
1009
|
+
constructor(endpointMapper = new OpenAIResponsesMapper()) {
|
|
1010
|
+
this.endpointMapper = endpointMapper;
|
|
1011
|
+
this.client = new import_openai.default();
|
|
1442
1012
|
}
|
|
1443
|
-
async infer(
|
|
1444
|
-
const
|
|
1445
|
-
const
|
|
1446
|
-
|
|
1447
|
-
return new InferenceResponse(contextItems, tokenUsage);
|
|
1013
|
+
async infer(inferenceParams) {
|
|
1014
|
+
const request = this.endpointMapper.toRequest(inferenceParams);
|
|
1015
|
+
const response = await this.client.responses.create(request);
|
|
1016
|
+
return this.endpointMapper.toResponse(response);
|
|
1448
1017
|
}
|
|
1449
|
-
async *stream(
|
|
1450
|
-
const
|
|
1451
|
-
|
|
1018
|
+
async *stream(inferenceParams, signal) {
|
|
1019
|
+
const request = this.endpointMapper.toRequest(inferenceParams);
|
|
1020
|
+
const response = await this.client.responses.create(request);
|
|
1021
|
+
for await (const event of response) {
|
|
1452
1022
|
if (signal == null ? void 0 : signal.aborted) {
|
|
1453
1023
|
break;
|
|
1454
1024
|
}
|
|
1455
|
-
yield new SemanticEvent(
|
|
1025
|
+
yield new SemanticEvent(event.type, event);
|
|
1456
1026
|
}
|
|
1457
1027
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1030
|
+
// src/infrastructure/providers/gemini/endpoints/gemini-generate-content.ts
|
|
1031
|
+
var import_genai = require("@google/genai");
|
|
1032
|
+
|
|
1033
|
+
// src/infrastructure/providers/gemini/endpoints/gemini-generate-content-mapper.ts
|
|
1034
|
+
var GeminiGenerateContentMapper = class {
|
|
1035
|
+
toRequest(inferenceParams) {
|
|
1036
|
+
const { contents, systemInstruction } = this.mapContextItems(inferenceParams);
|
|
1461
1037
|
const config = {};
|
|
1462
1038
|
if (systemInstruction) {
|
|
1463
1039
|
config.systemInstruction = systemInstruction;
|
|
1464
1040
|
}
|
|
1465
|
-
if (
|
|
1041
|
+
if (inferenceParams.tools && inferenceParams.tools.length > 0) {
|
|
1466
1042
|
config.tools = [
|
|
1467
1043
|
{
|
|
1468
|
-
functionDeclarations:
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
};
|
|
1474
|
-
})
|
|
1044
|
+
functionDeclarations: inferenceParams.tools.map((tool) => ({
|
|
1045
|
+
name: tool.name,
|
|
1046
|
+
description: tool.description,
|
|
1047
|
+
parametersJsonSchema: tool.parameters
|
|
1048
|
+
}))
|
|
1475
1049
|
}
|
|
1476
1050
|
];
|
|
1477
1051
|
}
|
|
1478
|
-
if (
|
|
1479
|
-
const effort = inferenceRequest.model.getReasoningEffort();
|
|
1480
|
-
const thinkingLevel = effort === "none" ? "minimal" : effort;
|
|
1481
|
-
config.thinkingConfig = { thinkingLevel, includeThoughts: true };
|
|
1482
|
-
}
|
|
1483
|
-
if (inferenceRequest.model.hasStructuredOutput()) {
|
|
1484
|
-
if (!specification.supportStructuredOutput) {
|
|
1485
|
-
throw new Error(`Structured output is not supported for model: ${specification.name}`);
|
|
1486
|
-
}
|
|
1487
|
-
const format = inferenceRequest.model.getStructuredOutput();
|
|
1052
|
+
if (inferenceParams.structuredOutput) {
|
|
1488
1053
|
config.responseMimeType = "application/json";
|
|
1489
|
-
config.responseSchema =
|
|
1054
|
+
config.responseSchema = inferenceParams.structuredOutput.schema;
|
|
1490
1055
|
}
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
if (!usage) {
|
|
1497
|
-
return void 0;
|
|
1056
|
+
if (inferenceParams.reasoningEffort) {
|
|
1057
|
+
config.thinkingConfig = {
|
|
1058
|
+
thinkingLevel: inferenceParams.reasoningEffort,
|
|
1059
|
+
includeThoughts: true
|
|
1060
|
+
};
|
|
1498
1061
|
}
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1062
|
+
const request = {
|
|
1063
|
+
model: inferenceParams.model,
|
|
1064
|
+
contents,
|
|
1065
|
+
config
|
|
1066
|
+
};
|
|
1067
|
+
if (inferenceParams.streaming) {
|
|
1068
|
+
request.stream = inferenceParams.streaming;
|
|
1069
|
+
}
|
|
1070
|
+
return request;
|
|
1506
1071
|
}
|
|
1507
|
-
|
|
1072
|
+
toResponse(response) {
|
|
1073
|
+
const contextItems = this.extractContextItems(response);
|
|
1074
|
+
const tokenUsage = this.extractTokenUsage(response);
|
|
1075
|
+
return new InferenceResponse(contextItems, tokenUsage);
|
|
1076
|
+
}
|
|
1077
|
+
mapContextItems(inferenceParams) {
|
|
1508
1078
|
var _a;
|
|
1079
|
+
const context = inferenceParams.context;
|
|
1509
1080
|
const contents = [];
|
|
1510
1081
|
const system = [];
|
|
1511
1082
|
const callNames = /* @__PURE__ */ new Map();
|
|
@@ -1548,36 +1119,13 @@ var GeminiGenerateContent = class {
|
|
|
1548
1119
|
systemInstruction: system.length > 0 ? system.join("\n\n") : void 0
|
|
1549
1120
|
};
|
|
1550
1121
|
}
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
if (part.thought && part.text) {
|
|
1557
|
-
items.push(
|
|
1558
|
-
ReasoningItem.rehydrate({
|
|
1559
|
-
content: InputText.rehydrate({ text: part.text }),
|
|
1560
|
-
encryptedContent: void 0,
|
|
1561
|
-
summary: []
|
|
1562
|
-
})
|
|
1563
|
-
);
|
|
1564
|
-
continue;
|
|
1565
|
-
}
|
|
1566
|
-
if (part.text) {
|
|
1567
|
-
items.push(ModelMessageItem.rehydrate({ text: part.text }));
|
|
1568
|
-
continue;
|
|
1569
|
-
}
|
|
1570
|
-
if (part.functionCall) {
|
|
1571
|
-
items.push(
|
|
1572
|
-
FunctionCallItem.rehydrate({
|
|
1573
|
-
callId: (_e = part.functionCall.id) != null ? _e : "",
|
|
1574
|
-
name: part.functionCall.name,
|
|
1575
|
-
args: JSON.stringify((_f = part.functionCall.args) != null ? _f : {})
|
|
1576
|
-
})
|
|
1577
|
-
);
|
|
1578
|
-
}
|
|
1122
|
+
addPart(contents, role, part) {
|
|
1123
|
+
const last = contents[contents.length - 1];
|
|
1124
|
+
if ((last == null ? void 0 : last.role) === role) {
|
|
1125
|
+
last.parts.push(part);
|
|
1126
|
+
return;
|
|
1579
1127
|
}
|
|
1580
|
-
|
|
1128
|
+
contents.push({ role, parts: [part] });
|
|
1581
1129
|
}
|
|
1582
1130
|
parseResponse(output) {
|
|
1583
1131
|
try {
|
|
@@ -1587,203 +1135,110 @@ var GeminiGenerateContent = class {
|
|
|
1587
1135
|
return { output };
|
|
1588
1136
|
}
|
|
1589
1137
|
}
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
return;
|
|
1595
|
-
}
|
|
1596
|
-
contents.push({ role, parts: [part] });
|
|
1597
|
-
}
|
|
1598
|
-
};
|
|
1599
|
-
|
|
1600
|
-
// src/infrastructure/providers/gemini/reasoning-effort.ts
|
|
1601
|
-
var GeminiReasoningEffort = class {
|
|
1602
|
-
constructor(reasoningEffort) {
|
|
1603
|
-
this.reasoningEffort = reasoningEffort;
|
|
1604
|
-
}
|
|
1605
|
-
setReasoningEffort(effort) {
|
|
1606
|
-
this.reasoningEffort = effort;
|
|
1607
|
-
}
|
|
1608
|
-
getReasoningEffort() {
|
|
1609
|
-
if (!this.reasoningEffort) {
|
|
1610
|
-
throw new Error("Reasoning effort not supported");
|
|
1138
|
+
extractTokenUsage(response) {
|
|
1139
|
+
var _a, _b, _c, _d, _e;
|
|
1140
|
+
const usage = response.usageMetadata;
|
|
1141
|
+
if (!usage) {
|
|
1142
|
+
return void 0;
|
|
1611
1143
|
}
|
|
1612
|
-
return
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
constructor() {
|
|
1619
|
-
this.specification = {
|
|
1620
|
-
name: "gemini-3.5-flash",
|
|
1621
|
-
provider: "google",
|
|
1622
|
-
supportReasoningEffort: true,
|
|
1623
|
-
defaultReasoningEffort: "medium",
|
|
1624
|
-
supportStreaming: true,
|
|
1625
|
-
contextWindowSize: 1048576,
|
|
1626
|
-
maxOutputTokens: 64e3,
|
|
1627
|
-
supportFunctionCalling: true,
|
|
1628
|
-
supportStructuredOutput: true
|
|
1629
|
-
};
|
|
1630
|
-
this.tools = [];
|
|
1631
|
-
this.streaming = false;
|
|
1632
|
-
this.structuredOutput = void 0;
|
|
1633
|
-
this.effort = new GeminiReasoningEffort(
|
|
1634
|
-
this.specification.defaultReasoningEffort
|
|
1635
|
-
);
|
|
1636
|
-
}
|
|
1637
|
-
setStreaming(streaming) {
|
|
1638
|
-
this.streaming = streaming;
|
|
1639
|
-
}
|
|
1640
|
-
getStreaming() {
|
|
1641
|
-
return this.streaming;
|
|
1642
|
-
}
|
|
1643
|
-
setTools(tools) {
|
|
1644
|
-
this.tools = tools;
|
|
1645
|
-
}
|
|
1646
|
-
getTools() {
|
|
1647
|
-
return this.tools;
|
|
1648
|
-
}
|
|
1649
|
-
setReasoningEffort(effort) {
|
|
1650
|
-
this.effort.setReasoningEffort(effort);
|
|
1651
|
-
}
|
|
1652
|
-
getReasoningEffort() {
|
|
1653
|
-
return this.effort.getReasoningEffort();
|
|
1654
|
-
}
|
|
1655
|
-
setStructuredOutput(format) {
|
|
1656
|
-
this.structuredOutput = format;
|
|
1657
|
-
}
|
|
1658
|
-
getStructuredOutput() {
|
|
1659
|
-
return this.structuredOutput;
|
|
1660
|
-
}
|
|
1661
|
-
hasStructuredOutput() {
|
|
1662
|
-
return this.structuredOutput !== void 0;
|
|
1663
|
-
}
|
|
1664
|
-
};
|
|
1665
|
-
|
|
1666
|
-
// src/infrastructure/providers/gemini/models/gemini-3-1-pro.ts
|
|
1667
|
-
var Gemini31Pro = class {
|
|
1668
|
-
constructor() {
|
|
1669
|
-
this.specification = {
|
|
1670
|
-
name: "gemini-3.1-pro-preview",
|
|
1671
|
-
provider: "google",
|
|
1672
|
-
supportReasoningEffort: true,
|
|
1673
|
-
defaultReasoningEffort: "high",
|
|
1674
|
-
supportStreaming: true,
|
|
1675
|
-
contextWindowSize: 1048576,
|
|
1676
|
-
maxOutputTokens: 64e3,
|
|
1677
|
-
supportFunctionCalling: true,
|
|
1678
|
-
supportStructuredOutput: true
|
|
1679
|
-
};
|
|
1680
|
-
this.tools = [];
|
|
1681
|
-
this.streaming = false;
|
|
1682
|
-
this.structuredOutput = void 0;
|
|
1683
|
-
this.effort = new GeminiReasoningEffort(
|
|
1684
|
-
this.specification.defaultReasoningEffort
|
|
1144
|
+
return new TokenUsage(
|
|
1145
|
+
(_a = usage.promptTokenCount) != null ? _a : 0,
|
|
1146
|
+
(_b = usage.candidatesTokenCount) != null ? _b : 0,
|
|
1147
|
+
(_c = usage.totalTokenCount) != null ? _c : 0,
|
|
1148
|
+
new InputTokenDetails((_d = usage.cachedContentTokenCount) != null ? _d : 0),
|
|
1149
|
+
new OutputTokenDetails((_e = usage.thoughtsTokenCount) != null ? _e : 0)
|
|
1685
1150
|
);
|
|
1686
1151
|
}
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1152
|
+
extractContextItems(response) {
|
|
1153
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1154
|
+
const items = [];
|
|
1155
|
+
const parts = (_d = (_c = (_b = (_a = response.candidates) == null ? void 0 : _a[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts) != null ? _d : [];
|
|
1156
|
+
for (const part of parts) {
|
|
1157
|
+
if (part.thought && part.text) {
|
|
1158
|
+
items.push(
|
|
1159
|
+
ReasoningItem.rehydrate({
|
|
1160
|
+
content: InputText.rehydrate({ text: part.text }),
|
|
1161
|
+
encryptedContent: void 0,
|
|
1162
|
+
summary: []
|
|
1163
|
+
})
|
|
1164
|
+
);
|
|
1165
|
+
continue;
|
|
1166
|
+
}
|
|
1167
|
+
if (part.text) {
|
|
1168
|
+
items.push(ModelMessageItem.rehydrate({ text: part.text }));
|
|
1169
|
+
continue;
|
|
1170
|
+
}
|
|
1171
|
+
if (part.functionCall) {
|
|
1172
|
+
items.push(
|
|
1173
|
+
FunctionCallItem.rehydrate({
|
|
1174
|
+
callId: (_e = part.functionCall.id) != null ? _e : "",
|
|
1175
|
+
name: part.functionCall.name,
|
|
1176
|
+
args: JSON.stringify((_f = part.functionCall.args) != null ? _f : {})
|
|
1177
|
+
})
|
|
1178
|
+
);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
return items;
|
|
1713
1182
|
}
|
|
1714
1183
|
};
|
|
1715
1184
|
|
|
1716
|
-
// src/infrastructure/providers/
|
|
1717
|
-
var
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
this.client = new import_openai2.default({
|
|
1722
|
-
baseURL: config.baseURL,
|
|
1723
|
-
apiKey: config.apiKey
|
|
1724
|
-
});
|
|
1725
|
-
this.extraBody = (_a = config.extraBody) != null ? _a : {};
|
|
1185
|
+
// src/infrastructure/providers/gemini/endpoints/gemini-generate-content.ts
|
|
1186
|
+
var GeminiGenerateContent = class {
|
|
1187
|
+
constructor(endpointMapper = new GeminiGenerateContentMapper()) {
|
|
1188
|
+
this.endpointMapper = endpointMapper;
|
|
1189
|
+
this.client = new import_genai.GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
|
|
1726
1190
|
}
|
|
1727
|
-
async infer(
|
|
1728
|
-
const
|
|
1729
|
-
const
|
|
1730
|
-
|
|
1731
|
-
return new InferenceResponse(contextItems, tokenUsage);
|
|
1191
|
+
async infer(inferenceParams) {
|
|
1192
|
+
const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
|
|
1193
|
+
const response = await this.client.models.generateContent(inferenceRequest);
|
|
1194
|
+
return this.endpointMapper.toResponse(response);
|
|
1732
1195
|
}
|
|
1733
|
-
async *stream(
|
|
1734
|
-
|
|
1735
|
-
const stream = await this.client.
|
|
1736
|
-
|
|
1737
|
-
stream: true
|
|
1738
|
-
});
|
|
1739
|
-
for await (const event of stream) {
|
|
1196
|
+
async *stream(inferenceParams, signal) {
|
|
1197
|
+
const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
|
|
1198
|
+
const stream = await this.client.models.generateContentStream(inferenceRequest);
|
|
1199
|
+
for await (const chunk of stream) {
|
|
1740
1200
|
if (signal == null ? void 0 : signal.aborted) {
|
|
1741
1201
|
break;
|
|
1742
1202
|
}
|
|
1743
|
-
yield new SemanticEvent(
|
|
1203
|
+
yield new SemanticEvent("generate_content_chunk", chunk);
|
|
1744
1204
|
}
|
|
1745
1205
|
}
|
|
1746
|
-
|
|
1747
|
-
|
|
1206
|
+
};
|
|
1207
|
+
|
|
1208
|
+
// src/infrastructure/providers/openai/endpoints/openai-chat-completions-mapper.ts
|
|
1209
|
+
var OpenAIChatCompletionsMapper = class {
|
|
1210
|
+
toRequest(inferenceParams) {
|
|
1748
1211
|
const request = {
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
messages: this.mapContextToRequest(inferenceRequest.context)
|
|
1212
|
+
model: inferenceParams.model,
|
|
1213
|
+
messages: this.mapContextItems(inferenceParams)
|
|
1752
1214
|
};
|
|
1753
|
-
if (
|
|
1754
|
-
request.tools =
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
};
|
|
1763
|
-
});
|
|
1215
|
+
if (inferenceParams.tools && inferenceParams.tools.length > 0) {
|
|
1216
|
+
request.tools = inferenceParams.tools.map((tool) => ({
|
|
1217
|
+
type: "function",
|
|
1218
|
+
function: {
|
|
1219
|
+
name: tool.name,
|
|
1220
|
+
description: tool.description,
|
|
1221
|
+
parameters: tool.parameters
|
|
1222
|
+
}
|
|
1223
|
+
}));
|
|
1764
1224
|
}
|
|
1765
|
-
if (
|
|
1766
|
-
request.reasoning_effort =
|
|
1225
|
+
if (inferenceParams.reasoningEffort) {
|
|
1226
|
+
request.reasoning_effort = inferenceParams.reasoningEffort;
|
|
1227
|
+
}
|
|
1228
|
+
if (inferenceParams.streaming) {
|
|
1229
|
+
request.stream = inferenceParams.streaming;
|
|
1767
1230
|
}
|
|
1768
1231
|
return request;
|
|
1769
1232
|
}
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
}
|
|
1775
|
-
return new TokenUsage(
|
|
1776
|
-
response.usage.prompt_tokens,
|
|
1777
|
-
response.usage.completion_tokens,
|
|
1778
|
-
response.usage.total_tokens,
|
|
1779
|
-
new InputTokenDetails((_b = (_a = response.usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
|
|
1780
|
-
new OutputTokenDetails((_d = (_c = response.usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
|
|
1781
|
-
);
|
|
1233
|
+
toResponse(response) {
|
|
1234
|
+
const contextItems = this.extractContextItems(response);
|
|
1235
|
+
const tokenUsage = this.extractTokenUsage(response);
|
|
1236
|
+
return new InferenceResponse(contextItems, tokenUsage);
|
|
1782
1237
|
}
|
|
1783
|
-
|
|
1238
|
+
mapContextItems(inferenceParams) {
|
|
1784
1239
|
var _a;
|
|
1785
1240
|
const messages = [];
|
|
1786
|
-
for (const item of context.getItems()) {
|
|
1241
|
+
for (const item of inferenceParams.context.getItems()) {
|
|
1787
1242
|
if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
|
|
1788
1243
|
messages.push({ role: "system", content: item.content.text });
|
|
1789
1244
|
continue;
|
|
@@ -1817,6 +1272,19 @@ var OpenAIChatCompletions = class {
|
|
|
1817
1272
|
}
|
|
1818
1273
|
return messages;
|
|
1819
1274
|
}
|
|
1275
|
+
extractTokenUsage(response) {
|
|
1276
|
+
var _a, _b, _c, _d;
|
|
1277
|
+
if (!response.usage) {
|
|
1278
|
+
return void 0;
|
|
1279
|
+
}
|
|
1280
|
+
return new TokenUsage(
|
|
1281
|
+
response.usage.prompt_tokens,
|
|
1282
|
+
response.usage.completion_tokens,
|
|
1283
|
+
response.usage.total_tokens,
|
|
1284
|
+
new InputTokenDetails((_b = (_a = response.usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
|
|
1285
|
+
new OutputTokenDetails((_d = (_c = response.usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
|
|
1286
|
+
);
|
|
1287
|
+
}
|
|
1820
1288
|
extractContextItems(response) {
|
|
1821
1289
|
var _a, _b, _c;
|
|
1822
1290
|
const items = [];
|
|
@@ -1849,179 +1317,482 @@ var OpenAIChatCompletions = class {
|
|
|
1849
1317
|
}
|
|
1850
1318
|
};
|
|
1851
1319
|
|
|
1852
|
-
// src/
|
|
1853
|
-
var
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
if (signal == null ? void 0 : signal.aborted) {
|
|
1864
|
-
break;
|
|
1865
|
-
}
|
|
1866
|
-
yield item;
|
|
1867
|
-
}
|
|
1320
|
+
// src/infrastructure/providers/openai/endpoints/openai-chat-completions.ts
|
|
1321
|
+
var import_openai2 = __toESM(require("openai"));
|
|
1322
|
+
var OpenAIChatCompletions = class {
|
|
1323
|
+
constructor(endpointMapper = new OpenAIChatCompletionsMapper(), config = {}) {
|
|
1324
|
+
var _a;
|
|
1325
|
+
this.endpointMapper = endpointMapper;
|
|
1326
|
+
this.client = new import_openai2.default({
|
|
1327
|
+
baseURL: config.baseURL,
|
|
1328
|
+
apiKey: config.apiKey
|
|
1329
|
+
});
|
|
1330
|
+
this.extraBody = (_a = config.extraBody) != null ? _a : {};
|
|
1868
1331
|
}
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
this.modelRepository = modelRepository;
|
|
1875
|
-
this.inferenceRunner = inferenceRunner;
|
|
1332
|
+
buildRequest(inferenceParams) {
|
|
1333
|
+
return {
|
|
1334
|
+
...this.extraBody,
|
|
1335
|
+
...this.endpointMapper.toRequest(inferenceParams)
|
|
1336
|
+
};
|
|
1876
1337
|
}
|
|
1877
|
-
|
|
1878
|
-
const
|
|
1879
|
-
|
|
1880
|
-
model.setStreaming(true);
|
|
1881
|
-
}
|
|
1882
|
-
if (tools) {
|
|
1883
|
-
model.setTools(tools);
|
|
1884
|
-
}
|
|
1885
|
-
if (reasoningEffort) {
|
|
1886
|
-
model.setReasoningEffort(reasoningEffort);
|
|
1887
|
-
}
|
|
1888
|
-
if (structuredOutput) {
|
|
1889
|
-
model.setStructuredOutput(structuredOutput);
|
|
1890
|
-
}
|
|
1891
|
-
return model;
|
|
1338
|
+
async infer(inferenceParams) {
|
|
1339
|
+
const response = await this.client.chat.completions.create(this.buildRequest(inferenceParams));
|
|
1340
|
+
return this.endpointMapper.toResponse(response);
|
|
1892
1341
|
}
|
|
1893
|
-
async
|
|
1894
|
-
|
|
1895
|
-
const
|
|
1896
|
-
const
|
|
1897
|
-
modelInfo.model = generativeModel;
|
|
1898
|
-
const result = this.inferenceRunner.run(context, modelInfo, signal);
|
|
1899
|
-
for await (const item of result) {
|
|
1342
|
+
async *stream(inferenceParams, signal) {
|
|
1343
|
+
var _a;
|
|
1344
|
+
const stream = await this.client.chat.completions.create(this.buildRequest(inferenceParams));
|
|
1345
|
+
for await (const event of stream) {
|
|
1900
1346
|
if (signal == null ? void 0 : signal.aborted) {
|
|
1901
1347
|
break;
|
|
1902
1348
|
}
|
|
1903
|
-
|
|
1904
|
-
environment.deliverReasoning(caller, item);
|
|
1905
|
-
} else if (item instanceof FunctionCallItem) {
|
|
1906
|
-
environment.deliverFunctionCall(caller, item);
|
|
1907
|
-
} else if (item instanceof ModelMessageItem) {
|
|
1908
|
-
environment.deliverModelMessage(caller, item);
|
|
1909
|
-
} else if (item instanceof SemanticEvent) {
|
|
1910
|
-
environment.deliverSemanticEvent(caller, item);
|
|
1911
|
-
}
|
|
1349
|
+
yield new SemanticEvent((_a = event.object) != null ? _a : "chat.completion.chunk", event);
|
|
1912
1350
|
}
|
|
1913
1351
|
}
|
|
1914
1352
|
};
|
|
1915
1353
|
|
|
1916
|
-
// src/
|
|
1917
|
-
var
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1354
|
+
// src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts
|
|
1355
|
+
var claudeSonnet46Specification = {
|
|
1356
|
+
name: "claude-sonnet-4-6",
|
|
1357
|
+
provider: "anthropic",
|
|
1358
|
+
supportsReasoningEffort: true,
|
|
1359
|
+
supportedReasoningEfforts: ["max", "high", "medium", "low"],
|
|
1360
|
+
supportedContextItemTypes: [
|
|
1361
|
+
"user_message",
|
|
1362
|
+
"system_message",
|
|
1363
|
+
"developer_message",
|
|
1364
|
+
"reasoning",
|
|
1365
|
+
"function_call",
|
|
1366
|
+
"function_call_output",
|
|
1367
|
+
"model_message"
|
|
1368
|
+
],
|
|
1369
|
+
supportsStreaming: true,
|
|
1370
|
+
contextWindowSize: 2e5,
|
|
1371
|
+
maxOutputTokens: 64e3,
|
|
1372
|
+
supportsFunctionCalling: true,
|
|
1373
|
+
supportsStructuredOutput: true
|
|
1374
|
+
};
|
|
1375
|
+
|
|
1376
|
+
// src/infrastructure/providers/anthropic/models/claude-4-8-opus.ts
|
|
1377
|
+
var claudeOpus48Specification = {
|
|
1378
|
+
name: "claude-opus-4-8",
|
|
1379
|
+
provider: "anthropic",
|
|
1380
|
+
supportsReasoningEffort: true,
|
|
1381
|
+
supportedReasoningEfforts: ["max", "xhigh", "high", "medium", "low"],
|
|
1382
|
+
supportedContextItemTypes: [
|
|
1383
|
+
"user_message",
|
|
1384
|
+
"system_message",
|
|
1385
|
+
"developer_message",
|
|
1386
|
+
"reasoning",
|
|
1387
|
+
"function_call",
|
|
1388
|
+
"function_call_output",
|
|
1389
|
+
"model_message"
|
|
1390
|
+
],
|
|
1391
|
+
supportsStreaming: true,
|
|
1392
|
+
contextWindowSize: 2e5,
|
|
1393
|
+
maxOutputTokens: 32e3,
|
|
1394
|
+
supportsFunctionCalling: true,
|
|
1395
|
+
supportsStructuredOutput: true
|
|
1396
|
+
};
|
|
1397
|
+
|
|
1398
|
+
// src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
|
|
1399
|
+
var claudeOpus47Specification = {
|
|
1400
|
+
name: "claude-opus-4-7",
|
|
1401
|
+
provider: "anthropic",
|
|
1402
|
+
supportsReasoningEffort: true,
|
|
1403
|
+
supportedReasoningEfforts: ["max", "xhigh", "high", "medium", "low"],
|
|
1404
|
+
supportedContextItemTypes: [
|
|
1405
|
+
"user_message",
|
|
1406
|
+
"system_message",
|
|
1407
|
+
"developer_message",
|
|
1408
|
+
"reasoning",
|
|
1409
|
+
"function_call",
|
|
1410
|
+
"function_call_output",
|
|
1411
|
+
"model_message"
|
|
1412
|
+
],
|
|
1413
|
+
supportsStreaming: true,
|
|
1414
|
+
contextWindowSize: 2e5,
|
|
1415
|
+
maxOutputTokens: 32e3,
|
|
1416
|
+
supportsFunctionCalling: true,
|
|
1417
|
+
supportsStructuredOutput: true
|
|
1418
|
+
};
|
|
1419
|
+
|
|
1420
|
+
// src/infrastructure/providers/gemini/models/gemini-3-5-flash.ts
|
|
1421
|
+
var gemini35FlashSpecification = {
|
|
1422
|
+
name: "gemini-3.5-flash",
|
|
1423
|
+
provider: "google",
|
|
1424
|
+
supportsReasoningEffort: true,
|
|
1425
|
+
supportedReasoningEfforts: ["high", "medium", "low", "minimal", "none"],
|
|
1426
|
+
supportedContextItemTypes: [
|
|
1427
|
+
"user_message",
|
|
1428
|
+
"system_message",
|
|
1429
|
+
"developer_message",
|
|
1430
|
+
"reasoning",
|
|
1431
|
+
"function_call",
|
|
1432
|
+
"function_call_output",
|
|
1433
|
+
"model_message"
|
|
1434
|
+
],
|
|
1435
|
+
supportsStreaming: true,
|
|
1436
|
+
contextWindowSize: 1048576,
|
|
1437
|
+
maxOutputTokens: 64e3,
|
|
1438
|
+
supportsFunctionCalling: true,
|
|
1439
|
+
supportsStructuredOutput: true
|
|
1440
|
+
};
|
|
1441
|
+
|
|
1442
|
+
// src/infrastructure/providers/gemini/models/gemini-3-1-pro.ts
|
|
1443
|
+
var gemini31ProSpecification = {
|
|
1444
|
+
name: "gemini-3.1-pro-preview",
|
|
1445
|
+
provider: "google",
|
|
1446
|
+
supportsReasoningEffort: true,
|
|
1447
|
+
supportedReasoningEfforts: ["high", "medium", "low", "minimal", "none"],
|
|
1448
|
+
supportedContextItemTypes: [
|
|
1449
|
+
"user_message",
|
|
1450
|
+
"system_message",
|
|
1451
|
+
"developer_message",
|
|
1452
|
+
"reasoning",
|
|
1453
|
+
"function_call",
|
|
1454
|
+
"function_call_output",
|
|
1455
|
+
"model_message"
|
|
1456
|
+
],
|
|
1457
|
+
supportsStreaming: true,
|
|
1458
|
+
contextWindowSize: 1048576,
|
|
1459
|
+
maxOutputTokens: 64e3,
|
|
1460
|
+
supportsFunctionCalling: true,
|
|
1461
|
+
supportsStructuredOutput: true
|
|
1462
|
+
};
|
|
1463
|
+
|
|
1464
|
+
// src/infrastructure/providers/deepseek/models/deepseek-v4-flash.ts
|
|
1465
|
+
var deepSeekV4FlashSpecification = {
|
|
1466
|
+
name: "deepseek-v4-flash",
|
|
1467
|
+
provider: "deepseek",
|
|
1468
|
+
supportsReasoningEffort: true,
|
|
1469
|
+
supportedReasoningEfforts: ["max", "high", "medium", "low", "none"],
|
|
1470
|
+
supportedContextItemTypes: [
|
|
1471
|
+
"user_message",
|
|
1472
|
+
"system_message",
|
|
1473
|
+
"developer_message",
|
|
1474
|
+
"reasoning",
|
|
1475
|
+
"function_call",
|
|
1476
|
+
"function_call_output",
|
|
1477
|
+
"model_message"
|
|
1478
|
+
],
|
|
1479
|
+
supportsStreaming: true,
|
|
1480
|
+
contextWindowSize: 1e6,
|
|
1481
|
+
maxOutputTokens: 384e3,
|
|
1482
|
+
supportsFunctionCalling: true,
|
|
1483
|
+
supportsStructuredOutput: false
|
|
1927
1484
|
};
|
|
1928
1485
|
|
|
1929
|
-
// src/
|
|
1930
|
-
var
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1486
|
+
// src/infrastructure/providers/deepseek/models/deepseek-v4-pro.ts
|
|
1487
|
+
var deepSeekV4ProSpecification = {
|
|
1488
|
+
name: "deepseek-v4-pro",
|
|
1489
|
+
provider: "deepseek",
|
|
1490
|
+
supportsReasoningEffort: true,
|
|
1491
|
+
supportedReasoningEfforts: ["max", "high", "medium", "low", "none"],
|
|
1492
|
+
supportedContextItemTypes: [
|
|
1493
|
+
"user_message",
|
|
1494
|
+
"system_message",
|
|
1495
|
+
"developer_message",
|
|
1496
|
+
"reasoning",
|
|
1497
|
+
"function_call",
|
|
1498
|
+
"function_call_output",
|
|
1499
|
+
"model_message"
|
|
1500
|
+
],
|
|
1501
|
+
supportsStreaming: true,
|
|
1502
|
+
contextWindowSize: 1e6,
|
|
1503
|
+
maxOutputTokens: 384e3,
|
|
1504
|
+
supportsFunctionCalling: true,
|
|
1505
|
+
supportsStructuredOutput: false
|
|
1506
|
+
};
|
|
1507
|
+
|
|
1508
|
+
// src/infrastructure/providers/openai/models/gpt-5-4.ts
|
|
1509
|
+
var gpt54Specification = {
|
|
1510
|
+
name: "gpt-5.4",
|
|
1511
|
+
provider: "openai",
|
|
1512
|
+
supportsReasoningEffort: true,
|
|
1513
|
+
supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
|
|
1514
|
+
supportedContextItemTypes: [
|
|
1515
|
+
"user_message",
|
|
1516
|
+
"system_message",
|
|
1517
|
+
"developer_message",
|
|
1518
|
+
"reasoning",
|
|
1519
|
+
"function_call",
|
|
1520
|
+
"function_call_output",
|
|
1521
|
+
"model_message"
|
|
1522
|
+
],
|
|
1523
|
+
supportsStreaming: true,
|
|
1524
|
+
contextWindowSize: 105e4,
|
|
1525
|
+
maxOutputTokens: 128e3,
|
|
1526
|
+
supportsFunctionCalling: true,
|
|
1527
|
+
supportsStructuredOutput: true
|
|
1528
|
+
};
|
|
1529
|
+
|
|
1530
|
+
// src/infrastructure/providers/openai/models/gpt-5-4-mini.ts
|
|
1531
|
+
var gpt54MiniSpecification = {
|
|
1532
|
+
name: "gpt-5.4-mini",
|
|
1533
|
+
provider: "openai",
|
|
1534
|
+
supportsReasoningEffort: true,
|
|
1535
|
+
supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
|
|
1536
|
+
supportedContextItemTypes: [
|
|
1537
|
+
"user_message",
|
|
1538
|
+
"system_message",
|
|
1539
|
+
"developer_message",
|
|
1540
|
+
"reasoning",
|
|
1541
|
+
"function_call",
|
|
1542
|
+
"function_call_output",
|
|
1543
|
+
"model_message"
|
|
1544
|
+
],
|
|
1545
|
+
supportsStreaming: true,
|
|
1546
|
+
contextWindowSize: 4e5,
|
|
1547
|
+
maxOutputTokens: 128e3,
|
|
1548
|
+
supportsFunctionCalling: true,
|
|
1549
|
+
supportsStructuredOutput: true
|
|
1550
|
+
};
|
|
1551
|
+
|
|
1552
|
+
// src/infrastructure/providers/openai/models/gpt-5-4-nano.ts
|
|
1553
|
+
var gpt54NanoSpecification = {
|
|
1554
|
+
name: "gpt-5.4-nano",
|
|
1555
|
+
provider: "openai",
|
|
1556
|
+
supportsReasoningEffort: true,
|
|
1557
|
+
supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
|
|
1558
|
+
supportedContextItemTypes: [
|
|
1559
|
+
"user_message",
|
|
1560
|
+
"system_message",
|
|
1561
|
+
"developer_message",
|
|
1562
|
+
"reasoning",
|
|
1563
|
+
"function_call",
|
|
1564
|
+
"function_call_output",
|
|
1565
|
+
"model_message"
|
|
1566
|
+
],
|
|
1567
|
+
supportsStreaming: true,
|
|
1568
|
+
contextWindowSize: 4e5,
|
|
1569
|
+
maxOutputTokens: 128e3,
|
|
1570
|
+
supportsFunctionCalling: true,
|
|
1571
|
+
supportsStructuredOutput: true
|
|
1572
|
+
};
|
|
1573
|
+
|
|
1574
|
+
// src/infrastructure/providers/openai/models/gpt-5-5.ts
|
|
1575
|
+
var gpt55Specification = {
|
|
1576
|
+
name: "gpt-5.5",
|
|
1577
|
+
provider: "openai",
|
|
1578
|
+
supportsReasoningEffort: true,
|
|
1579
|
+
supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
|
|
1580
|
+
supportedContextItemTypes: [
|
|
1581
|
+
"user_message",
|
|
1582
|
+
"system_message",
|
|
1583
|
+
"developer_message",
|
|
1584
|
+
"reasoning",
|
|
1585
|
+
"function_call",
|
|
1586
|
+
"function_call_output",
|
|
1587
|
+
"model_message"
|
|
1588
|
+
],
|
|
1589
|
+
supportsStreaming: true,
|
|
1590
|
+
contextWindowSize: 105e4,
|
|
1591
|
+
maxOutputTokens: 128e3,
|
|
1592
|
+
supportsFunctionCalling: true,
|
|
1593
|
+
supportsStructuredOutput: true
|
|
1594
|
+
};
|
|
1595
|
+
|
|
1596
|
+
// src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts
|
|
1597
|
+
var claudeHaiku45Specification = {
|
|
1598
|
+
name: "claude-haiku-4-5",
|
|
1599
|
+
provider: "anthropic",
|
|
1600
|
+
supportsReasoningEffort: true,
|
|
1601
|
+
supportedReasoningEfforts: ["high", "medium", "low", "none"],
|
|
1602
|
+
supportedContextItemTypes: [
|
|
1603
|
+
"user_message",
|
|
1604
|
+
"system_message",
|
|
1605
|
+
"developer_message",
|
|
1606
|
+
"reasoning",
|
|
1607
|
+
"function_call",
|
|
1608
|
+
"function_call_output",
|
|
1609
|
+
"model_message"
|
|
1610
|
+
],
|
|
1611
|
+
supportsStreaming: true,
|
|
1612
|
+
contextWindowSize: 2e5,
|
|
1613
|
+
maxOutputTokens: 64e3,
|
|
1614
|
+
supportsFunctionCalling: true,
|
|
1615
|
+
supportsStructuredOutput: true
|
|
1616
|
+
};
|
|
1617
|
+
|
|
1618
|
+
// src/infrastructure/repository/generative-model-repository.ts
|
|
1619
|
+
var InMemoryGenerativeModelRepository = class {
|
|
1620
|
+
getByModelName(modelName) {
|
|
1621
|
+
let generativeModel = void 0;
|
|
1622
|
+
switch (modelName) {
|
|
1623
|
+
case "gpt-5.4":
|
|
1624
|
+
generativeModel = {
|
|
1625
|
+
endpoint: new OpenAIResponses(),
|
|
1626
|
+
specification: gpt54Specification
|
|
1627
|
+
};
|
|
1628
|
+
break;
|
|
1629
|
+
case "gpt-5.4-mini":
|
|
1630
|
+
generativeModel = {
|
|
1631
|
+
endpoint: new OpenAIResponses(),
|
|
1632
|
+
specification: gpt54MiniSpecification
|
|
1633
|
+
};
|
|
1634
|
+
break;
|
|
1635
|
+
case "gpt-5.4-nano":
|
|
1636
|
+
generativeModel = {
|
|
1637
|
+
endpoint: new OpenAIResponses(),
|
|
1638
|
+
specification: gpt54NanoSpecification
|
|
1639
|
+
};
|
|
1640
|
+
break;
|
|
1641
|
+
case "gpt-5.5":
|
|
1642
|
+
generativeModel = {
|
|
1643
|
+
endpoint: new OpenAIResponses(),
|
|
1644
|
+
specification: gpt55Specification
|
|
1645
|
+
};
|
|
1646
|
+
break;
|
|
1647
|
+
case "claude-haiku-4-5":
|
|
1648
|
+
generativeModel = {
|
|
1649
|
+
endpoint: new AnthropicMessages(),
|
|
1650
|
+
specification: claudeHaiku45Specification
|
|
1651
|
+
};
|
|
1652
|
+
break;
|
|
1653
|
+
case "claude-sonnet-4-6":
|
|
1654
|
+
generativeModel = {
|
|
1655
|
+
endpoint: new AnthropicMessages(),
|
|
1656
|
+
specification: claudeSonnet46Specification
|
|
1657
|
+
};
|
|
1658
|
+
break;
|
|
1659
|
+
case "claude-opus-4-7":
|
|
1660
|
+
generativeModel = {
|
|
1661
|
+
endpoint: new AnthropicMessages(),
|
|
1662
|
+
specification: claudeOpus47Specification
|
|
1663
|
+
};
|
|
1664
|
+
break;
|
|
1665
|
+
case "claude-opus-4-8":
|
|
1666
|
+
generativeModel = {
|
|
1667
|
+
endpoint: new AnthropicMessages(),
|
|
1668
|
+
specification: claudeOpus48Specification
|
|
1669
|
+
};
|
|
1670
|
+
break;
|
|
1671
|
+
case "gemini-3.5-flash":
|
|
1672
|
+
generativeModel = {
|
|
1673
|
+
endpoint: new GeminiGenerateContent(),
|
|
1674
|
+
specification: gemini35FlashSpecification
|
|
1675
|
+
};
|
|
1676
|
+
break;
|
|
1677
|
+
case "gemini-3.1-pro-preview":
|
|
1678
|
+
generativeModel = {
|
|
1679
|
+
endpoint: new GeminiGenerateContent(),
|
|
1680
|
+
specification: gemini31ProSpecification
|
|
1681
|
+
};
|
|
1682
|
+
break;
|
|
1953
1683
|
case "deepseek-v4-flash":
|
|
1954
|
-
|
|
1684
|
+
generativeModel = {
|
|
1685
|
+
endpoint: new OpenAIChatCompletions(),
|
|
1686
|
+
specification: deepSeekV4FlashSpecification
|
|
1687
|
+
};
|
|
1688
|
+
break;
|
|
1955
1689
|
case "deepseek-v4-pro":
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1690
|
+
generativeModel = {
|
|
1691
|
+
endpoint: new OpenAIChatCompletions(),
|
|
1692
|
+
specification: deepSeekV4ProSpecification
|
|
1693
|
+
};
|
|
1694
|
+
}
|
|
1695
|
+
if (!generativeModel) {
|
|
1696
|
+
throw new Error(`Unsupported model: ${modelName}`);
|
|
1959
1697
|
}
|
|
1698
|
+
return Promise.resolve(generativeModel);
|
|
1960
1699
|
}
|
|
1961
1700
|
};
|
|
1962
1701
|
|
|
1963
|
-
// src/
|
|
1964
|
-
var
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1702
|
+
// src/domain/generative-model/request-validation/reasoning-effort.ts
|
|
1703
|
+
var ReasoningEffortValidation = class {
|
|
1704
|
+
constructor() {
|
|
1705
|
+
this.name = "reasoning-effort";
|
|
1706
|
+
}
|
|
1707
|
+
isValid(inferenceParams, model) {
|
|
1708
|
+
if (inferenceParams.reasoningEffort === void 0) {
|
|
1709
|
+
return true;
|
|
1968
1710
|
}
|
|
1969
|
-
if (!
|
|
1970
|
-
|
|
1971
|
-
|
|
1711
|
+
if (!model.supportsReasoningEffort) {
|
|
1712
|
+
return false;
|
|
1713
|
+
}
|
|
1714
|
+
return model.supportedReasoningEfforts.includes(inferenceParams.reasoningEffort);
|
|
1972
1715
|
}
|
|
1973
1716
|
};
|
|
1974
1717
|
|
|
1975
|
-
// src/
|
|
1976
|
-
var
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
onExternalFunctionCall(source, item) {
|
|
1980
|
-
}
|
|
1981
|
-
onFunctionCallOutput(item) {
|
|
1982
|
-
}
|
|
1983
|
-
onExternalFunctionCallOutput(source, item) {
|
|
1984
|
-
}
|
|
1985
|
-
onReasoning(item) {
|
|
1986
|
-
}
|
|
1987
|
-
onExternalReasoning(source, item) {
|
|
1988
|
-
}
|
|
1989
|
-
onModelMessage(item) {
|
|
1990
|
-
}
|
|
1991
|
-
onExternalModelMessage(source, item) {
|
|
1718
|
+
// src/domain/generative-model/request-validation/tool-calling.ts
|
|
1719
|
+
var ToolCallingValidation = class {
|
|
1720
|
+
constructor() {
|
|
1721
|
+
this.name = "tool-calling";
|
|
1992
1722
|
}
|
|
1993
|
-
|
|
1723
|
+
isValid(inferenceParams, model) {
|
|
1724
|
+
if (inferenceParams.tools === void 0) {
|
|
1725
|
+
return true;
|
|
1726
|
+
}
|
|
1727
|
+
return model.supportsFunctionCalling;
|
|
1994
1728
|
}
|
|
1995
|
-
|
|
1729
|
+
};
|
|
1730
|
+
|
|
1731
|
+
// src/domain/generative-model/request-validation/streaming.ts
|
|
1732
|
+
var StreamingValidation = class {
|
|
1733
|
+
constructor() {
|
|
1734
|
+
this.name = "streaming";
|
|
1996
1735
|
}
|
|
1997
|
-
|
|
1736
|
+
isValid(inferenceParams, model) {
|
|
1737
|
+
if (!inferenceParams.streaming) {
|
|
1738
|
+
return true;
|
|
1739
|
+
}
|
|
1740
|
+
return model.supportsStreaming;
|
|
1998
1741
|
}
|
|
1999
|
-
|
|
1742
|
+
};
|
|
1743
|
+
|
|
1744
|
+
// src/domain/generative-model/request-validation/context.ts
|
|
1745
|
+
function getContextItemValidationKey(item) {
|
|
1746
|
+
if (item instanceof UserMessageItem) {
|
|
1747
|
+
return "user_message";
|
|
2000
1748
|
}
|
|
2001
|
-
|
|
1749
|
+
if (item instanceof SystemMessageItem) {
|
|
1750
|
+
return "system_message";
|
|
2002
1751
|
}
|
|
2003
|
-
|
|
1752
|
+
if (item instanceof DeveloperMessageItem) {
|
|
1753
|
+
return "developer_message";
|
|
2004
1754
|
}
|
|
2005
|
-
|
|
1755
|
+
if (item instanceof ModelMessageItem) {
|
|
1756
|
+
return "model_message";
|
|
2006
1757
|
}
|
|
2007
|
-
|
|
1758
|
+
return item.getType();
|
|
1759
|
+
}
|
|
1760
|
+
var ContextValidation = class {
|
|
1761
|
+
constructor() {
|
|
1762
|
+
this.name = "context";
|
|
2008
1763
|
}
|
|
2009
|
-
|
|
1764
|
+
isValid(inferenceParams, model) {
|
|
1765
|
+
return inferenceParams.context.items.every(
|
|
1766
|
+
(item) => model.supportedContextItemTypes.includes(getContextItemValidationKey(item))
|
|
1767
|
+
);
|
|
2010
1768
|
}
|
|
2011
1769
|
};
|
|
2012
1770
|
|
|
2013
|
-
// src/
|
|
2014
|
-
var
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
1771
|
+
// src/domain/generative-model/request-validation/inference-request-validator.ts
|
|
1772
|
+
var defaultRequestValidationRules = [
|
|
1773
|
+
new ReasoningEffortValidation(),
|
|
1774
|
+
new ToolCallingValidation(),
|
|
1775
|
+
new StreamingValidation(),
|
|
1776
|
+
new StructuredOutputValidation(),
|
|
1777
|
+
new ContextValidation()
|
|
1778
|
+
];
|
|
1779
|
+
var InferenceRequestValidator = class {
|
|
1780
|
+
constructor(rules = defaultRequestValidationRules) {
|
|
1781
|
+
this.rules = rules;
|
|
1782
|
+
}
|
|
1783
|
+
validate(inferenceParams, model) {
|
|
1784
|
+
for (const rule of this.rules) {
|
|
1785
|
+
if (!rule.isValid(inferenceParams, model)) {
|
|
1786
|
+
throw new Error(`Request validation "${rule.name}" failed for model "${model.name}"`);
|
|
1787
|
+
}
|
|
2018
1788
|
}
|
|
2019
|
-
environment.deliverMessage(caller, message);
|
|
2020
1789
|
}
|
|
2021
1790
|
};
|
|
2022
1791
|
|
|
2023
1792
|
// src/index.ts
|
|
2024
|
-
var
|
|
1793
|
+
var generativeModelRepository = new InMemoryGenerativeModelRepository();
|
|
1794
|
+
var inferenceRequestValidator = new InferenceRequestValidator();
|
|
1795
|
+
var runInferenceUseCase = new RunInference(generativeModelRepository, inferenceRequestValidator);
|
|
2025
1796
|
var executeFunctionCallUseCase = new ExecuteFunctionCall(new FunctionCallRunner());
|
|
2026
1797
|
var sendMessageUseCase = new SendMessage();
|
|
2027
1798
|
var runInference = (inferenceParams) => {
|
|
@@ -2037,33 +1808,16 @@ var sendMessage = (environment, message, caller) => {
|
|
|
2037
1808
|
0 && (module.exports = {
|
|
2038
1809
|
AgenticEnvironment,
|
|
2039
1810
|
AgenticError,
|
|
2040
|
-
AnthropicMessages,
|
|
2041
1811
|
BaseParticipant,
|
|
2042
|
-
ClaudeHaiku45,
|
|
2043
|
-
ClaudeOpus47,
|
|
2044
|
-
ClaudeOpus48,
|
|
2045
|
-
ClaudeSonnet46,
|
|
2046
1812
|
ContextItem,
|
|
2047
|
-
DeepSeekV4Flash,
|
|
2048
|
-
DeepSeekV4Pro,
|
|
2049
1813
|
DeveloperMessageItem,
|
|
2050
1814
|
FunctionCallItem,
|
|
2051
1815
|
FunctionCallOutputItem,
|
|
2052
|
-
Gemini31Pro,
|
|
2053
|
-
Gemini35Flash,
|
|
2054
|
-
GeminiGenerateContent,
|
|
2055
|
-
Gpt54,
|
|
2056
|
-
Gpt54Mini,
|
|
2057
|
-
Gpt54Nano,
|
|
2058
|
-
Gpt55,
|
|
2059
1816
|
InMemoryModelContextRepository,
|
|
2060
|
-
InferenceRequest,
|
|
2061
1817
|
InferenceResponse,
|
|
2062
1818
|
InputTokenDetails,
|
|
2063
1819
|
ModelContext,
|
|
2064
1820
|
ModelMessageItem,
|
|
2065
|
-
OpenAIChatCompletions,
|
|
2066
|
-
OpenAIResponses,
|
|
2067
1821
|
OutputTokenDetails,
|
|
2068
1822
|
Participant,
|
|
2069
1823
|
ReasoningItem,
|