Download src/db/batch-continued-record.js from VanyaJ/bada-terminal: direct link, hf CLI and curl.
- Browser
- Download file 2.85 kB
-
https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/db/batch-continued-record.js
- Command line
-
hf download hf://VanyaJ/bada-terminal/src/db/batch-continued-record.js
-
curl -L -o batch-continued-record.js https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/db/batch-continued-record.js
2.85 kB
| // 실패 intent는 불변으로 두고, continue 정책이 실제 게시한 출력만 별도로 보존한다. | |
| // 설명 문서: docs/specs/batch-step-continuation.md (v0.18.0, R67 진행 중) | |
| const {hash,hex}=require('../services/bong-browser-resolution'),{same}=require('./batch-recovery-record'); | |
| const fail=()=>require('./batch-checkpoint-record').fail(); | |
| const uncertain=error=>require('../utils/cli-storage-error').isUncertainCliFailure({...error,retryable:false}); | |
| function resolved(record,key){return record.continuations?.[key]||require('./batch-memory-continue-record').resolved(record,key);} | |
| function validate(record){ | |
| const map=record.continuations;if(map===undefined)return; | |
| if(!map||typeof map!=='object'||Array.isArray(map)||!Object.keys(map).length||Object.keys(map).length>4096)fail(); | |
| const revisions=new Set(),steps=require('./batch-checkpoint-record').stepsFor({steps:record.definition.steps}); | |
| for(const [key,r]of Object.entries(map)){ | |
| const e=record.entries[key],keys=['version','kind','entryKey','originalEntryHash','recordedRevision','recordedAt','output','outputHash','usageIds','requestKeys','usageHash','invocationsHash']; | |
| const list=v=>Array.isArray(v)&&v.length<=4096&&new Set(v).size===v.length&&v.every(k=>typeof k==='string'&&k.length>0&&k.length<=512&&!['__proto__','constructor','prototype'].includes(k)); | |
| if(r?.version!==1||r.kind!=='continued'||r.entryKey!==key||e?.status!=='failed'||steps[e.stepIndex]?.on_failure!=='continue'||uncertain(e.error) | |
| ||Object.keys(r).length!==keys.length||Object.keys(r).some(k=>!keys.includes(k))||!['originalEntryHash','outputHash','usageHash','invocationsHash'].every(k=>hex(r[k]))||hash(e)!==r.originalEntryHash||hash(r.output)!==r.outputHash | |
| ||!Number.isSafeInteger(r.recordedRevision)||r.recordedRevision<3||r.recordedRevision>record.revision||revisions.has(r.recordedRevision)||!Number.isFinite(Date.parse(r.recordedAt))||Date.parse(r.recordedAt)<Date.parse(e.completedAt) | |
| ||!r.output||Object.keys(r.output).length!==2||typeof r.output.error!=='string'||r.output.error.slice(0,2000)!==e.error.message||typeof r.output._duration!=='string'||!/^\d+\.\d{2}$/.test(r.output._duration)||!Number.isFinite(Number(r.output._duration))||!list(r.usageIds)||!list(r.requestKeys))fail(); | |
| require('./batch-checkpoint-record').json(r.output);revisions.add(r.recordedRevision); | |
| } | |
| } | |
| function transition(next,previous){ | |
| const old=previous.continuations||{},actual=next.continuations||{},added=Object.keys(actual).filter(k=>!Object.hasOwn(old,k)); | |
| for(const [k,v]of Object.entries(old))if(!same(v,actual[k]))fail(); | |
| if(added.length){if(added.length!==1||added[0]!==previous.currentKey||actual[added[0]].recordedRevision!==previous.revision+1)fail();return true;} | |
| if(!same(old,actual))fail();return false; | |
| } | |
| module.exports={resolved,validate,transition,uncertain}; | |