Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["typescript", "unicorn", "oxc"],
"categories": {
"correctness": "error"
},
"rules": {
"unicorn/no-thenable": "off"
},
"env": {
"builtin": true
}
}
41 changes: 41 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@
"test:watch": "vitest",
"compile": "tsc --noEmit",
"format": "oxfmt",
"check": "bun --parallel compile 'oxfmt --check'"
"lint": "oxlint --fix",
"check": "bun --parallel compile 'oxfmt --check' 'oxlint'"
},
"dependencies": {
"@cursor/sdk": "1.0.18"
},
"devDependencies": {
"@types/bun": "1.3.14",
"oxfmt": "0.53.0",
"oxlint": "1.70.0",
"typescript": "7.0.1-rc",
"vitest": "4.1.8"
}
Expand Down
15 changes: 14 additions & 1 deletion scripts/cursor-sdk-local-agent-bridge.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const clientToolCallbackPath = "/client-tool-call"

const agentCache = new Map()
const agentRunQueues = new Map()
/** @type {Map<string, Set<unknown>>} */
const activeClientToolCaptures = new Map()
const forceNextRunAgentKeys = new Set()
let server = null
Expand Down Expand Up @@ -76,6 +77,12 @@ function startServer() {
return server
}

/**
* Handle a request to the local-agent bridge.
* @param {Request} request - The request to handle.
* @param {Response} response - The response to write the result to.
* @returns {Promise<void>}
*/
async function handleRequest(request, response) {
const url = new URL(request.url || "/", `http://${request.headers.host || `${host}:${port}`}`)

Expand Down Expand Up @@ -415,6 +422,7 @@ function registerActiveClientToolCapture(cacheKey, handler) {
async function captureActiveClientToolCall(cacheKey, toolCall) {
const handlers = activeClientToolCaptures.get(cacheKey)
if (!handlers || handlers.size === 0) return false
// oxlint-disable-next-line no-useless-spread (this is mutated concurrently, snapshot is required)
for (const handler of [...handlers]) {
if (await handler(toolCall)) return true
}
Expand Down Expand Up @@ -580,7 +588,7 @@ async function runClientForwardingMcpServer({
pending.add(task)
})
rl.on("close", async () => {
await Promise.allSettled([...pending])
await Promise.allSettled(pending)
resolve()
})
})
Expand Down Expand Up @@ -2442,6 +2450,11 @@ function parseClientTools(value) {
})
}

/**
* Read a JSON body from a request.
* @param {Request} request - The request to read the body from.
* @returns {Promise<Record<string, unknown>>} The parsed JSON body.
*/
async function readJsonBody(request) {
let body = ""
for await (const chunk of request) {
Expand Down
10 changes: 0 additions & 10 deletions worker/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1621,10 +1621,6 @@ function localSdkBridgeJsonResponse(kind: ReturnType<typeof sdkRunKind>): Respon
})
}

function decodeBase64ForTest(value: string): string {
return new TextDecoder().decode(Uint8Array.from(atob(value), (char) => char.charCodeAt(0)))
}

function concatTestBytes(chunks: Uint8Array[]): Uint8Array {
const total = chunks.reduce((sum, chunk) => sum + chunk.length, 0)
const output = new Uint8Array(total)
Expand All @@ -1636,12 +1632,6 @@ function concatTestBytes(chunks: Uint8Array[]): Uint8Array {
return output
}

function sseFrame(event: string, data: unknown, id?: string): Uint8Array {
return new TextEncoder().encode(
`${id ? `id: ${id}\n` : ""}event: ${event}\ndata: ${JSON.stringify(data)}\n\n`,
)
}

function chatResponseThinking(text: string): Uint8Array {
return protoMessage([
protoField(2, protoMessage([protoField(25, protoMessage([protoField(1, text)]))])),
Expand Down