@lobu/runtime-device 24.1.1 → 24.3.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.
Files changed (194) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +46 -134
  3. package/npm-shrinkwrap.json +229 -730
  4. package/package.json +1 -1
  5. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +20 -5
  6. package/vendor/cli/dist/chrome-extension/accessibility-tree.js +834 -0
  7. package/vendor/cli/dist/chrome-extension/ambient-context.js +53 -0
  8. package/vendor/cli/dist/chrome-extension/auth-refresh.js +167 -0
  9. package/vendor/cli/dist/chrome-extension/automation-run.js +13 -0
  10. package/vendor/cli/dist/chrome-extension/background.js +1155 -0
  11. package/vendor/cli/dist/chrome-extension/bridge.js +140 -0
  12. package/vendor/cli/dist/chrome-extension/browser-origin-policy.js +62 -0
  13. package/vendor/cli/dist/chrome-extension/browser-recovery.js +260 -0
  14. package/vendor/cli/dist/chrome-extension/browser-url-sanitizer.js +284 -0
  15. package/vendor/cli/dist/chrome-extension/completion-response.js +12 -0
  16. package/vendor/cli/dist/chrome-extension/config.js +144 -0
  17. package/vendor/cli/dist/chrome-extension/connector-manifests/chrome.json +1516 -0
  18. package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_bookmarks.json +84 -0
  19. package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_downloads.json +86 -0
  20. package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_history.json +78 -0
  21. package/vendor/cli/dist/chrome-extension/connector-manifests.js +1767 -0
  22. package/vendor/cli/dist/chrome-extension/console-capture.js +627 -0
  23. package/vendor/cli/dist/chrome-extension/control-activity.js +70 -0
  24. package/vendor/cli/dist/chrome-extension/debugger-lease.js +439 -0
  25. package/vendor/cli/dist/chrome-extension/feed-listener.js +488 -0
  26. package/vendor/cli/dist/chrome-extension/feed-transaction.js +48 -0
  27. package/vendor/cli/dist/chrome-extension/feeds.js +632 -0
  28. package/vendor/cli/dist/chrome-extension/focus-tab.js +25 -0
  29. package/vendor/cli/dist/chrome-extension/fonts/dm-mono-latin-500-normal.woff2 +0 -0
  30. package/vendor/cli/dist/chrome-extension/fonts/dm-sans-latin-400-normal.woff2 +0 -0
  31. package/vendor/cli/dist/chrome-extension/fonts/dm-sans-latin-600-normal.woff2 +0 -0
  32. package/vendor/cli/dist/chrome-extension/heartbeat.js +140 -0
  33. package/vendor/cli/dist/chrome-extension/icons/icon-128-rec.png +0 -0
  34. package/vendor/cli/dist/chrome-extension/icons/icon-128.png +0 -0
  35. package/vendor/cli/dist/chrome-extension/icons/icon-16-rec.png +0 -0
  36. package/vendor/cli/dist/chrome-extension/icons/icon-16.png +0 -0
  37. package/vendor/cli/dist/chrome-extension/icons/icon-32-rec.png +0 -0
  38. package/vendor/cli/dist/chrome-extension/icons/icon-32.png +0 -0
  39. package/vendor/cli/dist/chrome-extension/icons/icon-48-rec.png +0 -0
  40. package/vendor/cli/dist/chrome-extension/icons/icon-48.png +0 -0
  41. package/vendor/cli/dist/chrome-extension/lens-page.js +135 -0
  42. package/vendor/cli/dist/chrome-extension/lens-target.js +20 -0
  43. package/vendor/cli/dist/chrome-extension/manifest.json +76 -0
  44. package/vendor/cli/dist/chrome-extension/network-intercept.js +657 -0
  45. package/vendor/cli/dist/chrome-extension/page-activation.js +120 -0
  46. package/vendor/cli/dist/chrome-extension/page-dialogs.js +125 -0
  47. package/vendor/cli/dist/chrome-extension/page-url.js +11 -0
  48. package/vendor/cli/dist/chrome-extension/panel-session.js +184 -0
  49. package/vendor/cli/dist/chrome-extension/poll-auth.js +85 -0
  50. package/vendor/cli/dist/chrome-extension/poll-backoff.js +22 -0
  51. package/vendor/cli/dist/chrome-extension/run-fence.js +117 -0
  52. package/vendor/cli/dist/chrome-extension/setup-status.js +71 -0
  53. package/vendor/cli/dist/chrome-extension/side-panel-action-click.js +65 -0
  54. package/vendor/cli/dist/chrome-extension/sidepanel-context.js +50 -0
  55. package/vendor/cli/dist/chrome-extension/sidepanel.html +680 -0
  56. package/vendor/cli/dist/chrome-extension/sidepanel.js +1643 -0
  57. package/vendor/cli/dist/chrome-extension/tab-labels.js +233 -0
  58. package/vendor/cli/dist/chrome-extension/tools.js +3354 -0
  59. package/vendor/cli/dist/chrome-extension/watch-observer.js +354 -0
  60. package/vendor/cli/dist/chrome-extension/watch-redact.js +96 -0
  61. package/vendor/cli/dist/chrome-extension/watch.js +348 -0
  62. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +6 -4
  63. package/vendor/cli/dist/commands/_lib/apply/desired-state.js +5 -3
  64. package/vendor/cli/dist/commands/_lib/apply/diff.js +4 -3
  65. package/vendor/cli/dist/commands/_lib/chrome-for-testing.d.ts +13 -0
  66. package/vendor/cli/dist/commands/_lib/chrome-for-testing.js +226 -0
  67. package/vendor/cli/dist/commands/_lib/device-credential.d.ts +34 -0
  68. package/vendor/cli/dist/commands/_lib/device-credential.js +157 -0
  69. package/vendor/cli/dist/commands/_lib/device-wizard.d.ts +17 -0
  70. package/vendor/cli/dist/commands/_lib/device-wizard.js +11 -2
  71. package/vendor/cli/dist/commands/_lib/native-messaging.d.ts +7 -0
  72. package/vendor/cli/dist/commands/_lib/native-messaging.js +40 -0
  73. package/vendor/cli/dist/commands/browser.d.ts +23 -0
  74. package/vendor/cli/dist/commands/browser.js +492 -0
  75. package/vendor/cli/dist/commands/call.d.ts +12 -0
  76. package/vendor/cli/dist/commands/call.js +48 -26
  77. package/vendor/cli/dist/commands/chat.d.ts +0 -12
  78. package/vendor/cli/dist/commands/chat.js +1 -1
  79. package/vendor/cli/dist/commands/context.d.ts +3 -1
  80. package/vendor/cli/dist/commands/context.js +13 -2
  81. package/vendor/cli/dist/commands/daemon.js +38 -171
  82. package/vendor/cli/dist/commands/doctor.d.ts +0 -6
  83. package/vendor/cli/dist/commands/doctor.js +1 -1
  84. package/vendor/cli/dist/commands/memory/_lib/errors.d.ts +4 -1
  85. package/vendor/cli/dist/commands/memory/_lib/errors.js +9 -1
  86. package/vendor/cli/dist/commands/memory/_lib/mcp.d.ts +0 -9
  87. package/vendor/cli/dist/commands/memory/_lib/mcp.js +1 -23
  88. package/vendor/cli/dist/commands/memory/_lib/memory-auth.d.ts +20 -4
  89. package/vendor/cli/dist/commands/memory/_lib/memory-auth.js +21 -17
  90. package/vendor/cli/dist/commands/memory/_lib/seed-cmd.d.ts +0 -8
  91. package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +7 -18
  92. package/vendor/cli/dist/commands/memory/run.js +4 -25
  93. package/vendor/cli/dist/config/define.d.ts +1 -1
  94. package/vendor/cli/dist/connectors/gchat.ts +31 -1
  95. package/vendor/cli/dist/connectors/google_gmail.ts +70 -41
  96. package/vendor/cli/dist/connectors/google_gmail_references.ts +406 -0
  97. package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +107 -36
  98. package/vendor/cli/dist/connectors/linkedin-inbox.ts +13 -0
  99. package/vendor/cli/dist/connectors/linkedin.ts +1 -1
  100. package/vendor/cli/dist/connectors/postgres.ts +14 -8
  101. package/vendor/cli/dist/connectors/reddit.ts +171 -5
  102. package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +147 -61
  103. package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +6 -2
  104. package/vendor/cli/dist/connectors/whatsapp_web.ts +48 -17
  105. package/vendor/cli/dist/connectors/x-dm-adapter.js +252 -35
  106. package/vendor/cli/dist/connectors/x.ts +189 -13
  107. package/vendor/cli/dist/index.js +46 -6
  108. package/vendor/cli/dist/internal/cli-update-check.d.ts +33 -0
  109. package/vendor/cli/dist/internal/cli-update-check.js +98 -0
  110. package/vendor/cli/dist/internal/credentials.js +10 -36
  111. package/vendor/cli/dist/internal/device-state.d.ts +2 -0
  112. package/vendor/cli/dist/internal/device-state.js +4 -0
  113. package/vendor/cli/dist/internal/gateway-url.d.ts +0 -8
  114. package/vendor/cli/dist/internal/gateway-url.js +1 -1
  115. package/vendor/cli/dist/runtime-components.json +4 -4
  116. package/vendor/cli/dist/templates/AGENTS.md.tmpl +3 -1
  117. package/vendor/cli/dist/templates/TESTING.md.tmpl +8 -8
  118. package/vendor/cli/package.json +1 -1
  119. package/vendor/connector-sdk/dist/browser-requirement.js +1 -1
  120. package/vendor/connector-sdk/dist/connector-types.d.ts +34 -1
  121. package/vendor/connector-sdk/dist/index.d.ts +3 -1
  122. package/vendor/connector-sdk/dist/index.js +4 -0
  123. package/vendor/connector-sdk/dist/redact.d.ts +10 -0
  124. package/vendor/{connector-worker/dist/executor → connector-sdk/dist}/redact.js +0 -49
  125. package/vendor/connector-sdk/dist/types.d.ts +2 -1
  126. package/vendor/connector-sdk/package.json +6 -1
  127. package/vendor/connector-worker/dist/agent-turn/gateway-tools.d.ts +9 -0
  128. package/vendor/connector-worker/dist/agent-turn/gateway-tools.js +23 -2
  129. package/vendor/connector-worker/dist/agent-turn/guest-entry.js +14 -6
  130. package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +62 -25
  131. package/vendor/connector-worker/dist/agent-turn/media-tools.d.ts +1 -0
  132. package/vendor/connector-worker/dist/agent-turn/media-tools.js +5 -2
  133. package/vendor/connector-worker/dist/bin.js +2 -0
  134. package/vendor/connector-worker/dist/daemon/acp-adapters/THIRD_PARTY_LICENSES.txt +1 -1
  135. package/vendor/connector-worker/dist/daemon/acp-adapters/claude.js +7339 -2136
  136. package/vendor/connector-worker/dist/daemon/agent-turn.js +52 -17
  137. package/vendor/connector-worker/dist/daemon/automation.js +3 -13
  138. package/vendor/connector-worker/dist/daemon/client.d.ts +23 -3
  139. package/vendor/connector-worker/dist/daemon/client.js +59 -5
  140. package/vendor/connector-worker/dist/daemon/executor.d.ts +0 -28
  141. package/vendor/connector-worker/dist/daemon/executor.js +27 -12
  142. package/vendor/connector-worker/dist/daemon/index.d.ts +1 -1
  143. package/vendor/connector-worker/dist/daemon/index.js +1 -1
  144. package/vendor/connector-worker/dist/daemon/interactive-session.js +29 -6
  145. package/vendor/connector-worker/dist/daemon/poll-loop.js +29 -2
  146. package/vendor/connector-worker/dist/daemon/start.d.ts +0 -1
  147. package/vendor/connector-worker/dist/daemon/start.js +1 -1
  148. package/vendor/connector-worker/dist/daemon/terminal-delivery.d.ts +6 -10
  149. package/vendor/connector-worker/dist/daemon/terminal-delivery.js +59 -23
  150. package/vendor/connector-worker/dist/daemon/terminal-failure.js +2 -2
  151. package/vendor/connector-worker/dist/executor/isolate.js +4 -1
  152. package/vendor/connector-worker/dist/isolate/bridge.d.ts +6 -2
  153. package/vendor/connector-worker/dist/isolate/bridge.js +14 -8
  154. package/vendor/connector-worker/package.json +2 -2
  155. package/vendor/core/dist/agent-tooling.d.ts +8 -0
  156. package/vendor/core/dist/agent-tooling.js +9 -1
  157. package/vendor/core/dist/capabilities.d.ts +1 -1
  158. package/vendor/core/dist/capabilities.js +5 -0
  159. package/vendor/core/dist/connector-query-errors.d.ts +6 -0
  160. package/vendor/core/dist/connector-query-errors.js +4 -0
  161. package/vendor/core/dist/contracts/entity-reference.d.ts +3 -0
  162. package/vendor/core/dist/contracts/entity-reference.js +31 -0
  163. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +3 -0
  164. package/vendor/core/dist/contracts/tools/manage-automations.js +4 -1
  165. package/vendor/core/dist/contracts/tools/manage-connections.js +1 -1
  166. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +2 -2
  167. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +117 -34
  168. package/vendor/core/dist/contracts/tools/manage-entity.js +47 -14
  169. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +13 -4
  170. package/vendor/core/dist/contracts/tools/manage-operations.js +19 -7
  171. package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +6 -1
  172. package/vendor/core/dist/contracts/tools/read-knowledge.js +20 -1
  173. package/vendor/core/dist/contracts/tools/view-attach.d.ts +1 -1
  174. package/vendor/core/dist/contracts/tools/view-runtime.d.ts +2 -0
  175. package/vendor/core/dist/contracts/tools/view-runtime.js +3 -1
  176. package/vendor/core/dist/contracts/worker/device-automation.d.ts +4 -9
  177. package/vendor/core/dist/contracts/worker/device-automation.js +10 -15
  178. package/vendor/core/dist/contracts/worker/protocol.d.ts +20 -0
  179. package/vendor/core/dist/contracts/worker/protocol.js +20 -0
  180. package/vendor/core/dist/errors.d.ts +0 -20
  181. package/vendor/core/dist/errors.js +1 -25
  182. package/vendor/core/dist/otel.js +38 -10
  183. package/vendor/core/dist/reserved.d.ts +6 -3
  184. package/vendor/core/dist/reserved.js +6 -3
  185. package/vendor/core/dist/utils/ajv.js +3 -1
  186. package/vendor/core/dist/worker/auth.d.ts +3 -2
  187. package/vendor/core/package.json +31 -5
  188. package/vendor/postgres/cf/src/query.js +3 -1
  189. package/vendor/postgres/cjs/src/query.js +3 -1
  190. package/vendor/postgres/src/query.js +3 -1
  191. package/vendor/connector-worker/dist/executor/http-status.d.ts +0 -16
  192. package/vendor/connector-worker/dist/executor/http-status.js +0 -21
  193. package/vendor/connector-worker/dist/executor/redact.d.ts +0 -29
  194. /package/vendor/postgres/{.bun-tag-2f292c6554a8475e → .bun-tag-22d644c2873790db} +0 -0
@@ -0,0 +1,34 @@
1
+ export interface MintedDeviceCredential {
2
+ workerId: string;
3
+ workerApiToken: string;
4
+ expiresAt: number;
5
+ /**
6
+ * Browser sign-in session the gateway mints only for a `chrome-extension`
7
+ * device. Handed straight to that browser's side panel, never persisted.
8
+ */
9
+ sessionToken?: string;
10
+ }
11
+ interface MintDeviceCredentialOptions {
12
+ gatewayOrigin: string;
13
+ bearer: string;
14
+ platform: string;
15
+ workerId: string;
16
+ label: string;
17
+ }
18
+ export declare class DeviceMintError extends Error {
19
+ readonly status: number;
20
+ readonly code?: string | undefined;
21
+ constructor(message: string, status: number, code?: string | undefined);
22
+ }
23
+ export declare function requireInstallationLogin(contextName: string): Promise<string>;
24
+ export declare function mintDeviceCredentialWithReauth({ contextName, initialBearerIsChild, initialChildExpiresAt, interactiveReauth, options, }: {
25
+ contextName: string;
26
+ initialBearerIsChild: boolean;
27
+ initialChildExpiresAt?: number;
28
+ interactiveReauth: boolean;
29
+ options: MintDeviceCredentialOptions;
30
+ }): Promise<MintedDeviceCredential>;
31
+ export declare function persistDeviceCredential(contextName: string, statePlatform: string, credential: MintedDeviceCredential): Promise<void>;
32
+ export declare function canPrompt(): boolean;
33
+ export {};
34
+ //# sourceMappingURL=device-credential.d.ts.map
@@ -0,0 +1,157 @@
1
+ import { getContextToken } from "../../internal/credentials.js";
2
+ import { loadDeviceState, saveDeviceState, updateDeviceState, } from "../../internal/device-state.js";
3
+ import { extractApiError, fetchWithRetry, parseJsonResponse, } from "../../internal/http.js";
4
+ import { loginCommand } from "../login.js";
5
+ export class DeviceMintError extends Error {
6
+ status;
7
+ code;
8
+ constructor(message, status, code) {
9
+ super(message);
10
+ this.status = status;
11
+ this.code = code;
12
+ this.name = "DeviceMintError";
13
+ }
14
+ }
15
+ const LOGIN_SETUP_MESSAGE = (contextName) => `This Lobu installation is not logged in. Run \`lobu login --force --context ${contextName}\` in an interactive terminal, then retry.`;
16
+ export async function requireInstallationLogin(contextName) {
17
+ const existing = await getContextToken(contextName);
18
+ if (existing)
19
+ return existing;
20
+ return refreshInstallationLogin(contextName);
21
+ }
22
+ async function refreshInstallationLogin(contextName) {
23
+ if (!canPrompt())
24
+ throw new Error(LOGIN_SETUP_MESSAGE(contextName));
25
+ // The stored credential is absent, expired, revoked, or predates the daemon's
26
+ // device_worker:run scope. Without --force `lobu login` can short-circuit on
27
+ // that same credential with "Already logged in" and authorize nothing.
28
+ await loginCommand({ context: contextName, force: true });
29
+ const authenticated = await getContextToken(contextName);
30
+ if (!authenticated)
31
+ throw new Error(LOGIN_SETUP_MESSAGE(contextName));
32
+ return authenticated;
33
+ }
34
+ export async function mintDeviceCredentialWithReauth({ contextName, initialBearerIsChild, initialChildExpiresAt, interactiveReauth, options, }) {
35
+ try {
36
+ return await mintDeviceCredential(options);
37
+ }
38
+ catch (error) {
39
+ if (!isDeviceMintAuthError(error))
40
+ throw error;
41
+ // Do not let OAuth silently undo revocation of a still-live child.
42
+ if (initialBearerIsChild) {
43
+ if (!interactiveReauth)
44
+ throw error;
45
+ if (typeof initialChildExpiresAt !== "number" ||
46
+ initialChildExpiresAt > Date.now()) {
47
+ throw new DeviceMintError("The stored device credential was rejected before its local expiry; refusing to replace a possibly revoked device automatically. Re-pair this device explicitly.", error.status, error.code);
48
+ }
49
+ const installationBearer = await requireInstallationLogin(contextName);
50
+ try {
51
+ return await mintDeviceCredential({
52
+ ...options,
53
+ bearer: installationBearer,
54
+ });
55
+ }
56
+ catch (loginError) {
57
+ if (!isDeviceMintAuthError(loginError))
58
+ throw loginError;
59
+ }
60
+ }
61
+ // A stored login can be valid for ordinary MCP work but lack the newer
62
+ // device_worker:run scope. Interactive starts repair it through the same
63
+ // device-code flow; non-interactive starts receive the exact login command.
64
+ if (!interactiveReauth)
65
+ throw error;
66
+ return mintDeviceCredential({
67
+ ...options,
68
+ bearer: await refreshInstallationLogin(contextName),
69
+ });
70
+ }
71
+ }
72
+ /**
73
+ * True only for a refusal that re-authenticating can actually clear: an expired
74
+ * or revoked bearer (401), or a bearer the endpoint refuses to mint from
75
+ * (`insufficient_scope` — a missing `device_worker:run`, an MCP resource-bound
76
+ * token, or a child reaching past its own worker id). Every other 403 is a
77
+ * standing account condition (`personal_org_missing`); retrying it would
78
+ * force-revoke a working login through `lobu login --force` and still fail.
79
+ */
80
+ function isDeviceMintAuthError(error) {
81
+ if (!(error instanceof DeviceMintError))
82
+ return false;
83
+ if (error.status === 401)
84
+ return true;
85
+ return error.status === 403 && error.code === "insufficient_scope";
86
+ }
87
+ async function mintDeviceCredential(options) {
88
+ const url = `${options.gatewayOrigin}/api/me/devices/mint-child-token`;
89
+ const res = await fetchWithRetry(url, {
90
+ method: "POST",
91
+ headers: {
92
+ Accept: "application/json",
93
+ Authorization: `Bearer ${options.bearer}`,
94
+ "Content-Type": "application/json",
95
+ "X-Lobu-Client": "cli",
96
+ },
97
+ body: JSON.stringify({
98
+ platform: options.platform,
99
+ worker_id: options.workerId,
100
+ label: options.label,
101
+ }),
102
+ });
103
+ const parsed = (await parseJsonResponse(res, url, (message) => {
104
+ throw new DeviceMintError(message, res.status);
105
+ }));
106
+ if (!res.ok) {
107
+ const { message, code } = extractApiError(parsed, res.status, res.statusText);
108
+ throw new DeviceMintError(`Could not authorize this device: ${message}`, res.status, code);
109
+ }
110
+ const workerId = typeof parsed?.worker_id === "string" ? parsed.worker_id : "";
111
+ const workerApiToken = typeof parsed?.access_token === "string" ? parsed.access_token : "";
112
+ const expiresAt = typeof parsed?.expires_at === "string"
113
+ ? Date.parse(parsed.expires_at)
114
+ : Number.NaN;
115
+ if (!workerId ||
116
+ !workerApiToken.startsWith("owl_pat_") ||
117
+ !Number.isFinite(expiresAt)) {
118
+ throw new DeviceMintError("The gateway returned an invalid device credential.", res.status);
119
+ }
120
+ const sessionToken = typeof parsed?.session_token === "string" && parsed.session_token
121
+ ? parsed.session_token
122
+ : undefined;
123
+ return {
124
+ workerId,
125
+ workerApiToken,
126
+ expiresAt,
127
+ ...(sessionToken ? { sessionToken } : {}),
128
+ };
129
+ }
130
+ export async function persistDeviceCredential(contextName, statePlatform, credential) {
131
+ const state = {
132
+ workerId: credential.workerId,
133
+ workerApiToken: credential.workerApiToken,
134
+ expiresAt: credential.expiresAt,
135
+ };
136
+ const existing = await loadDeviceState(contextName, statePlatform);
137
+ if (existing) {
138
+ await updateDeviceState(contextName, statePlatform, state);
139
+ return;
140
+ }
141
+ try {
142
+ await saveDeviceState(contextName, statePlatform, state);
143
+ }
144
+ catch (error) {
145
+ const winner = await loadDeviceState(contextName, statePlatform);
146
+ if (winner?.workerId !== state.workerId)
147
+ throw error;
148
+ await updateDeviceState(contextName, statePlatform, state);
149
+ }
150
+ }
151
+ export function canPrompt() {
152
+ const ci = process.env.CI?.trim().toLowerCase();
153
+ return (process.stdin.isTTY === true &&
154
+ process.stdout.isTTY === true &&
155
+ (!ci || ci === "0" || ci === "false"));
156
+ }
157
+ //# sourceMappingURL=device-credential.js.map
@@ -12,6 +12,17 @@ export interface DeviceWizardOptions {
12
12
  authorizationToken: string;
13
13
  prompts?: DeviceWizardPrompts;
14
14
  }
15
+ export interface RemoteDevice {
16
+ id: string;
17
+ worker_id: string;
18
+ platform: string | null;
19
+ online: boolean;
20
+ label?: string | null;
21
+ organization_slug?: string | null;
22
+ /** Stamped by the device's first poll; minting a credential leaves it unset. */
23
+ app_version?: string | null;
24
+ last_seen_at?: string | null;
25
+ }
15
26
  export interface DeviceWizardResult {
16
27
  workerId: string;
17
28
  source: "reused" | "created";
@@ -22,4 +33,10 @@ export interface DeviceWizardPrompts {
22
33
  input: (config: Parameters<typeof input>[0]) => Promise<string>;
23
34
  }
24
35
  export declare function deviceWizard(options: DeviceWizardOptions): Promise<DeviceWizardResult>;
36
+ /** `GET /api/me/devices` failed; `status` is the gateway's HTTP status. */
37
+ export declare class DeviceListError extends Error {
38
+ readonly status: number;
39
+ constructor(message: string, status: number);
40
+ }
41
+ export declare function fetchRemoteDevices(gatewayOrigin: string, token: string): Promise<RemoteDevice[]>;
25
42
  //# sourceMappingURL=device-wizard.d.ts.map
@@ -76,7 +76,16 @@ export async function deviceWizard(options) {
76
76
  console.log();
77
77
  return { workerId, source };
78
78
  }
79
- async function fetchRemoteDevices(gatewayOrigin, token) {
79
+ /** `GET /api/me/devices` failed; `status` is the gateway's HTTP status. */
80
+ export class DeviceListError extends Error {
81
+ status;
82
+ constructor(message, status) {
83
+ super(message);
84
+ this.status = status;
85
+ this.name = "DeviceListError";
86
+ }
87
+ }
88
+ export async function fetchRemoteDevices(gatewayOrigin, token) {
80
89
  const url = `${gatewayOrigin}/api/me/devices`;
81
90
  const res = await fetchWithRetry(url, {
82
91
  headers: { Authorization: `Bearer ${token}` },
@@ -86,7 +95,7 @@ async function fetchRemoteDevices(gatewayOrigin, token) {
86
95
  }));
87
96
  if (!res.ok) {
88
97
  const { message } = extractApiError(parsed, res.status, res.statusText);
89
- throw new Error(`Could not list devices: ${message}`);
98
+ throw new DeviceListError(`Could not list devices: ${message}`, res.status);
90
99
  }
91
100
  if (!Array.isArray(parsed?.devices)) {
92
101
  throw new Error("Could not list devices: gateway returned an invalid response");
@@ -0,0 +1,7 @@
1
+ export declare function encodeNativeMessage(value: unknown): Buffer;
2
+ /**
3
+ * Read the first framed message from `input`. Resolves to null when the stream
4
+ * ends before a complete message arrives (Chrome closed the port).
5
+ */
6
+ export declare function readNativeMessage(input: AsyncIterable<Buffer | string>): Promise<unknown>;
7
+ //# sourceMappingURL=native-messaging.d.ts.map
@@ -0,0 +1,40 @@
1
+ // Chrome native messaging framing: each message is UTF-8 JSON preceded by its
2
+ // byte length as a 32-bit unsigned integer in native byte order. Every
3
+ // platform `lobu browser` supports (macOS, Linux on x64/arm64) is
4
+ // little-endian. Chrome caps a host's replies at 1 MiB.
5
+ const MAX_REPLY_BYTES = 1024 * 1024;
6
+ /** The extension only ever sends small control messages. */
7
+ const MAX_REQUEST_BYTES = 1024 * 1024;
8
+ export function encodeNativeMessage(value) {
9
+ const body = Buffer.from(JSON.stringify(value), "utf8");
10
+ if (body.length > MAX_REPLY_BYTES) {
11
+ throw new Error("native message reply exceeds Chrome's 1 MiB limit");
12
+ }
13
+ const header = Buffer.alloc(4);
14
+ header.writeUInt32LE(body.length, 0);
15
+ return Buffer.concat([header, body]);
16
+ }
17
+ /**
18
+ * Read the first framed message from `input`. Resolves to null when the stream
19
+ * ends before a complete message arrives (Chrome closed the port).
20
+ */
21
+ export async function readNativeMessage(input) {
22
+ let buffered = Buffer.alloc(0);
23
+ for await (const chunk of input) {
24
+ buffered = Buffer.concat([
25
+ buffered,
26
+ typeof chunk === "string" ? Buffer.from(chunk) : chunk,
27
+ ]);
28
+ if (buffered.length < 4)
29
+ continue;
30
+ const length = buffered.readUInt32LE(0);
31
+ if (length > MAX_REQUEST_BYTES) {
32
+ throw new Error(`native message of ${length} bytes is too large`);
33
+ }
34
+ if (buffered.length < 4 + length)
35
+ continue;
36
+ return JSON.parse(buffered.subarray(4, 4 + length).toString("utf8"));
37
+ }
38
+ return null;
39
+ }
40
+ //# sourceMappingURL=native-messaging.js.map
@@ -0,0 +1,23 @@
1
+ export interface BrowserStartOptions {
2
+ context?: string;
3
+ headless?: boolean;
4
+ }
5
+ export declare function browserStartCommand(rawName: string, options: BrowserStartOptions): Promise<void>;
6
+ export declare function browserStopCommand(rawName: string): Promise<void>;
7
+ export declare function browserListCommand(options: {
8
+ json?: boolean;
9
+ }): Promise<void>;
10
+ export declare function browserRemoveCommand(rawName: string): Promise<void>;
11
+ /**
12
+ * The native host's answer to one extension message. A `pair` request gets a
13
+ * freshly minted device credential in the desktop bridge's reply shape; every
14
+ * other message (the extension also publishes ambient tab context to a desktop
15
+ * app, which a named browser does not have) is declined.
16
+ */
17
+ export declare function nativeHostReply(name: string, message: unknown, log: (line: string) => Promise<unknown>): Promise<Record<string, unknown>>;
18
+ /**
19
+ * Native messaging host Chrome starts for the extension's desktop pairing.
20
+ * stdout is the framed channel to Chrome, so every other line goes to a log.
21
+ */
22
+ export declare function browserNativeHostCommand(rawName: string): Promise<void>;
23
+ //# sourceMappingURL=browser.d.ts.map