@mozaik-ai/core 3.4.2 → 3.5.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.d.mts +24 -28
- package/dist/index.d.ts +24 -28
- package/dist/index.js +76 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -56
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -449,48 +449,44 @@ interface ToolExecutor {
|
|
|
449
449
|
produce(functionCallItem: FunctionCallItem, signal?: AbortSignal): AsyncIterable<FunctionCallOutputItem>;
|
|
450
450
|
}
|
|
451
451
|
|
|
452
|
-
interface InferenceHandler {
|
|
453
|
-
produce(context: ModelContext, model: GenerativeModel, signal?: AbortSignal): AsyncIterable<ReasoningItem | FunctionCallItem | ModelMessageItem>;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
452
|
interface MessageSender {
|
|
457
453
|
stream(message: string, signal?: AbortSignal): AsyncIterable<string>;
|
|
458
454
|
}
|
|
459
455
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
abstract onMessage(participant: Participant, message: string): Promise<void>;
|
|
463
|
-
abstract onFunctionCall(participant: Participant, item: FunctionCallItem): Promise<void>;
|
|
464
|
-
abstract onReasoning(participant: Participant, item: ReasoningItem): Promise<void>;
|
|
465
|
-
abstract onOutputMessage(participant: Participant, item: ModelMessageItem): Promise<void>;
|
|
456
|
+
interface InferenceHandler {
|
|
457
|
+
produce(context: ModelContext, model: GenerativeModel, signal?: AbortSignal): AsyncIterable<ReasoningItem | FunctionCallItem | ModelMessageItem>;
|
|
466
458
|
}
|
|
467
459
|
|
|
468
460
|
declare abstract class AgenticEnvironment {
|
|
469
|
-
protected
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
leave(user: Participant): void;
|
|
461
|
+
protected subscribers: Participant[];
|
|
462
|
+
private isActive;
|
|
463
|
+
start(): Promise<void>;
|
|
464
|
+
stop(): void;
|
|
465
|
+
subscribe(subscriber: Participant): void;
|
|
466
|
+
unsubscribe(user: Participant): void;
|
|
476
467
|
notifyFunctionCallOutput(user: Participant, item: FunctionCallOutputItem): void;
|
|
477
468
|
notifyMessage(user: Participant, message: string): void;
|
|
478
|
-
abstract executeFunctionCall(user: Participant, functionCallItem: FunctionCallItem): Promise<void>;
|
|
479
|
-
abstract sendMessage(user: Participant, message: string): Promise<void>;
|
|
480
|
-
abstract runInference(user: Participant, context: ModelContext, model: GenerativeModel, signal?: AbortSignal): Promise<void>;
|
|
481
469
|
notifyFunctionCall(user: Participant, item: FunctionCallItem): void;
|
|
482
470
|
notifyReasoning(user: Participant, item: ReasoningItem): void;
|
|
483
471
|
notifyOutputMessage(user: Participant, item: ModelMessageItem): void;
|
|
484
472
|
}
|
|
485
473
|
|
|
486
|
-
declare class
|
|
487
|
-
|
|
474
|
+
declare abstract class Participant {
|
|
475
|
+
protected toolExecutor: ToolExecutor;
|
|
476
|
+
protected messageSender: MessageSender;
|
|
477
|
+
protected inferenceHandler: InferenceHandler;
|
|
478
|
+
protected environments: AgenticEnvironment[];
|
|
488
479
|
constructor(toolExecutor: ToolExecutor, messageSender: MessageSender, inferenceHandler: InferenceHandler);
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
480
|
+
abstract onFunctionCallOutput(participant: Participant, item: FunctionCallOutputItem): Promise<void>;
|
|
481
|
+
abstract onMessage(participant: Participant, message: string): Promise<void>;
|
|
482
|
+
abstract onFunctionCall(participant: Participant, item: FunctionCallItem): Promise<void>;
|
|
483
|
+
abstract onReasoning(participant: Participant, item: ReasoningItem): Promise<void>;
|
|
484
|
+
abstract onOutputMessage(participant: Participant, item: ModelMessageItem): Promise<void>;
|
|
485
|
+
sendMessage(message: string, environment: AgenticEnvironment): Promise<void>;
|
|
486
|
+
executeFunctionCall(functionCallItem: FunctionCallItem, environment: AgenticEnvironment): Promise<void>;
|
|
487
|
+
runInference(environment: AgenticEnvironment, context: ModelContext, model: GenerativeModel, signal?: AbortSignal): Promise<void>;
|
|
488
|
+
join(environment: AgenticEnvironment): void;
|
|
489
|
+
leave(environment: AgenticEnvironment): void;
|
|
494
490
|
}
|
|
495
491
|
|
|
496
|
-
export { type Action, Agent, AgentSociety, type AsyncAction, type AsyncRule, BaseSpecification, ContextItem, DeveloperMessageItem,
|
|
492
|
+
export { type Action, Agent, AgentSociety, AgenticEnvironment, type AsyncAction, type AsyncRule, BaseSpecification, ContextItem, DeveloperMessageItem, FunctionCallItem, FunctionCallOutputItem, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, If, InMemoryModelContextRepository, type InferenceHandler, InferenceRequest, InferenceResponse, type InferenceVisitor, InputTokenDetails, Loop, type MessageSender, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, type RuntimeContext, type Specification, SystemMessageItem, TokenUsage, type Tool, type ToolExecutor, UserMessageItem };
|
package/dist/index.d.ts
CHANGED
|
@@ -449,48 +449,44 @@ interface ToolExecutor {
|
|
|
449
449
|
produce(functionCallItem: FunctionCallItem, signal?: AbortSignal): AsyncIterable<FunctionCallOutputItem>;
|
|
450
450
|
}
|
|
451
451
|
|
|
452
|
-
interface InferenceHandler {
|
|
453
|
-
produce(context: ModelContext, model: GenerativeModel, signal?: AbortSignal): AsyncIterable<ReasoningItem | FunctionCallItem | ModelMessageItem>;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
452
|
interface MessageSender {
|
|
457
453
|
stream(message: string, signal?: AbortSignal): AsyncIterable<string>;
|
|
458
454
|
}
|
|
459
455
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
abstract onMessage(participant: Participant, message: string): Promise<void>;
|
|
463
|
-
abstract onFunctionCall(participant: Participant, item: FunctionCallItem): Promise<void>;
|
|
464
|
-
abstract onReasoning(participant: Participant, item: ReasoningItem): Promise<void>;
|
|
465
|
-
abstract onOutputMessage(participant: Participant, item: ModelMessageItem): Promise<void>;
|
|
456
|
+
interface InferenceHandler {
|
|
457
|
+
produce(context: ModelContext, model: GenerativeModel, signal?: AbortSignal): AsyncIterable<ReasoningItem | FunctionCallItem | ModelMessageItem>;
|
|
466
458
|
}
|
|
467
459
|
|
|
468
460
|
declare abstract class AgenticEnvironment {
|
|
469
|
-
protected
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
leave(user: Participant): void;
|
|
461
|
+
protected subscribers: Participant[];
|
|
462
|
+
private isActive;
|
|
463
|
+
start(): Promise<void>;
|
|
464
|
+
stop(): void;
|
|
465
|
+
subscribe(subscriber: Participant): void;
|
|
466
|
+
unsubscribe(user: Participant): void;
|
|
476
467
|
notifyFunctionCallOutput(user: Participant, item: FunctionCallOutputItem): void;
|
|
477
468
|
notifyMessage(user: Participant, message: string): void;
|
|
478
|
-
abstract executeFunctionCall(user: Participant, functionCallItem: FunctionCallItem): Promise<void>;
|
|
479
|
-
abstract sendMessage(user: Participant, message: string): Promise<void>;
|
|
480
|
-
abstract runInference(user: Participant, context: ModelContext, model: GenerativeModel, signal?: AbortSignal): Promise<void>;
|
|
481
469
|
notifyFunctionCall(user: Participant, item: FunctionCallItem): void;
|
|
482
470
|
notifyReasoning(user: Participant, item: ReasoningItem): void;
|
|
483
471
|
notifyOutputMessage(user: Participant, item: ModelMessageItem): void;
|
|
484
472
|
}
|
|
485
473
|
|
|
486
|
-
declare class
|
|
487
|
-
|
|
474
|
+
declare abstract class Participant {
|
|
475
|
+
protected toolExecutor: ToolExecutor;
|
|
476
|
+
protected messageSender: MessageSender;
|
|
477
|
+
protected inferenceHandler: InferenceHandler;
|
|
478
|
+
protected environments: AgenticEnvironment[];
|
|
488
479
|
constructor(toolExecutor: ToolExecutor, messageSender: MessageSender, inferenceHandler: InferenceHandler);
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
480
|
+
abstract onFunctionCallOutput(participant: Participant, item: FunctionCallOutputItem): Promise<void>;
|
|
481
|
+
abstract onMessage(participant: Participant, message: string): Promise<void>;
|
|
482
|
+
abstract onFunctionCall(participant: Participant, item: FunctionCallItem): Promise<void>;
|
|
483
|
+
abstract onReasoning(participant: Participant, item: ReasoningItem): Promise<void>;
|
|
484
|
+
abstract onOutputMessage(participant: Participant, item: ModelMessageItem): Promise<void>;
|
|
485
|
+
sendMessage(message: string, environment: AgenticEnvironment): Promise<void>;
|
|
486
|
+
executeFunctionCall(functionCallItem: FunctionCallItem, environment: AgenticEnvironment): Promise<void>;
|
|
487
|
+
runInference(environment: AgenticEnvironment, context: ModelContext, model: GenerativeModel, signal?: AbortSignal): Promise<void>;
|
|
488
|
+
join(environment: AgenticEnvironment): void;
|
|
489
|
+
leave(environment: AgenticEnvironment): void;
|
|
494
490
|
}
|
|
495
491
|
|
|
496
|
-
export { type Action, Agent, AgentSociety, type AsyncAction, type AsyncRule, BaseSpecification, ContextItem, DeveloperMessageItem,
|
|
492
|
+
export { type Action, Agent, AgentSociety, AgenticEnvironment, type AsyncAction, type AsyncRule, BaseSpecification, ContextItem, DeveloperMessageItem, FunctionCallItem, FunctionCallOutputItem, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, If, InMemoryModelContextRepository, type InferenceHandler, InferenceRequest, InferenceResponse, type InferenceVisitor, InputTokenDetails, Loop, type MessageSender, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, type RuntimeContext, type Specification, SystemMessageItem, TokenUsage, type Tool, type ToolExecutor, UserMessageItem };
|
package/dist/index.js
CHANGED
|
@@ -32,10 +32,10 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
Agent: () => Agent,
|
|
34
34
|
AgentSociety: () => AgentSociety,
|
|
35
|
+
AgenticEnvironment: () => AgenticEnvironment,
|
|
35
36
|
BaseSpecification: () => BaseSpecification,
|
|
36
37
|
ContextItem: () => ContextItem,
|
|
37
38
|
DeveloperMessageItem: () => DeveloperMessageItem,
|
|
38
|
-
Environment: () => Environment,
|
|
39
39
|
FunctionCallItem: () => FunctionCallItem,
|
|
40
40
|
FunctionCallOutputItem: () => FunctionCallOutputItem,
|
|
41
41
|
Gpt54: () => Gpt54,
|
|
@@ -1089,77 +1089,66 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
|
|
|
1089
1089
|
}
|
|
1090
1090
|
};
|
|
1091
1091
|
|
|
1092
|
-
// src/domain/agentic-environment/
|
|
1093
|
-
var
|
|
1092
|
+
// src/domain/agentic-environment/participant.ts
|
|
1093
|
+
var Participant = class {
|
|
1094
1094
|
constructor(toolExecutor, messageSender, inferenceHandler) {
|
|
1095
|
-
this.
|
|
1095
|
+
this.environments = [];
|
|
1096
1096
|
this.toolExecutor = toolExecutor;
|
|
1097
1097
|
this.messageSender = messageSender;
|
|
1098
1098
|
this.inferenceHandler = inferenceHandler;
|
|
1099
1099
|
}
|
|
1100
|
-
|
|
1101
|
-
this.
|
|
1102
|
-
|
|
1103
|
-
leave(user) {
|
|
1104
|
-
this.participants = this.participants.filter((p) => p !== user);
|
|
1105
|
-
}
|
|
1106
|
-
notifyFunctionCallOutput(user, item) {
|
|
1107
|
-
for (const participant of this.participants) {
|
|
1108
|
-
participant.onFunctionCallOutput(user, item);
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
notifyMessage(user, message) {
|
|
1112
|
-
for (const participant of this.participants) {
|
|
1113
|
-
if (participant === user) {
|
|
1114
|
-
continue;
|
|
1115
|
-
}
|
|
1116
|
-
participant.onMessage(user, message);
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
notifyFunctionCall(user, item) {
|
|
1120
|
-
for (const participant of this.participants) {
|
|
1121
|
-
participant.onFunctionCall(user, item);
|
|
1100
|
+
async sendMessage(message, environment) {
|
|
1101
|
+
if (!this.environments.includes(environment)) {
|
|
1102
|
+
return;
|
|
1122
1103
|
}
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
for (const participant of this.participants) {
|
|
1126
|
-
participant.onReasoning(user, item);
|
|
1104
|
+
for await (const messagePart of this.messageSender.stream(message)) {
|
|
1105
|
+
environment.notifyMessage(this, messagePart);
|
|
1127
1106
|
}
|
|
1128
1107
|
}
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1108
|
+
async executeFunctionCall(functionCallItem, environment) {
|
|
1109
|
+
if (!this.environments.includes(environment)) {
|
|
1110
|
+
return;
|
|
1132
1111
|
}
|
|
1133
|
-
}
|
|
1134
|
-
};
|
|
1135
|
-
|
|
1136
|
-
// src/application/environment.ts
|
|
1137
|
-
var Environment = class extends AgenticEnvironment {
|
|
1138
|
-
constructor(toolExecutor, messageSender, inferenceHandler) {
|
|
1139
|
-
super(toolExecutor, messageSender, inferenceHandler);
|
|
1140
|
-
this.isActive = false;
|
|
1141
|
-
}
|
|
1142
|
-
async executeFunctionCall(user, functionCallItem) {
|
|
1143
1112
|
for await (const item of this.toolExecutor.produce(functionCallItem)) {
|
|
1144
|
-
|
|
1113
|
+
environment.notifyFunctionCallOutput(this, item);
|
|
1145
1114
|
}
|
|
1146
1115
|
}
|
|
1147
|
-
async
|
|
1148
|
-
|
|
1149
|
-
|
|
1116
|
+
async runInference(environment, context, model, signal) {
|
|
1117
|
+
if (!this.environments.includes(environment)) {
|
|
1118
|
+
return;
|
|
1150
1119
|
}
|
|
1151
|
-
}
|
|
1152
|
-
async runInference(user, context, model, signal) {
|
|
1153
1120
|
for await (const item of this.inferenceHandler.produce(context, model, signal)) {
|
|
1154
1121
|
if (item instanceof FunctionCallItem) {
|
|
1155
|
-
|
|
1122
|
+
environment.notifyFunctionCall(this, item);
|
|
1156
1123
|
} else if (item instanceof ReasoningItem) {
|
|
1157
|
-
|
|
1124
|
+
environment.notifyReasoning(this, item);
|
|
1158
1125
|
} else if (item instanceof ModelMessageItem) {
|
|
1159
|
-
|
|
1126
|
+
environment.notifyOutputMessage(this, item);
|
|
1160
1127
|
}
|
|
1161
1128
|
}
|
|
1162
1129
|
}
|
|
1130
|
+
join(environment) {
|
|
1131
|
+
if (this.environments.includes(environment)) {
|
|
1132
|
+
return;
|
|
1133
|
+
}
|
|
1134
|
+
environment.subscribe(this);
|
|
1135
|
+
this.environments.push(environment);
|
|
1136
|
+
}
|
|
1137
|
+
leave(environment) {
|
|
1138
|
+
if (!this.environments.includes(environment)) {
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
environment.unsubscribe(this);
|
|
1142
|
+
this.environments = this.environments.filter((e) => e !== environment);
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
|
|
1146
|
+
// src/domain/agentic-environment/agentic-environment.ts
|
|
1147
|
+
var AgenticEnvironment = class {
|
|
1148
|
+
constructor() {
|
|
1149
|
+
this.subscribers = [];
|
|
1150
|
+
this.isActive = false;
|
|
1151
|
+
}
|
|
1163
1152
|
async start() {
|
|
1164
1153
|
this.isActive = true;
|
|
1165
1154
|
while (this.isActive) {
|
|
@@ -1169,19 +1158,49 @@ var Environment = class extends AgenticEnvironment {
|
|
|
1169
1158
|
stop() {
|
|
1170
1159
|
this.isActive = false;
|
|
1171
1160
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1161
|
+
subscribe(subscriber) {
|
|
1162
|
+
this.subscribers.push(subscriber);
|
|
1163
|
+
}
|
|
1164
|
+
unsubscribe(user) {
|
|
1165
|
+
this.subscribers = this.subscribers.filter((p) => p !== user);
|
|
1166
|
+
}
|
|
1167
|
+
notifyFunctionCallOutput(user, item) {
|
|
1168
|
+
for (const subscriber of this.subscribers) {
|
|
1169
|
+
subscriber.onFunctionCallOutput(subscriber, item);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
notifyMessage(user, message) {
|
|
1173
|
+
for (const subscriber of this.subscribers) {
|
|
1174
|
+
if (subscriber === user) {
|
|
1175
|
+
continue;
|
|
1176
|
+
}
|
|
1177
|
+
subscriber.onMessage(subscriber, message);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
notifyFunctionCall(user, item) {
|
|
1181
|
+
for (const subscriber of this.subscribers) {
|
|
1182
|
+
subscriber.onFunctionCall(user, item);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
notifyReasoning(user, item) {
|
|
1186
|
+
for (const subscriber of this.subscribers) {
|
|
1187
|
+
subscriber.onReasoning(user, item);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
notifyOutputMessage(user, item) {
|
|
1191
|
+
for (const subscriber of this.subscribers) {
|
|
1192
|
+
subscriber.onOutputMessage(user, item);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1176
1195
|
};
|
|
1177
1196
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1178
1197
|
0 && (module.exports = {
|
|
1179
1198
|
Agent,
|
|
1180
1199
|
AgentSociety,
|
|
1200
|
+
AgenticEnvironment,
|
|
1181
1201
|
BaseSpecification,
|
|
1182
1202
|
ContextItem,
|
|
1183
1203
|
DeveloperMessageItem,
|
|
1184
|
-
Environment,
|
|
1185
1204
|
FunctionCallItem,
|
|
1186
1205
|
FunctionCallOutputItem,
|
|
1187
1206
|
Gpt54,
|