@mozaik-ai/core 3.11.0 → 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.d.mts +214 -15
- package/dist/index.d.ts +214 -15
- package/dist/index.js +593 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +585 -45
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -1
package/dist/index.js
CHANGED
|
@@ -38,12 +38,19 @@ __export(index_exports, {
|
|
|
38
38
|
BaseObserver: () => BaseObserver,
|
|
39
39
|
ClaudeHaiku45: () => ClaudeHaiku45,
|
|
40
40
|
ClaudeOpus47: () => ClaudeOpus47,
|
|
41
|
+
ClaudeOpus48: () => ClaudeOpus48,
|
|
41
42
|
ClaudeSonnet46: () => ClaudeSonnet46,
|
|
42
43
|
ContextItem: () => ContextItem,
|
|
44
|
+
DeepSeekV4Flash: () => DeepSeekV4Flash,
|
|
45
|
+
DeepSeekV4Pro: () => DeepSeekV4Pro,
|
|
43
46
|
DefaultFunctionCallRunner: () => DefaultFunctionCallRunner,
|
|
47
|
+
DefaultInferenceRunner: () => DefaultInferenceRunner,
|
|
44
48
|
DeveloperMessageItem: () => DeveloperMessageItem,
|
|
45
49
|
FunctionCallItem: () => FunctionCallItem,
|
|
46
50
|
FunctionCallOutputItem: () => FunctionCallOutputItem,
|
|
51
|
+
Gemini31Pro: () => Gemini31Pro,
|
|
52
|
+
Gemini35Flash: () => Gemini35Flash,
|
|
53
|
+
GeminiGenerateContent: () => GeminiGenerateContent,
|
|
47
54
|
Gpt54: () => Gpt54,
|
|
48
55
|
Gpt54Mini: () => Gpt54Mini,
|
|
49
56
|
Gpt54Nano: () => Gpt54Nano,
|
|
@@ -56,7 +63,7 @@ __export(index_exports, {
|
|
|
56
63
|
ModelContext: () => ModelContext,
|
|
57
64
|
ModelMessageItem: () => ModelMessageItem,
|
|
58
65
|
Observer: () => Observer,
|
|
59
|
-
|
|
66
|
+
OpenAICompatibleChatCompletions: () => OpenAICompatibleChatCompletions,
|
|
60
67
|
OpenAIResponses: () => OpenAIResponses,
|
|
61
68
|
OutputTokenDetails: () => OutputTokenDetails,
|
|
62
69
|
Participant: () => Participant,
|
|
@@ -333,10 +340,10 @@ var Gpt54Nano = class {
|
|
|
333
340
|
supportFunctionCalling: true
|
|
334
341
|
};
|
|
335
342
|
this.tools = [];
|
|
343
|
+
this.streaming = false;
|
|
336
344
|
this.effort = new OpenAIReasoningEffort(
|
|
337
345
|
this.specification.defaultReasoningEffort
|
|
338
346
|
);
|
|
339
|
-
this.streaming = false;
|
|
340
347
|
}
|
|
341
348
|
setStreaming(streaming) {
|
|
342
349
|
this.streaming = streaming;
|
|
@@ -409,10 +416,10 @@ var Gpt54Mini = class {
|
|
|
409
416
|
supportFunctionCalling: true
|
|
410
417
|
};
|
|
411
418
|
this.tools = [];
|
|
419
|
+
this.streaming = false;
|
|
412
420
|
this.effort = new OpenAIReasoningEffort(
|
|
413
421
|
this.specification.defaultReasoningEffort
|
|
414
422
|
);
|
|
415
|
-
this.streaming = false;
|
|
416
423
|
}
|
|
417
424
|
setStreaming(streaming) {
|
|
418
425
|
this.streaming = streaming;
|
|
@@ -526,6 +533,7 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
|
|
|
526
533
|
var Participant = class {
|
|
527
534
|
constructor() {
|
|
528
535
|
this.environments = [];
|
|
536
|
+
this.listens = [];
|
|
529
537
|
}
|
|
530
538
|
join(environment) {
|
|
531
539
|
if (this.isJoinedTo(environment)) {
|
|
@@ -547,13 +555,17 @@ var Participant = class {
|
|
|
547
555
|
getEnvironments() {
|
|
548
556
|
return this.environments;
|
|
549
557
|
}
|
|
558
|
+
getListeners() {
|
|
559
|
+
return this.listens;
|
|
560
|
+
}
|
|
550
561
|
};
|
|
551
562
|
|
|
552
563
|
// src/domain/agentic-environment/agentic-environment.ts
|
|
553
564
|
var AgenticEnvironment = class {
|
|
554
|
-
constructor() {
|
|
565
|
+
constructor(name) {
|
|
555
566
|
this.subscribers = [];
|
|
556
567
|
this.isActive = false;
|
|
568
|
+
this.name = name;
|
|
557
569
|
}
|
|
558
570
|
subscribe(participant) {
|
|
559
571
|
this.subscribers.push(participant);
|
|
@@ -577,53 +589,53 @@ var AgenticEnvironment = class {
|
|
|
577
589
|
}
|
|
578
590
|
}
|
|
579
591
|
deliverFunctionCall(source, item) {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
subscriber.onExternalFunctionCall(source, item);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
592
|
+
this.deliverToSubscribers(source, {
|
|
593
|
+
internal: (src) => src.onFunctionCall(item),
|
|
594
|
+
external: (sub) => sub.onExternalFunctionCall(source, item)
|
|
595
|
+
});
|
|
587
596
|
}
|
|
588
597
|
deliverModelMessage(source, item) {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
subscriber.onExternalModelMessage(source, item);
|
|
594
|
-
}
|
|
595
|
-
}
|
|
598
|
+
this.deliverToSubscribers(source, {
|
|
599
|
+
internal: (src) => src.onModelMessage(item),
|
|
600
|
+
external: (sub) => sub.onExternalModelMessage(source, item)
|
|
601
|
+
});
|
|
596
602
|
}
|
|
597
603
|
deliverReasoning(source, item) {
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
subscriber.onExternalReasoning(source, item);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
604
|
+
this.deliverToSubscribers(source, {
|
|
605
|
+
internal: (src) => src.onReasoning(item),
|
|
606
|
+
external: (sub) => sub.onExternalReasoning(source, item)
|
|
607
|
+
});
|
|
605
608
|
}
|
|
606
609
|
deliverFunctionCallOutput(source, item) {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
subscriber.onExternalFunctionCallOutput(source, item);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
610
|
+
this.deliverToSubscribers(source, {
|
|
611
|
+
internal: (src) => src.onFunctionCallOutput(item),
|
|
612
|
+
external: (sub) => sub.onExternalFunctionCallOutput(source, item)
|
|
613
|
+
});
|
|
614
614
|
}
|
|
615
615
|
deliverMessage(source, message) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
}
|
|
616
|
+
this.deliverToSubscribers(source, {
|
|
617
|
+
external: (sub) => sub.onMessage(message)
|
|
618
|
+
});
|
|
620
619
|
}
|
|
621
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);
|
|
622
634
|
for (const subscriber of this.subscribers) {
|
|
623
635
|
if (subscriber === source) {
|
|
624
|
-
|
|
625
|
-
} else {
|
|
626
|
-
|
|
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);
|
|
627
639
|
}
|
|
628
640
|
}
|
|
629
641
|
}
|
|
@@ -764,8 +776,8 @@ var InferenceRequest = class {
|
|
|
764
776
|
}
|
|
765
777
|
};
|
|
766
778
|
|
|
767
|
-
// src/application/runners/
|
|
768
|
-
var
|
|
779
|
+
// src/application/runners/inference-runner.ts
|
|
780
|
+
var DefaultInferenceRunner = class {
|
|
769
781
|
constructor(runtime) {
|
|
770
782
|
this.runtime = runtime;
|
|
771
783
|
}
|
|
@@ -970,6 +982,142 @@ var OpenAIResponses = class {
|
|
|
970
982
|
}
|
|
971
983
|
};
|
|
972
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
|
+
|
|
973
1121
|
// src/infrastructure/providers/anthropic/runtime/anthropic-messages.ts
|
|
974
1122
|
var import_sdk = __toESM(require("@anthropic-ai/sdk"));
|
|
975
1123
|
var AnthropicMessages = class {
|
|
@@ -977,6 +1125,24 @@ var AnthropicMessages = class {
|
|
|
977
1125
|
this.client = new import_sdk.default();
|
|
978
1126
|
}
|
|
979
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) {
|
|
980
1146
|
const { messages, system } = this.mapContextToRequest(inferenceRequest.context);
|
|
981
1147
|
const specification = inferenceRequest.model.specification;
|
|
982
1148
|
const request = {
|
|
@@ -1007,10 +1173,7 @@ var AnthropicMessages = class {
|
|
|
1007
1173
|
};
|
|
1008
1174
|
}
|
|
1009
1175
|
}
|
|
1010
|
-
|
|
1011
|
-
const contextItems = this.extractContextItems(response);
|
|
1012
|
-
const tokenUsage = this.extractTokenUsage(response);
|
|
1013
|
-
return new InferenceResponse(contextItems, tokenUsage);
|
|
1176
|
+
return request;
|
|
1014
1177
|
}
|
|
1015
1178
|
extractTokenUsage(response) {
|
|
1016
1179
|
var _a, _b;
|
|
@@ -1130,6 +1293,44 @@ var AnthropicReasoningEffort = class {
|
|
|
1130
1293
|
}
|
|
1131
1294
|
};
|
|
1132
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
|
+
|
|
1133
1334
|
// src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
|
|
1134
1335
|
var ClaudeOpus47 = class {
|
|
1135
1336
|
constructor() {
|
|
@@ -1243,6 +1444,345 @@ var ClaudeHaiku45 = class {
|
|
|
1243
1444
|
return this.effort.getReasoningEffort();
|
|
1244
1445
|
}
|
|
1245
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
|
+
};
|
|
1246
1786
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1247
1787
|
0 && (module.exports = {
|
|
1248
1788
|
Agent,
|
|
@@ -1253,12 +1793,19 @@ var ClaudeHaiku45 = class {
|
|
|
1253
1793
|
BaseObserver,
|
|
1254
1794
|
ClaudeHaiku45,
|
|
1255
1795
|
ClaudeOpus47,
|
|
1796
|
+
ClaudeOpus48,
|
|
1256
1797
|
ClaudeSonnet46,
|
|
1257
1798
|
ContextItem,
|
|
1799
|
+
DeepSeekV4Flash,
|
|
1800
|
+
DeepSeekV4Pro,
|
|
1258
1801
|
DefaultFunctionCallRunner,
|
|
1802
|
+
DefaultInferenceRunner,
|
|
1259
1803
|
DeveloperMessageItem,
|
|
1260
1804
|
FunctionCallItem,
|
|
1261
1805
|
FunctionCallOutputItem,
|
|
1806
|
+
Gemini31Pro,
|
|
1807
|
+
Gemini35Flash,
|
|
1808
|
+
GeminiGenerateContent,
|
|
1262
1809
|
Gpt54,
|
|
1263
1810
|
Gpt54Mini,
|
|
1264
1811
|
Gpt54Nano,
|
|
@@ -1271,7 +1818,7 @@ var ClaudeHaiku45 = class {
|
|
|
1271
1818
|
ModelContext,
|
|
1272
1819
|
ModelMessageItem,
|
|
1273
1820
|
Observer,
|
|
1274
|
-
|
|
1821
|
+
OpenAICompatibleChatCompletions,
|
|
1275
1822
|
OpenAIResponses,
|
|
1276
1823
|
OutputTokenDetails,
|
|
1277
1824
|
Participant,
|