Skip to content

Allow InputType and InputSchema to diverge#13

Open
konard wants to merge 3 commits intotool2agent:masterfrom
konard:issue-4-8d4dadbba73d
Open

Allow InputType and InputSchema to diverge#13
konard wants to merge 3 commits intotool2agent:masterfrom
konard:issue-4-8d4dadbba73d

Conversation

@konard
Copy link
Copy Markdown

@konard konard commented Dec 27, 2025

Summary

Implements the proposed solution from issue #4 to allow InputType and InputSchema to diverge in the tool2agent function.

  • Add optional generic type parameters InputType and OutputType to tool2agent() that default to z.infer<InputSchema> and z.infer<OutputSchema> respectively
  • Middleware can now extend execute() inputs with additional context (e.g., WithTrackedEnv<InputType>) without unsafe type casts
  • The inputSchema still defines what the LLM generates, while InputType represents what the execute function receives

Example usage

// Define the base input schema (what the LLM generates)
const inputSchema = z.object({ query: z.string() });

// Define an extended input type (what middleware adds)
type ExtendedInput = z.infer<typeof inputSchema> & {
  middlewareContext: {
    userId: string;
    requestId: string;
  };
};

// Create a tool with extended input type
const tool = tool2agent<typeof inputSchema, typeof outputSchema, ExtendedInput>({
  inputSchema,
  outputSchema,
  execute: async (params: ExtendedInput) => {
    // params.middlewareContext is now available, added by middleware
    return { ok: true, value: { greeting: `Hello!` } };
  },
});

Test plan

  • All existing tests pass (55 passing, 2 pre-existing failures unrelated to this change)
  • Added type-level tests for the new functionality in test-d/index.test-d.ts
  • Lint and format checks pass
  • TypeScript compilation succeeds

Fixes #4

🤖 Generated with Claude Code

konard and others added 2 commits December 27, 2025 11:49
Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: tool2agent#4
Add optional generic type parameters InputType and OutputType to tool2agent
that default to z.infer<InputSchema> and z.infer<OutputSchema> respectively.

This enables middleware to extend execute() inputs with additional context
(e.g., WithTrackedEnv<InputType>) without needing unsafe type casts. The
inputSchema still defines what the LLM generates, while InputType represents
what the execute function receives (which may include middleware-injected data).

Changes:
- Add InputType and OutputType generic params to Tool2AgentParams
- Add InputType and OutputType generic params to tool2agent function
- Add ts-node transpileOnly config to support complex generics in tests
- Add type-level tests for the new functionality

Fixes tool2agent#4

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Allow InputType and InputSchema to diverge. Allow InputType and InputSchema to diverge Dec 27, 2025
@konard konard marked this pull request as ready for review December 27, 2025 11:09
@konard
Copy link
Copy Markdown
Author

konard commented Dec 27, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $11.358220 USD
  • Calculated by Anthropic: $7.238375 USD
  • Difference: $-4.119845 (-36.27%)
    📎 Log file uploaded as GitHub Gist (1076KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

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.

Allow InputType and InputSchema to diverge.

1 participant