@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.js CHANGED
@@ -32,9 +32,13 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  Agent: () => Agent,
34
34
  AgenticEnvironment: () => AgenticEnvironment,
35
+ AnthropicMessages: () => AnthropicMessages,
35
36
  BaseAgent: () => BaseAgent,
36
37
  BaseHuman: () => BaseHuman,
37
38
  BaseObserver: () => BaseObserver,
39
+ ClaudeHaiku45: () => ClaudeHaiku45,
40
+ ClaudeOpus47: () => ClaudeOpus47,
41
+ ClaudeSonnet46: () => ClaudeSonnet46,
38
42
  ContextItem: () => ContextItem,
39
43
  DefaultFunctionCallRunner: () => DefaultFunctionCallRunner,
40
44
  DeveloperMessageItem: () => DeveloperMessageItem,
@@ -46,11 +50,14 @@ __export(index_exports, {
46
50
  Gpt55: () => Gpt55,
47
51
  Human: () => Human,
48
52
  InMemoryModelContextRepository: () => InMemoryModelContextRepository,
53
+ InferenceRequest: () => InferenceRequest,
54
+ InferenceResponse: () => InferenceResponse,
49
55
  InputTokenDetails: () => InputTokenDetails,
50
56
  ModelContext: () => ModelContext,
51
57
  ModelMessageItem: () => ModelMessageItem,
52
58
  Observer: () => Observer,
53
59
  OpenAIInferenceRunner: () => OpenAIInferenceRunner,
60
+ OpenAIResponses: () => OpenAIResponses,
54
61
  OutputTokenDetails: () => OutputTokenDetails,
55
62
  Participant: () => Participant,
56
63
  ReasoningItem: () => ReasoningItem,
@@ -749,19 +756,171 @@ var BaseHuman = class extends Human {
749
756
  }
750
757
  };
751
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;
764
+ }
765
+ };
766
+
752
767
  // src/application/runners/openai-inference-runner.ts
753
- var import_openai = __toESM(require("openai"));
754
768
  var OpenAIInferenceRunner = class {
769
+ constructor(runtime) {
770
+ this.runtime = runtime;
771
+ }
755
772
  async *run(context, model, signal) {
756
- const input = this.mapContextToRequest(context);
757
- const specification = model.specification;
758
- let request = {
773
+ const request = new InferenceRequest(model, context);
774
+ if (model.getStreaming() && this.isStreamingRuntime(this.runtime)) {
775
+ yield* this.runtime.stream(request, signal);
776
+ return;
777
+ }
778
+ const response = await this.runtime.infer(request);
779
+ for (const item of response.contextItems) {
780
+ if (signal == null ? void 0 : signal.aborted) {
781
+ break;
782
+ }
783
+ yield item;
784
+ }
785
+ }
786
+ isStreamingRuntime(runtime) {
787
+ return typeof runtime.stream === "function";
788
+ }
789
+ };
790
+
791
+ // src/application/runners/function-call-runner.ts
792
+ var DefaultFunctionCallRunner = class {
793
+ constructor(tools) {
794
+ this.tools = tools;
795
+ }
796
+ async *run(call, signal) {
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));
801
+ }
802
+ };
803
+
804
+ // src/infrastructure/providers/openai/models/gpt-5-5.ts
805
+ var Gpt55 = class {
806
+ constructor() {
807
+ this.specification = {
808
+ name: "gpt-5.5",
809
+ supportReasoningEffort: true,
810
+ defaultReasoningEffort: "none",
811
+ supportStreaming: true,
812
+ contextWindowSize: 105e4,
813
+ maxOutputTokens: 128e3,
814
+ supportFunctionCalling: true
815
+ };
816
+ this.tools = [];
817
+ this.streaming = false;
818
+ this.effort = new OpenAIReasoningEffort(
819
+ this.specification.defaultReasoningEffort
820
+ );
821
+ }
822
+ setStreaming(streaming) {
823
+ this.streaming = streaming;
824
+ }
825
+ getStreaming() {
826
+ return this.streaming;
827
+ }
828
+ setTools(tools) {
829
+ this.tools = tools;
830
+ }
831
+ getTools() {
832
+ return this.tools;
833
+ }
834
+ setReasoningEffort(effort) {
835
+ this.effort.setReasoningEffort(effort);
836
+ }
837
+ getReasoningEffort() {
838
+ return this.effort.getReasoningEffort();
839
+ }
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() {
867
+ }
868
+ onLeft() {
869
+ }
870
+ onParticipantJoined(participant) {
871
+ }
872
+ onParticipantLeft(participant) {
873
+ }
874
+ onInternalEvent(item) {
875
+ }
876
+ onExternalEvent(source, item) {
877
+ }
878
+ };
879
+
880
+ // src/domain/generative-model/inference-response.ts
881
+ var InferenceResponse = class {
882
+ constructor(contextItems, tokenUsage) {
883
+ this.contextItems = contextItems;
884
+ this.tokenUsage = tokenUsage;
885
+ }
886
+ };
887
+
888
+ // src/infrastructure/providers/openai/runtime/openai-responses.ts
889
+ var import_openai = __toESM(require("openai"));
890
+ var OpenAIResponses = class {
891
+ constructor() {
892
+ this.client = new import_openai.default();
893
+ }
894
+ async infer(inferenceRequest) {
895
+ const request = this.buildRequest(inferenceRequest);
896
+ const response = await this.client.responses.create(request);
897
+ const contextItems = this.extractContextItems(response);
898
+ const tokenUsage = this.extractTokenUsage(response);
899
+ return new InferenceResponse(contextItems, tokenUsage);
900
+ }
901
+ async *stream(inferenceRequest, signal) {
902
+ const specification = inferenceRequest.model.specification;
903
+ if (!specification.supportStreaming) {
904
+ throw new Error("Streaming is not supported for this model");
905
+ }
906
+ const request = { ...this.buildRequest(inferenceRequest), stream: true };
907
+ const response = await this.client.responses.create(request);
908
+ for await (const event of response) {
909
+ if (signal == null ? void 0 : signal.aborted) {
910
+ break;
911
+ }
912
+ yield new SemanticEvent(event.type, event);
913
+ }
914
+ }
915
+ buildRequest(inferenceRequest) {
916
+ const specification = inferenceRequest.model.specification;
917
+ const input = this.mapContextToRequest(inferenceRequest.context);
918
+ const request = {
759
919
  model: specification.name,
760
- input,
761
- stream: model.getStreaming()
920
+ input
762
921
  };
763
- if (specification.supportFunctionCalling && model.getTools().length > 0) {
764
- request.tools = model.getTools().map((tool) => {
922
+ if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
923
+ request.tools = inferenceRequest.model.getTools().map((tool) => {
765
924
  return {
766
925
  type: tool.type,
767
926
  name: tool.name,
@@ -772,31 +931,10 @@ var OpenAIInferenceRunner = class {
772
931
  }
773
932
  if (specification.supportReasoningEffort) {
774
933
  request.reasoning = {
775
- effort: model.getReasoningEffort()
934
+ effort: inferenceRequest.model.getReasoningEffort()
776
935
  };
777
936
  }
778
- if (!specification.supportStreaming && model.getStreaming()) {
779
- throw new Error("Streaming is not supported for this model");
780
- }
781
- const openai = new import_openai.default();
782
- const response = await openai.responses.create(request);
783
- if (specification.supportStreaming && model.getStreaming()) {
784
- for await (const event of response) {
785
- if (signal == null ? void 0 : signal.aborted) {
786
- break;
787
- }
788
- yield new SemanticEvent(event.type, event);
789
- }
790
- } else {
791
- const contextItems = this.extractContextItems(response);
792
- const tokenUsage = this.extractTokenUsage(response);
793
- for (const item of contextItems) {
794
- if (signal == null ? void 0 : signal.aborted) {
795
- break;
796
- }
797
- yield item;
798
- }
799
- }
937
+ return request;
800
938
  }
801
939
  extractTokenUsage(response) {
802
940
  if (!response.usage) {
@@ -832,34 +970,181 @@ var OpenAIInferenceRunner = class {
832
970
  }
833
971
  };
834
972
 
835
- // src/application/runners/function-call-runner.ts
836
- var DefaultFunctionCallRunner = class {
837
- constructor(tools) {
838
- this.tools = tools;
973
+ // src/infrastructure/providers/anthropic/runtime/anthropic-messages.ts
974
+ var import_sdk = __toESM(require("@anthropic-ai/sdk"));
975
+ var AnthropicMessages = class {
976
+ constructor() {
977
+ this.client = new import_sdk.default();
839
978
  }
840
- async *run(call, signal) {
841
- const tool = this.tools.find((t) => t.name === call.name);
842
- if (!tool) throw new Error(`Unknown tool: ${call.name}`);
843
- const result = await tool.invoke(JSON.parse(call.args));
844
- yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
979
+ async infer(inferenceRequest) {
980
+ const { messages, system } = this.mapContextToRequest(inferenceRequest.context);
981
+ const specification = inferenceRequest.model.specification;
982
+ const request = {
983
+ model: specification.name,
984
+ max_tokens: specification.maxOutputTokens,
985
+ messages
986
+ };
987
+ if (system) {
988
+ request.system = system;
989
+ }
990
+ if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
991
+ request.tools = inferenceRequest.model.getTools().map((tool) => {
992
+ return {
993
+ name: tool.name,
994
+ description: tool.description,
995
+ input_schema: tool.parameters
996
+ };
997
+ });
998
+ }
999
+ if (specification.supportReasoningEffort) {
1000
+ const effort = inferenceRequest.model.getReasoningEffort();
1001
+ const budgets = { low: 1024, medium: 4096, high: 8192 };
1002
+ const budget = budgets[effort];
1003
+ if (budget !== void 0) {
1004
+ request.thinking = {
1005
+ type: "enabled",
1006
+ budget_tokens: Math.min(budget, specification.maxOutputTokens - 1)
1007
+ };
1008
+ }
1009
+ }
1010
+ const response = await this.client.messages.create(request);
1011
+ const contextItems = this.extractContextItems(response);
1012
+ const tokenUsage = this.extractTokenUsage(response);
1013
+ return new InferenceResponse(contextItems, tokenUsage);
1014
+ }
1015
+ extractTokenUsage(response) {
1016
+ var _a, _b;
1017
+ if (!response.usage) {
1018
+ return void 0;
1019
+ }
1020
+ return new TokenUsage(
1021
+ response.usage.input_tokens,
1022
+ response.usage.output_tokens,
1023
+ response.usage.input_tokens + response.usage.output_tokens,
1024
+ new InputTokenDetails(
1025
+ ((_a = response.usage.cache_creation_input_tokens) != null ? _a : 0) + ((_b = response.usage.cache_read_input_tokens) != null ? _b : 0)
1026
+ ),
1027
+ new OutputTokenDetails(0)
1028
+ );
1029
+ }
1030
+ mapContextToRequest(context) {
1031
+ const messages = [];
1032
+ const system = [];
1033
+ for (const item of context.getItems()) {
1034
+ if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
1035
+ system.push(item.content.text);
1036
+ continue;
1037
+ }
1038
+ if (item instanceof UserMessageItem) {
1039
+ this.addContentBlock(messages, "user", { type: "text", text: item.content.text });
1040
+ continue;
1041
+ }
1042
+ if (item instanceof ModelMessageItem) {
1043
+ this.addContentBlock(messages, "assistant", { type: "text", text: item.content.text });
1044
+ continue;
1045
+ }
1046
+ if (item instanceof FunctionCallItem) {
1047
+ let input;
1048
+ try {
1049
+ input = JSON.parse(item.args);
1050
+ } catch (e) {
1051
+ input = item.args;
1052
+ }
1053
+ this.addContentBlock(messages, "assistant", {
1054
+ type: "tool_use",
1055
+ id: item.callId,
1056
+ name: item.name,
1057
+ input
1058
+ });
1059
+ continue;
1060
+ }
1061
+ if (item instanceof FunctionCallOutputItem) {
1062
+ this.addContentBlock(messages, "user", {
1063
+ type: "tool_result",
1064
+ tool_use_id: item.callId,
1065
+ content: item.output.text
1066
+ });
1067
+ }
1068
+ }
1069
+ return {
1070
+ messages,
1071
+ system: system.length > 0 ? system.join("\n\n") : void 0
1072
+ };
1073
+ }
1074
+ extractContextItems(response) {
1075
+ var _a;
1076
+ const items = [];
1077
+ for (const block of response.content) {
1078
+ if (block.type === "text") {
1079
+ items.push(ModelMessageItem.rehydrate({ text: block.text }));
1080
+ continue;
1081
+ }
1082
+ if (block.type === "tool_use") {
1083
+ items.push(
1084
+ FunctionCallItem.rehydrate({
1085
+ callId: block.id,
1086
+ name: block.name,
1087
+ args: JSON.stringify((_a = block.input) != null ? _a : {})
1088
+ })
1089
+ );
1090
+ continue;
1091
+ }
1092
+ if (block.type === "thinking") {
1093
+ items.push(
1094
+ ReasoningItem.rehydrate({
1095
+ content: block.thinking ? InputText.rehydrate({ text: block.thinking }) : void 0,
1096
+ encryptedContent: void 0,
1097
+ summary: []
1098
+ })
1099
+ );
1100
+ }
1101
+ }
1102
+ return items;
1103
+ }
1104
+ addContentBlock(messages, role, block) {
1105
+ const lastMessage = messages[messages.length - 1];
1106
+ if ((lastMessage == null ? void 0 : lastMessage.role) === role) {
1107
+ lastMessage.content.push(block);
1108
+ return;
1109
+ }
1110
+ messages.push({
1111
+ role,
1112
+ content: [block]
1113
+ });
845
1114
  }
846
1115
  };
847
1116
 
848
- // src/infrastructure/providers/openai/models/gpt-5-5.ts
849
- var Gpt55 = class {
1117
+ // src/infrastructure/providers/anthropic/reasoning-effort.ts
1118
+ var AnthropicReasoningEffort = class {
1119
+ constructor(reasoningEffort) {
1120
+ this.reasoningEffort = reasoningEffort;
1121
+ }
1122
+ setReasoningEffort(effort) {
1123
+ this.reasoningEffort = effort;
1124
+ }
1125
+ getReasoningEffort() {
1126
+ if (!this.reasoningEffort) {
1127
+ throw new Error("Reasoning effort not supported");
1128
+ }
1129
+ return this.reasoningEffort;
1130
+ }
1131
+ };
1132
+
1133
+ // src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
1134
+ var ClaudeOpus47 = class {
850
1135
  constructor() {
851
1136
  this.specification = {
852
- name: "gpt-5.5",
1137
+ name: "claude-opus-4-7",
853
1138
  supportReasoningEffort: true,
854
1139
  defaultReasoningEffort: "none",
855
1140
  supportStreaming: true,
856
- contextWindowSize: 105e4,
857
- maxOutputTokens: 128e3,
1141
+ contextWindowSize: 2e5,
1142
+ maxOutputTokens: 32e3,
858
1143
  supportFunctionCalling: true
859
1144
  };
860
1145
  this.tools = [];
861
1146
  this.streaming = false;
862
- this.effort = new OpenAIReasoningEffort(
1147
+ this.effort = new AnthropicReasoningEffort(
863
1148
  this.specification.defaultReasoningEffort
864
1149
  );
865
1150
  }
@@ -883,50 +1168,92 @@ var Gpt55 = class {
883
1168
  }
884
1169
  };
885
1170
 
886
- // src/domain/agentic-environment/participants/observer.ts
887
- var Observer = class extends Participant {
888
- };
889
-
890
- // src/application/participants/observer.ts
891
- var BaseObserver = class extends Observer {
892
- onFunctionCall(item) {
893
- }
894
- onExternalFunctionCall(source, item) {
1171
+ // src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts
1172
+ var ClaudeSonnet46 = class {
1173
+ constructor() {
1174
+ this.specification = {
1175
+ name: "claude-sonnet-4-6",
1176
+ supportReasoningEffort: true,
1177
+ defaultReasoningEffort: "none",
1178
+ supportStreaming: true,
1179
+ contextWindowSize: 2e5,
1180
+ maxOutputTokens: 64e3,
1181
+ supportFunctionCalling: true
1182
+ };
1183
+ this.tools = [];
1184
+ this.streaming = false;
1185
+ this.effort = new AnthropicReasoningEffort(
1186
+ this.specification.defaultReasoningEffort
1187
+ );
895
1188
  }
896
- onFunctionCallOutput(item) {
1189
+ setStreaming(streaming) {
1190
+ this.streaming = streaming;
897
1191
  }
898
- onExternalFunctionCallOutput(source, item) {
1192
+ getStreaming() {
1193
+ return this.streaming;
899
1194
  }
900
- onReasoning(item) {
1195
+ setTools(tools) {
1196
+ this.tools = tools;
901
1197
  }
902
- onExternalReasoning(source, item) {
1198
+ getTools() {
1199
+ return this.tools;
903
1200
  }
904
- onModelMessage(item) {
1201
+ setReasoningEffort(effort) {
1202
+ this.effort.setReasoningEffort(effort);
905
1203
  }
906
- onExternalModelMessage(source, item) {
1204
+ getReasoningEffort() {
1205
+ return this.effort.getReasoningEffort();
907
1206
  }
908
- onMessage(message) {
1207
+ };
1208
+
1209
+ // src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts
1210
+ var ClaudeHaiku45 = class {
1211
+ constructor() {
1212
+ this.specification = {
1213
+ name: "claude-haiku-4-5",
1214
+ supportReasoningEffort: true,
1215
+ defaultReasoningEffort: "none",
1216
+ supportStreaming: true,
1217
+ contextWindowSize: 2e5,
1218
+ maxOutputTokens: 64e3,
1219
+ supportFunctionCalling: true
1220
+ };
1221
+ this.tools = [];
1222
+ this.streaming = false;
1223
+ this.effort = new AnthropicReasoningEffort(
1224
+ this.specification.defaultReasoningEffort
1225
+ );
909
1226
  }
910
- onJoined() {
1227
+ setStreaming(streaming) {
1228
+ this.streaming = streaming;
911
1229
  }
912
- onLeft() {
1230
+ getStreaming() {
1231
+ return this.streaming;
913
1232
  }
914
- onParticipantJoined(participant) {
1233
+ setTools(tools) {
1234
+ this.tools = tools;
915
1235
  }
916
- onParticipantLeft(participant) {
1236
+ getTools() {
1237
+ return this.tools;
917
1238
  }
918
- onInternalEvent(item) {
1239
+ setReasoningEffort(effort) {
1240
+ this.effort.setReasoningEffort(effort);
919
1241
  }
920
- onExternalEvent(source, item) {
1242
+ getReasoningEffort() {
1243
+ return this.effort.getReasoningEffort();
921
1244
  }
922
1245
  };
923
1246
  // Annotate the CommonJS export names for ESM import in node:
924
1247
  0 && (module.exports = {
925
1248
  Agent,
926
1249
  AgenticEnvironment,
1250
+ AnthropicMessages,
927
1251
  BaseAgent,
928
1252
  BaseHuman,
929
1253
  BaseObserver,
1254
+ ClaudeHaiku45,
1255
+ ClaudeOpus47,
1256
+ ClaudeSonnet46,
930
1257
  ContextItem,
931
1258
  DefaultFunctionCallRunner,
932
1259
  DeveloperMessageItem,
@@ -938,11 +1265,14 @@ var BaseObserver = class extends Observer {
938
1265
  Gpt55,
939
1266
  Human,
940
1267
  InMemoryModelContextRepository,
1268
+ InferenceRequest,
1269
+ InferenceResponse,
941
1270
  InputTokenDetails,
942
1271
  ModelContext,
943
1272
  ModelMessageItem,
944
1273
  Observer,
945
1274
  OpenAIInferenceRunner,
1275
+ OpenAIResponses,
946
1276
  OutputTokenDetails,
947
1277
  Participant,
948
1278
  ReasoningItem,