cw-ai

Installation
SKILL.md

CW Agents AI as a Service

Apps get AI through the CW Agents AI gateway: one endpoint per project, OpenAI-compatible chat plus a Decisions API, billed to the organization's monthly AI credits.

Why it runs on the app's server: the gateway key spends the organization's money. The browser calls the app, and the app calls the gateway, so the key never reaches a bundle, response or log. The server also owns models, prompts and limits, so a user can't swap in an expensive model or rewrite the instructions.

Setup

  1. Put the gateway in one server module, apps/api/src/services/ai-gateway.ts (code). Its base URL is a constant: https://agents.customware.ai/api/features/ai/v1/<projectId>.
    • Read projectId from the Builder's raw task record at .tasks/task.json (the brief .tasks/task.md lists it in its frontmatter) and write the real ID into the constant.
    • If the ID can't be determined, report that in the task outcome. A placeholder would ship an app whose AI calls all fail.
  2. The key is CUSTOMWARE_AI_GATEWAY_KEY from the server environment. CW Agents injects it in the dev sandbox and the live app when AI as a Service is on.
    • If it's missing, report that AI as a Service isn't available. Never invent credentials.
  3. Use the Vercel AI SDK on the server: ai with @openrouter/ai-sdk-provider (createOpenRouter({ baseURL, apiKey })). It handles streaming, tools and schema output. Pin exact versions (chat.md).
    • Don't pass OpenRouter-only options (provider, models, plugins, user, usage, transforms, extraBody). The gateway rejects unknown fields with 400, because it sets routing and billing itself.
  4. Before any AI screen, set up the UI with ui.md: install AI Elements and add the safe AiResponse. Every AI screen uses them; never fall back to plain components.

Capabilities

Installs
258
GitHub Stars
2
First Seen
10 days ago