Skip to content

Add TypeSpec AI Tools emitter to generate Effect SchemasFeature/schema gen#21

Open
adilhbay wants to merge 25 commits intothe-dev-tools:mainfrom
adilhbay:feature/schema-gen
Open

Add TypeSpec AI Tools emitter to generate Effect SchemasFeature/schema gen#21
adilhbay wants to merge 25 commits intothe-dev-tools:mainfrom
adilhbay:feature/schema-gen

Conversation

@adilhbay
Copy link

Summary

  • Add TypeSpec emitter that generates Effect Schema definitions from TypeSpec models
  • Support for @mutationTool, @explorationTool, and @executionTool decorators
  • Auto-generate mutation tool schemas (Create/Update/Delete) from collection models
  • Fix schema generation for optional fields with descriptions
  • Split ConnectNodes into sequential and branching tools for clearer API

adilhbay and others added 25 commits January 21, 2026 22:06
   - Use Object.values().map() instead of manual listing in index.ts
   - Delete schemas-effect.ts (209 lines of unnecessary re-exports)
   - Delete test-effect-schemas.ts (development artifact)
   - Build validation map dynamically from EffectSchemas

   Adding a new tool now requires only 2 steps:
   1. Add schema to MutationSchemas/ExplorationSchemas/ExecutionSchemas
   2. Run pnpm generate:schemas
Replace hand-written Effect Schema definitions with TypeSpec-generated code.
This introduces a new emitter that transforms @aitool decorated models into
Effect Schema TypeScript files.

New emitter infrastructure (tools/spec-lib/src/ai-tools/):
- lib.ts: @aitool decorator and ToolCategory enum
- main.tsp: TypeSpec declarations
- emitter.tsx: Alloy.js emitter generating Effect Schemas
- index.ts: Module exports

Tool definitions moved to TypeSpec (packages/spec/api/flow.tsp):
- 12 Mutation tools (CreateJsNode, ConnectNodes, etc.)
- 8 Exploration tools (GetWorkflowGraph, SearchApiDocs, etc.)
- 3 Execution tools (RunWorkflow, StopWorkflow, ValidateWorkflow)

The emitter generates code that imports shared schemas from common.ts
and produces the same JSON Schema output as the hand-written files.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
… decorator

Replace 23 duplicate AI tool models with a @mutationTool decorator on
collection models. The emitter resolves Insert/Update/Delete properties
at emit time based on primary keys, visibility, and exclude lists.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Auto-generate Get{ModelName} exploration tools from @mutationTool-decorated
collections using PK fields. Annotate FlowRunRequest/FlowStopRequest with
@aitool for execution schema generation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ema generation

Add a new @explorationTool decorator that generates custom exploration tools
from collection model primary keys. Apply it to the Flow model to create a
ValidateWorkflow tool. Also wire up execution and exploration schemas into
the JSON schema generator alongside mutations.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Extract getFieldSchema/formatStringLiteral to field-schema.ts, replace
implicit auto-generated Get* exploration tools with explicit @explorationTool
decorators on each mutation model, unify 3 import components and 4
tool/property schema components into single generic versions, and simplify
CategoryFiles to a uniform rendering path. Reduces emitter from 772 to 331
lines.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Make sourceHandle optional on Edge model so ConnectNodes allows omitting
it for sequential flows. Add exclude support to the emitter's Update case
so UpdateNodeConfig correctly omits the immutable kind field.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace single ConnectNodes tool with two specialized tools:
- ConnectSequentialNodes: excludes sourceHandle for ManualStart/JS/HTTP nodes
- ConnectBranchingNodes: requires sourceHandle for Condition/For/ForEach nodes

This eliminates the need for optional sourceHandle which caused Go type issues.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix OptionalPosition to apply annotations inside Schema.optional wrapper
- Fix emitter to generate correct code for optional fields with descriptions
- Add src/tools to tsconfig.lib.json include list
- Fix index signature access to use bracket notation in index.ts

Schema.optional() returns a PropertySignature that cannot be piped,
so annotations must be applied to the inner schema first.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…tter output

The emitter now generates common.ts and index.ts alongside the category files
in dist/ai-tools/v1/, removing the dependency on hand-written src/tools/ files.
JSON Schema conversion happens at module import time instead of a separate
build step.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…nd mutationTool

Makes name, title, and description optional on explorationTool/mutationTool decorators,
computing defaults from the model name using PascalCase splitting. Simplifies flow.tsp
by removing redundant decorator arguments that match the derived defaults.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use <hbr /> instead of {'\n'} and code tag instead of manual brace
expressions for improved readability. Output is unchanged.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
These files don't use any TypeSpec data - they're just hardcoded strings
in the emitter. Moving them to source files in packages/spec/src/tools/
reduces complexity and makes them easier to maintain.

- Create packages/spec/src/tools/common.ts with shared schemas
- Create packages/spec/src/tools/index.ts with runtime utilities
- Remove CommonSchemaFile and IndexFile components from emitter
- Update package.json exports to point to source files
- Generated files now import from @the-dev-tools/spec/tools/common

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Consolidates schema-related code in spec-lib package. The emitter now
generates imports from @the-dev-tools/spec-lib/common, avoiding circular
dependencies by hardcoding enum values instead of importing from protobuf.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Documents that ErrorHandling and SourceHandle literals must stay in
sync with protobuf definitions in api/flow/v1/flow.proto.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Runtime utilities (schemaToToolDefinition, validateToolInput, allToolSchemas)
are only used by the agent, so they belong in the client package. The spec
package now only exports the generated schemas.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use Effect's idiomatic error handling with Schema.decodeUnknownEither
and Either.mapLeft instead of wrapping decodeUnknownSync in try-catch.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant