@cursor/sdk 1.0.17 → 1.0.18
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/cjs/429.index.js +1 -0
- package/dist/cjs/642.index.js +1 -1
- package/dist/cjs/745.index.js +8 -0
- package/dist/cjs/745.index.js.LICENSE.txt +30 -0
- package/dist/cjs/agent.d.ts +2 -10
- package/dist/cjs/agent.d.ts.map +1 -1
- package/dist/cjs/analytics.d.ts +6 -0
- package/dist/cjs/analytics.d.ts.map +1 -1
- package/dist/cjs/cloud-agent.d.ts.map +1 -1
- package/dist/cjs/cloud-api-client.d.ts +1 -0
- package/dist/cjs/cloud-api-client.d.ts.map +1 -1
- package/dist/cjs/custom-tools.d.ts +29 -0
- package/dist/cjs/custom-tools.d.ts.map +1 -0
- package/dist/cjs/errors.d.ts +11 -1
- package/dist/cjs/errors.d.ts.map +1 -1
- package/dist/cjs/executor-types.d.ts +2 -1
- package/dist/cjs/executor-types.d.ts.map +1 -1
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -7
- package/dist/cjs/index.js.LICENSE.txt +0 -31
- package/dist/cjs/local-executor.d.ts +2 -0
- package/dist/cjs/local-executor.d.ts.map +1 -1
- package/dist/cjs/options.d.ts +55 -0
- package/dist/cjs/options.d.ts.map +1 -1
- package/dist/cjs/platform.d.ts +2 -0
- package/dist/cjs/platform.d.ts.map +1 -1
- package/dist/cjs/public-api.d.ts +1 -1
- package/dist/cjs/public-api.d.ts.map +1 -1
- package/dist/cjs/run-store-public-types.d.ts +6 -1
- package/dist/cjs/run-store-public-types.d.ts.map +1 -1
- package/dist/cjs/run.d.ts +2 -0
- package/dist/cjs/run.d.ts.map +1 -1
- package/dist/cjs/sdk-statsig.d.ts +5 -1
- package/dist/cjs/sdk-statsig.d.ts.map +1 -1
- package/dist/cjs/store/local-agent-record-conversion.d.ts.map +1 -1
- package/dist/cjs/store/local-agent-store.d.ts +1 -0
- package/dist/cjs/store/local-agent-store.d.ts.map +1 -1
- package/dist/esm/429.index.js +1 -0
- package/dist/esm/642.index.js +1 -1
- package/dist/esm/745.index.js +8 -0
- package/dist/esm/745.index.js.LICENSE.txt +30 -0
- package/dist/esm/agent.d.ts +2 -10
- package/dist/esm/agent.d.ts.map +1 -1
- package/dist/esm/analytics.d.ts +6 -0
- package/dist/esm/analytics.d.ts.map +1 -1
- package/dist/esm/cloud-agent.d.ts.map +1 -1
- package/dist/esm/cloud-api-client.d.ts +1 -0
- package/dist/esm/cloud-api-client.d.ts.map +1 -1
- package/dist/esm/custom-tools.d.ts +29 -0
- package/dist/esm/custom-tools.d.ts.map +1 -0
- package/dist/esm/errors.d.ts +11 -1
- package/dist/esm/errors.d.ts.map +1 -1
- package/dist/esm/executor-types.d.ts +2 -1
- package/dist/esm/executor-types.d.ts.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -7
- package/dist/esm/index.js.LICENSE.txt +0 -31
- package/dist/esm/local-executor.d.ts +2 -0
- package/dist/esm/local-executor.d.ts.map +1 -1
- package/dist/esm/options.d.ts +55 -0
- package/dist/esm/options.d.ts.map +1 -1
- package/dist/esm/platform.d.ts +2 -0
- package/dist/esm/platform.d.ts.map +1 -1
- package/dist/esm/public-api.d.ts +1 -1
- package/dist/esm/public-api.d.ts.map +1 -1
- package/dist/esm/run-store-public-types.d.ts +6 -1
- package/dist/esm/run-store-public-types.d.ts.map +1 -1
- package/dist/esm/run.d.ts +2 -0
- package/dist/esm/run.d.ts.map +1 -1
- package/dist/esm/sdk-statsig.d.ts +5 -1
- package/dist/esm/sdk-statsig.d.ts.map +1 -1
- package/dist/esm/store/local-agent-record-conversion.d.ts.map +1 -1
- package/dist/esm/store/local-agent-store.d.ts +1 -0
- package/dist/esm/store/local-agent-store.d.ts.map +1 -1
- package/package.json +11 -18
package/dist/cjs/642.index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.id=642,exports.ids=[642],exports.modules={"./src/agent/cloud-agent.ts"(t,e,i){i.r(e),i.d(e,{archiveCloudAgent:()=>K,cancelCloudRun:()=>x,createCloudAgent:()=>O,deleteCloudAgent:()=>U,getCloudAgent:()=>E,getCloudMe:()=>T,getCloudRun:()=>k,listCloudAgents:()=>M,listCloudModels:()=>$,listCloudRepositories:()=>L,listCloudRuns:()=>N,resumeCloudAgent:()=>j,unarchiveCloudAgent:()=>P,validateCloudModelAvailability:()=>A});var n=i("../cursor-sdk-local-runtime/dist/run-store/index.js"),s=i("./src/agent/analytics.ts"),o=i("./src/agent/cloud-api-client.ts"),r=i("./src/agent/errors.ts");function a(t){if(void 0===t)return;const e=[];for(const[i,n]of Object.entries(t))if("command"in n){if(void 0!==n.cwd)throw new r.j1(`Cloud MCP server "${i}" cannot include cwd.`);e.push(Object.assign({name:i},n))}else e.push(Object.assign({name:i},n));return e.length>0?e:void 0}var d=i("./src/agent/run-interaction-accumulator.ts"),u=i("./src/agent/subagent-conversion.ts"),l=i("./src/agent/tool-call-utils.ts"),c=i("./src/agent/types/delta-types.ts"),h=function(t,e,i,n){return new(i||(i=Promise))((function(s,o){function r(t){try{d(n.next(t))}catch(t){o(t)}}function a(t){try{d(n.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}d((n=n.apply(t,e||[])).next())}))},v=function(t){return this instanceof v?(this.v=t,this):new v(t)};function f(t){if(""===t)throw new r.j1("API key is required for cloud operations. Caller passed an empty apiKey explicitly; refusing to fall back to CURSOR_API_KEY.",{isRetryable:!1,code:"unauthenticated"});const e=null!=t?t:process.env.CURSOR_API_KEY;if(!e)throw new r.j1("API key is required for cloud operations. Set CURSOR_API_KEY or pass apiKey.",{isRetryable:!1,code:"unauthenticated"});return e}const m=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function g(t){if(!t.startsWith("bc-")||!m.test(t.slice(3)))throw new r.j1("Agent ID must be in the format 'bc-<uuid>'",{isRetryable:!1})}function y(t){if(!t.startsWith("run-")||!m.test(t.slice(4)))throw new r.j1("Run ID must be in the format 'run-<uuid>'",{isRetryable:!1})}function p(t){switch(t){case"CREATING":case"RUNNING":return"running";case"FINISHED":return"finished";case"CANCELLED":return"cancelled";default:return"error"}}function w(t){return"running"===t||"completed"===t||"error"===t}const b=new Set(["assistant","thinking","tool_call"]);class _{constructor(){this.queue=[],this.waiters=[],this.closed=!1}push(t){if(this.closed)return;const e=this.waiters.shift();if(!e)return this.queue.length>=8192?(this.overflow=new r.LF("Cloud agent message buffer overflow; consumer is too slow",{code:"stream_buffer_overflow",errorName:"CursorSdkError"}),void(this.closed=!0)):void this.queue.push(t);e({value:t,done:!1})}close(){var t;if(!this.closed)for(this.closed=!0;this.waiters.length>0;)null===(t=this.waiters.shift())||void 0===t||t({value:void 0,done:!0})}stream(){return function(t,e,i){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,s=i.apply(t,e||[]),o=[];return n=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),r("next"),r("throw"),r("return",(function(t){return function(e){return Promise.resolve(e).then(t,u)}})),n[Symbol.asyncIterator]=function(){return this},n;function r(t,e){s[t]&&(n[t]=function(e){return new Promise((function(i,n){o.push([t,e,i,n])>1||a(t,e)}))},e&&(n[t]=e(n[t])))}function a(t,e){try{(i=s[t](e)).value instanceof v?Promise.resolve(i.value.v).then(d,u):l(o[0][2],i)}catch(t){l(o[0][3],t)}var i}function d(t){a("next",t)}function u(t){a("throw",t)}function l(t,e){t(e),o.shift(),o.length&&a(o[0][0],o[0][1])}}(this,arguments,(function*(){for(;;){const t=this.queue.shift();if(t){yield yield v(t);continue}if(this.overflow)throw this.overflow;if(this.closed)return yield v(void 0);const e=yield v(new Promise((t=>{this.waiters.push(t)})));if(e.done)return yield v(void 0);yield yield v(e.value)}}))}}const I=new Set(["unauthorized","forbidden","not_found"]);function S(t,e){return h(this,void 0,void 0,(function*(){t<=0||(null==e?void 0:e.aborted)||(yield new Promise((i=>{const n=setTimeout((()=>{null==e||e.removeEventListener("abort",s),i()}),t),s=()=>{clearTimeout(n),i()};null==e||e.addEventListener("abort",s,{once:!0})})))}))}class R{constructor(t,e,i,n){this.client=t,this.buffer=new _,this.listeners=new Set,this.streamStarted=!1,this.emittedLegacyFrameIds=new Set,this.id=e.id,this.agentId=e.agentId,this._status=p(e.status),this.createdAt=Date.parse(e.createdAt);const s=(0,o.O)(e);this._result=s.result,this._durationMs=s.durationMs,this._git=s.git,this._model=n,this.sendOptions=i}get status(){return this._status}get result(){return this._result}get durationMs(){return this._durationMs}get git(){return this._git}get model(){return this._model}supports(t){return"stream"===t||"wait"===t||"cancel"===t||"conversation"===t}unsupportedReason(t){if(!this.supports(t))return`Unknown run operation "${t}"`}stream(){try{return this.ensureStreamStarted(),this.buffer.stream()}catch(t){throw(0,r.Nt)(t,{operation:"run.stream"})}}conversation(){return h(this,void 0,void 0,(function*(){var t,e;try{this.ensureStreamStarted();try{yield this.streamPromise}catch(t){}return null!==(e=null===(t=this.accumulator)||void 0===t?void 0:t.conversation())&&void 0!==e?e:[]}catch(t){throw(0,r.Nt)(t,{operation:"run.conversation"})}}))}wait(){return h(this,void 0,void 0,(function*(){try{if("running"!==this._status)return this.buildResult();this.ensureStreamStarted();try{yield this.streamPromise}catch(t){"running"===this._status&&this.setStatus("error")}return this.buildResult()}catch(t){throw(0,r.Nt)(t,{operation:"run.wait"})}}))}cancel(){return h(this,void 0,void 0,(function*(){var t;try{if("cancelled"===this._status)return;yield this.client.cancelRun({agentId:this.agentId,runId:this.id}),null===(t=this.abortController)||void 0===t||t.abort(),this.setStatus("cancelled")}catch(t){throw(0,r.Nt)(t,{operation:"run.cancel"})}}))}onDidChangeStatus(t){return this.listeners.add(t),()=>this.listeners.delete(t)}abortClientStream(){var t;null===(t=this.abortController)||void 0===t||t.abort()}disposeClientStream(){return h(this,void 0,void 0,(function*(){this.abortClientStream(),void 0!==this.streamPromise&&(yield function(t){return h(this,void 0,void 0,(function*(){let e;try{yield Promise.race([t.catch((()=>{})),new Promise((t=>{var i;e=setTimeout(t,2e3),null===(i=e.unref)||void 0===i||i.call(e)}))])}finally{void 0!==e&&clearTimeout(e)}}))}(this.streamPromise))}))}ensureStreamStarted(){var t,e;if(this.streamStarted)return;this.streamStarted=!0,this.abortController=new AbortController;const i=new d.e4({onDelta:null===(t=this.sendOptions)||void 0===t?void 0:t.onDelta,onStep:null===(e=this.sendOptions)||void 0===e?void 0:e.onStep});this.accumulator=i,this.streamPromise=this.runStreamLoop(i,this.abortController.signal),this.streamPromise.catch((()=>{}))}runStreamLoop(t,e){return h(this,void 0,void 0,(function*(){let i=0;const n=Date.now()+72e5;try{do{const o=yield this.runOneStreamAttempt(t,e);if(e.aborted)break;if("received-result"===o)break;if(yield this.refetchAndSync(),e.aborted||"running"!==this._status)break;if(Date.now()>=n)break;if(i>=6){yield this.pollRunUntilTerminal(e,n);break}const r=Math.min((s=i,Math.min(3e4,1e3*Math.pow(2,s))),Math.max(0,n-Date.now()));i++,yield S(r,e)}while("running"===this._status&&!e.aborted);"running"===this._status&&Date.now()>=n&&this.setStatus("error"),"finished"===this._status&&(yield t.flushPendingStep())}finally{this.buffer.close()}var s}))}runOneStreamAttempt(t,e){return h(this,void 0,void 0,(function*(){const i=this.lastEventId;let n=!1;try{const i=yield this.client.streamRun(Object.assign({agentId:this.agentId,runId:this.id,signal:e},void 0!==this.lastEventId?{lastEventId:this.lastEventId}:{}));yield function(t,e,i,n,s){return h(this,void 0,void 0,(function*(){var a,d,u,h,v,f,m,g;const y=t.body.getReader(),_=new TextDecoder;let S="";try{for(;;){if(null==s?void 0:s.aborted)return;const{value:t,done:R}=yield y.read();if(R)break;S+=_.decode(t,{stream:!0});let C=S.indexOf("\n\n");for(;-1!==C;){const t=S.slice(0,C);S=S.slice(C+2),C=S.indexOf("\n\n");const s=t.split("\n");let _,R;const O=[];for(const t of s)t.startsWith("id: ")?R=t.slice(4).trim():t.startsWith("event: ")?_=t.slice(7).trim():t.startsWith("data: ")&&O.push(t.slice(6));if(void 0!==R&&R.length>0&&(void 0===_||!b.has(_))&&(null===(a=n.onEventId)||void 0===a||a.call(n,R)),"done"===_)return void(yield y.cancel());if(0===O.length)continue;const A=O.join("\n");let j;try{j=JSON.parse(A)}catch(t){throw new r.Dr(`Malformed SSE event: ${A}`,{isRetryable:!0})}if(_&&(!b.has(_)||void 0===R||!1!==(null===(d=n.shouldEmitLegacyFrame)||void 0===d?void 0:d.call(n,R))))switch(_){case"assistant":{const t=(0,l.u)(j)?j:{};n.onMessage({type:"assistant",agent_id:e,run_id:i,message:{role:"assistant",content:[{type:"text",text:null!==(u=t.text)&&void 0!==u?u:""}]}});break}case"thinking":{const t=(0,l.u)(j)?j:{};n.onMessage({type:"thinking",agent_id:e,run_id:i,text:null!==(h=t.text)&&void 0!==h?h:""});break}case"tool_call":{const t=(0,l.u)(j)?j:{},s=(0,l.u)(t.data)?t.data:t,o=w(s.status)?s.status:"running",r="string"==typeof s.callId?s.callId:"",a="string"==typeof s.name?s.name:"unknown";n.onMessage(Object.assign(Object.assign(Object.assign({type:"tool_call",agent_id:e,run_id:i,call_id:r,name:a,status:o},"args"in s?{args:s.args}:{}),"result"in s?{result:s.result}:{}),(0,l.D)(s.truncated)?{truncated:s.truncated}:{}));break}case"interaction_update":{if(void 0===n.onInteractionUpdate)break;const t=c.Zs.safeParse(j);if(!t.success)break;yield n.onInteractionUpdate(t.data);break}case"status":{const t=((0,l.u)(j)?j:{}).status;t&&(null===(v=n.onStatusChange)||void 0===v||v.call(n,p(t)),n.onMessage({type:"status",agent_id:e,run_id:i,status:t}));break}case"result":if((0,l.u)(j)){const t=j,e=Object.assign(Object.assign({},t),"string"==typeof t.text&&void 0===t.result?{result:t.text}:{});null===(f=n.onResult)||void 0===f||f.call(n,(0,o.O)(e))}return void(yield y.cancel());case"heartbeat":break;case"error":{const t=(0,l.u)(j)?j:{},e=null!==(m=t.code)&&void 0!==m?m:"UNKNOWN",i=null!==(g=t.message)&&void 0!==g?g:"Unknown error";if(I.has(e))throw new r.j1(`[${e}] ${i}`,{code:e,isRetryable:!1});throw new r.c$(`[${e}] ${i}`,{code:e,isRetryable:!1})}}}}}catch(t){if((null==s?void 0:s.aborted)||"object"==typeof t&&null!==t&&"name"in t&&"AbortError"===t.name)return;throw t}finally{try{yield y.cancel()}catch(t){}}}))}(i,this.agentId,this.id,{onMessage:t=>this.buffer.push(t),onResult:t=>{var e;this._result=t.result,this._durationMs=t.durationMs,this._git=t.git,this.setStatus(p(null!==(e=t.status)&&void 0!==e?e:"FINISHED")),n=!0},onStatusChange:t=>{"running"===t&&this.setStatus(t)},onInteractionUpdate:e=>t.apply(e),onEventId:t=>{this.lastEventId=t,this.emittedLegacyFrameIds.clear()},shouldEmitLegacyFrame:t=>!this.emittedLegacyFrameIds.has(t)&&(this.emittedLegacyFrameIds.add(t),!0)},e)}catch(t){if(function(t){return t instanceof Error&&t.message.startsWith("[invalid_last_event_id]")}(t))this.lastEventId===i&&(this.lastEventId=void 0);else if(function(t){if(t instanceof r.v3||t instanceof r.j1)return!0;if(t instanceof Error){const e=/^\[([a-z_]+)\]/.exec(t.message);if(null!==e&&I.has(e[1]))return!0}return!1}(t))throw"running"===this._status&&this.setStatus("error"),t}return n?"received-result":"stream-dropped"}))}pollRunUntilTerminal(t,e){return h(this,void 0,void 0,(function*(){for(;"running"===this._status&&!t.aborted;){const i=e-Date.now();if(i<=0)return void this.setStatus("error");if(yield S(Math.min(15e3,i),t),t.aborted)return;yield this.refetchAndSync()}}))}setStatus(t){if(this._status!==t){this._status=t;for(const e of this.listeners)e(t)}}refetchAndSync(){return h(this,void 0,void 0,(function*(){let t;try{t=yield this.client.getRun({agentId:this.agentId,runId:this.id})}catch(t){if(t instanceof r.v3||t instanceof r.j1)throw"running"===this._status&&this.setStatus("error"),t;return}const e=(0,o.O)(t);void 0!==e.result&&(this._result=e.result),void 0!==e.durationMs&&(this._durationMs=e.durationMs),void 0!==e.git&&(this._git=e.git),"running"===this._status&&this.setStatus(p(t.status))}))}buildResult(){const t="running"===this._status?"error":this._status;return Object.assign(Object.assign(Object.assign(Object.assign({id:this.id,status:t},void 0!==this._result?{result:this._result}:{}),void 0!==this._model?{model:this._model}:{}),void 0!==this._durationMs?{durationMs:this._durationMs}:{}),void 0!==this._git?{git:this._git}:{})}}class C{constructor(t,e,i,n){this.client=e,this.options=i,this.activeRuns=new Set,this.agentId=t,this.serverCreated=n,this._model=i.model}get model(){return this._model}send(t,e){return h(this,void 0,void 0,(function*(){var i,n,o,d,l,c,h,v,f,m,g,y,p,w,b,_,I,S,C;try{const O=function(t){var e;return"string"==typeof t?{text:t}:{text:t.text,images:null===(e=t.images)||void 0===e?void 0:e.map((t=>"url"in t?{url:t.url,dimension:t.dimension}:{data:t.data,mimeType:t.mimeType,dimension:t.dimension}))}}(t),A=!this.serverCreated,j=null!==(i=null==e?void 0:e.mcpServers)&&void 0!==i?i:this.options.mcpServers,M=null!==(n=null==e?void 0:e.model)&&void 0!==n?n:this._model,N=void 0!==(null==e?void 0:e.mode)?e.mode:A?this.options.mode:void 0,k=void 0!==(null==e?void 0:e.onStep)||void 0!==(null==e?void 0:e.onDelta)?Object.assign(Object.assign({},void 0!==e.onStep?{onStep:e.onStep}:{}),void 0!==e.onDelta?{onDelta:e.onDelta}:{}):void 0;let x;if(A){const t=(0,u.SB)(this.options.agents),i=void 0!==(null===(o=this.options.cloud)||void 0===o?void 0:o.envVars),n=yield this.client.createAgent(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},i?{}:{agentId:this.agentId}),{prompt:O}),void 0!==M?{model:M}:{}),void 0!==this.options.name?{name:this.options.name}:{}),{mcpServers:a(j)}),void 0!==t?{customSubagents:t}:{}),{env:null===(d=this.options.cloud)||void 0===d?void 0:d.env,envVars:null===(l=this.options.cloud)||void 0===l?void 0:l.envVars,repos:null===(c=this.options.cloud)||void 0===c?void 0:c.repos,workOnCurrentBranch:null===(h=this.options.cloud)||void 0===h?void 0:h.workOnCurrentBranch,autoCreatePR:null===(v=this.options.cloud)||void 0===v?void 0:v.autoCreatePR,skipReviewerRequest:null===(f=this.options.cloud)||void 0===f?void 0:f.skipReviewerRequest}),void 0!==N?{mode:N}:{}),{idempotencyKey:null!==(m=null==e?void 0:e.idempotencyKey)&&void 0!==m?m:this.options.idempotencyKey});if(i)this.agentId=n.agent.id;else if(n.agent.id!==this.agentId)throw new r.c$(`Server returned mismatched agent id "${n.agent.id}"; expected "${this.agentId}". This indicates a backend bug.`,{isRetryable:!1});this.serverCreated=!0,x=new R(this.client,n.run,k,M)}else{const t=yield this.client.createRun(this.agentId,Object.assign(Object.assign({prompt:O,mcpServers:a(j)},void 0!==(null==e?void 0:e.model)?{model:e.model}:{}),void 0!==N?{mode:N}:{}),{idempotencyKey:null==e?void 0:e.idempotencyKey});x=new R(this.client,t.run,k,M)}void 0!==(null==e?void 0:e.model)&&(this._model=e.model);const D=null!==(p=null===(y=null===(g=this.options.cloud)||void 0===g?void 0:g.env)||void 0===y?void 0:y.type)&&void 0!==p?p:"cloud",E=null==M?void 0:M.params;(0,s.Zn)(this.options.apiKey,Object.assign(Object.assign({agent_id:this.agentId,run_id:x.id,runtime:D,model:null!==(w=null==M?void 0:M.id)&&void 0!==w?w:"default"},E&&E.length>0?{model_params:JSON.stringify(E)}:{}),{prompt_length:O.text.length,has_images:(null!==(_=null===(b=O.images)||void 0===b?void 0:b.length)&&void 0!==_?_:0)>0,is_resume:!A,mcp_server_count:Object.keys(null!=j?j:{}).length,cloud_repo_count:null===(S=null===(I=this.options.cloud)||void 0===I?void 0:I.repos)||void 0===S?void 0:S.length,cloud_auto_create_pr:null===(C=this.options.cloud)||void 0===C?void 0:C.autoCreatePR})),this.activeRuns.add(x);const K=this.options.apiKey,P=this.agentId,U=x.id;return x.wait().then((t=>{(0,s.G5)(K,{agent_id:P,run_id:U,runtime:D,end_reason:"finished"===t.status?"success":"cancelled"===t.status?"abort":"error"})})).finally((()=>{this.activeRuns.delete(x)})),x.ensureStreamStarted(),x}catch(t){throw(0,r.Nt)(t,{operation:"agent.send"})}}))}close(){for(const t of this.activeRuns)t.abortClientStream();(0,s.rd)()}reload(){return h(this,void 0,void 0,(function*(){}))}[Symbol.asyncDispose](){return h(this,void 0,void 0,(function*(){yield Promise.allSettled(Array.from(this.activeRuns,(t=>t.disposeClientStream()))),yield(0,s.rd)()}))}listArtifacts(){return h(this,void 0,void 0,(function*(){try{return this.serverCreated?(yield this.client.listArtifacts(this.agentId)).items.map((t=>({path:t.path,sizeBytes:t.sizeBytes,updatedAt:t.updatedAt}))):[]}catch(t){throw(0,r.Nt)(t,{operation:"agent.listArtifacts"})}}))}downloadArtifact(t){return h(this,void 0,void 0,(function*(){try{if(!this.serverCreated)throw new r.j1("Agent has not been created yet; call send() first.",{isRetryable:!1});const{url:e}=yield this.client.getArtifactDownloadUrl({agentId:this.agentId,path:t});let i;try{i=yield fetch(e)}catch(t){throw new r.Dr("Failed to download artifact",{cause:t,isRetryable:!0})}if(!i.ok)throw new r.Dr(`Failed to download artifact: ${i.status}`,{status:i.status,isRetryable:i.status>=500});return Buffer.from(yield i.arrayBuffer())}catch(t){throw(0,r.Nt)(t,{operation:"agent.downloadArtifact"})}}))}}function O(t){var e,i;const s=f(t.apiKey);if(void 0!==t.agentId&&void 0!==(null===(e=t.cloud)||void 0===e?void 0:e.envVars))throw new r.j1("cloud.envVars cannot be combined with agentId; omit agentId so the server can mint an agent id.",{isRetryable:!1});const a=new o.N(s),d=null!==(i=t.agentId)&&void 0!==i?i:(0,n.M2)();return new C(d,a,t,!1)}function A(t){return h(this,arguments,void 0,(function*({apiKey:t,model:e}){const i="string"==typeof e?e.trim():e.id.trim();if(0===i.length)throw new r.j1("Model id is required. Pass a non-empty `model.id` or `model: '<model-id>'`.",{isRetryable:!1,code:"invalid_model"});let n,s;try{n=f(t)}catch(t){if(t instanceof r.j1)return;throw t}try{s=(yield new o.N(n).listModels()).items}catch(t){if(t instanceof r.Dr||t instanceof r.v3||t instanceof r.OE)return;throw t}const a=s.some((t=>{var e;return t.id===i||!0===(null===(e=t.aliases)||void 0===e?void 0:e.includes(i))}));if(!a)throw new r.j1(`Model '${i}' is not available or invalid. Call Cursor.models.list() to see valid model ids.`,{isRetryable:!1,code:"invalid_model"})}))}function j(t,e){const i=f(e.apiKey),n=new o.N(i);return new C(t,n,Object.assign({},e),!0)}function M(t){return h(this,void 0,void 0,(function*(){const e=f(t.apiKey),i=new o.N(e),n=yield i.listAgents({limit:t.limit,cursor:t.cursor,prUrl:t.prUrl,includeArchived:t.includeArchived});return{items:n.items.map(D),nextCursor:n.nextCursor}}))}function N(t,e){return h(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new o.N(i),s=yield n.listRuns(t,{limit:e.limit,cursor:e.cursor});return{items:s.items.map((t=>new R(n,t))),nextCursor:s.nextCursor}}))}function k(t,e){return h(this,void 0,void 0,(function*(){y(t),g(e.agentId);const i=f(e.apiKey),n=new o.N(i),s=yield n.getRun({agentId:e.agentId,runId:t});return new R(n,s)}))}function x(t,e){return h(this,void 0,void 0,(function*(){y(t),g(e.agentId);const i=f(e.apiKey),n=new o.N(i);yield n.cancelRun({agentId:e.agentId,runId:t})}))}function D(t){var e,i,n;return{agentId:t.id,name:null!==(e=t.name)&&void 0!==e?e:"",summary:null!==(i=t.name)&&void 0!==i?i:"",lastModified:new Date(t.updatedAt).getTime(),createdAt:new Date(t.createdAt).getTime(),archived:"ARCHIVED"===t.status,runtime:"cloud",env:t.env,repos:null===(n=t.repos)||void 0===n?void 0:n.map((t=>t.url))}}function E(t,e){return h(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new o.N(i);return D(yield n.getAgent(t))}))}function K(t,e){return h(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new o.N(i);yield n.archiveAgent(t)}))}function P(t,e){return h(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new o.N(i);yield n.unarchiveAgent(t)}))}function U(t,e){return h(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new o.N(i);yield n.deleteAgent(t)}))}function T(t){return h(this,void 0,void 0,(function*(){const e=f(t.apiKey);return new o.N(e).getMe()}))}function $(t){return h(this,void 0,void 0,(function*(){const e=f(t.apiKey),i=new o.N(e);return(yield i.listModels()).items}))}function L(t){return h(this,void 0,void 0,(function*(){const e=f(t.apiKey),i=new o.N(e);return(yield i.listRepositories()).items}))}}};
|
|
1
|
+
"use strict";exports.id=642,exports.ids=[642],exports.modules={"./src/agent/cloud-agent.ts"(t,e,i){i.r(e),i.d(e,{archiveCloudAgent:()=>K,cancelCloudRun:()=>x,createCloudAgent:()=>O,deleteCloudAgent:()=>q,getCloudAgent:()=>E,getCloudMe:()=>T,getCloudRun:()=>k,listCloudAgents:()=>M,listCloudModels:()=>U,listCloudRepositories:()=>L,listCloudRuns:()=>N,resumeCloudAgent:()=>A,unarchiveCloudAgent:()=>P,validateCloudModelAvailability:()=>j});var n=i("../cursor-sdk-local-runtime/dist/run-store/index.js"),s=i("./src/agent/analytics.ts"),o=i("./src/agent/cloud-api-client.ts"),r=i("./src/agent/errors.ts");function a(t){if(void 0===t)return;const e=[];for(const[i,n]of Object.entries(t))if("command"in n){if(void 0!==n.cwd)throw new r.j1(`Cloud MCP server "${i}" cannot include cwd.`);e.push(Object.assign({name:i},n))}else e.push(Object.assign({name:i},n));return e.length>0?e:void 0}var d=i("./src/agent/run-interaction-accumulator.ts"),u=i("./src/agent/subagent-conversion.ts"),l=i("./src/agent/tool-call-utils.ts"),c=i("./src/agent/types/delta-types.ts"),h=function(t,e,i,n){return new(i||(i=Promise))((function(s,o){function r(t){try{d(n.next(t))}catch(t){o(t)}}function a(t){try{d(n.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}d((n=n.apply(t,e||[])).next())}))},v=function(t){return this instanceof v?(this.v=t,this):new v(t)};function f(t){if(""===t)throw new r.j1("API key is required for cloud operations. Caller passed an empty apiKey explicitly; refusing to fall back to CURSOR_API_KEY.",{isRetryable:!1,code:"unauthenticated"});const e=null!=t?t:process.env.CURSOR_API_KEY;if(!e)throw new r.j1("API key is required for cloud operations. Set CURSOR_API_KEY or pass apiKey.",{isRetryable:!1,code:"unauthenticated"});return e}const m=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function g(t){if(!t.startsWith("bc-")||!m.test(t.slice(3)))throw new r.j1("Agent ID must be in the format 'bc-<uuid>'",{isRetryable:!1})}function y(t){if(!t.startsWith("run-")||!m.test(t.slice(4)))throw new r.j1("Run ID must be in the format 'run-<uuid>'",{isRetryable:!1})}function p(t){switch(t){case"CREATING":case"RUNNING":return"running";case"FINISHED":return"finished";case"CANCELLED":return"cancelled";default:return"error"}}function w(t){return"running"===t||"completed"===t||"error"===t}const b=new Set(["assistant","thinking","tool_call"]);class _{constructor(){this.queue=[],this.waiters=[],this.closed=!1}push(t){if(this.closed)return;const e=this.waiters.shift();if(!e)return this.queue.length>=8192?(this.overflow=new r.LF("Cloud agent message buffer overflow; consumer is too slow",{code:"stream_buffer_overflow",errorName:"CursorSdkError"}),void(this.closed=!0)):void this.queue.push(t);e({value:t,done:!1})}close(){var t;if(!this.closed)for(this.closed=!0;this.waiters.length>0;)null===(t=this.waiters.shift())||void 0===t||t({value:void 0,done:!0})}stream(){return function(t,e,i){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,s=i.apply(t,e||[]),o=[];return n=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),r("next"),r("throw"),r("return",(function(t){return function(e){return Promise.resolve(e).then(t,u)}})),n[Symbol.asyncIterator]=function(){return this},n;function r(t,e){s[t]&&(n[t]=function(e){return new Promise((function(i,n){o.push([t,e,i,n])>1||a(t,e)}))},e&&(n[t]=e(n[t])))}function a(t,e){try{(i=s[t](e)).value instanceof v?Promise.resolve(i.value.v).then(d,u):l(o[0][2],i)}catch(t){l(o[0][3],t)}var i}function d(t){a("next",t)}function u(t){a("throw",t)}function l(t,e){t(e),o.shift(),o.length&&a(o[0][0],o[0][1])}}(this,arguments,(function*(){for(;;){const t=this.queue.shift();if(t){yield yield v(t);continue}if(this.overflow)throw this.overflow;if(this.closed)return yield v(void 0);const e=yield v(new Promise((t=>{this.waiters.push(t)})));if(e.done)return yield v(void 0);yield yield v(e.value)}}))}}const I=new Set(["unauthorized","forbidden","not_found"]);function S(t,e){return h(this,void 0,void 0,(function*(){t<=0||(null==e?void 0:e.aborted)||(yield new Promise((i=>{const n=setTimeout((()=>{null==e||e.removeEventListener("abort",s),i()}),t),s=()=>{clearTimeout(n),i()};null==e||e.addEventListener("abort",s,{once:!0})})))}))}class R{constructor(t,e,i,n){this.client=t,this.buffer=new _,this.listeners=new Set,this.streamStarted=!1,this.emittedLegacyFrameIds=new Set,this.id=e.id,this.agentId=e.agentId,this.requestId=e.requestId,this._status=p(e.status),this.createdAt=Date.parse(e.createdAt);const s=(0,o.O)(e);this._result=s.result,this._durationMs=s.durationMs,this._git=s.git,this._model=n,this.sendOptions=i}get status(){return this._status}get result(){return this._result}get durationMs(){return this._durationMs}get git(){return this._git}get model(){return this._model}supports(t){return"stream"===t||"wait"===t||"cancel"===t||"conversation"===t}unsupportedReason(t){if(!this.supports(t))return`Unknown run operation "${t}"`}stream(){try{return this.ensureStreamStarted(),this.buffer.stream()}catch(t){throw(0,r.Nt)(t,{operation:"run.stream"})}}conversation(){return h(this,void 0,void 0,(function*(){var t,e;try{this.ensureStreamStarted();try{yield this.streamPromise}catch(t){}return null!==(e=null===(t=this.accumulator)||void 0===t?void 0:t.conversation())&&void 0!==e?e:[]}catch(t){throw(0,r.Nt)(t,{operation:"run.conversation"})}}))}wait(){return h(this,void 0,void 0,(function*(){try{if("running"!==this._status)return this.buildResult();this.ensureStreamStarted();try{yield this.streamPromise}catch(t){"running"===this._status&&this.setStatus("error")}return this.buildResult()}catch(t){throw(0,r.Nt)(t,{operation:"run.wait"})}}))}cancel(){return h(this,void 0,void 0,(function*(){var t;try{if("cancelled"===this._status)return;yield this.client.cancelRun({agentId:this.agentId,runId:this.id}),null===(t=this.abortController)||void 0===t||t.abort(),this.setStatus("cancelled")}catch(t){throw(0,r.Nt)(t,{operation:"run.cancel"})}}))}onDidChangeStatus(t){return this.listeners.add(t),()=>this.listeners.delete(t)}abortClientStream(){var t;null===(t=this.abortController)||void 0===t||t.abort()}disposeClientStream(){return h(this,void 0,void 0,(function*(){this.abortClientStream(),void 0!==this.streamPromise&&(yield function(t){return h(this,void 0,void 0,(function*(){let e;try{yield Promise.race([t.catch((()=>{})),new Promise((t=>{var i;e=setTimeout(t,2e3),null===(i=e.unref)||void 0===i||i.call(e)}))])}finally{void 0!==e&&clearTimeout(e)}}))}(this.streamPromise))}))}ensureStreamStarted(){var t,e;if(this.streamStarted)return;this.streamStarted=!0,this.abortController=new AbortController;const i=new d.e4({onDelta:null===(t=this.sendOptions)||void 0===t?void 0:t.onDelta,onStep:null===(e=this.sendOptions)||void 0===e?void 0:e.onStep});this.accumulator=i,this.streamPromise=this.runStreamLoop(i,this.abortController.signal),this.streamPromise.catch((()=>{}))}runStreamLoop(t,e){return h(this,void 0,void 0,(function*(){let i=0;const n=Date.now()+72e5;try{do{const o=yield this.runOneStreamAttempt(t,e);if(e.aborted)break;if("received-result"===o)break;if(yield this.refetchAndSync(),e.aborted||"running"!==this._status)break;if(Date.now()>=n)break;if(i>=6){yield this.pollRunUntilTerminal(e,n);break}const r=Math.min((s=i,Math.min(3e4,1e3*Math.pow(2,s))),Math.max(0,n-Date.now()));i++,yield S(r,e)}while("running"===this._status&&!e.aborted);"running"===this._status&&Date.now()>=n&&this.setStatus("error"),"finished"===this._status&&(yield t.flushPendingStep())}finally{this.buffer.close()}var s}))}runOneStreamAttempt(t,e){return h(this,void 0,void 0,(function*(){const i=this.lastEventId;let n=!1;try{const i=yield this.client.streamRun(Object.assign({agentId:this.agentId,runId:this.id,signal:e},void 0!==this.lastEventId?{lastEventId:this.lastEventId}:{}));yield function(t,e,i,n,s){return h(this,void 0,void 0,(function*(){var a,d,u,h,v,f,m,g;const y=t.body.getReader(),_=new TextDecoder;let S="";try{for(;;){if(null==s?void 0:s.aborted)return;const{value:t,done:R}=yield y.read();if(R)break;S+=_.decode(t,{stream:!0});let C=S.indexOf("\n\n");for(;-1!==C;){const t=S.slice(0,C);S=S.slice(C+2),C=S.indexOf("\n\n");const s=t.split("\n");let _,R;const O=[];for(const t of s)t.startsWith("id: ")?R=t.slice(4).trim():t.startsWith("event: ")?_=t.slice(7).trim():t.startsWith("data: ")&&O.push(t.slice(6));if(void 0!==R&&R.length>0&&(void 0===_||!b.has(_))&&(null===(a=n.onEventId)||void 0===a||a.call(n,R)),"done"===_)return void(yield y.cancel());if(0===O.length)continue;const j=O.join("\n");let A;try{A=JSON.parse(j)}catch(t){throw new r.Dr(`Malformed SSE event: ${j}`,{isRetryable:!0})}if(_&&(!b.has(_)||void 0===R||!1!==(null===(d=n.shouldEmitLegacyFrame)||void 0===d?void 0:d.call(n,R))))switch(_){case"assistant":{const t=(0,l.u)(A)?A:{};n.onMessage({type:"assistant",agent_id:e,run_id:i,message:{role:"assistant",content:[{type:"text",text:null!==(u=t.text)&&void 0!==u?u:""}]}});break}case"thinking":{const t=(0,l.u)(A)?A:{};n.onMessage({type:"thinking",agent_id:e,run_id:i,text:null!==(h=t.text)&&void 0!==h?h:""});break}case"tool_call":{const t=(0,l.u)(A)?A:{},s=(0,l.u)(t.data)?t.data:t,o=w(s.status)?s.status:"running",r="string"==typeof s.callId?s.callId:"",a="string"==typeof s.name?s.name:"unknown";n.onMessage(Object.assign(Object.assign(Object.assign({type:"tool_call",agent_id:e,run_id:i,call_id:r,name:a,status:o},"args"in s?{args:s.args}:{}),"result"in s?{result:s.result}:{}),(0,l.D)(s.truncated)?{truncated:s.truncated}:{}));break}case"interaction_update":{if(void 0===n.onInteractionUpdate)break;const t=c.Zs.safeParse(A);if(!t.success)break;yield n.onInteractionUpdate(t.data);break}case"status":{const t=((0,l.u)(A)?A:{}).status;t&&(null===(v=n.onStatusChange)||void 0===v||v.call(n,p(t)),n.onMessage({type:"status",agent_id:e,run_id:i,status:t}));break}case"result":if((0,l.u)(A)){const t=A,e=Object.assign(Object.assign({},t),"string"==typeof t.text&&void 0===t.result?{result:t.text}:{});null===(f=n.onResult)||void 0===f||f.call(n,(0,o.O)(e))}return void(yield y.cancel());case"heartbeat":break;case"error":{const t=(0,l.u)(A)?A:{},e=null!==(m=t.code)&&void 0!==m?m:"UNKNOWN",i=null!==(g=t.message)&&void 0!==g?g:"Unknown error";if(I.has(e))throw new r.j1(`[${e}] ${i}`,{code:e,isRetryable:!1});throw new r.c$(`[${e}] ${i}`,{code:e,isRetryable:!1})}}}}}catch(t){if((null==s?void 0:s.aborted)||"object"==typeof t&&null!==t&&"name"in t&&"AbortError"===t.name)return;throw t}finally{try{yield y.cancel()}catch(t){}}}))}(i,this.agentId,this.id,{onMessage:t=>this.buffer.push(t),onResult:t=>{var e;this._result=t.result,this._durationMs=t.durationMs,this._git=t.git,this.setStatus(p(null!==(e=t.status)&&void 0!==e?e:"FINISHED")),n=!0},onStatusChange:t=>{"running"===t&&this.setStatus(t)},onInteractionUpdate:e=>t.apply(e),onEventId:t=>{this.lastEventId=t,this.emittedLegacyFrameIds.clear()},shouldEmitLegacyFrame:t=>!this.emittedLegacyFrameIds.has(t)&&(this.emittedLegacyFrameIds.add(t),!0)},e)}catch(t){if(function(t){return t instanceof Error&&t.message.startsWith("[invalid_last_event_id]")}(t))this.lastEventId===i&&(this.lastEventId=void 0);else if(function(t){if(t instanceof r.v3||t instanceof r.j1)return!0;if(t instanceof Error){const e=/^\[([a-z_]+)\]/.exec(t.message);if(null!==e&&I.has(e[1]))return!0}return!1}(t))throw"running"===this._status&&this.setStatus("error"),t}return n?"received-result":"stream-dropped"}))}pollRunUntilTerminal(t,e){return h(this,void 0,void 0,(function*(){for(;"running"===this._status&&!t.aborted;){const i=e-Date.now();if(i<=0)return void this.setStatus("error");if(yield S(Math.min(15e3,i),t),t.aborted)return;yield this.refetchAndSync()}}))}setStatus(t){if(this._status!==t){this._status=t;for(const e of this.listeners)e(t)}}refetchAndSync(){return h(this,void 0,void 0,(function*(){let t;try{t=yield this.client.getRun({agentId:this.agentId,runId:this.id})}catch(t){if(t instanceof r.v3||t instanceof r.j1)throw"running"===this._status&&this.setStatus("error"),t;return}const e=(0,o.O)(t);void 0!==e.result&&(this._result=e.result),void 0!==e.durationMs&&(this._durationMs=e.durationMs),void 0!==e.git&&(this._git=e.git),"running"===this._status&&this.setStatus(p(t.status))}))}buildResult(){const t="running"===this._status?"error":this._status;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({id:this.id},void 0!==this.requestId?{requestId:this.requestId}:{}),{status:t}),void 0!==this._result?{result:this._result}:{}),void 0!==this._model?{model:this._model}:{}),void 0!==this._durationMs?{durationMs:this._durationMs}:{}),void 0!==this._git?{git:this._git}:{})}}class C{constructor(t,e,i,n){this.client=e,this.options=i,this.activeRuns=new Set,this.agentId=t,this.serverCreated=n,this._model=i.model}get model(){return this._model}send(t,e){return h(this,void 0,void 0,(function*(){var i,n,o,d,l,c,h,v,f,m,g,y,p,w,b,_,I,S,C,O;try{if(void 0!==(null===(i=null==e?void 0:e.local)||void 0===i?void 0:i.customTools))throw new r.j1("Custom local tools are only supported for local SDK agents. Create the agent with getLocalPlatformOptions() or omit local.customTools.",{isRetryable:!1});const j=function(t){var e;return"string"==typeof t?{text:t}:{text:t.text,images:null===(e=t.images)||void 0===e?void 0:e.map((t=>"url"in t?{url:t.url,dimension:t.dimension}:{data:t.data,mimeType:t.mimeType,dimension:t.dimension}))}}(t),A=!this.serverCreated,M=null!==(n=null==e?void 0:e.mcpServers)&&void 0!==n?n:this.options.mcpServers,N=null!==(o=null==e?void 0:e.model)&&void 0!==o?o:this._model,k=void 0!==(null==e?void 0:e.mode)?e.mode:A?this.options.mode:void 0,x=void 0!==(null==e?void 0:e.onStep)||void 0!==(null==e?void 0:e.onDelta)?Object.assign(Object.assign({},void 0!==e.onStep?{onStep:e.onStep}:{}),void 0!==e.onDelta?{onDelta:e.onDelta}:{}):void 0;let D;if(A){const t=(0,u.SB)(this.options.agents),i=void 0!==(null===(d=this.options.cloud)||void 0===d?void 0:d.envVars),n=yield this.client.createAgent(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},i?{}:{agentId:this.agentId}),{prompt:j}),void 0!==N?{model:N}:{}),void 0!==this.options.name?{name:this.options.name}:{}),{mcpServers:a(M)}),void 0!==t?{customSubagents:t}:{}),{env:null===(l=this.options.cloud)||void 0===l?void 0:l.env,envVars:null===(c=this.options.cloud)||void 0===c?void 0:c.envVars,repos:null===(h=this.options.cloud)||void 0===h?void 0:h.repos,workOnCurrentBranch:null===(v=this.options.cloud)||void 0===v?void 0:v.workOnCurrentBranch,autoCreatePR:null===(f=this.options.cloud)||void 0===f?void 0:f.autoCreatePR,skipReviewerRequest:null===(m=this.options.cloud)||void 0===m?void 0:m.skipReviewerRequest}),void 0!==k?{mode:k}:{}),{idempotencyKey:null!==(g=null==e?void 0:e.idempotencyKey)&&void 0!==g?g:this.options.idempotencyKey});if(i)this.agentId=n.agent.id;else if(n.agent.id!==this.agentId)throw new r.c$(`Server returned mismatched agent id "${n.agent.id}"; expected "${this.agentId}". This indicates a backend bug.`,{isRetryable:!1});this.serverCreated=!0,D=new R(this.client,n.run,x,N)}else{const t=yield this.client.createRun(this.agentId,Object.assign(Object.assign({prompt:j,mcpServers:a(M)},void 0!==(null==e?void 0:e.model)?{model:e.model}:{}),void 0!==k?{mode:k}:{}),{idempotencyKey:null==e?void 0:e.idempotencyKey});D=new R(this.client,t.run,x,N)}void 0!==(null==e?void 0:e.model)&&(this._model=e.model);const E=null!==(w=null===(p=null===(y=this.options.cloud)||void 0===y?void 0:y.env)||void 0===p?void 0:p.type)&&void 0!==w?w:"cloud",K=null==N?void 0:N.params;(0,s.Zn)(this.options.apiKey,Object.assign(Object.assign({agent_id:this.agentId,run_id:D.id,request_id:D.requestId,runtime:E,model:null!==(b=null==N?void 0:N.id)&&void 0!==b?b:"default"},K&&K.length>0?{model_params:JSON.stringify(K)}:{}),{prompt_length:j.text.length,has_images:(null!==(I=null===(_=j.images)||void 0===_?void 0:_.length)&&void 0!==I?I:0)>0,is_resume:!A,mcp_server_count:Object.keys(null!=M?M:{}).length,cloud_repo_count:null===(C=null===(S=this.options.cloud)||void 0===S?void 0:S.repos)||void 0===C?void 0:C.length,cloud_auto_create_pr:null===(O=this.options.cloud)||void 0===O?void 0:O.autoCreatePR})),this.activeRuns.add(D);const P=this.options.apiKey,q=this.agentId,T=D.id;return D.wait().then((t=>{(0,s.G5)(P,{agent_id:q,run_id:T,request_id:D.requestId,runtime:E,end_reason:"finished"===t.status?"success":"cancelled"===t.status?"abort":"error"})})).finally((()=>{this.activeRuns.delete(D)})),D.ensureStreamStarted(),D}catch(t){throw(0,r.Nt)(t,{operation:"agent.send"})}}))}close(){for(const t of this.activeRuns)t.abortClientStream();(0,s.rd)()}reload(){return h(this,void 0,void 0,(function*(){}))}[Symbol.asyncDispose](){return h(this,void 0,void 0,(function*(){yield Promise.allSettled(Array.from(this.activeRuns,(t=>t.disposeClientStream()))),yield(0,s.rd)()}))}listArtifacts(){return h(this,void 0,void 0,(function*(){try{return this.serverCreated?(yield this.client.listArtifacts(this.agentId)).items.map((t=>({path:t.path,sizeBytes:t.sizeBytes,updatedAt:t.updatedAt}))):[]}catch(t){throw(0,r.Nt)(t,{operation:"agent.listArtifacts"})}}))}downloadArtifact(t){return h(this,void 0,void 0,(function*(){try{if(!this.serverCreated)throw new r.j1("Agent has not been created yet; call send() first.",{isRetryable:!1});const{url:e}=yield this.client.getArtifactDownloadUrl({agentId:this.agentId,path:t});let i;try{i=yield fetch(e)}catch(t){throw new r.Dr("Failed to download artifact",{cause:t,isRetryable:!0})}if(!i.ok)throw new r.Dr(`Failed to download artifact: ${i.status}`,{status:i.status,isRetryable:i.status>=500});return Buffer.from(yield i.arrayBuffer())}catch(t){throw(0,r.Nt)(t,{operation:"agent.downloadArtifact"})}}))}}function O(t){var e,i;const s=f(t.apiKey);if(void 0!==t.agentId&&void 0!==(null===(e=t.cloud)||void 0===e?void 0:e.envVars))throw new r.j1("cloud.envVars cannot be combined with agentId; omit agentId so the server can mint an agent id.",{isRetryable:!1});const a=new o.N(s),d=null!==(i=t.agentId)&&void 0!==i?i:(0,n.M2)();return new C(d,a,t,!1)}function j(t){return h(this,arguments,void 0,(function*({apiKey:t,model:e}){const i="string"==typeof e?e.trim():e.id.trim();if(0===i.length)throw new r.j1("Model id is required. Pass a non-empty `model.id` or `model: '<model-id>'`.",{isRetryable:!1,code:"invalid_model"});let n,s;try{n=f(t)}catch(t){if(t instanceof r.j1)return;throw t}try{s=(yield new o.N(n).listModels()).items}catch(t){if(t instanceof r.Dr||t instanceof r.v3||t instanceof r.OE)return;throw t}const a=s.some((t=>{var e;return t.id===i||!0===(null===(e=t.aliases)||void 0===e?void 0:e.includes(i))}));if(!a)throw new r.j1(`Model '${i}' is not available or invalid. Call Cursor.models.list() to see valid model ids.`,{isRetryable:!1,code:"invalid_model"})}))}function A(t,e){const i=f(e.apiKey),n=new o.N(i);return new C(t,n,Object.assign({},e),!0)}function M(t){return h(this,void 0,void 0,(function*(){const e=f(t.apiKey),i=new o.N(e),n=yield i.listAgents({limit:t.limit,cursor:t.cursor,prUrl:t.prUrl,includeArchived:t.includeArchived});return{items:n.items.map(D),nextCursor:n.nextCursor}}))}function N(t,e){return h(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new o.N(i),s=yield n.listRuns(t,{limit:e.limit,cursor:e.cursor});return{items:s.items.map((t=>new R(n,t))),nextCursor:s.nextCursor}}))}function k(t,e){return h(this,void 0,void 0,(function*(){y(t),g(e.agentId);const i=f(e.apiKey),n=new o.N(i),s=yield n.getRun({agentId:e.agentId,runId:t});return new R(n,s)}))}function x(t,e){return h(this,void 0,void 0,(function*(){y(t),g(e.agentId);const i=f(e.apiKey),n=new o.N(i);yield n.cancelRun({agentId:e.agentId,runId:t})}))}function D(t){var e,i,n;return{agentId:t.id,name:null!==(e=t.name)&&void 0!==e?e:"",summary:null!==(i=t.name)&&void 0!==i?i:"",lastModified:new Date(t.updatedAt).getTime(),createdAt:new Date(t.createdAt).getTime(),archived:"ARCHIVED"===t.status,runtime:"cloud",env:t.env,repos:null===(n=t.repos)||void 0===n?void 0:n.map((t=>t.url))}}function E(t,e){return h(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new o.N(i);return D(yield n.getAgent(t))}))}function K(t,e){return h(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new o.N(i);yield n.archiveAgent(t)}))}function P(t,e){return h(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new o.N(i);yield n.unarchiveAgent(t)}))}function q(t,e){return h(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new o.N(i);yield n.deleteAgent(t)}))}function T(t){return h(this,void 0,void 0,(function*(){const e=f(t.apiKey);return new o.N(e).getMe()}))}function U(t){return h(this,void 0,void 0,(function*(){const e=f(t.apiKey),i=new o.N(e);return(yield i.listModels()).items}))}function L(t){return h(this,void 0,void 0,(function*(){const e=f(t.apiKey),i=new o.N(e);return(yield i.listRepositories()).items}))}}};
|