@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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { log } from '../log.js';
|
|
3
|
+
import { reportTerminalFailure } from '../terminal-failure.js';
|
|
3
4
|
const FEED_READ_ACTION = '__lobu_feed_read';
|
|
4
5
|
const NATIVE_BRIDGE_HEARTBEAT_INTERVAL_MS = 30_000;
|
|
5
6
|
export const NATIVE_BRIDGE_EXECUTION_TIMEOUT_MS = 600_000;
|
|
@@ -8,7 +9,7 @@ export async function executeNativeBridgeRun(client, bridge, job, timeoutMs = NA
|
|
|
8
9
|
throw new Error('native bridge run is missing run_id');
|
|
9
10
|
const runId = job.run_id;
|
|
10
11
|
const requestId = randomUUID();
|
|
11
|
-
let
|
|
12
|
+
let currentOperation;
|
|
12
13
|
let itemsCollected = 0;
|
|
13
14
|
let checkpoint = asRecord(job.checkpoint);
|
|
14
15
|
let terminalDelivered = false;
|
|
@@ -70,8 +71,7 @@ export async function executeNativeBridgeRun(client, bridge, job, timeoutMs = NA
|
|
|
70
71
|
await deliverTerminal(() => client.completeAuth(payload));
|
|
71
72
|
};
|
|
72
73
|
try {
|
|
73
|
-
|
|
74
|
-
operation = currentOperation;
|
|
74
|
+
currentOperation = nativeOperation(job);
|
|
75
75
|
heartbeatInterval = setInterval(() => {
|
|
76
76
|
void client.heartbeat(runId).catch((error) => {
|
|
77
77
|
log.debug(`[native-bridge] Heartbeat for run ${runId} failed:`, error);
|
|
@@ -116,27 +116,32 @@ export async function executeNativeBridgeRun(client, bridge, job, timeoutMs = NA
|
|
|
116
116
|
catch (error) {
|
|
117
117
|
const message = error instanceof Error ? error.message : String(error);
|
|
118
118
|
log.info(`[native-bridge] Run ${runId} failed:`, message);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
119
|
+
if (terminalReporter !== undefined) {
|
|
120
|
+
// A success terminal was already selected but its delivery budget is
|
|
121
|
+
// exhausted. Its outcome is immutable: never flip an executed run to
|
|
122
|
+
// failed and drop its output — leave it for stale-run handling.
|
|
123
|
+
log.info(`[native-bridge] Terminal report for run ${runId} failed:`, message);
|
|
124
|
+
}
|
|
125
|
+
else if (currentOperation === 'sync' || currentOperation === 'auth') {
|
|
126
|
+
// No terminal was selected yet and the run is a sync/auth: keep its
|
|
127
|
+
// own completion, preserving the bounded retry and partial progress.
|
|
128
|
+
const complete = currentOperation === 'sync' ? completeSync : completeAuth;
|
|
129
|
+
try {
|
|
130
|
+
await complete({}, message);
|
|
131
|
+
}
|
|
132
|
+
catch (completionError) {
|
|
133
|
+
log.info(`[native-bridge] Terminal report for run ${runId} failed:`, completionError);
|
|
132
134
|
}
|
|
133
|
-
else if (job.run_type === 'embed_backfill')
|
|
134
|
-
await completeSync({}, message);
|
|
135
|
-
else
|
|
136
|
-
await completeAction({}, message);
|
|
137
135
|
}
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
else {
|
|
137
|
+
// No terminal was selected yet (bridge, stream, or timeout failure on
|
|
138
|
+
// any other run shape): report it under the run's own type.
|
|
139
|
+
try {
|
|
140
|
+
await reportTerminalFailure(client, job, message, 'error_message');
|
|
141
|
+
}
|
|
142
|
+
catch (completionError) {
|
|
143
|
+
log.info(`[native-bridge] Terminal report for run ${runId} failed:`, completionError);
|
|
144
|
+
}
|
|
140
145
|
}
|
|
141
146
|
return { itemsCollected, error: message };
|
|
142
147
|
}
|
|
@@ -165,9 +170,6 @@ async function runWithTimeout(bridge, requestId, runId, timeoutMs, run) {
|
|
|
165
170
|
}
|
|
166
171
|
}
|
|
167
172
|
function nativeOperation(job) {
|
|
168
|
-
if (job.run_type === 'automation' || job.run_type === 'embed_backfill') {
|
|
169
|
-
throw new Error('native bridge does not execute run_type ' + String(job.run_type));
|
|
170
|
-
}
|
|
171
173
|
if (job.run_type === 'sync')
|
|
172
174
|
return 'sync';
|
|
173
175
|
if (job.run_type === 'auth')
|
|
@@ -184,6 +186,8 @@ function bridgeJob(job) {
|
|
|
184
186
|
connector_key: job.connector_key,
|
|
185
187
|
connector_version: job.connector_version,
|
|
186
188
|
connector_manifest_hash: job.connector_manifest_hash,
|
|
189
|
+
source_attribution: job.source_attribution,
|
|
190
|
+
source_url: job.source_url,
|
|
187
191
|
feed_key: job.feed_key,
|
|
188
192
|
feed_id: job.feed_id,
|
|
189
193
|
config: job.config ?? {},
|
|
@@ -6,7 +6,7 @@ export declare const NATIVE_BRIDGE_MAX_INBOUND_FRAMES = 128;
|
|
|
6
6
|
export declare const NATIVE_BRIDGE_MAX_OUTBOUND_FRAMES = 128;
|
|
7
7
|
export declare const NATIVE_BRIDGE_MAX_OUTBOUND_FRAMES_PER_RUN = 32;
|
|
8
8
|
export declare const NATIVE_BRIDGE_MAX_RETAINED_RUN_KEYS = 128;
|
|
9
|
-
export declare const NATIVE_BRIDGE_KINDS: readonly ["hello", "hello_ack", "run", "cancel", "shutdown", "ping", "stream", "complete", "failed", "capabilities", "diagnostic"];
|
|
9
|
+
export declare const NATIVE_BRIDGE_KINDS: readonly ["hello", "hello_ack", "run", "cancel", "shutdown", "ping", "stream", "complete", "failed", "capabilities", "diagnostic", "activity"];
|
|
10
10
|
export type NativeBridgeKind = (typeof NATIVE_BRIDGE_KINDS)[number];
|
|
11
11
|
export interface NativeBridgeFrame {
|
|
12
12
|
version: number;
|
|
@@ -20,6 +20,8 @@ export interface WorkerPollLoopOptions {
|
|
|
20
20
|
beforeIdlePoll?: () => Promise<void>;
|
|
21
21
|
/** Persisted device credentials treat poll-time revocation as terminal. */
|
|
22
22
|
failClosedOnPollAuthError?: boolean;
|
|
23
|
+
/** Called with the new count each time a run starts or finishes. */
|
|
24
|
+
onActiveJobsChange?: (activeJobs: number) => void;
|
|
23
25
|
}
|
|
24
26
|
export type WorkerPollLoopExit = (code: number) => void;
|
|
25
27
|
export interface WorkerPollLoopSignalOptions {
|
|
@@ -35,6 +37,7 @@ export declare class WorkerPollLoop {
|
|
|
35
37
|
private readonly execute;
|
|
36
38
|
private readonly beforeIdlePoll?;
|
|
37
39
|
private readonly failClosedOnPollAuthError;
|
|
40
|
+
private readonly onActiveJobsChange?;
|
|
38
41
|
private running;
|
|
39
42
|
private admittingJobs;
|
|
40
43
|
private activeJobs;
|
|
@@ -19,6 +19,7 @@ export class WorkerPollLoop {
|
|
|
19
19
|
execute;
|
|
20
20
|
beforeIdlePoll;
|
|
21
21
|
failClosedOnPollAuthError;
|
|
22
|
+
onActiveJobsChange;
|
|
22
23
|
running = false;
|
|
23
24
|
admittingJobs = true;
|
|
24
25
|
activeJobs = 0;
|
|
@@ -35,6 +36,7 @@ export class WorkerPollLoop {
|
|
|
35
36
|
this.execute = options.execute;
|
|
36
37
|
this.beforeIdlePoll = options.beforeIdlePoll;
|
|
37
38
|
this.failClosedOnPollAuthError = options.failClosedOnPollAuthError === true;
|
|
39
|
+
this.onActiveJobsChange = options.onActiveJobsChange;
|
|
38
40
|
}
|
|
39
41
|
async start() {
|
|
40
42
|
if (this.running) {
|
|
@@ -46,7 +48,7 @@ export class WorkerPollLoop {
|
|
|
46
48
|
}
|
|
47
49
|
if (!this.admittingJobs)
|
|
48
50
|
return;
|
|
49
|
-
log.info(
|
|
51
|
+
log.info(`[daemon] Starting worker daemon (max concurrent jobs: ${this.maxConcurrentJobs})...`);
|
|
50
52
|
this.running = true;
|
|
51
53
|
while (this.running) {
|
|
52
54
|
if (this.activeJobs === 0)
|
|
@@ -135,6 +137,7 @@ export class WorkerPollLoop {
|
|
|
135
137
|
return undefined;
|
|
136
138
|
}
|
|
137
139
|
this.activeJobs++;
|
|
140
|
+
this.onActiveJobsChange?.(this.activeJobs);
|
|
138
141
|
Promise.resolve()
|
|
139
142
|
.then(() => this.execute(job))
|
|
140
143
|
.catch((err) => {
|
|
@@ -142,6 +145,7 @@ export class WorkerPollLoop {
|
|
|
142
145
|
})
|
|
143
146
|
.finally(() => {
|
|
144
147
|
this.activeJobs--;
|
|
148
|
+
this.onActiveJobsChange?.(this.activeJobs);
|
|
145
149
|
this.capacityVersion++;
|
|
146
150
|
this.wakePoll?.(true);
|
|
147
151
|
});
|
|
@@ -30,6 +30,7 @@ export declare function resolveDaemonLaunchContext(opts: Pick<DaemonStartOptions
|
|
|
30
30
|
platform: string | undefined;
|
|
31
31
|
interactiveSession: InteractiveSession | undefined;
|
|
32
32
|
};
|
|
33
|
+
export declare function resolveDaemonMaxConcurrentJobs(platform: string | undefined, env?: NodeJS.ProcessEnv, hostThreads?: number): number | undefined;
|
|
33
34
|
/**
|
|
34
35
|
* Validate the options and boot the daemon. Throws a user-facing `Error` on
|
|
35
36
|
* bad input; the caller prints it and exits non-zero.
|
|
@@ -11,17 +11,12 @@ import { CONNECTOR_HTTP_AUTH_CAPABILITY, EXECUTION_BACKENDS, } from '@lobu/core/
|
|
|
11
11
|
import { assertExternalDepsResolvable } from '../compile/index.js';
|
|
12
12
|
import { buildConnectorWorkerEnv } from '../env.js';
|
|
13
13
|
import { assertConnectorRuntimeLoadable } from '../self-check/index.js';
|
|
14
|
+
import { defaultDeviceMaxConcurrentJobs } from './device-concurrency.js';
|
|
14
15
|
import { DEVICE_MANIFESTS_BY_PLATFORM } from './device-manifests.js';
|
|
15
16
|
import { startDaemon } from './index.js';
|
|
16
17
|
import { log, setDebug } from './log.js';
|
|
17
18
|
import { attachInteractiveSession, deriveInteractiveWorkerId, detectInteractiveSession, } from './interactive-session.js';
|
|
18
|
-
|
|
19
|
-
* Accepted `--worker-id` shape. Deliberately narrow: the default is
|
|
20
|
-
* `<platform>:<short-hostname>` (or a session-derived id in a supported
|
|
21
|
-
* interactive agent), and anything a shell, a URL path, or a JSON payload
|
|
22
|
-
* would mangle has no business being a durable device identity.
|
|
23
|
-
*/
|
|
24
|
-
const WORKER_ID_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
19
|
+
import { assertValidWorkerId } from './worker-id.js';
|
|
25
20
|
export function resolveDaemonWorkerId(opts, platform, shortHostname, interactiveSession) {
|
|
26
21
|
return (opts.workerId ??
|
|
27
22
|
(interactiveSession
|
|
@@ -50,6 +45,14 @@ export function resolveDaemonLaunchContext(opts, env = process.env, sessionsDir)
|
|
|
50
45
|
interactiveSession: detected,
|
|
51
46
|
};
|
|
52
47
|
}
|
|
48
|
+
export function resolveDaemonMaxConcurrentJobs(platform, env = process.env, hostThreads) {
|
|
49
|
+
const configured = env.WORKER_MAX_CONCURRENT_JOBS
|
|
50
|
+
? Math.max(1, Number.parseInt(env.WORKER_MAX_CONCURRENT_JOBS, 10))
|
|
51
|
+
: undefined;
|
|
52
|
+
if (configured !== undefined && Number.isFinite(configured))
|
|
53
|
+
return configured;
|
|
54
|
+
return platform ? defaultDeviceMaxConcurrentJobs(hostThreads) : undefined;
|
|
55
|
+
}
|
|
53
56
|
/**
|
|
54
57
|
* Validate the options and boot the daemon. Throws a user-facing `Error` on
|
|
55
58
|
* bad input; the caller prints it and exits non-zero.
|
|
@@ -63,14 +66,8 @@ export async function startDaemonCommand(opts) {
|
|
|
63
66
|
if (platform && !isKnownPlatform(platform)) {
|
|
64
67
|
throw new Error(`unknown device platform '${platform}'`);
|
|
65
68
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// An unusable value therefore does not fail loudly — it mints a second device
|
|
69
|
-
// and the pinned Automations go quiet on this one. Reject it at boot instead.
|
|
70
|
-
if (opts.workerId !== undefined && !WORKER_ID_PATTERN.test(opts.workerId)) {
|
|
71
|
-
throw new Error(`invalid --worker-id '${opts.workerId}': expected 1-128 characters of ` +
|
|
72
|
-
'letters, digits, dot, underscore, colon or hyphen');
|
|
73
|
-
}
|
|
69
|
+
if (opts.workerId !== undefined)
|
|
70
|
+
assertValidWorkerId(opts.workerId);
|
|
74
71
|
if (capabilities.length > 0 && !platform) {
|
|
75
72
|
throw new Error('--capabilities requires --platform so the server can authorize the device capability set');
|
|
76
73
|
}
|
|
@@ -138,11 +135,9 @@ export async function startDaemonCommand(opts) {
|
|
|
138
135
|
};
|
|
139
136
|
log.info(`[cli] Starting worker daemon (ID: ${workerId}, API: ${opts.apiUrl})`);
|
|
140
137
|
const env = buildConnectorWorkerEnv();
|
|
141
|
-
const maxConcurrentJobs =
|
|
142
|
-
? Math.max(1, Number.parseInt(process.env.WORKER_MAX_CONCURRENT_JOBS, 10))
|
|
143
|
-
: undefined;
|
|
138
|
+
const maxConcurrentJobs = resolveDaemonMaxConcurrentJobs(platform);
|
|
144
139
|
if (platform) {
|
|
145
|
-
log.info(`[cli] device mode: platform=${platform} capabilities=${capabilities.join(',') || '(none)'}`);
|
|
140
|
+
log.info(`[cli] device mode: platform=${platform} capabilities=${capabilities.join(',') || '(none)'} max_concurrent_jobs=${maxConcurrentJobs}`);
|
|
146
141
|
if (opts.activeOrg) {
|
|
147
142
|
const deviceUrl = `${opts.apiUrl.replace(/\/+$/, '')}/${encodeURIComponent(opts.activeOrg)}/connectors/device/${encodeURIComponent(workerId)}`;
|
|
148
143
|
log.info(`[cli] Manage action permissions (Approval vs Auto) at: ${deviceUrl}`);
|
|
@@ -160,7 +155,7 @@ export async function startDaemonCommand(opts) {
|
|
|
160
155
|
...(platform ? { platform } : {}),
|
|
161
156
|
...(label ? { label } : {}),
|
|
162
157
|
...(platform ? { manifests: DEVICE_MANIFESTS_BY_PLATFORM[platform] ?? [] } : {}),
|
|
163
|
-
...(
|
|
158
|
+
...(maxConcurrentJobs ? { maxConcurrentJobs } : {}),
|
|
164
159
|
backendCapacity,
|
|
165
160
|
...(opts.workerCredentialMaintenance
|
|
166
161
|
? { workerCredentialMaintenance: opts.workerCredentialMaintenance }
|
|
@@ -20,17 +20,6 @@ export async function reportTerminalFailure(client, job, message, exitReason = '
|
|
|
20
20
|
});
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
if (job.run_type === 'chat_message') {
|
|
24
|
-
// Device chat completes through its adapter so the waiting Activity turn
|
|
25
|
-
// receives a thread_response. Generic sync completion would finalize the
|
|
26
|
-
// row without publishing that response.
|
|
27
|
-
await client.completeDeviceChat(job.run_id, {
|
|
28
|
-
worker_id: client.id,
|
|
29
|
-
error: message,
|
|
30
|
-
exit_reason: exitReason,
|
|
31
|
-
});
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
23
|
if (job.run_type === 'agent_turn') {
|
|
35
24
|
// The generic route refuses an agent turn with a 409, so a failure that
|
|
36
25
|
// fell through to it would leave the run parked until the stale sweep.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared device-daemon worker-id shape.
|
|
3
|
+
*
|
|
4
|
+
* Accepted `--worker-id` shape. Deliberately narrow: the default is
|
|
5
|
+
* `<platform>:<short-hostname>` (or a session-derived id in a supported
|
|
6
|
+
* interactive agent), and anything a shell, a URL path, or a JSON payload
|
|
7
|
+
* would mangle has no business being a durable device identity.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* `worker_id` is the device's identity: the server upserts on
|
|
11
|
+
* (user_id, worker_id) and Automation pins resolve the device row through it.
|
|
12
|
+
* An unusable value therefore does not fail loudly — it mints a second device
|
|
13
|
+
* and the pinned Automations go quiet on this one. Reject it at boot instead.
|
|
14
|
+
*/
|
|
15
|
+
export declare const WORKER_ID_PATTERN: RegExp;
|
|
16
|
+
export declare function assertValidWorkerId(workerId: string): void;
|
|
17
|
+
//# sourceMappingURL=worker-id.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared device-daemon worker-id shape.
|
|
3
|
+
*
|
|
4
|
+
* Accepted `--worker-id` shape. Deliberately narrow: the default is
|
|
5
|
+
* `<platform>:<short-hostname>` (or a session-derived id in a supported
|
|
6
|
+
* interactive agent), and anything a shell, a URL path, or a JSON payload
|
|
7
|
+
* would mangle has no business being a durable device identity.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* `worker_id` is the device's identity: the server upserts on
|
|
11
|
+
* (user_id, worker_id) and Automation pins resolve the device row through it.
|
|
12
|
+
* An unusable value therefore does not fail loudly — it mints a second device
|
|
13
|
+
* and the pinned Automations go quiet on this one. Reject it at boot instead.
|
|
14
|
+
*/
|
|
15
|
+
export const WORKER_ID_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
16
|
+
export function assertValidWorkerId(workerId) {
|
|
17
|
+
if (!WORKER_ID_PATTERN.test(workerId)) {
|
|
18
|
+
throw new Error(`invalid --worker-id '${workerId}': expected 1-128 characters of ` +
|
|
19
|
+
'letters, digits, dot, underscore, colon or hyphen');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=worker-id.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { ConnectorOperationRequest, ConnectorOperationResult } from '@lobu/connector-sdk';
|
|
1
2
|
import type { AgentTurnEvent, AgentTurnInput, AgentTurnOutput, AgentTurnSteer, RuntimeExecRequest, RuntimeExecResult } from '../agent-turn/types.js';
|
|
2
|
-
import type { AuthResult, ConnectorWebhookSchema, EventEnvelope, QueryContext, SyncCredentials, WebhookRegistration } from '@lobu/connector-sdk';
|
|
3
|
+
import type { AuthResult, ConnectorBrowserRequirement, ConnectorWebhookSchema, EventEnvelope, FeedReadMatch, QueryContext, SyncCredentials, WebhookRegistration } from '@lobu/connector-sdk';
|
|
3
4
|
import type { ConnectorHttpRequest, ConnectorHttpResponse } from '@lobu/core/contracts/worker/protocol';
|
|
4
5
|
/**
|
|
5
6
|
* Executor mode discriminator. The executor speaks the same V1 SDK shapes
|
|
@@ -7,6 +8,8 @@ import type { ConnectorHttpRequest, ConnectorHttpResponse } from '@lobu/core/con
|
|
|
7
8
|
* in, `SyncResult` / `ActionResult` / `AuthResult` out, no envelope.
|
|
8
9
|
*/
|
|
9
10
|
export type ExecutorJob = {
|
|
11
|
+
/** Gateway-issued resource grant; not connector config. */
|
|
12
|
+
browser?: ConnectorBrowserRequirement;
|
|
10
13
|
/** HTTP credentials stay in the gateway; every fetch uses the host hook. */
|
|
11
14
|
httpAuth?: boolean;
|
|
12
15
|
} & ({
|
|
@@ -28,6 +31,16 @@ export type ExecutorJob = {
|
|
|
28
31
|
credentials: SyncCredentials | null;
|
|
29
32
|
sessionState: Record<string, unknown> | null;
|
|
30
33
|
env: Record<string, string | undefined>;
|
|
34
|
+
} | {
|
|
35
|
+
/** Listener setup only; records are delivered by the browser notification transport. */
|
|
36
|
+
mode: 'observe';
|
|
37
|
+
feedId: number;
|
|
38
|
+
feedKey: string;
|
|
39
|
+
checkpoint: Record<string, unknown> | null;
|
|
40
|
+
config: Record<string, unknown>;
|
|
41
|
+
credentials: SyncCredentials | null;
|
|
42
|
+
sessionState: Record<string, unknown> | null;
|
|
43
|
+
env: Record<string, string | undefined>;
|
|
31
44
|
} | {
|
|
32
45
|
mode: 'authenticate';
|
|
33
46
|
config: Record<string, unknown>;
|
|
@@ -37,6 +50,7 @@ export type ExecutorJob = {
|
|
|
37
50
|
mode: 'query';
|
|
38
51
|
query: string;
|
|
39
52
|
exactMatch?: QueryContext['exactMatch'];
|
|
53
|
+
selection?: QueryContext['selection'];
|
|
40
54
|
config: Record<string, unknown>;
|
|
41
55
|
credentials: SyncCredentials | null;
|
|
42
56
|
sessionState: Record<string, unknown> | null;
|
|
@@ -67,6 +81,7 @@ export type ExecutorJob = {
|
|
|
67
81
|
column: string;
|
|
68
82
|
order: 'asc' | 'desc';
|
|
69
83
|
};
|
|
84
|
+
match?: FeedReadMatch;
|
|
70
85
|
} | {
|
|
71
86
|
mode: 'webhook_register';
|
|
72
87
|
config: Record<string, unknown>;
|
|
@@ -81,6 +96,15 @@ export type ExecutorJob = {
|
|
|
81
96
|
credentials: SyncCredentials | null;
|
|
82
97
|
sessionState: Record<string, unknown> | null;
|
|
83
98
|
env: Record<string, string | undefined>;
|
|
99
|
+
} | {
|
|
100
|
+
mode: 'webhook_record';
|
|
101
|
+
feedKey: string;
|
|
102
|
+
eventType: string;
|
|
103
|
+
payload: unknown;
|
|
104
|
+
receivedAt: string;
|
|
105
|
+
/** The feed instance config only. */
|
|
106
|
+
config: Record<string, unknown>;
|
|
107
|
+
env: Record<string, string | undefined>;
|
|
84
108
|
} | {
|
|
85
109
|
mode: 'webhook_unregister';
|
|
86
110
|
config: Record<string, unknown>;
|
|
@@ -96,6 +120,8 @@ export type ExecutorJob = {
|
|
|
96
120
|
* connector commits them, never collected onto the result.
|
|
97
121
|
*/
|
|
98
122
|
export type ExecutorResult = {
|
|
123
|
+
mode: 'observe';
|
|
124
|
+
} | {
|
|
99
125
|
mode: 'sync';
|
|
100
126
|
/** How the pass ended; see the SDK's `SyncResult.status`. */
|
|
101
127
|
status: 'complete' | 'more';
|
|
@@ -118,6 +144,7 @@ export type ExecutorResult = {
|
|
|
118
144
|
} | {
|
|
119
145
|
mode: 'read';
|
|
120
146
|
rows: Record<string, unknown>[];
|
|
147
|
+
rowCursors?: string[];
|
|
121
148
|
columns?: {
|
|
122
149
|
name: string;
|
|
123
150
|
type: string;
|
|
@@ -145,6 +172,9 @@ export type ExecutorResult = {
|
|
|
145
172
|
} | {
|
|
146
173
|
mode: 'agent_turn';
|
|
147
174
|
turn: AgentTurnOutput;
|
|
175
|
+
} | {
|
|
176
|
+
mode: 'webhook_record';
|
|
177
|
+
event: EventEnvelope | null;
|
|
148
178
|
} | {
|
|
149
179
|
mode: 'webhook_unregister';
|
|
150
180
|
};
|
|
@@ -189,7 +219,7 @@ export interface ExecutionHooks {
|
|
|
189
219
|
}) => Promise<Record<string, unknown>>;
|
|
190
220
|
/**
|
|
191
221
|
* Sync runs: connector code invoked
|
|
192
|
-
* `ctx.
|
|
222
|
+
* `ctx.browser.dispatch(actionKey, actionInput)`.
|
|
193
223
|
* The host (connector-worker daemon) forwards the call to the gateway
|
|
194
224
|
* (POST /api/workers/dispatch-chrome-action), which inserts a chrome
|
|
195
225
|
* connector action run, waits for the paired Owletto extension to claim
|
|
@@ -197,6 +227,8 @@ export interface ExecutionHooks {
|
|
|
197
227
|
* reject when no extension is reachable.
|
|
198
228
|
*/
|
|
199
229
|
onChromeDispatch?: (actionKey: string, actionInput: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
230
|
+
/** Action runs: delegate through the existing operation admission and device execution path. */
|
|
231
|
+
onOperationExecute?: (request: ConnectorOperationRequest) => Promise<ConnectorOperationResult>;
|
|
200
232
|
}
|
|
201
233
|
/**
|
|
202
234
|
* Pluggable executor interface. The canonical implementation is `IsolateExecutor`;
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* requires a Node builtin is rejected before any isolate work with
|
|
24
24
|
* `IsolateLaneIneligibleError`.
|
|
25
25
|
*/
|
|
26
|
+
import { BROWSER_VERIFY_OPERATION, constrainBrowserInput } from '@lobu/connector-sdk';
|
|
26
27
|
import net from 'node:net';
|
|
27
28
|
import tls from 'node:tls';
|
|
28
29
|
import { decideEgress } from '@lobu/connector-sdk/egress-policy';
|
|
@@ -30,6 +31,7 @@ import { isReservedIp, stripIpv6Brackets } from '@lobu/connector-sdk/ip-reachabi
|
|
|
30
31
|
import { normalizeDomainPattern } from '@lobu/core';
|
|
31
32
|
import { CredentialVault } from '../egress/credentials.js';
|
|
32
33
|
import { CONNECTOR_HTTP_MAX_BYTES } from '@lobu/core/contracts/worker/protocol';
|
|
34
|
+
import { isConnectorOperationRequest } from '@lobu/core/contracts/tools/manage-operations';
|
|
33
35
|
import { EgressDispatcher, fetchPublicUrl, MalformedHostError, parseExemptHosts, PrivateAddressError, resolveEgressAddresses, } from '../egress/transport.js';
|
|
34
36
|
import { IsolateHost, IsolateHostError } from '../isolate/bridge.js';
|
|
35
37
|
import { assertIsolateEligible } from '../isolate/eligibility.js';
|
|
@@ -100,6 +102,12 @@ const GUEST_RUNNER = String.raw `
|
|
|
100
102
|
return null;
|
|
101
103
|
}
|
|
102
104
|
|
|
105
|
+
function operations() {
|
|
106
|
+
return { execute: function (request) {
|
|
107
|
+
return H.async('executeOperation', JSON.stringify(request)).then(function (json) { return JSON.parse(json); });
|
|
108
|
+
}};
|
|
109
|
+
}
|
|
110
|
+
|
|
103
111
|
function chromeDispatcher() {
|
|
104
112
|
return {
|
|
105
113
|
dispatch: function (actionKey, actionInput) {
|
|
@@ -110,12 +118,6 @@ const GUEST_RUNNER = String.raw `
|
|
|
110
118
|
};
|
|
111
119
|
}
|
|
112
120
|
|
|
113
|
-
function withDispatcher(sessionState) {
|
|
114
|
-
var out = Object.assign({}, sessionState || {});
|
|
115
|
-
out.chrome_dispatcher = chromeDispatcher();
|
|
116
|
-
return out;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
121
|
// One commit may carry more events than one bridge message should. Every
|
|
120
122
|
// chunk but the last travels without a checkpoint, so the cursor moves only
|
|
121
123
|
// with the chunk that completes the page: an earlier chunk that lands alone
|
|
@@ -162,10 +164,16 @@ const GUEST_RUNNER = String.raw `
|
|
|
162
164
|
}
|
|
163
165
|
|
|
164
166
|
if (job.mode === 'action') {
|
|
167
|
+
if (job.actionKey === ${JSON.stringify(BROWSER_VERIFY_OPERATION)} && job.browser) {
|
|
168
|
+
var verified = await chromeDispatcher().dispatch(${JSON.stringify(BROWSER_VERIFY_OPERATION)}, {});
|
|
169
|
+
return { mode: 'action', output: verified };
|
|
170
|
+
}
|
|
165
171
|
var actionResult = await instance.execute({
|
|
172
|
+
operations: operations(),
|
|
166
173
|
actionKey: job.actionKey,
|
|
167
174
|
input: job.actionInput,
|
|
168
|
-
|
|
175
|
+
browser: job.browser ? chromeDispatcher() : undefined,
|
|
176
|
+
sessionState: Object.assign({}, job.sessionState || {}),
|
|
169
177
|
credentials: job.credentials,
|
|
170
178
|
config: mergedConfig
|
|
171
179
|
});
|
|
@@ -184,6 +192,18 @@ const GUEST_RUNNER = String.raw `
|
|
|
184
192
|
return { mode: 'webhook_register', registration: registration, webhookScheme: webhookScheme };
|
|
185
193
|
}
|
|
186
194
|
|
|
195
|
+
if (job.mode === 'webhook_record') {
|
|
196
|
+
var recordFeed = instance.definition && instance.definition.feeds && instance.definition.feeds[job.feedKey];
|
|
197
|
+
var recordWebhook = recordFeed && recordFeed.webhook;
|
|
198
|
+
if (!recordWebhook || recordWebhook.kind !== 'record' || typeof recordWebhook.normalize !== 'function') {
|
|
199
|
+
throw new Error("feed '" + job.feedKey + "' does not record webhook deliveries");
|
|
200
|
+
}
|
|
201
|
+
var recorded = await recordWebhook.normalize(job.payload, {
|
|
202
|
+
feedKey: job.feedKey, eventType: job.eventType, config: mergedConfig, receivedAt: job.receivedAt
|
|
203
|
+
});
|
|
204
|
+
return { mode: 'webhook_record', event: recorded || null };
|
|
205
|
+
}
|
|
206
|
+
|
|
187
207
|
if (job.mode === 'webhook_unregister') {
|
|
188
208
|
await instance.unregisterWebhook({
|
|
189
209
|
config: mergedConfig, credentials: job.credentials, sessionState: job.sessionState, externalId: job.externalId
|
|
@@ -192,25 +212,42 @@ const GUEST_RUNNER = String.raw `
|
|
|
192
212
|
}
|
|
193
213
|
|
|
194
214
|
if (job.mode === 'query') {
|
|
195
|
-
|
|
215
|
+
var queryCapabilities = instance.definition && instance.definition.queryCapabilities;
|
|
216
|
+
var supportsSelection = queryCapabilities && queryCapabilities.selection === true;
|
|
217
|
+
if (job.selection && (job.selection.search || (job.selection.filters && job.selection.filters.length)) && !supportsSelection) {
|
|
218
|
+
throw Object.assign(new Error('Connector does not support collection selection queries'), { status: 400 });
|
|
219
|
+
}
|
|
220
|
+
if (job.exactMatch && !(queryCapabilities && queryCapabilities.exactMatch === true)) {
|
|
196
221
|
throw Object.assign(new Error('Connector does not support exact-match queries'), { status: 400 });
|
|
197
222
|
}
|
|
198
223
|
var queryResult = await instance.query({
|
|
199
224
|
query: job.query, config: mergedConfig, credentials: job.credentials, sessionState: job.sessionState,
|
|
200
|
-
limit: job.limit, offset: job.offset, sort: job.sort, exactMatch: job.exactMatch
|
|
225
|
+
limit: job.limit, offset: job.offset, sort: job.sort, exactMatch: job.exactMatch, selection: supportsSelection ? job.selection : undefined
|
|
201
226
|
});
|
|
202
227
|
return { mode: 'query', rows: (queryResult && queryResult.rows) || [], columns: queryResult && queryResult.columns, total: queryResult && queryResult.total };
|
|
203
228
|
}
|
|
204
229
|
|
|
230
|
+
if (job.mode === 'observe') {
|
|
231
|
+
await instance.observe({
|
|
232
|
+
feedId: job.feedId, feedKey: job.feedKey, checkpoint: job.checkpoint,
|
|
233
|
+
config: mergedConfig, credentials: job.credentials, browser: job.browser ? chromeDispatcher() : undefined,
|
|
234
|
+
sessionState: Object.assign({}, job.sessionState || {}),
|
|
235
|
+
env: job.env
|
|
236
|
+
});
|
|
237
|
+
return { mode: 'observe' };
|
|
238
|
+
}
|
|
239
|
+
|
|
205
240
|
if (job.mode === 'read') {
|
|
206
241
|
var readResult = await instance.read({
|
|
207
242
|
feedId: job.feedId === null ? undefined : job.feedId, feedKey: job.feedKey, query: job.query, cursor: job.cursor,
|
|
208
243
|
window: job.window,
|
|
209
|
-
config: mergedConfig, credentials: job.credentials,
|
|
210
|
-
|
|
244
|
+
config: mergedConfig, credentials: job.credentials, browser: job.browser ? chromeDispatcher() : undefined,
|
|
245
|
+
sessionState: Object.assign({}, job.sessionState || {}),
|
|
246
|
+
limit: job.limit, offset: job.offset, sort: job.sort, match: job.match
|
|
211
247
|
});
|
|
212
248
|
return {
|
|
213
249
|
mode: 'read', rows: (readResult && readResult.rows) || [], columns: readResult && readResult.columns,
|
|
250
|
+
rowCursors: readResult && readResult.rowCursors,
|
|
214
251
|
total: readResult && readResult.total, nextCursor: readResult && readResult.nextCursor, hasMore: readResult && readResult.hasMore,
|
|
215
252
|
window: readResult && readResult.window
|
|
216
253
|
};
|
|
@@ -223,7 +260,8 @@ const GUEST_RUNNER = String.raw `
|
|
|
223
260
|
checkpoint: job.checkpoint,
|
|
224
261
|
credentials: job.credentials,
|
|
225
262
|
entityIds: job.entityIds,
|
|
226
|
-
|
|
263
|
+
browser: job.browser ? chromeDispatcher() : undefined,
|
|
264
|
+
sessionState: Object.assign({}, job.sessionState || {}),
|
|
227
265
|
commit: commit
|
|
228
266
|
});
|
|
229
267
|
// A commit the connector fired without awaiting still belongs to this pass.
|
|
@@ -730,9 +768,22 @@ export class IsolateExecutor {
|
|
|
730
768
|
});
|
|
731
769
|
return JSON.stringify(signal ?? {});
|
|
732
770
|
},
|
|
771
|
+
executeOperation: async (requestJson) => {
|
|
772
|
+
if (job.mode !== 'action' || !hooks?.onOperationExecute) {
|
|
773
|
+
throw new Error('Connector operations are not available in this execution context');
|
|
774
|
+
}
|
|
775
|
+
if (hooks.signal?.aborted)
|
|
776
|
+
throw new Error('Connector operation cancelled');
|
|
777
|
+
const request = parseGuestJson(requestJson, 'executeOperation');
|
|
778
|
+
if (!isConnectorOperationRequest(request))
|
|
779
|
+
throw new Error('Invalid connector operation request');
|
|
780
|
+
return JSON.stringify(await hooks.onOperationExecute(request));
|
|
781
|
+
},
|
|
733
782
|
dispatchChromeAction: async (actionKey, inputJson) => {
|
|
783
|
+
if (!job.browser)
|
|
784
|
+
throw new Error('Browser access was not granted for this connection');
|
|
734
785
|
if (!hooks?.onChromeDispatch) {
|
|
735
|
-
throw new Error('
|
|
786
|
+
throw new Error('ctx.browser is not available in this execution context (no onChromeDispatch hook)');
|
|
736
787
|
}
|
|
737
788
|
const parsed = parseGuestJson(inputJson, 'dispatchChromeAction');
|
|
738
789
|
const input = parsed && typeof parsed === 'object' ? parsed : {};
|
|
@@ -740,12 +791,12 @@ export class IsolateExecutor {
|
|
|
740
791
|
let timer;
|
|
741
792
|
const timeoutPromise = new Promise((_, reject) => {
|
|
742
793
|
timer = setTimeout(() => {
|
|
743
|
-
reject(new Error(`
|
|
794
|
+
reject(new Error(`ctx.browser.dispatch('${keyStr}') exceeded 120000ms; IPC may be wedged`));
|
|
744
795
|
}, 120_000);
|
|
745
796
|
});
|
|
746
797
|
try {
|
|
747
798
|
const output = await Promise.race([
|
|
748
|
-
hooks.onChromeDispatch(keyStr, input),
|
|
799
|
+
hooks.onChromeDispatch(keyStr, constrainBrowserInput(job.browser, keyStr, input)),
|
|
749
800
|
timeoutPromise,
|
|
750
801
|
]);
|
|
751
802
|
return JSON.stringify(output ?? {});
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* real credential into the runs table. Add new patterns here when a connector
|
|
6
6
|
* surfaces a new sensitive shape.
|
|
7
7
|
*/
|
|
8
|
+
export declare function isSecretOutputKey(key: string): boolean;
|
|
8
9
|
export declare function redactOutput(text: string): string;
|
|
9
10
|
/**
|
|
10
11
|
* Streaming redactor for live tee to parent stdout/stderr. Buffers up to the
|