@devicecloud.dev/dcd 5.11.0-beta.1 → 5.11.0-beta.11
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 +75 -3
- package/dist/commands/cloud.d.ts +1 -1
- package/dist/commands/cloud.js +7 -6
- package/dist/commands/device.d.ts +36 -0
- package/dist/commands/device.js +1151 -0
- package/dist/commands/live.d.ts +2 -0
- package/dist/commands/live.js +10 -1
- package/dist/commands/login.js +2 -17
- package/dist/commands/mcp.d.ts +13 -0
- package/dist/commands/mcp.js +180 -0
- package/dist/commands/upload.js +2 -8
- package/dist/config/flags/device.flags.d.ts +1 -1
- package/dist/config/flags/device.flags.js +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/gateways/device-gateway.d.ts +88 -0
- package/dist/gateways/device-gateway.js +140 -0
- package/dist/index.js +4 -0
- package/dist/mcp/bridge.d.ts +52 -0
- package/dist/mcp/bridge.js +288 -0
- package/dist/mcp/tools/run-cloud-test.d.ts +13 -0
- package/dist/mcp/tools/run-cloud-test.js +18 -8
- package/dist/methods.d.ts +24 -0
- package/dist/methods.js +147 -169
- package/dist/services/device-validation.service.js +1 -1
- package/dist/services/execution-plan.service.d.ts +27 -0
- package/dist/services/execution-plan.service.js +9 -1
- package/dist/services/metadata-extractor.service.d.ts +13 -0
- package/dist/services/metadata-extractor.service.js +35 -1
- package/dist/services/moropo.service.js +1 -1
- package/dist/services/results-polling.service.js +1 -1
- package/dist/types/domain/device-session.types.d.ts +211 -0
- package/dist/types/domain/device-session.types.js +5 -0
- package/dist/types/domain/device.types.d.ts +0 -2
- package/dist/types/domain/device.types.js +0 -2
- package/dist/types.d.ts +11 -0
- package/dist/utils/app-upload.d.ts +19 -0
- package/dist/utils/app-upload.js +63 -0
- package/dist/utils/auth.d.ts +0 -8
- package/dist/utils/auth.js +31 -27
- package/dist/utils/b2-retry.d.ts +49 -0
- package/dist/utils/b2-retry.js +77 -0
- package/dist/utils/browser.d.ts +16 -0
- package/dist/utils/browser.js +48 -0
- package/dist/utils/compatibility.d.ts +5 -7
- package/dist/utils/compatibility.js +5 -13
- package/dist/utils/device-artifacts.d.ts +55 -0
- package/dist/utils/device-artifacts.js +211 -0
- package/dist/utils/device-bundle.d.ts +35 -0
- package/dist/utils/device-bundle.js +162 -0
- package/dist/utils/device-matrix.js +1 -1
- package/dist/utils/device-output.d.ts +81 -0
- package/dist/utils/device-output.js +207 -0
- package/dist/utils/device-run.d.ts +29 -0
- package/dist/utils/device-run.js +113 -0
- package/dist/utils/mcp-install.d.ts +50 -0
- package/dist/utils/mcp-install.js +132 -0
- package/dist/utils/progress.d.ts +4 -0
- package/dist/utils/progress.js +45 -21
- package/package.json +2 -2
package/dist/commands/live.d.ts
CHANGED
package/dist/commands/live.js
CHANGED
|
@@ -10,6 +10,8 @@ import { resolveApiUrl } from '../utils/config-store.js';
|
|
|
10
10
|
import { colors, formatUrl } from '../utils/styling.js';
|
|
11
11
|
import { ui } from '../utils/ui.js';
|
|
12
12
|
const PLATFORM_OPTIONS = ['android', 'ios'];
|
|
13
|
+
/** Printed to stderr by every `dcd live` command. */
|
|
14
|
+
export const LIVE_DEPRECATION = ui.deprecation('`dcd live` is deprecated and will be removed. Use `dcd device` instead: see `dcd device --help`.');
|
|
13
15
|
const READY_TIMEOUT_MS = 180_000;
|
|
14
16
|
const READY_POLL_MS = 2_000;
|
|
15
17
|
async function requireAuth(keyFlag) {
|
|
@@ -131,7 +133,7 @@ const startSub = defineCommand({
|
|
|
131
133
|
},
|
|
132
134
|
'android-device': {
|
|
133
135
|
type: 'string',
|
|
134
|
-
description: '[Android] Device profile to match a cloud run (options: pixel-6, pixel-
|
|
136
|
+
description: '[Android] Device profile to match a cloud run (options: pixel-6, pixel-8, pixel-10, pixel-10-pro, pixel-10-pro-xl, pixel-11)',
|
|
135
137
|
},
|
|
136
138
|
'android-api-level': {
|
|
137
139
|
type: 'string',
|
|
@@ -591,8 +593,15 @@ export const liveCommand = defineCommand({
|
|
|
591
593
|
meta: {
|
|
592
594
|
name: 'live',
|
|
593
595
|
description: 'Start and interact with a live device session',
|
|
596
|
+
// Replaced by `dcd device` (Agent Devices plan 3.4). Kept working for
|
|
597
|
+
// existing scripts, but no longer listed in `dcd --help`.
|
|
598
|
+
hidden: true,
|
|
594
599
|
},
|
|
595
600
|
subCommands,
|
|
601
|
+
// Runs before any subcommand. On stderr, so --json output is unchanged.
|
|
602
|
+
setup() {
|
|
603
|
+
process.stderr.write(`${LIVE_DEPRECATION}\n`);
|
|
604
|
+
},
|
|
596
605
|
// citty's runCommand does not early-return after dispatching to a
|
|
597
606
|
// subcommand — it still invokes the parent `run` afterwards. So when a
|
|
598
607
|
// subcommand was matched, bail out here; otherwise the menu would print
|
package/dist/commands/login.js
CHANGED
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
*/
|
|
34
34
|
import * as p from '@clack/prompts';
|
|
35
35
|
import { defineCommand } from 'citty';
|
|
36
|
-
import { spawn } from 'node:child_process';
|
|
37
36
|
import { createHash, randomBytes } from 'node:crypto';
|
|
38
37
|
import { ENVIRONMENTS, inferEnvFromApiUrl, resolveFrontendUrl, } from '../config/environments.js';
|
|
39
38
|
import { getSupabaseKey } from '../config/supabase-key.js';
|
|
40
39
|
import { jsonFlag } from '../config/flags/output.flags.js';
|
|
40
|
+
import { openBrowser } from '../utils/browser.js';
|
|
41
41
|
import { canPrompt } from '../utils/ci.js';
|
|
42
42
|
import { CliError, logger } from '../utils/cli.js';
|
|
43
43
|
import { readConfig, writeConfig } from '../utils/config-store.js';
|
|
@@ -149,7 +149,7 @@ export const loginCommand = defineCommand({
|
|
|
149
149
|
rows.push(ui.note('Open this URL in a browser to finish login:'), colors.highlight(loginUrl));
|
|
150
150
|
}
|
|
151
151
|
else {
|
|
152
|
-
const opened = openBrowser(loginUrl);
|
|
152
|
+
const opened = await openBrowser(loginUrl);
|
|
153
153
|
rows.push(ui.note(opened
|
|
154
154
|
? 'Opening your browser…'
|
|
155
155
|
: 'Could not launch a browser. Open this URL manually:'));
|
|
@@ -235,21 +235,6 @@ export const loginCommand = defineCommand({
|
|
|
235
235
|
}
|
|
236
236
|
},
|
|
237
237
|
});
|
|
238
|
-
function openBrowser(url) {
|
|
239
|
-
const cmd = process.platform === 'darwin'
|
|
240
|
-
? { bin: 'open', args: [url] }
|
|
241
|
-
: process.platform === 'win32'
|
|
242
|
-
? { bin: 'cmd', args: ['/c', 'start', '""', url] }
|
|
243
|
-
: { bin: 'xdg-open', args: [url] };
|
|
244
|
-
try {
|
|
245
|
-
const child = spawn(cmd.bin, cmd.args, { detached: true, stdio: 'ignore' });
|
|
246
|
-
child.unref();
|
|
247
|
-
return true;
|
|
248
|
-
}
|
|
249
|
-
catch {
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
238
|
async function pollForClaim(apiUrl, state, codeVerifier) {
|
|
254
239
|
const claimUrl = `${apiUrl}/cli-login/claim`;
|
|
255
240
|
const deadline = Date.now() + LOGIN_TIMEOUT_MS;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dcd mcp`: the MCP server over stdio, for MCP clients to launch. It serves
|
|
3
|
+
* the dcd_* cloud-test tools and the device tools (see src/mcp/bridge.ts).
|
|
4
|
+
* Nothing but JSON-RPC may reach stdout. `dcd mcp install` adds it to a
|
|
5
|
+
* client's config.
|
|
6
|
+
*/
|
|
7
|
+
export declare const mcpCommand: import("citty").CommandDef<{
|
|
8
|
+
readonly 'read-only': {
|
|
9
|
+
readonly type: "boolean";
|
|
10
|
+
readonly default: false;
|
|
11
|
+
readonly description: "Serve only tools that change nothing (also DCD_MCP_READONLY=1)";
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import * as p from '@clack/prompts';
|
|
4
|
+
import { defineCommand } from 'citty';
|
|
5
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
6
|
+
import { jsonFlag } from '../config/flags/output.flags.js';
|
|
7
|
+
import { createBridgeServer } from '../mcp/bridge.js';
|
|
8
|
+
import { isReadOnly, logStderr } from '../mcp/context.js';
|
|
9
|
+
import { telemetry } from '../services/telemetry.service.js';
|
|
10
|
+
import { apiKeyOverride } from '../utils/auth.js';
|
|
11
|
+
import { canPrompt } from '../utils/ci.js';
|
|
12
|
+
import { CliError, getInstallMethod, logger } from '../utils/cli.js';
|
|
13
|
+
import { readConfig } from '../utils/config-store.js';
|
|
14
|
+
import { CLIENT_LABELS, claudeCodeAddArgs, clientConfigPath, MCP_CLIENTS, mcpServersSnippet, SERVER_NAME, serverLaunch, shellLine, stableNodePath, vscodeAddArgs, writeClientConfig, } from '../utils/mcp-install.js';
|
|
15
|
+
import { colors } from '../utils/styling.js';
|
|
16
|
+
import { ui } from '../utils/ui.js';
|
|
17
|
+
const RELOAD_HINT = {
|
|
18
|
+
'claude-code': 'Start a new Claude Code session to load it.',
|
|
19
|
+
'claude-desktop': 'Restart Claude Desktop to load it.',
|
|
20
|
+
cursor: 'Restart Cursor, or reload its MCP servers, to load it.',
|
|
21
|
+
vscode: 'VS Code asks you to trust the server the first time it starts.',
|
|
22
|
+
};
|
|
23
|
+
/** Run another tool's CLI without a shell. Undefined when it isn't installed. */
|
|
24
|
+
function runTool(command, args) {
|
|
25
|
+
const result = spawnSync(command, args, { encoding: 'utf8' });
|
|
26
|
+
if (result.error?.code === 'ENOENT')
|
|
27
|
+
return undefined;
|
|
28
|
+
return { ok: result.status === 0, output: `${result.stdout ?? ''}${result.stderr ?? ''}`.trim() };
|
|
29
|
+
}
|
|
30
|
+
async function pickClient(value) {
|
|
31
|
+
if (value) {
|
|
32
|
+
if (MCP_CLIENTS.includes(value))
|
|
33
|
+
return value;
|
|
34
|
+
throw new CliError(`Unknown client "${value}". Pick one of: ${MCP_CLIENTS.join(', ')}.`);
|
|
35
|
+
}
|
|
36
|
+
if (!canPrompt()) {
|
|
37
|
+
throw new CliError(`Say which client to set up: dcd mcp install <${MCP_CLIENTS.join('|')}>.`);
|
|
38
|
+
}
|
|
39
|
+
const picked = await p.select({
|
|
40
|
+
message: 'Which AI tool should use DeviceCloud?',
|
|
41
|
+
options: MCP_CLIENTS.map((c) => ({ value: c, label: CLIENT_LABELS[c] })),
|
|
42
|
+
});
|
|
43
|
+
if (p.isCancel(picked))
|
|
44
|
+
throw new CliError('Cancelled.');
|
|
45
|
+
return picked;
|
|
46
|
+
}
|
|
47
|
+
/** Add the server to `client`, through its CLI or its JSON config file. */
|
|
48
|
+
function install(client, launch) {
|
|
49
|
+
if (client === 'claude-code') {
|
|
50
|
+
const add = claudeCodeAddArgs(launch);
|
|
51
|
+
const removed = runTool('claude', ['mcp', 'remove', '--scope', 'user', SERVER_NAME]);
|
|
52
|
+
if (!removed) {
|
|
53
|
+
throw new CliError(`The claude command isn't on PATH. Run this where it is:\n ${shellLine('claude', add)}`);
|
|
54
|
+
}
|
|
55
|
+
const added = runTool('claude', add);
|
|
56
|
+
if (!added.ok)
|
|
57
|
+
throw new CliError(`claude mcp add failed: ${added.output}`);
|
|
58
|
+
return { target: shellLine('claude', add), replaced: removed.ok };
|
|
59
|
+
}
|
|
60
|
+
if (client === 'vscode') {
|
|
61
|
+
const add = vscodeAddArgs(launch);
|
|
62
|
+
const added = runTool('code', add);
|
|
63
|
+
if (!added) {
|
|
64
|
+
throw new CliError(`The code command isn't on PATH (in VS Code: "Shell Command: Install 'code' command in PATH"). Or run:\n ${shellLine('code', add)}`);
|
|
65
|
+
}
|
|
66
|
+
if (!added.ok)
|
|
67
|
+
throw new CliError(`code --add-mcp failed: ${added.output}`);
|
|
68
|
+
return { target: shellLine('code', add), replaced: false };
|
|
69
|
+
}
|
|
70
|
+
const file = clientConfigPath(client);
|
|
71
|
+
if (!file) {
|
|
72
|
+
throw new CliError(`${CLIENT_LABELS[client]} has no known config file on ${process.platform}. Add this to it by hand:\n${JSON.stringify(mcpServersSnippet(launch), null, 2)}`);
|
|
73
|
+
}
|
|
74
|
+
return { target: file, ...writeClientConfig(file, launch) };
|
|
75
|
+
}
|
|
76
|
+
/** What `--print` shows: the command to run, or the file and the entry for it. */
|
|
77
|
+
function preview(client, launch) {
|
|
78
|
+
if (client === 'claude-code')
|
|
79
|
+
return { target: 'command', text: shellLine('claude', claudeCodeAddArgs(launch)) };
|
|
80
|
+
if (client === 'vscode')
|
|
81
|
+
return { target: 'command', text: shellLine('code', vscodeAddArgs(launch)) };
|
|
82
|
+
return {
|
|
83
|
+
target: clientConfigPath(client) ?? 'your MCP config file',
|
|
84
|
+
text: JSON.stringify(mcpServersSnippet(launch), null, 2),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const installSub = defineCommand({
|
|
88
|
+
meta: {
|
|
89
|
+
name: 'install',
|
|
90
|
+
description: 'Add the DeviceCloud MCP server to Claude Code, Claude Desktop, Cursor or VS Code',
|
|
91
|
+
},
|
|
92
|
+
args: {
|
|
93
|
+
client: {
|
|
94
|
+
type: 'positional',
|
|
95
|
+
required: false,
|
|
96
|
+
description: `One of ${MCP_CLIENTS.join(', ')}. Asked when left out.`,
|
|
97
|
+
},
|
|
98
|
+
'read-only': {
|
|
99
|
+
type: 'boolean',
|
|
100
|
+
default: false,
|
|
101
|
+
description: 'Have the server offer only tools that change nothing',
|
|
102
|
+
},
|
|
103
|
+
print: {
|
|
104
|
+
type: 'boolean',
|
|
105
|
+
default: false,
|
|
106
|
+
description: 'Show what would be added, and change nothing',
|
|
107
|
+
},
|
|
108
|
+
json: jsonFlag,
|
|
109
|
+
},
|
|
110
|
+
async run({ args }) {
|
|
111
|
+
telemetry.setCommand('mcp install');
|
|
112
|
+
const client = await pickClient(args.client);
|
|
113
|
+
const installMethod = getInstallMethod();
|
|
114
|
+
const launch = serverLaunch({
|
|
115
|
+
installMethod,
|
|
116
|
+
execPath: installMethod === 'binary' ? process.execPath : stableNodePath(process.execPath),
|
|
117
|
+
// As started, not resolved: a global npm install's bin link keeps
|
|
118
|
+
// working across `npm install -g` upgrades.
|
|
119
|
+
scriptPath: process.argv[1] ? path.resolve(process.argv[1]) : undefined,
|
|
120
|
+
readOnly: Boolean(args['read-only']),
|
|
121
|
+
});
|
|
122
|
+
if (args.print) {
|
|
123
|
+
const shown = preview(client, launch);
|
|
124
|
+
if (args.json) {
|
|
125
|
+
logger.json({ status: 'SUCCESS', client, launch, target: shown.target, text: shown.text, written: false });
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
logger.log(ui.section(`${CLIENT_LABELS[client]} config`));
|
|
129
|
+
logger.log(ui.branch(ui.fields([['add to', shown.target]])));
|
|
130
|
+
logger.log(shown.text);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const result = install(client, launch);
|
|
134
|
+
const signedIn = Boolean(readConfig()?.session) || Boolean(apiKeyOverride());
|
|
135
|
+
if (args.json) {
|
|
136
|
+
logger.json({ status: 'SUCCESS', client, launch, target: result.target, replaced: result.replaced, written: true, signedIn });
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
logger.log(ui.success(`${result.replaced ? 'Updated' : 'Added'} DeviceCloud in ${CLIENT_LABELS[client]}`));
|
|
140
|
+
const rows = [
|
|
141
|
+
[client === 'claude-code' || client === 'vscode' ? 'ran' : 'wrote', result.target],
|
|
142
|
+
['starts', colors.highlight(shellLine(launch.command, launch.args))],
|
|
143
|
+
];
|
|
144
|
+
logger.log(ui.branch(ui.fields(rows)));
|
|
145
|
+
logger.log(ui.info(RELOAD_HINT[client]));
|
|
146
|
+
if (!signedIn) {
|
|
147
|
+
logger.log(ui.warn(`Not signed in. Run ${colors.highlight('dcd login')} so the server can use your account.`));
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
/**
|
|
152
|
+
* `dcd mcp`: the MCP server over stdio, for MCP clients to launch. It serves
|
|
153
|
+
* the dcd_* cloud-test tools and the device tools (see src/mcp/bridge.ts).
|
|
154
|
+
* Nothing but JSON-RPC may reach stdout. `dcd mcp install` adds it to a
|
|
155
|
+
* client's config.
|
|
156
|
+
*/
|
|
157
|
+
export const mcpCommand = defineCommand({
|
|
158
|
+
meta: {
|
|
159
|
+
name: 'mcp',
|
|
160
|
+
description: 'MCP server for AI agents, started by your MCP client (Claude, Cursor, VS Code)',
|
|
161
|
+
},
|
|
162
|
+
args: {
|
|
163
|
+
'read-only': {
|
|
164
|
+
type: 'boolean',
|
|
165
|
+
default: false,
|
|
166
|
+
description: 'Serve only tools that change nothing (also DCD_MCP_READONLY=1)',
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
subCommands: { install: installSub },
|
|
170
|
+
async run({ rawArgs }) {
|
|
171
|
+
// citty runs this after a subcommand too; `dcd mcp install` must not
|
|
172
|
+
// then start a server.
|
|
173
|
+
if (rawArgs.some((arg) => !arg.startsWith('-')))
|
|
174
|
+
return;
|
|
175
|
+
telemetry.setCommand('mcp');
|
|
176
|
+
const server = await createBridgeServer();
|
|
177
|
+
await server.connect(new StdioServerTransport());
|
|
178
|
+
logStderr(`DeviceCloud MCP server running on stdio${isReadOnly() ? ' (read-only)' : ''}`);
|
|
179
|
+
},
|
|
180
|
+
});
|
package/dist/commands/upload.js
CHANGED
|
@@ -6,8 +6,7 @@ import { outputFlags } from '../config/flags/output.flags.js';
|
|
|
6
6
|
import { uploadBinary, verifyAppZip } from '../methods.js';
|
|
7
7
|
import { telemetry } from '../services/telemetry.service.js';
|
|
8
8
|
import { resolveAuth } from '../utils/auth.js';
|
|
9
|
-
import {
|
|
10
|
-
import { CliError, getCliVersion, logger } from '../utils/cli.js';
|
|
9
|
+
import { CliError, logger } from '../utils/cli.js';
|
|
11
10
|
import { fetchCompatibilityData } from '../utils/compatibility.js';
|
|
12
11
|
import { resolveApiUrl } from '../utils/config-store.js';
|
|
13
12
|
import { checkKekForEncryption, resolveEncryption } from '../utils/envelope.js';
|
|
@@ -56,12 +55,7 @@ export const uploadCommand = defineCommand({
|
|
|
56
55
|
// failed fetch leaves the default off rather than failing the upload.
|
|
57
56
|
let serverDefault;
|
|
58
57
|
try {
|
|
59
|
-
const
|
|
60
|
-
const compatibilityData = await fetchCompatibilityData(apiUrl, auth, {
|
|
61
|
-
cliVersion: getCliVersion(),
|
|
62
|
-
ciProvider: ciContext.provider,
|
|
63
|
-
ciWrapperVersion: ciContext.wrapperVersion,
|
|
64
|
-
});
|
|
58
|
+
const compatibilityData = await fetchCompatibilityData(apiUrl, auth);
|
|
65
59
|
serverDefault = compatibilityData.encryption?.defaultOn;
|
|
66
60
|
}
|
|
67
61
|
catch (error) {
|
|
@@ -37,7 +37,7 @@ export declare const deviceFlags: {
|
|
|
37
37
|
};
|
|
38
38
|
readonly 'android-device-matrix': {
|
|
39
39
|
readonly type: "string";
|
|
40
|
-
readonly description: "[Android only] Device-matrix cell as <device>:<apiLevel> (append :play for Google Play), e.g. pixel-
|
|
40
|
+
readonly description: "[Android only] Device-matrix cell as <device>:<apiLevel> (append :play for Google Play), e.g. pixel-8:34 or pixel-8:34:play. Repeatable — every flow runs once per cell (no cross-product). Cannot be combined with --ios-device-matrix.";
|
|
41
41
|
};
|
|
42
42
|
readonly orientation: {
|
|
43
43
|
readonly type: "string";
|
|
@@ -42,7 +42,7 @@ export const deviceFlags = {
|
|
|
42
42
|
},
|
|
43
43
|
'android-device-matrix': {
|
|
44
44
|
type: 'string',
|
|
45
|
-
description: `[Android only] Device-matrix cell as <device>:<apiLevel> (append :play for Google Play), e.g. pixel-
|
|
45
|
+
description: `[Android only] Device-matrix cell as <device>:<apiLevel> (append :play for Google Play), e.g. pixel-8:34 or pixel-8:34:play. Repeatable — every flow runs once per cell (no cross-product). Cannot be combined with --ios-device-matrix.`,
|
|
46
46
|
},
|
|
47
47
|
orientation: {
|
|
48
48
|
type: 'string',
|
package/dist/constants.d.ts
CHANGED
|
@@ -183,7 +183,7 @@ export declare const flags: {
|
|
|
183
183
|
};
|
|
184
184
|
readonly 'android-device-matrix': {
|
|
185
185
|
readonly type: "string";
|
|
186
|
-
readonly description: "[Android only] Device-matrix cell as <device>:<apiLevel> (append :play for Google Play), e.g. pixel-
|
|
186
|
+
readonly description: "[Android only] Device-matrix cell as <device>:<apiLevel> (append :play for Google Play), e.g. pixel-8:34 or pixel-8:34:play. Repeatable — every flow runs once per cell (no cross-product). Cannot be combined with --ios-device-matrix.";
|
|
187
187
|
};
|
|
188
188
|
readonly orientation: {
|
|
189
189
|
readonly type: "string";
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { AuthContext } from '../types/domain/auth.types.js';
|
|
2
|
+
import type { DeviceArtifactsPage, DeviceBundleUploadUrls, DeviceFlowBundle, DeviceCatalogue, DeviceCommandResult, DeviceHumanStatus, DeviceInstalledApp, DeviceLogs, DeviceRunResponse, DeviceScreen, DeviceScreenshot, DeviceSession, StartDeviceSessionRequest } from '../types/domain/device-session.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* An error answer from /device/sessions. Unlike ApiError it keeps the API's
|
|
5
|
+
* machine code (`LIVE_NOT_FOUND`, `LIVE_SPEND_CAP`, …) and the `session`
|
|
6
|
+
* block some errors carry, because `dcd device` maps the code to an exit code
|
|
7
|
+
* and prints the session in its JSON envelope.
|
|
8
|
+
*/
|
|
9
|
+
export declare class DeviceApiError extends Error {
|
|
10
|
+
code: null | string;
|
|
11
|
+
session: DeviceSession | null;
|
|
12
|
+
status: number;
|
|
13
|
+
constructor(message: string, status: number, code: null | string, session: DeviceSession | null);
|
|
14
|
+
}
|
|
15
|
+
/** The Agent Devices session API (dcd docs/device-v1-plan.md, section 4.1). */
|
|
16
|
+
export declare const DeviceGateway: {
|
|
17
|
+
artifacts(baseUrl: string, auth: AuthContext, id: string, before?: string): Promise<DeviceArtifactsPage>;
|
|
18
|
+
bundleUploadUrls(baseUrl: string, auth: AuthContext, bytes: number): Promise<DeviceBundleUploadUrls>;
|
|
19
|
+
command(baseUrl: string, auth: AuthContext, id: string, commandId: string): Promise<DeviceRunResponse>;
|
|
20
|
+
/** Whether the session waits for a person, or was handed back. */
|
|
21
|
+
human(baseUrl: string, auth: AuthContext, id: string): Promise<{
|
|
22
|
+
human: DeviceHumanStatus;
|
|
23
|
+
session: DeviceSession;
|
|
24
|
+
}>;
|
|
25
|
+
inspect(baseUrl: string, auth: AuthContext, id: string, all?: boolean): Promise<{
|
|
26
|
+
screen: DeviceScreen;
|
|
27
|
+
session: DeviceSession;
|
|
28
|
+
}>;
|
|
29
|
+
install(baseUrl: string, auth: AuthContext, id: string, app: {
|
|
30
|
+
binaryUploadId: string;
|
|
31
|
+
} | {
|
|
32
|
+
url: string;
|
|
33
|
+
}): Promise<{
|
|
34
|
+
app: DeviceInstalledApp;
|
|
35
|
+
session: DeviceSession;
|
|
36
|
+
}>;
|
|
37
|
+
launch(baseUrl: string, auth: AuthContext, id: string, body: {
|
|
38
|
+
appId?: string;
|
|
39
|
+
clearState?: boolean;
|
|
40
|
+
}): Promise<{
|
|
41
|
+
result: DeviceCommandResult;
|
|
42
|
+
session: DeviceSession;
|
|
43
|
+
}>;
|
|
44
|
+
list(baseUrl: string, auth: AuthContext, all?: boolean): Promise<{
|
|
45
|
+
sessions: DeviceSession[];
|
|
46
|
+
}>;
|
|
47
|
+
logs(baseUrl: string, auth: AuthContext, id: string, lines: number): Promise<{
|
|
48
|
+
logs: DeviceLogs;
|
|
49
|
+
session: DeviceSession;
|
|
50
|
+
}>;
|
|
51
|
+
models(baseUrl: string, auth: AuthContext): Promise<DeviceCatalogue>;
|
|
52
|
+
registerBundle(baseUrl: string, auth: AuthContext, body: {
|
|
53
|
+
backblaze: boolean;
|
|
54
|
+
bytes: number;
|
|
55
|
+
enc?: unknown;
|
|
56
|
+
id: string;
|
|
57
|
+
sha: string;
|
|
58
|
+
supabase: boolean;
|
|
59
|
+
}): Promise<{
|
|
60
|
+
bundle: DeviceFlowBundle;
|
|
61
|
+
}>;
|
|
62
|
+
/** Ask a person for help: the session moves to needs_human until they hand it back. */
|
|
63
|
+
requestHuman(baseUrl: string, auth: AuthContext, id: string, reason: string): Promise<{
|
|
64
|
+
human: DeviceHumanStatus;
|
|
65
|
+
session: DeviceSession;
|
|
66
|
+
}>;
|
|
67
|
+
run(baseUrl: string, auth: AuthContext, id: string, body: {
|
|
68
|
+
env?: Record<string, string>;
|
|
69
|
+
flow?: string;
|
|
70
|
+
flowUploadId: string;
|
|
71
|
+
} | {
|
|
72
|
+
env?: Record<string, string>;
|
|
73
|
+
yaml: string;
|
|
74
|
+
}): Promise<DeviceRunResponse>;
|
|
75
|
+
screenshot(baseUrl: string, auth: AuthContext, id: string): Promise<{
|
|
76
|
+
screenshot: DeviceScreenshot;
|
|
77
|
+
session: DeviceSession;
|
|
78
|
+
}>;
|
|
79
|
+
start(baseUrl: string, auth: AuthContext, body: StartDeviceSessionRequest): Promise<{
|
|
80
|
+
session: DeviceSession;
|
|
81
|
+
}>;
|
|
82
|
+
status(baseUrl: string, auth: AuthContext, id: string): Promise<{
|
|
83
|
+
session: DeviceSession;
|
|
84
|
+
}>;
|
|
85
|
+
stop(baseUrl: string, auth: AuthContext, id: string): Promise<{
|
|
86
|
+
session: DeviceSession;
|
|
87
|
+
}>;
|
|
88
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { ApiGateway } from './api-gateway.js';
|
|
2
|
+
/**
|
|
3
|
+
* An error answer from /device/sessions. Unlike ApiError it keeps the API's
|
|
4
|
+
* machine code (`LIVE_NOT_FOUND`, `LIVE_SPEND_CAP`, …) and the `session`
|
|
5
|
+
* block some errors carry, because `dcd device` maps the code to an exit code
|
|
6
|
+
* and prints the session in its JSON envelope.
|
|
7
|
+
*/
|
|
8
|
+
export class DeviceApiError extends Error {
|
|
9
|
+
code;
|
|
10
|
+
session;
|
|
11
|
+
status;
|
|
12
|
+
constructor(message, status, code, session) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = 'DeviceApiError';
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.session = session;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The API's error envelope: `{ statusCode, message, error? }`, where `error`
|
|
22
|
+
* is either Nest's status text or a machine code such as LIVE_NOT_FOUND.
|
|
23
|
+
* Only an upper-case code is kept, so "Not Found" never reads as one.
|
|
24
|
+
*/
|
|
25
|
+
async function toDeviceApiError(res, path) {
|
|
26
|
+
const text = await res.text();
|
|
27
|
+
let body = {};
|
|
28
|
+
try {
|
|
29
|
+
body = JSON.parse(text);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Not JSON: a proxy page or plain text. The text is the message.
|
|
33
|
+
}
|
|
34
|
+
const raw = Array.isArray(body.message) ? body.message.join('; ') : body.message;
|
|
35
|
+
let message = typeof raw === 'string' && raw ? raw : text.trim() || `HTTP ${res.status}`;
|
|
36
|
+
if (res.status === 401) {
|
|
37
|
+
message =
|
|
38
|
+
'Authentication failed — your credentials are invalid or expired. ' +
|
|
39
|
+
`Re-run \`dcd login\` or check your API key. (${message})`;
|
|
40
|
+
}
|
|
41
|
+
const code = typeof body.error === 'string' && /^[A-Z][A-Z0-9_]+$/.test(body.error) ? body.error : null;
|
|
42
|
+
if (code === 'LIVE_HUMAN_IN_CONTROL') {
|
|
43
|
+
// The API's text points at MCP and raw HTTP too; a CLI user needs the command.
|
|
44
|
+
const id = /^\/device\/sessions\/([^/?]+)/.exec(path)?.[1];
|
|
45
|
+
const name = id ? decodeURIComponent(id) : '<id>';
|
|
46
|
+
message =
|
|
47
|
+
`A person has taken control of ${name} in the console, so it takes no commands until they hand it back. ` +
|
|
48
|
+
`Wait for that with \`dcd device human ${name} --wait\`.`;
|
|
49
|
+
}
|
|
50
|
+
const session = body.session && typeof body.session === 'object' ? body.session : null;
|
|
51
|
+
return new DeviceApiError(message, res.status, code, session);
|
|
52
|
+
}
|
|
53
|
+
async function request(baseUrl, auth, method, path, body) {
|
|
54
|
+
const url = `${baseUrl}${path}`;
|
|
55
|
+
let res;
|
|
56
|
+
try {
|
|
57
|
+
res = await fetch(url, {
|
|
58
|
+
method,
|
|
59
|
+
headers: {
|
|
60
|
+
...auth.headers,
|
|
61
|
+
// Recorded as the command's source in the session timeline.
|
|
62
|
+
'x-dcd-source': 'cli',
|
|
63
|
+
...(body === undefined ? {} : { 'content-type': 'application/json' }),
|
|
64
|
+
},
|
|
65
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error instanceof TypeError && error.message === 'fetch failed') {
|
|
70
|
+
throw ApiGateway.enhanceFetchError(error, url);
|
|
71
|
+
}
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
if (!res.ok)
|
|
75
|
+
throw await toDeviceApiError(res, path);
|
|
76
|
+
try {
|
|
77
|
+
return (await res.json());
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
throw new Error(`${method} ${path}: the API returned an invalid JSON response (${error instanceof Error ? error.message : String(error)})`, { cause: error });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const sessionPath = (id) => `/device/sessions/${encodeURIComponent(id)}`;
|
|
84
|
+
/** The Agent Devices session API (dcd docs/device-v1-plan.md, section 4.1). */
|
|
85
|
+
export const DeviceGateway = {
|
|
86
|
+
artifacts(baseUrl, auth, id, before) {
|
|
87
|
+
const query = new URLSearchParams({ limit: '200', ...(before && { before }) });
|
|
88
|
+
return request(baseUrl, auth, 'GET', `${sessionPath(id)}/artifacts?${query}`);
|
|
89
|
+
},
|
|
90
|
+
bundleUploadUrls(baseUrl, auth, bytes) {
|
|
91
|
+
return request(baseUrl, auth, 'POST', '/device/bundles/upload-url', { bytes });
|
|
92
|
+
},
|
|
93
|
+
command(baseUrl, auth, id, commandId) {
|
|
94
|
+
return request(baseUrl, auth, 'GET', `${sessionPath(id)}/commands/${encodeURIComponent(commandId)}`);
|
|
95
|
+
},
|
|
96
|
+
/** Whether the session waits for a person, or was handed back. */
|
|
97
|
+
human(baseUrl, auth, id) {
|
|
98
|
+
return request(baseUrl, auth, 'GET', `${sessionPath(id)}/human`);
|
|
99
|
+
},
|
|
100
|
+
inspect(baseUrl, auth, id, all = false) {
|
|
101
|
+
return request(baseUrl, auth, 'GET', `${sessionPath(id)}/inspect${all ? '?all=true' : ''}`);
|
|
102
|
+
},
|
|
103
|
+
install(baseUrl, auth, id, app) {
|
|
104
|
+
return request(baseUrl, auth, 'POST', `${sessionPath(id)}/install`, app);
|
|
105
|
+
},
|
|
106
|
+
launch(baseUrl, auth, id, body) {
|
|
107
|
+
return request(baseUrl, auth, 'POST', `${sessionPath(id)}/launch`, body);
|
|
108
|
+
},
|
|
109
|
+
list(baseUrl, auth, all = false) {
|
|
110
|
+
return request(baseUrl, auth, 'GET', `/device/sessions${all ? '?all=true' : ''}`);
|
|
111
|
+
},
|
|
112
|
+
logs(baseUrl, auth, id, lines) {
|
|
113
|
+
return request(baseUrl, auth, 'GET', `${sessionPath(id)}/logs?lines=${lines}`);
|
|
114
|
+
},
|
|
115
|
+
models(baseUrl, auth) {
|
|
116
|
+
return request(baseUrl, auth, 'GET', '/device/models');
|
|
117
|
+
},
|
|
118
|
+
registerBundle(baseUrl, auth, body) {
|
|
119
|
+
return request(baseUrl, auth, 'POST', '/device/bundles', body);
|
|
120
|
+
},
|
|
121
|
+
/** Ask a person for help: the session moves to needs_human until they hand it back. */
|
|
122
|
+
requestHuman(baseUrl, auth, id, reason) {
|
|
123
|
+
return request(baseUrl, auth, 'POST', `${sessionPath(id)}/request-human`, { reason });
|
|
124
|
+
},
|
|
125
|
+
run(baseUrl, auth, id, body) {
|
|
126
|
+
return request(baseUrl, auth, 'POST', `${sessionPath(id)}/run`, body);
|
|
127
|
+
},
|
|
128
|
+
screenshot(baseUrl, auth, id) {
|
|
129
|
+
return request(baseUrl, auth, 'GET', `${sessionPath(id)}/screenshot`);
|
|
130
|
+
},
|
|
131
|
+
start(baseUrl, auth, body) {
|
|
132
|
+
return request(baseUrl, auth, 'POST', '/device/sessions', body);
|
|
133
|
+
},
|
|
134
|
+
status(baseUrl, auth, id) {
|
|
135
|
+
return request(baseUrl, auth, 'GET', sessionPath(id));
|
|
136
|
+
},
|
|
137
|
+
stop(baseUrl, auth, id) {
|
|
138
|
+
return request(baseUrl, auth, 'DELETE', sessionPath(id));
|
|
139
|
+
},
|
|
140
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,12 @@ import { updateSettings } from '@clack/prompts';
|
|
|
3
3
|
import { defineCommand, runCommand, showUsage } from 'citty';
|
|
4
4
|
import { artifactsCommand } from './commands/artifacts.js';
|
|
5
5
|
import { cloudCommand } from './commands/cloud.js';
|
|
6
|
+
import { deviceCommand } from './commands/device.js';
|
|
6
7
|
import { listCommand } from './commands/list.js';
|
|
7
8
|
import { liveCommand } from './commands/live.js';
|
|
8
9
|
import { loginCommand } from './commands/login.js';
|
|
9
10
|
import { logoutCommand } from './commands/logout.js';
|
|
11
|
+
import { mcpCommand } from './commands/mcp.js';
|
|
10
12
|
import { statusCommand } from './commands/status.js';
|
|
11
13
|
import { switchOrgCommand } from './commands/switch-org.js';
|
|
12
14
|
import { upgradeCommand } from './commands/upgrade.js';
|
|
@@ -30,7 +32,9 @@ const main = defineCommand({
|
|
|
30
32
|
list: listCommand,
|
|
31
33
|
status: statusCommand,
|
|
32
34
|
artifacts: artifactsCommand,
|
|
35
|
+
device: deviceCommand,
|
|
33
36
|
live: liveCommand,
|
|
37
|
+
mcp: mcpCommand,
|
|
34
38
|
login: loginCommand,
|
|
35
39
|
logout: logoutCommand,
|
|
36
40
|
whoami: whoamiCommand,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { type Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import type { AuthContext } from '../types/domain/auth.types.js';
|
|
4
|
+
/**
|
|
5
|
+
* How long one forwarded call may take. Longer than dcd_run_cloud_test's
|
|
6
|
+
* longest wait (3600s) plus an upload. The MCP client calling this server
|
|
7
|
+
* still applies its own timeout, and its cancel is passed through.
|
|
8
|
+
*/
|
|
9
|
+
export declare const CALL_TIMEOUT_MS: number;
|
|
10
|
+
/** A hosted tool with this bridge's local inputs added. */
|
|
11
|
+
export declare function withLocalInputs(tool: Tool): Tool;
|
|
12
|
+
/**
|
|
13
|
+
* For a single flow file that uses other files (runFlow, runScript, addMedia
|
|
14
|
+
* and the like): the folder to upload as a bundle, and the file's path
|
|
15
|
+
* inside it. Sent as yaml on its own, the flow would fail on the device with
|
|
16
|
+
* an invalid file path, because the files it uses would not be there. Null
|
|
17
|
+
* when the flow uses no other files, or can't be read (the device reports
|
|
18
|
+
* that itself).
|
|
19
|
+
*/
|
|
20
|
+
export declare function flowFileBundle(file: string): {
|
|
21
|
+
dir: string;
|
|
22
|
+
entry: string;
|
|
23
|
+
} | null;
|
|
24
|
+
/**
|
|
25
|
+
* Do the local part of a call (uploads, reading a file) and return the
|
|
26
|
+
* arguments the hosted tool takes.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveLocalInputs(name: string, args: Record<string, unknown>, ctx: {
|
|
29
|
+
apiUrl: string;
|
|
30
|
+
auth: AuthContext;
|
|
31
|
+
}): Promise<Record<string, unknown>>;
|
|
32
|
+
/** How recent an open session must be to count as one a failed start may have made. */
|
|
33
|
+
export declare const START_RECOVERY_WINDOW_MS: number;
|
|
34
|
+
/**
|
|
35
|
+
* What to tell the agent when a start_device call failed without an answer
|
|
36
|
+
* (the connection dropped, or the server never replied). The request may
|
|
37
|
+
* still have started a session, which is billed while it runs, and an agent
|
|
38
|
+
* that just retries would end up with two. So list the open sessions started
|
|
39
|
+
* in the last couple of minutes, and say to check before starting again.
|
|
40
|
+
*/
|
|
41
|
+
export declare function explainFailedStart(message: string, ctx: {
|
|
42
|
+
apiUrl: string;
|
|
43
|
+
auth: AuthContext;
|
|
44
|
+
}, now?: number): Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Build the `dcd mcp` server. Without a reachable hosted endpoint (no
|
|
47
|
+
* credentials yet, or an API without it), it still serves the dcd_* tools
|
|
48
|
+
* and says why on stderr.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createBridgeServer(opts?: {
|
|
51
|
+
callTimeoutMs?: number;
|
|
52
|
+
}): Promise<Server>;
|