feat(vision): bind task screenshots, route vision and resume budget pauses
This commit is contained in:
+10
-2
@@ -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'});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user