@mozaik-ai/core 4.0.0-beta.9 → 4.0.1

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
@@ -186,6 +186,24 @@ interface FunctionCallParams {
186
186
  inferenceInput: InferenceInput;
187
187
  }
188
188
 
189
+ interface InterceptionHandler {
190
+ isSatisfiedBy(transition: ExecutableTransition): boolean;
191
+ handle(transition: ExecutableTransition): Promise<ExecutableTransition>;
192
+ }
193
+ type InterceptionOutput = {
194
+ type: "continue";
195
+ transition: LoopTransition;
196
+ } | {
197
+ type: "pause";
198
+ pendingTransition: LoopTransition;
199
+ } | {
200
+ type: "stop";
201
+ reason?: string;
202
+ };
203
+ interface InterceptionParams {
204
+ pendingTransition: LoopTransition;
205
+ }
206
+
189
207
  type LoopStateId = "context_update" | "inference" | "inference_streaming" | "function_call" | "model_message" | "idle";
190
208
  type ReceivedMessage = {
191
209
  content: string;
@@ -227,19 +245,15 @@ interface LoopStateContract {
227
245
  output: void;
228
246
  };
229
247
  }
230
- type InterceptionOutput = {
231
- type: "continue";
232
- transition: LoopTransition;
233
- } | {
234
- type: "pause";
235
- pendingTransition: LoopTransition;
236
- } | {
237
- type: "stop";
238
- reason?: string;
239
- };
240
- interface InterceptionParams {
241
- pendingTransition: LoopTransition;
242
- }
248
+ type ExecutableLoopStateId = Exclude<LoopStateId, "idle">;
249
+ type ExecutableTransition = LoopTransition<ExecutableLoopStateId>;
250
+ type LoopStateExecution<TStateId extends ExecutableLoopStateId = ExecutableLoopStateId> = {
251
+ [K in TStateId]: {
252
+ stateId: K;
253
+ input: LoopStateContract[K]["input"];
254
+ output: LoopStateContract[K]["output"];
255
+ };
256
+ }[TStateId];
243
257
  type LoopTransition<TStateId extends LoopStateId = LoopStateId> = {
244
258
  [K in TStateId]: {
245
259
  nextStateId: K;
@@ -247,6 +261,23 @@ type LoopTransition<TStateId extends LoopStateId = LoopStateId> = {
247
261
  };
248
262
  }[TStateId];
249
263
 
264
+ declare class InputTokenDetails {
265
+ readonly cached_tokens: number;
266
+ constructor(cached_tokens: number);
267
+ }
268
+ declare class OutputTokenDetails {
269
+ readonly reasoning_tokens: number;
270
+ constructor(reasoning_tokens: number);
271
+ }
272
+ declare class TokenUsage {
273
+ readonly inputTokens: number;
274
+ readonly outputTokens: number;
275
+ readonly totalTokens: number;
276
+ readonly inputTokenDetails: InputTokenDetails;
277
+ readonly outputTokenDetails: OutputTokenDetails;
278
+ constructor(inputTokens: number, outputTokens: number, totalTokens: number, inputTokenDetails: InputTokenDetails, outputTokenDetails: OutputTokenDetails);
279
+ }
280
+
250
281
  type InferenceInput = {
251
282
  model: string;
252
283
  maxOutputTokens?: number;
@@ -259,6 +290,7 @@ type InferenceInput = {
259
290
  type InferenceItem = FunctionCallItem | ReasoningItem | ModelMessageItem;
260
291
  type InferenceOutput = {
261
292
  items: InferenceItem[];
293
+ tokenUsage: TokenUsage | undefined;
262
294
  rowResponse: any;
263
295
  };
264
296
  interface InferenceRunner {
@@ -311,23 +343,6 @@ interface ModelContextRepository {
311
343
  getByProjectId(projectId: string): Promise<ModelContext[]>;
312
344
  }
313
345
 
314
- declare class InputTokenDetails {
315
- readonly cached_tokens: number;
316
- constructor(cached_tokens: number);
317
- }
318
- declare class OutputTokenDetails {
319
- readonly reasoning_tokens: number;
320
- constructor(reasoning_tokens: number);
321
- }
322
- declare class TokenUsage {
323
- readonly inputTokens: number;
324
- readonly outputTokens: number;
325
- readonly totalTokens: number;
326
- readonly inputTokenDetails: InputTokenDetails;
327
- readonly outputTokenDetails: OutputTokenDetails;
328
- constructor(inputTokens: number, outputTokens: number, totalTokens: number, inputTokenDetails: InputTokenDetails, outputTokenDetails: OutputTokenDetails);
329
- }
330
-
331
346
  interface McpServerConfig {
332
347
  /** The MCP server URL, e.g. https://api.githubcopilot.com/mcp/ */
333
348
  url: string;
@@ -459,11 +474,6 @@ declare abstract class RuntimeState {
459
474
  getParticipants(): readonly Participant[];
460
475
  }
461
476
 
462
- interface InterceptionHandler {
463
- isSatisfiedBy(transition: LoopTransition): boolean;
464
- handle(transition: LoopTransition): Promise<LoopTransition>;
465
- }
466
-
467
477
  declare class EventProcessor {
468
478
  process(event: SemanticEvent, consumer: Participant): void;
469
479
  }
@@ -497,7 +507,7 @@ declare function defineRuntime<TRuntimeState extends RuntimeState>(): {
497
507
  leave: (participant: Participant) => void;
498
508
  sendMessage: (message: string, senderId: string) => void;
499
509
  sendEvent: (event: SemanticEvent, senderId: string) => void;
500
- runLoop: (agentId: string, message: string, inferenceInput: InferenceInput, interceptionHandler: InterceptionHandler) => void;
510
+ runLoop: (agentId: string, message: string, inferenceInput: InferenceInput, interceptionHandler?: InterceptionHandler) => void;
501
511
  };
502
512
 
503
513
  declare const supportedModels: GenerativeModel[];
@@ -615,4 +625,4 @@ declare class DefaultInferenceRunner implements InferenceRunner {
615
625
  stream(input: InferenceInput): AsyncGenerator<SemanticEvent>;
616
626
  }
617
627
 
618
- export { Agent, AnthropicMessages, ContextItem, DefaultInferenceRunner, DeveloperMessageItem, type Endpoint, FunctionCallItem, FunctionCallOutputItem, GeminiGenerateContent, Human, type InferenceInput, type InferenceOutput, type InferenceRunner, type InferenceRunnerConfig, InputTokenDetails, McpClient, type McpServerConfig, McpToolRegistry, type McpToolSpec, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIChatCompletions, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, RuntimeState, SemanticEvent, type SituationContext, type SituationHandler, type SituationProcessor, SituationSpecification, type StructuredOutputFormat, SystemMessageItem, TokenUsage, type Tool, UserMessageItem, createAgent, createHuman, defineRuntime, supportedModels };
628
+ export { Agent, AnthropicMessages, ContextItem, DefaultInferenceRunner, DeveloperMessageItem, type Endpoint, type ExecutableLoopStateId, type ExecutableTransition, FunctionCallItem, FunctionCallOutputItem, GeminiGenerateContent, Human, type InferenceInput, type InferenceOutput, type InferenceRunner, type InferenceRunnerConfig, InputTokenDetails, type InterceptionHandler, type LoopStateExecution, type LoopTransition, McpClient, type McpServerConfig, McpToolRegistry, type McpToolSpec, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIChatCompletions, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, RuntimeState, SemanticEvent, type SituationContext, type SituationHandler, type SituationProcessor, SituationSpecification, type StructuredOutputFormat, SystemMessageItem, TokenUsage, type Tool, UserMessageItem, createAgent, createHuman, defineRuntime, supportedModels };
package/dist/index.d.ts CHANGED
@@ -186,6 +186,24 @@ interface FunctionCallParams {
186
186
  inferenceInput: InferenceInput;
187
187
  }
188
188
 
189
+ interface InterceptionHandler {
190
+ isSatisfiedBy(transition: ExecutableTransition): boolean;
191
+ handle(transition: ExecutableTransition): Promise<ExecutableTransition>;
192
+ }
193
+ type InterceptionOutput = {
194
+ type: "continue";
195
+ transition: LoopTransition;
196
+ } | {
197
+ type: "pause";
198
+ pendingTransition: LoopTransition;
199
+ } | {
200
+ type: "stop";
201
+ reason?: string;
202
+ };
203
+ interface InterceptionParams {
204
+ pendingTransition: LoopTransition;
205
+ }
206
+
189
207
  type LoopStateId = "context_update" | "inference" | "inference_streaming" | "function_call" | "model_message" | "idle";
190
208
  type ReceivedMessage = {
191
209
  content: string;
@@ -227,19 +245,15 @@ interface LoopStateContract {
227
245
  output: void;
228
246
  };
229
247
  }
230
- type InterceptionOutput = {
231
- type: "continue";
232
- transition: LoopTransition;
233
- } | {
234
- type: "pause";
235
- pendingTransition: LoopTransition;
236
- } | {
237
- type: "stop";
238
- reason?: string;
239
- };
240
- interface InterceptionParams {
241
- pendingTransition: LoopTransition;
242
- }
248
+ type ExecutableLoopStateId = Exclude<LoopStateId, "idle">;
249
+ type ExecutableTransition = LoopTransition<ExecutableLoopStateId>;
250
+ type LoopStateExecution<TStateId extends ExecutableLoopStateId = ExecutableLoopStateId> = {
251
+ [K in TStateId]: {
252
+ stateId: K;
253
+ input: LoopStateContract[K]["input"];
254
+ output: LoopStateContract[K]["output"];
255
+ };
256
+ }[TStateId];
243
257
  type LoopTransition<TStateId extends LoopStateId = LoopStateId> = {
244
258
  [K in TStateId]: {
245
259
  nextStateId: K;
@@ -247,6 +261,23 @@ type LoopTransition<TStateId extends LoopStateId = LoopStateId> = {
247
261
  };
248
262
  }[TStateId];
249
263
 
264
+ declare class InputTokenDetails {
265
+ readonly cached_tokens: number;
266
+ constructor(cached_tokens: number);
267
+ }
268
+ declare class OutputTokenDetails {
269
+ readonly reasoning_tokens: number;
270
+ constructor(reasoning_tokens: number);
271
+ }
272
+ declare class TokenUsage {
273
+ readonly inputTokens: number;
274
+ readonly outputTokens: number;
275
+ readonly totalTokens: number;
276
+ readonly inputTokenDetails: InputTokenDetails;
277
+ readonly outputTokenDetails: OutputTokenDetails;
278
+ constructor(inputTokens: number, outputTokens: number, totalTokens: number, inputTokenDetails: InputTokenDetails, outputTokenDetails: OutputTokenDetails);
279
+ }
280
+
250
281
  type InferenceInput = {
251
282
  model: string;
252
283
  maxOutputTokens?: number;
@@ -259,6 +290,7 @@ type InferenceInput = {
259
290
  type InferenceItem = FunctionCallItem | ReasoningItem | ModelMessageItem;
260
291
  type InferenceOutput = {
261
292
  items: InferenceItem[];
293
+ tokenUsage: TokenUsage | undefined;
262
294
  rowResponse: any;
263
295
  };
264
296
  interface InferenceRunner {
@@ -311,23 +343,6 @@ interface ModelContextRepository {
311
343
  getByProjectId(projectId: string): Promise<ModelContext[]>;
312
344
  }
313
345
 
314
- declare class InputTokenDetails {
315
- readonly cached_tokens: number;
316
- constructor(cached_tokens: number);
317
- }
318
- declare class OutputTokenDetails {
319
- readonly reasoning_tokens: number;
320
- constructor(reasoning_tokens: number);
321
- }
322
- declare class TokenUsage {
323
- readonly inputTokens: number;
324
- readonly outputTokens: number;
325
- readonly totalTokens: number;
326
- readonly inputTokenDetails: InputTokenDetails;
327
- readonly outputTokenDetails: OutputTokenDetails;
328
- constructor(inputTokens: number, outputTokens: number, totalTokens: number, inputTokenDetails: InputTokenDetails, outputTokenDetails: OutputTokenDetails);
329
- }
330
-
331
346
  interface McpServerConfig {
332
347
  /** The MCP server URL, e.g. https://api.githubcopilot.com/mcp/ */
333
348
  url: string;
@@ -459,11 +474,6 @@ declare abstract class RuntimeState {
459
474
  getParticipants(): readonly Participant[];
460
475
  }
461
476
 
462
- interface InterceptionHandler {
463
- isSatisfiedBy(transition: LoopTransition): boolean;
464
- handle(transition: LoopTransition): Promise<LoopTransition>;
465
- }
466
-
467
477
  declare class EventProcessor {
468
478
  process(event: SemanticEvent, consumer: Participant): void;
469
479
  }
@@ -497,7 +507,7 @@ declare function defineRuntime<TRuntimeState extends RuntimeState>(): {
497
507
  leave: (participant: Participant) => void;
498
508
  sendMessage: (message: string, senderId: string) => void;
499
509
  sendEvent: (event: SemanticEvent, senderId: string) => void;
500
- runLoop: (agentId: string, message: string, inferenceInput: InferenceInput, interceptionHandler: InterceptionHandler) => void;
510
+ runLoop: (agentId: string, message: string, inferenceInput: InferenceInput, interceptionHandler?: InterceptionHandler) => void;
501
511
  };
502
512
 
503
513
  declare const supportedModels: GenerativeModel[];
@@ -615,4 +625,4 @@ declare class DefaultInferenceRunner implements InferenceRunner {
615
625
  stream(input: InferenceInput): AsyncGenerator<SemanticEvent>;
616
626
  }
617
627
 
618
- export { Agent, AnthropicMessages, ContextItem, DefaultInferenceRunner, DeveloperMessageItem, type Endpoint, FunctionCallItem, FunctionCallOutputItem, GeminiGenerateContent, Human, type InferenceInput, type InferenceOutput, type InferenceRunner, type InferenceRunnerConfig, InputTokenDetails, McpClient, type McpServerConfig, McpToolRegistry, type McpToolSpec, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIChatCompletions, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, RuntimeState, SemanticEvent, type SituationContext, type SituationHandler, type SituationProcessor, SituationSpecification, type StructuredOutputFormat, SystemMessageItem, TokenUsage, type Tool, UserMessageItem, createAgent, createHuman, defineRuntime, supportedModels };
628
+ export { Agent, AnthropicMessages, ContextItem, DefaultInferenceRunner, DeveloperMessageItem, type Endpoint, type ExecutableLoopStateId, type ExecutableTransition, FunctionCallItem, FunctionCallOutputItem, GeminiGenerateContent, Human, type InferenceInput, type InferenceOutput, type InferenceRunner, type InferenceRunnerConfig, InputTokenDetails, type InterceptionHandler, type LoopStateExecution, type LoopTransition, McpClient, type McpServerConfig, McpToolRegistry, type McpToolSpec, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIChatCompletions, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, RuntimeState, SemanticEvent, type SituationContext, type SituationHandler, type SituationProcessor, SituationSpecification, type StructuredOutputFormat, SystemMessageItem, TokenUsage, type Tool, UserMessageItem, createAgent, createHuman, defineRuntime, supportedModels };
package/dist/index.js CHANGED
@@ -622,20 +622,20 @@ var AgentLoop = class _AgentLoop {
622
622
  this.interceptionHandler = interceptionHandler;
623
623
  }
624
624
  async run(message, loopVisitor) {
625
+ var _a;
625
626
  let transition = {
626
627
  nextStateId: "context_update",
627
628
  input: message
628
629
  };
629
630
  while (transition.nextStateId !== "idle") {
630
- const isInterceptionSatisfied = this.interceptionHandler.isSatisfiedBy(transition);
631
- if (isInterceptionSatisfied) {
631
+ const isInterceptionSatisfied = (_a = this.interceptionHandler) == null ? void 0 : _a.isSatisfiedBy(transition);
632
+ if (isInterceptionSatisfied && this.interceptionHandler) {
632
633
  loopVisitor.visitInterceptionStarted(transition);
633
634
  transition = await this.interceptionHandler.handle(transition);
634
635
  loopVisitor.visitInterceptionFinished(transition);
635
- } else {
636
- const execution = await this.stateExecutor.execute(transition, loopVisitor);
637
- transition = this.transitionResolver.resolve(execution);
638
636
  }
637
+ const execution = await this.stateExecutor.execute(transition, loopVisitor);
638
+ transition = this.transitionResolver.resolve(execution);
639
639
  }
640
640
  }
641
641
  getLoopId() {
@@ -1007,7 +1007,7 @@ var AnthropicMessagesMapper = class {
1007
1007
  if (inferenceInput.structuredOutput) {
1008
1008
  outputConfig.format = {
1009
1009
  type: "json_schema",
1010
- json_schema: inferenceInput.structuredOutput.schema
1010
+ schema: inferenceInput.structuredOutput.schema
1011
1011
  };
1012
1012
  }
1013
1013
  if (inferenceInput.reasoningEffort) {
@@ -1130,7 +1130,7 @@ var AnthropicMessagesMapper = class {
1130
1130
  );
1131
1131
  }
1132
1132
  }
1133
- return { items, rowResponse: response };
1133
+ return { items, tokenUsage: this.extractTokenUsage(response), rowResponse: response };
1134
1134
  }
1135
1135
  };
1136
1136
 
@@ -1318,6 +1318,7 @@ var OpenAIResponsesMapper = class {
1318
1318
  }
1319
1319
  return {
1320
1320
  items,
1321
+ tokenUsage: this.extractTokenUsage(response),
1321
1322
  rowResponse: response
1322
1323
  };
1323
1324
  }
@@ -1506,7 +1507,7 @@ var GeminiGenerateContentMapper = class {
1506
1507
  );
1507
1508
  }
1508
1509
  }
1509
- return { items, rowResponse: response };
1510
+ return { items, tokenUsage: this.extractTokenUsage(response), rowResponse: response };
1510
1511
  }
1511
1512
  };
1512
1513
 
@@ -1629,7 +1630,7 @@ var OpenAIChatCompletionsMapper = class {
1629
1630
  const items = [];
1630
1631
  const message = (_b = (_a = response.choices) == null ? void 0 : _a[0]) == null ? void 0 : _b.message;
1631
1632
  if (!message) {
1632
- return { items: [], rowResponse: response };
1633
+ return { items: [], tokenUsage: this.extractTokenUsage(response), rowResponse: response };
1633
1634
  }
1634
1635
  if (message.reasoning_content) {
1635
1636
  items.push(
@@ -1652,7 +1653,7 @@ var OpenAIChatCompletionsMapper = class {
1652
1653
  })
1653
1654
  );
1654
1655
  }
1655
- return { items, rowResponse: response };
1656
+ return { items, tokenUsage: this.extractTokenUsage(response), rowResponse: response };
1656
1657
  }
1657
1658
  };
1658
1659