@mozaik-ai/core 3.12.0 → 3.13.1
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/README.md +209 -102
- package/dist/index.d.mts +108 -570
- package/dist/index.d.ts +108 -570
- package/dist/index.js +1102 -1101
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1096 -1075
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
package/dist/index.mjs
CHANGED
|
@@ -35,9 +35,6 @@ var ModelContext = class _ModelContext {
|
|
|
35
35
|
static rehydrate(data) {
|
|
36
36
|
return new _ModelContext(data.id, data.projectId, data.items);
|
|
37
37
|
}
|
|
38
|
-
toJSON() {
|
|
39
|
-
return this.items.map((item) => item.toJSON());
|
|
40
|
-
}
|
|
41
38
|
};
|
|
42
39
|
|
|
43
40
|
// src/domain/model-context/context-item/context-item.ts
|
|
@@ -64,14 +61,6 @@ var InputText = class _InputText extends ItemContent {
|
|
|
64
61
|
static rehydrate(data) {
|
|
65
62
|
return new _InputText(data.text);
|
|
66
63
|
}
|
|
67
|
-
toJSON() {
|
|
68
|
-
return [
|
|
69
|
-
{
|
|
70
|
-
type: this.type,
|
|
71
|
-
text: this.text
|
|
72
|
-
}
|
|
73
|
-
];
|
|
74
|
-
}
|
|
75
64
|
};
|
|
76
65
|
|
|
77
66
|
// src/domain/model-context/context-item/client-item/user-message.ts
|
|
@@ -90,13 +79,6 @@ var UserMessageItem = class _UserMessageItem extends ContextItem {
|
|
|
90
79
|
const content = InputText.rehydrate(data);
|
|
91
80
|
return new _UserMessageItem(content);
|
|
92
81
|
}
|
|
93
|
-
toJSON() {
|
|
94
|
-
return {
|
|
95
|
-
type: this.type,
|
|
96
|
-
role: this.role,
|
|
97
|
-
content: this.content.toJSON()
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
82
|
};
|
|
101
83
|
|
|
102
84
|
// src/domain/model-context/context-item/client-item/developer-message.ts
|
|
@@ -107,13 +89,6 @@ var DeveloperMessageItem = class _DeveloperMessageItem extends ContextItem {
|
|
|
107
89
|
this.role = "developer";
|
|
108
90
|
this.content = content;
|
|
109
91
|
}
|
|
110
|
-
toJSON() {
|
|
111
|
-
return {
|
|
112
|
-
type: this.type,
|
|
113
|
-
role: this.role,
|
|
114
|
-
content: this.content.toJSON()
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
92
|
static create(text) {
|
|
118
93
|
const content = InputText.create(text);
|
|
119
94
|
return new _DeveloperMessageItem(content);
|
|
@@ -134,14 +109,6 @@ var OutputText = class _OutputText extends ItemContent {
|
|
|
134
109
|
static rehydrate(data) {
|
|
135
110
|
return new _OutputText(data.text);
|
|
136
111
|
}
|
|
137
|
-
toJSON() {
|
|
138
|
-
return [
|
|
139
|
-
{
|
|
140
|
-
type: this.type,
|
|
141
|
-
text: this.text
|
|
142
|
-
}
|
|
143
|
-
];
|
|
144
|
-
}
|
|
145
112
|
};
|
|
146
113
|
|
|
147
114
|
// src/domain/model-context/context-item/model-item/model-message.ts
|
|
@@ -156,13 +123,6 @@ var ModelMessageItem = class _ModelMessageItem extends ContextItem {
|
|
|
156
123
|
const content = OutputText.rehydrate(data);
|
|
157
124
|
return new _ModelMessageItem(content);
|
|
158
125
|
}
|
|
159
|
-
toJSON() {
|
|
160
|
-
return {
|
|
161
|
-
type: this.type,
|
|
162
|
-
role: this.role,
|
|
163
|
-
content: this.content.toJSON()
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
126
|
};
|
|
167
127
|
|
|
168
128
|
// src/domain/model-context/context-item/model-item/function-call.ts
|
|
@@ -177,14 +137,6 @@ var FunctionCallItem = class _FunctionCallItem extends ContextItem {
|
|
|
177
137
|
static rehydrate(data) {
|
|
178
138
|
return new _FunctionCallItem(data.callId, data.name, data.args);
|
|
179
139
|
}
|
|
180
|
-
toJSON() {
|
|
181
|
-
return {
|
|
182
|
-
type: this.type,
|
|
183
|
-
call_id: this.callId,
|
|
184
|
-
name: this.name,
|
|
185
|
-
arguments: this.args
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
140
|
};
|
|
189
141
|
|
|
190
142
|
// src/domain/model-context/context-item/model-item/reasoning.ts
|
|
@@ -199,14 +151,18 @@ var ReasoningItem = class _ReasoningItem extends ContextItem {
|
|
|
199
151
|
static rehydrate(data) {
|
|
200
152
|
return new _ReasoningItem(data.content, data.encryptedContent, data.summary);
|
|
201
153
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// src/domain/generative-model/request-validation/structured-output.ts
|
|
157
|
+
var StructuredOutputValidation = class {
|
|
158
|
+
constructor() {
|
|
159
|
+
this.name = "structured-output";
|
|
160
|
+
}
|
|
161
|
+
isValid(inferenceParams, model) {
|
|
162
|
+
if (inferenceParams.structuredOutput === void 0) {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
return model.supportsStructuredOutput;
|
|
210
166
|
}
|
|
211
167
|
};
|
|
212
168
|
|
|
@@ -225,143 +181,6 @@ var FunctionCallOutputItem = class _FunctionCallOutputItem extends ContextItem {
|
|
|
225
181
|
static rehydrate(data) {
|
|
226
182
|
return new _FunctionCallOutputItem(data.callId, data.output);
|
|
227
183
|
}
|
|
228
|
-
toJSON() {
|
|
229
|
-
return {
|
|
230
|
-
type: this.type,
|
|
231
|
-
call_id: this.callId,
|
|
232
|
-
output: this.output.toJSON()
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
// src/infrastructure/providers/openai/reasoning-effort.ts
|
|
238
|
-
var OpenAIReasoningEffort = class {
|
|
239
|
-
constructor(reasoningEffort) {
|
|
240
|
-
this.reasoningEffort = reasoningEffort;
|
|
241
|
-
}
|
|
242
|
-
setReasoningEffort(effort) {
|
|
243
|
-
this.reasoningEffort = effort;
|
|
244
|
-
}
|
|
245
|
-
getReasoningEffort() {
|
|
246
|
-
if (!this.reasoningEffort) {
|
|
247
|
-
throw new Error("Reasoning effort not supported");
|
|
248
|
-
}
|
|
249
|
-
return this.reasoningEffort;
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
// src/infrastructure/providers/openai/models/gpt-5-4-nano.ts
|
|
254
|
-
var Gpt54Nano = class {
|
|
255
|
-
constructor() {
|
|
256
|
-
this.specification = {
|
|
257
|
-
name: "gpt-5.4-nano",
|
|
258
|
-
supportReasoningEffort: true,
|
|
259
|
-
defaultReasoningEffort: "none",
|
|
260
|
-
supportStreaming: true,
|
|
261
|
-
contextWindowSize: 4e5,
|
|
262
|
-
maxOutputTokens: 128e3,
|
|
263
|
-
supportFunctionCalling: true
|
|
264
|
-
};
|
|
265
|
-
this.tools = [];
|
|
266
|
-
this.streaming = false;
|
|
267
|
-
this.effort = new OpenAIReasoningEffort(
|
|
268
|
-
this.specification.defaultReasoningEffort
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
setStreaming(streaming) {
|
|
272
|
-
this.streaming = streaming;
|
|
273
|
-
}
|
|
274
|
-
getStreaming() {
|
|
275
|
-
return this.streaming;
|
|
276
|
-
}
|
|
277
|
-
setTools(tools) {
|
|
278
|
-
this.tools = tools;
|
|
279
|
-
}
|
|
280
|
-
getTools() {
|
|
281
|
-
return this.tools;
|
|
282
|
-
}
|
|
283
|
-
setReasoningEffort(effort) {
|
|
284
|
-
this.effort.setReasoningEffort(effort);
|
|
285
|
-
}
|
|
286
|
-
getReasoningEffort() {
|
|
287
|
-
return this.effort.getReasoningEffort();
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
// src/infrastructure/providers/openai/models/gpt-5-4.ts
|
|
292
|
-
var Gpt54 = class {
|
|
293
|
-
constructor() {
|
|
294
|
-
this.specification = {
|
|
295
|
-
name: "gpt-5.4",
|
|
296
|
-
supportReasoningEffort: true,
|
|
297
|
-
defaultReasoningEffort: "none",
|
|
298
|
-
supportStreaming: true,
|
|
299
|
-
contextWindowSize: 105e4,
|
|
300
|
-
maxOutputTokens: 128e3,
|
|
301
|
-
supportFunctionCalling: true
|
|
302
|
-
};
|
|
303
|
-
this.tools = [];
|
|
304
|
-
this.streaming = false;
|
|
305
|
-
this.effort = new OpenAIReasoningEffort(
|
|
306
|
-
this.specification.defaultReasoningEffort
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
setStreaming(streaming) {
|
|
310
|
-
this.streaming = streaming;
|
|
311
|
-
}
|
|
312
|
-
getStreaming() {
|
|
313
|
-
return this.streaming;
|
|
314
|
-
}
|
|
315
|
-
setTools(tools) {
|
|
316
|
-
this.tools = tools;
|
|
317
|
-
}
|
|
318
|
-
getTools() {
|
|
319
|
-
return this.tools;
|
|
320
|
-
}
|
|
321
|
-
setReasoningEffort(effort) {
|
|
322
|
-
this.effort.setReasoningEffort(effort);
|
|
323
|
-
}
|
|
324
|
-
getReasoningEffort() {
|
|
325
|
-
return this.effort.getReasoningEffort();
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
// src/infrastructure/providers/openai/models/gpt-5-4-mini.ts
|
|
330
|
-
var Gpt54Mini = class {
|
|
331
|
-
constructor() {
|
|
332
|
-
this.specification = {
|
|
333
|
-
name: "gpt-5.4-mini",
|
|
334
|
-
supportReasoningEffort: true,
|
|
335
|
-
defaultReasoningEffort: "none",
|
|
336
|
-
supportStreaming: true,
|
|
337
|
-
contextWindowSize: 4e5,
|
|
338
|
-
maxOutputTokens: 128e3,
|
|
339
|
-
supportFunctionCalling: true
|
|
340
|
-
};
|
|
341
|
-
this.tools = [];
|
|
342
|
-
this.streaming = false;
|
|
343
|
-
this.effort = new OpenAIReasoningEffort(
|
|
344
|
-
this.specification.defaultReasoningEffort
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
setStreaming(streaming) {
|
|
348
|
-
this.streaming = streaming;
|
|
349
|
-
}
|
|
350
|
-
getStreaming() {
|
|
351
|
-
return this.streaming;
|
|
352
|
-
}
|
|
353
|
-
setReasoningEffort(effort) {
|
|
354
|
-
this.effort.setReasoningEffort(effort);
|
|
355
|
-
}
|
|
356
|
-
getReasoningEffort() {
|
|
357
|
-
return this.effort.getReasoningEffort();
|
|
358
|
-
}
|
|
359
|
-
setTools(tools) {
|
|
360
|
-
this.tools = tools;
|
|
361
|
-
}
|
|
362
|
-
getTools() {
|
|
363
|
-
return this.tools;
|
|
364
|
-
}
|
|
365
184
|
};
|
|
366
185
|
|
|
367
186
|
// src/domain/generative-model/token-usage.ts
|
|
@@ -435,13 +254,6 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
|
|
|
435
254
|
this.role = "system";
|
|
436
255
|
this.content = content;
|
|
437
256
|
}
|
|
438
|
-
toJSON() {
|
|
439
|
-
return {
|
|
440
|
-
type: this.type,
|
|
441
|
-
role: this.role,
|
|
442
|
-
content: this.content.toJSON()
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
257
|
static create(text) {
|
|
446
258
|
const content = InputText.create(text);
|
|
447
259
|
return new _SystemMessageItem(content);
|
|
@@ -452,11 +264,12 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
|
|
|
452
264
|
}
|
|
453
265
|
};
|
|
454
266
|
|
|
455
|
-
// src/domain/agentic-environment/
|
|
267
|
+
// src/domain/agentic-environment/participant.ts
|
|
456
268
|
var Participant = class {
|
|
457
269
|
constructor() {
|
|
458
270
|
this.environments = [];
|
|
459
271
|
this.listens = [];
|
|
272
|
+
this.active = /* @__PURE__ */ new Map();
|
|
460
273
|
}
|
|
461
274
|
join(environment) {
|
|
462
275
|
if (this.isJoinedTo(environment)) {
|
|
@@ -464,6 +277,7 @@ var Participant = class {
|
|
|
464
277
|
}
|
|
465
278
|
environment.subscribe(this);
|
|
466
279
|
this.environments.push(environment);
|
|
280
|
+
this.active.set(environment, true);
|
|
467
281
|
}
|
|
468
282
|
leave(environment) {
|
|
469
283
|
if (!this.isJoinedTo(environment)) {
|
|
@@ -471,6 +285,7 @@ var Participant = class {
|
|
|
471
285
|
}
|
|
472
286
|
environment.unsubscribe(this);
|
|
473
287
|
this.environments = this.environments.filter((e) => e !== environment);
|
|
288
|
+
this.active.delete(environment);
|
|
474
289
|
}
|
|
475
290
|
isJoinedTo(environment) {
|
|
476
291
|
return this.environments.includes(environment);
|
|
@@ -481,14 +296,46 @@ var Participant = class {
|
|
|
481
296
|
getListeners() {
|
|
482
297
|
return this.listens;
|
|
483
298
|
}
|
|
299
|
+
getEnvironmentState(environment) {
|
|
300
|
+
return this.active.get(environment);
|
|
301
|
+
}
|
|
302
|
+
markInactive(environment) {
|
|
303
|
+
if (this.active.has(environment)) {
|
|
304
|
+
this.active.set(environment, false);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
markActive(environment) {
|
|
308
|
+
if (this.active.has(environment)) {
|
|
309
|
+
this.active.set(environment, true);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
// src/domain/agentic-environment/errors/base-error.ts
|
|
315
|
+
var AgenticError = class extends Error {
|
|
316
|
+
constructor({ message, stack, source, enviornment }) {
|
|
317
|
+
super();
|
|
318
|
+
this.message = message;
|
|
319
|
+
this.stack = stack;
|
|
320
|
+
this.source = source;
|
|
321
|
+
this.environment = enviornment;
|
|
322
|
+
}
|
|
323
|
+
getSource() {
|
|
324
|
+
return this.source;
|
|
325
|
+
}
|
|
326
|
+
getEnvironment() {
|
|
327
|
+
return this.environment;
|
|
328
|
+
}
|
|
484
329
|
};
|
|
485
330
|
|
|
486
331
|
// src/domain/agentic-environment/agentic-environment.ts
|
|
487
332
|
var AgenticEnvironment = class {
|
|
488
|
-
constructor(name) {
|
|
333
|
+
constructor(name, opts) {
|
|
489
334
|
this.subscribers = [];
|
|
490
|
-
|
|
335
|
+
var _a;
|
|
491
336
|
this.name = name;
|
|
337
|
+
this.options = opts;
|
|
338
|
+
this.showLogs = ((_a = this.options) == null ? void 0 : _a.silent) !== false;
|
|
492
339
|
}
|
|
493
340
|
subscribe(participant) {
|
|
494
341
|
this.subscribers.push(participant);
|
|
@@ -546,6 +393,36 @@ var AgenticEnvironment = class {
|
|
|
546
393
|
external: (sub) => sub.onExternalEvent(source, item)
|
|
547
394
|
});
|
|
548
395
|
}
|
|
396
|
+
deliverError(source, error) {
|
|
397
|
+
this.deliverToSubscribers(source, {
|
|
398
|
+
internal: (src) => {
|
|
399
|
+
try {
|
|
400
|
+
src.onError(error);
|
|
401
|
+
} catch (error2) {
|
|
402
|
+
if (this.showLogs) {
|
|
403
|
+
console.warn(
|
|
404
|
+
`[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
|
|
405
|
+
${JSON.stringify({ error: error2 }, null, 2)}`
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
} finally {
|
|
409
|
+
src.markInactive(this);
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
external: (sub) => {
|
|
413
|
+
try {
|
|
414
|
+
sub.onParticipantError(source, error);
|
|
415
|
+
} catch (error2) {
|
|
416
|
+
if (this.showLogs) {
|
|
417
|
+
console.warn(
|
|
418
|
+
`[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
|
|
419
|
+
${JSON.stringify({ error: error2 }, null, 2)}`
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
}
|
|
549
426
|
getListeningParticipants(source) {
|
|
550
427
|
return this.subscribers.filter(
|
|
551
428
|
(sub) => sub !== source && (sub.getListeners().length === 0 || sub.getListeners().some((listener) => source instanceof listener))
|
|
@@ -555,26 +432,32 @@ var AgenticEnvironment = class {
|
|
|
555
432
|
var _a, _b;
|
|
556
433
|
const authorizedListeners = this.getListeningParticipants(source);
|
|
557
434
|
for (const subscriber of this.subscribers) {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
435
|
+
const isActive = subscriber.getEnvironmentState(this);
|
|
436
|
+
if (isActive) {
|
|
437
|
+
try {
|
|
438
|
+
if (subscriber === source) {
|
|
439
|
+
(_a = handlers == null ? void 0 : handlers.internal) == null ? void 0 : _a.call(handlers, subscriber);
|
|
440
|
+
} else if (authorizedListeners.includes(subscriber)) {
|
|
441
|
+
(_b = handlers == null ? void 0 : handlers.external) == null ? void 0 : _b.call(handlers, subscriber);
|
|
442
|
+
}
|
|
443
|
+
} catch (error) {
|
|
444
|
+
this.handleError(subscriber, error);
|
|
445
|
+
}
|
|
562
446
|
}
|
|
563
447
|
}
|
|
564
448
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
449
|
+
handleError(subscriber, error) {
|
|
450
|
+
if (error instanceof AgenticError) {
|
|
451
|
+
return this.deliverError(subscriber, error);
|
|
569
452
|
}
|
|
453
|
+
const agenticError = new AgenticError({
|
|
454
|
+
message: error.message,
|
|
455
|
+
stack: error.stack,
|
|
456
|
+
enviornment: this,
|
|
457
|
+
source: subscriber
|
|
458
|
+
});
|
|
459
|
+
return this.deliverError(subscriber, agenticError);
|
|
570
460
|
}
|
|
571
|
-
stop() {
|
|
572
|
-
this.isActive = false;
|
|
573
|
-
}
|
|
574
|
-
};
|
|
575
|
-
|
|
576
|
-
// src/domain/agentic-environment/participants/agent.ts
|
|
577
|
-
var Agent = class extends Participant {
|
|
578
461
|
};
|
|
579
462
|
|
|
580
463
|
// src/domain/model-context/semantic-event/semantic-event.ts
|
|
@@ -588,198 +471,101 @@ var SemanticEvent = class {
|
|
|
588
471
|
}
|
|
589
472
|
};
|
|
590
473
|
|
|
591
|
-
// src/
|
|
592
|
-
var
|
|
593
|
-
constructor(
|
|
594
|
-
|
|
595
|
-
this.
|
|
596
|
-
this.functionCallRunner = functionCallRunner;
|
|
597
|
-
}
|
|
598
|
-
onJoined() {
|
|
599
|
-
}
|
|
600
|
-
onLeft() {
|
|
601
|
-
}
|
|
602
|
-
onParticipantJoined(participant) {
|
|
603
|
-
}
|
|
604
|
-
onParticipantLeft(participant) {
|
|
605
|
-
}
|
|
606
|
-
onFunctionCall(item) {
|
|
607
|
-
}
|
|
608
|
-
onExternalFunctionCall(source, item) {
|
|
609
|
-
}
|
|
610
|
-
onFunctionCallOutput(item) {
|
|
611
|
-
}
|
|
612
|
-
onExternalFunctionCallOutput(source, item) {
|
|
613
|
-
}
|
|
614
|
-
onReasoning(item) {
|
|
615
|
-
}
|
|
616
|
-
onExternalReasoning(source, item) {
|
|
617
|
-
}
|
|
618
|
-
onModelMessage(item) {
|
|
619
|
-
}
|
|
620
|
-
onExternalModelMessage(source, item) {
|
|
621
|
-
}
|
|
622
|
-
onMessage(message) {
|
|
623
|
-
}
|
|
624
|
-
onInternalEvent(item) {
|
|
625
|
-
}
|
|
626
|
-
onExternalEvent(source, item) {
|
|
627
|
-
}
|
|
628
|
-
async executeFunctionCall(environment, functionCallItem, signal) {
|
|
629
|
-
if (!this.isJoinedTo(environment)) return;
|
|
630
|
-
const stream = this.functionCallRunner.run(functionCallItem, signal);
|
|
631
|
-
for await (const item of stream) {
|
|
632
|
-
environment.deliverFunctionCallOutput(this, item);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
async runInference(environment, context, model, signal) {
|
|
636
|
-
if (!this.isJoinedTo(environment)) return;
|
|
637
|
-
const stream = this.inferenceRunner.run(context, model, signal);
|
|
638
|
-
for await (const item of stream) {
|
|
639
|
-
if (item instanceof ReasoningItem) {
|
|
640
|
-
environment.deliverReasoning(this, item);
|
|
641
|
-
} else if (item instanceof FunctionCallItem) {
|
|
642
|
-
environment.deliverFunctionCall(this, item);
|
|
643
|
-
} else if (item instanceof ModelMessageItem) {
|
|
644
|
-
environment.deliverModelMessage(this, item);
|
|
645
|
-
} else if (item instanceof SemanticEvent) {
|
|
646
|
-
environment.deliverSemanticEvent(this, item);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
};
|
|
651
|
-
|
|
652
|
-
// src/domain/agentic-environment/participants/human.ts
|
|
653
|
-
var Human = class extends Participant {
|
|
654
|
-
sendMessage(environment, message) {
|
|
655
|
-
if (!this.isJoinedTo(environment)) throw new Error("Not joined to environment");
|
|
656
|
-
environment.deliverMessage(this, message);
|
|
657
|
-
}
|
|
658
|
-
};
|
|
659
|
-
|
|
660
|
-
// src/application/participants/human.ts
|
|
661
|
-
var BaseHuman = class extends Human {
|
|
662
|
-
onJoined() {
|
|
663
|
-
}
|
|
664
|
-
onLeft() {
|
|
665
|
-
}
|
|
666
|
-
onParticipantJoined(participant) {
|
|
667
|
-
}
|
|
668
|
-
onParticipantLeft(participant) {
|
|
669
|
-
}
|
|
670
|
-
onMessage(message) {
|
|
671
|
-
}
|
|
672
|
-
onFunctionCall(item) {
|
|
673
|
-
}
|
|
674
|
-
onFunctionCallOutput(item) {
|
|
675
|
-
}
|
|
676
|
-
onReasoning(item) {
|
|
677
|
-
}
|
|
678
|
-
onModelMessage(item) {
|
|
679
|
-
}
|
|
680
|
-
onExternalFunctionCall(source, item) {
|
|
681
|
-
}
|
|
682
|
-
onExternalFunctionCallOutput(source, item) {
|
|
683
|
-
}
|
|
684
|
-
onExternalReasoning(source, item) {
|
|
685
|
-
}
|
|
686
|
-
onExternalModelMessage(source, item) {
|
|
687
|
-
}
|
|
688
|
-
onInternalEvent(item) {
|
|
689
|
-
}
|
|
690
|
-
onExternalEvent(source, item) {
|
|
474
|
+
// src/domain/agentic-environment/inference/response.ts
|
|
475
|
+
var InferenceResponse = class {
|
|
476
|
+
constructor(contextItems, tokenUsage) {
|
|
477
|
+
this.contextItems = contextItems;
|
|
478
|
+
this.tokenUsage = tokenUsage;
|
|
691
479
|
}
|
|
692
480
|
};
|
|
693
481
|
|
|
694
|
-
// src/
|
|
695
|
-
var
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
482
|
+
// src/application/services/inference-runner.ts
|
|
483
|
+
var StreamingInference = class {
|
|
484
|
+
async *run(request, endpoint) {
|
|
485
|
+
var _a;
|
|
486
|
+
if ((_a = request.signal) == null ? void 0 : _a.aborted) {
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
yield* endpoint.stream(request, request.signal);
|
|
699
490
|
}
|
|
700
491
|
};
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
var
|
|
704
|
-
|
|
705
|
-
this.runtime = runtime;
|
|
706
|
-
}
|
|
707
|
-
async *run(context, model, signal) {
|
|
708
|
-
const request = new InferenceRequest(model, context);
|
|
709
|
-
if (model.getStreaming() && this.isStreamingRuntime(this.runtime)) {
|
|
710
|
-
yield* this.runtime.stream(request, signal);
|
|
492
|
+
var NonStreamingInference = class {
|
|
493
|
+
async *run(request, endpoint) {
|
|
494
|
+
var _a, _b;
|
|
495
|
+
if ((_a = request.signal) == null ? void 0 : _a.aborted) {
|
|
711
496
|
return;
|
|
712
497
|
}
|
|
713
|
-
const response = await
|
|
498
|
+
const response = await endpoint.infer(request);
|
|
714
499
|
for (const item of response.contextItems) {
|
|
715
|
-
if (signal == null ? void 0 :
|
|
500
|
+
if ((_b = request.signal) == null ? void 0 : _b.aborted) {
|
|
716
501
|
break;
|
|
717
502
|
}
|
|
718
503
|
yield item;
|
|
719
504
|
}
|
|
720
505
|
}
|
|
721
|
-
isStreamingRuntime(runtime) {
|
|
722
|
-
return typeof runtime.stream === "function";
|
|
723
|
-
}
|
|
724
506
|
};
|
|
725
507
|
|
|
726
|
-
// src/application/
|
|
727
|
-
var
|
|
728
|
-
constructor(
|
|
729
|
-
this.
|
|
508
|
+
// src/application/use-cases/run-inference.ts
|
|
509
|
+
var RunInference = class {
|
|
510
|
+
constructor(generativeModelRepository2, requestValidator) {
|
|
511
|
+
this.generativeModelRepository = generativeModelRepository2;
|
|
512
|
+
this.requestValidator = requestValidator;
|
|
730
513
|
}
|
|
731
|
-
async
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
const
|
|
735
|
-
|
|
514
|
+
async execute(inferenceParams) {
|
|
515
|
+
var _a;
|
|
516
|
+
const { caller, environment, signal } = inferenceParams;
|
|
517
|
+
const generativeModel = await this.generativeModelRepository.getByModelName(inferenceParams.model);
|
|
518
|
+
this.requestValidator.validate(inferenceParams, generativeModel.specification);
|
|
519
|
+
const resolvedParams = {
|
|
520
|
+
...inferenceParams,
|
|
521
|
+
maxOutputTokens: (_a = inferenceParams.maxOutputTokens) != null ? _a : generativeModel.specification.maxOutputTokens
|
|
522
|
+
};
|
|
523
|
+
const inferenceRunner = inferenceParams.streaming ? new StreamingInference() : new NonStreamingInference();
|
|
524
|
+
const result = inferenceRunner.run(resolvedParams, generativeModel.endpoint);
|
|
525
|
+
for await (const item of result) {
|
|
526
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
if (item instanceof ReasoningItem) {
|
|
530
|
+
environment.deliverReasoning(caller, item);
|
|
531
|
+
} else if (item instanceof FunctionCallItem) {
|
|
532
|
+
environment.deliverFunctionCall(caller, item);
|
|
533
|
+
} else if (item instanceof ModelMessageItem) {
|
|
534
|
+
environment.deliverModelMessage(caller, item);
|
|
535
|
+
} else if (item instanceof SemanticEvent) {
|
|
536
|
+
environment.deliverSemanticEvent(caller, item);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
736
539
|
}
|
|
737
540
|
};
|
|
738
541
|
|
|
739
|
-
// src/
|
|
740
|
-
var
|
|
741
|
-
constructor() {
|
|
742
|
-
this.
|
|
743
|
-
name: "gpt-5.5",
|
|
744
|
-
supportReasoningEffort: true,
|
|
745
|
-
defaultReasoningEffort: "none",
|
|
746
|
-
supportStreaming: true,
|
|
747
|
-
contextWindowSize: 105e4,
|
|
748
|
-
maxOutputTokens: 128e3,
|
|
749
|
-
supportFunctionCalling: true
|
|
750
|
-
};
|
|
751
|
-
this.tools = [];
|
|
752
|
-
this.streaming = false;
|
|
753
|
-
this.effort = new OpenAIReasoningEffort(
|
|
754
|
-
this.specification.defaultReasoningEffort
|
|
755
|
-
);
|
|
756
|
-
}
|
|
757
|
-
setStreaming(streaming) {
|
|
758
|
-
this.streaming = streaming;
|
|
759
|
-
}
|
|
760
|
-
getStreaming() {
|
|
761
|
-
return this.streaming;
|
|
762
|
-
}
|
|
763
|
-
setTools(tools) {
|
|
764
|
-
this.tools = tools;
|
|
765
|
-
}
|
|
766
|
-
getTools() {
|
|
767
|
-
return this.tools;
|
|
768
|
-
}
|
|
769
|
-
setReasoningEffort(effort) {
|
|
770
|
-
this.effort.setReasoningEffort(effort);
|
|
542
|
+
// src/application/use-cases/execute-function-call.ts
|
|
543
|
+
var ExecuteFunctionCall = class {
|
|
544
|
+
constructor(functionCallRunner) {
|
|
545
|
+
this.functionCallRunner = functionCallRunner;
|
|
771
546
|
}
|
|
772
|
-
|
|
773
|
-
|
|
547
|
+
async execute(environment, functionCallItem, tool, caller, signal) {
|
|
548
|
+
const stream = this.functionCallRunner.run(functionCallItem, tool, signal);
|
|
549
|
+
for await (const item of stream) {
|
|
550
|
+
environment.deliverFunctionCallOutput(caller, item);
|
|
551
|
+
}
|
|
774
552
|
}
|
|
775
553
|
};
|
|
776
554
|
|
|
777
|
-
// src/
|
|
778
|
-
var
|
|
555
|
+
// src/application/services/function-call-runner.ts
|
|
556
|
+
var FunctionCallRunner = class {
|
|
557
|
+
async *run(call, tool, signal) {
|
|
558
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
if (!tool) throw new Error(`Unknown tool: ${call.name}`);
|
|
562
|
+
const result = await tool.invoke(JSON.parse(call.args));
|
|
563
|
+
yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
|
|
564
|
+
}
|
|
779
565
|
};
|
|
780
566
|
|
|
781
|
-
// src/application/participants/
|
|
782
|
-
var
|
|
567
|
+
// src/application/participants/participant.ts
|
|
568
|
+
var BaseParticipant = class extends Participant {
|
|
783
569
|
onFunctionCall(item) {
|
|
784
570
|
}
|
|
785
571
|
onExternalFunctionCall(source, item) {
|
|
@@ -810,310 +596,79 @@ var BaseObserver = class extends Observer {
|
|
|
810
596
|
}
|
|
811
597
|
onExternalEvent(source, item) {
|
|
812
598
|
}
|
|
599
|
+
onError(error) {
|
|
600
|
+
}
|
|
601
|
+
onParticipantError(source, error) {
|
|
602
|
+
}
|
|
813
603
|
};
|
|
814
604
|
|
|
815
|
-
// src/
|
|
816
|
-
var
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
605
|
+
// src/application/use-cases/send-message.ts
|
|
606
|
+
var SendMessage = class {
|
|
607
|
+
async execute(environment, message, caller) {
|
|
608
|
+
if (!caller.isJoinedTo(environment)) {
|
|
609
|
+
throw new Error("Not joined to environment");
|
|
610
|
+
}
|
|
611
|
+
environment.deliverMessage(caller, message);
|
|
820
612
|
}
|
|
821
613
|
};
|
|
822
614
|
|
|
823
|
-
// src/infrastructure/providers/
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
615
|
+
// src/infrastructure/providers/anthropic/endpoints/anthropic-messages-mapper.ts
|
|
616
|
+
var AnthropicMessagesMapper = class {
|
|
617
|
+
toRequest(inferenceParams) {
|
|
618
|
+
const { messages, system } = this.mapContextItems(inferenceParams);
|
|
619
|
+
const outputConfig = {};
|
|
620
|
+
const request = {
|
|
621
|
+
model: inferenceParams.model,
|
|
622
|
+
messages
|
|
623
|
+
};
|
|
624
|
+
request.max_tokens = inferenceParams.maxOutputTokens;
|
|
625
|
+
if (system) {
|
|
626
|
+
request.system = system;
|
|
627
|
+
}
|
|
628
|
+
if (inferenceParams.tools && inferenceParams.tools.length > 0) {
|
|
629
|
+
request.tools = inferenceParams.tools.map((tool) => ({
|
|
630
|
+
name: tool.name,
|
|
631
|
+
description: tool.description,
|
|
632
|
+
input_schema: tool.parameters
|
|
633
|
+
}));
|
|
634
|
+
}
|
|
635
|
+
if (inferenceParams.structuredOutput) {
|
|
636
|
+
outputConfig.format = {
|
|
637
|
+
type: "json_schema",
|
|
638
|
+
json_schema: inferenceParams.structuredOutput.schema
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
if (inferenceParams.reasoningEffort) {
|
|
642
|
+
request.thinking = { type: "adaptive" };
|
|
643
|
+
outputConfig.effort = inferenceParams.reasoningEffort;
|
|
644
|
+
}
|
|
645
|
+
if (Object.keys(outputConfig).length > 0) {
|
|
646
|
+
request.output_config = outputConfig;
|
|
647
|
+
}
|
|
648
|
+
if (inferenceParams.streaming) {
|
|
649
|
+
request.stream = inferenceParams.streaming;
|
|
650
|
+
}
|
|
651
|
+
return request;
|
|
828
652
|
}
|
|
829
|
-
|
|
830
|
-
const request = this.buildRequest(inferenceRequest);
|
|
831
|
-
const response = await this.client.responses.create(request);
|
|
653
|
+
toResponse(response) {
|
|
832
654
|
const contextItems = this.extractContextItems(response);
|
|
833
655
|
const tokenUsage = this.extractTokenUsage(response);
|
|
834
656
|
return new InferenceResponse(contextItems, tokenUsage);
|
|
835
657
|
}
|
|
836
|
-
|
|
837
|
-
const
|
|
838
|
-
if (
|
|
839
|
-
|
|
658
|
+
addContentBlock(messages, role, block) {
|
|
659
|
+
const lastMessage = messages[messages.length - 1];
|
|
660
|
+
if ((lastMessage == null ? void 0 : lastMessage.role) === role) {
|
|
661
|
+
lastMessage.content.push(block);
|
|
662
|
+
return;
|
|
840
663
|
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
if (signal == null ? void 0 : signal.aborted) {
|
|
845
|
-
break;
|
|
846
|
-
}
|
|
847
|
-
yield new SemanticEvent(event.type, event);
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
buildRequest(inferenceRequest) {
|
|
851
|
-
const specification = inferenceRequest.model.specification;
|
|
852
|
-
const input = this.mapContextToRequest(inferenceRequest.context);
|
|
853
|
-
const request = {
|
|
854
|
-
model: specification.name,
|
|
855
|
-
input
|
|
856
|
-
};
|
|
857
|
-
if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
|
|
858
|
-
request.tools = inferenceRequest.model.getTools().map((tool) => {
|
|
859
|
-
return {
|
|
860
|
-
type: tool.type,
|
|
861
|
-
name: tool.name,
|
|
862
|
-
description: tool.description,
|
|
863
|
-
parameters: tool.parameters
|
|
864
|
-
};
|
|
865
|
-
});
|
|
866
|
-
}
|
|
867
|
-
if (specification.supportReasoningEffort) {
|
|
868
|
-
request.reasoning = {
|
|
869
|
-
effort: inferenceRequest.model.getReasoningEffort()
|
|
870
|
-
};
|
|
871
|
-
}
|
|
872
|
-
return request;
|
|
873
|
-
}
|
|
874
|
-
extractTokenUsage(response) {
|
|
875
|
-
if (!response.usage) {
|
|
876
|
-
return void 0;
|
|
877
|
-
}
|
|
878
|
-
return new TokenUsage(
|
|
879
|
-
response.usage.input_tokens,
|
|
880
|
-
response.usage.output_tokens,
|
|
881
|
-
response.usage.total_tokens,
|
|
882
|
-
new InputTokenDetails(response.usage.input_tokens_details.cached_tokens),
|
|
883
|
-
new OutputTokenDetails(response.usage.output_tokens_details.reasoning_tokens)
|
|
884
|
-
);
|
|
885
|
-
}
|
|
886
|
-
mapContextToRequest(context) {
|
|
887
|
-
return context.getItems().map((item) => item.toJSON());
|
|
888
|
-
}
|
|
889
|
-
extractContextItems(response) {
|
|
890
|
-
return response.output.map((item) => {
|
|
891
|
-
if (item.type === "message" && item.role === "assistant") {
|
|
892
|
-
return ModelMessageItem.rehydrate(item.content[0]);
|
|
893
|
-
}
|
|
894
|
-
if (item.type === "function_call") {
|
|
895
|
-
return FunctionCallItem.rehydrate({
|
|
896
|
-
callId: item.call_id,
|
|
897
|
-
name: item.name,
|
|
898
|
-
args: item.arguments
|
|
899
|
-
});
|
|
900
|
-
}
|
|
901
|
-
if (item.type === "reasoning") {
|
|
902
|
-
return ReasoningItem.rehydrate(item);
|
|
903
|
-
}
|
|
904
|
-
});
|
|
905
|
-
}
|
|
906
|
-
};
|
|
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
|
|
664
|
+
messages.push({
|
|
665
|
+
role,
|
|
666
|
+
content: [block]
|
|
930
667
|
});
|
|
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
668
|
}
|
|
938
|
-
|
|
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) {
|
|
669
|
+
mapContextItems(inferenceParams) {
|
|
1013
670
|
var _a, _b, _c;
|
|
1014
|
-
const
|
|
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
|
-
|
|
1044
|
-
// src/infrastructure/providers/anthropic/runtime/anthropic-messages.ts
|
|
1045
|
-
import Anthropic from "@anthropic-ai/sdk";
|
|
1046
|
-
var AnthropicMessages = class {
|
|
1047
|
-
constructor() {
|
|
1048
|
-
this.client = new Anthropic();
|
|
1049
|
-
}
|
|
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) {
|
|
1069
|
-
const { messages, system } = this.mapContextToRequest(inferenceRequest.context);
|
|
1070
|
-
const specification = inferenceRequest.model.specification;
|
|
1071
|
-
const request = {
|
|
1072
|
-
model: specification.name,
|
|
1073
|
-
max_tokens: specification.maxOutputTokens,
|
|
1074
|
-
messages
|
|
1075
|
-
};
|
|
1076
|
-
if (system) {
|
|
1077
|
-
request.system = system;
|
|
1078
|
-
}
|
|
1079
|
-
if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
|
|
1080
|
-
request.tools = inferenceRequest.model.getTools().map((tool) => {
|
|
1081
|
-
return {
|
|
1082
|
-
name: tool.name,
|
|
1083
|
-
description: tool.description,
|
|
1084
|
-
input_schema: tool.parameters
|
|
1085
|
-
};
|
|
1086
|
-
});
|
|
1087
|
-
}
|
|
1088
|
-
if (specification.supportReasoningEffort) {
|
|
1089
|
-
const effort = inferenceRequest.model.getReasoningEffort();
|
|
1090
|
-
const budgets = { low: 1024, medium: 4096, high: 8192 };
|
|
1091
|
-
const budget = budgets[effort];
|
|
1092
|
-
if (budget !== void 0) {
|
|
1093
|
-
request.thinking = {
|
|
1094
|
-
type: "enabled",
|
|
1095
|
-
budget_tokens: Math.min(budget, specification.maxOutputTokens - 1)
|
|
1096
|
-
};
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
return request;
|
|
1100
|
-
}
|
|
1101
|
-
extractTokenUsage(response) {
|
|
1102
|
-
var _a, _b;
|
|
1103
|
-
if (!response.usage) {
|
|
1104
|
-
return void 0;
|
|
1105
|
-
}
|
|
1106
|
-
return new TokenUsage(
|
|
1107
|
-
response.usage.input_tokens,
|
|
1108
|
-
response.usage.output_tokens,
|
|
1109
|
-
response.usage.input_tokens + response.usage.output_tokens,
|
|
1110
|
-
new InputTokenDetails(
|
|
1111
|
-
((_a = response.usage.cache_creation_input_tokens) != null ? _a : 0) + ((_b = response.usage.cache_read_input_tokens) != null ? _b : 0)
|
|
1112
|
-
),
|
|
1113
|
-
new OutputTokenDetails(0)
|
|
1114
|
-
);
|
|
1115
|
-
}
|
|
1116
|
-
mapContextToRequest(context) {
|
|
671
|
+
const context = inferenceParams.context;
|
|
1117
672
|
const messages = [];
|
|
1118
673
|
const system = [];
|
|
1119
674
|
for (const item of context.getItems()) {
|
|
@@ -1129,6 +684,14 @@ var AnthropicMessages = class {
|
|
|
1129
684
|
this.addContentBlock(messages, "assistant", { type: "text", text: item.content.text });
|
|
1130
685
|
continue;
|
|
1131
686
|
}
|
|
687
|
+
if (item instanceof ReasoningItem) {
|
|
688
|
+
this.addContentBlock(messages, "assistant", {
|
|
689
|
+
type: "thinking",
|
|
690
|
+
thinking: (_b = (_a = item.content) == null ? void 0 : _a.text) != null ? _b : "",
|
|
691
|
+
signature: (_c = item.encryptedContent) != null ? _c : ""
|
|
692
|
+
});
|
|
693
|
+
continue;
|
|
694
|
+
}
|
|
1132
695
|
if (item instanceof FunctionCallItem) {
|
|
1133
696
|
let input;
|
|
1134
697
|
try {
|
|
@@ -1157,6 +720,21 @@ var AnthropicMessages = class {
|
|
|
1157
720
|
system: system.length > 0 ? system.join("\n\n") : void 0
|
|
1158
721
|
};
|
|
1159
722
|
}
|
|
723
|
+
extractTokenUsage(response) {
|
|
724
|
+
var _a, _b;
|
|
725
|
+
if (!response.usage) {
|
|
726
|
+
return void 0;
|
|
727
|
+
}
|
|
728
|
+
return new TokenUsage(
|
|
729
|
+
response.usage.input_tokens,
|
|
730
|
+
response.usage.output_tokens,
|
|
731
|
+
response.usage.input_tokens + response.usage.output_tokens,
|
|
732
|
+
new InputTokenDetails(
|
|
733
|
+
((_a = response.usage.cache_creation_input_tokens) != null ? _a : 0) + ((_b = response.usage.cache_read_input_tokens) != null ? _b : 0)
|
|
734
|
+
),
|
|
735
|
+
new OutputTokenDetails(0)
|
|
736
|
+
);
|
|
737
|
+
}
|
|
1160
738
|
extractContextItems(response) {
|
|
1161
739
|
var _a;
|
|
1162
740
|
const items = [];
|
|
@@ -1179,7 +757,7 @@ var AnthropicMessages = class {
|
|
|
1179
757
|
items.push(
|
|
1180
758
|
ReasoningItem.rehydrate({
|
|
1181
759
|
content: block.thinking ? InputText.rehydrate({ text: block.thinking }) : void 0,
|
|
1182
|
-
encryptedContent:
|
|
760
|
+
encryptedContent: block.signature,
|
|
1183
761
|
summary: []
|
|
1184
762
|
})
|
|
1185
763
|
);
|
|
@@ -1187,343 +765,261 @@ var AnthropicMessages = class {
|
|
|
1187
765
|
}
|
|
1188
766
|
return items;
|
|
1189
767
|
}
|
|
1190
|
-
addContentBlock(messages, role, block) {
|
|
1191
|
-
const lastMessage = messages[messages.length - 1];
|
|
1192
|
-
if ((lastMessage == null ? void 0 : lastMessage.role) === role) {
|
|
1193
|
-
lastMessage.content.push(block);
|
|
1194
|
-
return;
|
|
1195
|
-
}
|
|
1196
|
-
messages.push({
|
|
1197
|
-
role,
|
|
1198
|
-
content: [block]
|
|
1199
|
-
});
|
|
1200
|
-
}
|
|
1201
768
|
};
|
|
1202
769
|
|
|
1203
|
-
// src/infrastructure/providers/anthropic/
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
770
|
+
// src/infrastructure/providers/anthropic/endpoints/anthropic-messages.ts
|
|
771
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
772
|
+
var AnthropicMessages = class {
|
|
773
|
+
constructor(endpointMapper = new AnthropicMessagesMapper()) {
|
|
774
|
+
this.endpointMapper = endpointMapper;
|
|
775
|
+
this.client = new Anthropic();
|
|
1207
776
|
}
|
|
1208
|
-
|
|
1209
|
-
|
|
777
|
+
async infer(inferenceParams) {
|
|
778
|
+
const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
|
|
779
|
+
const response = await this.client.messages.create(inferenceRequest);
|
|
780
|
+
return this.endpointMapper.toResponse(response);
|
|
1210
781
|
}
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
782
|
+
async *stream(inferenceParams, signal) {
|
|
783
|
+
const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
|
|
784
|
+
const stream = await this.client.messages.create(inferenceRequest);
|
|
785
|
+
for await (const event of stream) {
|
|
786
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
787
|
+
break;
|
|
788
|
+
}
|
|
789
|
+
yield new SemanticEvent(event.type, event);
|
|
1214
790
|
}
|
|
1215
|
-
return this.reasoningEffort;
|
|
1216
|
-
}
|
|
1217
|
-
};
|
|
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
791
|
}
|
|
1255
792
|
};
|
|
1256
793
|
|
|
1257
|
-
// src/infrastructure/providers/
|
|
1258
|
-
|
|
1259
|
-
constructor() {
|
|
1260
|
-
this.specification = {
|
|
1261
|
-
name: "claude-opus-4-7",
|
|
1262
|
-
supportReasoningEffort: true,
|
|
1263
|
-
defaultReasoningEffort: "none",
|
|
1264
|
-
supportStreaming: true,
|
|
1265
|
-
contextWindowSize: 2e5,
|
|
1266
|
-
maxOutputTokens: 32e3,
|
|
1267
|
-
supportFunctionCalling: true
|
|
1268
|
-
};
|
|
1269
|
-
this.tools = [];
|
|
1270
|
-
this.streaming = false;
|
|
1271
|
-
this.effort = new AnthropicReasoningEffort(
|
|
1272
|
-
this.specification.defaultReasoningEffort
|
|
1273
|
-
);
|
|
1274
|
-
}
|
|
1275
|
-
setStreaming(streaming) {
|
|
1276
|
-
this.streaming = streaming;
|
|
1277
|
-
}
|
|
1278
|
-
getStreaming() {
|
|
1279
|
-
return this.streaming;
|
|
1280
|
-
}
|
|
1281
|
-
setTools(tools) {
|
|
1282
|
-
this.tools = tools;
|
|
1283
|
-
}
|
|
1284
|
-
getTools() {
|
|
1285
|
-
return this.tools;
|
|
1286
|
-
}
|
|
1287
|
-
setReasoningEffort(effort) {
|
|
1288
|
-
this.effort.setReasoningEffort(effort);
|
|
1289
|
-
}
|
|
1290
|
-
getReasoningEffort() {
|
|
1291
|
-
return this.effort.getReasoningEffort();
|
|
1292
|
-
}
|
|
1293
|
-
};
|
|
794
|
+
// src/infrastructure/providers/openai/endpoints/openai-responses.ts
|
|
795
|
+
import OpenAI from "openai";
|
|
1294
796
|
|
|
1295
|
-
// src/
|
|
1296
|
-
var
|
|
1297
|
-
constructor() {
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
defaultReasoningEffort: "none",
|
|
1302
|
-
supportStreaming: true,
|
|
1303
|
-
contextWindowSize: 2e5,
|
|
1304
|
-
maxOutputTokens: 64e3,
|
|
1305
|
-
supportFunctionCalling: true
|
|
1306
|
-
};
|
|
1307
|
-
this.tools = [];
|
|
1308
|
-
this.streaming = false;
|
|
1309
|
-
this.effort = new AnthropicReasoningEffort(
|
|
1310
|
-
this.specification.defaultReasoningEffort
|
|
1311
|
-
);
|
|
1312
|
-
}
|
|
1313
|
-
setStreaming(streaming) {
|
|
1314
|
-
this.streaming = streaming;
|
|
1315
|
-
}
|
|
1316
|
-
getStreaming() {
|
|
1317
|
-
return this.streaming;
|
|
1318
|
-
}
|
|
1319
|
-
setTools(tools) {
|
|
1320
|
-
this.tools = tools;
|
|
1321
|
-
}
|
|
1322
|
-
getTools() {
|
|
1323
|
-
return this.tools;
|
|
1324
|
-
}
|
|
1325
|
-
setReasoningEffort(effort) {
|
|
1326
|
-
this.effort.setReasoningEffort(effort);
|
|
797
|
+
// src/domain/model-context/context-item/item-content/summary-text.ts
|
|
798
|
+
var SummaryText = class _SummaryText extends ItemContent {
|
|
799
|
+
constructor(text) {
|
|
800
|
+
super();
|
|
801
|
+
this.text = text;
|
|
802
|
+
this.type = "summary_text";
|
|
1327
803
|
}
|
|
1328
|
-
|
|
1329
|
-
return
|
|
804
|
+
static rehydrate(data) {
|
|
805
|
+
return new _SummaryText(data.text);
|
|
1330
806
|
}
|
|
1331
807
|
};
|
|
1332
808
|
|
|
1333
|
-
// src/infrastructure/providers/
|
|
1334
|
-
var
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
supportStreaming: true,
|
|
1341
|
-
contextWindowSize: 2e5,
|
|
1342
|
-
maxOutputTokens: 64e3,
|
|
1343
|
-
supportFunctionCalling: true
|
|
809
|
+
// src/infrastructure/providers/openai/endpoints/openai-responses-mapper.ts
|
|
810
|
+
var OpenAIResponsesMapper = class {
|
|
811
|
+
toRequest(inferenceParams) {
|
|
812
|
+
var _a, _b;
|
|
813
|
+
const request = {
|
|
814
|
+
model: inferenceParams.model,
|
|
815
|
+
input: this.mapContextItems(inferenceParams)
|
|
1344
816
|
};
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
this.streaming = streaming;
|
|
1353
|
-
}
|
|
1354
|
-
getStreaming() {
|
|
1355
|
-
return this.streaming;
|
|
1356
|
-
}
|
|
1357
|
-
setTools(tools) {
|
|
1358
|
-
this.tools = tools;
|
|
1359
|
-
}
|
|
1360
|
-
getTools() {
|
|
1361
|
-
return this.tools;
|
|
1362
|
-
}
|
|
1363
|
-
setReasoningEffort(effort) {
|
|
1364
|
-
this.effort.setReasoningEffort(effort);
|
|
1365
|
-
}
|
|
1366
|
-
getReasoningEffort() {
|
|
1367
|
-
return this.effort.getReasoningEffort();
|
|
1368
|
-
}
|
|
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");
|
|
817
|
+
if (inferenceParams.tools && inferenceParams.tools.length > 0) {
|
|
818
|
+
request.tools = inferenceParams.tools.map((tool) => ({
|
|
819
|
+
type: tool.type,
|
|
820
|
+
name: tool.name,
|
|
821
|
+
description: tool.description,
|
|
822
|
+
parameters: tool.parameters
|
|
823
|
+
}));
|
|
1382
824
|
}
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
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;
|
|
825
|
+
if (inferenceParams.reasoningEffort) {
|
|
826
|
+
request.reasoning = {
|
|
827
|
+
effort: inferenceParams.reasoningEffort
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
if (inferenceParams.structuredOutput) {
|
|
831
|
+
const format = inferenceParams.structuredOutput;
|
|
832
|
+
request.text = {
|
|
833
|
+
format: {
|
|
834
|
+
type: "json_schema",
|
|
835
|
+
name: (_a = format.name) != null ? _a : "response",
|
|
836
|
+
schema: format.schema,
|
|
837
|
+
strict: (_b = format.strict) != null ? _b : true
|
|
838
|
+
}
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
if (inferenceParams.streaming) {
|
|
842
|
+
request.stream = inferenceParams.streaming;
|
|
843
|
+
}
|
|
844
|
+
return request;
|
|
1416
845
|
}
|
|
1417
|
-
|
|
1418
|
-
this.
|
|
846
|
+
toResponse(response) {
|
|
847
|
+
const contextItems = this.extractContextItems(response);
|
|
848
|
+
const tokenUsage = this.extractTokenUsage(response);
|
|
849
|
+
return new InferenceResponse(contextItems, tokenUsage);
|
|
1419
850
|
}
|
|
1420
|
-
|
|
1421
|
-
|
|
851
|
+
mapContextItems(inferenceParams) {
|
|
852
|
+
const input = [];
|
|
853
|
+
for (const item of inferenceParams.context.getItems()) {
|
|
854
|
+
if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem || item instanceof UserMessageItem) {
|
|
855
|
+
input.push({
|
|
856
|
+
type: item.type,
|
|
857
|
+
role: item.role,
|
|
858
|
+
content: [{ type: "input_text", text: item.content.text }]
|
|
859
|
+
});
|
|
860
|
+
continue;
|
|
861
|
+
}
|
|
862
|
+
if (item instanceof ModelMessageItem) {
|
|
863
|
+
input.push({
|
|
864
|
+
type: item.type,
|
|
865
|
+
role: item.role,
|
|
866
|
+
content: [{ type: "output_text", text: item.content.text }]
|
|
867
|
+
});
|
|
868
|
+
continue;
|
|
869
|
+
}
|
|
870
|
+
if (item instanceof FunctionCallItem) {
|
|
871
|
+
input.push({
|
|
872
|
+
type: item.type,
|
|
873
|
+
call_id: item.callId,
|
|
874
|
+
name: item.name,
|
|
875
|
+
arguments: item.args
|
|
876
|
+
});
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
if (item instanceof FunctionCallOutputItem) {
|
|
880
|
+
input.push({
|
|
881
|
+
type: item.type,
|
|
882
|
+
call_id: item.callId,
|
|
883
|
+
output: [{ type: "input_text", text: item.output.text }]
|
|
884
|
+
});
|
|
885
|
+
continue;
|
|
886
|
+
}
|
|
887
|
+
if (item instanceof ReasoningItem) {
|
|
888
|
+
const reasoningInput = {
|
|
889
|
+
type: item.type,
|
|
890
|
+
summary: item.summary.map((summary) => ({ type: "summary_text", text: summary.text }))
|
|
891
|
+
};
|
|
892
|
+
if (item.encryptedContent !== void 0) {
|
|
893
|
+
reasoningInput.encrypted_content = item.encryptedContent;
|
|
894
|
+
}
|
|
895
|
+
input.push(reasoningInput);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
return input;
|
|
1422
899
|
}
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
maxOutputTokens: 384e3,
|
|
1435
|
-
supportFunctionCalling: true
|
|
1436
|
-
};
|
|
1437
|
-
this.tools = [];
|
|
1438
|
-
this.streaming = false;
|
|
1439
|
-
this.effort = new DeepSeekReasoningEffort(
|
|
1440
|
-
this.specification.defaultReasoningEffort
|
|
900
|
+
extractTokenUsage(response) {
|
|
901
|
+
var _a, _b, _c, _d;
|
|
902
|
+
if (!response.usage) {
|
|
903
|
+
return void 0;
|
|
904
|
+
}
|
|
905
|
+
return new TokenUsage(
|
|
906
|
+
response.usage.input_tokens,
|
|
907
|
+
response.usage.output_tokens,
|
|
908
|
+
response.usage.total_tokens,
|
|
909
|
+
new InputTokenDetails((_b = (_a = response.usage.input_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
|
|
910
|
+
new OutputTokenDetails((_d = (_c = response.usage.output_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
|
|
1441
911
|
);
|
|
1442
912
|
}
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
913
|
+
extractContextItems(response) {
|
|
914
|
+
var _a, _b, _c;
|
|
915
|
+
const items = [];
|
|
916
|
+
for (const item of (_a = response.output) != null ? _a : []) {
|
|
917
|
+
if (item.type === "message" && item.role === "assistant") {
|
|
918
|
+
const firstContent = (_b = item.content) == null ? void 0 : _b[0];
|
|
919
|
+
if (firstContent) {
|
|
920
|
+
items.push(ModelMessageItem.rehydrate(firstContent));
|
|
921
|
+
}
|
|
922
|
+
continue;
|
|
923
|
+
}
|
|
924
|
+
if (item.type === "function_call") {
|
|
925
|
+
items.push(
|
|
926
|
+
FunctionCallItem.rehydrate({
|
|
927
|
+
callId: item.call_id,
|
|
928
|
+
name: item.name,
|
|
929
|
+
args: item.arguments
|
|
930
|
+
})
|
|
931
|
+
);
|
|
932
|
+
continue;
|
|
933
|
+
}
|
|
934
|
+
if (item.type === "reasoning") {
|
|
935
|
+
items.push(
|
|
936
|
+
ReasoningItem.rehydrate({
|
|
937
|
+
content: void 0,
|
|
938
|
+
encryptedContent: item.encrypted_content,
|
|
939
|
+
summary: ((_c = item.summary) != null ? _c : []).map(
|
|
940
|
+
(summary) => SummaryText.rehydrate({ text: summary.text })
|
|
941
|
+
)
|
|
942
|
+
})
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
return items;
|
|
1460
947
|
}
|
|
1461
948
|
};
|
|
1462
949
|
|
|
1463
|
-
// src/infrastructure/providers/
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
this.client = new
|
|
950
|
+
// src/infrastructure/providers/openai/endpoints/openai-responses.ts
|
|
951
|
+
var OpenAIResponses = class {
|
|
952
|
+
constructor(endpointMapper = new OpenAIResponsesMapper()) {
|
|
953
|
+
this.endpointMapper = endpointMapper;
|
|
954
|
+
this.client = new OpenAI();
|
|
1468
955
|
}
|
|
1469
|
-
async infer(
|
|
1470
|
-
const
|
|
1471
|
-
const
|
|
1472
|
-
|
|
1473
|
-
return new InferenceResponse(contextItems, tokenUsage);
|
|
956
|
+
async infer(inferenceParams) {
|
|
957
|
+
const request = this.endpointMapper.toRequest(inferenceParams);
|
|
958
|
+
const response = await this.client.responses.create(request);
|
|
959
|
+
return this.endpointMapper.toResponse(response);
|
|
1474
960
|
}
|
|
1475
|
-
async *stream(
|
|
1476
|
-
const
|
|
1477
|
-
|
|
961
|
+
async *stream(inferenceParams, signal) {
|
|
962
|
+
const request = this.endpointMapper.toRequest(inferenceParams);
|
|
963
|
+
const response = await this.client.responses.create(request);
|
|
964
|
+
for await (const event of response) {
|
|
1478
965
|
if (signal == null ? void 0 : signal.aborted) {
|
|
1479
966
|
break;
|
|
1480
967
|
}
|
|
1481
|
-
yield new SemanticEvent(
|
|
968
|
+
yield new SemanticEvent(event.type, event);
|
|
1482
969
|
}
|
|
1483
970
|
}
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
971
|
+
};
|
|
972
|
+
|
|
973
|
+
// src/infrastructure/providers/gemini/endpoints/gemini-generate-content.ts
|
|
974
|
+
import { GoogleGenAI } from "@google/genai";
|
|
975
|
+
|
|
976
|
+
// src/infrastructure/providers/gemini/endpoints/gemini-generate-content-mapper.ts
|
|
977
|
+
var GeminiGenerateContentMapper = class {
|
|
978
|
+
toRequest(inferenceParams) {
|
|
979
|
+
const { contents, systemInstruction } = this.mapContextItems(inferenceParams);
|
|
1487
980
|
const config = {};
|
|
1488
981
|
if (systemInstruction) {
|
|
1489
982
|
config.systemInstruction = systemInstruction;
|
|
1490
983
|
}
|
|
1491
|
-
if (
|
|
984
|
+
if (inferenceParams.tools && inferenceParams.tools.length > 0) {
|
|
1492
985
|
config.tools = [
|
|
1493
986
|
{
|
|
1494
|
-
functionDeclarations:
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
};
|
|
1500
|
-
})
|
|
987
|
+
functionDeclarations: inferenceParams.tools.map((tool) => ({
|
|
988
|
+
name: tool.name,
|
|
989
|
+
description: tool.description,
|
|
990
|
+
parametersJsonSchema: tool.parameters
|
|
991
|
+
}))
|
|
1501
992
|
}
|
|
1502
993
|
];
|
|
1503
994
|
}
|
|
1504
|
-
if (
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
config.thinkingConfig = { thinkingLevel, includeThoughts: true };
|
|
995
|
+
if (inferenceParams.structuredOutput) {
|
|
996
|
+
config.responseMimeType = "application/json";
|
|
997
|
+
config.responseSchema = inferenceParams.structuredOutput.schema;
|
|
1508
998
|
}
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
if (!usage) {
|
|
1515
|
-
return void 0;
|
|
999
|
+
if (inferenceParams.reasoningEffort) {
|
|
1000
|
+
config.thinkingConfig = {
|
|
1001
|
+
thinkingLevel: inferenceParams.reasoningEffort,
|
|
1002
|
+
includeThoughts: true
|
|
1003
|
+
};
|
|
1516
1004
|
}
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1005
|
+
const request = {
|
|
1006
|
+
model: inferenceParams.model,
|
|
1007
|
+
contents,
|
|
1008
|
+
config
|
|
1009
|
+
};
|
|
1010
|
+
if (inferenceParams.streaming) {
|
|
1011
|
+
request.stream = inferenceParams.streaming;
|
|
1012
|
+
}
|
|
1013
|
+
return request;
|
|
1014
|
+
}
|
|
1015
|
+
toResponse(response) {
|
|
1016
|
+
const contextItems = this.extractContextItems(response);
|
|
1017
|
+
const tokenUsage = this.extractTokenUsage(response);
|
|
1018
|
+
return new InferenceResponse(contextItems, tokenUsage);
|
|
1524
1019
|
}
|
|
1525
|
-
|
|
1020
|
+
mapContextItems(inferenceParams) {
|
|
1526
1021
|
var _a;
|
|
1022
|
+
const context = inferenceParams.context;
|
|
1527
1023
|
const contents = [];
|
|
1528
1024
|
const system = [];
|
|
1529
1025
|
const callNames = /* @__PURE__ */ new Map();
|
|
@@ -1566,6 +1062,36 @@ var GeminiGenerateContent = class {
|
|
|
1566
1062
|
systemInstruction: system.length > 0 ? system.join("\n\n") : void 0
|
|
1567
1063
|
};
|
|
1568
1064
|
}
|
|
1065
|
+
addPart(contents, role, part) {
|
|
1066
|
+
const last = contents[contents.length - 1];
|
|
1067
|
+
if ((last == null ? void 0 : last.role) === role) {
|
|
1068
|
+
last.parts.push(part);
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
contents.push({ role, parts: [part] });
|
|
1072
|
+
}
|
|
1073
|
+
parseResponse(output) {
|
|
1074
|
+
try {
|
|
1075
|
+
const parsed = JSON.parse(output);
|
|
1076
|
+
return parsed && typeof parsed === "object" ? parsed : { output };
|
|
1077
|
+
} catch (e) {
|
|
1078
|
+
return { output };
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
extractTokenUsage(response) {
|
|
1082
|
+
var _a, _b, _c, _d, _e;
|
|
1083
|
+
const usage = response.usageMetadata;
|
|
1084
|
+
if (!usage) {
|
|
1085
|
+
return void 0;
|
|
1086
|
+
}
|
|
1087
|
+
return new TokenUsage(
|
|
1088
|
+
(_a = usage.promptTokenCount) != null ? _a : 0,
|
|
1089
|
+
(_b = usage.candidatesTokenCount) != null ? _b : 0,
|
|
1090
|
+
(_c = usage.totalTokenCount) != null ? _c : 0,
|
|
1091
|
+
new InputTokenDetails((_d = usage.cachedContentTokenCount) != null ? _d : 0),
|
|
1092
|
+
new OutputTokenDetails((_e = usage.thoughtsTokenCount) != null ? _e : 0)
|
|
1093
|
+
);
|
|
1094
|
+
}
|
|
1569
1095
|
extractContextItems(response) {
|
|
1570
1096
|
var _a, _b, _c, _d, _e, _f;
|
|
1571
1097
|
const items = [];
|
|
@@ -1597,157 +1123,652 @@ var GeminiGenerateContent = class {
|
|
|
1597
1123
|
}
|
|
1598
1124
|
return items;
|
|
1599
1125
|
}
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
}
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
// src/infrastructure/providers/gemini/endpoints/gemini-generate-content.ts
|
|
1129
|
+
var GeminiGenerateContent = class {
|
|
1130
|
+
constructor(endpointMapper = new GeminiGenerateContentMapper()) {
|
|
1131
|
+
this.endpointMapper = endpointMapper;
|
|
1132
|
+
this.client = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
|
|
1607
1133
|
}
|
|
1608
|
-
|
|
1609
|
-
const
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1134
|
+
async infer(inferenceParams) {
|
|
1135
|
+
const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
|
|
1136
|
+
const response = await this.client.models.generateContent(inferenceRequest);
|
|
1137
|
+
return this.endpointMapper.toResponse(response);
|
|
1138
|
+
}
|
|
1139
|
+
async *stream(inferenceParams, signal) {
|
|
1140
|
+
const inferenceRequest = this.endpointMapper.toRequest(inferenceParams);
|
|
1141
|
+
const stream = await this.client.models.generateContentStream(inferenceRequest);
|
|
1142
|
+
for await (const chunk of stream) {
|
|
1143
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1144
|
+
break;
|
|
1145
|
+
}
|
|
1146
|
+
yield new SemanticEvent("generate_content_chunk", chunk);
|
|
1613
1147
|
}
|
|
1614
|
-
contents.push({ role, parts: [part] });
|
|
1615
1148
|
}
|
|
1616
1149
|
};
|
|
1617
1150
|
|
|
1618
|
-
// src/infrastructure/providers/
|
|
1619
|
-
var
|
|
1620
|
-
|
|
1621
|
-
|
|
1151
|
+
// src/infrastructure/providers/openai/endpoints/openai-chat-completions-mapper.ts
|
|
1152
|
+
var OpenAIChatCompletionsMapper = class {
|
|
1153
|
+
toRequest(inferenceParams) {
|
|
1154
|
+
const request = {
|
|
1155
|
+
model: inferenceParams.model,
|
|
1156
|
+
messages: this.mapContextItems(inferenceParams)
|
|
1157
|
+
};
|
|
1158
|
+
if (inferenceParams.tools && inferenceParams.tools.length > 0) {
|
|
1159
|
+
request.tools = inferenceParams.tools.map((tool) => ({
|
|
1160
|
+
type: "function",
|
|
1161
|
+
function: {
|
|
1162
|
+
name: tool.name,
|
|
1163
|
+
description: tool.description,
|
|
1164
|
+
parameters: tool.parameters
|
|
1165
|
+
}
|
|
1166
|
+
}));
|
|
1167
|
+
}
|
|
1168
|
+
if (inferenceParams.reasoningEffort) {
|
|
1169
|
+
request.reasoning_effort = inferenceParams.reasoningEffort;
|
|
1170
|
+
}
|
|
1171
|
+
if (inferenceParams.streaming) {
|
|
1172
|
+
request.stream = inferenceParams.streaming;
|
|
1173
|
+
}
|
|
1174
|
+
return request;
|
|
1175
|
+
}
|
|
1176
|
+
toResponse(response) {
|
|
1177
|
+
const contextItems = this.extractContextItems(response);
|
|
1178
|
+
const tokenUsage = this.extractTokenUsage(response);
|
|
1179
|
+
return new InferenceResponse(contextItems, tokenUsage);
|
|
1180
|
+
}
|
|
1181
|
+
mapContextItems(inferenceParams) {
|
|
1182
|
+
var _a;
|
|
1183
|
+
const messages = [];
|
|
1184
|
+
for (const item of inferenceParams.context.getItems()) {
|
|
1185
|
+
if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
|
|
1186
|
+
messages.push({ role: "system", content: item.content.text });
|
|
1187
|
+
continue;
|
|
1188
|
+
}
|
|
1189
|
+
if (item instanceof UserMessageItem) {
|
|
1190
|
+
messages.push({ role: "user", content: item.content.text });
|
|
1191
|
+
continue;
|
|
1192
|
+
}
|
|
1193
|
+
if (item instanceof ModelMessageItem) {
|
|
1194
|
+
messages.push({ role: "assistant", content: item.content.text });
|
|
1195
|
+
continue;
|
|
1196
|
+
}
|
|
1197
|
+
if (item instanceof FunctionCallItem) {
|
|
1198
|
+
const toolCall = {
|
|
1199
|
+
id: item.callId,
|
|
1200
|
+
type: "function",
|
|
1201
|
+
function: { name: item.name, arguments: item.args }
|
|
1202
|
+
};
|
|
1203
|
+
const last = messages[messages.length - 1];
|
|
1204
|
+
if ((last == null ? void 0 : last.role) === "assistant") {
|
|
1205
|
+
last.tool_calls = (_a = last.tool_calls) != null ? _a : [];
|
|
1206
|
+
last.tool_calls.push(toolCall);
|
|
1207
|
+
} else {
|
|
1208
|
+
messages.push({ role: "assistant", content: null, tool_calls: [toolCall] });
|
|
1209
|
+
}
|
|
1210
|
+
continue;
|
|
1211
|
+
}
|
|
1212
|
+
if (item instanceof FunctionCallOutputItem) {
|
|
1213
|
+
messages.push({ role: "tool", tool_call_id: item.callId, content: item.output.text });
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
return messages;
|
|
1622
1217
|
}
|
|
1623
|
-
|
|
1624
|
-
|
|
1218
|
+
extractTokenUsage(response) {
|
|
1219
|
+
var _a, _b, _c, _d;
|
|
1220
|
+
if (!response.usage) {
|
|
1221
|
+
return void 0;
|
|
1222
|
+
}
|
|
1223
|
+
return new TokenUsage(
|
|
1224
|
+
response.usage.prompt_tokens,
|
|
1225
|
+
response.usage.completion_tokens,
|
|
1226
|
+
response.usage.total_tokens,
|
|
1227
|
+
new InputTokenDetails((_b = (_a = response.usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
|
|
1228
|
+
new OutputTokenDetails((_d = (_c = response.usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
|
|
1229
|
+
);
|
|
1625
1230
|
}
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1231
|
+
extractContextItems(response) {
|
|
1232
|
+
var _a, _b, _c;
|
|
1233
|
+
const items = [];
|
|
1234
|
+
const message = (_b = (_a = response.choices) == null ? void 0 : _a[0]) == null ? void 0 : _b.message;
|
|
1235
|
+
if (!message) {
|
|
1236
|
+
return items;
|
|
1237
|
+
}
|
|
1238
|
+
if (message.reasoning_content) {
|
|
1239
|
+
items.push(
|
|
1240
|
+
ReasoningItem.rehydrate({
|
|
1241
|
+
content: InputText.rehydrate({ text: message.reasoning_content }),
|
|
1242
|
+
encryptedContent: void 0,
|
|
1243
|
+
summary: []
|
|
1244
|
+
})
|
|
1245
|
+
);
|
|
1246
|
+
}
|
|
1247
|
+
if (message.content) {
|
|
1248
|
+
items.push(ModelMessageItem.rehydrate({ text: message.content }));
|
|
1249
|
+
}
|
|
1250
|
+
for (const toolCall of (_c = message.tool_calls) != null ? _c : []) {
|
|
1251
|
+
items.push(
|
|
1252
|
+
FunctionCallItem.rehydrate({
|
|
1253
|
+
callId: toolCall.id,
|
|
1254
|
+
name: toolCall.function.name,
|
|
1255
|
+
args: toolCall.function.arguments
|
|
1256
|
+
})
|
|
1257
|
+
);
|
|
1629
1258
|
}
|
|
1630
|
-
return
|
|
1259
|
+
return items;
|
|
1631
1260
|
}
|
|
1632
1261
|
};
|
|
1633
1262
|
|
|
1634
|
-
// src/infrastructure/providers/
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1263
|
+
// src/infrastructure/providers/openai/endpoints/openai-chat-completions.ts
|
|
1264
|
+
import OpenAI2 from "openai";
|
|
1265
|
+
var OpenAIChatCompletions = class {
|
|
1266
|
+
constructor(endpointMapper = new OpenAIChatCompletionsMapper(), config = {}) {
|
|
1267
|
+
var _a;
|
|
1268
|
+
this.endpointMapper = endpointMapper;
|
|
1269
|
+
this.client = new OpenAI2({
|
|
1270
|
+
baseURL: config.baseURL,
|
|
1271
|
+
apiKey: config.apiKey
|
|
1272
|
+
});
|
|
1273
|
+
this.extraBody = (_a = config.extraBody) != null ? _a : {};
|
|
1274
|
+
}
|
|
1275
|
+
buildRequest(inferenceParams) {
|
|
1276
|
+
return {
|
|
1277
|
+
...this.extraBody,
|
|
1278
|
+
...this.endpointMapper.toRequest(inferenceParams)
|
|
1645
1279
|
};
|
|
1646
|
-
this.tools = [];
|
|
1647
|
-
this.streaming = false;
|
|
1648
|
-
this.effort = new GeminiReasoningEffort(
|
|
1649
|
-
this.specification.defaultReasoningEffort
|
|
1650
|
-
);
|
|
1651
1280
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1281
|
+
async infer(inferenceParams) {
|
|
1282
|
+
const response = await this.client.chat.completions.create(this.buildRequest(inferenceParams));
|
|
1283
|
+
return this.endpointMapper.toResponse(response);
|
|
1284
|
+
}
|
|
1285
|
+
async *stream(inferenceParams, signal) {
|
|
1286
|
+
var _a;
|
|
1287
|
+
const stream = await this.client.chat.completions.create(this.buildRequest(inferenceParams));
|
|
1288
|
+
for await (const event of stream) {
|
|
1289
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1290
|
+
break;
|
|
1291
|
+
}
|
|
1292
|
+
yield new SemanticEvent((_a = event.object) != null ? _a : "chat.completion.chunk", event);
|
|
1293
|
+
}
|
|
1654
1294
|
}
|
|
1655
|
-
|
|
1656
|
-
|
|
1295
|
+
};
|
|
1296
|
+
|
|
1297
|
+
// src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts
|
|
1298
|
+
var claudeSonnet46Specification = {
|
|
1299
|
+
name: "claude-sonnet-4-6",
|
|
1300
|
+
provider: "anthropic",
|
|
1301
|
+
supportsReasoningEffort: true,
|
|
1302
|
+
supportedReasoningEfforts: ["max", "high", "medium", "low"],
|
|
1303
|
+
supportedContextItemTypes: [
|
|
1304
|
+
"user_message",
|
|
1305
|
+
"system_message",
|
|
1306
|
+
"developer_message",
|
|
1307
|
+
"reasoning",
|
|
1308
|
+
"function_call",
|
|
1309
|
+
"function_call_output",
|
|
1310
|
+
"model_message"
|
|
1311
|
+
],
|
|
1312
|
+
supportsStreaming: true,
|
|
1313
|
+
contextWindowSize: 2e5,
|
|
1314
|
+
maxOutputTokens: 64e3,
|
|
1315
|
+
supportsFunctionCalling: true,
|
|
1316
|
+
supportsStructuredOutput: true
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
// src/infrastructure/providers/anthropic/models/claude-4-8-opus.ts
|
|
1320
|
+
var claudeOpus48Specification = {
|
|
1321
|
+
name: "claude-opus-4-8",
|
|
1322
|
+
provider: "anthropic",
|
|
1323
|
+
supportsReasoningEffort: true,
|
|
1324
|
+
supportedReasoningEfforts: ["max", "xhigh", "high", "medium", "low"],
|
|
1325
|
+
supportedContextItemTypes: [
|
|
1326
|
+
"user_message",
|
|
1327
|
+
"system_message",
|
|
1328
|
+
"developer_message",
|
|
1329
|
+
"reasoning",
|
|
1330
|
+
"function_call",
|
|
1331
|
+
"function_call_output",
|
|
1332
|
+
"model_message"
|
|
1333
|
+
],
|
|
1334
|
+
supportsStreaming: true,
|
|
1335
|
+
contextWindowSize: 2e5,
|
|
1336
|
+
maxOutputTokens: 32e3,
|
|
1337
|
+
supportsFunctionCalling: true,
|
|
1338
|
+
supportsStructuredOutput: true
|
|
1339
|
+
};
|
|
1340
|
+
|
|
1341
|
+
// src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
|
|
1342
|
+
var claudeOpus47Specification = {
|
|
1343
|
+
name: "claude-opus-4-7",
|
|
1344
|
+
provider: "anthropic",
|
|
1345
|
+
supportsReasoningEffort: true,
|
|
1346
|
+
supportedReasoningEfforts: ["max", "xhigh", "high", "medium", "low"],
|
|
1347
|
+
supportedContextItemTypes: [
|
|
1348
|
+
"user_message",
|
|
1349
|
+
"system_message",
|
|
1350
|
+
"developer_message",
|
|
1351
|
+
"reasoning",
|
|
1352
|
+
"function_call",
|
|
1353
|
+
"function_call_output",
|
|
1354
|
+
"model_message"
|
|
1355
|
+
],
|
|
1356
|
+
supportsStreaming: true,
|
|
1357
|
+
contextWindowSize: 2e5,
|
|
1358
|
+
maxOutputTokens: 32e3,
|
|
1359
|
+
supportsFunctionCalling: true,
|
|
1360
|
+
supportsStructuredOutput: true
|
|
1361
|
+
};
|
|
1362
|
+
|
|
1363
|
+
// src/infrastructure/providers/gemini/models/gemini-3-5-flash.ts
|
|
1364
|
+
var gemini35FlashSpecification = {
|
|
1365
|
+
name: "gemini-3.5-flash",
|
|
1366
|
+
provider: "google",
|
|
1367
|
+
supportsReasoningEffort: true,
|
|
1368
|
+
supportedReasoningEfforts: ["high", "medium", "low", "minimal", "none"],
|
|
1369
|
+
supportedContextItemTypes: [
|
|
1370
|
+
"user_message",
|
|
1371
|
+
"system_message",
|
|
1372
|
+
"developer_message",
|
|
1373
|
+
"reasoning",
|
|
1374
|
+
"function_call",
|
|
1375
|
+
"function_call_output",
|
|
1376
|
+
"model_message"
|
|
1377
|
+
],
|
|
1378
|
+
supportsStreaming: true,
|
|
1379
|
+
contextWindowSize: 1048576,
|
|
1380
|
+
maxOutputTokens: 64e3,
|
|
1381
|
+
supportsFunctionCalling: true,
|
|
1382
|
+
supportsStructuredOutput: true
|
|
1383
|
+
};
|
|
1384
|
+
|
|
1385
|
+
// src/infrastructure/providers/gemini/models/gemini-3-1-pro.ts
|
|
1386
|
+
var gemini31ProSpecification = {
|
|
1387
|
+
name: "gemini-3.1-pro-preview",
|
|
1388
|
+
provider: "google",
|
|
1389
|
+
supportsReasoningEffort: true,
|
|
1390
|
+
supportedReasoningEfforts: ["high", "medium", "low", "minimal", "none"],
|
|
1391
|
+
supportedContextItemTypes: [
|
|
1392
|
+
"user_message",
|
|
1393
|
+
"system_message",
|
|
1394
|
+
"developer_message",
|
|
1395
|
+
"reasoning",
|
|
1396
|
+
"function_call",
|
|
1397
|
+
"function_call_output",
|
|
1398
|
+
"model_message"
|
|
1399
|
+
],
|
|
1400
|
+
supportsStreaming: true,
|
|
1401
|
+
contextWindowSize: 1048576,
|
|
1402
|
+
maxOutputTokens: 64e3,
|
|
1403
|
+
supportsFunctionCalling: true,
|
|
1404
|
+
supportsStructuredOutput: true
|
|
1405
|
+
};
|
|
1406
|
+
|
|
1407
|
+
// src/infrastructure/providers/deepseek/models/deepseek-v4-flash.ts
|
|
1408
|
+
var deepSeekV4FlashSpecification = {
|
|
1409
|
+
name: "deepseek-v4-flash",
|
|
1410
|
+
provider: "deepseek",
|
|
1411
|
+
supportsReasoningEffort: true,
|
|
1412
|
+
supportedReasoningEfforts: ["max", "high", "medium", "low", "none"],
|
|
1413
|
+
supportedContextItemTypes: [
|
|
1414
|
+
"user_message",
|
|
1415
|
+
"system_message",
|
|
1416
|
+
"developer_message",
|
|
1417
|
+
"reasoning",
|
|
1418
|
+
"function_call",
|
|
1419
|
+
"function_call_output",
|
|
1420
|
+
"model_message"
|
|
1421
|
+
],
|
|
1422
|
+
supportsStreaming: true,
|
|
1423
|
+
contextWindowSize: 1e6,
|
|
1424
|
+
maxOutputTokens: 384e3,
|
|
1425
|
+
supportsFunctionCalling: true,
|
|
1426
|
+
supportsStructuredOutput: false
|
|
1427
|
+
};
|
|
1428
|
+
|
|
1429
|
+
// src/infrastructure/providers/deepseek/models/deepseek-v4-pro.ts
|
|
1430
|
+
var deepSeekV4ProSpecification = {
|
|
1431
|
+
name: "deepseek-v4-pro",
|
|
1432
|
+
provider: "deepseek",
|
|
1433
|
+
supportsReasoningEffort: true,
|
|
1434
|
+
supportedReasoningEfforts: ["max", "high", "medium", "low", "none"],
|
|
1435
|
+
supportedContextItemTypes: [
|
|
1436
|
+
"user_message",
|
|
1437
|
+
"system_message",
|
|
1438
|
+
"developer_message",
|
|
1439
|
+
"reasoning",
|
|
1440
|
+
"function_call",
|
|
1441
|
+
"function_call_output",
|
|
1442
|
+
"model_message"
|
|
1443
|
+
],
|
|
1444
|
+
supportsStreaming: true,
|
|
1445
|
+
contextWindowSize: 1e6,
|
|
1446
|
+
maxOutputTokens: 384e3,
|
|
1447
|
+
supportsFunctionCalling: true,
|
|
1448
|
+
supportsStructuredOutput: false
|
|
1449
|
+
};
|
|
1450
|
+
|
|
1451
|
+
// src/infrastructure/providers/openai/models/gpt-5-4.ts
|
|
1452
|
+
var gpt54Specification = {
|
|
1453
|
+
name: "gpt-5.4",
|
|
1454
|
+
provider: "openai",
|
|
1455
|
+
supportsReasoningEffort: true,
|
|
1456
|
+
supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
|
|
1457
|
+
supportedContextItemTypes: [
|
|
1458
|
+
"user_message",
|
|
1459
|
+
"system_message",
|
|
1460
|
+
"developer_message",
|
|
1461
|
+
"reasoning",
|
|
1462
|
+
"function_call",
|
|
1463
|
+
"function_call_output",
|
|
1464
|
+
"model_message"
|
|
1465
|
+
],
|
|
1466
|
+
supportsStreaming: true,
|
|
1467
|
+
contextWindowSize: 105e4,
|
|
1468
|
+
maxOutputTokens: 128e3,
|
|
1469
|
+
supportsFunctionCalling: true,
|
|
1470
|
+
supportsStructuredOutput: true
|
|
1471
|
+
};
|
|
1472
|
+
|
|
1473
|
+
// src/infrastructure/providers/openai/models/gpt-5-4-mini.ts
|
|
1474
|
+
var gpt54MiniSpecification = {
|
|
1475
|
+
name: "gpt-5.4-mini",
|
|
1476
|
+
provider: "openai",
|
|
1477
|
+
supportsReasoningEffort: true,
|
|
1478
|
+
supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
|
|
1479
|
+
supportedContextItemTypes: [
|
|
1480
|
+
"user_message",
|
|
1481
|
+
"system_message",
|
|
1482
|
+
"developer_message",
|
|
1483
|
+
"reasoning",
|
|
1484
|
+
"function_call",
|
|
1485
|
+
"function_call_output",
|
|
1486
|
+
"model_message"
|
|
1487
|
+
],
|
|
1488
|
+
supportsStreaming: true,
|
|
1489
|
+
contextWindowSize: 4e5,
|
|
1490
|
+
maxOutputTokens: 128e3,
|
|
1491
|
+
supportsFunctionCalling: true,
|
|
1492
|
+
supportsStructuredOutput: true
|
|
1493
|
+
};
|
|
1494
|
+
|
|
1495
|
+
// src/infrastructure/providers/openai/models/gpt-5-4-nano.ts
|
|
1496
|
+
var gpt54NanoSpecification = {
|
|
1497
|
+
name: "gpt-5.4-nano",
|
|
1498
|
+
provider: "openai",
|
|
1499
|
+
supportsReasoningEffort: true,
|
|
1500
|
+
supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
|
|
1501
|
+
supportedContextItemTypes: [
|
|
1502
|
+
"user_message",
|
|
1503
|
+
"system_message",
|
|
1504
|
+
"developer_message",
|
|
1505
|
+
"reasoning",
|
|
1506
|
+
"function_call",
|
|
1507
|
+
"function_call_output",
|
|
1508
|
+
"model_message"
|
|
1509
|
+
],
|
|
1510
|
+
supportsStreaming: true,
|
|
1511
|
+
contextWindowSize: 4e5,
|
|
1512
|
+
maxOutputTokens: 128e3,
|
|
1513
|
+
supportsFunctionCalling: true,
|
|
1514
|
+
supportsStructuredOutput: true
|
|
1515
|
+
};
|
|
1516
|
+
|
|
1517
|
+
// src/infrastructure/providers/openai/models/gpt-5-5.ts
|
|
1518
|
+
var gpt55Specification = {
|
|
1519
|
+
name: "gpt-5.5",
|
|
1520
|
+
provider: "openai",
|
|
1521
|
+
supportsReasoningEffort: true,
|
|
1522
|
+
supportedReasoningEfforts: ["xhigh", "high", "medium", "low", "none"],
|
|
1523
|
+
supportedContextItemTypes: [
|
|
1524
|
+
"user_message",
|
|
1525
|
+
"system_message",
|
|
1526
|
+
"developer_message",
|
|
1527
|
+
"reasoning",
|
|
1528
|
+
"function_call",
|
|
1529
|
+
"function_call_output",
|
|
1530
|
+
"model_message"
|
|
1531
|
+
],
|
|
1532
|
+
supportsStreaming: true,
|
|
1533
|
+
contextWindowSize: 105e4,
|
|
1534
|
+
maxOutputTokens: 128e3,
|
|
1535
|
+
supportsFunctionCalling: true,
|
|
1536
|
+
supportsStructuredOutput: true
|
|
1537
|
+
};
|
|
1538
|
+
|
|
1539
|
+
// src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts
|
|
1540
|
+
var claudeHaiku45Specification = {
|
|
1541
|
+
name: "claude-haiku-4-5",
|
|
1542
|
+
provider: "anthropic",
|
|
1543
|
+
supportsReasoningEffort: true,
|
|
1544
|
+
supportedReasoningEfforts: ["high", "medium", "low", "none"],
|
|
1545
|
+
supportedContextItemTypes: [
|
|
1546
|
+
"user_message",
|
|
1547
|
+
"system_message",
|
|
1548
|
+
"developer_message",
|
|
1549
|
+
"reasoning",
|
|
1550
|
+
"function_call",
|
|
1551
|
+
"function_call_output",
|
|
1552
|
+
"model_message"
|
|
1553
|
+
],
|
|
1554
|
+
supportsStreaming: true,
|
|
1555
|
+
contextWindowSize: 2e5,
|
|
1556
|
+
maxOutputTokens: 64e3,
|
|
1557
|
+
supportsFunctionCalling: true,
|
|
1558
|
+
supportsStructuredOutput: true
|
|
1559
|
+
};
|
|
1560
|
+
|
|
1561
|
+
// src/infrastructure/repository/generative-model-repository.ts
|
|
1562
|
+
var InMemoryGenerativeModelRepository = class {
|
|
1563
|
+
getByModelName(modelName) {
|
|
1564
|
+
let generativeModel = void 0;
|
|
1565
|
+
switch (modelName) {
|
|
1566
|
+
case "gpt-5.4":
|
|
1567
|
+
generativeModel = {
|
|
1568
|
+
endpoint: new OpenAIResponses(),
|
|
1569
|
+
specification: gpt54Specification
|
|
1570
|
+
};
|
|
1571
|
+
break;
|
|
1572
|
+
case "gpt-5.4-mini":
|
|
1573
|
+
generativeModel = {
|
|
1574
|
+
endpoint: new OpenAIResponses(),
|
|
1575
|
+
specification: gpt54MiniSpecification
|
|
1576
|
+
};
|
|
1577
|
+
break;
|
|
1578
|
+
case "gpt-5.4-nano":
|
|
1579
|
+
generativeModel = {
|
|
1580
|
+
endpoint: new OpenAIResponses(),
|
|
1581
|
+
specification: gpt54NanoSpecification
|
|
1582
|
+
};
|
|
1583
|
+
break;
|
|
1584
|
+
case "gpt-5.5":
|
|
1585
|
+
generativeModel = {
|
|
1586
|
+
endpoint: new OpenAIResponses(),
|
|
1587
|
+
specification: gpt55Specification
|
|
1588
|
+
};
|
|
1589
|
+
break;
|
|
1590
|
+
case "claude-haiku-4-5":
|
|
1591
|
+
generativeModel = {
|
|
1592
|
+
endpoint: new AnthropicMessages(),
|
|
1593
|
+
specification: claudeHaiku45Specification
|
|
1594
|
+
};
|
|
1595
|
+
break;
|
|
1596
|
+
case "claude-sonnet-4-6":
|
|
1597
|
+
generativeModel = {
|
|
1598
|
+
endpoint: new AnthropicMessages(),
|
|
1599
|
+
specification: claudeSonnet46Specification
|
|
1600
|
+
};
|
|
1601
|
+
break;
|
|
1602
|
+
case "claude-opus-4-7":
|
|
1603
|
+
generativeModel = {
|
|
1604
|
+
endpoint: new AnthropicMessages(),
|
|
1605
|
+
specification: claudeOpus47Specification
|
|
1606
|
+
};
|
|
1607
|
+
break;
|
|
1608
|
+
case "claude-opus-4-8":
|
|
1609
|
+
generativeModel = {
|
|
1610
|
+
endpoint: new AnthropicMessages(),
|
|
1611
|
+
specification: claudeOpus48Specification
|
|
1612
|
+
};
|
|
1613
|
+
break;
|
|
1614
|
+
case "gemini-3.5-flash":
|
|
1615
|
+
generativeModel = {
|
|
1616
|
+
endpoint: new GeminiGenerateContent(),
|
|
1617
|
+
specification: gemini35FlashSpecification
|
|
1618
|
+
};
|
|
1619
|
+
break;
|
|
1620
|
+
case "gemini-3.1-pro-preview":
|
|
1621
|
+
generativeModel = {
|
|
1622
|
+
endpoint: new GeminiGenerateContent(),
|
|
1623
|
+
specification: gemini31ProSpecification
|
|
1624
|
+
};
|
|
1625
|
+
break;
|
|
1626
|
+
case "deepseek-v4-flash":
|
|
1627
|
+
generativeModel = {
|
|
1628
|
+
endpoint: new OpenAIChatCompletions(),
|
|
1629
|
+
specification: deepSeekV4FlashSpecification
|
|
1630
|
+
};
|
|
1631
|
+
break;
|
|
1632
|
+
case "deepseek-v4-pro":
|
|
1633
|
+
generativeModel = {
|
|
1634
|
+
endpoint: new OpenAIChatCompletions(),
|
|
1635
|
+
specification: deepSeekV4ProSpecification
|
|
1636
|
+
};
|
|
1637
|
+
}
|
|
1638
|
+
if (!generativeModel) {
|
|
1639
|
+
throw new Error(`Unsupported model: ${modelName}`);
|
|
1640
|
+
}
|
|
1641
|
+
return Promise.resolve(generativeModel);
|
|
1657
1642
|
}
|
|
1658
|
-
|
|
1659
|
-
|
|
1643
|
+
};
|
|
1644
|
+
|
|
1645
|
+
// src/domain/generative-model/request-validation/reasoning-effort.ts
|
|
1646
|
+
var ReasoningEffortValidation = class {
|
|
1647
|
+
constructor() {
|
|
1648
|
+
this.name = "reasoning-effort";
|
|
1660
1649
|
}
|
|
1661
|
-
|
|
1662
|
-
|
|
1650
|
+
isValid(inferenceParams, model) {
|
|
1651
|
+
if (inferenceParams.reasoningEffort === void 0) {
|
|
1652
|
+
return true;
|
|
1653
|
+
}
|
|
1654
|
+
if (!model.supportsReasoningEffort) {
|
|
1655
|
+
return false;
|
|
1656
|
+
}
|
|
1657
|
+
return model.supportedReasoningEfforts.includes(inferenceParams.reasoningEffort);
|
|
1663
1658
|
}
|
|
1664
|
-
|
|
1665
|
-
|
|
1659
|
+
};
|
|
1660
|
+
|
|
1661
|
+
// src/domain/generative-model/request-validation/tool-calling.ts
|
|
1662
|
+
var ToolCallingValidation = class {
|
|
1663
|
+
constructor() {
|
|
1664
|
+
this.name = "tool-calling";
|
|
1666
1665
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1666
|
+
isValid(inferenceParams, model) {
|
|
1667
|
+
if (inferenceParams.tools === void 0) {
|
|
1668
|
+
return true;
|
|
1669
|
+
}
|
|
1670
|
+
return model.supportsFunctionCalling;
|
|
1669
1671
|
}
|
|
1670
1672
|
};
|
|
1671
1673
|
|
|
1672
|
-
// src/
|
|
1673
|
-
var
|
|
1674
|
+
// src/domain/generative-model/request-validation/streaming.ts
|
|
1675
|
+
var StreamingValidation = class {
|
|
1674
1676
|
constructor() {
|
|
1675
|
-
this.
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1677
|
+
this.name = "streaming";
|
|
1678
|
+
}
|
|
1679
|
+
isValid(inferenceParams, model) {
|
|
1680
|
+
if (!inferenceParams.streaming) {
|
|
1681
|
+
return true;
|
|
1682
|
+
}
|
|
1683
|
+
return model.supportsStreaming;
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1686
|
+
|
|
1687
|
+
// src/domain/generative-model/request-validation/context.ts
|
|
1688
|
+
function getContextItemValidationKey(item) {
|
|
1689
|
+
if (item instanceof UserMessageItem) {
|
|
1690
|
+
return "user_message";
|
|
1689
1691
|
}
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
+
if (item instanceof SystemMessageItem) {
|
|
1693
|
+
return "system_message";
|
|
1692
1694
|
}
|
|
1693
|
-
|
|
1694
|
-
return
|
|
1695
|
+
if (item instanceof DeveloperMessageItem) {
|
|
1696
|
+
return "developer_message";
|
|
1695
1697
|
}
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
+
if (item instanceof ModelMessageItem) {
|
|
1699
|
+
return "model_message";
|
|
1698
1700
|
}
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
+
return item.getType();
|
|
1702
|
+
}
|
|
1703
|
+
var ContextValidation = class {
|
|
1704
|
+
constructor() {
|
|
1705
|
+
this.name = "context";
|
|
1701
1706
|
}
|
|
1702
|
-
|
|
1703
|
-
|
|
1707
|
+
isValid(inferenceParams, model) {
|
|
1708
|
+
return inferenceParams.context.items.every(
|
|
1709
|
+
(item) => model.supportedContextItemTypes.includes(getContextItemValidationKey(item))
|
|
1710
|
+
);
|
|
1704
1711
|
}
|
|
1705
|
-
|
|
1706
|
-
|
|
1712
|
+
};
|
|
1713
|
+
|
|
1714
|
+
// src/domain/generative-model/request-validation/inference-request-validator.ts
|
|
1715
|
+
var defaultRequestValidationRules = [
|
|
1716
|
+
new ReasoningEffortValidation(),
|
|
1717
|
+
new ToolCallingValidation(),
|
|
1718
|
+
new StreamingValidation(),
|
|
1719
|
+
new StructuredOutputValidation(),
|
|
1720
|
+
new ContextValidation()
|
|
1721
|
+
];
|
|
1722
|
+
var InferenceRequestValidator = class {
|
|
1723
|
+
constructor(rules = defaultRequestValidationRules) {
|
|
1724
|
+
this.rules = rules;
|
|
1725
|
+
}
|
|
1726
|
+
validate(inferenceParams, model) {
|
|
1727
|
+
for (const rule of this.rules) {
|
|
1728
|
+
if (!rule.isValid(inferenceParams, model)) {
|
|
1729
|
+
throw new Error(`Request validation "${rule.name}" failed for model "${model.name}"`);
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1707
1732
|
}
|
|
1708
1733
|
};
|
|
1734
|
+
|
|
1735
|
+
// src/index.ts
|
|
1736
|
+
var generativeModelRepository = new InMemoryGenerativeModelRepository();
|
|
1737
|
+
var inferenceRequestValidator = new InferenceRequestValidator();
|
|
1738
|
+
var runInferenceUseCase = new RunInference(generativeModelRepository, inferenceRequestValidator);
|
|
1739
|
+
var executeFunctionCallUseCase = new ExecuteFunctionCall(new FunctionCallRunner());
|
|
1740
|
+
var sendMessageUseCase = new SendMessage();
|
|
1741
|
+
var runInference = (inferenceParams) => {
|
|
1742
|
+
runInferenceUseCase.execute(inferenceParams);
|
|
1743
|
+
};
|
|
1744
|
+
var executeFunctionCall = (environment, functionCallItem, tool, caller) => {
|
|
1745
|
+
executeFunctionCallUseCase.execute(environment, functionCallItem, tool, caller);
|
|
1746
|
+
};
|
|
1747
|
+
var sendMessage = (environment, message, caller) => {
|
|
1748
|
+
sendMessageUseCase.execute(environment, message, caller);
|
|
1749
|
+
};
|
|
1709
1750
|
export {
|
|
1710
|
-
Agent,
|
|
1711
1751
|
AgenticEnvironment,
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
BaseHuman,
|
|
1715
|
-
BaseObserver,
|
|
1716
|
-
ClaudeHaiku45,
|
|
1717
|
-
ClaudeOpus47,
|
|
1718
|
-
ClaudeOpus48,
|
|
1719
|
-
ClaudeSonnet46,
|
|
1752
|
+
AgenticError,
|
|
1753
|
+
BaseParticipant,
|
|
1720
1754
|
ContextItem,
|
|
1721
|
-
DeepSeekV4Flash,
|
|
1722
|
-
DeepSeekV4Pro,
|
|
1723
|
-
DefaultFunctionCallRunner,
|
|
1724
|
-
DefaultInferenceRunner,
|
|
1725
1755
|
DeveloperMessageItem,
|
|
1726
1756
|
FunctionCallItem,
|
|
1727
1757
|
FunctionCallOutputItem,
|
|
1728
|
-
Gemini31Pro,
|
|
1729
|
-
Gemini35Flash,
|
|
1730
|
-
GeminiGenerateContent,
|
|
1731
|
-
Gpt54,
|
|
1732
|
-
Gpt54Mini,
|
|
1733
|
-
Gpt54Nano,
|
|
1734
|
-
Gpt55,
|
|
1735
|
-
Human,
|
|
1736
1758
|
InMemoryModelContextRepository,
|
|
1737
|
-
InferenceRequest,
|
|
1738
1759
|
InferenceResponse,
|
|
1739
1760
|
InputTokenDetails,
|
|
1740
1761
|
ModelContext,
|
|
1741
1762
|
ModelMessageItem,
|
|
1742
|
-
Observer,
|
|
1743
|
-
OpenAICompatibleChatCompletions,
|
|
1744
|
-
OpenAIResponses,
|
|
1745
1763
|
OutputTokenDetails,
|
|
1746
1764
|
Participant,
|
|
1747
1765
|
ReasoningItem,
|
|
1748
1766
|
SemanticEvent,
|
|
1749
1767
|
SystemMessageItem,
|
|
1750
1768
|
TokenUsage,
|
|
1751
|
-
UserMessageItem
|
|
1769
|
+
UserMessageItem,
|
|
1770
|
+
executeFunctionCall,
|
|
1771
|
+
runInference,
|
|
1772
|
+
sendMessage
|
|
1752
1773
|
};
|
|
1753
1774
|
//# sourceMappingURL=index.mjs.map
|