@mozaik-ai/core 4.0.0-beta.3 → 4.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -158,6 +158,7 @@ type InferenceOutput = {
158
158
  };
159
159
  interface InferenceRunner {
160
160
  run(request: InferenceInput): Promise<InferenceOutput>;
161
+ stream(request: InferenceInput): AsyncGenerator<SemanticEvent>;
161
162
  }
162
163
 
163
164
  interface InferenceEndpointMapper {
@@ -330,6 +331,7 @@ declare abstract class Participant {
330
331
  getManifest(): ParticipantManifest;
331
332
  getId(): string;
332
333
  getHandlers(): SituationHandler[];
334
+ setHandlers(handlers: SituationHandler[]): void;
333
335
  }
334
336
 
335
337
  declare class Memory {
@@ -406,8 +408,8 @@ declare class RuntimeService<TRuntimeState extends RuntimeState> {
406
408
  }
407
409
 
408
410
  type InferenceRunnerConfig = {
409
- supportedModels: GenerativeModel[];
410
- runner: InferenceRunner;
411
+ supportedModels?: GenerativeModel[];
412
+ runner?: InferenceRunner;
411
413
  };
412
414
  declare function defineRuntime<TRuntimeState extends RuntimeState>(): {
413
415
  initializeRuntime: (config: {
@@ -427,8 +429,9 @@ declare const supportedModels: GenerativeModel[];
427
429
 
428
430
  declare class OpenAIResponses implements Endpoint {
429
431
  endpointMapper: InferenceEndpointMapper;
430
- private readonly client;
432
+ private _client?;
431
433
  constructor(endpointMapper?: InferenceEndpointMapper);
434
+ private get client();
432
435
  infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
433
436
  stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
434
437
  }
@@ -472,9 +475,11 @@ interface OpenAICompatibleConfig {
472
475
  */
473
476
  declare class OpenAIChatCompletions implements Endpoint {
474
477
  endpointMapper: InferenceEndpointMapper;
475
- private readonly client;
478
+ private _client?;
479
+ private readonly clientConfig;
476
480
  private readonly extraBody;
477
481
  constructor(endpointMapper?: InferenceEndpointMapper, config?: OpenAICompatibleConfig);
482
+ private get client();
478
483
  private buildRequest;
479
484
  infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
480
485
  stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
@@ -491,8 +496,10 @@ interface AnthropicConnectionConfig {
491
496
  */
492
497
  declare class AnthropicMessages implements Endpoint {
493
498
  endpointMapper: InferenceEndpointMapper;
494
- private readonly client;
499
+ private _client?;
500
+ private readonly clientConfig;
495
501
  constructor(endpointMapper?: InferenceEndpointMapper, config?: AnthropicConnectionConfig);
502
+ private get client();
496
503
  infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
497
504
  stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
498
505
  }
@@ -511,10 +518,12 @@ interface GeminiConnectionConfig {
511
518
  */
512
519
  declare class GeminiGenerateContent implements Endpoint {
513
520
  endpointMapper: InferenceEndpointMapper;
514
- private readonly client;
521
+ private _client?;
522
+ private readonly clientConfig;
515
523
  constructor(endpointMapper?: InferenceEndpointMapper, config?: GeminiConnectionConfig);
524
+ private get client();
516
525
  infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
517
526
  stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
518
527
  }
519
528
 
520
- export { AnthropicMessages, ContextItem, DeveloperMessageItem, type Endpoint, FunctionCallItem, FunctionCallOutputItem, GeminiGenerateContent, type InferenceInput, type InferenceOutput, InputTokenDetails, McpClient, type McpServerConfig, McpToolRegistry, type McpToolSpec, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIChatCompletions, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, RuntimeState, SemanticEvent, type StructuredOutputFormat, SystemMessageItem, TokenUsage, type Tool, UserMessageItem, createAgent, createHuman, defineRuntime, supportedModels };
529
+ export { Agent, AnthropicMessages, ContextItem, DeveloperMessageItem, type Endpoint, FunctionCallItem, FunctionCallOutputItem, GeminiGenerateContent, Human, type InferenceInput, type InferenceOutput, type InferenceRunner, type InferenceRunnerConfig, InputTokenDetails, McpClient, type McpServerConfig, McpToolRegistry, type McpToolSpec, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIChatCompletions, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, RuntimeState, SemanticEvent, type SituationContext, type SituationHandler, type SituationProcessor, SituationSpecification, type StructuredOutputFormat, SystemMessageItem, TokenUsage, type Tool, UserMessageItem, createAgent, createHuman, defineRuntime, supportedModels };
package/dist/index.d.ts CHANGED
@@ -158,6 +158,7 @@ type InferenceOutput = {
158
158
  };
159
159
  interface InferenceRunner {
160
160
  run(request: InferenceInput): Promise<InferenceOutput>;
161
+ stream(request: InferenceInput): AsyncGenerator<SemanticEvent>;
161
162
  }
162
163
 
163
164
  interface InferenceEndpointMapper {
@@ -330,6 +331,7 @@ declare abstract class Participant {
330
331
  getManifest(): ParticipantManifest;
331
332
  getId(): string;
332
333
  getHandlers(): SituationHandler[];
334
+ setHandlers(handlers: SituationHandler[]): void;
333
335
  }
334
336
 
335
337
  declare class Memory {
@@ -406,8 +408,8 @@ declare class RuntimeService<TRuntimeState extends RuntimeState> {
406
408
  }
407
409
 
408
410
  type InferenceRunnerConfig = {
409
- supportedModels: GenerativeModel[];
410
- runner: InferenceRunner;
411
+ supportedModels?: GenerativeModel[];
412
+ runner?: InferenceRunner;
411
413
  };
412
414
  declare function defineRuntime<TRuntimeState extends RuntimeState>(): {
413
415
  initializeRuntime: (config: {
@@ -427,8 +429,9 @@ declare const supportedModels: GenerativeModel[];
427
429
 
428
430
  declare class OpenAIResponses implements Endpoint {
429
431
  endpointMapper: InferenceEndpointMapper;
430
- private readonly client;
432
+ private _client?;
431
433
  constructor(endpointMapper?: InferenceEndpointMapper);
434
+ private get client();
432
435
  infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
433
436
  stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
434
437
  }
@@ -472,9 +475,11 @@ interface OpenAICompatibleConfig {
472
475
  */
473
476
  declare class OpenAIChatCompletions implements Endpoint {
474
477
  endpointMapper: InferenceEndpointMapper;
475
- private readonly client;
478
+ private _client?;
479
+ private readonly clientConfig;
476
480
  private readonly extraBody;
477
481
  constructor(endpointMapper?: InferenceEndpointMapper, config?: OpenAICompatibleConfig);
482
+ private get client();
478
483
  private buildRequest;
479
484
  infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
480
485
  stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
@@ -491,8 +496,10 @@ interface AnthropicConnectionConfig {
491
496
  */
492
497
  declare class AnthropicMessages implements Endpoint {
493
498
  endpointMapper: InferenceEndpointMapper;
494
- private readonly client;
499
+ private _client?;
500
+ private readonly clientConfig;
495
501
  constructor(endpointMapper?: InferenceEndpointMapper, config?: AnthropicConnectionConfig);
502
+ private get client();
496
503
  infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
497
504
  stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
498
505
  }
@@ -511,10 +518,12 @@ interface GeminiConnectionConfig {
511
518
  */
512
519
  declare class GeminiGenerateContent implements Endpoint {
513
520
  endpointMapper: InferenceEndpointMapper;
514
- private readonly client;
521
+ private _client?;
522
+ private readonly clientConfig;
515
523
  constructor(endpointMapper?: InferenceEndpointMapper, config?: GeminiConnectionConfig);
524
+ private get client();
516
525
  infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
517
526
  stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
518
527
  }
519
528
 
520
- export { AnthropicMessages, ContextItem, DeveloperMessageItem, type Endpoint, FunctionCallItem, FunctionCallOutputItem, GeminiGenerateContent, type InferenceInput, type InferenceOutput, InputTokenDetails, McpClient, type McpServerConfig, McpToolRegistry, type McpToolSpec, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIChatCompletions, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, RuntimeState, SemanticEvent, type StructuredOutputFormat, SystemMessageItem, TokenUsage, type Tool, UserMessageItem, createAgent, createHuman, defineRuntime, supportedModels };
529
+ export { Agent, AnthropicMessages, ContextItem, DeveloperMessageItem, type Endpoint, FunctionCallItem, FunctionCallOutputItem, GeminiGenerateContent, Human, type InferenceInput, type InferenceOutput, type InferenceRunner, type InferenceRunnerConfig, InputTokenDetails, McpClient, type McpServerConfig, McpToolRegistry, type McpToolSpec, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIChatCompletions, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, RuntimeState, SemanticEvent, type SituationContext, type SituationHandler, type SituationProcessor, SituationSpecification, type StructuredOutputFormat, SystemMessageItem, TokenUsage, type Tool, UserMessageItem, createAgent, createHuman, defineRuntime, supportedModels };
package/dist/index.js CHANGED
@@ -30,12 +30,14 @@ 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,
33
34
  AnthropicMessages: () => AnthropicMessages,
34
35
  ContextItem: () => ContextItem,
35
36
  DeveloperMessageItem: () => DeveloperMessageItem,
36
37
  FunctionCallItem: () => FunctionCallItem,
37
38
  FunctionCallOutputItem: () => FunctionCallOutputItem,
38
39
  GeminiGenerateContent: () => GeminiGenerateContent,
40
+ Human: () => Human,
39
41
  InputTokenDetails: () => InputTokenDetails,
40
42
  McpClient: () => McpClient,
41
43
  McpToolRegistry: () => McpToolRegistry,
@@ -48,6 +50,7 @@ __export(index_exports, {
48
50
  ReasoningItem: () => ReasoningItem,
49
51
  RuntimeState: () => RuntimeState,
50
52
  SemanticEvent: () => SemanticEvent,
53
+ SituationSpecification: () => SituationSpecification,
51
54
  SystemMessageItem: () => SystemMessageItem,
52
55
  TokenUsage: () => TokenUsage,
53
56
  UserMessageItem: () => UserMessageItem,
@@ -413,6 +416,9 @@ var Participant = class {
413
416
  getHandlers() {
414
417
  return this.handlers;
415
418
  }
419
+ setHandlers(handlers) {
420
+ this.handlers = handlers;
421
+ }
416
422
  };
417
423
 
418
424
  // src/domain/agentic-environment/participant/memory.ts
@@ -603,7 +609,7 @@ var AgentLoop = class {
603
609
  }
604
610
  async run(message) {
605
611
  let transition = {
606
- nextStateId: "message_received",
612
+ nextStateId: "context_preparation",
607
613
  input: message
608
614
  };
609
615
  while (transition.nextStateId !== "idle") {
@@ -615,18 +621,21 @@ var AgentLoop = class {
615
621
 
616
622
  // src/domain/agentic-environment/loop/state-executor.ts
617
623
  var LoopStateExecutor = class {
618
- constructor(messageReceivedState, inferenceState, functionCallState, modelMessageState) {
619
- this.messageReceivedState = messageReceivedState;
624
+ constructor(contextPreparationState, inferenceState, inferenceStreamingState, functionCallState, modelMessageState) {
625
+ this.contextPreparationState = contextPreparationState;
620
626
  this.inferenceState = inferenceState;
627
+ this.inferenceStreamingState = inferenceStreamingState;
621
628
  this.functionCallState = functionCallState;
622
629
  this.modelMessageState = modelMessageState;
623
630
  }
624
631
  async execute(transition, loopVisitor) {
625
632
  switch (transition.nextStateId) {
626
- case "message_received":
627
- return await this.messageReceivedState.run(transition.input, loopVisitor);
633
+ case "context_preparation":
634
+ return await this.contextPreparationState.run(transition.input, loopVisitor);
628
635
  case "inference":
629
636
  return await this.inferenceState.run(transition.input, loopVisitor);
637
+ case "inference_streaming":
638
+ return await this.inferenceStreamingState.run(transition.input, loopVisitor);
630
639
  case "function_call":
631
640
  return await this.functionCallState.run(transition.input, loopVisitor);
632
641
  case "model_message":
@@ -667,19 +676,19 @@ var FunctionCallState = class {
667
676
  }
668
677
  };
669
678
 
670
- // src/application/states/message-received.ts
671
- var MessageReceivedState = class {
679
+ // src/application/states/context-preparation.ts
680
+ var ContextPreparationState = class {
672
681
  constructor() {
673
- this.id = "message_received";
682
+ this.id = "context_preparation";
674
683
  }
675
684
  async run(input, loopVisitor) {
676
- loopVisitor.visitMessageReceivedStarted(input);
685
+ loopVisitor.visitContextPreparationStarted(input);
677
686
  const userMessage = UserMessageItem.create(input.content);
678
687
  const output = {
679
688
  ...input.input,
680
689
  context: input.input.context.addContextItems([userMessage])
681
690
  };
682
- loopVisitor.visitMessageReceivedCompleted(output);
691
+ loopVisitor.visitContextPreparationCompleted(output);
683
692
  return {
684
693
  stateId: this.id,
685
694
  input,
@@ -720,17 +729,20 @@ var TransitionResolver = class {
720
729
  // src/domain/agentic-environment/loop/transition-specification.ts
721
730
  var MessageReceivedSpecification = class {
722
731
  isSatisfiedBy(execution) {
723
- return execution.stateId === "message_received";
732
+ return execution.stateId === "context_preparation";
724
733
  }
725
734
  };
735
+ function isInferenceExecution(execution) {
736
+ return execution.stateId === "inference" || execution.stateId === "inference_streaming";
737
+ }
726
738
  var InferenceProducedFunctionCallSpecification = class {
727
739
  isSatisfiedBy(execution) {
728
- return execution.stateId === "inference" && execution.output.items.some((item) => item.type === "function_call");
740
+ return isInferenceExecution(execution) && execution.output.items.some((item) => item.type === "function_call");
729
741
  }
730
742
  };
731
743
  var InferenceProducedModelMessageSpecification = class {
732
744
  isSatisfiedBy(execution) {
733
- return execution.stateId === "inference" && execution.output.items.some((item) => item.type === "message" && item.role === "assistant");
745
+ return isInferenceExecution(execution) && execution.output.items.some((item) => item.type === "message" && item.role === "assistant");
734
746
  }
735
747
  };
736
748
  var FunctionCallCompletedSpecification = class {
@@ -745,16 +757,17 @@ var ModelMessageCompletedSpecification = class {
745
757
  };
746
758
 
747
759
  // src/domain/agentic-environment/loop/transition-rule.ts
748
- var MessageReceivedToInferenceRule = class {
760
+ var ContextPreparationToInferenceRule = class {
749
761
  constructor() {
750
762
  this.specification = new MessageReceivedSpecification();
751
763
  }
752
764
  createTransition(execution) {
753
- if (execution.stateId !== "message_received") {
754
- throw new Error("Expected message_received execution");
765
+ if (execution.stateId !== "context_preparation") {
766
+ throw new Error("Expected context_preparation execution");
755
767
  }
768
+ const nextStateId = execution.output.streaming ? "inference_streaming" : "inference";
756
769
  return {
757
- nextStateId: "inference",
770
+ nextStateId,
758
771
  input: execution.output
759
772
  };
760
773
  }
@@ -764,7 +777,7 @@ var InferenceToFunctionCallRule = class {
764
777
  this.specification = new InferenceProducedFunctionCallSpecification();
765
778
  }
766
779
  createTransition(execution) {
767
- if (execution.stateId !== "inference" || !execution.output.items.some((item) => item.type === "function_call")) {
780
+ if (execution.stateId !== "inference" && execution.stateId !== "inference_streaming" || !execution.output.items.some((item) => item.type === "function_call")) {
768
781
  throw new Error("Expected inference function-call output");
769
782
  }
770
783
  const functionCallItem = execution.output.items.find((item) => item.type === "function_call");
@@ -785,7 +798,7 @@ var InferenceToModelMessageRule = class {
785
798
  this.specification = new InferenceProducedModelMessageSpecification();
786
799
  }
787
800
  createTransition(execution) {
788
- if (execution.stateId !== "inference" || !execution.output.items.some((item) => item.type === "message" && item.role === "assistant")) {
801
+ if (execution.stateId !== "inference" && execution.stateId !== "inference_streaming" || !execution.output.items.some((item) => item.type === "message" && item.role === "assistant")) {
789
802
  throw new Error("Expected inference model-message output");
790
803
  }
791
804
  const modelMessageItem = execution.output.items.find(
@@ -813,7 +826,7 @@ var FunctionCallToInferenceRule = class {
813
826
  const previousRequest = execution.input.inferenceInput;
814
827
  previousRequest.context.addContextItems([execution.input.call, execution.output.item]);
815
828
  return {
816
- nextStateId: "inference",
829
+ nextStateId: previousRequest.streaming ? "inference_streaming" : "inference",
817
830
  input: {
818
831
  ...previousRequest
819
832
  }
@@ -841,20 +854,19 @@ var EventPublisherLoopVisitor = class {
841
854
  this.agentId = agentId;
842
855
  this.runtime = runtime;
843
856
  }
844
- visitMessageReceivedStarted(input) {
857
+ visitContextPreparationStarted(input) {
845
858
  console.log("Visiting message received started: ", input);
846
- this.publish("message_received.started", input);
859
+ this.publish("context_preparation.started", input);
847
860
  }
848
- visitMessageReceivedCompleted(output) {
861
+ visitContextPreparationCompleted(output) {
849
862
  console.log("Visiting message received completed: ", output);
850
- this.publish("message_received.completed", output);
863
+ this.publish("context_preparation.completed", output);
851
864
  }
852
865
  visitInferenceStarted(input) {
853
866
  console.log("Visiting inference started: ", input);
854
867
  this.publish("inference.started", input);
855
868
  }
856
869
  visitInferenceEvent(event) {
857
- console.log("Visiting inference event: ", event);
858
870
  this.publish("inference.stream", event);
859
871
  }
860
872
  visitInferenceCompleted(output) {
@@ -883,6 +895,33 @@ var EventPublisherLoopVisitor = class {
883
895
  }
884
896
  };
885
897
 
898
+ // src/application/states/inference-streaming.ts
899
+ var InferenceStreamingState = class {
900
+ constructor(inferenceRunner) {
901
+ this.inferenceRunner = inferenceRunner;
902
+ this.id = "inference_streaming";
903
+ }
904
+ async run(input, loopVisitor) {
905
+ loopVisitor.visitInferenceStarted(input);
906
+ let output = void 0;
907
+ for await (const event of this.inferenceRunner.stream(input)) {
908
+ loopVisitor.visitInferenceEvent(event);
909
+ if (event.type === "inference.output") {
910
+ output = event.payload;
911
+ }
912
+ }
913
+ if (!output) {
914
+ throw new Error("Inference output not found");
915
+ }
916
+ loopVisitor.visitInferenceCompleted(output);
917
+ return {
918
+ stateId: "inference_streaming",
919
+ input,
920
+ output
921
+ };
922
+ }
923
+ };
924
+
886
925
  // src/application/use-cases/run-loop.ts
887
926
  function createRunLoop(resolveRuntime) {
888
927
  return function runLoop(agentId, message, inferenceInput) {
@@ -891,15 +930,16 @@ function createRunLoop(resolveRuntime) {
891
930
  const functionCallRunner = runtime.getFunctionCallRunner();
892
931
  const transitionResolver = new TransitionResolver([
893
932
  // High-priority interception rules would go first.
894
- new MessageReceivedToInferenceRule(),
933
+ new ContextPreparationToInferenceRule(),
895
934
  new InferenceToFunctionCallRule(),
896
935
  new InferenceToModelMessageRule(),
897
936
  new FunctionCallToInferenceRule(),
898
937
  new ModelMessageToIdleRule()
899
938
  ]);
900
939
  const stateExecutor = new LoopStateExecutor(
901
- new MessageReceivedState(),
940
+ new ContextPreparationState(),
902
941
  new InferenceState(inferenceRunner),
942
+ new InferenceStreamingState(inferenceRunner),
903
943
  new FunctionCallState(functionCallRunner),
904
944
  new ModelMessageState()
905
945
  );
@@ -1070,7 +1110,14 @@ var import_sdk = __toESM(require("@anthropic-ai/sdk"));
1070
1110
  var AnthropicMessages = class {
1071
1111
  constructor(endpointMapper = new AnthropicMessagesMapper(), config = {}) {
1072
1112
  this.endpointMapper = endpointMapper;
1073
- this.client = new import_sdk.default({ baseURL: config.baseURL, apiKey: config.apiKey });
1113
+ this.clientConfig = config;
1114
+ }
1115
+ get client() {
1116
+ var _a;
1117
+ return (_a = this._client) != null ? _a : this._client = new import_sdk.default({
1118
+ baseURL: this.clientConfig.baseURL,
1119
+ apiKey: this.clientConfig.apiKey
1120
+ });
1074
1121
  }
1075
1122
  async infer(inferenceInput) {
1076
1123
  const request = this.endpointMapper.toRequest(inferenceInput);
@@ -1079,10 +1126,17 @@ var AnthropicMessages = class {
1079
1126
  }
1080
1127
  async *stream(inferenceInput) {
1081
1128
  const request = this.endpointMapper.toRequest(inferenceInput);
1082
- const stream = await this.client.messages.create(request);
1129
+ const stream = this.client.messages.stream(request);
1083
1130
  for await (const event of stream) {
1084
1131
  yield event;
1085
1132
  }
1133
+ const output = this.endpointMapper.toResponse(await stream.finalMessage());
1134
+ yield {
1135
+ type: "inference.output",
1136
+ producerId: request.model,
1137
+ occurredAt: /* @__PURE__ */ new Date(),
1138
+ payload: output
1139
+ };
1086
1140
  }
1087
1141
  };
1088
1142
 
@@ -1244,7 +1298,10 @@ var OpenAIResponsesMapper = class {
1244
1298
  var OpenAIResponses = class {
1245
1299
  constructor(endpointMapper = new OpenAIResponsesMapper()) {
1246
1300
  this.endpointMapper = endpointMapper;
1247
- this.client = new import_openai.default();
1301
+ }
1302
+ get client() {
1303
+ var _a;
1304
+ return (_a = this._client) != null ? _a : this._client = new import_openai.default();
1248
1305
  }
1249
1306
  async infer(inferenceInput) {
1250
1307
  const request = this.endpointMapper.toRequest(inferenceInput);
@@ -1253,10 +1310,24 @@ var OpenAIResponses = class {
1253
1310
  }
1254
1311
  async *stream(inferenceInput) {
1255
1312
  const request = this.endpointMapper.toRequest(inferenceInput);
1256
- const response = await this.client.responses.create(request);
1257
- for await (const event of response) {
1313
+ const stream = await this.client.responses.create({ ...request, stream: true });
1314
+ let completedResponse = void 0;
1315
+ for await (const event of stream) {
1316
+ if (event.type === "response.completed") {
1317
+ completedResponse = event.response;
1318
+ }
1258
1319
  yield event;
1259
1320
  }
1321
+ if (!completedResponse) {
1322
+ throw new Error("Stream ended without a completed response");
1323
+ }
1324
+ const output = this.endpointMapper.toResponse(completedResponse);
1325
+ yield {
1326
+ type: "inference.output",
1327
+ payload: output,
1328
+ occurredAt: /* @__PURE__ */ new Date(),
1329
+ producerId: inferenceInput.model
1330
+ };
1260
1331
  }
1261
1332
  };
1262
1333
 
@@ -1413,11 +1484,14 @@ var GeminiGenerateContentMapper = class {
1413
1484
  // src/infrastructure/providers/gemini/endpoints/gemini-generate-content.ts
1414
1485
  var GeminiGenerateContent = class {
1415
1486
  constructor(endpointMapper = new GeminiGenerateContentMapper(), config = {}) {
1416
- var _a;
1417
1487
  this.endpointMapper = endpointMapper;
1418
- this.client = new import_genai.GoogleGenAI({
1419
- apiKey: (_a = config.apiKey) != null ? _a : process.env.GEMINI_API_KEY,
1420
- ...config.baseURL ? { httpOptions: { baseUrl: config.baseURL } } : {}
1488
+ this.clientConfig = config;
1489
+ }
1490
+ get client() {
1491
+ var _a, _b;
1492
+ return (_b = this._client) != null ? _b : this._client = new import_genai.GoogleGenAI({
1493
+ apiKey: (_a = this.clientConfig.apiKey) != null ? _a : process.env.GEMINI_API_KEY,
1494
+ ...this.clientConfig.baseURL ? { httpOptions: { baseUrl: this.clientConfig.baseURL } } : {}
1421
1495
  });
1422
1496
  }
1423
1497
  async infer(inferenceInput) {
@@ -1428,9 +1502,21 @@ var GeminiGenerateContent = class {
1428
1502
  async *stream(inferenceInput) {
1429
1503
  const request = this.endpointMapper.toRequest(inferenceInput);
1430
1504
  const stream = await this.client.models.generateContentStream(request);
1505
+ let lastEvent = void 0;
1431
1506
  for await (const chunk of stream) {
1507
+ lastEvent = chunk;
1432
1508
  yield chunk;
1433
1509
  }
1510
+ if (!lastEvent) {
1511
+ throw new Error("Last event not found");
1512
+ }
1513
+ const output = this.endpointMapper.toResponse(lastEvent);
1514
+ yield {
1515
+ type: "inference.output",
1516
+ producerId: request.model,
1517
+ occurredAt: /* @__PURE__ */ new Date(),
1518
+ payload: output
1519
+ };
1434
1520
  }
1435
1521
  };
1436
1522
 
@@ -1547,12 +1633,16 @@ var OpenAIChatCompletions = class {
1547
1633
  constructor(endpointMapper = new OpenAIChatCompletionsMapper(), config = {}) {
1548
1634
  var _a;
1549
1635
  this.endpointMapper = endpointMapper;
1550
- this.client = new import_openai2.default({
1551
- baseURL: config.baseURL,
1552
- apiKey: config.apiKey
1553
- });
1636
+ this.clientConfig = config;
1554
1637
  this.extraBody = (_a = config.extraBody) != null ? _a : {};
1555
1638
  }
1639
+ get client() {
1640
+ var _a;
1641
+ return (_a = this._client) != null ? _a : this._client = new import_openai2.default({
1642
+ baseURL: this.clientConfig.baseURL,
1643
+ apiKey: this.clientConfig.apiKey
1644
+ });
1645
+ }
1556
1646
  buildRequest(inferenceInput) {
1557
1647
  return {
1558
1648
  ...this.extraBody,
@@ -1564,10 +1654,17 @@ var OpenAIChatCompletions = class {
1564
1654
  return this.endpointMapper.toResponse(response);
1565
1655
  }
1566
1656
  async *stream(inferenceInput) {
1567
- const stream = await this.client.chat.completions.create(this.buildRequest(inferenceInput));
1568
- for await (const event of stream) {
1569
- yield event;
1657
+ const stream = this.client.chat.completions.stream(this.buildRequest(inferenceInput));
1658
+ for await (const chunk of stream) {
1659
+ yield chunk;
1570
1660
  }
1661
+ const output = this.endpointMapper.toResponse(await stream.finalChatCompletion());
1662
+ yield {
1663
+ type: "inference.output",
1664
+ payload: output,
1665
+ occurredAt: /* @__PURE__ */ new Date(),
1666
+ producerId: inferenceInput.model
1667
+ };
1571
1668
  }
1572
1669
  };
1573
1670
 
@@ -1991,13 +2088,13 @@ var DefaultInferenceRunner = class {
1991
2088
  this.requestValidator.validate(input, generativeModel.specification);
1992
2089
  return await generativeModel.endpoint.infer(input);
1993
2090
  }
1994
- async streamInference(input) {
2091
+ async *stream(input) {
1995
2092
  const generativeModel = this.supportedModels.find((model) => model.specification.name === input.model);
1996
2093
  if (!generativeModel) {
1997
2094
  throw new Error(`Unsupported model: ${input.model}`);
1998
2095
  }
1999
2096
  this.requestValidator.validate(input, generativeModel.specification);
2000
- return await generativeModel.endpoint.stream(input);
2097
+ yield* generativeModel.endpoint.stream(input);
2001
2098
  }
2002
2099
  };
2003
2100
 
@@ -2074,14 +2171,58 @@ function defineRuntime() {
2074
2171
  runLoop
2075
2172
  };
2076
2173
  }
2174
+
2175
+ // src/domain/agentic-environment/situation/situation-specification.ts
2176
+ var SituationSpecification = class {
2177
+ and(other) {
2178
+ return new AndSituationSpecification(this, other);
2179
+ }
2180
+ or(other) {
2181
+ return new OrSituationSpecification(this, other);
2182
+ }
2183
+ not() {
2184
+ return new NotSituationSpecification(this);
2185
+ }
2186
+ };
2187
+ var AndSituationSpecification = class extends SituationSpecification {
2188
+ constructor(left, right) {
2189
+ super();
2190
+ this.left = left;
2191
+ this.right = right;
2192
+ }
2193
+ isSatisfiedBy(situationContext) {
2194
+ return this.left.isSatisfiedBy(situationContext) && this.right.isSatisfiedBy(situationContext);
2195
+ }
2196
+ };
2197
+ var OrSituationSpecification = class extends SituationSpecification {
2198
+ constructor(left, right) {
2199
+ super();
2200
+ this.left = left;
2201
+ this.right = right;
2202
+ }
2203
+ isSatisfiedBy(situationContext) {
2204
+ return this.left.isSatisfiedBy(situationContext) || this.right.isSatisfiedBy(situationContext);
2205
+ }
2206
+ };
2207
+ var NotSituationSpecification = class extends SituationSpecification {
2208
+ constructor(rule) {
2209
+ super();
2210
+ this.rule = rule;
2211
+ }
2212
+ isSatisfiedBy(situationContext) {
2213
+ return !this.rule.isSatisfiedBy(situationContext);
2214
+ }
2215
+ };
2077
2216
  // Annotate the CommonJS export names for ESM import in node:
2078
2217
  0 && (module.exports = {
2218
+ Agent,
2079
2219
  AnthropicMessages,
2080
2220
  ContextItem,
2081
2221
  DeveloperMessageItem,
2082
2222
  FunctionCallItem,
2083
2223
  FunctionCallOutputItem,
2084
2224
  GeminiGenerateContent,
2225
+ Human,
2085
2226
  InputTokenDetails,
2086
2227
  McpClient,
2087
2228
  McpToolRegistry,
@@ -2094,6 +2235,7 @@ function defineRuntime() {
2094
2235
  ReasoningItem,
2095
2236
  RuntimeState,
2096
2237
  SemanticEvent,
2238
+ SituationSpecification,
2097
2239
  SystemMessageItem,
2098
2240
  TokenUsage,
2099
2241
  UserMessageItem,