Skip to content

Adding JSON schema#76

Open
sapiderman wants to merge 8 commits intohyperjumptech:mainfrom
sapiderman:add-json-schema
Open

Adding JSON schema#76
sapiderman wants to merge 8 commits intohyperjumptech:mainfrom
sapiderman:add-json-schema

Conversation

@sapiderman
Copy link
Collaborator

@sapiderman sapiderman commented Mar 4, 2026

PR

  1. Implements Add JSON schema for delivery-agent config #71
  2. Adding Schema validation

How to test

  1. Ran delivery.test.ts, expect all to pass.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds shared schema/type definitions for the delivery agent to the @workspace/agent-types package and updates the delivery agent to reuse the shared input schema for request validation.

Changes:

  • Added deliveryConfigSchema, deliveryInputSchema, and deliveryOutputSchema (plus inferred TS types) to @workspace/agent-types, and re-exported them from the package index.
  • Added Vitest tests for the new delivery schemas in @workspace/agent-types.
  • Updated the delivery agent POST handler to validate request bodies using the shared deliveryInputSchema and to return a 400 with details on Zod validation errors.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pnpm-lock.yaml Adds workspace linkage for @workspace/agent-types in the delivery agent importer.
packages/agent-types/src/index.ts Re-exports the new delivery schemas/types from @workspace/agent-types.
packages/agent-types/src/delivery.ts Introduces Zod schemas and inferred types for delivery config/input/output.
packages/agent-types/src/delivery.test.ts Adds Vitest coverage for the new delivery schemas.
apps/agents/delivery/src/_main.ts Switches request validation to shared schema; adds ZodError→400 response handling; adds docstring.
apps/agents/delivery/package.json Adds @workspace/agent-types dependency.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (2)

apps/agents/delivery/src/_main.ts:33

  • context.req.json() will throw on invalid JSON, but that currently falls through to the generic 500 handler. Since you’re already returning 400 for Zod validation errors, it would be more correct to also return a 400 for JSON parse errors (e.g., SyntaxError) so malformed requests aren’t reported as internal server errors.
  try {
    const body = await context.req.json();
    const data = await deliveryInputSchema.parseAsync(body);

    const token = context.req.header("Authorization");

    const deliveryData = await fetchDeliveryDataFromAgentDataAPI(

apps/agents/delivery/src/_main.ts:95

  • The new docstring says this function can return null, and the handler has a if (!deliveryData) { ... skipped: true } branch, but the implementation currently never returns null (it throws on any non-OK response). Either implement a real null return for the “no newsletter” case (e.g., 404 from Agent Data API) or update the return type/doc + remove the unreachable skip branch.
/**
 * Fetches the delivery data (newsletter and subscribers) for a specific ticker from the Agent Data API.
 *
 * @param token - The authorization token to pass to the API.
 * @param tickerId - The unique identifier of the ticker.
 * @returns A promise that resolves to the delivery data containing the newsletter and subscribers, or null.
 */
async function fetchDeliveryDataFromAgentDataAPI(
  token: string | undefined,
  tickerId: string,
): Promise<{
  newsletter: { subject: string; content: string };
  subscribers: { email: string }[];
} | null> {
  const url = new URL(env.AGENT_DATA_API_URL);
  url.pathname = "/api/delivery";
  url.searchParams.set("tickerId", tickerId);

  const res = await got.get(url.toString(), {
    headers: { ...(token && { Authorization: token }) },
    throwHttpErrors: false,
  });

  if (!res.ok) {
    throw new Error(`Agent data API error: ${res.statusCode}`);
  }

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

You can also share your feedback on Copilot code review. Take the survey.

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.

2 participants