@lobu/runtime-device 24.2.0 → 24.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +38 -124
  3. package/npm-shrinkwrap.json +169 -653
  4. package/package.json +1 -1
  5. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +6 -0
  6. package/vendor/cli/dist/commands/chat.d.ts +0 -12
  7. package/vendor/cli/dist/commands/chat.js +1 -1
  8. package/vendor/cli/dist/commands/daemon.js +36 -19
  9. package/vendor/cli/dist/commands/doctor.d.ts +0 -6
  10. package/vendor/cli/dist/commands/doctor.js +1 -1
  11. package/vendor/cli/dist/commands/memory/_lib/seed-cmd.d.ts +0 -8
  12. package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +1 -1
  13. package/vendor/cli/dist/config/define.d.ts +1 -1
  14. package/vendor/cli/dist/connectors/gchat.ts +31 -1
  15. package/vendor/cli/dist/connectors/postgres.ts +9 -5
  16. package/vendor/cli/dist/internal/cli-update-check.d.ts +33 -0
  17. package/vendor/cli/dist/internal/cli-update-check.js +98 -0
  18. package/vendor/cli/dist/internal/credentials.js +10 -36
  19. package/vendor/cli/dist/internal/gateway-url.d.ts +0 -8
  20. package/vendor/cli/dist/internal/gateway-url.js +1 -1
  21. package/vendor/cli/dist/runtime-components.json +4 -4
  22. package/vendor/cli/package.json +1 -1
  23. package/vendor/connector-sdk/dist/connector-types.d.ts +29 -0
  24. package/vendor/connector-sdk/dist/index.d.ts +3 -1
  25. package/vendor/connector-sdk/dist/index.js +4 -0
  26. package/vendor/connector-sdk/dist/redact.d.ts +10 -0
  27. package/vendor/{connector-worker/dist/executor → connector-sdk/dist}/redact.js +0 -49
  28. package/vendor/connector-sdk/dist/types.d.ts +2 -1
  29. package/vendor/connector-sdk/package.json +6 -1
  30. package/vendor/connector-worker/dist/daemon/acp-adapters/THIRD_PARTY_LICENSES.txt +1 -1
  31. package/vendor/connector-worker/dist/daemon/acp-adapters/claude.js +7339 -2136
  32. package/vendor/connector-worker/dist/daemon/automation.js +1 -1
  33. package/vendor/connector-worker/dist/daemon/client.d.ts +15 -1
  34. package/vendor/connector-worker/dist/daemon/client.js +51 -4
  35. package/vendor/connector-worker/dist/daemon/executor.d.ts +0 -28
  36. package/vendor/connector-worker/dist/daemon/executor.js +27 -12
  37. package/vendor/connector-worker/dist/daemon/index.d.ts +1 -1
  38. package/vendor/connector-worker/dist/daemon/index.js +1 -1
  39. package/vendor/connector-worker/dist/daemon/poll-loop.js +6 -1
  40. package/vendor/connector-worker/dist/daemon/start.d.ts +0 -1
  41. package/vendor/connector-worker/dist/daemon/start.js +1 -1
  42. package/vendor/connector-worker/dist/daemon/terminal-delivery.d.ts +1 -0
  43. package/vendor/connector-worker/dist/daemon/terminal-delivery.js +10 -6
  44. package/vendor/connector-worker/dist/executor/isolate.js +1 -1
  45. package/vendor/connector-worker/dist/isolate/bridge.d.ts +6 -2
  46. package/vendor/connector-worker/dist/isolate/bridge.js +14 -8
  47. package/vendor/connector-worker/package.json +2 -2
  48. package/vendor/core/dist/connector-query-errors.d.ts +6 -0
  49. package/vendor/core/dist/connector-query-errors.js +4 -0
  50. package/vendor/core/dist/contracts/tools/manage-automations.js +1 -1
  51. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +1 -1
  52. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +4 -0
  53. package/vendor/core/dist/contracts/tools/manage-entity.js +6 -0
  54. package/vendor/core/dist/contracts/worker/device-automation.d.ts +1 -1
  55. package/vendor/core/dist/contracts/worker/device-automation.js +1 -1
  56. package/vendor/core/dist/errors.d.ts +0 -20
  57. package/vendor/core/dist/errors.js +1 -25
  58. package/vendor/core/dist/otel.js +38 -10
  59. package/vendor/core/dist/utils/ajv.js +3 -1
  60. package/vendor/core/package.json +26 -5
  61. package/vendor/connector-worker/dist/executor/http-status.d.ts +0 -16
  62. package/vendor/connector-worker/dist/executor/http-status.js +0 -21
  63. package/vendor/connector-worker/dist/executor/redact.d.ts +0 -29
@@ -29,7 +29,7 @@ import { tmpdir } from 'node:os';
29
29
  import path from 'node:path';
30
30
  import { PROVIDER_BALANCE_EXHAUSTED } from '@lobu/core';
31
31
  import { buildDeviceAutomationPrompt, DEVICE_AGENT_SPECS_BY_KIND, } from '@lobu/core/contracts/worker/device-automation';
32
- import { redactOutput } from '../executor/redact.js';
32
+ import { redactOutput } from '@lobu/connector-sdk/redact';
33
33
  import { locateBinary, searchDirs } from './agent-binaries.js';
34
34
  import { releaseSupervisor, spawnSupervisedCli, terminateChild, waitForTargetExit, waitForTargetExitAfterTermination, } from './automation-process.js';
35
35
  import { WorkerHttpError } from './client.js';
@@ -97,7 +97,21 @@ export declare class MutableWorkerAdvertisementProvider implements WorkerAdverti
97
97
  export declare class WorkerHttpError extends Error {
98
98
  readonly status: number;
99
99
  readonly path: string;
100
- constructor(status: number, path: string, body: string);
100
+ /** The raw response body, for callers that read its structured error code. */
101
+ readonly responseBody?: string | undefined;
102
+ constructor(status: number, path: string, body: string,
103
+ /** The raw response body, for callers that read its structured error code. */
104
+ responseBody?: string | undefined);
105
+ }
106
+ /**
107
+ * The server refused this worker's poll with 409 `upgrade_required`: its
108
+ * reported version is below the server's MIN_CLIENT_VERSION floor. Retrying
109
+ * cannot help — the same binary sends the same version — so the poll loop
110
+ * treats this as terminal and the launcher tells the user how to update.
111
+ */
112
+ export declare class WorkerUpgradeRequiredError extends WorkerHttpError {
113
+ readonly description: string;
114
+ constructor(description: string);
101
115
  }
102
116
  /**
103
117
  * A 2xx body we could not read as a completion decision. The server answered,
@@ -56,13 +56,51 @@ function snapshotFingerprint(snapshot) {
56
56
  export class WorkerHttpError extends Error {
57
57
  status;
58
58
  path;
59
- constructor(status, path, body) {
59
+ responseBody;
60
+ constructor(status, path, body,
61
+ /** The raw response body, for callers that read its structured error code. */
62
+ responseBody) {
60
63
  super(`${path} failed: ${status} ${body.slice(0, 500)}`);
61
64
  this.status = status;
62
65
  this.path = path;
66
+ this.responseBody = responseBody;
63
67
  this.name = 'WorkerHttpError';
64
68
  }
65
69
  }
70
+ /**
71
+ * The server refused this worker's poll with 409 `upgrade_required`: its
72
+ * reported version is below the server's MIN_CLIENT_VERSION floor. Retrying
73
+ * cannot help — the same binary sends the same version — so the poll loop
74
+ * treats this as terminal and the launcher tells the user how to update.
75
+ */
76
+ export class WorkerUpgradeRequiredError extends WorkerHttpError {
77
+ description;
78
+ constructor(description) {
79
+ super(409, '/api/workers/poll', `upgrade_required: ${description}`);
80
+ this.description = description;
81
+ this.name = 'WorkerUpgradeRequiredError';
82
+ }
83
+ }
84
+ /** The poll refusal's description when a 409 carries `upgrade_required`, else null. */
85
+ function upgradeRequiredDescription(error) {
86
+ if (error.status !== 409 || !error.responseBody)
87
+ return null;
88
+ let body;
89
+ try {
90
+ body = JSON.parse(error.responseBody);
91
+ }
92
+ catch {
93
+ return null;
94
+ }
95
+ if (typeof body !== 'object' || body === null)
96
+ return null;
97
+ const { error: code, error_description: description } = body;
98
+ if (code !== 'upgrade_required')
99
+ return null;
100
+ return typeof description === 'string' && description.trim() !== ''
101
+ ? description
102
+ : 'This server requires a newer worker version';
103
+ }
66
104
  /**
67
105
  * A 2xx body we could not read as a completion decision. The server answered,
68
106
  * so re-sending would only mangle the same body — non-retriable.
@@ -155,7 +193,7 @@ export class WorkerClient {
155
193
  if (!response.ok) {
156
194
  const responseText = await response.text();
157
195
  const detail = `${response.statusText} ${responseText}`.trim();
158
- throw new WorkerHttpError(response.status, path, detail);
196
+ throw new WorkerHttpError(response.status, path, detail, responseText);
159
197
  }
160
198
  return response;
161
199
  }
@@ -175,7 +213,7 @@ export class WorkerClient {
175
213
  ? { ...this.advertisedCapabilities(), ...advertisement.capabilities }
176
214
  : this.advertisedCapabilities();
177
215
  const manifests = advertisement?.manifests ?? this.manifests;
178
- return this.requestJson('/api/workers/poll', {
216
+ const body = {
179
217
  worker_id: this.workerId,
180
218
  ...(options?.waitSeconds === undefined ? {} : { wait_seconds: options.waitSeconds }),
181
219
  capabilities,
@@ -200,7 +238,16 @@ export class WorkerClient {
200
238
  ...(this.advertisementProvider || manifests.length > 0
201
239
  ? { connector_manifests: manifests }
202
240
  : {}),
203
- }, options?.signal);
241
+ };
242
+ try {
243
+ return await this.requestJson('/api/workers/poll', body, options?.signal);
244
+ }
245
+ catch (error) {
246
+ const description = error instanceof WorkerHttpError ? upgradeRequiredDescription(error) : null;
247
+ if (description != null)
248
+ throw new WorkerUpgradeRequiredError(description);
249
+ throw error;
250
+ }
204
251
  }
205
252
  /**
206
253
  * Send heartbeat for active run
@@ -8,33 +8,6 @@ import type { Env } from '@lobu/connector-sdk';
8
8
  import type { AgentKind } from '@lobu/core/contracts/worker/device-automation';
9
9
  import { type ExecutorClient, type PollResponse } from './client.js';
10
10
  import type { SyncExecutor } from '../executor/interface.js';
11
- /**
12
- * Resolve the executable compiled code for a job.
13
- *
14
- * The gateway prefers omitting `compiled_code` for fleet workers and
15
- * relying on this side to find + compile the source locally from
16
- * `connector_key`. This saves the ~13 MB inline blob in poll responses
17
- * (lobu#771 postmortem trail; lobu#772 perf fix). Device workers and
18
- * DB-only user-uploaded connectors still receive `compiled_code`
19
- * directly — they don't have the connector source on disk.
20
- *
21
- * Gateway and worker images have different paths to the bundled source,
22
- * so the gateway sends only `connector_key` and each side resolves it
23
- * against its own filesystem.
24
- *
25
- * Returns `{ code }` on success or `{ error }` on failure. Callers must
26
- * surface the error to the gateway via `client.complete*` rather than
27
- * throwing — the daemon-level catch only logs, leaving runs stuck
28
- * `running` until stale-run reaping.
29
- */
30
- type JobCodeResult = {
31
- ok: true;
32
- code: string;
33
- } | {
34
- ok: false;
35
- error: string;
36
- };
37
- export declare function resolveJobCode(job: PollResponse): Promise<JobCodeResult>;
38
11
  export interface ExecutorConfig {
39
12
  heartbeatIntervalMs: number;
40
13
  /** Test-only override; production deliberately uses the 15-second default. */
@@ -100,5 +73,4 @@ export declare function executeRun(client: ExecutorClient, job: PollResponse, wo
100
73
  itemsCollected: number;
101
74
  error?: string;
102
75
  }>;
103
- export {};
104
76
  //# sourceMappingURL=executor.d.ts.map
@@ -13,10 +13,10 @@ import { executeAgentTurnRun } from './agent-turn.js';
13
13
  import { attachedInteractiveSession, attachInteractiveSession } from './interactive-session.js';
14
14
  import { log } from './log.js';
15
15
  import { reportTerminalFailure } from './terminal-failure.js';
16
- import { completeActionOnce } from './terminal-delivery.js';
16
+ import { completeActionOnce, completeSyncOnce } from './terminal-delivery.js';
17
17
  import { envelopeToContentItem } from '../executor/runtime.js';
18
18
  import { withoutDeploymentProviderKeys } from '../env.js';
19
- export async function resolveJobCode(job) {
19
+ async function resolveJobCode(job) {
20
20
  if (job.compiled_code)
21
21
  return { ok: true, code: job.compiled_code };
22
22
  // Inline compiled jobs must not load the optional compiler/SDK graph.
@@ -247,18 +247,32 @@ async function executeSyncRun(client, job, env, cfg) {
247
247
  if (!run_id || !connector_key) {
248
248
  throw new Error('Invalid run: missing run_id or connector_key');
249
249
  }
250
+ const deliver = async (payload, executionError) => {
251
+ try {
252
+ await completeSyncOnce(client, payload);
253
+ if (payload.status === 'success') {
254
+ log.info(`[executor] Sync run ${run_id} completed: ${payload.items_collected ?? 0} items`);
255
+ }
256
+ return { itemsCollected: payload.items_collected ?? 0, ...(executionError ? { error: executionError } : {}) };
257
+ }
258
+ catch (error) {
259
+ const message = error instanceof Error ? error.message : String(error);
260
+ log.error(`[executor] Sync run ${run_id} completion delivery failed:`, error);
261
+ return { itemsCollected: payload.items_collected ?? 0,
262
+ error: executionError ? `${executionError}; completion delivery failed: ${message}` : `Completion delivery failed: ${message}` };
263
+ }
264
+ };
250
265
  const execution = await resolveJobExecution(select, job, cfg.timeoutMs, cfg.executor);
251
266
  if (!execution.ok) {
252
267
  const errorMessage = `Run ${run_id} (${connector_key}): ${execution.error}`;
253
268
  log.error('[executor]', errorMessage);
254
- await client.complete({
269
+ return deliver({
255
270
  run_id,
256
271
  worker_id: client.id,
257
272
  status: 'failed',
258
273
  error_message: errorMessage,
259
274
  items_collected: 0,
260
- });
261
- return { itemsCollected: 0, error: errorMessage };
275
+ }, errorMessage);
262
276
  }
263
277
  const compiled_code = execution.code;
264
278
  const laneExecutor = execution.executor;
@@ -285,6 +299,8 @@ async function executeSyncRun(client, job, env, cfg) {
285
299
  }
286
300
  };
287
301
  startHeartbeat();
302
+ let terminalPayload;
303
+ let executionError;
288
304
  try {
289
305
  // The last checkpoint a commit made durable. Completion re-sends it so the
290
306
  // feed's `source_ack`, which only a successful completion may advance,
@@ -346,7 +362,7 @@ async function executeSyncRun(client, job, env, cfg) {
346
362
  throw new Error(`Expected sync result, got mode=${result.mode}`);
347
363
  }
348
364
  stopHeartbeat();
349
- await client.complete({
365
+ terminalPayload = {
350
366
  run_id,
351
367
  worker_id: client.id,
352
368
  status: 'success',
@@ -355,25 +371,24 @@ async function executeSyncRun(client, job, env, cfg) {
355
371
  ...(result.status === 'more' && cursorAdvanced(checkpoint, committedCheckpoint) ? { more: true } : {}),
356
372
  auth_update: result.auth_update ?? undefined,
357
373
  error_message: partialFetchFailureMessage(result.metadata),
358
- });
359
- log.info(`[executor] Sync run ${run_id} completed: ${itemsCollectedSoFar} items`);
360
- return { itemsCollected: itemsCollectedSoFar };
374
+ };
361
375
  }
362
376
  catch (error) {
363
377
  stopHeartbeat();
364
378
  const errorMessage = error instanceof Error ? error.message : String(error);
365
379
  log.error(`[executor] Sync run ${run_id} failed:`, error);
366
380
  const diag = extractExecutionDiagnostics(error);
367
- await client.complete({
381
+ terminalPayload = {
368
382
  run_id,
369
383
  worker_id: client.id,
370
384
  status: 'failed',
371
385
  items_collected: itemsCollectedSoFar,
372
386
  error_message: errorMessage,
373
387
  ...(diag ?? {}),
374
- });
375
- return { itemsCollected: itemsCollectedSoFar, error: errorMessage };
388
+ };
389
+ executionError = errorMessage;
376
390
  }
391
+ return deliver(terminalPayload, executionError);
377
392
  }
378
393
  /**
379
394
  * Connectors report per-source failures on an otherwise-successful sync via
@@ -4,7 +4,7 @@
4
4
  * Exports worker daemon, client, and executor.
5
5
  */
6
6
  export type { CompleteRequest, ContentItem, PollResponse, StreamBatch, WorkerAdvertisementProvider, WorkerAdvertisementSnapshot, WorkerCapabilities, } from './client.js';
7
- export { MutableWorkerAdvertisementProvider, WorkerClient } from './client.js';
7
+ export { MutableWorkerAdvertisementProvider, WorkerClient, WorkerUpgradeRequiredError, } from './client.js';
8
8
  export { NATIVE_BRIDGE_PROTOCOL, NATIVE_BRIDGE_PROTOCOL_VERSION, NativeBridgeProtocolError, } from './native-bridge/protocol.js';
9
9
  export { NativeBridgeClient } from './native-bridge/client.js';
10
10
  export type { ExecutorConfig } from './executor.js';
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Exports worker daemon, client, and executor.
5
5
  */
6
- export { MutableWorkerAdvertisementProvider, WorkerClient } from './client.js';
6
+ export { MutableWorkerAdvertisementProvider, WorkerClient, WorkerUpgradeRequiredError, } from './client.js';
7
7
  export { NATIVE_BRIDGE_PROTOCOL, NATIVE_BRIDGE_PROTOCOL_VERSION, NativeBridgeProtocolError, } from './native-bridge/protocol.js';
8
8
  export { NativeBridgeClient } from './native-bridge/client.js';
9
9
  export { executeRun } from './executor.js';
@@ -6,7 +6,7 @@
6
6
  * injected so the device build does not import fleet connector machinery.
7
7
  */
8
8
  import { WORKER_POLL_MAX_WAIT_SECONDS } from '@lobu/core/contracts/worker/protocol';
9
- import { WorkerHttpError } from './client.js';
9
+ import { WorkerHttpError, WorkerUpgradeRequiredError, } from './client.js';
10
10
  import { log } from './log.js';
11
11
  /** Drain budget for a daemon nobody told how long it has (devices, local runs). */
12
12
  const DEFAULT_SHUTDOWN_DRAIN_MS = 30_000;
@@ -85,6 +85,11 @@ export class WorkerPollLoop {
85
85
  break;
86
86
  // Server errors retain their retry backoff even if a slot opens.
87
87
  capacityVersion = undefined;
88
+ // Below the server's version floor, every retry sends the same version
89
+ // and is refused the same way: stop, so the launcher can say how to
90
+ // update instead of logging a poll error every interval forever.
91
+ if (err instanceof WorkerUpgradeRequiredError)
92
+ throw err;
88
93
  if (this.failClosedOnPollAuthError &&
89
94
  err instanceof WorkerHttpError &&
90
95
  (err.status === 401 || err.status === 403)) {
@@ -30,7 +30,6 @@ 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;
34
33
  /**
35
34
  * Validate the options and boot the daemon. Throws a user-facing `Error` on
36
35
  * bad input; the caller prints it and exits non-zero.
@@ -45,7 +45,7 @@ export function resolveDaemonLaunchContext(opts, env = process.env, sessionsDir)
45
45
  interactiveSession: detected,
46
46
  };
47
47
  }
48
- export function resolveDaemonMaxConcurrentJobs(platform, env = process.env, hostThreads) {
48
+ function resolveDaemonMaxConcurrentJobs(platform, env = process.env, hostThreads) {
49
49
  const configured = env.WORKER_MAX_CONCURRENT_JOBS
50
50
  ? Math.max(1, Number.parseInt(env.WORKER_MAX_CONCURRENT_JOBS, 10))
51
51
  : undefined;
@@ -4,6 +4,7 @@ import type { CompleteAgentTurnRequest, CompleteAgentTurnResponse, ExecutorClien
4
4
  * are retriable; an explicit decode failure or any other 4xx is not.
5
5
  */
6
6
  export declare function isRetriableDeliveryFailure(err: unknown): boolean;
7
+ export declare function completeSyncOnce(client: ExecutorClient, payload: Parameters<ExecutorClient['complete']>[0]): Promise<void>;
7
8
  export declare function completeActionOnce(client: ExecutorClient, payload: Parameters<ExecutorClient['completeAction']>[0]): Promise<void>;
8
9
  export declare function completeAgentTurnOnce(client: ExecutorClient, payload: CompleteAgentTurnRequest): Promise<CompleteAgentTurnResponse>;
9
10
  //# sourceMappingURL=terminal-delivery.d.ts.map
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Bounded delivery of an immutable terminal outcome. Execution and failure
3
- * reporting share the retry loop; action and agent-turn budgets differ.
3
+ * reporting share the retry loop; sync/action and agent-turn budgets differ.
4
4
  * WorkerDecodeError identifies an unreadable response, not an execution
5
5
  * failure, and is surfaced without retrying.
6
6
  */
7
7
  import { WorkerDecodeError, WorkerHttpError } from './client.js';
8
- /** Actions: two attempts in 15s, anything but an undecodable answer retried. */
8
+ /** Syncs/actions: two attempts in 15s, anything but an undecodable answer retried. */
9
9
  const ACTION_DELIVERY = {
10
10
  deadlineMs: 15_000,
11
11
  attempts: 2,
@@ -57,10 +57,11 @@ async function withTerminalDeliveryTimeout(promise, timeoutMs) {
57
57
  * commonest transient failure, and abandoning it there would leave the rest of
58
58
  * the deadline unused. The timeout does not cancel the in-flight request, so a
59
59
  * retry can reach a gateway that already accepted the first one -- that is
60
- * safe because both terminal writes are fenced: an action's by
61
- * `status = 'running' AND claimed_by = worker_id` (a second delivery answers
62
- * `already_finalized`), an agent turn's by the run row lock plus its stored
63
- * completion hash (an exact retry is acknowledged, a divergent one 409s).
60
+ * safe because terminal writes are fenced: syncs and actions by
61
+ * `status = 'running' AND claimed_by = worker_id` (a duplicate cannot repeat
62
+ * the terminal write or its side effects), an agent turn's by the run row lock
63
+ * plus its stored completion hash (an exact retry is acknowledged, a divergent
64
+ * one 409s).
64
65
  */
65
66
  async function deliverTerminal(send, policy) {
66
67
  const deadline = Date.now() + policy.deadlineMs;
@@ -88,6 +89,9 @@ async function deliverTerminal(send, policy) {
88
89
  }
89
90
  throw lastError instanceof Error ? lastError : new Error(String(lastError));
90
91
  }
92
+ export async function completeSyncOnce(client, payload) {
93
+ await deliverTerminal(() => client.complete(payload), ACTION_DELIVERY);
94
+ }
91
95
  export async function completeActionOnce(client, payload) {
92
96
  await deliverTerminal(() => client.completeAction(payload), ACTION_DELIVERY);
93
97
  }
@@ -37,7 +37,7 @@ import { IsolateHost, IsolateHostError } from '../isolate/bridge.js';
37
37
  import { assertIsolateEligible } from '../isolate/eligibility.js';
38
38
  import { isolatedVmUnavailableReason, loadIsolatedVm } from '../isolate/load.js';
39
39
  import { buildConnectorConfig } from './connector-config.js';
40
- import { redactOutput } from './redact.js';
40
+ import { redactOutput } from '@lobu/connector-sdk/redact';
41
41
  import { RingBuffer, ConnectorExecutionError } from './interface.js';
42
42
  const MIB = 1024 * 1024;
43
43
  const DEFAULT_OPTIONS = {
@@ -19,8 +19,10 @@
19
19
  * - `script.run({ timeout })` bounds only the synchronous part of the run; a
20
20
  * loop entered after an `await` is not interrupted. The wall clock here
21
21
  * disposes the isolate, which rejects the pending run.
22
- * - Exceeding `memoryLimit` disposes the isolate automatically; the run
23
- * rejects with "disposed during execution due to memory limit".
22
+ * - Exceeding `memoryLimit` disposes the isolate automatically and rejects
23
+ * the run. That is the only disposal the host does not perform itself, so
24
+ * an isolate disposed without `dispose()` is how a memory kill is told
25
+ * apart from a guest error whose text merely mentions a memory limit.
24
26
  * - `dispose()` on a disposed isolate throws; guard with `isDisposed`.
25
27
  */
26
28
  import type { IsolatedVm } from './ivm-types.js';
@@ -65,6 +67,8 @@ export declare class IsolateHost {
65
67
  private readonly sync;
66
68
  private terminalState;
67
69
  private timedOut;
70
+ /** Set before every host disposal; a disposed isolate without it was disposed by V8. */
71
+ private disposedByHost;
68
72
  private constructor();
69
73
  static create(options: IsolateHostOptions): Promise<IsolateHost>;
70
74
  /** The state the host imposed, if it ended the run. */
@@ -19,8 +19,10 @@
19
19
  * - `script.run({ timeout })` bounds only the synchronous part of the run; a
20
20
  * loop entered after an `await` is not interrupted. The wall clock here
21
21
  * disposes the isolate, which rejects the pending run.
22
- * - Exceeding `memoryLimit` disposes the isolate automatically; the run
23
- * rejects with "disposed during execution due to memory limit".
22
+ * - Exceeding `memoryLimit` disposes the isolate automatically and rejects
23
+ * the run. That is the only disposal the host does not perform itself, so
24
+ * an isolate disposed without `dispose()` is how a memory kill is told
25
+ * apart from a guest error whose text merely mentions a memory limit.
24
26
  * - `dispose()` on a disposed isolate throws; guard with `isDisposed`.
25
27
  */
26
28
  import { createPreludeHostSync, GUEST_PRELUDE } from './prelude.js';
@@ -57,6 +59,8 @@ export class IsolateHost {
57
59
  sync;
58
60
  terminalState = null;
59
61
  timedOut = false;
62
+ /** Set before every host disposal; a disposed isolate without it was disposed by V8. */
63
+ disposedByHost = false;
60
64
  constructor(isolate, context, options) {
61
65
  this.isolate = isolate;
62
66
  this.context = context;
@@ -204,19 +208,21 @@ export class IsolateHost {
204
208
  cause: error,
205
209
  });
206
210
  }
207
- const message = error instanceof Error ? error.message : String(error);
208
- if (/memory limit/i.test(message)) {
211
+ // Decided from the isolate's state, never the rejection's text: a guest's
212
+ // own error may say "memory limit" or "terminated" too.
213
+ if (!this.isolate.isDisposed)
214
+ return error;
215
+ if (!this.disposedByHost) {
209
216
  this.terminalState = { name: 'MemoryLimitExceeded', message: `isolate exceeded its ${this.options.memoryMb} MB memory limit` };
210
217
  return new IsolateHostError('memory', this.terminalState.message, this.terminalState, { cause: error });
211
218
  }
212
- if (/disposed|abandoned|terminated/i.test(message)) {
213
- return new IsolateHostError('crash', `isolate ended unexpectedly: ${message}`, null, { cause: error });
214
- }
215
- return error;
219
+ const message = error instanceof Error ? error.message : String(error);
220
+ return new IsolateHostError('crash', `isolate ended unexpectedly: ${message}`, null, { cause: error });
216
221
  }
217
222
  dispose() {
218
223
  if (this.isolate.isDisposed)
219
224
  return;
225
+ this.disposedByHost = true;
220
226
  try {
221
227
  this.isolate.dispose();
222
228
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/connector-worker",
3
- "version": "24.2.0",
3
+ "version": "24.3.0",
4
4
  "description": "Self-hosted worker for Lobu memory — connectors and embedding generation",
5
5
  "type": "module",
6
6
  "bin": {
@@ -70,7 +70,7 @@
70
70
  "esbuild": "^0.28.1",
71
71
  "just-bash": "^2.14.2",
72
72
  "pathe": "^2.0.3",
73
- "undici": "7.29.1"
73
+ "undici": "7.30.1"
74
74
  },
75
75
  "optionalDependencies": {
76
76
  "isolated-vm": "^6.2.0",
@@ -30,6 +30,12 @@ export type ToolErrorCode =
30
30
  | "VALIDATION"
31
31
  /** Denied by org-scope / cross-org visibility rules. */
32
32
  | "PERMISSION"
33
+ /**
34
+ * `manage_entity update` sent `manual_edit: true`, but the caller may not
35
+ * assert a person's edit: it lacks the `entities:manual_edit` scope, or an
36
+ * agent, MCP session or Automation is behind the call (HTTP 403).
37
+ */
38
+ | "MANUAL_EDIT_NOT_ALLOWED"
33
39
  /** Upstream throttled the request (HTTP 429 / too many requests). */
34
40
  | "RATE_LIMITED"
35
41
  /** Upstream request or DB statement timed out (e.g. PG 57014). */
@@ -50,6 +50,10 @@ exports.TOOL_ERRORS = {
50
50
  retryable: false,
51
51
  message: "Not permitted in this organization scope.",
52
52
  },
53
+ MANUAL_EDIT_NOT_ALLOWED: {
54
+ retryable: false,
55
+ message: "This caller may not assert a manual edit; it needs the entities:manual_edit scope and no agent, MCP session or Automation behind it.",
56
+ },
53
57
  RATE_LIMITED: {
54
58
  retryable: true,
55
59
  message: "The upstream rate limit was hit; retry shortly.",
@@ -122,7 +122,7 @@ exports.AutomationScheduleTriggerSchema = typebox_1.Type.Object({
122
122
  })),
123
123
  skip_if_unchanged: typebox_1.Type.Optional(typebox_1.Type.Boolean({
124
124
  default: true,
125
- description: "Native executors may skip unchanged source windows. External executors always receive due windows and decide whether to emit output.",
125
+ description: "Book a due window with no new or changed source content as a no-op run instead of dispatching an agent. Applies to native dispatch and to external claimNextWindow, which answers 409 for a skipped window.",
126
126
  })),
127
127
  }, { additionalProperties: false });
128
128
  exports.AutomationTriggerSchema = typebox_1.Type.Union([
@@ -114,7 +114,7 @@ exports.ManageEntitySchemaSchema = typebox_1.Type.Object({
114
114
  interactions: typebox_1.Type.Optional(typebox_1.Type.Record(typebox_1.Type.String(), typebox_1.Type.Object({ emits: typebox_1.Type.String() }))),
115
115
  })),
116
116
  ], {
117
- description: "[entity_type: create/update] Event semantic types this type produces, keyed by semantic_type slug. Each entry can have a description, optional metadataSchema (JSON Schema), optional jsonTemplate (the event card's render template), and optional interactions registry mapping template action names to emitted event kinds. Author interactive dashboards as React views attached to the kind (views.set with attach [{ event_kind }]), not as jsonTemplate. Supplying an object replaces the entire registry: read the current value and merge before updating. `null` clears all kinds; omit to leave unchanged.",
117
+ description: "[entity_type: create/update] Event semantic types this type produces, keyed by semantic_type slug. Each entry can have a description, optional metadataSchema (JSON Schema), optional jsonTemplate (the event card's render template), and optional interactions registry mapping template action names to emitted event kinds. Author interactive dashboards as React views attached to the kind (views.set with attach [{ event: '<kind>' }]), not as jsonTemplate. Supplying an object replaces the entire registry: read the current value and merge before updating. `null` clears all kinds; omit to leave unchanged.",
118
118
  })),
119
119
  backing: typebox_1.Type.Optional(typebox_1.Type.Union([typebox_1.Type.Null(), exports.BackingInputSchema], {
120
120
  description: "[entity_type: create/update] Makes the type DERIVED — a read-only SQL view. `{ sql }` runs over your org's internal tables; `{ sql, connection: <slug> }` runs LIVE against that connection's external database (read-only, no copy). `null` clears it (revert to a stored type); omit to leave unchanged. Read a derived type's rows by running its `backing_sql` (returned by `get`) through `query_sql` — and when `get` also returns a `backing_source`, pass it as `query_sql`'s `connection` so the view runs against the external DB instead of your internal tables. `get` also returns `measure_columns` (the view's aggregate columns, classified on read).",
@@ -24,6 +24,7 @@ export declare const UpdateEntityAction: import("@sinclair/typebox").TObject<{
24
24
  metadata: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>>;
25
25
  field_note: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
26
26
  affirm_fields: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
27
+ manual_edit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
27
28
  automation_source: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
28
29
  automation_id: import("@sinclair/typebox").TNumber;
29
30
  run_id: import("@sinclair/typebox").TNumber;
@@ -162,6 +163,7 @@ export declare const ManageEntitySchema: import("@sinclair/typebox").TUnion<[imp
162
163
  metadata: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>>;
163
164
  field_note: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
164
165
  affirm_fields: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
166
+ manual_edit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
165
167
  automation_source: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
166
168
  automation_id: import("@sinclair/typebox").TNumber;
167
169
  run_id: import("@sinclair/typebox").TNumber;
@@ -430,6 +432,8 @@ export declare const ManageEntityResultSchema: import("@sinclair/typebox").TUnio
430
432
  approval_current: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>>;
431
433
  /** Who proposed the blocked change: 'agent' | 'automation'. */
432
434
  approval_attribution: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<import("@sinclair/typebox").TLiteral<"automation" | "agent">[]>>;
435
+ /** True when a `manual_edit` assertion was honoured: the edit was recorded as the person's own. */
436
+ manual_edit_applied: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
433
437
  }>, import("@sinclair/typebox").TObject<{
434
438
  action: import("@sinclair/typebox").TLiteral<"list">;
435
439
  entities: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
@@ -128,6 +128,10 @@ exports.UpdateEntityAction = typebox_1.Type.Object({
128
128
  affirm_fields: typebox_1.Type.Optional(typebox_1.Type.Array(typebox_1.Type.String(), {
129
129
  description: "[update] Metadata field names whose CURRENT value the human approves as-is. No value change, but each is marked human-owned so an Automation can't later overwrite it without an approval. The 'approve' half of the recap feedback loop.",
130
130
  })),
131
+ // Asserted manual edit: a first-party backend records a person's own change
132
+ manual_edit: typebox_1.Type.Optional(typebox_1.Type.Boolean({
133
+ description: "[update] Assert that the signed-in person made this change themselves, so it is recorded as their manual edit: the fields it sets (and affirm_fields) become theirs, and Automations then queue an approval instead of updating them. A wrong assertion takes the field away from Automations. Honoured for a person's own web-session edit, or for a token minted with the entities:manual_edit scope by a person in the web app, with no agent, MCP session or Automation behind the call; otherwise the update fails with 403 MANUAL_EDIT_NOT_ALLOWED and nothing is written. Defaults to false.",
134
+ })),
131
135
  automation_source: typebox_1.Type.Optional(AutomationSource),
132
136
  });
133
137
  exports.ListEntitiesAction = typebox_1.Type.Object({
@@ -423,6 +427,8 @@ exports.ManageEntityResultSchema = typebox_1.Type.Union([
423
427
  approval_current: typebox_1.Type.Optional(typebox_1.Type.Record(typebox_1.Type.String(), typebox_1.Type.Unknown())),
424
428
  /** Who proposed the blocked change: 'agent' | 'automation'. */
425
429
  approval_attribution: typebox_1.Type.Optional(interaction_envelope_1.ApprovalAttributionSchema),
430
+ /** True when a `manual_edit` assertion was honoured: the edit was recorded as the person's own. */
431
+ manual_edit_applied: typebox_1.Type.Optional(typebox_1.Type.Boolean()),
426
432
  }),
427
433
  typebox_1.Type.Object({
428
434
  action: typebox_1.Type.Literal("list"),
@@ -8,7 +8,7 @@
8
8
  * headless args, flag mapping, MCP wiring). Adding a CLI is now one entry,
9
9
  * not a ~140-line executor copy.
10
10
  * - the Automation prompt builder — the completion contract the spawned CLI
11
- * must satisfy, pinned by golden-string fixtures in device-automation.test.ts.
11
+ * must satisfy.
12
12
  *
13
13
  * The connector-worker daemon consumes these from core. This module is pure
14
14
  * data + string building: it imports nothing above core.
@@ -9,7 +9,7 @@
9
9
  * headless args, flag mapping, MCP wiring). Adding a CLI is now one entry,
10
10
  * not a ~140-line executor copy.
11
11
  * - the Automation prompt builder — the completion contract the spawned CLI
12
- * must satisfy, pinned by golden-string fixtures in device-automation.test.ts.
12
+ * must satisfy.
13
13
  *
14
14
  * The connector-worker daemon consumes these from core. This module is pure
15
15
  * data + string building: it imports nothing above core.
@@ -39,26 +39,6 @@ export declare class OrchestratorError extends BaseError {
39
39
  static fromDatabaseError(error: any): OrchestratorError;
40
40
  toJSON(): Record<string, any>;
41
41
  }
42
- /**
43
- * Thrown when a worker spawn is declined because another replica already holds
44
- * the per-conversation lock for this turn — i.e. another pod legitimately OWNS
45
- * this conversation turn and is running it to completion.
46
- *
47
- * This is NOT a failure. It is the cross-pod "handled elsewhere" signal. Under
48
- * N>1 app replicas both pods drain the shared `thread_message` queue and race to
49
- * spawn the same per-conversation worker; exactly one wins the advisory lock.
50
- * The loser MUST drop silently — no user-facing error, no Critical log, no
51
- * retry (the winner holds the lock for the entire worker subprocess lifetime, so
52
- * retrying can never win). The winning pod discharges the shared turn-liveness
53
- * marker on its successful reply, so the user still receives the answer.
54
- *
55
- * Distinguished by type (not a magic message string) so the orchestrator can
56
- * tell "owned by another pod" apart from a genuine worker-startup failure (OOM,
57
- * spawn failure, bad config) which MUST still surface an error to the user.
58
- */
59
- export declare class ConversationOwnedElsewhereError extends BaseError {
60
- readonly name = "ConversationOwnedElsewhereError";
61
- }
62
42
  export declare class ConfigError extends BaseError {
63
43
  readonly name = "ConfigError";
64
44
  }