@mozaik-ai/core 3.11.0 → 3.13.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/README.md +47 -0
- package/dist/index.d.mts +374 -147
- package/dist/index.d.ts +374 -147
- package/dist/index.js +1069 -275
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1056 -266
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -1
- package/tests/README.md +31 -0
package/dist/index.js
CHANGED
|
@@ -30,33 +30,34 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
Agent: () => Agent,
|
|
34
33
|
AgenticEnvironment: () => AgenticEnvironment,
|
|
34
|
+
AgenticError: () => AgenticError,
|
|
35
35
|
AnthropicMessages: () => AnthropicMessages,
|
|
36
|
-
|
|
37
|
-
BaseHuman: () => BaseHuman,
|
|
38
|
-
BaseObserver: () => BaseObserver,
|
|
36
|
+
BaseParticipant: () => BaseParticipant,
|
|
39
37
|
ClaudeHaiku45: () => ClaudeHaiku45,
|
|
40
38
|
ClaudeOpus47: () => ClaudeOpus47,
|
|
39
|
+
ClaudeOpus48: () => ClaudeOpus48,
|
|
41
40
|
ClaudeSonnet46: () => ClaudeSonnet46,
|
|
42
41
|
ContextItem: () => ContextItem,
|
|
43
|
-
|
|
42
|
+
DeepSeekV4Flash: () => DeepSeekV4Flash,
|
|
43
|
+
DeepSeekV4Pro: () => DeepSeekV4Pro,
|
|
44
44
|
DeveloperMessageItem: () => DeveloperMessageItem,
|
|
45
45
|
FunctionCallItem: () => FunctionCallItem,
|
|
46
46
|
FunctionCallOutputItem: () => FunctionCallOutputItem,
|
|
47
|
+
Gemini31Pro: () => Gemini31Pro,
|
|
48
|
+
Gemini35Flash: () => Gemini35Flash,
|
|
49
|
+
GeminiGenerateContent: () => GeminiGenerateContent,
|
|
47
50
|
Gpt54: () => Gpt54,
|
|
48
51
|
Gpt54Mini: () => Gpt54Mini,
|
|
49
52
|
Gpt54Nano: () => Gpt54Nano,
|
|
50
53
|
Gpt55: () => Gpt55,
|
|
51
|
-
Human: () => Human,
|
|
52
54
|
InMemoryModelContextRepository: () => InMemoryModelContextRepository,
|
|
53
55
|
InferenceRequest: () => InferenceRequest,
|
|
54
56
|
InferenceResponse: () => InferenceResponse,
|
|
55
57
|
InputTokenDetails: () => InputTokenDetails,
|
|
56
58
|
ModelContext: () => ModelContext,
|
|
57
59
|
ModelMessageItem: () => ModelMessageItem,
|
|
58
|
-
|
|
59
|
-
OpenAIInferenceRunner: () => OpenAIInferenceRunner,
|
|
60
|
+
OpenAIChatCompletions: () => OpenAIChatCompletions,
|
|
60
61
|
OpenAIResponses: () => OpenAIResponses,
|
|
61
62
|
OutputTokenDetails: () => OutputTokenDetails,
|
|
62
63
|
Participant: () => Participant,
|
|
@@ -64,7 +65,10 @@ __export(index_exports, {
|
|
|
64
65
|
SemanticEvent: () => SemanticEvent,
|
|
65
66
|
SystemMessageItem: () => SystemMessageItem,
|
|
66
67
|
TokenUsage: () => TokenUsage,
|
|
67
|
-
UserMessageItem: () => UserMessageItem
|
|
68
|
+
UserMessageItem: () => UserMessageItem,
|
|
69
|
+
executeFunctionCall: () => executeFunctionCall,
|
|
70
|
+
runInference: () => runInference,
|
|
71
|
+
sendMessage: () => sendMessage
|
|
68
72
|
});
|
|
69
73
|
module.exports = __toCommonJS(index_exports);
|
|
70
74
|
|
|
@@ -325,18 +329,21 @@ var Gpt54Nano = class {
|
|
|
325
329
|
constructor() {
|
|
326
330
|
this.specification = {
|
|
327
331
|
name: "gpt-5.4-nano",
|
|
332
|
+
provider: "openai",
|
|
328
333
|
supportReasoningEffort: true,
|
|
329
334
|
defaultReasoningEffort: "none",
|
|
330
335
|
supportStreaming: true,
|
|
331
336
|
contextWindowSize: 4e5,
|
|
332
337
|
maxOutputTokens: 128e3,
|
|
333
|
-
supportFunctionCalling: true
|
|
338
|
+
supportFunctionCalling: true,
|
|
339
|
+
supportStructuredOutput: true
|
|
334
340
|
};
|
|
335
341
|
this.tools = [];
|
|
342
|
+
this.streaming = false;
|
|
343
|
+
this.structuredOutput = void 0;
|
|
336
344
|
this.effort = new OpenAIReasoningEffort(
|
|
337
345
|
this.specification.defaultReasoningEffort
|
|
338
346
|
);
|
|
339
|
-
this.streaming = false;
|
|
340
347
|
}
|
|
341
348
|
setStreaming(streaming) {
|
|
342
349
|
this.streaming = streaming;
|
|
@@ -356,6 +363,15 @@ var Gpt54Nano = class {
|
|
|
356
363
|
getReasoningEffort() {
|
|
357
364
|
return this.effort.getReasoningEffort();
|
|
358
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
|
+
}
|
|
359
375
|
};
|
|
360
376
|
|
|
361
377
|
// src/infrastructure/providers/openai/models/gpt-5-4.ts
|
|
@@ -363,15 +379,18 @@ var Gpt54 = class {
|
|
|
363
379
|
constructor() {
|
|
364
380
|
this.specification = {
|
|
365
381
|
name: "gpt-5.4",
|
|
382
|
+
provider: "openai",
|
|
366
383
|
supportReasoningEffort: true,
|
|
367
384
|
defaultReasoningEffort: "none",
|
|
368
385
|
supportStreaming: true,
|
|
369
386
|
contextWindowSize: 105e4,
|
|
370
387
|
maxOutputTokens: 128e3,
|
|
371
|
-
supportFunctionCalling: true
|
|
388
|
+
supportFunctionCalling: true,
|
|
389
|
+
supportStructuredOutput: true
|
|
372
390
|
};
|
|
373
391
|
this.tools = [];
|
|
374
392
|
this.streaming = false;
|
|
393
|
+
this.structuredOutput = void 0;
|
|
375
394
|
this.effort = new OpenAIReasoningEffort(
|
|
376
395
|
this.specification.defaultReasoningEffort
|
|
377
396
|
);
|
|
@@ -394,6 +413,15 @@ var Gpt54 = class {
|
|
|
394
413
|
getReasoningEffort() {
|
|
395
414
|
return this.effort.getReasoningEffort();
|
|
396
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
|
+
}
|
|
397
425
|
};
|
|
398
426
|
|
|
399
427
|
// src/infrastructure/providers/openai/models/gpt-5-4-mini.ts
|
|
@@ -401,18 +429,21 @@ var Gpt54Mini = class {
|
|
|
401
429
|
constructor() {
|
|
402
430
|
this.specification = {
|
|
403
431
|
name: "gpt-5.4-mini",
|
|
432
|
+
provider: "openai",
|
|
404
433
|
supportReasoningEffort: true,
|
|
405
434
|
defaultReasoningEffort: "none",
|
|
406
435
|
supportStreaming: true,
|
|
407
436
|
contextWindowSize: 4e5,
|
|
408
437
|
maxOutputTokens: 128e3,
|
|
409
|
-
supportFunctionCalling: true
|
|
438
|
+
supportFunctionCalling: true,
|
|
439
|
+
supportStructuredOutput: true
|
|
410
440
|
};
|
|
411
441
|
this.tools = [];
|
|
442
|
+
this.streaming = false;
|
|
443
|
+
this.structuredOutput = void 0;
|
|
412
444
|
this.effort = new OpenAIReasoningEffort(
|
|
413
445
|
this.specification.defaultReasoningEffort
|
|
414
446
|
);
|
|
415
|
-
this.streaming = false;
|
|
416
447
|
}
|
|
417
448
|
setStreaming(streaming) {
|
|
418
449
|
this.streaming = streaming;
|
|
@@ -432,6 +463,15 @@ var Gpt54Mini = class {
|
|
|
432
463
|
getTools() {
|
|
433
464
|
return this.tools;
|
|
434
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
|
+
}
|
|
435
475
|
};
|
|
436
476
|
|
|
437
477
|
// src/domain/generative-model/token-usage.ts
|
|
@@ -522,10 +562,12 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
|
|
|
522
562
|
}
|
|
523
563
|
};
|
|
524
564
|
|
|
525
|
-
// src/domain/agentic-environment/
|
|
565
|
+
// src/domain/agentic-environment/participant.ts
|
|
526
566
|
var Participant = class {
|
|
527
567
|
constructor() {
|
|
528
568
|
this.environments = [];
|
|
569
|
+
this.listens = [];
|
|
570
|
+
this.active = /* @__PURE__ */ new Map();
|
|
529
571
|
}
|
|
530
572
|
join(environment) {
|
|
531
573
|
if (this.isJoinedTo(environment)) {
|
|
@@ -533,6 +575,7 @@ var Participant = class {
|
|
|
533
575
|
}
|
|
534
576
|
environment.subscribe(this);
|
|
535
577
|
this.environments.push(environment);
|
|
578
|
+
this.active.set(environment, true);
|
|
536
579
|
}
|
|
537
580
|
leave(environment) {
|
|
538
581
|
if (!this.isJoinedTo(environment)) {
|
|
@@ -540,6 +583,7 @@ var Participant = class {
|
|
|
540
583
|
}
|
|
541
584
|
environment.unsubscribe(this);
|
|
542
585
|
this.environments = this.environments.filter((e) => e !== environment);
|
|
586
|
+
this.active.delete(environment);
|
|
543
587
|
}
|
|
544
588
|
isJoinedTo(environment) {
|
|
545
589
|
return this.environments.includes(environment);
|
|
@@ -547,13 +591,49 @@ var Participant = class {
|
|
|
547
591
|
getEnvironments() {
|
|
548
592
|
return this.environments;
|
|
549
593
|
}
|
|
594
|
+
getListeners() {
|
|
595
|
+
return this.listens;
|
|
596
|
+
}
|
|
597
|
+
getEnvironmentState(environment) {
|
|
598
|
+
return this.active.get(environment);
|
|
599
|
+
}
|
|
600
|
+
markInactive(environment) {
|
|
601
|
+
if (this.active.has(environment)) {
|
|
602
|
+
this.active.set(environment, false);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
markActive(environment) {
|
|
606
|
+
if (this.active.has(environment)) {
|
|
607
|
+
this.active.set(environment, true);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
// src/domain/agentic-environment/errors/base-error.ts
|
|
613
|
+
var AgenticError = class extends Error {
|
|
614
|
+
constructor({ message, stack, source, enviornment }) {
|
|
615
|
+
super();
|
|
616
|
+
this.message = message;
|
|
617
|
+
this.stack = stack;
|
|
618
|
+
this.source = source;
|
|
619
|
+
this.environment = enviornment;
|
|
620
|
+
}
|
|
621
|
+
getSource() {
|
|
622
|
+
return this.source;
|
|
623
|
+
}
|
|
624
|
+
getEnvironment() {
|
|
625
|
+
return this.environment;
|
|
626
|
+
}
|
|
550
627
|
};
|
|
551
628
|
|
|
552
629
|
// src/domain/agentic-environment/agentic-environment.ts
|
|
553
630
|
var AgenticEnvironment = class {
|
|
554
|
-
constructor() {
|
|
631
|
+
constructor(name, opts) {
|
|
555
632
|
this.subscribers = [];
|
|
556
|
-
|
|
633
|
+
var _a;
|
|
634
|
+
this.name = name;
|
|
635
|
+
this.options = opts;
|
|
636
|
+
this.showLogs = ((_a = this.options) == null ? void 0 : _a.silent) !== false;
|
|
557
637
|
}
|
|
558
638
|
subscribe(participant) {
|
|
559
639
|
this.subscribers.push(participant);
|
|
@@ -577,227 +657,100 @@ var AgenticEnvironment = class {
|
|
|
577
657
|
}
|
|
578
658
|
}
|
|
579
659
|
deliverFunctionCall(source, item) {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
subscriber.onExternalFunctionCall(source, item);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
660
|
+
this.deliverToSubscribers(source, {
|
|
661
|
+
internal: (src) => src.onFunctionCall(item),
|
|
662
|
+
external: (sub) => sub.onExternalFunctionCall(source, item)
|
|
663
|
+
});
|
|
587
664
|
}
|
|
588
665
|
deliverModelMessage(source, item) {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
subscriber.onExternalModelMessage(source, item);
|
|
594
|
-
}
|
|
595
|
-
}
|
|
666
|
+
this.deliverToSubscribers(source, {
|
|
667
|
+
internal: (src) => src.onModelMessage(item),
|
|
668
|
+
external: (sub) => sub.onExternalModelMessage(source, item)
|
|
669
|
+
});
|
|
596
670
|
}
|
|
597
671
|
deliverReasoning(source, item) {
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
subscriber.onExternalReasoning(source, item);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
672
|
+
this.deliverToSubscribers(source, {
|
|
673
|
+
internal: (src) => src.onReasoning(item),
|
|
674
|
+
external: (sub) => sub.onExternalReasoning(source, item)
|
|
675
|
+
});
|
|
605
676
|
}
|
|
606
677
|
deliverFunctionCallOutput(source, item) {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
subscriber.onExternalFunctionCallOutput(source, item);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
678
|
+
this.deliverToSubscribers(source, {
|
|
679
|
+
internal: (src) => src.onFunctionCallOutput(item),
|
|
680
|
+
external: (sub) => sub.onExternalFunctionCallOutput(source, item)
|
|
681
|
+
});
|
|
614
682
|
}
|
|
615
683
|
deliverMessage(source, message) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
}
|
|
684
|
+
this.deliverToSubscribers(source, {
|
|
685
|
+
external: (sub) => sub.onMessage(message)
|
|
686
|
+
});
|
|
620
687
|
}
|
|
621
688
|
deliverSemanticEvent(source, item) {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
subscriber.onExternalEvent(source, item);
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
async start() {
|
|
631
|
-
this.isActive = true;
|
|
632
|
-
while (this.isActive) {
|
|
633
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
stop() {
|
|
637
|
-
this.isActive = false;
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
|
-
|
|
641
|
-
// src/domain/agentic-environment/participants/agent.ts
|
|
642
|
-
var Agent = class extends Participant {
|
|
643
|
-
};
|
|
644
|
-
|
|
645
|
-
// src/domain/model-context/semantic-event/semantic-event.ts
|
|
646
|
-
var SemanticEvent = class {
|
|
647
|
-
constructor(type, data) {
|
|
648
|
-
this.type = type;
|
|
649
|
-
this.data = data;
|
|
650
|
-
}
|
|
651
|
-
getType() {
|
|
652
|
-
return this.type;
|
|
653
|
-
}
|
|
654
|
-
};
|
|
655
|
-
|
|
656
|
-
// src/application/participants/agent.ts
|
|
657
|
-
var BaseAgent = class extends Agent {
|
|
658
|
-
constructor(inferenceRunner, functionCallRunner) {
|
|
659
|
-
super();
|
|
660
|
-
this.inferenceRunner = inferenceRunner;
|
|
661
|
-
this.functionCallRunner = functionCallRunner;
|
|
662
|
-
}
|
|
663
|
-
onJoined() {
|
|
664
|
-
}
|
|
665
|
-
onLeft() {
|
|
666
|
-
}
|
|
667
|
-
onParticipantJoined(participant) {
|
|
668
|
-
}
|
|
669
|
-
onParticipantLeft(participant) {
|
|
670
|
-
}
|
|
671
|
-
onFunctionCall(item) {
|
|
672
|
-
}
|
|
673
|
-
onExternalFunctionCall(source, item) {
|
|
674
|
-
}
|
|
675
|
-
onFunctionCallOutput(item) {
|
|
676
|
-
}
|
|
677
|
-
onExternalFunctionCallOutput(source, item) {
|
|
678
|
-
}
|
|
679
|
-
onReasoning(item) {
|
|
680
|
-
}
|
|
681
|
-
onExternalReasoning(source, item) {
|
|
682
|
-
}
|
|
683
|
-
onModelMessage(item) {
|
|
684
|
-
}
|
|
685
|
-
onExternalModelMessage(source, item) {
|
|
686
|
-
}
|
|
687
|
-
onMessage(message) {
|
|
688
|
-
}
|
|
689
|
-
onInternalEvent(item) {
|
|
690
|
-
}
|
|
691
|
-
onExternalEvent(source, item) {
|
|
692
|
-
}
|
|
693
|
-
async executeFunctionCall(environment, functionCallItem, signal) {
|
|
694
|
-
if (!this.isJoinedTo(environment)) return;
|
|
695
|
-
const stream = this.functionCallRunner.run(functionCallItem, signal);
|
|
696
|
-
for await (const item of stream) {
|
|
697
|
-
environment.deliverFunctionCallOutput(this, item);
|
|
698
|
-
}
|
|
689
|
+
this.deliverToSubscribers(source, {
|
|
690
|
+
internal: (src) => src.onInternalEvent(item),
|
|
691
|
+
external: (sub) => sub.onExternalEvent(source, item)
|
|
692
|
+
});
|
|
699
693
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
694
|
+
deliverError(source, error) {
|
|
695
|
+
this.deliverToSubscribers(source, {
|
|
696
|
+
internal: (src) => {
|
|
697
|
+
try {
|
|
698
|
+
src.onError(error);
|
|
699
|
+
} catch (error2) {
|
|
700
|
+
if (this.showLogs) {
|
|
701
|
+
console.warn(`[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
|
|
702
|
+
${JSON.stringify({ error: error2 }, null, 2)}`);
|
|
703
|
+
}
|
|
704
|
+
} finally {
|
|
705
|
+
src.markInactive(this);
|
|
706
|
+
}
|
|
707
|
+
},
|
|
708
|
+
external: (sub) => {
|
|
709
|
+
try {
|
|
710
|
+
sub.onParticipantError(source, error);
|
|
711
|
+
} catch (error2) {
|
|
712
|
+
if (this.showLogs) {
|
|
713
|
+
console.warn(`[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
|
|
714
|
+
${JSON.stringify({ error: error2 }, null, 2)}`);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
712
717
|
}
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
};
|
|
716
|
-
|
|
717
|
-
// src/domain/agentic-environment/participants/human.ts
|
|
718
|
-
var Human = class extends Participant {
|
|
719
|
-
sendMessage(environment, message) {
|
|
720
|
-
if (!this.isJoinedTo(environment)) throw new Error("Not joined to environment");
|
|
721
|
-
environment.deliverMessage(this, message);
|
|
722
|
-
}
|
|
723
|
-
};
|
|
724
|
-
|
|
725
|
-
// src/application/participants/human.ts
|
|
726
|
-
var BaseHuman = class extends Human {
|
|
727
|
-
onJoined() {
|
|
728
|
-
}
|
|
729
|
-
onLeft() {
|
|
730
|
-
}
|
|
731
|
-
onParticipantJoined(participant) {
|
|
732
|
-
}
|
|
733
|
-
onParticipantLeft(participant) {
|
|
734
|
-
}
|
|
735
|
-
onMessage(message) {
|
|
736
|
-
}
|
|
737
|
-
onFunctionCall(item) {
|
|
738
|
-
}
|
|
739
|
-
onFunctionCallOutput(item) {
|
|
740
|
-
}
|
|
741
|
-
onReasoning(item) {
|
|
742
|
-
}
|
|
743
|
-
onModelMessage(item) {
|
|
744
|
-
}
|
|
745
|
-
onExternalFunctionCall(source, item) {
|
|
746
|
-
}
|
|
747
|
-
onExternalFunctionCallOutput(source, item) {
|
|
748
|
-
}
|
|
749
|
-
onExternalReasoning(source, item) {
|
|
750
|
-
}
|
|
751
|
-
onExternalModelMessage(source, item) {
|
|
752
|
-
}
|
|
753
|
-
onInternalEvent(item) {
|
|
754
|
-
}
|
|
755
|
-
onExternalEvent(source, item) {
|
|
756
|
-
}
|
|
757
|
-
};
|
|
758
|
-
|
|
759
|
-
// src/domain/generative-model/inference-request.ts
|
|
760
|
-
var InferenceRequest = class {
|
|
761
|
-
constructor(model, context) {
|
|
762
|
-
this.model = model;
|
|
763
|
-
this.context = context;
|
|
718
|
+
});
|
|
764
719
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
constructor(runtime) {
|
|
770
|
-
this.runtime = runtime;
|
|
720
|
+
getListeningParticipants(source) {
|
|
721
|
+
return this.subscribers.filter(
|
|
722
|
+
(sub) => sub !== source && (sub.getListeners().length === 0 || sub.getListeners().some((listener) => source instanceof listener))
|
|
723
|
+
);
|
|
771
724
|
}
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
725
|
+
deliverToSubscribers(source, handlers) {
|
|
726
|
+
var _a, _b;
|
|
727
|
+
const authorizedListeners = this.getListeningParticipants(source);
|
|
728
|
+
for (const subscriber of this.subscribers) {
|
|
729
|
+
const isActive = subscriber.getEnvironmentState(this);
|
|
730
|
+
if (isActive) {
|
|
731
|
+
try {
|
|
732
|
+
if (subscriber === source) {
|
|
733
|
+
(_a = handlers == null ? void 0 : handlers.internal) == null ? void 0 : _a.call(handlers, subscriber);
|
|
734
|
+
} else if (authorizedListeners.includes(subscriber)) {
|
|
735
|
+
(_b = handlers == null ? void 0 : handlers.external) == null ? void 0 : _b.call(handlers, subscriber);
|
|
736
|
+
}
|
|
737
|
+
} catch (error) {
|
|
738
|
+
this.handleError(subscriber, error);
|
|
739
|
+
}
|
|
782
740
|
}
|
|
783
|
-
yield item;
|
|
784
741
|
}
|
|
785
742
|
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
const tool = this.tools.find((t) => t.name === call.name);
|
|
798
|
-
if (!tool) throw new Error(`Unknown tool: ${call.name}`);
|
|
799
|
-
const result = await tool.invoke(JSON.parse(call.args));
|
|
800
|
-
yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
|
|
743
|
+
handleError(subscriber, error) {
|
|
744
|
+
if (error instanceof AgenticError) {
|
|
745
|
+
return this.deliverError(subscriber, error);
|
|
746
|
+
}
|
|
747
|
+
const agenticError = new AgenticError({
|
|
748
|
+
message: error.message,
|
|
749
|
+
stack: error.stack,
|
|
750
|
+
enviornment: this,
|
|
751
|
+
source: subscriber
|
|
752
|
+
});
|
|
753
|
+
return this.deliverError(subscriber, agenticError);
|
|
801
754
|
}
|
|
802
755
|
};
|
|
803
756
|
|
|
@@ -806,15 +759,18 @@ var Gpt55 = class {
|
|
|
806
759
|
constructor() {
|
|
807
760
|
this.specification = {
|
|
808
761
|
name: "gpt-5.5",
|
|
762
|
+
provider: "openai",
|
|
809
763
|
supportReasoningEffort: true,
|
|
810
764
|
defaultReasoningEffort: "none",
|
|
811
765
|
supportStreaming: true,
|
|
812
766
|
contextWindowSize: 105e4,
|
|
813
767
|
maxOutputTokens: 128e3,
|
|
814
|
-
supportFunctionCalling: true
|
|
768
|
+
supportFunctionCalling: true,
|
|
769
|
+
supportStructuredOutput: true
|
|
815
770
|
};
|
|
816
771
|
this.tools = [];
|
|
817
772
|
this.streaming = false;
|
|
773
|
+
this.structuredOutput = void 0;
|
|
818
774
|
this.effort = new OpenAIReasoningEffort(
|
|
819
775
|
this.specification.defaultReasoningEffort
|
|
820
776
|
);
|
|
@@ -837,47 +793,37 @@ var Gpt55 = class {
|
|
|
837
793
|
getReasoningEffort() {
|
|
838
794
|
return this.effort.getReasoningEffort();
|
|
839
795
|
}
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
// src/domain/agentic-environment/participants/observer.ts
|
|
843
|
-
var Observer = class extends Participant {
|
|
844
|
-
};
|
|
845
|
-
|
|
846
|
-
// src/application/participants/observer.ts
|
|
847
|
-
var BaseObserver = class extends Observer {
|
|
848
|
-
onFunctionCall(item) {
|
|
849
|
-
}
|
|
850
|
-
onExternalFunctionCall(source, item) {
|
|
851
|
-
}
|
|
852
|
-
onFunctionCallOutput(item) {
|
|
853
|
-
}
|
|
854
|
-
onExternalFunctionCallOutput(source, item) {
|
|
855
|
-
}
|
|
856
|
-
onReasoning(item) {
|
|
857
|
-
}
|
|
858
|
-
onExternalReasoning(source, item) {
|
|
859
|
-
}
|
|
860
|
-
onModelMessage(item) {
|
|
861
|
-
}
|
|
862
|
-
onExternalModelMessage(source, item) {
|
|
863
|
-
}
|
|
864
|
-
onMessage(message) {
|
|
865
|
-
}
|
|
866
|
-
onJoined() {
|
|
796
|
+
setStructuredOutput(format) {
|
|
797
|
+
this.structuredOutput = format;
|
|
867
798
|
}
|
|
868
|
-
|
|
799
|
+
getStructuredOutput() {
|
|
800
|
+
return this.structuredOutput;
|
|
869
801
|
}
|
|
870
|
-
|
|
802
|
+
hasStructuredOutput() {
|
|
803
|
+
return this.structuredOutput !== void 0;
|
|
871
804
|
}
|
|
872
|
-
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
// src/domain/model-context/semantic-event/semantic-event.ts
|
|
808
|
+
var SemanticEvent = class {
|
|
809
|
+
constructor(type, data) {
|
|
810
|
+
this.type = type;
|
|
811
|
+
this.data = data;
|
|
873
812
|
}
|
|
874
|
-
|
|
813
|
+
getType() {
|
|
814
|
+
return this.type;
|
|
875
815
|
}
|
|
876
|
-
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
// src/domain/agentic-environment/inference/request.ts
|
|
819
|
+
var InferenceRequest = class {
|
|
820
|
+
constructor(model, context) {
|
|
821
|
+
this.model = model;
|
|
822
|
+
this.context = context;
|
|
877
823
|
}
|
|
878
824
|
};
|
|
879
825
|
|
|
880
|
-
// src/domain/
|
|
826
|
+
// src/domain/agentic-environment/inference/response.ts
|
|
881
827
|
var InferenceResponse = class {
|
|
882
828
|
constructor(contextItems, tokenUsage) {
|
|
883
829
|
this.contextItems = contextItems;
|
|
@@ -913,6 +859,7 @@ var OpenAIResponses = class {
|
|
|
913
859
|
}
|
|
914
860
|
}
|
|
915
861
|
buildRequest(inferenceRequest) {
|
|
862
|
+
var _a, _b;
|
|
916
863
|
const specification = inferenceRequest.model.specification;
|
|
917
864
|
const input = this.mapContextToRequest(inferenceRequest.context);
|
|
918
865
|
const request = {
|
|
@@ -934,6 +881,20 @@ var OpenAIResponses = class {
|
|
|
934
881
|
effort: inferenceRequest.model.getReasoningEffort()
|
|
935
882
|
};
|
|
936
883
|
}
|
|
884
|
+
if (inferenceRequest.model.hasStructuredOutput()) {
|
|
885
|
+
if (!specification.supportStructuredOutput) {
|
|
886
|
+
throw new Error(`Structured output is not supported for model: ${specification.name}`);
|
|
887
|
+
}
|
|
888
|
+
const format = inferenceRequest.model.getStructuredOutput();
|
|
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
|
+
}
|
|
937
898
|
return request;
|
|
938
899
|
}
|
|
939
900
|
extractTokenUsage(response) {
|
|
@@ -977,6 +938,24 @@ var AnthropicMessages = class {
|
|
|
977
938
|
this.client = new import_sdk.default();
|
|
978
939
|
}
|
|
979
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);
|
|
945
|
+
}
|
|
946
|
+
async *stream(inferenceRequest, signal) {
|
|
947
|
+
const stream = await this.client.messages.create({
|
|
948
|
+
...this.buildRequest(inferenceRequest),
|
|
949
|
+
stream: true
|
|
950
|
+
});
|
|
951
|
+
for await (const event of stream) {
|
|
952
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
953
|
+
break;
|
|
954
|
+
}
|
|
955
|
+
yield new SemanticEvent(event.type, event);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
buildRequest(inferenceRequest) {
|
|
980
959
|
const { messages, system } = this.mapContextToRequest(inferenceRequest.context);
|
|
981
960
|
const specification = inferenceRequest.model.specification;
|
|
982
961
|
const request = {
|
|
@@ -1007,14 +986,23 @@ var AnthropicMessages = class {
|
|
|
1007
986
|
};
|
|
1008
987
|
}
|
|
1009
988
|
}
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
989
|
+
if (inferenceRequest.model.hasStructuredOutput()) {
|
|
990
|
+
if (!specification.supportStructuredOutput) {
|
|
991
|
+
throw new Error(`Structured output is not supported for model: ${specification.name}`);
|
|
992
|
+
}
|
|
993
|
+
const format = inferenceRequest.model.getStructuredOutput();
|
|
994
|
+
request.output_config = {
|
|
995
|
+
format: {
|
|
996
|
+
type: "json_schema",
|
|
997
|
+
json_schema: format.schema
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
return request;
|
|
1002
|
+
}
|
|
1003
|
+
extractTokenUsage(response) {
|
|
1004
|
+
var _a, _b;
|
|
1005
|
+
if (!response.usage) {
|
|
1018
1006
|
return void 0;
|
|
1019
1007
|
}
|
|
1020
1008
|
return new TokenUsage(
|
|
@@ -1130,20 +1118,73 @@ var AnthropicReasoningEffort = class {
|
|
|
1130
1118
|
}
|
|
1131
1119
|
};
|
|
1132
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
|
+
}
|
|
1169
|
+
};
|
|
1170
|
+
|
|
1133
1171
|
// src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
|
|
1134
1172
|
var ClaudeOpus47 = class {
|
|
1135
1173
|
constructor() {
|
|
1136
1174
|
this.specification = {
|
|
1137
1175
|
name: "claude-opus-4-7",
|
|
1176
|
+
provider: "anthropic",
|
|
1138
1177
|
supportReasoningEffort: true,
|
|
1139
1178
|
defaultReasoningEffort: "none",
|
|
1140
1179
|
supportStreaming: true,
|
|
1141
1180
|
contextWindowSize: 2e5,
|
|
1142
1181
|
maxOutputTokens: 32e3,
|
|
1143
|
-
supportFunctionCalling: true
|
|
1182
|
+
supportFunctionCalling: true,
|
|
1183
|
+
supportStructuredOutput: true
|
|
1144
1184
|
};
|
|
1145
1185
|
this.tools = [];
|
|
1146
1186
|
this.streaming = false;
|
|
1187
|
+
this.structuredOutput = void 0;
|
|
1147
1188
|
this.effort = new AnthropicReasoningEffort(
|
|
1148
1189
|
this.specification.defaultReasoningEffort
|
|
1149
1190
|
);
|
|
@@ -1166,6 +1207,15 @@ var ClaudeOpus47 = class {
|
|
|
1166
1207
|
getReasoningEffort() {
|
|
1167
1208
|
return this.effort.getReasoningEffort();
|
|
1168
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
|
+
}
|
|
1169
1219
|
};
|
|
1170
1220
|
|
|
1171
1221
|
// src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts
|
|
@@ -1173,15 +1223,18 @@ var ClaudeSonnet46 = class {
|
|
|
1173
1223
|
constructor() {
|
|
1174
1224
|
this.specification = {
|
|
1175
1225
|
name: "claude-sonnet-4-6",
|
|
1226
|
+
provider: "anthropic",
|
|
1176
1227
|
supportReasoningEffort: true,
|
|
1177
1228
|
defaultReasoningEffort: "none",
|
|
1178
1229
|
supportStreaming: true,
|
|
1179
1230
|
contextWindowSize: 2e5,
|
|
1180
1231
|
maxOutputTokens: 64e3,
|
|
1181
|
-
supportFunctionCalling: true
|
|
1232
|
+
supportFunctionCalling: true,
|
|
1233
|
+
supportStructuredOutput: true
|
|
1182
1234
|
};
|
|
1183
1235
|
this.tools = [];
|
|
1184
1236
|
this.streaming = false;
|
|
1237
|
+
this.structuredOutput = void 0;
|
|
1185
1238
|
this.effort = new AnthropicReasoningEffort(
|
|
1186
1239
|
this.specification.defaultReasoningEffort
|
|
1187
1240
|
);
|
|
@@ -1204,6 +1257,15 @@ var ClaudeSonnet46 = class {
|
|
|
1204
1257
|
getReasoningEffort() {
|
|
1205
1258
|
return this.effort.getReasoningEffort();
|
|
1206
1259
|
}
|
|
1260
|
+
setStructuredOutput(format) {
|
|
1261
|
+
this.structuredOutput = format;
|
|
1262
|
+
}
|
|
1263
|
+
getStructuredOutput() {
|
|
1264
|
+
return this.structuredOutput;
|
|
1265
|
+
}
|
|
1266
|
+
hasStructuredOutput() {
|
|
1267
|
+
return this.structuredOutput !== void 0;
|
|
1268
|
+
}
|
|
1207
1269
|
};
|
|
1208
1270
|
|
|
1209
1271
|
// src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts
|
|
@@ -1211,15 +1273,18 @@ var ClaudeHaiku45 = class {
|
|
|
1211
1273
|
constructor() {
|
|
1212
1274
|
this.specification = {
|
|
1213
1275
|
name: "claude-haiku-4-5",
|
|
1276
|
+
provider: "anthropic",
|
|
1214
1277
|
supportReasoningEffort: true,
|
|
1215
1278
|
defaultReasoningEffort: "none",
|
|
1216
1279
|
supportStreaming: true,
|
|
1217
1280
|
contextWindowSize: 2e5,
|
|
1218
1281
|
maxOutputTokens: 64e3,
|
|
1219
|
-
supportFunctionCalling: true
|
|
1282
|
+
supportFunctionCalling: true,
|
|
1283
|
+
supportStructuredOutput: true
|
|
1220
1284
|
};
|
|
1221
1285
|
this.tools = [];
|
|
1222
1286
|
this.streaming = false;
|
|
1287
|
+
this.structuredOutput = void 0;
|
|
1223
1288
|
this.effort = new AnthropicReasoningEffort(
|
|
1224
1289
|
this.specification.defaultReasoningEffort
|
|
1225
1290
|
);
|
|
@@ -1242,36 +1307,762 @@ var ClaudeHaiku45 = class {
|
|
|
1242
1307
|
getReasoningEffort() {
|
|
1243
1308
|
return this.effort.getReasoningEffort();
|
|
1244
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");
|
|
1332
|
+
}
|
|
1333
|
+
return this.reasoningEffort;
|
|
1334
|
+
}
|
|
1335
|
+
};
|
|
1336
|
+
|
|
1337
|
+
// src/infrastructure/providers/deepseek/models/deepseek-v4-flash.ts
|
|
1338
|
+
var DeepSeekV4Flash = class {
|
|
1339
|
+
constructor() {
|
|
1340
|
+
this.specification = {
|
|
1341
|
+
name: "deepseek-v4-flash",
|
|
1342
|
+
provider: "deepseek",
|
|
1343
|
+
supportReasoningEffort: true,
|
|
1344
|
+
defaultReasoningEffort: "high",
|
|
1345
|
+
supportStreaming: true,
|
|
1346
|
+
contextWindowSize: 1e6,
|
|
1347
|
+
maxOutputTokens: 384e3,
|
|
1348
|
+
supportFunctionCalling: true,
|
|
1349
|
+
supportStructuredOutput: false
|
|
1350
|
+
};
|
|
1351
|
+
this.tools = [];
|
|
1352
|
+
this.streaming = false;
|
|
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;
|
|
1378
|
+
}
|
|
1379
|
+
getStructuredOutput() {
|
|
1380
|
+
return this.structuredOutput;
|
|
1381
|
+
}
|
|
1382
|
+
hasStructuredOutput() {
|
|
1383
|
+
return this.structuredOutput !== void 0;
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
|
|
1387
|
+
// src/infrastructure/providers/deepseek/models/deepseek-v4-pro.ts
|
|
1388
|
+
var DeepSeekV4Pro = class {
|
|
1389
|
+
constructor() {
|
|
1390
|
+
this.specification = {
|
|
1391
|
+
name: "deepseek-v4-pro",
|
|
1392
|
+
provider: "deepseek",
|
|
1393
|
+
supportReasoningEffort: true,
|
|
1394
|
+
defaultReasoningEffort: "high",
|
|
1395
|
+
supportStreaming: true,
|
|
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
|
|
1406
|
+
);
|
|
1407
|
+
}
|
|
1408
|
+
setStreaming(streaming) {
|
|
1409
|
+
this.streaming = streaming;
|
|
1410
|
+
}
|
|
1411
|
+
getStreaming() {
|
|
1412
|
+
return this.streaming;
|
|
1413
|
+
}
|
|
1414
|
+
setTools(tools) {
|
|
1415
|
+
this.tools = tools;
|
|
1416
|
+
}
|
|
1417
|
+
getTools() {
|
|
1418
|
+
return this.tools;
|
|
1419
|
+
}
|
|
1420
|
+
setReasoningEffort(effort) {
|
|
1421
|
+
this.effort.setReasoningEffort(effort);
|
|
1422
|
+
}
|
|
1423
|
+
getReasoningEffort() {
|
|
1424
|
+
return this.effort.getReasoningEffort();
|
|
1425
|
+
}
|
|
1426
|
+
setStructuredOutput(format) {
|
|
1427
|
+
this.structuredOutput = format;
|
|
1428
|
+
}
|
|
1429
|
+
getStructuredOutput() {
|
|
1430
|
+
return this.structuredOutput;
|
|
1431
|
+
}
|
|
1432
|
+
hasStructuredOutput() {
|
|
1433
|
+
return this.structuredOutput !== void 0;
|
|
1434
|
+
}
|
|
1435
|
+
};
|
|
1436
|
+
|
|
1437
|
+
// src/infrastructure/providers/gemini/runtime/gemini-generate-content.ts
|
|
1438
|
+
var import_genai = require("@google/genai");
|
|
1439
|
+
var GeminiGenerateContent = class {
|
|
1440
|
+
constructor() {
|
|
1441
|
+
this.client = new import_genai.GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
|
|
1442
|
+
}
|
|
1443
|
+
async infer(inferenceRequest) {
|
|
1444
|
+
const response = await this.client.models.generateContent(this.buildRequest(inferenceRequest));
|
|
1445
|
+
const contextItems = this.extractContextItems(response);
|
|
1446
|
+
const tokenUsage = this.extractTokenUsage(response);
|
|
1447
|
+
return new InferenceResponse(contextItems, tokenUsage);
|
|
1448
|
+
}
|
|
1449
|
+
async *stream(inferenceRequest, signal) {
|
|
1450
|
+
const stream = await this.client.models.generateContentStream(this.buildRequest(inferenceRequest));
|
|
1451
|
+
for await (const chunk of stream) {
|
|
1452
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1453
|
+
break;
|
|
1454
|
+
}
|
|
1455
|
+
yield new SemanticEvent("generate_content_chunk", chunk);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
buildRequest(inferenceRequest) {
|
|
1459
|
+
const specification = inferenceRequest.model.specification;
|
|
1460
|
+
const { contents, systemInstruction } = this.mapContextToRequest(inferenceRequest.context);
|
|
1461
|
+
const config = {};
|
|
1462
|
+
if (systemInstruction) {
|
|
1463
|
+
config.systemInstruction = systemInstruction;
|
|
1464
|
+
}
|
|
1465
|
+
if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
|
|
1466
|
+
config.tools = [
|
|
1467
|
+
{
|
|
1468
|
+
functionDeclarations: inferenceRequest.model.getTools().map((tool) => {
|
|
1469
|
+
return {
|
|
1470
|
+
name: tool.name,
|
|
1471
|
+
description: tool.description,
|
|
1472
|
+
parametersJsonSchema: tool.parameters
|
|
1473
|
+
};
|
|
1474
|
+
})
|
|
1475
|
+
}
|
|
1476
|
+
];
|
|
1477
|
+
}
|
|
1478
|
+
if (specification.supportReasoningEffort) {
|
|
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();
|
|
1488
|
+
config.responseMimeType = "application/json";
|
|
1489
|
+
config.responseSchema = format.schema;
|
|
1490
|
+
}
|
|
1491
|
+
return { model: specification.name, contents, config };
|
|
1492
|
+
}
|
|
1493
|
+
extractTokenUsage(response) {
|
|
1494
|
+
var _a, _b, _c, _d, _e;
|
|
1495
|
+
const usage = response.usageMetadata;
|
|
1496
|
+
if (!usage) {
|
|
1497
|
+
return void 0;
|
|
1498
|
+
}
|
|
1499
|
+
return new TokenUsage(
|
|
1500
|
+
(_a = usage.promptTokenCount) != null ? _a : 0,
|
|
1501
|
+
(_b = usage.candidatesTokenCount) != null ? _b : 0,
|
|
1502
|
+
(_c = usage.totalTokenCount) != null ? _c : 0,
|
|
1503
|
+
new InputTokenDetails((_d = usage.cachedContentTokenCount) != null ? _d : 0),
|
|
1504
|
+
new OutputTokenDetails((_e = usage.thoughtsTokenCount) != null ? _e : 0)
|
|
1505
|
+
);
|
|
1506
|
+
}
|
|
1507
|
+
mapContextToRequest(context) {
|
|
1508
|
+
var _a;
|
|
1509
|
+
const contents = [];
|
|
1510
|
+
const system = [];
|
|
1511
|
+
const callNames = /* @__PURE__ */ new Map();
|
|
1512
|
+
for (const item of context.getItems()) {
|
|
1513
|
+
if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
|
|
1514
|
+
system.push(item.content.text);
|
|
1515
|
+
continue;
|
|
1516
|
+
}
|
|
1517
|
+
if (item instanceof UserMessageItem) {
|
|
1518
|
+
this.addPart(contents, "user", { text: item.content.text });
|
|
1519
|
+
continue;
|
|
1520
|
+
}
|
|
1521
|
+
if (item instanceof ModelMessageItem) {
|
|
1522
|
+
this.addPart(contents, "model", { text: item.content.text });
|
|
1523
|
+
continue;
|
|
1524
|
+
}
|
|
1525
|
+
if (item instanceof FunctionCallItem) {
|
|
1526
|
+
callNames.set(item.callId, item.name);
|
|
1527
|
+
let args;
|
|
1528
|
+
try {
|
|
1529
|
+
args = JSON.parse(item.args);
|
|
1530
|
+
} catch (e) {
|
|
1531
|
+
args = {};
|
|
1532
|
+
}
|
|
1533
|
+
this.addPart(contents, "model", { functionCall: { id: item.callId, name: item.name, args } });
|
|
1534
|
+
continue;
|
|
1535
|
+
}
|
|
1536
|
+
if (item instanceof FunctionCallOutputItem) {
|
|
1537
|
+
this.addPart(contents, "user", {
|
|
1538
|
+
functionResponse: {
|
|
1539
|
+
id: item.callId,
|
|
1540
|
+
name: (_a = callNames.get(item.callId)) != null ? _a : "",
|
|
1541
|
+
response: this.parseResponse(item.output.text)
|
|
1542
|
+
}
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
return {
|
|
1547
|
+
contents,
|
|
1548
|
+
systemInstruction: system.length > 0 ? system.join("\n\n") : void 0
|
|
1549
|
+
};
|
|
1550
|
+
}
|
|
1551
|
+
extractContextItems(response) {
|
|
1552
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1553
|
+
const items = [];
|
|
1554
|
+
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 : [];
|
|
1555
|
+
for (const part of parts) {
|
|
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
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
return items;
|
|
1581
|
+
}
|
|
1582
|
+
parseResponse(output) {
|
|
1583
|
+
try {
|
|
1584
|
+
const parsed = JSON.parse(output);
|
|
1585
|
+
return parsed && typeof parsed === "object" ? parsed : { output };
|
|
1586
|
+
} catch (e) {
|
|
1587
|
+
return { output };
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
addPart(contents, role, part) {
|
|
1591
|
+
const last = contents[contents.length - 1];
|
|
1592
|
+
if ((last == null ? void 0 : last.role) === role) {
|
|
1593
|
+
last.parts.push(part);
|
|
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");
|
|
1611
|
+
}
|
|
1612
|
+
return this.reasoningEffort;
|
|
1613
|
+
}
|
|
1614
|
+
};
|
|
1615
|
+
|
|
1616
|
+
// src/infrastructure/providers/gemini/models/gemini-3-5-flash.ts
|
|
1617
|
+
var Gemini35Flash = class {
|
|
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
|
|
1685
|
+
);
|
|
1686
|
+
}
|
|
1687
|
+
setStreaming(streaming) {
|
|
1688
|
+
this.streaming = streaming;
|
|
1689
|
+
}
|
|
1690
|
+
getStreaming() {
|
|
1691
|
+
return this.streaming;
|
|
1692
|
+
}
|
|
1693
|
+
setTools(tools) {
|
|
1694
|
+
this.tools = tools;
|
|
1695
|
+
}
|
|
1696
|
+
getTools() {
|
|
1697
|
+
return this.tools;
|
|
1698
|
+
}
|
|
1699
|
+
setReasoningEffort(effort) {
|
|
1700
|
+
this.effort.setReasoningEffort(effort);
|
|
1701
|
+
}
|
|
1702
|
+
getReasoningEffort() {
|
|
1703
|
+
return this.effort.getReasoningEffort();
|
|
1704
|
+
}
|
|
1705
|
+
setStructuredOutput(format) {
|
|
1706
|
+
this.structuredOutput = format;
|
|
1707
|
+
}
|
|
1708
|
+
getStructuredOutput() {
|
|
1709
|
+
return this.structuredOutput;
|
|
1710
|
+
}
|
|
1711
|
+
hasStructuredOutput() {
|
|
1712
|
+
return this.structuredOutput !== void 0;
|
|
1713
|
+
}
|
|
1714
|
+
};
|
|
1715
|
+
|
|
1716
|
+
// src/infrastructure/providers/openai/runtime/openai-chat-completions.ts
|
|
1717
|
+
var import_openai2 = __toESM(require("openai"));
|
|
1718
|
+
var OpenAIChatCompletions = class {
|
|
1719
|
+
constructor(config = {}) {
|
|
1720
|
+
var _a;
|
|
1721
|
+
this.client = new import_openai2.default({
|
|
1722
|
+
baseURL: config.baseURL,
|
|
1723
|
+
apiKey: config.apiKey
|
|
1724
|
+
});
|
|
1725
|
+
this.extraBody = (_a = config.extraBody) != null ? _a : {};
|
|
1726
|
+
}
|
|
1727
|
+
async infer(inferenceRequest) {
|
|
1728
|
+
const response = await this.client.chat.completions.create(this.buildRequest(inferenceRequest));
|
|
1729
|
+
const contextItems = this.extractContextItems(response);
|
|
1730
|
+
const tokenUsage = this.extractTokenUsage(response);
|
|
1731
|
+
return new InferenceResponse(contextItems, tokenUsage);
|
|
1732
|
+
}
|
|
1733
|
+
async *stream(inferenceRequest, signal) {
|
|
1734
|
+
var _a;
|
|
1735
|
+
const stream = await this.client.chat.completions.create({
|
|
1736
|
+
...this.buildRequest(inferenceRequest),
|
|
1737
|
+
stream: true
|
|
1738
|
+
});
|
|
1739
|
+
for await (const event of stream) {
|
|
1740
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1741
|
+
break;
|
|
1742
|
+
}
|
|
1743
|
+
yield new SemanticEvent((_a = event.object) != null ? _a : "chat.completion.chunk", event);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
buildRequest(inferenceRequest) {
|
|
1747
|
+
const specification = inferenceRequest.model.specification;
|
|
1748
|
+
const request = {
|
|
1749
|
+
...this.extraBody,
|
|
1750
|
+
model: specification.name,
|
|
1751
|
+
messages: this.mapContextToRequest(inferenceRequest.context)
|
|
1752
|
+
};
|
|
1753
|
+
if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
|
|
1754
|
+
request.tools = inferenceRequest.model.getTools().map((tool) => {
|
|
1755
|
+
return {
|
|
1756
|
+
type: "function",
|
|
1757
|
+
function: {
|
|
1758
|
+
name: tool.name,
|
|
1759
|
+
description: tool.description,
|
|
1760
|
+
parameters: tool.parameters
|
|
1761
|
+
}
|
|
1762
|
+
};
|
|
1763
|
+
});
|
|
1764
|
+
}
|
|
1765
|
+
if (specification.supportReasoningEffort) {
|
|
1766
|
+
request.reasoning_effort = inferenceRequest.model.getReasoningEffort();
|
|
1767
|
+
}
|
|
1768
|
+
return request;
|
|
1769
|
+
}
|
|
1770
|
+
extractTokenUsage(response) {
|
|
1771
|
+
var _a, _b, _c, _d;
|
|
1772
|
+
if (!response.usage) {
|
|
1773
|
+
return void 0;
|
|
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
|
+
);
|
|
1782
|
+
}
|
|
1783
|
+
mapContextToRequest(context) {
|
|
1784
|
+
var _a;
|
|
1785
|
+
const messages = [];
|
|
1786
|
+
for (const item of context.getItems()) {
|
|
1787
|
+
if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
|
|
1788
|
+
messages.push({ role: "system", content: item.content.text });
|
|
1789
|
+
continue;
|
|
1790
|
+
}
|
|
1791
|
+
if (item instanceof UserMessageItem) {
|
|
1792
|
+
messages.push({ role: "user", content: item.content.text });
|
|
1793
|
+
continue;
|
|
1794
|
+
}
|
|
1795
|
+
if (item instanceof ModelMessageItem) {
|
|
1796
|
+
messages.push({ role: "assistant", content: item.content.text });
|
|
1797
|
+
continue;
|
|
1798
|
+
}
|
|
1799
|
+
if (item instanceof FunctionCallItem) {
|
|
1800
|
+
const toolCall = {
|
|
1801
|
+
id: item.callId,
|
|
1802
|
+
type: "function",
|
|
1803
|
+
function: { name: item.name, arguments: item.args }
|
|
1804
|
+
};
|
|
1805
|
+
const last = messages[messages.length - 1];
|
|
1806
|
+
if ((last == null ? void 0 : last.role) === "assistant") {
|
|
1807
|
+
last.tool_calls = (_a = last.tool_calls) != null ? _a : [];
|
|
1808
|
+
last.tool_calls.push(toolCall);
|
|
1809
|
+
} else {
|
|
1810
|
+
messages.push({ role: "assistant", content: null, tool_calls: [toolCall] });
|
|
1811
|
+
}
|
|
1812
|
+
continue;
|
|
1813
|
+
}
|
|
1814
|
+
if (item instanceof FunctionCallOutputItem) {
|
|
1815
|
+
messages.push({ role: "tool", tool_call_id: item.callId, content: item.output.text });
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
return messages;
|
|
1819
|
+
}
|
|
1820
|
+
extractContextItems(response) {
|
|
1821
|
+
var _a, _b, _c;
|
|
1822
|
+
const items = [];
|
|
1823
|
+
const message = (_b = (_a = response.choices) == null ? void 0 : _a[0]) == null ? void 0 : _b.message;
|
|
1824
|
+
if (!message) {
|
|
1825
|
+
return items;
|
|
1826
|
+
}
|
|
1827
|
+
if (message.reasoning_content) {
|
|
1828
|
+
items.push(
|
|
1829
|
+
ReasoningItem.rehydrate({
|
|
1830
|
+
content: InputText.rehydrate({ text: message.reasoning_content }),
|
|
1831
|
+
encryptedContent: void 0,
|
|
1832
|
+
summary: []
|
|
1833
|
+
})
|
|
1834
|
+
);
|
|
1835
|
+
}
|
|
1836
|
+
if (message.content) {
|
|
1837
|
+
items.push(ModelMessageItem.rehydrate({ text: message.content }));
|
|
1838
|
+
}
|
|
1839
|
+
for (const toolCall of (_c = message.tool_calls) != null ? _c : []) {
|
|
1840
|
+
items.push(
|
|
1841
|
+
FunctionCallItem.rehydrate({
|
|
1842
|
+
callId: toolCall.id,
|
|
1843
|
+
name: toolCall.function.name,
|
|
1844
|
+
args: toolCall.function.arguments
|
|
1845
|
+
})
|
|
1846
|
+
);
|
|
1847
|
+
}
|
|
1848
|
+
return items;
|
|
1849
|
+
}
|
|
1850
|
+
};
|
|
1851
|
+
|
|
1852
|
+
// src/application/services/inference-runner.ts
|
|
1853
|
+
var InferenceRunner = class {
|
|
1854
|
+
async *run(context, modelInfo, signal) {
|
|
1855
|
+
const { model, endpoint } = modelInfo;
|
|
1856
|
+
const request = new InferenceRequest(model, context);
|
|
1857
|
+
if (model.getStreaming()) {
|
|
1858
|
+
yield* endpoint.stream(request);
|
|
1859
|
+
return;
|
|
1860
|
+
}
|
|
1861
|
+
const response = await endpoint.infer(request);
|
|
1862
|
+
for (const item of response.contextItems) {
|
|
1863
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1864
|
+
break;
|
|
1865
|
+
}
|
|
1866
|
+
yield item;
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
};
|
|
1870
|
+
|
|
1871
|
+
// src/application/use-cases/run-inference.ts
|
|
1872
|
+
var RunInference = class {
|
|
1873
|
+
constructor(modelRepository, inferenceRunner) {
|
|
1874
|
+
this.modelRepository = modelRepository;
|
|
1875
|
+
this.inferenceRunner = inferenceRunner;
|
|
1876
|
+
}
|
|
1877
|
+
setModelCapabilities(model, inferenceParams) {
|
|
1878
|
+
const { streaming, tools, reasoningEffort, structuredOutput } = inferenceParams;
|
|
1879
|
+
if (streaming) {
|
|
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;
|
|
1892
|
+
}
|
|
1893
|
+
async execute(inferenceParams) {
|
|
1894
|
+
const { model, context, caller, environment, signal } = inferenceParams;
|
|
1895
|
+
const modelInfo = this.modelRepository.getModelInfo(model);
|
|
1896
|
+
const generativeModel = this.setModelCapabilities(modelInfo.model, inferenceParams);
|
|
1897
|
+
modelInfo.model = generativeModel;
|
|
1898
|
+
const result = this.inferenceRunner.run(context, modelInfo, signal);
|
|
1899
|
+
for await (const item of result) {
|
|
1900
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1901
|
+
break;
|
|
1902
|
+
}
|
|
1903
|
+
if (item instanceof ReasoningItem) {
|
|
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
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
};
|
|
1915
|
+
|
|
1916
|
+
// src/application/use-cases/execute-function-call.ts
|
|
1917
|
+
var ExecuteFunctionCall = class {
|
|
1918
|
+
constructor(functionCallRunner) {
|
|
1919
|
+
this.functionCallRunner = functionCallRunner;
|
|
1920
|
+
}
|
|
1921
|
+
async execute(environment, functionCallItem, tool, caller, signal) {
|
|
1922
|
+
const stream = this.functionCallRunner.run(functionCallItem, tool, signal);
|
|
1923
|
+
for await (const item of stream) {
|
|
1924
|
+
environment.deliverFunctionCallOutput(caller, item);
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
};
|
|
1928
|
+
|
|
1929
|
+
// src/application/services/model-repository.ts
|
|
1930
|
+
var ModelRepository = class {
|
|
1931
|
+
getModelInfo(model) {
|
|
1932
|
+
switch (model) {
|
|
1933
|
+
case "gpt-5-4":
|
|
1934
|
+
return { endpoint: new OpenAIResponses(), model: new Gpt54() };
|
|
1935
|
+
case "gpt-5-4-mini":
|
|
1936
|
+
return { endpoint: new OpenAIResponses(), model: new Gpt54Mini() };
|
|
1937
|
+
case "gpt-5-4-nano":
|
|
1938
|
+
return { endpoint: new OpenAIResponses(), model: new Gpt54Nano() };
|
|
1939
|
+
case "gpt-5-5":
|
|
1940
|
+
return { endpoint: new OpenAIResponses(), model: new Gpt55() };
|
|
1941
|
+
case "claude-4-5-haiku":
|
|
1942
|
+
return { endpoint: new AnthropicMessages(), model: new ClaudeHaiku45() };
|
|
1943
|
+
case "claude-4-6-sonnet":
|
|
1944
|
+
return { endpoint: new AnthropicMessages(), model: new ClaudeSonnet46() };
|
|
1945
|
+
case "claude-4-7-opus":
|
|
1946
|
+
return { endpoint: new AnthropicMessages(), model: new ClaudeOpus47() };
|
|
1947
|
+
case "claude-4-8-opus":
|
|
1948
|
+
return { endpoint: new AnthropicMessages(), model: new ClaudeOpus48() };
|
|
1949
|
+
case "gemini-3-5-flash":
|
|
1950
|
+
return { endpoint: new GeminiGenerateContent(), model: new Gemini35Flash() };
|
|
1951
|
+
case "gemini-3-1-pro":
|
|
1952
|
+
return { endpoint: new GeminiGenerateContent(), model: new Gemini31Pro() };
|
|
1953
|
+
case "deepseek-v4-flash":
|
|
1954
|
+
return { endpoint: new OpenAIChatCompletions(), model: new DeepSeekV4Flash() };
|
|
1955
|
+
case "deepseek-v4-pro":
|
|
1956
|
+
return { endpoint: new OpenAIChatCompletions(), model: new DeepSeekV4Pro() };
|
|
1957
|
+
default:
|
|
1958
|
+
throw new Error(`Unsupported model: ${model}`);
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
};
|
|
1962
|
+
|
|
1963
|
+
// src/application/services/function-call-runner.ts
|
|
1964
|
+
var FunctionCallRunner = class {
|
|
1965
|
+
async *run(call, tool, signal) {
|
|
1966
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1967
|
+
return;
|
|
1968
|
+
}
|
|
1969
|
+
if (!tool) throw new Error(`Unknown tool: ${call.name}`);
|
|
1970
|
+
const result = await tool.invoke(JSON.parse(call.args));
|
|
1971
|
+
yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
|
|
1972
|
+
}
|
|
1973
|
+
};
|
|
1974
|
+
|
|
1975
|
+
// src/application/participants/participant.ts
|
|
1976
|
+
var BaseParticipant = class extends Participant {
|
|
1977
|
+
onFunctionCall(item) {
|
|
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) {
|
|
1992
|
+
}
|
|
1993
|
+
onMessage(message) {
|
|
1994
|
+
}
|
|
1995
|
+
onJoined() {
|
|
1996
|
+
}
|
|
1997
|
+
onLeft() {
|
|
1998
|
+
}
|
|
1999
|
+
onParticipantJoined(participant) {
|
|
2000
|
+
}
|
|
2001
|
+
onParticipantLeft(participant) {
|
|
2002
|
+
}
|
|
2003
|
+
onInternalEvent(item) {
|
|
2004
|
+
}
|
|
2005
|
+
onExternalEvent(source, item) {
|
|
2006
|
+
}
|
|
2007
|
+
onError(error) {
|
|
2008
|
+
}
|
|
2009
|
+
onParticipantError(source, error) {
|
|
2010
|
+
}
|
|
2011
|
+
};
|
|
2012
|
+
|
|
2013
|
+
// src/application/use-cases/send-message.ts
|
|
2014
|
+
var SendMessage = class {
|
|
2015
|
+
async execute(environment, message, caller) {
|
|
2016
|
+
if (!caller.isJoinedTo(environment)) {
|
|
2017
|
+
throw new Error("Not joined to environment");
|
|
2018
|
+
}
|
|
2019
|
+
environment.deliverMessage(caller, message);
|
|
2020
|
+
}
|
|
2021
|
+
};
|
|
2022
|
+
|
|
2023
|
+
// src/index.ts
|
|
2024
|
+
var runInferenceUseCase = new RunInference(new ModelRepository(), new InferenceRunner());
|
|
2025
|
+
var executeFunctionCallUseCase = new ExecuteFunctionCall(new FunctionCallRunner());
|
|
2026
|
+
var sendMessageUseCase = new SendMessage();
|
|
2027
|
+
var runInference = (inferenceParams) => {
|
|
2028
|
+
runInferenceUseCase.execute(inferenceParams);
|
|
2029
|
+
};
|
|
2030
|
+
var executeFunctionCall = (environment, functionCallItem, tool, caller) => {
|
|
2031
|
+
executeFunctionCallUseCase.execute(environment, functionCallItem, tool, caller);
|
|
2032
|
+
};
|
|
2033
|
+
var sendMessage = (environment, message, caller) => {
|
|
2034
|
+
sendMessageUseCase.execute(environment, message, caller);
|
|
1245
2035
|
};
|
|
1246
2036
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1247
2037
|
0 && (module.exports = {
|
|
1248
|
-
Agent,
|
|
1249
2038
|
AgenticEnvironment,
|
|
2039
|
+
AgenticError,
|
|
1250
2040
|
AnthropicMessages,
|
|
1251
|
-
|
|
1252
|
-
BaseHuman,
|
|
1253
|
-
BaseObserver,
|
|
2041
|
+
BaseParticipant,
|
|
1254
2042
|
ClaudeHaiku45,
|
|
1255
2043
|
ClaudeOpus47,
|
|
2044
|
+
ClaudeOpus48,
|
|
1256
2045
|
ClaudeSonnet46,
|
|
1257
2046
|
ContextItem,
|
|
1258
|
-
|
|
2047
|
+
DeepSeekV4Flash,
|
|
2048
|
+
DeepSeekV4Pro,
|
|
1259
2049
|
DeveloperMessageItem,
|
|
1260
2050
|
FunctionCallItem,
|
|
1261
2051
|
FunctionCallOutputItem,
|
|
2052
|
+
Gemini31Pro,
|
|
2053
|
+
Gemini35Flash,
|
|
2054
|
+
GeminiGenerateContent,
|
|
1262
2055
|
Gpt54,
|
|
1263
2056
|
Gpt54Mini,
|
|
1264
2057
|
Gpt54Nano,
|
|
1265
2058
|
Gpt55,
|
|
1266
|
-
Human,
|
|
1267
2059
|
InMemoryModelContextRepository,
|
|
1268
2060
|
InferenceRequest,
|
|
1269
2061
|
InferenceResponse,
|
|
1270
2062
|
InputTokenDetails,
|
|
1271
2063
|
ModelContext,
|
|
1272
2064
|
ModelMessageItem,
|
|
1273
|
-
|
|
1274
|
-
OpenAIInferenceRunner,
|
|
2065
|
+
OpenAIChatCompletions,
|
|
1275
2066
|
OpenAIResponses,
|
|
1276
2067
|
OutputTokenDetails,
|
|
1277
2068
|
Participant,
|
|
@@ -1279,6 +2070,9 @@ var ClaudeHaiku45 = class {
|
|
|
1279
2070
|
SemanticEvent,
|
|
1280
2071
|
SystemMessageItem,
|
|
1281
2072
|
TokenUsage,
|
|
1282
|
-
UserMessageItem
|
|
2073
|
+
UserMessageItem,
|
|
2074
|
+
executeFunctionCall,
|
|
2075
|
+
runInference,
|
|
2076
|
+
sendMessage
|
|
1283
2077
|
});
|
|
1284
2078
|
//# sourceMappingURL=index.js.map
|