@mozaik-ai/core 3.10.3 → 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
@@ -686,19 +686,171 @@ var BaseHuman = class extends Human {
686
686
  }
687
687
  };
688
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
+
689
697
  // src/application/runners/openai-inference-runner.ts
690
- import OpenAI from "openai";
691
698
  var OpenAIInferenceRunner = class {
699
+ constructor(runtime) {
700
+ this.runtime = runtime;
701
+ }
692
702
  async *run(context, model, signal) {
693
- const input = this.mapContextToRequest(context);
694
- const specification = model.specification;
695
- 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 = {
696
849
  model: specification.name,
697
- input,
698
- stream: model.getStreaming()
850
+ input
699
851
  };
700
- if (specification.supportFunctionCalling && model.getTools().length > 0) {
701
- request.tools = model.getTools().map((tool) => {
852
+ if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
853
+ request.tools = inferenceRequest.model.getTools().map((tool) => {
702
854
  return {
703
855
  type: tool.type,
704
856
  name: tool.name,
@@ -709,31 +861,10 @@ var OpenAIInferenceRunner = class {
709
861
  }
710
862
  if (specification.supportReasoningEffort) {
711
863
  request.reasoning = {
712
- effort: model.getReasoningEffort()
864
+ effort: inferenceRequest.model.getReasoningEffort()
713
865
  };
714
866
  }
715
- if (!specification.supportStreaming && model.getStreaming()) {
716
- throw new Error("Streaming is not supported for this model");
717
- }
718
- const openai = new OpenAI();
719
- const response = await openai.responses.create(request);
720
- if (specification.supportStreaming && model.getStreaming()) {
721
- for await (const event of response) {
722
- if (signal == null ? void 0 : signal.aborted) {
723
- break;
724
- }
725
- yield new SemanticEvent(event.type, event);
726
- }
727
- } else {
728
- const contextItems = this.extractContextItems(response);
729
- const tokenUsage = this.extractTokenUsage(response);
730
- for (const item of contextItems) {
731
- if (signal == null ? void 0 : signal.aborted) {
732
- break;
733
- }
734
- yield item;
735
- }
736
- }
867
+ return request;
737
868
  }
738
869
  extractTokenUsage(response) {
739
870
  if (!response.usage) {
@@ -769,34 +900,181 @@ var OpenAIInferenceRunner = class {
769
900
  }
770
901
  };
771
902
 
772
- // src/application/runners/function-call-runner.ts
773
- var DefaultFunctionCallRunner = class {
774
- constructor(tools) {
775
- 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();
776
908
  }
777
- async *run(call, signal) {
778
- const tool = this.tools.find((t) => t.name === call.name);
779
- if (!tool) throw new Error(`Unknown tool: ${call.name}`);
780
- const result = await tool.invoke(JSON.parse(call.args));
781
- 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
+ });
782
1044
  }
783
1045
  };
784
1046
 
785
- // src/infrastructure/providers/openai/models/gpt-5-5.ts
786
- 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 {
787
1065
  constructor() {
788
1066
  this.specification = {
789
- name: "gpt-5.5",
1067
+ name: "claude-opus-4-7",
790
1068
  supportReasoningEffort: true,
791
1069
  defaultReasoningEffort: "none",
792
1070
  supportStreaming: true,
793
- contextWindowSize: 105e4,
794
- maxOutputTokens: 128e3,
1071
+ contextWindowSize: 2e5,
1072
+ maxOutputTokens: 32e3,
795
1073
  supportFunctionCalling: true
796
1074
  };
797
1075
  this.tools = [];
798
1076
  this.streaming = false;
799
- this.effort = new OpenAIReasoningEffort(
1077
+ this.effort = new AnthropicReasoningEffort(
800
1078
  this.specification.defaultReasoningEffort
801
1079
  );
802
1080
  }
@@ -820,49 +1098,91 @@ var Gpt55 = class {
820
1098
  }
821
1099
  };
822
1100
 
823
- // src/domain/agentic-environment/participants/observer.ts
824
- var Observer = class extends Participant {
825
- };
826
-
827
- // src/application/participants/observer.ts
828
- var BaseObserver = class extends Observer {
829
- onFunctionCall(item) {
830
- }
831
- 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
+ );
832
1118
  }
833
- onFunctionCallOutput(item) {
1119
+ setStreaming(streaming) {
1120
+ this.streaming = streaming;
834
1121
  }
835
- onExternalFunctionCallOutput(source, item) {
1122
+ getStreaming() {
1123
+ return this.streaming;
836
1124
  }
837
- onReasoning(item) {
1125
+ setTools(tools) {
1126
+ this.tools = tools;
838
1127
  }
839
- onExternalReasoning(source, item) {
1128
+ getTools() {
1129
+ return this.tools;
840
1130
  }
841
- onModelMessage(item) {
1131
+ setReasoningEffort(effort) {
1132
+ this.effort.setReasoningEffort(effort);
842
1133
  }
843
- onExternalModelMessage(source, item) {
1134
+ getReasoningEffort() {
1135
+ return this.effort.getReasoningEffort();
844
1136
  }
845
- 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
+ );
846
1156
  }
847
- onJoined() {
1157
+ setStreaming(streaming) {
1158
+ this.streaming = streaming;
848
1159
  }
849
- onLeft() {
1160
+ getStreaming() {
1161
+ return this.streaming;
850
1162
  }
851
- onParticipantJoined(participant) {
1163
+ setTools(tools) {
1164
+ this.tools = tools;
852
1165
  }
853
- onParticipantLeft(participant) {
1166
+ getTools() {
1167
+ return this.tools;
854
1168
  }
855
- onInternalEvent(item) {
1169
+ setReasoningEffort(effort) {
1170
+ this.effort.setReasoningEffort(effort);
856
1171
  }
857
- onExternalEvent(source, item) {
1172
+ getReasoningEffort() {
1173
+ return this.effort.getReasoningEffort();
858
1174
  }
859
1175
  };
860
1176
  export {
861
1177
  Agent,
862
1178
  AgenticEnvironment,
1179
+ AnthropicMessages,
863
1180
  BaseAgent,
864
1181
  BaseHuman,
865
1182
  BaseObserver,
1183
+ ClaudeHaiku45,
1184
+ ClaudeOpus47,
1185
+ ClaudeSonnet46,
866
1186
  ContextItem,
867
1187
  DefaultFunctionCallRunner,
868
1188
  DeveloperMessageItem,
@@ -874,11 +1194,14 @@ export {
874
1194
  Gpt55,
875
1195
  Human,
876
1196
  InMemoryModelContextRepository,
1197
+ InferenceRequest,
1198
+ InferenceResponse,
877
1199
  InputTokenDetails,
878
1200
  ModelContext,
879
1201
  ModelMessageItem,
880
1202
  Observer,
881
1203
  OpenAIInferenceRunner,
1204
+ OpenAIResponses,
882
1205
  OutputTokenDetails,
883
1206
  Participant,
884
1207
  ReasoningItem,