@mozaik-ai/core 4.0.0-beta.1 → 4.0.0-beta.10

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,15 +1,23 @@
1
1
  <div align="center">
2
2
  <h1>Mozaik</h1>
3
- <p>TypeScript runtime for concurrent AI agents</p>
4
-
5
- <img width="150" height="150" alt="mozaik-avatar-dark" src="https://github.com/user-attachments/assets/e832c359-0581-42f7-96f3-d6e221c5af95" />
3
+ <p>Mozaik is a TypeScript runtime for interoperable AI agents.</p>
6
4
 
7
5
  ![npm downloads](https://img.shields.io/npm/dt/@mozaik-ai/core) ![npm downloads weekly](https://img.shields.io/npm/dw/@mozaik-ai/core) ![npm version](https://img.shields.io/npm/v/@mozaik-ai/core)
8
6
 
9
- Mozaik is a TypeScript runtime for non-blocking AI agents that work independently, communicate through semantic events, and coordinate without predefined workflows.
7
+ <img width="512" height="512" alt="agent-interoperability" src="https://github.com/user-attachments/assets/4b24bf27-afe2-4520-a396-5c46da6dab17" />
10
8
 
11
9
  </div>
12
10
 
11
+ ## Agent Interoperability
12
+
13
+ Our main goal is to unlock agent interoperability across projects, so Mozaik is built around three core attributes:
14
+
15
+ - **Concurrency** - Agents work independently without blocking one another.
16
+ - **Awareness** - Agents understand other participants, events, and their shared environment.
17
+ - **Adaptivity** - Agents change their behavior based on runtime state and emerging needs.
18
+
19
+ Together, these capabilities free AI agents from specific harnesses, allowing them to work across projects - so every newly created agent adds value to the entire ecosystem.
20
+
13
21
  ---
14
22
 
15
23
  ## Installation
package/dist/index.d.mts CHANGED
@@ -129,6 +129,46 @@ interface FunctionTool {
129
129
  }
130
130
  type Tool = FunctionTool;
131
131
 
132
+ type SituationContext$1<TEvent extends SemanticEvent = SemanticEvent> = {
133
+ readonly event: TEvent;
134
+ readonly participant: Participant;
135
+ };
136
+ declare abstract class SituationSpecification<TEvent extends SemanticEvent = SemanticEvent> {
137
+ abstract isSatisfiedBy(situationContext: SituationContext$1<TEvent>): boolean;
138
+ and(other: SituationSpecification<TEvent>): SituationSpecification<TEvent>;
139
+ or(other: SituationSpecification<TEvent>): SituationSpecification<TEvent>;
140
+ not(): SituationSpecification<TEvent>;
141
+ }
142
+
143
+ interface SituationHandler {
144
+ readonly specification: SituationSpecification;
145
+ readonly processor: SituationProcessor;
146
+ }
147
+ type SituationContext<TEvent extends SemanticEvent = SemanticEvent> = {
148
+ readonly event: TEvent;
149
+ readonly participant: Participant;
150
+ };
151
+ interface SituationProcessor {
152
+ apply(context: SituationContext): void | Promise<void>;
153
+ }
154
+
155
+ type ParticipantRole = "agent" | "human";
156
+ type ParticipantManifest = {
157
+ readonly id: string;
158
+ readonly name: string;
159
+ readonly role: ParticipantRole;
160
+ readonly capabilities?: readonly string[];
161
+ };
162
+ declare abstract class Participant {
163
+ private readonly manifest;
164
+ private handlers;
165
+ protected constructor(manifest: ParticipantManifest, handlers: SituationHandler[]);
166
+ getManifest(): ParticipantManifest;
167
+ getId(): string;
168
+ getHandlers(): SituationHandler[];
169
+ setHandlers(handlers: SituationHandler[]): void;
170
+ }
171
+
132
172
  declare class SemanticEvent<TType extends string = string, TPayload = unknown> {
133
173
  readonly type: TType;
134
174
  readonly producerId: string;
@@ -141,6 +181,71 @@ declare class SemanticEvent<TType extends string = string, TPayload = unknown> {
141
181
  interface FunctionCallRunner {
142
182
  run(call: FunctionCallItem, tool: Tool): Promise<FunctionCallOutputItem>;
143
183
  }
184
+ interface FunctionCallParams {
185
+ call: FunctionCallItem;
186
+ inferenceInput: InferenceInput;
187
+ }
188
+
189
+ type LoopStateId = "context_update" | "inference" | "inference_streaming" | "function_call" | "model_message" | "idle";
190
+ type ReceivedMessage = {
191
+ content: string;
192
+ input: InferenceInput;
193
+ };
194
+ interface FunctionCallExecutionOutput {
195
+ item: FunctionCallOutputItem;
196
+ }
197
+ interface ModelMessageParams {
198
+ answer: ModelMessageItem;
199
+ }
200
+ interface LoopStateContract {
201
+ context_update: {
202
+ input: ReceivedMessage;
203
+ output: InferenceInput;
204
+ };
205
+ inference: {
206
+ input: InferenceInput;
207
+ output: InferenceOutput;
208
+ };
209
+ inference_streaming: {
210
+ input: InferenceInput;
211
+ output: InferenceOutput;
212
+ };
213
+ function_call: {
214
+ input: FunctionCallParams;
215
+ output: FunctionCallExecutionOutput;
216
+ };
217
+ model_message: {
218
+ input: ModelMessageParams;
219
+ output: void;
220
+ };
221
+ interception: {
222
+ input: InterceptionParams;
223
+ output: InterceptionOutput;
224
+ };
225
+ idle: {
226
+ input: undefined;
227
+ output: void;
228
+ };
229
+ }
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
+ }
243
+ type LoopTransition<TStateId extends LoopStateId = LoopStateId> = {
244
+ [K in TStateId]: {
245
+ nextStateId: K;
246
+ input: LoopStateContract[K]["input"];
247
+ };
248
+ }[TStateId];
144
249
 
145
250
  type InferenceInput = {
146
251
  model: string;
@@ -158,6 +263,7 @@ type InferenceOutput = {
158
263
  };
159
264
  interface InferenceRunner {
160
265
  run(request: InferenceInput): Promise<InferenceOutput>;
266
+ stream(request: InferenceInput): AsyncGenerator<SemanticEvent>;
161
267
  }
162
268
 
163
269
  interface InferenceEndpointMapper {
@@ -188,6 +294,11 @@ type ModelSpecification = {
188
294
  supportsStructuredOutput: boolean;
189
295
  };
190
296
 
297
+ interface RequestValidationRule {
298
+ readonly name: string;
299
+ isValid(inferenceInput: InferenceInput, model: ModelSpecification): boolean;
300
+ }
301
+
191
302
  type StructuredOutputFormat = {
192
303
  name?: string;
193
304
  schema: Record<string, any>;
@@ -293,45 +404,6 @@ declare class SystemMessageItem extends ContextItem {
293
404
  }): SystemMessageItem;
294
405
  }
295
406
 
296
- type SituationContext$1<TEvent extends SemanticEvent = SemanticEvent> = {
297
- readonly event: TEvent;
298
- readonly participant: Participant;
299
- };
300
- declare abstract class SituationSpecification<TEvent extends SemanticEvent = SemanticEvent> {
301
- abstract isSatisfiedBy(situationContext: SituationContext$1<TEvent>): boolean;
302
- and(other: SituationSpecification<TEvent>): SituationSpecification<TEvent>;
303
- or(other: SituationSpecification<TEvent>): SituationSpecification<TEvent>;
304
- not(): SituationSpecification<TEvent>;
305
- }
306
-
307
- interface SituationHandler {
308
- readonly specification: SituationSpecification;
309
- readonly processor: SituationProcessor;
310
- }
311
- type SituationContext<TEvent extends SemanticEvent = SemanticEvent> = {
312
- readonly event: TEvent;
313
- readonly participant: Participant;
314
- };
315
- interface SituationProcessor {
316
- apply(context: SituationContext): void | Promise<void>;
317
- }
318
-
319
- type ParticipantRole = "agent" | "human";
320
- type ParticipantManifest = {
321
- readonly id: string;
322
- readonly name: string;
323
- readonly role: ParticipantRole;
324
- readonly capabilities?: readonly string[];
325
- };
326
- declare abstract class Participant {
327
- private readonly manifest;
328
- private handlers;
329
- protected constructor(manifest: ParticipantManifest, handlers: SituationHandler[]);
330
- getManifest(): ParticipantManifest;
331
- getId(): string;
332
- getHandlers(): SituationHandler[];
333
- }
334
-
335
407
  declare class Memory {
336
408
  private readonly context;
337
409
  private constructor();
@@ -387,6 +459,11 @@ declare abstract class RuntimeState {
387
459
  getParticipants(): readonly Participant[];
388
460
  }
389
461
 
462
+ interface InterceptionHandler {
463
+ isSatisfiedBy(transition: LoopTransition): boolean;
464
+ handle(transition: LoopTransition): Promise<LoopTransition>;
465
+ }
466
+
390
467
  declare class EventProcessor {
391
468
  process(event: SemanticEvent, consumer: Participant): void;
392
469
  }
@@ -406,8 +483,8 @@ declare class RuntimeService<TRuntimeState extends RuntimeState> {
406
483
  }
407
484
 
408
485
  type InferenceRunnerConfig = {
409
- supportedModels: GenerativeModel[];
410
- runner: InferenceRunner;
486
+ supportedModels?: GenerativeModel[];
487
+ runner?: InferenceRunner;
411
488
  };
412
489
  declare function defineRuntime<TRuntimeState extends RuntimeState>(): {
413
490
  initializeRuntime: (config: {
@@ -419,7 +496,123 @@ declare function defineRuntime<TRuntimeState extends RuntimeState>(): {
419
496
  join: (participant: Participant) => void;
420
497
  leave: (participant: Participant) => void;
421
498
  sendMessage: (message: string, senderId: string) => void;
422
- runLoop: (agentId: string, message: string, inferenceInput: InferenceInput) => void;
499
+ sendEvent: (event: SemanticEvent, senderId: string) => void;
500
+ runLoop: (agentId: string, message: string, inferenceInput: InferenceInput, interceptionHandler?: InterceptionHandler) => void;
423
501
  };
424
502
 
425
- export { ContextItem, DeveloperMessageItem, type Endpoint, FunctionCallItem, FunctionCallOutputItem, type InferenceInput, type InferenceOutput, InputTokenDetails, McpClient, type McpServerConfig, McpToolRegistry, type McpToolSpec, ModelContext, type ModelContextRepository, ModelMessageItem, OutputTokenDetails, Participant, ReasoningItem, RuntimeState, SemanticEvent, type StructuredOutputFormat, SystemMessageItem, TokenUsage, type Tool, UserMessageItem, createAgent, createHuman, defineRuntime };
503
+ declare const supportedModels: GenerativeModel[];
504
+
505
+ declare class OpenAIResponses implements Endpoint {
506
+ endpointMapper: InferenceEndpointMapper;
507
+ private _client?;
508
+ constructor(endpointMapper?: InferenceEndpointMapper);
509
+ private get client();
510
+ infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
511
+ stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
512
+ }
513
+
514
+ /**
515
+ * Optional connection config. When omitted, the `openai` SDK reads
516
+ * `OPENAI_API_KEY` and `OPENAI_BASE_URL` from the environment, so the
517
+ * default-constructed runtime targets whatever `OPENAI_BASE_URL` points
518
+ * at (real OpenAI when unset). Provider presets (e.g. DeepSeek) pass an
519
+ * explicit base URL + credential.
520
+ */
521
+ interface OpenAICompatibleConfig {
522
+ baseURL?: string;
523
+ apiKey?: string;
524
+ /**
525
+ * Extra request-body fields merged into every `chat.completions`
526
+ * call. This is how provider-specific quirks are handled **without
527
+ * a per-provider subclass in mozaik** — the consumer supplies the
528
+ * vendor-only fields (e.g. DeepSeek's `{ thinking: { type } }`,
529
+ * safety flags, routing hints). Standard fields the runtime already
530
+ * sets (`model`, `messages`, `tools`, `reasoning_effort`) take
531
+ * precedence and are not overwritten.
532
+ */
533
+ extraBody?: Record<string, unknown>;
534
+ }
535
+ /**
536
+ * Generic adapter for any **OpenAI Chat Completions**-compatible
537
+ * endpoint — real OpenAI, DeepSeek, Xiaomi MiMo, OpenRouter, vLLM,
538
+ * Ollama, etc. It speaks `/chat/completions` (not the Responses API),
539
+ * which is the dialect third-party OpenAI-compatible providers expose.
540
+ *
541
+ * The base URL and credential are configurable; everything else (the
542
+ * `ModelContext` ⇄ chat-message conversion, tool-call round-trip, token
543
+ * usage extraction) is provider-agnostic. Provider-specific request
544
+ * shaping (e.g. DeepSeek's `thinking` field) is supplied by the
545
+ * consumer via {@link OpenAICompatibleConfig.extraBody} — mozaik stays
546
+ * generic and gains no per-provider subclasses.
547
+ *
548
+ * Was `DeepSeekChatCompletions`; generalized so consumers can point it
549
+ * at any OpenAI-compatible endpoint.
550
+ */
551
+ declare class OpenAIChatCompletions implements Endpoint {
552
+ endpointMapper: InferenceEndpointMapper;
553
+ private _client?;
554
+ private readonly clientConfig;
555
+ private readonly extraBody;
556
+ constructor(endpointMapper?: InferenceEndpointMapper, config?: OpenAICompatibleConfig);
557
+ private get client();
558
+ private buildRequest;
559
+ infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
560
+ stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
561
+ }
562
+
563
+ interface AnthropicConnectionConfig {
564
+ baseURL?: string;
565
+ apiKey?: string;
566
+ }
567
+ /**
568
+ * Native Anthropic adapter on the `@anthropic-ai/sdk` (`messages.create`).
569
+ * Maps domain context to Anthropic's `messages`/`content` blocks shape,
570
+ * system prompt, tools, adaptive thinking, and structured output config.
571
+ */
572
+ declare class AnthropicMessages implements Endpoint {
573
+ endpointMapper: InferenceEndpointMapper;
574
+ private _client?;
575
+ private readonly clientConfig;
576
+ constructor(endpointMapper?: InferenceEndpointMapper, config?: AnthropicConnectionConfig);
577
+ private get client();
578
+ infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
579
+ stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
580
+ }
581
+
582
+ interface GeminiConnectionConfig {
583
+ baseURL?: string;
584
+ apiKey?: string;
585
+ }
586
+ /**
587
+ * Native Gemini adapter on the `@google/genai` SDK (`generateContent` /
588
+ * `generateContentStream`). Unlike an OpenAI-compat shim this maps our
589
+ * domain context to Gemini's native `contents`/`parts` shape, system
590
+ * instruction, `functionDeclarations`, and `thinkingConfig`, and reads
591
+ * thought parts + native usage metadata back out. Another `ModelRuntime`
592
+ * — no runner or port changes.
593
+ */
594
+ declare class GeminiGenerateContent implements Endpoint {
595
+ endpointMapper: InferenceEndpointMapper;
596
+ private _client?;
597
+ private readonly clientConfig;
598
+ constructor(endpointMapper?: InferenceEndpointMapper, config?: GeminiConnectionConfig);
599
+ private get client();
600
+ infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
601
+ stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
602
+ }
603
+
604
+ declare class InferenceInputValidator {
605
+ private readonly rules;
606
+ constructor(rules?: RequestValidationRule[]);
607
+ validate(inferenceInput: InferenceInput, model: ModelSpecification): void;
608
+ }
609
+
610
+ declare class DefaultInferenceRunner implements InferenceRunner {
611
+ private readonly supportedModels;
612
+ private readonly requestValidator;
613
+ constructor(supportedModels: GenerativeModel[], requestValidator: InferenceInputValidator);
614
+ run(input: InferenceInput): Promise<InferenceOutput>;
615
+ stream(input: InferenceInput): AsyncGenerator<SemanticEvent>;
616
+ }
617
+
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 };
package/dist/index.d.ts CHANGED
@@ -129,6 +129,46 @@ interface FunctionTool {
129
129
  }
130
130
  type Tool = FunctionTool;
131
131
 
132
+ type SituationContext$1<TEvent extends SemanticEvent = SemanticEvent> = {
133
+ readonly event: TEvent;
134
+ readonly participant: Participant;
135
+ };
136
+ declare abstract class SituationSpecification<TEvent extends SemanticEvent = SemanticEvent> {
137
+ abstract isSatisfiedBy(situationContext: SituationContext$1<TEvent>): boolean;
138
+ and(other: SituationSpecification<TEvent>): SituationSpecification<TEvent>;
139
+ or(other: SituationSpecification<TEvent>): SituationSpecification<TEvent>;
140
+ not(): SituationSpecification<TEvent>;
141
+ }
142
+
143
+ interface SituationHandler {
144
+ readonly specification: SituationSpecification;
145
+ readonly processor: SituationProcessor;
146
+ }
147
+ type SituationContext<TEvent extends SemanticEvent = SemanticEvent> = {
148
+ readonly event: TEvent;
149
+ readonly participant: Participant;
150
+ };
151
+ interface SituationProcessor {
152
+ apply(context: SituationContext): void | Promise<void>;
153
+ }
154
+
155
+ type ParticipantRole = "agent" | "human";
156
+ type ParticipantManifest = {
157
+ readonly id: string;
158
+ readonly name: string;
159
+ readonly role: ParticipantRole;
160
+ readonly capabilities?: readonly string[];
161
+ };
162
+ declare abstract class Participant {
163
+ private readonly manifest;
164
+ private handlers;
165
+ protected constructor(manifest: ParticipantManifest, handlers: SituationHandler[]);
166
+ getManifest(): ParticipantManifest;
167
+ getId(): string;
168
+ getHandlers(): SituationHandler[];
169
+ setHandlers(handlers: SituationHandler[]): void;
170
+ }
171
+
132
172
  declare class SemanticEvent<TType extends string = string, TPayload = unknown> {
133
173
  readonly type: TType;
134
174
  readonly producerId: string;
@@ -141,6 +181,71 @@ declare class SemanticEvent<TType extends string = string, TPayload = unknown> {
141
181
  interface FunctionCallRunner {
142
182
  run(call: FunctionCallItem, tool: Tool): Promise<FunctionCallOutputItem>;
143
183
  }
184
+ interface FunctionCallParams {
185
+ call: FunctionCallItem;
186
+ inferenceInput: InferenceInput;
187
+ }
188
+
189
+ type LoopStateId = "context_update" | "inference" | "inference_streaming" | "function_call" | "model_message" | "idle";
190
+ type ReceivedMessage = {
191
+ content: string;
192
+ input: InferenceInput;
193
+ };
194
+ interface FunctionCallExecutionOutput {
195
+ item: FunctionCallOutputItem;
196
+ }
197
+ interface ModelMessageParams {
198
+ answer: ModelMessageItem;
199
+ }
200
+ interface LoopStateContract {
201
+ context_update: {
202
+ input: ReceivedMessage;
203
+ output: InferenceInput;
204
+ };
205
+ inference: {
206
+ input: InferenceInput;
207
+ output: InferenceOutput;
208
+ };
209
+ inference_streaming: {
210
+ input: InferenceInput;
211
+ output: InferenceOutput;
212
+ };
213
+ function_call: {
214
+ input: FunctionCallParams;
215
+ output: FunctionCallExecutionOutput;
216
+ };
217
+ model_message: {
218
+ input: ModelMessageParams;
219
+ output: void;
220
+ };
221
+ interception: {
222
+ input: InterceptionParams;
223
+ output: InterceptionOutput;
224
+ };
225
+ idle: {
226
+ input: undefined;
227
+ output: void;
228
+ };
229
+ }
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
+ }
243
+ type LoopTransition<TStateId extends LoopStateId = LoopStateId> = {
244
+ [K in TStateId]: {
245
+ nextStateId: K;
246
+ input: LoopStateContract[K]["input"];
247
+ };
248
+ }[TStateId];
144
249
 
145
250
  type InferenceInput = {
146
251
  model: string;
@@ -158,6 +263,7 @@ type InferenceOutput = {
158
263
  };
159
264
  interface InferenceRunner {
160
265
  run(request: InferenceInput): Promise<InferenceOutput>;
266
+ stream(request: InferenceInput): AsyncGenerator<SemanticEvent>;
161
267
  }
162
268
 
163
269
  interface InferenceEndpointMapper {
@@ -188,6 +294,11 @@ type ModelSpecification = {
188
294
  supportsStructuredOutput: boolean;
189
295
  };
190
296
 
297
+ interface RequestValidationRule {
298
+ readonly name: string;
299
+ isValid(inferenceInput: InferenceInput, model: ModelSpecification): boolean;
300
+ }
301
+
191
302
  type StructuredOutputFormat = {
192
303
  name?: string;
193
304
  schema: Record<string, any>;
@@ -293,45 +404,6 @@ declare class SystemMessageItem extends ContextItem {
293
404
  }): SystemMessageItem;
294
405
  }
295
406
 
296
- type SituationContext$1<TEvent extends SemanticEvent = SemanticEvent> = {
297
- readonly event: TEvent;
298
- readonly participant: Participant;
299
- };
300
- declare abstract class SituationSpecification<TEvent extends SemanticEvent = SemanticEvent> {
301
- abstract isSatisfiedBy(situationContext: SituationContext$1<TEvent>): boolean;
302
- and(other: SituationSpecification<TEvent>): SituationSpecification<TEvent>;
303
- or(other: SituationSpecification<TEvent>): SituationSpecification<TEvent>;
304
- not(): SituationSpecification<TEvent>;
305
- }
306
-
307
- interface SituationHandler {
308
- readonly specification: SituationSpecification;
309
- readonly processor: SituationProcessor;
310
- }
311
- type SituationContext<TEvent extends SemanticEvent = SemanticEvent> = {
312
- readonly event: TEvent;
313
- readonly participant: Participant;
314
- };
315
- interface SituationProcessor {
316
- apply(context: SituationContext): void | Promise<void>;
317
- }
318
-
319
- type ParticipantRole = "agent" | "human";
320
- type ParticipantManifest = {
321
- readonly id: string;
322
- readonly name: string;
323
- readonly role: ParticipantRole;
324
- readonly capabilities?: readonly string[];
325
- };
326
- declare abstract class Participant {
327
- private readonly manifest;
328
- private handlers;
329
- protected constructor(manifest: ParticipantManifest, handlers: SituationHandler[]);
330
- getManifest(): ParticipantManifest;
331
- getId(): string;
332
- getHandlers(): SituationHandler[];
333
- }
334
-
335
407
  declare class Memory {
336
408
  private readonly context;
337
409
  private constructor();
@@ -387,6 +459,11 @@ declare abstract class RuntimeState {
387
459
  getParticipants(): readonly Participant[];
388
460
  }
389
461
 
462
+ interface InterceptionHandler {
463
+ isSatisfiedBy(transition: LoopTransition): boolean;
464
+ handle(transition: LoopTransition): Promise<LoopTransition>;
465
+ }
466
+
390
467
  declare class EventProcessor {
391
468
  process(event: SemanticEvent, consumer: Participant): void;
392
469
  }
@@ -406,8 +483,8 @@ declare class RuntimeService<TRuntimeState extends RuntimeState> {
406
483
  }
407
484
 
408
485
  type InferenceRunnerConfig = {
409
- supportedModels: GenerativeModel[];
410
- runner: InferenceRunner;
486
+ supportedModels?: GenerativeModel[];
487
+ runner?: InferenceRunner;
411
488
  };
412
489
  declare function defineRuntime<TRuntimeState extends RuntimeState>(): {
413
490
  initializeRuntime: (config: {
@@ -419,7 +496,123 @@ declare function defineRuntime<TRuntimeState extends RuntimeState>(): {
419
496
  join: (participant: Participant) => void;
420
497
  leave: (participant: Participant) => void;
421
498
  sendMessage: (message: string, senderId: string) => void;
422
- runLoop: (agentId: string, message: string, inferenceInput: InferenceInput) => void;
499
+ sendEvent: (event: SemanticEvent, senderId: string) => void;
500
+ runLoop: (agentId: string, message: string, inferenceInput: InferenceInput, interceptionHandler?: InterceptionHandler) => void;
423
501
  };
424
502
 
425
- export { ContextItem, DeveloperMessageItem, type Endpoint, FunctionCallItem, FunctionCallOutputItem, type InferenceInput, type InferenceOutput, InputTokenDetails, McpClient, type McpServerConfig, McpToolRegistry, type McpToolSpec, ModelContext, type ModelContextRepository, ModelMessageItem, OutputTokenDetails, Participant, ReasoningItem, RuntimeState, SemanticEvent, type StructuredOutputFormat, SystemMessageItem, TokenUsage, type Tool, UserMessageItem, createAgent, createHuman, defineRuntime };
503
+ declare const supportedModels: GenerativeModel[];
504
+
505
+ declare class OpenAIResponses implements Endpoint {
506
+ endpointMapper: InferenceEndpointMapper;
507
+ private _client?;
508
+ constructor(endpointMapper?: InferenceEndpointMapper);
509
+ private get client();
510
+ infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
511
+ stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
512
+ }
513
+
514
+ /**
515
+ * Optional connection config. When omitted, the `openai` SDK reads
516
+ * `OPENAI_API_KEY` and `OPENAI_BASE_URL` from the environment, so the
517
+ * default-constructed runtime targets whatever `OPENAI_BASE_URL` points
518
+ * at (real OpenAI when unset). Provider presets (e.g. DeepSeek) pass an
519
+ * explicit base URL + credential.
520
+ */
521
+ interface OpenAICompatibleConfig {
522
+ baseURL?: string;
523
+ apiKey?: string;
524
+ /**
525
+ * Extra request-body fields merged into every `chat.completions`
526
+ * call. This is how provider-specific quirks are handled **without
527
+ * a per-provider subclass in mozaik** — the consumer supplies the
528
+ * vendor-only fields (e.g. DeepSeek's `{ thinking: { type } }`,
529
+ * safety flags, routing hints). Standard fields the runtime already
530
+ * sets (`model`, `messages`, `tools`, `reasoning_effort`) take
531
+ * precedence and are not overwritten.
532
+ */
533
+ extraBody?: Record<string, unknown>;
534
+ }
535
+ /**
536
+ * Generic adapter for any **OpenAI Chat Completions**-compatible
537
+ * endpoint — real OpenAI, DeepSeek, Xiaomi MiMo, OpenRouter, vLLM,
538
+ * Ollama, etc. It speaks `/chat/completions` (not the Responses API),
539
+ * which is the dialect third-party OpenAI-compatible providers expose.
540
+ *
541
+ * The base URL and credential are configurable; everything else (the
542
+ * `ModelContext` ⇄ chat-message conversion, tool-call round-trip, token
543
+ * usage extraction) is provider-agnostic. Provider-specific request
544
+ * shaping (e.g. DeepSeek's `thinking` field) is supplied by the
545
+ * consumer via {@link OpenAICompatibleConfig.extraBody} — mozaik stays
546
+ * generic and gains no per-provider subclasses.
547
+ *
548
+ * Was `DeepSeekChatCompletions`; generalized so consumers can point it
549
+ * at any OpenAI-compatible endpoint.
550
+ */
551
+ declare class OpenAIChatCompletions implements Endpoint {
552
+ endpointMapper: InferenceEndpointMapper;
553
+ private _client?;
554
+ private readonly clientConfig;
555
+ private readonly extraBody;
556
+ constructor(endpointMapper?: InferenceEndpointMapper, config?: OpenAICompatibleConfig);
557
+ private get client();
558
+ private buildRequest;
559
+ infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
560
+ stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
561
+ }
562
+
563
+ interface AnthropicConnectionConfig {
564
+ baseURL?: string;
565
+ apiKey?: string;
566
+ }
567
+ /**
568
+ * Native Anthropic adapter on the `@anthropic-ai/sdk` (`messages.create`).
569
+ * Maps domain context to Anthropic's `messages`/`content` blocks shape,
570
+ * system prompt, tools, adaptive thinking, and structured output config.
571
+ */
572
+ declare class AnthropicMessages implements Endpoint {
573
+ endpointMapper: InferenceEndpointMapper;
574
+ private _client?;
575
+ private readonly clientConfig;
576
+ constructor(endpointMapper?: InferenceEndpointMapper, config?: AnthropicConnectionConfig);
577
+ private get client();
578
+ infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
579
+ stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
580
+ }
581
+
582
+ interface GeminiConnectionConfig {
583
+ baseURL?: string;
584
+ apiKey?: string;
585
+ }
586
+ /**
587
+ * Native Gemini adapter on the `@google/genai` SDK (`generateContent` /
588
+ * `generateContentStream`). Unlike an OpenAI-compat shim this maps our
589
+ * domain context to Gemini's native `contents`/`parts` shape, system
590
+ * instruction, `functionDeclarations`, and `thinkingConfig`, and reads
591
+ * thought parts + native usage metadata back out. Another `ModelRuntime`
592
+ * — no runner or port changes.
593
+ */
594
+ declare class GeminiGenerateContent implements Endpoint {
595
+ endpointMapper: InferenceEndpointMapper;
596
+ private _client?;
597
+ private readonly clientConfig;
598
+ constructor(endpointMapper?: InferenceEndpointMapper, config?: GeminiConnectionConfig);
599
+ private get client();
600
+ infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
601
+ stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
602
+ }
603
+
604
+ declare class InferenceInputValidator {
605
+ private readonly rules;
606
+ constructor(rules?: RequestValidationRule[]);
607
+ validate(inferenceInput: InferenceInput, model: ModelSpecification): void;
608
+ }
609
+
610
+ declare class DefaultInferenceRunner implements InferenceRunner {
611
+ private readonly supportedModels;
612
+ private readonly requestValidator;
613
+ constructor(supportedModels: GenerativeModel[], requestValidator: InferenceInputValidator);
614
+ run(input: InferenceInput): Promise<InferenceOutput>;
615
+ stream(input: InferenceInput): AsyncGenerator<SemanticEvent>;
616
+ }
617
+
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 };