Auggyv0.5.0
PreviewDocs / Advanced Preview

defineRoute

Advanced preview: define focused HTTP routes with typed schemas, auth modes, and generated-client support.

Optional app integration

This surface is not part of the default agent path and does not make Auggy a general application backend. Its API may change before 1.0; pin exact versions and validate authorization and operational boundaries.

Shape

Optional app-integration API

defineRoute is not required to build an Auggy agent. Use it for a focused deterministic integration, not as a replacement for a general application backend.

Route definitionTypeScript
defineRoute.post("/orders/:id/refund", {
  auth: "visitor.required",
  params: z.object({ id: z.string() }),
  body: z.object({ reason: z.string() }),
  maxBodyBytes: 8192,
  rateLimit: { maxPerMinute: 5 },
  requires: { action: "refund.issue", resource: { param: "id" } },
  response: z.object({ refundId: z.string(), orderId: z.string() }),
  handler: async ({ params, body }) => {
    return json(await refundOrder(params.id, body.reason));
  },
});

defineRoute.get and defineRoute.post are the supported methods. Paths take exact segments and full-segment params such as /orders/:id.

Options

OptionUse
authOne of none, bearer, creator, visitor.optional, visitor.required, or agent.required.
params, query, bodyZod schemas; parsed and validated before the handler runs.
responseZod schema for the success JSON body; types the generated client's data.
maxBodyBytesPer-route request body cap.
rateLimit{ maxPerMinute } per-route rate limit.
timeoutMsPer-route handler timeout.
policyWebhook policy metadata, such as webhook.signature("stripe", { secretEnv }) or webhook.signature("svix", { secretEnv }).
requiresDelegated authorization rule: { action, resource: { param } }.
handlerReceives parsed { params, query, body, request } and returns a Response; json() is the standard helper.

Auth modes

ModeUse
nonePublic routes.
bearerTrusted server or operator callers with bearer credentials.
creatorCreator-only maintenance and back-office actions.
visitor.optionalPublic routes that can enrich behavior when a visitor token is present.
visitor.requiredPrivate visitor routes that require verified visitor identity.
agent.requiredAdmitted agent callers.

Related