@lobu/runtime-device 24.8.0 → 24.9.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 (70) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +24 -24
  3. package/npm-shrinkwrap.json +179 -175
  4. package/package.json +1 -1
  5. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +14 -3
  6. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +27 -0
  7. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +16 -5
  8. package/vendor/cli/dist/commands/_lib/apply/client.js +31 -9
  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/memory/_lib/seed-cmd.js +6 -2
  21. package/vendor/cli/dist/config/define.d.ts +21 -3
  22. package/vendor/cli/dist/connectors/README.md +6 -2
  23. package/vendor/cli/dist/connectors/github.ts +16 -3
  24. package/vendor/cli/dist/connectors/market_quotes.ts +388 -91
  25. package/vendor/cli/dist/connectors/postgres.ts +21 -14
  26. package/vendor/cli/dist/connectors/x-dm-adapter.js +55 -21
  27. package/vendor/cli/dist/connectors/x.ts +1 -1
  28. package/vendor/cli/dist/runtime-components.json +4 -4
  29. package/vendor/cli/package.json +1 -1
  30. package/vendor/connector-sdk/dist/connector-types.d.ts +23 -2
  31. package/vendor/connector-sdk/package.json +1 -1
  32. package/vendor/connector-worker/dist/daemon/automation.js +7 -4
  33. package/vendor/connector-worker/dist/executor/isolate.js +3 -0
  34. package/vendor/connector-worker/package.json +1 -1
  35. package/vendor/core/dist/classify-error.d.ts +3 -4
  36. package/vendor/core/dist/classify-error.js +8 -8
  37. package/vendor/core/dist/contracts/tools/collection-presentation.d.ts +17 -1
  38. package/vendor/core/dist/contracts/tools/collection-presentation.js +27 -3
  39. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +39 -0
  40. package/vendor/core/dist/contracts/tools/manage-automations.js +11 -1
  41. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +1 -1
  42. package/vendor/core/dist/contracts/tools/manage-views.d.ts +249 -7
  43. package/vendor/core/dist/contracts/tools/manage-views.js +83 -21
  44. package/vendor/core/dist/contracts/tools/navigation.d.ts +248 -0
  45. package/vendor/core/dist/contracts/tools/navigation.js +284 -0
  46. package/vendor/core/dist/contracts/tools/view-attach.d.ts +7 -0
  47. package/vendor/core/dist/contracts/tools/view-attach.js +15 -0
  48. package/vendor/core/dist/contracts/tools/view-content-hash.d.ts +4 -1
  49. package/vendor/core/dist/contracts/tools/view-content-hash.js +4 -2
  50. package/vendor/core/dist/contracts/tools/view-definition.d.ts +2 -0
  51. package/vendor/core/dist/contracts/tools/view-definition.js +52 -0
  52. package/vendor/core/dist/contracts/tools/view-host.d.ts +68 -0
  53. package/vendor/core/dist/contracts/tools/view-host.js +28 -1
  54. package/vendor/core/dist/contracts/tools/view-scope.d.ts +31 -0
  55. package/vendor/core/dist/contracts/tools/view-scope.js +45 -0
  56. package/vendor/core/dist/errors.d.ts +17 -24
  57. package/vendor/core/dist/errors.js +17 -24
  58. package/vendor/core/dist/types.d.ts +0 -6
  59. package/vendor/core/package.json +11 -1
  60. package/vendor/views/dist/api.d.ts +30 -5
  61. package/vendor/views/dist/api.js +22 -8
  62. package/vendor/views/dist/bridge.d.ts +17 -0
  63. package/vendor/views/dist/bridge.js +49 -1
  64. package/vendor/views/dist/components.d.ts +27 -5
  65. package/vendor/views/dist/components.js +57 -7
  66. package/vendor/views/dist/embed.d.ts +98 -0
  67. package/vendor/views/dist/embed.js +418 -0
  68. package/vendor/views/dist/index.d.ts +3 -1
  69. package/vendor/views/dist/index.js +1 -0
  70. package/vendor/views/package.json +1 -1
@@ -621,6 +621,20 @@ export function xDirectMessagesProgram() {
621
621
  fail("Unable to attach source subscription");
622
622
  return { listening: true };
623
623
  }
624
+ // X serves at most 50 entries per notifications page (`count=50`); the
625
+ // cap leaves room for a page grown by a replacement instruction.
626
+ const PAGE_ROWS_MAX = 200;
627
+ // A short row-identity hash for the in-page cursor: a page's returned set
628
+ // stays well under the 10,000-character cursor bound.
629
+ async function rowKey(id) {
630
+ const hash = await crypto.subtle.digest(
631
+ "SHA-256",
632
+ new TextEncoder().encode(id),
633
+ );
634
+ return Array.from(new Uint8Array(hash).slice(0, 6), (x) =>
635
+ x.toString(16).padStart(2, "0"),
636
+ ).join("");
637
+ }
624
638
  // The notification API is read from this same neutral page. In particular,
625
639
  // never render /notifications or call its seen/read-state endpoints here.
626
640
  async function readNotifications(input) {
@@ -635,13 +649,32 @@ export function xDirectMessagesProgram() {
635
649
  fail("Invalid notification cursor");
636
650
  cursor = JSON.parse(input.cursor);
637
651
  if (
638
- cursor.v !== 1 ||
652
+ ![1, 2].includes(cursor.v) ||
639
653
  cursor.kind !== "notifications" ||
640
654
  cursor.account !== self ||
641
- !(cursor.source === null || typeof cursor.source === "string") ||
642
- !(cursor.after === null || typeof cursor.after === "string")
655
+ !(cursor.source === null || typeof cursor.source === "string")
643
656
  )
644
657
  fail("Notification cursor belongs to another account or source");
658
+ // v1 boundary cursors persist in sync checkpoints and equal a v2
659
+ // cursor with nothing returned yet. A v1 cursor inside a source page
660
+ // anchored on one row, which X can re-key; that read must restart.
661
+ if (cursor.v === 1) {
662
+ if (cursor.after !== null) {
663
+ account(self);
664
+ if (input.restartExpired)
665
+ return { rows: [], account_id: self, expired: true };
666
+ fail(
667
+ "Notification cursor format changed; restart the read (coverage incomplete)",
668
+ );
669
+ }
670
+ cursor = { ...cursor, returned: [] };
671
+ }
672
+ if (
673
+ !Array.isArray(cursor.returned) ||
674
+ cursor.returned.length > PAGE_ROWS_MAX ||
675
+ !cursor.returned.every((x) => typeof x === "string" && x.length === 12)
676
+ )
677
+ fail("Invalid notification cursor");
645
678
  }
646
679
  const path =
647
680
  "/i/api/2/notifications/all.json?count=50" +
@@ -760,39 +793,40 @@ export function xDirectMessagesProgram() {
760
793
  if (input.metadataOnly) delete row.text;
761
794
  all.push(row);
762
795
  }
763
- let start = 0;
764
- if (cursor?.after) {
765
- start = all.findIndex((row) => row.id === cursor.after) + 1;
766
- if (!start) {
767
- account(self);
768
- if (input.restartExpired)
769
- return { rows: [], account_id: self, expired: true };
770
- fail(
771
- "Notification page changed; restart the read (coverage incomplete)",
772
- );
773
- }
774
- }
775
- const rows = all.slice(start, start + limit);
776
- const moreInPage = start + rows.length < all.length;
796
+ // Resume by excluding rows already returned from this source page, not
797
+ // by anchoring on one row: X regroups its newest page between reads
798
+ // (re-keying, dropping, or reordering grouped reactions). A re-keyed
799
+ // row may come back as a duplicate reference, deduped by origin_id;
800
+ // no row is ever skipped.
801
+ const returned = new Set(cursor?.returned ?? []);
802
+ const keys = [];
803
+ for (const row of all) keys.push(await rowKey(row.id));
804
+ const remaining = all.filter((_, index) => !returned.has(keys[index]));
805
+ const rows = remaining.slice(0, limit);
806
+ const moreInPage = rows.length < remaining.length;
777
807
  if (!moreInPage && cursor && next === cursor.source) {
778
808
  if (all.length) fail("Notification cursor did not advance");
779
809
  next = undefined;
780
810
  }
811
+ // Keep only keys still on the page, so the set stays page-bounded.
812
+ const sent = new Set(rows.map((row) => row.id));
781
813
  const nextCursor = moreInPage
782
814
  ? JSON.stringify({
783
- v: 1,
815
+ v: 2,
784
816
  kind: "notifications",
785
817
  account: self,
786
818
  source: cursor?.source ?? null,
787
- after: rows.at(-1).id,
819
+ returned: keys.filter(
820
+ (key, index) => returned.has(key) || sent.has(all[index].id),
821
+ ),
788
822
  })
789
823
  : next
790
824
  ? JSON.stringify({
791
- v: 1,
825
+ v: 2,
792
826
  kind: "notifications",
793
827
  account: self,
794
828
  source: next,
795
- after: null,
829
+ returned: [],
796
830
  })
797
831
  : undefined;
798
832
  if (account() !== self)
@@ -3876,7 +3876,7 @@ export default class XConnector extends ConnectorRuntime {
3876
3876
  name: "X (Twitter)",
3877
3877
  description:
3878
3878
  "Fetches tweets, browser-visible like history, bookmarks, and DMs through the X API v2 or the paired Owletto Chrome extension, reads the chronological Following timeline live through the X API, captures notification references and the accounts you follow, reads and answers DMs live in the paired browser, and likes posts or follows accounts there. Links social actors into the person and company graph.",
3879
- version: "3.17.1",
3879
+ version: "3.17.2",
3880
3880
  faviconDomain: "x.com",
3881
3881
  browser: {
3882
3882
  origins: ["https://x.com", "https://twitter.com"],
@@ -5,7 +5,7 @@
5
5
  "server": "dist/server.bundle.mjs",
6
6
  "embeddingsServer": "dist/embeddings-server.mjs"
7
7
  },
8
- "version": "24.8.0",
8
+ "version": "24.9.0",
9
9
  "verify": "dist/verify.mjs"
10
10
  },
11
11
  "device": {
@@ -16,7 +16,7 @@
16
16
  "connector": "node_modules/@lobu/cli/dist/commands/connector.js",
17
17
  "worker": "node_modules/@lobu/connector-worker/dist/bin.js"
18
18
  },
19
- "version": "24.8.0",
19
+ "version": "24.9.0",
20
20
  "verify": "dist/verify.mjs"
21
21
  },
22
22
  "postgres": {
@@ -24,7 +24,7 @@
24
24
  "entries": {
25
25
  "postgres": "dist/index.mjs"
26
26
  },
27
- "version": "24.8.0",
27
+ "version": "24.9.0",
28
28
  "verify": "dist/verify.mjs"
29
29
  },
30
30
  "embeddings": {
@@ -32,7 +32,7 @@
32
32
  "entries": {
33
33
  "embeddings": "dist/embeddings.js"
34
34
  },
35
- "version": "24.8.0",
35
+ "version": "24.9.0",
36
36
  "verify": "dist/verify.mjs"
37
37
  }
38
38
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/cli",
3
- "version": "24.8.0",
3
+ "version": "24.9.0",
4
4
  "description": "CLI for deploying and managing AI agents on Lobu",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -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';
@@ -1118,12 +1131,20 @@ export interface QueryContext<F = Record<string, unknown>> {
1118
1131
  * connector, which owns its source dialect. Requires queryCapabilities.exactMatch.
1119
1132
  * `verbatim: true` preserves the scalar string without trimming and additionally
1120
1133
  * requires queryCapabilities.verbatimExactMatch. The default stays trimmed.
1134
+ * Exactly one of `value` / `values` is set. `values` (1-500 strings) keeps a
1135
+ * row whose key equals ANY of them, under the same per-column semantics as
1136
+ * `value`, and additionally requires queryCapabilities.exactMatchAny.
1121
1137
  */
1122
1138
  exactMatch?: {
1123
1139
  columns: string[];
1124
- value: string;
1125
1140
  verbatim?: boolean;
1126
- };
1141
+ } & ({
1142
+ value: string;
1143
+ values?: never;
1144
+ } | {
1145
+ values: string[];
1146
+ value?: never;
1147
+ });
1127
1148
  /**
1128
1149
  * Shared collection predicates, applied before sorting and pagination.
1129
1150
  * Search is a literal case-insensitive substring of the projected name.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/connector-sdk",
3
- "version": "24.8.0",
3
+ "version": "24.9.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/);
@@ -223,6 +223,9 @@ const GUEST_RUNNER = String.raw `
223
223
  if (job.exactMatch && job.exactMatch.verbatim === true && !(queryCapabilities && queryCapabilities.verbatimExactMatch === true)) {
224
224
  throw Object.assign(new Error('Connector does not support verbatim exact-match queries'), { status: 400 });
225
225
  }
226
+ if (job.exactMatch && job.exactMatch.values !== undefined && !(queryCapabilities && queryCapabilities.exactMatchAny === true)) {
227
+ throw Object.assign(new Error('Connector does not support multi-value exact-match queries'), { status: 400 });
228
+ }
226
229
  var queryResult = await instance.query({
227
230
  query: job.query, config: mergedConfig, credentials: job.credentials, sessionState: job.sessionState,
228
231
  limit: job.limit, offset: job.offset, sort: job.sort, exactMatch: job.exactMatch, selection: supportsSelection ? job.selection : undefined
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/connector-worker",
3
- "version": "24.8.0",
3
+ "version": "24.9.0",
4
4
  "description": "Self-hosted worker for Lobu memory — connectors and embedding generation",
5
5
  "type": "module",
6
6
  "bin": {
@@ -5,10 +5,9 @@
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
13
  * - An unclassified failure also misses the `PROVIDER_*` Sentry alerting.
@@ -6,10 +6,9 @@
6
6
  * `AgentErrorCode`. Every other layer consumes this rather than growing its
7
7
  * own regex, and three of them act on the result:
8
8
  *
9
- * - `providerQuotaResetNotBefore` (automations/schedule-cursor.ts) returns
10
- * `null` unless the code is `PROVIDER_QUOTA_EXHAUSTED`, so an unclassified
11
- * quota trip never parks the Automation until the provider's reset — it
12
- * keeps firing on schedule against an exhausted quota.
9
+ * - `classifyRunOutcome` (server runs/run-outcome.ts) stamps a classified
10
+ * failure `infra_error`; an unclassified provider refusal is blamed on the
11
+ * agent as `agent_error`.
13
12
  * - `response-renderer.ts` and `chat-response-bridge.ts` resolve the code to
14
13
  * a remediation CTA; with none, the user gets the provider's raw prose.
15
14
  * - An unclassified failure also misses the `PROVIDER_*` Sentry alerting.
@@ -86,10 +85,11 @@ function classifyErrorMessage(message) {
86
85
  // dodged the PROVIDER_* alert.
87
86
  //
88
87
  // It belongs HERE and not in `PROVIDER_BALANCE_EXHAUSTED` above: a
89
- // subscription usage limit is WINDOWED — the provider names its own reset,
90
- // hours or days out — while that union parks an Automation for a flat day
91
- // regardless. Parking a windowed limit on a balance schedule would be a
92
- // worse bug than the one this fixes.
88
+ // subscription usage limit is WINDOWED — it clears on the provider's own
89
+ // reset — while that union means the account cannot spend until someone tops
90
+ // it up. The device daemon stops a retrying OpenCode run on balance wording
91
+ // alone, so a windowed limit in that union would cut short a run the CLI's
92
+ // own retry could still finish.
93
93
  if (errors_js_1.PROVIDER_WINDOWED_QUOTA.test(message))
94
94
  return errors_js_1.AgentErrorCode.PROVIDER_QUOTA_EXHAUSTED;
95
95
  // Gemini can end a turn with this provider-side tool-call rejection instead
@@ -40,6 +40,11 @@ declare const PresetSchema: import("@sinclair/typebox").TObject<{
40
40
  toDays: import("@sinclair/typebox").TInteger;
41
41
  timeZone: import("@sinclair/typebox").TString;
42
42
  }>>;
43
+ /** Adds `{ field, op: "eq", value: <signed-in user's email> }`. Only a
44
+ * filter: read access is still enforced server-side. */
45
+ viewer: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
46
+ field: import("@sinclair/typebox").TString;
47
+ }>>;
43
48
  }>;
44
49
  export declare const CollectionPresentationSchema: import("@sinclair/typebox").TObject<{
45
50
  presets: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
@@ -71,6 +76,11 @@ export declare const CollectionPresentationSchema: import("@sinclair/typebox").T
71
76
  toDays: import("@sinclair/typebox").TInteger;
72
77
  timeZone: import("@sinclair/typebox").TString;
73
78
  }>>;
79
+ /** Adds `{ field, op: "eq", value: <signed-in user's email> }`. Only a
80
+ * filter: read access is still enforced server-side. */
81
+ viewer: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
82
+ field: import("@sinclair/typebox").TString;
83
+ }>>;
74
84
  }>>>;
75
85
  table: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
76
86
  columns: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
@@ -88,6 +98,12 @@ export type CollectionPresentation = Static<typeof CollectionPresentationSchema>
88
98
  export type CollectionPreset = Static<typeof PresetSchema>;
89
99
  export type CollectionTable = Static<typeof TableSchema>;
90
100
  export declare function parseCollectionPresentation(raw: unknown): CollectionPresentation;
91
- export declare function resolveCollectionPreset(preset: CollectionPreset, now?: Date): CollectionSelection;
101
+ /**
102
+ * The preset as a concrete selection. A viewer preset needs the signed-in
103
+ * viewer and throws without one, so it never widens to every row.
104
+ */
105
+ export declare function resolveCollectionPreset(preset: CollectionPreset, now?: Date, viewer?: {
106
+ email: string;
107
+ }): CollectionSelection;
92
108
  export {};
93
109
  //# sourceMappingURL=collection-presentation.d.ts.map
@@ -32,6 +32,9 @@ const PresetSchema = typebox_1.Type.Object({
32
32
  toDays: typebox_1.Type.Integer({ minimum: -3660, maximum: 3660 }),
33
33
  timeZone: typebox_1.Type.String({ minLength: 1, maxLength: 100 }),
34
34
  }, { additionalProperties: false })),
35
+ /** Adds `{ field, op: "eq", value: <signed-in user's email> }`. Only a
36
+ * filter: read access is still enforced server-side. */
37
+ viewer: typebox_1.Type.Optional(typebox_1.Type.Object({ field: Field }, { additionalProperties: false })),
35
38
  }, { additionalProperties: false });
36
39
  exports.CollectionPresentationSchema = typebox_1.Type.Object({
37
40
  presets: typebox_1.Type.Optional(typebox_1.Type.Array(PresetSchema, { maxItems: 32 })),
@@ -41,6 +44,7 @@ exports.CollectionPresentationSchema = typebox_1.Type.Object({
41
44
  * Both calls run as the viewer; this binding grants no source access. */
42
45
  facetQuery: typebox_1.Type.Optional(typebox_1.Type.String({ minLength: 1, maxLength: 64000 })),
43
46
  }, { additionalProperties: false });
47
+ const MAX_FILTERS = collection_selection_1.AttributeFiltersSchema.maxItems ?? 32;
44
48
  function parseCollectionPresentation(raw) {
45
49
  if (!value_1.Value.Check(exports.CollectionPresentationSchema, raw))
46
50
  throw new Error("Invalid collection presentation configuration");
@@ -49,9 +53,13 @@ function parseCollectionPresentation(raw) {
49
53
  if (keys.has(preset.key))
50
54
  throw new Error(`Duplicate collection preset: ${preset.key}`);
51
55
  keys.add(preset.key);
56
+ // The resolved selection must still fit the selection contract.
57
+ if ((preset.selection.filters?.length ?? 0) +
58
+ (preset.viewer ? 1 : 0) +
59
+ (preset.relativeDate ? 2 : 0) >
60
+ MAX_FILTERS)
61
+ throw new Error(`Collection preset ${preset.key} resolves to more than ${MAX_FILTERS} filters`);
52
62
  if (preset.relativeDate) {
53
- if ((preset.selection.filters?.length ?? 0) > 30)
54
- throw new Error("Relative date presets support at most 30 other filters");
55
63
  if (preset.relativeDate.fromDays > preset.relativeDate.toDays)
56
64
  throw new Error("Relative date range is reversed");
57
65
  // Intl validates IANA timezone names, including UTC.
@@ -62,8 +70,24 @@ function parseCollectionPresentation(raw) {
62
70
  }
63
71
  return raw;
64
72
  }
65
- function resolveCollectionPreset(preset, now = new Date()) {
73
+ /**
74
+ * The preset as a concrete selection. A viewer preset needs the signed-in
75
+ * viewer and throws without one, so it never widens to every row.
76
+ */
77
+ function resolveCollectionPreset(preset, now = new Date(), viewer) {
66
78
  const selection = structuredClone(preset.selection);
79
+ if (preset.viewer) {
80
+ if (!viewer?.email)
81
+ throw new Error(`Collection preset ${preset.key} needs a signed-in viewer`);
82
+ selection.filters = [
83
+ ...(selection.filters ?? []),
84
+ {
85
+ field: preset.viewer.field,
86
+ op: "eq",
87
+ value: viewer.email.toLowerCase(),
88
+ },
89
+ ];
90
+ }
67
91
  if (!preset.relativeDate)
68
92
  return selection;
69
93
  const { field, fromDays, toDays, timeZone } = preset.relativeDate;
@@ -402,6 +402,19 @@ export declare const AutomationClaimNextWindowContextSchema: import("@sinclair/t
402
402
  feed_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
403
403
  }>>>;
404
404
  extraction_schema: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>>;
405
+ /**
406
+ * The run's pinned Automation version instructions. Present on the first
407
+ * page of a window (no source_cursor / before_* cursor), omitted on
408
+ * continuation pages. Follow these instead of a cached copy of the prompt.
409
+ */
410
+ instructions: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
411
+ version_id: import("@sinclair/typebox").TInteger;
412
+ prompt: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
413
+ skills: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
414
+ name: import("@sinclair/typebox").TString;
415
+ content: import("@sinclair/typebox").TString;
416
+ }>>;
417
+ }>>;
405
418
  }>;
406
419
  export type AutomationClaimNextWindowContext = Static<typeof AutomationClaimNextWindowContextSchema>;
407
420
  export declare const AutomationClaimNextWindowResultSchema: import("@sinclair/typebox").TObject<{
@@ -433,6 +446,19 @@ export declare const AutomationClaimNextWindowResultSchema: import("@sinclair/ty
433
446
  feed_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
434
447
  }>>>;
435
448
  extraction_schema: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>>;
449
+ /**
450
+ * The run's pinned Automation version instructions. Present on the first
451
+ * page of a window (no source_cursor / before_* cursor), omitted on
452
+ * continuation pages. Follow these instead of a cached copy of the prompt.
453
+ */
454
+ instructions: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
455
+ version_id: import("@sinclair/typebox").TInteger;
456
+ prompt: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
457
+ skills: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
458
+ name: import("@sinclair/typebox").TString;
459
+ content: import("@sinclair/typebox").TString;
460
+ }>>;
461
+ }>>;
436
462
  }>;
437
463
  }>;
438
464
  export type AutomationClaimNextWindowResult = Static<typeof AutomationClaimNextWindowResultSchema>;
@@ -599,6 +625,19 @@ export declare const ManageAutomationsResultSchema: import("@sinclair/typebox").
599
625
  feed_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
600
626
  }>>>;
601
627
  extraction_schema: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>>;
628
+ /**
629
+ * The run's pinned Automation version instructions. Present on the first
630
+ * page of a window (no source_cursor / before_* cursor), omitted on
631
+ * continuation pages. Follow these instead of a cached copy of the prompt.
632
+ */
633
+ instructions: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
634
+ version_id: import("@sinclair/typebox").TInteger;
635
+ prompt: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
636
+ skills: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
637
+ name: import("@sinclair/typebox").TString;
638
+ content: import("@sinclair/typebox").TString;
639
+ }>>;
640
+ }>>;
602
641
  }>;
603
642
  }>, import("@sinclair/typebox").TObject<{
604
643
  action: import("@sinclair/typebox").TLiteral<"trigger">;
@@ -355,7 +355,7 @@ exports.ManageAutomationsSchema = typebox_1.Type.Object({
355
355
  description: "Submit an Automation window result and advance the Automation arrival mark. Required after every claim_next_window, including when the window held nothing actionable: the mark moves only inside this call, so an unfinished claim lets the lease expire, times the run out, and serves the same content again on the next claim.",
356
356
  }),
357
357
  typebox_1.Type.Literal("claim_next_window", {
358
- description: "Atomically claim the Automation unclaimed arrival window and return bounded source context plus a fenced window token. The window is [arrival mark, now - settle) over events.created_at, not a calendar period. The caller MUST finish the claim with complete_window, even for an empty or non-actionable window.",
358
+ description: "Atomically claim the Automation unclaimed arrival window and return bounded source context plus a fenced window token. The first page carries context.instructions, the prompt and skills of the run's pinned version; follow them instead of a cached copy. The window is [arrival mark, now - settle) over events.created_at, not a calendar period. The caller MUST finish the claim with complete_window, even for an empty or non-actionable window.",
359
359
  }),
360
360
  typebox_1.Type.Literal("trigger", {
361
361
  description: "Create or reuse an immediate Automation run. The result identifies whether Lobu, a device worker, this caller, or another external caller owns execution. Follow the returned next_action: a pending external run uses knowledge.read then automations.completeWindow, while the owner of an existing external lease resumes it with automations.claimNextWindow.",
@@ -689,6 +689,16 @@ exports.AutomationClaimNextWindowContextSchema = typebox_1.Type.Object({
689
689
  feed_id: typebox_1.Type.Optional(typebox_1.Type.Integer()),
690
690
  }))),
691
691
  extraction_schema: typebox_1.Type.Optional(typebox_1.Type.Record(typebox_1.Type.String(), typebox_1.Type.Unknown())),
692
+ /**
693
+ * The run's pinned Automation version instructions. Present on the first
694
+ * page of a window (no source_cursor / before_* cursor), omitted on
695
+ * continuation pages. Follow these instead of a cached copy of the prompt.
696
+ */
697
+ instructions: typebox_1.Type.Optional(typebox_1.Type.Object({
698
+ version_id: typebox_1.Type.Integer(),
699
+ prompt: typebox_1.Type.Union([typebox_1.Type.String(), typebox_1.Type.Null()]),
700
+ skills: typebox_1.Type.Array(typebox_1.Type.Object({ name: typebox_1.Type.String(), content: typebox_1.Type.String() })),
701
+ })),
692
702
  });
693
703
  exports.AutomationClaimNextWindowResultSchema = typebox_1.Type.Object({
694
704
  action: typebox_1.Type.Literal("claim_next_window"),
@@ -95,7 +95,7 @@ exports.ManageEntitySchemaSchema = typebox_1.Type.Object({
95
95
  name: typebox_1.Type.Optional(typebox_1.Type.String({ description: "[create/update] Display name", minLength: 1 })),
96
96
  description: typebox_1.Type.Optional(typebox_1.Type.String({ description: "[create/update] Description" })),
97
97
  metadata_schema: typebox_1.Type.Optional(typebox_1.Type.Record(typebox_1.Type.String(), typebox_1.Type.Unknown(), {
98
- description: "[create/update] JSON Schema for metadata validation. Source-backed types declare a durable projected key with root x-lobu-record-key naming the key column; this enables string entity_id + entity_type addressing and authored links without storing source rows. A linked type cannot change its backing or key until its edges are unlinked. Entity property annotations: x-facet: true exposes scalar enum values as collection filters; x-sidebar: true also exposes those values as navigation shortcuts. x-enum-labels maps stringified enum values to display labels. x-table-label or title labels the attribute. These annotations do not grant access or define separate segments.",
98
+ description: "[create/update] JSON Schema for metadata validation. Source-backed types declare a durable projected key with root x-lobu-record-key naming the key column; this enables string entity_id + entity_type addressing and authored links without storing source rows. A linked type cannot change its backing or key until its edges are unlinked. Root x-lobu-stamps maps a server-owned timestamp field to the field it tracks (e.g. { stage_at: stage }): the stamp must be a declared property with type string and format date-time, and the tracked field a declared property; every write sets the stamp when the tracked field is set on create or changes value, and caller-supplied stamp values are ignored. Entity property annotations: x-facet: true exposes scalar enum values as collection filters; x-sidebar: true also exposes those values as navigation shortcuts. x-enum-labels maps stringified enum values to display labels. x-table-label or title labels the attribute. These annotations do not grant access or define separate segments.",
99
99
  })),
100
100
  list_scope: typebox_1.Type.Optional(typebox_1.Type.Union([typebox_1.Type.Literal("accessible"), typebox_1.Type.Literal("organization")], {
101
101
  description: "[list] accessible (default) includes the current org plus public schemas; organization returns only the bound org.",