@mozaik-ai/core 3.3.4 → 3.4.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 CHANGED
@@ -122,6 +122,26 @@ declare class ReasoningItem extends ContextItem {
122
122
  toJSON(): any;
123
123
  }
124
124
 
125
+ interface ReasoningEffort<Effort extends string> {
126
+ setReasoningEffort(effort: Effort): void;
127
+ getReasoningEffort(): Effort;
128
+ }
129
+
130
+ interface FunctionTool {
131
+ type: "function";
132
+ name: string;
133
+ description: string;
134
+ parameters: Record<string, any>;
135
+ strict: boolean;
136
+ invoke: (args: any) => Promise<any>;
137
+ }
138
+ type Tool = FunctionTool;
139
+
140
+ interface ToolCallingCapability {
141
+ setTools(tools: Tool[]): void;
142
+ getTools(): Tool[];
143
+ }
144
+
125
145
  type ModelSpecification = {
126
146
  name: string;
127
147
  supportReasoningEffort: boolean;
@@ -131,7 +151,7 @@ type ModelSpecification = {
131
151
  maxOutputTokens: number;
132
152
  supportFunctionCalling: boolean;
133
153
  };
134
- interface GenerativeModel {
154
+ interface GenerativeModel extends ReasoningEffort<string>, ToolCallingCapability {
135
155
  readonly specification: ModelSpecification;
136
156
  }
137
157
 
@@ -154,26 +174,6 @@ interface ModelContextRepository {
154
174
  getByProjectId(projectId: string): Promise<ModelContext[]>;
155
175
  }
156
176
 
157
- interface ReasoningEffort<Effort extends string> {
158
- setReasoningEffort(effort: Effort): void;
159
- getReasoningEffort(): Effort;
160
- }
161
-
162
- interface FunctionTool {
163
- type: "function";
164
- name: string;
165
- description: string;
166
- parameters: Record<string, any>;
167
- strict: boolean;
168
- invoke: (args: any) => Promise<any>;
169
- }
170
- type Tool = FunctionTool;
171
-
172
- interface ToolCallingCapability {
173
- setTools(tools: Tool[]): void;
174
- getTools(): Tool[];
175
- }
176
-
177
177
  declare class InferenceRequest {
178
178
  readonly model: GenerativeModel & ReasoningEffort<string> & ToolCallingCapability;
179
179
  readonly context: ModelContext;
@@ -324,6 +324,18 @@ declare class InMemoryModelContextRepository implements ModelContextRepository {
324
324
  private clone;
325
325
  }
326
326
 
327
+ declare enum HookId {
328
+ BEFORE_MESSAGE_RECEIVED = "BEFORE_MESSAGE_RECEIVED",
329
+ AFTER_MESSAGE_RECEIVED = "AFTER_MESSAGE_RECEIVED",
330
+ BEFORE_INFERENCE = "BEFORE_INFERENCE",
331
+ AFTER_INFERENCE = "AFTER_INFERENCE",
332
+ BEFORE_FUNCTION_CALL = "BEFORE_FUNCTION_CALL",
333
+ AFTER_FUNCTION_CALL = "AFTER_FUNCTION_CALL",
334
+ BEFORE_MODEL_RESPONDED = "BEFORE_MODEL_RESPONDED",
335
+ AFTER_MODEL_RESPONDED = "AFTER_MODEL_RESPONDED",
336
+ ON_ERROR = "ON_ERROR"
337
+ }
338
+
327
339
  interface TransitionRecord {
328
340
  fromState: StateId;
329
341
  toState: StateId;
@@ -367,6 +379,19 @@ interface RuntimeContext {
367
379
  error?: Error;
368
380
  }
369
381
 
382
+ declare class AgentRuntime {
383
+ private hooksRegistry;
384
+ private stateHandlerRegistry;
385
+ constructor();
386
+ onMessageReceived(runtimeContext: RuntimeContext): Promise<void>;
387
+ onInferencePending(runtimeContext: RuntimeContext): Promise<void>;
388
+ onFunctionCallPending(runtimeContext: RuntimeContext): Promise<void>;
389
+ onError(context: RuntimeContext): Promise<void>;
390
+ onModelResponded(context: RuntimeContext): Promise<void>;
391
+ on(hookId: HookId, callback: (data: any) => Promise<void>): Promise<void>;
392
+ start(userMessage: UserMessageItem, model: GenerativeModel & ReasoningEffort<string> & ToolCallingCapability, context: ModelContext): Promise<void>;
393
+ }
394
+
370
395
  interface InferenceVisitor {
371
396
  onStart(context: RuntimeContext): Promise<void>;
372
397
  afterInference(inferenceResponse: InferenceResponse): Promise<void>;
@@ -380,7 +405,7 @@ interface FunctionCallVisitor {
380
405
  declare class Agent {
381
406
  private visitor;
382
407
  private functionCallVisitor;
383
- private runtime;
408
+ protected runtime: AgentRuntime;
384
409
  constructor();
385
410
  beforeMessageReceived(context: RuntimeContext): Promise<void>;
386
411
  afterMessageReceived(context: RuntimeContext): Promise<void>;
@@ -420,4 +445,49 @@ declare class SystemMessageItem extends ContextItem {
420
445
  }): SystemMessageItem;
421
446
  }
422
447
 
423
- export { type Action, Agent, AgentSociety, type AsyncAction, type AsyncRule, BaseSpecification, ContextItem, DeveloperMessageItem, FunctionCallItem, FunctionCallOutputItem, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, If, InMemoryModelContextRepository, InferenceRequest, InferenceResponse, type InferenceVisitor, InputTokenDetails, Loop, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIResponses, OutputTokenDetails, ReasoningItem, type RuntimeContext, type Specification, SystemMessageItem, TokenUsage, type Tool, UserMessageItem };
448
+ interface ToolExecutor {
449
+ produce(functionCallItem: FunctionCallItem, signal?: AbortSignal): AsyncIterable<FunctionCallOutputItem>;
450
+ }
451
+
452
+ interface InferenceHandler {
453
+ produce(context: ModelContext, model: GenerativeModel, signal?: AbortSignal): AsyncIterable<ReasoningItem | FunctionCallItem | ModelMessageItem>;
454
+ }
455
+
456
+ interface MessageSender {
457
+ stream(message: string, signal?: AbortSignal): AsyncIterable<string>;
458
+ }
459
+
460
+ declare abstract class Participant {
461
+ abstract onFunctionCallOutput(participant: Participant, item: FunctionCallOutputItem): Promise<void>;
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>;
466
+ }
467
+
468
+ declare abstract class AgenticEnvironment {
469
+ protected toolExecutor: ToolExecutor;
470
+ protected messageSender: MessageSender;
471
+ protected inferenceHandler: InferenceHandler;
472
+ protected participants: Participant[];
473
+ constructor(toolExecutor: ToolExecutor, messageSender: MessageSender, inferenceHandler: InferenceHandler);
474
+ join(user: Participant): void;
475
+ leave(user: Participant): void;
476
+ notifyFunctionCallOutput(user: Participant, item: FunctionCallOutputItem): void;
477
+ 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
+ notifyFunctionCall(user: Participant, item: FunctionCallItem): void;
482
+ notifyReasoning(user: Participant, item: ReasoningItem): void;
483
+ notifyOutputMessage(user: Participant, item: ModelMessageItem): void;
484
+ }
485
+
486
+ declare class Environment extends AgenticEnvironment {
487
+ constructor(toolExecutor: ToolExecutor, messageSender: MessageSender, inferenceHandler: InferenceHandler);
488
+ executeFunctionCall(user: Participant, functionCallItem: FunctionCallItem): Promise<void>;
489
+ sendMessage(user: Participant, message: string): Promise<void>;
490
+ runInference(user: Participant, context: ModelContext, model: GenerativeModel, signal?: AbortSignal): Promise<void>;
491
+ }
492
+
493
+ export { type Action, Agent, AgentSociety, type AsyncAction, type AsyncRule, BaseSpecification, ContextItem, DeveloperMessageItem, Environment, 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, ReasoningItem, type RuntimeContext, type Specification, SystemMessageItem, TokenUsage, type Tool, type ToolExecutor, UserMessageItem };
package/dist/index.d.ts CHANGED
@@ -122,6 +122,26 @@ declare class ReasoningItem extends ContextItem {
122
122
  toJSON(): any;
123
123
  }
124
124
 
125
+ interface ReasoningEffort<Effort extends string> {
126
+ setReasoningEffort(effort: Effort): void;
127
+ getReasoningEffort(): Effort;
128
+ }
129
+
130
+ interface FunctionTool {
131
+ type: "function";
132
+ name: string;
133
+ description: string;
134
+ parameters: Record<string, any>;
135
+ strict: boolean;
136
+ invoke: (args: any) => Promise<any>;
137
+ }
138
+ type Tool = FunctionTool;
139
+
140
+ interface ToolCallingCapability {
141
+ setTools(tools: Tool[]): void;
142
+ getTools(): Tool[];
143
+ }
144
+
125
145
  type ModelSpecification = {
126
146
  name: string;
127
147
  supportReasoningEffort: boolean;
@@ -131,7 +151,7 @@ type ModelSpecification = {
131
151
  maxOutputTokens: number;
132
152
  supportFunctionCalling: boolean;
133
153
  };
134
- interface GenerativeModel {
154
+ interface GenerativeModel extends ReasoningEffort<string>, ToolCallingCapability {
135
155
  readonly specification: ModelSpecification;
136
156
  }
137
157
 
@@ -154,26 +174,6 @@ interface ModelContextRepository {
154
174
  getByProjectId(projectId: string): Promise<ModelContext[]>;
155
175
  }
156
176
 
157
- interface ReasoningEffort<Effort extends string> {
158
- setReasoningEffort(effort: Effort): void;
159
- getReasoningEffort(): Effort;
160
- }
161
-
162
- interface FunctionTool {
163
- type: "function";
164
- name: string;
165
- description: string;
166
- parameters: Record<string, any>;
167
- strict: boolean;
168
- invoke: (args: any) => Promise<any>;
169
- }
170
- type Tool = FunctionTool;
171
-
172
- interface ToolCallingCapability {
173
- setTools(tools: Tool[]): void;
174
- getTools(): Tool[];
175
- }
176
-
177
177
  declare class InferenceRequest {
178
178
  readonly model: GenerativeModel & ReasoningEffort<string> & ToolCallingCapability;
179
179
  readonly context: ModelContext;
@@ -324,6 +324,18 @@ declare class InMemoryModelContextRepository implements ModelContextRepository {
324
324
  private clone;
325
325
  }
326
326
 
327
+ declare enum HookId {
328
+ BEFORE_MESSAGE_RECEIVED = "BEFORE_MESSAGE_RECEIVED",
329
+ AFTER_MESSAGE_RECEIVED = "AFTER_MESSAGE_RECEIVED",
330
+ BEFORE_INFERENCE = "BEFORE_INFERENCE",
331
+ AFTER_INFERENCE = "AFTER_INFERENCE",
332
+ BEFORE_FUNCTION_CALL = "BEFORE_FUNCTION_CALL",
333
+ AFTER_FUNCTION_CALL = "AFTER_FUNCTION_CALL",
334
+ BEFORE_MODEL_RESPONDED = "BEFORE_MODEL_RESPONDED",
335
+ AFTER_MODEL_RESPONDED = "AFTER_MODEL_RESPONDED",
336
+ ON_ERROR = "ON_ERROR"
337
+ }
338
+
327
339
  interface TransitionRecord {
328
340
  fromState: StateId;
329
341
  toState: StateId;
@@ -367,6 +379,19 @@ interface RuntimeContext {
367
379
  error?: Error;
368
380
  }
369
381
 
382
+ declare class AgentRuntime {
383
+ private hooksRegistry;
384
+ private stateHandlerRegistry;
385
+ constructor();
386
+ onMessageReceived(runtimeContext: RuntimeContext): Promise<void>;
387
+ onInferencePending(runtimeContext: RuntimeContext): Promise<void>;
388
+ onFunctionCallPending(runtimeContext: RuntimeContext): Promise<void>;
389
+ onError(context: RuntimeContext): Promise<void>;
390
+ onModelResponded(context: RuntimeContext): Promise<void>;
391
+ on(hookId: HookId, callback: (data: any) => Promise<void>): Promise<void>;
392
+ start(userMessage: UserMessageItem, model: GenerativeModel & ReasoningEffort<string> & ToolCallingCapability, context: ModelContext): Promise<void>;
393
+ }
394
+
370
395
  interface InferenceVisitor {
371
396
  onStart(context: RuntimeContext): Promise<void>;
372
397
  afterInference(inferenceResponse: InferenceResponse): Promise<void>;
@@ -380,7 +405,7 @@ interface FunctionCallVisitor {
380
405
  declare class Agent {
381
406
  private visitor;
382
407
  private functionCallVisitor;
383
- private runtime;
408
+ protected runtime: AgentRuntime;
384
409
  constructor();
385
410
  beforeMessageReceived(context: RuntimeContext): Promise<void>;
386
411
  afterMessageReceived(context: RuntimeContext): Promise<void>;
@@ -420,4 +445,49 @@ declare class SystemMessageItem extends ContextItem {
420
445
  }): SystemMessageItem;
421
446
  }
422
447
 
423
- export { type Action, Agent, AgentSociety, type AsyncAction, type AsyncRule, BaseSpecification, ContextItem, DeveloperMessageItem, FunctionCallItem, FunctionCallOutputItem, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, If, InMemoryModelContextRepository, InferenceRequest, InferenceResponse, type InferenceVisitor, InputTokenDetails, Loop, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIResponses, OutputTokenDetails, ReasoningItem, type RuntimeContext, type Specification, SystemMessageItem, TokenUsage, type Tool, UserMessageItem };
448
+ interface ToolExecutor {
449
+ produce(functionCallItem: FunctionCallItem, signal?: AbortSignal): AsyncIterable<FunctionCallOutputItem>;
450
+ }
451
+
452
+ interface InferenceHandler {
453
+ produce(context: ModelContext, model: GenerativeModel, signal?: AbortSignal): AsyncIterable<ReasoningItem | FunctionCallItem | ModelMessageItem>;
454
+ }
455
+
456
+ interface MessageSender {
457
+ stream(message: string, signal?: AbortSignal): AsyncIterable<string>;
458
+ }
459
+
460
+ declare abstract class Participant {
461
+ abstract onFunctionCallOutput(participant: Participant, item: FunctionCallOutputItem): Promise<void>;
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>;
466
+ }
467
+
468
+ declare abstract class AgenticEnvironment {
469
+ protected toolExecutor: ToolExecutor;
470
+ protected messageSender: MessageSender;
471
+ protected inferenceHandler: InferenceHandler;
472
+ protected participants: Participant[];
473
+ constructor(toolExecutor: ToolExecutor, messageSender: MessageSender, inferenceHandler: InferenceHandler);
474
+ join(user: Participant): void;
475
+ leave(user: Participant): void;
476
+ notifyFunctionCallOutput(user: Participant, item: FunctionCallOutputItem): void;
477
+ 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
+ notifyFunctionCall(user: Participant, item: FunctionCallItem): void;
482
+ notifyReasoning(user: Participant, item: ReasoningItem): void;
483
+ notifyOutputMessage(user: Participant, item: ModelMessageItem): void;
484
+ }
485
+
486
+ declare class Environment extends AgenticEnvironment {
487
+ constructor(toolExecutor: ToolExecutor, messageSender: MessageSender, inferenceHandler: InferenceHandler);
488
+ executeFunctionCall(user: Participant, functionCallItem: FunctionCallItem): Promise<void>;
489
+ sendMessage(user: Participant, message: string): Promise<void>;
490
+ runInference(user: Participant, context: ModelContext, model: GenerativeModel, signal?: AbortSignal): Promise<void>;
491
+ }
492
+
493
+ export { type Action, Agent, AgentSociety, type AsyncAction, type AsyncRule, BaseSpecification, ContextItem, DeveloperMessageItem, Environment, 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, ReasoningItem, type RuntimeContext, type Specification, SystemMessageItem, TokenUsage, type Tool, type ToolExecutor, UserMessageItem };
package/dist/index.js CHANGED
@@ -35,6 +35,7 @@ __export(index_exports, {
35
35
  BaseSpecification: () => BaseSpecification,
36
36
  ContextItem: () => ContextItem,
37
37
  DeveloperMessageItem: () => DeveloperMessageItem,
38
+ Environment: () => Environment,
38
39
  FunctionCallItem: () => FunctionCallItem,
39
40
  FunctionCallOutputItem: () => FunctionCallOutputItem,
40
41
  Gpt54: () => Gpt54,
@@ -1086,6 +1087,78 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
1086
1087
  return new _SystemMessageItem(content);
1087
1088
  }
1088
1089
  };
1090
+
1091
+ // src/domain/agentic-environment/agentic-environment.ts
1092
+ var AgenticEnvironment = class {
1093
+ constructor(toolExecutor, messageSender, inferenceHandler) {
1094
+ this.participants = [];
1095
+ this.toolExecutor = toolExecutor;
1096
+ this.messageSender = messageSender;
1097
+ this.inferenceHandler = inferenceHandler;
1098
+ }
1099
+ join(user) {
1100
+ this.participants.push(user);
1101
+ }
1102
+ leave(user) {
1103
+ this.participants = this.participants.filter((p) => p !== user);
1104
+ }
1105
+ notifyFunctionCallOutput(user, item) {
1106
+ for (const participant of this.participants) {
1107
+ participant.onFunctionCallOutput(user, item);
1108
+ }
1109
+ }
1110
+ notifyMessage(user, message) {
1111
+ for (const participant of this.participants) {
1112
+ if (participant === user) {
1113
+ continue;
1114
+ }
1115
+ participant.onMessage(user, message);
1116
+ }
1117
+ }
1118
+ notifyFunctionCall(user, item) {
1119
+ for (const participant of this.participants) {
1120
+ participant.onFunctionCall(user, item);
1121
+ }
1122
+ }
1123
+ notifyReasoning(user, item) {
1124
+ for (const participant of this.participants) {
1125
+ participant.onReasoning(user, item);
1126
+ }
1127
+ }
1128
+ notifyOutputMessage(user, item) {
1129
+ for (const participant of this.participants) {
1130
+ participant.onOutputMessage(user, item);
1131
+ }
1132
+ }
1133
+ };
1134
+
1135
+ // src/application/environment.ts
1136
+ var Environment = class extends AgenticEnvironment {
1137
+ constructor(toolExecutor, messageSender, inferenceHandler) {
1138
+ super(toolExecutor, messageSender, inferenceHandler);
1139
+ }
1140
+ async executeFunctionCall(user, functionCallItem) {
1141
+ for await (const item of this.toolExecutor.produce(functionCallItem)) {
1142
+ this.notifyFunctionCallOutput(user, item);
1143
+ }
1144
+ }
1145
+ async sendMessage(user, message) {
1146
+ for await (const messagePart of this.messageSender.stream(message)) {
1147
+ this.notifyMessage(user, messagePart);
1148
+ }
1149
+ }
1150
+ async runInference(user, context, model, signal) {
1151
+ for await (const item of this.inferenceHandler.produce(context, model, signal)) {
1152
+ if (item instanceof FunctionCallItem) {
1153
+ this.notifyFunctionCall(user, item);
1154
+ } else if (item instanceof ReasoningItem) {
1155
+ this.notifyReasoning(user, item);
1156
+ } else if (item instanceof ModelMessageItem) {
1157
+ this.notifyOutputMessage(user, item);
1158
+ }
1159
+ }
1160
+ }
1161
+ };
1089
1162
  // Annotate the CommonJS export names for ESM import in node:
1090
1163
  0 && (module.exports = {
1091
1164
  Agent,
@@ -1093,6 +1166,7 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
1093
1166
  BaseSpecification,
1094
1167
  ContextItem,
1095
1168
  DeveloperMessageItem,
1169
+ Environment,
1096
1170
  FunctionCallItem,
1097
1171
  FunctionCallOutputItem,
1098
1172
  Gpt54,