From c05d8dcded25323524dd096df1ab3204e379f36c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=87=95=E8=B5=84=E4=BC=9F?= <> Date: Mon, 8 Jun 2026 17:46:59 +0800 Subject: [PATCH] Use generated docs in local circuit prompt --- .../create-local-circuit-prompt.ts | 6 +- tests/tscircuitCoder.test.ts | 63 ++++++++++--------- tests/utils/generate-random-prompts.test.ts | 15 +++-- 3 files changed, 44 insertions(+), 40 deletions(-) diff --git a/lib/prompt-templates/create-local-circuit-prompt.ts b/lib/prompt-templates/create-local-circuit-prompt.ts index a93f11f..7a814dc 100644 --- a/lib/prompt-templates/create-local-circuit-prompt.ts +++ b/lib/prompt-templates/create-local-circuit-prompt.ts @@ -1,7 +1,7 @@ import { + fp, getFootprintNamesByType, getFootprintSizes, - fp, } from "@tscircuit/footprinter" async function fetchFileContent(url: string): Promise { @@ -34,9 +34,7 @@ export const createLocalCircuitPrompt = async () => { ) const propsDoc = - (await fetchFileContent( - "https://raw.githubusercontent.com/tscircuit/props/main/generated/COMPONENT_TYPES.md", - )) || "" + (await fetchFileContent("https://docs.tscircuit.com/ai.txt")) || "" const cleanedPropsDoc = propsDoc .split("\n") diff --git a/tests/tscircuitCoder.test.ts b/tests/tscircuitCoder.test.ts index d66c022..ed765a6 100644 --- a/tests/tscircuitCoder.test.ts +++ b/tests/tscircuitCoder.test.ts @@ -1,39 +1,42 @@ -import { createTscircuitCoder } from "lib/tscircuit-coder/tscircuitCoder" import { expect, test } from "bun:test" +import { createTscircuitCoder } from "lib/tscircuit-coder/tscircuitCoder" import { getPrimarySourceCodeFromVfs } from "lib/utils/get-primary-source-code-from-vfs" -test("TscircuitCoder submitPrompt streams and updates vfs", async () => { - const streamedChunks: string[] = [] - let vfsUpdated = false - const tscircuitCoder = createTscircuitCoder() - tscircuitCoder.on("streamedChunk", (chunk: string) => { - streamedChunks.push(chunk) - }) - tscircuitCoder.on("vfsChanged", () => { - vfsUpdated = true - }) +test.skipIf(!process.env.OPENAI_API_KEY)( + "TscircuitCoder submitPrompt streams and updates vfs", + async () => { + const streamedChunks: string[] = [] + let vfsUpdated = false + const tscircuitCoder = createTscircuitCoder() + tscircuitCoder.on("streamedChunk", (chunk: string) => { + streamedChunks.push(chunk) + }) + tscircuitCoder.on("vfsChanged", () => { + vfsUpdated = true + }) - await tscircuitCoder.submitPrompt({ - prompt: "create bridge rectifier circuit", - }) + await tscircuitCoder.submitPrompt({ + prompt: "create bridge rectifier circuit", + }) - await tscircuitCoder.submitPrompt({ - prompt: "add a transistor component", - }) + await tscircuitCoder.submitPrompt({ + prompt: "add a transistor component", + }) - let codeWithTransistor = getPrimarySourceCodeFromVfs(tscircuitCoder.vfs) - expect(codeWithTransistor).toInclude("transistor") + const codeWithTransistor = getPrimarySourceCodeFromVfs(tscircuitCoder.vfs) + expect(codeWithTransistor).toInclude("transistor") - await tscircuitCoder.submitPrompt({ - prompt: "add a tssop20 chip", - }) + await tscircuitCoder.submitPrompt({ + prompt: "add a tssop20 chip", + }) - let codeWithChip = getPrimarySourceCodeFromVfs(tscircuitCoder.vfs) - expect(codeWithChip).toInclude("tssop20") - expect(codeWithChip).toInclude("transistor") + const codeWithChip = getPrimarySourceCodeFromVfs(tscircuitCoder.vfs) + expect(codeWithChip).toInclude("tssop20") + expect(codeWithChip).toInclude("transistor") - expect(streamedChunks.length).toBeGreaterThan(0) - const vfsKeys = Object.keys(tscircuitCoder.vfs) - expect(vfsKeys.length).toBeGreaterThan(0) - expect(vfsUpdated).toBe(true) -}) + expect(streamedChunks.length).toBeGreaterThan(0) + const vfsKeys = Object.keys(tscircuitCoder.vfs) + expect(vfsKeys.length).toBeGreaterThan(0) + expect(vfsUpdated).toBe(true) + }, +) diff --git a/tests/utils/generate-random-prompts.test.ts b/tests/utils/generate-random-prompts.test.ts index 41a061c..6df587b 100644 --- a/tests/utils/generate-random-prompts.test.ts +++ b/tests/utils/generate-random-prompts.test.ts @@ -1,11 +1,14 @@ -import { describe, it, expect } from "bun:test" +import { describe, expect, it } from "bun:test" import { generateRandomPrompts } from "../../lib/utils/generate-random-prompts" describe("generateRandomPrompts", () => { - it("should return an array of prompts", async () => { - const prompts = await generateRandomPrompts(3) + it.skipIf(!process.env.OPENAI_API_KEY)( + "should return an array of prompts", + async () => { + const prompts = await generateRandomPrompts(3) - expect(Array.isArray(prompts)).toBe(true) - expect(prompts.length).toBe(3) - }) + expect(Array.isArray(prompts)).toBe(true) + expect(prompts.length).toBe(3) + }, + ) })