UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

268 lines (267 loc) • 9.79 kB
import { l as normalizeOptionalString } from "../../string-coerce-CCIiB4H7.mjs"; import { m as asSafeIntegerInRange } from "../../number-coercion-D6u-4YD8.mjs"; import { l as normalizeBaseUrl, p as sanitizeConfiguredModelProviderRequest } from "../../provider-request-config-CCij-nof.mjs"; import { t as applyModelCompatPatch } from "../../provider-model-compat-DgjEUAN7.mjs"; import "../../string-coerce-runtime-BwAZZDf5.mjs"; import { _ as resolveProviderOperationTimeoutMs, a as createProviderOperationTimeoutResolver, r as createProviderOperationDeadline, u as pollProviderOperationJson } from "../../shared-CfcMLHIP.mjs"; import "../../provider-model-shared-Dg70R9-2.mjs"; import { i as resolveGeneratedMediaMaxBytes } from "../../configured-max-bytes-lKIaFMol.mjs"; import { n as isProviderApiKeyConfiguredAsync } from "../../provider-auth-availability-Bv9WFzc3.mjs"; import { t as downloadGeneratedVideoAsset } from "../../media-generation-runtime-g6IBf-_Q.mjs"; import { t as postJsonResponse } from "../../provider-json-post-BR01v-xE.mjs"; import { t as resolveProviderApiKeyHttpRequestConfig } from "../../provider-http-LcawLneq.mjs"; import { c as resolveImageSourceUrl } from "../../image-assets-C4Dd3W6i.mjs"; import "../../image-generation-D00XjYzo.mjs"; import "../../provider-auth-D_oAZ3fr.mjs"; import { t as defineSingleProviderPluginEntry } from "../../provider-entry-CRfSFsHE.mjs"; import { t as openclaw_plugin_default } from "../../openclaw.plugin-D5sHRK8Y.mjs"; import { t as TOGETHER_BASE_URL } from "../../models-oCVOrmr8.mjs"; import { r as applyTogetherConnectionConfig } from "../../onboard-CE7wlXO2.mjs"; //#region extensions/together/index.ts const PROVIDER_ID = "together"; const DEFAULT_TOGETHER_VIDEO_MODEL = "Wan-AI/wan2.7-t2v"; const TOGETHER_IMAGE_TO_VIDEO_MODELS = /* @__PURE__ */ new Set(["Wan-AI/wan2.7-i2v"]); const TOGETHER_VIDEO_BASE_URL = "https://api.together.xyz/v2"; const DEFAULT_TIMEOUT_MS = 12e4; const DEFAULT_OPERATION_TIMEOUT_MS = 12e5; const POLL_INTERVAL_MS = 5e3; const MAX_POLL_ATTEMPTS = 240; const TOGETHER_MIN_DURATION_SECONDS = 1; const TOGETHER_MAX_DURATION_SECONDS = 10; const TOGETHER_WAN_DURATIONS = [ 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; const TOGETHER_MODEL_DURATIONS = { "Wan-AI/wan2.7-t2v": TOGETHER_WAN_DURATIONS, "Wan-AI/wan2.7-i2v": TOGETHER_WAN_DURATIONS }; const TOGETHER_WAN_SIZES = { "1280x720": { resolution: "720P", ratio: "16:9" }, "1920x1080": { resolution: "1080P", ratio: "16:9" }, "720x1280": { resolution: "720P", ratio: "9:16" }, "1080x1920": { resolution: "1080P", ratio: "9:16" }, "960x960": { resolution: "720P", ratio: "1:1" }, "1440x1440": { resolution: "1080P", ratio: "1:1" }, "1104x832": { resolution: "720P", ratio: "4:3" }, "1648x1248": { resolution: "1080P", ratio: "4:3" }, "832x1104": { resolution: "720P", ratio: "3:4" }, "1248x1648": { resolution: "1080P", ratio: "3:4" } }; function extractTogetherVideoUrl(e) { const t = Array.isArray(e.outputs) ? e.outputs : e.outputs ? [e.outputs] : []; for (const e of t) { const t = normalizeOptionalString(e.video_url) ?? normalizeOptionalString(e.url); if (t) return t; } } function readTogetherVideoFailureMessage(e) { return e.status === "failed" ? normalizeOptionalString(e.error?.message) ?? "Together video generation failed" : void 0; } var together_default = defineSingleProviderPluginEntry({ id: PROVIDER_ID, name: "Together Provider", description: "Bundled Together provider plugin", manifest: openclaw_plugin_default, provider: { label: "Together", docsPath: "/providers/together", manifestAuth: { applyConfig: applyTogetherConnectionConfig }, catalog: { liveModelDiscovery: true, discoveryMode: "strict" }, normalizeResolvedModel: ({ model: e }) => e.api === "openai-completions" && ["https://api.together.xyz/v1", "https://api.together.ai/v1"].includes(e.baseUrl.trim().replace(/\/+$/u, "")) ? applyModelCompatPatch(e, { supportsPromptCacheKey: e.compat?.supportsPromptCacheKey ?? true, supportsLongCacheRetention: e.compat?.supportsLongCacheRetention ?? false }) : e, classifyFailoverReason: ({ errorMessage: e }) => /\bconcurrency limit\b.*\b(?:breached|reached)\b/i.test(e) ? "rate_limit" : void 0 }, register(e) { e.registerVideoGenerationProvider({ id: "together", label: "Together", defaultModel: DEFAULT_TOGETHER_VIDEO_MODEL, models: [ DEFAULT_TOGETHER_VIDEO_MODEL, "Wan-AI/wan2.7-i2v", "minimax/hailuo-02" ], isConfiguredAsync: (e) => isProviderApiKeyConfiguredAsync({ provider: "together", ...e }), capabilities: { generate: { maxVideos: 1, maxDurationSeconds: TOGETHER_MAX_DURATION_SECONDS, supportedDurationSecondsByModel: TOGETHER_MODEL_DURATIONS, supportsSize: true }, imageToVideo: { enabled: true, maxInputImagesByModel: { "Wan-AI/wan2.7-i2v": 1 }, maxDurationSeconds: TOGETHER_MAX_DURATION_SECONDS, supportedDurationSecondsByModel: TOGETHER_MODEL_DURATIONS, supportsSize: true }, videoToVideo: { enabled: false } }, async generateVideo(e) { if ((e.inputVideos?.length ?? 0) > 0) throw new Error("Together video generation does not support video reference inputs."); const t = fetch; const n = normalizeOptionalString(e.cfg?.models?.providers?.together?.baseUrl); const r = !n || normalizeBaseUrl(n) === normalizeBaseUrl(TOGETHER_BASE_URL) ? TOGETHER_VIDEO_BASE_URL : n; const { baseUrl: i, allowPrivateNetwork: a, headers: o, dispatcherPolicy: s } = await resolveProviderApiKeyHttpRequestConfig({ req: e, missingApiKeyMessage: "Together API key missing", baseUrl: r, defaultBaseUrl: TOGETHER_VIDEO_BASE_URL, request: sanitizeConfiguredModelProviderRequest(e.cfg?.models?.providers?.together?.request), allowPrivateNetwork: false, provider: "together", capability: "video" }); const c = createProviderOperationDeadline({ timeoutMs: e.timeoutMs, label: "Together video generation" }); const l = normalizeOptionalString(e.model) ?? DEFAULT_TOGETHER_VIDEO_MODEL; const u = l === DEFAULT_TOGETHER_VIDEO_MODEL || TOGETHER_IMAGE_TO_VIDEO_MODELS.has(l); const d = { model: l, prompt: e.prompt }; const f = e.durationSeconds; if (typeof f === "number" && Number.isFinite(f)) { const e = asSafeIntegerInRange(Math.round(f), { min: u ? TOGETHER_WAN_DURATIONS[0] : TOGETHER_MIN_DURATION_SECONDS, max: TOGETHER_MAX_DURATION_SECONDS }); if (e !== void 0) d.seconds = String(e); } const p = normalizeOptionalString(e.size); if (p && u) { const e = TOGETHER_WAN_SIZES[p]; if (!e) throw new Error(`Together video model ${l} does not support size ${p}. Use ${Object.keys(TOGETHER_WAN_SIZES).join(", ")} or omit size.`); Object.assign(d, e); } else if (p) { const e = /^(\d+)x(\d+)$/u.exec(p); if (e) { d.width = Number.parseInt(e[1] ?? "", 10); d.height = Number.parseInt(e[2] ?? "", 10); } } if (e.inputImages?.[0]) { if (!TOGETHER_IMAGE_TO_VIDEO_MODELS.has(l)) throw new Error(`Together video model ${l} does not support image reference inputs. Use Wan-AI/wan2.7-i2v or omit input images.`); d.media = { frame_images: [{ input_image: resolveImageSourceUrl(e.inputImages[0], "Together reference image is missing image data."), frame: "first" }] }; } const m = await postJsonResponse({ url: `${i}/videos`, headers: o, body: d, timeoutMs: resolveProviderOperationTimeoutMs({ deadline: c, defaultTimeoutMs: DEFAULT_TIMEOUT_MS }), fetchFn: t, allowPrivateNetwork: a, dispatcherPolicy: s, errorLabel: "Together video generation failed" }); const h = readTogetherVideoFailureMessage(m); if (h) throw new Error(h); const g = normalizeOptionalString(m.id); if (!g) throw new Error("Together video generation response missing id"); const _ = m.status === "completed" ? m : await pollProviderOperationJson({ url: `${i}/videos/${g}`, headers: o, deadline: c.deadlineAtMs === void 0 ? createProviderOperationDeadline({ timeoutMs: DEFAULT_OPERATION_TIMEOUT_MS, label: `Together video generation task ${g}` }) : { ...c, label: `Together video generation task ${g}` }, defaultTimeoutMs: DEFAULT_TIMEOUT_MS, fetchFn: t, ssrfPolicy: { allowPrivateNetwork: a }, dispatcherPolicy: s, maxAttempts: MAX_POLL_ATTEMPTS, pollIntervalMs: POLL_INTERVAL_MS, requestFailedMessage: "Together video status request failed", timeoutMessage: `Together video generation task ${g} did not finish in time`, isComplete: (e) => e.status === "completed", getFailureMessage: readTogetherVideoFailureMessage }); const v = extractTogetherVideoUrl(_); if (!v) throw new Error("Together video generation completed without an output URL"); return { videos: [await downloadGeneratedVideoAsset({ url: v, timeoutMs: createProviderOperationTimeoutResolver({ deadline: c, defaultTimeoutMs: DEFAULT_TIMEOUT_MS }), defaultTimeoutMs: DEFAULT_TIMEOUT_MS, fetchFn: t, provider: "together", label: "Together generated video download", requestFailedMessage: "Together generated video download failed", maxBytes: resolveGeneratedMediaMaxBytes(e.cfg, "video"), validateBinaryResponse: true, chunkTimeoutMs: 0 })], model: _.model ?? e.model ?? DEFAULT_TOGETHER_VIDEO_MODEL, metadata: { videoId: g, status: _.status, videoUrl: v } }; } }); } }); //#endregion export { together_default as default };