@mozaik-ai/core 3.12.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/dist/index.js CHANGED
@@ -30,12 +30,10 @@ 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
- BaseAgent: () => BaseAgent,
37
- BaseHuman: () => BaseHuman,
38
- BaseObserver: () => BaseObserver,
36
+ BaseParticipant: () => BaseParticipant,
39
37
  ClaudeHaiku45: () => ClaudeHaiku45,
40
38
  ClaudeOpus47: () => ClaudeOpus47,
41
39
  ClaudeOpus48: () => ClaudeOpus48,
@@ -43,8 +41,6 @@ __export(index_exports, {
43
41
  ContextItem: () => ContextItem,
44
42
  DeepSeekV4Flash: () => DeepSeekV4Flash,
45
43
  DeepSeekV4Pro: () => DeepSeekV4Pro,
46
- DefaultFunctionCallRunner: () => DefaultFunctionCallRunner,
47
- DefaultInferenceRunner: () => DefaultInferenceRunner,
48
44
  DeveloperMessageItem: () => DeveloperMessageItem,
49
45
  FunctionCallItem: () => FunctionCallItem,
50
46
  FunctionCallOutputItem: () => FunctionCallOutputItem,
@@ -55,15 +51,13 @@ __export(index_exports, {
55
51
  Gpt54Mini: () => Gpt54Mini,
56
52
  Gpt54Nano: () => Gpt54Nano,
57
53
  Gpt55: () => Gpt55,
58
- Human: () => Human,
59
54
  InMemoryModelContextRepository: () => InMemoryModelContextRepository,
60
55
  InferenceRequest: () => InferenceRequest,
61
56
  InferenceResponse: () => InferenceResponse,
62
57
  InputTokenDetails: () => InputTokenDetails,
63
58
  ModelContext: () => ModelContext,
64
59
  ModelMessageItem: () => ModelMessageItem,
65
- Observer: () => Observer,
66
- OpenAICompatibleChatCompletions: () => OpenAICompatibleChatCompletions,
60
+ OpenAIChatCompletions: () => OpenAIChatCompletions,
67
61
  OpenAIResponses: () => OpenAIResponses,
68
62
  OutputTokenDetails: () => OutputTokenDetails,
69
63
  Participant: () => Participant,
@@ -71,7 +65,10 @@ __export(index_exports, {
71
65
  SemanticEvent: () => SemanticEvent,
72
66
  SystemMessageItem: () => SystemMessageItem,
73
67
  TokenUsage: () => TokenUsage,
74
- UserMessageItem: () => UserMessageItem
68
+ UserMessageItem: () => UserMessageItem,
69
+ executeFunctionCall: () => executeFunctionCall,
70
+ runInference: () => runInference,
71
+ sendMessage: () => sendMessage
75
72
  });
76
73
  module.exports = __toCommonJS(index_exports);
77
74
 
@@ -332,15 +329,18 @@ var Gpt54Nano = class {
332
329
  constructor() {
333
330
  this.specification = {
334
331
  name: "gpt-5.4-nano",
332
+ provider: "openai",
335
333
  supportReasoningEffort: true,
336
334
  defaultReasoningEffort: "none",
337
335
  supportStreaming: true,
338
336
  contextWindowSize: 4e5,
339
337
  maxOutputTokens: 128e3,
340
- supportFunctionCalling: true
338
+ supportFunctionCalling: true,
339
+ supportStructuredOutput: true
341
340
  };
342
341
  this.tools = [];
343
342
  this.streaming = false;
343
+ this.structuredOutput = void 0;
344
344
  this.effort = new OpenAIReasoningEffort(
345
345
  this.specification.defaultReasoningEffort
346
346
  );
@@ -363,6 +363,15 @@ var Gpt54Nano = class {
363
363
  getReasoningEffort() {
364
364
  return this.effort.getReasoningEffort();
365
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
+ }
366
375
  };
367
376
 
368
377
  // src/infrastructure/providers/openai/models/gpt-5-4.ts
@@ -370,15 +379,18 @@ var Gpt54 = class {
370
379
  constructor() {
371
380
  this.specification = {
372
381
  name: "gpt-5.4",
382
+ provider: "openai",
373
383
  supportReasoningEffort: true,
374
384
  defaultReasoningEffort: "none",
375
385
  supportStreaming: true,
376
386
  contextWindowSize: 105e4,
377
387
  maxOutputTokens: 128e3,
378
- supportFunctionCalling: true
388
+ supportFunctionCalling: true,
389
+ supportStructuredOutput: true
379
390
  };
380
391
  this.tools = [];
381
392
  this.streaming = false;
393
+ this.structuredOutput = void 0;
382
394
  this.effort = new OpenAIReasoningEffort(
383
395
  this.specification.defaultReasoningEffort
384
396
  );
@@ -401,6 +413,15 @@ var Gpt54 = class {
401
413
  getReasoningEffort() {
402
414
  return this.effort.getReasoningEffort();
403
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
+ }
404
425
  };
405
426
 
406
427
  // src/infrastructure/providers/openai/models/gpt-5-4-mini.ts
@@ -408,15 +429,18 @@ var Gpt54Mini = class {
408
429
  constructor() {
409
430
  this.specification = {
410
431
  name: "gpt-5.4-mini",
432
+ provider: "openai",
411
433
  supportReasoningEffort: true,
412
434
  defaultReasoningEffort: "none",
413
435
  supportStreaming: true,
414
436
  contextWindowSize: 4e5,
415
437
  maxOutputTokens: 128e3,
416
- supportFunctionCalling: true
438
+ supportFunctionCalling: true,
439
+ supportStructuredOutput: true
417
440
  };
418
441
  this.tools = [];
419
442
  this.streaming = false;
443
+ this.structuredOutput = void 0;
420
444
  this.effort = new OpenAIReasoningEffort(
421
445
  this.specification.defaultReasoningEffort
422
446
  );
@@ -439,6 +463,15 @@ var Gpt54Mini = class {
439
463
  getTools() {
440
464
  return this.tools;
441
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
+ }
442
475
  };
443
476
 
444
477
  // src/domain/generative-model/token-usage.ts
@@ -529,11 +562,12 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
529
562
  }
530
563
  };
531
564
 
532
- // src/domain/agentic-environment/participants/participant.ts
565
+ // src/domain/agentic-environment/participant.ts
533
566
  var Participant = class {
534
567
  constructor() {
535
568
  this.environments = [];
536
569
  this.listens = [];
570
+ this.active = /* @__PURE__ */ new Map();
537
571
  }
538
572
  join(environment) {
539
573
  if (this.isJoinedTo(environment)) {
@@ -541,6 +575,7 @@ var Participant = class {
541
575
  }
542
576
  environment.subscribe(this);
543
577
  this.environments.push(environment);
578
+ this.active.set(environment, true);
544
579
  }
545
580
  leave(environment) {
546
581
  if (!this.isJoinedTo(environment)) {
@@ -548,6 +583,7 @@ var Participant = class {
548
583
  }
549
584
  environment.unsubscribe(this);
550
585
  this.environments = this.environments.filter((e) => e !== environment);
586
+ this.active.delete(environment);
551
587
  }
552
588
  isJoinedTo(environment) {
553
589
  return this.environments.includes(environment);
@@ -558,14 +594,46 @@ var Participant = class {
558
594
  getListeners() {
559
595
  return this.listens;
560
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
+ }
561
627
  };
562
628
 
563
629
  // src/domain/agentic-environment/agentic-environment.ts
564
630
  var AgenticEnvironment = class {
565
- constructor(name) {
631
+ constructor(name, opts) {
566
632
  this.subscribers = [];
567
- this.isActive = false;
633
+ var _a;
568
634
  this.name = name;
635
+ this.options = opts;
636
+ this.showLogs = ((_a = this.options) == null ? void 0 : _a.silent) !== false;
569
637
  }
570
638
  subscribe(participant) {
571
639
  this.subscribers.push(participant);
@@ -623,6 +691,32 @@ var AgenticEnvironment = class {
623
691
  external: (sub) => sub.onExternalEvent(source, item)
624
692
  });
625
693
  }
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
+ }
717
+ }
718
+ });
719
+ }
626
720
  getListeningParticipants(source) {
627
721
  return this.subscribers.filter(
628
722
  (sub) => sub !== source && (sub.getListeners().length === 0 || sub.getListeners().some((listener) => source instanceof listener))
@@ -632,184 +726,31 @@ var AgenticEnvironment = class {
632
726
  var _a, _b;
633
727
  const authorizedListeners = this.getListeningParticipants(source);
634
728
  for (const subscriber of this.subscribers) {
635
- if (subscriber === source) {
636
- (_a = handlers == null ? void 0 : handlers.internal) == null ? void 0 : _a.call(handlers, subscriber);
637
- } else if (authorizedListeners.includes(subscriber)) {
638
- (_b = handlers == null ? void 0 : handlers.external) == null ? void 0 : _b.call(handlers, subscriber);
639
- }
640
- }
641
- }
642
- async start() {
643
- this.isActive = true;
644
- while (this.isActive) {
645
- await new Promise((resolve) => setTimeout(resolve, 100));
646
- }
647
- }
648
- stop() {
649
- this.isActive = false;
650
- }
651
- };
652
-
653
- // src/domain/agentic-environment/participants/agent.ts
654
- var Agent = class extends Participant {
655
- };
656
-
657
- // src/domain/model-context/semantic-event/semantic-event.ts
658
- var SemanticEvent = class {
659
- constructor(type, data) {
660
- this.type = type;
661
- this.data = data;
662
- }
663
- getType() {
664
- return this.type;
665
- }
666
- };
667
-
668
- // src/application/participants/agent.ts
669
- var BaseAgent = class extends Agent {
670
- constructor(inferenceRunner, functionCallRunner) {
671
- super();
672
- this.inferenceRunner = inferenceRunner;
673
- this.functionCallRunner = functionCallRunner;
674
- }
675
- onJoined() {
676
- }
677
- onLeft() {
678
- }
679
- onParticipantJoined(participant) {
680
- }
681
- onParticipantLeft(participant) {
682
- }
683
- onFunctionCall(item) {
684
- }
685
- onExternalFunctionCall(source, item) {
686
- }
687
- onFunctionCallOutput(item) {
688
- }
689
- onExternalFunctionCallOutput(source, item) {
690
- }
691
- onReasoning(item) {
692
- }
693
- onExternalReasoning(source, item) {
694
- }
695
- onModelMessage(item) {
696
- }
697
- onExternalModelMessage(source, item) {
698
- }
699
- onMessage(message) {
700
- }
701
- onInternalEvent(item) {
702
- }
703
- onExternalEvent(source, item) {
704
- }
705
- async executeFunctionCall(environment, functionCallItem, signal) {
706
- if (!this.isJoinedTo(environment)) return;
707
- const stream = this.functionCallRunner.run(functionCallItem, signal);
708
- for await (const item of stream) {
709
- environment.deliverFunctionCallOutput(this, item);
710
- }
711
- }
712
- async runInference(environment, context, model, signal) {
713
- if (!this.isJoinedTo(environment)) return;
714
- const stream = this.inferenceRunner.run(context, model, signal);
715
- for await (const item of stream) {
716
- if (item instanceof ReasoningItem) {
717
- environment.deliverReasoning(this, item);
718
- } else if (item instanceof FunctionCallItem) {
719
- environment.deliverFunctionCall(this, item);
720
- } else if (item instanceof ModelMessageItem) {
721
- environment.deliverModelMessage(this, item);
722
- } else if (item instanceof SemanticEvent) {
723
- environment.deliverSemanticEvent(this, item);
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
+ }
724
740
  }
725
741
  }
726
742
  }
727
- };
728
-
729
- // src/domain/agentic-environment/participants/human.ts
730
- var Human = class extends Participant {
731
- sendMessage(environment, message) {
732
- if (!this.isJoinedTo(environment)) throw new Error("Not joined to environment");
733
- environment.deliverMessage(this, message);
734
- }
735
- };
736
-
737
- // src/application/participants/human.ts
738
- var BaseHuman = class extends Human {
739
- onJoined() {
740
- }
741
- onLeft() {
742
- }
743
- onParticipantJoined(participant) {
744
- }
745
- onParticipantLeft(participant) {
746
- }
747
- onMessage(message) {
748
- }
749
- onFunctionCall(item) {
750
- }
751
- onFunctionCallOutput(item) {
752
- }
753
- onReasoning(item) {
754
- }
755
- onModelMessage(item) {
756
- }
757
- onExternalFunctionCall(source, item) {
758
- }
759
- onExternalFunctionCallOutput(source, item) {
760
- }
761
- onExternalReasoning(source, item) {
762
- }
763
- onExternalModelMessage(source, item) {
764
- }
765
- onInternalEvent(item) {
766
- }
767
- onExternalEvent(source, item) {
768
- }
769
- };
770
-
771
- // src/domain/generative-model/inference-request.ts
772
- var InferenceRequest = class {
773
- constructor(model, context) {
774
- this.model = model;
775
- this.context = context;
776
- }
777
- };
778
-
779
- // src/application/runners/inference-runner.ts
780
- var DefaultInferenceRunner = class {
781
- constructor(runtime) {
782
- this.runtime = runtime;
783
- }
784
- async *run(context, model, signal) {
785
- const request = new InferenceRequest(model, context);
786
- if (model.getStreaming() && this.isStreamingRuntime(this.runtime)) {
787
- yield* this.runtime.stream(request, signal);
788
- return;
789
- }
790
- const response = await this.runtime.infer(request);
791
- for (const item of response.contextItems) {
792
- if (signal == null ? void 0 : signal.aborted) {
793
- break;
794
- }
795
- yield item;
743
+ handleError(subscriber, error) {
744
+ if (error instanceof AgenticError) {
745
+ return this.deliverError(subscriber, error);
796
746
  }
797
- }
798
- isStreamingRuntime(runtime) {
799
- return typeof runtime.stream === "function";
800
- }
801
- };
802
-
803
- // src/application/runners/function-call-runner.ts
804
- var DefaultFunctionCallRunner = class {
805
- constructor(tools) {
806
- this.tools = tools;
807
- }
808
- async *run(call, signal) {
809
- const tool = this.tools.find((t) => t.name === call.name);
810
- if (!tool) throw new Error(`Unknown tool: ${call.name}`);
811
- const result = await tool.invoke(JSON.parse(call.args));
812
- yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
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);
813
754
  }
814
755
  };
815
756
 
@@ -818,15 +759,18 @@ var Gpt55 = class {
818
759
  constructor() {
819
760
  this.specification = {
820
761
  name: "gpt-5.5",
762
+ provider: "openai",
821
763
  supportReasoningEffort: true,
822
764
  defaultReasoningEffort: "none",
823
765
  supportStreaming: true,
824
766
  contextWindowSize: 105e4,
825
767
  maxOutputTokens: 128e3,
826
- supportFunctionCalling: true
768
+ supportFunctionCalling: true,
769
+ supportStructuredOutput: true
827
770
  };
828
771
  this.tools = [];
829
772
  this.streaming = false;
773
+ this.structuredOutput = void 0;
830
774
  this.effort = new OpenAIReasoningEffort(
831
775
  this.specification.defaultReasoningEffort
832
776
  );
@@ -849,47 +793,37 @@ var Gpt55 = class {
849
793
  getReasoningEffort() {
850
794
  return this.effort.getReasoningEffort();
851
795
  }
852
- };
853
-
854
- // src/domain/agentic-environment/participants/observer.ts
855
- var Observer = class extends Participant {
856
- };
857
-
858
- // src/application/participants/observer.ts
859
- var BaseObserver = class extends Observer {
860
- onFunctionCall(item) {
861
- }
862
- onExternalFunctionCall(source, item) {
863
- }
864
- onFunctionCallOutput(item) {
865
- }
866
- onExternalFunctionCallOutput(source, item) {
867
- }
868
- onReasoning(item) {
869
- }
870
- onExternalReasoning(source, item) {
871
- }
872
- onModelMessage(item) {
873
- }
874
- onExternalModelMessage(source, item) {
875
- }
876
- onMessage(message) {
877
- }
878
- onJoined() {
796
+ setStructuredOutput(format) {
797
+ this.structuredOutput = format;
879
798
  }
880
- onLeft() {
799
+ getStructuredOutput() {
800
+ return this.structuredOutput;
881
801
  }
882
- onParticipantJoined(participant) {
802
+ hasStructuredOutput() {
803
+ return this.structuredOutput !== void 0;
883
804
  }
884
- onParticipantLeft(participant) {
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;
885
812
  }
886
- onInternalEvent(item) {
813
+ getType() {
814
+ return this.type;
887
815
  }
888
- onExternalEvent(source, item) {
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;
889
823
  }
890
824
  };
891
825
 
892
- // src/domain/generative-model/inference-response.ts
826
+ // src/domain/agentic-environment/inference/response.ts
893
827
  var InferenceResponse = class {
894
828
  constructor(contextItems, tokenUsage) {
895
829
  this.contextItems = contextItems;
@@ -925,6 +859,7 @@ var OpenAIResponses = class {
925
859
  }
926
860
  }
927
861
  buildRequest(inferenceRequest) {
862
+ var _a, _b;
928
863
  const specification = inferenceRequest.model.specification;
929
864
  const input = this.mapContextToRequest(inferenceRequest.context);
930
865
  const request = {
@@ -946,6 +881,20 @@ var OpenAIResponses = class {
946
881
  effort: inferenceRequest.model.getReasoningEffort()
947
882
  };
948
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
+ }
949
898
  return request;
950
899
  }
951
900
  extractTokenUsage(response) {
@@ -982,142 +931,6 @@ var OpenAIResponses = class {
982
931
  }
983
932
  };
984
933
 
985
- // src/infrastructure/providers/openai/runtime/openai-compatible-chat-completions.ts
986
- var import_openai2 = __toESM(require("openai"));
987
- var OpenAICompatibleChatCompletions = class {
988
- constructor(config = {}) {
989
- var _a;
990
- this.client = new import_openai2.default({
991
- baseURL: config.baseURL,
992
- apiKey: config.apiKey
993
- });
994
- this.extraBody = (_a = config.extraBody) != null ? _a : {};
995
- }
996
- async infer(inferenceRequest) {
997
- const response = await this.client.chat.completions.create(this.buildRequest(inferenceRequest));
998
- const contextItems = this.extractContextItems(response);
999
- const tokenUsage = this.extractTokenUsage(response);
1000
- return new InferenceResponse(contextItems, tokenUsage);
1001
- }
1002
- async *stream(inferenceRequest, signal) {
1003
- var _a;
1004
- const stream = await this.client.chat.completions.create({
1005
- ...this.buildRequest(inferenceRequest),
1006
- stream: true
1007
- });
1008
- for await (const event of stream) {
1009
- if (signal == null ? void 0 : signal.aborted) {
1010
- break;
1011
- }
1012
- yield new SemanticEvent((_a = event.object) != null ? _a : "chat.completion.chunk", event);
1013
- }
1014
- }
1015
- buildRequest(inferenceRequest) {
1016
- const specification = inferenceRequest.model.specification;
1017
- const request = {
1018
- ...this.extraBody,
1019
- model: specification.name,
1020
- messages: this.mapContextToRequest(inferenceRequest.context)
1021
- };
1022
- if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
1023
- request.tools = inferenceRequest.model.getTools().map((tool) => {
1024
- return {
1025
- type: "function",
1026
- function: {
1027
- name: tool.name,
1028
- description: tool.description,
1029
- parameters: tool.parameters
1030
- }
1031
- };
1032
- });
1033
- }
1034
- if (specification.supportReasoningEffort) {
1035
- request.reasoning_effort = inferenceRequest.model.getReasoningEffort();
1036
- }
1037
- return request;
1038
- }
1039
- extractTokenUsage(response) {
1040
- var _a, _b, _c, _d;
1041
- if (!response.usage) {
1042
- return void 0;
1043
- }
1044
- return new TokenUsage(
1045
- response.usage.prompt_tokens,
1046
- response.usage.completion_tokens,
1047
- response.usage.total_tokens,
1048
- new InputTokenDetails((_b = (_a = response.usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
1049
- new OutputTokenDetails((_d = (_c = response.usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
1050
- );
1051
- }
1052
- mapContextToRequest(context) {
1053
- var _a;
1054
- const messages = [];
1055
- for (const item of context.getItems()) {
1056
- if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
1057
- messages.push({ role: "system", content: item.content.text });
1058
- continue;
1059
- }
1060
- if (item instanceof UserMessageItem) {
1061
- messages.push({ role: "user", content: item.content.text });
1062
- continue;
1063
- }
1064
- if (item instanceof ModelMessageItem) {
1065
- messages.push({ role: "assistant", content: item.content.text });
1066
- continue;
1067
- }
1068
- if (item instanceof FunctionCallItem) {
1069
- const toolCall = {
1070
- id: item.callId,
1071
- type: "function",
1072
- function: { name: item.name, arguments: item.args }
1073
- };
1074
- const last = messages[messages.length - 1];
1075
- if ((last == null ? void 0 : last.role) === "assistant") {
1076
- last.tool_calls = (_a = last.tool_calls) != null ? _a : [];
1077
- last.tool_calls.push(toolCall);
1078
- } else {
1079
- messages.push({ role: "assistant", content: null, tool_calls: [toolCall] });
1080
- }
1081
- continue;
1082
- }
1083
- if (item instanceof FunctionCallOutputItem) {
1084
- messages.push({ role: "tool", tool_call_id: item.callId, content: item.output.text });
1085
- }
1086
- }
1087
- return messages;
1088
- }
1089
- extractContextItems(response) {
1090
- var _a, _b, _c;
1091
- const items = [];
1092
- const message = (_b = (_a = response.choices) == null ? void 0 : _a[0]) == null ? void 0 : _b.message;
1093
- if (!message) {
1094
- return items;
1095
- }
1096
- if (message.reasoning_content) {
1097
- items.push(
1098
- ReasoningItem.rehydrate({
1099
- content: InputText.rehydrate({ text: message.reasoning_content }),
1100
- encryptedContent: void 0,
1101
- summary: []
1102
- })
1103
- );
1104
- }
1105
- if (message.content) {
1106
- items.push(ModelMessageItem.rehydrate({ text: message.content }));
1107
- }
1108
- for (const toolCall of (_c = message.tool_calls) != null ? _c : []) {
1109
- items.push(
1110
- FunctionCallItem.rehydrate({
1111
- callId: toolCall.id,
1112
- name: toolCall.function.name,
1113
- args: toolCall.function.arguments
1114
- })
1115
- );
1116
- }
1117
- return items;
1118
- }
1119
- };
1120
-
1121
934
  // src/infrastructure/providers/anthropic/runtime/anthropic-messages.ts
1122
935
  var import_sdk = __toESM(require("@anthropic-ai/sdk"));
1123
936
  var AnthropicMessages = class {
@@ -1173,6 +986,18 @@ var AnthropicMessages = class {
1173
986
  };
1174
987
  }
1175
988
  }
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
+ }
1176
1001
  return request;
1177
1002
  }
1178
1003
  extractTokenUsage(response) {
@@ -1298,15 +1123,18 @@ var ClaudeOpus48 = class {
1298
1123
  constructor() {
1299
1124
  this.specification = {
1300
1125
  name: "claude-opus-4-8",
1126
+ provider: "anthropic",
1301
1127
  supportReasoningEffort: true,
1302
1128
  defaultReasoningEffort: "none",
1303
1129
  supportStreaming: true,
1304
1130
  contextWindowSize: 2e5,
1305
1131
  maxOutputTokens: 32e3,
1306
- supportFunctionCalling: true
1132
+ supportFunctionCalling: true,
1133
+ supportStructuredOutput: true
1307
1134
  };
1308
1135
  this.tools = [];
1309
1136
  this.streaming = false;
1137
+ this.structuredOutput = void 0;
1310
1138
  this.effort = new AnthropicReasoningEffort(
1311
1139
  this.specification.defaultReasoningEffort
1312
1140
  );
@@ -1329,6 +1157,15 @@ var ClaudeOpus48 = class {
1329
1157
  getReasoningEffort() {
1330
1158
  return this.effort.getReasoningEffort();
1331
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
+ }
1332
1169
  };
1333
1170
 
1334
1171
  // src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
@@ -1336,15 +1173,18 @@ var ClaudeOpus47 = class {
1336
1173
  constructor() {
1337
1174
  this.specification = {
1338
1175
  name: "claude-opus-4-7",
1176
+ provider: "anthropic",
1339
1177
  supportReasoningEffort: true,
1340
1178
  defaultReasoningEffort: "none",
1341
1179
  supportStreaming: true,
1342
1180
  contextWindowSize: 2e5,
1343
1181
  maxOutputTokens: 32e3,
1344
- supportFunctionCalling: true
1182
+ supportFunctionCalling: true,
1183
+ supportStructuredOutput: true
1345
1184
  };
1346
1185
  this.tools = [];
1347
1186
  this.streaming = false;
1187
+ this.structuredOutput = void 0;
1348
1188
  this.effort = new AnthropicReasoningEffort(
1349
1189
  this.specification.defaultReasoningEffort
1350
1190
  );
@@ -1367,6 +1207,15 @@ var ClaudeOpus47 = class {
1367
1207
  getReasoningEffort() {
1368
1208
  return this.effort.getReasoningEffort();
1369
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
+ }
1370
1219
  };
1371
1220
 
1372
1221
  // src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts
@@ -1374,15 +1223,18 @@ var ClaudeSonnet46 = class {
1374
1223
  constructor() {
1375
1224
  this.specification = {
1376
1225
  name: "claude-sonnet-4-6",
1226
+ provider: "anthropic",
1377
1227
  supportReasoningEffort: true,
1378
1228
  defaultReasoningEffort: "none",
1379
1229
  supportStreaming: true,
1380
1230
  contextWindowSize: 2e5,
1381
1231
  maxOutputTokens: 64e3,
1382
- supportFunctionCalling: true
1232
+ supportFunctionCalling: true,
1233
+ supportStructuredOutput: true
1383
1234
  };
1384
1235
  this.tools = [];
1385
1236
  this.streaming = false;
1237
+ this.structuredOutput = void 0;
1386
1238
  this.effort = new AnthropicReasoningEffort(
1387
1239
  this.specification.defaultReasoningEffort
1388
1240
  );
@@ -1405,6 +1257,15 @@ var ClaudeSonnet46 = class {
1405
1257
  getReasoningEffort() {
1406
1258
  return this.effort.getReasoningEffort();
1407
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
+ }
1408
1269
  };
1409
1270
 
1410
1271
  // src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts
@@ -1412,15 +1273,18 @@ var ClaudeHaiku45 = class {
1412
1273
  constructor() {
1413
1274
  this.specification = {
1414
1275
  name: "claude-haiku-4-5",
1276
+ provider: "anthropic",
1415
1277
  supportReasoningEffort: true,
1416
1278
  defaultReasoningEffort: "none",
1417
1279
  supportStreaming: true,
1418
1280
  contextWindowSize: 2e5,
1419
1281
  maxOutputTokens: 64e3,
1420
- supportFunctionCalling: true
1282
+ supportFunctionCalling: true,
1283
+ supportStructuredOutput: true
1421
1284
  };
1422
1285
  this.tools = [];
1423
1286
  this.streaming = false;
1287
+ this.structuredOutput = void 0;
1424
1288
  this.effort = new AnthropicReasoningEffort(
1425
1289
  this.specification.defaultReasoningEffort
1426
1290
  );
@@ -1443,6 +1307,15 @@ var ClaudeHaiku45 = class {
1443
1307
  getReasoningEffort() {
1444
1308
  return this.effort.getReasoningEffort();
1445
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
+ }
1446
1319
  };
1447
1320
 
1448
1321
  // src/infrastructure/providers/deepseek/reasoning-effort.ts
@@ -1466,15 +1339,18 @@ var DeepSeekV4Flash = class {
1466
1339
  constructor() {
1467
1340
  this.specification = {
1468
1341
  name: "deepseek-v4-flash",
1342
+ provider: "deepseek",
1469
1343
  supportReasoningEffort: true,
1470
1344
  defaultReasoningEffort: "high",
1471
1345
  supportStreaming: true,
1472
1346
  contextWindowSize: 1e6,
1473
1347
  maxOutputTokens: 384e3,
1474
- supportFunctionCalling: true
1348
+ supportFunctionCalling: true,
1349
+ supportStructuredOutput: false
1475
1350
  };
1476
1351
  this.tools = [];
1477
1352
  this.streaming = false;
1353
+ this.structuredOutput = void 0;
1478
1354
  this.effort = new DeepSeekReasoningEffort(
1479
1355
  this.specification.defaultReasoningEffort
1480
1356
  );
@@ -1497,6 +1373,15 @@ var DeepSeekV4Flash = class {
1497
1373
  getReasoningEffort() {
1498
1374
  return this.effort.getReasoningEffort();
1499
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
+ }
1500
1385
  };
1501
1386
 
1502
1387
  // src/infrastructure/providers/deepseek/models/deepseek-v4-pro.ts
@@ -1504,15 +1389,18 @@ var DeepSeekV4Pro = class {
1504
1389
  constructor() {
1505
1390
  this.specification = {
1506
1391
  name: "deepseek-v4-pro",
1392
+ provider: "deepseek",
1507
1393
  supportReasoningEffort: true,
1508
1394
  defaultReasoningEffort: "high",
1509
1395
  supportStreaming: true,
1510
1396
  contextWindowSize: 1e6,
1511
1397
  maxOutputTokens: 384e3,
1512
- supportFunctionCalling: true
1398
+ supportFunctionCalling: true,
1399
+ supportStructuredOutput: false
1513
1400
  };
1514
1401
  this.tools = [];
1515
1402
  this.streaming = false;
1403
+ this.structuredOutput = void 0;
1516
1404
  this.effort = new DeepSeekReasoningEffort(
1517
1405
  this.specification.defaultReasoningEffort
1518
1406
  );
@@ -1535,6 +1423,15 @@ var DeepSeekV4Pro = class {
1535
1423
  getReasoningEffort() {
1536
1424
  return this.effort.getReasoningEffort();
1537
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
+ }
1538
1435
  };
1539
1436
 
1540
1437
  // src/infrastructure/providers/gemini/runtime/gemini-generate-content.ts
@@ -1583,6 +1480,14 @@ var GeminiGenerateContent = class {
1583
1480
  const thinkingLevel = effort === "none" ? "minimal" : effort;
1584
1481
  config.thinkingConfig = { thinkingLevel, includeThoughts: true };
1585
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
+ }
1586
1491
  return { model: specification.name, contents, config };
1587
1492
  }
1588
1493
  extractTokenUsage(response) {
@@ -1713,15 +1618,18 @@ var Gemini35Flash = class {
1713
1618
  constructor() {
1714
1619
  this.specification = {
1715
1620
  name: "gemini-3.5-flash",
1621
+ provider: "google",
1716
1622
  supportReasoningEffort: true,
1717
1623
  defaultReasoningEffort: "medium",
1718
1624
  supportStreaming: true,
1719
1625
  contextWindowSize: 1048576,
1720
1626
  maxOutputTokens: 64e3,
1721
- supportFunctionCalling: true
1627
+ supportFunctionCalling: true,
1628
+ supportStructuredOutput: true
1722
1629
  };
1723
1630
  this.tools = [];
1724
1631
  this.streaming = false;
1632
+ this.structuredOutput = void 0;
1725
1633
  this.effort = new GeminiReasoningEffort(
1726
1634
  this.specification.defaultReasoningEffort
1727
1635
  );
@@ -1744,6 +1652,15 @@ var Gemini35Flash = class {
1744
1652
  getReasoningEffort() {
1745
1653
  return this.effort.getReasoningEffort();
1746
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
+ }
1747
1664
  };
1748
1665
 
1749
1666
  // src/infrastructure/providers/gemini/models/gemini-3-1-pro.ts
@@ -1751,15 +1668,18 @@ var Gemini31Pro = class {
1751
1668
  constructor() {
1752
1669
  this.specification = {
1753
1670
  name: "gemini-3.1-pro-preview",
1671
+ provider: "google",
1754
1672
  supportReasoningEffort: true,
1755
1673
  defaultReasoningEffort: "high",
1756
1674
  supportStreaming: true,
1757
1675
  contextWindowSize: 1048576,
1758
1676
  maxOutputTokens: 64e3,
1759
- supportFunctionCalling: true
1677
+ supportFunctionCalling: true,
1678
+ supportStructuredOutput: true
1760
1679
  };
1761
1680
  this.tools = [];
1762
1681
  this.streaming = false;
1682
+ this.structuredOutput = void 0;
1763
1683
  this.effort = new GeminiReasoningEffort(
1764
1684
  this.specification.defaultReasoningEffort
1765
1685
  );
@@ -1782,15 +1702,343 @@ var Gemini31Pro = class {
1782
1702
  getReasoningEffort() {
1783
1703
  return this.effort.getReasoningEffort();
1784
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);
1785
2035
  };
1786
2036
  // Annotate the CommonJS export names for ESM import in node:
1787
2037
  0 && (module.exports = {
1788
- Agent,
1789
2038
  AgenticEnvironment,
2039
+ AgenticError,
1790
2040
  AnthropicMessages,
1791
- BaseAgent,
1792
- BaseHuman,
1793
- BaseObserver,
2041
+ BaseParticipant,
1794
2042
  ClaudeHaiku45,
1795
2043
  ClaudeOpus47,
1796
2044
  ClaudeOpus48,
@@ -1798,8 +2046,6 @@ var Gemini31Pro = class {
1798
2046
  ContextItem,
1799
2047
  DeepSeekV4Flash,
1800
2048
  DeepSeekV4Pro,
1801
- DefaultFunctionCallRunner,
1802
- DefaultInferenceRunner,
1803
2049
  DeveloperMessageItem,
1804
2050
  FunctionCallItem,
1805
2051
  FunctionCallOutputItem,
@@ -1810,15 +2056,13 @@ var Gemini31Pro = class {
1810
2056
  Gpt54Mini,
1811
2057
  Gpt54Nano,
1812
2058
  Gpt55,
1813
- Human,
1814
2059
  InMemoryModelContextRepository,
1815
2060
  InferenceRequest,
1816
2061
  InferenceResponse,
1817
2062
  InputTokenDetails,
1818
2063
  ModelContext,
1819
2064
  ModelMessageItem,
1820
- Observer,
1821
- OpenAICompatibleChatCompletions,
2065
+ OpenAIChatCompletions,
1822
2066
  OpenAIResponses,
1823
2067
  OutputTokenDetails,
1824
2068
  Participant,
@@ -1826,6 +2070,9 @@ var Gemini31Pro = class {
1826
2070
  SemanticEvent,
1827
2071
  SystemMessageItem,
1828
2072
  TokenUsage,
1829
- UserMessageItem
2073
+ UserMessageItem,
2074
+ executeFunctionCall,
2075
+ runInference,
2076
+ sendMessage
1830
2077
  });
1831
2078
  //# sourceMappingURL=index.js.map