@mozaik-ai/core 3.11.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/dist/index.mjs CHANGED
@@ -255,18 +255,21 @@ 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 = [];
268
+ this.streaming = false;
269
+ this.structuredOutput = void 0;
266
270
  this.effort = new OpenAIReasoningEffort(
267
271
  this.specification.defaultReasoningEffort
268
272
  );
269
- this.streaming = false;
270
273
  }
271
274
  setStreaming(streaming) {
272
275
  this.streaming = streaming;
@@ -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,18 +355,21 @@ 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 = [];
368
+ this.streaming = false;
369
+ this.structuredOutput = void 0;
342
370
  this.effort = new OpenAIReasoningEffort(
343
371
  this.specification.defaultReasoningEffort
344
372
  );
345
- this.streaming = false;
346
373
  }
347
374
  setStreaming(streaming) {
348
375
  this.streaming = streaming;
@@ -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,10 +488,12 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
452
488
  }
453
489
  };
454
490
 
455
- // src/domain/agentic-environment/participants/participant.ts
491
+ // src/domain/agentic-environment/participant.ts
456
492
  var Participant = class {
457
493
  constructor() {
458
494
  this.environments = [];
495
+ this.listens = [];
496
+ this.active = /* @__PURE__ */ new Map();
459
497
  }
460
498
  join(environment) {
461
499
  if (this.isJoinedTo(environment)) {
@@ -463,6 +501,7 @@ var Participant = class {
463
501
  }
464
502
  environment.subscribe(this);
465
503
  this.environments.push(environment);
504
+ this.active.set(environment, true);
466
505
  }
467
506
  leave(environment) {
468
507
  if (!this.isJoinedTo(environment)) {
@@ -470,6 +509,7 @@ var Participant = class {
470
509
  }
471
510
  environment.unsubscribe(this);
472
511
  this.environments = this.environments.filter((e) => e !== environment);
512
+ this.active.delete(environment);
473
513
  }
474
514
  isJoinedTo(environment) {
475
515
  return this.environments.includes(environment);
@@ -477,13 +517,49 @@ var Participant = class {
477
517
  getEnvironments() {
478
518
  return this.environments;
479
519
  }
520
+ getListeners() {
521
+ return this.listens;
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
+ }
480
553
  };
481
554
 
482
555
  // src/domain/agentic-environment/agentic-environment.ts
483
556
  var AgenticEnvironment = class {
484
- constructor() {
557
+ constructor(name, opts) {
485
558
  this.subscribers = [];
486
- this.isActive = false;
559
+ var _a;
560
+ this.name = name;
561
+ this.options = opts;
562
+ this.showLogs = ((_a = this.options) == null ? void 0 : _a.silent) !== false;
487
563
  }
488
564
  subscribe(participant) {
489
565
  this.subscribers.push(participant);
@@ -507,227 +583,100 @@ var AgenticEnvironment = class {
507
583
  }
508
584
  }
509
585
  deliverFunctionCall(source, item) {
510
- for (const subscriber of this.subscribers) {
511
- if (subscriber === source) {
512
- subscriber.onFunctionCall(item);
513
- } else {
514
- subscriber.onExternalFunctionCall(source, item);
515
- }
516
- }
586
+ this.deliverToSubscribers(source, {
587
+ internal: (src) => src.onFunctionCall(item),
588
+ external: (sub) => sub.onExternalFunctionCall(source, item)
589
+ });
517
590
  }
518
591
  deliverModelMessage(source, item) {
519
- for (const subscriber of this.subscribers) {
520
- if (subscriber === source) {
521
- subscriber.onModelMessage(item);
522
- } else {
523
- subscriber.onExternalModelMessage(source, item);
524
- }
525
- }
592
+ this.deliverToSubscribers(source, {
593
+ internal: (src) => src.onModelMessage(item),
594
+ external: (sub) => sub.onExternalModelMessage(source, item)
595
+ });
526
596
  }
527
597
  deliverReasoning(source, item) {
528
- for (const subscriber of this.subscribers) {
529
- if (subscriber === source) {
530
- subscriber.onReasoning(item);
531
- } else {
532
- subscriber.onExternalReasoning(source, item);
533
- }
534
- }
598
+ this.deliverToSubscribers(source, {
599
+ internal: (src) => src.onReasoning(item),
600
+ external: (sub) => sub.onExternalReasoning(source, item)
601
+ });
535
602
  }
536
603
  deliverFunctionCallOutput(source, item) {
537
- for (const subscriber of this.subscribers) {
538
- if (subscriber === source) {
539
- subscriber.onFunctionCallOutput(item);
540
- } else {
541
- subscriber.onExternalFunctionCallOutput(source, item);
542
- }
543
- }
604
+ this.deliverToSubscribers(source, {
605
+ internal: (src) => src.onFunctionCallOutput(item),
606
+ external: (sub) => sub.onExternalFunctionCallOutput(source, item)
607
+ });
544
608
  }
545
609
  deliverMessage(source, message) {
546
- for (const subscriber of this.subscribers) {
547
- if (subscriber === source) continue;
548
- subscriber.onMessage(message);
549
- }
610
+ this.deliverToSubscribers(source, {
611
+ external: (sub) => sub.onMessage(message)
612
+ });
550
613
  }
551
614
  deliverSemanticEvent(source, item) {
552
- for (const subscriber of this.subscribers) {
553
- if (subscriber === source) {
554
- subscriber.onInternalEvent(item);
555
- } else {
556
- subscriber.onExternalEvent(source, item);
557
- }
558
- }
559
- }
560
- async start() {
561
- this.isActive = true;
562
- while (this.isActive) {
563
- await new Promise((resolve) => setTimeout(resolve, 100));
564
- }
565
- }
566
- stop() {
567
- this.isActive = false;
568
- }
569
- };
570
-
571
- // src/domain/agentic-environment/participants/agent.ts
572
- var Agent = class extends Participant {
573
- };
574
-
575
- // src/domain/model-context/semantic-event/semantic-event.ts
576
- var SemanticEvent = class {
577
- constructor(type, data) {
578
- this.type = type;
579
- this.data = data;
580
- }
581
- getType() {
582
- return this.type;
583
- }
584
- };
585
-
586
- // src/application/participants/agent.ts
587
- var BaseAgent = class extends Agent {
588
- constructor(inferenceRunner, functionCallRunner) {
589
- super();
590
- this.inferenceRunner = inferenceRunner;
591
- this.functionCallRunner = functionCallRunner;
592
- }
593
- onJoined() {
594
- }
595
- onLeft() {
596
- }
597
- onParticipantJoined(participant) {
598
- }
599
- onParticipantLeft(participant) {
600
- }
601
- onFunctionCall(item) {
602
- }
603
- onExternalFunctionCall(source, item) {
604
- }
605
- onFunctionCallOutput(item) {
606
- }
607
- onExternalFunctionCallOutput(source, item) {
608
- }
609
- onReasoning(item) {
610
- }
611
- onExternalReasoning(source, item) {
612
- }
613
- onModelMessage(item) {
614
- }
615
- onExternalModelMessage(source, item) {
616
- }
617
- onMessage(message) {
618
- }
619
- onInternalEvent(item) {
620
- }
621
- onExternalEvent(source, item) {
622
- }
623
- async executeFunctionCall(environment, functionCallItem, signal) {
624
- if (!this.isJoinedTo(environment)) return;
625
- const stream = this.functionCallRunner.run(functionCallItem, signal);
626
- for await (const item of stream) {
627
- environment.deliverFunctionCallOutput(this, item);
628
- }
615
+ this.deliverToSubscribers(source, {
616
+ internal: (src) => src.onInternalEvent(item),
617
+ external: (sub) => sub.onExternalEvent(source, item)
618
+ });
629
619
  }
630
- async runInference(environment, context, model, signal) {
631
- if (!this.isJoinedTo(environment)) return;
632
- const stream = this.inferenceRunner.run(context, model, signal);
633
- for await (const item of stream) {
634
- if (item instanceof ReasoningItem) {
635
- environment.deliverReasoning(this, item);
636
- } else if (item instanceof FunctionCallItem) {
637
- environment.deliverFunctionCall(this, item);
638
- } else if (item instanceof ModelMessageItem) {
639
- environment.deliverModelMessage(this, item);
640
- } else if (item instanceof SemanticEvent) {
641
- environment.deliverSemanticEvent(this, item);
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
+ }
642
643
  }
643
- }
644
- }
645
- };
646
-
647
- // src/domain/agentic-environment/participants/human.ts
648
- var Human = class extends Participant {
649
- sendMessage(environment, message) {
650
- if (!this.isJoinedTo(environment)) throw new Error("Not joined to environment");
651
- environment.deliverMessage(this, message);
652
- }
653
- };
654
-
655
- // src/application/participants/human.ts
656
- var BaseHuman = class extends Human {
657
- onJoined() {
658
- }
659
- onLeft() {
660
- }
661
- onParticipantJoined(participant) {
662
- }
663
- onParticipantLeft(participant) {
664
- }
665
- onMessage(message) {
666
- }
667
- onFunctionCall(item) {
668
- }
669
- onFunctionCallOutput(item) {
670
- }
671
- onReasoning(item) {
672
- }
673
- onModelMessage(item) {
674
- }
675
- onExternalFunctionCall(source, item) {
676
- }
677
- onExternalFunctionCallOutput(source, item) {
678
- }
679
- onExternalReasoning(source, item) {
680
- }
681
- onExternalModelMessage(source, item) {
682
- }
683
- onInternalEvent(item) {
684
- }
685
- onExternalEvent(source, item) {
686
- }
687
- };
688
-
689
- // src/domain/generative-model/inference-request.ts
690
- var InferenceRequest = class {
691
- constructor(model, context) {
692
- this.model = model;
693
- this.context = context;
644
+ });
694
645
  }
695
- };
696
-
697
- // src/application/runners/openai-inference-runner.ts
698
- var OpenAIInferenceRunner = class {
699
- constructor(runtime) {
700
- this.runtime = runtime;
646
+ getListeningParticipants(source) {
647
+ return this.subscribers.filter(
648
+ (sub) => sub !== source && (sub.getListeners().length === 0 || sub.getListeners().some((listener) => source instanceof listener))
649
+ );
701
650
  }
702
- async *run(context, model, signal) {
703
- const request = new InferenceRequest(model, context);
704
- if (model.getStreaming() && this.isStreamingRuntime(this.runtime)) {
705
- yield* this.runtime.stream(request, signal);
706
- return;
707
- }
708
- const response = await this.runtime.infer(request);
709
- for (const item of response.contextItems) {
710
- if (signal == null ? void 0 : signal.aborted) {
711
- break;
651
+ deliverToSubscribers(source, handlers) {
652
+ var _a, _b;
653
+ const authorizedListeners = this.getListeningParticipants(source);
654
+ for (const subscriber of this.subscribers) {
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
+ }
712
666
  }
713
- yield item;
714
667
  }
715
668
  }
716
- isStreamingRuntime(runtime) {
717
- return typeof runtime.stream === "function";
718
- }
719
- };
720
-
721
- // src/application/runners/function-call-runner.ts
722
- var DefaultFunctionCallRunner = class {
723
- constructor(tools) {
724
- this.tools = tools;
725
- }
726
- async *run(call, signal) {
727
- const tool = this.tools.find((t) => t.name === call.name);
728
- if (!tool) throw new Error(`Unknown tool: ${call.name}`);
729
- const result = await tool.invoke(JSON.parse(call.args));
730
- yield FunctionCallOutputItem.create(call.callId, JSON.stringify(result));
669
+ handleError(subscriber, error) {
670
+ if (error instanceof AgenticError) {
671
+ return this.deliverError(subscriber, error);
672
+ }
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);
731
680
  }
732
681
  };
733
682
 
@@ -736,15 +685,18 @@ var Gpt55 = class {
736
685
  constructor() {
737
686
  this.specification = {
738
687
  name: "gpt-5.5",
688
+ provider: "openai",
739
689
  supportReasoningEffort: true,
740
690
  defaultReasoningEffort: "none",
741
691
  supportStreaming: true,
742
692
  contextWindowSize: 105e4,
743
693
  maxOutputTokens: 128e3,
744
- supportFunctionCalling: true
694
+ supportFunctionCalling: true,
695
+ supportStructuredOutput: true
745
696
  };
746
697
  this.tools = [];
747
698
  this.streaming = false;
699
+ this.structuredOutput = void 0;
748
700
  this.effort = new OpenAIReasoningEffort(
749
701
  this.specification.defaultReasoningEffort
750
702
  );
@@ -767,47 +719,37 @@ var Gpt55 = class {
767
719
  getReasoningEffort() {
768
720
  return this.effort.getReasoningEffort();
769
721
  }
770
- };
771
-
772
- // src/domain/agentic-environment/participants/observer.ts
773
- var Observer = class extends Participant {
774
- };
775
-
776
- // src/application/participants/observer.ts
777
- var BaseObserver = class extends Observer {
778
- onFunctionCall(item) {
779
- }
780
- onExternalFunctionCall(source, item) {
781
- }
782
- onFunctionCallOutput(item) {
783
- }
784
- onExternalFunctionCallOutput(source, item) {
785
- }
786
- onReasoning(item) {
787
- }
788
- onExternalReasoning(source, item) {
789
- }
790
- onModelMessage(item) {
791
- }
792
- onExternalModelMessage(source, item) {
793
- }
794
- onMessage(message) {
795
- }
796
- onJoined() {
722
+ setStructuredOutput(format) {
723
+ this.structuredOutput = format;
797
724
  }
798
- onLeft() {
725
+ getStructuredOutput() {
726
+ return this.structuredOutput;
799
727
  }
800
- onParticipantJoined(participant) {
728
+ hasStructuredOutput() {
729
+ return this.structuredOutput !== void 0;
801
730
  }
802
- 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;
803
738
  }
804
- onInternalEvent(item) {
739
+ getType() {
740
+ return this.type;
805
741
  }
806
- onExternalEvent(source, item) {
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;
807
749
  }
808
750
  };
809
751
 
810
- // src/domain/generative-model/inference-response.ts
752
+ // src/domain/agentic-environment/inference/response.ts
811
753
  var InferenceResponse = class {
812
754
  constructor(contextItems, tokenUsage) {
813
755
  this.contextItems = contextItems;
@@ -843,6 +785,7 @@ var OpenAIResponses = class {
843
785
  }
844
786
  }
845
787
  buildRequest(inferenceRequest) {
788
+ var _a, _b;
846
789
  const specification = inferenceRequest.model.specification;
847
790
  const input = this.mapContextToRequest(inferenceRequest.context);
848
791
  const request = {
@@ -864,6 +807,20 @@ var OpenAIResponses = class {
864
807
  effort: inferenceRequest.model.getReasoningEffort()
865
808
  };
866
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
+ }
867
824
  return request;
868
825
  }
869
826
  extractTokenUsage(response) {
@@ -907,6 +864,24 @@ var AnthropicMessages = class {
907
864
  this.client = new Anthropic();
908
865
  }
909
866
  async infer(inferenceRequest) {
867
+ const response = await this.client.messages.create(this.buildRequest(inferenceRequest));
868
+ const contextItems = this.extractContextItems(response);
869
+ const tokenUsage = this.extractTokenUsage(response);
870
+ return new InferenceResponse(contextItems, tokenUsage);
871
+ }
872
+ async *stream(inferenceRequest, signal) {
873
+ const stream = await this.client.messages.create({
874
+ ...this.buildRequest(inferenceRequest),
875
+ stream: true
876
+ });
877
+ for await (const event of stream) {
878
+ if (signal == null ? void 0 : signal.aborted) {
879
+ break;
880
+ }
881
+ yield new SemanticEvent(event.type, event);
882
+ }
883
+ }
884
+ buildRequest(inferenceRequest) {
910
885
  const { messages, system } = this.mapContextToRequest(inferenceRequest.context);
911
886
  const specification = inferenceRequest.model.specification;
912
887
  const request = {
@@ -937,14 +912,23 @@ var AnthropicMessages = class {
937
912
  };
938
913
  }
939
914
  }
940
- const response = await this.client.messages.create(request);
941
- const contextItems = this.extractContextItems(response);
942
- const tokenUsage = this.extractTokenUsage(response);
943
- return new InferenceResponse(contextItems, tokenUsage);
944
- }
945
- extractTokenUsage(response) {
946
- var _a, _b;
947
- if (!response.usage) {
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
+ }
927
+ return request;
928
+ }
929
+ extractTokenUsage(response) {
930
+ var _a, _b;
931
+ if (!response.usage) {
948
932
  return void 0;
949
933
  }
950
934
  return new TokenUsage(
@@ -1060,20 +1044,73 @@ var AnthropicReasoningEffort = class {
1060
1044
  }
1061
1045
  };
1062
1046
 
1047
+ // src/infrastructure/providers/anthropic/models/claude-4-8-opus.ts
1048
+ var ClaudeOpus48 = class {
1049
+ constructor() {
1050
+ this.specification = {
1051
+ name: "claude-opus-4-8",
1052
+ provider: "anthropic",
1053
+ supportReasoningEffort: true,
1054
+ defaultReasoningEffort: "none",
1055
+ supportStreaming: true,
1056
+ contextWindowSize: 2e5,
1057
+ maxOutputTokens: 32e3,
1058
+ supportFunctionCalling: true,
1059
+ supportStructuredOutput: true
1060
+ };
1061
+ this.tools = [];
1062
+ this.streaming = false;
1063
+ this.structuredOutput = void 0;
1064
+ this.effort = new AnthropicReasoningEffort(
1065
+ this.specification.defaultReasoningEffort
1066
+ );
1067
+ }
1068
+ setStreaming(streaming) {
1069
+ this.streaming = streaming;
1070
+ }
1071
+ getStreaming() {
1072
+ return this.streaming;
1073
+ }
1074
+ setTools(tools) {
1075
+ this.tools = tools;
1076
+ }
1077
+ getTools() {
1078
+ return this.tools;
1079
+ }
1080
+ setReasoningEffort(effort) {
1081
+ this.effort.setReasoningEffort(effort);
1082
+ }
1083
+ getReasoningEffort() {
1084
+ return this.effort.getReasoningEffort();
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
+ }
1095
+ };
1096
+
1063
1097
  // src/infrastructure/providers/anthropic/models/claude-4-7-opus.ts
1064
1098
  var ClaudeOpus47 = class {
1065
1099
  constructor() {
1066
1100
  this.specification = {
1067
1101
  name: "claude-opus-4-7",
1102
+ provider: "anthropic",
1068
1103
  supportReasoningEffort: true,
1069
1104
  defaultReasoningEffort: "none",
1070
1105
  supportStreaming: true,
1071
1106
  contextWindowSize: 2e5,
1072
1107
  maxOutputTokens: 32e3,
1073
- supportFunctionCalling: true
1108
+ supportFunctionCalling: true,
1109
+ supportStructuredOutput: true
1074
1110
  };
1075
1111
  this.tools = [];
1076
1112
  this.streaming = false;
1113
+ this.structuredOutput = void 0;
1077
1114
  this.effort = new AnthropicReasoningEffort(
1078
1115
  this.specification.defaultReasoningEffort
1079
1116
  );
@@ -1096,6 +1133,15 @@ var ClaudeOpus47 = class {
1096
1133
  getReasoningEffort() {
1097
1134
  return this.effort.getReasoningEffort();
1098
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
+ }
1099
1145
  };
1100
1146
 
1101
1147
  // src/infrastructure/providers/anthropic/models/claude-4-6-sonnet.ts
@@ -1103,15 +1149,18 @@ var ClaudeSonnet46 = class {
1103
1149
  constructor() {
1104
1150
  this.specification = {
1105
1151
  name: "claude-sonnet-4-6",
1152
+ provider: "anthropic",
1106
1153
  supportReasoningEffort: true,
1107
1154
  defaultReasoningEffort: "none",
1108
1155
  supportStreaming: true,
1109
1156
  contextWindowSize: 2e5,
1110
1157
  maxOutputTokens: 64e3,
1111
- supportFunctionCalling: true
1158
+ supportFunctionCalling: true,
1159
+ supportStructuredOutput: true
1112
1160
  };
1113
1161
  this.tools = [];
1114
1162
  this.streaming = false;
1163
+ this.structuredOutput = void 0;
1115
1164
  this.effort = new AnthropicReasoningEffort(
1116
1165
  this.specification.defaultReasoningEffort
1117
1166
  );
@@ -1134,6 +1183,15 @@ var ClaudeSonnet46 = class {
1134
1183
  getReasoningEffort() {
1135
1184
  return this.effort.getReasoningEffort();
1136
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
+ }
1137
1195
  };
1138
1196
 
1139
1197
  // src/infrastructure/providers/anthropic/models/claude-4-5-haiku.ts
@@ -1141,15 +1199,18 @@ var ClaudeHaiku45 = class {
1141
1199
  constructor() {
1142
1200
  this.specification = {
1143
1201
  name: "claude-haiku-4-5",
1202
+ provider: "anthropic",
1144
1203
  supportReasoningEffort: true,
1145
1204
  defaultReasoningEffort: "none",
1146
1205
  supportStreaming: true,
1147
1206
  contextWindowSize: 2e5,
1148
1207
  maxOutputTokens: 64e3,
1149
- supportFunctionCalling: true
1208
+ supportFunctionCalling: true,
1209
+ supportStructuredOutput: true
1150
1210
  };
1151
1211
  this.tools = [];
1152
1212
  this.streaming = false;
1213
+ this.structuredOutput = void 0;
1153
1214
  this.effort = new AnthropicReasoningEffort(
1154
1215
  this.specification.defaultReasoningEffort
1155
1216
  );
@@ -1172,35 +1233,761 @@ var ClaudeHaiku45 = class {
1172
1233
  getReasoningEffort() {
1173
1234
  return this.effort.getReasoningEffort();
1174
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
+ }
1245
+ };
1246
+
1247
+ // src/infrastructure/providers/deepseek/reasoning-effort.ts
1248
+ var DeepSeekReasoningEffort = class {
1249
+ constructor(reasoningEffort) {
1250
+ this.reasoningEffort = reasoningEffort;
1251
+ }
1252
+ setReasoningEffort(effort) {
1253
+ this.reasoningEffort = effort;
1254
+ }
1255
+ getReasoningEffort() {
1256
+ if (!this.reasoningEffort) {
1257
+ throw new Error("Reasoning effort not supported");
1258
+ }
1259
+ return this.reasoningEffort;
1260
+ }
1261
+ };
1262
+
1263
+ // src/infrastructure/providers/deepseek/models/deepseek-v4-flash.ts
1264
+ var DeepSeekV4Flash = class {
1265
+ constructor() {
1266
+ this.specification = {
1267
+ name: "deepseek-v4-flash",
1268
+ provider: "deepseek",
1269
+ supportReasoningEffort: true,
1270
+ defaultReasoningEffort: "high",
1271
+ supportStreaming: true,
1272
+ contextWindowSize: 1e6,
1273
+ maxOutputTokens: 384e3,
1274
+ supportFunctionCalling: true,
1275
+ supportStructuredOutput: false
1276
+ };
1277
+ this.tools = [];
1278
+ this.streaming = false;
1279
+ this.structuredOutput = void 0;
1280
+ this.effort = new DeepSeekReasoningEffort(
1281
+ this.specification.defaultReasoningEffort
1282
+ );
1283
+ }
1284
+ setStreaming(streaming) {
1285
+ this.streaming = streaming;
1286
+ }
1287
+ getStreaming() {
1288
+ return this.streaming;
1289
+ }
1290
+ setTools(tools) {
1291
+ this.tools = tools;
1292
+ }
1293
+ getTools() {
1294
+ return this.tools;
1295
+ }
1296
+ setReasoningEffort(effort) {
1297
+ this.effort.setReasoningEffort(effort);
1298
+ }
1299
+ getReasoningEffort() {
1300
+ return this.effort.getReasoningEffort();
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
+ }
1311
+ };
1312
+
1313
+ // src/infrastructure/providers/deepseek/models/deepseek-v4-pro.ts
1314
+ var DeepSeekV4Pro = class {
1315
+ constructor() {
1316
+ this.specification = {
1317
+ name: "deepseek-v4-pro",
1318
+ provider: "deepseek",
1319
+ supportReasoningEffort: true,
1320
+ defaultReasoningEffort: "high",
1321
+ supportStreaming: true,
1322
+ contextWindowSize: 1e6,
1323
+ maxOutputTokens: 384e3,
1324
+ supportFunctionCalling: true,
1325
+ supportStructuredOutput: false
1326
+ };
1327
+ this.tools = [];
1328
+ this.streaming = false;
1329
+ this.structuredOutput = void 0;
1330
+ this.effort = new DeepSeekReasoningEffort(
1331
+ this.specification.defaultReasoningEffort
1332
+ );
1333
+ }
1334
+ setStreaming(streaming) {
1335
+ this.streaming = streaming;
1336
+ }
1337
+ getStreaming() {
1338
+ return this.streaming;
1339
+ }
1340
+ setTools(tools) {
1341
+ this.tools = tools;
1342
+ }
1343
+ getTools() {
1344
+ return this.tools;
1345
+ }
1346
+ setReasoningEffort(effort) {
1347
+ this.effort.setReasoningEffort(effort);
1348
+ }
1349
+ getReasoningEffort() {
1350
+ return this.effort.getReasoningEffort();
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
+ }
1361
+ };
1362
+
1363
+ // src/infrastructure/providers/gemini/runtime/gemini-generate-content.ts
1364
+ import { GoogleGenAI } from "@google/genai";
1365
+ var GeminiGenerateContent = class {
1366
+ constructor() {
1367
+ this.client = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
1368
+ }
1369
+ async infer(inferenceRequest) {
1370
+ const response = await this.client.models.generateContent(this.buildRequest(inferenceRequest));
1371
+ const contextItems = this.extractContextItems(response);
1372
+ const tokenUsage = this.extractTokenUsage(response);
1373
+ return new InferenceResponse(contextItems, tokenUsage);
1374
+ }
1375
+ async *stream(inferenceRequest, signal) {
1376
+ const stream = await this.client.models.generateContentStream(this.buildRequest(inferenceRequest));
1377
+ for await (const chunk of stream) {
1378
+ if (signal == null ? void 0 : signal.aborted) {
1379
+ break;
1380
+ }
1381
+ yield new SemanticEvent("generate_content_chunk", chunk);
1382
+ }
1383
+ }
1384
+ buildRequest(inferenceRequest) {
1385
+ const specification = inferenceRequest.model.specification;
1386
+ const { contents, systemInstruction } = this.mapContextToRequest(inferenceRequest.context);
1387
+ const config = {};
1388
+ if (systemInstruction) {
1389
+ config.systemInstruction = systemInstruction;
1390
+ }
1391
+ if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
1392
+ config.tools = [
1393
+ {
1394
+ functionDeclarations: inferenceRequest.model.getTools().map((tool) => {
1395
+ return {
1396
+ name: tool.name,
1397
+ description: tool.description,
1398
+ parametersJsonSchema: tool.parameters
1399
+ };
1400
+ })
1401
+ }
1402
+ ];
1403
+ }
1404
+ if (specification.supportReasoningEffort) {
1405
+ const effort = inferenceRequest.model.getReasoningEffort();
1406
+ const thinkingLevel = effort === "none" ? "minimal" : effort;
1407
+ config.thinkingConfig = { thinkingLevel, includeThoughts: true };
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
+ }
1417
+ return { model: specification.name, contents, config };
1418
+ }
1419
+ extractTokenUsage(response) {
1420
+ var _a, _b, _c, _d, _e;
1421
+ const usage = response.usageMetadata;
1422
+ if (!usage) {
1423
+ return void 0;
1424
+ }
1425
+ return new TokenUsage(
1426
+ (_a = usage.promptTokenCount) != null ? _a : 0,
1427
+ (_b = usage.candidatesTokenCount) != null ? _b : 0,
1428
+ (_c = usage.totalTokenCount) != null ? _c : 0,
1429
+ new InputTokenDetails((_d = usage.cachedContentTokenCount) != null ? _d : 0),
1430
+ new OutputTokenDetails((_e = usage.thoughtsTokenCount) != null ? _e : 0)
1431
+ );
1432
+ }
1433
+ mapContextToRequest(context) {
1434
+ var _a;
1435
+ const contents = [];
1436
+ const system = [];
1437
+ const callNames = /* @__PURE__ */ new Map();
1438
+ for (const item of context.getItems()) {
1439
+ if (item instanceof DeveloperMessageItem || item instanceof SystemMessageItem) {
1440
+ system.push(item.content.text);
1441
+ continue;
1442
+ }
1443
+ if (item instanceof UserMessageItem) {
1444
+ this.addPart(contents, "user", { text: item.content.text });
1445
+ continue;
1446
+ }
1447
+ if (item instanceof ModelMessageItem) {
1448
+ this.addPart(contents, "model", { text: item.content.text });
1449
+ continue;
1450
+ }
1451
+ if (item instanceof FunctionCallItem) {
1452
+ callNames.set(item.callId, item.name);
1453
+ let args;
1454
+ try {
1455
+ args = JSON.parse(item.args);
1456
+ } catch (e) {
1457
+ args = {};
1458
+ }
1459
+ this.addPart(contents, "model", { functionCall: { id: item.callId, name: item.name, args } });
1460
+ continue;
1461
+ }
1462
+ if (item instanceof FunctionCallOutputItem) {
1463
+ this.addPart(contents, "user", {
1464
+ functionResponse: {
1465
+ id: item.callId,
1466
+ name: (_a = callNames.get(item.callId)) != null ? _a : "",
1467
+ response: this.parseResponse(item.output.text)
1468
+ }
1469
+ });
1470
+ }
1471
+ }
1472
+ return {
1473
+ contents,
1474
+ systemInstruction: system.length > 0 ? system.join("\n\n") : void 0
1475
+ };
1476
+ }
1477
+ extractContextItems(response) {
1478
+ var _a, _b, _c, _d, _e, _f;
1479
+ const items = [];
1480
+ const parts = (_d = (_c = (_b = (_a = response.candidates) == null ? void 0 : _a[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts) != null ? _d : [];
1481
+ for (const part of parts) {
1482
+ if (part.thought && part.text) {
1483
+ items.push(
1484
+ ReasoningItem.rehydrate({
1485
+ content: InputText.rehydrate({ text: part.text }),
1486
+ encryptedContent: void 0,
1487
+ summary: []
1488
+ })
1489
+ );
1490
+ continue;
1491
+ }
1492
+ if (part.text) {
1493
+ items.push(ModelMessageItem.rehydrate({ text: part.text }));
1494
+ continue;
1495
+ }
1496
+ if (part.functionCall) {
1497
+ items.push(
1498
+ FunctionCallItem.rehydrate({
1499
+ callId: (_e = part.functionCall.id) != null ? _e : "",
1500
+ name: part.functionCall.name,
1501
+ args: JSON.stringify((_f = part.functionCall.args) != null ? _f : {})
1502
+ })
1503
+ );
1504
+ }
1505
+ }
1506
+ return items;
1507
+ }
1508
+ parseResponse(output) {
1509
+ try {
1510
+ const parsed = JSON.parse(output);
1511
+ return parsed && typeof parsed === "object" ? parsed : { output };
1512
+ } catch (e) {
1513
+ return { output };
1514
+ }
1515
+ }
1516
+ addPart(contents, role, part) {
1517
+ const last = contents[contents.length - 1];
1518
+ if ((last == null ? void 0 : last.role) === role) {
1519
+ last.parts.push(part);
1520
+ return;
1521
+ }
1522
+ contents.push({ role, parts: [part] });
1523
+ }
1524
+ };
1525
+
1526
+ // src/infrastructure/providers/gemini/reasoning-effort.ts
1527
+ var GeminiReasoningEffort = class {
1528
+ constructor(reasoningEffort) {
1529
+ this.reasoningEffort = reasoningEffort;
1530
+ }
1531
+ setReasoningEffort(effort) {
1532
+ this.reasoningEffort = effort;
1533
+ }
1534
+ getReasoningEffort() {
1535
+ if (!this.reasoningEffort) {
1536
+ throw new Error("Reasoning effort not supported");
1537
+ }
1538
+ return this.reasoningEffort;
1539
+ }
1540
+ };
1541
+
1542
+ // src/infrastructure/providers/gemini/models/gemini-3-5-flash.ts
1543
+ var Gemini35Flash = class {
1544
+ constructor() {
1545
+ this.specification = {
1546
+ name: "gemini-3.5-flash",
1547
+ provider: "google",
1548
+ supportReasoningEffort: true,
1549
+ defaultReasoningEffort: "medium",
1550
+ supportStreaming: true,
1551
+ contextWindowSize: 1048576,
1552
+ maxOutputTokens: 64e3,
1553
+ supportFunctionCalling: true,
1554
+ supportStructuredOutput: true
1555
+ };
1556
+ this.tools = [];
1557
+ this.streaming = false;
1558
+ this.structuredOutput = void 0;
1559
+ this.effort = new GeminiReasoningEffort(
1560
+ this.specification.defaultReasoningEffort
1561
+ );
1562
+ }
1563
+ setStreaming(streaming) {
1564
+ this.streaming = streaming;
1565
+ }
1566
+ getStreaming() {
1567
+ return this.streaming;
1568
+ }
1569
+ setTools(tools) {
1570
+ this.tools = tools;
1571
+ }
1572
+ getTools() {
1573
+ return this.tools;
1574
+ }
1575
+ setReasoningEffort(effort) {
1576
+ this.effort.setReasoningEffort(effort);
1577
+ }
1578
+ getReasoningEffort() {
1579
+ return this.effort.getReasoningEffort();
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
+ }
1590
+ };
1591
+
1592
+ // src/infrastructure/providers/gemini/models/gemini-3-1-pro.ts
1593
+ var Gemini31Pro = class {
1594
+ constructor() {
1595
+ this.specification = {
1596
+ name: "gemini-3.1-pro-preview",
1597
+ provider: "google",
1598
+ supportReasoningEffort: true,
1599
+ defaultReasoningEffort: "high",
1600
+ supportStreaming: true,
1601
+ contextWindowSize: 1048576,
1602
+ maxOutputTokens: 64e3,
1603
+ supportFunctionCalling: true,
1604
+ supportStructuredOutput: true
1605
+ };
1606
+ this.tools = [];
1607
+ this.streaming = false;
1608
+ this.structuredOutput = void 0;
1609
+ this.effort = new GeminiReasoningEffort(
1610
+ this.specification.defaultReasoningEffort
1611
+ );
1612
+ }
1613
+ setStreaming(streaming) {
1614
+ this.streaming = streaming;
1615
+ }
1616
+ getStreaming() {
1617
+ return this.streaming;
1618
+ }
1619
+ setTools(tools) {
1620
+ this.tools = tools;
1621
+ }
1622
+ getTools() {
1623
+ return this.tools;
1624
+ }
1625
+ setReasoningEffort(effort) {
1626
+ this.effort.setReasoningEffort(effort);
1627
+ }
1628
+ getReasoningEffort() {
1629
+ return this.effort.getReasoningEffort();
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);
1175
1961
  };
1176
1962
  export {
1177
- Agent,
1178
1963
  AgenticEnvironment,
1964
+ AgenticError,
1179
1965
  AnthropicMessages,
1180
- BaseAgent,
1181
- BaseHuman,
1182
- BaseObserver,
1966
+ BaseParticipant,
1183
1967
  ClaudeHaiku45,
1184
1968
  ClaudeOpus47,
1969
+ ClaudeOpus48,
1185
1970
  ClaudeSonnet46,
1186
1971
  ContextItem,
1187
- DefaultFunctionCallRunner,
1972
+ DeepSeekV4Flash,
1973
+ DeepSeekV4Pro,
1188
1974
  DeveloperMessageItem,
1189
1975
  FunctionCallItem,
1190
1976
  FunctionCallOutputItem,
1977
+ Gemini31Pro,
1978
+ Gemini35Flash,
1979
+ GeminiGenerateContent,
1191
1980
  Gpt54,
1192
1981
  Gpt54Mini,
1193
1982
  Gpt54Nano,
1194
1983
  Gpt55,
1195
- Human,
1196
1984
  InMemoryModelContextRepository,
1197
1985
  InferenceRequest,
1198
1986
  InferenceResponse,
1199
1987
  InputTokenDetails,
1200
1988
  ModelContext,
1201
1989
  ModelMessageItem,
1202
- Observer,
1203
- OpenAIInferenceRunner,
1990
+ OpenAIChatCompletions,
1204
1991
  OpenAIResponses,
1205
1992
  OutputTokenDetails,
1206
1993
  Participant,
@@ -1208,6 +1995,9 @@ export {
1208
1995
  SemanticEvent,
1209
1996
  SystemMessageItem,
1210
1997
  TokenUsage,
1211
- UserMessageItem
1998
+ UserMessageItem,
1999
+ executeFunctionCall,
2000
+ runInference,
2001
+ sendMessage
1212
2002
  };
1213
2003
  //# sourceMappingURL=index.mjs.map