@cursor/sdk 1.0.26 → 1.0.27-beta.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/cjs/417.js +1 -0
- package/dist/cjs/642.js +1 -1
- package/dist/cjs/agent/options.d.ts +86 -1
- package/dist/cjs/agent/options.d.ts.map +1 -1
- package/dist/cjs/agent/usage-types.d.ts +12 -3
- package/dist/cjs/agent/usage-types.d.ts.map +1 -1
- package/dist/cjs/agent.d.ts +11 -5
- package/dist/cjs/agent.d.ts.map +1 -1
- package/dist/cjs/analytics.d.ts.map +1 -1
- package/dist/cjs/auth/credential-store.d.ts +56 -0
- package/dist/cjs/auth/credential-store.d.ts.map +1 -0
- package/dist/cjs/auth/login-flow.d.ts +72 -0
- package/dist/cjs/auth/login-flow.d.ts.map +1 -0
- package/dist/cjs/auth/login.d.ts +86 -0
- package/dist/cjs/auth/login.d.ts.map +1 -0
- package/dist/cjs/auth/mint-api-key.d.ts +29 -0
- package/dist/cjs/auth/mint-api-key.d.ts.map +1 -0
- package/dist/cjs/auth/open-browser.d.ts +12 -0
- package/dist/cjs/auth/open-browser.d.ts.map +1 -0
- package/dist/cjs/auth/stored-credentials.d.ts +20 -0
- package/dist/cjs/auth/stored-credentials.d.ts.map +1 -0
- package/dist/cjs/cloud-agent.d.ts +1 -3
- package/dist/cjs/cloud-agent.d.ts.map +1 -1
- package/dist/cjs/cloud-api-client.d.ts +4 -0
- package/dist/cjs/cloud-api-client.d.ts.map +1 -1
- package/dist/cjs/cloud-executor.d.ts.map +1 -1
- package/dist/cjs/executor-common.d.ts.map +1 -1
- package/dist/cjs/executor-types.d.ts +16 -0
- package/dist/cjs/executor-types.d.ts.map +1 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/local-executor.d.ts +7 -0
- package/dist/cjs/local-executor.d.ts.map +1 -1
- package/dist/cjs/native/vendored-tree-sitter.d.ts +19 -0
- package/dist/cjs/native/vendored-tree-sitter.d.ts.map +1 -0
- package/dist/cjs/options.d.ts +86 -1
- package/dist/cjs/options.d.ts.map +1 -1
- package/dist/cjs/platform-package-locator.d.ts +23 -0
- package/dist/cjs/platform-package-locator.d.ts.map +1 -0
- package/dist/cjs/platform.d.ts +9 -2
- package/dist/cjs/platform.d.ts.map +1 -1
- package/dist/cjs/public-api.d.ts +5 -1
- package/dist/cjs/public-api.d.ts.map +1 -1
- package/dist/cjs/sqlite.js +1 -1
- package/dist/cjs/stubs.d.ts +14 -2
- package/dist/cjs/stubs.d.ts.map +1 -1
- package/dist/cjs/tools-option.d.ts +31 -0
- package/dist/cjs/tools-option.d.ts.map +1 -0
- package/dist/cjs/usage-types.d.ts +12 -3
- package/dist/cjs/usage-types.d.ts.map +1 -1
- package/dist/esm/357.js +1 -1
- package/dist/esm/642.js +1 -1
- package/dist/esm/agent/options.d.ts +86 -1
- package/dist/esm/agent/options.d.ts.map +1 -1
- package/dist/esm/agent/usage-types.d.ts +12 -3
- package/dist/esm/agent/usage-types.d.ts.map +1 -1
- package/dist/esm/agent.d.ts +11 -5
- package/dist/esm/agent.d.ts.map +1 -1
- package/dist/esm/analytics.d.ts.map +1 -1
- package/dist/esm/auth/credential-store.d.ts +56 -0
- package/dist/esm/auth/credential-store.d.ts.map +1 -0
- package/dist/esm/auth/login-flow.d.ts +72 -0
- package/dist/esm/auth/login-flow.d.ts.map +1 -0
- package/dist/esm/auth/login.d.ts +86 -0
- package/dist/esm/auth/login.d.ts.map +1 -0
- package/dist/esm/auth/mint-api-key.d.ts +29 -0
- package/dist/esm/auth/mint-api-key.d.ts.map +1 -0
- package/dist/esm/auth/open-browser.d.ts +12 -0
- package/dist/esm/auth/open-browser.d.ts.map +1 -0
- package/dist/esm/auth/stored-credentials.d.ts +20 -0
- package/dist/esm/auth/stored-credentials.d.ts.map +1 -0
- package/dist/esm/cloud-agent.d.ts +1 -3
- package/dist/esm/cloud-agent.d.ts.map +1 -1
- package/dist/esm/cloud-api-client.d.ts +4 -0
- package/dist/esm/cloud-api-client.d.ts.map +1 -1
- package/dist/esm/cloud-executor.d.ts.map +1 -1
- package/dist/esm/executor-common.d.ts.map +1 -1
- package/dist/esm/executor-types.d.ts +16 -0
- package/dist/esm/executor-types.d.ts.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/local-executor.d.ts +7 -0
- package/dist/esm/local-executor.d.ts.map +1 -1
- package/dist/esm/native/vendored-tree-sitter.d.ts +19 -0
- package/dist/esm/native/vendored-tree-sitter.d.ts.map +1 -0
- package/dist/esm/options.d.ts +86 -1
- package/dist/esm/options.d.ts.map +1 -1
- package/dist/esm/platform-package-locator.d.ts +23 -0
- package/dist/esm/platform-package-locator.d.ts.map +1 -0
- package/dist/esm/platform.d.ts +9 -2
- package/dist/esm/platform.d.ts.map +1 -1
- package/dist/esm/public-api.d.ts +5 -1
- package/dist/esm/public-api.d.ts.map +1 -1
- package/dist/esm/sqlite.js +1 -1
- package/dist/esm/stubs.d.ts +14 -2
- package/dist/esm/stubs.d.ts.map +1 -1
- package/dist/esm/tools-option.d.ts +31 -0
- package/dist/esm/tools-option.d.ts.map +1 -0
- package/dist/esm/usage-types.d.ts +12 -3
- package/dist/esm/usage-types.d.ts.map +1 -1
- package/package.json +13 -14
- package/dist/cjs/223.js +0 -1
package/dist/cjs/642.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:()=>T,cancelCloudRun:()=>K,createCloudAgent:()=>A,deleteCloudAgent:()=>L,getCloudAgent:()=>q,getCloudAgentUsage:()=>P,getCloudMe:()=>F,getCloudRun:()=>M,listCloudAgents:()=>k,listCloudModels:()=>W,listCloudRepositories:()=>V,listCloudRuns:()=>E,resumeCloudAgent:()=>N,unarchiveCloudAgent:()=>$,validateCloudModelAvailability:()=>D});var n=i("../cursor-sdk-local-runtime/dist/run-store/index.js"),s=i("./src/agent/analytics.ts"),r=i("./src/agent/cloud-api-client.ts"),o=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 o.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=i("./src/agent/usage-types.ts"),v=function(t,e,i,n){return new(i||(i=Promise))((function(s,r){function o(t){try{d(n.next(t))}catch(t){r(t)}}function a(t){try{d(n.throw(t))}catch(t){r(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(o,a)}d((n=n.apply(t,e||[])).next())}))},g=function(t){return this instanceof g?(this.v=t,this):new g(t)};function f(t){if(""===t)throw new o.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 o.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 p(t){if(!t.startsWith("bc-")||!m.test(t.slice(3)))throw new o.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 o.j1("Run ID must be in the format 'run-<uuid>'",{isRetryable:!1})}function w(t){switch(t){case"CREATING":case"RUNNING":return"running";case"FINISHED":return"finished";case"CANCELLED":return"cancelled";default:return"error"}}function b(t){return"running"===t||"completed"===t||"error"===t}const _=new Set(["assistant","thinking","tool_call"]);class I{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 o.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||[]),r=[];return n=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),o("next"),o("throw"),o("return",(function(t){return function(e){return Promise.resolve(e).then(t,u)}})),n[Symbol.asyncIterator]=function(){return this},n;function o(t,e){s[t]&&(n[t]=function(e){return new Promise((function(i,n){r.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 g?Promise.resolve(i.value.v).then(d,u):l(r[0][2],i)}catch(t){l(r[0][3],t)}var i}function d(t){a("next",t)}function u(t){a("throw",t)}function l(t,e){t(e),r.shift(),r.length&&a(r[0][0],r[0][1])}}(this,arguments,(function*(){for(;;){const t=this.queue.shift();if(t){yield yield g(t);continue}if(this.overflow)throw this.overflow;if(this.closed)return yield g(void 0);const e=yield g(new Promise((t=>{this.waiters.push(t)})));if(e.done)return yield g(void 0);yield yield g(e.value)}}))}}const S=new Set(["unauthorized","forbidden","not_found"]);function O(t,e){return v(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 j{constructor(t,e,i,n){this.client=t,this.buffer=new I,this.listeners=new Set,this.streamStarted=!1,this.emittedLegacyFrameIds=new Set,this.appliedInteractionUpdates=new Set,this.id=e.id,this.agentId=e.agentId,this.requestId=e.requestId,this._status=w(e.status),this.createdAt=Date.parse(e.createdAt);const s=(0,r.O)(e);this._result=s.result,this._error="error"===this._status?s.error:void 0,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 error(){return"error"===this._status?this._error:void 0}get usage(){return this._usage}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,o.Nt)(t,{operation:"run.stream"})}}conversation(){return v(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,o.Nt)(t,{operation:"run.conversation"})}}))}wait(){return v(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._error=(0,o.D7)(t),this.setStatus("error"))}return this.buildResult()}catch(t){throw(0,o.Nt)(t,{operation:"run.wait"})}}))}cancel(){return v(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,o.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 v(this,void 0,void 0,(function*(){this.abortClientStream(),void 0!==this.streamPromise&&(yield function(t){return v(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 v(this,void 0,void 0,(function*(){let i=0;const n=Date.now()+72e5;try{do{const r=yield this.runOneStreamAttempt(t,e);if(e.aborted)break;if("received-result"===r)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 o=Math.min((s=i,Math.min(3e4,1e3*Math.pow(2,s))),Math.max(0,n-Date.now()));i++,yield O(o,e)}while("running"===this._status&&!e.aborted);"running"===this._status&&Date.now()>=n&&this.setWaitDeadlineError(),yield t.flushPendingStep()}finally{this.buffer.close()}var s}))}applyInteractionUpdate(t,e){return v(this,void 0,void 0,(function*(){var i;if(yield t.apply(e),this._usage=null!==(i=t.usage())&&void 0!==i?i:this._usage,"turn-ended"!==e.type)return;const n=(0,h.q)(e.usage);n&&this.buffer.push({type:"usage",agent_id:this.agentId,run_id:this.id,usage:n})}))}runOneStreamAttempt(t,e){return v(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 v(this,void 0,void 0,(function*(){var a,d,u,h,v,g,f,m,p;const y=t.body.getReader(),I=new TextDecoder;let O="";try{for(;;){if(null==s?void 0:s.aborted)return;const{value:t,done:j}=yield y.read();if(j)break;O+=I.decode(t,{stream:!0});let C=O.indexOf("\n\n");for(;-1!==C;){const t=O.slice(0,C);O=O.slice(C+2),C=O.indexOf("\n\n");const s=t.split("\n");let I,j;const R=[];for(const t of s)t.startsWith("id: ")?j=t.slice(4).trim():t.startsWith("event: ")?I=t.slice(7).trim():t.startsWith("data: ")&&R.push(t.slice(6));if(void 0!==j&&j.length>0&&(void 0===I||!_.has(I))&&(null===(a=n.onEventId)||void 0===a||a.call(n,j)),"done"===I)return void(yield y.cancel());if(0===R.length)continue;const A=R.join("\n");let D;try{D=JSON.parse(A)}catch(t){throw new o.Dr(`Malformed SSE event: ${A}`,{isRetryable:!0})}if(I&&(!_.has(I)||void 0===j||!1!==(null===(d=n.shouldEmitLegacyFrame)||void 0===d?void 0:d.call(n,j))))switch(I){case"assistant":{const t=(0,l.u)(D)?D:{};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)(D)?D:{};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)(D)?D:{},s=(0,l.u)(t.data)?t.data:t,r=b(s.status)?s.status:"running",o="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:o,name:a,status:r},"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;if(!1===(null===(v=n.shouldApplyInteractionUpdate)||void 0===v?void 0:v.call(n,j,A)))break;const t=c.Zs.safeParse(D);if(!t.success)break;yield n.onInteractionUpdate(t.data);break}case"status":{const t=((0,l.u)(D)?D:{}).status;t&&(null===(g=n.onStatusChange)||void 0===g||g.call(n,w(t)),n.onMessage({type:"status",agent_id:e,run_id:i,status:t}));break}case"result":if((0,l.u)(D)){const t=D,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,r.O)(e))}return void(yield y.cancel());case"heartbeat":break;case"error":{const t=(0,l.u)(D)?D:{},e=null!==(m=t.code)&&void 0!==m?m:"UNKNOWN",i=null!==(p=t.message)&&void 0!==p?p:"Unknown error";if(S.has(e))throw new o.j1(`[${e}] ${i}`,{code:e,isRetryable:!1});throw new o.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,i;this._result=t.result;const s=w(null!==(e=t.status)&&void 0!==e?e:"FINISHED");this._error="error"===s?null!==(i=t.error)&&void 0!==i?i:this._error:void 0,this._durationMs=t.durationMs,this._git=t.git,this.setStatus(s),n=!0},onStatusChange:t=>{"running"===t&&this.setStatus(t)},onInteractionUpdate:e=>this.applyInteractionUpdate(t,e),onEventId:t=>{this.lastEventId=t,this.emittedLegacyFrameIds.clear()},shouldEmitLegacyFrame:t=>!this.emittedLegacyFrameIds.has(t)&&(this.emittedLegacyFrameIds.add(t),!0),shouldApplyInteractionUpdate:(t,e)=>{var i;const n=void 0!==t&&t.length>0?t:`${null!==(i=this.lastEventId)&&void 0!==i?i:""}\0${e}`;return!this.appliedInteractionUpdates.has(n)&&(this.appliedInteractionUpdates.add(n),!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 o.v3||t instanceof o.j1)return!0;if(t instanceof Error){const e=/^\[([a-z_]+)\]/.exec(t.message);if(null!==e&&S.has(e[1]))return!0}return!1}(t))throw"running"===this._status&&(this._error=(0,o.D7)(t),this.setStatus("error")),t}return n?"received-result":"stream-dropped"}))}pollRunUntilTerminal(t,e){return v(this,void 0,void 0,(function*(){for(;"running"===this._status&&!t.aborted;){const i=e-Date.now();if(i<=0)return void this.setWaitDeadlineError();if(yield O(Math.min(15e3,i),t),t.aborted)return;yield this.refetchAndSync()}}))}setWaitDeadlineError(){this._error={message:"Timed out waiting for the cloud run to finish."},this.setStatus("error")}setStatus(t){if(this._status!==t){this._status=t;for(const e of this.listeners)e(t)}}refetchAndSync(){return v(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 o.v3||t instanceof o.j1)throw"running"===this._status&&(this._error=(0,o.D7)(t),this.setStatus("error")),t;return}const e=(0,r.O)(t);void 0!==e.result&&(this._result=e.result);const i=w(t.status);"error"===i&&void 0!==e.error?this._error=e.error:"error"!==i&&(this._error=void 0),void 0!==e.durationMs&&(this._durationMs=e.durationMs),void 0!==e.git&&(this._git=e.git),"running"===this._status&&this.setStatus(i)}))}buildResult(){const t="running"===this._status?"error":this._status;return Object.assign(Object.assign(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}:{}),"error"===t&&void 0!==this._error?{error:this._error}:{}),void 0!==this._model?{model:this._model}:{}),void 0!==this._durationMs?{durationMs:this._durationMs}:{}),void 0!==this._git?{git:this._git}:{}),void 0!==this._usage?{usage:this._usage}:{})}}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 v(this,void 0,void 0,(function*(){var i,n,r,d,l,c,h,v,g,f,m,p,y,w,b,_,I,S,O,C,A;const D=null!==(r=null===(n=null===(i=this.options.cloud)||void 0===i?void 0:i.env)||void 0===n?void 0:n.type)&&void 0!==r?r:"cloud";let N=!1;try{if(void 0!==(null===(d=null==e?void 0:e.local)||void 0===d?void 0:d.customTools))throw new o.j1("Custom local tools are only supported for local SDK agents. Create the agent with getLocalPlatformOptions() or omit local.customTools.",{isRetryable:!1});const i=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),n=!this.serverCreated,r=null!==(l=null==e?void 0:e.mcpServers)&&void 0!==l?l:this.options.mcpServers,k=null!==(c=null==e?void 0:e.model)&&void 0!==c?c:this._model,E=void 0!==(null==e?void 0:e.mode)?e.mode:n?this.options.mode:void 0,M=null===(h=this.options.cloud)||void 0===h?void 0:h.envVars,K=null===(v=null==e?void 0:e.cloud)||void 0===v?void 0:v.envVars,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 P;if(n){const t=(0,u.SB)(this.options.agents),n=R(M),s=yield this.client.createAgent(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},n?{}:{agentId:this.agentId}),{prompt:i}),void 0!==k?{model:k}:{}),void 0!==this.options.name?{name:this.options.name}:{}),{mcpServers:a(r)}),void 0!==t?{customSubagents:t}:{}),{env:null===(g=this.options.cloud)||void 0===g?void 0:g.env}),R(M)?{envVars:M}:{}),R(K)?{runEnvVars:K}:{}),void 0!==(null===(f=this.options.cloud)||void 0===f?void 0:f.metadata)?{metadata:this.options.cloud.metadata}:{}),{repos:null===(m=this.options.cloud)||void 0===m?void 0:m.repos,workOnCurrentBranch:null===(p=this.options.cloud)||void 0===p?void 0:p.workOnCurrentBranch,autoCreatePR:null===(y=this.options.cloud)||void 0===y?void 0:y.autoCreatePR,skipReviewerRequest:null===(w=this.options.cloud)||void 0===w?void 0:w.skipReviewerRequest}),void 0!==E?{mode:E}:{}),{idempotencyKey:null!==(b=null==e?void 0:e.idempotencyKey)&&void 0!==b?b:this.options.idempotencyKey});if(n)this.agentId=s.agent.id;else if(s.agent.id!==this.agentId)throw new o.c$(`Server returned mismatched agent id "${s.agent.id}"; expected "${this.agentId}". This indicates a backend bug.`,{isRetryable:!1});this.serverCreated=!0,P=new j(this.client,s.run,x,k)}else{const t=yield this.client.createRun(this.agentId,Object.assign(Object.assign(Object.assign({prompt:i,mcpServers:a(r)},void 0!==(null==e?void 0:e.model)?{model:e.model}:{}),R(K)?{envVars:K}:{}),void 0!==E?{mode:E}:{}),{idempotencyKey:null==e?void 0:e.idempotencyKey});P=new j(this.client,t.run,x,k)}void 0!==(null==e?void 0:e.model)&&(this._model=e.model);const U=null==k?void 0:k.params;(0,s.Zn)(this.options.apiKey,Object.assign(Object.assign({agent_id:this.agentId,run_id:P.id,request_id:P.requestId,runtime:D,model:null!==(_=null==k?void 0:k.id)&&void 0!==_?_:"default"},U&&U.length>0?{model_params:JSON.stringify(U)}:{}),{prompt_length:i.text.length,has_images:(null!==(S=null===(I=i.images)||void 0===I?void 0:I.length)&&void 0!==S?S:0)>0,is_resume:!n,mcp_server_count:Object.keys(null!=r?r:{}).length,cloud_repo_count:null===(C=null===(O=this.options.cloud)||void 0===O?void 0:O.repos)||void 0===C?void 0:C.length,cloud_auto_create_pr:null===(A=this.options.cloud)||void 0===A?void 0:A.autoCreatePR})),N=!0,this.activeRuns.add(P);const q=this.options.apiKey,T=this.agentId,$=P.id;return P.wait().then((t=>{var e;(0,s.G5)(q,{agent_id:T,run_id:$,request_id:P.requestId,runtime:D,end_reason:"finished"===t.status?"success":"cancelled"===t.status?"abort":"error",error_code:"error"===t.status?null===(e=t.error)||void 0===e?void 0:e.code:void 0})})).finally((()=>{this.activeRuns.delete(P)})),P.ensureStreamStarted(),P}catch(t){const e=(0,o.Nt)(t,{operation:"agent.send"});throw N||(0,s.CI)({apiKey:this.options.apiKey,runtime:D,error:e}),e}}))}close(){for(const t of this.activeRuns)t.abortClientStream();(0,s.rd)()}reload(){return v(this,void 0,void 0,(function*(){}))}[Symbol.asyncDispose](){return v(this,void 0,void 0,(function*(){yield Promise.allSettled(Array.from(this.activeRuns,(t=>t.disposeClientStream()))),yield(0,s.rd)()}))}listArtifacts(){return v(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,o.Nt)(t,{operation:"agent.listArtifacts"})}}))}getUsage(t){return v(this,void 0,void 0,(function*(){try{return x(yield this.client.getAgentUsage(this.agentId,t))}catch(t){throw(0,o.Nt)(t,{operation:"agent.getUsage"})}}))}downloadArtifact(t){return v(this,void 0,void 0,(function*(){try{if(!this.serverCreated)throw new o.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 o.Dr("Failed to download artifact",{cause:t,isRetryable:!0})}if(!i.ok)throw new o.Dr(`Failed to download artifact: ${i.status}`,{status:i.status,isRetryable:i.status>=500});return Buffer.from(yield i.arrayBuffer())}catch(t){throw(0,o.Nt)(t,{operation:"agent.downloadArtifact"})}}))}}function R(t){return void 0!==t&&Object.keys(t).length>0}function A(t){var e,i;const s=f(t.apiKey);if(void 0!==t.agentId&&R(null===(e=t.cloud)||void 0===e?void 0:e.envVars))throw new o.j1("cloud.envVars cannot be combined with agentId; omit agentId so the server can mint an agent id.",{isRetryable:!1});const a=new r.N(s),d=null!==(i=t.agentId)&&void 0!==i?i:(0,n.M2)();return new C(d,a,t,!1)}function D(t){return v(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 o.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 o.j1)return;throw t}try{s=(yield new r.N(n).listModels()).items}catch(t){if(t instanceof o.Dr||t instanceof o.v3||t instanceof o.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 o.j1(`Model '${i}' is not available or invalid. Call Cursor.models.list() to see valid model ids.`,{isRetryable:!1,code:"invalid_model"})}))}function N(t,e){const i=f(e.apiKey),n=new r.N(i);return new C(t,n,Object.assign({},e),!0)}function k(t){return v(this,void 0,void 0,(function*(){const e=f(t.apiKey),i=new r.N(e),n=yield i.listAgents({limit:t.limit,cursor:t.cursor,prUrl:t.prUrl,includeArchived:t.includeArchived});return{items:n.items.map(U),nextCursor:n.nextCursor}}))}function E(t,e){return v(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new r.N(i),s=yield n.listRuns(t,{limit:e.limit,cursor:e.cursor});return{items:s.items.map((t=>new j(n,t))),nextCursor:s.nextCursor}}))}function M(t,e){return v(this,void 0,void 0,(function*(){y(t),p(e.agentId);const i=f(e.apiKey),n=new r.N(i),s=yield n.getRun({agentId:e.agentId,runId:t});return new j(n,s)}))}function K(t,e){return v(this,void 0,void 0,(function*(){y(t),p(e.agentId);const i=f(e.apiKey),n=new r.N(i);yield n.cancelRun({agentId:e.agentId,runId:t})}))}function x(t){return Object.assign(Object.assign({usage:t.totalUsage},void 0!==t.cost?{cost:t.cost}:{}),{runs:t.runs.map((t=>Object.assign({runId:t.id,usage:t.usage},void 0!==t.cost?{cost:t.cost}:{})))})}function P(t,e){return v(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new r.N(i);return x(yield n.getAgentUsage(t,{runId:e.runId}))}))}function U(t){var e,i,n;return Object.assign({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))},void 0!==t.metadata?{metadata:t.metadata}:{})}function q(t,e){return v(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new r.N(i);return U(yield n.getAgent(t))}))}function T(t,e){return v(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new r.N(i);yield n.archiveAgent(t)}))}function $(t,e){return v(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new r.N(i);yield n.unarchiveAgent(t)}))}function L(t,e){return v(this,void 0,void 0,(function*(){const i=f(e.apiKey),n=new r.N(i);yield n.deleteAgent(t)}))}function F(t){return v(this,void 0,void 0,(function*(){const e=f(t.apiKey);return new r.N(e).getMe()}))}function W(t){return v(this,void 0,void 0,(function*(){const e=f(t.apiKey),i=new r.N(e);return(yield i.listModels()).items}))}function V(t){return v(this,void 0,void 0,(function*(){const e=f(t.apiKey),i=new r.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:()=>q,cancelCloudRun:()=>K,createCloudAgent:()=>D,deleteCloudAgent:()=>$,getCloudAgent:()=>U,getCloudMe:()=>L,getCloudRun:()=>x,listCloudAgents:()=>M,listCloudModels:()=>F,listCloudRepositories:()=>W,listCloudRuns:()=>E,resumeCloudAgent:()=>k,unarchiveCloudAgent:()=>T,validateCloudModelAvailability:()=>N});var n=i("../cursor-sdk-local-runtime/dist/run-store/index.js"),s=i("./src/agent/analytics.ts"),r=i("./src/agent/auth/stored-credentials.ts"),o=i("./src/agent/cloud-api-client.ts"),a=i("./src/agent/errors.ts");function d(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 a.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 u=i("./src/agent/run-interaction-accumulator.ts"),l=i("./src/agent/subagent-conversion.ts"),c=i("./src/agent/tool-call-utils.ts"),h=i("./src/agent/types/delta-types.ts"),v=i("./src/agent/usage-types.ts"),f=function(t,e,i,n){return new(i||(i=Promise))((function(s,r){function o(t){try{d(n.next(t))}catch(t){r(t)}}function a(t){try{d(n.throw(t))}catch(t){r(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(o,a)}d((n=n.apply(t,e||[])).next())}))},g=function(t){return this instanceof g?(this.v=t,this):new g(t)};function m(t){if(""===t)throw new a.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=(0,r.Lc)(t);if(!e)throw new a.j1("API key is required for cloud operations. Set CURSOR_API_KEY, pass apiKey, or run Cursor.auth.login().",{isRetryable:!1,code:"unauthenticated"});return e}const p=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function y(t){if(!t.startsWith("bc-")||!p.test(t.slice(3)))throw new a.j1("Agent ID must be in the format 'bc-<uuid>'",{isRetryable:!1})}function w(t){if(!t.startsWith("run-")||!p.test(t.slice(4)))throw new a.j1("Run ID must be in the format 'run-<uuid>'",{isRetryable:!1})}function b(t){switch(t){case"CREATING":case"RUNNING":return"running";case"FINISHED":return"finished";case"CANCELLED":return"cancelled";default:return"error"}}function _(t){return"running"===t||"completed"===t||"error"===t}const I=new Set(["assistant","thinking","tool_call"]);class S{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 a.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||[]),r=[];return n=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),o("next"),o("throw"),o("return",(function(t){return function(e){return Promise.resolve(e).then(t,u)}})),n[Symbol.asyncIterator]=function(){return this},n;function o(t,e){s[t]&&(n[t]=function(e){return new Promise((function(i,n){r.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 g?Promise.resolve(i.value.v).then(d,u):l(r[0][2],i)}catch(t){l(r[0][3],t)}var i}function d(t){a("next",t)}function u(t){a("throw",t)}function l(t,e){t(e),r.shift(),r.length&&a(r[0][0],r[0][1])}}(this,arguments,(function*(){for(;;){const t=this.queue.shift();if(t){yield yield g(t);continue}if(this.overflow)throw this.overflow;if(this.closed)return yield g(void 0);const e=yield g(new Promise((t=>{this.waiters.push(t)})));if(e.done)return yield g(void 0);yield yield g(e.value)}}))}}const O=new Set(["unauthorized","forbidden","not_found"]);function C(t,e){return f(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 j{constructor(t,e,i,n){this.client=t,this.buffer=new S,this.listeners=new Set,this.streamStarted=!1,this.emittedLegacyFrameIds=new Set,this.appliedInteractionUpdates=new Set,this.id=e.id,this.agentId=e.agentId,this.requestId=e.requestId,this._status=b(e.status),this.createdAt=Date.parse(e.createdAt);const s=(0,o.O0)(e);this._result=s.result,this._error="error"===this._status?s.error:void 0,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 error(){return"error"===this._status?this._error:void 0}get usage(){return this._usage}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,a.Nt)(t,{operation:"run.stream"})}}conversation(){return f(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,a.Nt)(t,{operation:"run.conversation"})}}))}wait(){return f(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._error=(0,a.D7)(t),this.setStatus("error"))}return this.buildResult()}catch(t){throw(0,a.Nt)(t,{operation:"run.wait"})}}))}cancel(){return f(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,a.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 f(this,void 0,void 0,(function*(){this.abortClientStream(),void 0!==this.streamPromise&&(yield function(t){return f(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 u.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 f(this,void 0,void 0,(function*(){let i=0;const n=Date.now()+72e5;try{do{const r=yield this.runOneStreamAttempt(t,e);if(e.aborted)break;if("received-result"===r)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 o=Math.min((s=i,Math.min(3e4,1e3*Math.pow(2,s))),Math.max(0,n-Date.now()));i++,yield C(o,e)}while("running"===this._status&&!e.aborted);"running"===this._status&&Date.now()>=n&&this.setWaitDeadlineError(),yield t.flushPendingStep()}finally{this.buffer.close()}var s}))}applyInteractionUpdate(t,e){return f(this,void 0,void 0,(function*(){var i;if(yield t.apply(e),this._usage=null!==(i=t.usage())&&void 0!==i?i:this._usage,"turn-ended"!==e.type)return;const n=(0,v.q)(e.usage);n&&this.buffer.push({type:"usage",agent_id:this.agentId,run_id:this.id,usage:n})}))}runOneStreamAttempt(t,e){return f(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 f(this,void 0,void 0,(function*(){var r,d,u,l,v,f,g,m,p;const y=t.body.getReader(),w=new TextDecoder;let S="";try{for(;;){if(null==s?void 0:s.aborted)return;const{value:t,done:C}=yield y.read();if(C)break;S+=w.decode(t,{stream:!0});let j=S.indexOf("\n\n");for(;-1!==j;){const t=S.slice(0,j);S=S.slice(j+2),j=S.indexOf("\n\n");const s=t.split("\n");let w,C;const R=[];for(const t of s)t.startsWith("id: ")?C=t.slice(4).trim():t.startsWith("event: ")?w=t.slice(7).trim():t.startsWith("data: ")&&R.push(t.slice(6));if(void 0!==C&&C.length>0&&(void 0===w||!I.has(w))&&(null===(r=n.onEventId)||void 0===r||r.call(n,C)),"done"===w)return void(yield y.cancel());if(0===R.length)continue;const A=R.join("\n");let D;try{D=JSON.parse(A)}catch(t){throw new a.Dr(`Malformed SSE event: ${A}`,{isRetryable:!0})}if(w&&(!I.has(w)||void 0===C||!1!==(null===(d=n.shouldEmitLegacyFrame)||void 0===d?void 0:d.call(n,C))))switch(w){case"assistant":{const t=(0,c.u)(D)?D:{};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,c.u)(D)?D:{};n.onMessage({type:"thinking",agent_id:e,run_id:i,text:null!==(l=t.text)&&void 0!==l?l:""});break}case"tool_call":{const t=(0,c.u)(D)?D:{},s=(0,c.u)(t.data)?t.data:t,r=_(s.status)?s.status:"running",o="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:o,name:a,status:r},"args"in s?{args:s.args}:{}),"result"in s?{result:s.result}:{}),(0,c.D)(s.truncated)?{truncated:s.truncated}:{}));break}case"interaction_update":{if(void 0===n.onInteractionUpdate)break;if(!1===(null===(v=n.shouldApplyInteractionUpdate)||void 0===v?void 0:v.call(n,C,A)))break;const t=h.Zs.safeParse(D);if(!t.success)break;yield n.onInteractionUpdate(t.data);break}case"status":{const t=((0,c.u)(D)?D:{}).status;t&&(null===(f=n.onStatusChange)||void 0===f||f.call(n,b(t)),n.onMessage({type:"status",agent_id:e,run_id:i,status:t}));break}case"result":if((0,c.u)(D)){const t=D,e=Object.assign(Object.assign({},t),"string"==typeof t.text&&void 0===t.result?{result:t.text}:{});null===(g=n.onResult)||void 0===g||g.call(n,(0,o.O0)(e))}return void(yield y.cancel());case"heartbeat":break;case"error":{const t=(0,c.u)(D)?D:{},e=null!==(m=t.code)&&void 0!==m?m:"UNKNOWN",i=null!==(p=t.message)&&void 0!==p?p:"Unknown error";if(O.has(e))throw new a.j1(`[${e}] ${i}`,{code:e,isRetryable:!1});throw new a.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,i;this._result=t.result;const s=b(null!==(e=t.status)&&void 0!==e?e:"FINISHED");this._error="error"===s?null!==(i=t.error)&&void 0!==i?i:this._error:void 0,this._durationMs=t.durationMs,this._git=t.git,this.setStatus(s),n=!0},onStatusChange:t=>{"running"===t&&this.setStatus(t)},onInteractionUpdate:e=>this.applyInteractionUpdate(t,e),onEventId:t=>{this.lastEventId=t,this.emittedLegacyFrameIds.clear()},shouldEmitLegacyFrame:t=>!this.emittedLegacyFrameIds.has(t)&&(this.emittedLegacyFrameIds.add(t),!0),shouldApplyInteractionUpdate:(t,e)=>{var i;const n=void 0!==t&&t.length>0?t:`${null!==(i=this.lastEventId)&&void 0!==i?i:""}\0${e}`;return!this.appliedInteractionUpdates.has(n)&&(this.appliedInteractionUpdates.add(n),!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 a.v3||t instanceof a.j1)return!0;if(t instanceof Error){const e=/^\[([a-z_]+)\]/.exec(t.message);if(null!==e&&O.has(e[1]))return!0}return!1}(t))throw"running"===this._status&&(this._error=(0,a.D7)(t),this.setStatus("error")),t}return n?"received-result":"stream-dropped"}))}pollRunUntilTerminal(t,e){return f(this,void 0,void 0,(function*(){for(;"running"===this._status&&!t.aborted;){const i=e-Date.now();if(i<=0)return void this.setWaitDeadlineError();if(yield C(Math.min(15e3,i),t),t.aborted)return;yield this.refetchAndSync()}}))}setWaitDeadlineError(){this._error={message:"Timed out waiting for the cloud run to finish."},this.setStatus("error")}setStatus(t){if(this._status!==t){this._status=t;for(const e of this.listeners)e(t)}}refetchAndSync(){return f(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 a.v3||t instanceof a.j1)throw"running"===this._status&&(this._error=(0,a.D7)(t),this.setStatus("error")),t;return}const e=(0,o.O0)(t);void 0!==e.result&&(this._result=e.result);const i=b(t.status);"error"===i&&void 0!==e.error?this._error=e.error:"error"!==i&&(this._error=void 0),void 0!==e.durationMs&&(this._durationMs=e.durationMs),void 0!==e.git&&(this._git=e.git),"running"===this._status&&this.setStatus(i)}))}buildResult(){const t="running"===this._status?"error":this._status;return Object.assign(Object.assign(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}:{}),"error"===t&&void 0!==this._error?{error:this._error}:{}),void 0!==this._model?{model:this._model}:{}),void 0!==this._durationMs?{durationMs:this._durationMs}:{}),void 0!==this._git?{git:this._git}:{}),void 0!==this._usage?{usage:this._usage}:{})}}class R{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 f(this,void 0,void 0,(function*(){var i,n,r,o,u,c,h,v,f,g,m,p,y,w,b,_,I,S,O,C,R,D;const N=null!==(r=null===(n=null===(i=this.options.cloud)||void 0===i?void 0:i.env)||void 0===n?void 0:n.type)&&void 0!==r?r:"cloud";let k=!1;try{if(void 0!==(null===(o=null==e?void 0:e.local)||void 0===o?void 0:o.customTools))throw new a.j1("Custom local tools are only supported for local SDK agents. Create the agent with getLocalPlatformOptions() or omit local.customTools.",{isRetryable:!1});const i=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),n=!this.serverCreated,r=null!==(u=null==e?void 0:e.mcpServers)&&void 0!==u?u:this.options.mcpServers,M=null!==(c=null==e?void 0:e.model)&&void 0!==c?c:this._model,E=void 0!==(null==e?void 0:e.mode)?e.mode:n?this.options.mode:void 0,x=null===(h=this.options.cloud)||void 0===h?void 0:h.envVars,K=null===(v=null==e?void 0:e.cloud)||void 0===v?void 0:v.envVars,P=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 U;if(n){const t=(0,l.SB)(this.options.agents),n=A(x),s=yield this.client.createAgent(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},n?{}:{agentId:this.agentId}),{prompt:i}),void 0!==M?{model:M}:{}),void 0!==this.options.name?{name:this.options.name}:{}),{mcpServers:d(r)}),void 0!==t?{customSubagents:t}:{}),{env:null===(f=this.options.cloud)||void 0===f?void 0:f.env}),A(x)?{envVars:x}:{}),A(K)?{runEnvVars:K}:{}),void 0!==(null===(g=this.options.cloud)||void 0===g?void 0:g.metadata)?{metadata:this.options.cloud.metadata}:{}),{repos:null===(m=this.options.cloud)||void 0===m?void 0:m.repos,workOnCurrentBranch:null===(p=this.options.cloud)||void 0===p?void 0:p.workOnCurrentBranch,autoCreatePR:null===(y=this.options.cloud)||void 0===y?void 0:y.autoCreatePR,openAsCursorGithubApp:null===(w=this.options.cloud)||void 0===w?void 0:w.openAsCursorGithubApp,skipReviewerRequest:null===(b=this.options.cloud)||void 0===b?void 0:b.skipReviewerRequest}),void 0!==E?{mode:E}:{}),{idempotencyKey:null!==(_=null==e?void 0:e.idempotencyKey)&&void 0!==_?_:this.options.idempotencyKey});if(n)this.agentId=s.agent.id;else if(s.agent.id!==this.agentId)throw new a.c$(`Server returned mismatched agent id "${s.agent.id}"; expected "${this.agentId}". This indicates a backend bug.`,{isRetryable:!1});this.serverCreated=!0,U=new j(this.client,s.run,P,M)}else{const t=yield this.client.createRun(this.agentId,Object.assign(Object.assign(Object.assign({prompt:i,mcpServers:d(r)},void 0!==(null==e?void 0:e.model)?{model:e.model}:{}),A(K)?{envVars:K}:{}),void 0!==E?{mode:E}:{}),{idempotencyKey:null==e?void 0:e.idempotencyKey});U=new j(this.client,t.run,P,M)}void 0!==(null==e?void 0:e.model)&&(this._model=e.model);const q=null==M?void 0:M.params;(0,s.Zn)(this.options.apiKey,Object.assign(Object.assign({agent_id:this.agentId,run_id:U.id,request_id:U.requestId,runtime:N,model:null!==(I=null==M?void 0:M.id)&&void 0!==I?I:"default"},q&&q.length>0?{model_params:JSON.stringify(q)}:{}),{prompt_length:i.text.length,has_images:(null!==(O=null===(S=i.images)||void 0===S?void 0:S.length)&&void 0!==O?O:0)>0,is_resume:!n,mcp_server_count:Object.keys(null!=r?r:{}).length,cloud_repo_count:null===(R=null===(C=this.options.cloud)||void 0===C?void 0:C.repos)||void 0===R?void 0:R.length,cloud_auto_create_pr:null===(D=this.options.cloud)||void 0===D?void 0:D.autoCreatePR})),k=!0,this.activeRuns.add(U);const T=this.options.apiKey,$=this.agentId,L=U.id;return U.wait().then((t=>{var e;(0,s.G5)(T,{agent_id:$,run_id:L,request_id:U.requestId,runtime:N,end_reason:"finished"===t.status?"success":"cancelled"===t.status?"abort":"error",error_code:"error"===t.status?null===(e=t.error)||void 0===e?void 0:e.code:void 0})})).finally((()=>{this.activeRuns.delete(U)})),U.ensureStreamStarted(),U}catch(t){const e=(0,a.Nt)(t,{operation:"agent.send"});throw k||(0,s.CI)({apiKey:this.options.apiKey,runtime:N,error:e}),e}}))}close(){for(const t of this.activeRuns)t.abortClientStream();(0,s.rd)()}reload(){return f(this,void 0,void 0,(function*(){}))}[Symbol.asyncDispose](){return f(this,void 0,void 0,(function*(){yield Promise.allSettled(Array.from(this.activeRuns,(t=>t.disposeClientStream()))),yield(0,s.rd)()}))}listArtifacts(){return f(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,a.Nt)(t,{operation:"agent.listArtifacts"})}}))}getUsage(t){return f(this,void 0,void 0,(function*(){try{const e=yield this.client.getAgentUsage(this.agentId,t);return(0,o.nu)(e)}catch(t){throw(0,a.Nt)(t,{operation:"agent.getUsage"})}}))}downloadArtifact(t){return f(this,void 0,void 0,(function*(){try{if(!this.serverCreated)throw new a.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 a.Dr("Failed to download artifact",{cause:t,isRetryable:!0})}if(!i.ok)throw new a.Dr(`Failed to download artifact: ${i.status}`,{status:i.status,isRetryable:i.status>=500});return Buffer.from(yield i.arrayBuffer())}catch(t){throw(0,a.Nt)(t,{operation:"agent.downloadArtifact"})}}))}}function A(t){return void 0!==t&&Object.keys(t).length>0}function D(t){var e,i;const s=m(t.apiKey);if(void 0!==t.agentId&&A(null===(e=t.cloud)||void 0===e?void 0:e.envVars))throw new a.j1("cloud.envVars cannot be combined with agentId; omit agentId so the server can mint an agent id.",{isRetryable:!1});const r=new o.N_(s),d=null!==(i=t.agentId)&&void 0!==i?i:(0,n.M2)();return new R(d,r,t,!1)}function N(t){return f(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 a.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=m(t)}catch(t){if(t instanceof a.j1)return;throw t}try{s=(yield new o.N_(n).listModels()).items}catch(t){if(t instanceof a.Dr||t instanceof a.v3||t instanceof a.OE)return;throw t}const r=s.some((t=>{var e;return t.id===i||!0===(null===(e=t.aliases)||void 0===e?void 0:e.includes(i))}));if(!r)throw new a.j1(`Model '${i}' is not available or invalid. Call Cursor.models.list() to see valid model ids.`,{isRetryable:!1,code:"invalid_model"})}))}function k(t,e){const i=m(e.apiKey),n=new o.N_(i);return new R(t,n,Object.assign({},e),!0)}function M(t){return f(this,void 0,void 0,(function*(){const e=m(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(P),nextCursor:n.nextCursor}}))}function E(t,e){return f(this,void 0,void 0,(function*(){const i=m(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 j(n,t))),nextCursor:s.nextCursor}}))}function x(t,e){return f(this,void 0,void 0,(function*(){w(t),y(e.agentId);const i=m(e.apiKey),n=new o.N_(i),s=yield n.getRun({agentId:e.agentId,runId:t});return new j(n,s)}))}function K(t,e){return f(this,void 0,void 0,(function*(){w(t),y(e.agentId);const i=m(e.apiKey),n=new o.N_(i);yield n.cancelRun({agentId:e.agentId,runId:t})}))}function P(t){var e,i,n;return Object.assign({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))},void 0!==t.metadata?{metadata:t.metadata}:{})}function U(t,e){return f(this,void 0,void 0,(function*(){const i=m(e.apiKey),n=new o.N_(i);return P(yield n.getAgent(t))}))}function q(t,e){return f(this,void 0,void 0,(function*(){const i=m(e.apiKey),n=new o.N_(i);yield n.archiveAgent(t)}))}function T(t,e){return f(this,void 0,void 0,(function*(){const i=m(e.apiKey),n=new o.N_(i);yield n.unarchiveAgent(t)}))}function $(t,e){return f(this,void 0,void 0,(function*(){const i=m(e.apiKey),n=new o.N_(i);yield n.deleteAgent(t)}))}function L(t){return f(this,void 0,void 0,(function*(){const e=m(t.apiKey);return new o.N_(e).getMe()}))}function F(t){return f(this,void 0,void 0,(function*(){const e=m(t.apiKey),i=new o.N_(e);return(yield i.listModels()).items}))}function W(t){return f(this,void 0,void 0,(function*(){const e=m(t.apiKey),i=new o.N_(e);return(yield i.listRepositories()).items}))}}};
|
|
@@ -106,7 +106,18 @@ export interface AgentDefinition {
|
|
|
106
106
|
* `Partial<NonNullable<AgentOptions["local"]>>`.
|
|
107
107
|
*/
|
|
108
108
|
export interface LocalAgentOptions {
|
|
109
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Primary working directory for this local agent (default shell cwd and
|
|
111
|
+
* local agent-store scoping).
|
|
112
|
+
*/
|
|
113
|
+
cwd?: string;
|
|
114
|
+
/**
|
|
115
|
+
* Additional / multi-root workspace folders. Merged with {@link cwd} (cwd
|
|
116
|
+
* first, duplicates dropped) so project rules, skills, and request-context
|
|
117
|
+
* workspace metadata load from every unique path. {@link cwd} remains the
|
|
118
|
+
* primary working directory for the default shell and agent-store scoping.
|
|
119
|
+
*/
|
|
120
|
+
dirs?: string[];
|
|
110
121
|
/**
|
|
111
122
|
* Enable Cursor's Auto-review for local tool calls. When this is true,
|
|
112
123
|
* local runs select the classifier-backed Auto mode whenever the connected
|
|
@@ -189,6 +200,11 @@ export interface CloudAgentOptions {
|
|
|
189
200
|
}>;
|
|
190
201
|
workOnCurrentBranch?: boolean;
|
|
191
202
|
autoCreatePR?: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* When true, open PRs as the Cursor GitHub App instead of the API-key owner.
|
|
205
|
+
* Defaults to true for service-account keys and false for user keys.
|
|
206
|
+
*/
|
|
207
|
+
openAsCursorGithubApp?: boolean;
|
|
192
208
|
skipReviewerRequest?: boolean;
|
|
193
209
|
/**
|
|
194
210
|
* Per-session env vars injected into the cloud agent's shell, e.g. for
|
|
@@ -228,6 +244,18 @@ export interface CursorAgentPlatformOptions {
|
|
|
228
244
|
eventStore?: RunEventStore;
|
|
229
245
|
eventNotifier?: RunEventNotifier;
|
|
230
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Public tool names accepted by {@link AgentOptions.tools}.
|
|
249
|
+
*
|
|
250
|
+
* The listed literals are a curated set of the common local-agent built-in
|
|
251
|
+
* tools, surfaced for editor autocomplete. They are not the full vocabulary:
|
|
252
|
+
* the complete set is derived from the agent proto at runtime, so the
|
|
253
|
+
* `(string & {})` member keeps the type open — any other public tool name,
|
|
254
|
+
* capability group, or raw proto tool name (e.g. `"web_search_tool_call"`) is
|
|
255
|
+
* still accepted. Unknown names are rejected at `Agent.create` /
|
|
256
|
+
* `Agent.resume`, not by the type.
|
|
257
|
+
*/
|
|
258
|
+
export type ToolName = "shell" | "read" | "edit" | "grep" | "glob" | "ls" | "task" | "mcp" | "webSearch" | "delete" | "readLints" | "webFetch" | "semSearch" | "updateTodos" | "readTodos" | "askQuestion" | "await" | "generateImage" | "applyAgentDiff" | (string & {});
|
|
231
259
|
export interface AgentOptions {
|
|
232
260
|
/**
|
|
233
261
|
* Model selection (`{ id, params? }`). Required for local agents; optional
|
|
@@ -236,6 +264,63 @@ export interface AgentOptions {
|
|
|
236
264
|
*/
|
|
237
265
|
model?: ModelSelection;
|
|
238
266
|
apiKey?: string;
|
|
267
|
+
/**
|
|
268
|
+
* Restricts the built-in tools available to the model:
|
|
269
|
+
*
|
|
270
|
+
* - `undefined` (default) — the standard toolset for the selected model.
|
|
271
|
+
* - `[]` — no built-in tools; the model can only respond with text.
|
|
272
|
+
* - Non-empty — only the listed tools are offered to the model.
|
|
273
|
+
*
|
|
274
|
+
* Tool names use the SDK's public tool vocabulary — the same names carried
|
|
275
|
+
* by `tool_call` stream events (`"shell"`, `"read"`, `"edit"`, `"grep"`,
|
|
276
|
+
* `"glob"`, `"ls"`, `"task"`, `"mcp"`, ...). The vocabulary is derived from
|
|
277
|
+
* the agent proto, so tools added to the platform are addressable without
|
|
278
|
+
* an SDK update; raw proto tool names such as `"web_search_tool_call"` are
|
|
279
|
+
* also accepted. Unknown names throw a `ConfigurationError` at
|
|
280
|
+
* `Agent.create` / `Agent.resume` listing the valid names.
|
|
281
|
+
*
|
|
282
|
+
* Notes:
|
|
283
|
+
* - `"shell"` and `"mcp"` are capability groups: `"shell"` also grants
|
|
284
|
+
* shell stdin writes, and `"mcp"` grants the whole MCP tool family
|
|
285
|
+
* (including {@link LocalAgentOptions.customTools}); omitting `"mcp"`
|
|
286
|
+
* disables MCP entirely.
|
|
287
|
+
* - `"task"` gates subagents. Subagents launched through it keep their own
|
|
288
|
+
* curated toolsets; the restriction applies to the main agent loop.
|
|
289
|
+
* - Not persisted on the agent: pass `tools` again on `Agent.resume` to
|
|
290
|
+
* keep the restriction for follow-up runs.
|
|
291
|
+
*
|
|
292
|
+
* Local agents only for now; combining `tools` with `cloud` throws a
|
|
293
|
+
* `ConfigurationError`.
|
|
294
|
+
*
|
|
295
|
+
* See {@link ToolName} for the accepted names.
|
|
296
|
+
*/
|
|
297
|
+
tools?: ToolName[];
|
|
298
|
+
/**
|
|
299
|
+
* Removes the listed built-in tools from the model's toolset. The
|
|
300
|
+
* complement of {@link AgentOptions.tools}: instead of naming what stays,
|
|
301
|
+
* name what goes, and everything else in the default toolset remains
|
|
302
|
+
* available — including tools added to the platform after this SDK was
|
|
303
|
+
* released.
|
|
304
|
+
*
|
|
305
|
+
* Accepts the same vocabulary as `tools` (public names, capability groups,
|
|
306
|
+
* raw proto names); unknown names throw a `ConfigurationError` at
|
|
307
|
+
* `Agent.create` / `Agent.resume`. Capability groups expand the same way:
|
|
308
|
+
* `"shell"` also removes shell stdin writes, and `"mcp"` removes the whole
|
|
309
|
+
* MCP tool family (including {@link LocalAgentOptions.customTools}).
|
|
310
|
+
*
|
|
311
|
+
* Notes:
|
|
312
|
+
* - Combines with `tools` as deny-wins: a tool must be listed in `tools`
|
|
313
|
+
* (when set) and not listed in `disallowedTools` to be offered.
|
|
314
|
+
* - Like `tools`, the exclusion applies to the main agent loop: subagents
|
|
315
|
+
* launched through `"task"` keep their own curated toolsets. Disallow
|
|
316
|
+
* `"task"` to prevent subagents entirely.
|
|
317
|
+
* - Not persisted on the agent: pass `disallowedTools` again on
|
|
318
|
+
* `Agent.resume` to keep the exclusion for follow-up runs.
|
|
319
|
+
*
|
|
320
|
+
* Local agents only for now; combining `disallowedTools` with `cloud`
|
|
321
|
+
* throws a `ConfigurationError`.
|
|
322
|
+
*/
|
|
323
|
+
disallowedTools?: ToolName[];
|
|
239
324
|
/**
|
|
240
325
|
* Optional human-readable name for the agent, surfaced as the `title` in
|
|
241
326
|
* `Agent.list()` / `Agent.get()`. Cloud agents auto-generate a name from
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/agent/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,aAAa,EACd,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEpE,wCAAwC;AACxC,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,CAAC;AAE/C,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,QAAQ,GAChB;IACE,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAC/B,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAC/B,CAAC;AAEN,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;CACrB;AAED,MAAM,MAAM,eAAe,GACvB;IACE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,GACD;IAC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Ae,CAAC,CAAC;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gDAAgD;IAChD,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB"}
|
|
@@ -11,8 +11,12 @@ export interface UsageCost {
|
|
|
11
11
|
*/
|
|
12
12
|
chargedCents: number;
|
|
13
13
|
}
|
|
14
|
-
/** Token usage and cost for
|
|
14
|
+
/** Token usage and cost for one cloud run or local turn. */
|
|
15
15
|
export interface RunUsage {
|
|
16
|
+
/**
|
|
17
|
+
* The `run-<uuid>` run ID for a cloud agent, or the turn's usage UUID for a
|
|
18
|
+
* local agent. This is also the value accepted by `GetUsageOptions.runId`.
|
|
19
|
+
*/
|
|
16
20
|
runId: string;
|
|
17
21
|
usage: TokenUsage;
|
|
18
22
|
/** Absent when the backend does not report cost yet. */
|
|
@@ -23,10 +27,15 @@ export interface RunUsage {
|
|
|
23
27
|
* `Agent.getUsage(agentId)`.
|
|
24
28
|
*/
|
|
25
29
|
export interface AgentUsage {
|
|
26
|
-
/**
|
|
30
|
+
/** Total billed token usage for the whole agent. */
|
|
27
31
|
usage: TokenUsage;
|
|
28
|
-
/**
|
|
32
|
+
/** Total billed cost for the whole agent. Absent when not yet reported. */
|
|
29
33
|
cost?: UsageCost;
|
|
34
|
+
/**
|
|
35
|
+
* Per-run entries for cloud agents. Local agent entries are per-turn groups
|
|
36
|
+
* keyed by usage UUID. Local events without a usage UUID count toward
|
|
37
|
+
* `usage` and `cost` only, so the totals can exceed the sum of these entries.
|
|
38
|
+
*/
|
|
30
39
|
runs: RunUsage[];
|
|
31
40
|
}
|
|
32
41
|
/** Per-turn or cumulative token counts. `totalTokens` excludes `reasoningTokens` (a subset of output). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage-types.d.ts","sourceRoot":"","sources":["../../../src/agent/usage-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,iEAAiE;IACjE,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,
|
|
1
|
+
{"version":3,"file":"usage-types.d.ts","sourceRoot":"","sources":["../../../src/agent/usage-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,iEAAiE;IACjE,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,4DAA4D;AAC5D,MAAM,WAAW,QAAQ;IACvB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,UAAU,CAAC;IAClB,wDAAwD;IACxD,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,oDAAoD;IACpD,KAAK,EAAE,UAAU,CAAC;IAClB,2EAA2E;IAC3E,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;;;OAIG;IACH,IAAI,EAAE,QAAQ,EAAE,CAAC;CAClB;AAED,0GAA0G;AAC1G,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,kGAAkG;AAClG,wBAAgB,YAAY,CAC1B,KAAK,EAAE,cAAc,GAAG,SAAS,GAChC,UAAU,GAAG,SAAS,CAoBxB;AAED,8EAA8E;AAC9E,wBAAgB,aAAa,CAC3B,MAAM,EAAE,aAAa,CAAC,cAAc,GAAG,SAAS,CAAC,GAChD,UAAU,GAAG,SAAS,CAoCxB"}
|
package/dist/cjs/agent.d.ts
CHANGED
|
@@ -18,13 +18,19 @@ export interface SDKAgent {
|
|
|
18
18
|
listArtifacts(): Promise<import("./artifacts.js").SDKArtifact[]>;
|
|
19
19
|
downloadArtifact(path: string): Promise<Buffer>;
|
|
20
20
|
/**
|
|
21
|
-
* Fetch billed token usage and dollar cost for this agent
|
|
22
|
-
*
|
|
21
|
+
* Fetch billed token usage and dollar cost for this agent. Cloud agents
|
|
22
|
+
* return a per-run breakdown. Local agents return a per-turn breakdown whose
|
|
23
|
+
* entries are keyed by usage UUID.
|
|
23
24
|
*/
|
|
24
25
|
getUsage(options?: GetUsageOptions): Promise<AgentUsage>;
|
|
25
26
|
}
|
|
26
27
|
export interface GetUsageOptions {
|
|
27
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Restrict the result to one cloud run or local turn. For cloud agents, pass
|
|
30
|
+
* a `run-<uuid>` run ID. For local agents, pass a usage UUID from a previous
|
|
31
|
+
* `getUsage().runs[].runId`; client-side `run-<uuid>` labels throw a
|
|
32
|
+
* `ConfigurationError`.
|
|
33
|
+
*/
|
|
28
34
|
runId?: string;
|
|
29
35
|
}
|
|
30
36
|
export interface SendOptions {
|
|
@@ -151,7 +157,7 @@ export interface AgentMessage {
|
|
|
151
157
|
* - `cwd` is used when routing to the local store (defaults to `process.cwd()`).
|
|
152
158
|
* - `store` overrides the module default from `Cursor.configure({ local: { store } })`.
|
|
153
159
|
* - `apiKey` is used when routing to the cloud API (falls back to
|
|
154
|
-
* `process.env.CURSOR_API_KEY`).
|
|
160
|
+
* `process.env.CURSOR_API_KEY`, then the stored `Cursor.auth.login()` key).
|
|
155
161
|
*/
|
|
156
162
|
export interface GetAgentOptions {
|
|
157
163
|
cwd?: string;
|
|
@@ -166,7 +172,7 @@ export interface AgentOperationOptions {
|
|
|
166
172
|
/**
|
|
167
173
|
* Options for cloud-only account/catalog operations (Cursor.me, Cursor.models.list,
|
|
168
174
|
* Cursor.repositories.list). If `apiKey` is omitted, falls back to
|
|
169
|
-
* `process.env.CURSOR_API_KEY
|
|
175
|
+
* `process.env.CURSOR_API_KEY`, then the stored `Cursor.auth.login()` key.
|
|
170
176
|
*/
|
|
171
177
|
export interface CursorRequestOptions {
|
|
172
178
|
apiKey?: string;
|
package/dist/cjs/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/agent/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,cAAc,EACd,cAAc,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,CAAC;IAC3C,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5E,KAAK,IAAI,IAAI,CAAC;IACd,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,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MAAM,CAAC;IACvB,mEAAmE;IACnE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0DAA0D;IAC1D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,aAAa,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../src/agent/analytics.ts"],"names":[],"mappings":"AAIA,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EACV,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,EAEvB,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,UAAU,EACX,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../src/agent/analytics.ts"],"names":[],"mappings":"AAIA,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EACV,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,EAEvB,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,UAAU,EACX,MAAM,gCAAgC,CAAC;AAKxC,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AA6FvE;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,GAAE,MAAa,GACvB,OAAO,CAAC,IAAI,CAAC,CAGf;AAGD,wBAAgB,wBAAwB,IAAI,IAAI,CAE/C;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,KAAK,EAAE,kBAAkB,GACxB,IAAI,CAEN;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,KAAK,EAAE,oBAAoB,GAC1B,IAAI,CAEN;AAED,wBAAgB,uBAAuB,CAAC,EACtC,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,cAAc,CAAC;CACvB,GAAG,IAAI,CAYP;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,KAAK,EAAE,sBAAsB,GAC5B,IAAI,CAEN;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,KAAK,EAAE,uBAAuB,GAC7B,IAAI,CAEN;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,KAAK,EAAE,uBAAuB,GAC7B,IAAI,CAEN;AAMD,YAAY,EACV,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,UAAU,EACV,aAAa,GACd,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credentials persisted by `Cursor.auth.login()`.
|
|
3
|
+
*
|
|
4
|
+
* Deliberately holds the minted user API key rather than the login session
|
|
5
|
+
* tokens: the API key is the narrower credential (it can expire, is visible
|
|
6
|
+
* and revocable in the dashboard's API-keys list, and is the only credential
|
|
7
|
+
* the SDK's surfaces accept), while the session token would grant the whole
|
|
8
|
+
* account. The session tokens are dropped as soon as the key is minted.
|
|
9
|
+
*/
|
|
10
|
+
export interface StoredSdkCredentials {
|
|
11
|
+
version: 1;
|
|
12
|
+
/** API base URL the key was minted against. Keys are backend-paired. */
|
|
13
|
+
backendUrl: string;
|
|
14
|
+
apiKey: string;
|
|
15
|
+
/** Epoch ms; absent when the key never expires. */
|
|
16
|
+
apiKeyExpiresAtMs?: number;
|
|
17
|
+
/** Email of the logged-in user, for `Cursor.auth.status()` display. */
|
|
18
|
+
email?: string;
|
|
19
|
+
createdAtMs: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Pluggable persistence for SDK login credentials. The default is
|
|
23
|
+
* {@link FileCredentialStore}; embedders (e.g. multi-tenant hosts holding one
|
|
24
|
+
* credential per end user) can implement their own.
|
|
25
|
+
*/
|
|
26
|
+
export interface SdkCredentialStore {
|
|
27
|
+
load(): Promise<StoredSdkCredentials | undefined>;
|
|
28
|
+
save(credentials: StoredSdkCredentials): Promise<void>;
|
|
29
|
+
clear(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/** Default on-disk location: `~/.cursor/sdk/auth.json`. */
|
|
32
|
+
export declare function getDefaultSdkAuthPath(): string;
|
|
33
|
+
/** Validate an untrusted parsed JSON value; undefined when foreign-shaped. */
|
|
34
|
+
export declare function parseStoredSdkCredentials(value: unknown): StoredSdkCredentials | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* JSON file store with owner-only permissions (0600 file / 0700 directory),
|
|
37
|
+
* re-asserted on every save so a pre-existing looser file or directory is
|
|
38
|
+
* tightened rather than trusted. A corrupt or foreign-shaped file loads as
|
|
39
|
+
* "logged out" rather than throwing, so a bad write never wedges the SDK.
|
|
40
|
+
*/
|
|
41
|
+
export declare class FileCredentialStore implements SdkCredentialStore {
|
|
42
|
+
private readonly filePath;
|
|
43
|
+
constructor(filePath?: string);
|
|
44
|
+
get path(): string;
|
|
45
|
+
load(): Promise<StoredSdkCredentials | undefined>;
|
|
46
|
+
save(credentials: StoredSdkCredentials): Promise<void>;
|
|
47
|
+
clear(): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
/** In-memory store for tests and hosts that must never touch disk. */
|
|
50
|
+
export declare class InMemoryCredentialStore implements SdkCredentialStore {
|
|
51
|
+
private credentials;
|
|
52
|
+
load(): Promise<StoredSdkCredentials | undefined>;
|
|
53
|
+
save(credentials: StoredSdkCredentials): Promise<void>;
|
|
54
|
+
clear(): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=credential-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential-store.d.ts","sourceRoot":"","sources":["../../../src/agent/auth/credential-store.ts"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,CAAC,CAAC;IACX,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,IAAI,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC;IAClD,IAAI,CAAC,WAAW,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,2DAA2D;AAC3D,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED,8EAA8E;AAC9E,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,GACb,oBAAoB,GAAG,SAAS,CAElC;AA2CD;;;;;GAKG;AACH,qBAAa,mBAAoB,YAAW,kBAAkB;IAC5D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAElC,YAAY,QAAQ,CAAC,EAAE,MAAM,EAE5B;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAEK,IAAI,IAAI,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAYtD;IAEK,IAAI,CAAC,WAAW,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkB3D;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;CACF;AAED,sEAAsE;AACtE,qBAAa,uBAAwB,YAAW,kBAAkB;IAChE,OAAO,CAAC,WAAW,CAAmC;IAEhD,IAAI,IAAI,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAEtD;IAEK,IAAI,CAAC,WAAW,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3D;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;CACF"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-login handshake primitives for the SDK.
|
|
3
|
+
*
|
|
4
|
+
* This is the same PKCE-style flow the Cursor CLI uses (see
|
|
5
|
+
* `@anysphere/cursor-config`'s `LoginManager`): generate a random `verifier`,
|
|
6
|
+
* derive a `challenge` = base64url(sha256(verifier)), and send the user's
|
|
7
|
+
* browser to the portal's `/loginDeepControl` page with the challenge and a
|
|
8
|
+
* one-time `uuid`. The browser session completes the login and posts the
|
|
9
|
+
* challenge back to the backend; meanwhile the SDK polls `/auth/poll` with the
|
|
10
|
+
* `verifier` until the backend releases the session tokens. Only the process
|
|
11
|
+
* that generated the verifier can redeem the login.
|
|
12
|
+
*
|
|
13
|
+
* Reimplemented here (rather than importing `@anysphere/cursor-config`)
|
|
14
|
+
* because the public SDK bundle must stay free of that package's heavy
|
|
15
|
+
* dependency tree; the flow itself is ~100 lines against stable endpoints.
|
|
16
|
+
*/
|
|
17
|
+
/** Session tokens released by the backend once the browser login completes. */
|
|
18
|
+
export interface SdkLoginTokens {
|
|
19
|
+
accessToken: string;
|
|
20
|
+
refreshToken: string;
|
|
21
|
+
}
|
|
22
|
+
export interface LoginHandshake {
|
|
23
|
+
/** One-time login id, shared between the browser page and the poll. */
|
|
24
|
+
uuid: string;
|
|
25
|
+
/** Secret proving this process initiated the login. Never leaves the host except via `/auth/poll`. */
|
|
26
|
+
verifier: string;
|
|
27
|
+
/** Browser URL that completes the login. */
|
|
28
|
+
loginUrl: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function stripTrailingSlashes(url: string): string;
|
|
31
|
+
/** Portal (website) base URL hosting the browser login page. */
|
|
32
|
+
export declare function resolveWebsiteUrl(url?: string): string;
|
|
33
|
+
/** API base URL serving `/auth/poll` and the Connect RPCs. */
|
|
34
|
+
export declare function resolveApiBaseUrl(url?: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Generate the login handshake. `redirectTarget=sdk` attributes the login to
|
|
37
|
+
* the SDK on the portal's confirmation and success pages.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createLoginHandshake(websiteUrl: string): LoginHandshake;
|
|
40
|
+
export interface PollLoginOptions {
|
|
41
|
+
apiUrl: string;
|
|
42
|
+
uuid: string;
|
|
43
|
+
verifier: string;
|
|
44
|
+
signal?: AbortSignal;
|
|
45
|
+
/** Notified once if the backend forces the GET fallback. */
|
|
46
|
+
onWarning?: (message: string) => void;
|
|
47
|
+
/** Test seams; production callers use the defaults. */
|
|
48
|
+
maxAttempts?: number;
|
|
49
|
+
baseDelayMs?: number;
|
|
50
|
+
maxDelayMs?: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Poll `/auth/poll` until the browser completes the login.
|
|
54
|
+
*
|
|
55
|
+
* **POST, with the verifier in the JSON body.** The verifier is redeemable:
|
|
56
|
+
* anyone holding it (plus the uuid) can complete the login and mint a durable
|
|
57
|
+
* user API key, so it must not reach a URL — not the backend's access log, not
|
|
58
|
+
* a proxy's request log, not shell history. `POST /auth/poll` exists for
|
|
59
|
+
* exactly this reason.
|
|
60
|
+
*
|
|
61
|
+
* A backend predating that route answers POST with a route-not-found 404;
|
|
62
|
+
* those get one sticky fallback to `GET /auth/poll?uuid=…&verifier=…` so the
|
|
63
|
+
* login still completes (with a warning, since that is the exposure POST
|
|
64
|
+
* removes) instead of mistaking an unserved verb for a pending login and
|
|
65
|
+
* hanging until the timeout.
|
|
66
|
+
*
|
|
67
|
+
* The backend returns 404 while the login is pending. Returns `null` on
|
|
68
|
+
* abort, timeout (~20 minutes with default settings), or after 3 consecutive
|
|
69
|
+
* non-404 errors.
|
|
70
|
+
*/
|
|
71
|
+
export declare function pollForLoginTokens(options: PollLoginOptions): Promise<SdkLoginTokens | null>;
|
|
72
|
+
//# sourceMappingURL=login-flow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login-flow.d.ts","sourceRoot":"","sources":["../../../src/agent/auth/login-flow.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AAEH,+EAA+E;AAC/E,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,sGAAsG;IACtG,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;CAClB;AAUD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,gEAAgE;AAChE,wBAAgB,iBAAiB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAItD;AAED,8DAA8D;AAC9D,wBAAgB,iBAAiB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAItD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,CAQvE;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAwDD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAmHhC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type SdkCredentialStore } from "./credential-store.js";
|
|
2
|
+
/** Default lifetime of the API key minted by a login: 90 days. */
|
|
3
|
+
export declare const DEFAULT_LOGIN_API_KEY_TTL_MS: number;
|
|
4
|
+
export interface SdkLoginOptions {
|
|
5
|
+
/**
|
|
6
|
+
* API base URL serving `/auth/poll` and the Connect RPCs. Defaults to
|
|
7
|
+
* `CURSOR_BACKEND_URL` then production. The minted key only works against
|
|
8
|
+
* this backend.
|
|
9
|
+
*/
|
|
10
|
+
backendUrl?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Website base URL hosting the browser login page. Defaults to
|
|
13
|
+
* `CURSOR_WEBSITE_URL` then production.
|
|
14
|
+
*/
|
|
15
|
+
websiteUrl?: string;
|
|
16
|
+
/**
|
|
17
|
+
* How to get the login URL in front of the user:
|
|
18
|
+
* - `true` (default): open the system browser when that is likely to work
|
|
19
|
+
* (skipped in SSH sessions or when `NO_OPEN_BROWSER` is set).
|
|
20
|
+
* - `false`: never open a browser; the host surfaces the URL itself via
|
|
21
|
+
* {@link onLoginUrl}.
|
|
22
|
+
* - a function: custom opener (e.g. an Electron shell or a QR renderer).
|
|
23
|
+
*/
|
|
24
|
+
openBrowser?: boolean | ((url: string) => void | Promise<void>);
|
|
25
|
+
/**
|
|
26
|
+
* Always invoked with the login URL before waiting, so hosts can display it.
|
|
27
|
+
* When this is omitted and no browser was opened, the URL is written to
|
|
28
|
+
* stderr so the login stays completable.
|
|
29
|
+
*/
|
|
30
|
+
onLoginUrl?: (url: string) => void;
|
|
31
|
+
/** Aborts the poll; `login` resolves by throwing an AuthenticationError. */
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
/**
|
|
34
|
+
* Where to persist the resulting credentials. Defaults to the on-disk
|
|
35
|
+
* {@link FileCredentialStore} (`~/.cursor/sdk/auth.json`). Pass `null` to
|
|
36
|
+
* skip persistence entirely and only receive the key in the result.
|
|
37
|
+
*/
|
|
38
|
+
store?: SdkCredentialStore | null;
|
|
39
|
+
/** Display name of the minted key in the dashboard's API-keys list. */
|
|
40
|
+
apiKeyName?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Lifetime of the minted key in ms, from now.
|
|
43
|
+
* Defaults to {@link DEFAULT_LOGIN_API_KEY_TTL_MS} (90 days).
|
|
44
|
+
*/
|
|
45
|
+
apiKeyTtlMs?: number;
|
|
46
|
+
}
|
|
47
|
+
export interface SdkLoginResult {
|
|
48
|
+
/** The minted user API key. Also persisted unless `store: null`. */
|
|
49
|
+
apiKey: string;
|
|
50
|
+
/** Email of the logged-in account, when the identity lookup succeeded. */
|
|
51
|
+
email?: string;
|
|
52
|
+
/** Epoch ms at which the minted key expires. */
|
|
53
|
+
apiKeyExpiresAtMs: number;
|
|
54
|
+
}
|
|
55
|
+
export type SdkAuthStatus = {
|
|
56
|
+
status: "logged-out";
|
|
57
|
+
} | {
|
|
58
|
+
status: "logged-in";
|
|
59
|
+
backendUrl: string;
|
|
60
|
+
email?: string;
|
|
61
|
+
apiKeyExpiresAtMs?: number;
|
|
62
|
+
};
|
|
63
|
+
export interface SdkAuthStatusOptions {
|
|
64
|
+
store?: SdkCredentialStore;
|
|
65
|
+
}
|
|
66
|
+
export interface SdkLogoutOptions {
|
|
67
|
+
store?: SdkCredentialStore;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Interactive end-user login for the SDK.
|
|
71
|
+
*
|
|
72
|
+
* Flow: generate a one-time challenge, send the user's browser to the portal
|
|
73
|
+
* login page, poll until the browser completes, then use the resulting
|
|
74
|
+
* session token once — to mint a named, expiring user API key — and drop it.
|
|
75
|
+
* The API key is persisted (by default to `~/.cursor/sdk/auth.json`) and
|
|
76
|
+
* returned; it is the credential all SDK operations use.
|
|
77
|
+
*/
|
|
78
|
+
export declare function sdkLogin(options?: SdkLoginOptions): Promise<SdkLoginResult>;
|
|
79
|
+
/**
|
|
80
|
+
* Forget the stored login. Local-only: the minted key stays valid until its
|
|
81
|
+
* expiry unless revoked from the dashboard's API-keys page.
|
|
82
|
+
*/
|
|
83
|
+
export declare function sdkLogout(options?: SdkLogoutOptions): Promise<void>;
|
|
84
|
+
/** Report whether a stored, unexpired login exists. Never returns the key. */
|
|
85
|
+
export declare function sdkAuthStatus(options?: SdkAuthStatusOptions): Promise<SdkAuthStatus>;
|
|
86
|
+
//# sourceMappingURL=login.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/agent/auth/login.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,kBAAkB,EAExB,MAAM,uBAAuB,CAAC;AAW/B,kEAAkE;AAClE,eAAO,MAAM,4BAA4B,EAAE,MAAiC,CAAC;AAE7E,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAChE;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,4EAA4E;IAC5E,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;;OAIG;IACH,KAAK,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAClC,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,oEA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