constructor-research-mcp 0.6.4 → 0.6.7-beta.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/INSTALL.md +2 -0
- package/README.md +44 -16
- package/dist/agents.d.ts +7 -2
- package/dist/agents.js +15 -4
- package/dist/api.d.ts +12 -0
- package/dist/api.js +64 -2
- package/dist/config.d.ts +6 -0
- package/dist/config.js +5 -0
- package/dist/deployment.d.ts +12 -0
- package/dist/deployment.js +210 -22
- package/dist/desk.d.ts +6 -0
- package/dist/desk.js +14 -0
- package/dist/diagnose.d.ts +57 -0
- package/dist/diagnose.js +183 -0
- package/dist/install.js +36 -5
- package/dist/key.d.ts +3 -1
- package/dist/key.js +8 -3
- package/dist/logs.d.ts +16 -0
- package/dist/logs.js +51 -3
- package/dist/runtime.js +8 -2
- package/dist/schemas.js +1 -2
- package/dist/server.js +11 -6
- package/dist/store.d.ts +25 -0
- package/dist/text.d.ts +6 -0
- package/dist/text.js +208 -0
- package/dist/wait.d.ts +6 -3
- package/dist/wait.js +8 -16
- package/examples/codex.toml +2 -0
- package/package.json +1 -1
package/dist/install.js
CHANGED
|
@@ -230,11 +230,17 @@ export async function runInstall(argv) {
|
|
|
230
230
|
let base;
|
|
231
231
|
/** Inside a Constructor desk, the server it names; the key is checked there too. */
|
|
232
232
|
const deskServer = config.localDesk?.server;
|
|
233
|
+
/** The access key the desk provides (RESEARCH_ACCESS_KEY); no question then. A key given for -y wins. */
|
|
234
|
+
const deskKey = config.deskKey &&
|
|
235
|
+
!flag("--key-stdin") &&
|
|
236
|
+
!(yes && env.CONSTRUCTOR_ACCESS_KEY)
|
|
237
|
+
? accessKey(config.deskKey)
|
|
238
|
+
: undefined;
|
|
233
239
|
try {
|
|
234
240
|
const given = value("--constructor");
|
|
235
241
|
if (given)
|
|
236
242
|
base = linkOrigin(given);
|
|
237
|
-
else if (yes)
|
|
243
|
+
else if (yes || deskKey)
|
|
238
244
|
base = saved?.url ?? deskServer ?? DEFAULT_BASE_URL;
|
|
239
245
|
else {
|
|
240
246
|
// Inside a desk its server is the likely answer, but the user may open another address.
|
|
@@ -319,7 +325,30 @@ export async function runInstall(argv) {
|
|
|
319
325
|
return route.result;
|
|
320
326
|
};
|
|
321
327
|
let key;
|
|
322
|
-
|
|
328
|
+
let keySource;
|
|
329
|
+
let deskDone = false;
|
|
330
|
+
if (deskKey) {
|
|
331
|
+
if ((await check(deskKey)) === "ok") {
|
|
332
|
+
deskDone = true;
|
|
333
|
+
// A key the user saved for this Constructor stays: the MCP falls back to it.
|
|
334
|
+
if (saved?.url === base && !saved.source && saved.key !== deskKey)
|
|
335
|
+
p.log.info(`This desk provides an access key (${mask(deskKey)}); the MCP uses it, and the key saved for ${short(base)} if Constructor rejects the desk's.`);
|
|
336
|
+
else {
|
|
337
|
+
key = deskKey;
|
|
338
|
+
keySource = "desk";
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
if (yes)
|
|
343
|
+
keyProblem = "the access key this desk provides was not accepted";
|
|
344
|
+
else
|
|
345
|
+
p.log.warn("The access key this desk provides was not accepted.");
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (deskDone) {
|
|
349
|
+
// The desk's key is accepted; nothing to ask.
|
|
350
|
+
}
|
|
351
|
+
else if (yes) {
|
|
323
352
|
const raw = flag("--key-stdin")
|
|
324
353
|
? await readStdin()
|
|
325
354
|
: env.CONSTRUCTOR_ACCESS_KEY;
|
|
@@ -333,7 +362,7 @@ export async function runInstall(argv) {
|
|
|
333
362
|
}
|
|
334
363
|
}
|
|
335
364
|
else if (!(saved && saved.url === base))
|
|
336
|
-
keyProblem
|
|
365
|
+
keyProblem ||= "no key given (CONSTRUCTOR_ACCESS_KEY or --key-stdin)";
|
|
337
366
|
}
|
|
338
367
|
else {
|
|
339
368
|
const keep = saved?.url === base &&
|
|
@@ -371,9 +400,11 @@ export async function runInstall(argv) {
|
|
|
371
400
|
if (dry)
|
|
372
401
|
p.log.info(`Dry run: key ${mask(key)} not saved.`);
|
|
373
402
|
else {
|
|
374
|
-
await saveKeyFile(config.keyFile, base, key);
|
|
403
|
+
await saveKeyFile(config.keyFile, base, key, keySource);
|
|
375
404
|
keySaved = true;
|
|
376
|
-
p.log.success(
|
|
405
|
+
p.log.success(keySource
|
|
406
|
+
? `The access key this desk provides (${mask(key)}) is saved to ${bold(show(config.keyFile))} ${dim("(readable only by you)")}, so the wait command finds it too; no key from you is needed`
|
|
407
|
+
: `Key saved to ${bold(show(config.keyFile))} ${dim("(readable only by you)")}`);
|
|
377
408
|
}
|
|
378
409
|
}
|
|
379
410
|
else if (keyProblem)
|
package/dist/key.d.ts
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
export interface SavedKey {
|
|
3
3
|
url: string;
|
|
4
4
|
key: string;
|
|
5
|
+
/** "desk": the MCP saved the key a Constructor desk provides (CONSTRUCTOR_ACCESS_KEY); absent: the user saved it. */
|
|
6
|
+
source?: "desk";
|
|
5
7
|
}
|
|
6
8
|
/** The saved key, or undefined when none was saved. A broken file throws. */
|
|
7
9
|
export declare function readKeyFile(file: string): Promise<SavedKey | undefined>;
|
|
8
10
|
/** Saves the key for one Constructor, mode 600, replacing the file in one step. */
|
|
9
|
-
export declare function saveKeyFile(file: string, url: string, key: string): Promise<void>;
|
|
11
|
+
export declare function saveKeyFile(file: string, url: string, key: string, source?: "desk"): Promise<void>;
|
|
10
12
|
export type KeyCheck = "ok" | "rejected" | "no_api" | "unreachable";
|
|
11
13
|
/** Ask Constructor whether it accepts the key: 200 accepted, 401 rejected, else no public API. */
|
|
12
14
|
export declare function checkKey(url: string, apiPath: string, key: string, timeoutMs?: number): Promise<{
|
package/dist/key.js
CHANGED
|
@@ -23,13 +23,18 @@ export async function readKeyFile(file) {
|
|
|
23
23
|
}
|
|
24
24
|
if (typeof data?.key !== "string" || typeof data?.url !== "string")
|
|
25
25
|
throw new Error("expected url and key");
|
|
26
|
-
return {
|
|
26
|
+
return {
|
|
27
|
+
url: originOf(data.url),
|
|
28
|
+
key: data.key,
|
|
29
|
+
...(data.source === "desk" ? { source: "desk" } : {}),
|
|
30
|
+
};
|
|
27
31
|
}
|
|
28
32
|
/** Saves the key for one Constructor, mode 600, replacing the file in one step. */
|
|
29
|
-
export async function saveKeyFile(file, url, key) {
|
|
33
|
+
export async function saveKeyFile(file, url, key, source) {
|
|
30
34
|
await mkdir(dirname(file), { recursive: true, mode: 0o700 });
|
|
31
35
|
const tmp = `${file}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
|
|
32
|
-
await writeFile(tmp, JSON.stringify({ url: originOf(url), key }) +
|
|
36
|
+
await writeFile(tmp, JSON.stringify({ url: originOf(url), key, ...(source ? { source } : {}) }) +
|
|
37
|
+
"\n", {
|
|
33
38
|
mode: 0o600,
|
|
34
39
|
flag: "wx",
|
|
35
40
|
});
|
package/dist/logs.d.ts
CHANGED
|
@@ -22,6 +22,14 @@ export interface LogView {
|
|
|
22
22
|
restarted_at?: string[];
|
|
23
23
|
/** When the MCP followed this log; lines printed outside these periods were never seen. */
|
|
24
24
|
watched?: Period[];
|
|
25
|
+
/**
|
|
26
|
+
* A build log the MCP followed to its end without a connection problem: these lines are all
|
|
27
|
+
* the build printed (but for `dropped` older ones). False while live, after an error, or
|
|
28
|
+
* without lines.
|
|
29
|
+
*/
|
|
30
|
+
complete?: boolean;
|
|
31
|
+
/** Older lines dropped to keep the last KEEP. */
|
|
32
|
+
dropped?: number;
|
|
25
33
|
message?: string;
|
|
26
34
|
}
|
|
27
35
|
/**
|
|
@@ -55,6 +63,14 @@ export declare class LogFollower {
|
|
|
55
63
|
follow(id: string, kind?: LogKind): void;
|
|
56
64
|
/** Last `count` lines, following first if the build or service may still be running. */
|
|
57
65
|
tail(id: string, kind?: LogKind, count?: number, waitMs?: number): Promise<LogView>;
|
|
66
|
+
/** How long settle() waits for a build log to end; tests shorten it. */
|
|
67
|
+
settleMs: number;
|
|
68
|
+
/**
|
|
69
|
+
* All kept lines of a build that just ended, after waiting (up to settleMs) for its stream
|
|
70
|
+
* to deliver the last lines and close: a failure is read from the final log, not an early
|
|
71
|
+
* live one. Undefined when the MCP has no lines.
|
|
72
|
+
*/
|
|
73
|
+
settle(id: string, kind?: LogKind): Promise<LogView | undefined>;
|
|
58
74
|
/** Kept lines without contacting the platform. */
|
|
59
75
|
peek(id: string, kind?: LogKind, count?: number): Promise<LogView | undefined>;
|
|
60
76
|
close(): Promise<void>;
|
package/dist/logs.js
CHANGED
|
@@ -2,6 +2,7 @@ import { mkdir, readdir, readFile, rm, stat, writeFile, } from "node:fs/promises
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { setTimeout as delay } from "node:timers/promises";
|
|
4
4
|
import { ToolError, segment } from "./api.js";
|
|
5
|
+
import { redact } from "./diagnose.js";
|
|
5
6
|
/** Lines kept per build or service, in memory and in its file. */
|
|
6
7
|
export const KEEP = 2000;
|
|
7
8
|
/** The most lines get_logs returns at once. */
|
|
@@ -71,6 +72,7 @@ export class LogFollower {
|
|
|
71
72
|
restarts: [],
|
|
72
73
|
state: "live",
|
|
73
74
|
saved: 0,
|
|
75
|
+
total: 0,
|
|
74
76
|
watched: [],
|
|
75
77
|
};
|
|
76
78
|
this.logs.set(`${kind}:${id}`, log);
|
|
@@ -110,6 +112,25 @@ export class LogFollower {
|
|
|
110
112
|
}
|
|
111
113
|
return this.view(id, log, count);
|
|
112
114
|
}
|
|
115
|
+
/** How long settle() waits for a build log to end; tests shorten it. */
|
|
116
|
+
settleMs = 5000;
|
|
117
|
+
/**
|
|
118
|
+
* All kept lines of a build that just ended, after waiting (up to settleMs) for its stream
|
|
119
|
+
* to deliver the last lines and close: a failure is read from the final log, not an early
|
|
120
|
+
* live one. Undefined when the MCP has no lines.
|
|
121
|
+
*/
|
|
122
|
+
async settle(id, kind = "build") {
|
|
123
|
+
let log = this.logs.get(`${kind}:${id}`) ?? (await this.load(id, kind));
|
|
124
|
+
if (!log)
|
|
125
|
+
return undefined;
|
|
126
|
+
if (!log.reader && log.state !== "finished")
|
|
127
|
+
this.follow(id, kind);
|
|
128
|
+
log = this.logs.get(`${kind}:${id}`);
|
|
129
|
+
const deadline = Date.now() + this.settleMs;
|
|
130
|
+
while (log.reader && Date.now() < deadline)
|
|
131
|
+
await delay(100);
|
|
132
|
+
return log.lines.length ? this.view(id, log, KEEP) : undefined;
|
|
133
|
+
}
|
|
113
134
|
/** Kept lines without contacting the platform. */
|
|
114
135
|
async peek(id, kind = "build", count = 20) {
|
|
115
136
|
const log = this.logs.get(`${kind}:${id}`) ?? (await this.load(id, kind));
|
|
@@ -152,12 +173,19 @@ export class LogFollower {
|
|
|
152
173
|
const more = log.lines.length > lines.length
|
|
153
174
|
? `${log.lines.length} lines are kept; ask for more with lines (up to ${SHOW}).`
|
|
154
175
|
: undefined;
|
|
176
|
+
const dropped = Math.max(0, log.total - log.lines.length);
|
|
155
177
|
return {
|
|
156
178
|
kind: log.kind,
|
|
157
179
|
id,
|
|
158
180
|
state: log.state,
|
|
159
181
|
lines,
|
|
160
182
|
last_received_at: log.received,
|
|
183
|
+
...(service
|
|
184
|
+
? {}
|
|
185
|
+
: {
|
|
186
|
+
complete: log.state === "finished" && !log.error && log.lines.length > 0,
|
|
187
|
+
}),
|
|
188
|
+
...(dropped ? { dropped } : {}),
|
|
161
189
|
...(restarts
|
|
162
190
|
? { restarts_seen: restarts, restarted_at: log.restarts }
|
|
163
191
|
: {}),
|
|
@@ -197,6 +225,8 @@ export class LogFollower {
|
|
|
197
225
|
failures = 0;
|
|
198
226
|
log.fresh = true;
|
|
199
227
|
log.pending = [];
|
|
228
|
+
log.replaying = !!log.last;
|
|
229
|
+
log.replaySame = 0;
|
|
200
230
|
let partial = "";
|
|
201
231
|
const decoder = new TextDecoder();
|
|
202
232
|
for await (const chunk of response.body) {
|
|
@@ -276,9 +306,21 @@ export class LogFollower {
|
|
|
276
306
|
this.keep(log, h);
|
|
277
307
|
}
|
|
278
308
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
log.last
|
|
309
|
+
// A reconnect replays what is kept: skip up to the last line seen, counting lines that
|
|
310
|
+
// share its stamp. On a live stream equal stamps are new lines, never repeats.
|
|
311
|
+
if (log.replaying && log.last) {
|
|
312
|
+
if (stamp < log.last)
|
|
313
|
+
return;
|
|
314
|
+
if (stamp === log.last && ++log.replaySame <= (log.lastCount ?? 1))
|
|
315
|
+
return;
|
|
316
|
+
log.replaying = false;
|
|
317
|
+
}
|
|
318
|
+
if (stamp === log.last)
|
|
319
|
+
log.lastCount = (log.lastCount ?? 1) + 1;
|
|
320
|
+
else {
|
|
321
|
+
log.last = stamp;
|
|
322
|
+
log.lastCount = 1;
|
|
323
|
+
}
|
|
282
324
|
// A line that is only a timestamp carries nothing to show.
|
|
283
325
|
if (line.length > stamp.length)
|
|
284
326
|
this.keep(log, line);
|
|
@@ -295,6 +337,7 @@ export class LogFollower {
|
|
|
295
337
|
}
|
|
296
338
|
keep(log, line) {
|
|
297
339
|
log.received = new Date().toISOString();
|
|
340
|
+
line = redact(line);
|
|
298
341
|
if (line === log.previous && log.lines.length) {
|
|
299
342
|
log.repeats = (log.repeats ?? 1) + 1;
|
|
300
343
|
log.lines[log.lines.length - 1] = `${line} (×${log.repeats})`;
|
|
@@ -302,6 +345,7 @@ export class LogFollower {
|
|
|
302
345
|
}
|
|
303
346
|
log.previous = line;
|
|
304
347
|
log.repeats = 1;
|
|
348
|
+
log.total++;
|
|
305
349
|
log.lines.push(line.length > WIDTH ? line.slice(0, WIDTH) + "…" : line);
|
|
306
350
|
if (log.lines.length > KEEP)
|
|
307
351
|
log.lines.shift();
|
|
@@ -317,10 +361,12 @@ export class LogFollower {
|
|
|
317
361
|
state: log.reader && !force ? "live" : log.state,
|
|
318
362
|
lines: log.lines,
|
|
319
363
|
last: log.last,
|
|
364
|
+
last_count: log.lastCount,
|
|
320
365
|
restarts: log.restarts,
|
|
321
366
|
received: log.received,
|
|
322
367
|
error: log.error,
|
|
323
368
|
watched: log.watched,
|
|
369
|
+
total: log.total,
|
|
324
370
|
}), { mode: 0o600 });
|
|
325
371
|
if (Date.now() - this.rotated > 60 * 60 * 1000)
|
|
326
372
|
await this.rotate();
|
|
@@ -339,10 +385,12 @@ export class LogFollower {
|
|
|
339
385
|
lines: Array.isArray(kept.lines) ? kept.lines.slice(-KEEP) : [],
|
|
340
386
|
state: kept.state === "finished" ? "finished" : "unavailable",
|
|
341
387
|
last: kept.last,
|
|
388
|
+
lastCount: Number.isInteger(kept.last_count) ? kept.last_count : 1,
|
|
342
389
|
restarts: Array.isArray(kept.restarts) ? kept.restarts : [],
|
|
343
390
|
received: kept.received,
|
|
344
391
|
error: kept.error,
|
|
345
392
|
saved: 0,
|
|
393
|
+
total: Number.isInteger(kept.total) ? kept.total : 0,
|
|
346
394
|
watched: Array.isArray(kept.watched)
|
|
347
395
|
? kept.watched.filter((p) => typeof p?.from === "string")
|
|
348
396
|
: [],
|
package/dist/runtime.js
CHANGED
|
@@ -194,6 +194,12 @@ export class DeploymentRuntime {
|
|
|
194
194
|
status: op.status,
|
|
195
195
|
project_id: op.project_id,
|
|
196
196
|
application_id: op.application_id,
|
|
197
|
+
created_at: op.created_at,
|
|
198
|
+
elapsed_seconds: Math.max(0, Math.round(((terminal.has(op.status) || paused.has(op.status)
|
|
199
|
+
? Date.parse(op.updated_at)
|
|
200
|
+
: Date.now()) -
|
|
201
|
+
Date.parse(op.created_at)) /
|
|
202
|
+
1000)),
|
|
197
203
|
readiness: ready.readiness,
|
|
198
204
|
readiness_checks: ready.readiness_checks,
|
|
199
205
|
message: [ready.message ?? op.result?.message, replacedNote(op.replaced)]
|
|
@@ -209,7 +215,7 @@ export class DeploymentRuntime {
|
|
|
209
215
|
? "paused"
|
|
210
216
|
: "background",
|
|
211
217
|
next_action: op.status === "failed"
|
|
212
|
-
? "Tell the user which stage/service failed and pass on the message. failure.
|
|
218
|
+
? "Tell the user which stage/service failed and pass on the message. The text lists the errors found in the log (failure.diagnostics) or its last lines (failure.log_tail), with how much of the log was captured; get_logs with the image or service ID shows more. Do not investigate using browser or other tools."
|
|
213
219
|
: op.status === "needs_key"
|
|
214
220
|
? `${this.engine.api.keyHelp("Constructor rejected the access key, or none is set.")} Then check this deployment again.`
|
|
215
221
|
: op.status === "needs_upload"
|
|
@@ -220,7 +226,7 @@ export class DeploymentRuntime {
|
|
|
220
226
|
? "Inspect the uncertain mutation in Constructor before submitting a new operation."
|
|
221
227
|
: terminal.has(op.status)
|
|
222
228
|
? undefined
|
|
223
|
-
: `NOT FINISHED: do not answer the user yet. Run now, in the foreground: \`${waitCommand(this.engine.api.config, [op.id])}\`. It returns when the deployment ends and prints the public URL or what failed. No shell: call get_deployment with this deployment_id and wait_seconds=45 again, until it is finished.`,
|
|
229
|
+
: `NOT FINISHED: do not answer the user yet. Run now, in the foreground: \`${waitCommand(this.engine.api.config, [op.id])}\`. It returns when the deployment ends and prints the public URL or what failed; do not pipe it (\`| tail\` hides its exit code: 0 finished, 2 failed or needs the user, 3 still running). No shell: call get_deployment with this deployment_id and wait_seconds=45 again, until it is finished.`,
|
|
224
230
|
};
|
|
225
231
|
}
|
|
226
232
|
async wait(id, milliseconds) {
|
package/dist/schemas.js
CHANGED
|
@@ -168,8 +168,7 @@ export const deployInput = z
|
|
|
168
168
|
.refine((x) => !!x.deployment_id || (!!x.application_name && !!x.services), "New deployments require application_name and services. To resume, provide deployment_id and optional service overrides.");
|
|
169
169
|
export const updateInput = z
|
|
170
170
|
.strictObject({ ...deploymentShape, application_id: id.optional() })
|
|
171
|
-
.refine((x) => !!x.deployment_id ||
|
|
172
|
-
((!!x.project_id || !!x.desk_url) && !!x.application_id && !!x.services), "Updates require desk_url or project_id, plus application_id and services, or deployment_id to resume.");
|
|
171
|
+
.refine((x) => !!x.deployment_id || (!!x.application_id && !!x.services), "update_app needs application_id and services (or deployment_id to resume). Get the IDs with get_deployment: with no arguments it lists every application with its project_id, application_id and service IDs. Pass project_id or desk_url too; without them the MCP looks the project up from application_id.");
|
|
173
172
|
export const lifecycleInput = z.strictObject({
|
|
174
173
|
project_id: id,
|
|
175
174
|
application_id: id,
|
package/dist/server.js
CHANGED
|
@@ -31,6 +31,7 @@ const DESK_DEFAULT = new Set([
|
|
|
31
31
|
]);
|
|
32
32
|
import { ZodError } from "zod";
|
|
33
33
|
import { buildInput, listInput, deployInput, updateInput, lifecycleInput, deleteInput, getInput, logsInput, listFilesInput, createFolderInput, syncFilesInput, movePathInput, deletePathInput, } from "./schemas.js";
|
|
34
|
+
import { render } from "./text.js";
|
|
34
35
|
async function main() {
|
|
35
36
|
const config = configFromEnv();
|
|
36
37
|
const api = new PlatformApi(config);
|
|
@@ -54,6 +55,13 @@ async function main() {
|
|
|
54
55
|
};
|
|
55
56
|
const prepared = async (fn, single, a, notes) => {
|
|
56
57
|
const begun = Date.now();
|
|
58
|
+
// An update with only application_id: the project that has it, when exactly one does.
|
|
59
|
+
if (!single && !a.project_id && !a.deployment_id && a.application_id) {
|
|
60
|
+
const project = await engine.locateApplication(a.application_id);
|
|
61
|
+
notes.push(`Used project_id ${project}, the only project with application ${a.application_id}; pass project_id next time.`);
|
|
62
|
+
const { project_name: _n, ...rest } = a;
|
|
63
|
+
a = { ...rest, project_id: project };
|
|
64
|
+
}
|
|
57
65
|
// No target anywhere: a new project, named by the agent, or a clear ask for that name.
|
|
58
66
|
if (!single && !a.project_id && !a.deployment_id && a.services) {
|
|
59
67
|
if (!a.project_name?.trim())
|
|
@@ -248,7 +256,7 @@ async function main() {
|
|
|
248
256
|
? text.replace(/Where to act: use the project or desk the user named.*?is created for the app\. /, deskInstructions(config.localDesk) + " ")
|
|
249
257
|
: text;
|
|
250
258
|
const server = new McpServer({ name: "constructor-research", version: VERSION }, {
|
|
251
|
-
instructions: withDesk(`Access: the MCP works with one Constructor and the user's personal access key for it, set up outside the chat. When a tool returns needs_key, pass its instructions on to the user; never ask for the key in the chat. Never read the key file or call Constructor's API yourself (curl, scripts): everything goes through these tools, and if they cannot do something, tell the user. Where to act: use the project or desk the user named, now or earlier in the conversation; a desk link (the browser address of a desk, with /projects/<project>/desks/<desk>) goes in desk_url. Do not pick an existing project yourself. When the user named none, do not ask: call deploy_app with project_name, a short name (one to three words, from the app), and the MCP creates a new project with deployment on; tell the user a new Constructor project with that name is created for the app. Given a project only (project_id), the MCP uses its only desk, or creates one for a deploy when there is none; when the project has several desks it returns desk_choice_required with their names and links: ask the user which one. Ask the user only before replacing, renaming or deleting files on a disk, once per request for the whole list (the tools return confirm_required); creating folders and uploading new files need no question. ${RULES} For a local app, pass build.local_path (the folder with the Dockerfile) and deploy_app uploads it first. A service can also take image: a public registry reference (repo:tag) that runs unchanged. The MCP uses the copy in the project when there is one (list_images shows source and reference), otherwise adds it to the project as an external image, with no desk and no build; if Constructor refuses it (image_refused), tell the user the reason. Hardware: leave it out; the default is used. Set hardware minimums only when the app cannot run without a GPU or a lot of RAM. Use deploy_app/update_app once for the WHOLE application. The MCP builds, resolves service URLs, configures and starts services in the background. IDs are automatic. To wait, run the wait command that next_action names (with a shell), or call get_deployment(wait_seconds=45) again until it is finished; never perform the deployment steps yourself. Never end the turn while a deployment the user asked for is still running. When the user asks to deploy or build, wait until the deployment is finished before answering, then give the public URL or what failed. On failure, tell the user the failed stage/service
|
|
259
|
+
instructions: withDesk(`Access: the MCP works with one Constructor and the user's personal access key for it, set up outside the chat. When a tool returns needs_key, pass its instructions on to the user; never ask for the key in the chat. Never read the key file or call Constructor's API yourself (curl, scripts): everything goes through these tools, and if they cannot do something, tell the user. Where to act: use the project or desk the user named, now or earlier in the conversation; a desk link (the browser address of a desk, with /projects/<project>/desks/<desk>) goes in desk_url. Do not pick an existing project yourself. When the user named none, do not ask: call deploy_app with project_name, a short name (one to three words, from the app), and the MCP creates a new project with deployment on; tell the user a new Constructor project with that name is created for the app. Given a project only (project_id), the MCP uses its only desk, or creates one for a deploy when there is none; when the project has several desks it returns desk_choice_required with their names and links: ask the user which one. Ask the user only before replacing, renaming or deleting files on a disk, once per request for the whole list (the tools return confirm_required); creating folders and uploading new files need no question. ${RULES} For a local app, pass build.local_path (the folder with the Dockerfile) and deploy_app uploads it first. A service can also take image: a public registry reference (repo:tag) that runs unchanged. The MCP uses the copy in the project when there is one (list_images shows source and reference), otherwise adds it to the project as an external image, with no desk and no build; if Constructor refuses it (image_refused), tell the user the reason. Hardware: leave it out; the default is used. Set hardware minimums only when the app cannot run without a GPU or a lot of RAM. Use deploy_app/update_app once for the WHOLE application. The MCP builds, resolves service URLs, configures and starts services in the background. IDs are automatic. To wait, run the wait command that next_action names (with a shell), or call get_deployment(wait_seconds=45) again until it is finished; never perform the deployment steps yourself. Never end the turn while a deployment the user asked for is still running. When the user asks to deploy or build, wait until the deployment is finished before answering, then give the public URL or what failed. On failure, tell the user the failed stage/service and the errors the result lists (taken from the whole kept log, with how much of it was captured); get_logs shows more. Do not use browser or debugging tools. To remove applications, services or images, use delete_resources (it asks the user first). For source files: sync_files to the desk before building (the MCP checks each Dockerfile on the disk and reports warnings); after a needs_upload pause, sync and call get_deployment with files_uploaded=true. Started is not readiness.`),
|
|
252
260
|
});
|
|
253
261
|
const register = (name, description, schema, fn, readOnly = false, budget = 20000, scope) => {
|
|
254
262
|
const here = config.localDesk && DESK_DEFAULT.has(name) ? config.localDesk : undefined;
|
|
@@ -294,10 +302,7 @@ async function main() {
|
|
|
294
302
|
content: [
|
|
295
303
|
{
|
|
296
304
|
type: "text",
|
|
297
|
-
text: result
|
|
298
|
-
(result.status
|
|
299
|
-
? `${result.status}${result.deployment_id ? ` (${result.deployment_id})` : ""}${result.message ? `: ${result.message}` : ""}${result.execution === "background" && result.next_action ? `\n${result.next_action}` : ""}`
|
|
300
|
-
: `Discovery result: ${result.total !== undefined ? result.total + " images" : Object.keys(result).join(", ")}. See structuredContent for details.`),
|
|
305
|
+
text: render(result),
|
|
301
306
|
},
|
|
302
307
|
],
|
|
303
308
|
// A preformatted text (build logs) is not repeated in structuredContent.
|
|
@@ -342,7 +347,7 @@ async function main() {
|
|
|
342
347
|
register("deploy_app", "Deploy the WHOLE app in one request: prepare project/disk, build or reuse all images, resolve internal/public service references, configure and start. Runs in the background. IDs are automatic. To resume a failure, send deployment_id and service overrides (for example replacement image_id); successful builds are preserved. On failure, failure.log_tail and get_logs show what the build or service printed." +
|
|
343
348
|
" " +
|
|
344
349
|
RULES, deployInput, checked((a) => runtime.deploy(a)), false, 60000, "deploy");
|
|
345
|
-
register("update_app", "Update/add selected services in one request; preserve omitted settings. MCP handles builds, links and restarts in the background. Environment variables merge; supplied port/volume lists replace their lists. Resume a failed update using deployment_id and service overrides. The Dockerfile rules in deploy_app apply.", updateInput, checked((a) => runtime.update(a)), false, 60000, "deploy");
|
|
350
|
+
register("update_app", "Update/add selected services of an existing application in one request; preserve omitted settings. Needs project_id (or desk_url), application_id and services: get_deployment with no arguments lists every application with its project_id, application_id and service IDs (without project_id the MCP looks it up from application_id, only when one project has it). Name existing services by service_id or their current name; they keep their IDs and volumes. MCP handles builds, links and restarts in the background. Environment variables merge; supplied port/volume lists replace their lists. Resume a failed update using deployment_id and service overrides. The Dockerfile rules in deploy_app apply.", updateInput, checked((a) => runtime.update(a)), false, 60000, "deploy");
|
|
346
351
|
register("start_app", "Start all or selected services as one operation. MCP handles all requests. Waits up to wait_seconds (default 20); remaining execution continues in the background. Started does not mean ready.", lifecycleInput, (a) => runtime.lifecycle("start", a), false, 20000, "project");
|
|
347
352
|
register("stop_app", "Stop all or selected services as one operation. MCP handles all requests. Waits up to wait_seconds (default 20). Stopped means stop requests accepted, not verified teardown.", lifecycleInput, (a) => runtime.lifecycle("stop", a), false, 20000, "project");
|
|
348
353
|
register("delete_resources", "Delete applications (each with all its services), single services, or images of one project, in one call for the whole request. Without confirm it returns what would be deleted (confirm_required), with public URLs and volumes whose data is lost, for the user to approve once; repeat with confirm=true. An image a remaining service uses is kept. Unfinished deployments of affected applications are ended first. Cannot be undone.", deleteInput, (a) => engine.deleteResources(a), false, 60000, "project");
|
package/dist/store.d.ts
CHANGED
|
@@ -32,6 +32,8 @@ export interface Operation {
|
|
|
32
32
|
errorSeen?: Record<string, string>;
|
|
33
33
|
/** Name of the failed image per build that was already rebuilt once. */
|
|
34
34
|
retried?: Record<string, string>;
|
|
35
|
+
/** Every build this operation started per service, with what its log said when it failed. */
|
|
36
|
+
attempts?: Record<string, BuildAttempt[]>;
|
|
35
37
|
/** Public-URL checks after start. */
|
|
36
38
|
readiness?: {
|
|
37
39
|
since: number;
|
|
@@ -59,8 +61,31 @@ export interface Operation {
|
|
|
59
61
|
desk_link?: string;
|
|
60
62
|
/** Last build log lines, when the MCP followed the build. */
|
|
61
63
|
log_tail?: string[];
|
|
64
|
+
/** Error excerpts from the whole kept log (diagnose.ts), bounded and with secrets masked. */
|
|
65
|
+
diagnostics?: string[];
|
|
66
|
+
/** Error blocks found in the log, and how many the excerpt leaves out. */
|
|
67
|
+
diagnostics_found?: number;
|
|
68
|
+
diagnostics_omitted?: number;
|
|
69
|
+
/** What the kept log covers: complete (followed to the end), partial, live or none. */
|
|
70
|
+
log_coverage?: "complete" | "partial" | "live" | "none";
|
|
71
|
+
log_lines_kept?: number;
|
|
72
|
+
/** compile / transient / unknown, and why (diagnose.ts classify). */
|
|
73
|
+
cause?: string;
|
|
74
|
+
cause_reason?: string;
|
|
75
|
+
/** How to read the whole kept log. */
|
|
76
|
+
logs_hint?: string;
|
|
62
77
|
};
|
|
63
78
|
}
|
|
79
|
+
/** One build of a service within an operation. */
|
|
80
|
+
export interface BuildAttempt {
|
|
81
|
+
image_id: string;
|
|
82
|
+
image_name?: string;
|
|
83
|
+
result: "error";
|
|
84
|
+
cause: string;
|
|
85
|
+
reason: string;
|
|
86
|
+
/** What the MCP did next: rebuilt once, or not, and why. */
|
|
87
|
+
next?: string;
|
|
88
|
+
}
|
|
64
89
|
export declare class StateStore {
|
|
65
90
|
readonly config: Config;
|
|
66
91
|
constructor(config: Config);
|
package/dist/text.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Longest text for one result; lists beyond it are cut with a count. */
|
|
2
|
+
export declare const MAX_TEXT = 12000;
|
|
3
|
+
/** deploy_app, update_app, build_image, start/stop and get_deployment(deployment_id). */
|
|
4
|
+
export declare function deployment(r: any): string;
|
|
5
|
+
/** The text an agent reads for a tool's result. */
|
|
6
|
+
export declare function render(result: any): string;
|
package/dist/text.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// The text content of every tool result. Some clients (OpenCode) show the agent only this
|
|
2
|
+
// text, never structuredContent, so it must carry what the agent acts on: real IDs, public
|
|
3
|
+
// URLs, statuses, what failed and how to read more. structuredContent stays as it was.
|
|
4
|
+
// Values Constructor did not return read "unavailable"; nothing is guessed.
|
|
5
|
+
import { duration } from "./diagnose.js";
|
|
6
|
+
/** Longest text for one result; lists beyond it are cut with a count. */
|
|
7
|
+
export const MAX_TEXT = 12000;
|
|
8
|
+
const NA = "unavailable";
|
|
9
|
+
const val = (v) => v === undefined || v === null || v === "" ? NA : String(v);
|
|
10
|
+
/** Joins lines and cuts the result to MAX_TEXT, saying so. */
|
|
11
|
+
function finish(lines) {
|
|
12
|
+
const out = lines.filter((l) => !!l).join("\n");
|
|
13
|
+
if (out.length <= MAX_TEXT)
|
|
14
|
+
return out;
|
|
15
|
+
const cut = out.slice(0, MAX_TEXT);
|
|
16
|
+
const end = cut.lastIndexOf("\n");
|
|
17
|
+
return `${end > 0 ? cut.slice(0, end) : cut}\n… cut to ${MAX_TEXT} characters; structuredContent has the rest.`;
|
|
18
|
+
}
|
|
19
|
+
/** Up to `max` items of a list, then a line saying how many more there are. */
|
|
20
|
+
function some(items, max, line) {
|
|
21
|
+
const out = items.slice(0, max).flatMap(line);
|
|
22
|
+
if (items.length > max)
|
|
23
|
+
out.push(` … and ${items.length - max} more; structuredContent has all of them.`);
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
function volumes(s) {
|
|
27
|
+
const v = (s.volumes ?? []).map((x) => `${x.mount_point ?? x.name}${x.size_gb ? ` (${x.size_gb} GB)` : ""}`);
|
|
28
|
+
return v.length ? ` volumes: ${v.join(", ")};` : "";
|
|
29
|
+
}
|
|
30
|
+
/** One line for a service of an application, as get_deployment returns it. */
|
|
31
|
+
function serviceLine(s) {
|
|
32
|
+
const id = s.id ?? s.service_id;
|
|
33
|
+
const name = s.name ?? s.service_name;
|
|
34
|
+
return ` - service ${val(name)} (service_id: ${val(id)}): status ${val(s.status)}; image_id ${val(s.image_id)};${volumes(s)} public URL: ${s.public_url ?? "none (no public port)"}`;
|
|
35
|
+
}
|
|
36
|
+
/** An application with its services; for update_app the agent needs all of these IDs. */
|
|
37
|
+
function applicationLines(a, project) {
|
|
38
|
+
const id = a.id ?? a.application_id;
|
|
39
|
+
const name = a.name ?? a.application_name;
|
|
40
|
+
return [
|
|
41
|
+
`- application ${val(name)} (application_id: ${val(id)}${project ? `, project_id: ${project}` : ""})`,
|
|
42
|
+
...((a.services ?? []).length
|
|
43
|
+
? some(a.services, 30, (s) => [serviceLine(s)])
|
|
44
|
+
: [" - no services"]),
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
const UPDATE_HINT = "To change an application, call update_app with project_id (or desk_url), application_id and the services to change; existing services keep their IDs and volumes.";
|
|
48
|
+
/** get_deployment with no arguments: every project with deployment on. */
|
|
49
|
+
function overview(r) {
|
|
50
|
+
return finish([
|
|
51
|
+
r.summary,
|
|
52
|
+
...some(r.projects ?? [], 40, (p) => [
|
|
53
|
+
`Project ${val(p.project_name)} (project_id: ${val(p.project_id)})${p.error ? `: applications could not be loaded (${p.error})` : ""}`,
|
|
54
|
+
...(p.applications ?? []).flatMap((a) => applicationLines(a)),
|
|
55
|
+
...(p.applications && !p.applications.length
|
|
56
|
+
? ["- no applications"]
|
|
57
|
+
: []),
|
|
58
|
+
]),
|
|
59
|
+
r.projects_without_deployment?.length
|
|
60
|
+
? `Projects without deployment: ${r.projects_without_deployment.length}.`
|
|
61
|
+
: undefined,
|
|
62
|
+
UPDATE_HINT,
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
/** get_deployment with a project: its desks, images and applications. */
|
|
66
|
+
function project(r) {
|
|
67
|
+
return finish([
|
|
68
|
+
`Project ${r.project_id}.`,
|
|
69
|
+
`Applications (${r.applications.length}):`,
|
|
70
|
+
...(r.applications.length
|
|
71
|
+
? some(r.applications, 30, (a) => applicationLines(a))
|
|
72
|
+
: ["- none"]),
|
|
73
|
+
r.desks?.length
|
|
74
|
+
? `Desks: ${r.desks.map((d) => `${val(d.name)} (desk_id: ${val(d.id)}, ${val(d.state)})`).join("; ")}.`
|
|
75
|
+
: undefined,
|
|
76
|
+
r.images?.length
|
|
77
|
+
? `Images (${r.images.length}): ${r.images
|
|
78
|
+
.slice(0, 30)
|
|
79
|
+
.map((i) => `${val(i.name)} (image_id: ${val(i.id)}, ${val(i.build_status)})`)
|
|
80
|
+
.join("; ")}${r.images.length > 30 ? `; … ${r.images.length - 30} more` : ""}.`
|
|
81
|
+
: undefined,
|
|
82
|
+
UPDATE_HINT,
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
/** get_deployment with project and application_id. */
|
|
86
|
+
function application(r) {
|
|
87
|
+
return finish([
|
|
88
|
+
`Project ${val(r.project_id)}.`,
|
|
89
|
+
...applicationLines(r),
|
|
90
|
+
UPDATE_HINT,
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
function images(r) {
|
|
94
|
+
return finish([
|
|
95
|
+
`${r.total} image${r.total === 1 ? "" : "s"}:`,
|
|
96
|
+
...some(r.results ?? [], 60, (i) => [
|
|
97
|
+
`- ${val(i.name)} (image_id: ${val(i.id)}): ${val(i.build_status)}${i.source === "external" ? `, external ${val(i.reference)}` : i.dockerfile ? `, ${i.dockerfile}${i.desk_name ? ` on desk ${i.desk_name}` : ""}` : ""}`,
|
|
98
|
+
]),
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
/** A build of this deployment: status, age, log coverage and steps with their durations. */
|
|
102
|
+
function buildLines(b, running) {
|
|
103
|
+
const age = running && b.requested_at
|
|
104
|
+
? `, requested ${duration((Date.now() - Date.parse(b.requested_at)) / 1000)} ago`
|
|
105
|
+
: "";
|
|
106
|
+
const log = b.log ?? {};
|
|
107
|
+
const coverage = log.coverage === "complete"
|
|
108
|
+
? `build log followed to its end (${log.lines_kept} lines kept)`
|
|
109
|
+
: log.coverage === "live"
|
|
110
|
+
? `build log live (${log.lines_kept} lines so far)`
|
|
111
|
+
: log.coverage === "partial"
|
|
112
|
+
? `build log may be incomplete (${log.lines_kept} lines kept)`
|
|
113
|
+
: "no build log captured";
|
|
114
|
+
const out = [
|
|
115
|
+
` - build ${val(b.service)}: image ${val(b.name)} (image_id: ${val(b.id)}) ${val(b.build_status)}${age}; ${coverage}.`,
|
|
116
|
+
];
|
|
117
|
+
const st = log.steps ?? [];
|
|
118
|
+
if (st.length)
|
|
119
|
+
out.push(` steps (from log timestamps; estimates, pull time included): ${st
|
|
120
|
+
.map((s) => `${s.step} ${s.last && running ? `running for ${duration(s.seconds)} so far` : duration(s.seconds)}`)
|
|
121
|
+
.join(" | ")}`);
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
/** deploy_app, update_app, build_image, start/stop and get_deployment(deployment_id). */
|
|
125
|
+
export function deployment(r) {
|
|
126
|
+
const running = r.execution === "background" || r.status === "building";
|
|
127
|
+
const elapsed = typeof r.elapsed_seconds === "number"
|
|
128
|
+
? `${running ? "running for" : "took"} ${duration(r.elapsed_seconds)}`
|
|
129
|
+
: undefined;
|
|
130
|
+
const f = r.failure;
|
|
131
|
+
const lines = [
|
|
132
|
+
`Deployment ${r.deployment_id} (${val(r.operation)}): ${r.status}${elapsed ? `, ${elapsed}` : ""}.`,
|
|
133
|
+
r.operation === "build"
|
|
134
|
+
? `Project ${val(r.project_id)}.`
|
|
135
|
+
: `Project ${val(r.project_id)}; application ${r.application_name ? `${r.application_name} ` : ""}(application_id: ${r.application_id ?? "not created yet"}).`,
|
|
136
|
+
r.message,
|
|
137
|
+
];
|
|
138
|
+
const svcs = r.services ?? [];
|
|
139
|
+
if (svcs.length) {
|
|
140
|
+
lines.push("Services (as Constructor reports them now):");
|
|
141
|
+
for (const s of svcs.slice(0, 30)) {
|
|
142
|
+
const image = s.attempted_image_id === undefined
|
|
143
|
+
? `image_id ${val(s.image_id)}`
|
|
144
|
+
: s.runs_attempted_image
|
|
145
|
+
? `runs the image this deployment built (${s.image_id})`
|
|
146
|
+
: `runs image ${val(s.image_id)}, NOT the image this deployment attempted (${s.attempted_image_id})`;
|
|
147
|
+
const ready = r.readiness_checks?.[s.name];
|
|
148
|
+
lines.push(` - ${val(s.name)} (service_id: ${val(s.id)}): ${val(s.status)}; ${image};${volumes(s)} public URL: ${s.public_url ?? "none (no public port)"}${ready ? `; answered ${ready.status === null ? "nothing" : `HTTP ${ready.status}`}` : ""}${s.restarts_seen ? `; ${s.restarts_seen} restart(s) seen` : ""}`);
|
|
149
|
+
}
|
|
150
|
+
if (svcs.length > 30)
|
|
151
|
+
lines.push(` … and ${svcs.length - 30} more services.`);
|
|
152
|
+
}
|
|
153
|
+
else if (r.application_id)
|
|
154
|
+
lines.push("Services: unavailable (Constructor did not return the application).");
|
|
155
|
+
const builds = r.images ?? [];
|
|
156
|
+
if (builds.length) {
|
|
157
|
+
lines.push("Builds of this deployment:");
|
|
158
|
+
for (const b of builds)
|
|
159
|
+
lines.push(...buildLines(b, running));
|
|
160
|
+
}
|
|
161
|
+
const attempts = Object.entries(r.build_attempts ?? {});
|
|
162
|
+
// Earlier attempts; the current image's outcome is in the build list and the failure.
|
|
163
|
+
const current = new Set(builds.map((b) => b.id));
|
|
164
|
+
for (const [service, list] of attempts)
|
|
165
|
+
for (const a of list.filter((a) => !current.has(a.image_id)))
|
|
166
|
+
lines.push(` - failed build of ${service}: ${val(a.image_name)} (image_id: ${a.image_id}), cause ${a.cause}: ${a.reason}${a.next ? `; ${a.next}` : ""}.`);
|
|
167
|
+
if (f) {
|
|
168
|
+
lines.push(`Failure: stage ${val(f.stage)}${f.service ? `, service ${f.service}` : ""}${f.image_id ? `, image ${val(f.image_name)} (image_id: ${f.image_id})` : ""}${f.dockerfile ? `, Dockerfile ${f.dockerfile}` : ""}${f.cause ? `; cause ${f.cause}${f.cause_reason ? ` (${f.cause_reason})` : ""}` : ""}.`);
|
|
169
|
+
if (f.diagnostics?.length) {
|
|
170
|
+
lines.push(`Errors from the ${f.stage === "build" ? "build" : "service"} log (${f.diagnostics_found} found${f.diagnostics_omitted ? `, ${f.diagnostics_omitted} left out` : ""}):`, ...f.diagnostics.map((l) => ` ${l}`));
|
|
171
|
+
}
|
|
172
|
+
else if (f.log_tail?.length)
|
|
173
|
+
lines.push("Last log lines:", ...f.log_tail.slice(-20).map((l) => ` ${l}`));
|
|
174
|
+
if (f.log_coverage)
|
|
175
|
+
lines.push(`Log coverage: ${f.log_coverage}${f.log_coverage === "complete" ? "" : f.log_coverage === "none" ? " (nothing was captured)" : " (diagnostics may be missing lines)"}.`);
|
|
176
|
+
if (f.logs_hint)
|
|
177
|
+
lines.push(f.logs_hint);
|
|
178
|
+
}
|
|
179
|
+
if (r.volumes_to_wipe?.length)
|
|
180
|
+
lines.push(`Volumes that would lose data: ${r.volumes_to_wipe.join("; ")}.`);
|
|
181
|
+
if (r.status === "started" && r.readiness)
|
|
182
|
+
lines.push(`Readiness: ${r.readiness}.`);
|
|
183
|
+
if (r.next_action)
|
|
184
|
+
lines.push(`Next: ${r.next_action}`);
|
|
185
|
+
return finish(lines);
|
|
186
|
+
}
|
|
187
|
+
/** The text an agent reads for a tool's result. */
|
|
188
|
+
export function render(result) {
|
|
189
|
+
if (typeof result?.text === "string")
|
|
190
|
+
return result.text;
|
|
191
|
+
if (result?.deployment_id && result.status)
|
|
192
|
+
return deployment(result);
|
|
193
|
+
if (Array.isArray(result?.projects))
|
|
194
|
+
return overview(result);
|
|
195
|
+
if (result?.project_id && Array.isArray(result.applications))
|
|
196
|
+
return project(result);
|
|
197
|
+
if (result?.id && result.project_id && Array.isArray(result.services))
|
|
198
|
+
return application(result);
|
|
199
|
+
if (Array.isArray(result?.results) && typeof result.total === "number")
|
|
200
|
+
return images(result);
|
|
201
|
+
if (result?.status)
|
|
202
|
+
return finish([
|
|
203
|
+
`${result.status}${result.message ? `: ${result.message}` : ""}`,
|
|
204
|
+
result.next_action ? `Next: ${result.next_action}` : undefined,
|
|
205
|
+
]);
|
|
206
|
+
// Anything else: the data itself, bounded, rather than a pointer to structuredContent.
|
|
207
|
+
return finish([JSON.stringify(result, null, 1)]);
|
|
208
|
+
}
|