@mozaik-ai/core 3.10.3 → 3.12.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.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import OpenAI from 'openai';
2
+ import Anthropic from '@anthropic-ai/sdk';
2
3
 
3
4
  declare abstract class ContextItem {
4
5
  abstract readonly type: string;
@@ -192,8 +193,8 @@ declare class Gpt54Nano implements GenerativeModel {
192
193
  supportFunctionCalling: boolean;
193
194
  };
194
195
  private tools;
195
- private readonly effort;
196
196
  private streaming;
197
+ private readonly effort;
197
198
  setStreaming(streaming: boolean): void;
198
199
  getStreaming(): boolean;
199
200
  setTools(tools: Tool[]): void;
@@ -214,11 +215,11 @@ declare class Gpt54 implements GenerativeModel {
214
215
  };
215
216
  private tools;
216
217
  private streaming;
218
+ private readonly effort;
217
219
  setStreaming(streaming: boolean): void;
218
220
  getStreaming(): boolean;
219
221
  setTools(tools: Tool[]): void;
220
222
  getTools(): Tool[];
221
- private readonly effort;
222
223
  setReasoningEffort(effort: OpenAIReasoningEffortType): void;
223
224
  getReasoningEffort(): OpenAIReasoningEffortType;
224
225
  }
@@ -234,8 +235,8 @@ declare class Gpt54Mini implements GenerativeModel {
234
235
  supportFunctionCalling: boolean;
235
236
  };
236
237
  private tools;
237
- private readonly effort;
238
238
  private streaming;
239
+ private readonly effort;
239
240
  setStreaming(streaming: boolean): void;
240
241
  getStreaming(): boolean;
241
242
  setReasoningEffort(effort: OpenAIReasoningEffortType): void;
@@ -291,7 +292,9 @@ declare class SemanticEvent<T> {
291
292
 
292
293
  declare class AgenticEnvironment {
293
294
  protected subscribers: Participant[];
295
+ private name?;
294
296
  private isActive;
297
+ constructor(name?: string);
295
298
  subscribe(participant: Participant): void;
296
299
  unsubscribe(participant: Participant): void;
297
300
  deliverFunctionCall(source: Participant, item: FunctionCallItem): void;
@@ -300,16 +303,21 @@ declare class AgenticEnvironment {
300
303
  deliverFunctionCallOutput(source: Participant, item: FunctionCallOutputItem): void;
301
304
  deliverMessage(source: Participant, message: string): void;
302
305
  deliverSemanticEvent(source: Participant, item: SemanticEvent<unknown>): void;
306
+ private getListeningParticipants;
307
+ private deliverToSubscribers;
303
308
  start(): Promise<void>;
304
309
  stop(): void;
305
310
  }
306
311
 
312
+ type ParticipantClassConstructor = new (...args: any[]) => Participant;
307
313
  declare abstract class Participant {
308
314
  private environments;
315
+ protected listens: ParticipantClassConstructor[];
309
316
  join(environment: AgenticEnvironment): void;
310
317
  leave(environment: AgenticEnvironment): void;
311
318
  protected isJoinedTo(environment: AgenticEnvironment): boolean;
312
319
  getEnvironments(): AgenticEnvironment[];
320
+ getListeners(): ParticipantClassConstructor[];
313
321
  abstract onParticipantJoined(participant: Participant): Promise<void> | void;
314
322
  abstract onParticipantLeft(participant: Participant): Promise<void> | void;
315
323
  abstract onJoined(): Promise<void> | void;
@@ -385,12 +393,43 @@ declare class BaseHuman extends Human {
385
393
  onExternalEvent(source: Participant, item: SemanticEvent<unknown>): void;
386
394
  }
387
395
 
396
+ declare class InferenceRequest {
397
+ readonly model: GenerativeModel & ReasoningEffort<string> & ToolCallingCapability;
398
+ readonly context: ModelContext;
399
+ constructor(model: GenerativeModel & ReasoningEffort<string> & ToolCallingCapability, context: ModelContext);
400
+ }
401
+
402
+ declare class InferenceResponse {
403
+ readonly contextItems: ContextItem[];
404
+ readonly tokenUsage?: TokenUsage;
405
+ constructor(contextItems: ContextItem[], tokenUsage: TokenUsage | undefined);
406
+ }
407
+
408
+ /**
409
+ * Provider-agnostic port for a single round of inference.
410
+ *
411
+ * Lives in the domain layer; concrete adapters (OpenAI Responses,
412
+ * Anthropic Messages, DeepSeek Chat Completions, …) live in the
413
+ * infrastructure layer and are injected into application-layer runners
414
+ * through their constructor. The application layer must depend on this
415
+ * interface, never on a concrete provider client.
416
+ */
417
+ interface ModelRuntime {
418
+ infer(request: InferenceRequest): Promise<InferenceResponse>;
419
+ }
420
+
388
421
  type InferenceItem = ReasoningItem | FunctionCallItem | ModelMessageItem | SemanticEvent<unknown>;
389
- declare class OpenAIInferenceRunner implements InferenceRunner {
422
+ /**
423
+ * Provider-agnostic inference runner: it depends on
424
+ * the {@link ModelRuntime} domain port and receives a concrete
425
+ * infrastructure adapter (OpenAIResponses, AnthropicMessages, …)
426
+ * through its constructor.
427
+ */
428
+ declare class DefaultInferenceRunner implements InferenceRunner {
429
+ private readonly runtime;
430
+ constructor(runtime: ModelRuntime);
390
431
  run(context: ModelContext, model: GenerativeModel, signal?: AbortSignal): AsyncIterable<InferenceItem>;
391
- extractTokenUsage(response: OpenAI.Responses.Response): TokenUsage | undefined;
392
- mapContextToRequest(context: ModelContext): any[];
393
- extractContextItems(response: any): ContextItem[];
432
+ private isStreamingRuntime;
394
433
  }
395
434
 
396
435
  declare class DefaultFunctionCallRunner implements FunctionCallRunner {
@@ -411,11 +450,11 @@ declare class Gpt55 implements GenerativeModel {
411
450
  };
412
451
  private tools;
413
452
  private streaming;
453
+ private readonly effort;
414
454
  setStreaming(streaming: boolean): void;
415
455
  getStreaming(): boolean;
416
456
  setTools(tools: Tool[]): void;
417
457
  getTools(): Tool[];
418
- private readonly effort;
419
458
  setReasoningEffort(effort: OpenAIReasoningEffortType): void;
420
459
  getReasoningEffort(): OpenAIReasoningEffortType;
421
460
  }
@@ -441,4 +480,299 @@ declare class BaseObserver extends Observer {
441
480
  onExternalEvent(source: Participant, item: SemanticEvent<unknown>): void;
442
481
  }
443
482
 
444
- export { Agent, AgenticEnvironment, BaseAgent, BaseHuman, BaseObserver, ContextItem, DefaultFunctionCallRunner, DeveloperMessageItem, FunctionCallItem, FunctionCallOutputItem, type FunctionCallRunner, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, Gpt55, Human, InMemoryModelContextRepository, type InferenceRunner, InputTokenDetails, ModelContext, type ModelContextRepository, ModelMessageItem, Observer, OpenAIInferenceRunner, OutputTokenDetails, Participant, ReasoningItem, SemanticEvent, SystemMessageItem, TokenUsage, type Tool, UserMessageItem };
483
+ /**
484
+ * Optional streaming companion to {@link ModelRuntime}. Adapters whose
485
+ * provider can stream a round implement this in addition to
486
+ * `ModelRuntime`; runners delegate to `stream` only when the model has
487
+ * streaming enabled and the injected runtime actually implements it.
488
+ */
489
+ interface StreamingRuntime {
490
+ stream(request: InferenceRequest, signal?: AbortSignal): AsyncIterable<ReasoningItem | FunctionCallItem | ModelMessageItem | SemanticEvent<unknown>>;
491
+ }
492
+
493
+ declare class OpenAIResponses implements ModelRuntime, StreamingRuntime {
494
+ private readonly client;
495
+ constructor();
496
+ infer(inferenceRequest: InferenceRequest): Promise<InferenceResponse>;
497
+ stream(inferenceRequest: InferenceRequest, signal?: AbortSignal): AsyncIterable<ReasoningItem | FunctionCallItem | ModelMessageItem | SemanticEvent<unknown>>;
498
+ private buildRequest;
499
+ extractTokenUsage(response: OpenAI.Responses.Response): TokenUsage | undefined;
500
+ mapContextToRequest(context: ModelContext): any[];
501
+ extractContextItems(response: any): ContextItem[];
502
+ }
503
+
504
+ /**
505
+ * Optional connection config. When omitted, the `openai` SDK reads
506
+ * `OPENAI_API_KEY` and `OPENAI_BASE_URL` from the environment, so the
507
+ * default-constructed runtime targets whatever `OPENAI_BASE_URL` points
508
+ * at (real OpenAI when unset). Provider presets (e.g. DeepSeek) pass an
509
+ * explicit base URL + credential.
510
+ */
511
+ interface OpenAICompatibleConfig {
512
+ baseURL?: string;
513
+ apiKey?: string;
514
+ /**
515
+ * Extra request-body fields merged into every `chat.completions`
516
+ * call. This is how provider-specific quirks are handled **without
517
+ * a per-provider subclass in mozaik** — the consumer supplies the
518
+ * vendor-only fields (e.g. DeepSeek's `{ thinking: { type } }`,
519
+ * safety flags, routing hints). Standard fields the runtime already
520
+ * sets (`model`, `messages`, `tools`, `reasoning_effort`) take
521
+ * precedence and are not overwritten.
522
+ */
523
+ extraBody?: Record<string, unknown>;
524
+ }
525
+ /**
526
+ * Generic adapter for any **OpenAI Chat Completions**-compatible
527
+ * endpoint — real OpenAI, DeepSeek, Xiaomi MiMo, OpenRouter, vLLM,
528
+ * Ollama, etc. It speaks `/chat/completions` (not the Responses API),
529
+ * which is the dialect third-party OpenAI-compatible providers expose.
530
+ *
531
+ * The base URL and credential are configurable; everything else (the
532
+ * `ModelContext` ⇄ chat-message conversion, tool-call round-trip, token
533
+ * usage extraction) is provider-agnostic. Provider-specific request
534
+ * shaping (e.g. DeepSeek's `thinking` field) is supplied by the
535
+ * consumer via {@link OpenAICompatibleConfig.extraBody} — mozaik stays
536
+ * generic and gains no per-provider subclasses.
537
+ *
538
+ * Was `DeepSeekChatCompletions`; generalized so consumers can point it
539
+ * at any OpenAI-compatible endpoint.
540
+ */
541
+ declare class OpenAICompatibleChatCompletions implements ModelRuntime, StreamingRuntime {
542
+ private readonly client;
543
+ private readonly extraBody;
544
+ constructor(config?: OpenAICompatibleConfig);
545
+ infer(inferenceRequest: InferenceRequest): Promise<InferenceResponse>;
546
+ stream(inferenceRequest: InferenceRequest, signal?: AbortSignal): AsyncIterable<ReasoningItem | FunctionCallItem | ModelMessageItem | SemanticEvent<unknown>>;
547
+ buildRequest(inferenceRequest: InferenceRequest): any;
548
+ extractTokenUsage(response: any): TokenUsage | undefined;
549
+ mapContextToRequest(context: ModelContext): any[];
550
+ extractContextItems(response: any): ContextItem[];
551
+ }
552
+
553
+ declare class AnthropicMessages implements ModelRuntime, StreamingRuntime {
554
+ private readonly client;
555
+ constructor();
556
+ infer(inferenceRequest: InferenceRequest): Promise<InferenceResponse>;
557
+ stream(inferenceRequest: InferenceRequest, signal?: AbortSignal): AsyncIterable<ReasoningItem | FunctionCallItem | ModelMessageItem | SemanticEvent<unknown>>;
558
+ private buildRequest;
559
+ extractTokenUsage(response: Anthropic.Messages.Message): TokenUsage | undefined;
560
+ mapContextToRequest(context: ModelContext): {
561
+ messages: any[];
562
+ system?: string;
563
+ };
564
+ extractContextItems(response: Anthropic.Messages.Message): ContextItem[];
565
+ private addContentBlock;
566
+ }
567
+
568
+ type AnthropicReasoningEffortType = "high" | "medium" | "low" | "none";
569
+
570
+ declare class ClaudeOpus48 implements GenerativeModel {
571
+ readonly specification: {
572
+ name: string;
573
+ supportReasoningEffort: boolean;
574
+ defaultReasoningEffort: AnthropicReasoningEffortType;
575
+ supportStreaming: boolean;
576
+ contextWindowSize: number;
577
+ maxOutputTokens: number;
578
+ supportFunctionCalling: boolean;
579
+ };
580
+ private tools;
581
+ private streaming;
582
+ private readonly effort;
583
+ setStreaming(streaming: boolean): void;
584
+ getStreaming(): boolean;
585
+ setTools(tools: Tool[]): void;
586
+ getTools(): Tool[];
587
+ setReasoningEffort(effort: AnthropicReasoningEffortType): void;
588
+ getReasoningEffort(): AnthropicReasoningEffortType;
589
+ }
590
+
591
+ declare class ClaudeOpus47 implements GenerativeModel {
592
+ readonly specification: {
593
+ name: string;
594
+ supportReasoningEffort: boolean;
595
+ defaultReasoningEffort: AnthropicReasoningEffortType;
596
+ supportStreaming: boolean;
597
+ contextWindowSize: number;
598
+ maxOutputTokens: number;
599
+ supportFunctionCalling: boolean;
600
+ };
601
+ private tools;
602
+ private streaming;
603
+ private readonly effort;
604
+ setStreaming(streaming: boolean): void;
605
+ getStreaming(): boolean;
606
+ setTools(tools: Tool[]): void;
607
+ getTools(): Tool[];
608
+ setReasoningEffort(effort: AnthropicReasoningEffortType): void;
609
+ getReasoningEffort(): AnthropicReasoningEffortType;
610
+ }
611
+
612
+ declare class ClaudeSonnet46 implements GenerativeModel {
613
+ readonly specification: {
614
+ name: string;
615
+ supportReasoningEffort: boolean;
616
+ defaultReasoningEffort: AnthropicReasoningEffortType;
617
+ supportStreaming: boolean;
618
+ contextWindowSize: number;
619
+ maxOutputTokens: number;
620
+ supportFunctionCalling: boolean;
621
+ };
622
+ private tools;
623
+ private streaming;
624
+ setStreaming(streaming: boolean): void;
625
+ getStreaming(): boolean;
626
+ setTools(tools: Tool[]): void;
627
+ getTools(): Tool[];
628
+ private readonly effort;
629
+ setReasoningEffort(effort: AnthropicReasoningEffortType): void;
630
+ getReasoningEffort(): AnthropicReasoningEffortType;
631
+ }
632
+
633
+ declare class ClaudeHaiku45 implements GenerativeModel {
634
+ readonly specification: {
635
+ name: string;
636
+ supportReasoningEffort: boolean;
637
+ defaultReasoningEffort: AnthropicReasoningEffortType;
638
+ supportStreaming: boolean;
639
+ contextWindowSize: number;
640
+ maxOutputTokens: number;
641
+ supportFunctionCalling: boolean;
642
+ };
643
+ private tools;
644
+ private streaming;
645
+ private readonly effort;
646
+ setStreaming(streaming: boolean): void;
647
+ getStreaming(): boolean;
648
+ setTools(tools: Tool[]): void;
649
+ getTools(): Tool[];
650
+ setReasoningEffort(effort: AnthropicReasoningEffortType): void;
651
+ getReasoningEffort(): AnthropicReasoningEffortType;
652
+ }
653
+
654
+ /**
655
+ * DeepSeek V4 reasoning levels. `"none"` selects non-thinking mode
656
+ * (`thinking: { type: "disabled" }`); any other value enables thinking
657
+ * mode and is forwarded as the `reasoning_effort` request parameter.
658
+ */
659
+ type DeepSeekReasoningEffortType = "max" | "high" | "medium" | "low" | "none";
660
+
661
+ declare class DeepSeekV4Flash implements GenerativeModel {
662
+ readonly specification: {
663
+ name: string;
664
+ supportReasoningEffort: boolean;
665
+ defaultReasoningEffort: DeepSeekReasoningEffortType;
666
+ supportStreaming: boolean;
667
+ contextWindowSize: number;
668
+ maxOutputTokens: number;
669
+ supportFunctionCalling: boolean;
670
+ };
671
+ private tools;
672
+ private streaming;
673
+ private readonly effort;
674
+ setStreaming(streaming: boolean): void;
675
+ getStreaming(): boolean;
676
+ setTools(tools: Tool[]): void;
677
+ getTools(): Tool[];
678
+ setReasoningEffort(effort: DeepSeekReasoningEffortType): void;
679
+ getReasoningEffort(): DeepSeekReasoningEffortType;
680
+ }
681
+
682
+ declare class DeepSeekV4Pro implements GenerativeModel {
683
+ readonly specification: {
684
+ name: string;
685
+ supportReasoningEffort: boolean;
686
+ defaultReasoningEffort: DeepSeekReasoningEffortType;
687
+ supportStreaming: boolean;
688
+ contextWindowSize: number;
689
+ maxOutputTokens: number;
690
+ supportFunctionCalling: boolean;
691
+ };
692
+ private tools;
693
+ private streaming;
694
+ private readonly effort;
695
+ setStreaming(streaming: boolean): void;
696
+ getStreaming(): boolean;
697
+ setTools(tools: Tool[]): void;
698
+ getTools(): Tool[];
699
+ setReasoningEffort(effort: DeepSeekReasoningEffortType): void;
700
+ getReasoningEffort(): DeepSeekReasoningEffortType;
701
+ }
702
+
703
+ /**
704
+ * Native Gemini adapter on the `@google/genai` SDK (`generateContent` /
705
+ * `generateContentStream`). Unlike an OpenAI-compat shim this maps our
706
+ * domain context to Gemini's native `contents`/`parts` shape, system
707
+ * instruction, `functionDeclarations`, and `thinkingConfig`, and reads
708
+ * thought parts + native usage metadata back out. Another `ModelRuntime`
709
+ * — no runner or port changes.
710
+ */
711
+ declare class GeminiGenerateContent implements ModelRuntime, StreamingRuntime {
712
+ private readonly client;
713
+ constructor();
714
+ infer(inferenceRequest: InferenceRequest): Promise<InferenceResponse>;
715
+ stream(inferenceRequest: InferenceRequest, signal?: AbortSignal): AsyncIterable<ReasoningItem | FunctionCallItem | ModelMessageItem | SemanticEvent<unknown>>;
716
+ private buildRequest;
717
+ extractTokenUsage(response: any): TokenUsage | undefined;
718
+ mapContextToRequest(context: ModelContext): {
719
+ contents: any[];
720
+ systemInstruction?: string;
721
+ };
722
+ extractContextItems(response: any): ContextItem[];
723
+ private parseResponse;
724
+ private addPart;
725
+ }
726
+
727
+ /**
728
+ * Gemini reasoning levels, forwarded as the `reasoning_effort` request
729
+ * parameter on the OpenAI-compatible endpoint. `"none"` only disables
730
+ * thinking on Gemini 2.5 models; Gemini 3.x always thinks, so for those
731
+ * the adapter simply omits `reasoning_effort` when set to `"none"` and
732
+ * lets the model use its default thinking level.
733
+ */
734
+ type GeminiReasoningEffortType = "high" | "medium" | "low" | "minimal" | "none";
735
+
736
+ declare class Gemini35Flash implements GenerativeModel {
737
+ readonly specification: {
738
+ name: string;
739
+ supportReasoningEffort: boolean;
740
+ defaultReasoningEffort: GeminiReasoningEffortType;
741
+ supportStreaming: boolean;
742
+ contextWindowSize: number;
743
+ maxOutputTokens: number;
744
+ supportFunctionCalling: boolean;
745
+ };
746
+ private tools;
747
+ private streaming;
748
+ private readonly effort;
749
+ setStreaming(streaming: boolean): void;
750
+ getStreaming(): boolean;
751
+ setTools(tools: Tool[]): void;
752
+ getTools(): Tool[];
753
+ setReasoningEffort(effort: GeminiReasoningEffortType): void;
754
+ getReasoningEffort(): GeminiReasoningEffortType;
755
+ }
756
+
757
+ declare class Gemini31Pro implements GenerativeModel {
758
+ readonly specification: {
759
+ name: string;
760
+ supportReasoningEffort: boolean;
761
+ defaultReasoningEffort: GeminiReasoningEffortType;
762
+ supportStreaming: boolean;
763
+ contextWindowSize: number;
764
+ maxOutputTokens: number;
765
+ supportFunctionCalling: boolean;
766
+ };
767
+ private tools;
768
+ private streaming;
769
+ private readonly effort;
770
+ setStreaming(streaming: boolean): void;
771
+ getStreaming(): boolean;
772
+ setTools(tools: Tool[]): void;
773
+ getTools(): Tool[];
774
+ setReasoningEffort(effort: GeminiReasoningEffortType): void;
775
+ getReasoningEffort(): GeminiReasoningEffortType;
776
+ }
777
+
778
+ export { Agent, AgenticEnvironment, AnthropicMessages, BaseAgent, BaseHuman, BaseObserver, ClaudeHaiku45, ClaudeOpus47, ClaudeOpus48, ClaudeSonnet46, ContextItem, DeepSeekV4Flash, DeepSeekV4Pro, DefaultFunctionCallRunner, DefaultInferenceRunner, DeveloperMessageItem, FunctionCallItem, FunctionCallOutputItem, type FunctionCallRunner, Gemini31Pro, Gemini35Flash, GeminiGenerateContent, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, Gpt55, Human, InMemoryModelContextRepository, InferenceRequest, InferenceResponse, type InferenceRunner, InputTokenDetails, ModelContext, type ModelContextRepository, ModelMessageItem, type ModelRuntime, Observer, OpenAICompatibleChatCompletions, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, SemanticEvent, type StreamingRuntime, SystemMessageItem, TokenUsage, type Tool, UserMessageItem };