diff --git a/packages/experimental/cua-macos/tests/persistent-bridge.built.e2e.ts b/packages/experimental/cua-macos/tests/persistent-bridge.built.e2e.ts index 742319c72d..b37b79b6c1 100644 --- a/packages/experimental/cua-macos/tests/persistent-bridge.built.e2e.ts +++ b/packages/experimental/cua-macos/tests/persistent-bridge.built.e2e.ts @@ -4,7 +4,7 @@ import { existsSync } from 'node:fs' import { mkdtemp, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import { dirname, join } from 'node:path' -import { fileURLToPath, pathToFileURL } from 'node:url' +import { fileURLToPath } from 'node:url' import { Context } from '@deepseek-ai/cordis' import Loader from '@deepseek-ai/cordis-plugin-loader' import { mountAgentLoopTestDependencies, mountAgentLoopTestHarness } from '@deepseek-ai/dsh-agent-loop-testkit' @@ -71,7 +71,9 @@ it.skipIf(process.platform === 'win32' || !existsSync(bridge) || !existsSync(boo } } }], })) expect((await run('await import("@deepseek-ai/dsh-cua/bridge")', 'unresolved')).error?.message).toContain('Cannot find package') - const initialization = `var { connectCua } = await import(${JSON.stringify(pathToFileURL(bridge).href)});\nvar cua = connectCua(() => tools.cua, text => console.log(text));` + const section = (await ctx.systemPrompt.assemble()).sections.find(value => value.name === 'computer-use:dsh-cua') + const initialization = section?.text.match(/Persistent PTC initialization:\n\n```ts\n([\s\S]*?)\n```/u)?.[1] + expect(initialization).toContain('/lib/bridge.js') const first = await run(`${initialization}\nvar app = await cua.getApp("test.fixture"); var win = await app.getWindow(7); await win.click("0"); var shot = await win.getScreenshot(); ({ mimeType: shot.mimeType, pixelWidth: shot.pixelWidth, pixelHeight: shot.pixelHeight, windowId: shot.windowId, byteLength: shot.bytes.length });`, 'first') expect(first.error).toBeUndefined() expect(first.value).toEqual({ mimeType: 'image/png', pixelWidth: 1, pixelHeight: 1, windowId: 7, byteLength: 90 }) diff --git a/packages/experimental/cua-macos/tests/provider-lifecycle.spec.ts b/packages/experimental/cua-macos/tests/provider-lifecycle.spec.ts index 4176134351..59aea174b6 100644 --- a/packages/experimental/cua-macos/tests/provider-lifecycle.spec.ts +++ b/packages/experimental/cua-macos/tests/provider-lifecycle.spec.ts @@ -901,7 +901,7 @@ it('adds an installation-owned bridge URL when persistent PTC is available', asy await f.ctx.plugin(Sandbox) await f.ctx.plugin(SandboxPolicy) await f.ctx.plugin(NodeRuntime, { executionMode: 'persistent-in-memory' }) - expect(await text()).toContain(new URL('../../cua/src/bridge.ts', import.meta.url).href) + expect(await text()).toContain(new URL('../../cua/lib/bridge.js', import.meta.url).href) }) it('keeps Cordis loading until preparation succeeds and reports preparation failure through the fiber', async () => { diff --git a/packages/experimental/cua/src/tool-registration.ts b/packages/experimental/cua/src/tool-registration.ts index 9d01d8459d..53a4aa2ba5 100644 --- a/packages/experimental/cua/src/tool-registration.ts +++ b/packages/experimental/cua/src/tool-registration.ts @@ -28,7 +28,9 @@ const programDescription = 'Run a TypeScript program to observe and operate desk export function installCuaTools( ctx: Context, config: CuaConfig, tool: ToolDefinition, guidance: string, programGuidance: string, ): () => void | Promise { - const bridgeUrl = JSON.stringify(new URL(`./bridge${extname(new URL(import.meta.url).pathname)}`, import.meta.url).href) + // PTC publishes the installed JS entry; automatic CUA initialization follows the Host's code format. + const ptcBridgeUrl = JSON.stringify(new URL('../lib/bridge.js', import.meta.url).href) + const programBridgeUrl = JSON.stringify(new URL(`./bridge${extname(new URL(import.meta.url).pathname)}`, import.meta.url).href) const prompt = { name: 'computer-use:dsh-cua', order: ctx.systemPrompt.getSectionOrder('TOOL_COMPUTER_USE') } const rawPrompt: PromptSection = { ...prompt, text: () => { const runtime = ctx.get('ptcRuntime') @@ -37,7 +39,7 @@ export function installCuaTools( Persistent PTC initialization: \`\`\`ts -var { connectCua } = await import(${bridgeUrl}); +var { connectCua } = await import(${ptcBridgeUrl}); var cua = connectCua(() => tools.cua, text => console.log(text)); \`\`\`` } } @@ -59,7 +61,7 @@ var cua = connectCua(() => tools.cua, text => console.log(text)); const program = createRunCodeTool(consumer, { name: 'cua_run_code', description: programDescription, runtime: consumer.ptcRuntime, tools: [tool], limits: config.runCode.executor, - initialization: `globalThis.cua ??= (await import(${bridgeUrl})).connectCua(() => tools.cua, text => console.log(text));`, + initialization: `globalThis.cua ??= (await import(${programBridgeUrl})).connectCua(() => tools.cua, text => console.log(text));`, }) const scopes = new Map void } }>() consumer.effect(() => async () => { diff --git a/snapshots/session/ptc-script-retained/system-prompt.expected.md b/snapshots/session/ptc-script-retained/system-prompt.expected.md index 2d8ea7912e..2fb8f327e3 100644 --- a/snapshots/session/ptc-script-retained/system-prompt.expected.md +++ b/snapshots/session/ptc-script-retained/system-prompt.expected.md @@ -92,7 +92,7 @@ Maximum click holdMs: 5000 ms. Persistent PTC initialization: ```ts -var { connectCua } = await import("file://{{cwd}}/cua-runtime/src/bridge.ts"); +var { connectCua } = await import("file://{{cwd}}/cua-runtime/lib/bridge.js"); var cua = connectCua(() => tools.cua, text => console.log(text)); ```