@lobu/runtime-device 24.1.0 → 24.2.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/dist/component.json +1 -1
- package/dist/dependencies.bun.lock +26 -28
- package/npm-shrinkwrap.json +155 -172
- package/package.json +1 -1
- package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +14 -5
- package/vendor/cli/dist/chrome-extension/accessibility-tree.js +834 -0
- package/vendor/cli/dist/chrome-extension/ambient-context.js +53 -0
- package/vendor/cli/dist/chrome-extension/auth-refresh.js +167 -0
- package/vendor/cli/dist/chrome-extension/automation-run.js +13 -0
- package/vendor/cli/dist/chrome-extension/background.js +1155 -0
- package/vendor/cli/dist/chrome-extension/bridge.js +140 -0
- package/vendor/cli/dist/chrome-extension/browser-origin-policy.js +62 -0
- package/vendor/cli/dist/chrome-extension/browser-recovery.js +260 -0
- package/vendor/cli/dist/chrome-extension/browser-url-sanitizer.js +284 -0
- package/vendor/cli/dist/chrome-extension/completion-response.js +12 -0
- package/vendor/cli/dist/chrome-extension/config.js +144 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome.json +1516 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_bookmarks.json +84 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_downloads.json +86 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_history.json +78 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests.js +1767 -0
- package/vendor/cli/dist/chrome-extension/console-capture.js +627 -0
- package/vendor/cli/dist/chrome-extension/control-activity.js +70 -0
- package/vendor/cli/dist/chrome-extension/debugger-lease.js +439 -0
- package/vendor/cli/dist/chrome-extension/feed-listener.js +488 -0
- package/vendor/cli/dist/chrome-extension/feed-transaction.js +48 -0
- package/vendor/cli/dist/chrome-extension/feeds.js +632 -0
- package/vendor/cli/dist/chrome-extension/focus-tab.js +25 -0
- package/vendor/cli/dist/chrome-extension/fonts/dm-mono-latin-500-normal.woff2 +0 -0
- package/vendor/cli/dist/chrome-extension/fonts/dm-sans-latin-400-normal.woff2 +0 -0
- package/vendor/cli/dist/chrome-extension/fonts/dm-sans-latin-600-normal.woff2 +0 -0
- package/vendor/cli/dist/chrome-extension/heartbeat.js +140 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-128-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-128.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-16-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-16.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-32-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-32.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-48-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-48.png +0 -0
- package/vendor/cli/dist/chrome-extension/lens-page.js +135 -0
- package/vendor/cli/dist/chrome-extension/lens-target.js +20 -0
- package/vendor/cli/dist/chrome-extension/manifest.json +76 -0
- package/vendor/cli/dist/chrome-extension/network-intercept.js +657 -0
- package/vendor/cli/dist/chrome-extension/page-activation.js +120 -0
- package/vendor/cli/dist/chrome-extension/page-dialogs.js +125 -0
- package/vendor/cli/dist/chrome-extension/page-url.js +11 -0
- package/vendor/cli/dist/chrome-extension/panel-session.js +184 -0
- package/vendor/cli/dist/chrome-extension/poll-auth.js +85 -0
- package/vendor/cli/dist/chrome-extension/poll-backoff.js +22 -0
- package/vendor/cli/dist/chrome-extension/run-fence.js +117 -0
- package/vendor/cli/dist/chrome-extension/setup-status.js +71 -0
- package/vendor/cli/dist/chrome-extension/side-panel-action-click.js +65 -0
- package/vendor/cli/dist/chrome-extension/sidepanel-context.js +50 -0
- package/vendor/cli/dist/chrome-extension/sidepanel.html +680 -0
- package/vendor/cli/dist/chrome-extension/sidepanel.js +1643 -0
- package/vendor/cli/dist/chrome-extension/tab-labels.js +233 -0
- package/vendor/cli/dist/chrome-extension/tools.js +3354 -0
- package/vendor/cli/dist/chrome-extension/watch-observer.js +354 -0
- package/vendor/cli/dist/chrome-extension/watch-redact.js +96 -0
- package/vendor/cli/dist/chrome-extension/watch.js +348 -0
- package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +6 -4
- package/vendor/cli/dist/commands/_lib/apply/desired-state.js +5 -3
- package/vendor/cli/dist/commands/_lib/apply/diff.js +4 -3
- package/vendor/cli/dist/commands/_lib/apply/render.js +4 -14
- package/vendor/cli/dist/commands/_lib/chrome-for-testing.d.ts +13 -0
- package/vendor/cli/dist/commands/_lib/chrome-for-testing.js +226 -0
- package/vendor/cli/dist/commands/_lib/device-credential.d.ts +34 -0
- package/vendor/cli/dist/commands/_lib/device-credential.js +157 -0
- package/vendor/cli/dist/commands/_lib/device-wizard.d.ts +17 -0
- package/vendor/cli/dist/commands/_lib/device-wizard.js +11 -2
- package/vendor/cli/dist/commands/_lib/native-messaging.d.ts +7 -0
- package/vendor/cli/dist/commands/_lib/native-messaging.js +40 -0
- package/vendor/cli/dist/commands/browser.d.ts +23 -0
- package/vendor/cli/dist/commands/browser.js +492 -0
- package/vendor/cli/dist/commands/call.d.ts +12 -0
- package/vendor/cli/dist/commands/call.js +48 -26
- package/vendor/cli/dist/commands/context.d.ts +3 -1
- package/vendor/cli/dist/commands/context.js +13 -2
- package/vendor/cli/dist/commands/daemon.js +2 -152
- package/vendor/cli/dist/commands/memory/_lib/errors.d.ts +4 -1
- package/vendor/cli/dist/commands/memory/_lib/errors.js +9 -1
- package/vendor/cli/dist/commands/memory/_lib/mcp.d.ts +0 -9
- package/vendor/cli/dist/commands/memory/_lib/mcp.js +1 -23
- package/vendor/cli/dist/commands/memory/_lib/memory-auth.d.ts +20 -4
- package/vendor/cli/dist/commands/memory/_lib/memory-auth.js +21 -17
- package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +6 -17
- package/vendor/cli/dist/commands/memory/run.js +4 -25
- package/vendor/cli/dist/connectors/google_gmail.ts +70 -41
- package/vendor/cli/dist/connectors/google_gmail_references.ts +406 -0
- package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +107 -36
- package/vendor/cli/dist/connectors/linkedin-inbox.ts +13 -0
- package/vendor/cli/dist/connectors/linkedin.ts +1 -1
- package/vendor/cli/dist/connectors/postgres.ts +5 -3
- package/vendor/cli/dist/connectors/reddit.ts +171 -5
- package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +147 -61
- package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +6 -2
- package/vendor/cli/dist/connectors/whatsapp_web.ts +48 -17
- package/vendor/cli/dist/connectors/x-dm-adapter.js +252 -35
- package/vendor/cli/dist/connectors/x.ts +189 -13
- package/vendor/cli/dist/index.js +46 -6
- package/vendor/cli/dist/internal/device-state.d.ts +2 -0
- package/vendor/cli/dist/internal/device-state.js +4 -0
- package/vendor/cli/dist/runtime-components.json +4 -4
- package/vendor/cli/dist/templates/AGENTS.md.tmpl +3 -1
- package/vendor/cli/dist/templates/TESTING.md.tmpl +8 -8
- package/vendor/cli/package.json +1 -1
- package/vendor/connector-sdk/dist/browser-requirement.js +1 -1
- package/vendor/connector-sdk/dist/connector-types.d.ts +5 -1
- package/vendor/connector-sdk/package.json +1 -1
- package/vendor/connector-worker/dist/agent-turn/gateway-tools.d.ts +9 -0
- package/vendor/connector-worker/dist/agent-turn/gateway-tools.js +23 -2
- package/vendor/connector-worker/dist/agent-turn/guest-entry.js +14 -6
- package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +62 -25
- package/vendor/connector-worker/dist/agent-turn/media-tools.d.ts +1 -0
- package/vendor/connector-worker/dist/agent-turn/media-tools.js +5 -2
- package/vendor/connector-worker/dist/bin.js +2 -0
- package/vendor/connector-worker/dist/daemon/agent-turn.js +52 -17
- package/vendor/connector-worker/dist/daemon/automation.js +2 -12
- package/vendor/connector-worker/dist/daemon/client.d.ts +8 -2
- package/vendor/connector-worker/dist/daemon/client.js +8 -1
- package/vendor/connector-worker/dist/daemon/interactive-session.js +29 -6
- package/vendor/connector-worker/dist/daemon/poll-loop.js +23 -1
- package/vendor/connector-worker/dist/daemon/terminal-delivery.d.ts +5 -10
- package/vendor/connector-worker/dist/daemon/terminal-delivery.js +55 -23
- package/vendor/connector-worker/dist/daemon/terminal-failure.js +2 -2
- package/vendor/connector-worker/dist/executor/isolate.js +3 -0
- package/vendor/connector-worker/package.json +1 -1
- package/vendor/core/dist/agent-tooling.d.ts +8 -0
- package/vendor/core/dist/agent-tooling.js +9 -1
- package/vendor/core/dist/capabilities.d.ts +1 -1
- package/vendor/core/dist/capabilities.js +5 -0
- package/vendor/core/dist/contracts/entity-reference.d.ts +3 -0
- package/vendor/core/dist/contracts/entity-reference.js +31 -0
- package/vendor/core/dist/contracts/tools/manage-automations.d.ts +3 -0
- package/vendor/core/dist/contracts/tools/manage-automations.js +3 -0
- package/vendor/core/dist/contracts/tools/manage-connections.js +1 -1
- package/vendor/core/dist/contracts/tools/manage-entity-schema.js +1 -1
- package/vendor/core/dist/contracts/tools/manage-entity.d.ts +113 -34
- package/vendor/core/dist/contracts/tools/manage-entity.js +41 -14
- package/vendor/core/dist/contracts/tools/manage-operations.d.ts +13 -4
- package/vendor/core/dist/contracts/tools/manage-operations.js +19 -7
- package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +6 -1
- package/vendor/core/dist/contracts/tools/read-knowledge.js +20 -1
- package/vendor/core/dist/contracts/tools/view-attach.d.ts +1 -1
- package/vendor/core/dist/contracts/tools/view-runtime.d.ts +2 -0
- package/vendor/core/dist/contracts/tools/view-runtime.js +3 -1
- package/vendor/core/dist/contracts/worker/device-automation.d.ts +4 -9
- package/vendor/core/dist/contracts/worker/device-automation.js +10 -15
- package/vendor/core/dist/contracts/worker/protocol.d.ts +20 -0
- package/vendor/core/dist/contracts/worker/protocol.js +20 -0
- package/vendor/core/dist/reserved.d.ts +6 -3
- package/vendor/core/dist/reserved.js +6 -3
- package/vendor/core/dist/worker/auth.d.ts +3 -2
- package/vendor/core/package.json +6 -1
- package/vendor/postgres/cf/src/query.js +3 -1
- package/vendor/postgres/cjs/src/query.js +3 -1
- package/vendor/postgres/src/query.js +3 -1
- /package/vendor/postgres/{.bun-tag-2f292c6554a8475e → .bun-tag-22d644c2873790db} +0 -0
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
import { execFile, spawn } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { appendFile, chmod, mkdir, readdir, readFile, readlink, rm, writeFile, } from "node:fs/promises";
|
|
5
|
+
import { homedir, hostname } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { promisify } from "node:util";
|
|
9
|
+
import { apiUrlToGatewayOrigin, findContextByOrigin, loadContextConfig, resolveContext, } from "../internal/context.js";
|
|
10
|
+
import { getContextToken } from "../internal/credentials.js";
|
|
11
|
+
import { deleteDeviceState, loadDeviceState, } from "../internal/device-state.js";
|
|
12
|
+
import { extractApiError, fetchWithRetry, parseJsonResponse, } from "../internal/http.js";
|
|
13
|
+
import { resolveBrowserExecutable } from "./_lib/chrome-for-testing.js";
|
|
14
|
+
import { DeviceMintError, mintDeviceCredentialWithReauth, persistDeviceCredential, requireInstallationLogin, } from "./_lib/device-credential.js";
|
|
15
|
+
import { DeviceListError, fetchRemoteDevices, } from "./_lib/device-wizard.js";
|
|
16
|
+
import { encodeNativeMessage, readNativeMessage, } from "./_lib/native-messaging.js";
|
|
17
|
+
// A named browser is a Chrome for Testing profile with the Lobu extension
|
|
18
|
+
// loaded, registered as its own `chrome-extension` device. The CLI never hands
|
|
19
|
+
// the extension a token on the command line: it installs itself as the
|
|
20
|
+
// profile's `ai.lobu.bridge` native messaging host, the same host the Mac app
|
|
21
|
+
// provides, and the extension's existing desktop pairing asks it for a device
|
|
22
|
+
// credential minted from this CLI's login.
|
|
23
|
+
const NATIVE_HOST_NAME = "ai.lobu.bridge";
|
|
24
|
+
const PLATFORM = "chrome-extension";
|
|
25
|
+
const NAME_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$/;
|
|
26
|
+
const PAIR_TIMEOUT_MS = 90_000;
|
|
27
|
+
const PAIR_POLL_MS = 2_000;
|
|
28
|
+
const STOP_TIMEOUT_MS = 10_000;
|
|
29
|
+
const execFileAsync = promisify(execFile);
|
|
30
|
+
function browsersRoot() {
|
|
31
|
+
return join(homedir(), ".config", "lobu", "browsers");
|
|
32
|
+
}
|
|
33
|
+
function browserDir(name) {
|
|
34
|
+
return join(browsersRoot(), name);
|
|
35
|
+
}
|
|
36
|
+
function profileDir(name) {
|
|
37
|
+
return join(browserDir(name), "profile");
|
|
38
|
+
}
|
|
39
|
+
/** Device-state slot holding the latest credential handed to this browser. */
|
|
40
|
+
function credentialSlot(name) {
|
|
41
|
+
return `${PLATFORM}-browser-${name}`;
|
|
42
|
+
}
|
|
43
|
+
function requireName(name) {
|
|
44
|
+
const trimmed = name.trim();
|
|
45
|
+
if (!NAME_PATTERN.test(trimmed)) {
|
|
46
|
+
throw new Error(`Invalid browser name "${name}". Use 1-32 lowercase letters, digits, or hyphens, starting and ending with a letter or digit.`);
|
|
47
|
+
}
|
|
48
|
+
return trimmed;
|
|
49
|
+
}
|
|
50
|
+
function bundledExtensionDir() {
|
|
51
|
+
return fileURLToPath(new URL("../chrome-extension/", import.meta.url));
|
|
52
|
+
}
|
|
53
|
+
/** Chrome derives an unpacked extension's id from its manifest `key`. */
|
|
54
|
+
async function extensionId(extensionDir) {
|
|
55
|
+
const manifest = JSON.parse(await readFile(join(extensionDir, "manifest.json"), "utf8"));
|
|
56
|
+
if (!manifest.key) {
|
|
57
|
+
throw new Error("The bundled Lobu extension has no manifest key.");
|
|
58
|
+
}
|
|
59
|
+
return [
|
|
60
|
+
...createHash("sha256")
|
|
61
|
+
.update(Buffer.from(manifest.key, "base64"))
|
|
62
|
+
.digest("hex")
|
|
63
|
+
.slice(0, 32),
|
|
64
|
+
]
|
|
65
|
+
.map((digit) => String.fromCharCode(97 + Number.parseInt(digit, 16)))
|
|
66
|
+
.join("");
|
|
67
|
+
}
|
|
68
|
+
async function readRecord(name) {
|
|
69
|
+
try {
|
|
70
|
+
const parsed = JSON.parse(await readFile(join(browserDir(name), "browser.json"), "utf8"));
|
|
71
|
+
if (parsed.name !== name ||
|
|
72
|
+
typeof parsed.context !== "string" ||
|
|
73
|
+
typeof parsed.gatewayOrigin !== "string" ||
|
|
74
|
+
typeof parsed.workerId !== "string" ||
|
|
75
|
+
typeof parsed.label !== "string") {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return parsed;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function requireRecord(name) {
|
|
85
|
+
const record = await readRecord(name);
|
|
86
|
+
if (!record) {
|
|
87
|
+
throw new Error(`No browser named "${name}". Run \`lobu browser list\` to see your browsers.`);
|
|
88
|
+
}
|
|
89
|
+
return record;
|
|
90
|
+
}
|
|
91
|
+
async function resolveTarget(contextOption) {
|
|
92
|
+
const resolved = await resolveContext(contextOption);
|
|
93
|
+
const gatewayOrigin = apiUrlToGatewayOrigin(resolved.url);
|
|
94
|
+
if (resolved.source !== "env") {
|
|
95
|
+
return { context: resolved.name, gatewayOrigin };
|
|
96
|
+
}
|
|
97
|
+
// A LOBU_API_URL override only borrows the login of a context saved for it.
|
|
98
|
+
const matched = await findContextByOrigin(gatewayOrigin);
|
|
99
|
+
if (!matched) {
|
|
100
|
+
throw new Error(`No saved context points at ${gatewayOrigin}. Run \`lobu login\` for it first.`);
|
|
101
|
+
}
|
|
102
|
+
return { context: matched.name, gatewayOrigin };
|
|
103
|
+
}
|
|
104
|
+
/** The pid of the browser that owns `name`'s profile, or null when none runs. */
|
|
105
|
+
async function runningPid(name) {
|
|
106
|
+
const profile = profileDir(name);
|
|
107
|
+
let lock;
|
|
108
|
+
try {
|
|
109
|
+
// Chrome points this at `<hostname>-<pid>` while it holds the profile.
|
|
110
|
+
lock = await readlink(join(profile, "SingletonLock"));
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const pid = Number.parseInt(lock.slice(lock.lastIndexOf("-") + 1), 10);
|
|
116
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
117
|
+
return null;
|
|
118
|
+
try {
|
|
119
|
+
// The lock outlives a crash, and pids are reused: confirm the process
|
|
120
|
+
// really is a browser on this profile before trusting or signalling it.
|
|
121
|
+
const { stdout } = await execFileAsync("ps", [
|
|
122
|
+
"-ww",
|
|
123
|
+
"-p",
|
|
124
|
+
String(pid),
|
|
125
|
+
"-o",
|
|
126
|
+
"command=",
|
|
127
|
+
]);
|
|
128
|
+
// Chrome follows the profile flag with further flags, so a trailing space
|
|
129
|
+
// stops `/browsers/work/profile` matching `/browsers/work/profile-other`.
|
|
130
|
+
const argument = `--user-data-dir=${profile}`;
|
|
131
|
+
const command = stdout.trimEnd();
|
|
132
|
+
return command.includes(`${argument} `) || command.endsWith(argument)
|
|
133
|
+
? pid
|
|
134
|
+
: null;
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Whether the browser's context still points at the gateway it paired with. A
|
|
142
|
+
* context repointed elsewhere holds that other gateway's login, which must
|
|
143
|
+
* never be sent to this browser's gateway. Read from the saved contexts, not
|
|
144
|
+
* through LOBU_API_URL, which only overrides where a command connects.
|
|
145
|
+
*/
|
|
146
|
+
async function contextStillTargets(record) {
|
|
147
|
+
const entry = (await loadContextConfig()).contexts[record.context];
|
|
148
|
+
return (entry !== undefined &&
|
|
149
|
+
apiUrlToGatewayOrigin(entry.url) === record.gatewayOrigin);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Bearers for device requests, best first: the browser's own child credential,
|
|
153
|
+
* which belongs to the account that owns the device and outlives a lapsed
|
|
154
|
+
* login, then the context's login, only while the context still points at this
|
|
155
|
+
* browser's gateway. The login may belong to another account by now.
|
|
156
|
+
*/
|
|
157
|
+
async function deviceBearers(record) {
|
|
158
|
+
const bearers = [];
|
|
159
|
+
const live = await liveCredential(record);
|
|
160
|
+
if (live)
|
|
161
|
+
bearers.push(live.workerApiToken);
|
|
162
|
+
if (await contextStillTargets(record)) {
|
|
163
|
+
const login = await getContextToken(record.context);
|
|
164
|
+
if (login)
|
|
165
|
+
bearers.push(login);
|
|
166
|
+
}
|
|
167
|
+
if (bearers.length === 0) {
|
|
168
|
+
throw new Error(`Context "${record.context}" is not logged in. Run \`lobu login --context ${record.context}\`.`);
|
|
169
|
+
}
|
|
170
|
+
return bearers;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* This browser's device and the bearer that listed it. A bearer that does not
|
|
174
|
+
* list it may simply belong to another account, so the device counts as
|
|
175
|
+
* missing only once every bearer the gateway accepts has been asked.
|
|
176
|
+
*/
|
|
177
|
+
async function findDevice(record) {
|
|
178
|
+
let accepted = false;
|
|
179
|
+
let rejection;
|
|
180
|
+
for (const bearer of await deviceBearers(record)) {
|
|
181
|
+
try {
|
|
182
|
+
const devices = await fetchRemoteDevices(record.gatewayOrigin, bearer);
|
|
183
|
+
const device = devices.find((entry) => entry.worker_id === record.workerId);
|
|
184
|
+
if (device)
|
|
185
|
+
return { device, bearer };
|
|
186
|
+
accepted = true;
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
const rejected = error instanceof DeviceListError &&
|
|
190
|
+
(error.status === 401 || error.status === 403);
|
|
191
|
+
if (!rejected)
|
|
192
|
+
throw error;
|
|
193
|
+
rejection = error;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (accepted)
|
|
197
|
+
return { device: null };
|
|
198
|
+
throw rejection;
|
|
199
|
+
}
|
|
200
|
+
/** The cached credential minted for this browser, while it is unexpired. */
|
|
201
|
+
async function liveCredential(record) {
|
|
202
|
+
const cached = await loadDeviceState(record.context, credentialSlot(record.name));
|
|
203
|
+
return cached?.workerId === record.workerId &&
|
|
204
|
+
cached.workerApiToken &&
|
|
205
|
+
cached.expiresAt &&
|
|
206
|
+
cached.expiresAt > Date.now()
|
|
207
|
+
? {
|
|
208
|
+
workerId: cached.workerId,
|
|
209
|
+
workerApiToken: cached.workerApiToken,
|
|
210
|
+
expiresAt: cached.expiresAt,
|
|
211
|
+
}
|
|
212
|
+
: undefined;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The device credential to hand this browser. A login mints a fresh one, and
|
|
216
|
+
* only a full-access login also gets the side panel's sign-in session. Without
|
|
217
|
+
* a usable login the unexpired cached credential is returned unchanged: minting
|
|
218
|
+
* from it would revoke it, and the extension keeps its current token when a
|
|
219
|
+
* reply carries no session, so a rotation would strand it on a revoked one.
|
|
220
|
+
*/
|
|
221
|
+
async function credentialForBrowser(record, interactive) {
|
|
222
|
+
// Minting can fall back to the context's login, or refresh it, so it never
|
|
223
|
+
// runs once the context points at another gateway.
|
|
224
|
+
if (!(await contextStillTargets(record))) {
|
|
225
|
+
throw new Error(`Context "${record.context}" no longer points at ${record.gatewayOrigin}, where browser "${record.name}" is registered. Point it back, or run \`lobu browser rm ${record.name}\` and start the browser again.`);
|
|
226
|
+
}
|
|
227
|
+
const live = await liveCredential(record);
|
|
228
|
+
const login = interactive
|
|
229
|
+
? await requireInstallationLogin(record.context)
|
|
230
|
+
: ((await getContextToken(record.context)) ?? undefined);
|
|
231
|
+
if (!login) {
|
|
232
|
+
if (live)
|
|
233
|
+
return live;
|
|
234
|
+
throw new Error(`Context "${record.context}" is not logged in. Run \`lobu browser start ${record.name}\` in a terminal.`);
|
|
235
|
+
}
|
|
236
|
+
let minted;
|
|
237
|
+
try {
|
|
238
|
+
minted = await mintDeviceCredentialWithReauth({
|
|
239
|
+
contextName: record.context,
|
|
240
|
+
initialBearerIsChild: false,
|
|
241
|
+
interactiveReauth: interactive,
|
|
242
|
+
options: {
|
|
243
|
+
gatewayOrigin: record.gatewayOrigin,
|
|
244
|
+
bearer: login,
|
|
245
|
+
platform: PLATFORM,
|
|
246
|
+
workerId: record.workerId,
|
|
247
|
+
label: record.label,
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
if (live && error instanceof DeviceMintError)
|
|
253
|
+
return live;
|
|
254
|
+
throw error;
|
|
255
|
+
}
|
|
256
|
+
if (minted.workerId !== record.workerId) {
|
|
257
|
+
throw new Error(`The gateway registered this browser as "${minted.workerId}" instead of "${record.workerId}". Another device of yours already uses that id; remove it or pick a different browser name.`);
|
|
258
|
+
}
|
|
259
|
+
await persistDeviceCredential(record.context, credentialSlot(record.name), minted);
|
|
260
|
+
return minted;
|
|
261
|
+
}
|
|
262
|
+
async function writeNativeHost(name, extensionDir) {
|
|
263
|
+
const dir = browserDir(name);
|
|
264
|
+
const wrapper = join(dir, "native-host");
|
|
265
|
+
const cliEntry = fileURLToPath(new URL("../../bin/lobu.js", import.meta.url));
|
|
266
|
+
const quote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
|
|
267
|
+
// Chrome passes a host no arguments of our choosing, so the browser name is
|
|
268
|
+
// baked into this per-browser script. Rewritten on every start so it follows
|
|
269
|
+
// the CLI and Node the user runs now.
|
|
270
|
+
await writeFile(wrapper, `#!/bin/sh\n# Generated by \`lobu browser start\`. Chrome runs this to pair the Lobu extension.\nexec ${quote(process.execPath)} ${quote(cliEntry)} browser native-host ${quote(name)}\n`, { mode: 0o700 });
|
|
271
|
+
await chmod(wrapper, 0o700);
|
|
272
|
+
// Chrome looks for user-level hosts in <user-data-dir>/NativeMessagingHosts,
|
|
273
|
+
// so this host serves only this browser and never the user's own Chrome.
|
|
274
|
+
const hostsDir = join(profileDir(name), "NativeMessagingHosts");
|
|
275
|
+
await mkdir(hostsDir, { recursive: true });
|
|
276
|
+
await writeFile(join(hostsDir, `${NATIVE_HOST_NAME}.json`), `${JSON.stringify({
|
|
277
|
+
name: NATIVE_HOST_NAME,
|
|
278
|
+
description: `Lobu pairing for the "${name}" browser`,
|
|
279
|
+
path: wrapper,
|
|
280
|
+
type: "stdio",
|
|
281
|
+
allowed_origins: [
|
|
282
|
+
`chrome-extension://${await extensionId(extensionDir)}/`,
|
|
283
|
+
],
|
|
284
|
+
}, null, 2)}\n`);
|
|
285
|
+
}
|
|
286
|
+
async function waitForFirstPoll(record, previousSeenAt) {
|
|
287
|
+
const deadline = Date.now() + PAIR_TIMEOUT_MS;
|
|
288
|
+
for (;;) {
|
|
289
|
+
const { device } = await findDevice(record);
|
|
290
|
+
// A poll stamps app_version; minting the credential only touches
|
|
291
|
+
// last_seen_at, so a fresh device is not online until it has polled.
|
|
292
|
+
if (device?.online &&
|
|
293
|
+
device.app_version &&
|
|
294
|
+
device.last_seen_at !== previousSeenAt) {
|
|
295
|
+
return device;
|
|
296
|
+
}
|
|
297
|
+
if (Date.now() >= deadline) {
|
|
298
|
+
throw new Error(`The "${record.name}" browser opened but did not connect within ${PAIR_TIMEOUT_MS / 1000}s. Open the Lobu side panel in that window to see why; the pairing log is ${join(browserDir(record.name), "native-host.log")}.`);
|
|
299
|
+
}
|
|
300
|
+
await new Promise((resolve) => setTimeout(resolve, PAIR_POLL_MS));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
export async function browserStartCommand(rawName, options) {
|
|
304
|
+
const name = requireName(rawName);
|
|
305
|
+
const extensionDir = bundledExtensionDir();
|
|
306
|
+
if (!existsSync(join(extensionDir, "manifest.json"))) {
|
|
307
|
+
throw new Error(`This lobu build does not include the Lobu extension (looked in ${extensionDir}).`);
|
|
308
|
+
}
|
|
309
|
+
let record = await readRecord(name);
|
|
310
|
+
if (record && options.context && options.context !== record.context) {
|
|
311
|
+
throw new Error(`Browser "${name}" belongs to context "${record.context}". Use \`--context ${record.context}\`, or \`lobu browser rm ${name}\` first.`);
|
|
312
|
+
}
|
|
313
|
+
if (!record) {
|
|
314
|
+
const target = await resolveTarget(options.context);
|
|
315
|
+
const shortHost = hostname().split(".")[0] || hostname();
|
|
316
|
+
record = {
|
|
317
|
+
name,
|
|
318
|
+
context: target.context,
|
|
319
|
+
gatewayOrigin: target.gatewayOrigin,
|
|
320
|
+
workerId: `${PLATFORM}:${shortHost}:${name}`,
|
|
321
|
+
label: `${name} (${shortHost})`,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
// Authorize up front, where a login prompt is still possible: the native
|
|
325
|
+
// host later runs under Chrome with no terminal. Skipped while the cached
|
|
326
|
+
// credential is live, because re-minting would revoke the one the extension
|
|
327
|
+
// is using.
|
|
328
|
+
if (!(await liveCredential(record))) {
|
|
329
|
+
await credentialForBrowser(record, true);
|
|
330
|
+
}
|
|
331
|
+
await mkdir(profileDir(name), { recursive: true });
|
|
332
|
+
await writeFile(join(browserDir(name), "browser.json"), `${JSON.stringify(record, null, 2)}\n`);
|
|
333
|
+
await writeNativeHost(name, extensionDir);
|
|
334
|
+
const pid = await runningPid(name);
|
|
335
|
+
if (pid) {
|
|
336
|
+
const { device } = await findDevice(record);
|
|
337
|
+
console.log(`Browser "${name}" is already running (pid ${pid}, device ${device?.online ? "online" : "offline"}).`);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const executable = await resolveBrowserExecutable();
|
|
341
|
+
const { device: previous } = await findDevice(record);
|
|
342
|
+
const child = spawn(executable, [
|
|
343
|
+
`--user-data-dir=${profileDir(name)}`,
|
|
344
|
+
`--load-extension=${extensionDir}`,
|
|
345
|
+
"--no-first-run",
|
|
346
|
+
"--no-default-browser-check",
|
|
347
|
+
...(options.headless ? ["--headless=new"] : []),
|
|
348
|
+
], { detached: true, stdio: "ignore" });
|
|
349
|
+
await new Promise((resolve, reject) => {
|
|
350
|
+
child.once("spawn", resolve);
|
|
351
|
+
child.once("error", reject);
|
|
352
|
+
});
|
|
353
|
+
child.unref();
|
|
354
|
+
console.log(`Starting browser "${name}"…`);
|
|
355
|
+
const device = await waitForFirstPoll(record, previous?.last_seen_at ?? null);
|
|
356
|
+
console.log(`Browser "${name}" is connected as device "${record.label}".`);
|
|
357
|
+
console.log(` Device id: ${device.id}`);
|
|
358
|
+
console.log(` Workspace context: ${record.context} (${record.gatewayOrigin})`);
|
|
359
|
+
console.log(` Profile: ${profileDir(name)}`);
|
|
360
|
+
}
|
|
361
|
+
export async function browserStopCommand(rawName) {
|
|
362
|
+
const name = requireName(rawName);
|
|
363
|
+
await requireRecord(name);
|
|
364
|
+
const pid = await runningPid(name);
|
|
365
|
+
if (!pid) {
|
|
366
|
+
console.log(`Browser "${name}" is not running.`);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
process.kill(pid, "SIGTERM");
|
|
370
|
+
const deadline = Date.now() + STOP_TIMEOUT_MS;
|
|
371
|
+
while ((await runningPid(name)) === pid) {
|
|
372
|
+
if (Date.now() >= deadline) {
|
|
373
|
+
process.kill(pid, "SIGKILL");
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
377
|
+
}
|
|
378
|
+
console.log(`Stopped browser "${name}".`);
|
|
379
|
+
}
|
|
380
|
+
export async function browserListCommand(options) {
|
|
381
|
+
let names = [];
|
|
382
|
+
try {
|
|
383
|
+
names = (await readdir(browsersRoot())).sort();
|
|
384
|
+
}
|
|
385
|
+
catch {
|
|
386
|
+
// No browsers yet.
|
|
387
|
+
}
|
|
388
|
+
const rows = [];
|
|
389
|
+
for (const name of names) {
|
|
390
|
+
const record = await readRecord(name);
|
|
391
|
+
if (!record)
|
|
392
|
+
continue;
|
|
393
|
+
let device = "unknown";
|
|
394
|
+
try {
|
|
395
|
+
const { device: found } = await findDevice(record);
|
|
396
|
+
device = found ? (found.online ? "online" : "offline") : "missing";
|
|
397
|
+
}
|
|
398
|
+
catch {
|
|
399
|
+
// Offline gateway or lapsed login: show the browser anyway.
|
|
400
|
+
}
|
|
401
|
+
rows.push({
|
|
402
|
+
name,
|
|
403
|
+
context: record.context,
|
|
404
|
+
running: (await runningPid(name)) !== null,
|
|
405
|
+
device,
|
|
406
|
+
profile: profileDir(name),
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
if (options.json) {
|
|
410
|
+
console.log(JSON.stringify({ browsers: rows }, null, 2));
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (rows.length === 0) {
|
|
414
|
+
console.log("No browsers yet. Start one with `lobu browser start <name>`.");
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
for (const row of rows) {
|
|
418
|
+
console.log(`${row.name}\t${row.running ? "running" : "stopped"}\tdevice ${row.device}\t${row.context}`);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
export async function browserRemoveCommand(rawName) {
|
|
422
|
+
const name = requireName(rawName);
|
|
423
|
+
const record = await requireRecord(name);
|
|
424
|
+
if (await runningPid(name))
|
|
425
|
+
await browserStopCommand(name);
|
|
426
|
+
const found = await findDevice(record);
|
|
427
|
+
if (found.device) {
|
|
428
|
+
const url = `${record.gatewayOrigin}/api/me/devices/${encodeURIComponent(found.device.id)}`;
|
|
429
|
+
const res = await fetchWithRetry(url, {
|
|
430
|
+
method: "DELETE",
|
|
431
|
+
headers: {
|
|
432
|
+
Accept: "application/json",
|
|
433
|
+
Authorization: `Bearer ${found.bearer}`,
|
|
434
|
+
"X-Lobu-Client": "cli",
|
|
435
|
+
},
|
|
436
|
+
});
|
|
437
|
+
if (!res.ok) {
|
|
438
|
+
const parsed = await parseJsonResponse(res, url, (message) => {
|
|
439
|
+
throw new Error(message);
|
|
440
|
+
});
|
|
441
|
+
const { message } = extractApiError(parsed, res.status, res.statusText);
|
|
442
|
+
throw new Error(`Could not remove the "${name}" device, so its profile was kept: ${message}`);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
await deleteDeviceState(record.context, credentialSlot(name));
|
|
446
|
+
await rm(browserDir(name), { recursive: true, force: true });
|
|
447
|
+
console.log(found.device
|
|
448
|
+
? `Removed browser "${name}" and its device.`
|
|
449
|
+
: `Removed browser "${name}"; no registered device was found for it.`);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* The native host's answer to one extension message. A `pair` request gets a
|
|
453
|
+
* freshly minted device credential in the desktop bridge's reply shape; every
|
|
454
|
+
* other message (the extension also publishes ambient tab context to a desktop
|
|
455
|
+
* app, which a named browser does not have) is declined.
|
|
456
|
+
*/
|
|
457
|
+
export async function nativeHostReply(name, message, log) {
|
|
458
|
+
if (message?.op !== "pair") {
|
|
459
|
+
return { ok: false, error: "unsupported" };
|
|
460
|
+
}
|
|
461
|
+
try {
|
|
462
|
+
const record = await requireRecord(name);
|
|
463
|
+
const minted = await credentialForBrowser(record, false);
|
|
464
|
+
await log(`paired worker ${minted.workerId} ${minted.sessionToken ? "with" : "without"} a side panel session`);
|
|
465
|
+
return {
|
|
466
|
+
gateway_url: record.gatewayOrigin,
|
|
467
|
+
worker_id: minted.workerId,
|
|
468
|
+
access_token: minted.workerApiToken,
|
|
469
|
+
session_token: minted.sessionToken ?? null,
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
catch (error) {
|
|
473
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
474
|
+
await log(`pairing failed: ${text}`);
|
|
475
|
+
return { error: text };
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Native messaging host Chrome starts for the extension's desktop pairing.
|
|
480
|
+
* stdout is the framed channel to Chrome, so every other line goes to a log.
|
|
481
|
+
*/
|
|
482
|
+
export async function browserNativeHostCommand(rawName) {
|
|
483
|
+
const name = requireName(rawName);
|
|
484
|
+
const logFile = join(browserDir(name), "native-host.log");
|
|
485
|
+
const log = (line) => appendFile(logFile, `${new Date().toISOString()} ${line}\n`).catch(() => undefined);
|
|
486
|
+
console.log = (...args) => {
|
|
487
|
+
void log(args.map(String).join(" "));
|
|
488
|
+
};
|
|
489
|
+
const reply = await nativeHostReply(name, await readNativeMessage(process.stdin), log);
|
|
490
|
+
await new Promise((resolve, reject) => process.stdout.write(encodeNativeMessage(reply), (error) => error ? reject(error) : resolve()));
|
|
491
|
+
}
|
|
492
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -9,6 +9,16 @@
|
|
|
9
9
|
* --arg key=value flat string field (top-level only)
|
|
10
10
|
* --arg key:=<jsonvalue> JSON-parsed field (httpie-style)
|
|
11
11
|
*
|
|
12
|
+
* `run_sdk`, `query_sdk` and `query_sql` require a non-empty `title` arg: it is
|
|
13
|
+
* the heading the activity feed shows for the call. The check runs before any
|
|
14
|
+
* request.
|
|
15
|
+
*
|
|
16
|
+
* Transport: REST by default. A runtime credential (LOBU_API_TOKEN +
|
|
17
|
+
* LOBU_MEMORY_URL, e.g. a device Automation run's worker access) is valid only
|
|
18
|
+
* on MCP routes, so that case sends the same call as MCP `tools/call` to
|
|
19
|
+
* LOBU_MEMORY_URL, which already names the org; the printed result is then the
|
|
20
|
+
* MCP tool result.
|
|
21
|
+
*
|
|
12
22
|
* Output is pretty JSON by default; `--raw` switches to compact JSON for piping.
|
|
13
23
|
* Errors go to stderr with exit code 1 (ApiError) / 2 (validation). A tool
|
|
14
24
|
* that reports failure inside a 200 payload still prints its JSON, then exits 1.
|
|
@@ -28,6 +38,8 @@ interface CallOptions {
|
|
|
28
38
|
export declare function parseArgEntry(entry: string): [string, unknown];
|
|
29
39
|
/** Build the args payload from the three mutually-exclusive sources. */
|
|
30
40
|
export declare function buildArgs(options: CallOptions): Promise<Record<string, unknown>>;
|
|
41
|
+
/** Refuse an untitled run_sdk / query_sdk / query_sql call before any request. */
|
|
42
|
+
export declare function assertCallTitle(tool: string, args: Record<string, unknown>): void;
|
|
31
43
|
export declare function callCommand(tool: string | undefined, options?: CallOptions): Promise<void>;
|
|
32
44
|
export {};
|
|
33
45
|
//# sourceMappingURL=call.d.ts.map
|
|
@@ -9,6 +9,16 @@
|
|
|
9
9
|
* --arg key=value flat string field (top-level only)
|
|
10
10
|
* --arg key:=<jsonvalue> JSON-parsed field (httpie-style)
|
|
11
11
|
*
|
|
12
|
+
* `run_sdk`, `query_sdk` and `query_sql` require a non-empty `title` arg: it is
|
|
13
|
+
* the heading the activity feed shows for the call. The check runs before any
|
|
14
|
+
* request.
|
|
15
|
+
*
|
|
16
|
+
* Transport: REST by default. A runtime credential (LOBU_API_TOKEN +
|
|
17
|
+
* LOBU_MEMORY_URL, e.g. a device Automation run's worker access) is valid only
|
|
18
|
+
* on MCP routes, so that case sends the same call as MCP `tools/call` to
|
|
19
|
+
* LOBU_MEMORY_URL, which already names the org; the printed result is then the
|
|
20
|
+
* MCP tool result.
|
|
21
|
+
*
|
|
12
22
|
* Output is pretty JSON by default; `--raw` switches to compact JSON for piping.
|
|
13
23
|
* Errors go to stderr with exit code 1 (ApiError) / 2 (validation). A tool
|
|
14
24
|
* that reports failure inside a 200 payload still prints its JSON, then exits 1.
|
|
@@ -17,8 +27,8 @@ import { readFile } from "node:fs/promises";
|
|
|
17
27
|
import { resolveApiClient } from "../internal/api-client.js";
|
|
18
28
|
import { printJson } from "../internal/output.js";
|
|
19
29
|
import { isFailedToolPayload, parseJsonObject, ValidationError, } from "./memory/_lib/errors.js";
|
|
20
|
-
import { restToolCall } from "./memory/_lib/mcp.js";
|
|
21
|
-
import {
|
|
30
|
+
import { mcpRpc, restToolCall } from "./memory/_lib/mcp.js";
|
|
31
|
+
import { hasRuntimeMcpAccess, resolveToolMcpUrl, } from "./memory/_lib/memory-auth.js";
|
|
22
32
|
/** Parse a single `--arg key=value` or `key:=<json>` entry into a [key, value]. */
|
|
23
33
|
export function parseArgEntry(entry) {
|
|
24
34
|
// `:=` first — must be longer than `=` to win the prefix match.
|
|
@@ -97,20 +107,19 @@ export async function buildArgs(options) {
|
|
|
97
107
|
// honest default; many admin tools have all-optional fields.
|
|
98
108
|
return {};
|
|
99
109
|
}
|
|
100
|
-
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
108
|
-
return
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return mcpUrlForOrg(base, org);
|
|
110
|
+
/** Tools whose calls the activity feed heads with the caller's `title`. */
|
|
111
|
+
const TITLED_TOOLS = new Set(["run_sdk", "query_sdk", "query_sql"]);
|
|
112
|
+
/** Refuse an untitled run_sdk / query_sdk / query_sql call before any request. */
|
|
113
|
+
export function assertCallTitle(tool, args) {
|
|
114
|
+
if (!TITLED_TOOLS.has(tool))
|
|
115
|
+
return;
|
|
116
|
+
const title = args.title;
|
|
117
|
+
if (typeof title === "string" && title.trim())
|
|
118
|
+
return;
|
|
119
|
+
const body = tool === "query_sql" ? "--arg sql='SELECT ...'" : "--arg script='...'";
|
|
120
|
+
throw new ValidationError(`${tool} requires a non-empty \`title\` arg; it names this call in the activity feed. Add one, e.g.:\n` +
|
|
121
|
+
` lobu call ${tool} --arg title='Recent support tickets' ${body}\n` +
|
|
122
|
+
`(or a "title" field in the --input-file / stdin JSON).`);
|
|
114
123
|
}
|
|
115
124
|
function printToolList(tools, options) {
|
|
116
125
|
const visible = options.includeInternal
|
|
@@ -135,24 +144,37 @@ function printToolList(tools, options) {
|
|
|
135
144
|
export async function callCommand(tool, options = {}) {
|
|
136
145
|
const json = options.json === true;
|
|
137
146
|
const raw = options.raw === true;
|
|
147
|
+
const runtimeMcp = hasRuntimeMcpAccess();
|
|
138
148
|
if (options.list || !tool) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
149
|
+
let result;
|
|
150
|
+
if (runtimeMcp) {
|
|
151
|
+
const { url } = await resolveToolMcpUrl(options);
|
|
152
|
+
result = (await mcpRpc(url, "tools/list", undefined, options.context));
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
const { client, orgSlug } = await resolveApiClient({
|
|
156
|
+
context: options.context,
|
|
157
|
+
org: options.org,
|
|
158
|
+
apiUrl: options.url,
|
|
159
|
+
});
|
|
160
|
+
result = await client.get(`/api/${encodeURIComponent(orgSlug)}/tools`);
|
|
161
|
+
}
|
|
162
|
+
printToolList(Array.isArray(result?.tools) ? result.tools : [], {
|
|
147
163
|
json,
|
|
148
164
|
raw,
|
|
149
165
|
includeInternal: options.all === true,
|
|
150
166
|
});
|
|
151
167
|
return;
|
|
152
168
|
}
|
|
153
|
-
const mcpUrl = await resolveCallEndpoint(options);
|
|
154
169
|
const args = await buildArgs(options);
|
|
155
|
-
|
|
170
|
+
assertCallTitle(tool, args);
|
|
171
|
+
const endpoint = await resolveToolMcpUrl(options);
|
|
172
|
+
if (!runtimeMcp && !endpoint.org) {
|
|
173
|
+
throw new ValidationError("Cannot resolve org slug. Pass --org or run `lobu context use <name>` / `lobu org set <slug>`.");
|
|
174
|
+
}
|
|
175
|
+
const result = runtimeMcp
|
|
176
|
+
? await mcpRpc(endpoint.url, "tools/call", { name: tool, arguments: args }, options.context)
|
|
177
|
+
: await restToolCall(endpoint.url, tool, args, options.context);
|
|
156
178
|
printJson(result, raw);
|
|
157
179
|
// Same contract as `memory run`: the printed JSON stays parseable, but a
|
|
158
180
|
// reported failure must fail the shell or CI gates pass silently.
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export declare function contextListCommand(
|
|
1
|
+
export declare function contextListCommand(options?: {
|
|
2
|
+
json?: boolean;
|
|
3
|
+
}): Promise<void>;
|
|
2
4
|
export declare function contextCurrentCommand(): Promise<void>;
|
|
3
5
|
export declare function contextAddCommand(options: {
|
|
4
6
|
name: string;
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import { addContext, getCurrentContextName, loadContextConfig, removeContext, resolveContext, setCurrentContext, } from "../internal/index.js";
|
|
3
|
-
export async function contextListCommand() {
|
|
2
|
+
import { addContext, getCurrentContextName, loadContextConfig, loadCredentials, removeContext, resolveContext, setCurrentContext, } from "../internal/index.js";
|
|
3
|
+
export async function contextListCommand(options = {}) {
|
|
4
4
|
const config = await loadContextConfig();
|
|
5
5
|
const currentContext = await getCurrentContextName();
|
|
6
|
+
if (options.json) {
|
|
7
|
+
// Stored credentials may be expired; listing must not refresh them.
|
|
8
|
+
const contexts = await Promise.all(Object.entries(config.contexts).map(async ([name, context]) => ({
|
|
9
|
+
name,
|
|
10
|
+
url: context.url,
|
|
11
|
+
current: name === currentContext,
|
|
12
|
+
loggedIn: (await loadCredentials(name)) !== null,
|
|
13
|
+
})));
|
|
14
|
+
process.stdout.write(`${JSON.stringify({ current: currentContext, contexts }, null, 2)}\n`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
6
17
|
console.log(chalk.bold("\n Lobu contexts"));
|
|
7
18
|
for (const [name, context] of Object.entries(config.contexts)) {
|
|
8
19
|
const marker = name === currentContext ? chalk.green(" *") : " ";
|