@mozaik-ai/core 4.0.0-beta.6 → 4.0.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -4
- package/dist/index.d.mts +111 -41
- package/dist/index.d.ts +111 -41
- package/dist/index.js +68 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -314,6 +314,16 @@ var SemanticEvent = class _SemanticEvent {
|
|
|
314
314
|
return new _SemanticEvent(type, producerId, occurredAt, payload);
|
|
315
315
|
}
|
|
316
316
|
};
|
|
317
|
+
var ParticipantJoinedEvent = class extends SemanticEvent {
|
|
318
|
+
static init(manifest) {
|
|
319
|
+
return SemanticEvent.create("participant.joined", manifest.id, manifest);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
var ParticipantLeftEvent = class extends SemanticEvent {
|
|
323
|
+
static init(manifest) {
|
|
324
|
+
return SemanticEvent.create("participant.left", manifest.id, manifest);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
317
327
|
var MessageSentEvent = class extends SemanticEvent {
|
|
318
328
|
static init(producerId, message) {
|
|
319
329
|
return SemanticEvent.create("message.sent", producerId, { message });
|
|
@@ -472,9 +482,11 @@ var RuntimeService = class {
|
|
|
472
482
|
}
|
|
473
483
|
join(participant) {
|
|
474
484
|
this.state.addParticipant(participant);
|
|
485
|
+
this.publish(ParticipantJoinedEvent.init(participant.getManifest()));
|
|
475
486
|
}
|
|
476
487
|
leave(participant) {
|
|
477
488
|
this.state.removeParticipant(participant);
|
|
489
|
+
this.publish(ParticipantLeftEvent.init(participant.getManifest()));
|
|
478
490
|
}
|
|
479
491
|
publish(event) {
|
|
480
492
|
for (const participant of this.state.getParticipants()) {
|
|
@@ -538,28 +550,43 @@ function createSendMessage(resolveRuntime) {
|
|
|
538
550
|
}
|
|
539
551
|
|
|
540
552
|
// src/domain/agentic-environment/loop/agent-loop.ts
|
|
541
|
-
var AgentLoop = class {
|
|
542
|
-
constructor(stateExecutor, transitionResolver,
|
|
553
|
+
var AgentLoop = class _AgentLoop {
|
|
554
|
+
constructor(loopId, stateExecutor, transitionResolver, interceptionHandler) {
|
|
555
|
+
this.loopId = loopId;
|
|
543
556
|
this.stateExecutor = stateExecutor;
|
|
544
557
|
this.transitionResolver = transitionResolver;
|
|
545
|
-
this.
|
|
558
|
+
this.interceptionHandler = interceptionHandler;
|
|
546
559
|
}
|
|
547
|
-
async run(message) {
|
|
560
|
+
async run(message, loopVisitor) {
|
|
548
561
|
let transition = {
|
|
549
|
-
nextStateId: "
|
|
562
|
+
nextStateId: "context_update",
|
|
550
563
|
input: message
|
|
551
564
|
};
|
|
552
565
|
while (transition.nextStateId !== "idle") {
|
|
553
|
-
const
|
|
554
|
-
|
|
566
|
+
const isInterceptionSatisfied = this.interceptionHandler.isSatisfiedBy(transition);
|
|
567
|
+
if (isInterceptionSatisfied) {
|
|
568
|
+
loopVisitor.visitInterceptionStarted(transition);
|
|
569
|
+
transition = await this.interceptionHandler.handle(transition);
|
|
570
|
+
loopVisitor.visitInterceptionFinished(transition);
|
|
571
|
+
} else {
|
|
572
|
+
const execution = await this.stateExecutor.execute(transition, loopVisitor);
|
|
573
|
+
transition = this.transitionResolver.resolve(execution);
|
|
574
|
+
}
|
|
555
575
|
}
|
|
556
576
|
}
|
|
577
|
+
getLoopId() {
|
|
578
|
+
return this.loopId;
|
|
579
|
+
}
|
|
580
|
+
static create(stateExecutor, transitionResolver, interceptionHandler) {
|
|
581
|
+
const loopId = crypto.randomUUID();
|
|
582
|
+
return new _AgentLoop(loopId, stateExecutor, transitionResolver, interceptionHandler);
|
|
583
|
+
}
|
|
557
584
|
};
|
|
558
585
|
|
|
559
586
|
// src/domain/agentic-environment/loop/state-executor.ts
|
|
560
587
|
var LoopStateExecutor = class {
|
|
561
|
-
constructor(
|
|
562
|
-
this.
|
|
588
|
+
constructor(contextUpdateState, inferenceState, inferenceStreamingState, functionCallState, modelMessageState) {
|
|
589
|
+
this.contextUpdateState = contextUpdateState;
|
|
563
590
|
this.inferenceState = inferenceState;
|
|
564
591
|
this.inferenceStreamingState = inferenceStreamingState;
|
|
565
592
|
this.functionCallState = functionCallState;
|
|
@@ -567,8 +594,8 @@ var LoopStateExecutor = class {
|
|
|
567
594
|
}
|
|
568
595
|
async execute(transition, loopVisitor) {
|
|
569
596
|
switch (transition.nextStateId) {
|
|
570
|
-
case "
|
|
571
|
-
return await this.
|
|
597
|
+
case "context_update":
|
|
598
|
+
return await this.contextUpdateState.run(transition.input, loopVisitor);
|
|
572
599
|
case "inference":
|
|
573
600
|
return await this.inferenceState.run(transition.input, loopVisitor);
|
|
574
601
|
case "inference_streaming":
|
|
@@ -613,19 +640,19 @@ var FunctionCallState = class {
|
|
|
613
640
|
}
|
|
614
641
|
};
|
|
615
642
|
|
|
616
|
-
// src/application/states/context-
|
|
617
|
-
var
|
|
643
|
+
// src/application/states/context-update.ts
|
|
644
|
+
var ContextUpdateState = class {
|
|
618
645
|
constructor() {
|
|
619
|
-
this.id = "
|
|
646
|
+
this.id = "context_update";
|
|
620
647
|
}
|
|
621
648
|
async run(input, loopVisitor) {
|
|
622
|
-
loopVisitor.
|
|
649
|
+
loopVisitor.visitContextUpdateStarted(input);
|
|
623
650
|
const userMessage = UserMessageItem.create(input.content);
|
|
624
651
|
const output = {
|
|
625
652
|
...input.input,
|
|
626
653
|
context: input.input.context.addContextItems([userMessage])
|
|
627
654
|
};
|
|
628
|
-
loopVisitor.
|
|
655
|
+
loopVisitor.visitContextUpdateCompleted(output);
|
|
629
656
|
return {
|
|
630
657
|
stateId: this.id,
|
|
631
658
|
input,
|
|
@@ -666,7 +693,7 @@ var TransitionResolver = class {
|
|
|
666
693
|
// src/domain/agentic-environment/loop/transition-specification.ts
|
|
667
694
|
var MessageReceivedSpecification = class {
|
|
668
695
|
isSatisfiedBy(execution) {
|
|
669
|
-
return execution.stateId === "
|
|
696
|
+
return execution.stateId === "context_update";
|
|
670
697
|
}
|
|
671
698
|
};
|
|
672
699
|
function isInferenceExecution(execution) {
|
|
@@ -699,7 +726,7 @@ var ContextPreparationToInferenceRule = class {
|
|
|
699
726
|
this.specification = new MessageReceivedSpecification();
|
|
700
727
|
}
|
|
701
728
|
createTransition(execution) {
|
|
702
|
-
if (execution.stateId !== "
|
|
729
|
+
if (execution.stateId !== "context_update") {
|
|
703
730
|
throw new Error("Expected context_preparation execution");
|
|
704
731
|
}
|
|
705
732
|
const nextStateId = execution.output.streaming ? "inference_streaming" : "inference";
|
|
@@ -787,15 +814,16 @@ var ModelMessageToIdleRule = class {
|
|
|
787
814
|
|
|
788
815
|
// src/domain/agentic-environment/loop/event-publisher-visitor.ts
|
|
789
816
|
var EventPublisherLoopVisitor = class {
|
|
790
|
-
constructor(agentId, runtime) {
|
|
817
|
+
constructor(agentId, loopId, runtime) {
|
|
791
818
|
this.agentId = agentId;
|
|
819
|
+
this.loopId = loopId;
|
|
792
820
|
this.runtime = runtime;
|
|
793
821
|
}
|
|
794
|
-
|
|
795
|
-
this.publish("
|
|
822
|
+
visitContextUpdateStarted(input) {
|
|
823
|
+
this.publish("context_update.started", { ...input, loopId: this.loopId });
|
|
796
824
|
}
|
|
797
|
-
|
|
798
|
-
this.publish("
|
|
825
|
+
visitContextUpdateCompleted(output) {
|
|
826
|
+
this.publish("context_update.completed", { ...output, loopId: this.loopId });
|
|
799
827
|
}
|
|
800
828
|
visitInferenceStarted(input) {
|
|
801
829
|
this.publish("inference.started", input);
|
|
@@ -815,12 +843,18 @@ var EventPublisherLoopVisitor = class {
|
|
|
815
843
|
visitModelAnswer(input) {
|
|
816
844
|
this.publish("model.answer", input);
|
|
817
845
|
}
|
|
846
|
+
visitInterceptionStarted(transition) {
|
|
847
|
+
this.publish("interception.started", transition);
|
|
848
|
+
}
|
|
849
|
+
visitInterceptionFinished(transition) {
|
|
850
|
+
this.publish("interception.finished", transition);
|
|
851
|
+
}
|
|
818
852
|
publish(type, payload) {
|
|
819
853
|
this.runtime.publish({
|
|
820
854
|
type,
|
|
821
855
|
producerId: this.agentId,
|
|
822
856
|
occurredAt: /* @__PURE__ */ new Date(),
|
|
823
|
-
payload
|
|
857
|
+
payload: { ...payload, loopId: this.loopId }
|
|
824
858
|
});
|
|
825
859
|
}
|
|
826
860
|
};
|
|
@@ -854,7 +888,7 @@ var InferenceStreamingState = class {
|
|
|
854
888
|
|
|
855
889
|
// src/application/use-cases/run-loop.ts
|
|
856
890
|
function createRunLoop(resolveRuntime) {
|
|
857
|
-
return function runLoop(agentId, message, inferenceInput) {
|
|
891
|
+
return function runLoop(agentId, message, inferenceInput, interceptionHandler) {
|
|
858
892
|
const runtime = resolveRuntime();
|
|
859
893
|
const inferenceRunner = runtime.getInferenceRunner();
|
|
860
894
|
const functionCallRunner = runtime.getFunctionCallRunner();
|
|
@@ -867,21 +901,21 @@ function createRunLoop(resolveRuntime) {
|
|
|
867
901
|
new ModelMessageToIdleRule()
|
|
868
902
|
]);
|
|
869
903
|
const stateExecutor = new LoopStateExecutor(
|
|
870
|
-
new
|
|
904
|
+
new ContextUpdateState(),
|
|
871
905
|
new InferenceState(inferenceRunner),
|
|
872
906
|
new InferenceStreamingState(inferenceRunner),
|
|
873
907
|
new FunctionCallState(functionCallRunner),
|
|
874
908
|
new ModelMessageState()
|
|
875
909
|
);
|
|
876
|
-
const agentLoop =
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
910
|
+
const agentLoop = AgentLoop.create(stateExecutor, transitionResolver, interceptionHandler);
|
|
911
|
+
const loopVisitor = new EventPublisherLoopVisitor(agentId, agentLoop.getLoopId(), runtime);
|
|
912
|
+
agentLoop.run(
|
|
913
|
+
{
|
|
914
|
+
content: message,
|
|
915
|
+
input: inferenceInput
|
|
916
|
+
},
|
|
917
|
+
loopVisitor
|
|
880
918
|
);
|
|
881
|
-
agentLoop.run({
|
|
882
|
-
content: message,
|
|
883
|
-
input: inferenceInput
|
|
884
|
-
});
|
|
885
919
|
};
|
|
886
920
|
}
|
|
887
921
|
|