@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.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,
@@ -548,24 +555,25 @@ var AgenticEnvironment = class {
548
555
  this.subscribers = [];
549
556
  this.isActive = false;
550
557
  }
551
- subscribe(subscriber) {
552
- this.subscribers.push(subscriber);
553
- for (const subscriber2 of this.subscribers) {
554
- if (subscriber2 === subscriber2) {
555
- subscriber2.onJoined();
558
+ subscribe(participant) {
559
+ this.subscribers.push(participant);
560
+ for (const subscriber of this.subscribers) {
561
+ if (participant === subscriber) {
562
+ participant.onJoined();
556
563
  } else {
557
- subscriber2.onParticipantJoined(subscriber2);
564
+ subscriber.onParticipantJoined(participant);
558
565
  }
559
566
  }
560
567
  }
561
- unsubscribe(subscriber) {
562
- this.subscribers = this.subscribers.filter((p) => p !== subscriber);
563
- for (const subscriber2 of this.subscribers) {
564
- if (subscriber2 === subscriber2) {
565
- subscriber2.onLeft();
566
- } else {
567
- subscriber2.onParticipantLeft(subscriber2);
568
- }
568
+ unsubscribe(participant) {
569
+ const exists = this.subscribers.includes(participant);
570
+ if (!exists) {
571
+ return;
572
+ }
573
+ participant.onLeft();
574
+ this.subscribers = this.subscribers.filter((p) => p !== participant);
575
+ for (const subscriber of this.subscribers) {
576
+ subscriber.onParticipantLeft(participant);
569
577
  }
570
578
  }
571
579
  deliverFunctionCall(source, item) {
@@ -748,19 +756,171 @@ var BaseHuman = class extends Human {
748
756
  }
749
757
  };
750
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
+
751
767
  // src/application/runners/openai-inference-runner.ts
752
- var import_openai = __toESM(require("openai"));
753
768
  var OpenAIInferenceRunner = class {
769
+ constructor(runtime) {
770
+ this.runtime = runtime;
771
+ }
754
772
  async *run(context, model, signal) {
755
- const input = this.mapContextToRequest(context);
756
- const specification = model.specification;
757
- 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 = {
758
919
  model: specification.name,
759
- input,
760
- stream: model.getStreaming()
920
+ input
761
921
  };
762
- if (specification.supportFunctionCalling && model.getTools().length > 0) {
763
- request.tools = model.getTools().map((tool) => {
922
+ if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
923
+ request.tools = inferenceRequest.model.getTools().map((tool) => {
764
924
  return {
765
925
  type: tool.type,
766
926
  name: tool.name,
@@ -771,31 +931,10 @@ var OpenAIInferenceRunner = class {
771
931
  }
772
932
  if (specification.supportReasoningEffort) {
773
933
  request.reasoning = {
774
- effort: model.getReasoningEffort()
934
+ effort: inferenceRequest.model.getReasoningEffort()
775
935
  };
776
936
  }
777
- if (!specification.supportStreaming && model.getStreaming()) {
778
- throw new Error("Streaming is not supported for this model");
779
- }
780
- const openai = new import_openai.default();
781
- const response = await openai.responses.create(request);
782
- if (specification.supportStreaming && model.getStreaming()) {
783
- for await (const event of response) {
784
- if (signal == null ? void 0 : signal.aborted) {
785
- break;
786
- }
787
- yield new SemanticEvent(event.type, event);
788
- }
789
- } else {
790
- const contextItems = this.extractContextItems(response);
791
- const tokenUsage = this.extractTokenUsage(response);
792
- for (const item of contextItems) {
793
- if (signal == null ? void 0 : signal.aborted) {
794
- break;
795
- }
796
- yield item;
797
- }
798
- }
937
+ return request;
799
938
  }
800
939
  extractTokenUsage(response) {
801
940
  if (!response.usage) {
@@ -831,34 +970,181 @@ var OpenAIInferenceRunner = class {
831
970
  }
832
971
  };
833
972
 
834
- // src/application/runners/function-call-runner.ts
835
- var DefaultFunctionCallRunner = class {
836
- constructor(tools) {
837
- 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();
838
978
  }
839
- async *run(call, signal) {
840
- const tool = this.tools.find((t) => t.name === call.name);
841
- if (!tool) throw new Error(`Unknown tool: ${call.name}`);
842
- const result = await tool.invoke(JSON.parse(call.args));
843
- 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
+ });
844
1114
  }
845
1115
  };
846
1116
 
847
- // src/infrastructure/providers/openai/models/gpt-5-5.ts
848
- 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 {
849
1135
  constructor() {
850
1136
  this.specification = {
851
- name: "gpt-5.5",
1137
+ name: "claude-opus-4-7",
852
1138
  supportReasoningEffort: true,
853
1139
  defaultReasoningEffort: "none",
854
1140
  supportStreaming: true,
855
- contextWindowSize: 105e4,
856
- maxOutputTokens: 128e3,
1141
+ contextWindowSize: 2e5,
1142
+ maxOutputTokens: 32e3,
857
1143
  supportFunctionCalling: true
858
1144
  };
859
1145
  this.tools = [];
860
1146
  this.streaming = false;
861
- this.effort = new OpenAIReasoningEffort(
1147
+ this.effort = new AnthropicReasoningEffort(
862
1148
  this.specification.defaultReasoningEffort
863
1149
  );
864
1150
  }
@@ -882,50 +1168,92 @@ var Gpt55 = class {
882
1168
  }
883
1169
  };
884
1170
 
885
- // src/domain/agentic-environment/participants/observer.ts
886
- var Observer = class extends Participant {
887
- };
888
-
889
- // src/application/participants/observer.ts
890
- var BaseObserver = class extends Observer {
891
- onFunctionCall(item) {
892
- }
893
- 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
+ );
894
1188
  }
895
- onFunctionCallOutput(item) {
1189
+ setStreaming(streaming) {
1190
+ this.streaming = streaming;
896
1191
  }
897
- onExternalFunctionCallOutput(source, item) {
1192
+ getStreaming() {
1193
+ return this.streaming;
898
1194
  }
899
- onReasoning(item) {
1195
+ setTools(tools) {
1196
+ this.tools = tools;
900
1197
  }
901
- onExternalReasoning(source, item) {
1198
+ getTools() {
1199
+ return this.tools;
902
1200
  }
903
- onModelMessage(item) {
1201
+ setReasoningEffort(effort) {
1202
+ this.effort.setReasoningEffort(effort);
904
1203
  }
905
- onExternalModelMessage(source, item) {
1204
+ getReasoningEffort() {
1205
+ return this.effort.getReasoningEffort();
906
1206
  }
907
- 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
+ );
908
1226
  }
909
- onJoined() {
1227
+ setStreaming(streaming) {
1228
+ this.streaming = streaming;
910
1229
  }
911
- onLeft() {
1230
+ getStreaming() {
1231
+ return this.streaming;
912
1232
  }
913
- onParticipantJoined(participant) {
1233
+ setTools(tools) {
1234
+ this.tools = tools;
914
1235
  }
915
- onParticipantLeft(participant) {
1236
+ getTools() {
1237
+ return this.tools;
916
1238
  }
917
- onInternalEvent(item) {
1239
+ setReasoningEffort(effort) {
1240
+ this.effort.setReasoningEffort(effort);
918
1241
  }
919
- onExternalEvent(source, item) {
1242
+ getReasoningEffort() {
1243
+ return this.effort.getReasoningEffort();
920
1244
  }
921
1245
  };
922
1246
  // Annotate the CommonJS export names for ESM import in node:
923
1247
  0 && (module.exports = {
924
1248
  Agent,
925
1249
  AgenticEnvironment,
1250
+ AnthropicMessages,
926
1251
  BaseAgent,
927
1252
  BaseHuman,
928
1253
  BaseObserver,
1254
+ ClaudeHaiku45,
1255
+ ClaudeOpus47,
1256
+ ClaudeSonnet46,
929
1257
  ContextItem,
930
1258
  DefaultFunctionCallRunner,
931
1259
  DeveloperMessageItem,
@@ -937,11 +1265,14 @@ var BaseObserver = class extends Observer {
937
1265
  Gpt55,
938
1266
  Human,
939
1267
  InMemoryModelContextRepository,
1268
+ InferenceRequest,
1269
+ InferenceResponse,
940
1270
  InputTokenDetails,
941
1271
  ModelContext,
942
1272
  ModelMessageItem,
943
1273
  Observer,
944
1274
  OpenAIInferenceRunner,
1275
+ OpenAIResponses,
945
1276
  OutputTokenDetails,
946
1277
  Participant,
947
1278
  ReasoningItem,