Skip to content

Add TypeScript drawing example mirroring Python drawing sample#336

Merged
TalZaccai merged 4 commits into
mainfrom
copilot/238-add-typescript-example
Jun 1, 2026
Merged

Add TypeScript drawing example mirroring Python drawing sample#336
TalZaccai merged 4 commits into
mainfrom
copilot/238-add-typescript-example

Conversation

Copilot AI commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

This PR adds a TypeScript example equivalent to the Python drawing sample from PR #238, so the same structured drawing workflow is available in both SDKs. It introduces schema-driven translation for drawing intents plus a renderer output path in the TypeScript examples set.

  • New drawing example workspace

    • Added typescript/examples/drawing with its own package.json, tsconfig, README, and sample prompts.
    • Wired into the existing examples workspace build flow.
  • Drawing schema + translator loop

    • Added drawingSchema.ts with Drawing, Box, Ellipse, Arrow, Style, and UnknownText.
    • Added main.ts that translates user input to Drawing JSON and keeps request history across turns to support iterative refinements.
  • Renderer output

    • Added render.ts to convert translated drawing objects into SVG primitives (rect, ellipse, line with arrow marker), including style handling (fill/stroke/dash/corners).
    • Writes rendered output to dist/drawing.svg on successful translations.
  • Examples index update

    • Added Drawing to typescript/examples/README.md so it appears in the canonical example list.
const validator = createTypeScriptJsonValidator<Drawing>(schema, "Drawing");
const translator = createJsonTranslator(model, validator);

const response = await translator.translate(history.join("\n"));
if (response.success) {
  fs.writeFileSync(outputPath, renderDrawingToSvg(response.data), "utf8");
}

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a TypeScript counterpart to the Python drawing sample (PR #238): a new drawing example workspace that translates natural-language requests into a typed Drawing JSON via TypeChat and renders the result to SVG.

Changes:

  • New typescript/examples/drawing workspace (package.json, src/tsconfig.json, README) wired into the examples workspaces.
  • drawingSchema.ts defining Drawing/Box/Ellipse/Arrow/Style/UnknownText, plus a main.ts interactive loop that joins request history before translating.
  • render.ts that emits SVG (rect/ellipse/line with arrowhead marker, fill/stroke/dash/rounded corners) and writes to dist/drawing.svg.
Show a summary per file
File Description
typescript/examples/README.md Adds Drawing to the canonical example list.
typescript/examples/drawing/README.md New per-example README and usage instructions.
typescript/examples/drawing/package.json New workspace manifest mirroring the math example.
typescript/examples/drawing/src/tsconfig.json Strict TS build config for the example.
typescript/examples/drawing/src/drawingSchema.ts New schema with shape, style, and unknown-text types (uses snake_case props).
typescript/examples/drawing/src/main.ts Translator loop that appends to history before translating.
typescript/examples/drawing/src/render.ts Converts Drawing to SVG primitives with style handling.
typescript/examples/drawing/src/input.txt Sample iterative prompts.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 8/8 changed files
  • Comments generated: 2

Comment thread typescript/examples/drawing/src/drawingSchema.ts Outdated
Comment thread typescript/examples/drawing/src/main.ts
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@robgruen robgruen marked this pull request as ready for review June 1, 2026 22:19
@TalZaccai TalZaccai merged commit 1e610bf into main Jun 1, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants