feat(vision): bind task screenshots, route vision and resume budget pauses

This commit is contained in:
Agent Workbench Dev
2026-11-01 00:48:38 +08:00
parent 0d1ab743f1
commit 96a7ed19c7
79 changed files with 1721 additions and 36 deletions
+10 -2
View File
@@ -1,8 +1,8 @@
let accessToken = '';
export function setToken(token: string) { accessToken = token; }
export async function api<T>(path: string, input?: unknown): Promise<T> {
export async function api<T>(path: string, input?: unknown,method?:string): Promise<T> {
const response = await fetch('/api' + path, {
method: input === undefined ? 'GET' : 'POST',
method: method??(input === undefined ? 'GET' : 'POST'),
headers: { 'Content-Type': 'application/json', ...(accessToken ? { 'X-Workbench-Token': accessToken } : {}) },
...(input === undefined ? {} : { body: JSON.stringify(input) }),
});
@@ -56,3 +56,11 @@ export async function browserImageBlob(sessionId: string, jobId: string, artifac
if (!response.ok) { const value = await response.json().catch(() => ({})); throw new Error(value.error || '页面截图读取失败。'); }
return response.blob();
}
export async function inputImageBlob(sessionId:string,image:import('./types').InputAttachment,original=false):Promise<Blob>{
const response=await fetch('/api/sessions/'+sessionId+'/input-attachments/'+image.id+'/'+(original?'original':'image'),{headers:{'X-Workbench-Token':accessToken},cache:'no-store'});
if(!response.ok){const value=await response.json().catch(()=>({}));throw new Error(value.error||'截图读取失败,请刷新核对。');}
const bytes=await response.arrayBuffer(),digest=Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256',bytes)),value=>value.toString(16).padStart(2,'0')).join('');
if(digest!==(original?image.sha256:image.sentSha256))throw new Error('截图SHA-256核对失败,未展示或下载。');
return new Blob([bytes],{type:original?image.mediaType:'image/png'});
}