@mozaik-ai/core 3.10.3 → 3.12.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,25 +32,39 @@ 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
+ ClaudeOpus48: () => ClaudeOpus48,
42
+ ClaudeSonnet46: () => ClaudeSonnet46,
38
43
  ContextItem: () => ContextItem,
44
+ DeepSeekV4Flash: () => DeepSeekV4Flash,
45
+ DeepSeekV4Pro: () => DeepSeekV4Pro,
39
46
  DefaultFunctionCallRunner: () => DefaultFunctionCallRunner,
47
+ DefaultInferenceRunner: () => DefaultInferenceRunner,
40
48
  DeveloperMessageItem: () => DeveloperMessageItem,
41
49
  FunctionCallItem: () => FunctionCallItem,
42
50
  FunctionCallOutputItem: () => FunctionCallOutputItem,
51
+ Gemini31Pro: () => Gemini31Pro,
52
+ Gemini35Flash: () => Gemini35Flash,
53
+ GeminiGenerateContent: () => GeminiGenerateContent,
43
54
  Gpt54: () => Gpt54,
44
55
  Gpt54Mini: () => Gpt54Mini,
45
56
  Gpt54Nano: () => Gpt54Nano,
46
57
  Gpt55: () => Gpt55,
47
58
  Human: () => Human,
48
59
  InMemoryModelContextRepository: () => InMemoryModelContextRepository,
60
+ InferenceRequest: () => InferenceRequest,
61
+ InferenceResponse: () => InferenceResponse,
49
62
  InputTokenDetails: () => InputTokenDetails,
50
63
  ModelContext: () => ModelContext,
51
64
  ModelMessageItem: () => ModelMessageItem,
52
65
  Observer: () => Observer,
53
- OpenAIInferenceRunner: () => OpenAIInferenceRunner,
66
+ OpenAICompatibleChatCompletions: () => OpenAICompatibleChatCompletions,
67
+ OpenAIResponses: () => OpenAIResponses,
54
68
  OutputTokenDetails: () => OutputTokenDetails,
55
69
  Participant: () => Participant,
56
70
  ReasoningItem: () => ReasoningItem,
@@ -326,10 +340,10 @@ var Gpt54Nano = class {
326
340
  supportFunctionCalling: true
327
341
  };
328
342
  this.tools = [];
343
+ this.streaming = false;
329
344
  this.effort = new OpenAIReasoningEffort(
330
345
  this.specification.defaultReasoningEffort
331
346
  );
332
- this.streaming = false;
333
347
  }
334
348
  setStreaming(streaming) {
335
349
  this.streaming = streaming;
@@ -402,10 +416,10 @@ var Gpt54Mini = class {
402
416
  supportFunctionCalling: true
403
417
  };
404
418
  this.tools = [];
419
+ this.streaming = false;
405
420
  this.effort = new OpenAIReasoningEffort(
406
421
  this.specification.defaultReasoningEffort
407
422
  );
408
- this.streaming = false;
409
423
  }
410
424
  setStreaming(streaming) {
411
425
  this.streaming = streaming;
@@ -519,6 +533,7 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
519
533
  var Participant = class {
520
534
  constructor() {
521
535
  this.environments = [];
536
+ this.listens = [];
522
537
  }
523
538
  join(environment) {
524
539
  if (this.isJoinedTo(environment)) {
@@ -540,13 +555,17 @@ var Participant = class {
540
555
  getEnvironments() {
541
556
  return this.environments;
542
557
  }
558
+ getListeners() {
559
+ return this.listens;
560
+ }
543
561
  };
544
562
 
545
563
  // src/domain/agentic-environment/agentic-environment.ts
546
564
  var AgenticEnvironment = class {
547
- constructor() {
565
+ constructor(name) {
548
566
  this.subscribers = [];
549
567
  this.isActive = false;
568
+ this.name = name;
550
569
  }
551
570
  subscribe(participant) {
552
571
  this.subscribers.push(participant);
@@ -570,53 +589,53 @@ var AgenticEnvironment = class {
570
589
  }
571
590
  }
572
591
  deliverFunctionCall(source, item) {
573
- for (const subscriber of this.subscribers) {
574
- if (subscriber === source) {
575
- subscriber.onFunctionCall(item);
576
- } else {
577
- subscriber.onExternalFunctionCall(source, item);
578
- }
579
- }
592
+ this.deliverToSubscribers(source, {
593
+ internal: (src) => src.onFunctionCall(item),
594
+ external: (sub) => sub.onExternalFunctionCall(source, item)
595
+ });
580
596
  }
581
597
  deliverModelMessage(source, item) {
582
- for (const subscriber of this.subscribers) {
583
- if (subscriber === source) {
584
- subscriber.onModelMessage(item);
585
- } else {
586
- subscriber.onExternalModelMessage(source, item);
587
- }
588
- }
598
+ this.deliverToSubscribers(source, {
599
+ internal: (src) => src.onModelMessage(item),
600
+ external: (sub) => sub.onExternalModelMessage(source, item)
601
+ });
589
602
  }
590
603
  deliverReasoning(source, item) {
591
- for (const subscriber of this.subscribers) {
592
- if (subscriber === source) {
593
- subscriber.onReasoning(item);
594
- } else {
595
- subscriber.onExternalReasoning(source, item);
596
- }
597
- }
604
+ this.deliverToSubscribers(source, {
605
+ internal: (src) => src.onReasoning(item),
606
+ external: (sub) => sub.onExternalReasoning(source, item)
607
+ });
598
608
  }
599
609
  deliverFunctionCallOutput(source, item) {
600
- for (const subscriber of this.subscribers) {
601
- if (subscriber === source) {
602
- subscriber.onFunctionCallOutput(item);
603
- } else {
604
- subscriber.onExternalFunctionCallOutput(source, item);
605
- }
606
- }
610
+ this.deliverToSubscribers(source, {
611
+ internal: (src) => src.onFunctionCallOutput(item),
612
+ external: (sub) => sub.onExternalFunctionCallOutput(source, item)
613
+ });
607
614
  }
608
615
  deliverMessage(source, message) {
609
- for (const subscriber of this.subscribers) {
610
- if (subscriber === source) continue;
611
- subscriber.onMessage(message);
612
- }
616
+ this.deliverToSubscribers(source, {
617
+ external: (sub) => sub.onMessage(message)
618
+ });
613
619
  }
614
620
  deliverSemanticEvent(source, item) {
621
+ this.deliverToSubscribers(source, {
622
+ internal: (src) => src.onInternalEvent(item),
623
+ external: (sub) => sub.onExternalEvent(source, item)
624
+ });
625
+ }
626
+ getListeningParticipants(source) {
627
+ return this.subscribers.filter(
628
+ (sub) => sub !== source && (sub.getListeners().length === 0 || sub.getListeners().some((listener) => source instanceof listener))
629
+ );
630
+ }
631
+ deliverToSubscribers(source, handlers) {
632
+ var _a, _b;
633
+ const authorizedListeners = this.getListeningParticipants(source);
615
634
  for (const subscriber of this.subscribers) {
616
635
  if (subscriber === source) {
617
- subscriber.onInternalEvent(item);
618
- } else {
619
- subscriber.onExternalEvent(source, item);
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);
620
639
  }
621
640
  }
622
641
  }
@@ -749,86 +768,35 @@ var BaseHuman = class extends Human {
749
768
  }
750
769
  };
751
770
 
752
- // src/application/runners/openai-inference-runner.ts
753
- var import_openai = __toESM(require("openai"));
754
- var OpenAIInferenceRunner = class {
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
+ }
755
784
  async *run(context, model, signal) {
756
- const input = this.mapContextToRequest(context);
757
- const specification = model.specification;
758
- let request = {
759
- model: specification.name,
760
- input,
761
- stream: model.getStreaming()
762
- };
763
- if (specification.supportFunctionCalling && model.getTools().length > 0) {
764
- request.tools = model.getTools().map((tool) => {
765
- return {
766
- type: tool.type,
767
- name: tool.name,
768
- description: tool.description,
769
- parameters: tool.parameters
770
- };
771
- });
772
- }
773
- if (specification.supportReasoningEffort) {
774
- request.reasoning = {
775
- effort: model.getReasoningEffort()
776
- };
777
- }
778
- if (!specification.supportStreaming && model.getStreaming()) {
779
- throw new Error("Streaming is not supported for this model");
785
+ const request = new InferenceRequest(model, context);
786
+ if (model.getStreaming() && this.isStreamingRuntime(this.runtime)) {
787
+ yield* this.runtime.stream(request, signal);
788
+ return;
780
789
  }
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;
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;
798
794
  }
795
+ yield item;
799
796
  }
800
797
  }
801
- extractTokenUsage(response) {
802
- if (!response.usage) {
803
- return void 0;
804
- }
805
- return new TokenUsage(
806
- response.usage.input_tokens,
807
- response.usage.output_tokens,
808
- response.usage.total_tokens,
809
- new InputTokenDetails(response.usage.input_tokens_details.cached_tokens),
810
- new OutputTokenDetails(response.usage.output_tokens_details.reasoning_tokens)
811
- );
812
- }
813
- mapContextToRequest(context) {
814
- return context.getItems().map((item) => item.toJSON());
815
- }
816
- extractContextItems(response) {
817
- return response.output.map((item) => {
818
- if (item.type === "message" && item.role === "assistant") {
819
- return ModelMessageItem.rehydrate(item.content[0]);
820
- }
821
- if (item.type === "function_call") {
822
- return FunctionCallItem.rehydrate({
823
- callId: item.call_id,
824
- name: item.name,
825
- args: item.arguments
826
- });
827
- }
828
- if (item.type === "reasoning") {
829
- return ReasoningItem.rehydrate(item);
830
- }
831
- });
798
+ isStreamingRuntime(runtime) {
799
+ return typeof runtime.stream === "function";
832
800
  }
833
801
  };
834
802
 
@@ -920,29 +888,938 @@ var BaseObserver = class extends Observer {
920
888
  onExternalEvent(source, item) {
921
889
  }
922
890
  };
891
+
892
+ // src/domain/generative-model/inference-response.ts
893
+ var InferenceResponse = class {
894
+ constructor(contextItems, tokenUsage) {
895
+ this.contextItems = contextItems;
896
+ this.tokenUsage = tokenUsage;
897
+ }
898
+ };
899
+
900
+ // src/infrastructure/providers/openai/runtime/openai-responses.ts
901
+ var import_openai = __toESM(require("openai"));
902
+ var OpenAIResponses = class {
903
+ constructor() {
904
+ this.client = new import_openai.default();
905
+ }
906
+ async infer(inferenceRequest) {
907
+ const request = this.buildRequest(inferenceRequest);
908
+ const response = await this.client.responses.create(request);
909
+ const contextItems = this.extractContextItems(response);
910
+ const tokenUsage = this.extractTokenUsage(response);
911
+ return new InferenceResponse(contextItems, tokenUsage);
912
+ }
913
+ async *stream(inferenceRequest, signal) {
914
+ const specification = inferenceRequest.model.specification;
915
+ if (!specification.supportStreaming) {
916
+ throw new Error("Streaming is not supported for this model");
917
+ }
918
+ const request = { ...this.buildRequest(inferenceRequest), stream: true };
919
+ const response = await this.client.responses.create(request);
920
+ for await (const event of response) {
921
+ if (signal == null ? void 0 : signal.aborted) {
922
+ break;
923
+ }
924
+ yield new SemanticEvent(event.type, event);
925
+ }
926
+ }
927
+ buildRequest(inferenceRequest) {
928
+ const specification = inferenceRequest.model.specification;
929
+ const input = this.mapContextToRequest(inferenceRequest.context);
930
+ const request = {
931
+ model: specification.name,
932
+ input
933
+ };
934
+ if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
935
+ request.tools = inferenceRequest.model.getTools().map((tool) => {
936
+ return {
937
+ type: tool.type,
938
+ name: tool.name,
939
+ description: tool.description,
940
+ parameters: tool.parameters
941
+ };
942
+ });
943
+ }
944
+ if (specification.supportReasoningEffort) {
945
+ request.reasoning = {
946
+ effort: inferenceRequest.model.getReasoningEffort()
947
+ };
948
+ }
949
+ return request;
950
+ }
951
+ extractTokenUsage(response) {
952
+ if (!response.usage) {
953
+ return void 0;
954
+ }
955
+ return new TokenUsage(
956
+ response.usage.input_tokens,
957
+ response.usage.output_tokens,
958
+ response.usage.total_tokens,
959
+ new InputTokenDetails(response.usage.input_tokens_details.cached_tokens),
960
+ new OutputTokenDetails(response.usage.output_tokens_details.reasoning_tokens)
961
+ );
962
+ }
963
+ mapContextToRequest(context) {
964
+ return context.getItems().map((item) => item.toJSON());
965
+ }
966
+ extractContextItems(response) {
967
+ return response.output.map((item) => {
968
+ if (item.type === "message" && item.role === "assistant") {
969
+ return ModelMessageItem.rehydrate(item.content[0]);
970
+ }
971
+ if (item.type === "function_call") {
972
+ return FunctionCallItem.rehydrate({
973
+ callId: item.call_id,
974
+ name: item.name,
975
+ args: item.arguments
976
+ });
977
+ }
978
+ if (item.type === "reasoning") {
979
+ return ReasoningItem.rehydrate(item);
980
+ }
981
+ });
982
+ }
983
+ };
984
+
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
+ // src/infrastructure/providers/anthropic/runtime/anthropic-messages.ts
1122
+ var import_sdk = __toESM(require("@anthropic-ai/sdk"));
1123
+ var AnthropicMessages = class {
1124
+ constructor() {
1125
+ this.client = new import_sdk.default();
1126
+ }
1127
+ async infer(inferenceRequest) {
1128
+ const response = await this.client.messages.create(this.buildRequest(inferenceRequest));
1129
+ const contextItems = this.extractContextItems(response);
1130
+ const tokenUsage = this.extractTokenUsage(response);
1131
+ return new InferenceResponse(contextItems, tokenUsage);
1132
+ }
1133
+ async *stream(inferenceRequest, signal) {
1134
+ const stream = await this.client.messages.create({
1135
+ ...this.buildRequest(inferenceRequest),
1136
+ stream: true
1137
+ });
1138
+ for await (const event of stream) {
1139
+ if (signal == null ? void 0 : signal.aborted) {
1140
+ break;
1141
+ }
1142
+ yield new SemanticEvent(event.type, event);
1143
+ }
1144
+ }
1145
+ buildRequest(inferenceRequest) {
1146
+ const { messages, system } = this.mapContextToRequest(inferenceRequest.context);
1147
+ const specification = inferenceRequest.model.specification;
1148
+ const request = {
1149
+ model: specification.name,
1150
+ max_tokens: specification.maxOutputTokens,
1151
+ messages
1152
+ };
1153
+ if (system) {
1154
+ request.system = system;
1155
+ }
1156
+ if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
1157
+ request.tools = inferenceRequest.model.getTools().map((tool) => {
1158
+ return {
1159
+ name: tool.name,
1160
+ description: tool.description,
1161
+ input_schema: tool.parameters
1162
+ };
1163
+ });
1164
+ }
1165
+ if (specification.supportReasoningEffort) {
1166
+ const effort = inferenceRequest.model.getReasoningEffort();
1167
+ const budgets = { low: 1024, medium: 4096, high: 8192 };
1168
+ const budget = budgets[effort];
1169
+ if (budget !== void 0) {
1170
+ request.thinking = {
1171
+ type: "enabled",
1172
+ budget_tokens: Math.min(budget, specification.maxOutputTokens - 1)
1173
+ };
1174
+ }
1175
+ }
1176
+ return request;
1177
+ }
1178
+ extractTokenUsage(response) {
1179
+ var _a, _b;
1180
+ if (!response.usage) {
1181
+ return void 0;
1182
+ }
1183
+ return new TokenUsage(
1184
+ response.usage.input_tokens,
1185
+ response.usage.output_tokens,
1186
+ response.usage.input_tokens + response.usage.output_tokens,
1187
+ new InputTokenDetails(
1188
+ ((_a = response.usage.cache_creation_input_tokens) != null ? _a : 0) + ((_b = response.usage.cache_read_input_tokens) != null ? _b : 0)
1189
+ ),
1190
+ new OutputTokenDetails(0)
1191
+ );
1192
+ }
1193
+ mapContextToRequest(context) {
1194
+ const messages = [];
1195
+ const system = [];
1196
+ for (const item of context.getItems()) {
1197
+ if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
1198
+ system.push(item.content.text);
1199
+ continue;
1200
+ }
1201
+ if (item instanceof UserMessageItem) {
1202
+ this.addContentBlock(messages, "user", { type: "text", text: item.content.text });
1203
+ continue;
1204
+ }
1205
+ if (item instanceof ModelMessageItem) {
1206
+ this.addContentBlock(messages, "assistant", { type: "text", text: item.content.text });
1207
+ continue;
1208
+ }
1209
+ if (item instanceof FunctionCallItem) {
1210
+ let input;
1211
+ try {
1212
+ input = JSON.parse(item.args);
1213
+ } catch (e) {
1214
+ input = item.args;
1215
+ }
1216
+ this.addContentBlock(messages, "assistant", {
1217
+ type: "tool_use",
1218
+ id: item.callId,
1219
+ name: item.name,
1220
+ input
1221
+ });
1222
+ continue;
1223
+ }
1224
+ if (item instanceof FunctionCallOutputItem) {
1225
+ this.addContentBlock(messages, "user", {
1226
+ type: "tool_result",
1227
+ tool_use_id: item.callId,
1228
+ content: item.output.text
1229
+ });
1230
+ }
1231
+ }
1232
+ return {
1233
+ messages,
1234
+ system: system.length > 0 ? system.join("\n\n") : void 0
1235
+ };
1236
+ }
1237
+ extractContextItems(response) {
1238
+ var _a;
1239
+ const items = [];
1240
+ for (const block of response.content) {
1241
+ if (block.type === "text") {
1242
+ items.push(ModelMessageItem.rehydrate({ text: block.text }));
1243
+ continue;
1244
+ }
1245
+ if (block.type === "tool_use") {
1246
+ items.push(
1247
+ FunctionCallItem.rehydrate({
1248
+ callId: block.id,
1249
+ name: block.name,
1250
+ args: JSON.stringify((_a = block.input) != null ? _a : {})
1251
+ })
1252
+ );
1253
+ continue;
1254
+ }
1255
+ if (block.type === "thinking") {
1256
+ items.push(
1257
+ ReasoningItem.rehydrate({
1258
+ content: block.thinking ? InputText.rehydrate({ text: block.thinking }) : void 0,
1259
+ encryptedContent: void 0,
1260
+ summary: []
1261
+ })
1262
+ );
1263
+ }
1264
+ }
1265
+ return items;
1266
+ }
1267
+ addContentBlock(messages, role, block) {
1268
+ const lastMessage = messages[messages.length - 1];
1269
+ if ((lastMessage == null ? void 0 : lastMessage.role) === role) {
1270
+ lastMessage.content.push(block);
1271
+ return;
1272
+ }
1273
+ messages.push({
1274
+ role,
1275
+ content: [block]
1276
+ });
1277
+ }
1278
+ };
1279
+
1280
+ // src/infrastructure/providers/anthropic/reasoning-effort.ts
1281
+ var AnthropicReasoningEffort = class {
1282
+ constructor(reasoningEffort) {
1283
+ this.reasoningEffort = reasoningEffort;
1284
+ }
1285
+ setReasoningEffort(effort) {
1286
+ this.reasoningEffort = effort;
1287
+ }
1288
+ getReasoningEffort() {
1289
+ if (!this.reasoningEffort) {
1290
+ throw new Error("Reasoning effort not supported");
1291
+ }
1292
+ return this.reasoningEffort;
1293
+ }
1294
+ };
1295
+
1296
+ // src/infrastructure/providers/anthropic/models/claude-4-8-opus.ts
1297
+ var ClaudeOpus48 = class {
1298
+ constructor() {
1299
+ this.specification = {
1300
+ name: "claude-opus-4-8",
1301
+ supportReasoningEffort: true,
1302
+ defaultReasoningEffort: "none",
1303
+ supportStreaming: true,
1304
+ contextWindowSize: 2e5,
1305
+ maxOutputTokens: 32e3,
1306
+ supportFunctionCalling: true
1307
+ };
1308
+ this.tools = [];
1309
+ this.streaming = false;
1310
+ this.effort = new AnthropicReasoningEffort(
1311
+ this.specification.defaultReasoningEffort
1312
+ );
1313
+ }
1314
+ setStreaming(streaming) {
1315
+ this.streaming = streaming;
1316
+ }
1317
+ getStreaming() {
1318
+ return this.streaming;
1319
+ }
1320
+ setTools(tools) {
1321
+ this.tools = tools;
1322
+ }
1323
+ getTools() {
1324
+ return this.tools;
1325
+ }
1326
+ setReasoningEffort(effort) {
1327
+ this.effort.setReasoningEffort(effort);
1328
+ }
1329
+ getReasoningEffort() {
1330
+ return this.effort.getReasoningEffort();
1331
+ }
1332
+ };
1333
+
1334
+ // src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
1335
+ var ClaudeOpus47 = class {
1336
+ constructor() {
1337
+ this.specification = {
1338
+ name: "claude-opus-4-7",
1339
+ supportReasoningEffort: true,
1340
+ defaultReasoningEffort: "none",
1341
+ supportStreaming: true,
1342
+ contextWindowSize: 2e5,
1343
+ maxOutputTokens: 32e3,
1344
+ supportFunctionCalling: true
1345
+ };
1346
+ this.tools = [];
1347
+ this.streaming = false;
1348
+ this.effort = new AnthropicReasoningEffort(
1349
+ this.specification.defaultReasoningEffort
1350
+ );
1351
+ }
1352
+ setStreaming(streaming) {
1353
+ this.streaming = streaming;
1354
+ }
1355
+ getStreaming() {
1356
+ return this.streaming;
1357
+ }
1358
+ setTools(tools) {
1359
+ this.tools = tools;
1360
+ }
1361
+ getTools() {
1362
+ return this.tools;
1363
+ }
1364
+ setReasoningEffort(effort) {
1365
+ this.effort.setReasoningEffort(effort);
1366
+ }
1367
+ getReasoningEffort() {
1368
+ return this.effort.getReasoningEffort();
1369
+ }
1370
+ };
1371
+
1372
+ // src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts
1373
+ var ClaudeSonnet46 = class {
1374
+ constructor() {
1375
+ this.specification = {
1376
+ name: "claude-sonnet-4-6",
1377
+ supportReasoningEffort: true,
1378
+ defaultReasoningEffort: "none",
1379
+ supportStreaming: true,
1380
+ contextWindowSize: 2e5,
1381
+ maxOutputTokens: 64e3,
1382
+ supportFunctionCalling: true
1383
+ };
1384
+ this.tools = [];
1385
+ this.streaming = false;
1386
+ this.effort = new AnthropicReasoningEffort(
1387
+ this.specification.defaultReasoningEffort
1388
+ );
1389
+ }
1390
+ setStreaming(streaming) {
1391
+ this.streaming = streaming;
1392
+ }
1393
+ getStreaming() {
1394
+ return this.streaming;
1395
+ }
1396
+ setTools(tools) {
1397
+ this.tools = tools;
1398
+ }
1399
+ getTools() {
1400
+ return this.tools;
1401
+ }
1402
+ setReasoningEffort(effort) {
1403
+ this.effort.setReasoningEffort(effort);
1404
+ }
1405
+ getReasoningEffort() {
1406
+ return this.effort.getReasoningEffort();
1407
+ }
1408
+ };
1409
+
1410
+ // src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts
1411
+ var ClaudeHaiku45 = class {
1412
+ constructor() {
1413
+ this.specification = {
1414
+ name: "claude-haiku-4-5",
1415
+ supportReasoningEffort: true,
1416
+ defaultReasoningEffort: "none",
1417
+ supportStreaming: true,
1418
+ contextWindowSize: 2e5,
1419
+ maxOutputTokens: 64e3,
1420
+ supportFunctionCalling: true
1421
+ };
1422
+ this.tools = [];
1423
+ this.streaming = false;
1424
+ this.effort = new AnthropicReasoningEffort(
1425
+ this.specification.defaultReasoningEffort
1426
+ );
1427
+ }
1428
+ setStreaming(streaming) {
1429
+ this.streaming = streaming;
1430
+ }
1431
+ getStreaming() {
1432
+ return this.streaming;
1433
+ }
1434
+ setTools(tools) {
1435
+ this.tools = tools;
1436
+ }
1437
+ getTools() {
1438
+ return this.tools;
1439
+ }
1440
+ setReasoningEffort(effort) {
1441
+ this.effort.setReasoningEffort(effort);
1442
+ }
1443
+ getReasoningEffort() {
1444
+ return this.effort.getReasoningEffort();
1445
+ }
1446
+ };
1447
+
1448
+ // src/infrastructure/providers/deepseek/reasoning-effort.ts
1449
+ var DeepSeekReasoningEffort = class {
1450
+ constructor(reasoningEffort) {
1451
+ this.reasoningEffort = reasoningEffort;
1452
+ }
1453
+ setReasoningEffort(effort) {
1454
+ this.reasoningEffort = effort;
1455
+ }
1456
+ getReasoningEffort() {
1457
+ if (!this.reasoningEffort) {
1458
+ throw new Error("Reasoning effort not supported");
1459
+ }
1460
+ return this.reasoningEffort;
1461
+ }
1462
+ };
1463
+
1464
+ // src/infrastructure/providers/deepseek/models/deepseek-v4-flash.ts
1465
+ var DeepSeekV4Flash = class {
1466
+ constructor() {
1467
+ this.specification = {
1468
+ name: "deepseek-v4-flash",
1469
+ supportReasoningEffort: true,
1470
+ defaultReasoningEffort: "high",
1471
+ supportStreaming: true,
1472
+ contextWindowSize: 1e6,
1473
+ maxOutputTokens: 384e3,
1474
+ supportFunctionCalling: true
1475
+ };
1476
+ this.tools = [];
1477
+ this.streaming = false;
1478
+ this.effort = new DeepSeekReasoningEffort(
1479
+ this.specification.defaultReasoningEffort
1480
+ );
1481
+ }
1482
+ setStreaming(streaming) {
1483
+ this.streaming = streaming;
1484
+ }
1485
+ getStreaming() {
1486
+ return this.streaming;
1487
+ }
1488
+ setTools(tools) {
1489
+ this.tools = tools;
1490
+ }
1491
+ getTools() {
1492
+ return this.tools;
1493
+ }
1494
+ setReasoningEffort(effort) {
1495
+ this.effort.setReasoningEffort(effort);
1496
+ }
1497
+ getReasoningEffort() {
1498
+ return this.effort.getReasoningEffort();
1499
+ }
1500
+ };
1501
+
1502
+ // src/infrastructure/providers/deepseek/models/deepseek-v4-pro.ts
1503
+ var DeepSeekV4Pro = class {
1504
+ constructor() {
1505
+ this.specification = {
1506
+ name: "deepseek-v4-pro",
1507
+ supportReasoningEffort: true,
1508
+ defaultReasoningEffort: "high",
1509
+ supportStreaming: true,
1510
+ contextWindowSize: 1e6,
1511
+ maxOutputTokens: 384e3,
1512
+ supportFunctionCalling: true
1513
+ };
1514
+ this.tools = [];
1515
+ this.streaming = false;
1516
+ this.effort = new DeepSeekReasoningEffort(
1517
+ this.specification.defaultReasoningEffort
1518
+ );
1519
+ }
1520
+ setStreaming(streaming) {
1521
+ this.streaming = streaming;
1522
+ }
1523
+ getStreaming() {
1524
+ return this.streaming;
1525
+ }
1526
+ setTools(tools) {
1527
+ this.tools = tools;
1528
+ }
1529
+ getTools() {
1530
+ return this.tools;
1531
+ }
1532
+ setReasoningEffort(effort) {
1533
+ this.effort.setReasoningEffort(effort);
1534
+ }
1535
+ getReasoningEffort() {
1536
+ return this.effort.getReasoningEffort();
1537
+ }
1538
+ };
1539
+
1540
+ // src/infrastructure/providers/gemini/runtime/gemini-generate-content.ts
1541
+ var import_genai = require("@google/genai");
1542
+ var GeminiGenerateContent = class {
1543
+ constructor() {
1544
+ this.client = new import_genai.GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
1545
+ }
1546
+ async infer(inferenceRequest) {
1547
+ const response = await this.client.models.generateContent(this.buildRequest(inferenceRequest));
1548
+ const contextItems = this.extractContextItems(response);
1549
+ const tokenUsage = this.extractTokenUsage(response);
1550
+ return new InferenceResponse(contextItems, tokenUsage);
1551
+ }
1552
+ async *stream(inferenceRequest, signal) {
1553
+ const stream = await this.client.models.generateContentStream(this.buildRequest(inferenceRequest));
1554
+ for await (const chunk of stream) {
1555
+ if (signal == null ? void 0 : signal.aborted) {
1556
+ break;
1557
+ }
1558
+ yield new SemanticEvent("generate_content_chunk", chunk);
1559
+ }
1560
+ }
1561
+ buildRequest(inferenceRequest) {
1562
+ const specification = inferenceRequest.model.specification;
1563
+ const { contents, systemInstruction } = this.mapContextToRequest(inferenceRequest.context);
1564
+ const config = {};
1565
+ if (systemInstruction) {
1566
+ config.systemInstruction = systemInstruction;
1567
+ }
1568
+ if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
1569
+ config.tools = [
1570
+ {
1571
+ functionDeclarations: inferenceRequest.model.getTools().map((tool) => {
1572
+ return {
1573
+ name: tool.name,
1574
+ description: tool.description,
1575
+ parametersJsonSchema: tool.parameters
1576
+ };
1577
+ })
1578
+ }
1579
+ ];
1580
+ }
1581
+ if (specification.supportReasoningEffort) {
1582
+ const effort = inferenceRequest.model.getReasoningEffort();
1583
+ const thinkingLevel = effort === "none" ? "minimal" : effort;
1584
+ config.thinkingConfig = { thinkingLevel, includeThoughts: true };
1585
+ }
1586
+ return { model: specification.name, contents, config };
1587
+ }
1588
+ extractTokenUsage(response) {
1589
+ var _a, _b, _c, _d, _e;
1590
+ const usage = response.usageMetadata;
1591
+ if (!usage) {
1592
+ return void 0;
1593
+ }
1594
+ return new TokenUsage(
1595
+ (_a = usage.promptTokenCount) != null ? _a : 0,
1596
+ (_b = usage.candidatesTokenCount) != null ? _b : 0,
1597
+ (_c = usage.totalTokenCount) != null ? _c : 0,
1598
+ new InputTokenDetails((_d = usage.cachedContentTokenCount) != null ? _d : 0),
1599
+ new OutputTokenDetails((_e = usage.thoughtsTokenCount) != null ? _e : 0)
1600
+ );
1601
+ }
1602
+ mapContextToRequest(context) {
1603
+ var _a;
1604
+ const contents = [];
1605
+ const system = [];
1606
+ const callNames = /* @__PURE__ */ new Map();
1607
+ for (const item of context.getItems()) {
1608
+ if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
1609
+ system.push(item.content.text);
1610
+ continue;
1611
+ }
1612
+ if (item instanceof UserMessageItem) {
1613
+ this.addPart(contents, "user", { text: item.content.text });
1614
+ continue;
1615
+ }
1616
+ if (item instanceof ModelMessageItem) {
1617
+ this.addPart(contents, "model", { text: item.content.text });
1618
+ continue;
1619
+ }
1620
+ if (item instanceof FunctionCallItem) {
1621
+ callNames.set(item.callId, item.name);
1622
+ let args;
1623
+ try {
1624
+ args = JSON.parse(item.args);
1625
+ } catch (e) {
1626
+ args = {};
1627
+ }
1628
+ this.addPart(contents, "model", { functionCall: { id: item.callId, name: item.name, args } });
1629
+ continue;
1630
+ }
1631
+ if (item instanceof FunctionCallOutputItem) {
1632
+ this.addPart(contents, "user", {
1633
+ functionResponse: {
1634
+ id: item.callId,
1635
+ name: (_a = callNames.get(item.callId)) != null ? _a : "",
1636
+ response: this.parseResponse(item.output.text)
1637
+ }
1638
+ });
1639
+ }
1640
+ }
1641
+ return {
1642
+ contents,
1643
+ systemInstruction: system.length > 0 ? system.join("\n\n") : void 0
1644
+ };
1645
+ }
1646
+ extractContextItems(response) {
1647
+ var _a, _b, _c, _d, _e, _f;
1648
+ const items = [];
1649
+ const parts = (_d = (_c = (_b = (_a = response.candidates) == null ? void 0 : _a[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts) != null ? _d : [];
1650
+ for (const part of parts) {
1651
+ if (part.thought && part.text) {
1652
+ items.push(
1653
+ ReasoningItem.rehydrate({
1654
+ content: InputText.rehydrate({ text: part.text }),
1655
+ encryptedContent: void 0,
1656
+ summary: []
1657
+ })
1658
+ );
1659
+ continue;
1660
+ }
1661
+ if (part.text) {
1662
+ items.push(ModelMessageItem.rehydrate({ text: part.text }));
1663
+ continue;
1664
+ }
1665
+ if (part.functionCall) {
1666
+ items.push(
1667
+ FunctionCallItem.rehydrate({
1668
+ callId: (_e = part.functionCall.id) != null ? _e : "",
1669
+ name: part.functionCall.name,
1670
+ args: JSON.stringify((_f = part.functionCall.args) != null ? _f : {})
1671
+ })
1672
+ );
1673
+ }
1674
+ }
1675
+ return items;
1676
+ }
1677
+ parseResponse(output) {
1678
+ try {
1679
+ const parsed = JSON.parse(output);
1680
+ return parsed && typeof parsed === "object" ? parsed : { output };
1681
+ } catch (e) {
1682
+ return { output };
1683
+ }
1684
+ }
1685
+ addPart(contents, role, part) {
1686
+ const last = contents[contents.length - 1];
1687
+ if ((last == null ? void 0 : last.role) === role) {
1688
+ last.parts.push(part);
1689
+ return;
1690
+ }
1691
+ contents.push({ role, parts: [part] });
1692
+ }
1693
+ };
1694
+
1695
+ // src/infrastructure/providers/gemini/reasoning-effort.ts
1696
+ var GeminiReasoningEffort = class {
1697
+ constructor(reasoningEffort) {
1698
+ this.reasoningEffort = reasoningEffort;
1699
+ }
1700
+ setReasoningEffort(effort) {
1701
+ this.reasoningEffort = effort;
1702
+ }
1703
+ getReasoningEffort() {
1704
+ if (!this.reasoningEffort) {
1705
+ throw new Error("Reasoning effort not supported");
1706
+ }
1707
+ return this.reasoningEffort;
1708
+ }
1709
+ };
1710
+
1711
+ // src/infrastructure/providers/gemini/models/gemini-3-5-flash.ts
1712
+ var Gemini35Flash = class {
1713
+ constructor() {
1714
+ this.specification = {
1715
+ name: "gemini-3.5-flash",
1716
+ supportReasoningEffort: true,
1717
+ defaultReasoningEffort: "medium",
1718
+ supportStreaming: true,
1719
+ contextWindowSize: 1048576,
1720
+ maxOutputTokens: 64e3,
1721
+ supportFunctionCalling: true
1722
+ };
1723
+ this.tools = [];
1724
+ this.streaming = false;
1725
+ this.effort = new GeminiReasoningEffort(
1726
+ this.specification.defaultReasoningEffort
1727
+ );
1728
+ }
1729
+ setStreaming(streaming) {
1730
+ this.streaming = streaming;
1731
+ }
1732
+ getStreaming() {
1733
+ return this.streaming;
1734
+ }
1735
+ setTools(tools) {
1736
+ this.tools = tools;
1737
+ }
1738
+ getTools() {
1739
+ return this.tools;
1740
+ }
1741
+ setReasoningEffort(effort) {
1742
+ this.effort.setReasoningEffort(effort);
1743
+ }
1744
+ getReasoningEffort() {
1745
+ return this.effort.getReasoningEffort();
1746
+ }
1747
+ };
1748
+
1749
+ // src/infrastructure/providers/gemini/models/gemini-3-1-pro.ts
1750
+ var Gemini31Pro = class {
1751
+ constructor() {
1752
+ this.specification = {
1753
+ name: "gemini-3.1-pro-preview",
1754
+ supportReasoningEffort: true,
1755
+ defaultReasoningEffort: "high",
1756
+ supportStreaming: true,
1757
+ contextWindowSize: 1048576,
1758
+ maxOutputTokens: 64e3,
1759
+ supportFunctionCalling: true
1760
+ };
1761
+ this.tools = [];
1762
+ this.streaming = false;
1763
+ this.effort = new GeminiReasoningEffort(
1764
+ this.specification.defaultReasoningEffort
1765
+ );
1766
+ }
1767
+ setStreaming(streaming) {
1768
+ this.streaming = streaming;
1769
+ }
1770
+ getStreaming() {
1771
+ return this.streaming;
1772
+ }
1773
+ setTools(tools) {
1774
+ this.tools = tools;
1775
+ }
1776
+ getTools() {
1777
+ return this.tools;
1778
+ }
1779
+ setReasoningEffort(effort) {
1780
+ this.effort.setReasoningEffort(effort);
1781
+ }
1782
+ getReasoningEffort() {
1783
+ return this.effort.getReasoningEffort();
1784
+ }
1785
+ };
923
1786
  // Annotate the CommonJS export names for ESM import in node:
924
1787
  0 && (module.exports = {
925
1788
  Agent,
926
1789
  AgenticEnvironment,
1790
+ AnthropicMessages,
927
1791
  BaseAgent,
928
1792
  BaseHuman,
929
1793
  BaseObserver,
1794
+ ClaudeHaiku45,
1795
+ ClaudeOpus47,
1796
+ ClaudeOpus48,
1797
+ ClaudeSonnet46,
930
1798
  ContextItem,
1799
+ DeepSeekV4Flash,
1800
+ DeepSeekV4Pro,
931
1801
  DefaultFunctionCallRunner,
1802
+ DefaultInferenceRunner,
932
1803
  DeveloperMessageItem,
933
1804
  FunctionCallItem,
934
1805
  FunctionCallOutputItem,
1806
+ Gemini31Pro,
1807
+ Gemini35Flash,
1808
+ GeminiGenerateContent,
935
1809
  Gpt54,
936
1810
  Gpt54Mini,
937
1811
  Gpt54Nano,
938
1812
  Gpt55,
939
1813
  Human,
940
1814
  InMemoryModelContextRepository,
1815
+ InferenceRequest,
1816
+ InferenceResponse,
941
1817
  InputTokenDetails,
942
1818
  ModelContext,
943
1819
  ModelMessageItem,
944
1820
  Observer,
945
- OpenAIInferenceRunner,
1821
+ OpenAICompatibleChatCompletions,
1822
+ OpenAIResponses,
946
1823
  OutputTokenDetails,
947
1824
  Participant,
948
1825
  ReasoningItem,