mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-11 04:10:44 +08:00
重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
This commit is contained in:
parent
4a23b715a2
commit
dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions
44
openclaw/extensions/deepgram/audio.live.test.ts
Normal file
44
openclaw/extensions/deepgram/audio.live.test.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { isLiveTestEnabled } from "../../src/agents/live-test-helpers.js";
|
||||
import { transcribeDeepgramAudio } from "./audio.js";
|
||||
|
||||
const DEEPGRAM_KEY = process.env.DEEPGRAM_API_KEY ?? "";
|
||||
const DEEPGRAM_MODEL = process.env.DEEPGRAM_MODEL?.trim() || "nova-3";
|
||||
const DEEPGRAM_BASE_URL = process.env.DEEPGRAM_BASE_URL?.trim();
|
||||
const SAMPLE_URL =
|
||||
process.env.DEEPGRAM_SAMPLE_URL?.trim() ||
|
||||
"https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav";
|
||||
const LIVE = isLiveTestEnabled(["DEEPGRAM_LIVE_TEST"]);
|
||||
|
||||
const describeLive = LIVE && DEEPGRAM_KEY ? describe : describe.skip;
|
||||
|
||||
async function fetchSampleBuffer(url: string, timeoutMs: number): Promise<Buffer> {
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), Math.max(1, timeoutMs));
|
||||
try {
|
||||
const res = await fetch(url, { signal: controller.signal });
|
||||
if (!res.ok) {
|
||||
throw new Error(`Sample download failed (HTTP ${res.status})`);
|
||||
}
|
||||
const data = await res.arrayBuffer();
|
||||
return Buffer.from(data);
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
|
||||
describeLive("deepgram live", () => {
|
||||
it("transcribes sample audio", async () => {
|
||||
const buffer = await fetchSampleBuffer(SAMPLE_URL, 15000);
|
||||
const result = await transcribeDeepgramAudio({
|
||||
buffer,
|
||||
fileName: "sample.wav",
|
||||
mime: "audio/wav",
|
||||
apiKey: DEEPGRAM_KEY,
|
||||
model: DEEPGRAM_MODEL,
|
||||
baseUrl: DEEPGRAM_BASE_URL,
|
||||
timeoutMs: 20000,
|
||||
});
|
||||
expect(result.text.trim().length).toBeGreaterThan(0);
|
||||
}, 30000);
|
||||
});
|
||||
83
openclaw/extensions/deepgram/audio.test.ts
Normal file
83
openclaw/extensions/deepgram/audio.test.ts
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
createAuthCaptureJsonFetch,
|
||||
createRequestCaptureJsonFetch,
|
||||
installPinnedHostnameTestHooks,
|
||||
} from "../../src/media-understanding/audio.test-helpers.ts";
|
||||
import { transcribeDeepgramAudio } from "./audio.js";
|
||||
|
||||
installPinnedHostnameTestHooks();
|
||||
|
||||
describe("transcribeDeepgramAudio", () => {
|
||||
it("respects lowercase authorization header overrides", async () => {
|
||||
const { fetchFn, getAuthHeader } = createAuthCaptureJsonFetch({
|
||||
results: { channels: [{ alternatives: [{ transcript: "ok" }] }] },
|
||||
});
|
||||
|
||||
const result = await transcribeDeepgramAudio({
|
||||
buffer: Buffer.from("audio"),
|
||||
fileName: "note.mp3",
|
||||
apiKey: "test-key",
|
||||
timeoutMs: 1000,
|
||||
headers: { authorization: "Token override" },
|
||||
fetchFn,
|
||||
});
|
||||
|
||||
expect(getAuthHeader()).toBe("Token override");
|
||||
expect(result.text).toBe("ok");
|
||||
});
|
||||
|
||||
it("builds the expected request payload", async () => {
|
||||
const { fetchFn, getRequest } = createRequestCaptureJsonFetch({
|
||||
results: { channels: [{ alternatives: [{ transcript: "hello" }] }] },
|
||||
});
|
||||
|
||||
const result = await transcribeDeepgramAudio({
|
||||
buffer: Buffer.from("audio-bytes"),
|
||||
fileName: "voice.wav",
|
||||
apiKey: "test-key",
|
||||
timeoutMs: 1234,
|
||||
baseUrl: "https://api.example.com/v1/",
|
||||
model: " ",
|
||||
language: " en ",
|
||||
mime: "audio/wav",
|
||||
headers: { "X-Custom": "1" },
|
||||
query: {
|
||||
punctuate: false,
|
||||
smart_format: true,
|
||||
},
|
||||
fetchFn,
|
||||
});
|
||||
const { url: seenUrl, init: seenInit } = getRequest();
|
||||
|
||||
expect(result.model).toBe("nova-3");
|
||||
expect(result.text).toBe("hello");
|
||||
expect(seenUrl).toBe(
|
||||
"https://api.example.com/v1/listen?model=nova-3&language=en&punctuate=false&smart_format=true",
|
||||
);
|
||||
expect(seenInit?.method).toBe("POST");
|
||||
expect(seenInit?.signal).toBeInstanceOf(AbortSignal);
|
||||
|
||||
const headers = new Headers(seenInit?.headers);
|
||||
expect(headers.get("authorization")).toBe("Token test-key");
|
||||
expect(headers.get("x-custom")).toBe("1");
|
||||
expect(headers.get("content-type")).toBe("audio/wav");
|
||||
expect(seenInit?.body).toBeInstanceOf(Uint8Array);
|
||||
});
|
||||
|
||||
it("throws when the provider response omits transcript", async () => {
|
||||
const { fetchFn } = createRequestCaptureJsonFetch({
|
||||
results: { channels: [{ alternatives: [{}] }] },
|
||||
});
|
||||
|
||||
await expect(
|
||||
transcribeDeepgramAudio({
|
||||
buffer: Buffer.from("audio-bytes"),
|
||||
fileName: "voice.wav",
|
||||
apiKey: "test-key",
|
||||
timeoutMs: 1234,
|
||||
fetchFn,
|
||||
}),
|
||||
).rejects.toThrow("Audio transcription response missing transcript");
|
||||
});
|
||||
});
|
||||
87
openclaw/extensions/deepgram/audio.ts
Normal file
87
openclaw/extensions/deepgram/audio.ts
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import type {
|
||||
AudioTranscriptionRequest,
|
||||
AudioTranscriptionResult,
|
||||
} from "openclaw/plugin-sdk/media-understanding";
|
||||
import {
|
||||
assertOkOrThrowHttpError,
|
||||
postTranscriptionRequest,
|
||||
resolveProviderHttpRequestConfig,
|
||||
requireTranscriptionText,
|
||||
} from "openclaw/plugin-sdk/provider-http";
|
||||
|
||||
export const DEFAULT_DEEPGRAM_AUDIO_BASE_URL = "https://api.deepgram.com/v1";
|
||||
export const DEFAULT_DEEPGRAM_AUDIO_MODEL = "nova-3";
|
||||
|
||||
function resolveModel(model?: string): string {
|
||||
const trimmed = model?.trim();
|
||||
return trimmed || DEFAULT_DEEPGRAM_AUDIO_MODEL;
|
||||
}
|
||||
|
||||
type DeepgramTranscriptResponse = {
|
||||
results?: {
|
||||
channels?: Array<{
|
||||
alternatives?: Array<{
|
||||
transcript?: string;
|
||||
}>;
|
||||
}>;
|
||||
};
|
||||
};
|
||||
|
||||
export async function transcribeDeepgramAudio(
|
||||
params: AudioTranscriptionRequest,
|
||||
): Promise<AudioTranscriptionResult> {
|
||||
const fetchFn = params.fetchFn ?? fetch;
|
||||
const model = resolveModel(params.model);
|
||||
const { baseUrl, allowPrivateNetwork, headers, dispatcherPolicy } =
|
||||
resolveProviderHttpRequestConfig({
|
||||
baseUrl: params.baseUrl,
|
||||
defaultBaseUrl: DEFAULT_DEEPGRAM_AUDIO_BASE_URL,
|
||||
headers: params.headers,
|
||||
request: params.request,
|
||||
defaultHeaders: {
|
||||
authorization: `Token ${params.apiKey}`,
|
||||
"content-type": params.mime ?? "application/octet-stream",
|
||||
},
|
||||
provider: "deepgram",
|
||||
capability: "audio",
|
||||
transport: "media-understanding",
|
||||
});
|
||||
|
||||
const url = new URL(`${baseUrl}/listen`);
|
||||
url.searchParams.set("model", model);
|
||||
if (params.language?.trim()) {
|
||||
url.searchParams.set("language", params.language.trim());
|
||||
}
|
||||
if (params.query) {
|
||||
for (const [key, value] of Object.entries(params.query)) {
|
||||
if (value === undefined) {
|
||||
continue;
|
||||
}
|
||||
url.searchParams.set(key, String(value));
|
||||
}
|
||||
}
|
||||
|
||||
const body = new Uint8Array(params.buffer);
|
||||
const { response: res, release } = await postTranscriptionRequest({
|
||||
url: url.toString(),
|
||||
headers,
|
||||
body,
|
||||
timeoutMs: params.timeoutMs,
|
||||
fetchFn,
|
||||
allowPrivateNetwork,
|
||||
dispatcherPolicy,
|
||||
});
|
||||
|
||||
try {
|
||||
await assertOkOrThrowHttpError(res, "Audio transcription failed");
|
||||
|
||||
const payload = (await res.json()) as DeepgramTranscriptResponse;
|
||||
const transcript = requireTranscriptionText(
|
||||
payload.results?.channels?.[0]?.alternatives?.[0]?.transcript,
|
||||
"Audio transcription response missing transcript",
|
||||
);
|
||||
return { text: transcript, model };
|
||||
} finally {
|
||||
await release();
|
||||
}
|
||||
}
|
||||
11
openclaw/extensions/deepgram/index.ts
Normal file
11
openclaw/extensions/deepgram/index.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import { deepgramMediaUnderstandingProvider } from "./media-understanding-provider.js";
|
||||
|
||||
export default definePluginEntry({
|
||||
id: "deepgram",
|
||||
name: "Deepgram Media Understanding",
|
||||
description: "Bundled Deepgram audio transcription provider",
|
||||
register(api) {
|
||||
api.registerMediaUnderstandingProvider(deepgramMediaUnderstandingProvider);
|
||||
},
|
||||
});
|
||||
10
openclaw/extensions/deepgram/media-understanding-provider.ts
Normal file
10
openclaw/extensions/deepgram/media-understanding-provider.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import type { MediaUnderstandingProvider } from "openclaw/plugin-sdk/media-understanding";
|
||||
import { transcribeDeepgramAudio } from "./audio.js";
|
||||
|
||||
export const deepgramMediaUnderstandingProvider: MediaUnderstandingProvider = {
|
||||
id: "deepgram",
|
||||
capabilities: ["audio"],
|
||||
defaultModels: { audio: "nova-3" },
|
||||
autoPriority: { audio: 30 },
|
||||
transcribeAudio: transcribeDeepgramAudio,
|
||||
};
|
||||
15
openclaw/extensions/deepgram/openclaw.plugin.json
Normal file
15
openclaw/extensions/deepgram/openclaw.plugin.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"id": "deepgram",
|
||||
"enabledByDefault": true,
|
||||
"providerAuthEnvVars": {
|
||||
"deepgram": ["DEEPGRAM_API_KEY"]
|
||||
},
|
||||
"contracts": {
|
||||
"mediaUnderstandingProviders": ["deepgram"]
|
||||
},
|
||||
"configSchema": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {}
|
||||
}
|
||||
}
|
||||
15
openclaw/extensions/deepgram/package.json
Normal file
15
openclaw/extensions/deepgram/package.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "@openclaw/deepgram-provider",
|
||||
"version": "2026.4.20",
|
||||
"private": true,
|
||||
"description": "OpenClaw Deepgram media-understanding provider",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@openclaw/plugin-sdk": "workspace:*"
|
||||
},
|
||||
"openclaw": {
|
||||
"extensions": [
|
||||
"./index.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
1
openclaw/extensions/deepgram/test-api.ts
Normal file
1
openclaw/extensions/deepgram/test-api.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export { deepgramMediaUnderstandingProvider } from "./media-understanding-provider.js";
|
||||
16
openclaw/extensions/deepgram/tsconfig.json
Normal file
16
openclaw/extensions/deepgram/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue