From b3706d58f7173176c6edd144f772ced50b0921c5 Mon Sep 17 00:00:00 2001 From: Yusuke Ohi Date: Wed, 13 May 2026 12:01:30 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat(agent):=20POOL=E5=AE=B9=E9=87=8F?= =?UTF-8?q?=E8=AA=BF=E6=95=B4=E3=81=A8Agent.create=E3=81=AElocal=20cwd?= =?UTF-8?q?=E6=98=8E=E7=A4=BA=E3=82=92=E9=81=A9=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 2 +- src/openai-proxy.ts | 1 + src/provider.ts | 16 +++++++++++++--- tests/provider.test.ts | 5 ++++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index c7e94e4..75d3431 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,7 @@ import { startOpenAiProxy } from "./openai-proxy.js"; import { createProviderHook } from "./provider.js"; import { STATIC_FALLBACK_MODELS, makeModelMeta } from "./models.js"; -const POOL_CAPACITY = 8; +const POOL_CAPACITY = 10; /** * OpenCode client with extended properties used by this plugin. diff --git a/src/openai-proxy.ts b/src/openai-proxy.ts index 7af77d8..0ff647e 100644 --- a/src/openai-proxy.ts +++ b/src/openai-proxy.ts @@ -162,6 +162,7 @@ async function handleChat(req: IncomingMessage, res: ServerResponse, log: Logger agent = await Agent.create({ apiKey, model: { id: modelId }, + local: { cwd: process.cwd() }, }); messageToSend = translated.fullPromptOnMiss; log.debug("cursor-openai-proxy: pool miss", { prefixHash: translated.prefixHash.slice(0, 8) }); diff --git a/src/provider.ts b/src/provider.ts index b7c0aca..0b7c066 100644 --- a/src/provider.ts +++ b/src/provider.ts @@ -313,7 +313,7 @@ async function runDoStream(opts: { * Single attempt to create an agent with error classification and logging. */ async function performAgentCreationAttempt(deps: { - Agent: { create: (opts: { apiKey: string; model: { id: string } }) => Promise }; + Agent: { create: (opts: AgentCreateOpts) => Promise }; apiKey: string; modelId: string; log: Logger; @@ -322,7 +322,11 @@ async function performAgentCreationAttempt(deps: { const { Agent, apiKey, modelId, log, attempt } = deps; try { log.debug("cursor-provider: calling Agent.create", { modelId, attempt }); - const agent = (await Agent.create({ apiKey, model: { id: modelId } })) as SDKAgent; + const agent = (await Agent.create({ + apiKey, + model: { id: modelId }, + local: { cwd: process.cwd() }, + })) as SDKAgent; return { agent }; } catch (err) { const decision = classifyError(err, { phase: "create" }); @@ -337,12 +341,18 @@ async function performAgentCreationAttempt(deps: { } } +type AgentCreateOpts = { + apiKey: string; + model: { id: string }; + local: { cwd: string }; +}; + async function createAgentWithRetry(deps: { apiKey: string; modelId: string; log: Logger }): Promise { const { Agent } = await import("@cursor/sdk"); const { log } = deps; for (let attempt = 1; attempt <= 3; attempt++) { - const result = await performAgentCreationAttempt({ Agent: Agent as unknown as { create: (opts: { apiKey: string; model: { id: string } }) => Promise }, ...deps, attempt }); + const result = await performAgentCreationAttempt({ Agent: Agent as unknown as { create: (opts: AgentCreateOpts) => Promise }, ...deps, attempt }); if ("agent" in result) return result.agent; if (!result.canRetry) { diff --git a/tests/provider.test.ts b/tests/provider.test.ts index 5e45e1d..26f22a0 100644 --- a/tests/provider.test.ts +++ b/tests/provider.test.ts @@ -138,7 +138,10 @@ describe("createProviderHook.models()", () => { // models1 から生成された doStream なので ctx1 を使うべき expect(resolveApiKey).toHaveBeenCalledWith(ctx1, expect.anything()); expect(sdk.Agent.create).toHaveBeenCalledWith( - expect.objectContaining({ apiKey: "key-1" }), + expect.objectContaining({ + apiKey: "key-1", + local: { cwd: process.cwd() }, + }), ); }); From 68dd3c23460e2dfc6d0e681a430c1b2c58a822e3 Mon Sep 17 00:00:00 2001 From: Yusuke Ohi Date: Thu, 14 May 2026 09:42:37 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat(agent):=20=E3=83=AD=E3=83=BC=E3=82=AB?= =?UTF-8?q?=E3=83=AB=E3=83=A2=E3=83=BC=E3=83=89=E3=81=A7=E3=81=AE=E3=82=A8?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=82=A7=E3=83=B3=E3=83=88=E4=BD=9C=E6=88=90?= =?UTF-8?q?=E3=82=92=E3=82=B5=E3=83=9D=E3=83=BC=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/openai-proxy.ts | 10 +++++++++- src/provider.ts | 12 ++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/openai-proxy.ts b/src/openai-proxy.ts index 0ff647e..8e01c01 100644 --- a/src/openai-proxy.ts +++ b/src/openai-proxy.ts @@ -152,7 +152,15 @@ async function handleChat(req: IncomingMessage, res: ServerResponse, log: Logger } else { const maxRetries = 3; let attempt = 0; - const { Agent } = (await import("@cursor/sdk")) as { Agent: typeof import("@cursor/sdk").Agent }; + const { Agent } = (await import("@cursor/sdk")) as unknown as { + Agent: { + create: (opts: { + apiKey: string; + model: { id: string }; + local: { cwd: string }; + }) => Promise; + }; + }; while (attempt < maxRetries) { attempt++; diff --git a/src/provider.ts b/src/provider.ts index 0b7c066..a5429df 100644 --- a/src/provider.ts +++ b/src/provider.ts @@ -309,6 +309,12 @@ async function runDoStream(opts: { return { stream }; } +type AgentCreateOpts = { + apiKey: string; + model: { id: string }; + local: { cwd: string }; +}; + /** * Single attempt to create an agent with error classification and logging. */ @@ -341,12 +347,6 @@ async function performAgentCreationAttempt(deps: { } } -type AgentCreateOpts = { - apiKey: string; - model: { id: string }; - local: { cwd: string }; -}; - async function createAgentWithRetry(deps: { apiKey: string; modelId: string; log: Logger }): Promise { const { Agent } = await import("@cursor/sdk"); const { log } = deps;