@hyperwindmill/caretaker-cli 0.34.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +16 -0
- package/dist/cli/orchestrator_demo.d.ts +39 -0
- package/dist/cli/orchestrator_demo.d.ts.map +1 -0
- package/dist/cli/orchestrator_demo.js +98 -0
- package/dist/cli/web/api_access.d.ts.map +1 -1
- package/dist/cli/web/api_access.js +1 -1
- package/dist/cli/web/openapi.d.ts +5 -0
- package/dist/cli/web/openapi.d.ts.map +1 -1
- package/dist/cli/web/openapi.js +78 -5
- package/dist/cli/web/orchestrator.d.ts +51 -0
- package/dist/cli/web/orchestrator.d.ts.map +1 -0
- package/dist/cli/web/orchestrator.js +596 -0
- package/dist/cli/web/orchestrator_core.d.ts +83 -0
- package/dist/cli/web/orchestrator_core.d.ts.map +1 -0
- package/dist/cli/web/orchestrator_core.js +219 -0
- package/dist/cli/web/save_config.d.ts +8 -0
- package/dist/cli/web/save_config.d.ts.map +1 -0
- package/dist/cli/web/save_config.js +9 -0
- package/dist/cli/web/scheduler/task_strategy.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_strategy.js +21 -2
- package/dist/cli/web/server.d.ts +3 -0
- package/dist/cli/web/server.d.ts.map +1 -1
- package/dist/cli/web/server.js +50 -19
- package/dist/lib/task_git.d.ts +3 -0
- package/dist/lib/task_git.d.ts.map +1 -1
- package/dist/lib/task_git.js +29 -0
- package/dist/store/db.d.ts +5 -0
- package/dist/store/db.d.ts.map +1 -1
- package/dist/store/db.js +12 -0
- package/dist/store/orchestrator.d.ts +50 -0
- package/dist/store/orchestrator.d.ts.map +1 -0
- package/dist/store/orchestrator.js +127 -0
- package/dist/webview/standalone.css +159 -1
- package/dist/webview/standalone.css.map +2 -2
- package/dist/webview/standalone.js +784 -504
- package/dist/webview/standalone.js.map +4 -4
- package/package.json +3 -3
package/dist/cli/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAgBA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAgBA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA8G1D"}
|
package/dist/cli/index.js
CHANGED
|
@@ -70,6 +70,22 @@ export async function runCli(argv) {
|
|
|
70
70
|
}
|
|
71
71
|
await startServer(parseInt(opts.port, 10), opts.host, { port: apiPort, host: opts.apiHost });
|
|
72
72
|
});
|
|
73
|
+
program
|
|
74
|
+
.command('orchestrator-demo')
|
|
75
|
+
.description('Launch an in-memory demo orchestrator implementing protocol v1.')
|
|
76
|
+
.requiredOption('--token <token>', 'Bearer token required for all orchestrator routes')
|
|
77
|
+
.option('-p, --port <number>', 'Port to listen on', '4000')
|
|
78
|
+
.option('-h, --host <string>', 'Host to bind to', '127.0.0.1')
|
|
79
|
+
.option('-n, --name <name>', 'Display name returned by /health and /register')
|
|
80
|
+
.action(async (opts) => {
|
|
81
|
+
const { startDemoOrchestrator } = await import('./orchestrator_demo.js');
|
|
82
|
+
startDemoOrchestrator({
|
|
83
|
+
port: parseInt(opts.port, 10),
|
|
84
|
+
host: opts.host,
|
|
85
|
+
token: opts.token,
|
|
86
|
+
name: opts.name,
|
|
87
|
+
});
|
|
88
|
+
});
|
|
73
89
|
program
|
|
74
90
|
.command('mcp')
|
|
75
91
|
.description('Serve the caretaker task/project tools over stdio for an external MCP client.')
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
export interface DemoInstance {
|
|
3
|
+
instanceId: string;
|
|
4
|
+
name: string;
|
|
5
|
+
version: string;
|
|
6
|
+
lastSeenAt: string;
|
|
7
|
+
}
|
|
8
|
+
export interface DemoQueuedMessage {
|
|
9
|
+
id: string;
|
|
10
|
+
method: string;
|
|
11
|
+
path: string;
|
|
12
|
+
body?: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface DemoResult {
|
|
15
|
+
id: string;
|
|
16
|
+
status: number;
|
|
17
|
+
body: unknown;
|
|
18
|
+
}
|
|
19
|
+
export interface DemoOrchestrator {
|
|
20
|
+
app: Hono;
|
|
21
|
+
enqueue(instanceId: string, msg: {
|
|
22
|
+
method: string;
|
|
23
|
+
path: string;
|
|
24
|
+
body?: unknown;
|
|
25
|
+
}): string;
|
|
26
|
+
results(instanceId: string): DemoResult[];
|
|
27
|
+
instances(): DemoInstance[];
|
|
28
|
+
}
|
|
29
|
+
export declare function createDemoOrchestrator(opts: {
|
|
30
|
+
token: string;
|
|
31
|
+
name?: string;
|
|
32
|
+
}): DemoOrchestrator;
|
|
33
|
+
export declare function startDemoOrchestrator(opts: {
|
|
34
|
+
port: number;
|
|
35
|
+
host: string;
|
|
36
|
+
token: string;
|
|
37
|
+
name?: string;
|
|
38
|
+
}): void;
|
|
39
|
+
//# sourceMappingURL=orchestrator_demo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator_demo.d.ts","sourceRoot":"","sources":["../../src/cli/orchestrator_demo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAI5B,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,IAAI,CAAC;IACV,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC;IAC3F,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,EAAE,CAAC;IAC1C,SAAS,IAAI,YAAY,EAAE,CAAC;CAC7B;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,gBAAgB,CAyG/F;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,IAAI,CAYP"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { serve } from '@hono/node-server';
|
|
3
|
+
import { Hono } from 'hono';
|
|
4
|
+
import { bearerToken } from './web/api_access.js';
|
|
5
|
+
import { PROTOCOL_VERSION } from './web/orchestrator_core.js';
|
|
6
|
+
export function createDemoOrchestrator(opts) {
|
|
7
|
+
const displayName = opts.name || 'Demo Orchestrator';
|
|
8
|
+
const instancesMap = new Map();
|
|
9
|
+
const queues = new Map();
|
|
10
|
+
const resultsMap = new Map();
|
|
11
|
+
function enqueue(instanceId, msg) {
|
|
12
|
+
const id = randomUUID();
|
|
13
|
+
const list = queues.get(instanceId) ?? [];
|
|
14
|
+
list.push({
|
|
15
|
+
id,
|
|
16
|
+
method: msg.method,
|
|
17
|
+
path: msg.path,
|
|
18
|
+
...(msg.body !== undefined ? { body: msg.body } : {}),
|
|
19
|
+
});
|
|
20
|
+
queues.set(instanceId, list);
|
|
21
|
+
return id;
|
|
22
|
+
}
|
|
23
|
+
function results(instanceId) {
|
|
24
|
+
return Array.from(resultsMap.get(instanceId)?.values() ?? []);
|
|
25
|
+
}
|
|
26
|
+
function instances() {
|
|
27
|
+
return Array.from(instancesMap.values());
|
|
28
|
+
}
|
|
29
|
+
const app = new Hono();
|
|
30
|
+
app.use('*', async (c, next) => {
|
|
31
|
+
const tok = bearerToken(c.req.header('authorization'));
|
|
32
|
+
if (!tok || tok !== opts.token) {
|
|
33
|
+
return c.json({ error: 'Unauthorized' }, 401);
|
|
34
|
+
}
|
|
35
|
+
return next();
|
|
36
|
+
});
|
|
37
|
+
app.get('/health', (c) => {
|
|
38
|
+
return c.json({ ok: true, protocol: PROTOCOL_VERSION, name: displayName });
|
|
39
|
+
});
|
|
40
|
+
app.post('/register', async (c) => {
|
|
41
|
+
const body = (await c.req.json());
|
|
42
|
+
if (!body.instanceId || typeof body.instanceId !== 'string') {
|
|
43
|
+
return c.json({ error: 'instanceId is required' }, 400);
|
|
44
|
+
}
|
|
45
|
+
instancesMap.set(body.instanceId, {
|
|
46
|
+
instanceId: body.instanceId,
|
|
47
|
+
name: typeof body.name === 'string' ? body.name : '',
|
|
48
|
+
version: typeof body.version === 'string' ? body.version : '',
|
|
49
|
+
lastSeenAt: new Date().toISOString(),
|
|
50
|
+
});
|
|
51
|
+
return c.json({ ok: true, name: displayName });
|
|
52
|
+
});
|
|
53
|
+
app.post('/poll', async (c) => {
|
|
54
|
+
const body = (await c.req.json());
|
|
55
|
+
const instanceId = body.instanceId;
|
|
56
|
+
if (!instanceId || !instancesMap.has(instanceId)) {
|
|
57
|
+
return c.json({ error: 'Unknown instanceId' }, 409);
|
|
58
|
+
}
|
|
59
|
+
const inst = instancesMap.get(instanceId);
|
|
60
|
+
inst.lastSeenAt = new Date().toISOString();
|
|
61
|
+
let instResults = resultsMap.get(instanceId);
|
|
62
|
+
if (!instResults) {
|
|
63
|
+
instResults = new Map();
|
|
64
|
+
resultsMap.set(instanceId, instResults);
|
|
65
|
+
}
|
|
66
|
+
for (const r of body.results ?? []) {
|
|
67
|
+
if (r && typeof r.id === 'string' && !instResults.has(r.id)) {
|
|
68
|
+
instResults.set(r.id, { id: r.id, status: r.status, body: r.body ?? null });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const pending = (queues.get(instanceId) ?? []).filter((m) => !instResults.has(m.id));
|
|
72
|
+
queues.set(instanceId, pending);
|
|
73
|
+
return c.json({ messages: pending });
|
|
74
|
+
});
|
|
75
|
+
app.get('/instances', (c) => {
|
|
76
|
+
return c.json({ instances: instances() });
|
|
77
|
+
});
|
|
78
|
+
app.post('/instances/:id/messages', async (c) => {
|
|
79
|
+
const body = (await c.req.json());
|
|
80
|
+
const id = enqueue(c.req.param('id'), body);
|
|
81
|
+
return c.json({ id });
|
|
82
|
+
});
|
|
83
|
+
app.get('/instances/:id/results', (c) => {
|
|
84
|
+
return c.json({ results: results(c.req.param('id')) });
|
|
85
|
+
});
|
|
86
|
+
return { app, enqueue, results, instances };
|
|
87
|
+
}
|
|
88
|
+
export function startDemoOrchestrator(opts) {
|
|
89
|
+
const demo = createDemoOrchestrator({ token: opts.token, name: opts.name });
|
|
90
|
+
serve({
|
|
91
|
+
fetch: demo.app.fetch,
|
|
92
|
+
port: opts.port,
|
|
93
|
+
hostname: opts.host,
|
|
94
|
+
});
|
|
95
|
+
const baseUrl = `http://${opts.host}:${opts.port}`;
|
|
96
|
+
console.log(`Demo orchestrator listening on ${baseUrl}`);
|
|
97
|
+
console.log(`Enqueue a message: curl -X POST ${baseUrl}/instances/<instanceId>/messages -H "Authorization: Bearer ${opts.token}" -H "Content-Type: application/json" -d '{"method":"GET","path":"/api/projects"}'`);
|
|
98
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api_access.d.ts","sourceRoot":"","sources":["../../../src/cli/web/api_access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAWjC;;;;;;;;;;GAUG;AAEH,KAAK,KAAK,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE5E,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAG5E;AAED;;uDAEuD;AACvD,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"api_access.d.ts","sourceRoot":"","sources":["../../../src/cli/web/api_access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAWjC;;;;;;;;;;GAUG;AAEH,KAAK,KAAK,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE5E,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAG5E;AAED;;uDAEuD;AACvD,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAKnD;AAED;;4DAE4D;AAC5D,wBAAgB,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAkB,GAAG,KAAK,CAsBlH;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAGvD;AAED,MAAM,WAAW,kBAAkB;IACjC,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAqBD;;gCAEgC;AAChC,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBzF;AAED,+DAA+D;AAC/D,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAuC3E"}
|
|
@@ -11,7 +11,7 @@ export function bearerToken(header) {
|
|
|
11
11
|
export function isApiPath(pathname) {
|
|
12
12
|
if (!pathname.startsWith('/api/'))
|
|
13
13
|
return false;
|
|
14
|
-
return !['/api/ws', '/api/mcp', '/api/access'].some((p) => pathname === p || pathname.startsWith(`${p}/`));
|
|
14
|
+
return !['/api/ws', '/api/mcp', '/api/access', '/api/orchestrator'].some((p) => pathname === p || pathname.startsWith(`${p}/`));
|
|
15
15
|
}
|
|
16
16
|
/** Wraps the app's fetch for the API port. The token is checked first, so an
|
|
17
17
|
* unauthenticated caller learns nothing about which paths exist — apart from
|
|
@@ -4,4 +4,9 @@ export declare function openApiDocument(version: string): Record<string, unknown
|
|
|
4
4
|
* token on the API port too, or Swagger UI's Authorize could never load. */
|
|
5
5
|
export declare const OPENAPI_PUBLIC_PATHS: string[];
|
|
6
6
|
export declare function registerOpenApi(app: Hono): void;
|
|
7
|
+
/**
|
|
8
|
+
* True when method + pathname is an operation of `paths` ({param} = exactly
|
|
9
|
+
* one non-empty segment), or GET /api/openapi.json. Pathname only: no query.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isDocumentedRoute(method: string, pathname: string): boolean;
|
|
7
12
|
//# sourceMappingURL=openapi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../../src/cli/web/openapi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../../src/cli/web/openapi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAifjC,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoBxE;AAED;6EAC6E;AAC7E,eAAO,MAAM,oBAAoB,UAAqC,CAAC;AAmCvE,wBAAgB,eAAe,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAI/C;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CA2B3E"}
|
package/dist/cli/web/openapi.js
CHANGED
|
@@ -230,7 +230,7 @@ const paths = {
|
|
|
230
230
|
get: {
|
|
231
231
|
tags: ['Tasks'],
|
|
232
232
|
summary: 'List the tasks of a project',
|
|
233
|
-
description: 'An unknown project answers an empty list.',
|
|
233
|
+
description: 'An unknown project answers an empty list. Without `after` and `limit` every task comes back, in storage order. With either, tasks come ordered by `seq`: page with `limit` and pass the `seq` of the last task received as `after`; a page shorter than `limit` is the end.',
|
|
234
234
|
parameters: [
|
|
235
235
|
...project,
|
|
236
236
|
{
|
|
@@ -239,8 +239,25 @@ const paths = {
|
|
|
239
239
|
description: 'true includes archived tasks.',
|
|
240
240
|
schema: { type: 'string', enum: ['true'] },
|
|
241
241
|
},
|
|
242
|
+
{
|
|
243
|
+
name: 'after',
|
|
244
|
+
in: 'query',
|
|
245
|
+
required: false,
|
|
246
|
+
description: 'Return only tasks with a seq greater than this one.',
|
|
247
|
+
schema: { type: 'integer', minimum: 0 },
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
name: 'limit',
|
|
251
|
+
in: 'query',
|
|
252
|
+
required: false,
|
|
253
|
+
description: 'At most this many tasks.',
|
|
254
|
+
schema: { type: 'integer', minimum: 1, maximum: 500 },
|
|
255
|
+
},
|
|
242
256
|
],
|
|
243
|
-
responses: {
|
|
257
|
+
responses: {
|
|
258
|
+
200: res('Tasks, with status, checklist and blockedReason.', { type: 'array', items: ref('Task') }),
|
|
259
|
+
400: errorRes('`after` or `limit` is not a valid integer, or `limit` is outside 1..500.'),
|
|
260
|
+
},
|
|
244
261
|
},
|
|
245
262
|
post: {
|
|
246
263
|
tags: ['Tasks'],
|
|
@@ -290,9 +307,28 @@ const paths = {
|
|
|
290
307
|
get: {
|
|
291
308
|
tags: ['Tasks'],
|
|
292
309
|
summary: 'Read the task thread',
|
|
293
|
-
description: 'Oldest first. An unknown task answers an empty list.',
|
|
294
|
-
parameters:
|
|
295
|
-
|
|
310
|
+
description: 'Oldest first (by message id). An unknown task answers an empty list. Without `after` and `limit` the whole thread comes back. To read a long thread in bounded responses, page with `limit` and pass the id of the last message received as `after`; a page shorter than `limit` is the end. To follow a thread, keep the last id and ask only for what came `after` it.',
|
|
311
|
+
parameters: [
|
|
312
|
+
...task,
|
|
313
|
+
{
|
|
314
|
+
name: 'after',
|
|
315
|
+
in: 'query',
|
|
316
|
+
required: false,
|
|
317
|
+
description: 'Return only messages with an id greater than this one.',
|
|
318
|
+
schema: { type: 'integer', minimum: 0 },
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
name: 'limit',
|
|
322
|
+
in: 'query',
|
|
323
|
+
required: false,
|
|
324
|
+
description: 'At most this many messages.',
|
|
325
|
+
schema: { type: 'integer', minimum: 1, maximum: 500 },
|
|
326
|
+
},
|
|
327
|
+
],
|
|
328
|
+
responses: {
|
|
329
|
+
200: res('Messages.', { type: 'array', items: ref('TaskMessage') }),
|
|
330
|
+
400: errorRes('`after` or `limit` is not a valid integer, or `limit` is outside 1..500.'),
|
|
331
|
+
},
|
|
296
332
|
},
|
|
297
333
|
post: {
|
|
298
334
|
tags: ['Tasks'],
|
|
@@ -487,3 +523,40 @@ export function registerOpenApi(app) {
|
|
|
487
523
|
app.get('/api/openapi.json', (c) => c.json(openApiDocument(version)));
|
|
488
524
|
app.get('/api/docs', (c) => c.html(DOCS_HTML));
|
|
489
525
|
}
|
|
526
|
+
/**
|
|
527
|
+
* True when method + pathname is an operation of `paths` ({param} = exactly
|
|
528
|
+
* one non-empty segment), or GET /api/openapi.json. Pathname only: no query.
|
|
529
|
+
*/
|
|
530
|
+
export function isDocumentedRoute(method, pathname) {
|
|
531
|
+
if (!pathname || pathname.includes('?'))
|
|
532
|
+
return false;
|
|
533
|
+
const lowerMethod = method.toLowerCase();
|
|
534
|
+
if (lowerMethod === 'get' && pathname === '/api/openapi.json')
|
|
535
|
+
return true;
|
|
536
|
+
const pathSegs = pathname.split('/');
|
|
537
|
+
for (const [template, ops] of Object.entries(paths)) {
|
|
538
|
+
if (!Object.prototype.hasOwnProperty.call(ops, lowerMethod))
|
|
539
|
+
continue;
|
|
540
|
+
const templateSegs = template.split('/');
|
|
541
|
+
if (templateSegs.length !== pathSegs.length)
|
|
542
|
+
continue;
|
|
543
|
+
let match = true;
|
|
544
|
+
for (let i = 0; i < templateSegs.length; i++) {
|
|
545
|
+
const t = templateSegs[i];
|
|
546
|
+
const p = pathSegs[i];
|
|
547
|
+
if (t.startsWith('{') && t.endsWith('}')) {
|
|
548
|
+
if (p.length === 0) {
|
|
549
|
+
match = false;
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
else if (t !== p) {
|
|
554
|
+
match = false;
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
if (match)
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Hono } from 'hono';
|
|
2
|
+
import { type RemoteMessage } from './orchestrator_core.js';
|
|
3
|
+
export type AppLike = {
|
|
4
|
+
request(path: string, init?: RequestInit): Response | Promise<Response>;
|
|
5
|
+
};
|
|
6
|
+
export interface CycleDeps {
|
|
7
|
+
app: AppLike;
|
|
8
|
+
fetch: typeof fetch;
|
|
9
|
+
now?: () => Date;
|
|
10
|
+
}
|
|
11
|
+
export interface OrchestratorStatus {
|
|
12
|
+
state: 'off' | 'registering' | 'connected' | 'error';
|
|
13
|
+
orchestratorName?: string;
|
|
14
|
+
lastPollAt?: string;
|
|
15
|
+
lastError?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Runs one request against the in-process Hono app. Never throws.
|
|
19
|
+
* Refuses (404) when the normalized pathname is not documented in OpenAPI.
|
|
20
|
+
* Response bodies over MAX_BODY_BYTES become 413.
|
|
21
|
+
*/
|
|
22
|
+
export declare function applyMessage(app: AppLike, msg: RemoteMessage): Promise<{
|
|
23
|
+
status: number;
|
|
24
|
+
body: unknown;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* One register-if-needed + poll cycle. Never throws; failures land in status.
|
|
28
|
+
*/
|
|
29
|
+
export declare function runCycle(deps: CycleDeps): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Approves or rejects a pending ledger message.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolvePending(app: AppLike, id: string, decision: 'approve' | 'reject'): Promise<'ok' | 'not_found' | 'not_pending'>;
|
|
34
|
+
export declare function orchestratorStatus(): OrchestratorStatus;
|
|
35
|
+
/**
|
|
36
|
+
* Config-save hook: forgets the registration and the status, and retires any
|
|
37
|
+
* cycle still running under the previous configuration. Leaves the boot
|
|
38
|
+
* recovery alone: it runs once per process, and re-running it would settle a
|
|
39
|
+
* message that is being applied right now as an interrupted one.
|
|
40
|
+
*/
|
|
41
|
+
export declare function resetOrchestrator(): void;
|
|
42
|
+
/** Tests only: also re-arms the once-per-process boot recovery. */
|
|
43
|
+
export declare function resetOrchestratorForTests(): void;
|
|
44
|
+
export declare function stopOrchestrator(): void;
|
|
45
|
+
/**
|
|
46
|
+
* (Re)starts the self-rescheduling poll loop from the saved config.
|
|
47
|
+
* Runs recoverLedger once per process before the first cycle.
|
|
48
|
+
*/
|
|
49
|
+
export declare function startOrchestrator(app: AppLike, fetchImpl?: typeof fetch): void;
|
|
50
|
+
export declare function registerOrchestrator(app: Hono, fetchImpl?: typeof fetch): void;
|
|
51
|
+
//# sourceMappingURL=orchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../../src/cli/web/orchestrator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAUjC,OAAO,EAYL,KAAK,aAAa,EACnB,MAAM,wBAAwB,CAAC;AAGhC,MAAM,MAAM,OAAO,GAAG;IACpB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACzE,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,KAAK,GAAG,aAAa,GAAG,WAAW,GAAG,OAAO,CAAC;IACrD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAgED;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,aAAa,GACjB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CA2C5C;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAIvD;AAiQD;;GAEG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,OAAO,EACZ,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAC7B,OAAO,CAAC,IAAI,GAAG,WAAW,GAAG,aAAa,CAAC,CA0C7C;AAED,wBAAgB,kBAAkB,IAAI,kBAAkB,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAIxC;AAED,mEAAmE;AACnE,wBAAgB,yBAAyB,IAAI,IAAI,CAGhD;AAED,wBAAgB,gBAAgB,IAAI,IAAI,CAMvC;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,GAAE,OAAO,KAAa,GAAG,IAAI,CA6BrF;AAqBD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,GAAE,OAAO,KAAa,GAAG,IAAI,CAqGrF"}
|