export class TinoClient {
  constructor(private apiKey:string,private baseUrl="https://app.spinarditech.com/api/v1/public"){}
  private async request(path:string,init:RequestInit={}){const response=await fetch(this.baseUrl+path,{...init,headers:{Authorization:"Bearer "+this.apiKey,"Content-Type":"application/json",...(init.headers||{})}});const data=await response.json();if(!response.ok)throw new Error(data?.error?.message||data?.error||"Tino API error");return data}
  agents(){return this.request("/agents")}
  workflows(){return this.request("/workflows")}
  executions(){return this.request("/executions")}
  execute(workflowId:string,input:Record<string,unknown>={},idempotencyKey=crypto.randomUUID()){return this.request("/executions",{method:"POST",headers:{"Idempotency-Key":idempotencyKey},body:JSON.stringify({workflow_id:workflowId,input})})}
  execution(id:string){return this.request("/executions/"+id)}
  cancelExecution(id:string){return this.request("/executions/"+id,{method:"POST",body:JSON.stringify({action:"cancel"})})}
  knowledge(){return this.request("/knowledge")}
}
