UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 8.23 kB
import{l as normalizeOptionalString}from"../../string-coerce-CpTFcSwY.mjs";import{m as asSafeIntegerInRange}from"../../number-coercion-B3CfI447.mjs";import{l as normalizeBaseUrl,p as sanitizeConfiguredModelProviderRequest}from"../../provider-request-config-BQ-HhEKu.mjs";import{t as applyModelCompatPatch}from"../../provider-model-compat-wfM9WYj6.mjs";import"../../string-coerce-runtime-BYDH9Quw.mjs";import{_ as resolveProviderOperationTimeoutMs,a as createProviderOperationTimeoutResolver,r as createProviderOperationDeadline,u as pollProviderOperationJson}from"../../shared-BGvdIfYO.mjs";import"../../provider-model-shared-Cx--TZoK.mjs";import{i as resolveGeneratedMediaMaxBytes}from"../../configured-max-bytes-D7sE4PVV.mjs";import{t as downloadGeneratedVideoAsset}from"../../media-generation-runtime-BFOVKJoy.mjs";import{c as resolveImageSourceUrl}from"../../image-assets-PunGVmB-.mjs";import{n as isProviderApiKeyConfiguredAsync}from"../../provider-auth-availability-BcdrxLsU.mjs";import{t as postJsonResponse}from"../../provider-json-post-CAsK-CuC.mjs";import{t as resolveProviderApiKeyHttpRequestConfig}from"../../provider-http-D0sVd8r_.mjs";import"../../image-generation-C9u55YgW.mjs";import"../../provider-auth-Czspvb3-.mjs";import{t as defineSingleProviderPluginEntry}from"../../provider-entry-CTyJ4-xs.mjs";import{t as openclaw_plugin_default}from"../../openclaw.plugin-COcrDqb0.mjs";import{t as TOGETHER_BASE_URL}from"../../models-CLC4O7J7.mjs";import{r as applyTogetherConnectionConfig}from"../../onboard-Kam8WFtM.mjs"; //!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}}}})}});export{together_default as default};