@uploadfilm/sdk 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +4 -0
- package/README.md +529 -2
- package/dist/ai/embed.d.ts +58 -0
- package/dist/ai/fake.d.ts +41 -0
- package/dist/ai/http.d.ts +17 -0
- package/dist/ai/index.d.ts +27 -0
- package/dist/ai/languages.d.ts +2 -0
- package/dist/ai/ollama.d.ts +23 -0
- package/dist/ai/openaiCompatible.d.ts +54 -0
- package/dist/ai/passages.d.ts +28 -0
- package/dist/ai/transcribe.d.ts +84 -0
- package/dist/ai/types.d.ts +141 -0
- package/dist/ai/usage.d.ts +66 -0
- package/dist/ai/whisperJson.d.ts +15 -0
- package/dist/ai/workersAi.d.ts +56 -0
- package/dist/ai.js +1 -0
- package/dist/ai.mjs +1 -0
- package/dist/cards/files.d.ts +91 -0
- package/dist/cards/index.d.ts +15 -0
- package/dist/cards/layouts.d.ts +121 -0
- package/dist/cards/probe.d.ts +69 -0
- package/dist/cards/proxies.d.ts +70 -0
- package/dist/cards/select.d.ts +68 -0
- package/dist/cards/volumes.d.ts +170 -0
- package/dist/cards/xml.d.ts +80 -0
- package/dist/cards.js +1 -0
- package/dist/cards.mjs +1 -0
- package/dist/copy/checksums.d.ts +66 -0
- package/dist/copy/engine.d.ts +24 -0
- package/dist/copy/errors.d.ts +109 -0
- package/dist/copy/index.d.ts +15 -0
- package/dist/copy/steps.d.ts +28 -0
- package/dist/copy/sweep.d.ts +24 -0
- package/dist/copy/types.d.ts +363 -0
- package/dist/embed/player.js +2 -0
- package/dist/host/adapters.d.ts +107 -0
- package/dist/host/detect.d.ts +68 -0
- package/dist/host/encoders.d.ts +34 -0
- package/dist/host/environment.d.ts +53 -0
- package/dist/host/index.d.ts +20 -0
- package/dist/host/linux.d.ts +94 -0
- package/dist/host/mac.d.ts +47 -0
- package/dist/host/network.d.ts +54 -0
- package/dist/host/node.d.ts +13 -0
- package/dist/host/policy.d.ts +101 -0
- package/dist/host/tuner.d.ts +48 -0
- package/dist/host/types.d.ts +118 -0
- package/dist/host-node.js +1 -0
- package/dist/host-node.mjs +1 -0
- package/dist/host.js +1 -0
- package/dist/host.mjs +1 -0
- package/dist/images/index.d.ts +11 -0
- package/dist/images/settings.d.ts +43 -0
- package/dist/images/types.d.ts +83 -0
- package/dist/images/url.d.ts +65 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/player/adapters/hlsjs.d.ts +28 -0
- package/dist/player/bandwidthMemory.d.ts +28 -0
- package/dist/player/captions/index.d.ts +55 -0
- package/dist/player/embed/code.d.ts +195 -0
- package/dist/player/embed/constants.d.ts +4 -0
- package/dist/player/embed/controller.d.ts +62 -0
- package/dist/player/embed/element.d.ts +32 -0
- package/dist/player/embed/frame.d.ts +65 -0
- package/dist/player/embed/global.d.ts +14 -0
- package/dist/player/embed/index.d.ts +15 -0
- package/dist/player/embed/loader.d.ts +1 -0
- package/dist/player/embed/oembed.d.ts +74 -0
- package/dist/player/embed/protocol.d.ts +64 -0
- package/dist/player/engine.d.ts +215 -0
- package/dist/player/index.d.ts +18 -0
- package/dist/player/start.d.ts +62 -0
- package/dist/player/store.d.ts +10 -0
- package/dist/player/storyboard/index.d.ts +161 -0
- package/dist/player/stream.d.ts +206 -0
- package/dist/player/tracks.d.ts +41 -0
- package/dist/player.js +1 -0
- package/dist/player.mjs +1 -0
- package/dist/proxies/args.d.ts +19 -0
- package/dist/proxies/budget.d.ts +57 -0
- package/dist/proxies/camera.d.ts +104 -0
- package/dist/proxies/formats.d.ts +36 -0
- package/dist/proxies/index.d.ts +18 -0
- package/dist/proxies/jobs.d.ts +98 -0
- package/dist/proxies/node.d.ts +32 -0
- package/dist/proxies/plan.d.ts +89 -0
- package/dist/proxies/probe.d.ts +39 -0
- package/dist/proxies/render.d.ts +104 -0
- package/dist/proxies/safety.d.ts +45 -0
- package/dist/proxies/types.d.ts +83 -0
- package/dist/proxies/upload.d.ts +14 -0
- package/dist/react/BigPlay.d.ts +26 -0
- package/dist/react/Player.d.ts +58 -0
- package/dist/react/embed/index.d.ts +45 -0
- package/dist/react/examples/CustomControls.d.ts +8 -0
- package/dist/react/images/Image.d.ts +16 -0
- package/dist/react/images/index.d.ts +4 -0
- package/dist/react/images/useImage.d.ts +47 -0
- package/dist/react/index.d.ts +17 -0
- package/dist/react/storyboard/index.d.ts +58 -0
- package/dist/react/theme.d.ts +37 -0
- package/dist/react/useAdapterErrors.d.ts +8 -0
- package/dist/react/usePlaybackStart.d.ts +18 -0
- package/dist/react/usePlayer.d.ts +28 -0
- package/dist/react/useReducedMotion.d.ts +2 -0
- package/dist/react/useTimedTrack.d.ts +22 -0
- package/dist/react.js +1 -0
- package/dist/react.mjs +1 -0
- package/dist/server/auth/apiKeys.d.ts +30 -0
- package/dist/server/auth/cache.d.ts +21 -0
- package/dist/server/auth/deviceTokens.d.ts +38 -0
- package/dist/server/auth/envelope.d.ts +15 -0
- package/dist/server/auth/grants.d.ts +76 -0
- package/dist/server/auth/index.d.ts +19 -0
- package/dist/server/auth/jwt.d.ts +65 -0
- package/dist/server/auth/keyring.d.ts +31 -0
- package/dist/server/auth/kv.d.ts +12 -0
- package/dist/server/auth/repository.d.ts +45 -0
- package/dist/server/auth/revocations.d.ts +21 -0
- package/dist/server/auth/scope.d.ts +4 -0
- package/dist/server/auth/serviceAuth.d.ts +24 -0
- package/dist/server/auth/signedUrls.d.ts +28 -0
- package/dist/server/embed/index.d.ts +36 -0
- package/dist/server/embed/lifecycle.d.ts +53 -0
- package/dist/server/embed/playerScript.d.ts +4 -0
- package/dist/server/images/index.d.ts +15 -0
- package/dist/server/images/job.d.ts +80 -0
- package/dist/server/images/layout.d.ts +24 -0
- package/dist/server/images/params.d.ts +90 -0
- package/dist/server/images/route.d.ts +101 -0
- package/dist/server/images/sign.d.ts +55 -0
- package/dist/server/index.d.ts +42 -0
- package/dist/server/media/client.d.ts +99 -0
- package/dist/server/media/frameCheck.d.ts +62 -0
- package/dist/server/media/index.d.ts +10 -0
- package/dist/server/media/protocol.d.ts +556 -0
- package/dist/server/media/storyboard.d.ts +144 -0
- package/dist/server/media/transcript.d.ts +143 -0
- package/dist/server/pipeline/index.d.ts +12 -0
- package/dist/server/pipeline/match.d.ts +10 -0
- package/dist/server/pipeline/pipeline.d.ts +182 -0
- package/dist/server/pipeline/queues.d.ts +108 -0
- package/dist/server/pipeline/sources.d.ts +54 -0
- package/dist/server/r2/client.d.ts +164 -0
- package/dist/server/r2/crc32.d.ts +24 -0
- package/dist/server/r2/encoding.d.ts +35 -0
- package/dist/server/r2/errors.d.ts +9 -0
- package/dist/server/r2/integrity.d.ts +25 -0
- package/dist/server/r2/parts.d.ts +46 -0
- package/dist/server/r2/sign.d.ts +47 -0
- package/dist/server/redis/index.d.ts +39 -0
- package/dist/server/state/memory.d.ts +18 -0
- package/dist/server/state/r2.d.ts +73 -0
- package/dist/server/state/types.d.ts +57 -0
- package/dist/server/storage/chunked.d.ts +25 -0
- package/dist/server/storage/index.d.ts +12 -0
- package/dist/server/storage/r2.d.ts +96 -0
- package/dist/server/storage/s3.d.ts +144 -0
- package/dist/server/testing/fake-r2.d.ts +410 -0
- package/dist/server/testing/index.d.ts +10 -0
- package/dist/server/testing/kv-contract.d.ts +14 -0
- package/dist/server/transfer/handler.d.ts +217 -0
- package/dist/server/transfer/keys.d.ts +45 -0
- package/dist/server/transfer/protocol.d.ts +190 -0
- package/dist/server/zip/client.d.ts +32 -0
- package/dist/server/zip/generations.d.ts +83 -0
- package/dist/server/zip/index.d.ts +12 -0
- package/dist/server/zip/planner.d.ts +94 -0
- package/dist/server/zip/sign.d.ts +22 -0
- package/dist/server-media.js +1 -0
- package/dist/server-media.mjs +1 -0
- package/dist/server-redis.js +1 -0
- package/dist/server-redis.mjs +1 -0
- package/dist/server-testing.js +1 -0
- package/dist/server-testing.mjs +1 -0
- package/dist/server.js +1 -0
- package/dist/server.mjs +1 -0
- package/dist/storage/browserFile.d.ts +19 -0
- package/dist/storage/index.d.ts +12 -0
- package/dist/storage/local.d.ts +9 -0
- package/dist/storage/presigned.d.ts +22 -0
- package/dist/sync/ffmpeg.d.ts +44 -0
- package/dist/sync/index.d.ts +17 -0
- package/dist/sync/match.d.ts +28 -0
- package/dist/sync/probe.d.ts +30 -0
- package/dist/sync/timecode.d.ts +50 -0
- package/dist/sync/transcript.d.ts +35 -0
- package/dist/sync/types.d.ts +172 -0
- package/dist/sync/waveform.d.ts +89 -0
- package/dist/sync.js +1 -0
- package/dist/sync.mjs +1 -0
- package/dist/transfer/claims.d.ts +41 -0
- package/dist/transfer/client.d.ts +267 -0
- package/dist/transfer/download.d.ts +192 -0
- package/dist/transfer/engine.d.ts +402 -0
- package/dist/transfer/errors.d.ts +50 -0
- package/dist/transfer/growing/bytes.d.ts +17 -0
- package/dist/transfer/growing/index.d.ts +12 -0
- package/dist/transfer/growing/parts.d.ts +157 -0
- package/dist/transfer/growing/retry.d.ts +38 -0
- package/dist/transfer/growing/store.d.ts +66 -0
- package/dist/transfer/growing/upload.d.ts +126 -0
- package/dist/transfer/index.d.ts +40 -0
- package/dist/transfer/integrity.d.ts +93 -0
- package/dist/transfer/limits.d.ts +34 -0
- package/dist/transfer/node.d.ts +63 -0
- package/dist/transfer/pool.d.ts +83 -0
- package/dist/transfer/protocol.d.ts +172 -0
- package/dist/transfer/signer.d.ts +29 -0
- package/dist/transfer/storage.d.ts +135 -0
- package/dist/transfer/timing.d.ts +132 -0
- package/dist/transfer/transports/electronNet.d.ts +62 -0
- package/dist/transfer/transports/fetch.d.ts +15 -0
- package/dist/transfer/transports/retryAfter.d.ts +12 -0
- package/dist/transfer/transports/undici.d.ts +72 -0
- package/dist/transfer/tuner.d.ts +56 -0
- package/dist/workers/cli.mjs +115 -0
- package/dist/workers/media/config.mjs +53 -0
- package/dist/workers/media/container/Dockerfile +19 -0
- package/dist/workers/media/container/FFMPEG.md +129 -0
- package/dist/workers/media/container/runner.mjs +2690 -0
- package/dist/workers/media/index.mjs +1011 -0
- package/dist/workers/media/init/config.ts +52 -0
- package/dist/workers/media/init/worker.ts +8 -0
- package/dist/workers/media/init/wrangler.toml +44 -0
- package/dist/workers/media/runner.mjs +2656 -0
- package/dist/workers/media/types/build/entry/config.d.mts +6 -0
- package/dist/workers/media/types/build/entry/index.d.mts +43 -0
- package/dist/workers/media/types/build/entry/program.d.mts +13 -0
- package/dist/workers/media/types/build/entry/runner.d.mts +12 -0
- package/dist/workers/media/types/build/entry/settings.d.mts +40 -0
- package/dist/workers/media/types/src/config.d.mts +135 -0
- package/dist/workers/media/types/src/jobs.d.mts +73 -0
- package/dist/workers/media/types/src/runner/container.d.mts +32 -0
- package/dist/workers/media/types/src/runner/ffmpeg.d.mts +227 -0
- package/dist/workers/media/types/src/runner/job.d.mts +107 -0
- package/dist/workers/media/types/src/runner/node.d.mts +71 -0
- package/dist/workers/media/types/src/runner/plugins.d.mts +45 -0
- package/dist/workers/media/types/src/serve.d.mts +107 -0
- package/dist/workers/media/types/src/steps/audio.d.mts +33 -0
- package/dist/workers/media/types/src/steps/edit.d.mts +62 -0
- package/dist/workers/media/types/src/steps/frameCheck.d.mts +44 -0
- package/dist/workers/media/types/src/steps/gate.d.mts +18 -0
- package/dist/workers/media/types/src/steps/paths.d.mts +1 -0
- package/dist/workers/media/types/src/steps/prep.d.mts +60 -0
- package/dist/workers/media/types/src/steps/render.d.mts +40 -0
- package/dist/workers/media/types/src/steps/runner.d.mts +30 -0
- package/dist/workers/media/types/src/steps/transcribe.d.mts +89 -0
- package/dist/workers/media/types/src/storyboard/index.d.mts +61 -0
- package/dist/workers/media/types/src/transcoder.d.mts +30 -0
- package/dist/workers/media/types/src/worker.d.mts +30 -0
- package/dist/workers/zip/index.mjs +589 -0
- package/dist/workers/zip/init/config.ts +22 -0
- package/dist/workers/zip/init/worker.ts +5 -0
- package/dist/workers/zip/init/wrangler.toml +25 -0
- package/dist/workers/zip/types/build/entry/index.d.mts +5 -0
- package/dist/workers/zip/types/src/config.d.mts +35 -0
- package/dist/workers/zip/types/src/serve.d.mts +86 -0
- package/dist/workers/zip/types/src/worker.d.mts +12 -0
- package/dist/zip/index.d.ts +13 -0
- package/dist/zip/layout.d.ts +129 -0
- package/dist/zip/names.d.ts +34 -0
- package/dist/zip/plan.d.ts +115 -0
- package/dist/zip/sw.d.ts +7 -0
- package/package.json +313 -4
package/dist/ai.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class e extends Error{permanent;adapter;status;constructor(e,t,n){super(`${e}: ${t}`.slice(0,1e3),void 0===n.cause?void 0:{cause:n.cause}),this.name="AiError",this.adapter=e,this.permanent=n.permanent,void 0!==n.status&&(this.status=n.status)}}const t=e=>408===e||409===e||425===e||429===e||e>=500;function n(e,t){if(!e)return;let n=0,a=!1;return void 0!==e.perCallUsd&&(n+=e.perCallUsd,a=!0),void 0!==e.perAudioMinuteUsd&&void 0!==t.audioSeconds&&(n+=e.perAudioMinuteUsd*t.audioSeconds/60,a=!0),void 0!==e.perMillionInputTokensUsd&&void 0!==t.inputTokens&&(n+=e.perMillionInputTokensUsd*t.inputTokens/1e6,a=!0),a?Math.round(1e8*n)/1e8:void 0}function a(e,t){if("number"==typeof t.reportedUsd&&Number.isFinite(t.reportedUsd)&&t.reportedUsd>=0)return{costUsd:t.reportedUsd,costSource:"reported"};const a=n(e,t);return void 0===a?{costSource:"unknown"}:{costUsd:a,costSource:"estimated"}}function r(){const e=new Map,t=t=>{const n=`${t.kind}\0${t.adapter}\0${t.model}`;let a=e.get(n);return a||e.set(n,a={adapter:t.adapter,model:t.model,kind:t.kind,calls:0,failures:0,latencyMs:{total:0,max:0},audioSeconds:0,inputs:0,inputTokens:0,costUsd:0,unpriced:0}),a};return{record(e){const n=t(e);n.calls++,n.latencyMs.total+=e.latencyMs,n.latencyMs.max=Math.max(n.latencyMs.max,e.latencyMs),n.audioSeconds+=e.audioSeconds??0,n.inputs+=e.inputs??0,n.inputTokens+=e.inputTokens??0,void 0!==e.costUsd?n.costUsd=Math.round(1e8*(n.costUsd+e.costUsd))/1e8:"local"!==e.costSource&&n.unpriced++},failure(e){const n=t(e);n.failures++,n.latencyMs.total+=e.latencyMs,n.latencyMs.max=Math.max(n.latencyMs.max,e.latencyMs)},totals:()=>[...e.values()].map(e=>({...e,latencyMs:{...e.latencyMs}}))}}function s(e,t){const n=t.now??Date.now;return{adapter:e.adapter,model:e.model,...void 0!==e.maxBytes?{maxBytes:e.maxBytes}:{},async transcribe(a,r){const s=n();try{const n=await e.transcribe(a,r);return i(()=>t.onUsage?.(n.usage)),n}catch(a){throw i(()=>t.onFailure?.({adapter:e.adapter,model:e.model,kind:"transcribe",latencyMs:n()-s,error:a})),a}}}}function o(e,t){const n=t.now??Date.now;return{adapter:e.adapter,model:e.model,accepts:e.accepts,...void 0!==e.maxBatch?{maxBatch:e.maxBatch}:{},async embed(a,r){const s=n();try{const n=await e.embed(a,r);return i(()=>t.onUsage?.(n.usage)),n}catch(a){throw i(()=>t.onFailure?.({adapter:e.adapter,model:e.model,kind:"embed",latencyMs:n()-s,error:a})),a}}}}function i(e){try{const t=e();t?.catch?.(()=>{})}catch{}}const c={en:"english",zh:"chinese",de:"german",es:"spanish",ru:"russian",ko:"korean",fr:"french",ja:"japanese",pt:"portuguese",tr:"turkish",pl:"polish",ca:"catalan",nl:"dutch",ar:"arabic",sv:"swedish",it:"italian",id:"indonesian",hi:"hindi",fi:"finnish",vi:"vietnamese",he:"hebrew",uk:"ukrainian",el:"greek",ms:"malay",cs:"czech",ro:"romanian",da:"danish",hu:"hungarian",ta:"tamil",no:"norwegian",th:"thai",ur:"urdu",hr:"croatian",bg:"bulgarian",lt:"lithuanian",la:"latin",mi:"maori",ml:"malayalam",cy:"welsh",sk:"slovak",te:"telugu",fa:"persian",lv:"latvian",bn:"bengali",sr:"serbian",az:"azerbaijani",sl:"slovenian",kn:"kannada",et:"estonian",mk:"macedonian",br:"breton",eu:"basque",is:"icelandic",hy:"armenian",ne:"nepali",mn:"mongolian",bs:"bosnian",kk:"kazakh",sq:"albanian",sw:"swahili",gl:"galician",mr:"marathi",pa:"punjabi",si:"sinhala",km:"khmer",sn:"shona",yo:"yoruba",so:"somali",af:"afrikaans",oc:"occitan",ka:"georgian",be:"belarusian",tg:"tajik",sd:"sindhi",gu:"gujarati",am:"amharic",yi:"yiddish",lo:"lao",uz:"uzbek",fo:"faroese",ht:"haitian creole",ps:"pashto",tk:"turkmen",nn:"nynorsk",mt:"maltese",sa:"sanskrit",lb:"luxembourgish",my:"myanmar",bo:"tibetan",tl:"tagalog",mg:"malagasy",as:"assamese",tt:"tatar",haw:"hawaiian",ln:"lingala",ha:"hausa",ba:"bashkir",jw:"javanese",su:"sundanese",yue:"cantonese"},d=Object.fromEntries(Object.entries(c).map(([e,t])=>[t,e]));function m(e){if("string"!=typeof e)return;const t=e.trim().toLowerCase();if(!t)return;if(c[t])return t;const n=t.split(/[-_]/)[0];return/^[a-z]{2,3}$/.test(n)&&c[n]?n:d[t]}Object.assign(d,{burmese:"my",valencian:"ca",flemish:"nl",haitian:"ht",letzeburgesch:"lb",pushto:"ps",panjabi:"pa",moldavian:"ro",moldovan:"ro",sinhalese:"si",castilian:"es",mandarin:"zh"});const l=e=>"number"==typeof e&&Number.isFinite(e),u=e=>Math.min(1,Math.max(0,e)),p=e=>Math.round(1e3*e)/1e3,h=e=>l(e)?p(u(Math.exp(Math.min(0,e)))):void 0;function g(e){if(!e||"object"!=typeof e)return null;const t="string"==typeof e.word?e.word:"string"==typeof e.text?e.text:null;if(null===t||!t.trim()||!l(e.start)||!l(e.end))return null;const n=l(e.probability)?e.probability:l(e.confidence)?e.confidence:void 0;return{word:t.trim(),start:Math.max(0,e.start),end:Math.max(0,e.end),...void 0!==n?{confidence:p(u(n))}:{}}}function f(t,n,a){if(!n||"object"!=typeof n)throw new e(t,"not an answer",{permanent:!1});const r=n,s=m(r.transcription_info?.language??r.language),o=r.transcription_info?.language_probability??r.language_probability,i=l(o)?p(u(o)):void 0,c=Array.isArray(r.words)?r.words.map(g).filter(Boolean):[];let d;if(Array.isArray(r.segments)){d=[];for(const e of r.segments){if(!e||"object"!=typeof e||!l(e.start)||!l(e.end)||"string"!=typeof e.text)continue;const t=Array.isArray(e.words)?e.words.map(e=>g(e)).filter(Boolean):[],n=h(e.avg_logprob);d.push({start:Math.max(0,e.start),end:Math.max(0,e.start,e.end),text:e.text,...t.length?{words:t}:{},...void 0!==n?{confidence:n}:{},...l(e.no_speech_prob)?{noSpeechProb:p(u(e.no_speech_prob))}:{}})}if(c.length&&d.every(e=>!e.words)){let e=0;d.forEach((t,n)=>{const a=d[n+1]?.start??1/0,r=[];for(;e<c.length&&(c[e].start<a||n===d.length-1);)r.push(c[e++]);r.length&&(t.words=r)})}}else{if("string"!=typeof r.text)throw new e(t,"no segments or text in the answer",{permanent:!1});{const e=c.length?{start:c[0].start,end:c[c.length-1].end}:{start:0,end:a??0};d=r.text.trim()?[{...e,text:r.text,...c.length?{words:c}:{}}]:[]}}const f="string"==typeof r.text?r.text.trim():d.map(e=>e.text.trim()).join(" ");return{segments:d,...s?{language:s}:{},...void 0!==i?{languageConfidence:i}:{},text:f}}const w=async e=>"function"==typeof e?await e():e,b=67108864;async function y(n,a,r,s,o){if(o.signal?.aborted)throw new e(n,"aborted",{permanent:!0});const i=function(e,t){const n=new AbortController;let a=!1;const r=setTimeout(()=>{a=!0,n.abort(new Error(`no answer in ${Math.round(t/1e3)} s`))},t);r.unref?.();const s=()=>n.abort(e?.reason);return e?.aborted?n.abort(e.reason):e?.addEventListener("abort",s,{once:!0}),{signal:n.signal,timedOut:()=>a,done:()=>{clearTimeout(r),e?.removeEventListener("abort",s)}}}(o.signal,o.timeoutMs);let c,d;try{c=await a(r,{...s,signal:i.signal})}catch(t){if(i.done(),o.signal?.aborted&&!i.timedOut())throw new e(n,"aborted",{permanent:!0,cause:t});throw new e(n,i.timedOut()?`no answer in ${Math.round(o.timeoutMs/1e3)} s`:`network: ${t?.message??String(t)}`,{permanent:!1,cause:t})}try{d=await async function(e){const t=Number(e.headers.get("content-length"));if(Number.isFinite(t)&&t>b)throw new Error(`answer of ${t} bytes (at most 67108864)`);if(!e.body)return await e.text();const n=e.body.getReader(),a=[];let r=0;for(;;){const{done:e,value:t}=await n.read();if(e)break;if(r+=t.byteLength,r>b)throw await n.cancel().catch(()=>{}),new Error("answer over 67108864 bytes");a.push(t)}const s=new Uint8Array(r);let o=0;for(const e of a)s.set(e,o),o+=e.byteLength;return(new TextDecoder).decode(s)}(c)}catch(t){const a=i.timedOut();if(i.done(),await(c.body?.cancel().catch(()=>{})),o.signal?.aborted&&!a)throw new e(n,"aborted",{permanent:!0,cause:t});throw new e(n,a?`answer not finished in ${Math.round(o.timeoutMs/1e3)} s`:t.message,{permanent:!1,cause:t})}if(i.done(),!c.ok){const a=function(e){try{const t=JSON.parse(e),n=t.error,a="string"==typeof n?n:"string"==typeof n?.message?n.message:"string"==typeof t.message?t.message:void 0;return a?.slice(0,300)}catch{return e.trim().slice(0,200)||void 0}}(d)??c.statusText??"";throw new e(n,`HTTP ${c.status}${a?`: ${a}`:""}`,{permanent:!t(c.status),status:c.status})}try{return{json:JSON.parse(d),headers:c.headers}}catch{throw new e(n,"answer is not JSON",{permanent:!1,status:c.status})}}function x(e){let t="";for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)}const M=e=>e.replace(/\/+$/,""),k="workers-ai",v="@cf/openai/whisper-large-v3-turbo",$=3e5,S=/^@cf\/openai\/whisper(?:-tiny-en)?$/,U=4194304,A=16777216;function j(t,n){if(S.test(t)){if(n.length>U)throw new e(k,`a ${n.length}-byte chunk is too big for ${t} (at most 4194304)`,{permanent:!0});return{audio:Array.from(n)}}return{audio:x(n)}}function T(t,n,a=k){let r;return Promise.race([t,new Promise((t,s)=>{r=setTimeout(()=>s(new e(a,`no answer in ${Math.round(n/1e3)} s`,{permanent:!1})),n),r.unref?.()})]).finally(()=>clearTimeout(r))}function B(t){if(t instanceof e)return t;const n=t?.message??String(t),a=/\b(?:invalid input|bad input|AiError: 400|unsupported)\b/i.test(n);return new e(k,n,{permanent:a,cause:t})}function _(t){const n=t.model??v,r=t.now??Date.now;return{adapter:k,model:n,maxBytes:S.test(n)?U:A,async transcribe(s,o={}){if(!t.ai?.run)throw new e(k,"no AI binding",{permanent:!0});if(o.signal?.aborted)throw new e(k,"aborted",{permanent:!0});const i=S.test(n)?U:A;if(s.bytes.length>i)throw new e(k,`a ${s.bytes.length}-byte chunk is too big for ${n} (at most ${i})`,{permanent:!0});const c=j(n,s.bytes);o.language&&(c.language=o.language),o.prompt&&(c.initial_prompt=o.prompt);const d=r();let m;try{m=await T(t.ai.run(n,c),t.timeoutMs??$)}catch(e){throw B(e)}const l=f(k,m,s.seconds),u=m.transcription_info,p=s.seconds??("number"==typeof u?.duration?u.duration:void 0);return{...l,usage:{adapter:k,model:n,kind:"transcribe",latencyMs:r()-d,...void 0!==p?{audioSeconds:p}:{},...a(t.price,{audioSeconds:p})}}}}}function O(t){if(!t.model)throw new e(k,"an embedding model must be named",{permanent:!0});const n=t.now??Date.now,r=t.maxBatch??100;return{adapter:k,model:t.model,accepts:{text:!0,image:!1},maxBatch:r,async embed(s,o={}){if("text"!==s.kind)throw new e(k,`${t.model}: images are not supported`,{permanent:!0});if(s.texts.length>r)throw new e(k,`${s.texts.length} texts in one call (at most ${r})`,{permanent:!0});if(o.signal?.aborted)throw new e(k,"aborted",{permanent:!0});const i=n();let c;try{c=await T(t.ai.run(t.model,{text:s.texts}),t.timeoutMs??6e4)}catch(e){throw B(e)}const d=E(k,c,s.texts.length);return{vectors:d,dimensions:d[0]?.length??0,usage:{adapter:k,model:t.model,kind:"embed",latencyMs:n()-i,inputs:s.texts.length,...a(t.price,{})}}}}}function E(e,t,n){const a=t;return C(e,Array.isArray(a?.data)?a.data:Array.isArray(a?.response)?a.response:null,n)}function C(t,n,a){if(!Array.isArray(n))throw new e(t,"no vectors in the answer",{permanent:!1});if(n.length!==a)throw new e(t,`${n.length} vectors for ${a} inputs`,{permanent:!1});let r=-1;for(const a of n){if(!Array.isArray(a)||!a.length||!a.every(e=>"number"==typeof e&&Number.isFinite(e)))throw new e(t,"a vector that isn't finite numbers",{permanent:!1});if(-1===r)r=a.length;else if(a.length!==r)throw new e(t,"vectors of different lengths",{permanent:!1})}return n}function N(t){const n=t.fetch??((e,t)=>fetch(e,t)),a=M(t.baseUrl??"https://api.cloudflare.com/client/v4");if(!/^[0-9a-f]{32}$/i.test(t.accountId))throw new e(k,"account id must be 32 hex characters",{permanent:!0});return{async run(r,s){if(!/^@cf\/[\w.-]+\/[\w.@-]+$/.test(r))throw new e(k,`not a Workers AI model id: ${r}`,{permanent:!0});const o=await w(t.token);if(!o)throw new e(k,"no API token",{permanent:!0});const{json:i}=await y(k,n,`${a}/accounts/${t.accountId}/ai/run/${r}`,{method:"POST",headers:{authorization:`Bearer ${o}`,"content-type":"application/json"},body:JSON.stringify(s)},{timeoutMs:t.timeoutMs??$}),c=i;if(!1===c.success)throw new e(k,c.errors?.map(e=>e.message).join("; ")||"failed",{permanent:!1});return c.result??i}}}const F="openai-compatible";function z(t,n){let a;try{a=new URL(t.baseUrl)}catch{throw new e(n,"baseUrl is not a URL",{permanent:!0})}if("https:"!==a.protocol&&("http:"!==a.protocol||!/^(localhost|127\.0\.0\.1|\[::1\])$/.test(a.hostname)))throw new e(n,"baseUrl must be https (http only for localhost)",{permanent:!0});if(a.username||a.password||a.search)throw new e(n,"baseUrl must not carry credentials or a query",{permanent:!0});if(!t.model)throw new e(n,"a model must be named",{permanent:!0});return M(a.href)}async function I(e,t={}){const n=await w(e.apiKey);return{...e.headers,...t,...n?{authorization:`Bearer ${n}`}:{}}}const P={"audio/ogg":"ogg","audio/opus":"ogg","audio/wav":"wav","audio/x-wav":"wav","audio/mpeg":"mp3","audio/mp4":"m4a","audio/flac":"flac","audio/webm":"webm"};function D(t){const n=t.name??F,r=`${z(t,n)}/audio/transcriptions`,s=t.fetch??((e,t)=>fetch(e,t)),o=t.now??Date.now,i=t.responseFormat??"verbose_json",c=t.maxBytes??26214400;return{adapter:n,model:t.model,maxBytes:c,async transcribe(d,m={}){if(d.bytes.length>c)throw new e(n,`${d.bytes.length} bytes (at most ${c})`,{permanent:!0});const l=new FormData,u=d.name??`audio.${P[d.mimeType.split(";")[0].trim()]??"bin"}`;l.append("file",new Blob([d.bytes],{type:d.mimeType}),u),l.append("model",t.model),l.append("response_format",i),"verbose_json"===i&&(l.append("timestamp_granularities[]","segment"),!1!==t.words&&l.append("timestamp_granularities[]","word")),m.language&&l.append("language",m.language),m.prompt&&l.append("prompt",m.prompt);const p=o(),{json:h}=await y(n,s,r,{method:"POST",headers:await I(t),body:l},{timeoutMs:t.timeoutMs??3e5,signal:m.signal}),g=h,w=d.seconds??L(g.duration)??L(g.usage?.seconds),b=f(n,h,w),x=L(g.usage?.input_tokens);return{...b,...m.language&&!b.language?{language:m.language}:{},usage:{adapter:n,model:t.model,kind:"transcribe",latencyMs:o()-p,...void 0!==w?{audioSeconds:w}:{},...void 0!==x?{inputTokens:x}:{},...a(t.price,{audioSeconds:w,inputTokens:x,reportedUsd:L(g.usage?.cost)})}}}}}const L=e=>"number"==typeof e&&Number.isFinite(e)?e:void 0;function J(t){const n=t.name??F,r=`${z(t,n)}/embeddings`,s=t.fetch??((e,t)=>fetch(e,t)),o=t.now??Date.now,i=t.maxBatch??64;return{adapter:n,model:t.model,accepts:{text:!0,image:!!t.images},maxBatch:i,async embed(c,d={}){const m="text"===c.kind?c.texts.length:c.images.length;if(m>i)throw new e(n,`${m} inputs in one call (at most ${i})`,{permanent:!0});if("image"===c.kind&&!t.images)throw new e(n,`${t.model}: images are not supported (set images: true for an endpoint that embeds them)`,{permanent:!0});const l=d.purpose?t.prefixes?.[d.purpose]??"":"",u="text"===c.kind?c.texts.map(e=>l+e):c.images.map(e=>({image:`data:${e.mimeType};base64,${x(e.bytes)}`})),p=o(),{json:h}=await y(n,s,r,{method:"POST",headers:await I(t,{"content-type":"application/json"}),body:JSON.stringify({model:t.model,input:u,encoding_format:"float",...t.dimensions?{dimensions:t.dimensions}:{}})},{timeoutMs:t.timeoutMs??6e4,signal:d.signal}),g=h;if(!Array.isArray(g.data))throw new e(n,"no data in the answer",{permanent:!1});const f=Array.from({length:m},()=>{});if(g.data.forEach((e,t)=>{const n="number"==typeof e?.index?e.index:t;Number.isInteger(n)&&n>=0&&n<m&&void 0===f[n]&&(f[n]=e.embedding)}),g.data.length!==m||f.some(e=>void 0===e))throw new e(n,`${g.data.length} vectors for ${m} inputs`,{permanent:!1});const w=C(n,f,m),b=L(g.usage?.prompt_tokens)??L(g.usage?.total_tokens);return{vectors:w,dimensions:w[0]?.length??0,usage:{adapter:n,model:t.model,kind:"embed",latencyMs:o()-p,inputs:m,...void 0!==b?{inputTokens:b}:{},...a(t.price,{inputTokens:b,reportedUsd:L(g.usage?.cost)})}}}}}const R="ollama";function q(t){if(!t.model)throw new e(R,"a model must be named",{permanent:!0});let n;try{n=`${M(new URL(t.baseUrl).href)}/api/embed`}catch{throw new e(R,"baseUrl is not a URL",{permanent:!0})}const a=t.fetch??((e,t)=>fetch(e,t)),r=t.now??Date.now,s=t.maxBatch??64;return{adapter:R,model:t.model,accepts:{text:!0,image:!1},maxBatch:s,async embed(o,i={}){if("text"!==o.kind)throw new e(R,"images are not supported",{permanent:!0});if(!o.texts.length)return{vectors:[],dimensions:0,usage:{adapter:R,model:t.model,kind:"embed",latencyMs:0,inputs:0,costUsd:0,costSource:"local"}};if(o.texts.length>s)throw new e(R,`${o.texts.length} texts in one call (at most ${s})`,{permanent:!0});const c=i.purpose?t.prefixes?.[i.purpose]??"":"",d=r(),{json:m}=await y(R,a,n,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({model:t.model,input:o.texts.map(e=>c+e),...t.keepAlive?{keep_alive:t.keepAlive}:{}})},{timeoutMs:t.timeoutMs??12e4,signal:i.signal}),l=m,u=C(R,l.embeddings,o.texts.length),p="number"==typeof l.prompt_eval_count?l.prompt_eval_count:void 0;return{vectors:u,dimensions:u[0].length,usage:{adapter:R,model:t.model,kind:"embed",latencyMs:r()-d,inputs:o.texts.length,...void 0!==p?{inputTokens:p}:{},costUsd:0,costSource:"local"}}}}}function W(t){const n=[],a=t.model??"fake-whisper";return{adapter:"fake",model:a,...void 0!==t.maxBytes?{maxBytes:t.maxBytes}:{},calls:n,async transcribe(r,s={}){const o=n.length;if(n.push({audio:r,options:s}),s.signal?.aborted)throw new e("fake","aborted",{permanent:!0});const i="function"==typeof t.answers?await t.answers(r,o,s):t.answers[Math.min(o,t.answers.length-1)];if(i instanceof Error)throw i;if(!i)throw new e("fake","no scripted answer",{permanent:!0});const c=i.segments.map(e=>({...e,...e.words?{words:e.words.map(e=>({...e}))}:{}})),d=r.seconds;return{...i,segments:c,text:i.text??c.map(e=>e.text.trim()).join(" "),usage:{adapter:"fake",model:a,kind:"transcribe",latencyMs:t.latencyMs??0,...void 0!==d?{audioSeconds:d}:{},...void 0!==t.perAudioMinuteUsd&&void 0!==d?{costUsd:t.perAudioMinuteUsd*d/60,costSource:"estimated"}:{costSource:"unknown"}}}}}}function G(e,t){const n=Array.from({length:t},(t,n)=>function(e,t){let n=2166136261^t;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619)>>>0;return n>>>0}(e,n+1)/4294967295*2-1),a=Math.hypot(...n)||1;return n.map(e=>Math.round(e/a*1e6)/1e6)}function H(t={}){const n=t.dimensions??8,a=t.model??"fake-embed",r=[],s=t.maxBatch??16;return{adapter:"fake",model:a,accepts:{text:!0,image:!!t.images},maxBatch:s,calls:r,async embed(o){const i=r.length;r.push(o);const c=t.failOn?.(i);if(c)throw c;const d="text"===o.kind?o.texts:o.images.map(e=>`${e.mimeType}:${e.bytes.length}:${Array.from(e.bytes.subarray(0,64)).join(",")}`);if("image"===o.kind&&!t.images)throw new e("fake","images are not supported",{permanent:!0});if(d.length>s)throw new e("fake",`${d.length} inputs (at most ${s})`,{permanent:!0});return{vectors:d.map(e=>G(e,n)),dimensions:n,usage:{adapter:"fake",model:a,kind:"embed",latencyMs:t.latencyMs??0,inputs:d.length,costSource:"unknown"}}}}}const K=e=>Math.round(1e3*e)/1e3;function V(e,t,n){let a=0;for(const r of n)a+=Math.max(0,Math.min(t,r.end)-Math.max(e,r.start));return a}function Q(e,t,n,a){const r=t-e;if(r<=0)return n.some(t=>e>=t.start&&e<=t.end);const s=V(e,t,n);return s>0&&s>=.8*r&&r-s<=a}function X(e){const t=Math.max(0,Math.round(1e3*e)),n=Math.floor(t/36e5),a=Math.floor(t/6e4)%60,r=Math.floor(t/1e3)%60,s=(e,t=2)=>String(e).padStart(t,"0");return`${s(n)}:${s(a)}:${s(r)}.${s(t%1e3,3)}`}function Y(e){const t=["WEBVTT",""];return e.segments.forEach((e,n)=>{const a=e.end>e.start?e.end:e.start+.5;t.push(String(n+1),`${X(e.start)} --\x3e ${X(a)}`,(e=>e.replace(/\r\n?/g,"\n").replace(/\n\s*\n/g,"\n").replace(/-->/g,"→").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").trim())(e.text),"")}),t.join("\n")}const Z=43200,ee=16777216;function te(e){return{...e.language?{transcription_info:{language:e.language}}:{},segments:e.segments.map(e=>({start:e.start,end:e.end,text:e.text,...e.words?.length?{words:e.words.map(e=>({word:e.word,start:e.start,end:e.end}))}:{}}))}}const ne=(t,n)=>{if(n instanceof e)return n;const a=n?.permanent,r=String(n?.message??n),s=n?.adapter;return new e("string"==typeof s?s:t,"string"==typeof s&&r.startsWith(`${s}: `)?r.slice(s.length+2):r,{permanent:!0===a,cause:n})};async function ae(t){const n=t.transcriber,a=t.index,r=[],s=[];let o=0;const c=a.chunks.filter(e=>{const t=((e,t)=>e.end-e.start-V(e.start,e.end,t)<=.05)(e,a.silences);return t&&o++,!t});if(c.length&&!n?.transcribe)throw new e("transcript","no transcriber",{permanent:!0});const d=c.reduce((e,t)=>e+(t.end-t.start),0),m=t.maxSeconds??43200;if(d>m)throw new e("transcript",`${Math.round(d/360)/10} h of audio (at most ${m/3600} h)`,{permanent:!0});const l=Math.min(t.maxChunkBytes??ee,n?.maxBytes??1/0),u=t.now??Date.now,p=new Map,h=t.progress??{get:async e=>p.get(e),put:async(e,t)=>{p.set(e,t)}};for(let a=0;a<c.length;a++){const o=c[a],d=await h.get(a);if(d){const e=d.usage;e&&r.push(e),s.push({chunk:o,result:d});continue}if(t.signal?.aborted)throw new e("transcript","aborted",{permanent:!0});if(void 0!==t.deadline&&u()>t.deadline)return{done:!1,sent:a,left:c.length-a,usage:r};const m=await t.load(o);if(!m)throw new e("transcript",`${o.file} missing`,{permanent:!0});if(m.length>l)throw new e("transcript",`${o.file} is ${m.length} bytes (at most ${l} for ${n.adapter})`,{permanent:!0});const p=u();let g;try{g=await n.transcribe({bytes:m,mimeType:t.mimeType??"audio/ogg",name:o.file.split("/").pop(),seconds:Math.round(1e3*(o.end-o.start))/1e3},{...t.language?{language:t.language}:{},...t.prompt?{prompt:t.prompt}:{},...t.signal?{signal:t.signal}:{}})}catch(e){const a=ne(n.adapter,e);throw i(()=>t.onFailure?.({adapter:n.adapter,model:n.model,kind:"transcribe",latencyMs:u()-p,error:a})),a}if(!g||!Array.isArray(g.segments))throw new e(n.adapter,"not a transcription",{permanent:!1});r.push(g.usage),i(()=>t.onUsage?.(g.usage));const f=te(g);await h.put(a,g.usage?{...f,usage:g.usage}:f),s.push({chunk:o,result:f})}const g=function(e,t){const n=[];let a=0,r=e.language;for(const{chunk:s,result:o}of e.results){r??=o.transcription_info?.language;const i=s.end-s.start;for(const r of o.segments??[]){const o=String(r.text??"").trim();if(!o||!Number.isFinite(r.start)||!Number.isFinite(r.end))continue;const c=K(s.start+Math.max(0,Math.min(r.start,i))),d=K(s.start+Math.max(0,Math.min(Math.max(r.end,r.start),i)));if(Q(c,d,e.silences,t.edgeS)){a++;continue}const m=(r.words??[]).filter(e=>e&&"string"==typeof e.word&&Number.isFinite(e.start)&&Number.isFinite(e.end)).map(e=>({word:e.word.trim(),start:K(s.start+Math.max(0,e.start)),end:K(s.start+Math.max(0,e.end))})).filter(t=>t.word&&!Q(t.start,t.end,e.silences,0));n.push({start:c,end:Math.max(c,d),text:o,...m.length?{words:m}:{}})}}return n.sort((e,t)=>e.start-t.start),{format:1,model:e.model,...r?{language:r}:{},seconds:K(e.seconds),segments:n,text:n.map(e=>e.text).join(" "),dropped:a,silentChunks:e.silentChunks??0}}({model:t.model??n?.model??"none",seconds:a.seconds,silences:a.silences,results:s,silentChunks:o,...t.language?{language:t.language}:{}},t.vad);return{done:!0,transcript:g,sent:c.length,usage:r}}async function re(t){try{const e=await t();return e.done?{state:"done",transcript:e.transcript,usage:e.usage}:{state:"pending",left:e.left,usage:e.usage}}catch(t){const n=t instanceof e?t.permanent:!!t?.permanent;return{state:"error",reason:String(t?.message??t).slice(0,500),permanent:n}}}const se=e=>Math.round(1e3*e)/1e3;function oe(e,t,n){const a=e.text.trim();if(!a)return[];if(a.length<=t&&e.end-e.start<=n)return[{start:e.start,end:e.end,text:a}];const r=e.words?.filter(e=>e.word.trim()),s=[],o=e=>e.replace(/[^\p{L}\p{N}]+/gu,"");if(r?.length&&o(r.map(e=>e.word).join(""))===o(a)){let e=null;for(const a of r)for(const r of ie(a.word.trim(),t))e&&(e.text.length+1+r.length>t||Math.max(e.end,a.end)-e.start>n)&&(s.push(e),e=null),e=e?{start:e.start,end:Math.max(e.end,a.end),text:`${e.text} ${r}`}:{start:a.start,end:a.end,text:r};return e&&s.push(e),s}const i=e.end-e.start,c=i>n?Math.max(1,Math.floor(a.length*n/i)):t;t=Math.min(t,c);let d=0;for(const n of function(e,t){const n=[];let a=e;for(;a.length>t;){const e=a.slice(0,t+1);let r=Math.max(e.lastIndexOf(". "),e.lastIndexOf("? "),e.lastIndexOf("! "),e.lastIndexOf("。"));r>0&&(r+=1),r>t&&(r=-1),r<=t/3&&(r=e.lastIndexOf(" ")),r<=0&&(r=t),r=ce(a,r),n.push(a.slice(0,r).trim()),a=a.slice(r).trim()}a&&n.push(a);return n.filter(Boolean)}(a,t)){const t=a.indexOf(n,d),r=t<0?d:t;s.push({start:se(e.start+i*r/a.length),end:se(e.start+i*(r+n.length)/a.length),text:n}),d=r+n.length}return s}function ie(e,t){if(e.length<=t)return[e];const n=[];for(let a=0;a<e.length;){const r=ce(e,Math.min(e.length,a+t),a);n.push(e.slice(a,r)),a=r}return n}function ce(e,t,n=0){const a=e.charCodeAt(t-1);return t<e.length&&a>=55296&&a<=56319&&t-1>n?t-1:t}function de(e,t){if(!(t.maxSeconds>0&&t.maxChars>0))throw new RangeError("maxSeconds and maxChars must be positive");const n=Math.max(0,t.overlapS??0),a=e.segments.flatMap(e=>oe(e,t.maxChars,t.maxSeconds)).sort((e,t)=>e.start-t.start),r=[];let s=[];const o=()=>{if(!s.length)return;r.push({index:r.length,start:se(s[0].start),end:se(Math.max(...s.map(e=>e.end))),text:s.map(e=>e.text).join(" ")});const e=Math.max(...s.map(e=>e.end)),t=[];if(n>0)for(let a=s.length-1;a>0&&s[a].start>=e-n;a--)t.unshift(s[a]);s=t};let i=0;for(const e of a){const n=s[s.length-1],a=s.reduce((e,t)=>e+t.text.length+1,0)+e.text.length,r=e.end-(s[0]?.start??e.start),c=n&&void 0!==t.breakOnGapS&&e.start-n.end>=t.breakOnGapS;if(s.length&&(a>t.maxChars||r>t.maxSeconds||c)){i>0&&o(),i=0;const n=s.reduce((e,t)=>e+t.text.length+1,0)+e.text.length;(c||n>t.maxChars||e.end-(s[0]?.start??e.start)>t.maxSeconds)&&(s=[])}s.push(e),i++}return i>0&&o(),r}async function me(e,t,n,a){const r=Math.max(1,Math.min(n.batchSize??n.embedder.maxBatch??32,n.embedder.maxBatch??1/0)),s=Math.ceil(e.length/r),o=[];let c=0,d=0;try{for(let m=0;m<s;m++){if(n.signal?.aborted)throw Object.assign(new Error("aborted"),{permanent:!0});const l=e.slice(m*r,(m+1)*r),u=await n.embedder.embed(t(l),{...n.signal?{signal:n.signal}:{},...a?{purpose:a}:{}});if(u.vectors.length!==l.length)throw new Error(`${u.vectors.length} vectors for ${l.length} inputs`);if(d&&u.dimensions!==d)throw new Error(`vectors changed length (${d} → ${u.dimensions})`);d=u.dimensions,o.push(u.usage),i(()=>n.onUsage?.(u.usage)),await n.onEmbeddings({items:l,vectors:u.vectors,adapter:n.embedder.adapter,model:n.embedder.model,dimensions:u.dimensions,usage:u.usage,batch:m,batches:s}),c++}}catch(e){return{state:"error",reason:String(e?.message??e).slice(0,500),permanent:!!e?.permanent,delivered:c,usage:o}}return{state:"done",items:e.length,batches:s,dimensions:d,usage:o}}async function le(e){let t;try{t=de(e.transcript,e.passages)}catch(e){return{state:"error",reason:String(e?.message??e),permanent:!0,delivered:0,usage:[]}}return ue({...e,passages:t})}function ue(e){return e.embedder.accepts.text?me(e.passages,e=>({kind:"text",texts:e.map(e=>e.text)}),e,"document"):Promise.resolve({state:"error",reason:`${e.embedder.adapter}: does not embed text`,permanent:!0,delivered:0,usage:[]})}function pe(e){return e.embedder.accepts.image?me(e.frames,e=>({kind:"image",images:e}),e):Promise.resolve({state:"error",reason:`${e.embedder.adapter}: does not embed images`,permanent:!0,delivered:0,usage:[]})}const he="ai";export{e as AiError,b as MAX_ANSWER_BYTES,ee as MAX_CHUNK_BYTES,Z as MAX_TRANSCRIPT_S,he as SDK_ENTRY,$ as WORKERS_AI_TIMEOUT_MS,v as WORKERS_AI_WHISPER,h as confidenceFromLogprob,a as costOf,w as credential,pe as embedFrames,ue as embedPassages,le as embedTranscript,n as estimateCost,H as fakeEmbedder,W as fakeTranscriber,G as fakeVector,te as keepAnswer,m as languageCode,q as ollamaEmbedder,J as openAiCompatibleEmbedder,D as openAiCompatibleTranscriber,i as quietly,E as readVectors,f as readWhisperJson,o as recordedEmbedder,s as recordedTranscriber,re as settleTranscript,Y as toWebVtt,ae as transcribeAudio,de as transcriptPassages,t as transientStatus,r as usageLog,j as whisperInput,O as workersAiEmbedder,N as workersAiRest,_ as workersAiTranscriber};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** "video" | "audio" | "image" | "other": the same words as UploadFilm's manifest FileKind. */
|
|
2
|
+
export type FileKind = "video" | "audio" | "image" | "other";
|
|
3
|
+
/** Names a walk never lists (OS litter); dot files and AppleDouble "._" files are skipped too. */
|
|
4
|
+
export declare const SKIP_NAMES: ReadonlySet<string>;
|
|
5
|
+
/**
|
|
6
|
+
* Camera files that are video: besides the usual containers, RAW clips (.braw Blackmagic, .r3d RED and Nikon R3D NE,
|
|
7
|
+
* .crm Canon Cinema RAW Light, .nev Nikon N-RAW), 360 originals (.insv Insta360, .360 GoPro MAX, .osv DJI Osmo 360),
|
|
8
|
+
* HDV captures (.m2t: MPEG-2 in a transport stream) and the low-res copies cameras record next to their clips (.lrv
|
|
9
|
+
* GoPro/Insta360, .lrf DJI: MP4 inside). Not here: ARRI .ari/.arx and Kinefinity .krw, which can be one file per frame.
|
|
10
|
+
*/
|
|
11
|
+
export declare const VIDEO_EXTENSIONS: ReadonlySet<string>;
|
|
12
|
+
export declare const AUDIO_EXTENSIONS: ReadonlySet<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Stills, camera RAW included: Sony .arw, Canon .cr3, Nikon .nef, Fujifilm .raf, Panasonic .rw2, Olympus/OM .orf,
|
|
15
|
+
* Pentax .pef, Samsung .srw, Hasselblad .3fr, Phase One .iiq, and DNG.
|
|
16
|
+
*/
|
|
17
|
+
export declare const IMAGE_EXTENSIONS: ReadonlySet<string>;
|
|
18
|
+
export declare const kindOf: (p: string) => FileKind;
|
|
19
|
+
export declare const mimeOf: (p: string) => string;
|
|
20
|
+
export declare const isImagePath: (p: string) => boolean;
|
|
21
|
+
/** Something a walk couldn't read (a folder that failed to list, a broken link, a link to a folder not added). */
|
|
22
|
+
export interface ScanIssue {
|
|
23
|
+
/** Path inside what was added (as its files would have been named). */
|
|
24
|
+
rel: string;
|
|
25
|
+
/** Where it was when we tried. */
|
|
26
|
+
abs: string;
|
|
27
|
+
/** "<abs>: <what went wrong>" */
|
|
28
|
+
error: string;
|
|
29
|
+
/** A link to a folder that wasn't followed: where it points (adding that folder settles it). */
|
|
30
|
+
target?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface Found {
|
|
33
|
+
abs: string;
|
|
34
|
+
/** Path inside what was added, forward slashes. */
|
|
35
|
+
rel: string;
|
|
36
|
+
size: number;
|
|
37
|
+
mtimeMs: number;
|
|
38
|
+
/** Birth time; 0 where the filesystem doesn't record one. */
|
|
39
|
+
birthtimeMs: number;
|
|
40
|
+
}
|
|
41
|
+
/** A place this scan read completely (a folder listed, a file stat'ed): any earlier issue at or under it is settled. */
|
|
42
|
+
export interface Read {
|
|
43
|
+
rel: string;
|
|
44
|
+
abs: string;
|
|
45
|
+
/** Volume UUID + path inside it (when known). */
|
|
46
|
+
volume?: {
|
|
47
|
+
uuid: string;
|
|
48
|
+
sub: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Every file under one folder (a card's mount point), sorted by path; folders that failed to list are in `errors`. */
|
|
52
|
+
export declare function walkFolder(root: string): Promise<{
|
|
53
|
+
files: Found[];
|
|
54
|
+
errors: ScanIssue[];
|
|
55
|
+
read: Read[];
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* One thing that was dropped: a folder (a card, a shoot folder) or the loose files dropped
|
|
59
|
+
* alongside. Paths are relative to it.
|
|
60
|
+
*/
|
|
61
|
+
export interface Root {
|
|
62
|
+
/** The folder dropped, or for loose files the folder they're in. */
|
|
63
|
+
abs: string;
|
|
64
|
+
/** Its name as found: a card's volume name, a folder's name. */
|
|
65
|
+
name: string;
|
|
66
|
+
dir: boolean;
|
|
67
|
+
files: Found[];
|
|
68
|
+
errors: ScanIssue[];
|
|
69
|
+
read: Read[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Walk what was dropped, one Root per folder (plus one for any loose files). `files`, `errors`
|
|
73
|
+
* and `read` are the same results flattened (one folder dropped into an empty target → its contents at the root,
|
|
74
|
+
* anything else under the folder's name).
|
|
75
|
+
*/
|
|
76
|
+
export declare function collect(paths: string[], intoEmptyProject: boolean): Promise<{
|
|
77
|
+
roots: Root[];
|
|
78
|
+
missing: ScanIssue[];
|
|
79
|
+
files: Found[];
|
|
80
|
+
suggestedName?: string;
|
|
81
|
+
errors: ScanIssue[];
|
|
82
|
+
read: Read[];
|
|
83
|
+
}>;
|
|
84
|
+
/** A file's own created/modified dates as ISO strings (created left out when the filesystem has none). */
|
|
85
|
+
export declare const fileDates: (s: {
|
|
86
|
+
birthtimeMs: number;
|
|
87
|
+
mtimeMs: number;
|
|
88
|
+
}) => {
|
|
89
|
+
fileCreatedAt: string | undefined;
|
|
90
|
+
fileModifiedAt: string | undefined;
|
|
91
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@uploadfilm/sdk/cards`: camera cards in Node (no Electron, no DOM). Mounted volumes (list, watch, classify,
|
|
3
|
+
* recognise a card seen before), camera folder layouts read into clips (spans, camera proxies, sidecars, LUTs,
|
|
4
|
+
* metadata), selection helpers and the upload plan; plus the file kinds, folder walk and ffprobe probe products
|
|
5
|
+
* build on. docs/platform/CARDS.md.
|
|
6
|
+
*/
|
|
7
|
+
/** Which entry point a module came from; lets each consumer prove the alias or package resolves. */
|
|
8
|
+
export declare const SDK_ENTRY: "cards";
|
|
9
|
+
export * from "./files";
|
|
10
|
+
export * from "./probe";
|
|
11
|
+
export * from "./xml";
|
|
12
|
+
export * from "./proxies";
|
|
13
|
+
export * from "./layouts";
|
|
14
|
+
export * from "./select";
|
|
15
|
+
export * from "./volumes";
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { type Found, type ScanIssue } from "./files";
|
|
2
|
+
import { type MediaInfo, type ProbeOptions } from "./probe";
|
|
3
|
+
import { type Brand } from "./proxies";
|
|
4
|
+
export type CameraLayout = "sony-xavc" | "sony-xdcam" | "canon-xf" | "canon-dcim" | "panasonic-p2" | "panasonic-avchd" | "panasonic-lumix" | "blackmagic" | "gopro" | "dji" | "iphone" | "arri" | "red" | "dcim" | "loose";
|
|
5
|
+
export declare const CAMERA_LAYOUTS: readonly CameraLayout[];
|
|
6
|
+
export interface CardFile {
|
|
7
|
+
/** Absolute path. */
|
|
8
|
+
abs: string;
|
|
9
|
+
/** Path inside the card (forward slashes). */
|
|
10
|
+
rel: string;
|
|
11
|
+
size: number;
|
|
12
|
+
mtimeMs: number;
|
|
13
|
+
}
|
|
14
|
+
/** "metadata": camera XML, RED RMD, Blackmagic .sidecar, AVCHD CPI…; "telemetry": DJI SRT, GPS logs; "thumbnail": THM/T01.JPG; "audio": a voice memo; "reference": RED ONE reference movies. */
|
|
15
|
+
export type SidecarKind = "metadata" | "telemetry" | "thumbnail" | "audio" | "reference" | "other";
|
|
16
|
+
export interface Sidecar extends CardFile {
|
|
17
|
+
kind: SidecarKind;
|
|
18
|
+
}
|
|
19
|
+
export interface ClipMetadata {
|
|
20
|
+
make?: string;
|
|
21
|
+
model?: string;
|
|
22
|
+
lens?: string;
|
|
23
|
+
serial?: string;
|
|
24
|
+
/** Start timecode of the first segment, "HH:MM:SS:FF". */
|
|
25
|
+
timecode?: string;
|
|
26
|
+
/** Recording start as the camera wrote it (ISO 8601; offset kept). */
|
|
27
|
+
recordedAt?: string;
|
|
28
|
+
/** Seconds, all segments together; only when every segment's length is known. */
|
|
29
|
+
duration?: number;
|
|
30
|
+
width?: number;
|
|
31
|
+
height?: number;
|
|
32
|
+
fps?: number;
|
|
33
|
+
codec?: string;
|
|
34
|
+
/** "S-Log3 Cine", "C-Log2", "V-Log", "HLG"… only when the camera's XML (or the file's transfer tag) says so. */
|
|
35
|
+
logProfile?: string;
|
|
36
|
+
colorPrimaries?: string;
|
|
37
|
+
/** Reel/card name in the clip name (A001 in A001C001…). */
|
|
38
|
+
reel?: string;
|
|
39
|
+
/** Camera letter in the clip name (A in A001C001…): "A-cam". */
|
|
40
|
+
cameraLetter?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface Clip {
|
|
43
|
+
/** Stable for a card: layout + the first original's path. */
|
|
44
|
+
id: string;
|
|
45
|
+
layout: CameraLayout;
|
|
46
|
+
/** The camera's name for the take (C0001, GX010042, A001_C001_0502R5, DJI_0001). */
|
|
47
|
+
name: string;
|
|
48
|
+
kind: "video" | "photo" | "audio";
|
|
49
|
+
/** The recording, segments in order (GoPro chapters, RED _001/_002 R3Ds, AVCHD files, ARRIRAW frames). */
|
|
50
|
+
originals: CardFile[];
|
|
51
|
+
/**
|
|
52
|
+
* The low-res copy the camera recorded, matched by the camera-proxy rules: one per segment when the camera makes
|
|
53
|
+
* one per segment (GoPro LRV per chapter), else one. [] when the camera made none (or the match was ambiguous).
|
|
54
|
+
*/
|
|
55
|
+
proxies: CardFile[];
|
|
56
|
+
/**
|
|
57
|
+
* Which segment each proxy is the copy of (index into `originals`), when the camera makes one per segment: GoPro's
|
|
58
|
+
* GL02… is chapter 2's even when chapter 1's LRV is missing. undefined: one proxy for the whole take.
|
|
59
|
+
*/
|
|
60
|
+
proxySegments?: number[];
|
|
61
|
+
/** Camera-proxy rule that paired the proxy (decides how strict `proxyCheck` is). */
|
|
62
|
+
proxyBrand?: Brand;
|
|
63
|
+
/**
|
|
64
|
+
* When probed: null when the proxy proves to be the same take (length, frame rate, timecode, time); otherwise why
|
|
65
|
+
* not. undefined when not probed or no proxy.
|
|
66
|
+
*/
|
|
67
|
+
proxyCheck?: string | null;
|
|
68
|
+
/**
|
|
69
|
+
* Files the camera-proxy rules paired with this clip but that didn't prove to be its proxy (`proxyCheck` said why,
|
|
70
|
+
* or Canon's loose names were never checked because nothing was probed). They are clips of their own now: a file
|
|
71
|
+
* that may be a separate recording is never left out of an upload plan as "only a proxy".
|
|
72
|
+
*/
|
|
73
|
+
rejectedProxies?: {
|
|
74
|
+
rel: string;
|
|
75
|
+
why: string;
|
|
76
|
+
}[];
|
|
77
|
+
/** Other files of the original recording, made with it (Panasonic P2's per-channel audio MXFs): uploaded as originals. */
|
|
78
|
+
tracks: CardFile[];
|
|
79
|
+
sidecars: Sidecar[];
|
|
80
|
+
/** .cube / .3dl LUTs: next to the clip (same name first), then the card's LUT folders. */
|
|
81
|
+
luts: CardFile[];
|
|
82
|
+
metadata: ClipMetadata;
|
|
83
|
+
/** Probe of the first original and of the first proxy (when probed). */
|
|
84
|
+
probe?: {
|
|
85
|
+
original?: MediaInfo;
|
|
86
|
+
proxy?: MediaInfo;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export interface CardReading {
|
|
90
|
+
root: string;
|
|
91
|
+
/** Layouts found, in the order of `CAMERA_LAYOUTS`. */
|
|
92
|
+
layouts: CameraLayout[];
|
|
93
|
+
clips: Clip[];
|
|
94
|
+
/** Files no clip took: the camera's own index files (MEDIAPRO.XML, STATUS.BIN, AVCHD playlists…), documents. */
|
|
95
|
+
other: CardFile[];
|
|
96
|
+
/** Folders or files that couldn't be read: the reading is incomplete. */
|
|
97
|
+
errors: ScanIssue[];
|
|
98
|
+
}
|
|
99
|
+
export interface ReadCardOptions extends ProbeOptions {
|
|
100
|
+
/**
|
|
101
|
+
* Probe clips with ffprobe for duration, resolution, codec, timecode and the proxy check (default false: names,
|
|
102
|
+
* places and camera XML only). Or a function to probe with (ExifTool, MediaInfo, a cache…).
|
|
103
|
+
*/
|
|
104
|
+
probe?: boolean | ((abs: string) => Promise<MediaInfo | undefined>);
|
|
105
|
+
/** Probes at a time (default 2: a card reader is slow and the camera's card may be busy). */
|
|
106
|
+
concurrency?: number;
|
|
107
|
+
/** Files already listed (a product's own walk); default: the card is walked. */
|
|
108
|
+
files?: Found[];
|
|
109
|
+
}
|
|
110
|
+
/** Clip name → reel and camera letter: A001C001…, A001_C001_…, A001_08011205_C001 (Blackmagic), AA0001C001… (Canon 2024). */
|
|
111
|
+
export declare function reelOf(name: string): {
|
|
112
|
+
reel?: string;
|
|
113
|
+
cameraLetter?: string;
|
|
114
|
+
};
|
|
115
|
+
/** What a card reading treats as media (a clip's original): the file kinds plus MORE_STILLS. */
|
|
116
|
+
export declare const isCardMedia: (rel: string) => boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Read a card (or any folder) into clips. Never writes to it. Files are listed once; with `probe`, each clip's
|
|
119
|
+
* segments and first proxy are probed (`concurrency` at a time) for metadata and the proxy's same-take check.
|
|
120
|
+
*/
|
|
121
|
+
export declare function readCard(root: string, opts?: ReadCardOptions): Promise<CardReading>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** What a probe knows about a clip or still. Every field optional: only what the file says. */
|
|
2
|
+
export interface MediaInfo {
|
|
3
|
+
/** Seconds. */
|
|
4
|
+
duration?: number;
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
fps?: number;
|
|
8
|
+
/** e.g. "h264", "hevc", "prores". */
|
|
9
|
+
videoCodec?: string;
|
|
10
|
+
/** e.g. "High 4:2:2 Intra", "Main 10". */
|
|
11
|
+
profile?: string;
|
|
12
|
+
pixFmt?: string;
|
|
13
|
+
bitrate?: number;
|
|
14
|
+
audioCodec?: string;
|
|
15
|
+
audioChannels?: number;
|
|
16
|
+
/** Camera make/model when the file says so (Sony XML sidecar, QuickTime tags). */
|
|
17
|
+
camera?: string;
|
|
18
|
+
/** e.g. "S-Log3" when known. */
|
|
19
|
+
gamma?: string;
|
|
20
|
+
/** Recording time, ISO 8601. */
|
|
21
|
+
createdAt?: string;
|
|
22
|
+
/** Start timecode (SMPTE, e.g. "02:16:56:12"). */
|
|
23
|
+
timecode?: string;
|
|
24
|
+
colorRange?: string;
|
|
25
|
+
colorSpace?: string;
|
|
26
|
+
colorPrimaries?: string;
|
|
27
|
+
colorTransfer?: string;
|
|
28
|
+
/** Video frames in the file (from the container). */
|
|
29
|
+
frames?: number;
|
|
30
|
+
/** Audio streams and their channel counts, e.g. [2] or [1, 1, 1, 1]. */
|
|
31
|
+
audioTracks?: number[];
|
|
32
|
+
/** Audio tracks ffmpeg can decode, by position among the audio streams. */
|
|
33
|
+
audioDecodable?: number[];
|
|
34
|
+
/** Display rotation in degrees. width/height above are already the displayed size. */
|
|
35
|
+
rotation?: number;
|
|
36
|
+
/** Variable frame rate. */
|
|
37
|
+
vfr?: boolean;
|
|
38
|
+
/** GPS from the file (ISO 6709 tag). Private data: a product decides who sees it. */
|
|
39
|
+
location?: {
|
|
40
|
+
lat: number;
|
|
41
|
+
lon: number;
|
|
42
|
+
altitude?: number;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* The container ffprobe found (its format_name, e.g. "mov,mp4,m4a,3gp,3g2,mj2", "matroska,webm", "mpegts"),
|
|
46
|
+
* whatever the extension says. Probes made before it was recorded don't have it.
|
|
47
|
+
*/
|
|
48
|
+
container?: string;
|
|
49
|
+
}
|
|
50
|
+
/** Runs a command and resolves with its stdout (the default runs it with execFile: no shell). */
|
|
51
|
+
export type Runner = (cmd: string, args: string[], timeoutMs: number) => Promise<string>;
|
|
52
|
+
export declare const execRunner: Runner;
|
|
53
|
+
export interface ProbeOptions {
|
|
54
|
+
/** ffprobe to run (default "ffprobe" on PATH). */
|
|
55
|
+
ffprobe?: string;
|
|
56
|
+
run?: Runner;
|
|
57
|
+
/** Default 30 s. */
|
|
58
|
+
timeoutMs?: number;
|
|
59
|
+
/** Read the Sony <clip>M01.XML sidecar next to the file (default true). */
|
|
60
|
+
sidecar?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** "+37.7919-122.4092+074.368/" (ISO 6709: QuickTime and Android location tags). */
|
|
63
|
+
export declare function parseIso6709(v?: string): MediaInfo["location"];
|
|
64
|
+
/** ffprobe's `-show_format -show_streams` JSON → MediaInfo (pure; `abs` only decides "still" and finds the sidecar). */
|
|
65
|
+
export declare function mediaInfoFromFfprobe(d: any, abs: string, opts?: {
|
|
66
|
+
sidecar?: boolean;
|
|
67
|
+
}): MediaInfo;
|
|
68
|
+
/** Probe one file with ffprobe. undefined when ffprobe can't read it (RAW without a decoder, damaged, a timeout). */
|
|
69
|
+
export declare function probeMedia(abs: string, opts?: ProbeOptions): Promise<MediaInfo | undefined>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Camera-recorded proxies: which file on a card is the low-res copy the camera made of which clip, and whether that
|
|
3
|
+
* copy can stand in for the clip (the same take; plays in a browser). Moved from UploadFilm's app/src/main/proxyPolicy.ts
|
|
4
|
+
* (the camera-proxies work); the rules are unchanged. Pure: no I/O.
|
|
5
|
+
*/
|
|
6
|
+
import type { MediaInfo } from "./probe";
|
|
7
|
+
/**
|
|
8
|
+
* Is this a format a browser plays as a proxy: 8-bit 4:2:0 H.264 in MP4/MOV, AAC/MP3 audio or none. DJI's .LRF and
|
|
9
|
+
* GoPro's/Insta360's .LRV are MP4 files under another extension: judged by what's inside like any MP4 (a proxy is
|
|
10
|
+
* always uploaded as video/mp4).
|
|
11
|
+
*/
|
|
12
|
+
export declare function browserPlayable(name: string, m: MediaInfo | undefined): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* A file's path, but with the name it has on disk: a rename changes only `name` and `path` (`diskName` keeps the
|
|
15
|
+
* camera's name), so anything matched against what's on the card reads this instead of `path`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const diskPath: (f: {
|
|
18
|
+
path: string;
|
|
19
|
+
folder?: string;
|
|
20
|
+
diskName?: string;
|
|
21
|
+
}) => string;
|
|
22
|
+
/**
|
|
23
|
+
* What the matcher needs of a file. `path` is its path in the product (forward slashes); `src` the card it came from.
|
|
24
|
+
* A file the product renamed is matched by its name on disk (`diskName`, see diskPath), not its new name.
|
|
25
|
+
*/
|
|
26
|
+
export interface Entry {
|
|
27
|
+
id: string;
|
|
28
|
+
path: string;
|
|
29
|
+
folder?: string;
|
|
30
|
+
diskName?: string;
|
|
31
|
+
size: number;
|
|
32
|
+
kind: string;
|
|
33
|
+
/** The card or folder it came from, and its path on it. Without it, only the cross-card rules (Canon, LUMIX) apply. */
|
|
34
|
+
src?: {
|
|
35
|
+
id: string;
|
|
36
|
+
rel?: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Which rule paired a clip with its proxy. It decides how strictly the two must prove they're the same take
|
|
41
|
+
* (cameraProxyFits): "canon" and "lumix" pair across cards, so they need the timecode or recording time to agree;
|
|
42
|
+
* "canon-loose" (names that differ in Canon's two random characters) needs the timecode itself.
|
|
43
|
+
*/
|
|
44
|
+
export type Brand = "sony" | "panasonic" | "lumix" | "canon" | "canon-loose" | "dji" | "gopro" | "insta360" | "nikon" | "blackmagic" | "red";
|
|
45
|
+
/**
|
|
46
|
+
* The camera's own proxy for each main clip in `files`: main id → proxy entry, and the set of entries that are a
|
|
47
|
+
* camera proxy of something here. Pairs come from the rules above by name and place only; a key with more than one
|
|
48
|
+
* main or more than one proxy is ambiguous and pairs nothing, and a file that would end up in two pairs is in none.
|
|
49
|
+
* When in doubt, no pair: the clip then gets the proxy it would have had anyway. A pairing never affects whether an
|
|
50
|
+
* original is uploaded (a camera proxy's own file goes up like any other file); a file no rule pairs, such as an LRV
|
|
51
|
+
* whose clip isn't among the files given, is an ordinary clip.
|
|
52
|
+
*/
|
|
53
|
+
export declare function matchCameraProxies(files: Entry[]): {
|
|
54
|
+
proxyFor: Map<string, {
|
|
55
|
+
entry: Entry;
|
|
56
|
+
brand: Brand;
|
|
57
|
+
}>;
|
|
58
|
+
proxies: Set<string>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Are the clip and its camera proxy the same take: they cover the same span (durations within half a second or 1 %:
|
|
62
|
+
* camera proxies can end a frame or two apart), and agree on every other signal both files carry: frame rate, start
|
|
63
|
+
* timecode, recording time. Any of those disagreeing turns it down. Rules that pair across cards ("canon", "lumix")
|
|
64
|
+
* also need the timecode or the recording time to agree, and Canon's loose names ("canon-loose") the timecode itself. Blackmagic records its proxies at
|
|
65
|
+
* the project frame rate, so an off-speed clip's proxy runs longer or shorter than the clip: accepted only when both
|
|
66
|
+
* carry the same start timecode. null when the same take, else why not.
|
|
67
|
+
*/
|
|
68
|
+
export declare function sameTake(main: MediaInfo | undefined, proxy: MediaInfo | undefined, brand: Brand): string | null;
|
|
69
|
+
/** Is a camera proxy fit to stand in for its clip as is: a browser plays it and it's the same take. null when fit, else why not. */
|
|
70
|
+
export declare function cameraProxyFits(main: MediaInfo | undefined, proxyName: string, proxy: MediaInfo | undefined, brand?: Brand): string | null;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { CameraLayout, CardFile, Clip } from "./layouts";
|
|
2
|
+
/**
|
|
3
|
+
* The calendar day a clip was recorded, "YYYY-MM-DD". A time the camera wrote with its own offset (+02:00), or with no
|
|
4
|
+
* offset at all (the camera's clock, local by definition), is that day as written; one in UTC ("Z") is read in
|
|
5
|
+
* `timeZone` (default the system's). No recording time: the first original's modification time (`fallback` true).
|
|
6
|
+
*/
|
|
7
|
+
export declare function recordedDay(c: Clip, timeZone?: string): {
|
|
8
|
+
day: string;
|
|
9
|
+
fallback: boolean;
|
|
10
|
+
} | undefined;
|
|
11
|
+
export interface ClipFilter {
|
|
12
|
+
/** "YYYY-MM-DD", or several. */
|
|
13
|
+
recordedOn?: string | string[];
|
|
14
|
+
/** Also match clips with no recording time by their file date (default true). */
|
|
15
|
+
fileDateFallback?: boolean;
|
|
16
|
+
timeZone?: string;
|
|
17
|
+
/** Camera letter(s) ("A" for A-cam), from the clip name or `cameraOf`. */
|
|
18
|
+
camera?: string | string[];
|
|
19
|
+
/** A product's own camera assignment (e.g. per card): wins over the clip name's letter. */
|
|
20
|
+
cameraOf?: (c: Clip) => string | undefined;
|
|
21
|
+
layout?: CameraLayout | CameraLayout[];
|
|
22
|
+
kind?: Clip["kind"] | Clip["kind"][];
|
|
23
|
+
/** Substring of the camera model, case-insensitive ("FX30"). */
|
|
24
|
+
model?: string;
|
|
25
|
+
}
|
|
26
|
+
/** The clips matching every given condition. */
|
|
27
|
+
export declare function selectClips(clips: Clip[], f: ClipFilter): Clip[];
|
|
28
|
+
export declare const clipsRecordedOn: (clips: Clip[], day: string, timeZone?: string) => Clip[];
|
|
29
|
+
export declare const clipsFromCamera: (clips: Clip[], camera: string, cameraOf?: (c: Clip) => string | undefined) => Clip[];
|
|
30
|
+
/** Days on which clips were recorded, with how many: for a "which day?" picker. */
|
|
31
|
+
export declare function recordingDays(clips: Clip[], timeZone?: string): {
|
|
32
|
+
day: string;
|
|
33
|
+
clips: number;
|
|
34
|
+
}[];
|
|
35
|
+
export type PlanRole = "original" | "proxy" | "sidecar" | "lut" | "other";
|
|
36
|
+
export interface PlanFile extends CardFile {
|
|
37
|
+
role: PlanRole;
|
|
38
|
+
/** Clips this file belongs to (a card's LUT folder is shared). */
|
|
39
|
+
clipIds: string[];
|
|
40
|
+
/** Segment position for an original or a per-segment proxy (0-based). */
|
|
41
|
+
segment?: number;
|
|
42
|
+
contentType: string;
|
|
43
|
+
}
|
|
44
|
+
export interface UploadPlan {
|
|
45
|
+
/** Originals of every clip first (in clip order), then proxies, sidecars and LUTs. Each file once. */
|
|
46
|
+
files: PlanFile[];
|
|
47
|
+
bytes: number;
|
|
48
|
+
/** Bytes by role. */
|
|
49
|
+
byRole: Record<PlanRole, number>;
|
|
50
|
+
clips: number;
|
|
51
|
+
}
|
|
52
|
+
export interface PlanOptions {
|
|
53
|
+
originals?: boolean;
|
|
54
|
+
proxies?: boolean;
|
|
55
|
+
sidecars?: boolean;
|
|
56
|
+
luts?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Files of the card no clip took (`CardReading.other`: the camera's index files, documents…) to send too, after
|
|
59
|
+
* everything else, role "other". A product that backs up a whole card passes them; nothing on a card is otherwise
|
|
60
|
+
* in a plan unless it belongs to a clip.
|
|
61
|
+
*/
|
|
62
|
+
others?: CardFile[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The files to send for `clips`, ready for a transfer engine: an original is never dropped from a plan that asks
|
|
66
|
+
* for originals, and every file appears once (shared LUTs list every clip they belong to).
|
|
67
|
+
*/
|
|
68
|
+
export declare function uploadPlan(clips: Clip[], opts?: PlanOptions): UploadPlan;
|