Vendor OpenClaw source as Adolf fork baseline
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled

Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11),
free to diverge. Tree copied sans upstream .git; upstream remote added for
future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19.
Preserves docs/ARCHITECTURE.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
This commit is contained in:
2026-07-05 09:36:54 +00:00
parent 3216769225
commit bedb527145
21108 changed files with 6010766 additions and 0 deletions

View File

@@ -0,0 +1,183 @@
// Mistral tests cover api plugin behavior.
import { registerSingleProviderPlugin } from "openclaw/plugin-sdk/plugin-test-runtime";
import { describe, expect, it } from "vitest";
import {
applyMistralModelCompat,
MISTRAL_MEDIUM_3_5_ID,
MISTRAL_MODEL_TRANSPORT_PATCH,
MISTRAL_SMALL_LATEST_ID,
resolveMistralCompatPatch,
} from "./api.js";
import mistralPlugin from "./index.js";
type MistralCompatShape = {
maxTokensField?: "max_completion_tokens" | "max_tokens";
reasoningEffortMap?: Record<string, string>;
supportsLongCacheRetention?: boolean;
supportsPromptCacheKey?: boolean;
supportsReasoningEffort?: boolean;
supportsStore?: boolean;
};
function readCompat(model: unknown): MistralCompatShape | undefined {
return (model as { compat?: MistralCompatShape }).compat;
}
function supportsStore(model: unknown): boolean | undefined {
return readCompat(model)?.supportsStore;
}
function supportsPromptCacheKey(model: unknown): boolean | undefined {
return readCompat(model)?.supportsPromptCacheKey;
}
function supportsLongCacheRetention(model: unknown): boolean | undefined {
return readCompat(model)?.supportsLongCacheRetention;
}
function supportsReasoningEffort(model: unknown): boolean | undefined {
return readCompat(model)?.supportsReasoningEffort;
}
function maxTokensField(model: unknown): "max_completion_tokens" | "max_tokens" | undefined {
return readCompat(model)?.maxTokensField;
}
function reasoningEffortMap(model: unknown): Record<string, string> | undefined {
return readCompat(model)?.reasoningEffortMap;
}
const MISTRAL_REASONING_EFFORT_MAP = {
off: "none",
minimal: "none",
low: "high",
medium: "high",
high: "high",
xhigh: "high",
adaptive: "high",
max: "high",
};
describe("resolveMistralCompatPatch", () => {
it("enables reasoning_effort mapping for mistral-small-latest", () => {
expect(resolveMistralCompatPatch({ id: MISTRAL_SMALL_LATEST_ID })).toEqual({
supportsStore: false,
supportsPromptCacheKey: true,
supportsLongCacheRetention: false,
supportsReasoningEffort: true,
maxTokensField: "max_tokens",
reasoningEffortMap: MISTRAL_REASONING_EFFORT_MAP,
});
});
it("enables reasoning_effort mapping for mistral-medium-3-5", () => {
expect(resolveMistralCompatPatch({ id: MISTRAL_MEDIUM_3_5_ID })).toEqual({
supportsStore: false,
supportsPromptCacheKey: true,
supportsLongCacheRetention: false,
supportsReasoningEffort: true,
maxTokensField: "max_tokens",
reasoningEffortMap: MISTRAL_REASONING_EFFORT_MAP,
});
});
it("disables reasoning_effort for other Mistral model ids", () => {
expect(resolveMistralCompatPatch({ id: "mistral-large-latest" })).toEqual({
...MISTRAL_MODEL_TRANSPORT_PATCH,
supportsReasoningEffort: false,
});
});
});
describe("applyMistralModelCompat", () => {
it("applies the Mistral request-shape compat flags", () => {
const normalized = applyMistralModelCompat({});
expect(supportsStore(normalized)).toBe(false);
expect(supportsPromptCacheKey(normalized)).toBe(true);
expect(supportsLongCacheRetention(normalized)).toBe(false);
expect(supportsReasoningEffort(normalized)).toBe(false);
expect(maxTokensField(normalized)).toBe("max_tokens");
expect(reasoningEffortMap(normalized)).toBeUndefined();
});
it("applies reasoning compat for mistral-small-latest", () => {
const normalized = applyMistralModelCompat({ id: MISTRAL_SMALL_LATEST_ID });
expect(supportsReasoningEffort(normalized)).toBe(true);
expect(reasoningEffortMap(normalized)?.high).toBe("high");
expect(reasoningEffortMap(normalized)?.off).toBe("none");
});
it("applies reasoning compat for mistral-medium-3-5", () => {
const normalized = applyMistralModelCompat({ id: MISTRAL_MEDIUM_3_5_ID });
expect(supportsReasoningEffort(normalized)).toBe(true);
expect(reasoningEffortMap(normalized)?.high).toBe("high");
expect(reasoningEffortMap(normalized)?.off).toBe("none");
});
it("overrides explicit compat values that would trigger 422s", () => {
const normalized = applyMistralModelCompat({
compat: {
supportsStore: true,
supportsReasoningEffort: true,
maxTokensField: "max_completion_tokens" as const,
},
});
expect(supportsStore(normalized)).toBe(false);
expect(supportsReasoningEffort(normalized)).toBe(false);
expect(maxTokensField(normalized)).toBe("max_tokens");
});
it("overrides explicit compat on mistral-small-latest except reasoning enablement", () => {
const normalized = applyMistralModelCompat({
id: MISTRAL_SMALL_LATEST_ID,
compat: {
supportsStore: true,
supportsReasoningEffort: false,
maxTokensField: "max_completion_tokens" as const,
},
});
expect(supportsStore(normalized)).toBe(false);
expect(supportsReasoningEffort(normalized)).toBe(true);
expect(maxTokensField(normalized)).toBe("max_tokens");
});
it("returns the same object when the compat patch is already present", () => {
const model = {
compat: {
supportsStore: false,
supportsPromptCacheKey: true,
supportsLongCacheRetention: false,
supportsReasoningEffort: false,
maxTokensField: "max_tokens" as const,
},
};
expect(applyMistralModelCompat(model)).toBe(model);
});
it("returns the same object when mistral-small-latest compat is fully normalized", () => {
const model = {
id: MISTRAL_SMALL_LATEST_ID,
compat: resolveMistralCompatPatch({ id: MISTRAL_SMALL_LATEST_ID }),
};
expect(applyMistralModelCompat(model)).toBe(model);
});
it("returns the same object when mistral-medium-3-5 compat is fully normalized", () => {
const model = {
id: MISTRAL_MEDIUM_3_5_ID,
compat: resolveMistralCompatPatch({ id: MISTRAL_MEDIUM_3_5_ID }),
};
expect(applyMistralModelCompat(model)).toBe(model);
});
it("exposes thinking profile levels for mistral-medium-3-5", async () => {
const provider = await registerSingleProviderPlugin(mistralPlugin);
expect(
provider.resolveThinkingProfile?.({
provider: "mistral",
modelId: MISTRAL_MEDIUM_3_5_ID,
}),
).toEqual({ levels: [{ id: "off" }, { id: "high" }], defaultLevel: "off" });
});
});

90
extensions/mistral/api.ts Normal file
View File

@@ -0,0 +1,90 @@
// Mistral API module exposes the plugin public contract.
export { buildMistralProvider } from "./provider-catalog.js";
export {
buildMistralModelDefinition,
MISTRAL_BASE_URL,
MISTRAL_DEFAULT_MODEL_ID,
} from "./model-definitions.js";
export {
applyMistralConfig,
applyMistralProviderConfig,
MISTRAL_DEFAULT_MODEL_REF,
} from "./onboard.js";
const MISTRAL_MAX_TOKENS_FIELD = "max_tokens";
export const MISTRAL_MODEL_TRANSPORT_PATCH = {
supportsStore: false,
supportsPromptCacheKey: true,
supportsLongCacheRetention: false,
maxTokensField: MISTRAL_MAX_TOKENS_FIELD,
} as const satisfies {
supportsStore: boolean;
supportsPromptCacheKey: boolean;
supportsLongCacheRetention: boolean;
maxTokensField: "max_tokens";
};
const MISTRAL_SMALL_LATEST_REASONING_EFFORT_MAP: Record<string, string> = {
off: "none",
minimal: "none",
low: "high",
medium: "high",
high: "high",
xhigh: "high",
adaptive: "high",
max: "high",
};
export const MISTRAL_SMALL_LATEST_ID = "mistral-small-latest";
export const MISTRAL_MEDIUM_3_5_ID = "mistral-medium-3-5";
export function resolveMistralCompatPatch(model: { id?: string }): {
supportsStore: boolean;
supportsPromptCacheKey: boolean;
supportsLongCacheRetention: boolean;
supportsReasoningEffort: boolean;
maxTokensField: "max_tokens";
reasoningEffortMap?: Record<string, string>;
} {
const reasoningEnabled =
model.id === MISTRAL_SMALL_LATEST_ID || model.id === MISTRAL_MEDIUM_3_5_ID;
return {
...MISTRAL_MODEL_TRANSPORT_PATCH,
supportsReasoningEffort: reasoningEnabled,
reasoningEffortMap: reasoningEnabled ? MISTRAL_SMALL_LATEST_REASONING_EFFORT_MAP : undefined,
};
}
function compatMatchesResolved(
compat: Record<string, unknown> | undefined,
modelId: string | undefined,
): boolean {
const expected = resolveMistralCompatPatch({ id: modelId });
return (
compat?.supportsStore === expected.supportsStore &&
compat?.supportsPromptCacheKey === expected.supportsPromptCacheKey &&
compat?.supportsLongCacheRetention === expected.supportsLongCacheRetention &&
compat?.supportsReasoningEffort === expected.supportsReasoningEffort &&
compat?.maxTokensField === expected.maxTokensField &&
compat?.reasoningEffortMap === expected.reasoningEffortMap
);
}
export function applyMistralModelCompat<T extends { compat?: unknown; id?: string }>(model: T): T {
const compat =
model.compat && typeof model.compat === "object"
? (model.compat as Record<string, unknown>)
: undefined;
if (compatMatchesResolved(compat, model.id)) {
return model;
}
const patch = resolveMistralCompatPatch(model);
return {
...model,
compat: {
...compat,
...patch,
} as T extends { compat?: infer TCompat } ? TCompat : never,
} as T;
}

View File

@@ -0,0 +1,53 @@
// Mistral provider module implements model/runtime integration.
import {
createRemoteEmbeddingProvider,
normalizeEmbeddingModelWithPrefixes,
resolveRemoteEmbeddingClient,
type MemoryEmbeddingProvider,
type MemoryEmbeddingProviderCreateOptions,
} from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
import type { SsrFPolicy } from "openclaw/plugin-sdk/ssrf-runtime";
type MistralEmbeddingClient = {
baseUrl: string;
headers: Record<string, string>;
ssrfPolicy?: SsrFPolicy;
model: string;
};
export const DEFAULT_MISTRAL_EMBEDDING_MODEL = "mistral-embed";
const DEFAULT_MISTRAL_BASE_URL = "https://api.mistral.ai/v1";
function normalizeMistralModel(model: string): string {
return normalizeEmbeddingModelWithPrefixes({
model,
defaultModel: DEFAULT_MISTRAL_EMBEDDING_MODEL,
prefixes: ["mistral/"],
});
}
export async function createMistralEmbeddingProvider(
options: MemoryEmbeddingProviderCreateOptions,
): Promise<{ provider: MemoryEmbeddingProvider; client: MistralEmbeddingClient }> {
const client = await resolveMistralEmbeddingClient(options);
return {
provider: createRemoteEmbeddingProvider({
id: "mistral",
client,
errorPrefix: "mistral embeddings failed",
}),
client,
};
}
async function resolveMistralEmbeddingClient(
options: MemoryEmbeddingProviderCreateOptions,
): Promise<MistralEmbeddingClient> {
return await resolveRemoteEmbeddingClient({
provider: "mistral",
options,
defaultBaseUrl: DEFAULT_MISTRAL_BASE_URL,
normalizeModel: normalizeMistralModel,
});
}

View File

@@ -0,0 +1,59 @@
// Mistral plugin entrypoint registers its OpenClaw integration.
import { defineSingleProviderPluginEntry } from "openclaw/plugin-sdk/provider-entry";
import { applyMistralModelCompat, MISTRAL_SMALL_LATEST_ID, MISTRAL_MEDIUM_3_5_ID } from "./api.js";
import { mistralMediaUnderstandingProvider } from "./media-understanding-provider.js";
import { mistralMemoryEmbeddingProviderAdapter } from "./memory-embedding-adapter.js";
import { applyMistralConfig, MISTRAL_DEFAULT_MODEL_REF } from "./onboard.js";
import { buildMistralProvider } from "./provider-catalog.js";
import { buildMistralRealtimeTranscriptionProvider } from "./realtime-transcription-provider.js";
const PROVIDER_ID = "mistral";
function buildMistralReplayPolicy() {
return {
sanitizeToolCallIds: true,
toolCallIdMode: "strict9" as const,
};
}
export default defineSingleProviderPluginEntry({
id: PROVIDER_ID,
name: "Mistral Provider",
description: "Bundled Mistral provider plugin",
provider: {
label: "Mistral",
docsPath: "/providers/models",
auth: [
{
methodId: "api-key",
label: "Mistral API key",
hint: "API key",
optionKey: "mistralApiKey",
flagName: "--mistral-api-key",
envVar: "MISTRAL_API_KEY",
promptMessage: "Enter Mistral API key",
defaultModel: MISTRAL_DEFAULT_MODEL_REF,
applyConfig: (cfg) => applyMistralConfig(cfg),
wizard: {
groupLabel: "Mistral AI",
},
},
],
catalog: {
buildProvider: buildMistralProvider,
allowExplicitBaseUrl: true,
},
matchesContextOverflowError: ({ errorMessage }) =>
/\bmistral\b.*(?:input.*too long|token limit.*exceeded)/i.test(errorMessage),
normalizeResolvedModel: ({ model }) => applyMistralModelCompat(model),
resolveThinkingProfile: ({ modelId }) =>
modelId === MISTRAL_SMALL_LATEST_ID || modelId === MISTRAL_MEDIUM_3_5_ID
? { levels: [{ id: "off" }, { id: "high" }], defaultLevel: "off" }
: undefined,
buildReplayPolicy: () => buildMistralReplayPolicy(),
},
register(api) {
api.registerMemoryEmbeddingProvider(mistralMemoryEmbeddingProviderAdapter);
api.registerMediaUnderstandingProvider(mistralMediaUnderstandingProvider);
api.registerRealtimeTranscriptionProvider(buildMistralRealtimeTranscriptionProvider());
},
});

View File

@@ -0,0 +1,47 @@
// Mistral tests cover media understanding provider plugin behavior.
import {
createRequestCaptureJsonFetch,
installPinnedHostnameTestHooks,
} from "openclaw/plugin-sdk/test-env";
import { describe, expect, it } from "vitest";
import { mistralMediaUnderstandingProvider } from "./media-understanding-provider.js";
installPinnedHostnameTestHooks();
describe("mistralMediaUnderstandingProvider", () => {
it("has expected provider metadata", () => {
expect(mistralMediaUnderstandingProvider.id).toBe("mistral");
expect(mistralMediaUnderstandingProvider.capabilities).toEqual(["audio"]);
expect(mistralMediaUnderstandingProvider.transcribeAudio).toBeTypeOf("function");
});
it("uses Mistral base URL by default", async () => {
const { fetchFn, getRequest } = createRequestCaptureJsonFetch({ text: "bonjour" });
const result = await mistralMediaUnderstandingProvider.transcribeAudio!({
buffer: Buffer.from("audio-bytes"),
fileName: "voice.ogg",
apiKey: "test-mistral-key",
timeoutMs: 5000,
fetchFn,
});
expect(getRequest().url).toBe("https://api.mistral.ai/v1/audio/transcriptions");
expect(result.text).toBe("bonjour");
});
it("allows overriding baseUrl", async () => {
const { fetchFn, getRequest } = createRequestCaptureJsonFetch({ text: "ok" });
await mistralMediaUnderstandingProvider.transcribeAudio!({
buffer: Buffer.from("audio"),
fileName: "note.mp3",
apiKey: "key",
timeoutMs: 1000,
baseUrl: "https://custom.mistral.example/v1",
fetchFn,
});
expect(getRequest().url).toBe("https://custom.mistral.example/v1/audio/transcriptions");
});
});

View File

@@ -0,0 +1,22 @@
// Mistral provider module implements model/runtime integration.
import {
transcribeOpenAiCompatibleAudio,
type MediaUnderstandingProvider,
} from "openclaw/plugin-sdk/media-understanding";
const DEFAULT_MISTRAL_AUDIO_BASE_URL = "https://api.mistral.ai/v1";
const DEFAULT_MISTRAL_AUDIO_MODEL = "voxtral-mini-latest";
export const mistralMediaUnderstandingProvider: MediaUnderstandingProvider = {
id: "mistral",
capabilities: ["audio"],
defaultModels: { audio: DEFAULT_MISTRAL_AUDIO_MODEL },
autoPriority: { audio: 50 },
transcribeAudio: async (req) =>
await transcribeOpenAiCompatibleAudio({
...req,
baseUrl: req.baseUrl ?? DEFAULT_MISTRAL_AUDIO_BASE_URL,
defaultBaseUrl: DEFAULT_MISTRAL_AUDIO_BASE_URL,
defaultModel: DEFAULT_MISTRAL_AUDIO_MODEL,
}),
};

View File

@@ -0,0 +1,36 @@
// Mistral plugin module implements memory embedding adapter behavior.
import {
isMissingEmbeddingApiKeyError,
type MemoryEmbeddingProviderAdapter,
} from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
import {
createMistralEmbeddingProvider,
DEFAULT_MISTRAL_EMBEDDING_MODEL,
} from "./embedding-provider.js";
export const mistralMemoryEmbeddingProviderAdapter: MemoryEmbeddingProviderAdapter = {
id: "mistral",
defaultModel: DEFAULT_MISTRAL_EMBEDDING_MODEL,
transport: "remote",
authProviderId: "mistral",
autoSelectPriority: 50,
allowExplicitWhenConfiguredAuto: true,
shouldContinueAutoSelection: isMissingEmbeddingApiKeyError,
create: async (options) => {
const { provider, client } = await createMistralEmbeddingProvider({
...options,
provider: "mistral",
fallback: "none",
});
return {
provider,
runtime: {
id: "mistral",
cacheKeyData: {
provider: "mistral",
model: client.model,
},
},
};
},
};

View File

@@ -0,0 +1,63 @@
// Mistral tests cover mistral plugin behavior.
import {
normalizeTranscriptForMatch,
runRealtimeSttLiveTest,
synthesizeElevenLabsLiveSpeech,
} from "openclaw/plugin-sdk/provider-test-contracts";
import { isLiveTestEnabled } from "openclaw/plugin-sdk/test-env";
import { describe, expect, it } from "vitest";
import { mistralMediaUnderstandingProvider } from "./media-understanding-provider.js";
import { buildMistralRealtimeTranscriptionProvider } from "./realtime-transcription-provider.js";
const MISTRAL_KEY = process.env.MISTRAL_API_KEY ?? "";
const ELEVENLABS_KEY = process.env.ELEVENLABS_API_KEY ?? "";
const LIVE = isLiveTestEnabled(["MISTRAL_LIVE_TEST"]);
const describeLive = LIVE && MISTRAL_KEY && ELEVENLABS_KEY ? describe : describe.skip;
describeLive("mistral plugin live", () => {
it("transcribes synthesized speech through the media provider", async () => {
const phrase = "Testing OpenClaw Mistral speech to text integration OK.";
const audio = await synthesizeElevenLabsLiveSpeech({
text: phrase,
apiKey: ELEVENLABS_KEY,
outputFormat: "mp3_44100_128",
timeoutMs: 30_000,
});
const transcript = await mistralMediaUnderstandingProvider.transcribeAudio?.({
buffer: audio,
fileName: "mistral-live.mp3",
mime: "audio/mpeg",
apiKey: MISTRAL_KEY,
timeoutMs: 60_000,
});
const normalized = normalizeTranscriptForMatch(transcript?.text ?? "");
expect(normalized).toContain("openclaw");
expect(normalized).toContain("mistral");
}, 90_000);
it("streams realtime STT through the registered transcription provider", async () => {
const provider = buildMistralRealtimeTranscriptionProvider();
const phrase = "Testing OpenClaw Mistral realtime transcription integration OK.";
const speech = await synthesizeElevenLabsLiveSpeech({
text: phrase,
apiKey: ELEVENLABS_KEY,
outputFormat: "ulaw_8000",
timeoutMs: 30_000,
});
expect(speech.byteLength).toBeGreaterThan(0);
await runRealtimeSttLiveTest({
provider,
providerConfig: {
apiKey: MISTRAL_KEY,
sampleRate: 8000,
encoding: "pcm_mulaw",
targetStreamingDelayMs: 800,
},
audio: Buffer.concat([Buffer.alloc(4000, 0xff), speech, Buffer.alloc(8000, 0xff)]),
closeBeforeWait: true,
});
}, 90_000);
});

View File

@@ -0,0 +1,79 @@
// Mistral tests cover model definitions plugin behavior.
import { describe, expect, it } from "vitest";
import {
buildMistralCatalogModels,
buildMistralModelDefinition,
MISTRAL_DEFAULT_MODEL_ID,
} from "./model-definitions.js";
function catalogModelById(models: ReturnType<typeof buildMistralCatalogModels>, id: string) {
const model = models.find((candidate) => candidate.id === id);
if (!model) {
throw new Error(`expected Mistral catalog model ${id}`);
}
return model;
}
describe("mistral model definitions", () => {
it("uses current OpenClaw pricing for the bundled default model", () => {
const model = buildMistralModelDefinition();
expect(model.id).toBe(MISTRAL_DEFAULT_MODEL_ID);
expect(model.contextWindow).toBe(262144);
expect(model.maxTokens).toBe(16384);
expect(model.cost).toEqual({
input: 0.5,
output: 1.5,
cacheRead: 0.05,
cacheWrite: 0,
});
});
it("prices cached Mistral input tokens at ten percent of standard input tokens", () => {
const models = buildMistralCatalogModels();
for (const model of models) {
expect(model.cost.cacheRead).toBeCloseTo(model.cost.input * 0.1, 10);
expect(model.cost.cacheWrite).toBe(0);
}
});
it("charges nonzero cost for cached-token usage on the default model", () => {
const model = buildMistralModelDefinition();
const cacheReadTokens = 20_000;
const cacheReadCost = (model.cost.cacheRead / 1_000_000) * cacheReadTokens;
expect(cacheReadCost).toBeCloseTo(0.001, 10);
expect(cacheReadCost).toBeGreaterThan(0);
});
it("publishes a curated set of current Mistral catalog models", () => {
const models = buildMistralCatalogModels();
const codestral = catalogModelById(models, "codestral-latest");
expect(codestral.input).toEqual(["text"]);
expect(codestral.contextWindow).toBe(256000);
expect(codestral.maxTokens).toBe(4096);
const magistralSmall = catalogModelById(models, "magistral-small");
expect(magistralSmall.reasoning).toBe(true);
expect(magistralSmall.input).toEqual(["text"]);
expect(magistralSmall.contextWindow).toBe(128000);
expect(magistralSmall.maxTokens).toBe(40000);
const medium = catalogModelById(models, "mistral-medium-3-5");
expect(medium.reasoning).toBe(true);
expect(medium.input).toEqual(["text", "image"]);
expect(medium.contextWindow).toBe(262144);
expect(medium.maxTokens).toBe(8192);
const smallLatest = catalogModelById(models, "mistral-small-latest");
expect(smallLatest.reasoning).toBe(true);
expect(smallLatest.input).toEqual(["text", "image"]);
expect(smallLatest.contextWindow).toBe(128000);
expect(smallLatest.maxTokens).toBe(16384);
const pixtralLarge = catalogModelById(models, "pixtral-large-latest");
expect(pixtralLarge.input).toEqual(["text", "image"]);
expect(pixtralLarge.contextWindow).toBe(128000);
expect(pixtralLarge.maxTokens).toBe(32768);
});
});

View File

@@ -0,0 +1,24 @@
// Mistral plugin module implements model definitions behavior.
import { buildManifestModelProviderConfig } from "openclaw/plugin-sdk/provider-catalog-shared";
import type { ModelDefinitionConfig } from "openclaw/plugin-sdk/provider-model-shared";
import manifest from "./openclaw.plugin.json" with { type: "json" };
const MISTRAL_MANIFEST_CATALOG = manifest.modelCatalog.providers.mistral;
export const MISTRAL_BASE_URL = MISTRAL_MANIFEST_CATALOG.baseUrl;
export const MISTRAL_DEFAULT_MODEL_ID = "mistral-large-latest";
export function buildMistralModelDefinition(): ModelDefinitionConfig {
const model = buildMistralCatalogModels().find((entry) => entry.id === MISTRAL_DEFAULT_MODEL_ID);
if (!model) {
throw new Error(`Missing Mistral provider model ${MISTRAL_DEFAULT_MODEL_ID}`);
}
return model;
}
export function buildMistralCatalogModels(): ModelDefinitionConfig[] {
return buildManifestModelProviderConfig({
providerId: "mistral",
catalog: MISTRAL_MANIFEST_CATALOG,
}).models;
}

View File

@@ -0,0 +1,55 @@
// Mistral tests cover onboard plugin behavior.
import {
expectProviderOnboardMergedLegacyConfig,
expectProviderOnboardPrimaryAndFallbacks,
} from "openclaw/plugin-sdk/provider-test-contracts";
import { describe, expect, it } from "vitest";
import { buildMistralModelDefinition as buildBundledMistralModelDefinition } from "./model-definitions.js";
import {
applyMistralConfig,
applyMistralProviderConfig,
MISTRAL_DEFAULT_MODEL_REF,
} from "./onboard.js";
describe("mistral onboard", () => {
it("adds Mistral provider with correct settings", () => {
const cfg = applyMistralConfig({});
expect(cfg.models?.providers?.mistral?.baseUrl).toBe("https://api.mistral.ai/v1");
expect(cfg.models?.providers?.mistral?.api).toBe("openai-completions");
expectProviderOnboardPrimaryAndFallbacks({
applyConfig: applyMistralConfig,
modelRef: MISTRAL_DEFAULT_MODEL_REF,
});
});
it("merges Mistral models and keeps existing provider overrides", () => {
const provider = expectProviderOnboardMergedLegacyConfig({
applyProviderConfig: applyMistralProviderConfig,
providerId: "mistral",
providerApi: "openai-completions",
baseUrl: "https://api.mistral.ai/v1",
legacyApi: "anthropic-messages",
legacyModelId: "custom-model",
legacyModelName: "Custom",
});
expect(provider?.models.map((m) => m.id)).toEqual(["custom-model", "mistral-large-latest"]);
const mistralDefault = provider?.models.find((model) => model.id === "mistral-large-latest");
expect(mistralDefault?.contextWindow).toBe(262144);
expect(mistralDefault?.maxTokens).toBe(16384);
});
it("uses the bundled mistral default model definition", () => {
const bundled = buildBundledMistralModelDefinition();
const cfg = applyMistralProviderConfig({});
const defaultModel = cfg.models?.providers?.mistral?.models.find(
(model) => model.id === bundled.id,
);
expect(defaultModel).toEqual(bundled);
});
it("adds the expected alias for the default model", () => {
const cfg = applyMistralProviderConfig({});
expect(cfg.agents?.defaults?.models?.[MISTRAL_DEFAULT_MODEL_REF]?.alias).toBe("Mistral");
});
});

View File

@@ -0,0 +1,32 @@
// Mistral setup module handles plugin onboarding behavior.
import {
createDefaultModelPresetAppliers,
type OpenClawConfig,
} from "openclaw/plugin-sdk/provider-onboard";
import {
buildMistralModelDefinition,
MISTRAL_BASE_URL,
MISTRAL_DEFAULT_MODEL_ID,
} from "./model-definitions.js";
export const MISTRAL_DEFAULT_MODEL_REF = `mistral/${MISTRAL_DEFAULT_MODEL_ID}`;
const mistralPresetAppliers = createDefaultModelPresetAppliers({
primaryModelRef: MISTRAL_DEFAULT_MODEL_REF,
resolveParams: (_cfg: OpenClawConfig) => ({
providerId: "mistral",
api: "openai-completions",
baseUrl: MISTRAL_BASE_URL,
defaultModel: buildMistralModelDefinition(),
defaultModelId: MISTRAL_DEFAULT_MODEL_ID,
aliases: [{ modelRef: MISTRAL_DEFAULT_MODEL_REF, alias: "Mistral" }],
}),
});
export function applyMistralProviderConfig(cfg: OpenClawConfig): OpenClawConfig {
return mistralPresetAppliers.applyProviderConfig(cfg);
}
export function applyMistralConfig(cfg: OpenClawConfig): OpenClawConfig {
return mistralPresetAppliers.applyConfig(cfg);
}

View File

@@ -0,0 +1,186 @@
{
"id": "mistral",
"icon": "https://cdn.simpleicons.org/mistralai",
"activation": {
"onStartup": false
},
"enabledByDefault": true,
"providers": ["mistral"],
"providerEndpoints": [
{
"endpointClass": "mistral-public",
"hosts": ["api.mistral.ai"]
}
],
"providerRequest": {
"providers": {
"mistral": {
"family": "mistral"
}
}
},
"modelCatalog": {
"providers": {
"mistral": {
"baseUrl": "https://api.mistral.ai/v1",
"api": "openai-completions",
"models": [
{
"id": "codestral-latest",
"name": "Codestral (latest)",
"input": ["text"],
"contextWindow": 256000,
"maxTokens": 4096,
"cost": {
"input": 0.3,
"output": 0.9,
"cacheRead": 0.03,
"cacheWrite": 0
}
},
{
"id": "devstral-medium-latest",
"name": "Devstral 2 (latest)",
"input": ["text"],
"contextWindow": 262144,
"maxTokens": 32768,
"cost": {
"input": 0.4,
"output": 2,
"cacheRead": 0.04,
"cacheWrite": 0
}
},
{
"id": "magistral-small",
"name": "Magistral Small",
"input": ["text"],
"reasoning": true,
"contextWindow": 128000,
"maxTokens": 40000,
"cost": {
"input": 0.5,
"output": 1.5,
"cacheRead": 0.05,
"cacheWrite": 0
}
},
{
"id": "mistral-large-latest",
"name": "Mistral Large (latest)",
"input": ["text", "image"],
"contextWindow": 262144,
"maxTokens": 16384,
"cost": {
"input": 0.5,
"output": 1.5,
"cacheRead": 0.05,
"cacheWrite": 0
}
},
{
"id": "mistral-medium-2508",
"name": "Mistral Medium 3.1",
"input": ["text", "image"],
"contextWindow": 262144,
"maxTokens": 8192,
"cost": {
"input": 0.4,
"output": 2,
"cacheRead": 0.04,
"cacheWrite": 0
}
},
{
"id": "mistral-medium-3-5",
"name": "Mistral Medium 3.5",
"input": ["text", "image"],
"reasoning": true,
"contextWindow": 262144,
"maxTokens": 8192,
"cost": {
"input": 1.5,
"output": 7.5,
"cacheRead": 0.15,
"cacheWrite": 0
}
},
{
"id": "mistral-small-latest",
"name": "Mistral Small (latest)",
"input": ["text", "image"],
"reasoning": true,
"contextWindow": 128000,
"maxTokens": 16384,
"cost": {
"input": 0.1,
"output": 0.3,
"cacheRead": 0.01,
"cacheWrite": 0
}
},
{
"id": "pixtral-large-latest",
"name": "Pixtral Large (latest)",
"input": ["text", "image"],
"contextWindow": 128000,
"maxTokens": 32768,
"cost": {
"input": 2,
"output": 6,
"cacheRead": 0.2,
"cacheWrite": 0
}
}
]
}
},
"discovery": {
"mistral": "static"
}
},
"setup": {
"providers": [
{
"id": "mistral",
"envVars": ["MISTRAL_API_KEY"]
}
]
},
"providerAuthChoices": [
{
"provider": "mistral",
"method": "api-key",
"choiceId": "mistral-api-key",
"choiceLabel": "Mistral API key",
"groupId": "mistral",
"groupLabel": "Mistral AI",
"groupHint": "API key",
"optionKey": "mistralApiKey",
"cliFlag": "--mistral-api-key",
"cliOption": "--mistral-api-key <key>",
"cliDescription": "Mistral API key"
}
],
"contracts": {
"memoryEmbeddingProviders": ["mistral"],
"mediaUnderstandingProviders": ["mistral"],
"realtimeTranscriptionProviders": ["mistral"]
},
"mediaUnderstandingProviderMetadata": {
"mistral": {
"capabilities": ["audio"],
"defaultModels": {
"audio": "voxtral-mini-latest"
},
"autoPriority": {
"audio": 50
}
}
},
"configSchema": {
"type": "object",
"additionalProperties": false,
"properties": {}
}
}

View File

@@ -0,0 +1,15 @@
{
"name": "@openclaw/mistral-provider",
"version": "2026.6.11",
"private": true,
"description": "OpenClaw Mistral provider plugin",
"type": "module",
"devDependencies": {
"@openclaw/plugin-sdk": "workspace:*"
},
"openclaw": {
"extensions": [
"./index.ts"
]
}
}

View File

@@ -0,0 +1,11 @@
// Mistral provider module implements model/runtime integration.
import { buildManifestModelProviderConfig } from "openclaw/plugin-sdk/provider-catalog-shared";
import type { ModelProviderConfig } from "openclaw/plugin-sdk/provider-model-shared";
import manifest from "./openclaw.plugin.json" with { type: "json" };
export function buildMistralProvider(): ModelProviderConfig {
return buildManifestModelProviderConfig({
providerId: "mistral",
catalog: manifest.modelCatalog.providers.mistral,
});
}

View File

@@ -0,0 +1,78 @@
// Mistral tests cover realtime transcription provider plugin behavior.
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
import { afterEach, describe, expect, it, vi } from "vitest";
import {
testing,
buildMistralRealtimeTranscriptionProvider,
} from "./realtime-transcription-provider.js";
describe("buildMistralRealtimeTranscriptionProvider", () => {
afterEach(() => {
vi.unstubAllEnvs();
});
it("normalizes nested provider config", () => {
const provider = buildMistralRealtimeTranscriptionProvider();
const resolved = provider.resolveConfig?.({
cfg: {} as OpenClawConfig,
rawConfig: {
providers: {
mistral: {
apiKey: "mistral-key",
model: "voxtral-mini-transcribe-realtime-2602",
encoding: "g711_ulaw",
sample_rate: "8000",
target_streaming_delay_ms: "240",
},
},
},
});
expect(resolved).toEqual({
apiKey: "mistral-key",
baseUrl: undefined,
model: "voxtral-mini-transcribe-realtime-2602",
encoding: "pcm_mulaw",
sampleRate: 8000,
targetStreamingDelayMs: 240,
});
});
it("normalizes pasted API key artifacts for realtime auth headers", () => {
const provider = buildMistralRealtimeTranscriptionProvider();
const resolved = provider.resolveConfig?.({
cfg: {} as OpenClawConfig,
rawConfig: {
providers: {
mistral: {
apiKey: " sk-\r\nmistral│ ",
},
},
},
});
expect(resolved?.apiKey).toBe("sk-mistral");
});
it("builds a Mistral realtime websocket URL", () => {
const url = testing.toMistralRealtimeWsUrl({
apiKey: "mistral-key",
baseUrl: "https://api.mistral.ai/v1",
model: "voxtral-mini-transcribe-realtime-2602",
providerConfig: {},
sampleRate: 8000,
encoding: "pcm_mulaw",
targetStreamingDelayMs: 800,
});
expect(url).toContain("wss://api.mistral.ai/v1/audio/transcriptions/realtime?");
expect(url).toContain("model=voxtral-mini-transcribe-realtime-2602");
expect(url).toContain("target_streaming_delay_ms=800");
});
it("requires an API key when creating sessions", () => {
vi.stubEnv("MISTRAL_API_KEY", "");
const provider = buildMistralRealtimeTranscriptionProvider();
expect(() => provider.createSession({ providerConfig: {} })).toThrow("Mistral API key missing");
});
});

View File

@@ -0,0 +1,279 @@
// Mistral provider module implements model/runtime integration.
import {
createRealtimeTranscriptionWebSocketSession,
type RealtimeTranscriptionProviderConfig,
type RealtimeTranscriptionProviderPlugin,
type RealtimeTranscriptionSession,
type RealtimeTranscriptionSessionCreateRequest,
type RealtimeTranscriptionWebSocketTransport,
} from "openclaw/plugin-sdk/realtime-transcription";
import {
normalizeResolvedSecretInputString,
normalizeSecretInput,
} from "openclaw/plugin-sdk/secret-input";
import {
asOptionalRecord as readRecord,
normalizeOptionalString,
parseFiniteNumber as readFiniteNumber,
} from "openclaw/plugin-sdk/string-coerce-runtime";
type MistralRealtimeTranscriptionEncoding =
| "pcm_s16le"
| "pcm_s32le"
| "pcm_f16le"
| "pcm_f32le"
| "pcm_mulaw"
| "pcm_alaw";
type MistralRealtimeTranscriptionProviderConfig = {
apiKey?: string;
baseUrl?: string;
model?: string;
sampleRate?: number;
encoding?: MistralRealtimeTranscriptionEncoding;
targetStreamingDelayMs?: number;
};
type MistralRealtimeTranscriptionSessionConfig = RealtimeTranscriptionSessionCreateRequest & {
apiKey: string;
baseUrl: string;
model: string;
sampleRate: number;
encoding: MistralRealtimeTranscriptionEncoding;
targetStreamingDelayMs?: number;
};
type MistralRealtimeTranscriptionEvent = {
type?: string;
text?: string;
error?: {
message?: unknown;
code?: number;
};
};
const MISTRAL_REALTIME_DEFAULT_BASE_URL = "wss://api.mistral.ai";
const MISTRAL_REALTIME_DEFAULT_MODEL = "voxtral-mini-transcribe-realtime-2602";
const MISTRAL_REALTIME_DEFAULT_SAMPLE_RATE = 8000;
const MISTRAL_REALTIME_DEFAULT_ENCODING: MistralRealtimeTranscriptionEncoding = "pcm_mulaw";
const MISTRAL_REALTIME_DEFAULT_DELAY_MS = 800;
const MISTRAL_REALTIME_CONNECT_TIMEOUT_MS = 10_000;
const MISTRAL_REALTIME_CLOSE_TIMEOUT_MS = 5_000;
const MISTRAL_REALTIME_MAX_RECONNECT_ATTEMPTS = 5;
const MISTRAL_REALTIME_RECONNECT_DELAY_MS = 1000;
const MISTRAL_REALTIME_MAX_QUEUED_BYTES = 2 * 1024 * 1024;
function readNestedMistralConfig(rawConfig: RealtimeTranscriptionProviderConfig) {
const raw = readRecord(rawConfig);
const providers = readRecord(raw?.providers);
return readRecord(providers?.mistral ?? raw?.mistral ?? raw) ?? {};
}
function normalizeMistralEncoding(
value: unknown,
): MistralRealtimeTranscriptionEncoding | undefined {
const normalized = normalizeOptionalString(value)?.toLowerCase();
if (!normalized) {
return undefined;
}
switch (normalized) {
case "pcm":
case "linear16":
case "pcm_s16le":
return "pcm_s16le";
case "pcm_s32le":
case "pcm_f16le":
case "pcm_f32le":
return normalized;
case "mulaw":
case "ulaw":
case "g711_ulaw":
case "g711-mulaw":
case "pcm_mulaw":
return "pcm_mulaw";
case "alaw":
case "g711_alaw":
case "g711-alaw":
case "pcm_alaw":
return "pcm_alaw";
default:
throw new Error(`Invalid Mistral realtime transcription encoding: ${normalized}`);
}
}
function normalizeMistralRealtimeBaseUrl(value?: string): string {
const raw = normalizeOptionalString(value ?? process.env.MISTRAL_REALTIME_BASE_URL);
if (!raw) {
return MISTRAL_REALTIME_DEFAULT_BASE_URL;
}
const url = new URL(raw);
url.protocol =
url.protocol === "http:" ? "ws:" : url.protocol === "https:" ? "wss:" : url.protocol;
url.pathname = url.pathname.replace(/\/v1\/?$/, "").replace(/\/+$/, "");
return url.toString().replace(/\/+$/, "");
}
function toMistralRealtimeWsUrl(config: MistralRealtimeTranscriptionSessionConfig): string {
const base = new URL(`${normalizeMistralRealtimeBaseUrl(config.baseUrl)}/`);
const url = new URL("v1/audio/transcriptions/realtime", base);
url.searchParams.set("model", config.model);
if (config.targetStreamingDelayMs != null) {
url.searchParams.set("target_streaming_delay_ms", String(config.targetStreamingDelayMs));
}
return url.toString();
}
function normalizeProviderConfig(
config: RealtimeTranscriptionProviderConfig,
): MistralRealtimeTranscriptionProviderConfig {
const raw = readNestedMistralConfig(config);
return {
apiKey: normalizeMistralApiKey(raw.apiKey),
baseUrl: normalizeOptionalString(raw.baseUrl),
model: normalizeOptionalString(raw.model ?? raw.sttModel),
sampleRate: readFiniteNumber(raw.sampleRate ?? raw.sample_rate),
encoding: normalizeMistralEncoding(raw.encoding),
targetStreamingDelayMs: readFiniteNumber(
raw.targetStreamingDelayMs ?? raw.target_streaming_delay_ms ?? raw.delayMs,
),
};
}
function normalizeMistralApiKey(value: unknown): string | undefined {
const resolved = normalizeResolvedSecretInputString({
value,
path: "plugins.entries.voice-call.config.streaming.providers.mistral.apiKey",
});
return normalizeSecretInput(resolved) || undefined;
}
function readErrorDetail(event: MistralRealtimeTranscriptionEvent): string {
const message = event.error?.message;
if (typeof message === "string") {
return message;
}
if (message && typeof message === "object") {
return JSON.stringify(message);
}
if (typeof event.error?.code === "number") {
return `Mistral realtime transcription error (${event.error.code})`;
}
return "Mistral realtime transcription error";
}
function createMistralRealtimeTranscriptionSession(
config: MistralRealtimeTranscriptionSessionConfig,
): RealtimeTranscriptionSession {
let partialText = "";
const handleEvent = (
event: MistralRealtimeTranscriptionEvent,
transport: RealtimeTranscriptionWebSocketTransport,
) => {
if (event.type === "session.created") {
transport.sendJson({
type: "session.update",
session: {
audio_format: {
encoding: config.encoding,
sample_rate: config.sampleRate,
},
},
});
transport.markReady();
return;
}
if (!transport.isReady() && event.type === "error") {
transport.failConnect(new Error(readErrorDetail(event)));
return;
}
switch (event.type) {
case "transcription.text.delta":
if (event.text) {
partialText += event.text;
config.onPartial?.(partialText);
}
return;
case "transcription.segment":
if (event.text) {
config.onTranscript?.(event.text);
partialText = "";
}
return;
case "transcription.done":
if (partialText.trim()) {
config.onTranscript?.(partialText);
partialText = "";
}
transport.closeNow();
return;
case "error":
config.onError?.(new Error(readErrorDetail(event)));
default:
}
};
return createRealtimeTranscriptionWebSocketSession<MistralRealtimeTranscriptionEvent>({
providerId: "mistral",
callbacks: config,
url: () => toMistralRealtimeWsUrl(config),
headers: { Authorization: `Bearer ${config.apiKey}` },
connectTimeoutMs: MISTRAL_REALTIME_CONNECT_TIMEOUT_MS,
closeTimeoutMs: MISTRAL_REALTIME_CLOSE_TIMEOUT_MS,
maxReconnectAttempts: MISTRAL_REALTIME_MAX_RECONNECT_ATTEMPTS,
reconnectDelayMs: MISTRAL_REALTIME_RECONNECT_DELAY_MS,
maxQueuedBytes: MISTRAL_REALTIME_MAX_QUEUED_BYTES,
connectTimeoutMessage: "Mistral realtime transcription connection timeout",
reconnectLimitMessage: "Mistral realtime transcription reconnect limit reached",
sendAudio: (audio, transport) => {
transport.sendJson({
type: "input_audio.append",
audio: audio.toString("base64"),
});
},
onClose: (transport) => {
transport.sendJson({ type: "input_audio.flush" });
transport.sendJson({ type: "input_audio.end" });
},
onMessage: handleEvent,
});
}
export function buildMistralRealtimeTranscriptionProvider(): RealtimeTranscriptionProviderPlugin {
return {
id: "mistral",
label: "Mistral Realtime Transcription",
aliases: ["mistral-realtime", "voxtral-realtime"],
defaultModel: MISTRAL_REALTIME_DEFAULT_MODEL,
autoSelectOrder: 45,
resolveConfig: ({ rawConfig }) => normalizeProviderConfig(rawConfig),
isConfigured: ({ providerConfig }) =>
Boolean(
normalizeProviderConfig(providerConfig).apiKey ||
normalizeMistralApiKey(process.env.MISTRAL_API_KEY),
),
createSession: (req) => {
const config = normalizeProviderConfig(req.providerConfig);
const apiKey = config.apiKey || normalizeMistralApiKey(process.env.MISTRAL_API_KEY);
if (!apiKey) {
throw new Error("Mistral API key missing");
}
return createMistralRealtimeTranscriptionSession({
...req,
apiKey,
baseUrl: normalizeMistralRealtimeBaseUrl(config.baseUrl),
model: config.model ?? MISTRAL_REALTIME_DEFAULT_MODEL,
sampleRate: config.sampleRate ?? MISTRAL_REALTIME_DEFAULT_SAMPLE_RATE,
encoding: config.encoding ?? MISTRAL_REALTIME_DEFAULT_ENCODING,
targetStreamingDelayMs: config.targetStreamingDelayMs ?? MISTRAL_REALTIME_DEFAULT_DELAY_MS,
});
},
};
}
export const testing = {
normalizeProviderConfig,
toMistralRealtimeWsUrl,
};
export { testing as __testing };

View File

@@ -0,0 +1,3 @@
// Mistral API module exposes the plugin public contract.
export { mistralMediaUnderstandingProvider } from "./media-understanding-provider.js";
export { buildMistralRealtimeTranscriptionProvider } from "./realtime-transcription-provider.js";

View File

@@ -0,0 +1,16 @@
{
"extends": "../tsconfig.package-boundary.base.json",
"compilerOptions": {
"rootDir": "."
},
"include": ["./*.ts", "./src/**/*.ts"],
"exclude": [
"./**/*.test.ts",
"./dist/**",
"./node_modules/**",
"./src/test-support/**",
"./src/**/*test-helpers.ts",
"./src/**/*test-harness.ts",
"./src/**/*test-support.ts"
]
}