@mozaik-ai/core 3.10.2 → 3.11.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.mjs CHANGED
@@ -485,24 +485,25 @@ var AgenticEnvironment = class {
485
485
  this.subscribers = [];
486
486
  this.isActive = false;
487
487
  }
488
- subscribe(subscriber) {
489
- this.subscribers.push(subscriber);
490
- for (const subscriber2 of this.subscribers) {
491
- if (subscriber2 === subscriber2) {
492
- subscriber2.onJoined();
488
+ subscribe(participant) {
489
+ this.subscribers.push(participant);
490
+ for (const subscriber of this.subscribers) {
491
+ if (participant === subscriber) {
492
+ participant.onJoined();
493
493
  } else {
494
- subscriber2.onParticipantJoined(subscriber2);
494
+ subscriber.onParticipantJoined(participant);
495
495
  }
496
496
  }
497
497
  }
498
- unsubscribe(subscriber) {
499
- this.subscribers = this.subscribers.filter((p) => p !== subscriber);
500
- for (const subscriber2 of this.subscribers) {
501
- if (subscriber2 === subscriber2) {
502
- subscriber2.onLeft();
503
- } else {
504
- subscriber2.onParticipantLeft(subscriber2);
505
- }
498
+ unsubscribe(participant) {
499
+ const exists = this.subscribers.includes(participant);
500
+ if (!exists) {
501
+ return;
502
+ }
503
+ participant.onLeft();
504
+ this.subscribers = this.subscribers.filter((p) => p !== participant);
505
+ for (const subscriber of this.subscribers) {
506
+ subscriber.onParticipantLeft(participant);
506
507
  }
507
508
  }
508
509
  deliverFunctionCall(source, item) {
@@ -685,19 +686,171 @@ var BaseHuman = class extends Human {
685
686
  }
686
687
  };
687
688
 
689
+ // src/domain/generative-model/inference-request.ts
690
+ var InferenceRequest = class {
691
+ constructor(model, context) {
692
+ this.model = model;
693
+ this.context = context;
694
+ }
695
+ };
696
+
688
697
  // src/application/runners/openai-inference-runner.ts
689
- import OpenAI from "openai";
690
698
  var OpenAIInferenceRunner = class {
699
+ constructor(runtime) {
700
+ this.runtime = runtime;
701
+ }
691
702
  async *run(context, model, signal) {
692
- const input = this.mapContextToRequest(context);
693
- const specification = model.specification;
694
- let request = {
703
+ const request = new InferenceRequest(model, context);
704
+ if (model.getStreaming() && this.isStreamingRuntime(this.runtime)) {
705
+ yield* this.runtime.stream(request, signal);
706
+ return;
707
+ }
708
+ const response = await this.runtime.infer(request);
709
+ for (const item of response.contextItems) {
710
+ if (signal == null ? void 0 : signal.aborted) {
711
+ break;
712
+ }
713
+ yield item;
714
+ }
715
+ }
716
+ isStreamingRuntime(runtime) {
717
+ return typeof runtime.stream === "function";
718
+ }
719
+ };
720
+
721
+ // src/application/runners/function-call-runner.ts
722
+ var DefaultFunctionCallRunner = class {
723
+ constructor(tools) {
724
+ this.tools = tools;
725
+ }
726
+ async *run(call, signal) {
727
+ const tool = this.tools.find((t) => t.name === call.name);
728
+ if (!tool) throw new Error(`Unknown tool: ${call.name}`);
729
+ const result = await tool.invoke(JSON.parse(call.args));
730
+ yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
731
+ }
732
+ };
733
+
734
+ // src/infrastructure/providers/openai/models/gpt-5-5.ts
735
+ var Gpt55 = class {
736
+ constructor() {
737
+ this.specification = {
738
+ name: "gpt-5.5",
739
+ supportReasoningEffort: true,
740
+ defaultReasoningEffort: "none",
741
+ supportStreaming: true,
742
+ contextWindowSize: 105e4,
743
+ maxOutputTokens: 128e3,
744
+ supportFunctionCalling: true
745
+ };
746
+ this.tools = [];
747
+ this.streaming = false;
748
+ this.effort = new OpenAIReasoningEffort(
749
+ this.specification.defaultReasoningEffort
750
+ );
751
+ }
752
+ setStreaming(streaming) {
753
+ this.streaming = streaming;
754
+ }
755
+ getStreaming() {
756
+ return this.streaming;
757
+ }
758
+ setTools(tools) {
759
+ this.tools = tools;
760
+ }
761
+ getTools() {
762
+ return this.tools;
763
+ }
764
+ setReasoningEffort(effort) {
765
+ this.effort.setReasoningEffort(effort);
766
+ }
767
+ getReasoningEffort() {
768
+ return this.effort.getReasoningEffort();
769
+ }
770
+ };
771
+
772
+ // src/domain/agentic-environment/participants/observer.ts
773
+ var Observer = class extends Participant {
774
+ };
775
+
776
+ // src/application/participants/observer.ts
777
+ var BaseObserver = class extends Observer {
778
+ onFunctionCall(item) {
779
+ }
780
+ onExternalFunctionCall(source, item) {
781
+ }
782
+ onFunctionCallOutput(item) {
783
+ }
784
+ onExternalFunctionCallOutput(source, item) {
785
+ }
786
+ onReasoning(item) {
787
+ }
788
+ onExternalReasoning(source, item) {
789
+ }
790
+ onModelMessage(item) {
791
+ }
792
+ onExternalModelMessage(source, item) {
793
+ }
794
+ onMessage(message) {
795
+ }
796
+ onJoined() {
797
+ }
798
+ onLeft() {
799
+ }
800
+ onParticipantJoined(participant) {
801
+ }
802
+ onParticipantLeft(participant) {
803
+ }
804
+ onInternalEvent(item) {
805
+ }
806
+ onExternalEvent(source, item) {
807
+ }
808
+ };
809
+
810
+ // src/domain/generative-model/inference-response.ts
811
+ var InferenceResponse = class {
812
+ constructor(contextItems, tokenUsage) {
813
+ this.contextItems = contextItems;
814
+ this.tokenUsage = tokenUsage;
815
+ }
816
+ };
817
+
818
+ // src/infrastructure/providers/openai/runtime/openai-responses.ts
819
+ import OpenAI from "openai";
820
+ var OpenAIResponses = class {
821
+ constructor() {
822
+ this.client = new OpenAI();
823
+ }
824
+ async infer(inferenceRequest) {
825
+ const request = this.buildRequest(inferenceRequest);
826
+ const response = await this.client.responses.create(request);
827
+ const contextItems = this.extractContextItems(response);
828
+ const tokenUsage = this.extractTokenUsage(response);
829
+ return new InferenceResponse(contextItems, tokenUsage);
830
+ }
831
+ async *stream(inferenceRequest, signal) {
832
+ const specification = inferenceRequest.model.specification;
833
+ if (!specification.supportStreaming) {
834
+ throw new Error("Streaming is not supported for this model");
835
+ }
836
+ const request = { ...this.buildRequest(inferenceRequest), stream: true };
837
+ const response = await this.client.responses.create(request);
838
+ for await (const event of response) {
839
+ if (signal == null ? void 0 : signal.aborted) {
840
+ break;
841
+ }
842
+ yield new SemanticEvent(event.type, event);
843
+ }
844
+ }
845
+ buildRequest(inferenceRequest) {
846
+ const specification = inferenceRequest.model.specification;
847
+ const input = this.mapContextToRequest(inferenceRequest.context);
848
+ const request = {
695
849
  model: specification.name,
696
- input,
697
- stream: model.getStreaming()
850
+ input
698
851
  };
699
- if (specification.supportFunctionCalling && model.getTools().length > 0) {
700
- request.tools = model.getTools().map((tool) => {
852
+ if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
853
+ request.tools = inferenceRequest.model.getTools().map((tool) => {
701
854
  return {
702
855
  type: tool.type,
703
856
  name: tool.name,
@@ -708,31 +861,10 @@ var OpenAIInferenceRunner = class {
708
861
  }
709
862
  if (specification.supportReasoningEffort) {
710
863
  request.reasoning = {
711
- effort: model.getReasoningEffort()
864
+ effort: inferenceRequest.model.getReasoningEffort()
712
865
  };
713
866
  }
714
- if (!specification.supportStreaming && model.getStreaming()) {
715
- throw new Error("Streaming is not supported for this model");
716
- }
717
- const openai = new OpenAI();
718
- const response = await openai.responses.create(request);
719
- if (specification.supportStreaming && model.getStreaming()) {
720
- for await (const event of response) {
721
- if (signal == null ? void 0 : signal.aborted) {
722
- break;
723
- }
724
- yield new SemanticEvent(event.type, event);
725
- }
726
- } else {
727
- const contextItems = this.extractContextItems(response);
728
- const tokenUsage = this.extractTokenUsage(response);
729
- for (const item of contextItems) {
730
- if (signal == null ? void 0 : signal.aborted) {
731
- break;
732
- }
733
- yield item;
734
- }
735
- }
867
+ return request;
736
868
  }
737
869
  extractTokenUsage(response) {
738
870
  if (!response.usage) {
@@ -768,34 +900,181 @@ var OpenAIInferenceRunner = class {
768
900
  }
769
901
  };
770
902
 
771
- // src/application/runners/function-call-runner.ts
772
- var DefaultFunctionCallRunner = class {
773
- constructor(tools) {
774
- this.tools = tools;
903
+ // src/infrastructure/providers/anthropic/runtime/anthropic-messages.ts
904
+ import Anthropic from "@anthropic-ai/sdk";
905
+ var AnthropicMessages = class {
906
+ constructor() {
907
+ this.client = new Anthropic();
775
908
  }
776
- async *run(call, signal) {
777
- const tool = this.tools.find((t) => t.name === call.name);
778
- if (!tool) throw new Error(`Unknown tool: ${call.name}`);
779
- const result = await tool.invoke(JSON.parse(call.args));
780
- yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
909
+ async infer(inferenceRequest) {
910
+ const { messages, system } = this.mapContextToRequest(inferenceRequest.context);
911
+ const specification = inferenceRequest.model.specification;
912
+ const request = {
913
+ model: specification.name,
914
+ max_tokens: specification.maxOutputTokens,
915
+ messages
916
+ };
917
+ if (system) {
918
+ request.system = system;
919
+ }
920
+ if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
921
+ request.tools = inferenceRequest.model.getTools().map((tool) => {
922
+ return {
923
+ name: tool.name,
924
+ description: tool.description,
925
+ input_schema: tool.parameters
926
+ };
927
+ });
928
+ }
929
+ if (specification.supportReasoningEffort) {
930
+ const effort = inferenceRequest.model.getReasoningEffort();
931
+ const budgets = { low: 1024, medium: 4096, high: 8192 };
932
+ const budget = budgets[effort];
933
+ if (budget !== void 0) {
934
+ request.thinking = {
935
+ type: "enabled",
936
+ budget_tokens: Math.min(budget, specification.maxOutputTokens - 1)
937
+ };
938
+ }
939
+ }
940
+ const response = await this.client.messages.create(request);
941
+ const contextItems = this.extractContextItems(response);
942
+ const tokenUsage = this.extractTokenUsage(response);
943
+ return new InferenceResponse(contextItems, tokenUsage);
944
+ }
945
+ extractTokenUsage(response) {
946
+ var _a, _b;
947
+ if (!response.usage) {
948
+ return void 0;
949
+ }
950
+ return new TokenUsage(
951
+ response.usage.input_tokens,
952
+ response.usage.output_tokens,
953
+ response.usage.input_tokens + response.usage.output_tokens,
954
+ new InputTokenDetails(
955
+ ((_a = response.usage.cache_creation_input_tokens) != null ? _a : 0) + ((_b = response.usage.cache_read_input_tokens) != null ? _b : 0)
956
+ ),
957
+ new OutputTokenDetails(0)
958
+ );
959
+ }
960
+ mapContextToRequest(context) {
961
+ const messages = [];
962
+ const system = [];
963
+ for (const item of context.getItems()) {
964
+ if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
965
+ system.push(item.content.text);
966
+ continue;
967
+ }
968
+ if (item instanceof UserMessageItem) {
969
+ this.addContentBlock(messages, "user", { type: "text", text: item.content.text });
970
+ continue;
971
+ }
972
+ if (item instanceof ModelMessageItem) {
973
+ this.addContentBlock(messages, "assistant", { type: "text", text: item.content.text });
974
+ continue;
975
+ }
976
+ if (item instanceof FunctionCallItem) {
977
+ let input;
978
+ try {
979
+ input = JSON.parse(item.args);
980
+ } catch (e) {
981
+ input = item.args;
982
+ }
983
+ this.addContentBlock(messages, "assistant", {
984
+ type: "tool_use",
985
+ id: item.callId,
986
+ name: item.name,
987
+ input
988
+ });
989
+ continue;
990
+ }
991
+ if (item instanceof FunctionCallOutputItem) {
992
+ this.addContentBlock(messages, "user", {
993
+ type: "tool_result",
994
+ tool_use_id: item.callId,
995
+ content: item.output.text
996
+ });
997
+ }
998
+ }
999
+ return {
1000
+ messages,
1001
+ system: system.length > 0 ? system.join("\n\n") : void 0
1002
+ };
1003
+ }
1004
+ extractContextItems(response) {
1005
+ var _a;
1006
+ const items = [];
1007
+ for (const block of response.content) {
1008
+ if (block.type === "text") {
1009
+ items.push(ModelMessageItem.rehydrate({ text: block.text }));
1010
+ continue;
1011
+ }
1012
+ if (block.type === "tool_use") {
1013
+ items.push(
1014
+ FunctionCallItem.rehydrate({
1015
+ callId: block.id,
1016
+ name: block.name,
1017
+ args: JSON.stringify((_a = block.input) != null ? _a : {})
1018
+ })
1019
+ );
1020
+ continue;
1021
+ }
1022
+ if (block.type === "thinking") {
1023
+ items.push(
1024
+ ReasoningItem.rehydrate({
1025
+ content: block.thinking ? InputText.rehydrate({ text: block.thinking }) : void 0,
1026
+ encryptedContent: void 0,
1027
+ summary: []
1028
+ })
1029
+ );
1030
+ }
1031
+ }
1032
+ return items;
1033
+ }
1034
+ addContentBlock(messages, role, block) {
1035
+ const lastMessage = messages[messages.length - 1];
1036
+ if ((lastMessage == null ? void 0 : lastMessage.role) === role) {
1037
+ lastMessage.content.push(block);
1038
+ return;
1039
+ }
1040
+ messages.push({
1041
+ role,
1042
+ content: [block]
1043
+ });
781
1044
  }
782
1045
  };
783
1046
 
784
- // src/infrastructure/providers/openai/models/gpt-5-5.ts
785
- var Gpt55 = class {
1047
+ // src/infrastructure/providers/anthropic/reasoning-effort.ts
1048
+ var AnthropicReasoningEffort = class {
1049
+ constructor(reasoningEffort) {
1050
+ this.reasoningEffort = reasoningEffort;
1051
+ }
1052
+ setReasoningEffort(effort) {
1053
+ this.reasoningEffort = effort;
1054
+ }
1055
+ getReasoningEffort() {
1056
+ if (!this.reasoningEffort) {
1057
+ throw new Error("Reasoning effort not supported");
1058
+ }
1059
+ return this.reasoningEffort;
1060
+ }
1061
+ };
1062
+
1063
+ // src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
1064
+ var ClaudeOpus47 = class {
786
1065
  constructor() {
787
1066
  this.specification = {
788
- name: "gpt-5.5",
1067
+ name: "claude-opus-4-7",
789
1068
  supportReasoningEffort: true,
790
1069
  defaultReasoningEffort: "none",
791
1070
  supportStreaming: true,
792
- contextWindowSize: 105e4,
793
- maxOutputTokens: 128e3,
1071
+ contextWindowSize: 2e5,
1072
+ maxOutputTokens: 32e3,
794
1073
  supportFunctionCalling: true
795
1074
  };
796
1075
  this.tools = [];
797
1076
  this.streaming = false;
798
- this.effort = new OpenAIReasoningEffort(
1077
+ this.effort = new AnthropicReasoningEffort(
799
1078
  this.specification.defaultReasoningEffort
800
1079
  );
801
1080
  }
@@ -819,49 +1098,91 @@ var Gpt55 = class {
819
1098
  }
820
1099
  };
821
1100
 
822
- // src/domain/agentic-environment/participants/observer.ts
823
- var Observer = class extends Participant {
824
- };
825
-
826
- // src/application/participants/observer.ts
827
- var BaseObserver = class extends Observer {
828
- onFunctionCall(item) {
829
- }
830
- onExternalFunctionCall(source, item) {
1101
+ // src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts
1102
+ var ClaudeSonnet46 = class {
1103
+ constructor() {
1104
+ this.specification = {
1105
+ name: "claude-sonnet-4-6",
1106
+ supportReasoningEffort: true,
1107
+ defaultReasoningEffort: "none",
1108
+ supportStreaming: true,
1109
+ contextWindowSize: 2e5,
1110
+ maxOutputTokens: 64e3,
1111
+ supportFunctionCalling: true
1112
+ };
1113
+ this.tools = [];
1114
+ this.streaming = false;
1115
+ this.effort = new AnthropicReasoningEffort(
1116
+ this.specification.defaultReasoningEffort
1117
+ );
831
1118
  }
832
- onFunctionCallOutput(item) {
1119
+ setStreaming(streaming) {
1120
+ this.streaming = streaming;
833
1121
  }
834
- onExternalFunctionCallOutput(source, item) {
1122
+ getStreaming() {
1123
+ return this.streaming;
835
1124
  }
836
- onReasoning(item) {
1125
+ setTools(tools) {
1126
+ this.tools = tools;
837
1127
  }
838
- onExternalReasoning(source, item) {
1128
+ getTools() {
1129
+ return this.tools;
839
1130
  }
840
- onModelMessage(item) {
1131
+ setReasoningEffort(effort) {
1132
+ this.effort.setReasoningEffort(effort);
841
1133
  }
842
- onExternalModelMessage(source, item) {
1134
+ getReasoningEffort() {
1135
+ return this.effort.getReasoningEffort();
843
1136
  }
844
- onMessage(message) {
1137
+ };
1138
+
1139
+ // src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts
1140
+ var ClaudeHaiku45 = class {
1141
+ constructor() {
1142
+ this.specification = {
1143
+ name: "claude-haiku-4-5",
1144
+ supportReasoningEffort: true,
1145
+ defaultReasoningEffort: "none",
1146
+ supportStreaming: true,
1147
+ contextWindowSize: 2e5,
1148
+ maxOutputTokens: 64e3,
1149
+ supportFunctionCalling: true
1150
+ };
1151
+ this.tools = [];
1152
+ this.streaming = false;
1153
+ this.effort = new AnthropicReasoningEffort(
1154
+ this.specification.defaultReasoningEffort
1155
+ );
845
1156
  }
846
- onJoined() {
1157
+ setStreaming(streaming) {
1158
+ this.streaming = streaming;
847
1159
  }
848
- onLeft() {
1160
+ getStreaming() {
1161
+ return this.streaming;
849
1162
  }
850
- onParticipantJoined(participant) {
1163
+ setTools(tools) {
1164
+ this.tools = tools;
851
1165
  }
852
- onParticipantLeft(participant) {
1166
+ getTools() {
1167
+ return this.tools;
853
1168
  }
854
- onInternalEvent(item) {
1169
+ setReasoningEffort(effort) {
1170
+ this.effort.setReasoningEffort(effort);
855
1171
  }
856
- onExternalEvent(source, item) {
1172
+ getReasoningEffort() {
1173
+ return this.effort.getReasoningEffort();
857
1174
  }
858
1175
  };
859
1176
  export {
860
1177
  Agent,
861
1178
  AgenticEnvironment,
1179
+ AnthropicMessages,
862
1180
  BaseAgent,
863
1181
  BaseHuman,
864
1182
  BaseObserver,
1183
+ ClaudeHaiku45,
1184
+ ClaudeOpus47,
1185
+ ClaudeSonnet46,
865
1186
  ContextItem,
866
1187
  DefaultFunctionCallRunner,
867
1188
  DeveloperMessageItem,
@@ -873,11 +1194,14 @@ export {
873
1194
  Gpt55,
874
1195
  Human,
875
1196
  InMemoryModelContextRepository,
1197
+ InferenceRequest,
1198
+ InferenceResponse,
876
1199
  InputTokenDetails,
877
1200
  ModelContext,
878
1201
  ModelMessageItem,
879
1202
  Observer,
880
1203
  OpenAIInferenceRunner,
1204
+ OpenAIResponses,
881
1205
  OutputTokenDetails,
882
1206
  Participant,
883
1207
  ReasoningItem,