MCPcopy Create free account
hub / github.com/cursor/cookbook / CodingAgentSession

Class CodingAgentSession

sdk/coding-agent-cli/src/agent.ts:69–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67].join("\n")
68
69export class CodingAgentSession {
70 private agent: SDKAgent
71 private agentKey: string
72 private cloudRepository: CloudRepository | null = null
73 private currentRun: Run | null = null
74 private readonly apiKey: string
75 private readonly cwd: string
76 private readonly force: boolean
77 private mode: ExecutionMode
78 private modelSelection: ModelSelection
79
80 constructor(options: CodingAgentSessionOptions) {
81 this.apiKey = options.apiKey
82 this.cwd = options.cwd
83 this.force = options.force
84 this.mode = options.executionMode ?? "local"
85 this.modelSelection = options.model
86 this.agent = this.createAgent()
87 this.agentKey = this.currentAgentKey()
88 }
89
90 get model() {
91 return this.modelSelection
92 }
93
94 get executionMode() {
95 return this.mode
96 }
97
98 get executionTarget() {
99 return this.mode === "local"
100 ? this.cwd
101 : formatCloudRepository(this.cloudRepository ?? detectCloudRepository(this.cwd))
102 }
103
104 setModel(model: ModelSelection) {
105 this.modelSelection = model
106 }
107
108 async listModels(): Promise<ModelChoice[]> {
109 const models = await Cursor.models.list({ apiKey: this.apiKey })
110 const choices = disambiguateGlobalDuplicateLabels(
111 dedupeModelChoices(models.flatMap(modelToChoices))
112 )
113
114 return choices.length > 0
115 ? choices
116 : [{ label: this.modelSelection.id, value: this.modelSelection }]
117 }
118
119 async reset() {
120 await this.replaceAgent()
121 }
122
123 async setExecutionMode(mode: ExecutionMode) {
124 if (this.currentRun) {
125 throw new Error("Wait for the current run to finish before switching execution mode.")
126 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected