From b0c669d083b044e4767b290e3533df628e4fa1de Mon Sep 17 00:00:00 2001 From: Ikki Nishihara Date: Sun, 11 Oct 2026 17:33:29 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Stagehand=E3=81=AEWorkers=20AI=E5=85=A5?= =?UTF-8?q?=E5=8A=9B=E5=9E=8B=E3=82=92=E4=BF=AE=E6=AD=A3=20#227?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cf_typecheck_stagehand.yml | 34 +++++++++++++++++++ .../examples/stagehand/package.json | 1 + .../stagehand/src/worker/workersAIClient.ts | 8 +++-- 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/cf_typecheck_stagehand.yml diff --git a/.github/workflows/cf_typecheck_stagehand.yml b/.github/workflows/cf_typecheck_stagehand.yml new file mode 100644 index 000000000..a8111a818 --- /dev/null +++ b/.github/workflows/cf_typecheck_stagehand.yml @@ -0,0 +1,34 @@ +name: "Playwright for Cloudflare - Stagehand Typecheck" + +on: + pull_request: + paths: + - "packages/playwright-cloudflare/examples/stagehand/**" + - ".github/workflows/cf_typecheck_stagehand.yml" + push: + branches: [main] + paths: + - "packages/playwright-cloudflare/examples/stagehand/**" + - ".github/workflows/cf_typecheck_stagehand.yml" + +permissions: + contents: read + +jobs: + typecheck: + runs-on: ubuntu-latest + defaults: + run: + working-directory: packages/playwright-cloudflare/examples/stagehand + env: + WRANGLER_SEND_METRICS: "false" + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: "24.x" + cache: npm + cache-dependency-path: packages/playwright-cloudflare/examples/stagehand/package-lock.json + - run: npm ci + - run: npx wrangler types + - run: npm run typecheck diff --git a/packages/playwright-cloudflare/examples/stagehand/package.json b/packages/playwright-cloudflare/examples/stagehand/package.json index 8d0fe1c10..560c84332 100644 --- a/packages/playwright-cloudflare/examples/stagehand/package.json +++ b/packages/playwright-cloudflare/examples/stagehand/package.json @@ -9,6 +9,7 @@ "scripts": { "dev": "vite", "build": "vite build", + "typecheck": "tsc --noEmit", "preview": "npm run build && vite preview", "deploy": "npm run build && wrangler deploy" }, diff --git a/packages/playwright-cloudflare/examples/stagehand/src/worker/workersAIClient.ts b/packages/playwright-cloudflare/examples/stagehand/src/worker/workersAIClient.ts index 8b08b0af9..bff0c7a10 100644 --- a/packages/playwright-cloudflare/examples/stagehand/src/worker/workersAIClient.ts +++ b/packages/playwright-cloudflare/examples/stagehand/src/worker/workersAIClient.ts @@ -10,6 +10,7 @@ type WorkersAIOptions = AiOptions & { }; const modelId = "@cf/meta/llama-3.3-70b-instruct-fp8-fast"; +type ModelInputs = AiModels[typeof modelId]["inputs"]; // Basic implementation of LLMClient for Workers AI. // This uses @cf/meta/llama-3.3-70b-instruct-fp8-fast model. If you want to @@ -29,16 +30,17 @@ export class WorkersAIClient extends LLMClient { async createChatCompletion({ options }: CreateChatCompletionOptions): Promise { const schema = options.response_model?.schema; this.options?.logger?.({ category: "workersai", message: "thinking..." }); - const { response } = await this.binding.run(this.modelName as keyof AiModels, { + // Stagehand's message and tool types are broader than the Workers AI declarations. + const inputs = { messages: options.messages, - // @ts-ignore tools: options.tools, response_format: schema ? { type: "json_schema", json_schema: zodToJsonSchema(schema), } : undefined, temperature: 0, - }, this.options) as AiTextGenerationOutput; + } as unknown as ModelInputs; + const { response } = await this.binding.run(modelId, inputs, this.options) as AiTextGenerationOutput; this.options?.logger?.({ category: "workersai", message: "completed thinking!" }); return {