@parall/cli 1.47.0 → 1.48.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clip.d.ts","sourceRoot":"","sources":["../../src/commands/clip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"clip.d.ts","sourceRoot":"","sources":["../../src/commands/clip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAgCpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,QA4OpD"}
|
package/dist/commands/clip.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolveCredentials } from '../lib/client.js';
|
|
2
2
|
import { invokeClipAwaitingActivation } from '../lib/clip-invoke.js';
|
|
3
|
-
import {
|
|
3
|
+
import { execEdgeClipAwaitingActivation } from '../lib/edge-exec.js';
|
|
4
|
+
import { printJson, printError, parsePositiveInt } from '../lib/output.js';
|
|
4
5
|
/**
|
|
5
6
|
* Derive a CLI-friendly alias from a registry source string.
|
|
6
7
|
* Handles scoped packages ("@scope/name@1.0.0" → "name") and
|
|
@@ -159,6 +160,66 @@ export function registerClipCommands(program) {
|
|
|
159
160
|
printError(err);
|
|
160
161
|
}
|
|
161
162
|
});
|
|
163
|
+
clip
|
|
164
|
+
.command('exec')
|
|
165
|
+
.description('Execute a registry (Edge) clip command on an Edge device. A cloud (hosted) profile is reachable ONLY via --connection; with neither --connection nor --edge, the server resolves just your OWN online desktop device (legacy BYOC fallback — never a cloud profile)')
|
|
166
|
+
.argument('<clip>', 'Clip name in the org clip registry')
|
|
167
|
+
.argument('<command>', 'Command name to execute')
|
|
168
|
+
.argument('[args]', 'Command arguments (JSON string or plain text)')
|
|
169
|
+
.option('--connection <ref>', 'Clip connection id (ccn_…) or alias. REQUIRED to reach a cloud (hosted) profile — the binding its maintainer created is the authorization')
|
|
170
|
+
.option('--edge <edgeId>', 'A desktop (BYOC) device you own. Mutually exclusive with --connection')
|
|
171
|
+
.option('--profile <name>', 'Browser profile (with --connection it may only restate the granted one)')
|
|
172
|
+
.option('--timeout <ms>', 'Execution timeout in milliseconds', '30000')
|
|
173
|
+
.action(async (clipName, command, args, opts) => {
|
|
174
|
+
try {
|
|
175
|
+
const { client, orgId } = resolveCredentials();
|
|
176
|
+
let parsedArgs;
|
|
177
|
+
if (args !== undefined) {
|
|
178
|
+
try {
|
|
179
|
+
parsedArgs = JSON.parse(args);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
parsedArgs = args;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// Strict grammar, validated BEFORE the wire: parseInt would accept
|
|
186
|
+
// "5000ms" or "1.5", and the server silently replaces an out-of-range
|
|
187
|
+
// timeout with its 30s default — so a malformed flag would run with a
|
|
188
|
+
// deadline the caller never asked for. printError never returns.
|
|
189
|
+
let timeoutMs;
|
|
190
|
+
if (opts?.timeout) {
|
|
191
|
+
timeoutMs = parsePositiveInt(opts.timeout);
|
|
192
|
+
if (timeoutMs === undefined || timeoutMs > 120_000) {
|
|
193
|
+
printError(new Error('--timeout must be an integer between 1 and 120000 (milliseconds)'));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const req = {
|
|
197
|
+
clip: clipName,
|
|
198
|
+
command,
|
|
199
|
+
args: parsedArgs,
|
|
200
|
+
connection: opts?.connection,
|
|
201
|
+
edge_id: opts?.edge,
|
|
202
|
+
profile: opts?.profile,
|
|
203
|
+
timeout: timeoutMs,
|
|
204
|
+
};
|
|
205
|
+
// A cold cloud profile answers 503 EDGE_ACTIVATING BEFORE anything is
|
|
206
|
+
// dispatched; absorb that one retryable window here (bounded, one
|
|
207
|
+
// correlation id) instead of making every agent hand-roll a loop.
|
|
208
|
+
// Everything else — OUTCOME_UNKNOWN above all — propagates untouched:
|
|
209
|
+
// a dispatched command may have executed, and retrying it is not this
|
|
210
|
+
// tool's call. See lib/edge-exec.ts.
|
|
211
|
+
const result = await execEdgeClipAwaitingActivation(client, orgId, req);
|
|
212
|
+
if (result.success) {
|
|
213
|
+
printJson(result.data ?? null);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
printError(new Error(result.error ?? 'execution failed'));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
printError(err);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
162
223
|
clip
|
|
163
224
|
.command('remove')
|
|
164
225
|
.description('Remove a clip by alias')
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { EdgeClipExecResult, ExecEdgeClipRequest, ParallClient } from '@parall/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Cloud (hosted) Edge activation wait — CLI-side bounded retry for `clip exec`.
|
|
4
|
+
*
|
|
5
|
+
* A clip connection bound to a `placement=hosted` Edge whose pod is cold returns
|
|
6
|
+
* 503 EDGE_ACTIVATING from the exec pre-flight: the platform is starting the
|
|
7
|
+
* pod, and the command has NOT been dispatched (the server answers before any
|
|
8
|
+
* publish), so retrying the identical request cannot double-execute anything.
|
|
9
|
+
* This module absorbs that one precise error so a single `parall clip exec`
|
|
10
|
+
* rides through cold start instead of forcing the caller (agent or human) into
|
|
11
|
+
* a blind retry loop.
|
|
12
|
+
*
|
|
13
|
+
* Everything else propagates on first occurrence — especially OUTCOME_UNKNOWN
|
|
14
|
+
* (504): the command was dispatched and MAY HAVE EXECUTED; an automatic retry
|
|
15
|
+
* could post, order or delete twice. That decision belongs to the caller, with
|
|
16
|
+
* the request id from the error message, never to a loop in here.
|
|
17
|
+
*
|
|
18
|
+
* Deliberately NOT in the SDK: `execEdgeClip()` keeps its throw-on-503
|
|
19
|
+
* semantics for every other consumer; only the CLI exec behavior waits.
|
|
20
|
+
* Mirrors lib/clip-invoke.ts (the v2 hosted-browser wait) — same budget, same
|
|
21
|
+
* schedule, same exact-code matching discipline.
|
|
22
|
+
*/
|
|
23
|
+
/** Total activation wait budget. Independent of the clip command --timeout:
|
|
24
|
+
* each attempt keeps its own full command timeout, so worst-case wall clock is
|
|
25
|
+
* roughly this budget plus one command timeout. */
|
|
26
|
+
export declare const EDGE_ACTIVATION_WAIT_BUDGET_MS = 60000;
|
|
27
|
+
/** Backoff schedule between activation retries; the last entry repeats. */
|
|
28
|
+
export declare const EDGE_ACTIVATION_BACKOFF_MS: number[];
|
|
29
|
+
/** Injectable time hooks so tests never really sleep. */
|
|
30
|
+
export type EdgeActivationWaitHooks = {
|
|
31
|
+
sleep?: (ms: number) => Promise<void>;
|
|
32
|
+
now?: () => number;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The ONLY retryable error: a typed ApiError carrying exactly 503 +
|
|
36
|
+
* EDGE_ACTIVATING. Everything else — routing errors, EDGE_BUSY, capacity,
|
|
37
|
+
* repair, command failures, timeouts, OUTCOME_UNKNOWN, other 5xx — means
|
|
38
|
+
* retrying is either pointless or unsafe, so it propagates unchanged on the
|
|
39
|
+
* first occurrence.
|
|
40
|
+
*/
|
|
41
|
+
export declare function isEdgeActivationPending(err: unknown): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Execute an Edge clip, transparently absorbing the cloud-profile activation
|
|
44
|
+
* window.
|
|
45
|
+
*
|
|
46
|
+
* Retries the IDENTICAL request while the server reports EDGE_ACTIVATING,
|
|
47
|
+
* backing off 500ms → 1s → 2s (capped) until the 60s activation budget is
|
|
48
|
+
* spent. The whole loop carries one `correlation_id` (the caller's, or one
|
|
49
|
+
* minted here) so the server's exec audit reads the retries as a single
|
|
50
|
+
* logical call. Once the budget is spent, the LAST typed ApiError is rethrown
|
|
51
|
+
* as-is — status/code intact — so the printed error stays machine-readable.
|
|
52
|
+
* Any other failure is rethrown immediately.
|
|
53
|
+
*/
|
|
54
|
+
export declare function execEdgeClipAwaitingActivation(client: Pick<ParallClient, 'execEdgeClip'>, orgId: string, req: ExecEdgeClipRequest, hooks?: EdgeActivationWaitHooks): Promise<EdgeClipExecResult>;
|
|
55
|
+
//# sourceMappingURL=edge-exec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edge-exec.d.ts","sourceRoot":"","sources":["../../src/lib/edge-exec.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGzF;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;oDAEoD;AACpD,eAAO,MAAM,8BAA8B,QAAS,CAAC;AAErD,2EAA2E;AAC3E,eAAO,MAAM,0BAA0B,UAAsB,CAAC;AAE9D,yDAAyD;AACzD,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB,CAAC;AAIF;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAE7D;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,EAC1C,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,mBAAmB,EACxB,KAAK,CAAC,EAAE,uBAAuB,GAC9B,OAAO,CAAC,kBAAkB,CAAC,CAuB7B"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { ApiError } from '@parall/sdk';
|
|
3
|
+
/**
|
|
4
|
+
* Cloud (hosted) Edge activation wait — CLI-side bounded retry for `clip exec`.
|
|
5
|
+
*
|
|
6
|
+
* A clip connection bound to a `placement=hosted` Edge whose pod is cold returns
|
|
7
|
+
* 503 EDGE_ACTIVATING from the exec pre-flight: the platform is starting the
|
|
8
|
+
* pod, and the command has NOT been dispatched (the server answers before any
|
|
9
|
+
* publish), so retrying the identical request cannot double-execute anything.
|
|
10
|
+
* This module absorbs that one precise error so a single `parall clip exec`
|
|
11
|
+
* rides through cold start instead of forcing the caller (agent or human) into
|
|
12
|
+
* a blind retry loop.
|
|
13
|
+
*
|
|
14
|
+
* Everything else propagates on first occurrence — especially OUTCOME_UNKNOWN
|
|
15
|
+
* (504): the command was dispatched and MAY HAVE EXECUTED; an automatic retry
|
|
16
|
+
* could post, order or delete twice. That decision belongs to the caller, with
|
|
17
|
+
* the request id from the error message, never to a loop in here.
|
|
18
|
+
*
|
|
19
|
+
* Deliberately NOT in the SDK: `execEdgeClip()` keeps its throw-on-503
|
|
20
|
+
* semantics for every other consumer; only the CLI exec behavior waits.
|
|
21
|
+
* Mirrors lib/clip-invoke.ts (the v2 hosted-browser wait) — same budget, same
|
|
22
|
+
* schedule, same exact-code matching discipline.
|
|
23
|
+
*/
|
|
24
|
+
/** Total activation wait budget. Independent of the clip command --timeout:
|
|
25
|
+
* each attempt keeps its own full command timeout, so worst-case wall clock is
|
|
26
|
+
* roughly this budget plus one command timeout. */
|
|
27
|
+
export const EDGE_ACTIVATION_WAIT_BUDGET_MS = 60_000;
|
|
28
|
+
/** Backoff schedule between activation retries; the last entry repeats. */
|
|
29
|
+
export const EDGE_ACTIVATION_BACKOFF_MS = [500, 1_000, 2_000];
|
|
30
|
+
const realSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
31
|
+
/**
|
|
32
|
+
* The ONLY retryable error: a typed ApiError carrying exactly 503 +
|
|
33
|
+
* EDGE_ACTIVATING. Everything else — routing errors, EDGE_BUSY, capacity,
|
|
34
|
+
* repair, command failures, timeouts, OUTCOME_UNKNOWN, other 5xx — means
|
|
35
|
+
* retrying is either pointless or unsafe, so it propagates unchanged on the
|
|
36
|
+
* first occurrence.
|
|
37
|
+
*/
|
|
38
|
+
export function isEdgeActivationPending(err) {
|
|
39
|
+
return err instanceof ApiError && err.status === 503 && err.code === 'EDGE_ACTIVATING';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Execute an Edge clip, transparently absorbing the cloud-profile activation
|
|
43
|
+
* window.
|
|
44
|
+
*
|
|
45
|
+
* Retries the IDENTICAL request while the server reports EDGE_ACTIVATING,
|
|
46
|
+
* backing off 500ms → 1s → 2s (capped) until the 60s activation budget is
|
|
47
|
+
* spent. The whole loop carries one `correlation_id` (the caller's, or one
|
|
48
|
+
* minted here) so the server's exec audit reads the retries as a single
|
|
49
|
+
* logical call. Once the budget is spent, the LAST typed ApiError is rethrown
|
|
50
|
+
* as-is — status/code intact — so the printed error stays machine-readable.
|
|
51
|
+
* Any other failure is rethrown immediately.
|
|
52
|
+
*/
|
|
53
|
+
export async function execEdgeClipAwaitingActivation(client, orgId, req, hooks) {
|
|
54
|
+
const sleep = hooks?.sleep ?? realSleep;
|
|
55
|
+
const now = hooks?.now ?? Date.now;
|
|
56
|
+
const pinned = {
|
|
57
|
+
...req,
|
|
58
|
+
correlation_id: req.correlation_id ?? randomUUID(),
|
|
59
|
+
};
|
|
60
|
+
const deadline = now() + EDGE_ACTIVATION_WAIT_BUDGET_MS;
|
|
61
|
+
for (let attempt = 0;; attempt++) {
|
|
62
|
+
try {
|
|
63
|
+
return await client.execEdgeClip(orgId, pinned);
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
if (!isEdgeActivationPending(err))
|
|
67
|
+
throw err;
|
|
68
|
+
const remaining = deadline - now();
|
|
69
|
+
if (remaining <= 0)
|
|
70
|
+
throw err;
|
|
71
|
+
const backoff = EDGE_ACTIVATION_BACKOFF_MS[Math.min(attempt, EDGE_ACTIVATION_BACKOFF_MS.length - 1)];
|
|
72
|
+
// Clamp to the remaining budget so the final sleep can't overrun it.
|
|
73
|
+
await sleep(Math.min(backoff, remaining));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parall/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.48.0",
|
|
4
4
|
"description": "CLI client for Parall — universal agent & human access to Parall API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"diff": "^8.0.3",
|
|
37
37
|
"js-yaml": "^4.1.0",
|
|
38
38
|
"zod": "^4.3.6",
|
|
39
|
-
"@parall/agent-core": "1.
|
|
40
|
-
"@parall/sdk": "1.
|
|
39
|
+
"@parall/agent-core": "1.48.0",
|
|
40
|
+
"@parall/sdk": "1.48.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/js-yaml": "^4.0.9",
|
|
44
44
|
"@types/node": "^22.0.0",
|
|
45
45
|
"typescript": "^5.7.0",
|
|
46
|
-
"@parall/agent-core": "1.
|
|
46
|
+
"@parall/agent-core": "1.48.0"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsc",
|