@lobu/runtime-device 21.2.1 → 23.0.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 +91 -83
- package/npm-shrinkwrap.json +492 -438
- package/package.json +12 -2
- package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +1 -1
- package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +5 -6
- package/vendor/cli/dist/commands/_lib/apply/client.d.ts +1 -0
- package/vendor/cli/dist/commands/_lib/apply/client.js +26 -7
- package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +9 -1
- package/vendor/cli/dist/commands/_lib/apply/diff.d.ts +1 -0
- package/vendor/cli/dist/commands/_lib/apply/diff.js +46 -4
- package/vendor/cli/dist/commands/_lib/apply/map-config.js +18 -38
- package/vendor/cli/dist/commands/_lib/init-from-org/bootstrap.js +5 -17
- package/vendor/cli/dist/commands/init.d.ts +0 -2
- package/vendor/cli/dist/commands/init.js +0 -27
- package/vendor/cli/dist/commands/login.d.ts +17 -0
- package/vendor/cli/dist/commands/login.js +43 -17
- package/vendor/cli/dist/commands/memory/_lib/errors.d.ts +0 -8
- package/vendor/cli/dist/commands/memory/_lib/errors.js +0 -12
- package/vendor/cli/dist/commands/memory/_lib/mcp.js +6 -6
- package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +4 -10
- package/vendor/cli/dist/config/define.d.ts +21 -15
- package/vendor/cli/dist/config/define.js +2 -2
- package/vendor/cli/dist/connectors/README.md +21 -6
- package/vendor/cli/dist/connectors/_google/actions.ts +270 -0
- package/vendor/cli/dist/connectors/_google/discovery/calendar_v3.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/chat_v1.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/docs_v1.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/drive_v3.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/gmail_v1.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/people_v1.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/sheets_v4.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/tasks_v1.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/youtube_v3.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery.ts +442 -0
- package/vendor/cli/dist/connectors/_google/errors.ts +91 -0
- package/vendor/cli/dist/connectors/_google/list-feed.ts +223 -0
- package/vendor/cli/dist/connectors/_google/policies.ts +127 -0
- package/vendor/cli/dist/connectors/agentid.ts +43 -0
- package/vendor/cli/dist/connectors/chat-user-identity.ts +2 -1
- package/vendor/cli/dist/connectors/github-automation-events.ts +9 -0
- package/vendor/cli/dist/connectors/github-identity.ts +28 -3
- package/vendor/cli/dist/connectors/github.ts +101 -59
- package/vendor/cli/dist/connectors/google_calendar.ts +207 -719
- package/vendor/cli/dist/connectors/google_drive.ts +16 -2
- package/vendor/cli/dist/connectors/google_gmail.ts +52 -33
- package/vendor/cli/dist/connectors/herdr.ts +406 -0
- package/vendor/cli/dist/connectors/jira-helpers.ts +313 -0
- package/vendor/cli/dist/connectors/jira.ts +35 -227
- package/vendor/cli/dist/connectors/linear.ts +7 -4
- package/vendor/cli/dist/connectors/linkedin-browser-script.ts +13 -0
- package/vendor/cli/dist/connectors/linkedin-draft-page.js +104 -0
- package/vendor/cli/dist/connectors/linkedin-drafts.ts +73 -0
- package/vendor/cli/dist/connectors/linkedin-identity.ts +32 -0
- package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +1185 -0
- package/vendor/cli/dist/connectors/linkedin-inbox.ts +156 -0
- package/vendor/cli/dist/connectors/linkedin-like.ts +114 -0
- package/vendor/cli/dist/connectors/linkedin-takeout.ts +577 -0
- package/vendor/cli/dist/connectors/linkedin.ts +3998 -0
- package/vendor/cli/dist/connectors/postgres.ts +27 -2
- package/vendor/cli/dist/connectors/takeout-utils.ts +240 -0
- package/vendor/cli/dist/connectors/tiktok-inbox-page.js +230 -0
- package/vendor/cli/dist/connectors/tiktok-web-page.js +217 -0
- package/vendor/cli/dist/connectors/tiktok_web.ts +319 -0
- package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +285 -567
- package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +74 -455
- package/vendor/cli/dist/connectors/whatsapp-web-identity.ts +135 -0
- package/vendor/cli/dist/connectors/whatsapp_web.ts +159 -618
- package/vendor/cli/dist/connectors/x-dm-adapter.js +556 -0
- package/vendor/cli/dist/connectors/x-identity.ts +31 -2
- package/vendor/cli/dist/connectors/x.ts +539 -253
- package/vendor/cli/dist/index.js +1 -37
- package/vendor/cli/dist/internal/context.d.ts +10 -0
- package/vendor/cli/dist/internal/context.js +26 -16
- package/vendor/cli/dist/internal/node-version.d.ts +1 -1
- package/vendor/cli/dist/internal/node-version.js +1 -1
- package/vendor/cli/dist/internal/oauth.d.ts +3 -1
- package/vendor/cli/dist/internal/oauth.js +4 -3
- package/vendor/cli/dist/internal/runtime-components.d.ts +9 -0
- package/vendor/cli/dist/internal/runtime-components.js +67 -2
- package/vendor/cli/dist/mac-auth.js +17 -1
- package/vendor/cli/dist/providers.json +1 -1
- package/vendor/cli/dist/runtime-components.json +4 -4
- package/vendor/cli/dist/templates/AGENTS.md.tmpl +12 -5
- package/vendor/cli/dist/templates/README.md.tmpl +1 -1
- package/vendor/cli/dist/vendor/ora/.bun-tag-fde20e9a6df212fa +0 -0
- package/vendor/cli/dist/vendor/ora/index.d.ts +332 -0
- package/vendor/cli/dist/vendor/ora/index.js +424 -0
- package/vendor/cli/dist/vendor/ora/license +9 -0
- package/vendor/cli/dist/vendor/ora/package.json +64 -0
- package/vendor/cli/dist/vendor/ora/readme.md +329 -0
- package/vendor/cli/package.json +2 -2
- package/vendor/connector-sdk/dist/browser-handoff-banner.d.ts +39 -0
- package/vendor/connector-sdk/dist/browser-handoff-banner.js +175 -0
- package/vendor/connector-sdk/dist/browser-requirement.d.ts +36 -0
- package/vendor/connector-sdk/dist/browser-requirement.js +60 -0
- package/vendor/connector-sdk/dist/browser-source-read.d.ts +52 -0
- package/vendor/connector-sdk/dist/browser-source-read.js +107 -0
- package/vendor/connector-sdk/dist/connector-runtime.d.ts +3 -1
- package/vendor/connector-sdk/dist/connector-runtime.js +10 -0
- package/vendor/connector-sdk/dist/connector-types.d.ts +169 -45
- package/vendor/connector-sdk/dist/define-connector.d.ts +4 -2
- package/vendor/connector-sdk/dist/define-connector.js +3 -0
- package/vendor/connector-sdk/dist/index.d.ts +8 -2
- package/vendor/connector-sdk/dist/index.js +3 -0
- package/vendor/connector-sdk/dist/reaction-client-types.d.ts +16 -21
- package/vendor/connector-sdk/dist/reaction-client-types.typecheck.d.ts +5 -0
- package/vendor/connector-sdk/package.json +13 -1
- package/vendor/connector-worker/dist/agent-turn/guest-entry.js +43 -30
- package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +416 -330
- package/vendor/connector-worker/dist/agent-turn/memory.d.ts +3 -2
- package/vendor/connector-worker/dist/agent-turn/memory.js +3 -20
- package/vendor/connector-worker/dist/agent-turn/types.d.ts +3 -15
- package/vendor/connector-worker/dist/agent-turn/workspace.d.ts +2 -2
- package/vendor/connector-worker/dist/agent-turn/workspace.js +2 -4
- package/vendor/connector-worker/dist/daemon/action-monitor.d.ts +12 -0
- package/vendor/connector-worker/dist/daemon/action-monitor.js +25 -0
- package/vendor/connector-worker/dist/daemon/agent-turn.js +0 -9
- package/vendor/connector-worker/dist/daemon/automation.d.ts +4 -11
- package/vendor/connector-worker/dist/daemon/automation.js +6 -6
- package/vendor/connector-worker/dist/daemon/builtins/index.d.ts +12 -0
- package/vendor/connector-worker/dist/daemon/builtins/index.js +61 -1
- package/vendor/connector-worker/dist/daemon/builtins/os-shell.d.ts +2 -1
- package/vendor/connector-worker/dist/daemon/builtins/os-shell.js +40 -27
- package/vendor/connector-worker/dist/daemon/client.d.ts +6 -4
- package/vendor/connector-worker/dist/daemon/client.js +3 -3
- package/vendor/connector-worker/dist/daemon/device-concurrency.d.ts +8 -0
- package/vendor/connector-worker/dist/daemon/device-concurrency.js +13 -0
- package/vendor/connector-worker/dist/daemon/executor.d.ts +1 -1
- package/vendor/connector-worker/dist/daemon/executor.js +48 -120
- package/vendor/connector-worker/dist/daemon/log.d.ts +2 -0
- package/vendor/connector-worker/dist/daemon/log.js +23 -2
- package/vendor/connector-worker/dist/daemon/mac-device-daemon.d.ts +23 -6
- package/vendor/connector-worker/dist/daemon/mac-device-daemon.js +57 -23
- package/vendor/connector-worker/dist/daemon/native-bridge/client.d.ts +6 -0
- package/vendor/connector-worker/dist/daemon/native-bridge/client.js +15 -0
- package/vendor/connector-worker/dist/daemon/native-bridge/executor.js +29 -25
- package/vendor/connector-worker/dist/daemon/native-bridge/protocol.d.ts +1 -1
- package/vendor/connector-worker/dist/daemon/native-bridge/protocol.js +1 -0
- package/vendor/connector-worker/dist/daemon/poll-loop.d.ts +3 -0
- package/vendor/connector-worker/dist/daemon/poll-loop.js +5 -1
- package/vendor/connector-worker/dist/daemon/start.d.ts +1 -0
- package/vendor/connector-worker/dist/daemon/start.js +15 -20
- package/vendor/connector-worker/dist/daemon/terminal-failure.js +0 -11
- package/vendor/connector-worker/dist/daemon/worker-id.d.ts +17 -0
- package/vendor/connector-worker/dist/daemon/worker-id.js +22 -0
- package/vendor/connector-worker/dist/executor/interface.d.ts +34 -2
- package/vendor/connector-worker/dist/executor/isolate.js +66 -15
- package/vendor/connector-worker/dist/executor/redact.d.ts +1 -0
- package/vendor/connector-worker/dist/executor/redact.js +97 -26
- package/vendor/connector-worker/dist/executor/runtime.d.ts +7 -0
- package/vendor/connector-worker/dist/executor/runtime.js +26 -0
- package/vendor/connector-worker/dist/isolate/bridge.js +3 -1
- package/vendor/connector-worker/dist/mac-device-daemon.js +24 -29
- package/vendor/connector-worker/package.json +2 -2
- package/vendor/core/dist/agent-policy.js +1 -1
- package/vendor/core/dist/agent-store.d.ts +2 -0
- package/vendor/core/dist/agent-tooling.d.ts +1 -1
- package/vendor/core/dist/agent-tooling.js +1 -1
- package/vendor/core/dist/capabilities.d.ts +1 -1
- package/vendor/core/dist/capabilities.js +2 -1
- package/vendor/core/dist/connector-query-errors.d.ts +32 -0
- package/vendor/core/dist/connector-query-errors.js +41 -1
- package/vendor/core/dist/contracts/agent-settings.d.ts +0 -11
- package/vendor/core/dist/contracts/agent-settings.js +1 -7
- package/vendor/core/dist/contracts/tools/collection-presentation.d.ts +93 -0
- package/vendor/core/dist/contracts/tools/collection-presentation.js +88 -0
- package/vendor/core/dist/contracts/tools/collection-selection.d.ts +47 -0
- package/vendor/core/dist/contracts/tools/collection-selection.js +74 -0
- package/vendor/core/dist/contracts/tools/manage-agents.d.ts +10 -4
- package/vendor/core/dist/contracts/tools/manage-auth-profiles.d.ts +1 -1
- package/vendor/core/dist/contracts/tools/manage-auth-profiles.js +5 -1
- package/vendor/core/dist/contracts/tools/manage-automations.d.ts +19 -4
- package/vendor/core/dist/contracts/tools/manage-automations.js +25 -8
- package/vendor/core/dist/contracts/tools/manage-connections.d.ts +1 -0
- package/vendor/core/dist/contracts/tools/manage-connections.js +3 -0
- package/vendor/core/dist/contracts/tools/manage-conversations.js +2 -2
- package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +11 -0
- package/vendor/core/dist/contracts/tools/manage-entity-schema.js +42 -3
- package/vendor/core/dist/contracts/tools/manage-entity.d.ts +181 -152
- package/vendor/core/dist/contracts/tools/manage-entity.js +118 -162
- package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +14 -0
- package/vendor/core/dist/contracts/tools/manage-feeds.js +17 -0
- package/vendor/core/dist/contracts/tools/manage-operations.d.ts +41 -3
- package/vendor/core/dist/contracts/tools/manage-operations.js +40 -2
- package/vendor/core/dist/contracts/tools/manage-views.d.ts +182 -7
- package/vendor/core/dist/contracts/tools/manage-views.js +49 -13
- package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +11 -2
- package/vendor/core/dist/contracts/tools/read-knowledge.js +23 -3
- package/vendor/core/dist/contracts/tools/save-memory.d.ts +3 -6
- package/vendor/core/dist/contracts/tools/save-memory.js +2 -6
- package/vendor/core/dist/contracts/tools/view-attach.d.ts +2 -1
- package/vendor/core/dist/contracts/tools/view-attach.js +7 -2
- package/vendor/core/dist/contracts/worker/protocol.d.ts +130 -159
- package/vendor/core/dist/contracts/worker/protocol.js +88 -76
- package/vendor/core/dist/device-pin-tombstones.d.ts +44 -0
- package/vendor/core/dist/device-pin-tombstones.js +57 -0
- package/vendor/core/dist/index.d.ts +5 -5
- package/vendor/core/dist/index.js +4 -6
- package/vendor/core/dist/json-template.d.ts +6 -10
- package/vendor/core/dist/json-template.js +5 -9
- package/vendor/core/dist/logger.js +17 -26
- package/vendor/core/dist/shell-safety.d.ts +9 -0
- package/vendor/core/dist/shell-safety.js +154 -0
- package/vendor/core/dist/suggestions.d.ts +1 -1
- package/vendor/core/dist/suggestions.js +1 -1
- package/vendor/core/dist/tool-trace-summary.d.ts +1 -1
- package/vendor/core/dist/tool-trace-summary.js +1 -1
- package/vendor/core/dist/types.d.ts +1 -3
- package/vendor/core/dist/utils/diagnostic-scrubber.d.ts +7 -0
- package/vendor/core/dist/utils/diagnostic-scrubber.js +437 -0
- package/vendor/core/dist/worker/auth.d.ts +44 -6
- package/vendor/core/dist/worker/auth.js +44 -11
- package/vendor/core/dist/worker/wire.d.ts +0 -10
- package/vendor/core/package.json +20 -11
- package/vendor/ora/.bun-tag-fde20e9a6df212fa +0 -0
- package/vendor/ora/index.d.ts +332 -0
- package/vendor/ora/index.js +424 -0
- package/vendor/ora/license +9 -0
- package/vendor/ora/package.json +53 -0
- package/vendor/ora/readme.md +329 -0
- package/vendor/cli/dist/commands/telemetry.d.ts +0 -10
- package/vendor/cli/dist/commands/telemetry.js +0 -66
- package/vendor/connector-worker/dist/daemon/device-chat.d.ts +0 -9
- package/vendor/connector-worker/dist/daemon/device-chat.js +0 -61
- package/vendor/core/dist/contracts/worker/device-chat.d.ts +0 -4
- package/vendor/core/dist/contracts/worker/device-chat.js +0 -26
- package/vendor/core/dist/sentry.d.ts +0 -26
- package/vendor/core/dist/sentry.js +0 -133
- package/vendor/core/dist/tool-policy.d.ts +0 -74
- package/vendor/core/dist/tool-policy.js +0 -305
- package/vendor/core/dist/utils/sentry-scrubber.d.ts +0 -29
- package/vendor/core/dist/utils/sentry-scrubber.js +0 -228
|
@@ -4,15 +4,17 @@
|
|
|
4
4
|
* Executes sync and action runs in a V8 isolate from compiled connector code.
|
|
5
5
|
* Generates embeddings and streams results.
|
|
6
6
|
*/
|
|
7
|
+
import { validateBrowserRequirement } from '@lobu/connector-sdk';
|
|
7
8
|
import { stableStringify } from '@lobu/core/contracts/tools/view-content-hash';
|
|
8
9
|
import { executeAutomationRun } from './automation.js';
|
|
9
|
-
import {
|
|
10
|
+
import { monitorActionRun } from './action-monitor.js';
|
|
11
|
+
import { executeDaemonBuiltinActionRun, hasDaemonBuiltin, hasDaemonBuiltinConnector, } from './builtins/index.js';
|
|
10
12
|
import { executeAgentTurnRun } from './agent-turn.js';
|
|
11
|
-
import { executeDeviceChatRun } from './device-chat.js';
|
|
12
13
|
import { attachedInteractiveSession, attachInteractiveSession } from './interactive-session.js';
|
|
13
14
|
import { log } from './log.js';
|
|
14
15
|
import { reportTerminalFailure } from './terminal-failure.js';
|
|
15
16
|
import { completeActionOnce } from './terminal-delivery.js';
|
|
17
|
+
import { envelopeToContentItem } from '../executor/runtime.js';
|
|
16
18
|
import { withoutDeploymentProviderKeys } from '../env.js';
|
|
17
19
|
export async function resolveJobCode(job) {
|
|
18
20
|
if (job.compiled_code)
|
|
@@ -77,7 +79,20 @@ async function resolveJobExecution(select, job, timeoutMs, customExecutor) {
|
|
|
77
79
|
return { ok: true, code: codeResult.code, executor: customExecutor };
|
|
78
80
|
}
|
|
79
81
|
try {
|
|
80
|
-
const executor = await select.selectExecutor({
|
|
82
|
+
const executor = await select.selectExecutor({
|
|
83
|
+
timeoutMs,
|
|
84
|
+
logSink: (level, line) => {
|
|
85
|
+
const context = { run_id: job.run_id, connector_key: job.connector_key, source: 'connector' };
|
|
86
|
+
if (level === 'error')
|
|
87
|
+
log.error(context, line);
|
|
88
|
+
else if (level === 'warn')
|
|
89
|
+
log.warn(context, line);
|
|
90
|
+
else if (level === 'debug')
|
|
91
|
+
log.debug(context, line);
|
|
92
|
+
else
|
|
93
|
+
log.info(context, line);
|
|
94
|
+
},
|
|
95
|
+
});
|
|
81
96
|
return { ok: true, code: codeResult.code, executor };
|
|
82
97
|
}
|
|
83
98
|
catch (err) {
|
|
@@ -176,7 +191,7 @@ export async function executeRun(client, job, workerEnv, config = {}) {
|
|
|
176
191
|
await reportTerminalFailure(client, job, message, 'error_message');
|
|
177
192
|
}
|
|
178
193
|
catch (error) {
|
|
179
|
-
log.
|
|
194
|
+
log.error('[executor] Failed to reject invalid daemon built-in run:', error);
|
|
180
195
|
}
|
|
181
196
|
return { itemsCollected: 0, error: message };
|
|
182
197
|
}
|
|
@@ -201,8 +216,6 @@ export async function executeRun(client, job, workerEnv, config = {}) {
|
|
|
201
216
|
// unreachable for them — but if a run does slip through (deploy skew), the
|
|
202
217
|
// dispatcher reports the failure rather than stomping the run.
|
|
203
218
|
return await executeAutomationRun(client, job, cfg);
|
|
204
|
-
case 'chat_message':
|
|
205
|
-
return await executeDeviceChatRun(client, job, cfg);
|
|
206
219
|
case 'agent_turn':
|
|
207
220
|
return await executeAgentTurnRun(client, job, env, cfg);
|
|
208
221
|
case 'embed_backfill':
|
|
@@ -215,12 +228,12 @@ export async function executeRun(client, job, workerEnv, config = {}) {
|
|
|
215
228
|
}
|
|
216
229
|
catch (error) {
|
|
217
230
|
const message = error instanceof Error ? error.message : String(error);
|
|
218
|
-
log.
|
|
231
|
+
log.error(`[executor] Unhandled ${job.run_type ?? 'unknown'} run ${job.run_id} failure:`, error);
|
|
219
232
|
try {
|
|
220
233
|
await reportTerminalFailure(client, job, message);
|
|
221
234
|
}
|
|
222
235
|
catch (completeErr) {
|
|
223
|
-
log.
|
|
236
|
+
log.error('[executor] Terminal completion after unhandled failure errored:', completeErr);
|
|
224
237
|
}
|
|
225
238
|
return { itemsCollected: 0, error: message };
|
|
226
239
|
}
|
|
@@ -237,7 +250,7 @@ async function executeSyncRun(client, job, env, cfg) {
|
|
|
237
250
|
const execution = await resolveJobExecution(select, job, cfg.timeoutMs, cfg.executor);
|
|
238
251
|
if (!execution.ok) {
|
|
239
252
|
const errorMessage = `Run ${run_id} (${connector_key}): ${execution.error}`;
|
|
240
|
-
log.
|
|
253
|
+
log.error('[executor]', errorMessage);
|
|
241
254
|
await client.complete({
|
|
242
255
|
run_id,
|
|
243
256
|
worker_id: client.id,
|
|
@@ -282,6 +295,7 @@ async function executeSyncRun(client, job, env, cfg) {
|
|
|
282
295
|
executor: laneExecutor,
|
|
283
296
|
job: {
|
|
284
297
|
mode: 'sync',
|
|
298
|
+
browser: validatedBrowserGrant(job.browser_grant),
|
|
285
299
|
httpAuth: job.http_auth,
|
|
286
300
|
config: mergeEnv(env, job.connection_credentials, feedConfig),
|
|
287
301
|
checkpoint: checkpoint,
|
|
@@ -348,7 +362,7 @@ async function executeSyncRun(client, job, env, cfg) {
|
|
|
348
362
|
catch (error) {
|
|
349
363
|
stopHeartbeat();
|
|
350
364
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
351
|
-
log.
|
|
365
|
+
log.error(`[executor] Sync run ${run_id} failed:`, error);
|
|
352
366
|
const diag = extractExecutionDiagnostics(error);
|
|
353
367
|
await client.complete({
|
|
354
368
|
run_id,
|
|
@@ -412,7 +426,7 @@ async function executeActionRun(client, job, env, cfg) {
|
|
|
412
426
|
const execution = await resolveJobExecution(select, job, cfg.timeoutMs, cfg.executor);
|
|
413
427
|
if (!execution.ok) {
|
|
414
428
|
const errorMessage = `Action run ${run_id} (${connector_key}): ${execution.error}`;
|
|
415
|
-
log.
|
|
429
|
+
log.error('[executor]', errorMessage);
|
|
416
430
|
await completeActionOnce(client, {
|
|
417
431
|
run_id,
|
|
418
432
|
worker_id: client.id,
|
|
@@ -424,21 +438,7 @@ async function executeActionRun(client, job, env, cfg) {
|
|
|
424
438
|
const compiled_code = execution.code;
|
|
425
439
|
const laneExecutor = execution.executor;
|
|
426
440
|
log.info(`[executor] Starting action run ${run_id} (${connector_key}/${action_key})`);
|
|
427
|
-
|
|
428
|
-
// mid-action. Action runs can legitimately take minutes (LLM calls,
|
|
429
|
-
// long Playwright sessions, third-party API rate-limit waits); the
|
|
430
|
-
// reaper's default threshold is 120s, so a 30s heartbeat gives ~3
|
|
431
|
-
// ticks of grace. Without this the row sits "running" until the worker
|
|
432
|
-
// process dies, and the lane was previously excluded from the reaper
|
|
433
|
-
// (lobu#859) because the heartbeat was missing.
|
|
434
|
-
const heartbeatInterval = setInterval(async () => {
|
|
435
|
-
try {
|
|
436
|
-
await client.heartbeat(run_id);
|
|
437
|
-
}
|
|
438
|
-
catch (err) {
|
|
439
|
-
log.debug('[executor] Action heartbeat failed:', err);
|
|
440
|
-
}
|
|
441
|
-
}, cfg.heartbeatIntervalMs);
|
|
441
|
+
const monitor = monitorActionRun(client, run_id, cfg);
|
|
442
442
|
let terminalPayloadStarted = false;
|
|
443
443
|
try {
|
|
444
444
|
const result = await executeCompiledConnector({
|
|
@@ -446,6 +446,7 @@ async function executeActionRun(client, job, env, cfg) {
|
|
|
446
446
|
executor: laneExecutor,
|
|
447
447
|
job: {
|
|
448
448
|
mode: 'action',
|
|
449
|
+
browser: validatedBrowserGrant(job.browser_grant),
|
|
449
450
|
httpAuth: job.http_auth,
|
|
450
451
|
// NOTE: unlike the gateway's inline action path (manage_operations
|
|
451
452
|
// `executeLocalActionInline`, which merges the connection's own config
|
|
@@ -466,7 +467,13 @@ async function executeActionRun(client, job, env, cfg) {
|
|
|
466
467
|
credentials: credentials ?? null,
|
|
467
468
|
},
|
|
468
469
|
hooks: {
|
|
470
|
+
signal: monitor.signal,
|
|
469
471
|
...(job.http_auth ? { onHttpFetch: (request, signal) => client.httpFetch(run_id, request, signal) } : {}),
|
|
472
|
+
onOperationExecute: async (request) => {
|
|
473
|
+
if (!client.executeConnectorOperation)
|
|
474
|
+
throw new Error('Connector operations are not available on this host');
|
|
475
|
+
return client.executeConnectorOperation({ parent_run_id: run_id, worker_id: client.id, request }, monitor.signal);
|
|
476
|
+
},
|
|
470
477
|
onChromeDispatch: async (actionKey, actionInput) => {
|
|
471
478
|
return client.dispatchChromeAction({
|
|
472
479
|
parent_run_id: run_id,
|
|
@@ -481,6 +488,8 @@ async function executeActionRun(client, job, env, cfg) {
|
|
|
481
488
|
throw new Error(`Expected action result, got mode=${result.mode}`);
|
|
482
489
|
}
|
|
483
490
|
const actionOutput = result.output;
|
|
491
|
+
if (monitor.revoked())
|
|
492
|
+
return { itemsCollected: 0 };
|
|
484
493
|
terminalPayloadStarted = true;
|
|
485
494
|
await completeActionOnce(client, {
|
|
486
495
|
run_id,
|
|
@@ -493,8 +502,8 @@ async function executeActionRun(client, job, env, cfg) {
|
|
|
493
502
|
}
|
|
494
503
|
catch (error) {
|
|
495
504
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
496
|
-
log.
|
|
497
|
-
if (terminalPayloadStarted) {
|
|
505
|
+
log.error(`[executor] Action run ${run_id} failed:`, error);
|
|
506
|
+
if (terminalPayloadStarted || monitor.revoked()) {
|
|
498
507
|
return { itemsCollected: 0, error: errorMessage };
|
|
499
508
|
}
|
|
500
509
|
await completeActionOnce(client, {
|
|
@@ -506,67 +515,7 @@ async function executeActionRun(client, job, env, cfg) {
|
|
|
506
515
|
return { itemsCollected: 0, error: errorMessage };
|
|
507
516
|
}
|
|
508
517
|
finally {
|
|
509
|
-
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
async function executeDaemonBuiltinActionRun(client, job, cfg) {
|
|
513
|
-
const { run_id, connector_key, action_key, action_input } = job;
|
|
514
|
-
if (!run_id || !connector_key || !action_key) {
|
|
515
|
-
throw new Error('Invalid daemon built-in action: missing run_id, connector_key, or action_key');
|
|
516
|
-
}
|
|
517
|
-
if (job.compiled_code) {
|
|
518
|
-
const message = 'operation_backend_unavailable: a daemon built-in payload must not contain compiled_code';
|
|
519
|
-
await completeActionOnce(client, {
|
|
520
|
-
run_id,
|
|
521
|
-
worker_id: client.id,
|
|
522
|
-
status: 'failed',
|
|
523
|
-
error_message: message,
|
|
524
|
-
});
|
|
525
|
-
return { itemsCollected: 0, error: message };
|
|
526
|
-
}
|
|
527
|
-
const heartbeatInterval = setInterval(async () => {
|
|
528
|
-
try {
|
|
529
|
-
await client.heartbeat(run_id);
|
|
530
|
-
}
|
|
531
|
-
catch (error) {
|
|
532
|
-
log.debug('[executor] Daemon built-in heartbeat failed:', error);
|
|
533
|
-
}
|
|
534
|
-
}, cfg.heartbeatIntervalMs);
|
|
535
|
-
try {
|
|
536
|
-
const result = await executeDaemonBuiltin({
|
|
537
|
-
connectorKey: connector_key,
|
|
538
|
-
actionKey: action_key,
|
|
539
|
-
input: (action_input ?? {}),
|
|
540
|
-
shutdownSignal: cfg.shutdownSignal,
|
|
541
|
-
});
|
|
542
|
-
if (!result.ok) {
|
|
543
|
-
const message = `${result.code}: ${result.error}`;
|
|
544
|
-
await completeActionOnce(client, {
|
|
545
|
-
run_id,
|
|
546
|
-
worker_id: client.id,
|
|
547
|
-
status: 'failed',
|
|
548
|
-
error_message: message,
|
|
549
|
-
...(result.output ? { action_output: result.output } : {}),
|
|
550
|
-
});
|
|
551
|
-
return { itemsCollected: 0, error: message };
|
|
552
|
-
}
|
|
553
|
-
await completeActionOnce(client, {
|
|
554
|
-
run_id,
|
|
555
|
-
worker_id: client.id,
|
|
556
|
-
status: 'success',
|
|
557
|
-
action_output: result.output,
|
|
558
|
-
});
|
|
559
|
-
return { itemsCollected: 0 };
|
|
560
|
-
}
|
|
561
|
-
catch (error) {
|
|
562
|
-
// Delivery uncertainty is not an execution failure. The immutable payload
|
|
563
|
-
// was retried above; never send a contradictory terminal result here.
|
|
564
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
565
|
-
log.info(`[executor] Daemon built-in terminal delivery uncertain for ${run_id}:`, message);
|
|
566
|
-
return { itemsCollected: 0, error: message };
|
|
567
|
-
}
|
|
568
|
-
finally {
|
|
569
|
-
clearInterval(heartbeatInterval);
|
|
518
|
+
monitor.stop();
|
|
570
519
|
}
|
|
571
520
|
}
|
|
572
521
|
/**
|
|
@@ -585,7 +534,7 @@ async function executeAuthRun(client, job, env, cfg) {
|
|
|
585
534
|
const execution = await resolveJobExecution(select, job, 0, cfg.executor);
|
|
586
535
|
if (!execution.ok) {
|
|
587
536
|
const errorMessage = `Auth run ${run_id} (${connector_key}): ${execution.error}`;
|
|
588
|
-
log.
|
|
537
|
+
log.error('[executor]', errorMessage);
|
|
589
538
|
await client.completeAuth({
|
|
590
539
|
run_id,
|
|
591
540
|
worker_id: client.id,
|
|
@@ -670,7 +619,7 @@ async function executeAuthRun(client, job, env, cfg) {
|
|
|
670
619
|
catch (error) {
|
|
671
620
|
clearInterval(heartbeatInterval);
|
|
672
621
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
673
|
-
log.
|
|
622
|
+
log.error(`[executor] Auth run ${run_id} failed:`, error);
|
|
674
623
|
const diag = extractExecutionDiagnostics(error);
|
|
675
624
|
try {
|
|
676
625
|
await client.completeAuth({
|
|
@@ -818,7 +767,7 @@ async function executeEmbedBackfillRun(client, job, _env, cfg) {
|
|
|
818
767
|
}
|
|
819
768
|
catch (error) {
|
|
820
769
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
821
|
-
log.
|
|
770
|
+
log.error(`[executor] Embed backfill run ${run_id} failed:`, error);
|
|
822
771
|
await client.complete({
|
|
823
772
|
run_id,
|
|
824
773
|
worker_id: client.id,
|
|
@@ -844,33 +793,6 @@ function mergeEnv(env, connectionCredentials, feedConfig) {
|
|
|
844
793
|
...(feedConfig ?? {}),
|
|
845
794
|
};
|
|
846
795
|
}
|
|
847
|
-
/**
|
|
848
|
-
* Convert a V1 EventEnvelope (the SDK's standard sync output) into the
|
|
849
|
-
* gateway-bound ContentItem shape (without an embedding).
|
|
850
|
-
*/
|
|
851
|
-
function toContentItem(event) {
|
|
852
|
-
const occurredAtIso = event.occurred_at instanceof Date
|
|
853
|
-
? event.occurred_at.toISOString()
|
|
854
|
-
: event.occurred_at;
|
|
855
|
-
return {
|
|
856
|
-
id: event.origin_id,
|
|
857
|
-
title: event.title,
|
|
858
|
-
payload_type: event.payload_type,
|
|
859
|
-
payload_text: event.payload_text,
|
|
860
|
-
payload_data: event.payload_data,
|
|
861
|
-
payload_template: event.payload_template,
|
|
862
|
-
attachments: event.attachments,
|
|
863
|
-
author_name: event.author_name,
|
|
864
|
-
occurred_at: occurredAtIso,
|
|
865
|
-
source_url: event.source_url ?? undefined,
|
|
866
|
-
score: typeof event.score === 'number' ? event.score : 0,
|
|
867
|
-
metadata: event.metadata ?? {},
|
|
868
|
-
origin_parent_id: event.origin_parent_id ?? undefined,
|
|
869
|
-
origin_type: event.origin_type,
|
|
870
|
-
semantic_type: event.semantic_type ?? event.origin_type,
|
|
871
|
-
automation_signals: event.automation_signals,
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
796
|
/**
|
|
875
797
|
* Convert a chunk of events into ContentItems, generating embeddings for the
|
|
876
798
|
* whole chunk in a single batch call (one HTTP round-trip / vectorized local
|
|
@@ -880,7 +802,7 @@ function toContentItem(event) {
|
|
|
880
802
|
* semantics as the previous per-event path).
|
|
881
803
|
*/
|
|
882
804
|
async function processEventChunk(events, generateEmbeddings) {
|
|
883
|
-
const contentItems = events.map(
|
|
805
|
+
const contentItems = events.map(envelopeToContentItem);
|
|
884
806
|
if (!generateEmbeddings || contentItems.length === 0) {
|
|
885
807
|
return contentItems;
|
|
886
808
|
}
|
|
@@ -918,4 +840,10 @@ async function processEventChunk(events, generateEmbeddings) {
|
|
|
918
840
|
}
|
|
919
841
|
return contentItems;
|
|
920
842
|
}
|
|
843
|
+
function validatedBrowserGrant(value) {
|
|
844
|
+
if (value == null)
|
|
845
|
+
return undefined;
|
|
846
|
+
validateBrowserRequirement(value);
|
|
847
|
+
return value;
|
|
848
|
+
}
|
|
921
849
|
//# sourceMappingURL=executor.js.map
|
|
@@ -10,6 +10,8 @@ export declare function setDebug(enabled: boolean): void;
|
|
|
10
10
|
export declare const log: {
|
|
11
11
|
/** Always-on: one line per run, startup/shutdown, and hard failures. */
|
|
12
12
|
info: (...parts: unknown[]) => void;
|
|
13
|
+
warn: (...parts: unknown[]) => void;
|
|
14
|
+
error: (...parts: unknown[]) => void;
|
|
13
15
|
/** Debug-only: poll chatter, heartbeats, retry and backoff detail. */
|
|
14
16
|
debug: (...parts: unknown[]) => void;
|
|
15
17
|
};
|
|
@@ -6,19 +6,40 @@
|
|
|
6
6
|
* the run's start and its terminal result — plus startup/shutdown and hard
|
|
7
7
|
* failures. Pass `--debug` to enable the poll/heartbeat/retry chatter.
|
|
8
8
|
*/
|
|
9
|
+
import { scrubDiagnosticValue } from '@lobu/core';
|
|
9
10
|
let debugEnabled = false;
|
|
11
|
+
function write(level, parts) {
|
|
12
|
+
let line;
|
|
13
|
+
try {
|
|
14
|
+
const record = scrubDiagnosticValue({
|
|
15
|
+
timestamp: new Date().toISOString(), level, service: 'lobu-worker',
|
|
16
|
+
release: process.env.APP_GIT_SHA,
|
|
17
|
+
message: parts.filter((part) => typeof part === 'string').join(' '),
|
|
18
|
+
data: parts.filter((part) => typeof part !== 'string'),
|
|
19
|
+
});
|
|
20
|
+
line = JSON.stringify(record, (_key, value) => typeof value === 'bigint' ? String(value) : value);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// A diagnostic must not prevent a run from reporting its terminal state.
|
|
24
|
+
line = JSON.stringify({ level, service: 'lobu-worker', message: 'Log record could not be serialized safely' });
|
|
25
|
+
}
|
|
26
|
+
// stderr is intentional: stdout belongs to the CLI's machine protocol.
|
|
27
|
+
console.error(line);
|
|
28
|
+
}
|
|
10
29
|
export function setDebug(enabled) {
|
|
11
30
|
debugEnabled = enabled;
|
|
12
31
|
}
|
|
13
32
|
export const log = {
|
|
14
33
|
/** Always-on: one line per run, startup/shutdown, and hard failures. */
|
|
15
34
|
info: (...parts) => {
|
|
16
|
-
|
|
35
|
+
write('info', parts);
|
|
17
36
|
},
|
|
37
|
+
warn: (...parts) => write('warn', parts),
|
|
38
|
+
error: (...parts) => write('error', parts),
|
|
18
39
|
/** Debug-only: poll chatter, heartbeats, retry and backoff detail. */
|
|
19
40
|
debug: (...parts) => {
|
|
20
41
|
if (debugEnabled)
|
|
21
|
-
|
|
42
|
+
write('debug', parts);
|
|
22
43
|
},
|
|
23
44
|
};
|
|
24
45
|
//# sourceMappingURL=log.js.map
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type AgentKind } from '@lobu/core/contracts/worker/device-automation';
|
|
2
2
|
import type { PollResponse } from '@lobu/core/contracts/worker/protocol';
|
|
3
|
-
import { MutableWorkerAdvertisementProvider } from './client.js';
|
|
3
|
+
import { MutableWorkerAdvertisementProvider, WorkerClient } from './client.js';
|
|
4
4
|
import { WorkerPollLoop } from './poll-loop.js';
|
|
5
5
|
import { NativeBridgeClient } from './native-bridge/client.js';
|
|
6
6
|
import { NATIVE_BRIDGE_PROTOCOL } from './native-bridge/protocol.js';
|
|
7
7
|
export declare const MAC_DEVICE_PLATFORM = "macos";
|
|
8
|
+
export type ValidatedMacDeviceDaemonOptions = Required<Pick<MacDeviceDaemonOptions, 'apiUrl' | 'workerId' | 'workerApiToken'>> & Omit<MacDeviceDaemonOptions, 'apiUrl' | 'workerId' | 'workerApiToken'>;
|
|
8
9
|
export declare const INTERNAL_ACP_ADAPTER_ARG = "--internal-acp-adapter";
|
|
9
10
|
export interface MacDeviceDaemonOptions {
|
|
10
11
|
apiUrl?: string;
|
|
@@ -25,6 +26,12 @@ export interface MacDeviceDaemonMetadata {
|
|
|
25
26
|
platform: typeof MAC_DEVICE_PLATFORM;
|
|
26
27
|
artifact: 'standalone-bun-macho-arm64';
|
|
27
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* EX_NOPERM: the server rejected the device credential (401/403). The app
|
|
31
|
+
* must resolve authorization instead of restarting with the same key.
|
|
32
|
+
*/
|
|
33
|
+
export declare const MAC_DAEMON_CREDENTIAL_REJECTED_EXIT = 77;
|
|
34
|
+
export declare function macDeviceDaemonExitCode(error: unknown): number;
|
|
28
35
|
export declare function macDeviceDaemonMetadata(version: string): MacDeviceDaemonMetadata;
|
|
29
36
|
/**
|
|
30
37
|
* Argv for re-entering this daemon's own entrypoint. A compiled artifact is its
|
|
@@ -34,9 +41,9 @@ export declare function macDeviceDaemonMetadata(version: string): MacDeviceDaemo
|
|
|
34
41
|
export declare function packagedDaemonArgs(...args: string[]): string[];
|
|
35
42
|
export declare function selectMacDeviceDaemonAgentKind(runnableAgentKinds: readonly AgentKind[], explicitAgentKind?: AgentKind): AgentKind | undefined;
|
|
36
43
|
export declare function createMacDeviceDaemonShutdown(controller: AbortController, loop: WorkerPollLoop, bridge?: NativeBridgeClient, shutdownTimeoutMs?: number): () => Promise<void>;
|
|
37
|
-
export declare function validateMacDeviceDaemonOptions(options: MacDeviceDaemonOptions
|
|
44
|
+
export declare function validateMacDeviceDaemonOptions(options: MacDeviceDaemonOptions, hostThreads?: number): ValidatedMacDeviceDaemonOptions;
|
|
38
45
|
/**
|
|
39
|
-
* Whether the
|
|
46
|
+
* Whether the app advertised a local implementation of this run's connector.
|
|
40
47
|
*
|
|
41
48
|
* The daemon answers from the inventory the Mac app itself declared over the
|
|
42
49
|
* bridge — the same manifests it advertises to the gateway — so what it will
|
|
@@ -46,14 +53,24 @@ export declare function validateMacDeviceDaemonOptions(options: MacDeviceDaemonO
|
|
|
46
53
|
* the contract's identity; a contract carrying its implementation cannot be
|
|
47
54
|
* shared with a second endpoint.
|
|
48
55
|
*
|
|
49
|
-
* A payload carrying `compiled_code` is not
|
|
56
|
+
* A payload carrying `compiled_code` is not local connector work: the
|
|
50
57
|
* gateway ships code only for connectors the device does NOT implement.
|
|
51
58
|
*/
|
|
52
59
|
export declare function bridgeImplementsRun(job: PollResponse, advertisementProvider: MutableWorkerAdvertisementProvider | undefined): boolean;
|
|
53
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Run a connector claim the app advertised. A daemon built-in (os.shell) runs
|
|
62
|
+
* here, with the built-in owning timeout, cancellation and process reaping.
|
|
63
|
+
* Everything else is native app work over the bridge.
|
|
64
|
+
*/
|
|
65
|
+
export declare function executeAdvertisedConnectorRun(client: WorkerClient, job: PollResponse, dependencies: {
|
|
66
|
+
advertisementProvider: MutableWorkerAdvertisementProvider | undefined;
|
|
67
|
+
bridge: NativeBridgeClient | undefined;
|
|
68
|
+
shutdownSignal?: AbortSignal;
|
|
69
|
+
}): Promise<unknown>;
|
|
70
|
+
export declare function createMacDeviceDaemon(options: ValidatedMacDeviceDaemonOptions, dependencies?: {
|
|
54
71
|
advertisementProvider?: MutableWorkerAdvertisementProvider;
|
|
55
72
|
bridge?: NativeBridgeClient;
|
|
56
73
|
shutdownController?: AbortController;
|
|
57
74
|
}): WorkerPollLoop;
|
|
58
|
-
export declare function runMacDeviceDaemon(options:
|
|
75
|
+
export declare function runMacDeviceDaemon(options: ValidatedMacDeviceDaemonOptions): Promise<void>;
|
|
59
76
|
//# sourceMappingURL=mac-device-daemon.d.ts.map
|
|
@@ -1,26 +1,36 @@
|
|
|
1
1
|
import { hostname } from 'node:os';
|
|
2
2
|
import { AGENT_KINDS, } from '@lobu/core/contracts/worker/device-automation';
|
|
3
3
|
import { executeAutomationRun } from './automation.js';
|
|
4
|
-
import {
|
|
4
|
+
import { executeDaemonBuiltinActionRun, hasDaemonBuiltin } from './builtins/index.js';
|
|
5
|
+
import { defaultDeviceMaxConcurrentJobs } from './device-concurrency.js';
|
|
5
6
|
import { locateBinary, resolveRunnableAgentKinds, supportsOpenCodeAcp, } from './agent-binaries.js';
|
|
6
|
-
import { MutableWorkerAdvertisementProvider, WorkerClient, } from './client.js';
|
|
7
|
+
import { MutableWorkerAdvertisementProvider, WorkerClient, WorkerHttpError, } from './client.js';
|
|
7
8
|
import { installWorkerPollLoopSignals, WorkerPollLoop } from './poll-loop.js';
|
|
8
9
|
import { setDebug } from './log.js';
|
|
9
10
|
import { NativeBridgeClient } from './native-bridge/client.js';
|
|
10
11
|
import { executeNativeBridgeRun } from './native-bridge/executor.js';
|
|
11
12
|
import { NATIVE_BRIDGE_PROTOCOL } from './native-bridge/protocol.js';
|
|
12
13
|
import { reportTerminalFailure } from './terminal-failure.js';
|
|
14
|
+
import { assertValidWorkerId } from './worker-id.js';
|
|
13
15
|
export const MAC_DEVICE_PLATFORM = 'macos';
|
|
14
|
-
const WORKER_ID_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
15
16
|
const WORKER_PAT_PATTERN = /^owl_pat_[A-Za-z0-9_-]{32}$/;
|
|
16
17
|
const DEFAULT_POLL_INTERVAL_MS = 10000;
|
|
17
18
|
// Source reads default to a ten-second end-to-end deadline. Keep the signed
|
|
18
19
|
// Mac daemon's claim latency well below that even when the server returns its
|
|
19
20
|
// normal ten-second idle hint.
|
|
20
21
|
const SOURCE_READ_IDLE_DELAY_CEILING_MS = 1000;
|
|
21
|
-
const DEFAULT_MAX_CONCURRENT_JOBS = 1;
|
|
22
22
|
const NATIVE_BRIDGE_SHUTDOWN_TIMEOUT_MS = 5000;
|
|
23
23
|
export const INTERNAL_ACP_ADAPTER_ARG = '--internal-acp-adapter';
|
|
24
|
+
/**
|
|
25
|
+
* EX_NOPERM: the server rejected the device credential (401/403). The app
|
|
26
|
+
* must resolve authorization instead of restarting with the same key.
|
|
27
|
+
*/
|
|
28
|
+
export const MAC_DAEMON_CREDENTIAL_REJECTED_EXIT = 77;
|
|
29
|
+
export function macDeviceDaemonExitCode(error) {
|
|
30
|
+
return error instanceof WorkerHttpError && (error.status === 401 || error.status === 403)
|
|
31
|
+
? MAC_DAEMON_CREDENTIAL_REJECTED_EXIT
|
|
32
|
+
: 1;
|
|
33
|
+
}
|
|
24
34
|
export function macDeviceDaemonMetadata(version) {
|
|
25
35
|
return {
|
|
26
36
|
name: 'lobu-device-daemon',
|
|
@@ -107,11 +117,9 @@ function withTimeout(promise, timeoutMs, label) {
|
|
|
107
117
|
});
|
|
108
118
|
});
|
|
109
119
|
}
|
|
110
|
-
export function validateMacDeviceDaemonOptions(options) {
|
|
120
|
+
export function validateMacDeviceDaemonOptions(options, hostThreads) {
|
|
111
121
|
const workerId = options.workerId?.trim() || defaultWorkerId();
|
|
112
|
-
|
|
113
|
-
throw new Error(`invalid --worker-id '${workerId}': expected 1-128 characters of letters, digits, dot, underscore, colon or hyphen`);
|
|
114
|
-
}
|
|
122
|
+
assertValidWorkerId(workerId);
|
|
115
123
|
const pollIntervalMs = validateNumber(options.pollIntervalMs, '--poll-interval-ms');
|
|
116
124
|
const maxConcurrentJobs = validateNumber(options.maxConcurrentJobs, '--max-concurrent-jobs');
|
|
117
125
|
const defaultAgentKind = validateAgentKind(options.defaultAgentKind);
|
|
@@ -151,7 +159,7 @@ export function validateMacDeviceDaemonOptions(options) {
|
|
|
151
159
|
workerId,
|
|
152
160
|
workerApiToken,
|
|
153
161
|
pollIntervalMs: pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS,
|
|
154
|
-
maxConcurrentJobs: maxConcurrentJobs ??
|
|
162
|
+
maxConcurrentJobs: maxConcurrentJobs ?? defaultDeviceMaxConcurrentJobs(hostThreads),
|
|
155
163
|
...(defaultAgentKind ? { defaultAgentKind } : {}),
|
|
156
164
|
};
|
|
157
165
|
}
|
|
@@ -164,7 +172,7 @@ async function rejectUnadvertisedConnector(client, job) {
|
|
|
164
172
|
await reportTerminalFailure(client, job, message, 'error_message');
|
|
165
173
|
}
|
|
166
174
|
/**
|
|
167
|
-
* Whether the
|
|
175
|
+
* Whether the app advertised a local implementation of this run's connector.
|
|
168
176
|
*
|
|
169
177
|
* The daemon answers from the inventory the Mac app itself declared over the
|
|
170
178
|
* bridge — the same manifests it advertises to the gateway — so what it will
|
|
@@ -174,7 +182,7 @@ async function rejectUnadvertisedConnector(client, job) {
|
|
|
174
182
|
* the contract's identity; a contract carrying its implementation cannot be
|
|
175
183
|
* shared with a second endpoint.
|
|
176
184
|
*
|
|
177
|
-
* A payload carrying `compiled_code` is not
|
|
185
|
+
* A payload carrying `compiled_code` is not local connector work: the
|
|
178
186
|
* gateway ships code only for connectors the device does NOT implement.
|
|
179
187
|
*/
|
|
180
188
|
export function bridgeImplementsRun(job, advertisementProvider) {
|
|
@@ -185,8 +193,31 @@ export function bridgeImplementsRun(job, advertisementProvider) {
|
|
|
185
193
|
manifest !== null &&
|
|
186
194
|
manifest.key === job.connector_key);
|
|
187
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Run a connector claim the app advertised. A daemon built-in (os.shell) runs
|
|
198
|
+
* here, with the built-in owning timeout, cancellation and process reaping.
|
|
199
|
+
* Everything else is native app work over the bridge.
|
|
200
|
+
*/
|
|
201
|
+
export async function executeAdvertisedConnectorRun(client, job, dependencies) {
|
|
202
|
+
if (!bridgeImplementsRun(job, dependencies.advertisementProvider)) {
|
|
203
|
+
return rejectUnadvertisedConnector(client, job);
|
|
204
|
+
}
|
|
205
|
+
if (job.run_type === 'action' &&
|
|
206
|
+
job.connector_key &&
|
|
207
|
+
job.action_key &&
|
|
208
|
+
hasDaemonBuiltin(job.connector_key, job.action_key)) {
|
|
209
|
+
return executeDaemonBuiltinActionRun(client, job, {
|
|
210
|
+
heartbeatIntervalMs: 30000,
|
|
211
|
+
...(dependencies.shutdownSignal ? { shutdownSignal: dependencies.shutdownSignal } : {}),
|
|
212
|
+
platform: 'macos',
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
if (!dependencies.bridge)
|
|
216
|
+
return rejectUnsupportedRun(client, job);
|
|
217
|
+
return executeNativeBridgeRun(client, dependencies.bridge, job);
|
|
218
|
+
}
|
|
188
219
|
export function createMacDeviceDaemon(options, dependencies = {}) {
|
|
189
|
-
const validated =
|
|
220
|
+
const validated = options;
|
|
190
221
|
if (validated.noPoll)
|
|
191
222
|
throw new Error('cannot create a polling daemon with --no-poll');
|
|
192
223
|
const discoveredAgentKinds = resolveRunnableAgentKinds();
|
|
@@ -271,21 +302,24 @@ export function createMacDeviceDaemon(options, dependencies = {}) {
|
|
|
271
302
|
pollIntervalMs: validated.pollIntervalMs,
|
|
272
303
|
maxIdleDelayMs: SOURCE_READ_IDLE_DELAY_CEILING_MS,
|
|
273
304
|
maxConcurrentJobs: validated.maxConcurrentJobs,
|
|
305
|
+
...(nativeBridge
|
|
306
|
+
? {
|
|
307
|
+
onActiveJobsChange: (activeJobs) => {
|
|
308
|
+
nativeBridge.reportActivity(activeJobs).catch(() => { });
|
|
309
|
+
},
|
|
310
|
+
}
|
|
311
|
+
: {}),
|
|
312
|
+
failClosedOnPollAuthError: true,
|
|
274
313
|
execute: async (job) => {
|
|
275
314
|
if (job.run_type === 'automation') {
|
|
276
315
|
return executeAutomationRun(client, job, automationConfig);
|
|
277
316
|
}
|
|
278
|
-
if (job.run_type === 'chat_message') {
|
|
279
|
-
return executeDeviceChatRun(client, job, automationConfig);
|
|
280
|
-
}
|
|
281
317
|
if (job.run_type === 'sync' || job.run_type === 'action' || job.run_type === 'auth') {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
return executeNativeBridgeRun(client, nativeBridge, job);
|
|
318
|
+
return executeAdvertisedConnectorRun(client, job, {
|
|
319
|
+
advertisementProvider: dependencies.advertisementProvider,
|
|
320
|
+
bridge: nativeBridge,
|
|
321
|
+
shutdownSignal: shutdownController.signal,
|
|
322
|
+
});
|
|
289
323
|
}
|
|
290
324
|
return rejectUnsupportedRun(client, job);
|
|
291
325
|
},
|
|
@@ -297,7 +331,7 @@ export function createMacDeviceDaemon(options, dependencies = {}) {
|
|
|
297
331
|
}
|
|
298
332
|
export async function runMacDeviceDaemon(options) {
|
|
299
333
|
setDebug(options.debug === true);
|
|
300
|
-
const validated =
|
|
334
|
+
const validated = options;
|
|
301
335
|
if (validated.noPoll)
|
|
302
336
|
return;
|
|
303
337
|
if (validated.supervisedStdio) {
|
|
@@ -37,6 +37,12 @@ export declare class NativeBridgeClient {
|
|
|
37
37
|
cancel(requestId: string, runId: number): Promise<void>;
|
|
38
38
|
cancelAndAbandon(requestId: string, runId: number, error: Error): Promise<void>;
|
|
39
39
|
cancelActiveRuns(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Tell the app how many runs this daemon is executing. The app holds staged
|
|
42
|
+
* updates while any are live: work the daemon runs itself (shell commands,
|
|
43
|
+
* Automations, chat) never passes through the app's own run table.
|
|
44
|
+
*/
|
|
45
|
+
reportActivity(activeRuns: number): Promise<void>;
|
|
40
46
|
shutdown(): Promise<void>;
|
|
41
47
|
close(error?: NativeBridgeProtocolError): void;
|
|
42
48
|
onTransportFailure(handler: (error: Error) => void): () => void;
|
|
@@ -144,6 +144,21 @@ export class NativeBridgeClient {
|
|
|
144
144
|
const cancellations = [...this.pending.values()].map((pending) => this.cancel(pending.requestId, pending.runId));
|
|
145
145
|
await Promise.allSettled(cancellations);
|
|
146
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Tell the app how many runs this daemon is executing. The app holds staged
|
|
149
|
+
* updates while any are live: work the daemon runs itself (shell commands,
|
|
150
|
+
* Automations, chat) never passes through the app's own run table.
|
|
151
|
+
*/
|
|
152
|
+
async reportActivity(activeRuns) {
|
|
153
|
+
if (!this.handshakeComplete || this.failure)
|
|
154
|
+
return;
|
|
155
|
+
await this.send({
|
|
156
|
+
version: NATIVE_BRIDGE_PROTOCOL_VERSION,
|
|
157
|
+
kind: 'activity',
|
|
158
|
+
request_id: randomUUID(),
|
|
159
|
+
payload: { active_runs: activeRuns },
|
|
160
|
+
});
|
|
161
|
+
}
|
|
147
162
|
async shutdown() {
|
|
148
163
|
if (!this.handshakeComplete || this.failure)
|
|
149
164
|
return;
|