@lobu/runtime-device 24.8.0 → 24.10.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 (110) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +36 -34
  3. package/npm-shrinkwrap.json +228 -207
  4. package/package.json +1 -1
  5. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +17 -3
  6. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +31 -4
  7. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +37 -22
  8. package/vendor/cli/dist/commands/_lib/apply/client.js +63 -43
  9. package/vendor/cli/dist/commands/_lib/apply/deployment.d.ts +8 -12
  10. package/vendor/cli/dist/commands/_lib/apply/deployment.js +14 -1
  11. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +8 -4
  12. package/vendor/cli/dist/commands/_lib/apply/desired-state.js +2 -1
  13. package/vendor/cli/dist/commands/_lib/apply/diff.d.ts +26 -7
  14. package/vendor/cli/dist/commands/_lib/apply/diff.js +101 -30
  15. package/vendor/cli/dist/commands/_lib/apply/map-config.js +29 -2
  16. package/vendor/cli/dist/commands/_lib/apply/render.js +2 -0
  17. package/vendor/cli/dist/commands/_lib/apply/shared.d.ts +20 -0
  18. package/vendor/cli/dist/commands/_lib/apply/shared.js +22 -0
  19. package/vendor/cli/dist/commands/_lib/init-from-org/bootstrap.js +14 -0
  20. package/vendor/cli/dist/commands/dev.js +2 -0
  21. package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +6 -2
  22. package/vendor/cli/dist/config/define.d.ts +21 -3
  23. package/vendor/cli/dist/connectors/README.md +6 -2
  24. package/vendor/cli/dist/connectors/github.ts +16 -3
  25. package/vendor/cli/dist/connectors/market_quotes.ts +388 -91
  26. package/vendor/cli/dist/connectors/postgres.ts +60 -38
  27. package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +41 -10
  28. package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +12 -2
  29. package/vendor/cli/dist/connectors/whatsapp_web.ts +18 -2
  30. package/vendor/cli/dist/connectors/x-dm-adapter.js +55 -21
  31. package/vendor/cli/dist/connectors/x.ts +1 -1
  32. package/vendor/cli/dist/internal/context.d.ts +5 -0
  33. package/vendor/cli/dist/internal/context.js +23 -9
  34. package/vendor/cli/dist/runtime-components.json +4 -4
  35. package/vendor/cli/package.json +1 -1
  36. package/vendor/connector-sdk/dist/connector-types.d.ts +29 -2
  37. package/vendor/connector-sdk/dist/index.d.ts +1 -0
  38. package/vendor/connector-sdk/dist/index.js +1 -0
  39. package/vendor/connector-sdk/dist/ip-reachability.d.ts +1 -1
  40. package/vendor/connector-sdk/dist/ip-reachability.js +1 -1
  41. package/vendor/connector-sdk/dist/logger.d.ts +1 -1
  42. package/vendor/connector-sdk/dist/logger.js +1 -1
  43. package/vendor/connector-sdk/dist/reaction-client-types.d.ts +3 -1
  44. package/vendor/connector-sdk/dist/retry.d.ts +1 -1
  45. package/vendor/connector-sdk/dist/retry.js +1 -1
  46. package/vendor/connector-sdk/dist/source-withheld-error.d.ts +16 -0
  47. package/vendor/connector-sdk/dist/source-withheld-error.js +19 -0
  48. package/vendor/connector-sdk/package.json +1 -1
  49. package/vendor/connector-worker/dist/daemon/automation.js +7 -4
  50. package/vendor/connector-worker/dist/daemon/index.d.ts +1 -0
  51. package/vendor/connector-worker/dist/daemon/index.js +1 -0
  52. package/vendor/connector-worker/dist/daemon/terminal-delivery.d.ts +12 -2
  53. package/vendor/connector-worker/dist/daemon/terminal-delivery.js +19 -12
  54. package/vendor/connector-worker/dist/executor/interface.d.ts +10 -0
  55. package/vendor/connector-worker/dist/executor/interface.js +6 -0
  56. package/vendor/connector-worker/dist/executor/isolate.d.ts +1 -0
  57. package/vendor/connector-worker/dist/executor/isolate.js +88 -24
  58. package/vendor/connector-worker/dist/isolate/prelude.js +5 -0
  59. package/vendor/connector-worker/package.json +1 -1
  60. package/vendor/core/dist/classify-error.d.ts +4 -5
  61. package/vendor/core/dist/classify-error.js +10 -10
  62. package/vendor/core/dist/contracts/tools/collection-presentation.d.ts +17 -1
  63. package/vendor/core/dist/contracts/tools/collection-presentation.js +27 -3
  64. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +67 -3
  65. package/vendor/core/dist/contracts/tools/manage-automations.js +38 -9
  66. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +1 -1
  67. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +8 -0
  68. package/vendor/core/dist/contracts/tools/manage-entity.js +11 -3
  69. package/vendor/core/dist/contracts/tools/manage-views.d.ts +249 -7
  70. package/vendor/core/dist/contracts/tools/manage-views.js +83 -21
  71. package/vendor/core/dist/contracts/tools/navigation.d.ts +248 -0
  72. package/vendor/core/dist/contracts/tools/navigation.js +284 -0
  73. package/vendor/core/dist/contracts/tools/save-memory.d.ts +11 -1
  74. package/vendor/core/dist/contracts/tools/save-memory.js +25 -3
  75. package/vendor/core/dist/contracts/tools/search-memory.js +1 -1
  76. package/vendor/core/dist/contracts/tools/view-attach.d.ts +7 -0
  77. package/vendor/core/dist/contracts/tools/view-attach.js +15 -0
  78. package/vendor/core/dist/contracts/tools/view-content-hash.d.ts +4 -1
  79. package/vendor/core/dist/contracts/tools/view-content-hash.js +4 -2
  80. package/vendor/core/dist/contracts/tools/view-definition.d.ts +2 -0
  81. package/vendor/core/dist/contracts/tools/view-definition.js +52 -0
  82. package/vendor/core/dist/contracts/tools/view-host.d.ts +68 -0
  83. package/vendor/core/dist/contracts/tools/view-host.js +28 -1
  84. package/vendor/core/dist/contracts/tools/view-scope.d.ts +31 -0
  85. package/vendor/core/dist/contracts/tools/view-scope.js +45 -0
  86. package/vendor/core/dist/credentials.d.ts +12 -0
  87. package/vendor/core/dist/credentials.js +1 -0
  88. package/vendor/core/dist/errors.d.ts +17 -24
  89. package/vendor/core/dist/errors.js +19 -26
  90. package/vendor/core/dist/types.d.ts +0 -6
  91. package/vendor/core/dist/worker/auth.d.ts +5 -0
  92. package/vendor/core/dist/worker/auth.js +15 -4
  93. package/vendor/core/package.json +11 -1
  94. package/vendor/postgres/cf/src/connection.js +7 -2
  95. package/vendor/postgres/cjs/src/connection.js +7 -2
  96. package/vendor/postgres/src/connection.js +7 -2
  97. package/vendor/views/dist/api.d.ts +30 -5
  98. package/vendor/views/dist/api.js +22 -8
  99. package/vendor/views/dist/bridge.d.ts +17 -0
  100. package/vendor/views/dist/bridge.js +49 -1
  101. package/vendor/views/dist/components.d.ts +27 -5
  102. package/vendor/views/dist/components.js +57 -7
  103. package/vendor/views/dist/embed.d.ts +98 -0
  104. package/vendor/views/dist/embed.js +418 -0
  105. package/vendor/views/dist/index.d.ts +3 -1
  106. package/vendor/views/dist/index.js +1 -0
  107. package/vendor/views/dist/native.d.ts +33 -1
  108. package/vendor/views/dist/native.js +3 -0
  109. package/vendor/views/package.json +1 -1
  110. /package/vendor/postgres/{.bun-tag-c81dacd34e959a7a → .bun-tag-652f2580b8090d71} +0 -0
@@ -42,6 +42,7 @@ export interface ConnectorDefinition {
42
42
  queryCapabilities?: {
43
43
  exactMatch?: boolean;
44
44
  verbatimExactMatch?: boolean;
45
+ exactMatchAny?: boolean;
45
46
  selection?: boolean;
46
47
  };
47
48
  /** Connector-normalized events that can activate Automations. */
@@ -74,6 +75,8 @@ export interface ConnectorDefinition {
74
75
  includeOperations?: string[];
75
76
  excludeOperations?: string[];
76
77
  includeTags?: string[];
78
+ /** HTTP methods to expose (e.g. `['get']` for a read-only surface). */
79
+ includeMethods?: string[];
77
80
  serverUrl?: string;
78
81
  };
79
82
  /**
@@ -338,6 +341,16 @@ export interface ConnectorAuthEnvField {
338
341
  example?: string;
339
342
  secret?: boolean;
340
343
  required?: boolean;
344
+ /**
345
+ * Send this field as the HTTP credential for generated `openapiConfig`
346
+ * operations (and MCP upstreams) when the connection authenticates with this
347
+ * env method: `<header>: <scheme> <value>`. Defaults: header `Authorization`,
348
+ * scheme `Bearer`. At most one env field per connector may set it.
349
+ */
350
+ httpCredential?: {
351
+ header?: string;
352
+ scheme?: string;
353
+ };
341
354
  }
342
355
  export interface ConnectorAuthEnvKeys {
343
356
  type: 'env_keys';
@@ -1074,6 +1087,12 @@ export interface FeedReadResult {
1074
1087
  window?: FeedReadWindowCoverage;
1075
1088
  }
1076
1089
  export type FeedSyncHandler<C = Record<string, unknown>, F = Record<string, unknown>> = (ctx: SyncContext<C, F>) => Promise<SyncResult>;
1090
+ /**
1091
+ * Reads one page from the source. Throw `SourceWithheldError` (or any error
1092
+ * whose own `code` is `'withheld'`) when the source deliberately withholds the
1093
+ * requested record: callers report it as private with the error's message as
1094
+ * the reason, and never retry it. Any other rejection is a read failure.
1095
+ */
1077
1096
  export type FeedReadHandler<F = Record<string, unknown>> = (ctx: FeedReadContext<F>) => Promise<FeedReadResult>;
1078
1097
  /** Executable feed definition held only inside a connector runtime. */
1079
1098
  export interface RuntimeFeedDefinition<C = Record<string, unknown>, F = Record<string, unknown>> extends Omit<FeedDefinition, 'operations' | 'webhook'> {
@@ -1118,12 +1137,20 @@ export interface QueryContext<F = Record<string, unknown>> {
1118
1137
  * connector, which owns its source dialect. Requires queryCapabilities.exactMatch.
1119
1138
  * `verbatim: true` preserves the scalar string without trimming and additionally
1120
1139
  * requires queryCapabilities.verbatimExactMatch. The default stays trimmed.
1140
+ * Exactly one of `value` / `values` is set. `values` (1-500 strings) keeps a
1141
+ * row whose key equals ANY of them, under the same per-column semantics as
1142
+ * `value`, and additionally requires queryCapabilities.exactMatchAny.
1121
1143
  */
1122
1144
  exactMatch?: {
1123
1145
  columns: string[];
1124
- value: string;
1125
1146
  verbatim?: boolean;
1126
- };
1147
+ } & ({
1148
+ value: string;
1149
+ values?: never;
1150
+ } | {
1151
+ values: string[];
1152
+ value?: never;
1153
+ });
1127
1154
  /**
1128
1155
  * Shared collection predicates, applied before sorting and pagination.
1129
1156
  * Search is a literal case-insensitive substring of the projected name.
@@ -58,6 +58,7 @@ export type { FileDelta, FileSystemSource, Snapshot } from './file-source.js';
58
58
  export { connect } from './net.js';
59
59
  export type { ConnectFn, Socket, SocketAddress, SocketOptions, } from './net.js';
60
60
  export { assertFeedReadWindow, validateFeedReadWindow } from './feed-read-window.js';
61
+ export { SourceWithheldError } from './source-withheld-error.js';
61
62
  export { isSecretOutputKey, redactOutput } from './redact.js';
62
63
  export { scrubDiagnosticValue } from '@lobu/core/diagnostic-scrubber';
63
64
  //# sourceMappingURL=index.d.ts.map
@@ -46,6 +46,7 @@ export { extensionNetworkSync } from './extension-network.js';
46
46
  // =============================================================================
47
47
  export { connect } from './net.js';
48
48
  export { assertFeedReadWindow, validateFeedReadWindow } from './feed-read-window.js';
49
+ export { SourceWithheldError } from './source-withheld-error.js';
49
50
  // The worker's output redaction catalog, shared so a connector that returns
50
51
  // third-party text (logs, messages) can scrub it with the same patterns.
51
52
  export { isSecretOutputKey, redactOutput } from './redact.js';
@@ -21,7 +21,7 @@
21
21
  * Keeping the classifier here rather than in each consumer is deliberate:
22
22
  * `@lobu/connector-sdk` is the only package every consumer can import (the
23
23
  * server package is not reachable from a bundled connector, and `@lobu/core`
24
- * pulls OpenTelemetry, Sentry, and winston, which connectors intentionally
24
+ * pulls OpenTelemetry and winston, which connectors intentionally
25
25
  * avoid).
26
26
  *
27
27
  * The matcher collapses the spellings an attacker can use to dress up an
@@ -21,7 +21,7 @@
21
21
  * Keeping the classifier here rather than in each consumer is deliberate:
22
22
  * `@lobu/connector-sdk` is the only package every consumer can import (the
23
23
  * server package is not reachable from a bundled connector, and `@lobu/core`
24
- * pulls OpenTelemetry, Sentry, and winston, which connectors intentionally
24
+ * pulls OpenTelemetry and winston, which connectors intentionally
25
25
  * avoid).
26
26
  *
27
27
  * The matcher collapses the spellings an attacker can use to dress up an
@@ -2,7 +2,7 @@
2
2
  * SDK logger.
3
3
  *
4
4
  * Deliberately self-contained. The package root must stay loadable inside a
5
- * V8 isolate, and `@lobu/core`'s root entry pulls winston, Sentry and
5
+ * V8 isolate, and `@lobu/core`'s root entry pulls winston and
6
6
  * OpenTelemetry into every connector bundle — 6 MB of gateway internals whose
7
7
  * first `require('util')` throws where no Node runtime exists (guarded by
8
8
  * `packages/server/src/__tests__/integration/sandbox/connector-isolate-lane.test.ts`).
@@ -2,7 +2,7 @@
2
2
  * SDK logger.
3
3
  *
4
4
  * Deliberately self-contained. The package root must stay loadable inside a
5
- * V8 isolate, and `@lobu/core`'s root entry pulls winston, Sentry and
5
+ * V8 isolate, and `@lobu/core`'s root entry pulls winston and
6
6
  * OpenTelemetry into every connector bundle — 6 MB of gateway internals whose
7
7
  * first `require('util')` throws where no Node runtime exists (guarded by
8
8
  * `packages/server/src/__tests__/integration/sandbox/connector-isolate-lane.test.ts`).
@@ -17,7 +17,7 @@ import type { ConnectionListInput } from "@lobu/core/contracts/tools/manage-conn
17
17
  import type { EntityCreateInput, EntityCreateResult, EntityDeleteInput, EntityDeleteResult, EntityDiscoverDuplicatesInput, EntityDiscoverDuplicatesResult, EntityGetInput, EntityGetResult, EntityLinkInput, EntityLinkResult, EntityListInput, EntityListResult, EntityListLinksInput, EntityListLinksResult, EntityUnlinkInput, EntityUnlinkResult, EntityUpdateInput, EntityUpdateResult, EntityUpdateLinkInput, EntityUpdateLinkResult } from "@lobu/core/contracts/tools/manage-entity";
18
18
  import type { OperationExecuteInput, OperationListAvailableInput, OperationListRunsInput } from "@lobu/core/contracts/tools/manage-operations";
19
19
  import type { PublicGetContentArgs } from "@lobu/core/contracts/tools/read-knowledge";
20
- import type { SaveContentInput } from "@lobu/core/contracts/tools/save-memory";
20
+ import type { SaveContentInput, UnlinkedEntityName } from "@lobu/core/contracts/tools/save-memory";
21
21
  import type { PublicSearchArgs } from "@lobu/core/contracts/tools/search-memory";
22
22
  /**
23
23
  * A rich card for chat delivery, as a plain serializable object — a `chat`
@@ -58,6 +58,8 @@ export interface KnowledgeSaveResult {
58
58
  id: number;
59
59
  created: boolean;
60
60
  metadata: Record<string, unknown>;
61
+ /** `{ name }` entries from `entity_ids` that did not link. */
62
+ unlinked: UnlinkedEntityName[];
61
63
  }
62
64
  export interface NotificationsSendInput {
63
65
  /** Notification title (≤200 chars). */
@@ -9,7 +9,7 @@
9
9
  * 503.
10
10
  *
11
11
  * The backoff loop lives here rather than being imported from `@lobu/core`:
12
- * core's root entry drags winston, Sentry and OpenTelemetry into every
12
+ * core's root entry drags winston and OpenTelemetry into every
13
13
  * connector bundle, and the package root must stay loadable inside a V8
14
14
  * isolate. It keeps the semantics of core's `retryWithBackoff` for the one
15
15
  * configuration `withHttpRetry` uses: exponential, capped, full jitter.
@@ -9,7 +9,7 @@
9
9
  * 503.
10
10
  *
11
11
  * The backoff loop lives here rather than being imported from `@lobu/core`:
12
- * core's root entry drags winston, Sentry and OpenTelemetry into every
12
+ * core's root entry drags winston and OpenTelemetry into every
13
13
  * connector bundle, and the package root must stay loadable inside a V8
14
14
  * isolate. It keeps the semantics of core's `retryWithBackoff` for the one
15
15
  * configuration `withHttpRetry` uses: exponential, capped, full jitter.
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Thrown from a feed `read` when the source deliberately withholds the
3
+ * requested record (for example, a private person's communications). The read
4
+ * is reported as withheld rather than failed: the caller is told the reason,
5
+ * nothing is retried, and pagination continues past it.
6
+ *
7
+ * The platform keys on the error's own `code === 'withheld'`, never on this
8
+ * class, so a connector on an older SDK opts in with
9
+ * `Object.assign(new Error(reason), { code: 'withheld' })`. The message is the
10
+ * human reason shown to the user.
11
+ */
12
+ export declare class SourceWithheldError extends Error {
13
+ readonly code: "withheld";
14
+ constructor(reason: string);
15
+ }
16
+ //# sourceMappingURL=source-withheld-error.d.ts.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Thrown from a feed `read` when the source deliberately withholds the
3
+ * requested record (for example, a private person's communications). The read
4
+ * is reported as withheld rather than failed: the caller is told the reason,
5
+ * nothing is retried, and pagination continues past it.
6
+ *
7
+ * The platform keys on the error's own `code === 'withheld'`, never on this
8
+ * class, so a connector on an older SDK opts in with
9
+ * `Object.assign(new Error(reason), { code: 'withheld' })`. The message is the
10
+ * human reason shown to the user.
11
+ */
12
+ export class SourceWithheldError extends Error {
13
+ code = 'withheld';
14
+ constructor(reason) {
15
+ super(reason);
16
+ this.name = 'SourceWithheldError';
17
+ }
18
+ }
19
+ //# sourceMappingURL=source-withheld-error.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/connector-sdk",
3
- "version": "24.8.0",
3
+ "version": "24.10.0",
4
4
  "description": "Lobu memory SDK — build pluggable connectors for Lobu memory",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -153,10 +153,13 @@ function drain(stream, capBytes) {
153
153
  * for deterministic account limits. Generic stream errors remain owned by the
154
154
  * CLI and its own retry loop.
155
155
  *
156
- * The wording accepted here must stay a subset of what the server's
157
- * `deviceProviderQuotaResetNotBefore` recognizes as quota evidence. Killing a
158
- * run the server will not park just moves the same failure to the next cron
159
- * tick, which is the waste this path exists to stop.
156
+ * OpenCode keeps retrying an account limit for the provider's whole reset
157
+ * window, so the run would otherwise burn its wall clock before failing.
158
+ * Accept only wording no in-run retry can clear: an empty balance, or a
159
+ * daily/weekly/monthly usage window that resets hours or more away. A short
160
+ * rate limit stays with the CLI, whose own retry may still finish the run.
161
+ * The relayed reason must still classify as provider quota in core's
162
+ * `classifyErrorMessage`, so the failed run is not blamed on the agent.
160
163
  */
161
164
  function openCodeTerminalRetryDiagnostic(output) {
162
165
  const lines = output.split(/\r?\n/);
@@ -13,4 +13,5 @@ export type { DaemonConfig } from './worker.js';
13
13
  export { startDaemon, WorkerDaemon } from './worker.js';
14
14
  export { resolveDaemonLaunchContext, resolveDaemonWorkerId, startDaemonCommand, type DaemonStartOptions, } from './start.js';
15
15
  export { executeClaimedAutomationRun, UnexecutableRunError } from './execute-run.js';
16
+ export { completeSyncOnce } from './terminal-delivery.js';
16
17
  //# sourceMappingURL=index.d.ts.map
@@ -10,4 +10,5 @@ export { executeRun } from './executor.js';
10
10
  export { startDaemon, WorkerDaemon } from './worker.js';
11
11
  export { resolveDaemonLaunchContext, resolveDaemonWorkerId, startDaemonCommand, } from './start.js';
12
12
  export { executeClaimedAutomationRun, UnexecutableRunError } from './execute-run.js';
13
+ export { completeSyncOnce } from './terminal-delivery.js';
13
14
  //# sourceMappingURL=index.js.map
@@ -1,10 +1,20 @@
1
1
  import type { CompleteAgentTurnRequest, CompleteAgentTurnResponse, ExecutorClient } from './client.js';
2
+ interface TerminalDeliveryPolicy {
3
+ deadlineMs: number;
4
+ attempts: number;
5
+ /** Pause before retry N (0-based), doubled each time; 0 retries at once. */
6
+ backoffMs: number;
7
+ retriable: (error: unknown) => boolean;
8
+ }
9
+ /** Compresses a sync/action delivery budget; tests pass this to keep backoff fast. */
10
+ type DeliveryTiming = Partial<Pick<TerminalDeliveryPolicy, 'deadlineMs' | 'backoffMs'>>;
2
11
  /**
3
12
  * A delivery failure's retry classification: HTTP 5xx/429 and transport errors
4
13
  * are retriable; an explicit decode failure or any other 4xx is not.
5
14
  */
6
15
  export declare function isRetriableDeliveryFailure(err: unknown): boolean;
7
- export declare function completeSyncOnce(client: ExecutorClient, payload: Parameters<ExecutorClient['complete']>[0]): Promise<void>;
8
- export declare function completeActionOnce(client: ExecutorClient, payload: Parameters<ExecutorClient['completeAction']>[0]): Promise<void>;
16
+ export declare function completeSyncOnce(client: ExecutorClient, payload: Parameters<ExecutorClient['complete']>[0], timing?: DeliveryTiming): Promise<void>;
17
+ export declare function completeActionOnce(client: ExecutorClient, payload: Parameters<ExecutorClient['completeAction']>[0], timing?: DeliveryTiming): Promise<void>;
9
18
  export declare function completeAgentTurnOnce(client: ExecutorClient, payload: CompleteAgentTurnRequest): Promise<CompleteAgentTurnResponse>;
19
+ export {};
10
20
  //# sourceMappingURL=terminal-delivery.d.ts.map
@@ -1,16 +1,23 @@
1
1
  /**
2
2
  * Bounded delivery of an immutable terminal outcome. Execution and failure
3
- * reporting share the retry loop; sync/action and agent-turn budgets differ.
4
- * WorkerDecodeError identifies an unreadable response, not an execution
5
- * failure, and is surfaced without retrying.
3
+ * reporting share the retry loop and its classification; sync/action and
4
+ * agent-turn budgets differ. WorkerDecodeError identifies an unreadable
5
+ * response, not an execution failure, and is surfaced without retrying.
6
6
  */
7
7
  import { WorkerDecodeError, WorkerHttpError } from './client.js';
8
- /** Syncs/actions: two attempts in 15s, anything but an undecodable answer retried. */
8
+ /**
9
+ * Syncs/actions ride out a gateway rollout: a dying replica answers 5xx or
10
+ * drops the connection, and an immediate retry would reach the same one. Six
11
+ * attempts back off 1s, 2s, 4s, 8s, 16s, all inside 90s -- the reaper writes
12
+ * a run off 120s after its last heartbeat, and the executor stops heartbeating
13
+ * up to 30s before delivery starts. A 4xx other than 429 is the gateway's
14
+ * answer and is not re-sent.
15
+ */
9
16
  const ACTION_DELIVERY = {
10
- deadlineMs: 15_000,
11
- attempts: 2,
12
- backoffMs: 0,
13
- retriable: (error) => !(error instanceof WorkerDecodeError),
17
+ deadlineMs: 90_000,
18
+ attempts: 6,
19
+ backoffMs: 1_000,
20
+ retriable: isRetriableDeliveryFailure,
14
21
  };
15
22
  /**
16
23
  * Agent turns retry transient delivery failures across a short gateway outage.
@@ -89,11 +96,11 @@ async function deliverTerminal(send, policy) {
89
96
  }
90
97
  throw lastError instanceof Error ? lastError : new Error(String(lastError));
91
98
  }
92
- export async function completeSyncOnce(client, payload) {
93
- await deliverTerminal(() => client.complete(payload), ACTION_DELIVERY);
99
+ export async function completeSyncOnce(client, payload, timing = {}) {
100
+ await deliverTerminal(() => client.complete(payload), { ...ACTION_DELIVERY, ...timing });
94
101
  }
95
- export async function completeActionOnce(client, payload) {
96
- await deliverTerminal(() => client.completeAction(payload), ACTION_DELIVERY);
102
+ export async function completeActionOnce(client, payload, timing = {}) {
103
+ await deliverTerminal(() => client.completeAction(payload), { ...ACTION_DELIVERY, ...timing });
97
104
  }
98
105
  export function completeAgentTurnOnce(client, payload) {
99
106
  return deliverTerminal(() => client.completeAgentTurn(payload), AGENT_TURN_DELIVERY);
@@ -238,12 +238,20 @@ export interface SyncExecutor {
238
238
  execute(compiledCode: string, job: ExecutorJob, hooks?: ExecutionHooks): Promise<ExecutorResult>;
239
239
  }
240
240
  export type ConnectorExitReason = 'ok' | 'error_message' | 'timeout' | 'oom' | 'crash';
241
+ /**
242
+ * A structured outcome the connector itself declared on the error it threw.
243
+ * `withheld`: the source deliberately withholds the record (SourceWithheldError).
244
+ */
245
+ export type ConnectorErrorCode = 'withheld';
241
246
  export interface ConnectorExecutionDiagnostics {
242
247
  exitCode: number | null;
243
248
  exitSignal: string | null;
244
249
  outputTail: string;
245
250
  exitReason: ConnectorExitReason;
246
251
  httpStatus?: number;
252
+ /** Validated PostgreSQL SQLSTATE; distinct from connector outcome codes. */
253
+ pgCode?: string;
254
+ code?: ConnectorErrorCode;
247
255
  }
248
256
  export declare class ConnectorExecutionError extends Error implements ConnectorExecutionDiagnostics {
249
257
  exitCode: number | null;
@@ -251,6 +259,8 @@ export declare class ConnectorExecutionError extends Error implements ConnectorE
251
259
  outputTail: string;
252
260
  exitReason: ConnectorExitReason;
253
261
  httpStatus?: number;
262
+ pgCode?: string;
263
+ code?: ConnectorErrorCode;
254
264
  constructor(message: string, diagnostics: ConnectorExecutionDiagnostics, options?: {
255
265
  cause?: unknown;
256
266
  });
@@ -4,6 +4,8 @@ export class ConnectorExecutionError extends Error {
4
4
  outputTail;
5
5
  exitReason;
6
6
  httpStatus;
7
+ pgCode;
8
+ code;
7
9
  constructor(message, diagnostics, options) {
8
10
  super(message, options);
9
11
  this.name = 'ConnectorExecutionError';
@@ -12,6 +14,10 @@ export class ConnectorExecutionError extends Error {
12
14
  this.outputTail = diagnostics.outputTail;
13
15
  this.exitReason = diagnostics.exitReason;
14
16
  this.httpStatus = diagnostics.httpStatus;
17
+ if (diagnostics.pgCode)
18
+ this.pgCode = diagnostics.pgCode;
19
+ if (diagnostics.code)
20
+ this.code = diagnostics.code;
15
21
  }
16
22
  }
17
23
  /** Per-stream ring buffer that preserves the most recent bytes. */
@@ -83,6 +83,7 @@ export declare class IsolateExecutor implements SyncExecutor {
83
83
  private assertHostAllowed;
84
84
  private requireIsolatedVm;
85
85
  execute(compiledCode: string, job: ExecutorJob, hooks?: ExecutionHooks): Promise<ExecutorResult>;
86
+ private executeInIsolate;
86
87
  /** Build the `ConnectorExecutionError` the daemon reports for a guest-thrown error. */
87
88
  private guestError;
88
89
  private hostFetch;
@@ -62,6 +62,8 @@ const MAX_REDIRECTS = 20;
62
62
  * reads; an honest connector drains or cancels every body it opens.
63
63
  */
64
64
  const MAX_OPEN_FETCHES = 1024;
65
+ /** Rejects a host hook that was still queued when the run ended; never a run's failure. */
66
+ const SKIPPED_HOOK = new Error('the run ended before this hook started');
65
67
  /** Thrown when a job demands the isolate lane on a host that cannot run one. */
66
68
  export class IsolateRuntimeUnavailableError extends Error {
67
69
  constructor(reason) {
@@ -223,6 +225,9 @@ const GUEST_RUNNER = String.raw `
223
225
  if (job.exactMatch && job.exactMatch.verbatim === true && !(queryCapabilities && queryCapabilities.verbatimExactMatch === true)) {
224
226
  throw Object.assign(new Error('Connector does not support verbatim exact-match queries'), { status: 400 });
225
227
  }
228
+ if (job.exactMatch && job.exactMatch.values !== undefined && !(queryCapabilities && queryCapabilities.exactMatchAny === true)) {
229
+ throw Object.assign(new Error('Connector does not support multi-value exact-match queries'), { status: 400 });
230
+ }
226
231
  var queryResult = await instance.query({
227
232
  query: job.query, config: mergedConfig, credentials: job.credentials, sessionState: job.sessionState,
228
233
  limit: job.limit, offset: job.offset, sort: job.sort, exactMatch: job.exactMatch, selection: supportsSelection ? job.selection : undefined
@@ -474,13 +479,44 @@ export class IsolateExecutor {
474
479
  return ivm;
475
480
  }
476
481
  async execute(compiledCode, job, hooks) {
482
+ const tail = new RingBuffer(STREAM_TAIL_CAP_BYTES);
483
+ if (this.options.timeoutMs === 0)
484
+ return this.executeInIsolate(compiledCode, job, hooks, tail);
485
+ // The budget belongs to the whole run, including native context setup.
486
+ // Race setup too: merely subtracting its duration would still leave a
487
+ // caller waiting indefinitely before the guest's timer could start.
488
+ const timeoutAbort = new AbortController();
489
+ const signal = hooks?.signal
490
+ ? AbortSignal.any([hooks.signal, timeoutAbort.signal])
491
+ : timeoutAbort.signal;
492
+ let timer;
493
+ const timeout = new Promise((_resolve, reject) => {
494
+ timer = setTimeout(() => {
495
+ const outputTail = redactOutput(tail.toString());
496
+ reject(new ConnectorExecutionError(`Execution timed out after ${this.options.timeoutMs}ms${outputTail ? `\n[console]\n${outputTail}` : ''}`, { exitCode: null, exitSignal: null, outputTail, exitReason: 'timeout' }));
497
+ // An in-flight host is terminated immediately. If setup resolves
498
+ // later, executeInIsolate's cancellation latch disposes it before
499
+ // handing it any guest code.
500
+ timeoutAbort.abort();
501
+ }, this.options.timeoutMs);
502
+ });
503
+ try {
504
+ return await Promise.race([
505
+ this.executeInIsolate(compiledCode, job, { ...hooks, signal }, tail),
506
+ timeout,
507
+ ]);
508
+ }
509
+ finally {
510
+ clearTimeout(timer);
511
+ }
512
+ }
513
+ async executeInIsolate(compiledCode, job, hooks, tail) {
477
514
  if (job.httpAuth && !hooks?.onHttpFetch) {
478
515
  throw new Error('HTTP authentication requires a gateway fetch hook');
479
516
  }
480
517
  assertIsolateEligible(compiledCode);
481
518
  const exemptHosts = [...this.exactAllowedHosts, ...operatorHttpExemptHosts(job)];
482
519
  const ivm = await this.requireIsolatedVm();
483
- const tail = new RingBuffer(STREAM_TAIL_CAP_BYTES);
484
520
  let logBytesUsed = 0;
485
521
  let logTruncated = false;
486
522
  let hookFailure = null;
@@ -558,7 +594,11 @@ export class IsolateExecutor {
558
594
  }
559
595
  });
560
596
  };
597
+ // The first state that ended the run. A run can end after the guest
598
+ // returned, while its hooks drain; that run did not complete.
599
+ let endedWith = null;
561
600
  const terminate = (state) => {
601
+ endedWith ??= state;
562
602
  runAbort.abort();
563
603
  for (const timer of pendingSleeps)
564
604
  clearTimeout(timer);
@@ -589,12 +629,21 @@ export class IsolateExecutor {
589
629
  hooks?.signal?.addEventListener('abort', onCancel, { once: true });
590
630
  const queueHook = (task) => {
591
631
  const next = processingChain.then(async () => {
632
+ // A hook queued behind one that outlived the run must not start: the
633
+ // run already has its terminal state, so any side effect now would
634
+ // land for a run reported as failed.
635
+ if (runAbort.signal.aborted)
636
+ throw SKIPPED_HOOK;
592
637
  await task();
593
638
  });
594
639
  // Keep the chain alive after a failure so later calls still see the
595
640
  // terminal state instead of re-running against a torn-down host.
596
641
  processingChain = next.catch(() => undefined);
597
642
  next.catch((error) => {
643
+ // A skipped hook is a consequence of the run's end, not its cause:
644
+ // the original failure keeps its name, status and diagnostics.
645
+ if (error === SKIPPED_HOOK)
646
+ return;
598
647
  if (hookFailure === null)
599
648
  hookFailure = error;
600
649
  terminate({ name: 'HookFailure', message: error instanceof Error ? error.message : String(error) });
@@ -702,7 +751,7 @@ export class IsolateExecutor {
702
751
  return { data: chunk.value, done: false };
703
752
  };
704
753
  const mergedConfig = job.mode === 'authenticate' ? job.config : buildConnectorConfig(job);
705
- host = await IsolateHost.create({
754
+ const createHost = () => IsolateHost.create({
706
755
  ivm,
707
756
  memoryMb: this.options.memoryMb,
708
757
  messageBytes: this.options.messageBytes,
@@ -1028,12 +1077,13 @@ export class IsolateExecutor {
1028
1077
  },
1029
1078
  },
1030
1079
  });
1031
- const redactedTail = () => redactOutput(tail.toString());
1032
- const withTail = (prefix) => {
1033
- const t = redactedTail();
1034
- return t ? `${prefix}\n[console]\n${t}` : prefix;
1035
- };
1036
1080
  try {
1081
+ host = await createHost();
1082
+ const redactedTail = () => redactOutput(tail.toString());
1083
+ const withTail = (prefix) => {
1084
+ const t = redactedTail();
1085
+ return t ? `${prefix}\n[console]\n${t}` : prefix;
1086
+ };
1037
1087
  const source = `var __job_json = ${jsonLiteral(guestJob)};\nvar __config_json = ${jsonLiteral(mergedConfig)};\n${compiledCode}\n${GUEST_RUNNER}`;
1038
1088
  let raw;
1039
1089
  try {
@@ -1044,7 +1094,9 @@ export class IsolateExecutor {
1044
1094
  // reports through exactly the path a mid-run cancel takes.
1045
1095
  if (cancelled || hooks?.signal?.aborted)
1046
1096
  host.terminate(cancelState);
1047
- raw = await host.run(source, { timeoutMs: this.options.timeoutMs });
1097
+ // execute owns the single deadline from entry, including setup and
1098
+ // outstanding hooks; a second guest timer would restart the budget.
1099
+ raw = await host.run(source, { timeoutMs: 0 });
1048
1100
  }
1049
1101
  catch (error) {
1050
1102
  if (hookFailure !== null)
@@ -1052,19 +1104,6 @@ export class IsolateExecutor {
1052
1104
  if (guestFatal)
1053
1105
  throw this.guestError(guestFatal, redactedTail());
1054
1106
  if (error instanceof IsolateHostError) {
1055
- if (error.kind === 'timeout') {
1056
- // Not "Feed execution": this executor runs feeds, connector
1057
- // actions AND agent turns, and a chat user whose turn timed out
1058
- // was being told a feed had failed. The classifier maps both
1059
- // spellings (classify-error.ts) so a mid-rollout worker still
1060
- // classifies.
1061
- throw new ConnectorExecutionError(withTail(`Execution timed out after ${this.options.timeoutMs}ms`), {
1062
- exitCode: null,
1063
- exitSignal: null,
1064
- outputTail: redactedTail(),
1065
- exitReason: 'timeout',
1066
- });
1067
- }
1068
1107
  if (error.kind === 'memory') {
1069
1108
  throw new ConnectorExecutionError(withTail(`Isolate out of memory (limit ${this.options.memoryMb} MB)`), {
1070
1109
  exitCode: null,
@@ -1084,10 +1123,31 @@ export class IsolateExecutor {
1084
1123
  throw this.guestError(error instanceof Error ? { name: error.name, message: error.message, stack: error.stack } : { message: String(error) }, redactedTail());
1085
1124
  }
1086
1125
  // Wait for hooks the guest fired without awaiting (or whose promise the
1087
- // guest dropped) before reporting the result.
1088
- await processingChain;
1126
+ // guest dropped) before reporting the result. A hook fired just before
1127
+ // the guest returned can join the chain after this wait begins, so wait
1128
+ // until the chain stops growing.
1129
+ let drained;
1130
+ do {
1131
+ drained = processingChain;
1132
+ await drained;
1133
+ } while (drained !== processingChain);
1089
1134
  if (hookFailure !== null)
1090
1135
  throw hookFailure;
1136
+ // The guest returned, but the run ended (e.g. cancelled) while its hooks
1137
+ // drained, so some never ran or never reached the host: reporting
1138
+ // success would drop their side effects silently.
1139
+ // Assigned inside `terminate`, which TypeScript's narrowing cannot see.
1140
+ const ended = endedWith;
1141
+ if (ended) {
1142
+ if (guestFatal)
1143
+ throw this.guestError(guestFatal, redactedTail());
1144
+ throw new ConnectorExecutionError(withTail(ended.message), {
1145
+ exitCode: null,
1146
+ exitSignal: null,
1147
+ outputTail: redactedTail(),
1148
+ exitReason: 'crash',
1149
+ });
1150
+ }
1091
1151
  const outcome = parseGuestJson(raw, 'result');
1092
1152
  if (!outcome || typeof outcome !== 'object' || typeof outcome.ok !== 'boolean') {
1093
1153
  throw new Error('result: guest returned a malformed outcome envelope');
@@ -1109,7 +1169,7 @@ export class IsolateExecutor {
1109
1169
  closeAllSockets();
1110
1170
  vault.clear();
1111
1171
  void egress.destroy().catch(() => undefined);
1112
- host.dispose();
1172
+ host?.dispose();
1113
1173
  }
1114
1174
  }
1115
1175
  /** Build the `ConnectorExecutionError` the daemon reports for a guest-thrown error. */
@@ -1123,6 +1183,10 @@ export class IsolateExecutor {
1123
1183
  httpStatus: typeof description.httpStatus === 'number' && description.httpStatus >= 100 && description.httpStatus < 600
1124
1184
  ? description.httpStatus
1125
1185
  : undefined,
1186
+ code: description.code === 'withheld' ? description.code : undefined,
1187
+ pgCode: typeof description.pgCode === 'string' && /^[0-9A-Z]{5}$/.test(description.pgCode) && !description.pgCode.startsWith('E')
1188
+ ? description.pgCode
1189
+ : undefined,
1126
1190
  });
1127
1191
  error.name = description.name ? redactOutput(String(description.name)) : 'ConnectorExecutionError';
1128
1192
  if (description.stack)
@@ -303,6 +303,11 @@ var exports = module.exports;
303
303
  if (error instanceof Error) {
304
304
  var desc = { name: String(error.name || 'Error'), message: String(error.message), stack: typeof error.stack === 'string' ? error.stack : undefined };
305
305
  if (typeof error.status === 'number' && error.status >= 100 && error.status < 600) desc.httpStatus = error.status;
306
+ // A deliberately withheld source read (SourceWithheldError, or any error
307
+ // whose own code is 'withheld'). SQLSTATE travels separately so it cannot
308
+ // be mistaken for a connector outcome. Ambiguous E-prefixed errnos stay opaque.
309
+ if (Object.prototype.hasOwnProperty.call(error, 'code') && error.code === 'withheld') desc.code = 'withheld';
310
+ if (Object.prototype.hasOwnProperty.call(error, 'code') && typeof error.code === 'string' && /^[0-9A-Z]{5}$/.test(error.code) && error.code.charAt(0) !== 'E') desc.pgCode = error.code;
306
311
  return desc;
307
312
  }
308
313
  var text;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/connector-worker",
3
- "version": "24.8.0",
3
+ "version": "24.10.0",
4
4
  "description": "Self-hosted worker for Lobu memory — connectors and embedding generation",
5
5
  "type": "module",
6
6
  "bin": {
@@ -5,13 +5,12 @@
5
5
  * `AgentErrorCode`. Every other layer consumes this rather than growing its
6
6
  * own regex, and three of them act on the result:
7
7
  *
8
- * - `providerQuotaResetNotBefore` (automations/schedule-cursor.ts) returns
9
- * `null` unless the code is `PROVIDER_QUOTA_EXHAUSTED`, so an unclassified
10
- * quota trip never parks the Automation until the provider's reset — it
11
- * keeps firing on schedule against an exhausted quota.
8
+ * - `classifyRunOutcome` (server runs/run-outcome.ts) stamps a classified
9
+ * failure `infra_error`; an unclassified provider refusal is blamed on the
10
+ * agent as `agent_error`.
12
11
  * - `response-renderer.ts` and `chat-response-bridge.ts` resolve the code to
13
12
  * a remediation CTA; with none, the user gets the provider's raw prose.
14
- * - An unclassified failure also misses the `PROVIDER_*` Sentry alerting.
13
+ * - An unclassified failure also misses the `PROVIDER_*` error alerting.
15
14
  *
16
15
  * Adding a failure mode = one pattern here + one entry in `AGENT_ERRORS`.
17
16
  *