@engini/cli 0.6.0 → 0.8.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/README.md +66 -2
- package/dist/cli.js +977 -32
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -20,20 +20,54 @@ engini applications list --available # discover connector apps
|
|
|
20
20
|
engini tools list --application monday # discover tools
|
|
21
21
|
engini tools call monday_create_item --args '{}' --connection 3
|
|
22
22
|
engini tools call gmail_send_mail --args '{}' --file attachmentsarray=@report.pdf # attach a file
|
|
23
|
+
engini tools result <handle> --select items.email # drill into a large result
|
|
23
24
|
```
|
|
24
25
|
|
|
25
26
|
## Commands
|
|
26
27
|
|
|
27
28
|
```
|
|
28
29
|
engini login | logout | whoami # auth
|
|
29
|
-
engini tools list | get | call
|
|
30
|
+
engini tools list | get | call | result # discover, execute & drill into results
|
|
30
31
|
engini applications list | get # browse connector apps
|
|
32
|
+
engini connect [<app>] # create a connection (interactive / agent-resumable)
|
|
31
33
|
engini connections list | get # inspect connections
|
|
32
|
-
engini
|
|
34
|
+
engini connections create | check | refresh | objects | select-objects # creation-flow primitives
|
|
35
|
+
engini connections sign-in-url | oauth-complete # OAuth2 start / finish primitives
|
|
33
36
|
```
|
|
34
37
|
|
|
35
38
|
Run `engini <command> --help` for details and examples on any command.
|
|
36
39
|
|
|
40
|
+
`connect <app>` discovers the app's authentication methods, collects credentials
|
|
41
|
+
(or runs the OAuth2 sign-in), creates the connection, checks it, refreshes its
|
|
42
|
+
objects, and — when the app supports it — lets you pick which objects to sync.
|
|
43
|
+
On a TTY it prompts and opens the browser inline. Async jobs poll up to
|
|
44
|
+
`--timeout` (`--no-wait` returns early; a timeout exits `124`).
|
|
45
|
+
|
|
46
|
+
### Agent recipe (piped / non-TTY)
|
|
47
|
+
|
|
48
|
+
`connect` never blocks for an agent: at each gate it prints a self-describing
|
|
49
|
+
`{ "need": …, "resume": "<exact next command>" }` and exits `5`. The agent asks
|
|
50
|
+
the user for the value and runs the `resume` command:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# direct-credential (e.g. monday)
|
|
54
|
+
engini connect monday --json # → {need:"fields", resume:"engini connect monday --auth 0 --field ApiKey=<value>"}
|
|
55
|
+
engini connect monday --auth 0 --field ApiKey=<key> # creates → checks → refreshes
|
|
56
|
+
|
|
57
|
+
# OAuth2 (e.g. outlook) — never opens a browser for the agent
|
|
58
|
+
engini connect outlook --json # → {need:"oauth", sign_in_url, state, resume:"engini connect outlook --oauth-state <state>"}
|
|
59
|
+
# show sign_in_url to the user; after they sign in:
|
|
60
|
+
engini connect outlook --oauth-state <state> # polls token → creates → checks → refreshes
|
|
61
|
+
|
|
62
|
+
# object selection (apps that support it) — resume never re-creates
|
|
63
|
+
engini connect <app> --json # → {need:"objects", connection_id, objects, resume:"engini connect <app> --connection <id> --object <id>"}
|
|
64
|
+
engini connect <app> --connection <id> --object 5 --object 9
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The same steps are available as standalone primitives: `connections sign-in-url`
|
|
68
|
+
/ `oauth-complete` (OAuth) and `connections create` / `check` / `refresh` /
|
|
69
|
+
`objects` / `select-objects`.
|
|
70
|
+
|
|
37
71
|
## Output & exit codes
|
|
38
72
|
|
|
39
73
|
Output adapts to context: human-readable on a TTY, **compact JSON when piped**, pretty JSON
|
|
@@ -47,6 +81,36 @@ with `--json`. Every command also accepts:
|
|
|
47
81
|
Exit codes are a stable contract: `0` success · `1` general error · `2` usage error ·
|
|
48
82
|
`3` authentication error · `4` not found · `5` validation error · `124` timeout.
|
|
49
83
|
|
|
84
|
+
## Large results (token economy)
|
|
85
|
+
|
|
86
|
+
Tool outputs can be huge — an agent shouldn't pay tokens for data it hasn't asked
|
|
87
|
+
for. When a `tools call` result exceeds `--max-bytes` (default `4096`), it is
|
|
88
|
+
spilled to a local sandbox and the command prints a compact envelope instead:
|
|
89
|
+
|
|
90
|
+
```jsonc
|
|
91
|
+
{ "handle": "h42", "history_id": 42, "data_size": 84211,
|
|
92
|
+
"shape": { "type": "object", "keys": { "items": "array", "total": "number" } },
|
|
93
|
+
"preview": { "id": 1, "email": "a@x.io" },
|
|
94
|
+
"hint": "Full result stored. Pull data with: engini tools result h42 …" }
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Then drill in with `tools result <handle>`, paying only for what you pull:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
engini tools result h42 --select items.email # dot-path (maps over a list)
|
|
101
|
+
engini tools result h42 --fields id,name # project keys per item
|
|
102
|
+
engini tools result h42 --select items --offset 20 --limit 10 # page a list
|
|
103
|
+
engini tools result h42 --full # the whole payload
|
|
104
|
+
engini tools result --list # known handles
|
|
105
|
+
engini tools result --clear # wipe the sandbox
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`--inline` (or `--max-bytes 0`) forces the full result inline; `--raw` / `--llm`
|
|
109
|
+
emit the full output as before and bypass the sandbox. Stored results live under
|
|
110
|
+
`$XDG_CACHE_HOME/engini/results/` (`%APPDATA%` on Windows) and are auto-pruned to
|
|
111
|
+
the most-recent 20, dropping anything older than 24h — so a handle is short-lived;
|
|
112
|
+
drill in during the same session.
|
|
113
|
+
|
|
50
114
|
## Configuration
|
|
51
115
|
|
|
52
116
|
Credentials and host config live in `$XDG_CONFIG_HOME/engini/config.toml`
|
package/dist/cli.js
CHANGED
|
@@ -26,6 +26,16 @@ async function confirm(question) {
|
|
|
26
26
|
rl.close();
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
async function promptText(label, fallback = "") {
|
|
30
|
+
const suffix = fallback ? ` [${fallback}]` : "";
|
|
31
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
32
|
+
try {
|
|
33
|
+
const answer = (await ask(rl, `${label}${suffix}: `)).trim();
|
|
34
|
+
return answer || fallback;
|
|
35
|
+
} finally {
|
|
36
|
+
rl.close();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
29
39
|
async function promptHidden(label) {
|
|
30
40
|
const output = process.stdout;
|
|
31
41
|
const rl = createInterface({ input: process.stdin, output, terminal: true });
|
|
@@ -107,17 +117,20 @@ function printOutput(obj) {
|
|
|
107
117
|
pretty(obj);
|
|
108
118
|
}
|
|
109
119
|
}
|
|
110
|
-
function
|
|
120
|
+
function progress(message) {
|
|
121
|
+
if (isTty() && !context.quiet) console.error(message);
|
|
122
|
+
}
|
|
123
|
+
function fail(code, message, hint2) {
|
|
111
124
|
if (isTty()) {
|
|
112
125
|
console.error(`Error: ${message}`);
|
|
113
|
-
if (
|
|
126
|
+
if (hint2) console.error(`Hint: ${hint2}`);
|
|
114
127
|
} else {
|
|
115
128
|
const payload = {
|
|
116
129
|
error: ERROR_NAMES[code] ?? "Error",
|
|
117
130
|
message,
|
|
118
131
|
exit_code: code
|
|
119
132
|
};
|
|
120
|
-
if (
|
|
133
|
+
if (hint2) payload.hint = hint2;
|
|
121
134
|
console.error(JSON.stringify(payload));
|
|
122
135
|
}
|
|
123
136
|
throw new CliError(code);
|
|
@@ -199,6 +212,7 @@ import {
|
|
|
199
212
|
EnginiAuthError,
|
|
200
213
|
EnginiError,
|
|
201
214
|
EnginiNotFoundError,
|
|
215
|
+
EnginiTimeoutError,
|
|
202
216
|
EnginiValidationError
|
|
203
217
|
} from "@engini/sdk";
|
|
204
218
|
|
|
@@ -267,6 +281,7 @@ function exitForError(err) {
|
|
|
267
281
|
if (err instanceof EnginiAuthError) return 3 /* AUTH */;
|
|
268
282
|
if (err instanceof EnginiNotFoundError) return 4 /* NOT_FOUND */;
|
|
269
283
|
if (err instanceof EnginiValidationError) return 5 /* VALIDATION */;
|
|
284
|
+
if (err instanceof EnginiTimeoutError) return 124 /* TIMEOUT */;
|
|
270
285
|
return 1 /* GENERIC */;
|
|
271
286
|
}
|
|
272
287
|
async function apiErrors(fn) {
|
|
@@ -361,24 +376,414 @@ function registerApplications(program) {
|
|
|
361
376
|
registerApplicationsGet(applications);
|
|
362
377
|
}
|
|
363
378
|
|
|
379
|
+
// src/connections/shared.ts
|
|
380
|
+
import { refreshFailed } from "@engini/sdk";
|
|
381
|
+
var OAUTH_DONE = /* @__PURE__ */ new Set(["completed", "complete", "success", "succeeded"]);
|
|
382
|
+
var OAUTH_FAILED = /* @__PURE__ */ new Set(["failed", "error", "cancelled", "canceled", "denied"]);
|
|
383
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
384
|
+
function collect(value, previous = []) {
|
|
385
|
+
return [...previous, value];
|
|
386
|
+
}
|
|
387
|
+
function parseId(value) {
|
|
388
|
+
if (!value) fail(2 /* USAGE */, "Missing required argument 'connection_id'.");
|
|
389
|
+
const id = Number(value);
|
|
390
|
+
if (!Number.isInteger(id)) fail(2 /* USAGE */, "connection_id must be an integer.");
|
|
391
|
+
return id;
|
|
392
|
+
}
|
|
393
|
+
function parseFields(specs) {
|
|
394
|
+
const out = {};
|
|
395
|
+
for (const spec of specs ?? []) {
|
|
396
|
+
const eq = spec.indexOf("=");
|
|
397
|
+
if (eq <= 0) {
|
|
398
|
+
fail(2 /* USAGE */, `--field must be key=value, got '${spec}'.`);
|
|
399
|
+
}
|
|
400
|
+
out[spec.slice(0, eq)] = spec.slice(eq + 1);
|
|
401
|
+
}
|
|
402
|
+
return out;
|
|
403
|
+
}
|
|
404
|
+
function need(payload) {
|
|
405
|
+
printOutput(payload);
|
|
406
|
+
throw new CliError(5 /* VALIDATION */);
|
|
407
|
+
}
|
|
408
|
+
function checkAlive(result) {
|
|
409
|
+
if (typeof result === "boolean") return result;
|
|
410
|
+
if (result && typeof result === "object") {
|
|
411
|
+
const record = result;
|
|
412
|
+
for (const key of ["isAlive", "is_alive", "alive", "isHealthy", "healthy", "success"]) {
|
|
413
|
+
if (key in record) return Boolean(record[key]);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
async function pollRefresh(client, connectionId, opts) {
|
|
419
|
+
if (!opts.wait) return "pending";
|
|
420
|
+
progress(
|
|
421
|
+
`Refreshing objects \u2014 this can take a moment (up to ${Math.round(opts.timeout)}s, Ctrl-C to abort)\u2026`
|
|
422
|
+
);
|
|
423
|
+
const status = await client.connections.waitForRefresh(connectionId, {
|
|
424
|
+
timeout: opts.timeout,
|
|
425
|
+
interval: opts.interval
|
|
426
|
+
});
|
|
427
|
+
if (refreshFailed(status)) {
|
|
428
|
+
const error = clean(status.error);
|
|
429
|
+
fail(1 /* GENERIC */, `Refresh failed: ${error ?? "the refresh job reported failure"}`);
|
|
430
|
+
}
|
|
431
|
+
return "completed";
|
|
432
|
+
}
|
|
433
|
+
async function pollAccessToken(client, state, opts) {
|
|
434
|
+
progress(
|
|
435
|
+
`Waiting for you to finish signing in (up to ${Math.round(opts.timeout)}s, Ctrl-C to abort)\u2026`
|
|
436
|
+
);
|
|
437
|
+
const deadline = Date.now() + opts.timeout * 1e3;
|
|
438
|
+
for (; ; ) {
|
|
439
|
+
const resp = await client.connections.getAccessToken(state);
|
|
440
|
+
const status = (resp.status ?? "").toLowerCase();
|
|
441
|
+
if (OAUTH_DONE.has(status)) return resp;
|
|
442
|
+
if (OAUTH_FAILED.has(status)) {
|
|
443
|
+
fail(1 /* GENERIC */, clean(resp.error_message) ?? "OAuth sign-in failed.");
|
|
444
|
+
}
|
|
445
|
+
if (Date.now() >= deadline) {
|
|
446
|
+
fail(124 /* TIMEOUT */, "OAuth sign-in did not complete in time.");
|
|
447
|
+
}
|
|
448
|
+
await sleep(opts.interval * 1e3);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function oauthFields(token) {
|
|
452
|
+
const fields = {};
|
|
453
|
+
for (const [key, value] of Object.entries(token.connectionData ?? {})) {
|
|
454
|
+
if (value === null || value === void 0) continue;
|
|
455
|
+
fields[key] = typeof value === "string" ? value : JSON.stringify(value);
|
|
456
|
+
}
|
|
457
|
+
return fields;
|
|
458
|
+
}
|
|
459
|
+
|
|
364
460
|
// src/connect.ts
|
|
365
461
|
function connectionsUrl(config) {
|
|
366
462
|
return `${config.identity_url.replace(/\/+$/, "")}/connections#integrations`;
|
|
367
463
|
}
|
|
368
|
-
function connectBody() {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
464
|
+
async function connectBody(application, opts) {
|
|
465
|
+
if (!application && opts.connection === void 0) {
|
|
466
|
+
const url = connectionsUrl(loadConfig());
|
|
467
|
+
openBrowser(url);
|
|
468
|
+
printOutput({ url });
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
const timing = {
|
|
472
|
+
wait: opts.wait !== false,
|
|
473
|
+
timeout: Number(opts.timeout ?? 300),
|
|
474
|
+
interval: Number(opts.pollInterval ?? 2)
|
|
475
|
+
};
|
|
476
|
+
const noObjects = opts.objects === false;
|
|
477
|
+
await apiErrors(async () => {
|
|
478
|
+
const client = buildClient();
|
|
479
|
+
if (opts.connection !== void 0) {
|
|
480
|
+
const connectionId2 = parseId(opts.connection);
|
|
481
|
+
const selected = await selectObjectStep(client, application, connectionId2, opts.object, {
|
|
482
|
+
...timing,
|
|
483
|
+
noObjects,
|
|
484
|
+
supported: true
|
|
485
|
+
});
|
|
486
|
+
printOutput({ connection_id: connectionId2, objects_selected: selected });
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (!application) fail(2 /* USAGE */, "Missing required argument 'application'.");
|
|
490
|
+
const detail4 = await client.applications.get(application);
|
|
491
|
+
const method = await chooseAuth(detail4.authenticationMethods ?? [], opts.auth, application);
|
|
492
|
+
if (dryRun()) {
|
|
493
|
+
printOutput({
|
|
494
|
+
would_connect: {
|
|
495
|
+
application,
|
|
496
|
+
authentication_id: method.authenticationId,
|
|
497
|
+
oauth: Boolean(method.requiresOAuthSignIn)
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
const name = await resolveName(opts.name, application);
|
|
503
|
+
const fields = method.requiresOAuthSignIn ? await oauthFieldsFor(client, application, method, opts.oauthState, timing) : await collectFields(method, application, opts.field);
|
|
504
|
+
progress(`Creating connection '${name}'\u2026`);
|
|
505
|
+
const created = await client.connections.create(
|
|
506
|
+
application,
|
|
507
|
+
name,
|
|
508
|
+
method.authenticationId,
|
|
509
|
+
fields
|
|
510
|
+
);
|
|
511
|
+
const connectionId = created.connectionId;
|
|
512
|
+
progress(`Checking connection ${connectionId}\u2026`);
|
|
513
|
+
const alive = checkAlive(await client.connections.check(connectionId));
|
|
514
|
+
if (alive === false) {
|
|
515
|
+
fail(1 /* GENERIC */, `Connection ${connectionId} failed its liveness check.`);
|
|
516
|
+
}
|
|
517
|
+
await client.connections.refresh(connectionId);
|
|
518
|
+
await pollRefresh(client, connectionId, timing);
|
|
519
|
+
const objectsSelected = await selectObjectStep(client, application, connectionId, opts.object, {
|
|
520
|
+
...timing,
|
|
521
|
+
noObjects,
|
|
522
|
+
supported: supportsObjectSelection(detail4, created)
|
|
523
|
+
});
|
|
524
|
+
printOutput({
|
|
525
|
+
connection_id: connectionId,
|
|
526
|
+
is_alive: alive,
|
|
527
|
+
objects_selected: objectsSelected
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
function supportsObjectSelection(detail4, created) {
|
|
532
|
+
if (clean(detail4.supportsObjectSelection)) return true;
|
|
533
|
+
return Boolean(created && clean(created.useSelectDBObjects));
|
|
534
|
+
}
|
|
535
|
+
function parseObjectIds(specs) {
|
|
536
|
+
return (specs ?? []).map((value) => {
|
|
537
|
+
const n = Number(value);
|
|
538
|
+
if (!Number.isInteger(n)) fail(2 /* USAGE */, `--object must be an integer, got '${value}'.`);
|
|
539
|
+
return n;
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
async function chooseAuth(methods, auth, application) {
|
|
543
|
+
if (methods.length === 0) {
|
|
544
|
+
fail(1 /* GENERIC */, `Application '${application}' exposes no authentication methods.`);
|
|
545
|
+
}
|
|
546
|
+
const byId = new Map(methods.map((m) => [m.authenticationId, m]));
|
|
547
|
+
if (auth !== void 0) {
|
|
548
|
+
const id = Number(auth);
|
|
549
|
+
const chosen = byId.get(id);
|
|
550
|
+
if (!chosen) {
|
|
551
|
+
fail(
|
|
552
|
+
2 /* USAGE */,
|
|
553
|
+
`No authentication method with id ${auth} for '${application}'.`,
|
|
554
|
+
`Run \`engini connect ${application} --json\` to list them.`
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
return chosen;
|
|
558
|
+
}
|
|
559
|
+
if (methods.length === 1) return methods[0];
|
|
560
|
+
if (isTty()) {
|
|
561
|
+
for (const m of methods) {
|
|
562
|
+
console.error(` ${m.authenticationId}: ${m.authenticationName} (${m.authenticationType})`);
|
|
563
|
+
}
|
|
564
|
+
const id = Number(await promptText("Choose an authentication method id"));
|
|
565
|
+
const chosen = byId.get(id);
|
|
566
|
+
if (!chosen) fail(2 /* USAGE */, `No authentication method with id ${id}.`);
|
|
567
|
+
return chosen;
|
|
568
|
+
}
|
|
569
|
+
return need({
|
|
570
|
+
need: "auth",
|
|
571
|
+
application,
|
|
572
|
+
methods: methods.map(methodSummary),
|
|
573
|
+
resume: `engini connect ${application} --auth <id>`
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
async function collectFields(method, application, field) {
|
|
577
|
+
const provided = parseFields(field);
|
|
578
|
+
const schema = method.connectionFields.filter((f) => !f.isHidden);
|
|
579
|
+
const required = schema.filter((f) => f.isRequired);
|
|
580
|
+
const missing = required.filter((f) => !(f.fieldName in provided));
|
|
581
|
+
if (missing.length === 0) return provided;
|
|
582
|
+
if (isTty()) {
|
|
583
|
+
for (const f of schema) {
|
|
584
|
+
if (f.fieldName in provided) continue;
|
|
585
|
+
const label = fieldLabel(f);
|
|
586
|
+
const value = f.isPassword ? await promptHidden(label) : await promptText(label, clean(f.defaultValue) ?? "");
|
|
587
|
+
if (value) provided[f.fieldName] = value;
|
|
588
|
+
}
|
|
589
|
+
return provided;
|
|
590
|
+
}
|
|
591
|
+
const fieldsFlags = required.map((f) => `--field ${f.fieldName}=<value>`).join(" ");
|
|
592
|
+
return need({
|
|
593
|
+
need: "fields",
|
|
594
|
+
application,
|
|
595
|
+
authentication_id: method.authenticationId,
|
|
596
|
+
fields: schema.map(fieldSummary),
|
|
597
|
+
resume: `engini connect ${application} --auth ${method.authenticationId} ${fieldsFlags}`
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
async function resolveName(name, application) {
|
|
601
|
+
if (name) return name;
|
|
602
|
+
const fallback = `${application} connection`;
|
|
603
|
+
if (isTty()) return promptText("Connection name", fallback);
|
|
604
|
+
return fallback;
|
|
605
|
+
}
|
|
606
|
+
async function selectObjectStep(client, application, connectionId, objectSpecs, opts) {
|
|
607
|
+
if (opts.noObjects || !opts.supported) return 0;
|
|
608
|
+
let ids = parseObjectIds(objectSpecs);
|
|
609
|
+
if (ids.length === 0) {
|
|
610
|
+
progress("Loading available objects\u2026");
|
|
611
|
+
const objs = await client.connections.objects(connectionId);
|
|
612
|
+
ids = await resolveObjects(objs, connectionId, application);
|
|
613
|
+
}
|
|
614
|
+
if (ids.length === 0) return 0;
|
|
615
|
+
await client.connections.selectObjects(connectionId, ids);
|
|
616
|
+
await pollRefresh(client, connectionId, opts);
|
|
617
|
+
return ids.length;
|
|
618
|
+
}
|
|
619
|
+
async function resolveObjects(objs, connectionId, application) {
|
|
620
|
+
if (objs.length === 0) return [];
|
|
621
|
+
if (isTty()) {
|
|
622
|
+
for (const o of objs) console.error(` ${o.objectId}: ${o.name} (${o.type})`);
|
|
623
|
+
const raw = await promptText("Object ids to select (comma/space separated, blank for none)");
|
|
624
|
+
return raw.split(/[\s,]+/).filter(Boolean).map(Number).filter(Number.isInteger);
|
|
625
|
+
}
|
|
626
|
+
const app = application ?? "<app>";
|
|
627
|
+
return need({
|
|
628
|
+
need: "objects",
|
|
629
|
+
application,
|
|
630
|
+
connection_id: connectionId,
|
|
631
|
+
objects: objs.map(objectSummary),
|
|
632
|
+
resume: `engini connect ${app} --connection ${connectionId} --object <id>`
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
async function oauthFieldsFor(client, application, method, oauthState, timing) {
|
|
636
|
+
if (oauthState) {
|
|
637
|
+
const token = await pollAccessToken(client, oauthState, timing);
|
|
638
|
+
return oauthFields(token);
|
|
639
|
+
}
|
|
640
|
+
const resp = await client.connections.getSignInUrl(application, method.authenticationId);
|
|
641
|
+
if (isTty() && timing.wait) {
|
|
642
|
+
openBrowser(resp.signInUrl);
|
|
643
|
+
progress(`Opened ${resp.signInUrl} \u2014 complete the sign-in in your browser.`);
|
|
644
|
+
const token = await pollAccessToken(client, resp.state, timing);
|
|
645
|
+
return oauthFields(token);
|
|
646
|
+
}
|
|
647
|
+
return need({
|
|
648
|
+
need: "oauth",
|
|
649
|
+
application,
|
|
650
|
+
authentication_id: method.authenticationId,
|
|
651
|
+
sign_in_url: resp.signInUrl,
|
|
652
|
+
state: resp.state,
|
|
653
|
+
resume: `engini connect ${application} --oauth-state ${resp.state}`
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
function fieldLabel(f) {
|
|
657
|
+
const label = clean(f.fieldDescription) ?? f.fieldName;
|
|
658
|
+
const placeholder = clean(f.placeholder);
|
|
659
|
+
return placeholder ? `${label} (${placeholder})` : label;
|
|
660
|
+
}
|
|
661
|
+
function methodSummary(m) {
|
|
662
|
+
return {
|
|
663
|
+
authentication_id: m.authenticationId,
|
|
664
|
+
authentication_type: m.authenticationType,
|
|
665
|
+
authentication_name: m.authenticationName,
|
|
666
|
+
requires_oauth: m.requiresOAuthSignIn,
|
|
667
|
+
fields: m.connectionFields.map(fieldSummary)
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
function fieldSummary(f) {
|
|
671
|
+
return {
|
|
672
|
+
field_name: f.fieldName,
|
|
673
|
+
is_required: f.isRequired,
|
|
674
|
+
is_password: f.isPassword,
|
|
675
|
+
description: clean(f.fieldDescription),
|
|
676
|
+
default: clean(f.defaultValue),
|
|
677
|
+
list_values: clean(f.listValues)
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
function objectSummary(o) {
|
|
681
|
+
return {
|
|
682
|
+
object_id: o.objectId,
|
|
683
|
+
name: o.name,
|
|
684
|
+
type: o.type,
|
|
685
|
+
is_selected: o.isSelected
|
|
686
|
+
};
|
|
372
687
|
}
|
|
373
688
|
function registerConnect(program) {
|
|
374
|
-
const cmd = program.command("connect").description("
|
|
689
|
+
const cmd = program.command("connect").description("Create a connection (interactive/agent-resumable), or open the connections page.").argument("[application]", "Application slug to connect").option("--auth <id>", "Authentication method id").option("--name <name>", "Connection name").option("--field <spec>", "Credential field: key=value (repeatable)", collect).option("--object <id>", "Object id to select (repeatable)", collect).option("--no-objects", "Skip object selection").option("--oauth-state <state>", "Resume an OAuth2 sign-in by its state token").option("--connection <id>", "Resume object selection for an existing connection id").option("--no-wait", "Return early instead of waiting for async jobs").option("--timeout <seconds>", "Seconds to wait before timing out").option("--poll-interval <seconds>", "Seconds between polls");
|
|
375
690
|
cmd.addHelpText(
|
|
376
691
|
"after",
|
|
377
|
-
|
|
692
|
+
[
|
|
693
|
+
"",
|
|
694
|
+
"Examples:",
|
|
695
|
+
" engini connect # open the web connections page",
|
|
696
|
+
" engini connect monday # interactive walkthrough (TTY)",
|
|
697
|
+
" engini connect monday --field ApiKey=\u2026 --name 'My Monday'",
|
|
698
|
+
" engini connect monday --json # agent: prints the next step + exit 5",
|
|
699
|
+
" engini connect outlook --oauth-state <state> # resume an OAuth sign-in",
|
|
700
|
+
" engini connect monday --connection 42 --object 5 # resume object selection"
|
|
701
|
+
].join("\n")
|
|
378
702
|
);
|
|
703
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
704
|
+
cmd.action(async (application, opts, command) => {
|
|
705
|
+
await runCommand(
|
|
706
|
+
command,
|
|
707
|
+
opts,
|
|
708
|
+
true,
|
|
709
|
+
() => connectBody(application, opts)
|
|
710
|
+
);
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// src/connections/check.ts
|
|
715
|
+
async function checkBody(connectionId) {
|
|
716
|
+
const id = parseId(connectionId);
|
|
717
|
+
const result = await apiErrors(async () => {
|
|
718
|
+
const client = buildClient();
|
|
719
|
+
return client.connections.check(id);
|
|
720
|
+
});
|
|
721
|
+
const alive = checkAlive(result);
|
|
722
|
+
if (alive === false) {
|
|
723
|
+
fail(1 /* GENERIC */, `Connection ${id} failed its liveness check.`);
|
|
724
|
+
}
|
|
725
|
+
printOutput({ connection_id: id, is_alive: alive, check: result });
|
|
726
|
+
}
|
|
727
|
+
function registerConnectionsCheck(connections) {
|
|
728
|
+
const cmd = connections.command("check").description("Test a connection's liveness.").argument("[connection_id]", "Connection id");
|
|
729
|
+
cmd.addHelpText("after", "\nExamples:\n engini connections check 42");
|
|
379
730
|
addUniversalOptions(cmd);
|
|
380
|
-
cmd.action(async (opts, command) => {
|
|
381
|
-
await runCommand(command, opts, false, () =>
|
|
731
|
+
cmd.action(async (id, opts, command) => {
|
|
732
|
+
await runCommand(command, opts, false, () => checkBody(id));
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// src/connections/create.ts
|
|
737
|
+
function summary(c) {
|
|
738
|
+
return {
|
|
739
|
+
connection_id: c.connectionId,
|
|
740
|
+
connection_name: c.connectionName,
|
|
741
|
+
application_slug: c.applicationSlug,
|
|
742
|
+
is_alive: clean(c.isAlive),
|
|
743
|
+
use_select_db_objects: clean(c.useSelectDBObjects)
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
async function createBody(application, opts) {
|
|
747
|
+
if (!application) fail(2 /* USAGE */, "Missing required argument 'application'.");
|
|
748
|
+
if (!opts.auth) fail(2 /* USAGE */, "Missing required option '--auth'.");
|
|
749
|
+
if (!opts.name) fail(2 /* USAGE */, "Missing required option '--name'.");
|
|
750
|
+
const auth = Number(opts.auth);
|
|
751
|
+
if (!Number.isInteger(auth)) fail(2 /* USAGE */, "--auth must be an integer.");
|
|
752
|
+
const fields = parseFields(opts.field);
|
|
753
|
+
if (dryRun()) {
|
|
754
|
+
printOutput({
|
|
755
|
+
would_create: {
|
|
756
|
+
application_slug: application,
|
|
757
|
+
connection_name: opts.name,
|
|
758
|
+
authentication_id: auth,
|
|
759
|
+
fields: Object.fromEntries(Object.entries(fields).map(([k, v]) => [k, maskSecret(v)])),
|
|
760
|
+
description: opts.description ?? null
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
const conn = await apiErrors(async () => {
|
|
766
|
+
const client = buildClient();
|
|
767
|
+
return client.connections.create(application, opts.name, auth, fields, {
|
|
768
|
+
description: opts.description
|
|
769
|
+
});
|
|
770
|
+
});
|
|
771
|
+
printOutput(summary(conn));
|
|
772
|
+
}
|
|
773
|
+
function registerConnectionsCreate(connections) {
|
|
774
|
+
const cmd = connections.command("create").description("Create a direct-credential connection.").argument("[application]", "Application slug").option("--auth <id>", "Authentication method id").option("--name <name>", "Connection name").option("--field <spec>", "Credential field: key=value (repeatable)", collect).option("--description <text>", "Connection description");
|
|
775
|
+
cmd.addHelpText(
|
|
776
|
+
"after",
|
|
777
|
+
"\nExamples:\n engini connections create slack --auth 2 --name Sales --field token=xoxb-1"
|
|
778
|
+
);
|
|
779
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
780
|
+
cmd.action(async (application, opts, command) => {
|
|
781
|
+
await runCommand(
|
|
782
|
+
command,
|
|
783
|
+
opts,
|
|
784
|
+
true,
|
|
785
|
+
() => createBody(application, opts)
|
|
786
|
+
);
|
|
382
787
|
});
|
|
383
788
|
}
|
|
384
789
|
|
|
@@ -399,7 +804,7 @@ function detail2(c) {
|
|
|
399
804
|
updated_date: clean(c.updatedDate)
|
|
400
805
|
};
|
|
401
806
|
}
|
|
402
|
-
function
|
|
807
|
+
function parseId2(value) {
|
|
403
808
|
if (!value) {
|
|
404
809
|
fail(2 /* USAGE */, "Missing required argument 'connection_id'.");
|
|
405
810
|
}
|
|
@@ -410,7 +815,7 @@ function parseId(value) {
|
|
|
410
815
|
return id;
|
|
411
816
|
}
|
|
412
817
|
async function getBody2(connectionId) {
|
|
413
|
-
const id =
|
|
818
|
+
const id = parseId2(connectionId);
|
|
414
819
|
const connection = await apiErrors(async () => {
|
|
415
820
|
const client = buildClient();
|
|
416
821
|
return client.connections.get(id);
|
|
@@ -457,11 +862,196 @@ function registerConnectionsList(connections) {
|
|
|
457
862
|
});
|
|
458
863
|
}
|
|
459
864
|
|
|
865
|
+
// src/connections/oauth-complete.ts
|
|
866
|
+
function summary2(c) {
|
|
867
|
+
return {
|
|
868
|
+
connection_id: c.connectionId,
|
|
869
|
+
connection_name: c.connectionName,
|
|
870
|
+
application_slug: c.applicationSlug,
|
|
871
|
+
is_alive: clean(c.isAlive),
|
|
872
|
+
use_select_db_objects: clean(c.useSelectDBObjects)
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
async function oauthCompleteBody(application, opts) {
|
|
876
|
+
if (!application) fail(2 /* USAGE */, "Missing required argument 'application'.");
|
|
877
|
+
if (!opts.auth) fail(2 /* USAGE */, "Missing required option '--auth'.");
|
|
878
|
+
if (!opts.state) fail(2 /* USAGE */, "Missing required option '--state'.");
|
|
879
|
+
const auth = Number(opts.auth);
|
|
880
|
+
if (!Number.isInteger(auth)) fail(2 /* USAGE */, "--auth must be an integer.");
|
|
881
|
+
const name = opts.name ?? `${application} connection`;
|
|
882
|
+
if (dryRun()) {
|
|
883
|
+
printOutput({ would_complete: { application, authentication_id: auth, state: opts.state } });
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
const conn = await apiErrors(async () => {
|
|
887
|
+
const client = buildClient();
|
|
888
|
+
const token = await pollAccessToken(client, opts.state, {
|
|
889
|
+
timeout: Number(opts.timeout ?? 300),
|
|
890
|
+
interval: Number(opts.pollInterval ?? 2)
|
|
891
|
+
});
|
|
892
|
+
progress(`Creating connection '${name}'\u2026`);
|
|
893
|
+
return client.connections.create(application, name, auth, oauthFields(token));
|
|
894
|
+
});
|
|
895
|
+
printOutput(summary2(conn));
|
|
896
|
+
}
|
|
897
|
+
function registerConnectionsOauthComplete(connections) {
|
|
898
|
+
const cmd = connections.command("oauth-complete").description("Finish an OAuth2 sign-in and create the connection.").argument("[application]", "Application slug").option("--auth <id>", "Authentication method id").option("--state <state>", "State token from `sign-in-url`").option("--name <name>", "Connection name").option("--timeout <seconds>", "Seconds to wait before timing out").option("--poll-interval <seconds>", "Seconds between polls");
|
|
899
|
+
cmd.addHelpText(
|
|
900
|
+
"after",
|
|
901
|
+
"\nExamples:\n engini connections oauth-complete outlook --auth 0 --state <state>"
|
|
902
|
+
);
|
|
903
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
904
|
+
cmd.action(
|
|
905
|
+
async (application, opts, command) => {
|
|
906
|
+
await runCommand(
|
|
907
|
+
command,
|
|
908
|
+
opts,
|
|
909
|
+
true,
|
|
910
|
+
() => oauthCompleteBody(application, opts)
|
|
911
|
+
);
|
|
912
|
+
}
|
|
913
|
+
);
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
// src/connections/objects.ts
|
|
917
|
+
function summary3(o) {
|
|
918
|
+
return {
|
|
919
|
+
object_id: o.objectId,
|
|
920
|
+
name: o.name,
|
|
921
|
+
type: o.type,
|
|
922
|
+
is_selected: o.isSelected
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
async function objectsBody(connectionId, opts) {
|
|
926
|
+
const id = parseId(connectionId);
|
|
927
|
+
const objs = await apiErrors(async () => {
|
|
928
|
+
const client = buildClient();
|
|
929
|
+
return client.connections.objects(id, { name: opts.name });
|
|
930
|
+
});
|
|
931
|
+
printOutput(objs.map(summary3));
|
|
932
|
+
}
|
|
933
|
+
function registerConnectionsObjects(connections) {
|
|
934
|
+
const cmd = connections.command("objects").description("List the objects a connection exposes.").argument("[connection_id]", "Connection id").option("--name <filter>", "Filter objects by name");
|
|
935
|
+
cmd.addHelpText("after", "\nExamples:\n engini connections objects 42 --name leads");
|
|
936
|
+
addUniversalOptions(cmd);
|
|
937
|
+
cmd.action(async (id, opts, command) => {
|
|
938
|
+
await runCommand(command, opts, false, () => objectsBody(id, opts));
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// src/connections/refresh.ts
|
|
943
|
+
async function refreshBody(connectionId, opts) {
|
|
944
|
+
const id = parseId(connectionId);
|
|
945
|
+
if (dryRun()) {
|
|
946
|
+
printOutput({ would_refresh: { connection_id: id } });
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
const status = await apiErrors(async () => {
|
|
950
|
+
const client = buildClient();
|
|
951
|
+
await client.connections.refresh(id);
|
|
952
|
+
return pollRefresh(client, id, {
|
|
953
|
+
wait: opts.wait !== false,
|
|
954
|
+
timeout: Number(opts.timeout ?? 300),
|
|
955
|
+
interval: Number(opts.pollInterval ?? 2)
|
|
956
|
+
});
|
|
957
|
+
});
|
|
958
|
+
printOutput({ connection_id: id, status });
|
|
959
|
+
}
|
|
960
|
+
function registerConnectionsRefresh(connections) {
|
|
961
|
+
const cmd = connections.command("refresh").description("Refresh a connection's objects (async).").argument("[connection_id]", "Connection id").option("--no-wait", "Return immediately instead of waiting for the refresh").option("--timeout <seconds>", "Seconds to wait before timing out").option("--poll-interval <seconds>", "Seconds between status polls");
|
|
962
|
+
cmd.addHelpText(
|
|
963
|
+
"after",
|
|
964
|
+
"\nExamples:\n engini connections refresh 42\n engini connections refresh 42 --no-wait"
|
|
965
|
+
);
|
|
966
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
967
|
+
cmd.action(async (id, opts, command) => {
|
|
968
|
+
await runCommand(command, opts, true, () => refreshBody(id, opts));
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
// src/connections/select-objects.ts
|
|
973
|
+
async function selectBody(connectionId, opts) {
|
|
974
|
+
const id = parseId(connectionId);
|
|
975
|
+
const objectIds = (opts.object ?? []).map((value) => {
|
|
976
|
+
const n = Number(value);
|
|
977
|
+
if (!Number.isInteger(n)) fail(2 /* USAGE */, `--object must be an integer, got '${value}'.`);
|
|
978
|
+
return n;
|
|
979
|
+
});
|
|
980
|
+
if (objectIds.length === 0) fail(2 /* USAGE */, "Pass at least one --object <id>.");
|
|
981
|
+
if (dryRun()) {
|
|
982
|
+
printOutput({ would_select: { connection_id: id, object_ids: objectIds } });
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
const status = await apiErrors(async () => {
|
|
986
|
+
const client = buildClient();
|
|
987
|
+
await client.connections.selectObjects(id, objectIds);
|
|
988
|
+
return pollRefresh(client, id, {
|
|
989
|
+
wait: opts.wait !== false,
|
|
990
|
+
timeout: Number(opts.timeout ?? 300),
|
|
991
|
+
interval: Number(opts.pollInterval ?? 2)
|
|
992
|
+
});
|
|
993
|
+
});
|
|
994
|
+
printOutput({
|
|
995
|
+
connection_id: id,
|
|
996
|
+
objects_selected: objectIds.length,
|
|
997
|
+
status
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
function registerConnectionsSelectObjects(connections) {
|
|
1001
|
+
const cmd = connections.command("select-objects").description("Choose which objects a connection syncs (async).").argument("[connection_id]", "Connection id").option("--object <id>", "Object id to select (repeatable)", collect).option("--no-wait", "Return immediately instead of waiting for the refresh").option("--timeout <seconds>", "Seconds to wait before timing out").option("--poll-interval <seconds>", "Seconds between status polls");
|
|
1002
|
+
cmd.addHelpText(
|
|
1003
|
+
"after",
|
|
1004
|
+
"\nExamples:\n engini connections select-objects 42 --object 5 --object 9"
|
|
1005
|
+
);
|
|
1006
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
1007
|
+
cmd.action(async (id, opts, command) => {
|
|
1008
|
+
await runCommand(command, opts, true, () => selectBody(id, opts));
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
// src/connections/sign-in-url.ts
|
|
1013
|
+
async function signInUrlBody(application, opts) {
|
|
1014
|
+
if (!application) fail(2 /* USAGE */, "Missing required argument 'application'.");
|
|
1015
|
+
if (!opts.auth) fail(2 /* USAGE */, "Missing required option '--auth'.");
|
|
1016
|
+
const auth = Number(opts.auth);
|
|
1017
|
+
if (!Number.isInteger(auth)) fail(2 /* USAGE */, "--auth must be an integer.");
|
|
1018
|
+
const fields = opts.field ? parseFields(opts.field) : void 0;
|
|
1019
|
+
const resp = await apiErrors(async () => {
|
|
1020
|
+
const client = buildClient();
|
|
1021
|
+
return client.connections.getSignInUrl(application, auth, { fields });
|
|
1022
|
+
});
|
|
1023
|
+
printOutput({
|
|
1024
|
+
sign_in_url: resp.signInUrl,
|
|
1025
|
+
state: resp.state,
|
|
1026
|
+
resume: `engini connections oauth-complete ${application} --auth ${auth} --state ${resp.state}`
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
function registerConnectionsSignInUrl(connections) {
|
|
1030
|
+
const cmd = connections.command("sign-in-url").description("Start an OAuth2 sign-in (returns the URL + state).").argument("[application]", "Application slug").option("--auth <id>", "Authentication method id").option("--field <spec>", "Pre-sign-in field: key=value (repeatable)", collect);
|
|
1031
|
+
cmd.addHelpText("after", "\nExamples:\n engini connections sign-in-url outlook --auth 0");
|
|
1032
|
+
addUniversalOptions(cmd);
|
|
1033
|
+
cmd.action(async (application, opts, command) => {
|
|
1034
|
+
await runCommand(
|
|
1035
|
+
command,
|
|
1036
|
+
opts,
|
|
1037
|
+
false,
|
|
1038
|
+
() => signInUrlBody(application, opts)
|
|
1039
|
+
);
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
|
|
460
1043
|
// src/connections/index.ts
|
|
461
1044
|
function registerConnections(program) {
|
|
462
|
-
const connections = program.command("connections").description("List, inspect, and remove connections.");
|
|
1045
|
+
const connections = program.command("connections").description("List, inspect, create, and remove connections.");
|
|
463
1046
|
registerConnectionsList(connections);
|
|
464
1047
|
registerConnectionsGet(connections);
|
|
1048
|
+
registerConnectionsCreate(connections);
|
|
1049
|
+
registerConnectionsCheck(connections);
|
|
1050
|
+
registerConnectionsRefresh(connections);
|
|
1051
|
+
registerConnectionsObjects(connections);
|
|
1052
|
+
registerConnectionsSelectObjects(connections);
|
|
1053
|
+
registerConnectionsSignInUrl(connections);
|
|
1054
|
+
registerConnectionsOauthComplete(connections);
|
|
465
1055
|
const del = connections.command("delete").description("Remove a connection.").argument("[connection_id]", "Connection id");
|
|
466
1056
|
addUniversalOptions(del, { mutating: true });
|
|
467
1057
|
del.action(async (_id, opts, command) => {
|
|
@@ -503,9 +1093,13 @@ CORE COMMANDS
|
|
|
503
1093
|
Discover available tools (one concise summary per tool).
|
|
504
1094
|
tools get <tool_id>
|
|
505
1095
|
Full input/output schema + capability flags for one tool.
|
|
506
|
-
tools call <tool_id> --args <json|@file|-> [--file <field=@path>] [--connection <id>] [--raw] [--llm <vendor>]
|
|
1096
|
+
tools call <tool_id> --args <json|@file|-> [--file <field=@path>] [--connection <id>] [--raw] [--llm <vendor>] [--inline]
|
|
507
1097
|
Execute a tool against a connection. Attach files with --file (repeat for a
|
|
508
|
-
list). Validate first with --dry-run.
|
|
1098
|
+
list). Validate first with --dry-run. A large result spills to a local
|
|
1099
|
+
handle (use --inline / --max-bytes <n> to control this).
|
|
1100
|
+
tools result <handle> [--select <path>] [--fields <a,b>] [--offset <n>] [--limit <m>] [--full] [--list] [--clear]
|
|
1101
|
+
Drill into a stored tools call result: extract a dot-path, project fields,
|
|
1102
|
+
or page a list \u2014 paying tokens only for what you pull.
|
|
509
1103
|
applications list [--search <q>] [--available] [--limit <n>]
|
|
510
1104
|
Browse connector apps (slug, categories, tool counts).
|
|
511
1105
|
applications get <slug>
|
|
@@ -519,10 +1113,22 @@ ACCOUNT
|
|
|
519
1113
|
whoami Show the authenticated user/company.
|
|
520
1114
|
|
|
521
1115
|
CONNECTIONS
|
|
1116
|
+
connect [<app>] Create a connection \u2014 interactive on a TTY, or
|
|
1117
|
+
agent-resumable when piped (prints {need, resume}).
|
|
1118
|
+
Resume with --oauth-state <state> (OAuth) or
|
|
1119
|
+
--connection <id> (object selection). No app \u2192 web page.
|
|
522
1120
|
connections list [--application <slug>] List your connections.
|
|
523
1121
|
connections get <id> Inspect a connection.
|
|
1122
|
+
connections create <app> --auth <id> --name <n> --field k=v
|
|
1123
|
+
Create a direct-credential connection.
|
|
1124
|
+
connections sign-in-url <app> --auth <id> Start an OAuth2 sign-in (returns URL + state).
|
|
1125
|
+
connections oauth-complete <app> --auth <id> --state <state>
|
|
1126
|
+
Finish an OAuth2 sign-in and create the connection.
|
|
1127
|
+
connections check <id> Test a connection's liveness.
|
|
1128
|
+
connections refresh <id> [--no-wait] Refresh a connection's objects (async).
|
|
1129
|
+
connections objects <id> List the objects a connection exposes.
|
|
1130
|
+
connections select-objects <id> --object <id> Choose which objects to sync (async).
|
|
524
1131
|
connections delete <id> Remove a connection. (coming soon)
|
|
525
|
-
connect Open the Engini connections page in your browser.
|
|
526
1132
|
|
|
527
1133
|
OUTPUT & EXIT CODES
|
|
528
1134
|
Output adapts to context: human-readable on a TTY, compact JSON when piped, pretty
|
|
@@ -564,6 +1170,11 @@ EXAMPLES
|
|
|
564
1170
|
# Provider-shaped result for an agent loop
|
|
565
1171
|
engini tools call monday_create_item --args '{}' --llm openai --tool-call-id call_1
|
|
566
1172
|
|
|
1173
|
+
# Large result -> handle; drill in without paying for the whole payload
|
|
1174
|
+
engini tools call list_rows --args '{}' # prints {handle, shape, preview, \u2026}
|
|
1175
|
+
engini tools result <handle> --select items.email
|
|
1176
|
+
engini tools result <handle> --fields id,name --offset 20 --limit 10
|
|
1177
|
+
|
|
567
1178
|
# Machine-readable arg schema (for agents)
|
|
568
1179
|
engini tools call --schema
|
|
569
1180
|
|
|
@@ -589,7 +1200,15 @@ var EXAMPLES = {
|
|
|
589
1200
|
engini tools call monday_create_item --args @item.json --connection 3
|
|
590
1201
|
echo '{"name":"x"}' | engini tools call monday_create_item --args -
|
|
591
1202
|
engini tools call gmail_send_mail --args '{}' --file attachmentsarray=@report.pdf
|
|
592
|
-
engini tools call monday_create_item --args '{}' --llm openai --tool-call-id call_1
|
|
1203
|
+
engini tools call monday_create_item --args '{}' --llm openai --tool-call-id call_1
|
|
1204
|
+
engini tools call list_rows --args '{}' # large result -> handle; then: engini tools result <handle>`,
|
|
1205
|
+
"tools result": `Examples:
|
|
1206
|
+
engini tools result h42 # shape + preview
|
|
1207
|
+
engini tools result h42 --select items.email # one dot-path (maps over a list)
|
|
1208
|
+
engini tools result h42 --fields id,name # project keys per item
|
|
1209
|
+
engini tools result h42 --select items --offset 20 --limit 10
|
|
1210
|
+
engini tools result --list # known handles
|
|
1211
|
+
engini tools result --clear # wipe the sandbox`,
|
|
593
1212
|
"applications list": `Examples:
|
|
594
1213
|
engini applications list --available --limit 10
|
|
595
1214
|
engini applications list --search crm --json
|
|
@@ -617,6 +1236,7 @@ function installHelp(program) {
|
|
|
617
1236
|
addExamples(sub("list"), EXAMPLES["tools list"]);
|
|
618
1237
|
addExamples(sub("get"), EXAMPLES["tools get"]);
|
|
619
1238
|
addExamples(sub("call"), EXAMPLES["tools call"]);
|
|
1239
|
+
addExamples(sub("result"), EXAMPLES["tools result"]);
|
|
620
1240
|
}
|
|
621
1241
|
const applications = find("applications");
|
|
622
1242
|
if (applications) {
|
|
@@ -649,20 +1269,20 @@ async function loginBody(opts) {
|
|
|
649
1269
|
}
|
|
650
1270
|
config.api_key = apiKey;
|
|
651
1271
|
config.auth_kind = "api-key";
|
|
652
|
-
const
|
|
1272
|
+
const summary5 = {
|
|
653
1273
|
auth_kind: "api-key",
|
|
654
1274
|
credential: maskSecret(apiKey),
|
|
655
1275
|
api_url: config.api_url
|
|
656
1276
|
};
|
|
657
1277
|
if (dryRun()) {
|
|
658
|
-
printOutput({ would_store:
|
|
1278
|
+
printOutput({ would_store: summary5 });
|
|
659
1279
|
return;
|
|
660
1280
|
}
|
|
661
1281
|
if (hadCredentials) {
|
|
662
1282
|
await confirmOrFail("Credentials already exist. Overwrite?", { force: Boolean(opts.force) });
|
|
663
1283
|
}
|
|
664
1284
|
saveConfig(config);
|
|
665
|
-
printOutput({ stored:
|
|
1285
|
+
printOutput({ stored: summary5 });
|
|
666
1286
|
}
|
|
667
1287
|
function registerLogin(program) {
|
|
668
1288
|
const cmd = program.command("login").description("Store an opaque Engini API key.").option("--api-key <key>", "Opaque Engini key (eng_\u2026)").option("--api-url <url>", "API base URL to persist (e.g. a staging host)").option("--identity-url <url>", "Dashboard base URL to persist (hosts the keys page)").option("--force", "Overwrite existing credentials without confirming");
|
|
@@ -699,19 +1319,254 @@ function registerLogout(program) {
|
|
|
699
1319
|
}
|
|
700
1320
|
|
|
701
1321
|
// src/tools/call.ts
|
|
702
|
-
import { readFileSync as
|
|
1322
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
703
1323
|
import {
|
|
704
1324
|
AnthropicProvider,
|
|
705
1325
|
File,
|
|
706
1326
|
OpenAIProvider
|
|
707
1327
|
} from "@engini/sdk";
|
|
1328
|
+
|
|
1329
|
+
// src/results.ts
|
|
1330
|
+
import { randomBytes } from "crypto";
|
|
1331
|
+
import {
|
|
1332
|
+
existsSync as existsSync2,
|
|
1333
|
+
mkdirSync as mkdirSync2,
|
|
1334
|
+
readFileSync as readFileSync2,
|
|
1335
|
+
readdirSync,
|
|
1336
|
+
rmSync,
|
|
1337
|
+
statSync,
|
|
1338
|
+
writeFileSync as writeFileSync2
|
|
1339
|
+
} from "fs";
|
|
1340
|
+
import { homedir as homedir2 } from "os";
|
|
1341
|
+
import { join as join2 } from "path";
|
|
1342
|
+
var MAX_RESULTS = 20;
|
|
1343
|
+
var TTL_SECONDS = 24 * 60 * 60;
|
|
1344
|
+
var PREVIEW_BYTES = 512;
|
|
1345
|
+
function cacheDir() {
|
|
1346
|
+
const base = process.platform === "win32" ? process.env.APPDATA ?? homedir2() : process.env.XDG_CACHE_HOME ?? join2(homedir2(), ".cache");
|
|
1347
|
+
return join2(base, "engini", "results");
|
|
1348
|
+
}
|
|
1349
|
+
function serialize(value) {
|
|
1350
|
+
return JSON.stringify(value ?? null);
|
|
1351
|
+
}
|
|
1352
|
+
function byteLength(value) {
|
|
1353
|
+
return Buffer.byteLength(serialize(value), "utf8");
|
|
1354
|
+
}
|
|
1355
|
+
function jsonFiles(dir) {
|
|
1356
|
+
if (!existsSync2(dir)) return [];
|
|
1357
|
+
return readdirSync(dir).filter((name) => name.endsWith(".json"));
|
|
1358
|
+
}
|
|
1359
|
+
function storeResult(output, historyId) {
|
|
1360
|
+
const handle = historyId !== null ? `h${historyId}` : `r${randomBytes(6).toString("hex")}`;
|
|
1361
|
+
const dir = cacheDir();
|
|
1362
|
+
mkdirSync2(dir, { recursive: true, mode: 448 });
|
|
1363
|
+
const dataSize = byteLength(output);
|
|
1364
|
+
const payload = {
|
|
1365
|
+
output: output ?? null,
|
|
1366
|
+
history_id: historyId,
|
|
1367
|
+
data_size: dataSize,
|
|
1368
|
+
created: Math.floor(Date.now() / 1e3)
|
|
1369
|
+
};
|
|
1370
|
+
writeFileSync2(join2(dir, `${handle}.json`), JSON.stringify(payload), { mode: 384 });
|
|
1371
|
+
prune();
|
|
1372
|
+
return { handle, dataSize };
|
|
1373
|
+
}
|
|
1374
|
+
function loadResult(handle) {
|
|
1375
|
+
const path = join2(cacheDir(), `${handle}.json`);
|
|
1376
|
+
if (!existsSync2(path)) return null;
|
|
1377
|
+
try {
|
|
1378
|
+
const data = JSON.parse(readFileSync2(path, "utf8"));
|
|
1379
|
+
return data && typeof data === "object" ? data : null;
|
|
1380
|
+
} catch {
|
|
1381
|
+
return null;
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
function listResults() {
|
|
1385
|
+
const dir = cacheDir();
|
|
1386
|
+
const now = Date.now();
|
|
1387
|
+
const rows = [];
|
|
1388
|
+
for (const name of jsonFiles(dir)) {
|
|
1389
|
+
const handle = name.slice(0, -".json".length);
|
|
1390
|
+
let mtimeMs;
|
|
1391
|
+
try {
|
|
1392
|
+
mtimeMs = statSync(join2(dir, name)).mtimeMs;
|
|
1393
|
+
} catch {
|
|
1394
|
+
continue;
|
|
1395
|
+
}
|
|
1396
|
+
const data = loadResult(handle);
|
|
1397
|
+
rows.push({
|
|
1398
|
+
mtime: mtimeMs,
|
|
1399
|
+
row: {
|
|
1400
|
+
handle,
|
|
1401
|
+
history_id: data?.history_id ?? null,
|
|
1402
|
+
data_size: data?.data_size ?? null,
|
|
1403
|
+
age_seconds: Math.floor((now - mtimeMs) / 1e3)
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
rows.sort((a, b) => b.mtime - a.mtime);
|
|
1408
|
+
return rows.map((r) => r.row);
|
|
1409
|
+
}
|
|
1410
|
+
function clearResults() {
|
|
1411
|
+
const dir = cacheDir();
|
|
1412
|
+
let count = 0;
|
|
1413
|
+
for (const name of jsonFiles(dir)) {
|
|
1414
|
+
rmSync(join2(dir, name), { force: true });
|
|
1415
|
+
count += 1;
|
|
1416
|
+
}
|
|
1417
|
+
return count;
|
|
1418
|
+
}
|
|
1419
|
+
function prune() {
|
|
1420
|
+
const dir = cacheDir();
|
|
1421
|
+
if (!existsSync2(dir)) return;
|
|
1422
|
+
const now = Date.now();
|
|
1423
|
+
const entries = [];
|
|
1424
|
+
for (const name of jsonFiles(dir)) {
|
|
1425
|
+
const path = join2(dir, name);
|
|
1426
|
+
try {
|
|
1427
|
+
entries.push({ path, mtime: statSync(path).mtimeMs });
|
|
1428
|
+
} catch {
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
entries.sort((a, b) => b.mtime - a.mtime);
|
|
1432
|
+
const survivors = [];
|
|
1433
|
+
for (const { path, mtime } of entries) {
|
|
1434
|
+
if (now - mtime > TTL_SECONDS * 1e3) rmSync(path, { force: true });
|
|
1435
|
+
else survivors.push(path);
|
|
1436
|
+
}
|
|
1437
|
+
for (const path of survivors.slice(MAX_RESULTS)) rmSync(path, { force: true });
|
|
1438
|
+
}
|
|
1439
|
+
function typeName(value) {
|
|
1440
|
+
if (value === null || value === void 0) return "null";
|
|
1441
|
+
if (Array.isArray(value)) return "array";
|
|
1442
|
+
switch (typeof value) {
|
|
1443
|
+
case "boolean":
|
|
1444
|
+
return "boolean";
|
|
1445
|
+
case "number":
|
|
1446
|
+
return "number";
|
|
1447
|
+
case "string":
|
|
1448
|
+
return "string";
|
|
1449
|
+
case "object":
|
|
1450
|
+
return "object";
|
|
1451
|
+
default:
|
|
1452
|
+
return "string";
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
function inferShape(value) {
|
|
1456
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
1457
|
+
const keys = {};
|
|
1458
|
+
for (const [k, v] of Object.entries(value)) keys[k] = typeName(v);
|
|
1459
|
+
return { type: "object", keys };
|
|
1460
|
+
}
|
|
1461
|
+
if (Array.isArray(value)) {
|
|
1462
|
+
const shape = { type: "array", length: value.length };
|
|
1463
|
+
if (value.length > 0) {
|
|
1464
|
+
const first = typeName(value[0]);
|
|
1465
|
+
const homogeneous = value.every((item) => typeName(item) === first);
|
|
1466
|
+
shape.item_shape = homogeneous ? inferShape(value[0]) : "mixed";
|
|
1467
|
+
}
|
|
1468
|
+
return shape;
|
|
1469
|
+
}
|
|
1470
|
+
return typeName(value);
|
|
1471
|
+
}
|
|
1472
|
+
function makePreview(value) {
|
|
1473
|
+
const candidate = Array.isArray(value) ? value.length > 0 ? value[0] : null : value;
|
|
1474
|
+
if (byteLength(candidate) <= PREVIEW_BYTES) return candidate ?? null;
|
|
1475
|
+
if (typeof candidate === "string") return `${candidate.slice(0, PREVIEW_BYTES)}\u2026`;
|
|
1476
|
+
return { _truncated: true, _note: "preview omitted; use --select/--fields" };
|
|
1477
|
+
}
|
|
1478
|
+
function hint(handle) {
|
|
1479
|
+
return `Full result stored. Pull data with: engini tools result ${handle} --select <path> | --fields a,b | --offset N --limit M`;
|
|
1480
|
+
}
|
|
1481
|
+
function buildEnvelope(handle, historyId, dataSize, output) {
|
|
1482
|
+
return {
|
|
1483
|
+
handle,
|
|
1484
|
+
history_id: historyId,
|
|
1485
|
+
data_size: dataSize,
|
|
1486
|
+
shape: inferShape(output),
|
|
1487
|
+
preview: makePreview(output),
|
|
1488
|
+
hint: hint(handle)
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
function parsePath(path) {
|
|
1492
|
+
const atoms = [];
|
|
1493
|
+
let token = "";
|
|
1494
|
+
let i = 0;
|
|
1495
|
+
while (i < path.length) {
|
|
1496
|
+
const ch = path[i];
|
|
1497
|
+
if (ch === ".") {
|
|
1498
|
+
if (token) {
|
|
1499
|
+
atoms.push({ kind: "key", value: token });
|
|
1500
|
+
token = "";
|
|
1501
|
+
}
|
|
1502
|
+
i += 1;
|
|
1503
|
+
} else if (ch === "[") {
|
|
1504
|
+
if (token) {
|
|
1505
|
+
atoms.push({ kind: "key", value: token });
|
|
1506
|
+
token = "";
|
|
1507
|
+
}
|
|
1508
|
+
const j = path.indexOf("]", i);
|
|
1509
|
+
if (j === -1) break;
|
|
1510
|
+
const digits = path.slice(i + 1, j);
|
|
1511
|
+
if (/^\d+$/.test(digits)) atoms.push({ kind: "index", value: Number(digits) });
|
|
1512
|
+
i = j + 1;
|
|
1513
|
+
} else {
|
|
1514
|
+
token += ch;
|
|
1515
|
+
i += 1;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
if (token) atoms.push({ kind: "key", value: token });
|
|
1519
|
+
return atoms;
|
|
1520
|
+
}
|
|
1521
|
+
function step(cur, atom) {
|
|
1522
|
+
if (atom.kind === "index") {
|
|
1523
|
+
if (Array.isArray(cur) && atom.value >= 0 && atom.value < cur.length) return cur[atom.value];
|
|
1524
|
+
return null;
|
|
1525
|
+
}
|
|
1526
|
+
if (Array.isArray(cur)) return cur.map((item) => step(item, atom));
|
|
1527
|
+
if (cur !== null && typeof cur === "object") {
|
|
1528
|
+
const value = cur[atom.value];
|
|
1529
|
+
return value === void 0 ? null : value;
|
|
1530
|
+
}
|
|
1531
|
+
return null;
|
|
1532
|
+
}
|
|
1533
|
+
function selectPath(value, path) {
|
|
1534
|
+
let cur = value;
|
|
1535
|
+
for (const atom of parsePath(path)) {
|
|
1536
|
+
cur = step(cur, atom);
|
|
1537
|
+
if (cur === null) return null;
|
|
1538
|
+
}
|
|
1539
|
+
return cur;
|
|
1540
|
+
}
|
|
1541
|
+
function pick(obj, fields) {
|
|
1542
|
+
const out = {};
|
|
1543
|
+
for (const k of fields) if (k in obj) out[k] = obj[k];
|
|
1544
|
+
return out;
|
|
1545
|
+
}
|
|
1546
|
+
function projectFields(value, fields) {
|
|
1547
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
1548
|
+
return pick(value, fields);
|
|
1549
|
+
}
|
|
1550
|
+
if (Array.isArray(value)) {
|
|
1551
|
+
return value.map(
|
|
1552
|
+
(item) => item !== null && typeof item === "object" && !Array.isArray(item) ? pick(item, fields) : null
|
|
1553
|
+
);
|
|
1554
|
+
}
|
|
1555
|
+
return null;
|
|
1556
|
+
}
|
|
1557
|
+
function paginate(value, offset, limit) {
|
|
1558
|
+
const sliced = value.slice(offset);
|
|
1559
|
+
return limit !== null ? sliced.slice(0, limit) : sliced;
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
// src/tools/call.ts
|
|
708
1563
|
function loadArgs(spec) {
|
|
709
1564
|
let text;
|
|
710
1565
|
if (spec === "-") {
|
|
711
|
-
text =
|
|
1566
|
+
text = readFileSync3(0, "utf8");
|
|
712
1567
|
} else if (spec.startsWith("@")) {
|
|
713
1568
|
try {
|
|
714
|
-
text =
|
|
1569
|
+
text = readFileSync3(spec.slice(1), "utf8");
|
|
715
1570
|
} catch (err) {
|
|
716
1571
|
return fail(2 /* USAGE */, `Cannot read ${spec.slice(1)}: ${err.message}`);
|
|
717
1572
|
}
|
|
@@ -788,8 +1643,15 @@ function renderResult(result, opts) {
|
|
|
788
1643
|
const call = { id: opts.toolCallId ?? opts.toolId, name: opts.toolId, arguments: {} };
|
|
789
1644
|
return provider.formatToolResult(call, { output: result.output });
|
|
790
1645
|
}
|
|
1646
|
+
const output = result.output;
|
|
1647
|
+
const size = Buffer.byteLength(serialize(output), "utf8");
|
|
1648
|
+
const historyId = result.historyId ?? null;
|
|
1649
|
+
if (!opts.inline && opts.maxBytes > 0 && size > opts.maxBytes) {
|
|
1650
|
+
const stored = storeResult(output, historyId);
|
|
1651
|
+
return buildEnvelope(stored.handle, historyId, stored.dataSize, output);
|
|
1652
|
+
}
|
|
791
1653
|
return {
|
|
792
|
-
output
|
|
1654
|
+
output,
|
|
793
1655
|
history_id: result.historyId,
|
|
794
1656
|
execution_info: result.executionInfo
|
|
795
1657
|
};
|
|
@@ -801,8 +1663,18 @@ async function callBody(toolId, opts) {
|
|
|
801
1663
|
if (opts.args === void 0) {
|
|
802
1664
|
fail(2 /* USAGE */, "Missing required option --args.");
|
|
803
1665
|
}
|
|
804
|
-
|
|
805
|
-
|
|
1666
|
+
const modes = [
|
|
1667
|
+
["--raw", Boolean(opts.raw)],
|
|
1668
|
+
["--llm", Boolean(opts.llm)],
|
|
1669
|
+
["--inline", Boolean(opts.inline)]
|
|
1670
|
+
];
|
|
1671
|
+
const explicit = modes.filter(([, on]) => on).map(([name]) => name);
|
|
1672
|
+
if (explicit.length > 1) {
|
|
1673
|
+
fail(2 /* USAGE */, `Pass only one of ${explicit.join(", ")}.`);
|
|
1674
|
+
}
|
|
1675
|
+
const maxBytes = opts.maxBytes === void 0 ? 4096 : Number(opts.maxBytes);
|
|
1676
|
+
if (!Number.isFinite(maxBytes) || maxBytes < 0) {
|
|
1677
|
+
fail(2 /* USAGE */, "--max-bytes must be a non-negative integer.");
|
|
806
1678
|
}
|
|
807
1679
|
const args = loadArgs(opts.args);
|
|
808
1680
|
Object.assign(args, loadFiles(opts.file));
|
|
@@ -830,7 +1702,9 @@ async function callBody(toolId, opts) {
|
|
|
830
1702
|
raw: opts.raw,
|
|
831
1703
|
llm: opts.llm,
|
|
832
1704
|
toolId,
|
|
833
|
-
toolCallId: opts.toolCallId
|
|
1705
|
+
toolCallId: opts.toolCallId,
|
|
1706
|
+
maxBytes,
|
|
1707
|
+
inline: opts.inline
|
|
834
1708
|
})
|
|
835
1709
|
);
|
|
836
1710
|
}
|
|
@@ -839,7 +1713,7 @@ function registerToolsCall(tools) {
|
|
|
839
1713
|
"--file <spec>",
|
|
840
1714
|
"Attach a file: field=@path (repeat the same field for a list of files)",
|
|
841
1715
|
collectFile
|
|
842
|
-
).option("--connection <id>", "Connection id to run against").option("--toolset <id>", "Toolset id to resolve the connection").option("--raw", "Emit the tool output verbatim (no envelope)").option("--llm <vendor>", "Provider-shaped result: openai|anthropic").option("--tool-call-id <id>", "Correlation id for --llm output");
|
|
1716
|
+
).option("--connection <id>", "Connection id to run against").option("--toolset <id>", "Toolset id to resolve the connection").option("--raw", "Emit the tool output verbatim (no envelope)").option("--llm <vendor>", "Provider-shaped result: openai|anthropic").option("--tool-call-id <id>", "Correlation id for --llm output").option("--max-bytes <n>", "Spill default-mode results larger than N bytes (0 = never)").option("--inline", "Force the full inline result, bypassing the sandbox");
|
|
843
1717
|
addUniversalOptions(cmd, { mutating: true });
|
|
844
1718
|
cmd.action(async (toolId, opts, command) => {
|
|
845
1719
|
await runCommand(command, opts, true, () => callBody(toolId, opts));
|
|
@@ -930,16 +1804,87 @@ function registerToolsList(tools) {
|
|
|
930
1804
|
});
|
|
931
1805
|
}
|
|
932
1806
|
|
|
1807
|
+
// src/tools/result.ts
|
|
1808
|
+
function collectSelect(value, previous = []) {
|
|
1809
|
+
return [...previous, value];
|
|
1810
|
+
}
|
|
1811
|
+
function resultBody(handle, opts) {
|
|
1812
|
+
if (opts.list) {
|
|
1813
|
+
printOutput(listResults());
|
|
1814
|
+
return;
|
|
1815
|
+
}
|
|
1816
|
+
if (opts.clear) {
|
|
1817
|
+
printOutput({ cleared: clearResults() });
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1820
|
+
if (!handle) {
|
|
1821
|
+
fail(2 /* USAGE */, "Missing required argument 'handle'.", "Pass a handle, or use --list.");
|
|
1822
|
+
}
|
|
1823
|
+
const stored = loadResult(handle);
|
|
1824
|
+
if (stored === null) {
|
|
1825
|
+
fail(
|
|
1826
|
+
4 /* NOT_FOUND */,
|
|
1827
|
+
`No stored result for handle '${handle}'.`,
|
|
1828
|
+
"It may have expired or been pruned; re-run the tool."
|
|
1829
|
+
);
|
|
1830
|
+
}
|
|
1831
|
+
const output = stored.output;
|
|
1832
|
+
if (opts.full) {
|
|
1833
|
+
printOutput(output);
|
|
1834
|
+
return;
|
|
1835
|
+
}
|
|
1836
|
+
const offset = opts.offset === void 0 ? 0 : Number(opts.offset);
|
|
1837
|
+
const limit = opts.limit === void 0 ? null : Number(opts.limit);
|
|
1838
|
+
const select = opts.select ?? [];
|
|
1839
|
+
const paging = offset !== 0 || limit !== null;
|
|
1840
|
+
if (select.length === 0 && opts.fields === void 0 && !paging) {
|
|
1841
|
+
printOutput(buildEnvelope(handle, stored.history_id ?? null, stored.data_size ?? null, output));
|
|
1842
|
+
return;
|
|
1843
|
+
}
|
|
1844
|
+
let value = output;
|
|
1845
|
+
if (select.length === 1) {
|
|
1846
|
+
value = selectPath(value, select[0]);
|
|
1847
|
+
} else if (select.length > 1) {
|
|
1848
|
+
const out = {};
|
|
1849
|
+
for (const path of select) out[path] = selectPath(output, path);
|
|
1850
|
+
value = out;
|
|
1851
|
+
}
|
|
1852
|
+
if (opts.fields !== void 0) {
|
|
1853
|
+
const keys = opts.fields.split(",").map((f) => f.trim()).filter(Boolean);
|
|
1854
|
+
value = projectFields(value, keys);
|
|
1855
|
+
}
|
|
1856
|
+
if (paging) {
|
|
1857
|
+
if (!Array.isArray(value)) {
|
|
1858
|
+
fail(2 /* USAGE */, "--offset/--limit require a list value.", "Use --select to reach a list first.");
|
|
1859
|
+
}
|
|
1860
|
+
value = paginate(value, offset, limit);
|
|
1861
|
+
}
|
|
1862
|
+
printOutput(value);
|
|
1863
|
+
}
|
|
1864
|
+
function registerToolsResult(tools) {
|
|
1865
|
+
const cmd = tools.command("result").description("Drill into a sandboxed tools call result.").argument("[handle]", "Result handle from a prior tools call").option("--select <path>", "Dot-path to extract, e.g. items.email (repeatable)", collectSelect).option("--fields <keys>", "Comma-separated keys to project from object(s)").option("--offset <n>", "Skip N items of a list value").option("--limit <m>", "Return at most M list items").option("--full", "Emit the entire stored payload").option("--list", "List stored result handles").option("--clear", "Delete all stored results");
|
|
1866
|
+
addUniversalOptions(cmd);
|
|
1867
|
+
cmd.action(async (handle, opts, command) => {
|
|
1868
|
+
await runCommand(
|
|
1869
|
+
command,
|
|
1870
|
+
opts,
|
|
1871
|
+
false,
|
|
1872
|
+
() => resultBody(handle, opts)
|
|
1873
|
+
);
|
|
1874
|
+
});
|
|
1875
|
+
}
|
|
1876
|
+
|
|
933
1877
|
// src/tools/index.ts
|
|
934
1878
|
function registerTools(program) {
|
|
935
1879
|
const tools = program.command("tools").description("Discover and execute tools.");
|
|
936
1880
|
registerToolsList(tools);
|
|
937
1881
|
registerToolsGet(tools);
|
|
938
1882
|
registerToolsCall(tools);
|
|
1883
|
+
registerToolsResult(tools);
|
|
939
1884
|
}
|
|
940
1885
|
|
|
941
1886
|
// src/whoami.ts
|
|
942
|
-
function
|
|
1887
|
+
function summary4(me) {
|
|
943
1888
|
return {
|
|
944
1889
|
full_name: clean(me.fullName),
|
|
945
1890
|
email: clean(me.email),
|
|
@@ -953,7 +1898,7 @@ async function whoamiBody() {
|
|
|
953
1898
|
const client = buildClient();
|
|
954
1899
|
return client.auth.whoami();
|
|
955
1900
|
});
|
|
956
|
-
printOutput(
|
|
1901
|
+
printOutput(summary4(me));
|
|
957
1902
|
}
|
|
958
1903
|
function registerWhoami(program) {
|
|
959
1904
|
const cmd = program.command("whoami").description("Report the authenticated user/company.");
|
|
@@ -965,7 +1910,7 @@ function registerWhoami(program) {
|
|
|
965
1910
|
}
|
|
966
1911
|
|
|
967
1912
|
// src/version.ts
|
|
968
|
-
var VERSION = true ? "0.
|
|
1913
|
+
var VERSION = true ? "0.8.0" : "0.0.0";
|
|
969
1914
|
|
|
970
1915
|
// src/main.ts
|
|
971
1916
|
function buildProgram() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@engini/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Engini CLI — machine-first command line over the Engini Public API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"test": "vitest run"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@engini/sdk": "^0.
|
|
24
|
+
"@engini/sdk": "^0.7.0",
|
|
25
25
|
"commander": "^12.1.0",
|
|
26
26
|
"smol-toml": "^1.3.0"
|
|
27
27
|
},
|