@moorline/control-api 0.0.1
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/bootstrap.d.ts +33 -0
- package/dist/bootstrap.js +149 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/client.d.ts +36 -0
- package/dist/client.js +123 -0
- package/dist/client.js.map +1 -0
- package/dist/contracts/api.d.ts +73 -0
- package/dist/contracts/api.js +32 -0
- package/dist/contracts/api.js.map +1 -0
- package/dist/contracts/routes.d.ts +118 -0
- package/dist/contracts/routes.js +588 -0
- package/dist/contracts/routes.js.map +1 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +9 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/validation.d.ts +12 -0
- package/dist/validation.js +62 -0
- package/dist/validation.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
interface ControlApiBootstrapRecord {
|
|
2
|
+
version: 1;
|
|
3
|
+
protocol: 'http';
|
|
4
|
+
adapterPackageId: string;
|
|
5
|
+
pid: number;
|
|
6
|
+
url: string;
|
|
7
|
+
token: string;
|
|
8
|
+
startedAt: string;
|
|
9
|
+
configPath: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function resolveControlApiConfigPath(customPath?: string): string;
|
|
12
|
+
export declare function readControlApiBootstrapRecord(configPath?: string): ControlApiBootstrapRecord | null;
|
|
13
|
+
export declare function writeControlApiBootstrapRecord(record: ControlApiBootstrapRecord): void;
|
|
14
|
+
export declare function clearControlApiBootstrapRecord(configPath?: string): void;
|
|
15
|
+
export declare class ApiBootstrapResolver {
|
|
16
|
+
private readonly input;
|
|
17
|
+
constructor(input: {
|
|
18
|
+
configPath?: string;
|
|
19
|
+
entrypoint?: string;
|
|
20
|
+
});
|
|
21
|
+
resolveConnection(input?: {
|
|
22
|
+
url?: string;
|
|
23
|
+
token?: string;
|
|
24
|
+
configPath?: string;
|
|
25
|
+
autoStart?: boolean;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
url: string;
|
|
28
|
+
token: string;
|
|
29
|
+
configPath: string;
|
|
30
|
+
}>;
|
|
31
|
+
startLocalApiInBackground(configPath?: string): Promise<ControlApiBootstrapRecord>;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
function sleep(ms) {
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
globalThis.setTimeout(resolve, ms);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function defaultMoorlineHomePath() {
|
|
11
|
+
const override = process.env.MOORLINE_HOME?.trim();
|
|
12
|
+
return resolve(override || homedir(), override ? '.' : '.moorline');
|
|
13
|
+
}
|
|
14
|
+
export function resolveControlApiConfigPath(customPath) {
|
|
15
|
+
return customPath ? resolve(customPath) : resolve(defaultMoorlineHomePath(), 'config.json');
|
|
16
|
+
}
|
|
17
|
+
function runtimeRootForConfigPath(configPath) {
|
|
18
|
+
if (!existsSync(configPath)) {
|
|
19
|
+
return resolve(defaultMoorlineHomePath(), 'runtime');
|
|
20
|
+
}
|
|
21
|
+
const parsed = JSON.parse(readFileSync(configPath, 'utf8'));
|
|
22
|
+
if (typeof parsed.runtimeRoot !== 'string' || parsed.runtimeRoot.trim().length === 0) {
|
|
23
|
+
return resolve(defaultMoorlineHomePath(), 'runtime');
|
|
24
|
+
}
|
|
25
|
+
return resolve(parsed.runtimeRoot);
|
|
26
|
+
}
|
|
27
|
+
function controlApiStateDir(configPath) {
|
|
28
|
+
return join(runtimeRootForConfigPath(configPath), 'state');
|
|
29
|
+
}
|
|
30
|
+
function controlApiBootstrapPath(configPath) {
|
|
31
|
+
return join(controlApiStateDir(resolveControlApiConfigPath(configPath)), 'control-api-bootstrap.json');
|
|
32
|
+
}
|
|
33
|
+
export function readControlApiBootstrapRecord(configPath) {
|
|
34
|
+
const path = controlApiBootstrapPath(configPath);
|
|
35
|
+
if (!existsSync(path)) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const parsed = JSON.parse(readFileSync(path, 'utf8'));
|
|
40
|
+
if (typeof parsed.pid !== 'number' ||
|
|
41
|
+
parsed.version !== 1 ||
|
|
42
|
+
parsed.protocol !== 'http' ||
|
|
43
|
+
typeof parsed.adapterPackageId !== 'string' ||
|
|
44
|
+
typeof parsed.url !== 'string' ||
|
|
45
|
+
typeof parsed.token !== 'string' ||
|
|
46
|
+
typeof parsed.startedAt !== 'string' ||
|
|
47
|
+
typeof parsed.configPath !== 'string') {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
version: 1,
|
|
52
|
+
protocol: 'http',
|
|
53
|
+
adapterPackageId: parsed.adapterPackageId,
|
|
54
|
+
pid: parsed.pid,
|
|
55
|
+
url: parsed.url,
|
|
56
|
+
token: parsed.token,
|
|
57
|
+
startedAt: parsed.startedAt,
|
|
58
|
+
configPath: parsed.configPath
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function writeControlApiBootstrapRecord(record) {
|
|
66
|
+
const path = controlApiBootstrapPath(record.configPath);
|
|
67
|
+
mkdirSync(controlApiStateDir(record.configPath), { recursive: true });
|
|
68
|
+
writeFileSync(path, `${JSON.stringify(record, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
69
|
+
chmodSync(path, 0o600);
|
|
70
|
+
}
|
|
71
|
+
export function clearControlApiBootstrapRecord(configPath) {
|
|
72
|
+
rmSync(controlApiBootstrapPath(configPath), { force: true });
|
|
73
|
+
}
|
|
74
|
+
async function isAuthenticated(url, token) {
|
|
75
|
+
try {
|
|
76
|
+
const response = await fetch(`${url.replace(/\/+$/, '')}/api/state/configure`, {
|
|
77
|
+
headers: {
|
|
78
|
+
authorization: `Bearer ${token}`
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return response.ok;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export class ApiBootstrapResolver {
|
|
88
|
+
input;
|
|
89
|
+
constructor(input) {
|
|
90
|
+
this.input = input;
|
|
91
|
+
}
|
|
92
|
+
async resolveConnection(input = {}) {
|
|
93
|
+
const configPath = resolveControlApiConfigPath(input.configPath ?? this.input.configPath);
|
|
94
|
+
const url = input.url ?? process.env.MOORLINE_API_URL;
|
|
95
|
+
const token = input.token ?? process.env.MOORLINE_API_TOKEN;
|
|
96
|
+
if (url && token) {
|
|
97
|
+
return { url, token, configPath };
|
|
98
|
+
}
|
|
99
|
+
if (url && !token) {
|
|
100
|
+
throw new Error('Control API token is required when using a remote --url or MOORLINE_API_URL.');
|
|
101
|
+
}
|
|
102
|
+
const record = readControlApiBootstrapRecord(configPath);
|
|
103
|
+
if (record && (await isAuthenticated(record.url, record.token))) {
|
|
104
|
+
return {
|
|
105
|
+
url: record.url,
|
|
106
|
+
token: record.token,
|
|
107
|
+
configPath
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const shouldAutoStart = input.autoStart ?? false;
|
|
111
|
+
if (!shouldAutoStart) {
|
|
112
|
+
throw new Error('Control API is not available. Start it with `moorline api start` or provide --url and --token.');
|
|
113
|
+
}
|
|
114
|
+
if (!this.input.entrypoint) {
|
|
115
|
+
throw new Error('Control API auto-start requires a Moorline CLI entrypoint.');
|
|
116
|
+
}
|
|
117
|
+
const started = await this.startLocalApiInBackground(configPath);
|
|
118
|
+
return {
|
|
119
|
+
url: started.url,
|
|
120
|
+
token: started.token,
|
|
121
|
+
configPath
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
async startLocalApiInBackground(configPath = resolveControlApiConfigPath(this.input.configPath)) {
|
|
125
|
+
const existing = readControlApiBootstrapRecord(configPath);
|
|
126
|
+
if (existing && (await isAuthenticated(existing.url, existing.token))) {
|
|
127
|
+
return existing;
|
|
128
|
+
}
|
|
129
|
+
if (!this.input.entrypoint) {
|
|
130
|
+
throw new Error('Control API auto-start requires a Moorline CLI entrypoint.');
|
|
131
|
+
}
|
|
132
|
+
const child = spawn(process.execPath, [this.input.entrypoint, 'api-run-foreground', '--config', configPath], {
|
|
133
|
+
detached: true,
|
|
134
|
+
stdio: 'ignore',
|
|
135
|
+
env: process.env
|
|
136
|
+
});
|
|
137
|
+
child.unref();
|
|
138
|
+
const timeoutAt = Date.now() + 20_000;
|
|
139
|
+
while (Date.now() < timeoutAt) {
|
|
140
|
+
const record = readControlApiBootstrapRecord(configPath);
|
|
141
|
+
if (record && (await isAuthenticated(record.url, record.token))) {
|
|
142
|
+
return record;
|
|
143
|
+
}
|
|
144
|
+
await sleep(250);
|
|
145
|
+
}
|
|
146
|
+
throw new Error('Timed out waiting for the Control API to start.');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=bootstrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChG,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAa1C,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,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CAAC,MAAM,eAAe,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YACtE,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;QAChF,CAAC;QACD,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,oBAAoB,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE;YAC3G,QAAQ,EAAE,IAAI;YACd,KAAK,EAAE,QAAQ;YACf,GAAG,EAAE,OAAO,CAAC,GAAG;SACjB,CAAC,CAAC;QACH,KAAK,CAAC,KAAK,EAAE,CAAC;QAEd,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC;QACtC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,EAAE,CAAC;YAC9B,MAAM,MAAM,GAAG,6BAA6B,CAAC,UAAU,CAAC,CAAC;YACzD,IAAI,MAAM,IAAI,CAAC,MAAM,eAAe,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBAChE,OAAO,MAAM,CAAC;YAChB,CAAC;YACD,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;CACF"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ControlApiBinaryGetPath, ControlApiBinaryPostPath, ControlApiGetPath, ControlApiPayloadForPath, ControlApiPostPath, ControlApiTextGetPath } from './contracts/routes.js';
|
|
2
|
+
export type MainLifecyclePolicy = 'detached' | 'stop_on_last_lease';
|
|
3
|
+
interface ControlApiClientOptions {
|
|
4
|
+
url?: string;
|
|
5
|
+
token?: string;
|
|
6
|
+
configPath?: string;
|
|
7
|
+
autoStart?: boolean;
|
|
8
|
+
entrypoint?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ControlApiLeaseBinding {
|
|
11
|
+
leaseId: string;
|
|
12
|
+
release(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare class ControlApiClient {
|
|
15
|
+
private readonly options;
|
|
16
|
+
private baseUrl;
|
|
17
|
+
private token;
|
|
18
|
+
constructor(options?: ControlApiClientOptions);
|
|
19
|
+
private ensureConnection;
|
|
20
|
+
get(path: ControlApiGetPath): Promise<unknown>;
|
|
21
|
+
post<Path extends ControlApiPostPath>(path: Path, body: ControlApiPayloadForPath<Path>): Promise<unknown>;
|
|
22
|
+
getText(path: ControlApiTextGetPath): Promise<string>;
|
|
23
|
+
getBinary(path: ControlApiBinaryGetPath): Promise<{
|
|
24
|
+
bytes: Uint8Array;
|
|
25
|
+
contentType: string;
|
|
26
|
+
contentDisposition: string | null;
|
|
27
|
+
}>;
|
|
28
|
+
postBinary(path: ControlApiBinaryPostPath, body: Uint8Array | ArrayBuffer, contentType: string): Promise<unknown>;
|
|
29
|
+
private request;
|
|
30
|
+
}
|
|
31
|
+
export declare function bindControlApiLease(client: Pick<ControlApiClient, 'post'>, input: {
|
|
32
|
+
clientName: string;
|
|
33
|
+
policy: MainLifecyclePolicy;
|
|
34
|
+
ttlMs?: number;
|
|
35
|
+
}): Promise<ControlApiLeaseBinding>;
|
|
36
|
+
export {};
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { ApiBootstrapResolver } from './bootstrap.js';
|
|
2
|
+
export class ControlApiClient {
|
|
3
|
+
options;
|
|
4
|
+
baseUrl = null;
|
|
5
|
+
token = null;
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
async ensureConnection() {
|
|
10
|
+
if (this.baseUrl && this.token) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const resolver = new ApiBootstrapResolver({
|
|
14
|
+
configPath: this.options.configPath,
|
|
15
|
+
...(this.options.entrypoint ? { entrypoint: this.options.entrypoint } : {})
|
|
16
|
+
});
|
|
17
|
+
const resolved = await resolver.resolveConnection({
|
|
18
|
+
url: this.options.url,
|
|
19
|
+
token: this.options.token,
|
|
20
|
+
configPath: this.options.configPath,
|
|
21
|
+
autoStart: this.options.autoStart
|
|
22
|
+
});
|
|
23
|
+
this.baseUrl = resolved.url.replace(/\/+$/, '');
|
|
24
|
+
this.token = resolved.token.trim();
|
|
25
|
+
}
|
|
26
|
+
async get(path) {
|
|
27
|
+
const response = await this.request(path, { method: 'GET' });
|
|
28
|
+
return response.status === 204 ? null : await response.json();
|
|
29
|
+
}
|
|
30
|
+
async post(path, body) {
|
|
31
|
+
const response = await this.request(path, {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
headers: {
|
|
34
|
+
'content-type': 'application/json'
|
|
35
|
+
},
|
|
36
|
+
body: JSON.stringify(body)
|
|
37
|
+
});
|
|
38
|
+
return response.status === 204 ? null : await response.json();
|
|
39
|
+
}
|
|
40
|
+
async getText(path) {
|
|
41
|
+
const response = await this.request(path, { method: 'GET' });
|
|
42
|
+
return await response.text();
|
|
43
|
+
}
|
|
44
|
+
async getBinary(path) {
|
|
45
|
+
const response = await this.request(path, { method: 'GET' });
|
|
46
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
47
|
+
return {
|
|
48
|
+
bytes,
|
|
49
|
+
contentType: response.headers.get('content-type') ?? 'application/octet-stream',
|
|
50
|
+
contentDisposition: response.headers.get('content-disposition')
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async postBinary(path, body, contentType) {
|
|
54
|
+
const response = await this.request(path, {
|
|
55
|
+
method: 'POST',
|
|
56
|
+
headers: {
|
|
57
|
+
'content-type': contentType
|
|
58
|
+
},
|
|
59
|
+
body
|
|
60
|
+
});
|
|
61
|
+
return response.status === 204 ? null : await response.json();
|
|
62
|
+
}
|
|
63
|
+
async request(path, init) {
|
|
64
|
+
await this.ensureConnection();
|
|
65
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
66
|
+
...init,
|
|
67
|
+
headers: {
|
|
68
|
+
authorization: `Bearer ${this.token}`,
|
|
69
|
+
...(init.headers ?? {})
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
const payload = await response.text();
|
|
74
|
+
let detail = payload || response.statusText;
|
|
75
|
+
try {
|
|
76
|
+
const parsed = JSON.parse(payload);
|
|
77
|
+
if (typeof parsed.error === 'string' && parsed.error.trim()) {
|
|
78
|
+
detail = parsed.error.trim();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// Keep payload.
|
|
83
|
+
}
|
|
84
|
+
throw new Error(`Control API request failed (${response.status} ${path}): ${detail}`);
|
|
85
|
+
}
|
|
86
|
+
return response;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export async function bindControlApiLease(client, input) {
|
|
90
|
+
const created = (await client.post('/api/leases/create', {
|
|
91
|
+
client: input.clientName,
|
|
92
|
+
policy: input.policy,
|
|
93
|
+
...(typeof input.ttlMs === 'number' ? { ttlMs: input.ttlMs } : {})
|
|
94
|
+
}));
|
|
95
|
+
if (typeof created.leaseId !== 'string' || created.leaseId.trim().length === 0) {
|
|
96
|
+
throw new Error('Control API lease creation returned an invalid lease id.');
|
|
97
|
+
}
|
|
98
|
+
const leaseId = created.leaseId;
|
|
99
|
+
const ttlMs = Math.max(5_000, input.ttlMs ?? 30_000);
|
|
100
|
+
const heartbeatMs = Math.max(1_000, Math.floor(ttlMs / 2));
|
|
101
|
+
let released = false;
|
|
102
|
+
const timer = globalThis.setInterval(() => {
|
|
103
|
+
if (released) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
void client.post('/api/leases/heartbeat', { leaseId, ttlMs }).catch(() => undefined);
|
|
107
|
+
}, heartbeatMs);
|
|
108
|
+
if (typeof timer.unref === 'function') {
|
|
109
|
+
timer.unref();
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
leaseId,
|
|
113
|
+
async release() {
|
|
114
|
+
if (released) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
released = true;
|
|
118
|
+
clearInterval(timer);
|
|
119
|
+
await client.post('/api/leases/release', { leaseId }).catch(() => undefined);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAyBtD,MAAM,OAAO,gBAAgB;IAIE;IAHrB,OAAO,GAAkB,IAAI,CAAC;IAC9B,KAAK,GAAkB,IAAI,CAAC;IAEpC,YAA6B,UAAmC,EAAE;QAArC,YAAO,GAAP,OAAO,CAA8B;IAAG,CAAC;IAE9D,KAAK,CAAC,gBAAgB;QAC5B,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC/B,OAAO;QACT,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAC;YACxC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;YACnC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC5E,CAAC,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,iBAAiB,CAAC;YAChD,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG;YACrB,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAA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,CAAC;IACrD,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;IAC3D,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,MAAM,KAAK,GAAG,UAAU,CAAC,WAAW,CAAC,GAAG,EAAE;QACxC,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO;QACT,CAAC;QACD,KAAK,MAAM,CAAC,IAAI,CAAC,uBAAuB,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACvF,CAAC,EAAE,WAAW,CAAC,CAAC;IAChB,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;QACtC,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;IAED,OAAO;QACL,OAAO;QACP,KAAK,CAAC,OAAO;YACX,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO;YACT,CAAC;YACD,QAAQ,GAAG,IAAI,CAAC;YAChB,aAAa,CAAC,KAAK,CAAC,CAAC;YACrB,MAAM,MAAM,CAAC,IAAI,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC/E,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
interface ManagementContribution {
|
|
2
|
+
placement?: string;
|
|
3
|
+
}
|
|
4
|
+
interface ManagementReadModel {
|
|
5
|
+
overview: {
|
|
6
|
+
sessions: number;
|
|
7
|
+
missions: number;
|
|
8
|
+
pendingRequests: number;
|
|
9
|
+
};
|
|
10
|
+
runtime: {
|
|
11
|
+
status: {
|
|
12
|
+
runningSessions: number;
|
|
13
|
+
waitingSessions: number;
|
|
14
|
+
};
|
|
15
|
+
control: {
|
|
16
|
+
acceptingNewWork: boolean;
|
|
17
|
+
};
|
|
18
|
+
} & Record<string, unknown>;
|
|
19
|
+
diagnostics: {
|
|
20
|
+
runtimeHealth: unknown;
|
|
21
|
+
recentRuntimeActivities: unknown;
|
|
22
|
+
recentAuditEvents: unknown;
|
|
23
|
+
};
|
|
24
|
+
objects: {
|
|
25
|
+
managementContributions: ManagementContribution[];
|
|
26
|
+
sessions: unknown;
|
|
27
|
+
missions: unknown;
|
|
28
|
+
pendingRequests: unknown;
|
|
29
|
+
};
|
|
30
|
+
setup: unknown;
|
|
31
|
+
settings: unknown;
|
|
32
|
+
packages: {
|
|
33
|
+
catalog?: unknown;
|
|
34
|
+
installed?: unknown;
|
|
35
|
+
} & Record<string, unknown>;
|
|
36
|
+
history: {
|
|
37
|
+
status?: unknown;
|
|
38
|
+
entries?: unknown;
|
|
39
|
+
} & Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
export interface ControlApiState {
|
|
42
|
+
generatedAt: string;
|
|
43
|
+
runtimeMode: 'runtime' | 'management_only';
|
|
44
|
+
readModel: ManagementReadModel;
|
|
45
|
+
operations: ControlApiOperationsState;
|
|
46
|
+
configure: ControlApiConfigureState;
|
|
47
|
+
}
|
|
48
|
+
export interface ControlApiOperationsState {
|
|
49
|
+
summary: {
|
|
50
|
+
sessions: number;
|
|
51
|
+
missions: number;
|
|
52
|
+
pendingRequests: number;
|
|
53
|
+
runningSessions: number;
|
|
54
|
+
waitingSessions: number;
|
|
55
|
+
acceptingNewWork: boolean;
|
|
56
|
+
};
|
|
57
|
+
runtime: ManagementReadModel['runtime'];
|
|
58
|
+
diagnostics: Pick<ManagementReadModel['diagnostics'], 'runtimeHealth' | 'recentRuntimeActivities' | 'recentAuditEvents'>;
|
|
59
|
+
managementContributions: ManagementReadModel['objects']['managementContributions'];
|
|
60
|
+
sessions: ManagementReadModel['objects']['sessions'];
|
|
61
|
+
missions: ManagementReadModel['objects']['missions'];
|
|
62
|
+
pendingRequests: ManagementReadModel['objects']['pendingRequests'];
|
|
63
|
+
}
|
|
64
|
+
export interface ControlApiConfigureState {
|
|
65
|
+
setup: ManagementReadModel['setup'];
|
|
66
|
+
settings: ManagementReadModel['settings'];
|
|
67
|
+
packages: ManagementReadModel['packages'];
|
|
68
|
+
history: ManagementReadModel['history'];
|
|
69
|
+
managementContributions: ManagementReadModel['objects']['managementContributions'];
|
|
70
|
+
}
|
|
71
|
+
export declare function projectOperationsState(model: ManagementReadModel): ControlApiOperationsState;
|
|
72
|
+
export declare function projectConfigureState(model: ManagementReadModel): ControlApiConfigureState;
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function projectOperationsState(model) {
|
|
2
|
+
return {
|
|
3
|
+
summary: {
|
|
4
|
+
sessions: model.overview.sessions,
|
|
5
|
+
missions: model.overview.missions,
|
|
6
|
+
pendingRequests: model.overview.pendingRequests,
|
|
7
|
+
runningSessions: model.runtime.status.runningSessions,
|
|
8
|
+
waitingSessions: model.runtime.status.waitingSessions,
|
|
9
|
+
acceptingNewWork: model.runtime.control.acceptingNewWork
|
|
10
|
+
},
|
|
11
|
+
runtime: model.runtime,
|
|
12
|
+
diagnostics: {
|
|
13
|
+
runtimeHealth: model.diagnostics.runtimeHealth,
|
|
14
|
+
recentRuntimeActivities: model.diagnostics.recentRuntimeActivities,
|
|
15
|
+
recentAuditEvents: model.diagnostics.recentAuditEvents
|
|
16
|
+
},
|
|
17
|
+
managementContributions: model.objects.managementContributions.filter((contribution) => typeof contribution.placement === 'string' && ['overview', 'control', 'work', 'health'].includes(contribution.placement)),
|
|
18
|
+
sessions: model.objects.sessions,
|
|
19
|
+
missions: model.objects.missions,
|
|
20
|
+
pendingRequests: model.objects.pendingRequests
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function projectConfigureState(model) {
|
|
24
|
+
return {
|
|
25
|
+
setup: model.setup,
|
|
26
|
+
settings: model.settings,
|
|
27
|
+
packages: model.packages,
|
|
28
|
+
history: model.history,
|
|
29
|
+
managementContributions: model.objects.managementContributions.filter((contribution) => typeof contribution.placement === 'string' && ['packages', 'settings'].includes(contribution.placement))
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../../src/contracts/api.ts"],"names":[],"mappings":"AA2EA,MAAM,UAAU,sBAAsB,CAAC,KAA0B;IAC/D,OAAO;QACL,OAAO,EAAE;YACP,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ;YACjC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ;YACjC,eAAe,EAAE,KAAK,CAAC,QAAQ,CAAC,eAAe;YAC/C,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe;YACrD,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe;YACrD,gBAAgB,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,gBAAgB;SACzD;QACD,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,WAAW,EAAE;YACX,aAAa,EAAE,KAAK,CAAC,WAAW,CAAC,aAAa;YAC9C,uBAAuB,EAAE,KAAK,CAAC,WAAW,CAAC,uBAAuB;YAClE,iBAAiB,EAAE,KAAK,CAAC,WAAW,CAAC,iBAAiB;SACvD;QACD,uBAAuB,EAAE,KAAK,CAAC,OAAO,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC,YAAoC,EAAE,EAAE,CAC7G,OAAO,YAAY,CAAC,SAAS,KAAK,QAAQ,IAAI,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,SAAS,CAAC,CACzH;QACD,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ;QAChC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ;QAChC,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,eAAe;KAC/C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,KAA0B;IAC9D,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,uBAAuB,EAAE,KAAK,CAAC,OAAO,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC,YAAoC,EAAE,EAAE,CAC7G,OAAO,YAAY,CAAC,SAAS,KAAK,QAAQ,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,SAAS,CAAC,CACxG;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { PackageKind, PackageSurface } from '@moorline/contracts';
|
|
2
|
+
import { parseControlApiRuntimeMode } from '../validation.js';
|
|
3
|
+
export type ControlApiGetPath = '/api/state' | '/api/main/status' | '/api/state/operations' | '/api/state/configure' | '/api/packages/catalog' | '/api/packages/search' | `/api/packages/search?${string}` | `/api/packages/info?${string}` | '/api/packages/installed' | '/api/history/status' | '/api/history/list' | `/api/history/show?${string}` | '/api/history/diff' | `/api/history/diff?${string}` | '/api/pending-requests/list' | `/api/pending-requests/inspect?${string}` | '/api/management/backup' | `/api/management/backup?${string}`;
|
|
4
|
+
export type ControlApiTextGetPath = '/api/management/diagnostics-export' | '/api/management/setup-export';
|
|
5
|
+
export type ControlApiBinaryGetPath = '/api/management/backup' | `/api/management/backup?${string}`;
|
|
6
|
+
export type ControlApiBinaryPostPath = '/api/management/import';
|
|
7
|
+
export type ControlApiPostPath = '/api/main/start' | '/api/main/stop' | '/api/main/restart' | '/api/shutdown' | '/api/leases/create' | '/api/leases/heartbeat' | '/api/leases/release' | '/api/runtime/accepting' | '/api/runtime/reload' | '/api/provider/test' | '/api/provider/start' | '/api/provider/stop' | '/api/work/session/create' | '/api/work/session/direct' | '/api/work/session/archive' | '/api/work/session/delete' | '/api/work/mission/create' | '/api/work/mission/pause' | '/api/work/mission/resume' | '/api/work/mission/stop' | '/api/work/mission/run' | '/api/work/mission/archive' | '/api/work/mission/delete' | '/api/packages/install' | '/api/packages/remove' | '/api/packages/enable' | '/api/packages/disable' | '/api/packages/activate' | '/api/packages/deactivate' | '/api/packages/select' | '/api/packages/config' | '/api/packages/apply' | '/api/history/snapshot' | '/api/history/restore' | '/api/history/discard' | '/api/pending-requests/resolve' | '/api/pending-requests/answer' | '/api/pending-requests/cancel' | '/api/management/default-model' | '/api/management/config-migration-warning/acknowledge';
|
|
8
|
+
type SessionTargetPayload = {
|
|
9
|
+
sessionId?: string;
|
|
10
|
+
spaceId?: string;
|
|
11
|
+
};
|
|
12
|
+
type SpaceSessionTargetPayload = {
|
|
13
|
+
sessionId?: string;
|
|
14
|
+
spaceId: string;
|
|
15
|
+
};
|
|
16
|
+
type MissionTargetPayload = {
|
|
17
|
+
missionId?: string;
|
|
18
|
+
spaceId: string;
|
|
19
|
+
};
|
|
20
|
+
type RuntimeReloadMode = 'graceful' | 'force';
|
|
21
|
+
export type ControlApiPayloadForPath<Path extends ControlApiPostPath> = Path extends '/api/main/start' | '/api/main/stop' | '/api/main/restart' | '/api/shutdown' ? Record<string, never> : Path extends '/api/leases/create' ? {
|
|
22
|
+
client?: string;
|
|
23
|
+
policy?: 'detached' | 'stop_on_last_lease';
|
|
24
|
+
ttlMs?: number;
|
|
25
|
+
} : Path extends '/api/leases/heartbeat' ? {
|
|
26
|
+
leaseId: string;
|
|
27
|
+
ttlMs?: number;
|
|
28
|
+
} : Path extends '/api/leases/release' ? {
|
|
29
|
+
leaseId: string;
|
|
30
|
+
} : Path extends '/api/runtime/accepting' ? {
|
|
31
|
+
accepting: boolean;
|
|
32
|
+
} : Path extends '/api/runtime/reload' ? {
|
|
33
|
+
mode: RuntimeReloadMode;
|
|
34
|
+
} : Path extends '/api/provider/test' ? {
|
|
35
|
+
sendTurn?: boolean;
|
|
36
|
+
prompt?: string;
|
|
37
|
+
} : Path extends '/api/provider/start' | '/api/provider/stop' ? {
|
|
38
|
+
threadId?: string;
|
|
39
|
+
} : Path extends '/api/work/session/create' ? {
|
|
40
|
+
requestedName: string;
|
|
41
|
+
runtimeMode: ReturnType<typeof parseControlApiRuntimeMode>;
|
|
42
|
+
initialInstruction?: string;
|
|
43
|
+
objective?: string;
|
|
44
|
+
} : Path extends '/api/work/session/direct' ? SessionTargetPayload & {
|
|
45
|
+
instruction: string;
|
|
46
|
+
reason?: string;
|
|
47
|
+
} : Path extends '/api/work/session/archive' | '/api/work/session/delete' ? SpaceSessionTargetPayload : Path extends '/api/work/mission/create' ? {
|
|
48
|
+
title: string;
|
|
49
|
+
goal: string;
|
|
50
|
+
schedule: string;
|
|
51
|
+
runtimeMode: ReturnType<typeof parseControlApiRuntimeMode>;
|
|
52
|
+
startTime?: string;
|
|
53
|
+
} : Path extends '/api/work/mission/pause' | '/api/work/mission/resume' | '/api/work/mission/stop' | '/api/work/mission/run' | '/api/work/mission/archive' | '/api/work/mission/delete' ? MissionTargetPayload : Path extends '/api/packages/install' ? {
|
|
54
|
+
kind: PackageKind;
|
|
55
|
+
surface?: PackageKind;
|
|
56
|
+
packageId?: string;
|
|
57
|
+
source?: string;
|
|
58
|
+
} : Path extends '/api/packages/remove' ? {
|
|
59
|
+
kind: PackageKind;
|
|
60
|
+
surface?: PackageKind;
|
|
61
|
+
packageId: string;
|
|
62
|
+
cascade?: boolean;
|
|
63
|
+
} : Path extends '/api/packages/enable' | '/api/packages/disable' ? {
|
|
64
|
+
surface: 'plugin' | 'skill';
|
|
65
|
+
packageId: string;
|
|
66
|
+
} : Path extends '/api/packages/activate' | '/api/packages/deactivate' ? {
|
|
67
|
+
surface: PackageSurface;
|
|
68
|
+
packageId: string;
|
|
69
|
+
} : Path extends '/api/packages/select' ? {
|
|
70
|
+
surface: 'api-adapter' | 'transport' | 'provider';
|
|
71
|
+
packageId: string | null;
|
|
72
|
+
} : Path extends '/api/packages/config' ? {
|
|
73
|
+
surface: PackageSurface;
|
|
74
|
+
packageId: string;
|
|
75
|
+
values?: Record<string, string>;
|
|
76
|
+
secretReplacements?: Array<{
|
|
77
|
+
key: string;
|
|
78
|
+
value: string;
|
|
79
|
+
}>;
|
|
80
|
+
} : Path extends '/api/packages/apply' ? Record<string, never> : Path extends '/api/history/snapshot' ? {
|
|
81
|
+
label: string;
|
|
82
|
+
} : Path extends '/api/history/restore' ? {
|
|
83
|
+
commitish: string;
|
|
84
|
+
path?: string;
|
|
85
|
+
} : Path extends '/api/history/discard' ? {
|
|
86
|
+
path?: string;
|
|
87
|
+
} : Path extends '/api/pending-requests/resolve' ? {
|
|
88
|
+
requestId: string;
|
|
89
|
+
decision: 'accept' | 'decline' | 'cancel';
|
|
90
|
+
} : Path extends '/api/pending-requests/answer' ? {
|
|
91
|
+
requestId: string;
|
|
92
|
+
answers: Record<string, string | string[]>;
|
|
93
|
+
} : Path extends '/api/pending-requests/cancel' ? {
|
|
94
|
+
requestId: string;
|
|
95
|
+
} : Path extends '/api/management/default-model' ? {
|
|
96
|
+
model: string;
|
|
97
|
+
} : Path extends '/api/management/config-migration-warning/acknowledge' ? Record<string, never> : never;
|
|
98
|
+
export type ControlApiPostCommand = {
|
|
99
|
+
[Path in ControlApiPostPath]: {
|
|
100
|
+
kind: 'api';
|
|
101
|
+
path: Path;
|
|
102
|
+
payload: ControlApiPayloadForPath<Path>;
|
|
103
|
+
};
|
|
104
|
+
}[ControlApiPostPath];
|
|
105
|
+
export type ControlApiPostRoute = ControlApiPostCommand;
|
|
106
|
+
export declare function parseControlApiPostRoute(pathname: string, rawBody: unknown): ControlApiPostRoute;
|
|
107
|
+
export declare function parseHistoryShowQuery(url: URL): {
|
|
108
|
+
commitish: string;
|
|
109
|
+
};
|
|
110
|
+
export declare function parseHistoryDiffQuery(url: URL): {
|
|
111
|
+
from?: string;
|
|
112
|
+
to?: string;
|
|
113
|
+
path?: string;
|
|
114
|
+
};
|
|
115
|
+
export declare function parsePendingInspectQuery(url: URL): {
|
|
116
|
+
requestId: string;
|
|
117
|
+
};
|
|
118
|
+
export {};
|