@mozaik-ai/core 4.0.0-beta.1 → 4.0.0-beta.10

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.js CHANGED
@@ -30,26 +30,35 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ Agent: () => Agent,
34
+ AnthropicMessages: () => AnthropicMessages,
33
35
  ContextItem: () => ContextItem,
36
+ DefaultInferenceRunner: () => DefaultInferenceRunner,
34
37
  DeveloperMessageItem: () => DeveloperMessageItem,
35
38
  FunctionCallItem: () => FunctionCallItem,
36
39
  FunctionCallOutputItem: () => FunctionCallOutputItem,
40
+ GeminiGenerateContent: () => GeminiGenerateContent,
41
+ Human: () => Human,
37
42
  InputTokenDetails: () => InputTokenDetails,
38
43
  McpClient: () => McpClient,
39
44
  McpToolRegistry: () => McpToolRegistry,
40
45
  ModelContext: () => ModelContext,
41
46
  ModelMessageItem: () => ModelMessageItem,
47
+ OpenAIChatCompletions: () => OpenAIChatCompletions,
48
+ OpenAIResponses: () => OpenAIResponses,
42
49
  OutputTokenDetails: () => OutputTokenDetails,
43
50
  Participant: () => Participant,
44
51
  ReasoningItem: () => ReasoningItem,
45
52
  RuntimeState: () => RuntimeState,
46
53
  SemanticEvent: () => SemanticEvent,
54
+ SituationSpecification: () => SituationSpecification,
47
55
  SystemMessageItem: () => SystemMessageItem,
48
56
  TokenUsage: () => TokenUsage,
49
57
  UserMessageItem: () => UserMessageItem,
50
58
  createAgent: () => createAgent,
51
59
  createHuman: () => createHuman,
52
- defineRuntime: () => defineRuntime
60
+ defineRuntime: () => defineRuntime,
61
+ supportedModels: () => supportedModels
53
62
  });
54
63
  module.exports = __toCommonJS(index_exports);
55
64
 
@@ -369,6 +378,16 @@ var SemanticEvent = class _SemanticEvent {
369
378
  return new _SemanticEvent(type, producerId, occurredAt, payload);
370
379
  }
371
380
  };
381
+ var ParticipantJoinedEvent = class extends SemanticEvent {
382
+ static init(manifest) {
383
+ return SemanticEvent.create("participant.joined", manifest.id, manifest);
384
+ }
385
+ };
386
+ var ParticipantLeftEvent = class extends SemanticEvent {
387
+ static init(manifest) {
388
+ return SemanticEvent.create("participant.left", manifest.id, manifest);
389
+ }
390
+ };
372
391
  var MessageSentEvent = class extends SemanticEvent {
373
392
  static init(producerId, message) {
374
393
  return SemanticEvent.create("message.sent", producerId, { message });
@@ -408,6 +427,9 @@ var Participant = class {
408
427
  getHandlers() {
409
428
  return this.handlers;
410
429
  }
430
+ setHandlers(handlers) {
431
+ this.handlers = handlers;
432
+ }
411
433
  };
412
434
 
413
435
  // src/domain/agentic-environment/participant/memory.ts
@@ -524,9 +546,11 @@ var RuntimeService = class {
524
546
  }
525
547
  join(participant) {
526
548
  this.state.addParticipant(participant);
549
+ this.publish(ParticipantJoinedEvent.init(participant.getManifest()));
527
550
  }
528
551
  leave(participant) {
529
552
  this.state.removeParticipant(participant);
553
+ this.publish(ParticipantLeftEvent.init(participant.getManifest()));
530
554
  }
531
555
  publish(event) {
532
556
  for (const participant of this.state.getParticipants()) {
@@ -590,38 +614,57 @@ function createSendMessage(resolveRuntime) {
590
614
  }
591
615
 
592
616
  // src/domain/agentic-environment/loop/agent-loop.ts
593
- var AgentLoop = class {
594
- constructor(stateExecutor, transitionResolver, loopVisitor) {
617
+ var AgentLoop = class _AgentLoop {
618
+ constructor(loopId, stateExecutor, transitionResolver, interceptionHandler) {
619
+ this.loopId = loopId;
595
620
  this.stateExecutor = stateExecutor;
596
621
  this.transitionResolver = transitionResolver;
597
- this.loopVisitor = loopVisitor;
622
+ this.interceptionHandler = interceptionHandler;
598
623
  }
599
- async run(message) {
624
+ async run(message, loopVisitor) {
625
+ var _a;
600
626
  let transition = {
601
- nextStateId: "message_received",
627
+ nextStateId: "context_update",
602
628
  input: message
603
629
  };
604
630
  while (transition.nextStateId !== "idle") {
605
- const execution = await this.stateExecutor.execute(transition, this.loopVisitor);
606
- transition = this.transitionResolver.resolve(execution);
631
+ const isInterceptionSatisfied = (_a = this.interceptionHandler) == null ? void 0 : _a.isSatisfiedBy(transition);
632
+ if (isInterceptionSatisfied && this.interceptionHandler) {
633
+ loopVisitor.visitInterceptionStarted(transition);
634
+ transition = await this.interceptionHandler.handle(transition);
635
+ loopVisitor.visitInterceptionFinished(transition);
636
+ } else {
637
+ const execution = await this.stateExecutor.execute(transition, loopVisitor);
638
+ transition = this.transitionResolver.resolve(execution);
639
+ }
607
640
  }
608
641
  }
642
+ getLoopId() {
643
+ return this.loopId;
644
+ }
645
+ static create(stateExecutor, transitionResolver, interceptionHandler) {
646
+ const loopId = crypto.randomUUID();
647
+ return new _AgentLoop(loopId, stateExecutor, transitionResolver, interceptionHandler);
648
+ }
609
649
  };
610
650
 
611
651
  // src/domain/agentic-environment/loop/state-executor.ts
612
652
  var LoopStateExecutor = class {
613
- constructor(messageReceivedState, inferenceState, functionCallState, modelMessageState) {
614
- this.messageReceivedState = messageReceivedState;
653
+ constructor(contextUpdateState, inferenceState, inferenceStreamingState, functionCallState, modelMessageState) {
654
+ this.contextUpdateState = contextUpdateState;
615
655
  this.inferenceState = inferenceState;
656
+ this.inferenceStreamingState = inferenceStreamingState;
616
657
  this.functionCallState = functionCallState;
617
658
  this.modelMessageState = modelMessageState;
618
659
  }
619
660
  async execute(transition, loopVisitor) {
620
661
  switch (transition.nextStateId) {
621
- case "message_received":
622
- return await this.messageReceivedState.run(transition.input, loopVisitor);
662
+ case "context_update":
663
+ return await this.contextUpdateState.run(transition.input, loopVisitor);
623
664
  case "inference":
624
665
  return await this.inferenceState.run(transition.input, loopVisitor);
666
+ case "inference_streaming":
667
+ return await this.inferenceStreamingState.run(transition.input, loopVisitor);
625
668
  case "function_call":
626
669
  return await this.functionCallState.run(transition.input, loopVisitor);
627
670
  case "model_message":
@@ -662,19 +705,19 @@ var FunctionCallState = class {
662
705
  }
663
706
  };
664
707
 
665
- // src/application/states/message-received.ts
666
- var MessageReceivedState = class {
708
+ // src/application/states/context-update.ts
709
+ var ContextUpdateState = class {
667
710
  constructor() {
668
- this.id = "message_received";
711
+ this.id = "context_update";
669
712
  }
670
713
  async run(input, loopVisitor) {
671
- loopVisitor.visitMessageReceivedStarted(input);
714
+ loopVisitor.visitContextUpdateStarted(input);
672
715
  const userMessage = UserMessageItem.create(input.content);
673
716
  const output = {
674
717
  ...input.input,
675
718
  context: input.input.context.addContextItems([userMessage])
676
719
  };
677
- loopVisitor.visitMessageReceivedCompleted(output);
720
+ loopVisitor.visitContextUpdateCompleted(output);
678
721
  return {
679
722
  stateId: this.id,
680
723
  input,
@@ -715,17 +758,20 @@ var TransitionResolver = class {
715
758
  // src/domain/agentic-environment/loop/transition-specification.ts
716
759
  var MessageReceivedSpecification = class {
717
760
  isSatisfiedBy(execution) {
718
- return execution.stateId === "message_received";
761
+ return execution.stateId === "context_update";
719
762
  }
720
763
  };
764
+ function isInferenceExecution(execution) {
765
+ return execution.stateId === "inference" || execution.stateId === "inference_streaming";
766
+ }
721
767
  var InferenceProducedFunctionCallSpecification = class {
722
768
  isSatisfiedBy(execution) {
723
- return execution.stateId === "inference" && execution.output.items.some((item) => item.type === "function_call");
769
+ return isInferenceExecution(execution) && execution.output.items.some((item) => item.type === "function_call");
724
770
  }
725
771
  };
726
772
  var InferenceProducedModelMessageSpecification = class {
727
773
  isSatisfiedBy(execution) {
728
- return execution.stateId === "inference" && execution.output.items.some((item) => item.type === "message" && item.role === "assistant");
774
+ return isInferenceExecution(execution) && execution.output.items.some((item) => item.type === "message" && item.role === "assistant");
729
775
  }
730
776
  };
731
777
  var FunctionCallCompletedSpecification = class {
@@ -740,16 +786,17 @@ var ModelMessageCompletedSpecification = class {
740
786
  };
741
787
 
742
788
  // src/domain/agentic-environment/loop/transition-rule.ts
743
- var MessageReceivedToInferenceRule = class {
789
+ var ContextPreparationToInferenceRule = class {
744
790
  constructor() {
745
791
  this.specification = new MessageReceivedSpecification();
746
792
  }
747
793
  createTransition(execution) {
748
- if (execution.stateId !== "message_received") {
749
- throw new Error("Expected message_received execution");
794
+ if (execution.stateId !== "context_update") {
795
+ throw new Error("Expected context_preparation execution");
750
796
  }
797
+ const nextStateId = execution.output.streaming ? "inference_streaming" : "inference";
751
798
  return {
752
- nextStateId: "inference",
799
+ nextStateId,
753
800
  input: execution.output
754
801
  };
755
802
  }
@@ -759,7 +806,7 @@ var InferenceToFunctionCallRule = class {
759
806
  this.specification = new InferenceProducedFunctionCallSpecification();
760
807
  }
761
808
  createTransition(execution) {
762
- if (execution.stateId !== "inference" || !execution.output.items.some((item) => item.type === "function_call")) {
809
+ if (execution.stateId !== "inference" && execution.stateId !== "inference_streaming" || !execution.output.items.some((item) => item.type === "function_call")) {
763
810
  throw new Error("Expected inference function-call output");
764
811
  }
765
812
  const functionCallItem = execution.output.items.find((item) => item.type === "function_call");
@@ -780,7 +827,7 @@ var InferenceToModelMessageRule = class {
780
827
  this.specification = new InferenceProducedModelMessageSpecification();
781
828
  }
782
829
  createTransition(execution) {
783
- if (execution.stateId !== "inference" || !execution.output.items.some((item) => item.type === "message" && item.role === "assistant")) {
830
+ if (execution.stateId !== "inference" && execution.stateId !== "inference_streaming" || !execution.output.items.some((item) => item.type === "message" && item.role === "assistant")) {
784
831
  throw new Error("Expected inference model-message output");
785
832
  }
786
833
  const modelMessageItem = execution.output.items.find(
@@ -808,7 +855,7 @@ var FunctionCallToInferenceRule = class {
808
855
  const previousRequest = execution.input.inferenceInput;
809
856
  previousRequest.context.addContextItems([execution.input.call, execution.output.item]);
810
857
  return {
811
- nextStateId: "inference",
858
+ nextStateId: previousRequest.streaming ? "inference_streaming" : "inference",
812
859
  input: {
813
860
  ...previousRequest
814
861
  }
@@ -831,82 +878,110 @@ var ModelMessageToIdleRule = class {
831
878
  };
832
879
 
833
880
  // src/domain/agentic-environment/loop/event-publisher-visitor.ts
881
+ var import_cloud_sdk = require("@mozaik-ai/cloud-sdk");
834
882
  var EventPublisherLoopVisitor = class {
835
- constructor(agentId, runtime) {
883
+ constructor(agentId, loopId, runtime) {
836
884
  this.agentId = agentId;
885
+ this.loopId = loopId;
837
886
  this.runtime = runtime;
887
+ this.cloud = (0, import_cloud_sdk.createCloudClient)();
838
888
  }
839
- visitMessageReceivedStarted(input) {
840
- console.log("Visiting message received started: ", input);
841
- this.publish("message_received.started", input);
889
+ visitContextUpdateStarted(input) {
890
+ this.publish("context_update.started", { ...input, loopId: this.loopId });
842
891
  }
843
- visitMessageReceivedCompleted(output) {
844
- console.log("Visiting message received completed: ", output);
845
- this.publish("message_received.completed", output);
892
+ visitContextUpdateCompleted(output) {
893
+ this.publish("context_update.completed", { ...output, loopId: this.loopId });
846
894
  }
847
895
  visitInferenceStarted(input) {
848
- console.log("Visiting inference started: ", input);
849
896
  this.publish("inference.started", input);
850
897
  }
851
898
  visitInferenceEvent(event) {
852
- console.log("Visiting inference event: ", event);
853
899
  this.publish("inference.stream", event);
854
900
  }
855
901
  visitInferenceCompleted(output) {
856
- console.log("Visiting inference completed: ", output);
857
902
  this.publish("inference.completed", output);
858
903
  }
859
904
  visitFunctionCallStarted(input) {
860
- console.log("Visiting function call started: ", input);
861
905
  this.publish("function_call.started", input);
862
906
  }
863
907
  visitFunctionCallCompleted(output) {
864
- console.log("Visiting function call completed: ", output);
865
908
  this.publish("function_call.completed", output);
866
909
  }
867
910
  visitModelAnswer(input) {
868
- console.log("Visiting model answer: ", input.answer);
869
911
  this.publish("model.answer", input);
870
912
  }
913
+ visitInterceptionStarted(transition) {
914
+ this.publish("interception.started", transition);
915
+ }
916
+ visitInterceptionFinished(transition) {
917
+ this.publish("interception.finished", transition);
918
+ }
871
919
  publish(type, payload) {
872
- this.runtime.publish({
873
- type,
874
- producerId: this.agentId,
875
- occurredAt: /* @__PURE__ */ new Date(),
876
- payload
877
- });
920
+ const event = new SemanticEvent(type, this.agentId, /* @__PURE__ */ new Date(), payload);
921
+ this.runtime.publish(event);
922
+ if (this.cloud.enabled) {
923
+ this.cloud.send(event);
924
+ }
925
+ }
926
+ };
927
+
928
+ // src/application/states/inference-streaming.ts
929
+ var InferenceStreamingState = class {
930
+ constructor(inferenceRunner) {
931
+ this.inferenceRunner = inferenceRunner;
932
+ this.id = "inference_streaming";
933
+ }
934
+ async run(input, loopVisitor) {
935
+ loopVisitor.visitInferenceStarted(input);
936
+ let output = void 0;
937
+ for await (const event of this.inferenceRunner.stream(input)) {
938
+ loopVisitor.visitInferenceEvent(event);
939
+ if (event.type === "inference.output") {
940
+ output = event.payload;
941
+ }
942
+ }
943
+ if (!output) {
944
+ throw new Error("Inference output not found");
945
+ }
946
+ loopVisitor.visitInferenceCompleted(output);
947
+ return {
948
+ stateId: "inference_streaming",
949
+ input,
950
+ output
951
+ };
878
952
  }
879
953
  };
880
954
 
881
955
  // src/application/use-cases/run-loop.ts
882
956
  function createRunLoop(resolveRuntime) {
883
- return function runLoop(agentId, message, inferenceInput) {
957
+ return function runLoop(agentId, message, inferenceInput, interceptionHandler) {
884
958
  const runtime = resolveRuntime();
885
959
  const inferenceRunner = runtime.getInferenceRunner();
886
960
  const functionCallRunner = runtime.getFunctionCallRunner();
887
961
  const transitionResolver = new TransitionResolver([
888
962
  // High-priority interception rules would go first.
889
- new MessageReceivedToInferenceRule(),
963
+ new ContextPreparationToInferenceRule(),
890
964
  new InferenceToFunctionCallRule(),
891
965
  new InferenceToModelMessageRule(),
892
966
  new FunctionCallToInferenceRule(),
893
967
  new ModelMessageToIdleRule()
894
968
  ]);
895
969
  const stateExecutor = new LoopStateExecutor(
896
- new MessageReceivedState(),
970
+ new ContextUpdateState(),
897
971
  new InferenceState(inferenceRunner),
972
+ new InferenceStreamingState(inferenceRunner),
898
973
  new FunctionCallState(functionCallRunner),
899
974
  new ModelMessageState()
900
975
  );
901
- const agentLoop = new AgentLoop(
902
- stateExecutor,
903
- transitionResolver,
904
- new EventPublisherLoopVisitor(agentId, runtime)
976
+ const agentLoop = AgentLoop.create(stateExecutor, transitionResolver, interceptionHandler);
977
+ const loopVisitor = new EventPublisherLoopVisitor(agentId, agentLoop.getLoopId(), runtime);
978
+ agentLoop.run(
979
+ {
980
+ content: message,
981
+ input: inferenceInput
982
+ },
983
+ loopVisitor
905
984
  );
906
- agentLoop.run({
907
- content: message,
908
- input: inferenceInput
909
- });
910
985
  };
911
986
  }
912
987
 
@@ -1065,7 +1140,14 @@ var import_sdk = __toESM(require("@anthropic-ai/sdk"));
1065
1140
  var AnthropicMessages = class {
1066
1141
  constructor(endpointMapper = new AnthropicMessagesMapper(), config = {}) {
1067
1142
  this.endpointMapper = endpointMapper;
1068
- this.client = new import_sdk.default({ baseURL: config.baseURL, apiKey: config.apiKey });
1143
+ this.clientConfig = config;
1144
+ }
1145
+ get client() {
1146
+ var _a;
1147
+ return (_a = this._client) != null ? _a : this._client = new import_sdk.default({
1148
+ baseURL: this.clientConfig.baseURL,
1149
+ apiKey: this.clientConfig.apiKey
1150
+ });
1069
1151
  }
1070
1152
  async infer(inferenceInput) {
1071
1153
  const request = this.endpointMapper.toRequest(inferenceInput);
@@ -1074,10 +1156,17 @@ var AnthropicMessages = class {
1074
1156
  }
1075
1157
  async *stream(inferenceInput) {
1076
1158
  const request = this.endpointMapper.toRequest(inferenceInput);
1077
- const stream = await this.client.messages.create(request);
1159
+ const stream = this.client.messages.stream(request);
1078
1160
  for await (const event of stream) {
1079
1161
  yield event;
1080
1162
  }
1163
+ const output = this.endpointMapper.toResponse(await stream.finalMessage());
1164
+ yield {
1165
+ type: "inference.output",
1166
+ producerId: request.model,
1167
+ occurredAt: /* @__PURE__ */ new Date(),
1168
+ payload: output
1169
+ };
1081
1170
  }
1082
1171
  };
1083
1172
 
@@ -1239,7 +1328,10 @@ var OpenAIResponsesMapper = class {
1239
1328
  var OpenAIResponses = class {
1240
1329
  constructor(endpointMapper = new OpenAIResponsesMapper()) {
1241
1330
  this.endpointMapper = endpointMapper;
1242
- this.client = new import_openai.default();
1331
+ }
1332
+ get client() {
1333
+ var _a;
1334
+ return (_a = this._client) != null ? _a : this._client = new import_openai.default();
1243
1335
  }
1244
1336
  async infer(inferenceInput) {
1245
1337
  const request = this.endpointMapper.toRequest(inferenceInput);
@@ -1248,10 +1340,24 @@ var OpenAIResponses = class {
1248
1340
  }
1249
1341
  async *stream(inferenceInput) {
1250
1342
  const request = this.endpointMapper.toRequest(inferenceInput);
1251
- const response = await this.client.responses.create(request);
1252
- for await (const event of response) {
1343
+ const stream = await this.client.responses.create({ ...request, stream: true });
1344
+ let completedResponse = void 0;
1345
+ for await (const event of stream) {
1346
+ if (event.type === "response.completed") {
1347
+ completedResponse = event.response;
1348
+ }
1253
1349
  yield event;
1254
1350
  }
1351
+ if (!completedResponse) {
1352
+ throw new Error("Stream ended without a completed response");
1353
+ }
1354
+ const output = this.endpointMapper.toResponse(completedResponse);
1355
+ yield {
1356
+ type: "inference.output",
1357
+ payload: output,
1358
+ occurredAt: /* @__PURE__ */ new Date(),
1359
+ producerId: inferenceInput.model
1360
+ };
1255
1361
  }
1256
1362
  };
1257
1363
 
@@ -1408,11 +1514,14 @@ var GeminiGenerateContentMapper = class {
1408
1514
  // src/infrastructure/providers/gemini/endpoints/gemini-generate-content.ts
1409
1515
  var GeminiGenerateContent = class {
1410
1516
  constructor(endpointMapper = new GeminiGenerateContentMapper(), config = {}) {
1411
- var _a;
1412
1517
  this.endpointMapper = endpointMapper;
1413
- this.client = new import_genai.GoogleGenAI({
1414
- apiKey: (_a = config.apiKey) != null ? _a : process.env.GEMINI_API_KEY,
1415
- ...config.baseURL ? { httpOptions: { baseUrl: config.baseURL } } : {}
1518
+ this.clientConfig = config;
1519
+ }
1520
+ get client() {
1521
+ var _a, _b;
1522
+ return (_b = this._client) != null ? _b : this._client = new import_genai.GoogleGenAI({
1523
+ apiKey: (_a = this.clientConfig.apiKey) != null ? _a : process.env.GEMINI_API_KEY,
1524
+ ...this.clientConfig.baseURL ? { httpOptions: { baseUrl: this.clientConfig.baseURL } } : {}
1416
1525
  });
1417
1526
  }
1418
1527
  async infer(inferenceInput) {
@@ -1423,9 +1532,21 @@ var GeminiGenerateContent = class {
1423
1532
  async *stream(inferenceInput) {
1424
1533
  const request = this.endpointMapper.toRequest(inferenceInput);
1425
1534
  const stream = await this.client.models.generateContentStream(request);
1535
+ let lastEvent = void 0;
1426
1536
  for await (const chunk of stream) {
1537
+ lastEvent = chunk;
1427
1538
  yield chunk;
1428
1539
  }
1540
+ if (!lastEvent) {
1541
+ throw new Error("Last event not found");
1542
+ }
1543
+ const output = this.endpointMapper.toResponse(lastEvent);
1544
+ yield {
1545
+ type: "inference.output",
1546
+ producerId: request.model,
1547
+ occurredAt: /* @__PURE__ */ new Date(),
1548
+ payload: output
1549
+ };
1429
1550
  }
1430
1551
  };
1431
1552
 
@@ -1542,12 +1663,16 @@ var OpenAIChatCompletions = class {
1542
1663
  constructor(endpointMapper = new OpenAIChatCompletionsMapper(), config = {}) {
1543
1664
  var _a;
1544
1665
  this.endpointMapper = endpointMapper;
1545
- this.client = new import_openai2.default({
1546
- baseURL: config.baseURL,
1547
- apiKey: config.apiKey
1548
- });
1666
+ this.clientConfig = config;
1549
1667
  this.extraBody = (_a = config.extraBody) != null ? _a : {};
1550
1668
  }
1669
+ get client() {
1670
+ var _a;
1671
+ return (_a = this._client) != null ? _a : this._client = new import_openai2.default({
1672
+ baseURL: this.clientConfig.baseURL,
1673
+ apiKey: this.clientConfig.apiKey
1674
+ });
1675
+ }
1551
1676
  buildRequest(inferenceInput) {
1552
1677
  return {
1553
1678
  ...this.extraBody,
@@ -1559,10 +1684,17 @@ var OpenAIChatCompletions = class {
1559
1684
  return this.endpointMapper.toResponse(response);
1560
1685
  }
1561
1686
  async *stream(inferenceInput) {
1562
- const stream = await this.client.chat.completions.create(this.buildRequest(inferenceInput));
1563
- for await (const event of stream) {
1564
- yield event;
1687
+ const stream = this.client.chat.completions.stream(this.buildRequest(inferenceInput));
1688
+ for await (const chunk of stream) {
1689
+ yield chunk;
1565
1690
  }
1691
+ const output = this.endpointMapper.toResponse(await stream.finalChatCompletion());
1692
+ yield {
1693
+ type: "inference.output",
1694
+ payload: output,
1695
+ occurredAt: /* @__PURE__ */ new Date(),
1696
+ producerId: inferenceInput.model
1697
+ };
1566
1698
  }
1567
1699
  };
1568
1700
 
@@ -1986,13 +2118,13 @@ var DefaultInferenceRunner = class {
1986
2118
  this.requestValidator.validate(input, generativeModel.specification);
1987
2119
  return await generativeModel.endpoint.infer(input);
1988
2120
  }
1989
- async streamInference(input) {
2121
+ async *stream(input) {
1990
2122
  const generativeModel = this.supportedModels.find((model) => model.specification.name === input.model);
1991
2123
  if (!generativeModel) {
1992
2124
  throw new Error(`Unsupported model: ${input.model}`);
1993
2125
  }
1994
2126
  this.requestValidator.validate(input, generativeModel.specification);
1995
- return await generativeModel.endpoint.stream(input);
2127
+ yield* generativeModel.endpoint.stream(input);
1996
2128
  }
1997
2129
  };
1998
2130
 
@@ -2008,6 +2140,18 @@ var DefaultFunctionCallRunner = class {
2008
2140
  }
2009
2141
  };
2010
2142
 
2143
+ // src/application/use-cases/send-event.ts
2144
+ function createSendEvent(resolveRuntime) {
2145
+ return function sendEvent(event, senderId) {
2146
+ const runtime = resolveRuntime();
2147
+ const participant = runtime.getParticipant(senderId);
2148
+ if (!participant) {
2149
+ throw new Error(`Participant ${senderId} not found`);
2150
+ }
2151
+ runtime.publish(event);
2152
+ };
2153
+ }
2154
+
2011
2155
  // src/define-runtime.ts
2012
2156
  function defineRuntime() {
2013
2157
  let runtime = null;
@@ -2044,6 +2188,7 @@ function defineRuntime() {
2044
2188
  const join = createJoin(resolveRuntime);
2045
2189
  const leave = createLeave(resolveRuntime);
2046
2190
  const sendMessage = createSendMessage(resolveRuntime);
2191
+ const sendEvent = createSendEvent(resolveRuntime);
2047
2192
  const runLoop = createRunLoop(resolveRuntime);
2048
2193
  return {
2049
2194
  initializeRuntime,
@@ -2052,30 +2197,82 @@ function defineRuntime() {
2052
2197
  join,
2053
2198
  leave,
2054
2199
  sendMessage,
2200
+ sendEvent,
2055
2201
  runLoop
2056
2202
  };
2057
2203
  }
2204
+
2205
+ // src/domain/agentic-environment/situation/situation-specification.ts
2206
+ var SituationSpecification = class {
2207
+ and(other) {
2208
+ return new AndSituationSpecification(this, other);
2209
+ }
2210
+ or(other) {
2211
+ return new OrSituationSpecification(this, other);
2212
+ }
2213
+ not() {
2214
+ return new NotSituationSpecification(this);
2215
+ }
2216
+ };
2217
+ var AndSituationSpecification = class extends SituationSpecification {
2218
+ constructor(left, right) {
2219
+ super();
2220
+ this.left = left;
2221
+ this.right = right;
2222
+ }
2223
+ isSatisfiedBy(situationContext) {
2224
+ return this.left.isSatisfiedBy(situationContext) && this.right.isSatisfiedBy(situationContext);
2225
+ }
2226
+ };
2227
+ var OrSituationSpecification = class extends SituationSpecification {
2228
+ constructor(left, right) {
2229
+ super();
2230
+ this.left = left;
2231
+ this.right = right;
2232
+ }
2233
+ isSatisfiedBy(situationContext) {
2234
+ return this.left.isSatisfiedBy(situationContext) || this.right.isSatisfiedBy(situationContext);
2235
+ }
2236
+ };
2237
+ var NotSituationSpecification = class extends SituationSpecification {
2238
+ constructor(rule) {
2239
+ super();
2240
+ this.rule = rule;
2241
+ }
2242
+ isSatisfiedBy(situationContext) {
2243
+ return !this.rule.isSatisfiedBy(situationContext);
2244
+ }
2245
+ };
2058
2246
  // Annotate the CommonJS export names for ESM import in node:
2059
2247
  0 && (module.exports = {
2248
+ Agent,
2249
+ AnthropicMessages,
2060
2250
  ContextItem,
2251
+ DefaultInferenceRunner,
2061
2252
  DeveloperMessageItem,
2062
2253
  FunctionCallItem,
2063
2254
  FunctionCallOutputItem,
2255
+ GeminiGenerateContent,
2256
+ Human,
2064
2257
  InputTokenDetails,
2065
2258
  McpClient,
2066
2259
  McpToolRegistry,
2067
2260
  ModelContext,
2068
2261
  ModelMessageItem,
2262
+ OpenAIChatCompletions,
2263
+ OpenAIResponses,
2069
2264
  OutputTokenDetails,
2070
2265
  Participant,
2071
2266
  ReasoningItem,
2072
2267
  RuntimeState,
2073
2268
  SemanticEvent,
2269
+ SituationSpecification,
2074
2270
  SystemMessageItem,
2075
2271
  TokenUsage,
2076
2272
  UserMessageItem,
2077
2273
  createAgent,
2078
2274
  createHuman,
2079
- defineRuntime
2275
+ defineRuntime,
2276
+ supportedModels
2080
2277
  });
2081
2278
  //# sourceMappingURL=index.js.map