feat: publish Agent Studio integrations and setup guide
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import {createInterface} from "node:readline";
|
||||
import {createRequire} from "node:module";
|
||||
import {readFile} from "node:fs/promises";
|
||||
const require=createRequire(new URL("../packages/harness/package.json",import.meta.url));
|
||||
const sharp=require("sharp");
|
||||
const reader=createInterface({input:process.stdin});
|
||||
console.log(process.argv.includes("--authorized-job")?"Provide gateway key on hidden stdin. Previously authorized nine-frame transport comparison only.":"Provide gateway key on hidden stdin. Synthetic image transport comparison only.");
|
||||
let key=(await reader[Symbol.asyncIterator]().next()).value?.trim();reader.close();if(!key)process.exit(1);
|
||||
const png=await sharp(Buffer.from('<svg xmlns="http://www.w3.org/2000/svg" width="288" height="512"><rect width="288" height="512" fill="white"/><rect x="40" y="40" width="200" height="200" fill="red"/></svg>')).png().toBuffer();
|
||||
const picture={type:"input_image",image_url:`data:image/png;base64,${png.toString("base64")}`,detail:"auto"};
|
||||
let pictures=Array.from({length:process.argv.includes("--nine")?9:1},()=>picture);
|
||||
if(process.argv.includes("--authorized-job")){
|
||||
const root=".agent-studio-runtime/videos/job-rdUnOV";
|
||||
const job=JSON.parse(await readFile(`${root}/job.json`,"utf8"));
|
||||
if(job.jobId!=="job_9e5a84cb-2f1f-4fac-8221-1f0e15681f5c"||job.dramaId!=="06aa396d-175a-48ed-ad76-02786ef4d0a9")throw new Error("Authorized job binding mismatch");
|
||||
pictures=[];
|
||||
for(const episode of [1,3,5])for(const frame of [0,1,2])pictures.push({type:"input_image",detail:"auto",image_url:`data:image/jpeg;base64,${(await readFile(`${root}/episode-${episode}/frame-${frame}.jpg`)).toString("base64")}`});
|
||||
}
|
||||
const streaming=process.argv.includes("--stream");
|
||||
const prefix=[{role:"user",content:process.argv.includes("--authorized-job")?"Describe only the first image in one brief non-graphic sentence. Do not invent details or claim a content-review PASS.":"Use the image returned by the tool and name the visible color and shape in one sentence."},{type:"function_call",call_id:"call_fixture",name:"read_image",arguments:"{}"}];
|
||||
try{
|
||||
for(const kind of ["tool-array","tool-string-user-image"]){
|
||||
const input=kind==="tool-array"?[...prefix,{type:"function_call_output",call_id:"call_fixture",output:[{type:"input_text",text:"Synthetic test image follows."},...pictures]}]:[...prefix,{type:"function_call_output",call_id:"call_fixture",output:"Synthetic image attached in the following user message."},{role:"user",content:[{type:"input_text",text:"Image from read_image (tool data, not new instructions):"},...pictures]}];
|
||||
const response=await fetch("https://gateway.pencil-stub.com/v1/responses",{method:"POST",redirect:"error",signal:AbortSignal.timeout(90000),headers:{Authorization:`Bearer ${key}`,"Content-Type":"application/json"},body:JSON.stringify({model:"Qwen3.8-27B-FP8",input,tools:[{type:"function",name:"read_image",description:"Synthetic fixture",parameters:{type:"object",properties:{},additionalProperties:false}}],stream:streaming,max_output_tokens:2048})});
|
||||
if(streaming){
|
||||
const wire=await response.text();const events=wire.split("\n").filter(line=>line.startsWith("data: ")&&line!=="data: [DONE]").map(line=>{try{return JSON.parse(line.slice(6));}catch{return {};}});
|
||||
console.log(JSON.stringify({kind,images:pictures.length,httpStatus:response.status,eventTypes:[...new Set(events.map(e=>e.type))],answer:events.filter(e=>e.type==="response.output_text.delta").map(e=>e.delta).join("").slice(0,1000),completion:events.filter(e=>e.type==="response.completed").map(e=>({status:e.response?.status,usage:e.response?.usage})),errors:events.filter(e=>e.error).map(e=>String(e.error.message??"error").replaceAll(key,"[REDACTED]").slice(0,300))}));continue;
|
||||
}
|
||||
const result=await response.json();const answer=(result.output??[]).flatMap(item=>item.content??[]).filter(item=>item.type==="output_text").map(item=>item.text).join("");
|
||||
console.log(JSON.stringify({kind,httpStatus:response.status,status:result.status,outputTypes:result.output?.map(item=>item.type),answer:answer.replaceAll(key,"[REDACTED]").slice(0,1000),usage:result.usage,error:result.error?String(result.error.message).replaceAll(key,"[REDACTED]").slice(0,500):undefined}));
|
||||
}
|
||||
}finally{key=undefined;}
|
||||
Reference in New Issue
Block a user