MCPcopy
hub / github.com/cursor/cookbook / sendPrompt

Method sendPrompt

sdk/coding-agent-cli/src/agent.ts:165–193  ·  view source on GitHub ↗
({ prompt, onEvent }: SendPromptOptions)

Source from the content-addressed store, hash-verified

163 }
164
165 async sendPrompt({ prompt, onEvent }: SendPromptOptions) {
166 await this.ensureAgentFresh()
167
168 const run = await this.agent.send(buildPrompt(prompt), {
169 ...(this.mode === "local" ? { model: this.modelSelection } : {}),
170 ...(this.mode === "local" && this.force ? { local: { force: true } } : {}),
171 })
172
173 this.currentRun = run
174
175 try {
176 for await (const event of run.stream()) {
177 emitSdkMessage(event, onEvent)
178 }
179
180 const result = await run.wait()
181 const usage = (result as { usage?: TokenUsage }).usage
182 onEvent({
183 type: "result",
184 status: result.status,
185 durationMs: result.durationMs,
186 usage,
187 })
188 } finally {
189 if (this.currentRun === run) {
190 this.currentRun = null
191 }
192 }
193 }
194
195 private createAgent() {
196 const options = {

Callers 2

runPlainPromptFunction · 0.95
sendPromptFunction · 0.80

Calls 3

ensureAgentFreshMethod · 0.95
buildPromptFunction · 0.70
emitSdkMessageFunction · 0.70

Tested by

no test coverage detected