broods 0.22.1 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account.d.ts +1 -1
- package/dist/account.js +1 -1
- package/dist/chunk-t6xktzr3.js +5 -0
- package/dist/{chunk-nq1vqmh0.js → chunk-vyvy543y.js} +2 -2
- package/dist/{chunk-3cvxks4m.js → chunk-zyz35wc1.js} +2 -2
- package/dist/cli/index.js +145 -120
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-prg3eaft.js +0 -5
package/dist/account.d.ts
CHANGED
|
@@ -323,7 +323,7 @@ interface AgentGitHubChannelConfig {
|
|
|
323
323
|
allowedChannelIds?: string[];
|
|
324
324
|
allowedUserIds?: string[];
|
|
325
325
|
/** Bot username for @-mention detection (e.g. "my-bot" or "my-bot[bot]"). */
|
|
326
|
-
|
|
326
|
+
botUserName?: string;
|
|
327
327
|
/** Bot's numeric GitHub user ID for self-message detection. */
|
|
328
328
|
botUserId?: number;
|
|
329
329
|
/** When false, the bot does not auto-trigger on new issues (opened/edited/reopened). Defaults to true. The bot still triggers when assigned to an issue. */
|
package/dist/account.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{S,r,y}from"./chunk-vyvy543y.js";export{r as BroodsAccountApiError,y as BroodsAccountClient,S as envPlaceholder};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
function p(r){if(r.events&&r.input!==void 0)throw Error("Run input accepts either `input` or `events`, not both");if(r.events&&r.events.length>0)return r.events;if(typeof r.input==="string")return[{role:"user",content:[{type:"text",text:r.input}]}];throw Error("Run input requires `input` (string) or a non-empty `events` array")}async function*b(r){let y=r.getReader(),S=new TextDecoder,I="";try{while(!0){let{done:H,value:G}=await y.read();if(H)break;I+=S.decode(G,{stream:!0});let J=I.split(`
|
|
2
|
+
`);I=J.pop()??"";for(let Y of J)if(Y.startsWith("data: "))yield Y.slice(6)}}finally{y.releaseLock()}}import{mkdir as Pe,readFile as Ue,writeFile as We}from"node:fs/promises";import{homedir as Me}from"node:os";import{dirname as $e,join as _e}from"node:path";var o="broods",s="_generated",l=_e(Me(),".broods","config.json"),pe="broods.app",fe="dashboard",Ke="gateway";async function w(){let r=process.env.BROODS_TOKEN,y=process.env.BROODS_BASE_URL;if(r&&y)return{baseUrl:n(y),token:r,createdAt:new Date().toISOString()};try{let S=JSON.parse(await Ue(l,"utf8"));if(typeof S.baseUrl!=="string"||!S.baseUrl)return null;return S}catch{return null}}async function f(r){await Pe($e(l),{recursive:!0}),await We(l,`${JSON.stringify(r,null,2)}
|
|
3
|
+
`,"utf8")}function a(){return process.env.BROODS_STAGE}function n(r){let y=r.length;while(y>0&&r.charCodeAt(y-1)===47)y-=1;return r.slice(0,y)}function h(r){try{let y=new URL(r);if(!y.hostname.startsWith(`${fe}.`))return;let S=y.hostname.slice(fe.length+1);if(S!==pe&&!S.endsWith(`.${pe}`))return;return y.hostname=`${Ke}.${S}`,n(y.origin)}catch{return}}import{existsSync as ye,readFileSync as ge,statSync as He}from"node:fs";import{join as he,resolve as Ce}from"node:path";var le=new Map,Be=new Set(Object.keys(process.env)),me=new Set;function e(r=process.cwd()){je(r);let y=Ge();return{dashboardUrl:process.env.BROODS_DASHBOARD_URL??y?.dashboardUrl,baseUrl:process.env.BROODS_BASE_URL??y?.baseUrl,token:process.env.BROODS_TOKEN??y?.token,project:process.env.BROODS_PROJECT,stage:a()}}function u(r,y=process.cwd()){let S=process.env[r];if(S===void 0)return!1;let I=Ce(y);for(let H of[".env.local",".env"]){let G=he(I,H);if(!ye(G))continue;let J=Se(ge(G,"utf8"));if(J[r]!==void 0)return J[r]!==S}return!0}function je(r){let y=Ce(r),S=process.env.BROODS_RELOAD_ENV==="1";for(let I of[".env",".env.local"]){let H=he(y,I);if(!ye(H)){le.delete(H);continue}let G=He(H).mtimeMs,J=le.get(H);if(J&&J.mtimeMs===G)continue;le.set(H,{mtimeMs:G});for(let[Y,Q]of Object.entries(Se(ge(H,"utf8"))))if(S||!Be.has(Y)||me.has(Y))process.env[Y]=Q,me.add(Y)}}function Se(r){let y={};for(let S of r.split(/\r?\n/)){let I=S.trim();if(!I||I.startsWith("#"))continue;let H=I.startsWith("export ")?I.slice(7).trim():I,G=H.indexOf("=");if(G<=0)continue;let J=H.slice(0,G).trim();if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(J))continue;y[J]=Le(H.slice(G+1).trim())}return y}function Le(r){if(r.startsWith('"')&&r.endsWith('"'))return r.slice(1,-1).replace(/\\n/g,`
|
|
4
|
+
`).replace(/\\"/g,'"');if(r.startsWith("'")&&r.endsWith("'"))return r.slice(1,-1);let y=r.indexOf(" #");return y>=0?r.slice(0,y).trimEnd():r}function Ge(){try{let r=JSON.parse(ge(l,"utf8"));if(typeof r.baseUrl!=="string"||typeof r.token!=="string")return null;return{baseUrl:n(r.baseUrl),...typeof r.dashboardUrl==="string"?{dashboardUrl:n(r.dashboardUrl)}:{},token:r.token}}catch{return null}}var c="https://gateway.broods.app";class x extends Error{accepted;constructor(r){super(`Ingress ${r.eventId} was accepted asynchronously with status ${r.status??"queued"}`);this.accepted=r;this.name="IngressAcceptedError"}}class d{baseUrl;apiKey;fetchImpl;constructor(r={}){e(),this.baseUrl=m(r.baseUrl||r.host||process.env.BROODS_BASE_URL||process.env.BROODS_HOST||c),this.apiKey=r.apiKey||process.env.BROODS_API_KEY||void 0,this.fetchImpl=r.fetch??fetch}channelWebhookUrl(r){return`${this.baseUrl}${r.webhookPath.startsWith("/")?"":"/"}${r.webhookPath}`}accountWebhookUrl(r,y){let S=[r,y].map(encodeURIComponent);return`${this.baseUrl}/webhooks/${S.join("/")}`}stageWebhookUrl(r,y,S){let I=[r,"dev",y,S].map(encodeURIComponent);return`${this.baseUrl}/webhooks/${I.join("/")}`}agent(r,y){if(typeof r==="string"){let I=r,H=y??"";if(!H)throw Error(`Agent ${I} is missing a generated id. Run broods dev --once or broods deploy to sync it first.`);return{id:H,run:(G)=>this.run({...G,agentName:I,agentId:H}),runAsync:(G)=>this.runAsync({...G,agentName:I,agentId:H}),stream:(G)=>this.stream({...G,agentName:I,agentId:H})}}let S=r;if(!S.id)throw Error(`Agent ${S.name} is missing a generated id. Run broods dev --once or broods deploy to sync it first.`);return{id:S.id,run:(I)=>this.run(S,I),runAsync:(I)=>this.runAsync(S,I),stream:(I)=>this.stream(S,I)}}async run(r,y){let S=[],I="",H=y?this.stream(r,y):this.stream(r);for await(let G of H)if(S.push(G),G.type==="text-delta")I+=G.text;return{text:I,events:S}}async*stream(r,y){let S=y?{...y,agentId:r.id,agentName:r.name}:r,I=Re(S,"cli"),H=y?this.scopedUrl(r):this.baseUrl,G=await this.openStream(I,H);if(!G.ok)throw Error(`Run failed: ${G.status} ${await G.text()}`);if(G.status===202)throw new x(be(await G.json(),I));if(!G.body)throw Error("Run response has no body");for await(let J of b(G.body)){let Y;try{Y=JSON.parse(J)}catch{continue}if(Y.type==="error")throw Error(`Agent run failed: ${Ve(Y.error)}`);yield Y}}async runAsync(r,y){let S=y?{...y,agentId:r.id,agentName:r.name}:r,I=Re(S,"async"),H=y?this.scopedUrl(r,"/async"):`${this.baseUrl}/async`,G=await this.fetchJson(H,{method:"POST",headers:this.apiKeyHeaders(),body:JSON.stringify(I)});if(G.status!==202)throw Error(`Async run failed: ${G.status} ${await Fe(G,"202 JSON")}`);let J=be(await G.json(),I);return{...J,conversationKey:I.conversationKey,poll:()=>this.getAsyncStatus(J),wait:(Y)=>this.waitForAsyncStatus(J,Y)}}async getAsyncStatus(r,y={}){let S=this.resolveStatusUrl(r,y),I=await this.fetchJson(S,{method:"GET",headers:this.apiKeyHeaders()});if(I.status===404)return{status:"not_found"};if(!I.ok)throw Error(`Status check failed: ${I.status} ${await I.text()}`);return await I.json()}async waitForAsyncStatus(r,y={}){let S=Date.now()+(y.timeoutMs??180000),I=y.intervalMs??2000;while(Date.now()<S){if(y.signal?.aborted)throw Error("Async status polling aborted.");let H=await this.getAsyncStatus(r,y);if(H.status==="awaiting_approval"||H.status==="completed"||H.status==="failed"||H.status==="expired"||H.status==="not_found")return H;await ze(I,y.signal)}throw Error("Polling timeout")}async createCron(r){let y=await this.fetchJson(`${this.baseUrl}/v1/crons`,{method:"POST",headers:this.apiKeyHeaders(),body:JSON.stringify(Ze(r))});if(y.status!==201)throw Error(`Create cron job failed: ${y.status} ${await te(y)}`);return await y.json()}async listCrons(){let r=await this.fetchJson(`${this.baseUrl}/v1/crons`,{method:"GET",headers:this.apiKeyHeaders()});if(!r.ok)throw Error(`List cron jobs failed: ${r.status} ${await te(r)}`);return(await r.json()).crons}async getCron(r){let y=await this.fetchJson(`${this.baseUrl}/v1/crons/${encodeURIComponent(r)}`,{method:"GET",headers:this.apiKeyHeaders()});if(y.status===404)return null;if(!y.ok)throw Error(`Get cron job failed: ${y.status} ${await te(y)}`);return await y.json()}async listCronRuns(r,y={}){let S=new URLSearchParams;if(y.limit!==void 0)S.set("limit",String(y.limit));let I=S.size>0?`?${S}`:"",H=await this.fetchJson(`${this.baseUrl}/v1/crons/${encodeURIComponent(r)}/runs${I}`,{method:"GET",headers:this.apiKeyHeaders()});if(!H.ok)throw Error(`List cron job runs failed: ${H.status} ${await te(H)}`);return(await H.json()).runs}async updateCron(r,y){let S=await this.fetchJson(`${this.baseUrl}/v1/crons/${encodeURIComponent(r)}`,{method:"PATCH",headers:this.apiKeyHeaders(),body:JSON.stringify(y)});if(!S.ok)throw Error(`Update cron job failed: ${S.status} ${await te(S)}`);return await S.json()}async deleteCron(r){let y=await this.fetchJson(`${this.baseUrl}/v1/crons/${encodeURIComponent(r)}`,{method:"DELETE",headers:this.apiKeyHeaders()});if(y.status===404)return!1;if(!y.ok)throw Error(`Delete cron job failed: ${y.status} ${await te(y)}`);return(await y.json()).deleted}scopedUrl(r,y=""){if(r.projectSlug&&r.stageSlug&&r.endpointId)return`${this.baseUrl}/v1/${encodeURIComponent(r.projectSlug)}/agents/${encodeURIComponent(r.stageSlug)}/${encodeURIComponent(r.endpointId)}${y}`;return`${this.baseUrl}${y}`}async openStream(r,y){if(this.apiKey)return await this.fetchCore(r,y,{Authorization:`Bearer ${this.apiKey}`});throw Error(`BroodsClient streams directly from the core service at ${this.baseUrl}. Provide apiKey. For a self-hosted core service, set host/baseUrl or BROODS_HOST/BROODS_BASE_URL.`)}async fetchCore(r,y,S){try{return await this.fetchImpl(y,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...S},body:JSON.stringify(r)})}catch(I){throw Error(`Cannot access the broods core service at ${y}. The SDK uses ${c} by default; set host/baseUrl or BROODS_HOST/BROODS_BASE_URL to your own core service URL if your account uses a custom deployment. Cause: ${I instanceof Error?I.message:String(I)}`)}}apiKeyHeaders(){if(!this.apiKey)throw Error("BroodsClient requires apiKey or BROODS_API_KEY.");return{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`}}async fetchJson(r,y){try{return await this.fetchImpl(r,{...y,headers:{"Content-Type":"application/json",...y.headers}})}catch(S){throw Error(`Cannot access the broods core service at ${r}. Cause: ${S instanceof Error?S.message:String(S)}`)}}resolveStatusUrl(r,y){if(typeof r!=="string")return r.statusUrl;if(/^https?:\/\//.test(r))return r;if(!y.agentId)throw Error("Polling by status id requires agentId.");return Je(this.baseUrl,r,y.agentId)}}function m(r){let y=r.trim(),S=/^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(y)?y:`https://${y}`;return n(S)}function Re(r,y){let S=r.eventId??`${y}-${Date.now()}`;return{agentId:r.agentId,eventId:S,conversationKey:r.conversationKey??S,events:p(r),...r.mode!==void 0?{mode:r.mode}:{},...r.idempotencyKey!==void 0?{idempotencyKey:r.idempotencyKey}:{},...r.system!==void 0?{system:r.system}:{},...r.model!==void 0?{model:r.model}:{}}}function be(r,y){if(!r||typeof r!=="object")throw Error("Async response must be an object");let S=r.statusUrl;if(typeof S!=="string"||S.length===0)throw Error("Async response missing statusUrl");let I=qe(S);if(!I.statusId)throw Error("Async response statusUrl missing status id");let H=typeof r.eventId==="string"?r.eventId:I.statusId,G=r.status,J=r.requestedMode;return{statusUrl:S,statusId:I.statusId,eventId:H,agentId:I.agentId??y.agentId,...G==="accepted"||G==="queued"||G==="applied"||G==="processing"?{status:G}:{},...J==="reject"||J==="followup"||J==="collect"||J==="steer"?{requestedMode:J}:{}}}function qe(r){let y=new URL(r),S=y.pathname.match(/\/status\/([^/]+)$/);return{statusId:S?.[1]?decodeURIComponent(S[1]):void 0,agentId:y.searchParams.get("agentId")??void 0}}function Je(r,y,S){return`${m(r)}/status/${encodeURIComponent(y)}?agentId=${encodeURIComponent(S)}`}async function Fe(r,y){if((r.headers.get("content-type")??"").toLowerCase().includes("text/event-stream"))return await r.body?.cancel().catch(()=>{}),`expected ${y}, but the server returned an SSE stream. This usually means the core deployment routed /async to the direct streaming runner instead of the async handler.`;let I=await r.text();if(I.length<=2000)return I;return`${I.slice(0,2000)}... [truncated ${I.length-2000} chars]`}async function te(r){let y=await r.text();if(y.includes("Request body must include eventId and conversationKey"))return`${y}. Cron job APIs must be served by the configured baseUrl. Prefer defining stable cron jobs with defineCron(...) in broods/ and syncing with \`broods dev\` or \`broods deploy\`.`;return y}function Ze(r){if("agentId"in r)return r;let y=r.agent,S=typeof y==="string"?y:y.id,{agent:I,...H}=r;return{...H,agentId:S}}function ze(r,y){return new Promise((S,I)=>{if(y?.aborted){I(Error("Async status polling aborted."));return}let H=setTimeout(S,r);y?.addEventListener("abort",()=>{clearTimeout(H),I(Error("Async status polling aborted."))},{once:!0})})}function Ve(r){if(typeof r==="string")return r;if(!r||typeof r!=="object")return String(r);let y=r,S=y.data?.error?.message??y.message??y.responseBody??JSON.stringify(r),I=y.name?`${y.name}: `:"",H=y.statusCode?` (HTTP ${y.statusCode})`:"";return`${I}${S}${H}`}var Ye=2000,ke=0,ie=1;class _{baseUrl;apiKey;WebSocketImpl;connectTimeoutMs;constructor(r={}){if(e(),this.baseUrl=ve(r.baseUrl||r.host||process.env.BROODS_BASE_URL||process.env.BROODS_HOST||c),this.apiKey=r.apiKey||process.env.BROODS_API_KEY||"",!this.apiKey)throw Error("BroodsWebSocketClient requires apiKey or BROODS_API_KEY.");this.WebSocketImpl=r.WebSocket,this.connectTimeoutMs=r.connectTimeoutMs??Ye}subscribe(r,y={}){let S=this.resolveWebSocket(),I=this.buildUrl(r),H=Xe(r),G=Ie(this.baseUrl),J=new S(I),Y=!1,Q=!1,ee=setTimeout(()=>{if(!Y)se(G)},this.connectTimeoutMs),de=(X=1000,ce="client closed")=>{if(Q)return;if(Q=!0,clearTimeout(ee),r.signal?.removeEventListener("abort",ae),J.readyState===ie||J.readyState===ke)J.close(X,ce)},se=(X)=>{y.onError?.(X),de(1011,"websocket error")},Oe=()=>{y.onDone?.(),de(1000,"done")},ae=()=>{if(J.readyState===ie)J.send(JSON.stringify({type:"cancel"}));se(Error("WebSocket run aborted."))};return r.signal?.addEventListener("abort",ae,{once:!0}),J.onopen=()=>{if(Y=!0,clearTimeout(ee),r.signal?.aborted){ae();return}J.send(JSON.stringify({type:"execute",agentId:H,events:p(r),sessionId:r.sessionId,...r.eventId!==void 0?{eventId:r.eventId}:{},...r.mode!==void 0?{mode:r.mode}:{},...r.idempotencyKey!==void 0?{idempotencyKey:r.idempotencyKey}:{},...r.system!==void 0?{system:r.system}:{},...r.model!==void 0?{model:r.model}:{}}))},J.onmessage=(X)=>{if(typeof X.data!=="string")return;let ce=Ae(X.data);if(!ce)return;let ue=xe(ce,y);switch(y.onMessage?.(ue),ue.type){case"meta":y.onMeta?.(ue);break;case"done":Oe();break;case"error":se(Error(we(ue.error)));break}},J.onerror=()=>{se(G)},J.onclose=(X)=>{if(clearTimeout(ee),r.signal?.removeEventListener("abort",ae),Q||X.code===1000)return;se(Error(X.reason||"WebSocket connection closed."))},{url:I,sendControl:function(X){if(J.readyState!==ie)throw Error("WebSocket is not open");J.send(JSON.stringify({type:"control",...X}))},close:de}}attach(r,y={}){let S=this.resolveWebSocket(),I=this.buildUrl(r),H=new S(I),G=!1,J=(Y=1000,Q="client closed")=>{if(G)return;if(G=!0,H.readyState===ie||H.readyState===ke)H.close(Y,Q)};return H.onopen=()=>H.send(JSON.stringify({type:"attach",...r,signal:void 0,agent:void 0})),H.onmessage=(Y)=>{if(typeof Y.data!=="string")return;let Q=Ae(Y.data);if(!Q)return;let ee=xe(Q,y);if(y.onMessage?.(ee),ee.type==="done")y.onDone?.();if(ee.type==="error")y.onError?.(Error(we(ee.error)))},H.onerror=()=>y.onError?.(Ie(this.baseUrl)),H.onclose=(Y)=>{if(!G&&Y.code!==1000)y.onError?.(Error(Y.reason||"WebSocket connection closed."))},{url:I,sendControl:function(Y){if(H.readyState!==ie)throw Error("WebSocket is not open");H.send(JSON.stringify({type:"control",...Y}))},close:J}}async*stream(r){let y=[],S=!1,I=null,H=null,G=()=>{H?.(),H=null},J=this.subscribe(r,{onMessage:function(Y){y.push(Y),G()},onDone:function(){S=!0,G()},onError:function(Y){I=Y,G()}});try{while(!0){if(y.length>0){yield y.shift();continue}if(I)throw I;if(S)return;await new Promise((Y)=>{H=Y})}}finally{J.close()}}buildUrl(r){let y=Qe(r),S=r.projectSlug??r.agent?.projectSlug,I=r.stageSlug??r.agent?.stageSlug,H=S?`/${S}`:"",G=I?`/${I}`:"";return`${g(this.baseUrl)}/v1${H}/agents${G}/${encodeURIComponent(y)}/ws?token=${encodeURIComponent(this.apiKey)}`}resolveWebSocket(){let r=this.WebSocketImpl??globalThis.WebSocket;if(!r)throw Error("WebSocket is not available. Pass a WebSocket implementation in BroodsWebSocketClient options.");return r}}function Xe(r){let y=r.agentId??r.agent?.id??r.endpointId;if(!y)throw Error("WebSocket run requires agent, agentId, or endpointId.");return y}function Qe(r){let y=r.endpointId??r.agent?.endpointId??r.agent?.id;if(!y)throw Error("WebSocket run requires agent or endpointId.");return y}function g(r){let y=new URL(ve(r));if(y.protocol==="https:")y.protocol="wss:";if(y.protocol==="http:")y.protocol="ws:";return n(y.toString())}function ve(r){let y=r.trim();if(/^wss?:\/\//.test(y))return n(y);return m(y)}function Ie(r){return Error(`Cannot access the WebSocket service at ${r}.`)}function xe(r,y){if(r.type!=="output")return r;let S=r;return y.onOutput?.(S),S.data}function Ae(r){try{let y=JSON.parse(r);return typeof y==="object"&&y!==null&&typeof y.type==="string"?y:null}catch{return null}}function we(r){if(typeof r==="string")return r;if(r&&typeof r==="object"&&typeof r.message==="string")return r.message;return r===void 0?"WebSocket stream error.":JSON.stringify(r)}var De=Symbol.for("broods.resource"),Ne=Symbol.for("broods.config"),Te=Symbol.for("broods.connection"),Ee=/^[A-Z][A-Z0-9_]{0,63}$/,T=new Proxy((r)=>{if(!Ee.test(r))throw Error("env name must match /^[A-Z][A-Z0-9_]*$/ and be at most 64 characters.");return{__beeblastEnv:!0,name:r}},{get:function(r,y,S){if(typeof y==="string"&&Ee.test(y))throw Error(`env.${y} is not supported; use env("${y}")`);return Reflect.get(r,y,S)}});function ne(r,y,S,I){return{[De]:!0,kind:r,name:y,...S?{description:S}:{},config:I}}function oe(r,y){let{partition:S,...I}=y;return{[Te]:!0,kind:"connection",type:r,...S?{partition:S}:{},config:I}}function re(r,y,S,I,H){return ne("channelRecord",r,y,{...H,externalId:S,...I?{workspaceRef:I}:{}})}function k(r){return oe("discord",r)}function E(r){return oe("github",r)}function C(r){return oe("pancake",r)}function R(r){return oe("slack",r)}function A(r){return oe("telegram",r)}function M(r){return oe("zalo",r)}function P(r){let{name:y,description:S,channelId:I,guildId:H,...G}=r;return re(y,S,I,H,G)}function O(r){let{name:y,description:S,repo:I,...H}=r,[G,...J]=I.split("/");if(!G||J.length!==1||!J[0])throw Error(`Channel "${y}" repo must be "owner/name", not "${I}"`);return re(y,S,I,G,H)}function N(r){let{name:y,description:S,conversationId:I,...H}=r;return re(y,S,I,void 0,H)}function D(r){let{name:y,description:S,channelId:I,teamId:H,...G}=r;return re(y,S,I,H,G)}function j(r){let{name:y,description:S,chatId:I,...H}=r;return re(y,S,I,void 0,H)}function z(r){let{name:y,description:S,chatId:I,...H}=r;return re(y,S,I,void 0,H)}function U(r){return{[Ne]:!0,config:r}}function L(r){let{name:y,description:S,...I}=r;return ne("agent",y,S,I)}function Z(r){return r}function F(r){let{name:y,description:S,...I}=r;return ne("workspace",y,S,I)}function B(r){let{name:y,description:S,...I}=r;return ne("sandbox",y,S,I)}function W(r){let{name:y,description:S,...I}=r;return ne("skill",y,S,I)}function q(r){let{name:y,...S}=r;return ne("tool",y,void 0,S)}function K(r){let{name:y,description:S,...I}=r;return ne("policy",y,S,I)}function V(r){let{name:y,description:S,...I}=r;return ne("cron",y,S,I)}function t(r){return Boolean(r&&typeof r==="object"&&r[De])}function i(r){return Boolean(r&&typeof r==="object"&&r[Te])}function v(r){return Boolean(r&&typeof r==="object"&&r[Ne])}
|
|
5
|
+
export{p,b,o,s,l,w,f,a,n,h,e,u,c,x,d,m,_,g,T,k,E,C,R,A,M,P,O,N,D,j,z,U,L,Z,F,B,W,q,K,V,t,i,v};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var c=/^[A-Z][A-Z0-9_]*$/;function
|
|
2
|
-
export{
|
|
1
|
+
var c=/^[A-Z][A-Z0-9_]*$/;function S(e){if(!c.test(e)||e.length>64)throw Error("envPlaceholder name must match /^[A-Z][A-Z0-9_]*$/ and be at most 64 characters.");return`\${${e}}`}class r extends Error{status;body;constructor(e,t,n,s){super(`${e} ${t} failed with ${n}: ${s}`);this.name="BroodsAccountApiError",this.status=n,this.body=s}}function i(e){return typeof process<"u"?process?.env?.[e]:void 0}function a(e){return`?${new URLSearchParams({project:e.project,stage:e.stage}).toString()}`}class y{baseUrl;accountSecret;fetchImpl;constructor(e={}){let t=e.baseUrl??i("BROODS_BASE_URL")??"https://gateway.broods.app",n=e.accountSecret??i("BROODS_ACCOUNT_SECRET");if(!n)throw Error("BroodsAccountClient requires an accountSecret (or BROODS_ACCOUNT_SECRET).");let s=t.length;while(s>0&&t.charCodeAt(s-1)===47)s-=1;this.baseUrl=t.slice(0,s),this.accountSecret=n,this.fetchImpl=e.fetch??fetch}async getAccount(){let e=await this.request("GET","/v1/account");if(!e)throw new r("GET","/v1/account",404,"Account not found");return e.account}async updateAccount(e){return(await this.request("PATCH","/v1/account",e))?.account??null}async rotateSecret(){let e=await this.request("POST","/v1/account/rotate-secret");if(!e)throw new r("POST","/v1/account/rotate-secret",404,"Account not found");return e}async deleteAccount(){return await this.request("DELETE","/v1/account")??{deleted:!1}}webhookUrl(e,t){let n=[e,t].map(encodeURIComponent);return`${this.baseUrl}/webhooks/${n.join("/")}`}async listAgents(){return(await this.request("GET","/v1/agents"))?.agents??[]}async createAgent(e){let t=await this.request("POST","/v1/agents",e);if(!t)throw new r("POST","/v1/agents",404,"Not found");return t}async getAgent(e){return await this.request("GET",`/v1/agents/${encodeURIComponent(e)}`)}async updateAgent(e,t){return await this.request("PATCH",`/v1/agents/${encodeURIComponent(e)}`,t)}async deleteAgent(e){return(await this.request("DELETE",`/v1/agents/${encodeURIComponent(e)}`))?.deleted??!1}async listEnvVars(){return(await this.request("GET","/v1/env"))?.env??[]}async setEnvVar(e,t){await this.request("PUT",`/v1/env/${encodeURIComponent(e)}`,{value:t})}async deleteEnvVar(e){return(await this.request("DELETE",`/v1/env/${encodeURIComponent(e)}`))?.deleted??!1}async listCrons(){return(await this.request("GET","/v1/crons"))?.crons??[]}async createCron(e){let t=await this.request("POST","/v1/crons",e);if(!t)throw new r("POST","/v1/crons",404,"Not found");return t}async getCron(e){return await this.request("GET",`/v1/crons/${encodeURIComponent(e)}`)}async updateCron(e,t){return await this.request("PATCH",`/v1/crons/${encodeURIComponent(e)}`,t)}async deleteCron(e){return(await this.request("DELETE",`/v1/crons/${encodeURIComponent(e)}`))?.deleted??!1}async listCronRuns(e,t={}){let n=t.limit!==void 0?`?limit=${t.limit}`:"";return(await this.request("GET",`/v1/crons/${encodeURIComponent(e)}/runs${n}`))?.runs??[]}async listWorkspaces(){return(await this.request("GET","/v1/workspaces"))?.workspaces??[]}async createWorkspace(e){let t=await this.request("POST","/v1/workspaces",e);if(!t)throw new r("POST","/v1/workspaces",404,"Not found");return t}async getWorkspace(e){return await this.request("GET",`/v1/workspaces/${encodeURIComponent(e)}`)}async updateWorkspace(e,t){return await this.request("PATCH",`/v1/workspaces/${encodeURIComponent(e)}`,t)}async deleteWorkspace(e){return(await this.request("DELETE",`/v1/workspaces/${encodeURIComponent(e)}`))?.deleted??!1}async listWorkspaceFiles(e){return(await this.request("GET",`/v1/workspaces/${encodeURIComponent(e)}/files`))?.files??[]}async getWorkspaceFileUrl(e,t){let n=`?path=${encodeURIComponent(t)}`;return(await this.request("GET",`/v1/workspaces/${encodeURIComponent(e)}/files${n}`))?.url??null}async uploadWorkspaceFile(e,t){let n=`/v1/workspaces/${encodeURIComponent(e)}/files`,s=await this.request("POST",n,t);if(!s)throw new r("POST",n,404,"Workspace not found");return s.file}async renameWorkspaceFile(e,t,n){return(await this.request("PATCH",`/v1/workspaces/${encodeURIComponent(e)}/files`,{path:t,newPath:n}))?.renamed??!1}async deleteWorkspaceFile(e,t){return(await this.request("DELETE",`/v1/workspaces/${encodeURIComponent(e)}/files`,{path:t}))?.deleted??!1}async listSandboxes(){return(await this.request("GET","/v1/sandboxes"))?.sandboxes??[]}async createSandbox(e){let t=await this.request("POST","/v1/sandboxes",e);if(!t)throw new r("POST","/v1/sandboxes",404,"Not found");return t}async getSandbox(e){return await this.request("GET",`/v1/sandboxes/${encodeURIComponent(e)}`)}async updateSandbox(e,t){return await this.request("PATCH",`/v1/sandboxes/${encodeURIComponent(e)}`,t)}async deleteSandbox(e){return(await this.request("DELETE",`/v1/sandboxes/${encodeURIComponent(e)}`))?.deleted??!1}async suspendSandbox(e,t){return await this.sandboxAction(e,"suspend",{reservationKey:t})}async resumeSandbox(e,t){return await this.sandboxAction(e,"resume",{reservationKey:t})}async terminateSandbox(e,t){return await this.sandboxAction(e,"terminate",{reservationKey:t})}async snapshotSandbox(e,t,n){return await this.sandboxAction(e,"snapshot",{reservationKey:t,name:n})}async openSandboxTerminal(e,t){return await this.sandboxAction(e,"terminal",{reservationKey:t})}async listTools(e){let t=`/v1/tools${a(e)}`,n=await this.request("GET",t);if(!n)throw new r("GET",t,404,"Not found");return n.tools??[]}async createTool(e,t){let n=`/v1/tools${a(e)}`,s=await this.request("POST",n,t);if(!s)throw new r("POST",n,404,"Not found");return s}async getTool(e){return await this.request("GET",`/v1/tools/${encodeURIComponent(e)}`)}async updateTool(e,t){return await this.request("PATCH",`/v1/tools/${encodeURIComponent(e)}`,t)}async deleteTool(e){return(await this.request("DELETE",`/v1/tools/${encodeURIComponent(e)}`))?.deleted??!1}async listPolicies(){return(await this.request("GET","/v1/policies"))?.policies??[]}async createPolicy(e){let t=await this.request("POST","/v1/policies",e);if(!t)throw new r("POST","/v1/policies",404,"Not found");return t}async getPolicy(e){return await this.request("GET",`/v1/policies/${encodeURIComponent(e)}`)}async updatePolicy(e,t){return await this.request("PATCH",`/v1/policies/${encodeURIComponent(e)}`,t)}async deletePolicy(e){return(await this.request("DELETE",`/v1/policies/${encodeURIComponent(e)}`))?.deleted??!1}async listChannels(){return(await this.request("GET","/v1/channels"))?.channels??[]}async createChannel(e){let t=await this.request("POST","/v1/channels",e);if(!t)throw new r("POST","/v1/channels",404,"Not found");return t}async getChannel(e){return await this.request("GET",`/v1/channels/${encodeURIComponent(e)}`)}async updateChannel(e,t){return await this.request("PATCH",`/v1/channels/${encodeURIComponent(e)}`,t)}async deleteChannel(e){return(await this.request("DELETE",`/v1/channels/${encodeURIComponent(e)}`))?.deleted??!1}async listSkills(){return(await this.request("GET","/v1/skills"))?.skills??[]}async createSkill(e){let t=await this.request("POST","/v1/skills",e);if(!t)throw new r("POST","/v1/skills",404,"Not found");return t}async getSkill(e){return await this.request("GET",`/v1/skills/${encodeURIComponent(e)}`)}async uploadSkill(e,t){let n=`/v1/skills/${encodeURIComponent(e)}`,s=await this.request("PUT",n,t);if(!s)throw new r("PUT",n,404,"Skill not found");return s}async deleteSkill(e){return(await this.request("DELETE",`/v1/skills/${encodeURIComponent(e)}`))?.deleted??!1}async sandboxAction(e,t,n){let s=`/v1/sandboxes/${encodeURIComponent(e)}/${t}`,o=await this.request("POST",s,n);if(!o)throw new r("POST",s,404,"Sandbox not found");return o}async request(e,t,n){let s=await this.fetchImpl(`${this.baseUrl}${t}`,{method:e,headers:{Authorization:`Bearer ${this.accountSecret}`,...n!==void 0?{"Content-Type":"application/json"}:{}},...n!==void 0?{body:JSON.stringify(n)}:{}});if(s.status===404)return null;if(!s.ok)throw new r(e,t,s.status,await s.text());return await s.json()}}
|
|
2
|
+
export{S,r,y};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var d=Object.defineProperty;var e=(a)=>a;function f(a,b){this[a]=e.bind(null,b)}var
|
|
2
|
-
export{
|
|
1
|
+
var d=Object.defineProperty;var e=(a)=>a;function f(a,b){this[a]=e.bind(null,b)}var I=(a,b)=>{for(var c in b)d(a,c,{get:b[c],enumerable:!0,configurable:!0,set:f.bind(b,c)})};
|
|
2
|
+
export{I};
|