重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。

同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。

Made-with: Cursor
This commit is contained in:
oliver 2026-04-26 08:34:33 +08:00
parent 4a23b715a2
commit dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions

View file

@ -0,0 +1,7 @@
export {
buildTogetherModelDefinition,
TOGETHER_BASE_URL,
TOGETHER_MODEL_CATALOG,
} from "./models.js";
export { buildTogetherProvider } from "./provider-catalog.js";
export { applyTogetherConfig, TOGETHER_DEFAULT_MODEL_REF } from "./onboard.js";

View file

@ -0,0 +1,42 @@
import { defineSingleProviderPluginEntry } from "openclaw/plugin-sdk/provider-entry";
import { applyTogetherConfig, TOGETHER_DEFAULT_MODEL_REF } from "./onboard.js";
import { buildTogetherProvider } from "./provider-catalog.js";
import { buildTogetherVideoGenerationProvider } from "./video-generation-provider.js";
const PROVIDER_ID = "together";
export default defineSingleProviderPluginEntry({
id: PROVIDER_ID,
name: "Together Provider",
description: "Bundled Together provider plugin",
provider: {
label: "Together",
docsPath: "/providers/together",
auth: [
{
methodId: "api-key",
label: "Together AI API key",
hint: "API key",
optionKey: "togetherApiKey",
flagName: "--together-api-key",
envVar: "TOGETHER_API_KEY",
promptMessage: "Enter Together AI API key",
defaultModel: TOGETHER_DEFAULT_MODEL_REF,
applyConfig: (cfg) => applyTogetherConfig(cfg),
wizard: {
groupLabel: "Together AI",
},
},
],
catalog: {
buildProvider: buildTogetherProvider,
},
classifyFailoverReason: ({ errorMessage }) =>
/\bconcurrency limit\b.*\b(?:breached|reached)\b/i.test(errorMessage)
? "rate_limit"
: undefined,
},
register(api) {
api.registerVideoGenerationProvider(buildTogetherVideoGenerationProvider());
},
});

View file

@ -0,0 +1,133 @@
import type { ModelDefinitionConfig } from "openclaw/plugin-sdk/provider-model-shared";
export const TOGETHER_BASE_URL = "https://api.together.xyz/v1";
export const TOGETHER_MODEL_CATALOG: ModelDefinitionConfig[] = [
{
id: "zai-org/GLM-4.7",
name: "GLM 4.7 Fp8",
reasoning: false,
input: ["text"],
contextWindow: 202752,
maxTokens: 8192,
cost: {
input: 0.45,
output: 2.0,
cacheRead: 0.45,
cacheWrite: 2.0,
},
},
{
id: "moonshotai/Kimi-K2.5",
name: "Kimi K2.5",
reasoning: true,
input: ["text", "image"],
cost: {
input: 0.5,
output: 2.8,
cacheRead: 0.5,
cacheWrite: 2.8,
},
contextWindow: 262144,
maxTokens: 32768,
},
{
id: "meta-llama/Llama-3.3-70B-Instruct-Turbo",
name: "Llama 3.3 70B Instruct Turbo",
reasoning: false,
input: ["text"],
contextWindow: 131072,
maxTokens: 8192,
cost: {
input: 0.88,
output: 0.88,
cacheRead: 0.88,
cacheWrite: 0.88,
},
},
{
id: "meta-llama/Llama-4-Scout-17B-16E-Instruct",
name: "Llama 4 Scout 17B 16E Instruct",
reasoning: false,
input: ["text", "image"],
contextWindow: 10000000,
maxTokens: 32768,
cost: {
input: 0.18,
output: 0.59,
cacheRead: 0.18,
cacheWrite: 0.18,
},
},
{
id: "meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8",
name: "Llama 4 Maverick 17B 128E Instruct FP8",
reasoning: false,
input: ["text", "image"],
contextWindow: 20000000,
maxTokens: 32768,
cost: {
input: 0.27,
output: 0.85,
cacheRead: 0.27,
cacheWrite: 0.27,
},
},
{
id: "deepseek-ai/DeepSeek-V3.1",
name: "DeepSeek V3.1",
reasoning: false,
input: ["text"],
contextWindow: 131072,
maxTokens: 8192,
cost: {
input: 0.6,
output: 1.25,
cacheRead: 0.6,
cacheWrite: 0.6,
},
},
{
id: "deepseek-ai/DeepSeek-R1",
name: "DeepSeek R1",
reasoning: true,
input: ["text"],
contextWindow: 131072,
maxTokens: 8192,
cost: {
input: 3.0,
output: 7.0,
cacheRead: 3.0,
cacheWrite: 3.0,
},
},
{
id: "moonshotai/Kimi-K2-Instruct-0905",
name: "Kimi K2-Instruct 0905",
reasoning: false,
input: ["text"],
contextWindow: 262144,
maxTokens: 8192,
cost: {
input: 1.0,
output: 3.0,
cacheRead: 1.0,
cacheWrite: 3.0,
},
},
];
export function buildTogetherModelDefinition(
model: (typeof TOGETHER_MODEL_CATALOG)[number],
): ModelDefinitionConfig {
return {
id: model.id,
name: model.name,
api: "openai-completions",
reasoning: model.reasoning,
input: model.input,
cost: model.cost,
contextWindow: model.contextWindow,
maxTokens: model.maxTokens,
};
}

View file

@ -0,0 +1,30 @@
import {
createModelCatalogPresetAppliers,
type OpenClawConfig,
} from "openclaw/plugin-sdk/provider-onboard";
import {
buildTogetherModelDefinition,
TOGETHER_BASE_URL,
TOGETHER_MODEL_CATALOG,
} from "./models.js";
export const TOGETHER_DEFAULT_MODEL_REF = "together/moonshotai/Kimi-K2.5";
const togetherPresetAppliers = createModelCatalogPresetAppliers({
primaryModelRef: TOGETHER_DEFAULT_MODEL_REF,
resolveParams: (_cfg: OpenClawConfig) => ({
providerId: "together",
api: "openai-completions",
baseUrl: TOGETHER_BASE_URL,
catalogModels: TOGETHER_MODEL_CATALOG.map(buildTogetherModelDefinition),
aliases: [{ modelRef: TOGETHER_DEFAULT_MODEL_REF, alias: "Together AI" }],
}),
});
export function applyTogetherProviderConfig(cfg: OpenClawConfig): OpenClawConfig {
return togetherPresetAppliers.applyProviderConfig(cfg);
}
export function applyTogetherConfig(cfg: OpenClawConfig): OpenClawConfig {
return togetherPresetAppliers.applyConfig(cfg);
}

View file

@ -0,0 +1,31 @@
{
"id": "together",
"enabledByDefault": true,
"providers": ["together"],
"providerAuthEnvVars": {
"together": ["TOGETHER_API_KEY"]
},
"providerAuthChoices": [
{
"provider": "together",
"method": "api-key",
"choiceId": "together-api-key",
"choiceLabel": "Together AI API key",
"groupId": "together",
"groupLabel": "Together AI",
"groupHint": "API key",
"optionKey": "togetherApiKey",
"cliFlag": "--together-api-key",
"cliOption": "--together-api-key <key>",
"cliDescription": "Together AI API key"
}
],
"contracts": {
"videoGenerationProviders": ["together"]
},
"configSchema": {
"type": "object",
"additionalProperties": false,
"properties": {}
}
}

View file

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

View file

@ -0,0 +1,8 @@
import { describePluginRegistrationContract } from "../../test/helpers/plugins/plugin-registration-contract.js";
describePluginRegistrationContract({
pluginId: "together",
providerIds: ["together"],
videoGenerationProviderIds: ["together"],
requireGenerateVideo: true,
});

View file

@ -0,0 +1,14 @@
import type { ModelProviderConfig } from "openclaw/plugin-sdk/provider-model-shared";
import {
buildTogetherModelDefinition,
TOGETHER_BASE_URL,
TOGETHER_MODEL_CATALOG,
} from "./models.js";
export function buildTogetherProvider(): ModelProviderConfig {
return {
baseUrl: TOGETHER_BASE_URL,
api: "openai-completions",
models: TOGETHER_MODEL_CATALOG.map(buildTogetherModelDefinition),
};
}

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"
]
}

View file

@ -0,0 +1,66 @@
import { beforeAll, describe, expect, it, vi } from "vitest";
import { expectExplicitVideoGenerationCapabilities } from "../../test/helpers/media-generation/provider-capability-assertions.js";
import {
getProviderHttpMocks,
installProviderHttpMockCleanup,
} from "../../test/helpers/media-generation/provider-http-mocks.js";
const { postJsonRequestMock, fetchWithTimeoutMock } = getProviderHttpMocks();
let buildTogetherVideoGenerationProvider: typeof import("./video-generation-provider.js").buildTogetherVideoGenerationProvider;
beforeAll(async () => {
({ buildTogetherVideoGenerationProvider } = await import("./video-generation-provider.js"));
});
installProviderHttpMockCleanup();
describe("together video generation provider", () => {
it("declares explicit mode capabilities", () => {
expectExplicitVideoGenerationCapabilities(buildTogetherVideoGenerationProvider());
});
it("creates a video, polls completion, and downloads the output", async () => {
postJsonRequestMock.mockResolvedValue({
response: {
json: async () => ({
id: "video_123",
status: "in_progress",
}),
},
release: vi.fn(async () => {}),
});
fetchWithTimeoutMock
.mockResolvedValueOnce({
json: async () => ({
id: "video_123",
status: "completed",
outputs: { video_url: "https://example.com/together.mp4" },
}),
})
.mockResolvedValueOnce({
headers: new Headers({ "content-type": "video/mp4" }),
arrayBuffer: async () => Buffer.from("mp4-bytes"),
});
const provider = buildTogetherVideoGenerationProvider();
const result = await provider.generateVideo({
provider: "together",
model: "Wan-AI/Wan2.2-T2V-A14B",
prompt: "A bicycle weaving through a rainy neon street",
cfg: {},
});
expect(postJsonRequestMock).toHaveBeenCalledWith(
expect.objectContaining({
url: "https://api.together.xyz/v1/videos",
}),
);
expect(result.videos).toHaveLength(1);
expect(result.metadata).toEqual(
expect.objectContaining({
videoId: "video_123",
}),
);
});
});

View file

@ -0,0 +1,274 @@
import { isProviderApiKeyConfigured } from "openclaw/plugin-sdk/provider-auth";
import { resolveApiKeyForProvider } from "openclaw/plugin-sdk/provider-auth-runtime";
import {
assertOkOrThrowHttpError,
createProviderOperationDeadline,
fetchWithTimeout,
postJsonRequest,
resolveProviderOperationTimeoutMs,
resolveProviderHttpRequestConfig,
waitProviderOperationPollInterval,
} from "openclaw/plugin-sdk/provider-http";
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
import type {
GeneratedVideoAsset,
VideoGenerationProvider,
VideoGenerationRequest,
} from "openclaw/plugin-sdk/video-generation";
import { TOGETHER_BASE_URL } from "./models.js";
const DEFAULT_TOGETHER_VIDEO_MODEL = "Wan-AI/Wan2.2-T2V-A14B";
const DEFAULT_TIMEOUT_MS = 120_000;
const POLL_INTERVAL_MS = 5_000;
const MAX_POLL_ATTEMPTS = 120;
type TogetherVideoResponse = {
id?: string;
model?: string;
status?: "in_progress" | "completed" | "failed";
error?: {
code?: string;
message?: string;
} | null;
outputs?:
| {
video_url?: string;
url?: string;
}
| Array<{
video_url?: string;
url?: string;
}>;
};
function resolveTogetherVideoBaseUrl(req: VideoGenerationRequest): string {
return (
normalizeOptionalString(req.cfg?.models?.providers?.together?.baseUrl) ?? TOGETHER_BASE_URL
);
}
function toDataUrl(buffer: Buffer, mimeType: string): string {
return `data:${mimeType};base64,${buffer.toString("base64")}`;
}
function extractTogetherVideoUrl(payload: TogetherVideoResponse): string | undefined {
if (Array.isArray(payload.outputs)) {
for (const entry of payload.outputs) {
const url = normalizeOptionalString(entry.video_url) ?? normalizeOptionalString(entry.url);
if (url) {
return url;
}
}
return undefined;
}
return (
normalizeOptionalString(payload.outputs?.video_url) ??
normalizeOptionalString(payload.outputs?.url)
);
}
async function pollTogetherVideo(params: {
videoId: string;
headers: Headers;
timeoutMs?: number;
baseUrl: string;
fetchFn: typeof fetch;
}): Promise<TogetherVideoResponse> {
const deadline = createProviderOperationDeadline({
timeoutMs: params.timeoutMs,
label: `Together video generation task ${params.videoId}`,
});
for (let attempt = 0; attempt < MAX_POLL_ATTEMPTS; attempt += 1) {
const response = await fetchWithTimeout(
`${params.baseUrl}/videos/${params.videoId}`,
{
method: "GET",
headers: params.headers,
},
resolveProviderOperationTimeoutMs({ deadline, defaultTimeoutMs: DEFAULT_TIMEOUT_MS }),
params.fetchFn,
);
await assertOkOrThrowHttpError(response, "Together video status request failed");
const payload = (await response.json()) as TogetherVideoResponse;
if (payload.status === "completed") {
return payload;
}
if (payload.status === "failed") {
throw new Error(
normalizeOptionalString(payload.error?.message) ?? "Together video generation failed",
);
}
await waitProviderOperationPollInterval({ deadline, pollIntervalMs: POLL_INTERVAL_MS });
}
throw new Error(`Together video generation task ${params.videoId} did not finish in time`);
}
async function downloadTogetherVideo(params: {
url: string;
timeoutMs?: number;
fetchFn: typeof fetch;
}): Promise<GeneratedVideoAsset> {
const response = await fetchWithTimeout(
params.url,
{ method: "GET" },
params.timeoutMs ?? DEFAULT_TIMEOUT_MS,
params.fetchFn,
);
await assertOkOrThrowHttpError(response, "Together generated video download failed");
const mimeType = normalizeOptionalString(response.headers.get("content-type")) ?? "video/mp4";
const arrayBuffer = await response.arrayBuffer();
return {
buffer: Buffer.from(arrayBuffer),
mimeType,
fileName: `video-1.${mimeType.includes("webm") ? "webm" : "mp4"}`,
};
}
export function buildTogetherVideoGenerationProvider(): VideoGenerationProvider {
return {
id: "together",
label: "Together",
defaultModel: DEFAULT_TOGETHER_VIDEO_MODEL,
models: [
DEFAULT_TOGETHER_VIDEO_MODEL,
"Wan-AI/Wan2.2-I2V-A14B",
"minimax/Hailuo-02",
"Kwai/Kling-2.1-Master",
],
isConfigured: ({ agentDir }) =>
isProviderApiKeyConfigured({
provider: "together",
agentDir,
}),
capabilities: {
generate: {
maxVideos: 1,
maxDurationSeconds: 12,
supportsSize: true,
},
imageToVideo: {
enabled: true,
maxVideos: 1,
maxInputImages: 1,
maxDurationSeconds: 12,
supportsSize: true,
},
videoToVideo: {
enabled: false,
},
},
async generateVideo(req) {
if ((req.inputVideos?.length ?? 0) > 0) {
throw new Error("Together video generation does not support video reference inputs.");
}
const auth = await resolveApiKeyForProvider({
provider: "together",
cfg: req.cfg,
agentDir: req.agentDir,
store: req.authStore,
});
if (!auth.apiKey) {
throw new Error("Together API key missing");
}
const fetchFn = fetch;
const deadline = createProviderOperationDeadline({
timeoutMs: req.timeoutMs,
label: "Together video generation",
});
const { baseUrl, allowPrivateNetwork, headers, dispatcherPolicy } =
resolveProviderHttpRequestConfig({
baseUrl: resolveTogetherVideoBaseUrl(req),
defaultBaseUrl: TOGETHER_BASE_URL,
allowPrivateNetwork: false,
defaultHeaders: {
Authorization: `Bearer ${auth.apiKey}`,
"Content-Type": "application/json",
},
provider: "together",
capability: "video",
transport: "http",
});
const body: Record<string, unknown> = {
model: normalizeOptionalString(req.model) ?? DEFAULT_TOGETHER_VIDEO_MODEL,
prompt: req.prompt,
};
if (typeof req.durationSeconds === "number" && Number.isFinite(req.durationSeconds)) {
body.seconds = String(Math.max(1, Math.round(req.durationSeconds)));
}
const size = normalizeOptionalString(req.size);
if (size) {
const match = /^(\d+)x(\d+)$/u.exec(size);
if (match) {
body.width = Number.parseInt(match[1] ?? "", 10);
body.height = Number.parseInt(match[2] ?? "", 10);
}
}
if (req.inputImages?.[0]) {
const input = req.inputImages[0];
const value = normalizeOptionalString(input.url)
? normalizeOptionalString(input.url)
: input.buffer
? toDataUrl(input.buffer, normalizeOptionalString(input.mimeType) ?? "image/png")
: undefined;
if (!value) {
throw new Error("Together reference image is missing image data.");
}
body.reference_images = [value];
}
const { response, release } = await postJsonRequest({
url: `${baseUrl}/videos`,
headers,
body,
timeoutMs: resolveProviderOperationTimeoutMs({
deadline,
defaultTimeoutMs: DEFAULT_TIMEOUT_MS,
}),
fetchFn,
allowPrivateNetwork,
dispatcherPolicy,
});
try {
await assertOkOrThrowHttpError(response, "Together video generation failed");
const submitted = (await response.json()) as TogetherVideoResponse;
const videoId = normalizeOptionalString(submitted.id);
if (!videoId) {
throw new Error("Together video generation response missing id");
}
const completed = await pollTogetherVideo({
videoId,
headers,
timeoutMs: resolveProviderOperationTimeoutMs({
deadline,
defaultTimeoutMs: DEFAULT_TIMEOUT_MS,
}),
baseUrl,
fetchFn,
});
const videoUrl = extractTogetherVideoUrl(completed);
if (!videoUrl) {
throw new Error("Together video generation completed without an output URL");
}
const video = await downloadTogetherVideo({
url: videoUrl,
timeoutMs: resolveProviderOperationTimeoutMs({
deadline,
defaultTimeoutMs: DEFAULT_TIMEOUT_MS,
}),
fetchFn,
});
return {
videos: [video],
model: completed.model ?? req.model ?? DEFAULT_TOGETHER_VIDEO_MODEL,
metadata: {
videoId,
status: completed.status,
videoUrl,
},
};
} finally {
await release();
}
},
};
}