@mozaik-ai/core 2.13.8 → 3.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Mozaik
2
2
 
3
- **Mozaik** is a TypeScript library for building, managing, and evolving **LLM context**.
3
+ **Mozaik** is a TypeScript framework for building controllable multi-step AI agents.
4
4
 
5
5
  Instead of focusing on agents themselves, Mozaik provides a structured way to **model, manipulate, persist, and restore the context** that drives language model behavior. It implements a clean object model aligned with the **OpenResponses specification**, enabling developers to work with LLM inputs and outputs as composable, typed entities.
6
6
 
package/dist/index.d.mts CHANGED
@@ -23,11 +23,11 @@ declare class Context {
23
23
  toJSON(): any;
24
24
  }
25
25
 
26
- declare abstract class Content {
26
+ declare abstract class ItemContent {
27
27
  abstract readonly type: string;
28
28
  }
29
29
 
30
- declare class InputText extends Content {
30
+ declare class InputText extends ItemContent {
31
31
  readonly text: string;
32
32
  readonly type = "input_text";
33
33
  private constructor();
@@ -62,7 +62,7 @@ declare class DeveloperMessage extends ContextItem {
62
62
  }): DeveloperMessage;
63
63
  }
64
64
 
65
- declare class OutputText extends Content {
65
+ declare class OutputText extends ItemContent {
66
66
  readonly text: string;
67
67
  readonly type = "output_text";
68
68
  private constructor();
@@ -97,7 +97,7 @@ declare class FunctionCall extends ContextItem {
97
97
  toJSON(): any;
98
98
  }
99
99
 
100
- declare class SummaryText extends Content {
100
+ declare class SummaryText extends ItemContent {
101
101
  readonly text: string;
102
102
  readonly type = "summary_text";
103
103
  private constructor();
@@ -290,11 +290,6 @@ interface Action<T> {
290
290
  interface AsyncAction<T> {
291
291
  apply(candidate: T): Promise<T>;
292
292
  }
293
- interface Rule<T> {
294
- condition: Condition<T>;
295
- action: AsyncAction<T>;
296
- apply(candidate: T): T;
297
- }
298
293
  interface AsyncRule<T> {
299
294
  condition: Condition<T>;
300
295
  action: AsyncAction<T>;
@@ -328,4 +323,87 @@ declare class InMemoryContextRepository implements ContextRepository {
328
323
  private clone;
329
324
  }
330
325
 
331
- export { type Action, type AsyncAction, type AsyncRule, BaseCondition, type Condition, Context, ContextItem, type ContextRepository, DeveloperMessage, FunctionCall, FunctionCallOutput, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, If, InMemoryContextRepository, InferenceRequest, InferenceResponse, InputTokenDetails, Loop, ModelMessage, OpenAIResponses, OutputTokenDetails, Reasoning, type Rule, TokenUsage, type Tool, UserMessage };
326
+ declare enum HookId {
327
+ BEFORE_INFERENCE = "BEFORE_INFERENCE",
328
+ AFTER_INFERENCE = "AFTER_INFERENCE",
329
+ BEFORE_FUNCTION_CALL = "BEFORE_FUNCTION_CALL",
330
+ AFTER_FUNCTION_CALL = "AFTER_FUNCTION_CALL",
331
+ BEFORE_MODEL_MESSAGE = "BEFORE_MODEL_MESSAGE",
332
+ AFTER_MODEL_MESSAGE = "AFTER_MODEL_MESSAGE"
333
+ }
334
+
335
+ interface TransitionRecord {
336
+ fromState: StateId;
337
+ toState: StateId;
338
+ timestamp: Date;
339
+ duration: number;
340
+ error: Error | null;
341
+ }
342
+
343
+ declare enum StateId {
344
+ INFERENCE_PENDING = "INFERENCE_PENDING",
345
+ FUNCTION_CALL_PENDING = "FUNCTION_CALL_PENDING",
346
+ MODEL_MESSAGE_RECEIVED = "MODEL_MESSAGE_RECEIVED"
347
+ }
348
+
349
+ declare enum ExecutionStatus {
350
+ RUNNING = 0,
351
+ COMPLETED = 1,
352
+ FAILED = 2
353
+ }
354
+ declare class Execution {
355
+ executionId: string;
356
+ currentStateId: StateId;
357
+ previousStateId: StateId | null;
358
+ status: ExecutionStatus;
359
+ stepCount: number;
360
+ retryCounts: Map<StateId, number>;
361
+ history: TransitionRecord[];
362
+ constructor(executionId: string, currentStateId: StateId, previousStateId: StateId | null, status: ExecutionStatus, stepCount: number, retryCounts: Map<StateId, number>, history: TransitionRecord[]);
363
+ isTerminal(): boolean;
364
+ static create(): Execution;
365
+ }
366
+
367
+ interface RuntimeContext {
368
+ execution: Execution;
369
+ userMessage: UserMessage;
370
+ inferenceRequest?: InferenceRequest;
371
+ model: GenerativeModel & ReasoningEffort<string> & ToolCallingCapability;
372
+ context: Context;
373
+ inferenceResponse?: InferenceResponse;
374
+ functionCallOutput?: FunctionCallOutput;
375
+ modelMessage?: ModelMessage;
376
+ }
377
+
378
+ declare class AgentRuntime {
379
+ private hooksRegistry;
380
+ private stateHandlerRegistry;
381
+ constructor();
382
+ onInferencePending(context: RuntimeContext): Promise<void>;
383
+ onFunctionCallPending(context: RuntimeContext): Promise<void>;
384
+ onModelMessageReceived(context: RuntimeContext): Promise<void>;
385
+ on(hookId: HookId, callback: (data: any) => Promise<void>): Promise<void>;
386
+ start(userMessage: UserMessage, model: GenerativeModel & ReasoningEffort<string> & ToolCallingCapability, context: Context): Promise<void>;
387
+ }
388
+
389
+ interface InferenceVisitor {
390
+ onStart(context: RuntimeContext): Promise<void>;
391
+ afterInference(inferenceResponse: InferenceResponse): Promise<void>;
392
+ }
393
+
394
+ declare class Agent {
395
+ private readonly runtime;
396
+ private visitor;
397
+ constructor(runtime: AgentRuntime);
398
+ beforeInference(context: RuntimeContext): Promise<void>;
399
+ afterInference(context: RuntimeContext): Promise<void>;
400
+ beforeFunctionCall(context: RuntimeContext): Promise<void>;
401
+ afterFunctionCall(context: RuntimeContext): Promise<void>;
402
+ beforeModelMessage(context: RuntimeContext): Promise<void>;
403
+ afterModelMessage(context: RuntimeContext): Promise<void>;
404
+ onStart(context: RuntimeContext): Promise<void>;
405
+ setInferenceVisitor(visitor: InferenceVisitor): void;
406
+ run(userMessage: string, model: GenerativeModel & ReasoningEffort<string> & ToolCallingCapability, context: Context): Promise<void>;
407
+ }
408
+
409
+ export { type Action, Agent, AgentRuntime, type AsyncAction, type AsyncRule, BaseCondition, type Condition, Context, ContextItem, type ContextRepository, DeveloperMessage, FunctionCall, FunctionCallOutput, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, If, InMemoryContextRepository, InferenceRequest, InferenceResponse, type InferenceVisitor, InputTokenDetails, Loop, ModelMessage, OpenAIResponses, OutputTokenDetails, Reasoning, TokenUsage, type Tool, UserMessage };
package/dist/index.d.ts CHANGED
@@ -23,11 +23,11 @@ declare class Context {
23
23
  toJSON(): any;
24
24
  }
25
25
 
26
- declare abstract class Content {
26
+ declare abstract class ItemContent {
27
27
  abstract readonly type: string;
28
28
  }
29
29
 
30
- declare class InputText extends Content {
30
+ declare class InputText extends ItemContent {
31
31
  readonly text: string;
32
32
  readonly type = "input_text";
33
33
  private constructor();
@@ -62,7 +62,7 @@ declare class DeveloperMessage extends ContextItem {
62
62
  }): DeveloperMessage;
63
63
  }
64
64
 
65
- declare class OutputText extends Content {
65
+ declare class OutputText extends ItemContent {
66
66
  readonly text: string;
67
67
  readonly type = "output_text";
68
68
  private constructor();
@@ -97,7 +97,7 @@ declare class FunctionCall extends ContextItem {
97
97
  toJSON(): any;
98
98
  }
99
99
 
100
- declare class SummaryText extends Content {
100
+ declare class SummaryText extends ItemContent {
101
101
  readonly text: string;
102
102
  readonly type = "summary_text";
103
103
  private constructor();
@@ -290,11 +290,6 @@ interface Action<T> {
290
290
  interface AsyncAction<T> {
291
291
  apply(candidate: T): Promise<T>;
292
292
  }
293
- interface Rule<T> {
294
- condition: Condition<T>;
295
- action: AsyncAction<T>;
296
- apply(candidate: T): T;
297
- }
298
293
  interface AsyncRule<T> {
299
294
  condition: Condition<T>;
300
295
  action: AsyncAction<T>;
@@ -328,4 +323,87 @@ declare class InMemoryContextRepository implements ContextRepository {
328
323
  private clone;
329
324
  }
330
325
 
331
- export { type Action, type AsyncAction, type AsyncRule, BaseCondition, type Condition, Context, ContextItem, type ContextRepository, DeveloperMessage, FunctionCall, FunctionCallOutput, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, If, InMemoryContextRepository, InferenceRequest, InferenceResponse, InputTokenDetails, Loop, ModelMessage, OpenAIResponses, OutputTokenDetails, Reasoning, type Rule, TokenUsage, type Tool, UserMessage };
326
+ declare enum HookId {
327
+ BEFORE_INFERENCE = "BEFORE_INFERENCE",
328
+ AFTER_INFERENCE = "AFTER_INFERENCE",
329
+ BEFORE_FUNCTION_CALL = "BEFORE_FUNCTION_CALL",
330
+ AFTER_FUNCTION_CALL = "AFTER_FUNCTION_CALL",
331
+ BEFORE_MODEL_MESSAGE = "BEFORE_MODEL_MESSAGE",
332
+ AFTER_MODEL_MESSAGE = "AFTER_MODEL_MESSAGE"
333
+ }
334
+
335
+ interface TransitionRecord {
336
+ fromState: StateId;
337
+ toState: StateId;
338
+ timestamp: Date;
339
+ duration: number;
340
+ error: Error | null;
341
+ }
342
+
343
+ declare enum StateId {
344
+ INFERENCE_PENDING = "INFERENCE_PENDING",
345
+ FUNCTION_CALL_PENDING = "FUNCTION_CALL_PENDING",
346
+ MODEL_MESSAGE_RECEIVED = "MODEL_MESSAGE_RECEIVED"
347
+ }
348
+
349
+ declare enum ExecutionStatus {
350
+ RUNNING = 0,
351
+ COMPLETED = 1,
352
+ FAILED = 2
353
+ }
354
+ declare class Execution {
355
+ executionId: string;
356
+ currentStateId: StateId;
357
+ previousStateId: StateId | null;
358
+ status: ExecutionStatus;
359
+ stepCount: number;
360
+ retryCounts: Map<StateId, number>;
361
+ history: TransitionRecord[];
362
+ constructor(executionId: string, currentStateId: StateId, previousStateId: StateId | null, status: ExecutionStatus, stepCount: number, retryCounts: Map<StateId, number>, history: TransitionRecord[]);
363
+ isTerminal(): boolean;
364
+ static create(): Execution;
365
+ }
366
+
367
+ interface RuntimeContext {
368
+ execution: Execution;
369
+ userMessage: UserMessage;
370
+ inferenceRequest?: InferenceRequest;
371
+ model: GenerativeModel & ReasoningEffort<string> & ToolCallingCapability;
372
+ context: Context;
373
+ inferenceResponse?: InferenceResponse;
374
+ functionCallOutput?: FunctionCallOutput;
375
+ modelMessage?: ModelMessage;
376
+ }
377
+
378
+ declare class AgentRuntime {
379
+ private hooksRegistry;
380
+ private stateHandlerRegistry;
381
+ constructor();
382
+ onInferencePending(context: RuntimeContext): Promise<void>;
383
+ onFunctionCallPending(context: RuntimeContext): Promise<void>;
384
+ onModelMessageReceived(context: RuntimeContext): Promise<void>;
385
+ on(hookId: HookId, callback: (data: any) => Promise<void>): Promise<void>;
386
+ start(userMessage: UserMessage, model: GenerativeModel & ReasoningEffort<string> & ToolCallingCapability, context: Context): Promise<void>;
387
+ }
388
+
389
+ interface InferenceVisitor {
390
+ onStart(context: RuntimeContext): Promise<void>;
391
+ afterInference(inferenceResponse: InferenceResponse): Promise<void>;
392
+ }
393
+
394
+ declare class Agent {
395
+ private readonly runtime;
396
+ private visitor;
397
+ constructor(runtime: AgentRuntime);
398
+ beforeInference(context: RuntimeContext): Promise<void>;
399
+ afterInference(context: RuntimeContext): Promise<void>;
400
+ beforeFunctionCall(context: RuntimeContext): Promise<void>;
401
+ afterFunctionCall(context: RuntimeContext): Promise<void>;
402
+ beforeModelMessage(context: RuntimeContext): Promise<void>;
403
+ afterModelMessage(context: RuntimeContext): Promise<void>;
404
+ onStart(context: RuntimeContext): Promise<void>;
405
+ setInferenceVisitor(visitor: InferenceVisitor): void;
406
+ run(userMessage: string, model: GenerativeModel & ReasoningEffort<string> & ToolCallingCapability, context: Context): Promise<void>;
407
+ }
408
+
409
+ export { type Action, Agent, AgentRuntime, type AsyncAction, type AsyncRule, BaseCondition, type Condition, Context, ContextItem, type ContextRepository, DeveloperMessage, FunctionCall, FunctionCallOutput, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, If, InMemoryContextRepository, InferenceRequest, InferenceResponse, type InferenceVisitor, InputTokenDetails, Loop, ModelMessage, OpenAIResponses, OutputTokenDetails, Reasoning, TokenUsage, type Tool, UserMessage };