@mozaik-ai/core 4.0.0-beta.1 → 4.0.0-beta.11
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 +12 -4
- package/dist/index.d.mts +236 -43
- package/dist/index.d.ts +236 -43
- package/dist/index.js +273 -76
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +263 -75
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<h1>Mozaik</h1>
|
|
3
|
-
<p>TypeScript runtime for
|
|
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
|
  
|
|
8
6
|
|
|
9
|
-
|
|
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();
|
|
@@ -406,8 +478,8 @@ declare class RuntimeService<TRuntimeState extends RuntimeState> {
|
|
|
406
478
|
}
|
|
407
479
|
|
|
408
480
|
type InferenceRunnerConfig = {
|
|
409
|
-
supportedModels
|
|
410
|
-
runner
|
|
481
|
+
supportedModels?: GenerativeModel[];
|
|
482
|
+
runner?: InferenceRunner;
|
|
411
483
|
};
|
|
412
484
|
declare function defineRuntime<TRuntimeState extends RuntimeState>(): {
|
|
413
485
|
initializeRuntime: (config: {
|
|
@@ -419,7 +491,128 @@ declare function defineRuntime<TRuntimeState extends RuntimeState>(): {
|
|
|
419
491
|
join: (participant: Participant) => void;
|
|
420
492
|
leave: (participant: Participant) => void;
|
|
421
493
|
sendMessage: (message: string, senderId: string) => void;
|
|
422
|
-
|
|
494
|
+
sendEvent: (event: SemanticEvent, senderId: string) => void;
|
|
495
|
+
runLoop: (agentId: string, message: string, inferenceInput: InferenceInput, interceptionHandler?: InterceptionHandler) => void;
|
|
423
496
|
};
|
|
424
497
|
|
|
425
|
-
|
|
498
|
+
declare const supportedModels: GenerativeModel[];
|
|
499
|
+
|
|
500
|
+
declare class OpenAIResponses implements Endpoint {
|
|
501
|
+
endpointMapper: InferenceEndpointMapper;
|
|
502
|
+
private _client?;
|
|
503
|
+
constructor(endpointMapper?: InferenceEndpointMapper);
|
|
504
|
+
private get client();
|
|
505
|
+
infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
|
|
506
|
+
stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Optional connection config. When omitted, the `openai` SDK reads
|
|
511
|
+
* `OPENAI_API_KEY` and `OPENAI_BASE_URL` from the environment, so the
|
|
512
|
+
* default-constructed runtime targets whatever `OPENAI_BASE_URL` points
|
|
513
|
+
* at (real OpenAI when unset). Provider presets (e.g. DeepSeek) pass an
|
|
514
|
+
* explicit base URL + credential.
|
|
515
|
+
*/
|
|
516
|
+
interface OpenAICompatibleConfig {
|
|
517
|
+
baseURL?: string;
|
|
518
|
+
apiKey?: string;
|
|
519
|
+
/**
|
|
520
|
+
* Extra request-body fields merged into every `chat.completions`
|
|
521
|
+
* call. This is how provider-specific quirks are handled **without
|
|
522
|
+
* a per-provider subclass in mozaik** — the consumer supplies the
|
|
523
|
+
* vendor-only fields (e.g. DeepSeek's `{ thinking: { type } }`,
|
|
524
|
+
* safety flags, routing hints). Standard fields the runtime already
|
|
525
|
+
* sets (`model`, `messages`, `tools`, `reasoning_effort`) take
|
|
526
|
+
* precedence and are not overwritten.
|
|
527
|
+
*/
|
|
528
|
+
extraBody?: Record<string, unknown>;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Generic adapter for any **OpenAI Chat Completions**-compatible
|
|
532
|
+
* endpoint — real OpenAI, DeepSeek, Xiaomi MiMo, OpenRouter, vLLM,
|
|
533
|
+
* Ollama, etc. It speaks `/chat/completions` (not the Responses API),
|
|
534
|
+
* which is the dialect third-party OpenAI-compatible providers expose.
|
|
535
|
+
*
|
|
536
|
+
* The base URL and credential are configurable; everything else (the
|
|
537
|
+
* `ModelContext` ⇄ chat-message conversion, tool-call round-trip, token
|
|
538
|
+
* usage extraction) is provider-agnostic. Provider-specific request
|
|
539
|
+
* shaping (e.g. DeepSeek's `thinking` field) is supplied by the
|
|
540
|
+
* consumer via {@link OpenAICompatibleConfig.extraBody} — mozaik stays
|
|
541
|
+
* generic and gains no per-provider subclasses.
|
|
542
|
+
*
|
|
543
|
+
* Was `DeepSeekChatCompletions`; generalized so consumers can point it
|
|
544
|
+
* at any OpenAI-compatible endpoint.
|
|
545
|
+
*/
|
|
546
|
+
declare class OpenAIChatCompletions implements Endpoint {
|
|
547
|
+
endpointMapper: InferenceEndpointMapper;
|
|
548
|
+
private _client?;
|
|
549
|
+
private readonly clientConfig;
|
|
550
|
+
private readonly extraBody;
|
|
551
|
+
constructor(endpointMapper?: InferenceEndpointMapper, config?: OpenAICompatibleConfig);
|
|
552
|
+
private get client();
|
|
553
|
+
private buildRequest;
|
|
554
|
+
infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
|
|
555
|
+
stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
interface AnthropicConnectionConfig {
|
|
559
|
+
baseURL?: string;
|
|
560
|
+
apiKey?: string;
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Native Anthropic adapter on the `@anthropic-ai/sdk` (`messages.create`).
|
|
564
|
+
* Maps domain context to Anthropic's `messages`/`content` blocks shape,
|
|
565
|
+
* system prompt, tools, adaptive thinking, and structured output config.
|
|
566
|
+
*/
|
|
567
|
+
declare class AnthropicMessages implements Endpoint {
|
|
568
|
+
endpointMapper: InferenceEndpointMapper;
|
|
569
|
+
private _client?;
|
|
570
|
+
private readonly clientConfig;
|
|
571
|
+
constructor(endpointMapper?: InferenceEndpointMapper, config?: AnthropicConnectionConfig);
|
|
572
|
+
private get client();
|
|
573
|
+
infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
|
|
574
|
+
stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
interface GeminiConnectionConfig {
|
|
578
|
+
baseURL?: string;
|
|
579
|
+
apiKey?: string;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Native Gemini adapter on the `@google/genai` SDK (`generateContent` /
|
|
583
|
+
* `generateContentStream`). Unlike an OpenAI-compat shim this maps our
|
|
584
|
+
* domain context to Gemini's native `contents`/`parts` shape, system
|
|
585
|
+
* instruction, `functionDeclarations`, and `thinkingConfig`, and reads
|
|
586
|
+
* thought parts + native usage metadata back out. Another `ModelRuntime`
|
|
587
|
+
* — no runner or port changes.
|
|
588
|
+
*/
|
|
589
|
+
declare class GeminiGenerateContent implements Endpoint {
|
|
590
|
+
endpointMapper: InferenceEndpointMapper;
|
|
591
|
+
private _client?;
|
|
592
|
+
private readonly clientConfig;
|
|
593
|
+
constructor(endpointMapper?: InferenceEndpointMapper, config?: GeminiConnectionConfig);
|
|
594
|
+
private get client();
|
|
595
|
+
infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
|
|
596
|
+
stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
declare class InferenceInputValidator {
|
|
600
|
+
private readonly rules;
|
|
601
|
+
constructor(rules?: RequestValidationRule[]);
|
|
602
|
+
validate(inferenceInput: InferenceInput, model: ModelSpecification): void;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
declare class DefaultInferenceRunner implements InferenceRunner {
|
|
606
|
+
private readonly supportedModels;
|
|
607
|
+
private readonly requestValidator;
|
|
608
|
+
constructor(supportedModels: GenerativeModel[], requestValidator: InferenceInputValidator);
|
|
609
|
+
run(input: InferenceInput): Promise<InferenceOutput>;
|
|
610
|
+
stream(input: InferenceInput): AsyncGenerator<SemanticEvent>;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
interface InterceptionHandler {
|
|
614
|
+
isSatisfiedBy(transition: LoopTransition): boolean;
|
|
615
|
+
handle(transition: LoopTransition): Promise<LoopTransition>;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
export { Agent, AnthropicMessages, ContextItem, DefaultInferenceRunner, DeveloperMessageItem, type Endpoint, FunctionCallItem, FunctionCallOutputItem, GeminiGenerateContent, Human, type InferenceInput, type InferenceOutput, type InferenceRunner, type InferenceRunnerConfig, InputTokenDetails, type InterceptionHandler, 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();
|
|
@@ -406,8 +478,8 @@ declare class RuntimeService<TRuntimeState extends RuntimeState> {
|
|
|
406
478
|
}
|
|
407
479
|
|
|
408
480
|
type InferenceRunnerConfig = {
|
|
409
|
-
supportedModels
|
|
410
|
-
runner
|
|
481
|
+
supportedModels?: GenerativeModel[];
|
|
482
|
+
runner?: InferenceRunner;
|
|
411
483
|
};
|
|
412
484
|
declare function defineRuntime<TRuntimeState extends RuntimeState>(): {
|
|
413
485
|
initializeRuntime: (config: {
|
|
@@ -419,7 +491,128 @@ declare function defineRuntime<TRuntimeState extends RuntimeState>(): {
|
|
|
419
491
|
join: (participant: Participant) => void;
|
|
420
492
|
leave: (participant: Participant) => void;
|
|
421
493
|
sendMessage: (message: string, senderId: string) => void;
|
|
422
|
-
|
|
494
|
+
sendEvent: (event: SemanticEvent, senderId: string) => void;
|
|
495
|
+
runLoop: (agentId: string, message: string, inferenceInput: InferenceInput, interceptionHandler?: InterceptionHandler) => void;
|
|
423
496
|
};
|
|
424
497
|
|
|
425
|
-
|
|
498
|
+
declare const supportedModels: GenerativeModel[];
|
|
499
|
+
|
|
500
|
+
declare class OpenAIResponses implements Endpoint {
|
|
501
|
+
endpointMapper: InferenceEndpointMapper;
|
|
502
|
+
private _client?;
|
|
503
|
+
constructor(endpointMapper?: InferenceEndpointMapper);
|
|
504
|
+
private get client();
|
|
505
|
+
infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
|
|
506
|
+
stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Optional connection config. When omitted, the `openai` SDK reads
|
|
511
|
+
* `OPENAI_API_KEY` and `OPENAI_BASE_URL` from the environment, so the
|
|
512
|
+
* default-constructed runtime targets whatever `OPENAI_BASE_URL` points
|
|
513
|
+
* at (real OpenAI when unset). Provider presets (e.g. DeepSeek) pass an
|
|
514
|
+
* explicit base URL + credential.
|
|
515
|
+
*/
|
|
516
|
+
interface OpenAICompatibleConfig {
|
|
517
|
+
baseURL?: string;
|
|
518
|
+
apiKey?: string;
|
|
519
|
+
/**
|
|
520
|
+
* Extra request-body fields merged into every `chat.completions`
|
|
521
|
+
* call. This is how provider-specific quirks are handled **without
|
|
522
|
+
* a per-provider subclass in mozaik** — the consumer supplies the
|
|
523
|
+
* vendor-only fields (e.g. DeepSeek's `{ thinking: { type } }`,
|
|
524
|
+
* safety flags, routing hints). Standard fields the runtime already
|
|
525
|
+
* sets (`model`, `messages`, `tools`, `reasoning_effort`) take
|
|
526
|
+
* precedence and are not overwritten.
|
|
527
|
+
*/
|
|
528
|
+
extraBody?: Record<string, unknown>;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Generic adapter for any **OpenAI Chat Completions**-compatible
|
|
532
|
+
* endpoint — real OpenAI, DeepSeek, Xiaomi MiMo, OpenRouter, vLLM,
|
|
533
|
+
* Ollama, etc. It speaks `/chat/completions` (not the Responses API),
|
|
534
|
+
* which is the dialect third-party OpenAI-compatible providers expose.
|
|
535
|
+
*
|
|
536
|
+
* The base URL and credential are configurable; everything else (the
|
|
537
|
+
* `ModelContext` ⇄ chat-message conversion, tool-call round-trip, token
|
|
538
|
+
* usage extraction) is provider-agnostic. Provider-specific request
|
|
539
|
+
* shaping (e.g. DeepSeek's `thinking` field) is supplied by the
|
|
540
|
+
* consumer via {@link OpenAICompatibleConfig.extraBody} — mozaik stays
|
|
541
|
+
* generic and gains no per-provider subclasses.
|
|
542
|
+
*
|
|
543
|
+
* Was `DeepSeekChatCompletions`; generalized so consumers can point it
|
|
544
|
+
* at any OpenAI-compatible endpoint.
|
|
545
|
+
*/
|
|
546
|
+
declare class OpenAIChatCompletions implements Endpoint {
|
|
547
|
+
endpointMapper: InferenceEndpointMapper;
|
|
548
|
+
private _client?;
|
|
549
|
+
private readonly clientConfig;
|
|
550
|
+
private readonly extraBody;
|
|
551
|
+
constructor(endpointMapper?: InferenceEndpointMapper, config?: OpenAICompatibleConfig);
|
|
552
|
+
private get client();
|
|
553
|
+
private buildRequest;
|
|
554
|
+
infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
|
|
555
|
+
stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
interface AnthropicConnectionConfig {
|
|
559
|
+
baseURL?: string;
|
|
560
|
+
apiKey?: string;
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Native Anthropic adapter on the `@anthropic-ai/sdk` (`messages.create`).
|
|
564
|
+
* Maps domain context to Anthropic's `messages`/`content` blocks shape,
|
|
565
|
+
* system prompt, tools, adaptive thinking, and structured output config.
|
|
566
|
+
*/
|
|
567
|
+
declare class AnthropicMessages implements Endpoint {
|
|
568
|
+
endpointMapper: InferenceEndpointMapper;
|
|
569
|
+
private _client?;
|
|
570
|
+
private readonly clientConfig;
|
|
571
|
+
constructor(endpointMapper?: InferenceEndpointMapper, config?: AnthropicConnectionConfig);
|
|
572
|
+
private get client();
|
|
573
|
+
infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
|
|
574
|
+
stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
interface GeminiConnectionConfig {
|
|
578
|
+
baseURL?: string;
|
|
579
|
+
apiKey?: string;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Native Gemini adapter on the `@google/genai` SDK (`generateContent` /
|
|
583
|
+
* `generateContentStream`). Unlike an OpenAI-compat shim this maps our
|
|
584
|
+
* domain context to Gemini's native `contents`/`parts` shape, system
|
|
585
|
+
* instruction, `functionDeclarations`, and `thinkingConfig`, and reads
|
|
586
|
+
* thought parts + native usage metadata back out. Another `ModelRuntime`
|
|
587
|
+
* — no runner or port changes.
|
|
588
|
+
*/
|
|
589
|
+
declare class GeminiGenerateContent implements Endpoint {
|
|
590
|
+
endpointMapper: InferenceEndpointMapper;
|
|
591
|
+
private _client?;
|
|
592
|
+
private readonly clientConfig;
|
|
593
|
+
constructor(endpointMapper?: InferenceEndpointMapper, config?: GeminiConnectionConfig);
|
|
594
|
+
private get client();
|
|
595
|
+
infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
|
|
596
|
+
stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
declare class InferenceInputValidator {
|
|
600
|
+
private readonly rules;
|
|
601
|
+
constructor(rules?: RequestValidationRule[]);
|
|
602
|
+
validate(inferenceInput: InferenceInput, model: ModelSpecification): void;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
declare class DefaultInferenceRunner implements InferenceRunner {
|
|
606
|
+
private readonly supportedModels;
|
|
607
|
+
private readonly requestValidator;
|
|
608
|
+
constructor(supportedModels: GenerativeModel[], requestValidator: InferenceInputValidator);
|
|
609
|
+
run(input: InferenceInput): Promise<InferenceOutput>;
|
|
610
|
+
stream(input: InferenceInput): AsyncGenerator<SemanticEvent>;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
interface InterceptionHandler {
|
|
614
|
+
isSatisfiedBy(transition: LoopTransition): boolean;
|
|
615
|
+
handle(transition: LoopTransition): Promise<LoopTransition>;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
export { Agent, AnthropicMessages, ContextItem, DefaultInferenceRunner, DeveloperMessageItem, type Endpoint, FunctionCallItem, FunctionCallOutputItem, GeminiGenerateContent, Human, type InferenceInput, type InferenceOutput, type InferenceRunner, type InferenceRunnerConfig, InputTokenDetails, type InterceptionHandler, 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 };
|