test-studio-script-runner

โดย sanity-io

อธิบายเครื่องมือ Script Runner ของ dev/test-studio ใช้เมื่อเพิ่ม แก้ไข รัน หรือจัดทำเอกสารสคริปต์ใน dev/test-studio/src/script-runner หรือเมื่อ...

npx skills add https://github.com/sanity-io/plugins --skill test-studio-script-runner

Test Studio Script Runner

Use this skill when working with the Scripts tool in dev/test-studio.

Key Files

  • Tool plugin: dev/test-studio/src/script-runner/index.tsx
  • Runner UI: dev/test-studio/src/script-runner/ScriptRunnerTool.tsx
  • Script registry: dev/test-studio/src/script-runner/registry.ts
  • Script contract: dev/test-studio/src/script-runner/types.ts
  • Script modules: dev/test-studio/src/script-runner/scripts/*/index.ts
  • Agent-facing docs: dev/test-studio/src/script-runner/README.md

Read README.md and types.ts before changing the runner or adding scripts.

What The Tool Does

The runner is a Sanity Studio custom tool registered in the home workspace.

  • Home route: <studio>/home/scripts
  • Script route: <studio>/home/scripts/<script-name>

Scripts are browser-side TypeScript modules discovered at build time with Vite import.meta.glob. They run inside Sanity Studio with the logged-in user's permissions and receive the Studio client.

Adding A Script

Add a folder under dev/test-studio/src/script-runner/scripts/. The folder name should match the script name. Put the registered entrypoint in index.ts; any helper files can live beside it.

scripts/
  my-script-name/
    index.ts
    helpers.ts

Only scripts/*/index.ts files are discovered at build time.

import type {StudioScript} from '../../types'

const script: StudioScript = {
  name: 'my-script-name',
  title: 'My script name',
  description: 'What this script does.',
  apiVersion: '2026-03-01',
  inputs: [
    {
      name: 'documentId',
      title: 'Document ID',
      defaultValue: 'example-id',
      required: true,
    },
  ],
  async run({client, inputs, log}) {
    log.info(`Running for ${inputs.documentId}`)
    await client.fetch('*[_type == "post"][0...1]')
    log.success('Done')
  },
}

export default script

Script names must be unique and use lowercase letters, numbers, and hyphens. Keep the folder name and script name aligned. The script name becomes the URL segment.

Runtime Contract

run() receives:

  • client: Sanity Studio client, configured with the script apiVersion or the runner default.
  • inputs: string values from the run screen, keyed by input name.
  • log: info, success, warning, and error methods that append output in the UI.
  • signal: an AbortSignal reserved for script code that supports cancellation.

String Variables

Use inputs for string variables. Each input renders as a text field on the script run screen. Required inputs disable the run button until non-empty.

Available input fields:

  • name
  • title
  • description
  • defaultValue
  • placeholder
  • required

All values passed to scripts are strings. Validate and trim values inside run() when needed.

Browser-Safe Rules

Script runner modules execute in the browser. Do not use:

  • fs, path, or other Node built-ins
  • process.exit
  • direct environment variable access
  • SANITY_AUTH_TOKEN

Do not create a separate Sanity client from env vars. Use the provided client.

If a task needs Node-only APIs or token-based CLI behavior, keep it in dev/test-studio/scripts/ instead of the Studio script runner.

Verification

After changing the runner or adding scripts, run:

pnpm lint
pnpm --filter test-studio build

If pnpm --filter test-studio build fails because workspace package dist output is missing, build with dependencies first:

pnpm --filter test-studio... build

Skills เพิ่มเติมจาก sanity-io

performance-optimization
sanity-io
ปรับปรุงประสิทธิภาพการทำงานของแอปพลิเคชัน ใช้เมื่อมีข้อกำหนดด้านประสิทธิภาพ เมื่อสงสัยว่าประสิทธิภาพลดลง หรือเมื่อ Core Web Vitals หรือเวลาโหลด...
official
rxjs-like-a-pro
sanity-io
ทักษะนี้ช่วยให้คุณเขียนโค้ด RxJS ที่เป็นธรรมชาติ ประกอบกันได้ดี และปราศจากข้อผิดพลาดทั่วไป ปรัชญาหลัก: เก็บตรรกะไว้ในห่วงโซ่ observable ทุกครั้งที่คุณใช้ .subscribe() ให้ถามว่างานนั้นสามารถแสดงเป็นการแปลงภายใน .pipe() ได้หรือไม่
official
find-skills
sanity-io
ช่วยให้ผู้ใช้ค้นหาและติดตั้งสกิลเอเจนต์เมื่อพวกเขาถามคำถามเช่น "ฉันจะทำ X ได้อย่างไร", "หาสกิลสำหรับ X", "มีสกิลที่สามารถ...", หรือแสดง...
official
next-cache-components
sanity-io
Next.js 16 คอมโพเนนต์แคช - PPR, คำสั่ง use cache, cacheLife, cacheTag, updateTag
official
vercel-react-best-practices
sanity-io
แนวทางปฏิบัติที่ดีที่สุดในการเพิ่มประสิทธิภาพ React และ Next.js จากทีมวิศวกรรมของ Vercel ควรใช้ทักษะนี้เมื่อเขียน ตรวจสอบ หรือปรับโครงสร้าง React/Next.js…
official
frontend-design
sanity-io
สร้างอินเทอร์เฟซฟร้อนท์เอนด์ที่โดดเด่น มีคุณภาพระดับโปรดักชั่น พร้อมการออกแบบที่มีคุณภาพสูง ใช้ทักษะนี้เมื่อผู้ใช้ขอให้สร้างเว็บคอมโพเนนต์ เพจ หรือ...
official
plugin-transfer
sanity-io
แนะนำเอเจนต์ในการย้ายปลั๊กอินที่มีอยู่ไปยังโมโนรีโพนี้ด้วยเวิร์กโฟลว์ตัวสร้างคัดลอกปลั๊กอิน
official
create-agent-with-sanity-context
sanity-io
สร้างเอเจนต์ AI ที่สามารถเข้าถึงเนื้อหา Sanity อย่างมีโครงสร้างผ่าน Sanity Context ใช้เมื่อตั้งค่าแชทบอทที่ขับเคลื่อนด้วย Sanity หรือเชื่อมต่อผู้ช่วย AI เข้ากับ Sanity…
official