Repository navigation
Expand file tree
/
Copy pathroutes.html
More file actions
398 lines (376 loc) · 20.2 KB
/
Copy pathroutes.html
File metadata and controls
398 lines (376 loc) · 20.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web Routes, REST API & External CLI — ProjectCompass Docs</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css">
<link rel="stylesheet" href="assets/docs.css">
</head>
<body>
<header class="top-nav">
<div class="top-nav-inner">
<a href="../index.html" class="brand-link">
<svg class="compass-mini" viewBox="0 0 36 36" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="18" cy="18" r="15.5" stroke="currentColor" stroke-width="1.6" stroke-dasharray="3 2" opacity="0.6"/>
<circle cx="18" cy="18" r="13" stroke="currentColor" stroke-width="1.5"/>
<path d="M18 7 L18 24" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/>
<path d="M18 8 L26 22 L18 22 Z" fill="currentColor" fill-opacity="0.32" stroke="currentColor" stroke-width="1.3" stroke-linejoin="round"/>
<path d="M16.5 10.5 L11 22 L16.5 22 Z" fill="#fbbf24" fill-opacity="0.45" stroke="#fbbf24" stroke-width="1.2" stroke-linejoin="round"/>
<path d="M10 24.5 L26 24.5 L23.5 27.5 L12.5 27.5 Z" fill="currentColor" fill-opacity="0.5" stroke="currentColor" stroke-width="1.2" stroke-linejoin="round"/>
</svg>
<span>ProjectCompass</span>
<span class="brand-tag">⛵ Regatta Docs</span>
</a>
<div class="nav-actions">
<button type="button" id="theme-toggle" class="theme-toggle-btn">
<span aria-hidden="true">⛵</span> <span>Day Sail</span>
</button>
<button type="button" class="nav-toggle" id="nav-toggle" aria-label="Toggle navigation">
<svg class="icon-menu" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></svg>
<svg class="icon-close" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="6" y1="6" x2="18" y2="18"/><line x1="6" y1="18" x2="18" y2="6"/></svg>
<span class="nav-toggle-label-open">Menu</span>
<span class="nav-toggle-label-close">Close</span>
</button>
</div>
</div>
</header>
<nav class="nav-links" id="nav-links" aria-label="Primary Documentation Navigation">
<span class="nav-group-label">Getting Started</span>
<a href="../index.html">Hub</a>
<a href="overview.html">Overview</a>
<a href="user_guide.html">User Guide</a>
<span class="nav-separator"></span>
<span class="nav-group-label">Architecture</span>
<a href="architecture.html">Architecture</a>
<a href="core_classes.html">Core Classes</a>
<a href="templates.html">Templates</a>
<a href="routes.html" class="active">API & CLI</a>
<span class="nav-separator"></span>
<span class="nav-group-label">Infrastructure</span>
<a href="k0s_setup.html">k0s Setup</a>
<a href="kubernetes_console.html">K8s Console</a>
<a href="worker_library.html">Worker Library</a>
<span class="nav-separator"></span>
<span class="nav-group-label">Operations</span>
<a href="configuration.html">Config</a>
<a href="docker.html">Docker</a>
<a href="demo/index.html" class="nav-demo">🚀 Demo</a>
</nav>
<div class="nav-overlay" id="nav-overlay"></div><section class="page-header">
<div class="page-header-inner">
<div class="breadcrumb">
<a href="../index.html">⛵ Command Deck</a>
<span>/</span>
<span>Pillar IV: Sextant, Logbook & Harbor Ops</span>
<span>/</span>
<span>Web Routes, REST API & External CLI</span>
</div>
<h1>Web Routes, REST API & External CLI Reference</h1>
<p class="lead">
Complete endpoint catalog across all 8 Flask blueprints, authentication modes (Session, HTTP Basic, Bearer Token), JSON content negotiation, SSE streaming, and the standalone <code>scripts/compass_cli.py</code> command reference.
</p>
<div class="page-meta-badges">
<span class="badge badge-cyan">09 • Sextant & Telegraph</span>
<span class="badge badge-emerald">REST JSON + SSE</span>
<span class="badge badge-gold">scripts/compass_cli.py</span>
</div>
</div>
</section>
<div class="docs-layout">
<main class="docs-content">
<h2 id="authentication-and-negotiation">1. Authentication Modes & JSON Content Negotiation</h2>
<p>
ProjectCompass supports three authentication mechanisms evaluated by <code>blueprints/auth.py</code>:
</p>
<ol>
<li><strong>Browser Session Cookie</strong> — Established via <code>POST /login/</code> after verifying credentials against SQLite `User` records or `ADMIN_USERNAME` / `ADMIN_PASSWORD_HASH`.</li>
<li><strong>Bearer Token Authentication (Recommended for CLI & Worker SDK)</strong> — Pass <code>Authorization: Bearer <token></code> matching either a user's `api_token` in SQLite (`POST /api/tokens`) or the static `API_AUTH_TOKEN` environment variable.</li>
<li><strong>HTTP Basic Authentication</strong> — Pass <code>Authorization: Basic base64(username:password)</code>.</li>
</ol>
<div class="callout callout-captain">
<div class="callout-title">🧭 Captain's Log — Dual HTML / JSON Endpoints</div>
<p>
Operational routes such as <code>/workers</code>, <code>/runs</code>, and <code>/schedules/</code> render HTMX/Jinja2 HTML when visited in a browser, and automatically return structured JSON when the client sends <code>Accept: application/json</code> or <code>Content-Type: application/json</code>. The <code>/flows</code> route now redirects to <code>/analysis</code>; the flow editor at <code>/flows/<name></code> is still accessible from catalog links.
</p>
</div>
<h2 id="k8s-and-orchestration-api">2. Kubernetes Console & Orchestration Endpoints (<code>k8s_bp</code>)</h2>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Method</th>
<th>Endpoint</th>
<th>Description & Payload / Response</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="method method-get">GET</span></td>
<td><code>/workers</code></td>
<td>Syncs Kubernetes nodes with SQLite (`k8s_workers`) and returns worker list (`Ready`, `NotReady`, `Removed`), CPU/memory capacity, and cluster availability.</td>
</tr>
<tr>
<td><span class="method method-post">POST</span></td>
<td><code>/workers/register</code></td>
<td>Pre-registers or updates a worker node record (`{"name": "worker-01", "role": "worker", "labels": {...}}`).</td>
</tr>
<tr>
<td><span class="method method-post">POST</span></td>
<td><code>/workers/join-token</code></td>
<td>Generates a signed k0s join token (`{"role": "worker", "expiry": "24h"}`) and returns the ready-to-run join command.</td>
</tr>
<tr>
<td><span class="method method-post">POST</span></td>
<td><code>/workers/<name>/drain</code></td>
<td>Cordons the node (`unschedulable=True`) and evicts non-DaemonSet pods.</td>
</tr>
<tr>
<td><span class="method method-delete">DELETE</span></td>
<td><code>/workers/<name></code></td>
<td>Deletes the node from Kubernetes (if reachable) and marks it `Removed` in SQLite.</td>
</tr>
<tr>
<td><span class="method method-get">GET</span></td>
<td><code>/flows</code></td>
<td>Redirects to <code>/analysis</code>. Flows are now managed from the unified Analysis catalog — analyses with <code>compass_flow.yaml</code> + <code>Dockerfile</code> appear with a ⚡ Flow badge.</td>
</tr>
<tr>
<td><span class="method method-get">GET</span></td>
<td><code>/flows/<name></code></td>
<td>Flow editor accessible from catalog links. Returns flow metadata, source code, default `parameters`, `pip_requirements`, `secret_refs`, `image`, and version history.</td>
</tr>
<tr>
<td><span class="method method-post">POST</span></td>
<td><code>/flows/save</code></td>
<td>Creates or updates a Flow (`name`, `code`, `description`, `parameters`, `pip_requirements`, `secret_refs`, `image`, `cpu_request`, `memory_limit`, `node_selector`).</td>
</tr>
<tr>
<td><span class="method method-post">POST</span></td>
<td><code>/flows/<name>/run</code></td>
<td>Dispatches an isolated `batch/v1` Kubernetes Job. For Dockerfile-based flows, the image is built and pushed to the local registry before launching. Accepts `{"parameters": {...}, "secrets": {...}, "wait": false}` and returns `{"run_id": 42, "status": "running", "job_name": "..."}`.</td>
</tr>
<tr>
<td><span class="method method-get">GET</span></td>
<td><code>/runs</code></td>
<td>Lists recent `ExecutionRun` records (supports `?flow_name=&limit=25`).</td>
</tr>
<tr>
<td><span class="method method-get">GET</span></td>
<td><code>/runs/<run_id></code></td>
<td>Returns run status, start/end timestamps, `k8s_job_name`, and persisted `log_text`.</td>
</tr>
<tr>
<td><span class="method method-get">GET</span></td>
<td><code>/runs/<run_id>/stream</code></td>
<td>Server-Sent Events (`text/event-stream`) endpoint streaming live Pod stdout/stderr lines until Job completion.</td>
</tr>
<tr>
<td><span class="method method-post">POST</span></td>
<td><code>/runs/<run_id>/abort</code></td>
<td>Deletes the active Kubernetes Job/Pod and marks the run `aborted`.</td>
</tr>
</tbody>
</table>
</div>
<h2 id="rest-api-v1">3. Programmatic JSON REST API (<code>api_bp</code> & <code>rag_bp</code>)</h2>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Method</th>
<th>Endpoint</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="method method-get">GET</span></td>
<td><code>/health</code> & <code>/api/health</code></td>
<td>Liveness probe returning <code>{"status": "ok", "version": "0.1.0"}</code>.</td>
</tr>
<tr>
<td><span class="method method-get">GET</span></td>
<td><code>/api/analyses</code></td>
<td>Paginated catalog list supporting <code>?q=</code> (FTS5 search), <code>?product=</code>, <code>?owner=</code>, <code>?page=</code>, <code>?per_page=</code>.</td>
</tr>
<tr>
<td><span class="method method-get">GET</span></td>
<td><code>/api/analyses/<name></code></td>
<td>Full metadata, inputs, versions, rating summary, and comments for one analysis.</td>
</tr>
<tr>
<td><span class="method method-post">POST</span></td>
<td><code>/api/analyses/<name>/run</code></td>
<td>Executes a Structured Analysis or Kubernetes Flow with `{"parameters": {...}, "wait": false}`.</td>
</tr>
<tr>
<td><span class="method method-get">GET</span></td>
<td><code>/api/data</code> & <code>/api/data/<name>/preview</code></td>
<td>Lists datasets in <code>Saved_data/</code> and previews top $N$ rows (`?limit=10`).</td>
</tr>
<tr>
<td><span class="method method-post">POST</span></td>
<td><code>/api/query</code></td>
<td>Executes SQL via local DuckDB or a saved ConnectorX connection (`{"sql": "SELECT ...", "connection": "warehouse"}`).</td>
</tr>
<tr>
<td><span class="method method-get">GET</span></td>
<td><code>/api/search?q=<term></code></td>
<td>SQLite FTS5 full-text search across analysis titles, descriptions, products, owners, and countries.</td>
</tr>
<tr>
<td><span class="method method-post">POST</span></td>
<td><code>/api/tokens</code> & <span class="method method-delete">DELETE</span> <code>/api/tokens/<id></code></td>
<td>Generates or revokes Bearer API tokens.</td>
</tr>
<tr>
<td><span class="method method-post">POST</span></td>
<td><code>/rag/build/<name></code> & <code>/rag/index/<name></code></td>
<td>Chunks and embeds an analysis folder + comments into ChromaDB (`rag_data/`).</td>
</tr>
<tr>
<td><span class="method method-get">GET</span></td>
<td><code>/rag/status/<name></code> & <span class="method method-delete">DELETE</span> <code>/rag/index/<name></code></td>
<td>Inspects or deletes the per-analysis ChromaDB RAG collection.</td>
</tr>
<tr>
<td><span class="method method-post">POST</span></td>
<td><code>/chat/analysis/rag</code> & <code>/chat/analysis/rag/stream</code></td>
<td>Answers questions over an analysis using hybrid Vector + BM25 search, Mithril reranking, and source citations.</td>
</tr>
</tbody>
</table>
</div>
<h2 id="schedules">4. Schedules, Catalog & Data Explorer Web Routes</h2>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Method</th>
<th>Route</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="method method-get">GET</span></td>
<td><code>/schedules/</code></td>
<td>Lists all cron and interval schedules (`Schedule` model) across analyses, flows, and chains.</td>
</tr>
<tr>
<td><span class="method method-post">POST</span></td>
<td><code>/schedules/create</code></td>
<td>Creates a new cron or interval schedule (`flow_name`, `chain_name`, `analysis_name`, `cron_expr`, `parameters`, `webhook_url`).</td>
</tr>
<tr>
<td><span class="method method-post">POST</span></td>
<td><code>/schedules/<job_id>/toggle</code> & <code>/schedules/<job_id>/delete</code></td>
<td>Pauses/resumes or deletes a scheduled job in APScheduler and SQLite.</td>
</tr>
<tr>
<td><span class="method method-get">GET</span></td>
<td><code>/</code>, <code>/overview</code>, <code>/analysis</code>, <code>/executions</code></td>
<td>Main dashboard, platform overview, catalog browser, and execution history console.</td>
</tr>
<tr>
<td><span class="method method-get">GET</span> / <span class="method method-post">POST</span></td>
<td><code>/pipeline_builder</code>, <code>/pipeline_versions/<name></code></td>
<td>Visual <code>scomp-link</code> ML pipeline designer and version history manager.</td>
</tr>
<tr>
<td><span class="method method-get">GET</span> / <span class="method method-post">POST</span></td>
<td><code>/query_runner/</code>, <code>/query_results/</code>, <code>/graph_analysis/</code></td>
<td>DuckDB + ConnectorX SQL editor, result table pagination, and RAWGraphs visualization bridge.</td>
</tr>
<tr>
<td><span class="method method-get">GET</span> / <span class="method method-post">POST</span></td>
<td><code>/connections/</code>, <code>/connections/new</code>, <code>/connections/save</code>, <code>/connections/<id>/test</code></td>
<td>Encrypted remote database connection management and live latency testing.</td>
</tr>
</tbody>
</table>
</div>
<h2 id="external-cli-reference">5. External CLI Reference (<code>scripts/compass_cli.py</code>)</h2>
<p>
The standalone CLI in <code>scripts/compass_cli.py</code> (powered by <code>BaseCompassCliClient</code> and <code>CompassCliRunner</code> in <code>utils/cli_utils.py</code>) lets you operate workers, flows, chains, runs, and schedules from any terminal or CI/CD runner.
</p>
<h3 id="cli-env-and-auth">Environment Variables & Global Flags</h3>
<pre><code class="language-bash">export COMPASS_URL="http://localhost:8080"
export COMPASS_TOKEN="your-bearer-api-token"
# Or use HTTP Basic Auth:
# export COMPASS_USER="admin"
# export COMPASS_PASSWORD="your-password"</code></pre>
<h3 id="cli-command-examples">Complete CLI Command Cookbook</h3>
<pre><code class="language-bash"># 1. Inspect k0s worker nodes and cluster health
uv run python scripts/compass_cli.py workers list
# 2. Push (create or update) a Python Flow from a local .py file
uv run python scripts/compass_cli.py flows push churn-scoring ./flow.py \
--description "Daily k0s customer churn scoring" \
--params '{"region": "EMEA", "score_threshold": 0.7}' \
--pip "compass-worker-kit>=0.1.0,scomp-link>=2.2.0" \
--secret-refs "compass-master-auth" \
--image "python:3.11-slim" \
--message "v1.2 threshold tuning"
# 3. Trigger a Flow as an isolated k0s batch/v1 Job and wait for completion
uv run python scripts/compass_cli.py flows run churn-scoring \
--params '{"region": "APAC"}' \
--wait
# 4. List runs, inspect run status, or stream live Pod logs over SSE
uv run python scripts/compass_cli.py runs list --flow churn-scoring --limit 10
uv run python scripts/compass_cli.py runs get 42
uv run python scripts/compass_cli.py runs logs 42 --follow
uv run python scripts/compass_cli.py runs abort 42
# 5. Create and execute a sequential Flow Chain (StepA -> StepB -> StepC)
uv run python scripts/compass_cli.py chains save nightly-ml-chain "ingest-data,train-model,churn-scoring" \
--description "End-to-end nightly pipeline"
uv run python scripts/compass_cli.py chains run nightly-ml-chain --wait
# 6. Create and toggle Cron / Interval Schedules
uv run python scripts/compass_cli.py schedules create \
--chain nightly-ml-chain \
--type cron \
--cron "0 2 * * *" \
--params '{"env": "prod"}'
uv run python scripts/compass_cli.py schedules list
uv run python scripts/compass_cli.py schedules toggle sched_nightly_ml_chain</code></pre>
<div class="page-pager">
<a href="worker_library.html" class="pager-link">
<span class="pager-label">← Previous</span>
<span class="pager-title">Building the Custom Worker Library</span>
</a>
<a href="configuration.html" class="pager-link" style="text-align: right;">
<span class="pager-label">Next →</span>
<span class="pager-title">Configuration & RBAC Reference</span>
</a>
</div>
</main>
<aside class="docs-toc" aria-label="On this page">
<div class="docs-toc-title">🧭 On This Page</div>
<ul id="toc-list"></ul>
</aside>
</div>
<footer class="site-footer">
<div class="site-footer-inner">
<div>
<strong>ProjectCompass</strong> — <em>Organization Is Everything®</em> • By
<a href="https://giacomosaccaggi.github.io/" target="_blank" rel="noopener">Giacomo Saccaggi</a>
</div>
<div class="footer-links">
<a href="../index.html">Hub</a>
<a href="k0s_setup.html">k0s Setup</a>
<a href="kubernetes_console.html">K8s Console</a>
<a href="worker_library.html">Worker Library</a>
<a href="configuration.html">Config</a>
<a href="docker.html">Docker</a>
</div>
</div>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-bash.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
<script src="assets/docs.js"></script>
</body>
</html>