Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schematic Component Overview #62

Merged
merged 1 commit into from
Oct 23, 2024
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
Binary file modified bun.lockb
Binary file not shown.
157 changes: 157 additions & 0 deletions docs/SCHEMATIC_COMPONENT_OVERVIEW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Circuit JSON Specification: Schematic Component Overview

> Created at 2024-10-23T22:29:08.481Z
> Latest Version: https://github.com/tscircuit/circuit-json/blob/main/docs/SCHEMATIC_COMPONENT_OVERVIEW.md
Any type below can be imported from `circuit-json`. Every type has a corresponding
snake_case version which is a zod type that can be used to parse unknown json,
for example `SchematicComponent` has a `schematic_component.parse` function that you
can also import.

```ts
interface SchematicTrace {
type: "schematic_trace"
schematic_trace_id: string
source_trace_id: string
edges: Array<{
from: {
x: number
y: number
}
to: {
x: number
y: number
}
from_schematic_port_id?: string
to_schematic_port_id?: string
}>
}

interface SchematicBox {
type: "schematic_box"
schematic_component_id: string
width: number
height: number
x: number
y: number
}

interface SchematicLine {
type: "schematic_line"
schematic_component_id: string
x1: number
x2: number
y1: number
y2: number
}

interface SchematicError {
schematic_error_id: string
type: "schematic_error"
error_type: "schematic_port_not_found"
message: string
}

interface SchematicComponent {
type: "schematic_component"
rotation: number
size: { width: number; height: number }
center: { x: number; y: number }
source_component_id: string
schematic_component_id: string
pin_spacing?: number
pin_styles?: Record<
string,
{
left_margin?: number
right_margin?: number
top_margin?: number
bottom_margin?: number
}
>
box_width?: number
symbol_name?: string
port_arrangement?:
| {
left_size: number
right_size: number
top_size?: number
bottom_size?: number
}
| {
left_side?: {
pins: number[]
direction?: "top-to-bottom" | "bottom-to-top"
}
right_side?: {
pins: number[]
direction?: "top-to-bottom" | "bottom-to-top"
}
top_side?: {
pins: number[]
direction?: "left-to-right" | "right-to-left"
}
bottom_side?: {
pins: number[]
direction?: "left-to-right" | "right-to-left"
}
}
port_labels?: Record<string, string>
}

interface SchematicDebugRect {
type: "schematic_debug_object"
label?: string
shape: "rect"
center: { x: number; y: number }
size: { width: number; height: number }
}

interface SchematicDebugLine {
type: "schematic_debug_object"
label?: string
shape: "line"
start: { x: number; y: number }
end: { x: number; y: number }
}

type SchematicDebugObject = SchematicDebugRect | SchematicDebugLine

interface SchematicPort {
type: "schematic_port"
schematic_port_id: string
source_port_id: string
schematic_component_id?: string
center: { x: number; y: number }
facing_direction?: "up" | "down" | "left" | "right"
}

interface SchematicNetLabel {
type: "schematic_net_label"
source_net_id: string
center: { x: number; y: number }
anchor_side: "top" | "bottom" | "left" | "right"
text: string
}

interface SchematicPath {
type: "schematic_path"
schematic_component_id: string
fill_color?: "red" | "blue"
is_filled?: boolean
points: Array<{ x: number; y: number }>
}

interface SchematicText {
type: "schematic_text"
schematic_component_id: string
schematic_text_id: string
text: string
position: {
x: number
y: number
}
rotation: number
anchor: "center" | "left" | "right" | "top" | "bottom"
}
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@anthropic-ai/sdk": "^0.27.3",
"@anthropic-ai/sdk": "^0.30.1",
"@biomejs/biome": "^1.9.4",
"@types/bun": "^1.1.10",
"@types/convert-units": "^2.3.9",
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-pcb-component-overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const fileContents = fs
const anthropic = new Anthropic()

const msg = await anthropic.messages.create({
model: "claude-3-5-sonnet-20240620",
model: "claude-3-5-sonnet-20241022",
max_tokens: 4096,
messages: [
{
Expand Down
59 changes: 59 additions & 0 deletions scripts/generate-schematic-component-overview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import Anthropic from "@anthropic-ai/sdk"
import fs from "node:fs"
import path from "node:path"

// Read all the files in the src/schematic directory
const schematicDir = path.join(__dirname, "../src/schematic")
const fileContents = fs
.readdirSync(schematicDir)
.map((file) => path.join(schematicDir, file))
.filter((file) => file.endsWith(".ts"))
.map(
(file) => fs.readFileSync(file, "utf8"),
// // remove any lines that import
// .replace(/^import .*;$/gm, "")
// // remove any lines with z.infer, z.input, or z.output
// .replace(/^type .*=.*z\.(infer|input|output)<.*>$/gm, ""),
)

// Extract the type definitions from the file contents
const anthropic = new Anthropic()

const msg = await anthropic.messages.create({
model: "claude-3-5-sonnet-20241022",
max_tokens: 4096,
messages: [
{
role: "user",
content: `Extract/write interfaces all the exported type definitions from the following file contents. Do not include deprecated types. If it's a zod type, return the type without zod references (you may need to write a new type definition). Return as a \`\`\`ts codeblock.\n\n${fileContents.join("\n")}`,
},
],
})

const resText: string = (msg as any).content[0].text

const codefence = resText
.split("```")[1]!
.replace(/^ts\n/, "")
.replace(/^typescript\n/, "")

// Write to docs/SCHEMATIC_COMPONENT_OVERVIEW.md
const template = `# Circuit JSON Specification: Schematic Component Overview
> Created at ${new Date().toISOString()}
> Latest Version: https://github.com/tscircuit/circuit-json/blob/main/docs/SCHEMATIC_COMPONENT_OVERVIEW.md
Any type below can be imported from \`circuit-json\`. Every type has a corresponding
snake_case version which is a zod type that can be used to parse unknown json,
for example \`SchematicComponent\` has a \`schematic_component.parse\` function that you
can also import.
\`\`\`ts
${codefence}
\`\`\`
`.trim()

fs.writeFileSync(
path.join(__dirname, "../docs/SCHEMATIC_COMPONENT_OVERVIEW.md"),
template,
)
Loading