# OpenAI API Tool — Implementation Plan
# TSTP Tools Standard: index.php (dashboard), widgets.php (console), api/v1/router.php, assets/, config/, lib/

name: openai_tool
description: New TSTP tool exposing OpenAI API via token-gated proxy with request-access flow and admin console.
version: "1.0"

layout:
  tool_slug: openai
  dashboard_entry: tools/openai/index.php
  console_entry: tools/openai/widgets.php
  api_router: tools/openai/api/v1/router.php
  assets: tools/openai/assets/
  config: tools/openai/config/
  lib: tools/openai/lib/
  storage: tools/openai/storage/logs, tools/openai/storage/rate

required_sections:
  - Usage Examples
  - API Console
  - Health
  - Stats
  - Admin: Access Requests
  - Admin: Keys
  - Admin: Tool Setup

api_endpoints:
  public:
    - GET /bootstrap/status
    - POST /bootstrap/initialize
    - GET /health
    - POST /access/request
  authenticated:
    - GET /apps/me
    - POST /openai/chat/completions   # Proxy to OpenAI API
  admin:
    - GET /admin/access/requests
    - POST /admin/access/approve
    - POST /admin/access/reject
    - POST /admin/keys/create
    - POST /admin/keys/revoke
    - GET /admin/stats

dependencies:
  - dashboard/includes/ui/tstp_console_ui.php
  - dashboard/assets/css/tstp_console.css
  - dashboard/assets/js/tstp_console.js
  - PHP 7.4+ (PDO MySQL, json, curl)

testing:
  - PHP syntax check on all .php (php -l)
  - tools/openai/tests/run.php (self-check)
  - tools/openai/tests/scan_no_hardcoded_colors.php
  - tools/openai/tests/verify_console_root_paths.php

validation:
  - No hardcoded colors; use var(--tstp-*) only
  - No null coalescing operator (user rule)
  - Use isset() for superglobals and optional keys

deploy:
  - ftp/upload_tools_openai.py (same pattern as upload_tools_notes.py)
  - Verify: curl base URL and api/v1/router.php

no_workarounds: true
no_leftover_test_files: true
confirmation: Run upload with --full and document in PROOF.md
