@cursor/sdk 1.0.17 → 1.0.19
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/18.js +1 -0
- package/dist/cjs/19.js +1 -0
- package/dist/cjs/343.js +1 -0
- package/dist/cjs/400.js +1 -0
- package/dist/cjs/403.js +8 -0
- package/dist/cjs/618.js +1 -0
- package/dist/cjs/642.js +1 -0
- package/dist/cjs/656.js +1 -0
- package/dist/cjs/730.js +1 -0
- package/dist/cjs/796.js +1 -0
- package/dist/cjs/856.js +1 -0
- package/dist/cjs/914.js +1 -0
- package/dist/cjs/986.js +1 -0
- package/dist/cjs/996.js +1 -0
- package/dist/cjs/agent/options.d.ts +242 -0
- package/dist/cjs/agent/options.d.ts.map +1 -0
- package/dist/cjs/agent/run-event-notifier-api.d.ts +120 -0
- package/dist/cjs/agent/run-event-notifier-api.d.ts.map +1 -0
- package/dist/cjs/agent/run-store-public-types.d.ts +178 -0
- package/dist/cjs/agent/run-store-public-types.d.ts.map +1 -0
- package/dist/cjs/agent/store/local-agent-record-conversion.d.ts +7 -0
- package/dist/cjs/agent/store/local-agent-record-conversion.d.ts.map +1 -0
- package/dist/cjs/agent/store/local-agent-store.d.ts +289 -0
- package/dist/cjs/agent/store/local-agent-store.d.ts.map +1 -0
- package/dist/cjs/agent/store/sdk-state-root.d.ts +6 -0
- package/dist/cjs/agent/store/sdk-state-root.d.ts.map +1 -0
- package/dist/cjs/agent/store/sqlite-local-agent-store.d.ts +30 -0
- package/dist/cjs/agent/store/sqlite-local-agent-store.d.ts.map +1 -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 -8
- package/dist/cjs/local-executor.d.ts +3 -0
- package/dist/cjs/local-executor.d.ts.map +1 -1
- package/dist/cjs/options.d.ts +64 -3
- package/dist/cjs/options.d.ts.map +1 -1
- package/dist/cjs/platform.d.ts +3 -0
- package/dist/cjs/platform.d.ts.map +1 -1
- package/dist/cjs/public-api.d.ts +3 -3
- 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/safe-connect-transport.d.ts +9 -0
- package/dist/cjs/safe-connect-transport.d.ts.map +1 -0
- package/dist/cjs/safe-node-http-client.d.ts +11 -0
- package/dist/cjs/safe-node-http-client.d.ts.map +1 -0
- package/dist/cjs/sdk-config.d.ts +2 -1
- package/dist/cjs/sdk-config.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/sqlite.d.ts +8 -0
- package/dist/cjs/sqlite.d.ts.map +1 -0
- package/dist/cjs/sqlite.js +1 -0
- package/dist/cjs/store/index.d.ts +1 -2
- package/dist/cjs/store/index.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/cjs/store/open-default-local-agent-store.d.ts +4 -0
- package/dist/cjs/store/open-default-local-agent-store.d.ts.map +1 -0
- package/dist/cjs/store/sqlite-local-agent-store.d.ts.map +1 -1
- package/dist/cjs/store/sqlite-storage-unavailable.d.ts +6 -0
- package/dist/cjs/store/sqlite-storage-unavailable.d.ts.map +1 -0
- package/dist/cjs/transport.d.ts +47 -0
- package/dist/cjs/transport.d.ts.map +1 -0
- package/dist/esm/18.js +1 -0
- package/dist/esm/19.js +1 -0
- package/dist/esm/343.js +1 -0
- package/dist/esm/357.js +1 -0
- package/dist/esm/400.js +1 -0
- package/dist/esm/403.js +8 -0
- package/dist/esm/642.js +1 -0
- package/dist/esm/656.js +1 -0
- package/dist/esm/730.js +1 -0
- package/dist/esm/856.js +1 -0
- package/dist/esm/914.js +1 -0
- package/dist/esm/986.js +1 -0
- package/dist/esm/988.js +1 -0
- package/dist/esm/996.js +1 -0
- package/dist/esm/agent/options.d.ts +242 -0
- package/dist/esm/agent/options.d.ts.map +1 -0
- package/dist/esm/agent/run-event-notifier-api.d.ts +120 -0
- package/dist/esm/agent/run-event-notifier-api.d.ts.map +1 -0
- package/dist/esm/agent/run-store-public-types.d.ts +178 -0
- package/dist/esm/agent/run-store-public-types.d.ts.map +1 -0
- package/dist/esm/agent/store/local-agent-record-conversion.d.ts +7 -0
- package/dist/esm/agent/store/local-agent-record-conversion.d.ts.map +1 -0
- package/dist/esm/agent/store/local-agent-store.d.ts +289 -0
- package/dist/esm/agent/store/local-agent-store.d.ts.map +1 -0
- package/dist/esm/agent/store/sdk-state-root.d.ts +6 -0
- package/dist/esm/agent/store/sdk-state-root.d.ts.map +1 -0
- package/dist/esm/agent/store/sqlite-local-agent-store.d.ts +30 -0
- package/dist/esm/agent/store/sqlite-local-agent-store.d.ts.map +1 -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 -8
- package/dist/esm/local-executor.d.ts +3 -0
- package/dist/esm/local-executor.d.ts.map +1 -1
- package/dist/esm/options.d.ts +64 -3
- package/dist/esm/options.d.ts.map +1 -1
- package/dist/esm/platform.d.ts +3 -0
- package/dist/esm/platform.d.ts.map +1 -1
- package/dist/esm/public-api.d.ts +3 -3
- 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/safe-connect-transport.d.ts +9 -0
- package/dist/esm/safe-connect-transport.d.ts.map +1 -0
- package/dist/esm/safe-node-http-client.d.ts +11 -0
- package/dist/esm/safe-node-http-client.d.ts.map +1 -0
- package/dist/esm/sdk-config.d.ts +2 -1
- package/dist/esm/sdk-config.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/sqlite.d.ts +8 -0
- package/dist/esm/sqlite.d.ts.map +1 -0
- package/dist/esm/sqlite.js +1 -0
- package/dist/esm/store/index.d.ts +1 -2
- package/dist/esm/store/index.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/dist/esm/store/open-default-local-agent-store.d.ts +4 -0
- package/dist/esm/store/open-default-local-agent-store.d.ts.map +1 -0
- package/dist/esm/store/sqlite-local-agent-store.d.ts.map +1 -1
- package/dist/esm/store/sqlite-storage-unavailable.d.ts +6 -0
- package/dist/esm/store/sqlite-storage-unavailable.d.ts.map +1 -0
- package/dist/esm/transport.d.ts +47 -0
- package/dist/esm/transport.d.ts.map +1 -0
- package/package.json +23 -23
- package/dist/cjs/642.index.js +0 -1
- package/dist/esm/642.index.js +0 -1
- /package/dist/cjs/{index.js.LICENSE.txt → 403.js.LICENSE.txt} +0 -0
- /package/dist/esm/{index.js.LICENSE.txt → 403.js.LICENSE.txt} +0 -0
package/dist/esm/642.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const __webpack_esm_id__=642;export const __webpack_esm_ids__=[642];export const __webpack_esm_modules__={"./src/agent/cloud-agent.ts"(t,e,i){i.d(e,{archiveCloudAgent:()=>K,cancelCloudRun:()=>x,createCloudAgent:()=>O,deleteCloudAgent:()=>q,getCloudAgent:()=>E,getCloudMe:()=>T,getCloudRun:()=>N,listCloudAgents:()=>k,listCloudModels:()=>U,listCloudRepositories:()=>L,listCloudRuns:()=>M,resumeCloudAgent:()=>A,unarchiveCloudAgent:()=>P,validateCloudModelAvailability:()=>j}),i.r(e);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 p(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 y(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=y(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 p=t.body.getReader(),_=new TextDecoder;let S="";try{for(;;){if(null==s?void 0:s.aborted)return;const{value:t,done:R}=yield p.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 p.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,y(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 p.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 p.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(y(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(y(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,p,y,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,k=null!==(n=null==e?void 0:e.mcpServers)&&void 0!==n?n:this.options.mcpServers,M=null!==(o=null==e?void 0:e.model)&&void 0!==o?o:this._model,N=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!==M?{model:M}:{}),void 0!==this.options.name?{name:this.options.name}:{}),{mcpServers:a(k)}),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!==N?{mode:N}:{}),{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,M)}else{const t=yield this.client.createRun(this.agentId,Object.assign(Object.assign({prompt:j,mcpServers:a(k)},void 0!==(null==e?void 0:e.model)?{model:e.model}:{}),void 0!==N?{mode:N}:{}),{idempotencyKey:null==e?void 0:e.idempotencyKey});D=new R(this.client,t.run,x,M)}void 0!==(null==e?void 0:e.model)&&(this._model=e.model);const E=null!==(w=null===(y=null===(p=this.options.cloud)||void 0===p?void 0:p.env)||void 0===y?void 0:y.type)&&void 0!==w?w:"cloud",K=null==M?void 0:M.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==M?void 0:M.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!=k?k:{}).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 k(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 M(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 N(t,e){return h(this,void 0,void 0,(function*(){p(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*(){p(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}))}}};
|
package/dist/esm/656.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const __webpack_esm_id__=656;export const __webpack_esm_ids__=[656];export const __webpack_esm_modules__={"../cursor-sdk-local-runtime/dist/run-store/sqlite-run-event-store.js"(e,n,t){t.d(n,{SqliteRunEventStore:()=>d});var r=t("node:fs"),s=t("node:path"),i=t("../cursor-sdk-local-runtime/dist/run-store/sqlite/open-sqlite-driver.js");function o(e){return{runId:e.run_id,seq:e.seq,offset:e.offset,eventType:e.event_type,payload:e.payload_json?JSON.parse(e.payload_json):null,payloadRef:e.payload_ref,idempotencyKey:e.idempotency_key,createdAt:new Date(e.created_at)}}class d{options;driverPromise;disposed=!1;static async open(e){const n=new d(e);return await n.getDriver(),n}constructor(e){this.options=e}get dbPath(){return(0,s.join)(this.options.stateRoot,"index.db")}async appendRunEvent(e){var n,t,r,s,i,d;const a=await this.getDriver();a.exec("BEGIN IMMEDIATE");try{const u=null!==(n=e.idempotencyKey)&&void 0!==n?n:null;if(u){const n=a.get("SELECT *\n FROM run_events\n WHERE run_id = ? AND idempotency_key = ?\n LIMIT 1",[e.runId,u]);if(n)return a.exec("COMMIT"),o(n)}const l=a.get("SELECT MAX(seq) as max_seq FROM run_events WHERE run_id = ?",[e.runId]),c=(null!==(t=null==l?void 0:l.max_seq)&&void 0!==t?t:0)+1,_=String(c),v=(new Date).toISOString();return a.run("INSERT INTO run_events (\n run_id, seq, offset, event_type, payload_json, payload_ref, idempotency_key, created_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",[e.runId,c,_,e.eventType,JSON.stringify(null!==(r=e.payload)&&void 0!==r?r:null),null!==(s=e.payloadRef)&&void 0!==s?s:null,u,v]),a.exec("COMMIT"),{runId:e.runId,seq:c,offset:_,eventType:e.eventType,payload:null!==(i=e.payload)&&void 0!==i?i:null,payloadRef:null!==(d=e.payloadRef)&&void 0!==d?d:null,idempotencyKey:u,createdAt:new Date(v)}}catch(e){try{a.exec("ROLLBACK")}catch(e){}throw e}}async listRunEvents(e){var n,t;const r=await this.getDriver(),s=function(e){if(!e)return 0;if(!/^\d+$/.test(e))throw new Error(`Invalid run event offset ${e}`);const n=Number.parseInt(e,10);if(!Number.isFinite(n)||n<0)throw new Error(`Invalid run event offset ${e}`);return n}(e.afterOffset),i=null!==(t=e.limit)&&void 0!==t?t:100,d=r.all("SELECT *\n FROM run_events\n WHERE run_id = ? AND seq > ?\n ORDER BY seq ASC\n LIMIT ?",[e.runId,s,i+1]),a=d.length>i,u=d.slice(0,i).map(o);return Object.assign({events:u},a&&u.length>0?{nextOffset:null===(n=u[u.length-1])||void 0===n?void 0:n.offset}:{})}async deleteRunEvents(e){(await this.getDriver()).run("DELETE FROM run_events WHERE run_id = ?",[e.runId])}async dispose(){if(this.disposed=!0,!this.driverPromise)return;const e=await this.driverPromise.catch((()=>{}));e&&e.close(),this.driverPromise=void 0}async getDriver(){if(this.disposed)throw new Error("SqliteRunEventStore has been disposed");if(this.driverPromise)return this.driverPromise;const e=(async()=>{const e=(0,s.dirname)(this.dbPath);(0,r.existsSync)(e)||(0,r.mkdirSync)(e,{recursive:!0});const n=await(0,i.d)(this.dbPath);try{!function(e){e.exec("PRAGMA journal_mode = WAL;\n PRAGMA synchronous = NORMAL;\n PRAGMA busy_timeout = 5000;\n PRAGMA foreign_keys = ON;\n CREATE TABLE IF NOT EXISTS run_events (\n run_id TEXT NOT NULL,\n seq INTEGER NOT NULL,\n offset TEXT NOT NULL,\n event_type TEXT NOT NULL,\n payload_json TEXT,\n payload_ref TEXT,\n idempotency_key TEXT,\n created_at TEXT NOT NULL,\n PRIMARY KEY (run_id, seq),\n UNIQUE(run_id, offset)\n );");e.all("PRAGMA table_info(run_events)").some((e=>"idempotency_key"===e.name))||e.exec("ALTER TABLE run_events ADD COLUMN idempotency_key TEXT"),e.exec("CREATE UNIQUE INDEX IF NOT EXISTS run_events_idempotency_key_idx\n ON run_events (run_id, idempotency_key)\n WHERE idempotency_key IS NOT NULL")}(n)}catch(e){throw n.close(),e}return n})().catch((n=>{throw this.driverPromise===e&&(this.driverPromise=void 0),n}));return this.driverPromise=e,e}}},"../cursor-sdk-local-runtime/dist/run-store/sqlite/open-sqlite-driver.js"(e,n,t){t.d(n,{d:()=>s});class r extends Error{constructor(e,n){super(e,n),this.name="NoSqliteDriverError"}}async function s(e){if(void 0!==globalThis.Bun)return(await t.e(914).then(t.bind(t,"../cursor-sdk-local-runtime/dist/run-store/sqlite/bun-sqlite-driver.js"))).openBunSqliteDriver(e);let n;try{n=await t.e(343).then(t.bind(t,"../cursor-sdk-local-runtime/dist/run-store/sqlite/node-sqlite-driver.js"))}catch(e){if(function(e){return"ERR_UNKNOWN_BUILTIN_MODULE"===("object"==typeof e&&null!==e&&"code"in e&&"string"==typeof e.code?e.code:void 0)||(e instanceof Error?e.message.toLowerCase():String(e).toLowerCase()).includes("node:sqlite")}(e))throw new r("node:sqlite is not available in this runtime. The default local agent store requires Node >= 22.13 (or another runtime that implements node:sqlite). Configure a JsonlLocalAgentStore instead.",{cause:e});throw e}return n.openNodeSqliteDriver(e)}}};
|
package/dist/esm/730.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const __webpack_esm_id__=730;export const __webpack_esm_ids__=[730];export const __webpack_esm_modules__={"../cursor-sdk-local-runtime/dist/run-store/agent-checkpoint-store.js"(t,e,s){s.d(e,{LocalAgentCheckpointStore:()=>l});var o=s("node:crypto?8af2"),r=s("node:fs/promises"),a=s("node:path"),i=s("../agent-kv/dist/index.js"),n=s("../context/dist/index.js"),c=s("../cursor-sdk-local-runtime/dist/run-store/private-directory.js");class l{options;stores=new Map;constructor(t){this.options=t}async loadLatest(t){const{agentStore:e}=await this.getOrCreate(t),s=e.getMetadata("latestRootBlobId");return s&&0!==s.length?(await e.resetFromDb((0,n.q6)()),e.getConversationStateStructure()):null}async saveCheckpoint(t,e){const{agentStore:s}=await this.getOrCreate(t);return await s.handleCheckpoint((0,n.q6)(),e),{blobId:(0,i.nj)(s.getMetadata("latestRootBlobId")),storeKind:"local-sqlite"}}async getBlobStore(t){return(await this.getOrCreate(t)).sqliteStore}async listCheckpointBlobIds(t){const{sqliteStore:e}=await this.getOrCreate(t);return e.listBlobIds()}async getFullConversation(t){const{agentStore:e}=await this.getOrCreate(t);return await e.resetFromDb((0,n.q6)()),e.getFullConversation((0,n.q6)())}async dispose(){const t=[...this.stores.values()];this.stores.clear();const e=await Promise.allSettled(t);await Promise.all(e.filter((t=>"fulfilled"===t.status)).map((t=>t.value.sqliteStore.dispose())))}async deleteAgent(t){const e=this.stores.get(t);if(e){this.stores.delete(t);const s=await e.catch((()=>{}));s&&await s.sqliteStore.dispose().catch((()=>{}))}const s=(0,a.join)(this.options.stateRoot,"agents",d(t));await(0,r.rm)(s,{recursive:!0,force:!0})}async getOrCreate(t){const e=this.stores.get(t);if(e)return e;let s;return s=this.createEntry(t).catch((e=>{throw this.stores.get(t)===s&&this.stores.delete(t),e})),this.stores.set(t,s),s}async createEntry(t){const e=(0,a.join)(this.options.stateRoot,"agents"),o=(0,a.join)(e,d(t));(0,c.V)(this.options.stateRoot),(0,c.V)(e),(0,c.V)(o);const{SQLiteBlobStoreWithMetadata:r}=await s.e(18).then(s.bind(s,"../cursor-sdk-local-runtime/dist/run-store/sqlite-blob-store.js")),l=await r.initAndLoad((0,a.join)(o,"store.db"));try{l.set("agentId",t);const e=new i.pH(l,l);return await e.resetFromDb((0,n.q6)()),{sqliteStore:l,agentStore:e}}catch(t){throw await l.dispose().catch((()=>{})),t}}}function d(t){return`agent-${(0,o.createHash)("sha256").update(t).digest("hex")}`}},"../cursor-sdk-local-runtime/dist/run-store/private-directory.js"(t,e,s){s.d(e,{V:()=>r});var o=s("node:fs");function r(t){(0,o.existsSync)(t)||(0,o.mkdirSync)(t,{recursive:!0,mode:448});try{(0,o.chmodSync)(t,448)}catch(t){}}}};
|
package/dist/esm/856.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const __webpack_esm_id__=856;export const __webpack_esm_ids__=[856];export const __webpack_esm_modules__={"../cursor-sdk-local-runtime/dist/run-store/id.js"(t,e,n){n.d(e,{M2:()=>a,WQ:()=>s,nq:()=>i});var r=n("node:crypto?8af2");function s(){return`agent-${(0,r.randomUUID)()}`}function a(){return`bc-${(0,r.randomUUID)()}`}function i(){return`run-${(0,r.randomUUID)()}`}},"../cursor-sdk-local-runtime/dist/run-store/private-directory.js"(t,e,n){n.d(e,{V:()=>s});var r=n("node:fs");function s(t){(0,r.existsSync)(t)||(0,r.mkdirSync)(t,{recursive:!0,mode:448});try{(0,r.chmodSync)(t,448)}catch(t){}}},"../cursor-sdk-local-runtime/dist/run-store/sqlite-agent-run-store.js"(t,e,n){n.d(e,{SqliteAgentRunStore:()=>R});var r=n("node:path"),s=n("../cursor-sdk-local-runtime/dist/run-store/id.js"),a=n("../cursor-sdk-local-runtime/dist/run-store/private-directory.js"),i=n("../cursor-sdk-local-runtime/dist/run-store/sqlite/open-sqlite-driver.js"),o=n("../cursor-sdk-local-runtime/dist/run-store/status.js");function u(t){if(0===t.length)return[];const e=[];for(let n=0;n<t.length;n+=100)e.push(t.slice(n,n+100));return e}function d(){return(new Date).toISOString()}function l(t){return t?new Date(t):null}function c(t,e){return t?JSON.parse(t):e}function _(t){return JSON.stringify(t)}function E(t){return t?_(t):null}function g(t){const e=null==t?void 0:t.params;return e&&e.length>0?_(e):null}function h(t){return{agentId:t.agent_id,workspaceRef:t.workspace_ref,status:t.status,activeRunId:t.active_run_id,latestCheckpointRef:c(t.latest_checkpoint_ref_json,null),name:t.name,createdAt:new Date(t.created_at),updatedAt:new Date(t.updated_at),metadata:c(t.metadata_json,{})}}function m(t){return{runId:t.run_id,requestId:t.request_id,agentId:t.agent_id,turnNumber:t.turn_number,status:t.status,model:(e=t.model,n=t.model_params_json,null===e?null:null===n?{id:e}:{id:e,params:c(n,[])}),startCheckpointRef:c(t.start_checkpoint_ref_json,null),latestCheckpointRef:c(t.latest_checkpoint_ref_json,null),errorCode:t.error_code,usageRef:t.usage_ref,result:t.result,createdAt:new Date(t.created_at),updatedAt:new Date(t.updated_at),startedAt:l(t.started_at),finishedAt:l(t.finished_at),cancelledAt:l(t.cancelled_at),expiredAt:l(t.expired_at)};var e,n}function T(t){var e;const n=null!==(e=null==t?void 0:t.limit)&&void 0!==e?e:50,r=(null==t?void 0:t.cursor)?Number.parseInt(t.cursor,10):0;return{limit:n,offset:Number.isFinite(r)&&r>0?r:0}}class R{options;driverPromise;disposed=!1;static async open(t){const e=new R(t);return await e.getDriver(),e}constructor(t){this.options=t}get stateRoot(){return this.options.stateRoot}get dbPath(){return(0,r.join)(this.options.stateRoot,"index.db")}async createAgent(t){const e=await this.getDriver();return f(e,(()=>{var n,r,a,i,o,u;const l=null!==(r=t.agentId)&&void 0!==r?r:(0,s.WQ)(),c=(0,s.nq)(),E=d();e.run("INSERT INTO agents (\n agent_id, workspace_ref, status, active_run_id,\n latest_checkpoint_ref_json, name,\n metadata_json, created_at, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",[l,t.workspaceRef,"IDLE",c,null,null!==(a=t.name)&&void 0!==a?a:null,_(null!==(i=t.metadata)&&void 0!==i?i:{}),E,E]),e.run("INSERT INTO runs (\n run_id, request_id, agent_id, turn_number, status, model, model_params_json,\n start_checkpoint_ref_json, latest_checkpoint_ref_json,\n error_code, usage_ref, result,\n created_at, updated_at, started_at, finished_at,\n cancelled_at, expired_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",[c,null!==(o=t.requestId)&&void 0!==o?o:null,l,1,"QUEUED",null!==(u=null===(n=t.model)||void 0===n?void 0:n.id)&&void 0!==u?u:null,g(t.model),null,null,null,null,null,E,E,null,null,null,null]);const h=this.getAgentFromDb(e,l),m=this.getRunFromDb(e,l,c);if(!h||!m)throw new Error(`Failed to create agent ${l}`);return{agent:h,run:m}}))}async createFollowUpRun(t,e){const n=await this.getDriver();return f(n,(()=>{var r,a,i,u;const l=this.getAgentFromDb(n,t);if(!l)throw new Error(`Agent ${t} not found`);if("ARCHIVED"===l.status)throw new Error(`Cannot create follow-up run on archived agent ${t}. Unarchive it first.`);if(l.activeRunId){const e=this.getRunFromDb(n,t,l.activeRunId);if(e&&!(0,o.Qb)(e.status))throw new Error(`Agent ${t} already has active run`)}const c=n.get("SELECT COUNT(*) as count FROM runs WHERE agent_id = ?",[t]),_=(0,s.nq)(),h=d();n.run("INSERT INTO runs (\n run_id, request_id, agent_id, turn_number, status, model, model_params_json,\n start_checkpoint_ref_json, latest_checkpoint_ref_json,\n error_code, usage_ref, result,\n created_at, updated_at, started_at, finished_at,\n cancelled_at, expired_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",[_,null!==(a=e.requestId)&&void 0!==a?a:null,t,(null!==(i=null==c?void 0:c.count)&&void 0!==i?i:0)+1,"QUEUED",null!==(u=null===(r=e.model)||void 0===r?void 0:r.id)&&void 0!==u?u:null,g(e.model),E(l.latestCheckpointRef),l.latestCheckpointRef?E(l.latestCheckpointRef):null,null,null,null,h,h,null,null,null,null]),n.run("UPDATE agents SET active_run_id = ?, status = ?, updated_at = ? WHERE agent_id = ?",[_,"IDLE",h,t]);const m=this.getRunFromDb(n,t,_);if(!m)throw new Error(`Failed to create run ${_}`);return m}))}async listAgents(t){const e=await this.getDriver(),{limit:n,offset:r}=T(t),s=e.all("SELECT * FROM agents ORDER BY updated_at DESC LIMIT ? OFFSET ?",[n+1,r]),a=s.slice(0,n),i=s.length>n?String(r+n):void 0;return Object.assign({items:a.map(h)},i?{nextCursor:i}:{})}async getAgent(t){const e=await this.getDriver();return this.getAgentFromDb(e,t)}async listRuns(t,e){const n=await this.getDriver(),{limit:r,offset:s}=T(e),a=n.all("SELECT * FROM runs WHERE agent_id = ? ORDER BY turn_number ASC LIMIT ? OFFSET ?",[t,r+1,s]),i=a.slice(0,r),o=a.length>r?String(s+r):void 0;return Object.assign({items:i.map(m)},o?{nextCursor:o}:{})}async getRun(t,e){const n=await this.getDriver();return this.getRunFromDb(n,t,e)}async markRunStarting(t,e,n){const r=await this.getDriver();f(r,(()=>{var s;const a=this.requireRunFromDb(r,t,e);if((0,o.Qb)(a.status))throw new Error(`Cannot start terminal run ${e}`);const i=d();r.run("UPDATE runs SET request_id = COALESCE(?, request_id), status = ?, started_at = COALESCE(started_at, ?), updated_at = ? WHERE run_id = ? AND agent_id = ?",[null!==(s=null==n?void 0:n.requestId)&&void 0!==s?s:null,"RUNNING",i,i,e,t]),r.run("UPDATE agents\n SET active_run_id = ?,\n status = CASE\n WHEN status = 'ARCHIVED' THEN status\n ELSE 'RUNNING'\n END,\n updated_at = ?\n WHERE agent_id = ?",[e,i,t])}))}async patchCheckpoint(t,e,n){const r=await this.getDriver();f(r,(()=>{this.requireRunFromDb(r,t,e);const s=d();r.run("UPDATE runs\n SET latest_checkpoint_ref_json = ?,\n updated_at = ?\n WHERE run_id = ? AND agent_id = ?",[E(n),s,e,t]),r.run("UPDATE agents\n SET latest_checkpoint_ref_json = ?,\n updated_at = ?\n WHERE agent_id = ?",[E(n),s,t])}))}async markRunTerminal(t,e,n){const r=await this.getDriver();f(r,(()=>{var s,a,i;const u=this.requireRunFromDb(r,t,e);if((0,o.Qb)(u.status))return;const l=d();r.run("UPDATE runs\n SET status = ?,\n error_code = COALESCE(?, error_code),\n usage_ref = COALESCE(?, usage_ref),\n result = COALESCE(?, result),\n updated_at = ?,\n finished_at = CASE WHEN ? = 'FINISHED' THEN ? ELSE finished_at END,\n cancelled_at = CASE WHEN ? = 'CANCELLED' THEN ? ELSE cancelled_at END,\n expired_at = CASE WHEN ? = 'EXPIRED' THEN ? ELSE expired_at END\n WHERE run_id = ? AND agent_id = ?",[n.status,null!==(s=n.errorCode)&&void 0!==s?s:null,null!==(a=n.usageRef)&&void 0!==a?a:null,null!==(i=n.result)&&void 0!==i?i:null,l,n.status,l,n.status,l,n.status,l,e,t]),r.run("UPDATE agents\n SET active_run_id = NULL,\n status = CASE\n WHEN status = 'ARCHIVED' THEN status\n WHEN ? = 'ERROR' THEN 'ERROR'\n ELSE 'IDLE'\n END,\n updated_at = ?\n WHERE agent_id = ?",[n.status,l,t])}))}async cancelRun(t,e){await this.markRunTerminal(t,e,{status:"CANCELLED"})}async archiveAgent(t){const e=await this.getDriver();f(e,(()=>{if(!this.getAgentFromDb(e,t))throw new Error(`Agent ${t} not found`);const n=d();e.run("UPDATE agents SET status = 'ARCHIVED', updated_at = ? WHERE agent_id = ?",[n,t])}))}async unarchiveAgent(t){const e=await this.getDriver();f(e,(()=>{if(!this.getAgentFromDb(e,t))throw new Error(`Agent ${t} not found`);const n=d();e.run("UPDATE agents SET status = 'IDLE', updated_at = ? WHERE agent_id = ?",[n,t])}))}async deleteAgent(t){const e=await this.getDriver();f(e,(()=>{const n=this.getAgentFromDb(e,t);if(!n)throw new Error(`Agent ${t} not found`);if(n.activeRunId){const r=this.getRunFromDb(e,t,n.activeRunId);if(r&&!(0,o.Qb)(r.status))throw new Error(`Cannot delete agent ${t}: active run ${n.activeRunId} is not terminal. Call run.cancel() first.`)}e.run("DELETE FROM runs WHERE agent_id = ?",[t]),e.run("DELETE FROM agents WHERE agent_id = ?",[t])}))}async upsertAgentRecord(t){const e=await this.getDriver();f(e,(()=>{const n=this.getAgentFromDb(e,t.agentId),r=t.createdAt.toISOString(),s=t.updatedAt.toISOString();n?e.run("UPDATE agents SET\n workspace_ref = ?,\n status = ?,\n active_run_id = ?,\n latest_checkpoint_ref_json = ?,\n name = ?,\n metadata_json = ?,\n updated_at = ?\n WHERE agent_id = ?",[t.workspaceRef,t.status,t.activeRunId,E(t.latestCheckpointRef),t.name,_(t.metadata),s,t.agentId]):e.run("INSERT INTO agents (\n agent_id, workspace_ref, status, active_run_id,\n latest_checkpoint_ref_json, name,\n metadata_json, created_at, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",[t.agentId,t.workspaceRef,t.status,t.activeRunId,E(t.latestCheckpointRef),t.name,_(t.metadata),r,s])}))}async upsertRunRecord(t){const e=await this.getDriver();f(e,(()=>{var n,r,s,a,i,o,u,d,l,c,_;const h=this.getRunFromDb(e,t.agentId,t.runId),m=t.createdAt.toISOString(),T=t.updatedAt.toISOString(),R=null!==(o=null===(n=t.startedAt)||void 0===n?void 0:n.toISOString())&&void 0!==o?o:null,f=null!==(u=null===(r=t.finishedAt)||void 0===r?void 0:r.toISOString())&&void 0!==u?u:null,p=null!==(d=null===(s=t.cancelledAt)||void 0===s?void 0:s.toISOString())&&void 0!==d?d:null,v=null!==(l=null===(a=t.expiredAt)||void 0===a?void 0:a.toISOString())&&void 0!==l?l:null,A=[null!==(c=t.requestId)&&void 0!==c?c:null,t.turnNumber,t.status,null!==(_=null===(i=t.model)||void 0===i?void 0:i.id)&&void 0!==_?_:null,g(t.model),E(t.startCheckpointRef),E(t.latestCheckpointRef),t.errorCode,t.usageRef,t.result,T,R,f,p,v];h?e.run("UPDATE runs SET\n request_id = ?,\n turn_number = ?,\n status = ?,\n model = ?,\n model_params_json = ?,\n start_checkpoint_ref_json = ?,\n latest_checkpoint_ref_json = ?,\n error_code = ?,\n usage_ref = ?,\n result = ?,\n updated_at = ?,\n started_at = ?,\n finished_at = ?,\n cancelled_at = ?,\n expired_at = ?\n WHERE run_id = ? AND agent_id = ?",[...A,t.runId,t.agentId]):e.run("INSERT INTO runs (\n run_id, request_id, agent_id, turn_number, status, model, model_params_json,\n start_checkpoint_ref_json, latest_checkpoint_ref_json,\n error_code, usage_ref, result,\n created_at, updated_at, started_at, finished_at,\n cancelled_at, expired_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",[t.runId,...A.slice(0,1),t.agentId,...A.slice(1,10),m,...A.slice(10)])}))}async listAllAgentRecords(){return(await this.getDriver()).all("SELECT * FROM agents",[]).map(h)}async listAllRunRecords(t){const e=await this.getDriver();if(t&&t.length>0){const n=[];for(const r of u(t)){const t=r.map((()=>"?")).join(", "),s=e.all(`SELECT * FROM runs WHERE agent_id IN (${t})`,[...r]);n.push(...s.map(m))}return n}return e.all("SELECT * FROM runs",[]).map(m)}async deleteRunRecordsForAgents(t){if(0===t.length)return;const e=await this.getDriver();f(e,(()=>{for(const n of u(t)){const t=n.map((()=>"?")).join(", ");e.run(`DELETE FROM runs WHERE agent_id IN (${t})`,[...n])}}))}async deleteRunRecordsByKeys(t){if(0===t.length)return;const e=await this.getDriver();f(e,(()=>{for(const{agentId:n,runId:r}of t)e.run("DELETE FROM runs WHERE agent_id = ? AND run_id = ?",[n,r])}))}async dispose(){if(this.disposed=!0,!this.driverPromise)return;const t=await this.driverPromise.catch((()=>{}));t&&t.close(),this.driverPromise=void 0}async getDriver(){if(this.disposed)throw new Error("SqliteAgentRunStore has been disposed");if(this.driverPromise)return this.driverPromise;const t=(async()=>{const t=(0,r.dirname)(this.dbPath);(0,a.V)(t);const e=await(0,i.d)(this.dbPath);try{!function(t){t.exec("PRAGMA journal_mode = WAL;\n PRAGMA synchronous = NORMAL;\n PRAGMA busy_timeout = 5000;\n PRAGMA foreign_keys = ON;\n CREATE TABLE IF NOT EXISTS agents (\n agent_id TEXT PRIMARY KEY,\n workspace_ref TEXT NOT NULL,\n status TEXT NOT NULL,\n active_run_id TEXT,\n latest_checkpoint_ref_json TEXT,\n name TEXT,\n metadata_json TEXT NOT NULL DEFAULT '{}',\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL\n );\n CREATE TABLE IF NOT EXISTS runs (\n run_id TEXT PRIMARY KEY,\n request_id TEXT,\n agent_id TEXT NOT NULL REFERENCES agents(agent_id),\n turn_number INTEGER NOT NULL,\n status TEXT NOT NULL,\n model TEXT,\n model_params_json TEXT,\n start_checkpoint_ref_json TEXT,\n latest_checkpoint_ref_json TEXT,\n error_code TEXT,\n usage_ref TEXT,\n result TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n started_at TEXT,\n finished_at TEXT,\n cancelled_at TEXT,\n expired_at TEXT,\n UNIQUE(agent_id, turn_number)\n );");const e=t.all("PRAGMA table_info(runs)");e.some((t=>"request_id"===t.name))||t.exec("ALTER TABLE runs ADD COLUMN request_id TEXT"),e.some((t=>"model_params_json"===t.name))||t.exec("ALTER TABLE runs ADD COLUMN model_params_json TEXT"),e.some((t=>"result"===t.name))||t.exec("ALTER TABLE runs ADD COLUMN result TEXT")}(e)}catch(t){throw e.close(),t}return e})().catch((e=>{throw this.driverPromise===t&&(this.driverPromise=void 0),e}));return this.driverPromise=t,t}getAgentFromDb(t,e){const n=t.get("SELECT * FROM agents WHERE agent_id = ?",[e]);return n?h(n):null}getRunFromDb(t,e,n){const r=t.get("SELECT * FROM runs WHERE run_id = ? AND agent_id = ?",[n,e]);return r?m(r):null}requireRunFromDb(t,e,n){const r=this.getRunFromDb(t,e,n);if(!r)throw new Error(`Run ${n} not found for agent ${e}`);return r}}function f(t,e){t.exec("BEGIN IMMEDIATE");try{const n=e();return t.exec("COMMIT"),n}catch(e){try{t.exec("ROLLBACK")}catch(t){}throw e}}},"../cursor-sdk-local-runtime/dist/run-store/sqlite/open-sqlite-driver.js"(t,e,n){n.d(e,{d:()=>s});class r extends Error{constructor(t,e){super(t,e),this.name="NoSqliteDriverError"}}async function s(t){if(void 0!==globalThis.Bun)return(await n.e(914).then(n.bind(n,"../cursor-sdk-local-runtime/dist/run-store/sqlite/bun-sqlite-driver.js"))).openBunSqliteDriver(t);let e;try{e=await n.e(343).then(n.bind(n,"../cursor-sdk-local-runtime/dist/run-store/sqlite/node-sqlite-driver.js"))}catch(t){if(function(t){return"ERR_UNKNOWN_BUILTIN_MODULE"===("object"==typeof t&&null!==t&&"code"in t&&"string"==typeof t.code?t.code:void 0)||(t instanceof Error?t.message.toLowerCase():String(t).toLowerCase()).includes("node:sqlite")}(t))throw new r("node:sqlite is not available in this runtime. The default local agent store requires Node >= 22.13 (or another runtime that implements node:sqlite). Configure a JsonlLocalAgentStore instead.",{cause:t});throw t}return e.openNodeSqliteDriver(t)}},"../cursor-sdk-local-runtime/dist/run-store/status.js"(t,e,n){n.d(e,{Qb:()=>s});const r=new Set(["FINISHED","ERROR","CANCELLED","EXPIRED"]);function s(t){return r.has(t)}}};
|
package/dist/esm/914.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const __webpack_esm_id__=914;export const __webpack_esm_ids__=[914];export const __webpack_esm_modules__={"../cursor-sdk-local-runtime/dist/run-store/sqlite/bun-sqlite-driver.js"(e,t,s){s.a(e,(async(e,r)=>{try{s.d(t,{openBunSqliteDriver:()=>o});var n=s("bun:sqlite"),a=e([n]),c=a.then?(await a)():a;n=c[0];class i{db;statements=new Map;constructor(e){this.db=e}exec(e){this.db.run(e)}run(e,t=[]){const{changes:s}=this.prepare(e).run(...t);return{changes:Number(s)}}get(e,t=[]){const s=this.prepare(e).get(...t);return null!=s?s:void 0}all(e,t=[]){return this.prepare(e).all(...t)}close(){this.statements.clear(),this.db.close()}prepare(e){let t=this.statements.get(e);return t||(t=this.db.prepare(e),this.statements.set(e,t)),t}}function o(e){return new i(new n.Database(e,{create:!0}))}r()}catch(u){r(u)}}))}};
|
package/dist/esm/986.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const __webpack_esm_id__=986;export const __webpack_esm_ids__=[986];export const __webpack_esm_modules__={"./src/agent/store/sqlite-local-agent-store.ts"(e,t,n){n.r(t),n.d(t,{SqliteLocalAgentStore:()=>f});var o=n("../agent-kv/dist/index.js"),r=n("../context/dist/index.js"),i=n("./src/agent/store/local-agent-record-conversion.ts"),d=n("./src/agent/store/local-agent-store.ts"),l=n("./src/agent/store/sdk-state-root.ts"),s=function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function d(e){try{s(o.next(e))}catch(e){i(e)}}function l(e){try{s(o.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(d,l)}s((o=o.apply(e,t||[])).next())}))};function u(e){var t,n,o;return{runId:e.runId,seq:e.seq,offset:e.offset,eventType:e.eventType,payload:null!==(t=e.payload)&&void 0!==t?t:null,payloadRef:null!==(n=e.payloadRef)&&void 0!==n?n:null,idempotencyKey:null!==(o=e.idempotencyKey)&&void 0!==o?o:null,createdAt:e.createdAt.getTime()}}function c(e){return s(this,void 0,void 0,(function*(){return(yield e.listAllAgentRecords()).map((e=>e.agentId))}))}function a(e,t){return s(this,void 0,void 0,(function*(){return(yield e.runStore.listAllRunRecords([t])).map((e=>e.runId))}))}class f{static open(e){return s(this,void 0,void 0,(function*(){var t;const o=null!==(t=e.stateRoot)&&void 0!==t?t:(0,l.V)(e.workspaceRef),{createDefaultLocalAgentStores:r}=yield n.e(19).then(n.bind(n,"../cursor-sdk-local-runtime/dist/run-store/default-local-agent-stores.js")),i=yield r({stateRoot:o,workspaceRef:e.workspaceRef}),d=i.store,s=i.eventStore,u=i.checkpointStore;return function(e,t,n){if("function"!=typeof e.upsertAgentRecord)throw new Error("SqliteLocalAgentStore requires SqliteAgentRunStore from local runtime");if("function"!=typeof n.appendRunEvent)throw new Error("SqliteLocalAgentStore requires SqliteRunEventStore from local runtime");if("function"!=typeof t.listCheckpointBlobIds)throw new Error("SqliteLocalAgentStore requires LocalAgentCheckpointStore from local runtime")}(d,u,s),new f({stateRoot:o,workspaceRef:e.workspaceRef,runStore:d,checkpointStore:u,eventStore:s})}))}constructor(e){this.stateRoot=e.stateRoot,this.workspaceRef=e.workspaceRef,this.deps={runStore:e.runStore,checkpointStore:e.checkpointStore,eventStore:e.eventStore},this.agents=function(e){return{get:t=>s(this,[t],void 0,(function*({agentId:t}){const n=yield e.runStore.getAgent(t);return n?(0,i.EB)(n):null})),create:t=>s(this,[t],void 0,(function*({agent:t}){if(yield e.runStore.getAgent(t.agentId))throw new Error(`Agent ${t.agentId} already exists`);yield e.runStore.upsertAgentRecord((0,i.UY)(t));const n=yield e.runStore.getAgent(t.agentId);if(!n)throw new Error(`Failed to create agent ${t.agentId}`);return(0,i.EB)(n)})),update:t=>s(this,[t],void 0,(function*({agent:t}){if(!(yield e.runStore.getAgent(t.agentId)))throw new Error(`Agent ${t.agentId} not found`);yield e.runStore.upsertAgentRecord((0,i.UY)(t));const n=yield e.runStore.getAgent(t.agentId);if(!n)throw new Error(`Failed to update agent ${t.agentId}`);return(0,i.EB)(n)})),delete:t=>s(this,[t],void 0,(function*({filter:t}){const n=(yield e.runStore.listAllAgentRecords()).map(i.EB).filter((e=>(0,d.HL)(e,t)));if(0===n.length)throw new Error("No agents matched delete filter");for(const t of n){const n=yield a(e,t.agentId);for(const t of n)yield e.eventStore.deleteRunEvents({runId:t});yield e.checkpointStore.deleteAgent(t.agentId),yield e.runStore.deleteAgent(t.agentId)}})),list:t=>s(this,void 0,void 0,(function*(){const n=(yield e.runStore.listAllAgentRecords()).map(i.EB);return(0,d.tg)(n,null==t?void 0:t.filter)}))}}(this.deps),this.checkpoints=function(e){const t=(0,r.q6)();return{get:n=>s(this,[n],void 0,(function*({agentId:n,blobId:r}){const i=yield e.checkpointStore.getBlobStore(n),d=yield i.getBlob(t,(0,o.aD)(r));return d?function(e){const t=new Uint8Array(e.length);return t.set(e),t}(d):null})),create:n=>s(this,[n],void 0,(function*({agentId:n,blobId:r,data:i}){const d=yield e.checkpointStore.getBlobStore(n);if(yield d.getBlob(t,(0,o.aD)(r)))throw new Error(`Checkpoint blob ${r} already exists for agent ${n}`);yield d.setBlob(t,(0,o.aD)(r),i)})),update:n=>s(this,[n],void 0,(function*({agentId:n,blobId:r,data:i}){const d=yield e.checkpointStore.getBlobStore(n);if(!(yield d.getBlob(t,(0,o.aD)(r))))throw new Error(`Checkpoint blob ${r} not found for agent ${n}`);yield d.setBlob(t,(0,o.aD)(r),i)})),delete:t=>s(this,void 0,void 0,(function*(){const n=t.filter.agentIds&&t.filter.agentIds.length>0?t.filter.agentIds:yield c(e.runStore),o=t.filter.blobIds;for(const t of n)if(null==o?void 0:o.length){const n=yield e.checkpointStore.getBlobStore(t);for(const e of o)yield n.deleteBlob(e)}else yield e.checkpointStore.deleteAgent(t)})),list:t=>s(this,void 0,void 0,(function*(){const n=null==t?void 0:t.filter,o=(null==n?void 0:n.agentIds)&&n.agentIds.length>0?n.agentIds:yield c(e.runStore),r=[];for(const t of o){const o=yield e.checkpointStore.listCheckpointBlobIds(t);for(const e of o)(0,d.S$)({agentId:t,blobId:e},n)&&r.push(e)}return(0,d.Jg)(r,n)}))}}(this.deps),this.runs=function(e){return{get:t=>s(this,[t],void 0,(function*({agentId:t,runId:n}){const o=yield e.runStore.getRun(t,n);return o?(0,i.xu)(o):null})),create:t=>s(this,[t],void 0,(function*({run:t}){if(yield e.runStore.getRun(t.agentId,t.runId))throw new Error(`Run ${t.runId} already exists for agent ${t.agentId}`);yield e.runStore.upsertRunRecord((0,i.R)(t));const n=yield e.runStore.getRun(t.agentId,t.runId);if(!n)throw new Error(`Failed to create run ${t.runId} for agent ${t.agentId}`);return(0,i.xu)(n)})),update:t=>s(this,[t],void 0,(function*({run:t}){if(!(yield e.runStore.getRun(t.agentId,t.runId)))throw new Error(`Run ${t.runId} not found for agent ${t.agentId}`);yield e.runStore.upsertRunRecord((0,i.R)(t));const n=yield e.runStore.getRun(t.agentId,t.runId);if(!n)throw new Error(`Failed to update run ${t.runId} for agent ${t.agentId}`);return(0,i.xu)(n)})),delete:t=>s(this,void 0,void 0,(function*(){const n=t.filter,o=(null==n?void 0:n.agentIds)&&n.agentIds.length>0?n.agentIds:void 0,r=(yield e.runStore.listAllRunRecords(o)).map(i.xu).filter((e=>(0,d.hA)(e,n)));if(0!==r.length){for(const t of r)yield e.eventStore.deleteRunEvents({runId:t.runId});yield e.runStore.deleteRunRecordsByKeys(r.map((e=>({agentId:e.agentId,runId:e.runId}))))}})),list:t=>s(this,void 0,void 0,(function*(){const n=null==t?void 0:t.filter,o=(yield e.runStore.listAllRunRecords(null==n?void 0:n.agentIds)).map(i.xu).filter((e=>(0,d.hA)(e,n)));return(0,d.f1)(o,n)}))}}(this.deps),this.runEvents=function(e){return{append:t=>s(this,void 0,void 0,(function*(){return u(yield e.appendRunEvent({runId:t.runId,eventType:t.eventType,payload:t.payload,payloadRef:t.payloadRef,idempotencyKey:t.idempotencyKey}))})),list:t=>s(this,void 0,void 0,(function*(){var n;const o=yield e.listRunEvents({runId:t.runId,afterOffset:null!==(n=t.afterOffset)&&void 0!==n?n:void 0,limit:t.limit});return Object.assign({items:o.events.map(u)},void 0!==o.nextOffset?{nextOffset:o.nextOffset}:{})})),delete:t=>s(this,void 0,void 0,(function*(){var n;const o=null!==(n=t.filter.runIds)&&void 0!==n?n:[];for(const t of o)yield e.deleteRunEvents({runId:t})}))}}(e.eventStore)}dispose(){return s(this,void 0,void 0,(function*(){yield Promise.all([this.deps.runStore.dispose(),this.deps.eventStore.dispose(),this.deps.checkpointStore.dispose()])}))}}}};
|
package/dist/esm/988.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const __webpack_esm_id__=988;export const __webpack_esm_ids__=[988];export const __webpack_esm_modules__={"./src/agent/safe-connect-transport.ts"(n,e,t){t.a(n,(async(n,o)=>{try{t.r(e),t.d(e,{createSafeConnectTransport:()=>p});var s=t("../../node_modules/.pnpm/@connectrpc+connect@1.6.1_patch_hash=a4b9a5e69295313832387f25b708426bcf53041a2f50bc7b95_d0a2f6c9e28298af3d10922a7e4db69f/node_modules/@connectrpc/connect/dist/esm/protocol/limit-io.js"),c=t("../../node_modules/.pnpm/@connectrpc+connect@1.6.1_patch_hash=a4b9a5e69295313832387f25b708426bcf53041a2f50bc7b95_d0a2f6c9e28298af3d10922a7e4db69f/node_modules/@connectrpc/connect/dist/esm/protocol-connect/transport.js"),i=t("@connectrpc/connect-node"),a=t("./src/agent/safe-node-http-client.ts"),r=n([i,a]);function p(n){var e,t,o,r,p;let d;if("2"===n.httpVersion){const t=null!==(e=n.sessionManager)&&void 0!==e?e:new i.Http2SessionManager(n.baseUrl,{pingIntervalMs:n.pingIntervalMs,pingIdleConnection:n.pingIdleConnection,pingTimeoutMs:n.pingTimeoutMs,idleConnectionTimeoutMs:n.idleConnectionTimeoutMs},n.nodeOptions);d=(0,a.L)({httpVersion:"2",sessionProvider:()=>t})}else d=(0,a.L)({httpVersion:"1.1",nodeOptions:n.nodeOptions});return(0,c.o)(Object.assign(Object.assign(Object.assign({},n),{httpClient:d,useBinaryFormat:null===(t=n.useBinaryFormat)||void 0===t||t,interceptors:null!==(o=n.interceptors)&&void 0!==o?o:[],sendCompression:null!==(r=n.sendCompression)&&void 0!==r?r:null,acceptCompression:null!==(p=n.acceptCompression)&&void 0!==p?p:[i.compressionGzip,i.compressionBrotli]}),(0,s.NL)(n.readMaxBytes,n.writeMaxBytes,n.compressMinBytes)))}[i,a]=r.then?(await r)():r,o()}catch(d){o(d)}}))},"./src/agent/safe-node-http-client.ts"(n,e,t){t.a(n,(async(n,o)=>{try{t.d(e,{L:()=>r});var s=t("@connectrpc/connect-node"),c=n([s]),i=c.then?(await c)():c;function a(n){return void 0!==n.signal?n:Object.assign(Object.assign({},n),{signal:(new AbortController).signal})}function r(n){const e=(0,s.createNodeHttpClient)(n);return n=>e(a(n))}s=i[0],o()}catch(p){o(p)}}))}};
|
package/dist/esm/996.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const __webpack_esm_id__=996;export const __webpack_esm_ids__=[996];export const __webpack_esm_modules__={"../../node_modules/.pnpm/@connectrpc+connect@1.6.1_patch_hash=a4b9a5e69295313832387f25b708426bcf53041a2f50bc7b95_d0a2f6c9e28298af3d10922a7e4db69f/node_modules/@connectrpc/connect/dist/esm/protocol-connect/transport.js"(e,n,t){t.d(n,{o:()=>U});var r=t("@bufbuild/protobuf");const o="Content-Type",a="Content-Length",s="Content-Encoding",c="Connect-Content-Encoding",i="Accept-Encoding",d="Connect-Protocol-Version",u=/^application\/(connect\+)?(?:(json)(?:; ?charset=utf-?8)?|(proto))$|^text\/event-stream$/i;function l(e,n,t,a,u,l,f){const p=function(e,n,t,a,s){const c=new Headers(null!=a?a:{});return void 0!==t&&c.set("Connect-Timeout-Ms",`${t}`),c.set(o,e==r.MethodKind.Unary?n?"application/proto":"application/json":n?"application/connect+proto":"application/connect+json"),c.set(d,"1"),s&&c.set("User-Agent","connect-es/1.6.1"),c}(e,n,t,a,f);if(null!=l){const n=e==r.MethodKind.Unary?s:c;p.set(n,l.name)}if(u.length>0){const n=e==r.MethodKind.Unary?i:"Connect-Accept-Encoding";p.set(n,u.map((e=>e.name)).join(","))}return p}var f=t("../../node_modules/.pnpm/@connectrpc+connect@1.6.1_patch_hash=a4b9a5e69295313832387f25b708426bcf53041a2f50bc7b95_d0a2f6c9e28298af3d10922a7e4db69f/node_modules/@connectrpc/connect/dist/esm/code.js"),p=t("../../node_modules/.pnpm/@connectrpc+connect@1.6.1_patch_hash=a4b9a5e69295313832387f25b708426bcf53041a2f50bc7b95_d0a2f6c9e28298af3d10922a7e4db69f/node_modules/@connectrpc/connect/dist/esm/connect-error.js");function m(e,n,t,a,i){let d;const l=i.get(e==r.MethodKind.Unary?s:c);if(null!=l&&"identity"!==l.toLowerCase()&&(d=n.find((e=>e.name===l)),!d))throw new p.T(`unsupported response encoding "${l}"`,f.C.Internal,i);return Object.assign({compression:d},function(e,n,t,a){const s=a.get(o),c=function(e){if("text/event-stream"===e)return{stream:!0,binary:!0};const n=null==e?void 0:e.match(u);return n?{stream:!!n[1],binary:!!n[3]}:void 0}(s);if(200!==t){const n=new p.T(`HTTP ${t}`,function(e){switch(e){case 400:return f.C.Internal;case 401:return f.C.Unauthenticated;case 403:return f.C.PermissionDenied;case 404:return f.C.Unimplemented;case 429:case 502:case 503:case 504:return f.C.Unavailable;default:return f.C.Unknown}}(t),a);if(e==r.MethodKind.Unary&&c&&!c.binary)return{isUnaryError:!0,unaryError:n};throw n}const i=n,d=e!==r.MethodKind.Unary;if((null==c?void 0:c.binary)!==i||c.stream!==d)throw new p.T(`unsupported content type ${s}`,void 0===c?f.C.Unknown:f.C.Internal,a);return{isUnaryError:!1}}(e,t,a,i))}var h=t("../../node_modules/.pnpm/@connectrpc+connect@1.6.1_patch_hash=a4b9a5e69295313832387f25b708426bcf53041a2f50bc7b95_d0a2f6c9e28298af3d10922a7e4db69f/node_modules/@connectrpc/connect/dist/esm/protocol-connect/code-string.js");function y(e,n,t){var o;if(n&&new Headers(n).forEach(((e,n)=>t.metadata.append(n,e))),"object"!=typeof e||null==e||Array.isArray(e))throw t;let a=t.code;"code"in e&&"string"==typeof e.code&&(a=null!==(o=(0,h.X)(e.code))&&void 0!==o?o:a);const s=e.message;if(null!=s&&"string"!=typeof s)throw t;const c=new p.T(null!=s?s:"",a,n);if("details"in e&&Array.isArray(e.details))for(const n of e.details){if(null===n||"object"!=typeof n||Array.isArray(n)||"string"!=typeof n.type||"string"!=typeof n.value)throw t;try{c.details.push({type:n.type,value:r.protoBase64.dec(n.value),debug:n.debug})}catch(e){throw t}}return c}function b(e,n){const t={code:(0,h.s)(e.code)};return e.rawMessage.length>0&&(t.message=e.rawMessage),e.details.length>0&&(t.details=e.details.map((e=>{if("getType"in e){const t={type:e.getType().typeName,value:e.toBinary()};try{t.debug=e.toJson(n)}catch(e){}return t}return e})).map((e=>{var{value:n}=e,t=function(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(t[r[o]]=e[r[o]])}return t}(e,["value"]);return Object.assign(Object.assign({},t),{value:r.protoBase64.enc(n).replace(/=+$/,"")})}))),t}function g(...e){const n=new Headers;for(const t of e)t.forEach(((e,t)=>{n.append(t,e)}));return n}var w=t("../../node_modules/.pnpm/@connectrpc+connect@1.6.1_patch_hash=a4b9a5e69295313832387f25b708426bcf53041a2f50bc7b95_d0a2f6c9e28298af3d10922a7e4db69f/node_modules/@connectrpc/connect/dist/esm/protocol/async-iterable.js");function v(e,n,t){const r="string"==typeof n?n:n.typeName,o="string"==typeof t?t:t.name;return e.toString().replace(/\/?$/,`/${r}/${o}`)}function _(e,n){var t;return null!==(t=null==n?void 0:n.concat().reverse().reduce(((e,n)=>n(e)),e))&&void 0!==t?t:e}function C(e){if(!e.aborted)return;if(void 0!==e.reason)return e.reason;const n=new Error("This operation was aborted");return n.name="AbortError",n}function O(e,n){return n instanceof e?n:new e(n)}function E(e,n){function t(n){return!0===n.done?n:{done:n.done,value:O(e,n.value)}}return{[Symbol.asyncIterator](){const e=n[Symbol.asyncIterator](),r={next:()=>e.next().then(t)};return void 0!==e.throw&&(r.throw=n=>e.throw(n).then(t)),void 0!==e.return&&(r.return=n=>e.return(n).then(t)),r}}}function T(e){const{signal:n,cleanup:t}=function(e){const n=new AbortController,t=()=>{n.abort(new p.T("the operation timed out",f.C.DeadlineExceeded))};let r;return void 0!==e&&(e<=0?t():r=setTimeout(t,e)),{signal:n.signal,cleanup:()=>clearTimeout(r)}}(e.timeoutMs),r=function(...e){const n=new AbortController,t=e.filter((e=>void 0!==e)).concat(n.signal);for(const e of t){if(e.aborted){r.apply(e);break}e.addEventListener("abort",r)}function r(){n.signal.aborted||n.abort(C(this));for(const e of t)e.removeEventListener("abort",r)}return n}(e.signal,n);return[r.signal,function(e){const o=p.T.from(n.aborted?C(n):e);return r.abort(o),t(),Promise.reject(o)},function(){t(),r.abort()}]}var j=t("../../node_modules/.pnpm/@connectrpc+connect@1.6.1_patch_hash=a4b9a5e69295313832387f25b708426bcf53041a2f50bc7b95_d0a2f6c9e28298af3d10922a7e4db69f/node_modules/@connectrpc/connect/dist/esm/protocol/limit-io.js");function x(e,n,t,r){const o=S(I(e.I,n),r),a=S(M(e.I,t),r),s=S(I(e.O,n),r),c=S(M(e.O,t),r);return{getI:e=>e?o:a,getO:e=>e?s:c}}function S(e,n){return{serialize(t){const r=e.serialize(t);return(0,j.Tw)(n.writeMaxBytes,r.byteLength),r},parse:t=>((0,j.kk)(n.readMaxBytes,t.byteLength,!0),e.parse(t))}}function I(e,n){return{parse(t){try{return e.fromBinary(t,n)}catch(e){const n=e instanceof Error?e.message:String(e);throw new p.T(`parse binary: ${n}`,f.C.Internal)}},serialize(e){try{return e.toBinary(n)}catch(e){const n=e instanceof Error?e.message:String(e);throw new p.T(`serialize binary: ${n}`,f.C.Internal)}}}}function M(e,n){var t,r;const o=null!==(t=null==n?void 0:n.textEncoder)&&void 0!==t?t:new TextEncoder,a=null!==(r=null==n?void 0:n.textDecoder)&&void 0!==r?r:new TextDecoder,s=function(e){var n;const t=Object.assign({},e);return null!==(n=t.ignoreUnknownFields)&&void 0!==n||(t.ignoreUnknownFields=!0),t}(n);return{parse(n){try{const t=a.decode(n);return e.fromJsonString(t,s)}catch(e){throw p.T.from(e,f.C.InvalidArgument)}},serialize(e){try{const n=e.toJsonString(s);return o.encode(n)}catch(e){throw p.T.from(e,f.C.Internal)}}}}function A(){return{get(e){return e.id in this?this[e.id]:e.defaultValue},set(e,n){return this[e.id]=n,this},delete(e){return delete this[e.id],this}}}var B=function(e){return this instanceof B?(this.v=e,this):new B(e)};function U(e){return{async unary(n,t,c,u,f,p,h){const b=x(t,e.binaryOptions,e.jsonOptions,e);return u=void 0===u?e.defaultTimeoutMs:u<=0?void 0:u,await function(e){const n=_(e.next,e.interceptors),[t,r,o]=T(e);return n(Object.assign(Object.assign({},e.req),{message:O(e.req.method.I,e.req.message),signal:t})).then((e=>(o(),e)),r)}({interceptors:e.interceptors,signal:c,timeoutMs:u,req:{stream:!1,service:n,method:t,url:v(e.baseUrl,n,t),init:{},header:l(t.kind,e.useBinaryFormat,u,f,e.acceptCompression,e.sendCompression,!0),contextValues:null!=h?h:A(),message:p},next:async c=>{var u;let l,f=b.getI(e.useBinaryFormat).serialize(c.message);e.sendCompression&&f.byteLength>e.compressMinBytes?(f=await e.sendCompression.compress(f),c.header.set(s,e.sendCompression.name)):c.header.delete(s),!0===e.useHttpGet&&t.idempotency===r.MethodIdempotency.NoSideEffects?c=function(e,n,t){let c="?connect=v1";const u=e.header.get(o);0===(null==u?void 0:u.indexOf("application/"))&&(c+="&encoding="+encodeURIComponent(u.slice(12)));const l=e.header.get(s);null!==l&&"identity"!==l&&(c+="&compression="+encodeURIComponent(l),t=!0),t&&(c+="&base64=1"),c+="&message="+function(e,n){return n?r.protoBase64.enc(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""):encodeURIComponent((new TextDecoder).decode(e))}(n,t);const f=e.url+c,p=new Headers(e.header);return[d,o,a,s,i].forEach((e=>p.delete(e))),Object.assign(Object.assign({},e),{init:Object.assign(Object.assign({},e.init),{method:"GET"}),url:f,header:p})}(c,f,e.useBinaryFormat):(l=(0,w.T$)([f]),0===f.length&&c.header.set("Content-Length","0"));const p=await e.httpClient({url:c.url,method:null!==(u=c.init.method)&&void 0!==u?u:"POST",header:c.header,signal:c.signal,body:l}),{compression:h,isUnaryError:v,unaryError:_}=m(t.kind,e.acceptCompression,e.useBinaryFormat,p.status,p.header),[C,O]=function(e){const n=new Headers,t=new Headers;return e.forEach(((e,r)=>{r.toLowerCase().startsWith("trailer-")?t.append(r.substring(8),e):n.append(r,e)})),[n,t]}(p.header);let E=await(0,w.WK)(p.body,(0,w.SM)(e.readMaxBytes,p.header.get(a)),{propagateDownStreamError:!1});if(h&&(E=await h.decompress(E,e.readMaxBytes)),v)throw function(e,n,t){let r;try{r=JSON.parse((new TextDecoder).decode(e))}catch(e){throw t}return y(r,n,t)}(E,g(C,O),_);return{stream:!1,service:n,method:t,header:C,message:b.getO(e.useBinaryFormat).parse(E),trailer:O}}})},async stream(n,t,r,o,a,s,c){const i=x(t,e.binaryOptions,e.jsonOptions,e),d=function(e){const n=new TextEncoder;return{serialize(t){try{const r=function(e,n,t){const r={};void 0!==n&&(r.error=b(n,t),e=g(e,n.metadata));let o=!1;const a={};return e.forEach(((e,n)=>{o=!0,a[n]=[e]})),o&&(r.metadata=a),r}(t.metadata,t.error,e),o=JSON.stringify(r);return n.encode(o)}catch(e){const n=e instanceof Error?e.message:String(e);throw new p.T(`failed to serialize EndStreamResponse: ${n}`,f.C.Internal)}},parse(e){try{return function(e){const n=new p.T("invalid end stream",f.C.Unknown);let t;try{t=JSON.parse("string"==typeof e?e:(new TextDecoder).decode(e))}catch(e){throw n}if("object"!=typeof t||null==t||Array.isArray(t))throw n;const r=new Headers;if("metadata"in t){if("object"!=typeof t.metadata||null==t.metadata||Array.isArray(t.metadata))throw n;for(const[e,o]of Object.entries(t.metadata)){if(!Array.isArray(o)||o.some((e=>"string"!=typeof e)))throw n;for(const n of o)r.append(e,n)}}return{metadata:r,error:"error"in t&&null!=t.error?y(t.error,r,n):void 0}}(e)}catch(e){const n=e instanceof Error?e.message:String(e);throw new p.T(`failed to parse EndStreamResponse: ${n}`,f.C.InvalidArgument)}}}}(e.jsonOptions);return o=void 0===o?e.defaultTimeoutMs:o<=0?void 0:o,function(e){const n=_(e.next,e.interceptors),[t,r,o]=T(e),a=Object.assign(Object.assign({},e.req),{message:E(e.req.method.I,e.req.message),signal:t});let s=!1;return t.addEventListener("abort",(function(){var n,t;const r=e.req.message[Symbol.asyncIterator]();s||null===(n=r.throw)||void 0===n||n.call(r,this.reason).catch((()=>{})),null===(t=r.return)||void 0===t||t.call(r).catch((()=>{}))})),n(a).then((e=>Object.assign(Object.assign({},e),{message:{[Symbol.asyncIterator](){const n=e.message[Symbol.asyncIterator]();return{next:()=>n.next().then((e=>(1==e.done&&(s=!0,o()),e)),r)}}}})),r)}({interceptors:e.interceptors,signal:r,timeoutMs:o,req:{stream:!0,service:n,method:t,url:v(e.baseUrl,n,t),init:{method:"POST",redirect:"error",mode:"cors"},header:l(t.kind,e.useBinaryFormat,o,a,e.acceptCompression,e.sendCompression,!0),contextValues:null!=c?c:A(),message:s},next:async n=>{const r=await e.httpClient({url:n.url,method:"POST",header:n.header,signal:n.signal,body:(0,w.Fs)(n.message,(0,w.XO)(i.getI(e.useBinaryFormat)),(0,w.fM)(e.sendCompression,e.compressMinBytes),(0,w.yQ)(),{propagateDownStreamError:!0})}),{compression:o}=m(t.kind,e.acceptCompression,e.useBinaryFormat,r.status,r.header),a=Object.assign(Object.assign({},n),{header:r.header,trailer:new Headers,message:(0,w.Fs)(r.body,(0,w.pY)(e.readMaxBytes),(0,w.ew)(null!=o?o:null,e.readMaxBytes),(0,w.uv)(i.getO(e.useBinaryFormat),2,d),(function(e){return function(e,n,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=t.apply(e,n||[]),a=[];return r={},s("next"),s("throw"),s("return",(function(e){return function(n){return Promise.resolve(n).then(e,d)}})),r[Symbol.asyncIterator]=function(){return this},r;function s(e,n){o[e]&&(r[e]=function(n){return new Promise((function(t,r){a.push([e,n,t,r])>1||c(e,n)}))},n&&(r[e]=n(r[e])))}function c(e,n){try{(t=o[e](n)).value instanceof B?Promise.resolve(t.value.v).then(i,d):u(a[0][2],t)}catch(e){u(a[0][3],e)}var t}function i(e){c("next",e)}function d(e){c("throw",e)}function u(e,n){e(n),a.shift(),a.length&&c(a[0][0],a[0][1])}}(this,arguments,(function*(){var n,t,o,s;let c=!1;try{for(var i,d=!0,u=function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,t=e[Symbol.asyncIterator];return t?t.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(t){n[t]=e[t]&&function(n){return new Promise((function(r,o){!function(e,n,t,r){Promise.resolve(r).then((function(n){e({value:n,done:t})}),n)}(r,o,(n=e[t](n)).done,n.value)}))}}}(e);!(n=(i=yield B(u.next())).done);d=!0){s=i.value,d=!1;const e=s;if(e.end){if(c)throw new p.T("protocol error: received extra EndStreamResponse",f.C.InvalidArgument);if(c=!0,e.value.error){const n=e.value.error;throw r.header.forEach(((e,t)=>{n.metadata.append(t,e)})),n}e.value.metadata.forEach(((e,n)=>a.trailer.set(n,e)))}else{if(c)throw new p.T("protocol error: received extra message after EndStreamResponse",f.C.InvalidArgument);yield yield B(e.value)}}}catch(e){t={error:e}}finally{try{d||n||!(o=u.return)||(yield B(o.call(u)))}finally{if(t)throw t.error}}if(!c)throw new p.T("protocol error: missing EndStreamResponse",f.C.InvalidArgument)}))}),{propagateDownStreamError:!0})});return a}})}}}}};
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import type { AgentCheckpointStore, AgentRunStore, RunEventNotifier, RunEventStore } from "./run-store-public-types.js";
|
|
2
|
+
import type { LocalAgentStore } from "./store/local-agent-store.js";
|
|
3
|
+
/** Conversation mode for agent runs. */
|
|
4
|
+
export type AgentModeOption = "agent" | "plan";
|
|
5
|
+
export interface SDKImageDimension {
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
}
|
|
9
|
+
export type SDKImage = {
|
|
10
|
+
url: string;
|
|
11
|
+
dimension?: SDKImageDimension;
|
|
12
|
+
} | {
|
|
13
|
+
data: string;
|
|
14
|
+
mimeType: string;
|
|
15
|
+
dimension?: SDKImageDimension;
|
|
16
|
+
};
|
|
17
|
+
export interface SDKUserMessage {
|
|
18
|
+
text: string;
|
|
19
|
+
images?: SDKImage[];
|
|
20
|
+
}
|
|
21
|
+
export type McpServerConfig = {
|
|
22
|
+
type?: "stdio";
|
|
23
|
+
command: string;
|
|
24
|
+
args?: string[];
|
|
25
|
+
env?: Record<string, string>;
|
|
26
|
+
cwd?: string;
|
|
27
|
+
} | {
|
|
28
|
+
type?: "http" | "sse";
|
|
29
|
+
url: string;
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
auth?: {
|
|
32
|
+
CLIENT_ID: string;
|
|
33
|
+
CLIENT_SECRET?: string;
|
|
34
|
+
scopes?: string[];
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export type SettingSource = "project" | "user" | "team" | "mdm" | "plugins" | "all";
|
|
38
|
+
export type SDKJsonPrimitive = string | number | boolean | null;
|
|
39
|
+
export type SDKJsonValue = SDKJsonPrimitive | {
|
|
40
|
+
[key: string]: SDKJsonValue;
|
|
41
|
+
} | SDKJsonValue[];
|
|
42
|
+
export type SDKCustomToolContent = {
|
|
43
|
+
type: "text";
|
|
44
|
+
text: string;
|
|
45
|
+
} | {
|
|
46
|
+
type: "image";
|
|
47
|
+
data: string;
|
|
48
|
+
mimeType?: string;
|
|
49
|
+
};
|
|
50
|
+
export type SDKCustomToolResult = string | SDKJsonValue | {
|
|
51
|
+
content: SDKCustomToolContent[];
|
|
52
|
+
isError?: boolean;
|
|
53
|
+
structuredContent?: Record<string, SDKJsonValue>;
|
|
54
|
+
};
|
|
55
|
+
export interface SDKCustomToolContext {
|
|
56
|
+
toolCallId?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface SDKCustomTool {
|
|
59
|
+
description?: string;
|
|
60
|
+
inputSchema?: Record<string, SDKJsonValue>;
|
|
61
|
+
execute: (args: Record<string, SDKJsonValue>, context: SDKCustomToolContext) => SDKCustomToolResult | Promise<SDKCustomToolResult>;
|
|
62
|
+
}
|
|
63
|
+
export interface SandboxOptions {
|
|
64
|
+
enabled: boolean;
|
|
65
|
+
}
|
|
66
|
+
export interface ModelParameterValue {
|
|
67
|
+
id: string;
|
|
68
|
+
value: string;
|
|
69
|
+
}
|
|
70
|
+
export interface ModelSelection {
|
|
71
|
+
id: string;
|
|
72
|
+
params?: ModelParameterValue[];
|
|
73
|
+
}
|
|
74
|
+
export interface ModelParameterDefinition {
|
|
75
|
+
id: string;
|
|
76
|
+
displayName?: string;
|
|
77
|
+
values: Array<{
|
|
78
|
+
value: string;
|
|
79
|
+
displayName?: string;
|
|
80
|
+
}>;
|
|
81
|
+
}
|
|
82
|
+
export interface ModelVariant {
|
|
83
|
+
params: ModelParameterValue[];
|
|
84
|
+
displayName: string;
|
|
85
|
+
description?: string;
|
|
86
|
+
isDefault?: boolean;
|
|
87
|
+
}
|
|
88
|
+
export interface ModelListItem {
|
|
89
|
+
id: string;
|
|
90
|
+
displayName: string;
|
|
91
|
+
description?: string;
|
|
92
|
+
aliases?: string[];
|
|
93
|
+
parameters?: ModelParameterDefinition[];
|
|
94
|
+
variants?: ModelVariant[];
|
|
95
|
+
}
|
|
96
|
+
export interface AgentDefinition {
|
|
97
|
+
description: string;
|
|
98
|
+
prompt: string;
|
|
99
|
+
model?: ModelSelection | "inherit";
|
|
100
|
+
mcpServers?: Array<string | Record<string, McpServerConfig>>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Options that only apply to local agents. Exported as a standalone type so
|
|
104
|
+
* users can reference it directly (e.g. `Partial<LocalAgentOptions>`) instead
|
|
105
|
+
* of having to unwrap the optional `local` field on `AgentOptions` with
|
|
106
|
+
* `Partial<NonNullable<AgentOptions["local"]>>`.
|
|
107
|
+
*/
|
|
108
|
+
export interface LocalAgentOptions {
|
|
109
|
+
cwd?: string | string[];
|
|
110
|
+
/**
|
|
111
|
+
* Enable Cursor's Auto-review for local tool calls. When this is true,
|
|
112
|
+
* local runs select the classifier-backed Auto mode whenever the connected
|
|
113
|
+
* backend has the Auto-review classifier feature enabled.
|
|
114
|
+
*/
|
|
115
|
+
autoReview?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Custom {@link LocalAgentStore} for this call. When omitted, uses
|
|
118
|
+
* `Cursor.configure({ local: { store } })` if set; otherwise the default
|
|
119
|
+
* SQLite backend when `sqlite3` is installed (`@cursor/sdk/sqlite`), or
|
|
120
|
+
* {@link JsonlLocalAgentStore} when running without native SQLite.
|
|
121
|
+
* Agent rows hold a slim checkpoint ref (`latestCheckpoint.rootBlobId`);
|
|
122
|
+
* blob bytes live on `store.checkpoints`.
|
|
123
|
+
*/
|
|
124
|
+
store?: LocalAgentStore;
|
|
125
|
+
/**
|
|
126
|
+
* Ambient Cursor settings layers to load from the local filesystem.
|
|
127
|
+
* Local agents only. On cloud, `project` / `team` / `plugins` are
|
|
128
|
+
* always on and `user` / `mdm` / `local` have no VM equivalent, so
|
|
129
|
+
* this field is gated to the local shape.
|
|
130
|
+
*/
|
|
131
|
+
settingSources?: SettingSource[];
|
|
132
|
+
sandboxOptions?: SandboxOptions;
|
|
133
|
+
/**
|
|
134
|
+
* In-process callback tools for this agent, exposed as the
|
|
135
|
+
* `custom-user-tools` MCP server (`GetMcpTools` / `CallMcpTool`). Applied on
|
|
136
|
+
* every `send` unless overridden by {@link LocalSendOptions.customTools}.
|
|
137
|
+
* Local agents only; not supported on cloud agents.
|
|
138
|
+
*/
|
|
139
|
+
customTools?: Record<string, SDKCustomTool>;
|
|
140
|
+
/**
|
|
141
|
+
* Enable transport and stall auto-retry for local agent runs. Defaults to
|
|
142
|
+
* true for headless embedders; set false to surface transport errors on the
|
|
143
|
+
* first failure (legacy SDK behavior).
|
|
144
|
+
*/
|
|
145
|
+
enableAgentRetries?: boolean;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Per-send local overrides. Use with `Agent.send(..., { local })`. Agent-level
|
|
149
|
+
* defaults live on {@link LocalAgentOptions} (`Agent.create({ local })`).
|
|
150
|
+
*/
|
|
151
|
+
export interface LocalSendOptions {
|
|
152
|
+
/**
|
|
153
|
+
* Expire the currently active persisted run, if any, before starting this
|
|
154
|
+
* message as a new follow-up run. Recovery path for local agents left wedged
|
|
155
|
+
* after a crashed CLI process.
|
|
156
|
+
*/
|
|
157
|
+
force?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Custom tools for this send only. When set, replaces
|
|
160
|
+
* {@link LocalAgentOptions.customTools} for that run.
|
|
161
|
+
*/
|
|
162
|
+
customTools?: Record<string, SDKCustomTool>;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Options that only apply to cloud agents. Exported as a standalone type so
|
|
166
|
+
* users can reference it directly (e.g. `Partial<CloudAgentOptions>`) instead
|
|
167
|
+
* of having to unwrap the optional `cloud` field on `AgentOptions` with
|
|
168
|
+
* `Partial<NonNullable<AgentOptions["cloud"]>>`.
|
|
169
|
+
*/
|
|
170
|
+
export interface CloudAgentOptions {
|
|
171
|
+
env?: {
|
|
172
|
+
type: "cloud";
|
|
173
|
+
name?: string;
|
|
174
|
+
} | {
|
|
175
|
+
type: "pool";
|
|
176
|
+
name?: string;
|
|
177
|
+
} | {
|
|
178
|
+
type: "machine";
|
|
179
|
+
name?: string;
|
|
180
|
+
};
|
|
181
|
+
repos?: Array<{
|
|
182
|
+
url: string;
|
|
183
|
+
startingRef?: string;
|
|
184
|
+
prUrl?: string;
|
|
185
|
+
}>;
|
|
186
|
+
workOnCurrentBranch?: boolean;
|
|
187
|
+
autoCreatePR?: boolean;
|
|
188
|
+
skipReviewerRequest?: boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Per-session env vars injected into the cloud agent's shell, e.g. for
|
|
191
|
+
* caller-minted credentials. Encrypted at rest; deleted with the agent.
|
|
192
|
+
*/
|
|
193
|
+
envVars?: Record<string, string>;
|
|
194
|
+
}
|
|
195
|
+
export interface CursorAgentPlatformOptions {
|
|
196
|
+
/**
|
|
197
|
+
* Custom {@link LocalAgentStore}. Prefer `local.store` on `Agent.create` /
|
|
198
|
+
* `Agent.resume` unless constructing a platform directly. When omitted, the
|
|
199
|
+
* platform uses built-in SQLite under `stateRoot` — implement
|
|
200
|
+
* {@link LocalAgentStore} only to replace that default path.
|
|
201
|
+
*/
|
|
202
|
+
localStore?: LocalAgentStore;
|
|
203
|
+
stateRoot?: string;
|
|
204
|
+
workspaceRef?: string;
|
|
205
|
+
/**
|
|
206
|
+
* When set, custom-store reads filter to agents whose `cwd` matches. Populated
|
|
207
|
+
* from an explicit caller `cwd`; omitted when the caller did not pass one.
|
|
208
|
+
*/
|
|
209
|
+
scopedWorkspaceRef?: string;
|
|
210
|
+
/**
|
|
211
|
+
* Internal storage hooks retained for existing advanced callers.
|
|
212
|
+
*/
|
|
213
|
+
store?: AgentRunStore;
|
|
214
|
+
checkpointStore?: AgentCheckpointStore;
|
|
215
|
+
eventStore?: RunEventStore;
|
|
216
|
+
eventNotifier?: RunEventNotifier;
|
|
217
|
+
}
|
|
218
|
+
export interface AgentOptions {
|
|
219
|
+
/**
|
|
220
|
+
* Model selection (`{ id, params? }`). Required for local agents; optional
|
|
221
|
+
* for cloud (the server resolves the caller's configured default when
|
|
222
|
+
* omitted). Use `Cursor.models.list()` to discover valid selections.
|
|
223
|
+
*/
|
|
224
|
+
model?: ModelSelection;
|
|
225
|
+
apiKey?: string;
|
|
226
|
+
/**
|
|
227
|
+
* Optional human-readable name for the agent, surfaced as the `title` in
|
|
228
|
+
* `Agent.list()` / `Agent.get()`. Cloud agents auto-generate a name from
|
|
229
|
+
* the first prompt when this is omitted; local agents fall back to a
|
|
230
|
+
* generic default.
|
|
231
|
+
*/
|
|
232
|
+
name?: string;
|
|
233
|
+
local?: LocalAgentOptions;
|
|
234
|
+
cloud?: CloudAgentOptions;
|
|
235
|
+
mcpServers?: Record<string, McpServerConfig>;
|
|
236
|
+
agents?: Record<string, AgentDefinition>;
|
|
237
|
+
agentId?: string;
|
|
238
|
+
idempotencyKey?: string;
|
|
239
|
+
/** Initial conversation mode for this agent. */
|
|
240
|
+
mode?: AgentModeOption;
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +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;IACE,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE;QACL,SAAS,EAAE,MAAM,CAAC;QAClB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;CACH,CAAC;AAEN,MAAM,MAAM,aAAa,GACrB,SAAS,GACT,MAAM,GACN,MAAM,GACN,KAAK,GACL,SAAS,GACT,KAAK,CAAC;AAEV,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAChE,MAAM,MAAM,YAAY,GACpB,gBAAgB,GAChB;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;CAAE,GAC/B,YAAY,EAAE,CAAC;AAEnB,MAAM,MAAM,oBAAoB,GAC5B;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEN,MAAM,MAAM,mBAAmB,GAC3B,MAAM,GACN,YAAY,GACZ;IACE,OAAO,EAAE,oBAAoB,EAAE,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CAClD,CAAC;AAEN,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC3C,OAAO,EAAE,CACP,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAClC,OAAO,EAAE,oBAAoB,KAC1B,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACzD;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,mBAAmB,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,KAAK,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC,CAAC;CACJ;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,CAAC,EAAE,wBAAwB,EAAE,CAAC;IACxC,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IAGf,KAAK,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IACnC,UAAU,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;CAE9D;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;IACjC,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC5C;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAC7C;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EACA;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAChC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAC/B;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,KAAK,CAAC,EAAE,KAAK,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,0BAA0B;IACzC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,eAAe,CAAC,EAAE,oBAAoB,CAAC;IACvC,UAAU,CAAC,EAAE,aAAa,CAAC;IAC3B,aAAa,CAAC,EAAE,gBAAgB,CAAC;CAClC;AAED,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,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"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types and implementations for run event notifiers.
|
|
3
|
+
*
|
|
4
|
+
* These types are inlined to avoid leaking internal runtime package types
|
|
5
|
+
* in the published SDK declaration files.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Opaque resume token for a run event stream.
|
|
9
|
+
*
|
|
10
|
+
* Stores own the format of this token. The default local SQLite and in-memory
|
|
11
|
+
* stores use numeric sequence strings, but SDK callers and custom backends
|
|
12
|
+
* must only persist and pass the token back as an exclusive `afterOffset`.
|
|
13
|
+
*/
|
|
14
|
+
export type RunEventOffset = string;
|
|
15
|
+
/**
|
|
16
|
+
* Hint that a run's event log may have new events.
|
|
17
|
+
*/
|
|
18
|
+
export interface RunEventHint {
|
|
19
|
+
/**
|
|
20
|
+
* Run whose durable event log may have advanced.
|
|
21
|
+
*/
|
|
22
|
+
runId: string;
|
|
23
|
+
/**
|
|
24
|
+
* Latest appended offset known to the publisher. Hints are wakeups only:
|
|
25
|
+
* subscribers must always re-read the durable RunEventStore and must not
|
|
26
|
+
* assume every offset hint arrives exactly once.
|
|
27
|
+
*/
|
|
28
|
+
offset: RunEventOffset;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Input for subscribing to run event hints.
|
|
32
|
+
*/
|
|
33
|
+
export interface WatchRunEventsInput {
|
|
34
|
+
runId: string;
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Subscription to run event hints.
|
|
39
|
+
*/
|
|
40
|
+
export interface RunEventSubscription extends AsyncIterable<RunEventHint> {
|
|
41
|
+
readonly ready?: Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Notifier for publishing and subscribing to run event hints.
|
|
45
|
+
*/
|
|
46
|
+
export interface RunEventNotifier {
|
|
47
|
+
/**
|
|
48
|
+
* Publishes a best-effort wakeup after a durable run event append. Notifiers
|
|
49
|
+
* may drop, duplicate, coalesce, or delay hints; correctness must come from
|
|
50
|
+
* replaying the RunEventStore.
|
|
51
|
+
*/
|
|
52
|
+
publishRunEventAppended(input: RunEventHint): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Subscribes to best-effort wakeups for one run. Consumers must tolerate
|
|
55
|
+
* missed hints and use each hint only as a prompt to list durable events.
|
|
56
|
+
* When `ready` is present on the returned subscription, it resolves after
|
|
57
|
+
* the subscription is armed server-side.
|
|
58
|
+
*/
|
|
59
|
+
subscribeRunEvents(input: WatchRunEventsInput): RunEventSubscription;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Options for creating a local run event notifier client.
|
|
63
|
+
*/
|
|
64
|
+
export interface LocalRunEventNotifierOptions {
|
|
65
|
+
socketPath: string;
|
|
66
|
+
connectTimeoutMs?: number;
|
|
67
|
+
requestTimeoutMs?: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Options for starting a local run event notifier server.
|
|
71
|
+
*/
|
|
72
|
+
export interface LocalRunEventNotifierServerOptions {
|
|
73
|
+
socketPath: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Local run event notifier client that connects to a notifier server via Unix socket.
|
|
77
|
+
*
|
|
78
|
+
* This wrapper class ensures the public API doesn't leak internal implementation types.
|
|
79
|
+
*/
|
|
80
|
+
export declare class LocalRunEventNotifier implements RunEventNotifier {
|
|
81
|
+
private readonly impl;
|
|
82
|
+
constructor(options: LocalRunEventNotifierOptions);
|
|
83
|
+
publishRunEventAppended(input: RunEventHint): Promise<void>;
|
|
84
|
+
subscribeRunEvents(input: WatchRunEventsInput): RunEventSubscription;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Local run event notifier server that listens on a Unix socket.
|
|
88
|
+
*
|
|
89
|
+
* This wrapper class ensures the public API doesn't leak internal implementation types.
|
|
90
|
+
*/
|
|
91
|
+
export declare class LocalRunEventNotifierServer {
|
|
92
|
+
private readonly impl;
|
|
93
|
+
private constructor();
|
|
94
|
+
static listen(options: LocalRunEventNotifierServerOptions): Promise<LocalRunEventNotifierServer>;
|
|
95
|
+
close(): Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* In-memory run event notifier for testing and development.
|
|
99
|
+
*
|
|
100
|
+
* This wrapper class ensures the public API doesn't leak internal implementation types.
|
|
101
|
+
*/
|
|
102
|
+
export declare class InMemoryRunEventNotifier implements RunEventNotifier {
|
|
103
|
+
private readonly impl;
|
|
104
|
+
constructor();
|
|
105
|
+
publishRunEventAppended(input: RunEventHint): Promise<void>;
|
|
106
|
+
subscribeRunEvents(input: WatchRunEventsInput): RunEventSubscription;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Creates a local run event notifier client.
|
|
110
|
+
*/
|
|
111
|
+
export declare function createLocalRunEventNotifier(options: LocalRunEventNotifierOptions): RunEventNotifier;
|
|
112
|
+
/**
|
|
113
|
+
* Starts a local run event notifier server.
|
|
114
|
+
*/
|
|
115
|
+
export declare function startLocalRunEventNotifierServer(options: LocalRunEventNotifierServerOptions): Promise<LocalRunEventNotifierServer>;
|
|
116
|
+
/**
|
|
117
|
+
* Creates an in-memory run event notifier for testing and development.
|
|
118
|
+
*/
|
|
119
|
+
export declare function createInMemoryRunEventNotifier(): RunEventNotifier;
|
|
120
|
+
//# sourceMappingURL=run-event-notifier-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-event-notifier-api.d.ts","sourceRoot":"","sources":["../../../src/agent/run-event-notifier-api.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,MAAM,EAAE,cAAc,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,aAAa,CAAC,YAAY,CAAC;IACvE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,uBAAuB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D;;;;;OAKG;IACH,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,GAAG,oBAAoB,CAAC;CACtE;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,kCAAkC;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,qBAAa,qBAAsB,YAAW,gBAAgB;IAC5D,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA4B;gBAErC,OAAO,EAAE,4BAA4B;IAI3C,uBAAuB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjE,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,GAAG,oBAAoB;CAGrE;AAED;;;;GAIG;AACH,qBAAa,2BAA2B;IACtC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAkC;IAEvD,OAAO;WAIM,MAAM,CACjB,OAAO,EAAE,kCAAkC,GAC1C,OAAO,CAAC,2BAA2B,CAAC;IAKjC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B;AAED;;;;GAIG;AACH,qBAAa,wBAAyB,YAAW,gBAAgB;IAC/D,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA+B;;IAM9C,uBAAuB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjE,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,GAAG,oBAAoB;CAGrE;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,4BAA4B,GACpC,gBAAgB,CAElB;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,kCAAkC,GAC1C,OAAO,CAAC,2BAA2B,CAAC,CAEtC;AAED;;GAEG;AACH,wBAAgB,8BAA8B,IAAI,gBAAgB,CAEjE"}
|