@mozaik-ai/core 3.9.5 → 3.10.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.js CHANGED
@@ -30,10 +30,11 @@ 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
  AgenticEnvironment: () => AgenticEnvironment,
34
- BaseAgentParticipant: () => BaseAgentParticipant,
35
- BaseHumanParticipant: () => BaseHumanParticipant,
36
- BaseObserverParticipant: () => BaseObserverParticipant,
35
+ BaseAgent: () => BaseAgent,
36
+ BaseHuman: () => BaseHuman,
37
+ BaseObserver: () => BaseObserver,
37
38
  ContextItem: () => ContextItem,
38
39
  DefaultFunctionCallRunner: () => DefaultFunctionCallRunner,
39
40
  DeveloperMessageItem: () => DeveloperMessageItem,
@@ -43,14 +44,13 @@ __export(index_exports, {
43
44
  Gpt54Mini: () => Gpt54Mini,
44
45
  Gpt54Nano: () => Gpt54Nano,
45
46
  Gpt55: () => Gpt55,
47
+ Human: () => Human,
46
48
  InMemoryModelContextRepository: () => InMemoryModelContextRepository,
47
- InferenceRequest: () => InferenceRequest,
48
- InferenceResponse: () => InferenceResponse,
49
49
  InputTokenDetails: () => InputTokenDetails,
50
50
  ModelContext: () => ModelContext,
51
51
  ModelMessageItem: () => ModelMessageItem,
52
+ Observer: () => Observer,
52
53
  OpenAIInferenceRunner: () => OpenAIInferenceRunner,
53
- OpenAIResponses: () => OpenAIResponses,
54
54
  OutputTokenDetails: () => OutputTokenDetails,
55
55
  Participant: () => Participant,
56
56
  ReasoningItem: () => ReasoningItem,
@@ -296,110 +296,6 @@ var FunctionCallOutputItem = class _FunctionCallOutputItem extends ContextItem {
296
296
  }
297
297
  };
298
298
 
299
- // src/domain/generative-model/inference-response.ts
300
- var InferenceResponse = class {
301
- constructor(contextItems, tokenUsage) {
302
- this.contextItems = contextItems;
303
- this.tokenUsage = tokenUsage;
304
- }
305
- };
306
-
307
- // src/domain/generative-model/token-usage.ts
308
- var InputTokenDetails = class {
309
- constructor(cached_tokens) {
310
- this.cached_tokens = cached_tokens;
311
- }
312
- };
313
- var OutputTokenDetails = class {
314
- constructor(reasoning_tokens) {
315
- this.reasoning_tokens = reasoning_tokens;
316
- }
317
- };
318
- var TokenUsage = class {
319
- constructor(inputTokens, outputTokens, totalTokens, inputTokenDetails, outputTokenDetails) {
320
- this.inputTokens = inputTokens;
321
- this.outputTokens = outputTokens;
322
- this.totalTokens = totalTokens;
323
- this.inputTokenDetails = inputTokenDetails;
324
- this.outputTokenDetails = outputTokenDetails;
325
- }
326
- };
327
-
328
- // src/infrastructure/providers/openai/runtime/openai-responses.ts
329
- var import_openai = __toESM(require("openai"));
330
- var OpenAIResponses = class {
331
- constructor() {
332
- this.client = new import_openai.default();
333
- }
334
- async infer(inferenceRequest) {
335
- const input = this.mapContextToRequest(inferenceRequest.context);
336
- const specification = inferenceRequest.model.specification;
337
- let request = {
338
- model: specification.name,
339
- input
340
- };
341
- if (specification.supportFunctionCalling && inferenceRequest.model.getTools().length > 0) {
342
- request.tools = inferenceRequest.model.getTools().map((tool) => {
343
- return {
344
- type: tool.type,
345
- name: tool.name,
346
- description: tool.description,
347
- parameters: tool.parameters
348
- };
349
- });
350
- }
351
- if (specification.supportReasoningEffort) {
352
- request.reasoning = {
353
- effort: inferenceRequest.model.getReasoningEffort()
354
- };
355
- }
356
- const response = await this.client.responses.create(request);
357
- const contextItems = this.extractContextItems(response);
358
- const tokenUsage = this.extractTokenUsage(response);
359
- return new InferenceResponse(contextItems, tokenUsage);
360
- }
361
- extractTokenUsage(response) {
362
- if (!response.usage) {
363
- return void 0;
364
- }
365
- return new TokenUsage(
366
- response.usage.input_tokens,
367
- response.usage.output_tokens,
368
- response.usage.total_tokens,
369
- new InputTokenDetails(response.usage.input_tokens_details.cached_tokens),
370
- new OutputTokenDetails(response.usage.output_tokens_details.reasoning_tokens)
371
- );
372
- }
373
- mapContextToRequest(context) {
374
- return context.getItems().map((item) => item.toJSON());
375
- }
376
- extractContextItems(response) {
377
- return response.output.map((item) => {
378
- if (item.type === "message" && item.role === "assistant") {
379
- return ModelMessageItem.rehydrate(item.content[0]);
380
- }
381
- if (item.type === "function_call") {
382
- return FunctionCallItem.rehydrate({
383
- callId: item.call_id,
384
- name: item.name,
385
- args: item.arguments
386
- });
387
- }
388
- if (item.type === "reasoning") {
389
- return ReasoningItem.rehydrate(item);
390
- }
391
- });
392
- }
393
- };
394
-
395
- // src/domain/generative-model/inference-request.ts
396
- var InferenceRequest = class {
397
- constructor(model, context) {
398
- this.model = model;
399
- this.context = context;
400
- }
401
- };
402
-
403
299
  // src/infrastructure/providers/openai/reasoning-effort.ts
404
300
  var OpenAIReasoningEffort = class {
405
301
  constructor(reasoningEffort) {
@@ -432,6 +328,13 @@ var Gpt54Nano = class {
432
328
  this.effort = new OpenAIReasoningEffort(
433
329
  this.specification.defaultReasoningEffort
434
330
  );
331
+ this.streaming = false;
332
+ }
333
+ setStreaming(streaming) {
334
+ this.streaming = streaming;
335
+ }
336
+ getStreaming() {
337
+ return this.streaming;
435
338
  }
436
339
  setTools(tools) {
437
340
  this.tools = tools;
@@ -460,10 +363,17 @@ var Gpt54 = class {
460
363
  supportFunctionCalling: true
461
364
  };
462
365
  this.tools = [];
366
+ this.streaming = false;
463
367
  this.effort = new OpenAIReasoningEffort(
464
368
  this.specification.defaultReasoningEffort
465
369
  );
466
370
  }
371
+ setStreaming(streaming) {
372
+ this.streaming = streaming;
373
+ }
374
+ getStreaming() {
375
+ return this.streaming;
376
+ }
467
377
  setTools(tools) {
468
378
  this.tools = tools;
469
379
  }
@@ -494,6 +404,13 @@ var Gpt54Mini = class {
494
404
  this.effort = new OpenAIReasoningEffort(
495
405
  this.specification.defaultReasoningEffort
496
406
  );
407
+ this.streaming = false;
408
+ }
409
+ setStreaming(streaming) {
410
+ this.streaming = streaming;
411
+ }
412
+ getStreaming() {
413
+ return this.streaming;
497
414
  }
498
415
  setReasoningEffort(effort) {
499
416
  this.effort.setReasoningEffort(effort);
@@ -509,6 +426,27 @@ var Gpt54Mini = class {
509
426
  }
510
427
  };
511
428
 
429
+ // src/domain/generative-model/token-usage.ts
430
+ var InputTokenDetails = class {
431
+ constructor(cached_tokens) {
432
+ this.cached_tokens = cached_tokens;
433
+ }
434
+ };
435
+ var OutputTokenDetails = class {
436
+ constructor(reasoning_tokens) {
437
+ this.reasoning_tokens = reasoning_tokens;
438
+ }
439
+ };
440
+ var TokenUsage = class {
441
+ constructor(inputTokens, outputTokens, totalTokens, inputTokenDetails, outputTokenDetails) {
442
+ this.inputTokens = inputTokens;
443
+ this.outputTokens = outputTokens;
444
+ this.totalTokens = totalTokens;
445
+ this.inputTokenDetails = inputTokenDetails;
446
+ this.outputTokenDetails = outputTokenDetails;
447
+ }
448
+ };
449
+
512
450
  // src/infrastructure/repository/in-memory-model-context-repository.ts
513
451
  var InMemoryModelContextRepository = class {
514
452
  constructor() {
@@ -576,7 +514,7 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
576
514
  }
577
515
  };
578
516
 
579
- // src/domain/agentic-environment/participant.ts
517
+ // src/domain/agentic-environment/participants/participant.ts
580
518
  var Participant = class {
581
519
  constructor() {
582
520
  this.environments = [];
@@ -671,6 +609,15 @@ var AgenticEnvironment = class {
671
609
  subscriber.onMessage(message);
672
610
  }
673
611
  }
612
+ deliverSemanticEvent(source, item) {
613
+ for (const subscriber of this.subscribers) {
614
+ if (subscriber === source) {
615
+ subscriber.onInternalEvent(item);
616
+ } else {
617
+ subscriber.onExternalEvent(source, item);
618
+ }
619
+ }
620
+ }
674
621
  async start() {
675
622
  this.isActive = true;
676
623
  while (this.isActive) {
@@ -682,11 +629,25 @@ var AgenticEnvironment = class {
682
629
  }
683
630
  };
684
631
 
685
- // src/application/agent.ts
686
- var BaseAgentParticipant = class extends Participant {
687
- constructor(inputSource, inferenceRunner, functionCallRunner) {
632
+ // src/domain/agentic-environment/participants/agent.ts
633
+ var Agent = class extends Participant {
634
+ };
635
+
636
+ // src/domain/model-context/semantic-event/semantic-event.ts
637
+ var SemanticEvent = class {
638
+ constructor(type, data) {
639
+ this.type = type;
640
+ this.data = data;
641
+ }
642
+ getType() {
643
+ return this.type;
644
+ }
645
+ };
646
+
647
+ // src/application/participants/agent.ts
648
+ var BaseAgent = class extends Agent {
649
+ constructor(inferenceRunner, functionCallRunner) {
688
650
  super();
689
- this.inputSource = inputSource;
690
651
  this.inferenceRunner = inferenceRunner;
691
652
  this.functionCallRunner = functionCallRunner;
692
653
  }
@@ -716,41 +677,44 @@ var BaseAgentParticipant = class extends Participant {
716
677
  }
717
678
  onMessage(message) {
718
679
  }
680
+ onInternalEvent(item) {
681
+ }
682
+ onExternalEvent(source, item) {
683
+ }
719
684
  async executeFunctionCall(environment, functionCallItem, signal) {
720
685
  if (!this.isJoinedTo(environment)) return;
721
686
  const stream = this.functionCallRunner.run(functionCallItem, signal);
722
687
  for await (const item of stream) {
723
- await environment.deliverFunctionCallOutput(this, item);
688
+ environment.deliverFunctionCallOutput(this, item);
724
689
  }
725
690
  }
726
691
  async runInference(environment, context, model, signal) {
727
692
  if (!this.isJoinedTo(environment)) return;
728
693
  const stream = this.inferenceRunner.run(context, model, signal);
729
694
  for await (const item of stream) {
730
- if (item.type === "reasoning") {
731
- await environment.deliverReasoning(this, item);
732
- } else if (item.type === "function_call") {
733
- await environment.deliverFunctionCall(this, item);
734
- } else if (item.type === "message" && item.role === "assistant") {
735
- await environment.deliverModelMessage(this, item);
695
+ if (item instanceof ReasoningItem) {
696
+ environment.deliverReasoning(this, item);
697
+ } else if (item instanceof FunctionCallItem) {
698
+ environment.deliverFunctionCall(this, item);
699
+ } else if (item instanceof ModelMessageItem) {
700
+ environment.deliverModelMessage(this, item);
701
+ } else if (item instanceof SemanticEvent) {
702
+ environment.deliverSemanticEvent(this, item);
736
703
  }
737
704
  }
738
705
  }
739
- async streamInput(environment) {
740
- if (!this.isJoinedTo(environment)) return;
741
- const stream = this.inputSource.stream();
742
- for await (const message of stream) {
743
- await environment.deliverMessage(this, message);
744
- }
745
- }
746
706
  };
747
707
 
748
- // src/application/human.ts
749
- var BaseHumanParticipant = class extends Participant {
750
- constructor(inputSource) {
751
- super();
752
- this.inputSource = inputSource;
708
+ // src/domain/agentic-environment/participants/human.ts
709
+ var Human = class extends Participant {
710
+ sendMessage(environment, message) {
711
+ if (!this.isJoinedTo(environment)) throw new Error("Not joined to environment");
712
+ environment.deliverMessage(this, message);
753
713
  }
714
+ };
715
+
716
+ // src/application/participants/human.ts
717
+ var BaseHuman = class extends Human {
754
718
  onJoined() {
755
719
  }
756
720
  onLeft() {
@@ -777,29 +741,96 @@ var BaseHumanParticipant = class extends Participant {
777
741
  }
778
742
  onExternalModelMessage(source, item) {
779
743
  }
780
- async streamInput(environment) {
781
- if (!this.isJoinedTo(environment)) return;
782
- const stream = this.inputSource.stream();
783
- for await (const message of stream) {
784
- await environment.deliverMessage(this, message);
785
- }
744
+ onInternalEvent(item) {
745
+ }
746
+ onExternalEvent(source, item) {
786
747
  }
787
748
  };
788
749
 
789
- // src/application/openai-inference-runner.ts
750
+ // src/application/runners/openai-inference-runner.ts
751
+ var import_openai = __toESM(require("openai"));
790
752
  var OpenAIInferenceRunner = class {
791
- constructor() {
792
- this.runtime = new OpenAIResponses();
793
- }
794
753
  async *run(context, model, signal) {
795
- const response = await this.runtime.infer(new InferenceRequest(model, context));
796
- for (const item of response.contextItems) {
797
- yield item;
754
+ const input = this.mapContextToRequest(context);
755
+ const specification = model.specification;
756
+ let request = {
757
+ model: specification.name,
758
+ input,
759
+ stream: model.getStreaming()
760
+ };
761
+ if (specification.supportFunctionCalling && model.getTools().length > 0) {
762
+ request.tools = model.getTools().map((tool) => {
763
+ return {
764
+ type: tool.type,
765
+ name: tool.name,
766
+ description: tool.description,
767
+ parameters: tool.parameters
768
+ };
769
+ });
770
+ }
771
+ if (specification.supportReasoningEffort) {
772
+ request.reasoning = {
773
+ effort: model.getReasoningEffort()
774
+ };
775
+ }
776
+ if (!specification.supportStreaming && model.getStreaming()) {
777
+ throw new Error("Streaming is not supported for this model");
778
+ }
779
+ const openai = new import_openai.default();
780
+ const response = await openai.responses.create(request);
781
+ if (specification.supportStreaming && model.getStreaming()) {
782
+ for await (const event of response) {
783
+ if (signal == null ? void 0 : signal.aborted) {
784
+ break;
785
+ }
786
+ yield new SemanticEvent(event.type, event);
787
+ }
788
+ } else {
789
+ const contextItems = this.extractContextItems(response);
790
+ const tokenUsage = this.extractTokenUsage(response);
791
+ for (const item of contextItems) {
792
+ if (signal == null ? void 0 : signal.aborted) {
793
+ break;
794
+ }
795
+ yield item;
796
+ }
797
+ }
798
+ }
799
+ extractTokenUsage(response) {
800
+ if (!response.usage) {
801
+ return void 0;
798
802
  }
803
+ return new TokenUsage(
804
+ response.usage.input_tokens,
805
+ response.usage.output_tokens,
806
+ response.usage.total_tokens,
807
+ new InputTokenDetails(response.usage.input_tokens_details.cached_tokens),
808
+ new OutputTokenDetails(response.usage.output_tokens_details.reasoning_tokens)
809
+ );
810
+ }
811
+ mapContextToRequest(context) {
812
+ return context.getItems().map((item) => item.toJSON());
813
+ }
814
+ extractContextItems(response) {
815
+ return response.output.map((item) => {
816
+ if (item.type === "message" && item.role === "assistant") {
817
+ return ModelMessageItem.rehydrate(item.content[0]);
818
+ }
819
+ if (item.type === "function_call") {
820
+ return FunctionCallItem.rehydrate({
821
+ callId: item.call_id,
822
+ name: item.name,
823
+ args: item.arguments
824
+ });
825
+ }
826
+ if (item.type === "reasoning") {
827
+ return ReasoningItem.rehydrate(item);
828
+ }
829
+ });
799
830
  }
800
831
  };
801
832
 
802
- // src/application/function-call-runner.ts
833
+ // src/application/runners/function-call-runner.ts
803
834
  var DefaultFunctionCallRunner = class {
804
835
  constructor(tools) {
805
836
  this.tools = tools;
@@ -825,10 +856,17 @@ var Gpt55 = class {
825
856
  supportFunctionCalling: true
826
857
  };
827
858
  this.tools = [];
859
+ this.streaming = false;
828
860
  this.effort = new OpenAIReasoningEffort(
829
861
  this.specification.defaultReasoningEffort
830
862
  );
831
863
  }
864
+ setStreaming(streaming) {
865
+ this.streaming = streaming;
866
+ }
867
+ getStreaming() {
868
+ return this.streaming;
869
+ }
832
870
  setTools(tools) {
833
871
  this.tools = tools;
834
872
  }
@@ -843,8 +881,12 @@ var Gpt55 = class {
843
881
  }
844
882
  };
845
883
 
846
- // src/application/observer.ts
847
- var BaseObserverParticipant = class extends Participant {
884
+ // src/domain/agentic-environment/participants/observer.ts
885
+ var Observer = class extends Participant {
886
+ };
887
+
888
+ // src/application/participants/observer.ts
889
+ var BaseObserver = class extends Observer {
848
890
  onFunctionCall(item) {
849
891
  }
850
892
  onExternalFunctionCall(source, item) {
@@ -871,13 +913,18 @@ var BaseObserverParticipant = class extends Participant {
871
913
  }
872
914
  onParticipantLeft(participant) {
873
915
  }
916
+ onInternalEvent(item) {
917
+ }
918
+ onExternalEvent(source, item) {
919
+ }
874
920
  };
875
921
  // Annotate the CommonJS export names for ESM import in node:
876
922
  0 && (module.exports = {
923
+ Agent,
877
924
  AgenticEnvironment,
878
- BaseAgentParticipant,
879
- BaseHumanParticipant,
880
- BaseObserverParticipant,
925
+ BaseAgent,
926
+ BaseHuman,
927
+ BaseObserver,
881
928
  ContextItem,
882
929
  DefaultFunctionCallRunner,
883
930
  DeveloperMessageItem,
@@ -887,14 +934,13 @@ var BaseObserverParticipant = class extends Participant {
887
934
  Gpt54Mini,
888
935
  Gpt54Nano,
889
936
  Gpt55,
937
+ Human,
890
938
  InMemoryModelContextRepository,
891
- InferenceRequest,
892
- InferenceResponse,
893
939
  InputTokenDetails,
894
940
  ModelContext,
895
941
  ModelMessageItem,
942
+ Observer,
896
943
  OpenAIInferenceRunner,
897
- OpenAIResponses,
898
944
  OutputTokenDetails,
899
945
  Participant,
900
946
  ReasoningItem,