@mozaik-ai/core 3.3.1 → 3.3.4
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 +37 -44
- package/dist/index.d.ts +37 -44
- package/dist/index.js +134 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -81
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31,13 +31,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
Agent: () => Agent,
|
|
34
|
-
AgentRuntime: () => AgentRuntime,
|
|
35
34
|
AgentSociety: () => AgentSociety,
|
|
36
35
|
BaseSpecification: () => BaseSpecification,
|
|
37
36
|
ContextItem: () => ContextItem,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
DeveloperMessageItem: () => DeveloperMessageItem,
|
|
38
|
+
FunctionCallItem: () => FunctionCallItem,
|
|
39
|
+
FunctionCallOutputItem: () => FunctionCallOutputItem,
|
|
41
40
|
Gpt54: () => Gpt54,
|
|
42
41
|
Gpt54Mini: () => Gpt54Mini,
|
|
43
42
|
Gpt54Nano: () => Gpt54Nano,
|
|
@@ -48,12 +47,13 @@ __export(index_exports, {
|
|
|
48
47
|
InputTokenDetails: () => InputTokenDetails,
|
|
49
48
|
Loop: () => Loop,
|
|
50
49
|
ModelContext: () => ModelContext,
|
|
51
|
-
|
|
50
|
+
ModelMessageItem: () => ModelMessageItem,
|
|
52
51
|
OpenAIResponses: () => OpenAIResponses,
|
|
53
52
|
OutputTokenDetails: () => OutputTokenDetails,
|
|
54
|
-
|
|
53
|
+
ReasoningItem: () => ReasoningItem,
|
|
54
|
+
SystemMessageItem: () => SystemMessageItem,
|
|
55
55
|
TokenUsage: () => TokenUsage,
|
|
56
|
-
|
|
56
|
+
UserMessageItem: () => UserMessageItem
|
|
57
57
|
});
|
|
58
58
|
module.exports = __toCommonJS(index_exports);
|
|
59
59
|
|
|
@@ -134,7 +134,7 @@ var InputText = class _InputText extends ItemContent {
|
|
|
134
134
|
};
|
|
135
135
|
|
|
136
136
|
// src/domain/model-context/context-item/client-item/user-message.ts
|
|
137
|
-
var
|
|
137
|
+
var UserMessageItem = class _UserMessageItem extends ContextItem {
|
|
138
138
|
constructor(content) {
|
|
139
139
|
super();
|
|
140
140
|
this.type = "message";
|
|
@@ -143,11 +143,11 @@ var UserMessage = class _UserMessage extends ContextItem {
|
|
|
143
143
|
}
|
|
144
144
|
static create(text) {
|
|
145
145
|
const content = InputText.create(text);
|
|
146
|
-
return new
|
|
146
|
+
return new _UserMessageItem(content);
|
|
147
147
|
}
|
|
148
148
|
static rehydrate(data) {
|
|
149
149
|
const content = InputText.rehydrate(data);
|
|
150
|
-
return new
|
|
150
|
+
return new _UserMessageItem(content);
|
|
151
151
|
}
|
|
152
152
|
toJSON() {
|
|
153
153
|
return {
|
|
@@ -159,7 +159,7 @@ var UserMessage = class _UserMessage extends ContextItem {
|
|
|
159
159
|
};
|
|
160
160
|
|
|
161
161
|
// src/domain/model-context/context-item/client-item/developer-message.ts
|
|
162
|
-
var
|
|
162
|
+
var DeveloperMessageItem = class _DeveloperMessageItem extends ContextItem {
|
|
163
163
|
constructor(content) {
|
|
164
164
|
super();
|
|
165
165
|
this.type = "message";
|
|
@@ -175,11 +175,11 @@ var DeveloperMessage = class _DeveloperMessage extends ContextItem {
|
|
|
175
175
|
}
|
|
176
176
|
static create(text) {
|
|
177
177
|
const content = InputText.create(text);
|
|
178
|
-
return new
|
|
178
|
+
return new _DeveloperMessageItem(content);
|
|
179
179
|
}
|
|
180
180
|
static rehydrate(data) {
|
|
181
181
|
const content = InputText.rehydrate(data);
|
|
182
|
-
return new
|
|
182
|
+
return new _DeveloperMessageItem(content);
|
|
183
183
|
}
|
|
184
184
|
};
|
|
185
185
|
|
|
@@ -204,7 +204,7 @@ var OutputText = class _OutputText extends ItemContent {
|
|
|
204
204
|
};
|
|
205
205
|
|
|
206
206
|
// src/domain/model-context/context-item/model-item/model-message.ts
|
|
207
|
-
var
|
|
207
|
+
var ModelMessageItem = class _ModelMessageItem extends ContextItem {
|
|
208
208
|
constructor(content) {
|
|
209
209
|
super();
|
|
210
210
|
this.type = "message";
|
|
@@ -213,7 +213,7 @@ var ModelMessage = class _ModelMessage extends ContextItem {
|
|
|
213
213
|
}
|
|
214
214
|
static rehydrate(data) {
|
|
215
215
|
const content = OutputText.rehydrate(data);
|
|
216
|
-
return new
|
|
216
|
+
return new _ModelMessageItem(content);
|
|
217
217
|
}
|
|
218
218
|
toJSON() {
|
|
219
219
|
return {
|
|
@@ -225,7 +225,7 @@ var ModelMessage = class _ModelMessage extends ContextItem {
|
|
|
225
225
|
};
|
|
226
226
|
|
|
227
227
|
// src/domain/model-context/context-item/model-item/function-call.ts
|
|
228
|
-
var
|
|
228
|
+
var FunctionCallItem = class _FunctionCallItem extends ContextItem {
|
|
229
229
|
constructor(callId, name, args) {
|
|
230
230
|
super();
|
|
231
231
|
this.type = "function_call";
|
|
@@ -234,7 +234,7 @@ var FunctionCall = class _FunctionCall extends ContextItem {
|
|
|
234
234
|
this.args = args;
|
|
235
235
|
}
|
|
236
236
|
static rehydrate(data) {
|
|
237
|
-
return new
|
|
237
|
+
return new _FunctionCallItem(data.callId, data.name, data.args);
|
|
238
238
|
}
|
|
239
239
|
toJSON() {
|
|
240
240
|
return {
|
|
@@ -247,7 +247,7 @@ var FunctionCall = class _FunctionCall extends ContextItem {
|
|
|
247
247
|
};
|
|
248
248
|
|
|
249
249
|
// src/domain/model-context/context-item/model-item/reasoning.ts
|
|
250
|
-
var
|
|
250
|
+
var ReasoningItem = class _ReasoningItem extends ContextItem {
|
|
251
251
|
constructor(content, encryptedContent, summary = []) {
|
|
252
252
|
super();
|
|
253
253
|
this.type = "reasoning";
|
|
@@ -256,7 +256,7 @@ var Reasoning = class _Reasoning extends ContextItem {
|
|
|
256
256
|
this.summary = summary;
|
|
257
257
|
}
|
|
258
258
|
static rehydrate(data) {
|
|
259
|
-
return new
|
|
259
|
+
return new _ReasoningItem(data.content, data.encryptedContent, data.summary);
|
|
260
260
|
}
|
|
261
261
|
toJSON() {
|
|
262
262
|
var _a;
|
|
@@ -270,7 +270,7 @@ var Reasoning = class _Reasoning extends ContextItem {
|
|
|
270
270
|
};
|
|
271
271
|
|
|
272
272
|
// src/domain/model-context/context-item/client-item/function-call-output.ts
|
|
273
|
-
var
|
|
273
|
+
var FunctionCallOutputItem = class _FunctionCallOutputItem extends ContextItem {
|
|
274
274
|
constructor(callId, output) {
|
|
275
275
|
super();
|
|
276
276
|
this.type = "function_call_output";
|
|
@@ -279,10 +279,10 @@ var FunctionCallOutput = class _FunctionCallOutput extends ContextItem {
|
|
|
279
279
|
}
|
|
280
280
|
static create(callId, output) {
|
|
281
281
|
const outputText = InputText.create(output);
|
|
282
|
-
return new
|
|
282
|
+
return new _FunctionCallOutputItem(callId, outputText);
|
|
283
283
|
}
|
|
284
284
|
static rehydrate(data) {
|
|
285
|
-
return new
|
|
285
|
+
return new _FunctionCallOutputItem(data.callId, data.output);
|
|
286
286
|
}
|
|
287
287
|
toJSON() {
|
|
288
288
|
return {
|
|
@@ -373,17 +373,17 @@ var OpenAIResponses = class {
|
|
|
373
373
|
extractContextItems(response) {
|
|
374
374
|
return response.output.map((item) => {
|
|
375
375
|
if (item.type === "message" && item.role === "assistant") {
|
|
376
|
-
return
|
|
376
|
+
return ModelMessageItem.rehydrate(item.content[0]);
|
|
377
377
|
}
|
|
378
378
|
if (item.type === "function_call") {
|
|
379
|
-
return
|
|
379
|
+
return FunctionCallItem.rehydrate({
|
|
380
380
|
callId: item.call_id,
|
|
381
381
|
name: item.name,
|
|
382
382
|
args: item.arguments
|
|
383
383
|
});
|
|
384
384
|
}
|
|
385
385
|
if (item.type === "reasoning") {
|
|
386
|
-
return
|
|
386
|
+
return ReasoningItem.rehydrate(item);
|
|
387
387
|
}
|
|
388
388
|
});
|
|
389
389
|
}
|
|
@@ -674,32 +674,32 @@ var Fail = class {
|
|
|
674
674
|
};
|
|
675
675
|
|
|
676
676
|
// src/domain/model-context/specifications/function-call-requested.ts
|
|
677
|
-
var
|
|
677
|
+
var FunctionCallRequestedSpec = class extends BaseSpecification {
|
|
678
678
|
isSatisfiedBy(context) {
|
|
679
679
|
if (context.getItems().length === 0) {
|
|
680
680
|
return false;
|
|
681
681
|
}
|
|
682
|
-
const lastItem = context.
|
|
683
|
-
return lastItem instanceof
|
|
682
|
+
const lastItem = context.getLastItem();
|
|
683
|
+
return lastItem instanceof FunctionCallItem;
|
|
684
684
|
}
|
|
685
685
|
};
|
|
686
686
|
|
|
687
687
|
// src/domain/model-context/specifications/function-call-output-present.ts
|
|
688
|
-
var
|
|
688
|
+
var FunctionCallOutputPresentSpec = class extends BaseSpecification {
|
|
689
689
|
isSatisfiedBy(context) {
|
|
690
|
-
const lasteItem = context.
|
|
691
|
-
return lasteItem instanceof
|
|
690
|
+
const lasteItem = context.getLastItem();
|
|
691
|
+
return lasteItem instanceof FunctionCallOutputItem;
|
|
692
692
|
}
|
|
693
693
|
};
|
|
694
694
|
|
|
695
|
-
// src/domain/agent-loop/state/function-call.ts
|
|
696
|
-
var
|
|
695
|
+
// src/domain/agent-loop/state/function-call-pending.ts
|
|
696
|
+
var FunctionCallPendingState = class {
|
|
697
697
|
constructor() {
|
|
698
698
|
this.id = "FUNCTION_CALL_PENDING" /* FUNCTION_CALL_PENDING */;
|
|
699
699
|
this.beforeHookId = "BEFORE_FUNCTION_CALL" /* BEFORE_FUNCTION_CALL */;
|
|
700
700
|
this.afterHookId = "AFTER_FUNCTION_CALL" /* AFTER_FUNCTION_CALL */;
|
|
701
|
-
this.functionCallRequestedSpec = new
|
|
702
|
-
this.functionCallOutputPresentSpec = new
|
|
701
|
+
this.functionCallRequestedSpec = new FunctionCallRequestedSpec();
|
|
702
|
+
this.functionCallOutputPresentSpec = new FunctionCallOutputPresentSpec();
|
|
703
703
|
}
|
|
704
704
|
getDetails() {
|
|
705
705
|
return {
|
|
@@ -733,23 +733,23 @@ var Complete = class {
|
|
|
733
733
|
};
|
|
734
734
|
|
|
735
735
|
// src/domain/model-context/specifications/model-responded.ts
|
|
736
|
-
var
|
|
736
|
+
var ModelRespondedSpec = class extends BaseSpecification {
|
|
737
737
|
isSatisfiedBy(context) {
|
|
738
738
|
if (context.getItems().length === 0) {
|
|
739
739
|
return false;
|
|
740
740
|
}
|
|
741
|
-
const lastItem = context.
|
|
742
|
-
return lastItem instanceof
|
|
741
|
+
const lastItem = context.getLastItem();
|
|
742
|
+
return lastItem instanceof ModelMessageItem && lastItem.role === "assistant";
|
|
743
743
|
}
|
|
744
744
|
};
|
|
745
745
|
|
|
746
|
-
// src/domain/agent-loop/state/model-
|
|
747
|
-
var
|
|
746
|
+
// src/domain/agent-loop/state/model-responded.ts
|
|
747
|
+
var ModelRespondedState = class {
|
|
748
748
|
constructor() {
|
|
749
|
-
this.id = "
|
|
750
|
-
this.beforeHookId = "
|
|
751
|
-
this.afterHookId = "
|
|
752
|
-
this.
|
|
749
|
+
this.id = "MODEL_RESPONDED" /* MODEL_RESPONDED */;
|
|
750
|
+
this.beforeHookId = "BEFORE_MODEL_RESPONDED" /* BEFORE_MODEL_RESPONDED */;
|
|
751
|
+
this.afterHookId = "AFTER_MODEL_RESPONDED" /* AFTER_MODEL_RESPONDED */;
|
|
752
|
+
this.modelRespondedSpec = new ModelRespondedSpec();
|
|
753
753
|
}
|
|
754
754
|
getDetails() {
|
|
755
755
|
return {
|
|
@@ -759,12 +759,12 @@ var ModelMessageState = class {
|
|
|
759
759
|
};
|
|
760
760
|
}
|
|
761
761
|
validateEntry(runtime) {
|
|
762
|
-
if (!this.
|
|
762
|
+
if (!this.modelRespondedSpec.isSatisfiedBy(runtime.context)) {
|
|
763
763
|
throw new Error("Model message is not present in the context");
|
|
764
764
|
}
|
|
765
765
|
}
|
|
766
766
|
next(runtime) {
|
|
767
|
-
if (!this.
|
|
767
|
+
if (!this.modelRespondedSpec.isSatisfiedBy(runtime.context)) {
|
|
768
768
|
return new Fail("Model message is not present in the context");
|
|
769
769
|
}
|
|
770
770
|
const lastItem = runtime.context.getLastItem();
|
|
@@ -778,8 +778,8 @@ var InferencePendingState = class {
|
|
|
778
778
|
this.id = "INFERENCE_PENDING" /* INFERENCE_PENDING */;
|
|
779
779
|
this.beforeHookId = "BEFORE_INFERENCE" /* BEFORE_INFERENCE */;
|
|
780
780
|
this.afterHookId = "AFTER_INFERENCE" /* AFTER_INFERENCE */;
|
|
781
|
-
this.functionCallRequested = new
|
|
782
|
-
this.modelResponded = new
|
|
781
|
+
this.functionCallRequested = new FunctionCallRequestedSpec();
|
|
782
|
+
this.modelResponded = new ModelRespondedSpec();
|
|
783
783
|
}
|
|
784
784
|
getDetails() {
|
|
785
785
|
return {
|
|
@@ -794,40 +794,48 @@ var InferencePendingState = class {
|
|
|
794
794
|
if (this.functionCallRequested.isSatisfiedBy(runtime.context)) {
|
|
795
795
|
return new GoTo("FUNCTION_CALL_PENDING" /* FUNCTION_CALL_PENDING */);
|
|
796
796
|
} else if (this.modelResponded.isSatisfiedBy(runtime.context)) {
|
|
797
|
-
return new GoTo("
|
|
797
|
+
return new GoTo("MODEL_RESPONDED" /* MODEL_RESPONDED */);
|
|
798
798
|
}
|
|
799
799
|
return new Fail("Invalid response type");
|
|
800
800
|
}
|
|
801
801
|
};
|
|
802
802
|
|
|
803
|
-
// src/domain/agent-loop/
|
|
803
|
+
// src/domain/agent-loop/state/message-received.ts
|
|
804
|
+
var MessageReceivedState = class {
|
|
805
|
+
constructor() {
|
|
806
|
+
this.id = "MESSAGE_RECEIVED" /* MESSAGE_RECEIVED */;
|
|
807
|
+
this.beforeHookId = "BEFORE_MESSAGE_RECEIVED" /* BEFORE_MESSAGE_RECEIVED */;
|
|
808
|
+
this.afterHookId = "AFTER_MESSAGE_RECEIVED" /* AFTER_MESSAGE_RECEIVED */;
|
|
809
|
+
}
|
|
810
|
+
getDetails() {
|
|
811
|
+
return {
|
|
812
|
+
before: this.beforeHookId,
|
|
813
|
+
stateId: this.id,
|
|
814
|
+
after: this.afterHookId
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
validateEntry(context) {
|
|
818
|
+
}
|
|
819
|
+
next(context) {
|
|
820
|
+
return new GoTo("INFERENCE_PENDING" /* INFERENCE_PENDING */);
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
// src/domain/agent-loop/agent-loop.ts
|
|
804
825
|
var AgentLoop = class {
|
|
805
826
|
constructor() {
|
|
806
827
|
this.states = /* @__PURE__ */ new Map();
|
|
828
|
+
this.states.set("MESSAGE_RECEIVED" /* MESSAGE_RECEIVED */, new MessageReceivedState());
|
|
807
829
|
this.states.set("INFERENCE_PENDING" /* INFERENCE_PENDING */, new InferencePendingState());
|
|
808
|
-
this.states.set("FUNCTION_CALL_PENDING" /* FUNCTION_CALL_PENDING */, new
|
|
809
|
-
this.states.set("
|
|
830
|
+
this.states.set("FUNCTION_CALL_PENDING" /* FUNCTION_CALL_PENDING */, new FunctionCallPendingState());
|
|
831
|
+
this.states.set("MODEL_RESPONDED" /* MODEL_RESPONDED */, new ModelRespondedState());
|
|
810
832
|
}
|
|
811
|
-
|
|
833
|
+
getState(runtime) {
|
|
812
834
|
const state = this.states.get(runtime.execution.currentStateId);
|
|
813
835
|
if (!state) {
|
|
814
836
|
throw new Error(`State ${runtime.execution.currentStateId} not found`);
|
|
815
837
|
}
|
|
816
|
-
state
|
|
817
|
-
}
|
|
818
|
-
getStateDetails(runtime) {
|
|
819
|
-
const state = this.states.get(runtime.execution.currentStateId);
|
|
820
|
-
if (!state) {
|
|
821
|
-
throw new Error(`State ${runtime.execution.currentStateId} not found`);
|
|
822
|
-
}
|
|
823
|
-
return state.getDetails();
|
|
824
|
-
}
|
|
825
|
-
next(runtime) {
|
|
826
|
-
const state = this.states.get(runtime.execution.currentStateId);
|
|
827
|
-
if (!state) {
|
|
828
|
-
throw new Error(`State ${runtime.execution.currentStateId} not found`);
|
|
829
|
-
}
|
|
830
|
-
return state.next(runtime);
|
|
838
|
+
return state;
|
|
831
839
|
}
|
|
832
840
|
};
|
|
833
841
|
|
|
@@ -876,11 +884,15 @@ var AgentRuntime = class {
|
|
|
876
884
|
constructor() {
|
|
877
885
|
this.hooksRegistry = new HooksRegistry();
|
|
878
886
|
this.stateHandlerRegistry = new StateHandlerRegistry();
|
|
887
|
+
this.stateHandlerRegistry.registerHandler("MESSAGE_RECEIVED" /* MESSAGE_RECEIVED */, this.onMessageReceived);
|
|
879
888
|
this.stateHandlerRegistry.registerHandler("INFERENCE_PENDING" /* INFERENCE_PENDING */, this.onInferencePending);
|
|
880
889
|
this.stateHandlerRegistry.registerHandler("FUNCTION_CALL_PENDING" /* FUNCTION_CALL_PENDING */, this.onFunctionCallPending);
|
|
881
|
-
this.stateHandlerRegistry.registerHandler("
|
|
890
|
+
this.stateHandlerRegistry.registerHandler("MODEL_RESPONDED" /* MODEL_RESPONDED */, this.onModelResponded);
|
|
882
891
|
this.hooksRegistry.registerHandler("ON_ERROR" /* ON_ERROR */, this.onError);
|
|
883
892
|
}
|
|
893
|
+
async onMessageReceived(runtimeContext) {
|
|
894
|
+
return Promise.resolve();
|
|
895
|
+
}
|
|
884
896
|
async onInferencePending(runtimeContext) {
|
|
885
897
|
const openaiResponses = new OpenAIResponses();
|
|
886
898
|
const inferenceRequest = new InferenceRequest(runtimeContext.model, runtimeContext.context);
|
|
@@ -897,7 +909,7 @@ var AgentRuntime = class {
|
|
|
897
909
|
}
|
|
898
910
|
const functionCallOutput = await tool.invoke(functionCall.args);
|
|
899
911
|
runtimeContext.context.addContextItem(
|
|
900
|
-
|
|
912
|
+
FunctionCallOutputItem.create(functionCall.callId, JSON.stringify(functionCallOutput))
|
|
901
913
|
);
|
|
902
914
|
return Promise.resolve();
|
|
903
915
|
}
|
|
@@ -909,7 +921,7 @@ var AgentRuntime = class {
|
|
|
909
921
|
console.error(error);
|
|
910
922
|
return Promise.resolve();
|
|
911
923
|
}
|
|
912
|
-
async
|
|
924
|
+
async onModelResponded(context) {
|
|
913
925
|
return Promise.resolve();
|
|
914
926
|
}
|
|
915
927
|
async on(hookId, callback) {
|
|
@@ -927,9 +939,10 @@ var AgentRuntime = class {
|
|
|
927
939
|
};
|
|
928
940
|
while (!execution.isTerminal()) {
|
|
929
941
|
console.log("Executing state", execution.currentStateId);
|
|
942
|
+
const state = loop.getState(runtimeContext);
|
|
930
943
|
try {
|
|
931
|
-
|
|
932
|
-
const stateDetails =
|
|
944
|
+
state.validateEntry(runtimeContext);
|
|
945
|
+
const stateDetails = state.getDetails();
|
|
933
946
|
if (stateDetails.before) {
|
|
934
947
|
const handler = this.hooksRegistry.getHandler(stateDetails.before);
|
|
935
948
|
await handler(runtimeContext);
|
|
@@ -947,7 +960,7 @@ var AgentRuntime = class {
|
|
|
947
960
|
runtimeContext.error = error;
|
|
948
961
|
await handler(runtimeContext);
|
|
949
962
|
}
|
|
950
|
-
const transition =
|
|
963
|
+
const transition = state.next(runtimeContext);
|
|
951
964
|
await transition.apply(runtimeContext);
|
|
952
965
|
}
|
|
953
966
|
}
|
|
@@ -955,16 +968,24 @@ var AgentRuntime = class {
|
|
|
955
968
|
|
|
956
969
|
// src/application/agent.ts
|
|
957
970
|
var Agent = class {
|
|
958
|
-
constructor(
|
|
959
|
-
this.runtime =
|
|
971
|
+
constructor() {
|
|
972
|
+
this.runtime = new AgentRuntime();
|
|
973
|
+
this.runtime.on("BEFORE_MESSAGE_RECEIVED" /* BEFORE_MESSAGE_RECEIVED */, this.beforeMessageReceived);
|
|
974
|
+
this.runtime.on("AFTER_MESSAGE_RECEIVED" /* AFTER_MESSAGE_RECEIVED */, this.afterMessageReceived);
|
|
960
975
|
this.runtime.on("BEFORE_INFERENCE" /* BEFORE_INFERENCE */, this.beforeInference);
|
|
961
976
|
this.runtime.on("AFTER_INFERENCE" /* AFTER_INFERENCE */, this.afterInference);
|
|
962
977
|
this.runtime.on("BEFORE_FUNCTION_CALL" /* BEFORE_FUNCTION_CALL */, this.beforeFunctionCall);
|
|
963
978
|
this.runtime.on("AFTER_FUNCTION_CALL" /* AFTER_FUNCTION_CALL */, this.afterFunctionCall);
|
|
964
|
-
this.runtime.on("
|
|
965
|
-
this.runtime.on("
|
|
979
|
+
this.runtime.on("BEFORE_MODEL_RESPONDED" /* BEFORE_MODEL_RESPONDED */, this.beforeModelResponded);
|
|
980
|
+
this.runtime.on("AFTER_MODEL_RESPONDED" /* AFTER_MODEL_RESPONDED */, this.afterModelResponded);
|
|
966
981
|
this.runtime.on("ON_ERROR" /* ON_ERROR */, this.onError);
|
|
967
982
|
}
|
|
983
|
+
async beforeMessageReceived(context) {
|
|
984
|
+
return Promise.resolve();
|
|
985
|
+
}
|
|
986
|
+
async afterMessageReceived(context) {
|
|
987
|
+
return Promise.resolve();
|
|
988
|
+
}
|
|
968
989
|
async beforeInference(context) {
|
|
969
990
|
return Promise.resolve();
|
|
970
991
|
}
|
|
@@ -987,10 +1008,10 @@ var Agent = class {
|
|
|
987
1008
|
}
|
|
988
1009
|
return Promise.resolve();
|
|
989
1010
|
}
|
|
990
|
-
async
|
|
1011
|
+
async beforeModelResponded(context) {
|
|
991
1012
|
return Promise.resolve();
|
|
992
1013
|
}
|
|
993
|
-
async
|
|
1014
|
+
async afterModelResponded(context) {
|
|
994
1015
|
return Promise.resolve();
|
|
995
1016
|
}
|
|
996
1017
|
async onError(context) {
|
|
@@ -1010,7 +1031,7 @@ var Agent = class {
|
|
|
1010
1031
|
this.functionCallVisitor = visitor;
|
|
1011
1032
|
}
|
|
1012
1033
|
async run(userMessage, model, context) {
|
|
1013
|
-
const userMessageItem =
|
|
1034
|
+
const userMessageItem = UserMessageItem.create(userMessage);
|
|
1014
1035
|
return this.runtime.start(userMessageItem, model, context);
|
|
1015
1036
|
}
|
|
1016
1037
|
};
|
|
@@ -1040,16 +1061,40 @@ var AgentSociety = class {
|
|
|
1040
1061
|
this.isActive = false;
|
|
1041
1062
|
}
|
|
1042
1063
|
};
|
|
1064
|
+
|
|
1065
|
+
// src/domain/model-context/context-item/client-item/system-message.ts
|
|
1066
|
+
var SystemMessageItem = class _SystemMessageItem extends ContextItem {
|
|
1067
|
+
constructor(content) {
|
|
1068
|
+
super();
|
|
1069
|
+
this.type = "message";
|
|
1070
|
+
this.role = "system";
|
|
1071
|
+
this.content = content;
|
|
1072
|
+
}
|
|
1073
|
+
toJSON() {
|
|
1074
|
+
return {
|
|
1075
|
+
type: this.type,
|
|
1076
|
+
role: this.role,
|
|
1077
|
+
content: this.content.toJSON()
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
static create(text) {
|
|
1081
|
+
const content = InputText.create(text);
|
|
1082
|
+
return new _SystemMessageItem(content);
|
|
1083
|
+
}
|
|
1084
|
+
static rehydrate(data) {
|
|
1085
|
+
const content = InputText.rehydrate(data);
|
|
1086
|
+
return new _SystemMessageItem(content);
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1043
1089
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1044
1090
|
0 && (module.exports = {
|
|
1045
1091
|
Agent,
|
|
1046
|
-
AgentRuntime,
|
|
1047
1092
|
AgentSociety,
|
|
1048
1093
|
BaseSpecification,
|
|
1049
1094
|
ContextItem,
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1095
|
+
DeveloperMessageItem,
|
|
1096
|
+
FunctionCallItem,
|
|
1097
|
+
FunctionCallOutputItem,
|
|
1053
1098
|
Gpt54,
|
|
1054
1099
|
Gpt54Mini,
|
|
1055
1100
|
Gpt54Nano,
|
|
@@ -1060,11 +1105,12 @@ var AgentSociety = class {
|
|
|
1060
1105
|
InputTokenDetails,
|
|
1061
1106
|
Loop,
|
|
1062
1107
|
ModelContext,
|
|
1063
|
-
|
|
1108
|
+
ModelMessageItem,
|
|
1064
1109
|
OpenAIResponses,
|
|
1065
1110
|
OutputTokenDetails,
|
|
1066
|
-
|
|
1111
|
+
ReasoningItem,
|
|
1112
|
+
SystemMessageItem,
|
|
1067
1113
|
TokenUsage,
|
|
1068
|
-
|
|
1114
|
+
UserMessageItem
|
|
1069
1115
|
});
|
|
1070
1116
|
//# sourceMappingURL=index.js.map
|