@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.mjs
CHANGED
|
@@ -263,10 +263,10 @@ var Gpt54Nano = class {
|
|
|
263
263
|
supportFunctionCalling: true
|
|
264
264
|
};
|
|
265
265
|
this.tools = [];
|
|
266
|
+
this.streaming = false;
|
|
266
267
|
this.effort = new OpenAIReasoningEffort(
|
|
267
268
|
this.specification.defaultReasoningEffort
|
|
268
269
|
);
|
|
269
|
-
this.streaming = false;
|
|
270
270
|
}
|
|
271
271
|
setStreaming(streaming) {
|
|
272
272
|
this.streaming = streaming;
|
|
@@ -339,10 +339,10 @@ var Gpt54Mini = class {
|
|
|
339
339
|
supportFunctionCalling: true
|
|
340
340
|
};
|
|
341
341
|
this.tools = [];
|
|
342
|
+
this.streaming = false;
|
|
342
343
|
this.effort = new OpenAIReasoningEffort(
|
|
343
344
|
this.specification.defaultReasoningEffort
|
|
344
345
|
);
|
|
345
|
-
this.streaming = false;
|
|
346
346
|
}
|
|
347
347
|
setStreaming(streaming) {
|
|
348
348
|
this.streaming = streaming;
|
|
@@ -456,6 +456,7 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
|
|
|
456
456
|
var Participant = class {
|
|
457
457
|
constructor() {
|
|
458
458
|
this.environments = [];
|
|
459
|
+
this.listens = [];
|
|
459
460
|
}
|
|
460
461
|
join(environment) {
|
|
461
462
|
if (this.isJoinedTo(environment)) {
|
|
@@ -477,13 +478,17 @@ var Participant = class {
|
|
|
477
478
|
getEnvironments() {
|
|
478
479
|
return this.environments;
|
|
479
480
|
}
|
|
481
|
+
getListeners() {
|
|
482
|
+
return this.listens;
|
|
483
|
+
}
|
|
480
484
|
};
|
|
481
485
|
|
|
482
486
|
// src/domain/agentic-environment/agentic-environment.ts
|
|
483
487
|
var AgenticEnvironment = class {
|
|
484
|
-
constructor() {
|
|
488
|
+
constructor(name) {
|
|
485
489
|
this.subscribers = [];
|
|
486
490
|
this.isActive = false;
|
|
491
|
+
this.name = name;
|
|
487
492
|
}
|
|
488
493
|
subscribe(participant) {
|
|
489
494
|
this.subscribers.push(participant);
|
|
@@ -507,53 +512,53 @@ var AgenticEnvironment = class {
|
|
|
507
512
|
}
|
|
508
513
|
}
|
|
509
514
|
deliverFunctionCall(source, item) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
subscriber.onExternalFunctionCall(source, item);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
515
|
+
this.deliverToSubscribers(source, {
|
|
516
|
+
internal: (src) => src.onFunctionCall(item),
|
|
517
|
+
external: (sub) => sub.onExternalFunctionCall(source, item)
|
|
518
|
+
});
|
|
517
519
|
}
|
|
518
520
|
deliverModelMessage(source, item) {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
subscriber.onExternalModelMessage(source, item);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
521
|
+
this.deliverToSubscribers(source, {
|
|
522
|
+
internal: (src) => src.onModelMessage(item),
|
|
523
|
+
external: (sub) => sub.onExternalModelMessage(source, item)
|
|
524
|
+
});
|
|
526
525
|
}
|
|
527
526
|
deliverReasoning(source, item) {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
subscriber.onExternalReasoning(source, item);
|
|
533
|
-
}
|
|
534
|
-
}
|
|
527
|
+
this.deliverToSubscribers(source, {
|
|
528
|
+
internal: (src) => src.onReasoning(item),
|
|
529
|
+
external: (sub) => sub.onExternalReasoning(source, item)
|
|
530
|
+
});
|
|
535
531
|
}
|
|
536
532
|
deliverFunctionCallOutput(source, item) {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
subscriber.onExternalFunctionCallOutput(source, item);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
533
|
+
this.deliverToSubscribers(source, {
|
|
534
|
+
internal: (src) => src.onFunctionCallOutput(item),
|
|
535
|
+
external: (sub) => sub.onExternalFunctionCallOutput(source, item)
|
|
536
|
+
});
|
|
544
537
|
}
|
|
545
538
|
deliverMessage(source, message) {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
539
|
+
this.deliverToSubscribers(source, {
|
|
540
|
+
external: (sub) => sub.onMessage(message)
|
|
541
|
+
});
|
|
550
542
|
}
|
|
551
543
|
deliverSemanticEvent(source, item) {
|
|
544
|
+
this.deliverToSubscribers(source, {
|
|
545
|
+
internal: (src) => src.onInternalEvent(item),
|
|
546
|
+
external: (sub) => sub.onExternalEvent(source, item)
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
getListeningParticipants(source) {
|
|
550
|
+
return this.subscribers.filter(
|
|
551
|
+
(sub) => sub !== source && (sub.getListeners().length === 0 || sub.getListeners().some((listener) => source instanceof listener))
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
deliverToSubscribers(source, handlers) {
|
|
555
|
+
var _a, _b;
|
|
556
|
+
const authorizedListeners = this.getListeningParticipants(source);
|
|
552
557
|
for (const subscriber of this.subscribers) {
|
|
553
558
|
if (subscriber === source) {
|
|
554
|
-
|
|
555
|
-
} else {
|
|
556
|
-
|
|
559
|
+
(_a = handlers == null ? void 0 : handlers.internal) == null ? void 0 : _a.call(handlers, subscriber);
|
|
560
|
+
} else if (authorizedListeners.includes(subscriber)) {
|
|
561
|
+
(_b = handlers == null ? void 0 : handlers.external) == null ? void 0 : _b.call(handlers, subscriber);
|
|
557
562
|
}
|
|
558
563
|
}
|
|
559
564
|
}
|
|
@@ -694,8 +699,8 @@ var InferenceRequest = class {
|
|
|
694
699
|
}
|
|
695
700
|
};
|
|
696
701
|
|
|
697
|
-
// src/application/runners/
|
|
698
|
-
var
|
|
702
|
+
// src/application/runners/inference-runner.ts
|
|
703
|
+
var DefaultInferenceRunner = class {
|
|
699
704
|
constructor(runtime) {
|
|
700
705
|
this.runtime = runtime;
|
|
701
706
|
}
|
|
@@ -900,6 +905,142 @@ var OpenAIResponses = class {
|
|
|
900
905
|
}
|
|
901
906
|
};
|
|
902
907
|
|
|
908
|
+
// src/infrastructure/providers/openai/runtime/openai-compatible-chat-completions.ts
|
|
909
|
+
import OpenAI2 from "openai";
|
|
910
|
+
var OpenAICompatibleChatCompletions = class {
|
|
911
|
+
constructor(config = {}) {
|
|
912
|
+
var _a;
|
|
913
|
+
this.client = new OpenAI2({
|
|
914
|
+
baseURL: config.baseURL,
|
|
915
|
+
apiKey: config.apiKey
|
|
916
|
+
});
|
|
917
|
+
this.extraBody = (_a = config.extraBody) != null ? _a : {};
|
|
918
|
+
}
|
|
919
|
+
async infer(inferenceRequest) {
|
|
920
|
+
const response = await this.client.chat.completions.create(this.buildRequest(inferenceRequest));
|
|
921
|
+
const contextItems = this.extractContextItems(response);
|
|
922
|
+
const tokenUsage = this.extractTokenUsage(response);
|
|
923
|
+
return new InferenceResponse(contextItems, tokenUsage);
|
|
924
|
+
}
|
|
925
|
+
async *stream(inferenceRequest, signal) {
|
|
926
|
+
var _a;
|
|
927
|
+
const stream = await this.client.chat.completions.create({
|
|
928
|
+
...this.buildRequest(inferenceRequest),
|
|
929
|
+
stream: true
|
|
930
|
+
});
|
|
931
|
+
for await (const event of stream) {
|
|
932
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
933
|
+
break;
|
|
934
|
+
}
|
|
935
|
+
yield new SemanticEvent((_a = event.object) != null ? _a : "chat.completion.chunk", event);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
buildRequest(inferenceRequest) {
|
|
939
|
+
const specification = inferenceRequest.model.specification;
|
|
940
|
+
const request = {
|
|
941
|
+
...this.extraBody,
|
|
942
|
+
model: specification.name,
|
|
943
|
+
messages: this.mapContextToRequest(inferenceRequest.context)
|
|
944
|
+
};
|
|
945
|
+
if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
|
|
946
|
+
request.tools = inferenceRequest.model.getTools().map((tool) => {
|
|
947
|
+
return {
|
|
948
|
+
type: "function",
|
|
949
|
+
function: {
|
|
950
|
+
name: tool.name,
|
|
951
|
+
description: tool.description,
|
|
952
|
+
parameters: tool.parameters
|
|
953
|
+
}
|
|
954
|
+
};
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
if (specification.supportReasoningEffort) {
|
|
958
|
+
request.reasoning_effort = inferenceRequest.model.getReasoningEffort();
|
|
959
|
+
}
|
|
960
|
+
return request;
|
|
961
|
+
}
|
|
962
|
+
extractTokenUsage(response) {
|
|
963
|
+
var _a, _b, _c, _d;
|
|
964
|
+
if (!response.usage) {
|
|
965
|
+
return void 0;
|
|
966
|
+
}
|
|
967
|
+
return new TokenUsage(
|
|
968
|
+
response.usage.prompt_tokens,
|
|
969
|
+
response.usage.completion_tokens,
|
|
970
|
+
response.usage.total_tokens,
|
|
971
|
+
new InputTokenDetails((_b = (_a = response.usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
|
|
972
|
+
new OutputTokenDetails((_d = (_c = response.usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
|
|
973
|
+
);
|
|
974
|
+
}
|
|
975
|
+
mapContextToRequest(context) {
|
|
976
|
+
var _a;
|
|
977
|
+
const messages = [];
|
|
978
|
+
for (const item of context.getItems()) {
|
|
979
|
+
if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
|
|
980
|
+
messages.push({ role: "system", content: item.content.text });
|
|
981
|
+
continue;
|
|
982
|
+
}
|
|
983
|
+
if (item instanceof UserMessageItem) {
|
|
984
|
+
messages.push({ role: "user", content: item.content.text });
|
|
985
|
+
continue;
|
|
986
|
+
}
|
|
987
|
+
if (item instanceof ModelMessageItem) {
|
|
988
|
+
messages.push({ role: "assistant", content: item.content.text });
|
|
989
|
+
continue;
|
|
990
|
+
}
|
|
991
|
+
if (item instanceof FunctionCallItem) {
|
|
992
|
+
const toolCall = {
|
|
993
|
+
id: item.callId,
|
|
994
|
+
type: "function",
|
|
995
|
+
function: { name: item.name, arguments: item.args }
|
|
996
|
+
};
|
|
997
|
+
const last = messages[messages.length - 1];
|
|
998
|
+
if ((last == null ? void 0 : last.role) === "assistant") {
|
|
999
|
+
last.tool_calls = (_a = last.tool_calls) != null ? _a : [];
|
|
1000
|
+
last.tool_calls.push(toolCall);
|
|
1001
|
+
} else {
|
|
1002
|
+
messages.push({ role: "assistant", content: null, tool_calls: [toolCall] });
|
|
1003
|
+
}
|
|
1004
|
+
continue;
|
|
1005
|
+
}
|
|
1006
|
+
if (item instanceof FunctionCallOutputItem) {
|
|
1007
|
+
messages.push({ role: "tool", tool_call_id: item.callId, content: item.output.text });
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
return messages;
|
|
1011
|
+
}
|
|
1012
|
+
extractContextItems(response) {
|
|
1013
|
+
var _a, _b, _c;
|
|
1014
|
+
const items = [];
|
|
1015
|
+
const message = (_b = (_a = response.choices) == null ? void 0 : _a[0]) == null ? void 0 : _b.message;
|
|
1016
|
+
if (!message) {
|
|
1017
|
+
return items;
|
|
1018
|
+
}
|
|
1019
|
+
if (message.reasoning_content) {
|
|
1020
|
+
items.push(
|
|
1021
|
+
ReasoningItem.rehydrate({
|
|
1022
|
+
content: InputText.rehydrate({ text: message.reasoning_content }),
|
|
1023
|
+
encryptedContent: void 0,
|
|
1024
|
+
summary: []
|
|
1025
|
+
})
|
|
1026
|
+
);
|
|
1027
|
+
}
|
|
1028
|
+
if (message.content) {
|
|
1029
|
+
items.push(ModelMessageItem.rehydrate({ text: message.content }));
|
|
1030
|
+
}
|
|
1031
|
+
for (const toolCall of (_c = message.tool_calls) != null ? _c : []) {
|
|
1032
|
+
items.push(
|
|
1033
|
+
FunctionCallItem.rehydrate({
|
|
1034
|
+
callId: toolCall.id,
|
|
1035
|
+
name: toolCall.function.name,
|
|
1036
|
+
args: toolCall.function.arguments
|
|
1037
|
+
})
|
|
1038
|
+
);
|
|
1039
|
+
}
|
|
1040
|
+
return items;
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
|
|
903
1044
|
// src/infrastructure/providers/anthropic/runtime/anthropic-messages.ts
|
|
904
1045
|
import Anthropic from "@anthropic-ai/sdk";
|
|
905
1046
|
var AnthropicMessages = class {
|
|
@@ -907,6 +1048,24 @@ var AnthropicMessages = class {
|
|
|
907
1048
|
this.client = new Anthropic();
|
|
908
1049
|
}
|
|
909
1050
|
async infer(inferenceRequest) {
|
|
1051
|
+
const response = await this.client.messages.create(this.buildRequest(inferenceRequest));
|
|
1052
|
+
const contextItems = this.extractContextItems(response);
|
|
1053
|
+
const tokenUsage = this.extractTokenUsage(response);
|
|
1054
|
+
return new InferenceResponse(contextItems, tokenUsage);
|
|
1055
|
+
}
|
|
1056
|
+
async *stream(inferenceRequest, signal) {
|
|
1057
|
+
const stream = await this.client.messages.create({
|
|
1058
|
+
...this.buildRequest(inferenceRequest),
|
|
1059
|
+
stream: true
|
|
1060
|
+
});
|
|
1061
|
+
for await (const event of stream) {
|
|
1062
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1063
|
+
break;
|
|
1064
|
+
}
|
|
1065
|
+
yield new SemanticEvent(event.type, event);
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
buildRequest(inferenceRequest) {
|
|
910
1069
|
const { messages, system } = this.mapContextToRequest(inferenceRequest.context);
|
|
911
1070
|
const specification = inferenceRequest.model.specification;
|
|
912
1071
|
const request = {
|
|
@@ -937,10 +1096,7 @@ var AnthropicMessages = class {
|
|
|
937
1096
|
};
|
|
938
1097
|
}
|
|
939
1098
|
}
|
|
940
|
-
|
|
941
|
-
const contextItems = this.extractContextItems(response);
|
|
942
|
-
const tokenUsage = this.extractTokenUsage(response);
|
|
943
|
-
return new InferenceResponse(contextItems, tokenUsage);
|
|
1099
|
+
return request;
|
|
944
1100
|
}
|
|
945
1101
|
extractTokenUsage(response) {
|
|
946
1102
|
var _a, _b;
|
|
@@ -1060,6 +1216,44 @@ var AnthropicReasoningEffort = class {
|
|
|
1060
1216
|
}
|
|
1061
1217
|
};
|
|
1062
1218
|
|
|
1219
|
+
// src/infrastructure/providers/anthropic/models/claude-4-8-opus.ts
|
|
1220
|
+
var ClaudeOpus48 = class {
|
|
1221
|
+
constructor() {
|
|
1222
|
+
this.specification = {
|
|
1223
|
+
name: "claude-opus-4-8",
|
|
1224
|
+
supportReasoningEffort: true,
|
|
1225
|
+
defaultReasoningEffort: "none",
|
|
1226
|
+
supportStreaming: true,
|
|
1227
|
+
contextWindowSize: 2e5,
|
|
1228
|
+
maxOutputTokens: 32e3,
|
|
1229
|
+
supportFunctionCalling: true
|
|
1230
|
+
};
|
|
1231
|
+
this.tools = [];
|
|
1232
|
+
this.streaming = false;
|
|
1233
|
+
this.effort = new AnthropicReasoningEffort(
|
|
1234
|
+
this.specification.defaultReasoningEffort
|
|
1235
|
+
);
|
|
1236
|
+
}
|
|
1237
|
+
setStreaming(streaming) {
|
|
1238
|
+
this.streaming = streaming;
|
|
1239
|
+
}
|
|
1240
|
+
getStreaming() {
|
|
1241
|
+
return this.streaming;
|
|
1242
|
+
}
|
|
1243
|
+
setTools(tools) {
|
|
1244
|
+
this.tools = tools;
|
|
1245
|
+
}
|
|
1246
|
+
getTools() {
|
|
1247
|
+
return this.tools;
|
|
1248
|
+
}
|
|
1249
|
+
setReasoningEffort(effort) {
|
|
1250
|
+
this.effort.setReasoningEffort(effort);
|
|
1251
|
+
}
|
|
1252
|
+
getReasoningEffort() {
|
|
1253
|
+
return this.effort.getReasoningEffort();
|
|
1254
|
+
}
|
|
1255
|
+
};
|
|
1256
|
+
|
|
1063
1257
|
// src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
|
|
1064
1258
|
var ClaudeOpus47 = class {
|
|
1065
1259
|
constructor() {
|
|
@@ -1173,6 +1367,345 @@ var ClaudeHaiku45 = class {
|
|
|
1173
1367
|
return this.effort.getReasoningEffort();
|
|
1174
1368
|
}
|
|
1175
1369
|
};
|
|
1370
|
+
|
|
1371
|
+
// src/infrastructure/providers/deepseek/reasoning-effort.ts
|
|
1372
|
+
var DeepSeekReasoningEffort = class {
|
|
1373
|
+
constructor(reasoningEffort) {
|
|
1374
|
+
this.reasoningEffort = reasoningEffort;
|
|
1375
|
+
}
|
|
1376
|
+
setReasoningEffort(effort) {
|
|
1377
|
+
this.reasoningEffort = effort;
|
|
1378
|
+
}
|
|
1379
|
+
getReasoningEffort() {
|
|
1380
|
+
if (!this.reasoningEffort) {
|
|
1381
|
+
throw new Error("Reasoning effort not supported");
|
|
1382
|
+
}
|
|
1383
|
+
return this.reasoningEffort;
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
|
|
1387
|
+
// src/infrastructure/providers/deepseek/models/deepseek-v4-flash.ts
|
|
1388
|
+
var DeepSeekV4Flash = class {
|
|
1389
|
+
constructor() {
|
|
1390
|
+
this.specification = {
|
|
1391
|
+
name: "deepseek-v4-flash",
|
|
1392
|
+
supportReasoningEffort: true,
|
|
1393
|
+
defaultReasoningEffort: "high",
|
|
1394
|
+
supportStreaming: true,
|
|
1395
|
+
contextWindowSize: 1e6,
|
|
1396
|
+
maxOutputTokens: 384e3,
|
|
1397
|
+
supportFunctionCalling: true
|
|
1398
|
+
};
|
|
1399
|
+
this.tools = [];
|
|
1400
|
+
this.streaming = false;
|
|
1401
|
+
this.effort = new DeepSeekReasoningEffort(
|
|
1402
|
+
this.specification.defaultReasoningEffort
|
|
1403
|
+
);
|
|
1404
|
+
}
|
|
1405
|
+
setStreaming(streaming) {
|
|
1406
|
+
this.streaming = streaming;
|
|
1407
|
+
}
|
|
1408
|
+
getStreaming() {
|
|
1409
|
+
return this.streaming;
|
|
1410
|
+
}
|
|
1411
|
+
setTools(tools) {
|
|
1412
|
+
this.tools = tools;
|
|
1413
|
+
}
|
|
1414
|
+
getTools() {
|
|
1415
|
+
return this.tools;
|
|
1416
|
+
}
|
|
1417
|
+
setReasoningEffort(effort) {
|
|
1418
|
+
this.effort.setReasoningEffort(effort);
|
|
1419
|
+
}
|
|
1420
|
+
getReasoningEffort() {
|
|
1421
|
+
return this.effort.getReasoningEffort();
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1424
|
+
|
|
1425
|
+
// src/infrastructure/providers/deepseek/models/deepseek-v4-pro.ts
|
|
1426
|
+
var DeepSeekV4Pro = class {
|
|
1427
|
+
constructor() {
|
|
1428
|
+
this.specification = {
|
|
1429
|
+
name: "deepseek-v4-pro",
|
|
1430
|
+
supportReasoningEffort: true,
|
|
1431
|
+
defaultReasoningEffort: "high",
|
|
1432
|
+
supportStreaming: true,
|
|
1433
|
+
contextWindowSize: 1e6,
|
|
1434
|
+
maxOutputTokens: 384e3,
|
|
1435
|
+
supportFunctionCalling: true
|
|
1436
|
+
};
|
|
1437
|
+
this.tools = [];
|
|
1438
|
+
this.streaming = false;
|
|
1439
|
+
this.effort = new DeepSeekReasoningEffort(
|
|
1440
|
+
this.specification.defaultReasoningEffort
|
|
1441
|
+
);
|
|
1442
|
+
}
|
|
1443
|
+
setStreaming(streaming) {
|
|
1444
|
+
this.streaming = streaming;
|
|
1445
|
+
}
|
|
1446
|
+
getStreaming() {
|
|
1447
|
+
return this.streaming;
|
|
1448
|
+
}
|
|
1449
|
+
setTools(tools) {
|
|
1450
|
+
this.tools = tools;
|
|
1451
|
+
}
|
|
1452
|
+
getTools() {
|
|
1453
|
+
return this.tools;
|
|
1454
|
+
}
|
|
1455
|
+
setReasoningEffort(effort) {
|
|
1456
|
+
this.effort.setReasoningEffort(effort);
|
|
1457
|
+
}
|
|
1458
|
+
getReasoningEffort() {
|
|
1459
|
+
return this.effort.getReasoningEffort();
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
|
|
1463
|
+
// src/infrastructure/providers/gemini/runtime/gemini-generate-content.ts
|
|
1464
|
+
import { GoogleGenAI } from "@google/genai";
|
|
1465
|
+
var GeminiGenerateContent = class {
|
|
1466
|
+
constructor() {
|
|
1467
|
+
this.client = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
|
|
1468
|
+
}
|
|
1469
|
+
async infer(inferenceRequest) {
|
|
1470
|
+
const response = await this.client.models.generateContent(this.buildRequest(inferenceRequest));
|
|
1471
|
+
const contextItems = this.extractContextItems(response);
|
|
1472
|
+
const tokenUsage = this.extractTokenUsage(response);
|
|
1473
|
+
return new InferenceResponse(contextItems, tokenUsage);
|
|
1474
|
+
}
|
|
1475
|
+
async *stream(inferenceRequest, signal) {
|
|
1476
|
+
const stream = await this.client.models.generateContentStream(this.buildRequest(inferenceRequest));
|
|
1477
|
+
for await (const chunk of stream) {
|
|
1478
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1479
|
+
break;
|
|
1480
|
+
}
|
|
1481
|
+
yield new SemanticEvent("generate_content_chunk", chunk);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
buildRequest(inferenceRequest) {
|
|
1485
|
+
const specification = inferenceRequest.model.specification;
|
|
1486
|
+
const { contents, systemInstruction } = this.mapContextToRequest(inferenceRequest.context);
|
|
1487
|
+
const config = {};
|
|
1488
|
+
if (systemInstruction) {
|
|
1489
|
+
config.systemInstruction = systemInstruction;
|
|
1490
|
+
}
|
|
1491
|
+
if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
|
|
1492
|
+
config.tools = [
|
|
1493
|
+
{
|
|
1494
|
+
functionDeclarations: inferenceRequest.model.getTools().map((tool) => {
|
|
1495
|
+
return {
|
|
1496
|
+
name: tool.name,
|
|
1497
|
+
description: tool.description,
|
|
1498
|
+
parametersJsonSchema: tool.parameters
|
|
1499
|
+
};
|
|
1500
|
+
})
|
|
1501
|
+
}
|
|
1502
|
+
];
|
|
1503
|
+
}
|
|
1504
|
+
if (specification.supportReasoningEffort) {
|
|
1505
|
+
const effort = inferenceRequest.model.getReasoningEffort();
|
|
1506
|
+
const thinkingLevel = effort === "none" ? "minimal" : effort;
|
|
1507
|
+
config.thinkingConfig = { thinkingLevel, includeThoughts: true };
|
|
1508
|
+
}
|
|
1509
|
+
return { model: specification.name, contents, config };
|
|
1510
|
+
}
|
|
1511
|
+
extractTokenUsage(response) {
|
|
1512
|
+
var _a, _b, _c, _d, _e;
|
|
1513
|
+
const usage = response.usageMetadata;
|
|
1514
|
+
if (!usage) {
|
|
1515
|
+
return void 0;
|
|
1516
|
+
}
|
|
1517
|
+
return new TokenUsage(
|
|
1518
|
+
(_a = usage.promptTokenCount) != null ? _a : 0,
|
|
1519
|
+
(_b = usage.candidatesTokenCount) != null ? _b : 0,
|
|
1520
|
+
(_c = usage.totalTokenCount) != null ? _c : 0,
|
|
1521
|
+
new InputTokenDetails((_d = usage.cachedContentTokenCount) != null ? _d : 0),
|
|
1522
|
+
new OutputTokenDetails((_e = usage.thoughtsTokenCount) != null ? _e : 0)
|
|
1523
|
+
);
|
|
1524
|
+
}
|
|
1525
|
+
mapContextToRequest(context) {
|
|
1526
|
+
var _a;
|
|
1527
|
+
const contents = [];
|
|
1528
|
+
const system = [];
|
|
1529
|
+
const callNames = /* @__PURE__ */ new Map();
|
|
1530
|
+
for (const item of context.getItems()) {
|
|
1531
|
+
if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
|
|
1532
|
+
system.push(item.content.text);
|
|
1533
|
+
continue;
|
|
1534
|
+
}
|
|
1535
|
+
if (item instanceof UserMessageItem) {
|
|
1536
|
+
this.addPart(contents, "user", { text: item.content.text });
|
|
1537
|
+
continue;
|
|
1538
|
+
}
|
|
1539
|
+
if (item instanceof ModelMessageItem) {
|
|
1540
|
+
this.addPart(contents, "model", { text: item.content.text });
|
|
1541
|
+
continue;
|
|
1542
|
+
}
|
|
1543
|
+
if (item instanceof FunctionCallItem) {
|
|
1544
|
+
callNames.set(item.callId, item.name);
|
|
1545
|
+
let args;
|
|
1546
|
+
try {
|
|
1547
|
+
args = JSON.parse(item.args);
|
|
1548
|
+
} catch (e) {
|
|
1549
|
+
args = {};
|
|
1550
|
+
}
|
|
1551
|
+
this.addPart(contents, "model", { functionCall: { id: item.callId, name: item.name, args } });
|
|
1552
|
+
continue;
|
|
1553
|
+
}
|
|
1554
|
+
if (item instanceof FunctionCallOutputItem) {
|
|
1555
|
+
this.addPart(contents, "user", {
|
|
1556
|
+
functionResponse: {
|
|
1557
|
+
id: item.callId,
|
|
1558
|
+
name: (_a = callNames.get(item.callId)) != null ? _a : "",
|
|
1559
|
+
response: this.parseResponse(item.output.text)
|
|
1560
|
+
}
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
return {
|
|
1565
|
+
contents,
|
|
1566
|
+
systemInstruction: system.length > 0 ? system.join("\n\n") : void 0
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
extractContextItems(response) {
|
|
1570
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1571
|
+
const items = [];
|
|
1572
|
+
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 : [];
|
|
1573
|
+
for (const part of parts) {
|
|
1574
|
+
if (part.thought && part.text) {
|
|
1575
|
+
items.push(
|
|
1576
|
+
ReasoningItem.rehydrate({
|
|
1577
|
+
content: InputText.rehydrate({ text: part.text }),
|
|
1578
|
+
encryptedContent: void 0,
|
|
1579
|
+
summary: []
|
|
1580
|
+
})
|
|
1581
|
+
);
|
|
1582
|
+
continue;
|
|
1583
|
+
}
|
|
1584
|
+
if (part.text) {
|
|
1585
|
+
items.push(ModelMessageItem.rehydrate({ text: part.text }));
|
|
1586
|
+
continue;
|
|
1587
|
+
}
|
|
1588
|
+
if (part.functionCall) {
|
|
1589
|
+
items.push(
|
|
1590
|
+
FunctionCallItem.rehydrate({
|
|
1591
|
+
callId: (_e = part.functionCall.id) != null ? _e : "",
|
|
1592
|
+
name: part.functionCall.name,
|
|
1593
|
+
args: JSON.stringify((_f = part.functionCall.args) != null ? _f : {})
|
|
1594
|
+
})
|
|
1595
|
+
);
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
return items;
|
|
1599
|
+
}
|
|
1600
|
+
parseResponse(output) {
|
|
1601
|
+
try {
|
|
1602
|
+
const parsed = JSON.parse(output);
|
|
1603
|
+
return parsed && typeof parsed === "object" ? parsed : { output };
|
|
1604
|
+
} catch (e) {
|
|
1605
|
+
return { output };
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
addPart(contents, role, part) {
|
|
1609
|
+
const last = contents[contents.length - 1];
|
|
1610
|
+
if ((last == null ? void 0 : last.role) === role) {
|
|
1611
|
+
last.parts.push(part);
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1614
|
+
contents.push({ role, parts: [part] });
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
|
|
1618
|
+
// src/infrastructure/providers/gemini/reasoning-effort.ts
|
|
1619
|
+
var GeminiReasoningEffort = class {
|
|
1620
|
+
constructor(reasoningEffort) {
|
|
1621
|
+
this.reasoningEffort = reasoningEffort;
|
|
1622
|
+
}
|
|
1623
|
+
setReasoningEffort(effort) {
|
|
1624
|
+
this.reasoningEffort = effort;
|
|
1625
|
+
}
|
|
1626
|
+
getReasoningEffort() {
|
|
1627
|
+
if (!this.reasoningEffort) {
|
|
1628
|
+
throw new Error("Reasoning effort not supported");
|
|
1629
|
+
}
|
|
1630
|
+
return this.reasoningEffort;
|
|
1631
|
+
}
|
|
1632
|
+
};
|
|
1633
|
+
|
|
1634
|
+
// src/infrastructure/providers/gemini/models/gemini-3-5-flash.ts
|
|
1635
|
+
var Gemini35Flash = class {
|
|
1636
|
+
constructor() {
|
|
1637
|
+
this.specification = {
|
|
1638
|
+
name: "gemini-3.5-flash",
|
|
1639
|
+
supportReasoningEffort: true,
|
|
1640
|
+
defaultReasoningEffort: "medium",
|
|
1641
|
+
supportStreaming: true,
|
|
1642
|
+
contextWindowSize: 1048576,
|
|
1643
|
+
maxOutputTokens: 64e3,
|
|
1644
|
+
supportFunctionCalling: true
|
|
1645
|
+
};
|
|
1646
|
+
this.tools = [];
|
|
1647
|
+
this.streaming = false;
|
|
1648
|
+
this.effort = new GeminiReasoningEffort(
|
|
1649
|
+
this.specification.defaultReasoningEffort
|
|
1650
|
+
);
|
|
1651
|
+
}
|
|
1652
|
+
setStreaming(streaming) {
|
|
1653
|
+
this.streaming = streaming;
|
|
1654
|
+
}
|
|
1655
|
+
getStreaming() {
|
|
1656
|
+
return this.streaming;
|
|
1657
|
+
}
|
|
1658
|
+
setTools(tools) {
|
|
1659
|
+
this.tools = tools;
|
|
1660
|
+
}
|
|
1661
|
+
getTools() {
|
|
1662
|
+
return this.tools;
|
|
1663
|
+
}
|
|
1664
|
+
setReasoningEffort(effort) {
|
|
1665
|
+
this.effort.setReasoningEffort(effort);
|
|
1666
|
+
}
|
|
1667
|
+
getReasoningEffort() {
|
|
1668
|
+
return this.effort.getReasoningEffort();
|
|
1669
|
+
}
|
|
1670
|
+
};
|
|
1671
|
+
|
|
1672
|
+
// src/infrastructure/providers/gemini/models/gemini-3-1-pro.ts
|
|
1673
|
+
var Gemini31Pro = class {
|
|
1674
|
+
constructor() {
|
|
1675
|
+
this.specification = {
|
|
1676
|
+
name: "gemini-3.1-pro-preview",
|
|
1677
|
+
supportReasoningEffort: true,
|
|
1678
|
+
defaultReasoningEffort: "high",
|
|
1679
|
+
supportStreaming: true,
|
|
1680
|
+
contextWindowSize: 1048576,
|
|
1681
|
+
maxOutputTokens: 64e3,
|
|
1682
|
+
supportFunctionCalling: true
|
|
1683
|
+
};
|
|
1684
|
+
this.tools = [];
|
|
1685
|
+
this.streaming = false;
|
|
1686
|
+
this.effort = new GeminiReasoningEffort(
|
|
1687
|
+
this.specification.defaultReasoningEffort
|
|
1688
|
+
);
|
|
1689
|
+
}
|
|
1690
|
+
setStreaming(streaming) {
|
|
1691
|
+
this.streaming = streaming;
|
|
1692
|
+
}
|
|
1693
|
+
getStreaming() {
|
|
1694
|
+
return this.streaming;
|
|
1695
|
+
}
|
|
1696
|
+
setTools(tools) {
|
|
1697
|
+
this.tools = tools;
|
|
1698
|
+
}
|
|
1699
|
+
getTools() {
|
|
1700
|
+
return this.tools;
|
|
1701
|
+
}
|
|
1702
|
+
setReasoningEffort(effort) {
|
|
1703
|
+
this.effort.setReasoningEffort(effort);
|
|
1704
|
+
}
|
|
1705
|
+
getReasoningEffort() {
|
|
1706
|
+
return this.effort.getReasoningEffort();
|
|
1707
|
+
}
|
|
1708
|
+
};
|
|
1176
1709
|
export {
|
|
1177
1710
|
Agent,
|
|
1178
1711
|
AgenticEnvironment,
|
|
@@ -1182,12 +1715,19 @@ export {
|
|
|
1182
1715
|
BaseObserver,
|
|
1183
1716
|
ClaudeHaiku45,
|
|
1184
1717
|
ClaudeOpus47,
|
|
1718
|
+
ClaudeOpus48,
|
|
1185
1719
|
ClaudeSonnet46,
|
|
1186
1720
|
ContextItem,
|
|
1721
|
+
DeepSeekV4Flash,
|
|
1722
|
+
DeepSeekV4Pro,
|
|
1187
1723
|
DefaultFunctionCallRunner,
|
|
1724
|
+
DefaultInferenceRunner,
|
|
1188
1725
|
DeveloperMessageItem,
|
|
1189
1726
|
FunctionCallItem,
|
|
1190
1727
|
FunctionCallOutputItem,
|
|
1728
|
+
Gemini31Pro,
|
|
1729
|
+
Gemini35Flash,
|
|
1730
|
+
GeminiGenerateContent,
|
|
1191
1731
|
Gpt54,
|
|
1192
1732
|
Gpt54Mini,
|
|
1193
1733
|
Gpt54Nano,
|
|
@@ -1200,7 +1740,7 @@ export {
|
|
|
1200
1740
|
ModelContext,
|
|
1201
1741
|
ModelMessageItem,
|
|
1202
1742
|
Observer,
|
|
1203
|
-
|
|
1743
|
+
OpenAICompatibleChatCompletions,
|
|
1204
1744
|
OpenAIResponses,
|
|
1205
1745
|
OutputTokenDetails,
|
|
1206
1746
|
Participant,
|