@mozaik-ai/core 4.2.0-beta.8 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,139 @@
1
- type SituationContext$1<TEvent extends SpaceEvent = SpaceEvent> = {
1
+ declare abstract class ContextItem {
2
+ abstract readonly type: string;
3
+ getType(): string;
4
+ }
5
+
6
+ declare class FunctionCallItem extends ContextItem {
7
+ readonly type = "function_call";
8
+ readonly callId: string;
9
+ readonly name: string;
10
+ readonly args: string;
11
+ private constructor();
12
+ static rehydrate(data: {
13
+ callId: string;
14
+ name: string;
15
+ args: string;
16
+ }): FunctionCallItem;
17
+ }
18
+
19
+ declare abstract class ItemContent {
20
+ abstract readonly type: string;
21
+ }
22
+
23
+ declare class OutputText extends ItemContent {
24
+ readonly text: string;
25
+ readonly type = "output_text";
26
+ private constructor();
27
+ static rehydrate(data: {
28
+ text: string;
29
+ }): OutputText;
30
+ }
31
+
32
+ declare class ModelMessageItem extends ContextItem {
33
+ readonly type = "message";
34
+ readonly role = "assistant";
35
+ readonly content: OutputText;
36
+ private constructor();
37
+ static rehydrate(data: {
38
+ text: string;
39
+ }): ModelMessageItem;
40
+ }
41
+
42
+ declare class InputText extends ItemContent {
43
+ readonly text: string;
44
+ readonly type = "input_text";
45
+ private constructor();
46
+ static create(text: string): InputText;
47
+ static rehydrate(data: {
48
+ text: string;
49
+ }): InputText;
50
+ }
51
+
52
+ declare class SummaryText extends ItemContent {
53
+ readonly text: string;
54
+ readonly type = "summary_text";
55
+ private constructor();
56
+ static rehydrate(data: {
57
+ text: string;
58
+ }): SummaryText;
59
+ }
60
+
61
+ declare class ReasoningItem extends ContextItem {
62
+ readonly type = "reasoning";
63
+ readonly content: InputText | undefined;
64
+ readonly encryptedContent: string | undefined;
65
+ readonly summary: SummaryText[];
66
+ private constructor();
67
+ static rehydrate(data: {
68
+ content: InputText | undefined;
69
+ encryptedContent: string | undefined;
70
+ summary: SummaryText[];
71
+ }): ReasoningItem;
72
+ }
73
+
74
+ declare class ModelContext {
75
+ readonly id: string;
76
+ readonly items: ContextItem[];
77
+ constructor(id: string, items: ContextItem[]);
78
+ getItems(): ContextItem[];
79
+ addContextItems(contextItems: ContextItem[]): ModelContext;
80
+ addContextItem(item: ContextItem): ModelContext;
81
+ static create(): ModelContext;
82
+ static rehydrate(data: {
83
+ id: string;
84
+ items: ContextItem[];
85
+ }): ModelContext;
86
+ }
87
+
88
+ declare class UserMessageItem extends ContextItem {
89
+ readonly type = "message";
90
+ readonly role = "user";
91
+ readonly content: InputText;
92
+ private constructor();
93
+ static create(text: string): UserMessageItem;
94
+ static rehydrate(data: {
95
+ text: string;
96
+ }): UserMessageItem;
97
+ }
98
+
99
+ declare class DeveloperMessageItem extends ContextItem {
100
+ readonly type = "message";
101
+ readonly role = "developer";
102
+ readonly content: InputText;
103
+ private constructor();
104
+ static create(text: string): DeveloperMessageItem;
105
+ static rehydrate(data: {
106
+ text: string;
107
+ }): DeveloperMessageItem;
108
+ }
109
+
110
+ declare class FunctionCallOutputItem extends ContextItem {
111
+ readonly type = "function_call_output";
112
+ readonly callId: string;
113
+ readonly output: InputText;
114
+ private constructor();
115
+ static create(callId: string, output: string): FunctionCallOutputItem;
116
+ static rehydrate(data: {
117
+ callId: string;
118
+ output: InputText;
119
+ }): FunctionCallOutputItem;
120
+ }
121
+
122
+ interface FunctionTool {
123
+ type: "function";
124
+ name: string;
125
+ description: string;
126
+ parameters: Record<string, any>;
127
+ strict: boolean;
128
+ invoke: (args: any) => Promise<any>;
129
+ }
130
+ type Tool = FunctionTool;
131
+
132
+ type SituationContext$1<TEvent extends SemanticEvent = SemanticEvent> = {
2
133
  readonly event: TEvent;
3
134
  readonly participant: Participant;
4
135
  };
5
- declare abstract class SituationSpecification<TEvent extends SpaceEvent = SpaceEvent> {
136
+ declare abstract class SituationSpecification<TEvent extends SemanticEvent = SemanticEvent> {
6
137
  abstract isSatisfiedBy(situationContext: SituationContext$1<TEvent>): boolean;
7
138
  and(other: SituationSpecification<TEvent>): SituationSpecification<TEvent>;
8
139
  or(other: SituationSpecification<TEvent>): SituationSpecification<TEvent>;
@@ -13,7 +144,7 @@ interface SituationHandler {
13
144
  readonly specification: SituationSpecification;
14
145
  readonly processor: SituationProcessor;
15
146
  }
16
- type SituationContext<TEvent extends SpaceEvent = SpaceEvent> = {
147
+ type SituationContext<TEvent extends SemanticEvent = SemanticEvent> = {
17
148
  readonly event: TEvent;
18
149
  readonly participant: Participant;
19
150
  };
@@ -21,139 +152,161 @@ interface SituationProcessor {
21
152
  apply(context: SituationContext): void | Promise<void>;
22
153
  }
23
154
 
24
- type ParticipantRole = "agent" | "external";
155
+ type ParticipantRole = "agent" | "human";
25
156
  type ParticipantManifest = {
26
157
  readonly id: string;
27
158
  readonly name: string;
28
159
  readonly role: ParticipantRole;
29
160
  readonly capabilities?: readonly string[];
30
161
  };
31
- declare class Participant {
32
- private manifest;
162
+ declare abstract class Participant {
163
+ private readonly manifest;
33
164
  private handlers;
34
- constructor(manifest: ParticipantManifest, handlers: SituationHandler[]);
165
+ protected constructor(manifest: ParticipantManifest, handlers: SituationHandler[]);
35
166
  getManifest(): ParticipantManifest;
36
- setManifest(manifest: ParticipantManifest): void;
37
167
  getId(): string;
38
168
  getHandlers(): SituationHandler[];
39
169
  setHandlers(handlers: SituationHandler[]): void;
40
170
  }
41
171
 
42
- declare class SpaceEvent<TType extends string = string, TPayload = unknown> {
172
+ declare class SemanticEvent<TType extends string = string, TPayload = unknown> {
43
173
  readonly type: TType;
44
174
  readonly producerId: string;
45
175
  readonly occurredAt: Date;
46
176
  readonly payload: TPayload;
47
177
  constructor(type: TType, producerId: string, occurredAt: Date, payload: TPayload);
48
- static create<TType extends string = string, TPayload = unknown>(type: TType, producerId: string, occurredAt: Date, payload: TPayload): SpaceEvent<TType, TPayload>;
178
+ static create<TType extends string = string, TPayload = unknown>(type: TType, producerId: string, payload: TPayload): SemanticEvent<TType, TPayload>;
49
179
  }
50
180
 
51
- interface SharedState {
181
+ interface FunctionCallRunner {
182
+ run(call: FunctionCallItem, tool: Tool): Promise<FunctionCallOutputItem>;
52
183
  }
53
-
54
- interface FunctionTool {
55
- type: "function";
56
- name: string;
57
- description: string;
58
- parameters: Record<string, any>;
59
- strict: boolean;
60
- invoke: (args: any) => Promise<any> | any;
184
+ interface FunctionCallParams {
185
+ call: FunctionCallItem;
186
+ inferenceInput: InferenceInput;
61
187
  }
62
- type Tool = FunctionTool;
63
188
 
64
- type SpaceRecord = {
65
- id: string;
66
- name: string;
67
- participants: Participant[];
68
- };
69
- declare class Space {
70
- private readonly id;
71
- private name;
72
- private participants;
73
- private events;
74
- constructor(id: string, name: string, participants: Participant[], events?: SpaceEvent[]);
75
- getId(): string;
76
- getName(): string;
77
- addParticipant(participant: Participant): SpaceEvent | undefined;
78
- getParticipant(id: string): Participant | undefined;
79
- removeParticipant(participant: Participant): SpaceEvent;
80
- getParticipants(): Participant[];
81
- sendMessage(participant: Participant, message: string, occurredAt: Date): SpaceEvent;
82
- getEvents(): SpaceEvent[];
83
- static create(name: string, participants?: Participant[]): Space;
84
- get record(): SpaceRecord;
85
- static rehydrate({ id, name, participants }: SpaceRecord): Space;
189
+ interface InterceptionHandler {
190
+ isSatisfiedBy(transition: ExecutableTransition): boolean;
191
+ handle(transition: ExecutableTransition): Promise<ExecutableTransition>;
86
192
  }
87
-
88
- declare class RuntimeService<TSharedState extends SharedState> {
89
- readonly state: TSharedState;
90
- constructor(state: TSharedState);
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;
91
205
  }
92
206
 
93
- declare function defineRuntime<TSharedState extends SharedState>(): {
94
- initializeRuntime: (config: {
95
- state: TSharedState;
96
- }) => RuntimeService<TSharedState>;
97
- resolveRuntime: () => RuntimeService<TSharedState>;
98
- createParticipant: (name: string, capabilities: readonly string[], handlers: SituationHandler[]) => Promise<Participant>;
99
- createSpace: (name: string) => Promise<Space>;
100
- join: (spaceId: string, participant: Participant) => Promise<void>;
101
- leave: (spaceId: string, participantId: string) => Promise<void>;
102
- sendMessage: (spaceId: string, participantId: string, message: string) => Promise<void>;
103
- sendMessageTool: FunctionTool;
207
+ type LoopStateId = "message_received" | "inference" | "inference_streaming" | "function_call" | "model_message" | "idle";
208
+ type ReceivedMessage = {
209
+ content: string;
210
+ input: InferenceInput;
104
211
  };
212
+ interface FunctionCallExecutionOutput {
213
+ item: FunctionCallOutputItem;
214
+ }
215
+ interface ModelMessageParams {
216
+ answer: ModelMessageItem;
217
+ }
218
+ interface LoopStateContract {
219
+ message_received: {
220
+ input: ReceivedMessage;
221
+ output: InferenceInput;
222
+ };
223
+ inference: {
224
+ input: InferenceInput;
225
+ output: InferenceOutput;
226
+ };
227
+ inference_streaming: {
228
+ input: InferenceInput;
229
+ output: InferenceOutput;
230
+ };
231
+ function_call: {
232
+ input: FunctionCallParams;
233
+ output: FunctionCallExecutionOutput;
234
+ };
235
+ model_message: {
236
+ input: ModelMessageParams;
237
+ output: void;
238
+ };
239
+ interception: {
240
+ input: InterceptionParams;
241
+ output: InterceptionOutput;
242
+ };
243
+ idle: {
244
+ input: undefined;
245
+ output: void;
246
+ };
247
+ }
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];
257
+ type LoopTransition<TStateId extends LoopStateId = LoopStateId> = {
258
+ [K in TStateId]: {
259
+ nextStateId: K;
260
+ input: LoopStateContract[K]["input"];
261
+ };
262
+ }[TStateId];
105
263
 
106
- interface ItemContent {
107
- readonly type: string;
108
- }
109
- interface InputText extends ItemContent {
110
- readonly type: "input_text";
111
- readonly text: string;
112
- }
113
- interface SummaryText {
114
- readonly type: "summary_text";
115
- readonly text: string;
116
- }
117
- interface ReasoningItem {
118
- readonly type: "reasoning";
119
- readonly content?: InputText;
120
- readonly encryptedContent?: string;
121
- readonly summary: SummaryText[];
122
- }
123
- interface MessageItem {
124
- readonly type: "user_message" | "system_message" | "developer_message" | "model_message";
125
- readonly text: string;
126
- }
127
- interface ModelMessageItem extends MessageItem {
128
- readonly type: "model_message";
129
- readonly text: string;
264
+ declare class InputTokenDetails {
265
+ readonly cached_tokens: number;
266
+ constructor(cached_tokens: number);
130
267
  }
131
- interface ToolUseRequest {
132
- readonly type: "tool_use_request";
133
- readonly requestId: string;
134
- readonly toolName: string;
135
- readonly toolArguments: string;
268
+ declare class OutputTokenDetails {
269
+ readonly reasoning_tokens: number;
270
+ constructor(reasoning_tokens: number);
136
271
  }
137
- interface ToolUseResult {
138
- readonly type: "tool_use_result";
139
- readonly requestId: string;
140
- readonly result: InputText;
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);
141
279
  }
142
- type ContextItem = MessageItem | ReasoningItem | ToolUseRequest | ToolUseResult;
143
- type ModelOutputItem = ModelMessageItem | ToolUseRequest | ReasoningItem;
144
- type Context = {
145
- readonly items: ContextItem[];
280
+
281
+ type InferenceInput = {
282
+ model: string;
283
+ maxOutputTokens?: number;
284
+ reasoningEffort?: string;
285
+ tools?: Tool[];
286
+ streaming?: boolean;
287
+ structuredOutput?: StructuredOutputFormat;
288
+ context: ModelContext;
289
+ };
290
+ type InferenceItem = FunctionCallItem | ReasoningItem | ModelMessageItem;
291
+ type InferenceOutput = {
292
+ items: InferenceItem[];
293
+ tokenUsage: TokenUsage | undefined;
294
+ rowResponse: any;
146
295
  };
296
+ interface InferenceRunner {
297
+ run(request: InferenceInput): Promise<InferenceOutput>;
298
+ stream(request: InferenceInput): AsyncGenerator<SemanticEvent>;
299
+ }
147
300
 
148
301
  interface InferenceEndpointMapper {
149
- toRequest(inferenceRequest: InferenceRequest): any;
150
- toResponse(response: any): InferenceResult;
302
+ toRequest(inferenceInput: InferenceInput): any;
303
+ toResponse(response: any): InferenceOutput;
151
304
  }
152
305
 
153
306
  interface Endpoint {
154
307
  endpointMapper: InferenceEndpointMapper;
155
- infer(requestParams: InferenceRequest): Promise<InferenceResult>;
156
- stream(requestParams: InferenceRequest): AsyncIterable<SpaceEvent>;
308
+ infer(requestParams: InferenceInput): Promise<InferenceOutput>;
309
+ stream(requestParams: InferenceInput): AsyncIterable<SemanticEvent>;
157
310
  }
158
311
 
159
312
  type GenerativeModel = {
@@ -173,284 +326,312 @@ type ModelSpecification = {
173
326
  supportsStructuredOutput: boolean;
174
327
  };
175
328
 
329
+ interface RequestValidationRule {
330
+ readonly name: string;
331
+ isValid(inferenceInput: InferenceInput, model: ModelSpecification): boolean;
332
+ }
333
+
176
334
  type StructuredOutputFormat = {
177
335
  name?: string;
178
336
  schema: Record<string, any>;
179
337
  strict?: boolean;
180
338
  };
181
339
 
182
- declare class InputTokenDetails {
183
- readonly cached_tokens: number;
184
- constructor(cached_tokens: number);
340
+ interface ModelContextRepository {
341
+ save(context: ModelContext): Promise<void>;
342
+ get(id: string): Promise<ModelContext>;
343
+ getByProjectId(projectId: string): Promise<ModelContext[]>;
185
344
  }
186
- declare class OutputTokenDetails {
187
- readonly reasoning_tokens: number;
188
- constructor(reasoning_tokens: number);
345
+
346
+ interface McpServerConfig {
347
+ /** The MCP server URL, e.g. https://api.githubcopilot.com/mcp/ */
348
+ url: string;
349
+ /** Bearer token sent as `Authorization: Bearer <token>` (e.g. a GitHub token). */
350
+ authToken?: string;
351
+ /** Extra headers merged into every request (overridden by `authToken` for Authorization). */
352
+ headers?: Record<string, string>;
353
+ /** Client name reported to the server (defaults to "mozaik"). */
354
+ name?: string;
189
355
  }
190
- declare class TokenUsage {
191
- readonly inputTokens: number;
192
- readonly outputTokens: number;
193
- readonly totalTokens: number;
194
- readonly inputTokenDetails: InputTokenDetails;
195
- readonly outputTokenDetails: OutputTokenDetails;
196
- constructor(inputTokens: number, outputTokens: number, totalTokens: number, inputTokenDetails: InputTokenDetails, outputTokenDetails: OutputTokenDetails);
356
+ interface McpToolSpec {
357
+ name: string;
358
+ description: string;
359
+ /** JSON Schema for the tool's arguments (maps 1:1 to FunctionTool.parameters). */
360
+ inputSchema: Record<string, any>;
361
+ }
362
+ /**
363
+ * A thin wrapper over the MCP TypeScript SDK using the Streamable HTTP transport — what
364
+ * remote MCP servers (e.g. GitHub's `api.githubcopilot.com/mcp/`) speak. One client per
365
+ * server; lazily connects on first use. Infrastructure-only: the domain never sees this.
366
+ */
367
+ declare class McpClient {
368
+ private readonly config;
369
+ private readonly client;
370
+ private readonly transport;
371
+ private connected;
372
+ constructor(config: McpServerConfig);
373
+ connect(): Promise<void>;
374
+ /** The tools this server exposes. */
375
+ listTools(): Promise<McpToolSpec[]>;
376
+ /** Call a tool by name; returns its text output. Throws if the server flags an error. */
377
+ callTool(name: string, args: Record<string, any>): Promise<string>;
378
+ close(): Promise<void>;
197
379
  }
198
380
 
199
- type InferenceRequest = {
200
- model: string;
201
- maxOutputTokens?: number;
202
- reasoningEffort?: string;
203
- tools?: Tool[];
204
- streaming?: boolean;
205
- structuredOutput?: StructuredOutputFormat;
206
- context: Context;
207
- };
208
- type InferenceResult = {
209
- items: ModelOutputItem[];
210
- tokenUsage: TokenUsage | undefined;
211
- rowResponse: any;
212
- };
213
- interface InferenceRunner {
214
- run(request: InferenceRequest): Promise<InferenceResult>;
215
- stream(request: InferenceRequest): AsyncGenerator<SpaceEvent>;
381
+ /** The slice of an MCP client the registry needs — lets tests inject a fake. */
382
+ interface McpClientLike {
383
+ listTools(): Promise<Array<{
384
+ name: string;
385
+ description: string;
386
+ inputSchema: Record<string, any>;
387
+ }>>;
388
+ callTool(name: string, args: Record<string, any>): Promise<string>;
389
+ close(): Promise<void>;
390
+ }
391
+ /**
392
+ * Connects to one or more MCP servers and exposes their tools as mozaik `FunctionTool`s.
393
+ * Each tool's `invoke()` proxies the call back to its MCP server. Because they are plain
394
+ * FunctionTools, every provider mapper and the existing function-call loop handle them
395
+ * with no changes — MCP support adds no new tool type and touches no provider code.
396
+ *
397
+ * `strict` is false: MCP servers publish arbitrary JSON Schemas that won't always satisfy
398
+ * a provider's strict function-calling mode.
399
+ */
400
+ declare class McpToolRegistry {
401
+ private readonly servers;
402
+ private readonly createClient;
403
+ private readonly clients;
404
+ constructor(servers: McpServerConfig[], createClient?: (config: McpServerConfig) => McpClientLike);
405
+ /** Discover every tool across the configured servers, as FunctionTools ready to pass to a model. */
406
+ discoverTools(): Promise<FunctionTool[]>;
407
+ /** Close all underlying MCP connections. */
408
+ close(): Promise<void>;
216
409
  }
217
410
 
218
- interface Memory {
219
- remember(items: ContextItem[], participantId: string): void;
220
- recall(topic: string, participantId: string): ContextItem[];
411
+ declare class SystemMessageItem extends ContextItem {
412
+ readonly type = "message";
413
+ readonly role = "system";
414
+ readonly content: InputText;
415
+ private constructor();
416
+ static create(text: string): SystemMessageItem;
417
+ static rehydrate(data: {
418
+ text: string;
419
+ }): SystemMessageItem;
221
420
  }
222
421
 
223
- type AgentRecord = {
224
- id: string;
225
- manifest: ParticipantManifest;
226
- tools: Tool[];
227
- memory: Memory;
228
- handlers: SituationHandler[];
229
- };
422
+ declare class Memory {
423
+ private readonly context;
424
+ private constructor();
425
+ getContext(): ModelContext;
426
+ static create(): Memory;
427
+ }
230
428
 
231
429
  declare class Agent extends Participant {
232
430
  private memory;
431
+ private developerMessage;
233
432
  private tools;
234
- constructor(manifest: ParticipantManifest, tools: Tool[], memory: Memory, handlers: SituationHandler[]);
235
- getTools(): Tool[];
236
- getMemory(): Memory;
237
- static create({ manifest, tools, memory, handlers, }: {
238
- manifest: ParticipantManifest;
433
+ constructor(manifest: ParticipantManifest, developerMessage: string, tools: Tool[], memory: Memory, handlers: SituationHandler[]);
434
+ static create({ name, instruction, tools, capabilities, handlers, }: {
435
+ instruction: string;
239
436
  tools: Tool[];
240
- memory: Memory;
437
+ name: string;
438
+ capabilities: readonly string[];
241
439
  handlers: SituationHandler[];
242
440
  }): Agent;
243
- static rehydrate(record: AgentRecord): Agent;
244
- }
245
-
246
- interface AgentRepository {
247
- save(agent: Agent): Promise<void>;
248
- exists(id: string): Promise<boolean>;
249
- findById(id: string): Promise<Agent | undefined>;
250
- findAll(): Promise<Agent[]>;
441
+ getTools(): Tool[];
442
+ getDeveloperMessage(): string;
443
+ getMemory(): Memory;
251
444
  }
252
445
 
253
- type CompletedOperation = {
254
- type: "inference";
255
- operationId: string;
256
- requestedAt: Date;
257
- completedAt: Date;
258
- request: InferenceRequest;
259
- result: InferenceResult;
260
- } | {
261
- type: "tool_use";
262
- operationId: string;
263
- requestedAt: Date;
264
- completedAt: Date;
265
- call: ToolUseRequest;
266
- result: ToolUseResult;
267
- };
268
- type PendingInference = {
269
- id: string;
270
- type: "inference";
271
- requestedAt: Date;
272
- request: InferenceRequest;
273
- };
274
- type PendingToolExecution = {
275
- id: string;
276
- type: "tool_execution";
277
- requestedAt: Date;
278
- call: ToolUseRequest;
279
- };
280
- type PendingOperation = PendingInference | PendingToolExecution;
446
+ declare function createAgent({ name, capabilities, instruction, tools, handlers, }: {
447
+ name: string;
448
+ capabilities: readonly string[];
449
+ instruction: string;
450
+ tools: Tool[];
451
+ handlers: SituationHandler[];
452
+ }): Agent;
281
453
 
282
- interface LoopTransition {
283
- readonly occurredAt: Date;
284
- readonly previousState: LoopStateId;
285
- readonly nextState: LoopStateId;
286
- readonly reason: string;
287
- readonly operationId?: string;
454
+ declare class Human extends Participant {
455
+ constructor(manifest: ParticipantManifest, handlers: SituationHandler[]);
456
+ static create({ name, capabilities, handlers, }: {
457
+ name: string;
458
+ capabilities: readonly string[];
459
+ handlers: SituationHandler[];
460
+ }): Human;
288
461
  }
289
462
 
290
- type AgentLoop = {
291
- readonly agent: Agent;
292
- readonly loop: Loop;
293
- };
294
- declare abstract class LoopSpecification {
295
- abstract isSatisfiedBy(agentLoop: AgentLoop): boolean;
296
- and(other: LoopSpecification): LoopSpecification;
297
- or(other: LoopSpecification): LoopSpecification;
298
- not(): LoopSpecification;
299
- }
463
+ declare function createHuman({ name, capabilities, handlers, }: {
464
+ name: string;
465
+ capabilities: readonly string[];
466
+ handlers: SituationHandler[];
467
+ }): Human;
300
468
 
301
- type LoopControlDirective = InferenceDirective | ToolUseDirective | WaitDirective | CompleteDirective;
302
- type InferenceDirective = {
303
- type: "inference";
304
- request: InferenceRequest;
305
- };
306
- type ToolUseDirective = {
307
- type: "tool_use";
308
- call: ToolUseRequest;
309
- };
310
- type WaitDirective = {
311
- type: "wait";
312
- reason: string;
313
- };
314
- type CompleteDirective = {
315
- type: "complete";
316
- reason: string;
317
- };
469
+ declare abstract class RuntimeState {
470
+ participants: Map<string, Participant>;
471
+ addParticipant(participant: Participant): void;
472
+ removeParticipant(participant: Participant): void;
473
+ getParticipant(id: string): Participant | undefined;
474
+ getParticipants(): readonly Participant[];
475
+ }
318
476
 
319
- declare abstract class LoopAction {
320
- abstract execute(agentLoop: AgentLoop): LoopControlDirective;
477
+ declare class EventProcessor {
478
+ process(event: SemanticEvent, consumer: Participant): void;
321
479
  }
322
480
 
323
- type CreateLoopRuleParams = {
324
- readonly priority?: number;
325
- readonly when: LoopSpecification;
326
- readonly then: LoopAction;
327
- };
328
- type LoopRuleRecord = {
329
- readonly id: string;
330
- readonly priority: number;
331
- readonly condition: LoopSpecification;
332
- readonly action: LoopAction;
333
- };
334
- declare class LoopRule {
335
- _id: string;
336
- _priority: number;
337
- _condition: LoopSpecification;
338
- _action: LoopAction;
339
- constructor(id: string, condition: LoopSpecification, action: LoopAction, priority: number);
340
- get id(): string;
341
- get priority(): number;
342
- get condition(): LoopSpecification;
343
- get action(): LoopAction;
344
- static create(spec: CreateLoopRuleParams): LoopRule;
345
- static rehydrate(spec: LoopRuleRecord): LoopRule;
346
- }
347
- type RuleBookRecord = {
348
- readonly rules: LoopRuleRecord[];
349
- };
350
- declare class RuleBook {
351
- private rules;
352
- private constructor();
353
- addRule(rule: LoopRule): void;
354
- removeRule(rule: LoopRule): void;
355
- getRules(): readonly LoopRule[];
356
- static create(loopRuleParams: CreateLoopRuleParams[]): RuleBook;
357
- static rehydrate(record: RuleBookRecord): RuleBook;
358
- record(): RuleBookRecord;
359
- }
360
-
361
- interface LoopRecord {
362
- id: string;
363
- agentId: string;
364
- subject: string;
365
- createdAt: Date;
366
- state: LoopStateId;
367
- inferenceRequest?: InferenceRequest;
368
- pendingOperation?: PendingOperation;
369
- transitionHistory: LoopTransition[];
370
- operationHistory: CompletedOperation[];
371
- ruleBook: RuleBookRecord;
372
- }
373
-
374
- type LoopStateId = "idle" | "awaiting_inference_request" | "awaiting_inference" | "awaiting_tool_output" | "stopped" | "completed";
375
- type CreateLoopParams = {
376
- subject: string;
377
- agentId: string;
378
- rules: CreateLoopRuleParams[];
379
- } | {
380
- subject: string;
381
- agentId: string;
382
- request: InferenceRequest;
383
- };
384
- declare class Loop {
385
- private readonly loopId;
386
- private readonly agentId;
387
- private readonly subject;
388
- private readonly createdAt;
389
- private state;
390
- private pendingOperation;
391
- private readonly transitionHistory;
392
- private inferenceRequest;
393
- private readonly operationHistory;
394
- private readonly _ruleBook;
395
- private constructor();
396
- get id(): string;
397
- get stateId(): LoopStateId;
398
- get pending(): PendingOperation | undefined;
399
- get history(): readonly LoopTransition[];
400
- get completedOperations(): readonly CompletedOperation[];
401
- get request(): InferenceRequest | undefined;
402
- get ruleBook(): RuleBook;
403
- getSubject(): string;
404
- getAgentId(): string;
405
- record(): LoopRecord;
406
- moveToIdle(reason: string, transitionId: string): void;
407
- moveToAwaitingInference(operation: PendingInference): void;
408
- moveToAwaitingToolOutput(operation: Extract<PendingOperation, {
409
- type: "tool_execution";
410
- }>, occurredAt: Date): void;
411
- requestInference(request: InferenceRequest): PendingInference;
412
- requestToolUse(operationId: string, call: ToolUseRequest, requestedAt: Date): PendingToolExecution;
413
- private transitionTo;
414
- private assertIdle;
415
- private assertAwaitingInferenceRequest;
416
- receiveInferenceResult(operationId: string, result: InferenceResult): void;
417
- receiveToolUseResult(operationId: string, result: ToolUseResult): void;
418
- complete(reason: string): void;
419
- stop(reason: string): void;
420
- wait(reason: string): void;
421
- private assertNotSettled;
422
- static create(agentId: string, subject: string, ruleBook: RuleBook): Loop;
423
- static rehydrate(record: LoopRecord): Loop;
424
- }
425
-
426
- interface LoopRepository {
427
- save(loop: Loop): Promise<void>;
428
- findById(id: string): Promise<Loop | undefined>;
429
- }
430
-
431
- interface ToolUseRunner {
432
- run(request: ToolUseRequest, tool: Tool): Promise<ToolUseResult>;
481
+ declare class RuntimeService<TRuntimeState extends RuntimeState> {
482
+ readonly state: TRuntimeState;
483
+ private readonly processor;
484
+ private readonly inferenceRunner;
485
+ private readonly functionCallRunner;
486
+ constructor(state: TRuntimeState, processor: EventProcessor, inferenceRunner: InferenceRunner, functionCallRunner: FunctionCallRunner);
487
+ join(participant: Participant): void;
488
+ leave(participant: Participant): void;
489
+ publish(event: SemanticEvent): void;
490
+ getParticipant(id: string): Participant | undefined;
491
+ getInferenceRunner(): InferenceRunner;
492
+ getFunctionCallRunner(): FunctionCallRunner;
433
493
  }
434
494
 
435
495
  type InferenceRunnerConfig = {
436
496
  supportedModels?: GenerativeModel[];
437
497
  runner?: InferenceRunner;
438
498
  };
439
- type AgentModuleConfig = {
440
- agentRepository?: AgentRepository;
441
- agentLoopRepository?: LoopRepository;
442
- inferenceRunnerConfig?: InferenceRunnerConfig;
443
- toolRunner?: ToolUseRunner;
444
- };
445
- declare function defineAgentModule(config: AgentModuleConfig): {
446
- createAgent: (config: {
447
- name: string;
448
- instruction: string;
449
- tools: Tool[];
450
- handlers: SituationHandler[];
451
- }) => Promise<AgentRecord>;
452
- createLoop: (params: CreateLoopParams) => Promise<Loop>;
453
- runLoop: (loopId: string) => Promise<Loop>;
499
+ declare function defineRuntime<TRuntimeState extends RuntimeState>(): {
500
+ initializeRuntime: (config: {
501
+ state: TRuntimeState;
502
+ inferenceRunnerConfig?: InferenceRunnerConfig;
503
+ }) => RuntimeService<TRuntimeState>;
504
+ resolveRuntime: () => RuntimeService<TRuntimeState>;
505
+ resolveParticipant: (id: string) => Participant;
506
+ join: (participant: Participant) => void;
507
+ leave: (participant: Participant) => void;
508
+ sendMessage: (message: string, senderId: string) => void;
509
+ sendEvent: (event: SemanticEvent, senderId: string) => void;
510
+ runLoop: (agentId: string, message: string, inferenceInput: InferenceInput, interceptionHandler?: InterceptionHandler) => void;
454
511
  };
455
512
 
456
- export { Agent, type AgentModuleConfig, type AgentRepository, type GenerativeModel, type InferenceRunner, type InferenceRunnerConfig, type LoopRepository, type ModelMessageItem, Participant, type SharedState, type SituationContext, type SituationHandler, type SituationProcessor, SituationSpecification, SpaceEvent, type Tool, type ToolUseRequest, type ToolUseResult, type ToolUseRunner, defineAgentModule, defineRuntime };
513
+ declare const supportedModels: GenerativeModel[];
514
+
515
+ /**
516
+ * Optional connection config. When omitted, the `openai` SDK reads
517
+ * `OPENAI_API_KEY` and `OPENAI_BASE_URL` from the environment.
518
+ */
519
+ interface OpenAIResponsesConfig {
520
+ baseURL?: string;
521
+ apiKey?: string;
522
+ }
523
+ declare class OpenAIResponses implements Endpoint {
524
+ endpointMapper: InferenceEndpointMapper;
525
+ private _client?;
526
+ private readonly clientConfig;
527
+ constructor(endpointMapper?: InferenceEndpointMapper, config?: OpenAIResponsesConfig);
528
+ private get client();
529
+ infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
530
+ stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
531
+ }
532
+
533
+ /**
534
+ * Optional connection config. When omitted, the `openai` SDK reads
535
+ * `OPENAI_API_KEY` and `OPENAI_BASE_URL` from the environment, so the
536
+ * default-constructed runtime targets whatever `OPENAI_BASE_URL` points
537
+ * at (real OpenAI when unset). Provider presets (e.g. DeepSeek) pass an
538
+ * explicit base URL + credential.
539
+ */
540
+ interface OpenAICompatibleConfig {
541
+ baseURL?: string;
542
+ apiKey?: string;
543
+ /**
544
+ * Extra request-body fields merged into every `chat.completions`
545
+ * call. This is how provider-specific quirks are handled **without
546
+ * a per-provider subclass in mozaik** — the consumer supplies the
547
+ * vendor-only fields (e.g. DeepSeek's `{ thinking: { type } }`,
548
+ * safety flags, routing hints). Standard fields the runtime already
549
+ * sets (`model`, `messages`, `tools`, `reasoning_effort`) take
550
+ * precedence and are not overwritten.
551
+ */
552
+ extraBody?: Record<string, unknown>;
553
+ }
554
+ /**
555
+ * Generic adapter for any **OpenAI Chat Completions**-compatible
556
+ * endpoint — real OpenAI, DeepSeek, Xiaomi MiMo, OpenRouter, vLLM,
557
+ * Ollama, etc. It speaks `/chat/completions` (not the Responses API),
558
+ * which is the dialect third-party OpenAI-compatible providers expose.
559
+ *
560
+ * The base URL and credential are configurable; everything else (the
561
+ * `ModelContext` ⇄ chat-message conversion, tool-call round-trip, token
562
+ * usage extraction) is provider-agnostic. Provider-specific request
563
+ * shaping (e.g. DeepSeek's `thinking` field) is supplied by the
564
+ * consumer via {@link OpenAICompatibleConfig.extraBody} — mozaik stays
565
+ * generic and gains no per-provider subclasses.
566
+ *
567
+ * Was `DeepSeekChatCompletions`; generalized so consumers can point it
568
+ * at any OpenAI-compatible endpoint.
569
+ */
570
+ declare class OpenAIChatCompletions implements Endpoint {
571
+ endpointMapper: InferenceEndpointMapper;
572
+ private _client?;
573
+ private readonly clientConfig;
574
+ private readonly extraBody;
575
+ constructor(endpointMapper?: InferenceEndpointMapper, config?: OpenAICompatibleConfig);
576
+ private get client();
577
+ private buildRequest;
578
+ infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
579
+ stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
580
+ }
581
+
582
+ interface AnthropicConnectionConfig {
583
+ baseURL?: string;
584
+ apiKey?: string;
585
+ }
586
+ /**
587
+ * Native Anthropic adapter on the `@anthropic-ai/sdk` (`messages.create`).
588
+ * Maps domain context to Anthropic's `messages`/`content` blocks shape,
589
+ * system prompt, tools, adaptive thinking, and structured output config.
590
+ */
591
+ declare class AnthropicMessages implements Endpoint {
592
+ endpointMapper: InferenceEndpointMapper;
593
+ private _client?;
594
+ private readonly clientConfig;
595
+ constructor(endpointMapper?: InferenceEndpointMapper, config?: AnthropicConnectionConfig);
596
+ private get client();
597
+ infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
598
+ stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
599
+ }
600
+
601
+ interface GeminiConnectionConfig {
602
+ baseURL?: string;
603
+ apiKey?: string;
604
+ }
605
+ /**
606
+ * Native Gemini adapter on the `@google/genai` SDK (`generateContent` /
607
+ * `generateContentStream`). Unlike an OpenAI-compat shim this maps our
608
+ * domain context to Gemini's native `contents`/`parts` shape, system
609
+ * instruction, `functionDeclarations`, and `thinkingConfig`, and reads
610
+ * thought parts + native usage metadata back out. Another `ModelRuntime`
611
+ * — no runner or port changes.
612
+ */
613
+ declare class GeminiGenerateContent implements Endpoint {
614
+ endpointMapper: InferenceEndpointMapper;
615
+ private _client?;
616
+ private readonly clientConfig;
617
+ constructor(endpointMapper?: InferenceEndpointMapper, config?: GeminiConnectionConfig);
618
+ private get client();
619
+ infer(inferenceInput: InferenceInput): Promise<InferenceOutput>;
620
+ stream(inferenceInput: InferenceInput): AsyncIterable<SemanticEvent>;
621
+ }
622
+
623
+ declare class InferenceInputValidator {
624
+ private readonly rules;
625
+ constructor(rules?: RequestValidationRule[]);
626
+ validate(inferenceInput: InferenceInput, model: ModelSpecification): void;
627
+ }
628
+
629
+ declare class DefaultInferenceRunner implements InferenceRunner {
630
+ private readonly supportedModels;
631
+ private readonly requestValidator;
632
+ constructor(supportedModels: GenerativeModel[], requestValidator: InferenceInputValidator);
633
+ run(input: InferenceInput): Promise<InferenceOutput>;
634
+ stream(input: InferenceInput): AsyncGenerator<SemanticEvent>;
635
+ }
636
+
637
+ 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 };