gadget/gadget-code
Rob Colbert 07a760c7b5 feat: add numPredict, numCtx, maxCompletionTokens to model config pipeline
Fixes premature AI API response truncation by propagating inference
parameters through the entire probe → storage → runtime → API call chain.

Root cause: Ollama defaults num_predict to 128 tokens and num_ctx to
4096, silently truncating output and context. We never overrode these.

Changes:
- IAiModelSettings: add numPredict, maxCompletionTokens fields
- IDroneModelConfig: moved from gadget-drone to @gadget/api (shared),
  expanded with numPredict, numCtx, maxCompletionTokens params
- IAiModelConfig.params: add numPredict, numCtx, maxCompletionTokens
- IAiModelProbeResult.settings: add numPredict, maxCompletionTokens
- AiModelSettingsSchema (Mongoose): add numPredict, maxCompletionTokens
- Ollama extractSettings(): extract num_predict from model parameters
- Ollama generate()/chat(): pass options: { num_ctx, num_predict }
- OpenAI all three create() calls: add max_completion_tokens
- web-cli.ts onProviderProbe(): compute numPredict (-1 for Ollama)
  and maxCompletionTokens (contextWindow for OpenAI) during probe
- agent.ts main + subagent loops: read model settings from provider
  cached models, build IDroneModelConfig with stored params
- ai.ts: remove local IDroneModelConfig, import from @gadget/api
- chat-session.ts: add new params to title generation call
- Tests: update all fixtures with new params, all 19 tests pass

Defaults when model settings unavailable:
- numPredict: -1 (Ollama unlimited - generate until natural stop)
- numCtx: 131072 (128k - covers most modern models)
- maxCompletionTokens: 16384 (16k - reasonable OpenAI default)
2026-05-11 13:50:19 -04:00
..
.vscode created by merging gadget-code and gadget-drone 2026-04-28 09:20:37 -04:00
assets/icon created by merging gadget-code and gadget-drone 2026-04-28 09:20:37 -04:00
data/prompts subagents (written by an agent, for an agent) 2026-05-11 11:22:59 -04:00
docs philosophy shifting for Workspaces and Projects 2026-05-10 16:10:04 -04:00
frontend a pile of small fixes 2026-05-11 07:08:18 -04:00
nginx created by merging gadget-code and gadget-drone 2026-04-28 09:20:37 -04:00
scripts move from Types.ObjectId to GadgetId (a string) 2026-05-01 14:31:00 -04:00
src feat: add numPredict, numCtx, maxCompletionTokens to model config pipeline 2026-05-11 13:50:19 -04:00
ssl created by merging gadget-code and gadget-drone 2026-04-28 09:20:37 -04:00
supervisor created by merging gadget-code and gadget-drone 2026-04-28 09:20:37 -04:00
tests checkpoint that I plan to delete 2026-05-09 14:52:59 -04:00
types created by merging gadget-code and gadget-drone 2026-04-28 09:20:37 -04:00
.gitignore created by merging gadget-code and gadget-drone 2026-04-28 09:20:37 -04:00
AGENTS.md finishing touches on move to GadgetId from ObjectId 2026-05-01 15:07:37 -04:00
deploy created by merging gadget-code and gadget-drone 2026-04-28 09:20:37 -04:00
gadget-code.code-workspace created by merging gadget-code and gadget-drone 2026-04-28 09:20:37 -04:00
LICENSE created by merging gadget-code and gadget-drone 2026-04-28 09:20:37 -04:00
package.json welcome to The Grid 2026-05-01 22:28:22 -04:00
playwright.config.ts created by merging gadget-code and gadget-drone 2026-04-28 09:20:37 -04:00
pnpm-lock.yaml streaming responses (see ./docs/streaming-responses.md) 2026-05-07 21:36:01 -04:00
pnpm-workspace.yaml created by merging gadget-code and gadget-drone 2026-04-28 09:20:37 -04:00
README.md make reasoning effort configurable; remove sign up concept 2026-05-08 11:40:30 -04:00
release created by merging gadget-code and gadget-drone 2026-04-28 09:20:37 -04:00
tsconfig.json created by merging gadget-code and gadget-drone 2026-04-28 09:20:37 -04:00
vitest.config.ts make reasoning effort configurable; remove sign up concept 2026-05-08 11:40:30 -04:00

Gadget Code

A modern self-hosted and open source Agentic Engineering Environment. Gadget Code is a hackable TypeScript/Node.js web application - and application development framework - built with Express, React, Vite, and Tailwind CSS.

Gadget Code is a Gab-first initiative. It is most well-tested and tuned for use with Gab.ai as your "Big Brain" compute provider. However, it is designed to be easily adaptable for use with other compute providers as well as your own local Ollama, vLLM, or other OpenAI or Ollama API-compatible setup.

Architecture

┌─────────────────────────────────────────────────────────────┐
│                    Vite Dev Server (HTTPS)                  │
│                    https://code-dev.g4dge7.com:5174         │
│                                                             │
│  ┌───────────┐  ┌───────────┐  ┌───────────┐                │
│  │   /auth   │  │   /api    │  │  static   │                │
│  │   proxy   │  │  proxy    │  │  files    │                │
│  └────┬──────┘  └────┬──────┘  └───────────┘                │
│       │              │                                      │
│       ▼              ▼                                      │
│  ┌─────────────────────────────┐                            │
│  │   Backend (HTTP)            │                            │
│  │   http://localhost:3443     │                            │
│  │   - Express API             │                            │
│  │   - Socket.io               │                            │
│  │   - Session (Redis)         │                            │
│  │   - MongoDB                 │                            │
│  └─────────────────────────────┘                            │
└─────────────────────────────────────────────────────────────┘

Tech Stack

  • Frontend: React 19, Vite 8, Tailwind CSS 4, Socket.io Client
  • Backend: Express 5, TypeScript, Socket.io Server
  • Database: MongoDB (Mongoose)
  • Cache/Session: Redis (ioredis + connect-redis)
  • File Storage: MinIO
  • Testing: Vitest, Playwright

Getting Started

Prerequisites

  • Node.js 22+
  • pnpm 10+
  • MongoDB running on localhost:27017
  • Redis running on localhost:6379
  • SSL certificates in ssl/ directory

Installation

pnpm install

Development

# Start both backend and frontend
pnpm dev:backend   # Backend on http://localhost:3443
pnpm dev:frontend # Frontend on https://localhost:5174

Build

pnpm build          # Build backend + frontend
pnpm build:backend # Build TypeScript only
pnpm build:frontend # Build React/Vite only

Testing

pnpm test            # Run vitest unit tests
npx playwright test  # Run E2E integration tests

Scripts

Your environment can be managed with the following package.json scripts and npx commands.

Command Description
pnpm build Build backend + frontend
pnpm test Run vitest unit tests
npx playwright test Run E2E tests
pnpm dev:backend Start backend (port 3443)
pnpm dev:frontend Start frontend (port 5174)
pnpm start Start production build

Environment Variables

# Required
DTP_USER_PASSWORD_SALT="your-password-salt"
DTP_JWT_SECRET="your-jwt-secret"
DTP_SESSION_SECRET="your-session-secret"

# MongoDB
DTP_MONGODB_HOST="localhost"
DTP_MONGODB_DATABASE="gadget-code"

# Redis
DTP_REDIS_HOST="localhost"
DTP_REDIS_PORT="6379"

# HTTPS
DTP_HTTPS="enabled"
DTP_HTTPS_HOST="localhost"
DTP_HTTPS_PORT="3443"
DTP_HTTPS_KEY_FILE="/path/to/ssl/key.pem"
DTP_HTTPS_CRT_FILE="/path/to/ssl/cert.pem"

 # Session
 DTP_SESSION_TRUST_PROXY="enabled"
 DTP_SESSION_COOKIE_SECURE="enabled"
 DTP_SESSION_COOKIE_SAMESITE="strict"

Features

  • User authentication (sign in, sign out)
  • JWT-based session management
  • RESTful API structure
  • Socket.io real-time communication
  • File upload support (MinIO)
  • Email notifications
  • Tailwind CSS frontend with dark theme

Project Structure

/src
  /config          # Environment configuration
  /controllers    # Express route handlers
  /lib            # Core utilities
  /models         # Mongoose models
  /services       # Business logic
/frontend
  /src
    /components  # React components
    /pages       # React pages
    /lib         # Frontend utilities
  /public        # Static assets
  vite.config.ts # Vite configuration
/tests
  /e2e           # Playwright tests

API Endpoints

Method Endpoint Description
POST /auth/sign-in Authenticate
GET /auth/sign-out Sign out
GET /api/v1/user Get current user

License

SEE LICENSE IN LICENSE