@mozaik-ai/core 3.12.0 → 3.13.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/README.md +47 -0
- package/dist/index.d.mts +218 -190
- package/dist/index.d.ts +218 -190
- package/dist/index.js +625 -378
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +619 -369
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/tests/README.md +31 -0
package/dist/index.mjs
CHANGED
|
@@ -255,15 +255,18 @@ var Gpt54Nano = class {
|
|
|
255
255
|
constructor() {
|
|
256
256
|
this.specification = {
|
|
257
257
|
name: "gpt-5.4-nano",
|
|
258
|
+
provider: "openai",
|
|
258
259
|
supportReasoningEffort: true,
|
|
259
260
|
defaultReasoningEffort: "none",
|
|
260
261
|
supportStreaming: true,
|
|
261
262
|
contextWindowSize: 4e5,
|
|
262
263
|
maxOutputTokens: 128e3,
|
|
263
|
-
supportFunctionCalling: true
|
|
264
|
+
supportFunctionCalling: true,
|
|
265
|
+
supportStructuredOutput: true
|
|
264
266
|
};
|
|
265
267
|
this.tools = [];
|
|
266
268
|
this.streaming = false;
|
|
269
|
+
this.structuredOutput = void 0;
|
|
267
270
|
this.effort = new OpenAIReasoningEffort(
|
|
268
271
|
this.specification.defaultReasoningEffort
|
|
269
272
|
);
|
|
@@ -286,6 +289,15 @@ var Gpt54Nano = class {
|
|
|
286
289
|
getReasoningEffort() {
|
|
287
290
|
return this.effort.getReasoningEffort();
|
|
288
291
|
}
|
|
292
|
+
setStructuredOutput(format) {
|
|
293
|
+
this.structuredOutput = format;
|
|
294
|
+
}
|
|
295
|
+
getStructuredOutput() {
|
|
296
|
+
return this.structuredOutput;
|
|
297
|
+
}
|
|
298
|
+
hasStructuredOutput() {
|
|
299
|
+
return this.structuredOutput !== void 0;
|
|
300
|
+
}
|
|
289
301
|
};
|
|
290
302
|
|
|
291
303
|
// src/infrastructure/providers/openai/models/gpt-5-4.ts
|
|
@@ -293,15 +305,18 @@ var Gpt54 = class {
|
|
|
293
305
|
constructor() {
|
|
294
306
|
this.specification = {
|
|
295
307
|
name: "gpt-5.4",
|
|
308
|
+
provider: "openai",
|
|
296
309
|
supportReasoningEffort: true,
|
|
297
310
|
defaultReasoningEffort: "none",
|
|
298
311
|
supportStreaming: true,
|
|
299
312
|
contextWindowSize: 105e4,
|
|
300
313
|
maxOutputTokens: 128e3,
|
|
301
|
-
supportFunctionCalling: true
|
|
314
|
+
supportFunctionCalling: true,
|
|
315
|
+
supportStructuredOutput: true
|
|
302
316
|
};
|
|
303
317
|
this.tools = [];
|
|
304
318
|
this.streaming = false;
|
|
319
|
+
this.structuredOutput = void 0;
|
|
305
320
|
this.effort = new OpenAIReasoningEffort(
|
|
306
321
|
this.specification.defaultReasoningEffort
|
|
307
322
|
);
|
|
@@ -324,6 +339,15 @@ var Gpt54 = class {
|
|
|
324
339
|
getReasoningEffort() {
|
|
325
340
|
return this.effort.getReasoningEffort();
|
|
326
341
|
}
|
|
342
|
+
setStructuredOutput(format) {
|
|
343
|
+
this.structuredOutput = format;
|
|
344
|
+
}
|
|
345
|
+
getStructuredOutput() {
|
|
346
|
+
return this.structuredOutput;
|
|
347
|
+
}
|
|
348
|
+
hasStructuredOutput() {
|
|
349
|
+
return this.structuredOutput !== void 0;
|
|
350
|
+
}
|
|
327
351
|
};
|
|
328
352
|
|
|
329
353
|
// src/infrastructure/providers/openai/models/gpt-5-4-mini.ts
|
|
@@ -331,15 +355,18 @@ var Gpt54Mini = class {
|
|
|
331
355
|
constructor() {
|
|
332
356
|
this.specification = {
|
|
333
357
|
name: "gpt-5.4-mini",
|
|
358
|
+
provider: "openai",
|
|
334
359
|
supportReasoningEffort: true,
|
|
335
360
|
defaultReasoningEffort: "none",
|
|
336
361
|
supportStreaming: true,
|
|
337
362
|
contextWindowSize: 4e5,
|
|
338
363
|
maxOutputTokens: 128e3,
|
|
339
|
-
supportFunctionCalling: true
|
|
364
|
+
supportFunctionCalling: true,
|
|
365
|
+
supportStructuredOutput: true
|
|
340
366
|
};
|
|
341
367
|
this.tools = [];
|
|
342
368
|
this.streaming = false;
|
|
369
|
+
this.structuredOutput = void 0;
|
|
343
370
|
this.effort = new OpenAIReasoningEffort(
|
|
344
371
|
this.specification.defaultReasoningEffort
|
|
345
372
|
);
|
|
@@ -362,6 +389,15 @@ var Gpt54Mini = class {
|
|
|
362
389
|
getTools() {
|
|
363
390
|
return this.tools;
|
|
364
391
|
}
|
|
392
|
+
setStructuredOutput(format) {
|
|
393
|
+
this.structuredOutput = format;
|
|
394
|
+
}
|
|
395
|
+
getStructuredOutput() {
|
|
396
|
+
return this.structuredOutput;
|
|
397
|
+
}
|
|
398
|
+
hasStructuredOutput() {
|
|
399
|
+
return this.structuredOutput !== void 0;
|
|
400
|
+
}
|
|
365
401
|
};
|
|
366
402
|
|
|
367
403
|
// src/domain/generative-model/token-usage.ts
|
|
@@ -452,11 +488,12 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
|
|
|
452
488
|
}
|
|
453
489
|
};
|
|
454
490
|
|
|
455
|
-
// src/domain/agentic-environment/
|
|
491
|
+
// src/domain/agentic-environment/participant.ts
|
|
456
492
|
var Participant = class {
|
|
457
493
|
constructor() {
|
|
458
494
|
this.environments = [];
|
|
459
495
|
this.listens = [];
|
|
496
|
+
this.active = /* @__PURE__ */ new Map();
|
|
460
497
|
}
|
|
461
498
|
join(environment) {
|
|
462
499
|
if (this.isJoinedTo(environment)) {
|
|
@@ -464,6 +501,7 @@ var Participant = class {
|
|
|
464
501
|
}
|
|
465
502
|
environment.subscribe(this);
|
|
466
503
|
this.environments.push(environment);
|
|
504
|
+
this.active.set(environment, true);
|
|
467
505
|
}
|
|
468
506
|
leave(environment) {
|
|
469
507
|
if (!this.isJoinedTo(environment)) {
|
|
@@ -471,6 +509,7 @@ var Participant = class {
|
|
|
471
509
|
}
|
|
472
510
|
environment.unsubscribe(this);
|
|
473
511
|
this.environments = this.environments.filter((e) => e !== environment);
|
|
512
|
+
this.active.delete(environment);
|
|
474
513
|
}
|
|
475
514
|
isJoinedTo(environment) {
|
|
476
515
|
return this.environments.includes(environment);
|
|
@@ -481,14 +520,46 @@ var Participant = class {
|
|
|
481
520
|
getListeners() {
|
|
482
521
|
return this.listens;
|
|
483
522
|
}
|
|
523
|
+
getEnvironmentState(environment) {
|
|
524
|
+
return this.active.get(environment);
|
|
525
|
+
}
|
|
526
|
+
markInactive(environment) {
|
|
527
|
+
if (this.active.has(environment)) {
|
|
528
|
+
this.active.set(environment, false);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
markActive(environment) {
|
|
532
|
+
if (this.active.has(environment)) {
|
|
533
|
+
this.active.set(environment, true);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
// src/domain/agentic-environment/errors/base-error.ts
|
|
539
|
+
var AgenticError = class extends Error {
|
|
540
|
+
constructor({ message, stack, source, enviornment }) {
|
|
541
|
+
super();
|
|
542
|
+
this.message = message;
|
|
543
|
+
this.stack = stack;
|
|
544
|
+
this.source = source;
|
|
545
|
+
this.environment = enviornment;
|
|
546
|
+
}
|
|
547
|
+
getSource() {
|
|
548
|
+
return this.source;
|
|
549
|
+
}
|
|
550
|
+
getEnvironment() {
|
|
551
|
+
return this.environment;
|
|
552
|
+
}
|
|
484
553
|
};
|
|
485
554
|
|
|
486
555
|
// src/domain/agentic-environment/agentic-environment.ts
|
|
487
556
|
var AgenticEnvironment = class {
|
|
488
|
-
constructor(name) {
|
|
557
|
+
constructor(name, opts) {
|
|
489
558
|
this.subscribers = [];
|
|
490
|
-
|
|
559
|
+
var _a;
|
|
491
560
|
this.name = name;
|
|
561
|
+
this.options = opts;
|
|
562
|
+
this.showLogs = ((_a = this.options) == null ? void 0 : _a.silent) !== false;
|
|
492
563
|
}
|
|
493
564
|
subscribe(participant) {
|
|
494
565
|
this.subscribers.push(participant);
|
|
@@ -546,6 +617,32 @@ var AgenticEnvironment = class {
|
|
|
546
617
|
external: (sub) => sub.onExternalEvent(source, item)
|
|
547
618
|
});
|
|
548
619
|
}
|
|
620
|
+
deliverError(source, error) {
|
|
621
|
+
this.deliverToSubscribers(source, {
|
|
622
|
+
internal: (src) => {
|
|
623
|
+
try {
|
|
624
|
+
src.onError(error);
|
|
625
|
+
} catch (error2) {
|
|
626
|
+
if (this.showLogs) {
|
|
627
|
+
console.warn(`[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
|
|
628
|
+
${JSON.stringify({ error: error2 }, null, 2)}`);
|
|
629
|
+
}
|
|
630
|
+
} finally {
|
|
631
|
+
src.markInactive(this);
|
|
632
|
+
}
|
|
633
|
+
},
|
|
634
|
+
external: (sub) => {
|
|
635
|
+
try {
|
|
636
|
+
sub.onParticipantError(source, error);
|
|
637
|
+
} catch (error2) {
|
|
638
|
+
if (this.showLogs) {
|
|
639
|
+
console.warn(`[AgenticEnvironment] Participant.onError() failed. Reason: ${error2}
|
|
640
|
+
${JSON.stringify({ error: error2 }, null, 2)}`);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
}
|
|
549
646
|
getListeningParticipants(source) {
|
|
550
647
|
return this.subscribers.filter(
|
|
551
648
|
(sub) => sub !== source && (sub.getListeners().length === 0 || sub.getListeners().some((listener) => source instanceof listener))
|
|
@@ -555,184 +652,31 @@ var AgenticEnvironment = class {
|
|
|
555
652
|
var _a, _b;
|
|
556
653
|
const authorizedListeners = this.getListeningParticipants(source);
|
|
557
654
|
for (const subscriber of this.subscribers) {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
stop() {
|
|
572
|
-
this.isActive = false;
|
|
573
|
-
}
|
|
574
|
-
};
|
|
575
|
-
|
|
576
|
-
// src/domain/agentic-environment/participants/agent.ts
|
|
577
|
-
var Agent = class extends Participant {
|
|
578
|
-
};
|
|
579
|
-
|
|
580
|
-
// src/domain/model-context/semantic-event/semantic-event.ts
|
|
581
|
-
var SemanticEvent = class {
|
|
582
|
-
constructor(type, data) {
|
|
583
|
-
this.type = type;
|
|
584
|
-
this.data = data;
|
|
585
|
-
}
|
|
586
|
-
getType() {
|
|
587
|
-
return this.type;
|
|
588
|
-
}
|
|
589
|
-
};
|
|
590
|
-
|
|
591
|
-
// src/application/participants/agent.ts
|
|
592
|
-
var BaseAgent = class extends Agent {
|
|
593
|
-
constructor(inferenceRunner, functionCallRunner) {
|
|
594
|
-
super();
|
|
595
|
-
this.inferenceRunner = inferenceRunner;
|
|
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);
|
|
655
|
+
const isActive = subscriber.getEnvironmentState(this);
|
|
656
|
+
if (isActive) {
|
|
657
|
+
try {
|
|
658
|
+
if (subscriber === source) {
|
|
659
|
+
(_a = handlers == null ? void 0 : handlers.internal) == null ? void 0 : _a.call(handlers, subscriber);
|
|
660
|
+
} else if (authorizedListeners.includes(subscriber)) {
|
|
661
|
+
(_b = handlers == null ? void 0 : handlers.external) == null ? void 0 : _b.call(handlers, subscriber);
|
|
662
|
+
}
|
|
663
|
+
} catch (error) {
|
|
664
|
+
this.handleError(subscriber, error);
|
|
665
|
+
}
|
|
647
666
|
}
|
|
648
667
|
}
|
|
649
668
|
}
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
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) {
|
|
691
|
-
}
|
|
692
|
-
};
|
|
693
|
-
|
|
694
|
-
// src/domain/generative-model/inference-request.ts
|
|
695
|
-
var InferenceRequest = class {
|
|
696
|
-
constructor(model, context) {
|
|
697
|
-
this.model = model;
|
|
698
|
-
this.context = context;
|
|
699
|
-
}
|
|
700
|
-
};
|
|
701
|
-
|
|
702
|
-
// src/application/runners/inference-runner.ts
|
|
703
|
-
var DefaultInferenceRunner = class {
|
|
704
|
-
constructor(runtime) {
|
|
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);
|
|
711
|
-
return;
|
|
669
|
+
handleError(subscriber, error) {
|
|
670
|
+
if (error instanceof AgenticError) {
|
|
671
|
+
return this.deliverError(subscriber, error);
|
|
712
672
|
}
|
|
713
|
-
const
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
}
|
|
721
|
-
isStreamingRuntime(runtime) {
|
|
722
|
-
return typeof runtime.stream === "function";
|
|
723
|
-
}
|
|
724
|
-
};
|
|
725
|
-
|
|
726
|
-
// src/application/runners/function-call-runner.ts
|
|
727
|
-
var DefaultFunctionCallRunner = class {
|
|
728
|
-
constructor(tools) {
|
|
729
|
-
this.tools = tools;
|
|
730
|
-
}
|
|
731
|
-
async *run(call, signal) {
|
|
732
|
-
const tool = this.tools.find((t) => t.name === call.name);
|
|
733
|
-
if (!tool) throw new Error(`Unknown tool: ${call.name}`);
|
|
734
|
-
const result = await tool.invoke(JSON.parse(call.args));
|
|
735
|
-
yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
|
|
673
|
+
const agenticError = new AgenticError({
|
|
674
|
+
message: error.message,
|
|
675
|
+
stack: error.stack,
|
|
676
|
+
enviornment: this,
|
|
677
|
+
source: subscriber
|
|
678
|
+
});
|
|
679
|
+
return this.deliverError(subscriber, agenticError);
|
|
736
680
|
}
|
|
737
681
|
};
|
|
738
682
|
|
|
@@ -741,15 +685,18 @@ var Gpt55 = class {
|
|
|
741
685
|
constructor() {
|
|
742
686
|
this.specification = {
|
|
743
687
|
name: "gpt-5.5",
|
|
688
|
+
provider: "openai",
|
|
744
689
|
supportReasoningEffort: true,
|
|
745
690
|
defaultReasoningEffort: "none",
|
|
746
691
|
supportStreaming: true,
|
|
747
692
|
contextWindowSize: 105e4,
|
|
748
693
|
maxOutputTokens: 128e3,
|
|
749
|
-
supportFunctionCalling: true
|
|
694
|
+
supportFunctionCalling: true,
|
|
695
|
+
supportStructuredOutput: true
|
|
750
696
|
};
|
|
751
697
|
this.tools = [];
|
|
752
698
|
this.streaming = false;
|
|
699
|
+
this.structuredOutput = void 0;
|
|
753
700
|
this.effort = new OpenAIReasoningEffort(
|
|
754
701
|
this.specification.defaultReasoningEffort
|
|
755
702
|
);
|
|
@@ -772,47 +719,37 @@ var Gpt55 = class {
|
|
|
772
719
|
getReasoningEffort() {
|
|
773
720
|
return this.effort.getReasoningEffort();
|
|
774
721
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
// src/domain/agentic-environment/participants/observer.ts
|
|
778
|
-
var Observer = class extends Participant {
|
|
779
|
-
};
|
|
780
|
-
|
|
781
|
-
// src/application/participants/observer.ts
|
|
782
|
-
var BaseObserver = class extends Observer {
|
|
783
|
-
onFunctionCall(item) {
|
|
784
|
-
}
|
|
785
|
-
onExternalFunctionCall(source, item) {
|
|
722
|
+
setStructuredOutput(format) {
|
|
723
|
+
this.structuredOutput = format;
|
|
786
724
|
}
|
|
787
|
-
|
|
725
|
+
getStructuredOutput() {
|
|
726
|
+
return this.structuredOutput;
|
|
788
727
|
}
|
|
789
|
-
|
|
728
|
+
hasStructuredOutput() {
|
|
729
|
+
return this.structuredOutput !== void 0;
|
|
790
730
|
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
}
|
|
799
|
-
onMessage(message) {
|
|
800
|
-
}
|
|
801
|
-
onJoined() {
|
|
802
|
-
}
|
|
803
|
-
onLeft() {
|
|
804
|
-
}
|
|
805
|
-
onParticipantJoined(participant) {
|
|
806
|
-
}
|
|
807
|
-
onParticipantLeft(participant) {
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
// src/domain/model-context/semantic-event/semantic-event.ts
|
|
734
|
+
var SemanticEvent = class {
|
|
735
|
+
constructor(type, data) {
|
|
736
|
+
this.type = type;
|
|
737
|
+
this.data = data;
|
|
808
738
|
}
|
|
809
|
-
|
|
739
|
+
getType() {
|
|
740
|
+
return this.type;
|
|
810
741
|
}
|
|
811
|
-
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
// src/domain/agentic-environment/inference/request.ts
|
|
745
|
+
var InferenceRequest = class {
|
|
746
|
+
constructor(model, context) {
|
|
747
|
+
this.model = model;
|
|
748
|
+
this.context = context;
|
|
812
749
|
}
|
|
813
750
|
};
|
|
814
751
|
|
|
815
|
-
// src/domain/
|
|
752
|
+
// src/domain/agentic-environment/inference/response.ts
|
|
816
753
|
var InferenceResponse = class {
|
|
817
754
|
constructor(contextItems, tokenUsage) {
|
|
818
755
|
this.contextItems = contextItems;
|
|
@@ -848,6 +785,7 @@ var OpenAIResponses = class {
|
|
|
848
785
|
}
|
|
849
786
|
}
|
|
850
787
|
buildRequest(inferenceRequest) {
|
|
788
|
+
var _a, _b;
|
|
851
789
|
const specification = inferenceRequest.model.specification;
|
|
852
790
|
const input = this.mapContextToRequest(inferenceRequest.context);
|
|
853
791
|
const request = {
|
|
@@ -869,6 +807,20 @@ var OpenAIResponses = class {
|
|
|
869
807
|
effort: inferenceRequest.model.getReasoningEffort()
|
|
870
808
|
};
|
|
871
809
|
}
|
|
810
|
+
if (inferenceRequest.model.hasStructuredOutput()) {
|
|
811
|
+
if (!specification.supportStructuredOutput) {
|
|
812
|
+
throw new Error(`Structured output is not supported for model: ${specification.name}`);
|
|
813
|
+
}
|
|
814
|
+
const format = inferenceRequest.model.getStructuredOutput();
|
|
815
|
+
request.text = {
|
|
816
|
+
format: {
|
|
817
|
+
type: "json_schema",
|
|
818
|
+
name: (_a = format.name) != null ? _a : "response",
|
|
819
|
+
schema: format.schema,
|
|
820
|
+
strict: (_b = format.strict) != null ? _b : true
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
}
|
|
872
824
|
return request;
|
|
873
825
|
}
|
|
874
826
|
extractTokenUsage(response) {
|
|
@@ -901,143 +853,7 @@ var OpenAIResponses = class {
|
|
|
901
853
|
if (item.type === "reasoning") {
|
|
902
854
|
return ReasoningItem.rehydrate(item);
|
|
903
855
|
}
|
|
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
|
|
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;
|
|
856
|
+
});
|
|
1041
857
|
}
|
|
1042
858
|
};
|
|
1043
859
|
|
|
@@ -1096,6 +912,18 @@ var AnthropicMessages = class {
|
|
|
1096
912
|
};
|
|
1097
913
|
}
|
|
1098
914
|
}
|
|
915
|
+
if (inferenceRequest.model.hasStructuredOutput()) {
|
|
916
|
+
if (!specification.supportStructuredOutput) {
|
|
917
|
+
throw new Error(`Structured output is not supported for model: ${specification.name}`);
|
|
918
|
+
}
|
|
919
|
+
const format = inferenceRequest.model.getStructuredOutput();
|
|
920
|
+
request.output_config = {
|
|
921
|
+
format: {
|
|
922
|
+
type: "json_schema",
|
|
923
|
+
json_schema: format.schema
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
}
|
|
1099
927
|
return request;
|
|
1100
928
|
}
|
|
1101
929
|
extractTokenUsage(response) {
|
|
@@ -1221,15 +1049,18 @@ var ClaudeOpus48 = class {
|
|
|
1221
1049
|
constructor() {
|
|
1222
1050
|
this.specification = {
|
|
1223
1051
|
name: "claude-opus-4-8",
|
|
1052
|
+
provider: "anthropic",
|
|
1224
1053
|
supportReasoningEffort: true,
|
|
1225
1054
|
defaultReasoningEffort: "none",
|
|
1226
1055
|
supportStreaming: true,
|
|
1227
1056
|
contextWindowSize: 2e5,
|
|
1228
1057
|
maxOutputTokens: 32e3,
|
|
1229
|
-
supportFunctionCalling: true
|
|
1058
|
+
supportFunctionCalling: true,
|
|
1059
|
+
supportStructuredOutput: true
|
|
1230
1060
|
};
|
|
1231
1061
|
this.tools = [];
|
|
1232
1062
|
this.streaming = false;
|
|
1063
|
+
this.structuredOutput = void 0;
|
|
1233
1064
|
this.effort = new AnthropicReasoningEffort(
|
|
1234
1065
|
this.specification.defaultReasoningEffort
|
|
1235
1066
|
);
|
|
@@ -1252,6 +1083,15 @@ var ClaudeOpus48 = class {
|
|
|
1252
1083
|
getReasoningEffort() {
|
|
1253
1084
|
return this.effort.getReasoningEffort();
|
|
1254
1085
|
}
|
|
1086
|
+
setStructuredOutput(format) {
|
|
1087
|
+
this.structuredOutput = format;
|
|
1088
|
+
}
|
|
1089
|
+
getStructuredOutput() {
|
|
1090
|
+
return this.structuredOutput;
|
|
1091
|
+
}
|
|
1092
|
+
hasStructuredOutput() {
|
|
1093
|
+
return this.structuredOutput !== void 0;
|
|
1094
|
+
}
|
|
1255
1095
|
};
|
|
1256
1096
|
|
|
1257
1097
|
// src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
|
|
@@ -1259,15 +1099,18 @@ var ClaudeOpus47 = class {
|
|
|
1259
1099
|
constructor() {
|
|
1260
1100
|
this.specification = {
|
|
1261
1101
|
name: "claude-opus-4-7",
|
|
1102
|
+
provider: "anthropic",
|
|
1262
1103
|
supportReasoningEffort: true,
|
|
1263
1104
|
defaultReasoningEffort: "none",
|
|
1264
1105
|
supportStreaming: true,
|
|
1265
1106
|
contextWindowSize: 2e5,
|
|
1266
1107
|
maxOutputTokens: 32e3,
|
|
1267
|
-
supportFunctionCalling: true
|
|
1108
|
+
supportFunctionCalling: true,
|
|
1109
|
+
supportStructuredOutput: true
|
|
1268
1110
|
};
|
|
1269
1111
|
this.tools = [];
|
|
1270
1112
|
this.streaming = false;
|
|
1113
|
+
this.structuredOutput = void 0;
|
|
1271
1114
|
this.effort = new AnthropicReasoningEffort(
|
|
1272
1115
|
this.specification.defaultReasoningEffort
|
|
1273
1116
|
);
|
|
@@ -1290,6 +1133,15 @@ var ClaudeOpus47 = class {
|
|
|
1290
1133
|
getReasoningEffort() {
|
|
1291
1134
|
return this.effort.getReasoningEffort();
|
|
1292
1135
|
}
|
|
1136
|
+
setStructuredOutput(format) {
|
|
1137
|
+
this.structuredOutput = format;
|
|
1138
|
+
}
|
|
1139
|
+
getStructuredOutput() {
|
|
1140
|
+
return this.structuredOutput;
|
|
1141
|
+
}
|
|
1142
|
+
hasStructuredOutput() {
|
|
1143
|
+
return this.structuredOutput !== void 0;
|
|
1144
|
+
}
|
|
1293
1145
|
};
|
|
1294
1146
|
|
|
1295
1147
|
// src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts
|
|
@@ -1297,15 +1149,18 @@ var ClaudeSonnet46 = class {
|
|
|
1297
1149
|
constructor() {
|
|
1298
1150
|
this.specification = {
|
|
1299
1151
|
name: "claude-sonnet-4-6",
|
|
1152
|
+
provider: "anthropic",
|
|
1300
1153
|
supportReasoningEffort: true,
|
|
1301
1154
|
defaultReasoningEffort: "none",
|
|
1302
1155
|
supportStreaming: true,
|
|
1303
1156
|
contextWindowSize: 2e5,
|
|
1304
1157
|
maxOutputTokens: 64e3,
|
|
1305
|
-
supportFunctionCalling: true
|
|
1158
|
+
supportFunctionCalling: true,
|
|
1159
|
+
supportStructuredOutput: true
|
|
1306
1160
|
};
|
|
1307
1161
|
this.tools = [];
|
|
1308
1162
|
this.streaming = false;
|
|
1163
|
+
this.structuredOutput = void 0;
|
|
1309
1164
|
this.effort = new AnthropicReasoningEffort(
|
|
1310
1165
|
this.specification.defaultReasoningEffort
|
|
1311
1166
|
);
|
|
@@ -1328,6 +1183,15 @@ var ClaudeSonnet46 = class {
|
|
|
1328
1183
|
getReasoningEffort() {
|
|
1329
1184
|
return this.effort.getReasoningEffort();
|
|
1330
1185
|
}
|
|
1186
|
+
setStructuredOutput(format) {
|
|
1187
|
+
this.structuredOutput = format;
|
|
1188
|
+
}
|
|
1189
|
+
getStructuredOutput() {
|
|
1190
|
+
return this.structuredOutput;
|
|
1191
|
+
}
|
|
1192
|
+
hasStructuredOutput() {
|
|
1193
|
+
return this.structuredOutput !== void 0;
|
|
1194
|
+
}
|
|
1331
1195
|
};
|
|
1332
1196
|
|
|
1333
1197
|
// src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts
|
|
@@ -1335,15 +1199,18 @@ var ClaudeHaiku45 = class {
|
|
|
1335
1199
|
constructor() {
|
|
1336
1200
|
this.specification = {
|
|
1337
1201
|
name: "claude-haiku-4-5",
|
|
1202
|
+
provider: "anthropic",
|
|
1338
1203
|
supportReasoningEffort: true,
|
|
1339
1204
|
defaultReasoningEffort: "none",
|
|
1340
1205
|
supportStreaming: true,
|
|
1341
1206
|
contextWindowSize: 2e5,
|
|
1342
1207
|
maxOutputTokens: 64e3,
|
|
1343
|
-
supportFunctionCalling: true
|
|
1208
|
+
supportFunctionCalling: true,
|
|
1209
|
+
supportStructuredOutput: true
|
|
1344
1210
|
};
|
|
1345
1211
|
this.tools = [];
|
|
1346
1212
|
this.streaming = false;
|
|
1213
|
+
this.structuredOutput = void 0;
|
|
1347
1214
|
this.effort = new AnthropicReasoningEffort(
|
|
1348
1215
|
this.specification.defaultReasoningEffort
|
|
1349
1216
|
);
|
|
@@ -1366,6 +1233,15 @@ var ClaudeHaiku45 = class {
|
|
|
1366
1233
|
getReasoningEffort() {
|
|
1367
1234
|
return this.effort.getReasoningEffort();
|
|
1368
1235
|
}
|
|
1236
|
+
setStructuredOutput(format) {
|
|
1237
|
+
this.structuredOutput = format;
|
|
1238
|
+
}
|
|
1239
|
+
getStructuredOutput() {
|
|
1240
|
+
return this.structuredOutput;
|
|
1241
|
+
}
|
|
1242
|
+
hasStructuredOutput() {
|
|
1243
|
+
return this.structuredOutput !== void 0;
|
|
1244
|
+
}
|
|
1369
1245
|
};
|
|
1370
1246
|
|
|
1371
1247
|
// src/infrastructure/providers/deepseek/reasoning-effort.ts
|
|
@@ -1389,15 +1265,18 @@ var DeepSeekV4Flash = class {
|
|
|
1389
1265
|
constructor() {
|
|
1390
1266
|
this.specification = {
|
|
1391
1267
|
name: "deepseek-v4-flash",
|
|
1268
|
+
provider: "deepseek",
|
|
1392
1269
|
supportReasoningEffort: true,
|
|
1393
1270
|
defaultReasoningEffort: "high",
|
|
1394
1271
|
supportStreaming: true,
|
|
1395
1272
|
contextWindowSize: 1e6,
|
|
1396
1273
|
maxOutputTokens: 384e3,
|
|
1397
|
-
supportFunctionCalling: true
|
|
1274
|
+
supportFunctionCalling: true,
|
|
1275
|
+
supportStructuredOutput: false
|
|
1398
1276
|
};
|
|
1399
1277
|
this.tools = [];
|
|
1400
1278
|
this.streaming = false;
|
|
1279
|
+
this.structuredOutput = void 0;
|
|
1401
1280
|
this.effort = new DeepSeekReasoningEffort(
|
|
1402
1281
|
this.specification.defaultReasoningEffort
|
|
1403
1282
|
);
|
|
@@ -1420,6 +1299,15 @@ var DeepSeekV4Flash = class {
|
|
|
1420
1299
|
getReasoningEffort() {
|
|
1421
1300
|
return this.effort.getReasoningEffort();
|
|
1422
1301
|
}
|
|
1302
|
+
setStructuredOutput(format) {
|
|
1303
|
+
this.structuredOutput = format;
|
|
1304
|
+
}
|
|
1305
|
+
getStructuredOutput() {
|
|
1306
|
+
return this.structuredOutput;
|
|
1307
|
+
}
|
|
1308
|
+
hasStructuredOutput() {
|
|
1309
|
+
return this.structuredOutput !== void 0;
|
|
1310
|
+
}
|
|
1423
1311
|
};
|
|
1424
1312
|
|
|
1425
1313
|
// src/infrastructure/providers/deepseek/models/deepseek-v4-pro.ts
|
|
@@ -1427,15 +1315,18 @@ var DeepSeekV4Pro = class {
|
|
|
1427
1315
|
constructor() {
|
|
1428
1316
|
this.specification = {
|
|
1429
1317
|
name: "deepseek-v4-pro",
|
|
1318
|
+
provider: "deepseek",
|
|
1430
1319
|
supportReasoningEffort: true,
|
|
1431
1320
|
defaultReasoningEffort: "high",
|
|
1432
1321
|
supportStreaming: true,
|
|
1433
1322
|
contextWindowSize: 1e6,
|
|
1434
1323
|
maxOutputTokens: 384e3,
|
|
1435
|
-
supportFunctionCalling: true
|
|
1324
|
+
supportFunctionCalling: true,
|
|
1325
|
+
supportStructuredOutput: false
|
|
1436
1326
|
};
|
|
1437
1327
|
this.tools = [];
|
|
1438
1328
|
this.streaming = false;
|
|
1329
|
+
this.structuredOutput = void 0;
|
|
1439
1330
|
this.effort = new DeepSeekReasoningEffort(
|
|
1440
1331
|
this.specification.defaultReasoningEffort
|
|
1441
1332
|
);
|
|
@@ -1458,6 +1349,15 @@ var DeepSeekV4Pro = class {
|
|
|
1458
1349
|
getReasoningEffort() {
|
|
1459
1350
|
return this.effort.getReasoningEffort();
|
|
1460
1351
|
}
|
|
1352
|
+
setStructuredOutput(format) {
|
|
1353
|
+
this.structuredOutput = format;
|
|
1354
|
+
}
|
|
1355
|
+
getStructuredOutput() {
|
|
1356
|
+
return this.structuredOutput;
|
|
1357
|
+
}
|
|
1358
|
+
hasStructuredOutput() {
|
|
1359
|
+
return this.structuredOutput !== void 0;
|
|
1360
|
+
}
|
|
1461
1361
|
};
|
|
1462
1362
|
|
|
1463
1363
|
// src/infrastructure/providers/gemini/runtime/gemini-generate-content.ts
|
|
@@ -1506,6 +1406,14 @@ var GeminiGenerateContent = class {
|
|
|
1506
1406
|
const thinkingLevel = effort === "none" ? "minimal" : effort;
|
|
1507
1407
|
config.thinkingConfig = { thinkingLevel, includeThoughts: true };
|
|
1508
1408
|
}
|
|
1409
|
+
if (inferenceRequest.model.hasStructuredOutput()) {
|
|
1410
|
+
if (!specification.supportStructuredOutput) {
|
|
1411
|
+
throw new Error(`Structured output is not supported for model: ${specification.name}`);
|
|
1412
|
+
}
|
|
1413
|
+
const format = inferenceRequest.model.getStructuredOutput();
|
|
1414
|
+
config.responseMimeType = "application/json";
|
|
1415
|
+
config.responseSchema = format.schema;
|
|
1416
|
+
}
|
|
1509
1417
|
return { model: specification.name, contents, config };
|
|
1510
1418
|
}
|
|
1511
1419
|
extractTokenUsage(response) {
|
|
@@ -1636,15 +1544,18 @@ var Gemini35Flash = class {
|
|
|
1636
1544
|
constructor() {
|
|
1637
1545
|
this.specification = {
|
|
1638
1546
|
name: "gemini-3.5-flash",
|
|
1547
|
+
provider: "google",
|
|
1639
1548
|
supportReasoningEffort: true,
|
|
1640
1549
|
defaultReasoningEffort: "medium",
|
|
1641
1550
|
supportStreaming: true,
|
|
1642
1551
|
contextWindowSize: 1048576,
|
|
1643
1552
|
maxOutputTokens: 64e3,
|
|
1644
|
-
supportFunctionCalling: true
|
|
1553
|
+
supportFunctionCalling: true,
|
|
1554
|
+
supportStructuredOutput: true
|
|
1645
1555
|
};
|
|
1646
1556
|
this.tools = [];
|
|
1647
1557
|
this.streaming = false;
|
|
1558
|
+
this.structuredOutput = void 0;
|
|
1648
1559
|
this.effort = new GeminiReasoningEffort(
|
|
1649
1560
|
this.specification.defaultReasoningEffort
|
|
1650
1561
|
);
|
|
@@ -1667,6 +1578,15 @@ var Gemini35Flash = class {
|
|
|
1667
1578
|
getReasoningEffort() {
|
|
1668
1579
|
return this.effort.getReasoningEffort();
|
|
1669
1580
|
}
|
|
1581
|
+
setStructuredOutput(format) {
|
|
1582
|
+
this.structuredOutput = format;
|
|
1583
|
+
}
|
|
1584
|
+
getStructuredOutput() {
|
|
1585
|
+
return this.structuredOutput;
|
|
1586
|
+
}
|
|
1587
|
+
hasStructuredOutput() {
|
|
1588
|
+
return this.structuredOutput !== void 0;
|
|
1589
|
+
}
|
|
1670
1590
|
};
|
|
1671
1591
|
|
|
1672
1592
|
// src/infrastructure/providers/gemini/models/gemini-3-1-pro.ts
|
|
@@ -1674,15 +1594,18 @@ var Gemini31Pro = class {
|
|
|
1674
1594
|
constructor() {
|
|
1675
1595
|
this.specification = {
|
|
1676
1596
|
name: "gemini-3.1-pro-preview",
|
|
1597
|
+
provider: "google",
|
|
1677
1598
|
supportReasoningEffort: true,
|
|
1678
1599
|
defaultReasoningEffort: "high",
|
|
1679
1600
|
supportStreaming: true,
|
|
1680
1601
|
contextWindowSize: 1048576,
|
|
1681
1602
|
maxOutputTokens: 64e3,
|
|
1682
|
-
supportFunctionCalling: true
|
|
1603
|
+
supportFunctionCalling: true,
|
|
1604
|
+
supportStructuredOutput: true
|
|
1683
1605
|
};
|
|
1684
1606
|
this.tools = [];
|
|
1685
1607
|
this.streaming = false;
|
|
1608
|
+
this.structuredOutput = void 0;
|
|
1686
1609
|
this.effort = new GeminiReasoningEffort(
|
|
1687
1610
|
this.specification.defaultReasoningEffort
|
|
1688
1611
|
);
|
|
@@ -1705,14 +1628,342 @@ var Gemini31Pro = class {
|
|
|
1705
1628
|
getReasoningEffort() {
|
|
1706
1629
|
return this.effort.getReasoningEffort();
|
|
1707
1630
|
}
|
|
1631
|
+
setStructuredOutput(format) {
|
|
1632
|
+
this.structuredOutput = format;
|
|
1633
|
+
}
|
|
1634
|
+
getStructuredOutput() {
|
|
1635
|
+
return this.structuredOutput;
|
|
1636
|
+
}
|
|
1637
|
+
hasStructuredOutput() {
|
|
1638
|
+
return this.structuredOutput !== void 0;
|
|
1639
|
+
}
|
|
1640
|
+
};
|
|
1641
|
+
|
|
1642
|
+
// src/infrastructure/providers/openai/runtime/openai-chat-completions.ts
|
|
1643
|
+
import OpenAI2 from "openai";
|
|
1644
|
+
var OpenAIChatCompletions = class {
|
|
1645
|
+
constructor(config = {}) {
|
|
1646
|
+
var _a;
|
|
1647
|
+
this.client = new OpenAI2({
|
|
1648
|
+
baseURL: config.baseURL,
|
|
1649
|
+
apiKey: config.apiKey
|
|
1650
|
+
});
|
|
1651
|
+
this.extraBody = (_a = config.extraBody) != null ? _a : {};
|
|
1652
|
+
}
|
|
1653
|
+
async infer(inferenceRequest) {
|
|
1654
|
+
const response = await this.client.chat.completions.create(this.buildRequest(inferenceRequest));
|
|
1655
|
+
const contextItems = this.extractContextItems(response);
|
|
1656
|
+
const tokenUsage = this.extractTokenUsage(response);
|
|
1657
|
+
return new InferenceResponse(contextItems, tokenUsage);
|
|
1658
|
+
}
|
|
1659
|
+
async *stream(inferenceRequest, signal) {
|
|
1660
|
+
var _a;
|
|
1661
|
+
const stream = await this.client.chat.completions.create({
|
|
1662
|
+
...this.buildRequest(inferenceRequest),
|
|
1663
|
+
stream: true
|
|
1664
|
+
});
|
|
1665
|
+
for await (const event of stream) {
|
|
1666
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1667
|
+
break;
|
|
1668
|
+
}
|
|
1669
|
+
yield new SemanticEvent((_a = event.object) != null ? _a : "chat.completion.chunk", event);
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
buildRequest(inferenceRequest) {
|
|
1673
|
+
const specification = inferenceRequest.model.specification;
|
|
1674
|
+
const request = {
|
|
1675
|
+
...this.extraBody,
|
|
1676
|
+
model: specification.name,
|
|
1677
|
+
messages: this.mapContextToRequest(inferenceRequest.context)
|
|
1678
|
+
};
|
|
1679
|
+
if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
|
|
1680
|
+
request.tools = inferenceRequest.model.getTools().map((tool) => {
|
|
1681
|
+
return {
|
|
1682
|
+
type: "function",
|
|
1683
|
+
function: {
|
|
1684
|
+
name: tool.name,
|
|
1685
|
+
description: tool.description,
|
|
1686
|
+
parameters: tool.parameters
|
|
1687
|
+
}
|
|
1688
|
+
};
|
|
1689
|
+
});
|
|
1690
|
+
}
|
|
1691
|
+
if (specification.supportReasoningEffort) {
|
|
1692
|
+
request.reasoning_effort = inferenceRequest.model.getReasoningEffort();
|
|
1693
|
+
}
|
|
1694
|
+
return request;
|
|
1695
|
+
}
|
|
1696
|
+
extractTokenUsage(response) {
|
|
1697
|
+
var _a, _b, _c, _d;
|
|
1698
|
+
if (!response.usage) {
|
|
1699
|
+
return void 0;
|
|
1700
|
+
}
|
|
1701
|
+
return new TokenUsage(
|
|
1702
|
+
response.usage.prompt_tokens,
|
|
1703
|
+
response.usage.completion_tokens,
|
|
1704
|
+
response.usage.total_tokens,
|
|
1705
|
+
new InputTokenDetails((_b = (_a = response.usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) != null ? _b : 0),
|
|
1706
|
+
new OutputTokenDetails((_d = (_c = response.usage.completion_tokens_details) == null ? void 0 : _c.reasoning_tokens) != null ? _d : 0)
|
|
1707
|
+
);
|
|
1708
|
+
}
|
|
1709
|
+
mapContextToRequest(context) {
|
|
1710
|
+
var _a;
|
|
1711
|
+
const messages = [];
|
|
1712
|
+
for (const item of context.getItems()) {
|
|
1713
|
+
if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
|
|
1714
|
+
messages.push({ role: "system", content: item.content.text });
|
|
1715
|
+
continue;
|
|
1716
|
+
}
|
|
1717
|
+
if (item instanceof UserMessageItem) {
|
|
1718
|
+
messages.push({ role: "user", content: item.content.text });
|
|
1719
|
+
continue;
|
|
1720
|
+
}
|
|
1721
|
+
if (item instanceof ModelMessageItem) {
|
|
1722
|
+
messages.push({ role: "assistant", content: item.content.text });
|
|
1723
|
+
continue;
|
|
1724
|
+
}
|
|
1725
|
+
if (item instanceof FunctionCallItem) {
|
|
1726
|
+
const toolCall = {
|
|
1727
|
+
id: item.callId,
|
|
1728
|
+
type: "function",
|
|
1729
|
+
function: { name: item.name, arguments: item.args }
|
|
1730
|
+
};
|
|
1731
|
+
const last = messages[messages.length - 1];
|
|
1732
|
+
if ((last == null ? void 0 : last.role) === "assistant") {
|
|
1733
|
+
last.tool_calls = (_a = last.tool_calls) != null ? _a : [];
|
|
1734
|
+
last.tool_calls.push(toolCall);
|
|
1735
|
+
} else {
|
|
1736
|
+
messages.push({ role: "assistant", content: null, tool_calls: [toolCall] });
|
|
1737
|
+
}
|
|
1738
|
+
continue;
|
|
1739
|
+
}
|
|
1740
|
+
if (item instanceof FunctionCallOutputItem) {
|
|
1741
|
+
messages.push({ role: "tool", tool_call_id: item.callId, content: item.output.text });
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
return messages;
|
|
1745
|
+
}
|
|
1746
|
+
extractContextItems(response) {
|
|
1747
|
+
var _a, _b, _c;
|
|
1748
|
+
const items = [];
|
|
1749
|
+
const message = (_b = (_a = response.choices) == null ? void 0 : _a[0]) == null ? void 0 : _b.message;
|
|
1750
|
+
if (!message) {
|
|
1751
|
+
return items;
|
|
1752
|
+
}
|
|
1753
|
+
if (message.reasoning_content) {
|
|
1754
|
+
items.push(
|
|
1755
|
+
ReasoningItem.rehydrate({
|
|
1756
|
+
content: InputText.rehydrate({ text: message.reasoning_content }),
|
|
1757
|
+
encryptedContent: void 0,
|
|
1758
|
+
summary: []
|
|
1759
|
+
})
|
|
1760
|
+
);
|
|
1761
|
+
}
|
|
1762
|
+
if (message.content) {
|
|
1763
|
+
items.push(ModelMessageItem.rehydrate({ text: message.content }));
|
|
1764
|
+
}
|
|
1765
|
+
for (const toolCall of (_c = message.tool_calls) != null ? _c : []) {
|
|
1766
|
+
items.push(
|
|
1767
|
+
FunctionCallItem.rehydrate({
|
|
1768
|
+
callId: toolCall.id,
|
|
1769
|
+
name: toolCall.function.name,
|
|
1770
|
+
args: toolCall.function.arguments
|
|
1771
|
+
})
|
|
1772
|
+
);
|
|
1773
|
+
}
|
|
1774
|
+
return items;
|
|
1775
|
+
}
|
|
1776
|
+
};
|
|
1777
|
+
|
|
1778
|
+
// src/application/services/inference-runner.ts
|
|
1779
|
+
var InferenceRunner = class {
|
|
1780
|
+
async *run(context, modelInfo, signal) {
|
|
1781
|
+
const { model, endpoint } = modelInfo;
|
|
1782
|
+
const request = new InferenceRequest(model, context);
|
|
1783
|
+
if (model.getStreaming()) {
|
|
1784
|
+
yield* endpoint.stream(request);
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1787
|
+
const response = await endpoint.infer(request);
|
|
1788
|
+
for (const item of response.contextItems) {
|
|
1789
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1790
|
+
break;
|
|
1791
|
+
}
|
|
1792
|
+
yield item;
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
};
|
|
1796
|
+
|
|
1797
|
+
// src/application/use-cases/run-inference.ts
|
|
1798
|
+
var RunInference = class {
|
|
1799
|
+
constructor(modelRepository, inferenceRunner) {
|
|
1800
|
+
this.modelRepository = modelRepository;
|
|
1801
|
+
this.inferenceRunner = inferenceRunner;
|
|
1802
|
+
}
|
|
1803
|
+
setModelCapabilities(model, inferenceParams) {
|
|
1804
|
+
const { streaming, tools, reasoningEffort, structuredOutput } = inferenceParams;
|
|
1805
|
+
if (streaming) {
|
|
1806
|
+
model.setStreaming(true);
|
|
1807
|
+
}
|
|
1808
|
+
if (tools) {
|
|
1809
|
+
model.setTools(tools);
|
|
1810
|
+
}
|
|
1811
|
+
if (reasoningEffort) {
|
|
1812
|
+
model.setReasoningEffort(reasoningEffort);
|
|
1813
|
+
}
|
|
1814
|
+
if (structuredOutput) {
|
|
1815
|
+
model.setStructuredOutput(structuredOutput);
|
|
1816
|
+
}
|
|
1817
|
+
return model;
|
|
1818
|
+
}
|
|
1819
|
+
async execute(inferenceParams) {
|
|
1820
|
+
const { model, context, caller, environment, signal } = inferenceParams;
|
|
1821
|
+
const modelInfo = this.modelRepository.getModelInfo(model);
|
|
1822
|
+
const generativeModel = this.setModelCapabilities(modelInfo.model, inferenceParams);
|
|
1823
|
+
modelInfo.model = generativeModel;
|
|
1824
|
+
const result = this.inferenceRunner.run(context, modelInfo, signal);
|
|
1825
|
+
for await (const item of result) {
|
|
1826
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1827
|
+
break;
|
|
1828
|
+
}
|
|
1829
|
+
if (item instanceof ReasoningItem) {
|
|
1830
|
+
environment.deliverReasoning(caller, item);
|
|
1831
|
+
} else if (item instanceof FunctionCallItem) {
|
|
1832
|
+
environment.deliverFunctionCall(caller, item);
|
|
1833
|
+
} else if (item instanceof ModelMessageItem) {
|
|
1834
|
+
environment.deliverModelMessage(caller, item);
|
|
1835
|
+
} else if (item instanceof SemanticEvent) {
|
|
1836
|
+
environment.deliverSemanticEvent(caller, item);
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
};
|
|
1841
|
+
|
|
1842
|
+
// src/application/use-cases/execute-function-call.ts
|
|
1843
|
+
var ExecuteFunctionCall = class {
|
|
1844
|
+
constructor(functionCallRunner) {
|
|
1845
|
+
this.functionCallRunner = functionCallRunner;
|
|
1846
|
+
}
|
|
1847
|
+
async execute(environment, functionCallItem, tool, caller, signal) {
|
|
1848
|
+
const stream = this.functionCallRunner.run(functionCallItem, tool, signal);
|
|
1849
|
+
for await (const item of stream) {
|
|
1850
|
+
environment.deliverFunctionCallOutput(caller, item);
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
};
|
|
1854
|
+
|
|
1855
|
+
// src/application/services/model-repository.ts
|
|
1856
|
+
var ModelRepository = class {
|
|
1857
|
+
getModelInfo(model) {
|
|
1858
|
+
switch (model) {
|
|
1859
|
+
case "gpt-5-4":
|
|
1860
|
+
return { endpoint: new OpenAIResponses(), model: new Gpt54() };
|
|
1861
|
+
case "gpt-5-4-mini":
|
|
1862
|
+
return { endpoint: new OpenAIResponses(), model: new Gpt54Mini() };
|
|
1863
|
+
case "gpt-5-4-nano":
|
|
1864
|
+
return { endpoint: new OpenAIResponses(), model: new Gpt54Nano() };
|
|
1865
|
+
case "gpt-5-5":
|
|
1866
|
+
return { endpoint: new OpenAIResponses(), model: new Gpt55() };
|
|
1867
|
+
case "claude-4-5-haiku":
|
|
1868
|
+
return { endpoint: new AnthropicMessages(), model: new ClaudeHaiku45() };
|
|
1869
|
+
case "claude-4-6-sonnet":
|
|
1870
|
+
return { endpoint: new AnthropicMessages(), model: new ClaudeSonnet46() };
|
|
1871
|
+
case "claude-4-7-opus":
|
|
1872
|
+
return { endpoint: new AnthropicMessages(), model: new ClaudeOpus47() };
|
|
1873
|
+
case "claude-4-8-opus":
|
|
1874
|
+
return { endpoint: new AnthropicMessages(), model: new ClaudeOpus48() };
|
|
1875
|
+
case "gemini-3-5-flash":
|
|
1876
|
+
return { endpoint: new GeminiGenerateContent(), model: new Gemini35Flash() };
|
|
1877
|
+
case "gemini-3-1-pro":
|
|
1878
|
+
return { endpoint: new GeminiGenerateContent(), model: new Gemini31Pro() };
|
|
1879
|
+
case "deepseek-v4-flash":
|
|
1880
|
+
return { endpoint: new OpenAIChatCompletions(), model: new DeepSeekV4Flash() };
|
|
1881
|
+
case "deepseek-v4-pro":
|
|
1882
|
+
return { endpoint: new OpenAIChatCompletions(), model: new DeepSeekV4Pro() };
|
|
1883
|
+
default:
|
|
1884
|
+
throw new Error(`Unsupported model: ${model}`);
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
};
|
|
1888
|
+
|
|
1889
|
+
// src/application/services/function-call-runner.ts
|
|
1890
|
+
var FunctionCallRunner = class {
|
|
1891
|
+
async *run(call, tool, signal) {
|
|
1892
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1895
|
+
if (!tool) throw new Error(`Unknown tool: ${call.name}`);
|
|
1896
|
+
const result = await tool.invoke(JSON.parse(call.args));
|
|
1897
|
+
yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
|
|
1898
|
+
}
|
|
1899
|
+
};
|
|
1900
|
+
|
|
1901
|
+
// src/application/participants/participant.ts
|
|
1902
|
+
var BaseParticipant = class extends Participant {
|
|
1903
|
+
onFunctionCall(item) {
|
|
1904
|
+
}
|
|
1905
|
+
onExternalFunctionCall(source, item) {
|
|
1906
|
+
}
|
|
1907
|
+
onFunctionCallOutput(item) {
|
|
1908
|
+
}
|
|
1909
|
+
onExternalFunctionCallOutput(source, item) {
|
|
1910
|
+
}
|
|
1911
|
+
onReasoning(item) {
|
|
1912
|
+
}
|
|
1913
|
+
onExternalReasoning(source, item) {
|
|
1914
|
+
}
|
|
1915
|
+
onModelMessage(item) {
|
|
1916
|
+
}
|
|
1917
|
+
onExternalModelMessage(source, item) {
|
|
1918
|
+
}
|
|
1919
|
+
onMessage(message) {
|
|
1920
|
+
}
|
|
1921
|
+
onJoined() {
|
|
1922
|
+
}
|
|
1923
|
+
onLeft() {
|
|
1924
|
+
}
|
|
1925
|
+
onParticipantJoined(participant) {
|
|
1926
|
+
}
|
|
1927
|
+
onParticipantLeft(participant) {
|
|
1928
|
+
}
|
|
1929
|
+
onInternalEvent(item) {
|
|
1930
|
+
}
|
|
1931
|
+
onExternalEvent(source, item) {
|
|
1932
|
+
}
|
|
1933
|
+
onError(error) {
|
|
1934
|
+
}
|
|
1935
|
+
onParticipantError(source, error) {
|
|
1936
|
+
}
|
|
1937
|
+
};
|
|
1938
|
+
|
|
1939
|
+
// src/application/use-cases/send-message.ts
|
|
1940
|
+
var SendMessage = class {
|
|
1941
|
+
async execute(environment, message, caller) {
|
|
1942
|
+
if (!caller.isJoinedTo(environment)) {
|
|
1943
|
+
throw new Error("Not joined to environment");
|
|
1944
|
+
}
|
|
1945
|
+
environment.deliverMessage(caller, message);
|
|
1946
|
+
}
|
|
1947
|
+
};
|
|
1948
|
+
|
|
1949
|
+
// src/index.ts
|
|
1950
|
+
var runInferenceUseCase = new RunInference(new ModelRepository(), new InferenceRunner());
|
|
1951
|
+
var executeFunctionCallUseCase = new ExecuteFunctionCall(new FunctionCallRunner());
|
|
1952
|
+
var sendMessageUseCase = new SendMessage();
|
|
1953
|
+
var runInference = (inferenceParams) => {
|
|
1954
|
+
runInferenceUseCase.execute(inferenceParams);
|
|
1955
|
+
};
|
|
1956
|
+
var executeFunctionCall = (environment, functionCallItem, tool, caller) => {
|
|
1957
|
+
executeFunctionCallUseCase.execute(environment, functionCallItem, tool, caller);
|
|
1958
|
+
};
|
|
1959
|
+
var sendMessage = (environment, message, caller) => {
|
|
1960
|
+
sendMessageUseCase.execute(environment, message, caller);
|
|
1708
1961
|
};
|
|
1709
1962
|
export {
|
|
1710
|
-
Agent,
|
|
1711
1963
|
AgenticEnvironment,
|
|
1964
|
+
AgenticError,
|
|
1712
1965
|
AnthropicMessages,
|
|
1713
|
-
|
|
1714
|
-
BaseHuman,
|
|
1715
|
-
BaseObserver,
|
|
1966
|
+
BaseParticipant,
|
|
1716
1967
|
ClaudeHaiku45,
|
|
1717
1968
|
ClaudeOpus47,
|
|
1718
1969
|
ClaudeOpus48,
|
|
@@ -1720,8 +1971,6 @@ export {
|
|
|
1720
1971
|
ContextItem,
|
|
1721
1972
|
DeepSeekV4Flash,
|
|
1722
1973
|
DeepSeekV4Pro,
|
|
1723
|
-
DefaultFunctionCallRunner,
|
|
1724
|
-
DefaultInferenceRunner,
|
|
1725
1974
|
DeveloperMessageItem,
|
|
1726
1975
|
FunctionCallItem,
|
|
1727
1976
|
FunctionCallOutputItem,
|
|
@@ -1732,15 +1981,13 @@ export {
|
|
|
1732
1981
|
Gpt54Mini,
|
|
1733
1982
|
Gpt54Nano,
|
|
1734
1983
|
Gpt55,
|
|
1735
|
-
Human,
|
|
1736
1984
|
InMemoryModelContextRepository,
|
|
1737
1985
|
InferenceRequest,
|
|
1738
1986
|
InferenceResponse,
|
|
1739
1987
|
InputTokenDetails,
|
|
1740
1988
|
ModelContext,
|
|
1741
1989
|
ModelMessageItem,
|
|
1742
|
-
|
|
1743
|
-
OpenAICompatibleChatCompletions,
|
|
1990
|
+
OpenAIChatCompletions,
|
|
1744
1991
|
OpenAIResponses,
|
|
1745
1992
|
OutputTokenDetails,
|
|
1746
1993
|
Participant,
|
|
@@ -1748,6 +1995,9 @@ export {
|
|
|
1748
1995
|
SemanticEvent,
|
|
1749
1996
|
SystemMessageItem,
|
|
1750
1997
|
TokenUsage,
|
|
1751
|
-
UserMessageItem
|
|
1998
|
+
UserMessageItem,
|
|
1999
|
+
executeFunctionCall,
|
|
2000
|
+
runInference,
|
|
2001
|
+
sendMessage
|
|
1752
2002
|
};
|
|
1753
2003
|
//# sourceMappingURL=index.mjs.map
|