@lobu/runtime-device 23.0.0 → 24.1.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 (67) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +30 -27
  3. package/npm-shrinkwrap.json +131 -115
  4. package/package.json +2 -1
  5. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +73 -0
  6. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +9 -11
  7. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +3 -11
  8. package/vendor/cli/dist/commands/_lib/apply/client.js +3 -3
  9. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +0 -6
  10. package/vendor/cli/dist/commands/_lib/apply/desired-state.js +6 -15
  11. package/vendor/cli/dist/commands/_lib/apply/diff.js +1 -0
  12. package/vendor/cli/dist/commands/_lib/apply/map-config.js +8 -0
  13. package/vendor/cli/dist/commands/_lib/view-bundler.d.ts +2 -9
  14. package/vendor/cli/dist/commands/_lib/view-bundler.js +36 -119
  15. package/vendor/cli/dist/config/define.d.ts +8 -0
  16. package/vendor/cli/dist/connectors/README.md +1 -1
  17. package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +4 -7
  18. package/vendor/cli/dist/connectors/linkedin.ts +53 -34
  19. package/vendor/cli/dist/connectors/reddit.ts +92 -20
  20. package/vendor/cli/dist/connectors/slack.ts +1 -0
  21. package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +41 -11
  22. package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +1 -1
  23. package/vendor/cli/dist/connectors/whatsapp_web.ts +2 -2
  24. package/vendor/cli/dist/connectors/x-dm-adapter.js +65 -30
  25. package/vendor/cli/dist/connectors/x-identity.ts +5 -3
  26. package/vendor/cli/dist/runtime-components.json +4 -4
  27. package/vendor/cli/dist/templates/AGENTS.md.tmpl +10 -3
  28. package/vendor/cli/package.json +1 -1
  29. package/vendor/connector-sdk/package.json +1 -1
  30. package/vendor/connector-worker/dist/agent-turn/gateway-tools.d.ts +2 -2
  31. package/vendor/connector-worker/dist/agent-turn/gateway-tools.js +2 -2
  32. package/vendor/connector-worker/dist/agent-turn/guest-entry.js +34 -2
  33. package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +362 -300
  34. package/vendor/connector-worker/dist/agent-turn/native-session.d.ts +12 -0
  35. package/vendor/connector-worker/dist/agent-turn/native-session.js +32 -6
  36. package/vendor/connector-worker/dist/agent-turn/types.d.ts +24 -3
  37. package/vendor/connector-worker/dist/daemon/agent-turn.js +5 -1
  38. package/vendor/connector-worker/dist/daemon/automation-acp.js +23 -11
  39. package/vendor/connector-worker/dist/daemon/automation.js +20 -15
  40. package/vendor/connector-worker/dist/isolate/prelude.js +93 -44
  41. package/vendor/connector-worker/package.json +1 -1
  42. package/vendor/core/dist/agent-policy.js +0 -3
  43. package/vendor/core/dist/agent-tooling.d.ts +1 -1
  44. package/vendor/core/dist/agent-tooling.js +3 -1
  45. package/vendor/core/dist/contracts/agent-settings.d.ts +6 -2
  46. package/vendor/core/dist/contracts/agent-settings.js +12 -1
  47. package/vendor/core/dist/contracts/tools/manage-views.d.ts +53 -234
  48. package/vendor/core/dist/contracts/tools/manage-views.js +50 -76
  49. package/vendor/core/dist/contracts/tools/view-attach.d.ts +5 -8
  50. package/vendor/core/dist/contracts/tools/view-attach.js +14 -31
  51. package/vendor/core/dist/contracts/tools/view-definition.d.ts +21 -0
  52. package/vendor/core/dist/contracts/tools/view-definition.js +165 -0
  53. package/vendor/core/dist/contracts/tools/view-runtime.d.ts +74 -0
  54. package/vendor/core/dist/contracts/tools/view-runtime.js +86 -0
  55. package/vendor/core/dist/contracts/worker/protocol.d.ts +39 -2
  56. package/vendor/core/dist/contracts/worker/protocol.js +24 -1
  57. package/vendor/core/dist/index.d.ts +1 -1
  58. package/vendor/core/dist/index.js +2 -1
  59. package/vendor/core/dist/suggestions.d.ts +15 -2
  60. package/vendor/core/dist/suggestions.js +48 -3
  61. package/vendor/core/dist/types.d.ts +26 -0
  62. package/vendor/core/dist/types.js +5 -0
  63. package/vendor/core/package.json +16 -5
  64. package/vendor/postgres/cf/src/connection.js +18 -0
  65. package/vendor/postgres/cjs/src/connection.js +18 -0
  66. package/vendor/postgres/src/connection.js +18 -0
  67. /package/vendor/postgres/{.bun-tag-f39dafdb2305d504 → .bun-tag-2f292c6554a8475e} +0 -0
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Reddit Connector (V1 runtime)
3
3
  *
4
- * Fetches posts and comments from Reddit subreddits or search queries.
5
- * Supports both authenticated (OAuth) and unauthenticated (public JSON API) modes.
4
+ * Fetches posts and comments from Reddit subreddits or search queries, and the
5
+ * connected user's home feed. Supports both authenticated (OAuth) and
6
+ * unauthenticated (public JSON API) modes.
6
7
  */
7
8
 
8
9
  import {
@@ -16,6 +17,7 @@ import {
16
17
  type SyncContext,
17
18
  type SyncResult,
18
19
  } from '@lobu/connector-sdk';
20
+ import addFormats from 'ajv-formats';
19
21
 
20
22
  // ---------------------------------------------------------------------------
21
23
  // Reddit API types
@@ -71,6 +73,16 @@ interface RedditCheckpoint {
71
73
  pagination_cutoff?: string;
72
74
  }
73
75
 
76
+ // Use the gateway's URI format check: WHATWG URL parsing also accepts non-URI characters.
77
+ const isUri = addFormats.get('uri') as (value: string) => boolean;
78
+
79
+ /** Metadata declares these fields `format: uri`; one bad value rejects the whole batch. */
80
+ function httpUrl(value: string | undefined): string | undefined {
81
+ if (!value || !isUri(value) || !URL.canParse(value)) return undefined;
82
+ const { protocol } = new URL(value);
83
+ return protocol === 'http:' || protocol === 'https:' ? value : undefined;
84
+ }
85
+
74
86
  // ---------------------------------------------------------------------------
75
87
  // Connector
76
88
  // ---------------------------------------------------------------------------
@@ -79,8 +91,9 @@ export default class RedditConnector extends ConnectorRuntime {
79
91
  readonly definition: RuntimeConnectorDefinition = {
80
92
  key: 'reddit',
81
93
  name: 'Reddit',
82
- description: 'Fetches posts and comments from Reddit subreddits or search queries.',
83
- version: '1.0.0',
94
+ description:
95
+ "Fetches posts and comments from Reddit subreddits or search queries, and the connected user's home feed.",
96
+ version: '1.2.1',
84
97
  faviconDomain: 'reddit.com',
85
98
  authSchema: {
86
99
  methods: [
@@ -88,6 +101,7 @@ export default class RedditConnector extends ConnectorRuntime {
88
101
  type: 'oauth',
89
102
  provider: 'reddit',
90
103
  requiredScopes: ['identity', 'read', 'history'],
104
+ loginScopes: ['identity'],
91
105
  setupInstructions:
92
106
  'Create a Reddit app at https://www.reddit.com/prefs/apps — choose "web app" as the type. Set the redirect URI to {{redirect_uri}}, then copy the client ID and secret below.',
93
107
  },
@@ -238,6 +252,48 @@ export default class RedditConnector extends ConnectorRuntime {
238
252
  },
239
253
  },
240
254
  },
255
+ home_feed: {
256
+ key: 'home_feed',
257
+ name: 'Home feed',
258
+ sync: (ctx) => this.syncFeed(ctx),
259
+ description:
260
+ "Fetch the connected user's personalized home feed (Best). Requires user OAuth.",
261
+ displayNameTemplate: 'Reddit home feed',
262
+ configSchema: {
263
+ type: 'object',
264
+ properties: {
265
+ lookback_days: {
266
+ type: 'integer',
267
+ minimum: 1,
268
+ maximum: 30,
269
+ default: 7,
270
+ description: 'Skip home feed posts older than this many days.',
271
+ },
272
+ },
273
+ },
274
+ eventKinds: {
275
+ post: {
276
+ description: "A Reddit post from the connected user's home feed",
277
+ metadataSchema: {
278
+ type: 'object',
279
+ properties: {
280
+ subreddit: { type: 'string' },
281
+ score: { type: 'number', description: 'Reddit score (upvotes - downvotes)' },
282
+ num_comments: { type: 'number' },
283
+ upvote_ratio: { type: 'number' },
284
+ is_self: { type: 'boolean' },
285
+ domain: { type: 'string' },
286
+ thumbnail: { type: 'string', format: 'uri', description: 'Preview thumbnail URL' },
287
+ media_url: {
288
+ type: 'string',
289
+ format: 'uri',
290
+ description: 'Linked content URL for non-self posts (image, video, article)',
291
+ },
292
+ },
293
+ },
294
+ },
295
+ },
296
+ },
241
297
  },
242
298
  };
243
299
 
@@ -253,17 +309,20 @@ export default class RedditConnector extends ConnectorRuntime {
253
309
  const subreddit = ctx.config.subreddit as string | undefined;
254
310
  const searchTerms = ctx.config.search_terms as string | undefined;
255
311
  const isUserFeed = ctx.feedKey === 'user_activity';
256
- const contentType = isUserFeed ? 'overview' : ctx.feedKey === 'comments' ? 'comment' : 'post';
257
- const lookbackDays = (ctx.config.lookback_days as number) ?? 365;
312
+ // Best is ranked, not chronological: old posts interleave with new ones and
313
+ // a saved `after` anchor is meaningless once the ranking moves.
314
+ const isHomeFeed = ctx.feedKey === 'home_feed';
315
+ const contentType = isUserFeed
316
+ ? 'overview'
317
+ : isHomeFeed
318
+ ? 'home'
319
+ : ctx.feedKey === 'comments'
320
+ ? 'comment'
321
+ : 'post';
322
+ const lookbackDays = (ctx.config.lookback_days as number) ?? (isHomeFeed ? 7 : 365);
258
323
 
259
324
  // Resolve access token: user OAuth > app-only OAuth > unauthenticated
260
325
  const userAccessToken = ctx.credentials?.accessToken ?? null;
261
- let accessToken: string | undefined = userAccessToken ?? undefined;
262
- if (!accessToken) {
263
- accessToken = await this.getAppOnlyToken(ctx);
264
- }
265
- const baseUrl = accessToken ? 'https://oauth.reddit.com' : 'https://www.reddit.com';
266
-
267
326
  let username: string | undefined;
268
327
  if (isUserFeed) {
269
328
  if (!userAccessToken) {
@@ -273,9 +332,18 @@ export default class RedditConnector extends ConnectorRuntime {
273
332
  }
274
333
  username = await this.resolveUsername(ctx, userAccessToken);
275
334
  }
335
+ if (isHomeFeed && !userAccessToken) {
336
+ throw new Error('home_feed requires user OAuth. Connect Reddit with the read scope.');
337
+ }
338
+
339
+ let accessToken: string | undefined = userAccessToken ?? undefined;
340
+ if (!accessToken) {
341
+ accessToken = await this.getAppOnlyToken(ctx);
342
+ }
343
+ const baseUrl = accessToken ? 'https://oauth.reddit.com' : 'https://www.reddit.com';
276
344
 
277
345
  const previous = (ctx.checkpoint ?? {}) as RedditCheckpoint;
278
- const resumeAfter = previous.pagination_token ?? null;
346
+ const resumeAfter = isHomeFeed ? null : (previous.pagination_token ?? null);
279
347
  let cutoffDate = new Date();
280
348
  cutoffDate.setDate(cutoffDate.getDate() - lookbackDays);
281
349
  // Keep items eligible for the whole bounded sweep, even across sync runs.
@@ -355,6 +423,7 @@ export default class RedditConnector extends ConnectorRuntime {
355
423
  const itemDate = new Date(itemData.created_utc * 1000);
356
424
 
357
425
  if (itemDate < cutoffDate) {
426
+ if (isHomeFeed) continue;
358
427
  reachedCutoff = true;
359
428
  break;
360
429
  }
@@ -388,8 +457,9 @@ export default class RedditConnector extends ConnectorRuntime {
388
457
 
389
458
  const checkpoint: RedditCheckpoint = {
390
459
  last_timestamp: new Date().toISOString(),
391
- pagination_token: !reachedCutoff ? (after ?? undefined) : undefined,
392
- pagination_cutoff: !reachedCutoff && after ? cutoffDate.toISOString() : undefined,
460
+ pagination_token: !reachedCutoff && !isHomeFeed ? (after ?? undefined) : undefined,
461
+ pagination_cutoff:
462
+ !reachedCutoff && !isHomeFeed && after ? cutoffDate.toISOString() : undefined,
393
463
  };
394
464
 
395
465
  await ctx.commit(events, checkpoint as Record<string, unknown>);
@@ -498,6 +568,10 @@ export default class RedditConnector extends ConnectorRuntime {
498
568
  return `${baseUrl}/user/${encodeURIComponent(username)}/overview${jsonSuffix}?limit=100&sort=new${afterParam}`;
499
569
  }
500
570
 
571
+ if (contentType === 'home') {
572
+ return `${baseUrl}/best${jsonSuffix}?limit=100${afterParam}`;
573
+ }
574
+
501
575
  if (contentType === 'comment') {
502
576
  // Comments from a subreddit
503
577
  if (subredditPath) {
@@ -541,11 +615,9 @@ export default class RedditConnector extends ConnectorRuntime {
541
615
  });
542
616
 
543
617
  // For non-self posts, the Reddit `url` field points to the linked content (image, article, etc.)
544
- const mediaUrl = !post.is_self ? post.url : undefined;
545
- const thumbnail =
546
- post.thumbnail && !['self', 'default', 'nsfw', 'spoiler', ''].includes(post.thumbnail)
547
- ? post.thumbnail
548
- : undefined;
618
+ const mediaUrl = !post.is_self ? httpUrl(post.url) : undefined;
619
+ // `thumbnail` also carries placeholder words ("self", "image", "nsfw", ...).
620
+ const thumbnail = httpUrl(post.thumbnail);
549
621
 
550
622
  return {
551
623
  origin_id: `reddit_post_${post.name}`,
@@ -65,6 +65,7 @@ const SLACK_BOT_SCOPES = [
65
65
  const SLACK_BOT_EVENTS = [
66
66
  "app_home_opened",
67
67
  "app_mention",
68
+ "assistant_thread_started",
68
69
  "member_joined_channel",
69
70
  "member_left_channel",
70
71
  "message.channels",
@@ -33,8 +33,11 @@ export function whatsAppWebAdapterProgram() {
33
33
  // when this number moves: shipping a fix under the old number leaves every
34
34
  // already-open tab running the previous code with nothing to show for it.
35
35
  // Keep in lockstep with WHATSAPP_ADAPTER_VERSION in whatsapp-web-helpers.ts.
36
- const ADAPTER_VERSION = 25;
36
+ const ADAPTER_VERSION = 26;
37
37
  const SOURCE_ERROR_ID = "whatsapp-web:source-observation-error";
38
+ // Storage rows one `chat:` read examines; a whole personal history is
39
+ // usually under this, so one read answers.
40
+ const CHAT_SCAN_ROWS = 20_000;
38
41
  const MAX_RECORD_BYTES = 128 * 1024;
39
42
  const MAX_BUFFER_BYTES = 16 * 1024 * 1024;
40
43
  const MAX_BUFFER_ENTRIES = 10_000;
@@ -945,6 +948,11 @@ export function whatsAppWebAdapterProgram() {
945
948
  }
946
949
  const keyModule = requireFirst(["WAWebMsgKey"]);
947
950
  const exactId = query.startsWith("id:") ? query.slice(3) : null;
951
+ let chatJid = null;
952
+ if (query.startsWith("chat:")) {
953
+ const chat = await resolveChat(requireFirst(["WAWebCollections"]), { chat_jid: query.slice(5) });
954
+ chatJid = (await canonicalJid(modelData(chat).id ?? chat?.id)).jid;
955
+ }
948
956
  const database = await new Promise((resolve, reject) => {
949
957
  const request = indexedDB.open("model-storage");
950
958
  // Never create an empty replacement database when WhatsApp changes its
@@ -980,24 +988,46 @@ export function whatsAppWebAdapterProgram() {
980
988
  return;
981
989
  }
982
990
  rows.push({ position: cursor.key, id: cursor.value.id });
983
- if (rows.length > limit) resolve(rows);
991
+ if (rows.length > (chatJid === null ? limit : CHAT_SCAN_ROWS)) resolve(rows);
984
992
  else cursor.continue();
985
993
  };
986
994
  });
987
995
  } finally {
988
996
  database.close();
989
997
  }
990
- const hasMore = sourceRows.length > limit;
991
- const page = sourceRows.slice(0, limit);
998
+ let hasMore = sourceRows.length > limit;
999
+ let page = sourceRows.slice(0, limit);
1000
+ let last = page[page.length - 1];
1001
+ if (chatJid !== null) {
1002
+ // A chat read scans one large storage page, then keeps that chat's rows.
1003
+ // Matching happens after the transaction closes because LID conversion
1004
+ // awaits, and history can key a chat by phone or by LID.
1005
+ const examined = sourceRows.slice(0, CHAT_SCAN_ROWS);
1006
+ const canonical = new Map();
1007
+ const matches = [];
1008
+ for (const row of examined) {
1009
+ const remote = keyModule.fromString(row.id).remote;
1010
+ const raw = widString(remote);
1011
+ if (!canonical.has(raw)) canonical.set(raw, (await canonicalJid(remote)).jid);
1012
+ if (canonical.get(raw) !== chatJid) continue;
1013
+ matches.push(row);
1014
+ if (matches.length > limit) break;
1015
+ }
1016
+ page = matches.slice(0, limit);
1017
+ hasMore = matches.length > limit || sourceRows.length > CHAT_SCAN_ROWS;
1018
+ last = matches.length > limit ? page[page.length - 1] : examined[examined.length - 1];
1019
+ }
992
1020
  const collections = requireFirst(["WAWebCollections"]);
993
- const selected = page.filter((row) => {
1021
+ const selected = [];
1022
+ for (const row of page) {
994
1023
  const key = keyModule.fromString(row.id);
995
- if (exactId !== null && key.id !== exactId) return false;
1024
+ if (exactId !== null && key.id !== exactId) continue;
996
1025
  const remote = widString(key.remote);
997
- if (remote === "status@broadcast" || remote.endsWith("@newsletter")) return false;
1026
+ if (remote === "status@broadcast" || remote.endsWith("@newsletter")) continue;
998
1027
  const isGroup = remote.endsWith("@g.us");
999
- return !(chatFilter === "group" && !isGroup) && !(chatFilter === "individual" && isGroup);
1000
- });
1028
+ if ((chatFilter === "group" && !isGroup) || (chatFilter === "individual" && isGroup)) continue;
1029
+ selected.push(row);
1030
+ }
1001
1031
  const results = [];
1002
1032
  if (selected.length) {
1003
1033
  const loaded = await collections.Msg.getMessagesById(selected.map((row) => row.id));
@@ -1014,14 +1044,14 @@ export function whatsAppWebAdapterProgram() {
1014
1044
  // Skip them like search does; throwing would pin every later read to
1015
1045
  // the same cursor.
1016
1046
  if (!message || message.timestamp <= 0) continue;
1017
- if (exactId === null && query && !`${message.body}\n${message.caption}`.toLowerCase().includes(query.toLowerCase())) continue;
1047
+ if (exactId === null && chatJid === null && query && !`${message.body}\n${message.caption}`.toLowerCase().includes(query.toLowerCase())) continue;
1018
1048
  results.push(message);
1019
1049
  }
1020
1050
  }
1021
1051
  return {
1022
1052
  results,
1023
1053
  hasMore,
1024
- ...(hasMore ? { nextCursor: JSON.stringify({ v: 1, before: page[page.length - 1].position, query, chat_filter: chatFilter }) } : {}),
1054
+ ...(hasMore ? { nextCursor: JSON.stringify({ v: 1, before: last.position, query, chat_filter: chatFilter }) } : {}),
1025
1055
  };
1026
1056
  }
1027
1057
 
@@ -14,7 +14,7 @@ import {
14
14
  WHATSAPP_PHONE_SERVER,
15
15
  } from "./whatsapp-web-identity.js";
16
16
 
17
- export const WHATSAPP_ADAPTER_VERSION = 25;
17
+ export const WHATSAPP_ADAPTER_VERSION = 26;
18
18
  export const WHATSAPP_ORIGIN = "https://web.whatsapp.com";
19
19
 
20
20
  export type ChatFilter = "all" | "individual" | "group";
@@ -354,7 +354,7 @@ export default class WhatsAppWebConnector extends ConnectorRuntime<
354
354
  name: "WhatsApp",
355
355
  description:
356
356
  "Personal WhatsApp messages read live from WhatsApp Web in the paired Owletto Chrome without importing message history. Automations react to new-message references and read content on demand. Search, draft, send, edit, react to, and revoke messages.",
357
- version: "2.1.0",
357
+ version: "2.2.0",
358
358
  faviconDomain: "whatsapp.com",
359
359
  authSchema: { methods: [{ type: "browser", mode: "live" }] },
360
360
  browser: {
@@ -392,7 +392,7 @@ export default class WhatsAppWebConnector extends ConnectorRuntime<
392
392
  key: "live_messages",
393
393
  name: "Live messages",
394
394
  description:
395
- "Read messages directly from WhatsApp Web without importing history, using literal text search or id:<message ID>. Active Automations can subscribe to new-message references. Requires the paired browser to be online and signed in; reconnects replay messages still available in WhatsApp's local history.",
395
+ "Read messages directly from WhatsApp Web without importing history, using literal text search, id:<message ID>, or chat:<chat JID> for one chat's messages in reverse storage order. Follow cursors even after an empty filtered page. Active Automations can subscribe to new-message references. Requires the paired browser to be online and signed in; reconnects replay messages still available in WhatsApp's local history.",
396
396
  read: (ctx) => this.readMessages(ctx),
397
397
  observe: (ctx) => this.observeMessages(ctx),
398
398
  webhook: { mode: "trigger", events: ["message.created"] },
@@ -31,10 +31,16 @@ export function xDirectMessagesProgram() {
31
31
  const UPDATE_PAGES_PER_PASS = 10;
32
32
  // Matching recent text without a request id is ambiguous, not delivery proof.
33
33
  const RESEND_WINDOW_MS = 10 * 60 * 1000;
34
+ // Reconcile 503 responses before retrying: a failed response can still land.
35
+ const UNAVAILABLE_SEND_RETRY_DELAYS_MS = [3000, 7000];
36
+ // Abort network work before Chrome's 80s awaited-evaluation deadline.
37
+ const SEND_TIMEOUT_MS = 70000;
34
38
  const BATCH_EVENTS = 500;
35
39
  const BATCH_BYTES = 128 * 1024;
36
- function fail(message) {
37
- throw new Error(`X direct messages: ${message}`);
40
+ function fail(message, status) {
41
+ const error = new Error(`X direct messages: ${message}`);
42
+ if (status !== undefined) error.status = status;
43
+ throw error;
38
44
  }
39
45
  function cookie(name) {
40
46
  const raw = document.cookie
@@ -49,13 +55,16 @@ export function xDirectMessagesProgram() {
49
55
  return match[1];
50
56
  }
51
57
  async function request(path, init = {}) {
58
+ init.signal?.throwIfAborted();
52
59
  const self = account();
53
60
  const csrf = cookie("ct0");
54
61
  if (!csrf) fail("Sign in to X in the paired browser");
55
62
  const response = await fetch(path, {
56
63
  credentials: "include",
57
- signal: AbortSignal.timeout(20000),
58
64
  ...init,
65
+ signal: init.signal
66
+ ? AbortSignal.any([init.signal, AbortSignal.timeout(20000)])
67
+ : AbortSignal.timeout(20000),
59
68
  headers: {
60
69
  authorization: WEB_CLIENT_BEARER,
61
70
  "x-csrf-token": csrf,
@@ -73,6 +82,7 @@ export function xDirectMessagesProgram() {
73
82
  }
74
83
  fail(
75
84
  `request failed (HTTP ${response.status}${code === null ? "" : `, X error ${code}`})`,
85
+ response.status,
76
86
  );
77
87
  }
78
88
  const body = await response.json();
@@ -85,10 +95,11 @@ export function xDirectMessagesProgram() {
85
95
  );
86
96
  return body?.inbox_initial_state ?? fail("Inbox state is unavailable");
87
97
  }
88
- async function conversation(conversationId, maxId) {
98
+ async function conversation(conversationId, maxId, signal) {
89
99
  const page = maxId ? `&max_id=${encodeURIComponent(maxId)}` : "";
90
100
  const body = await request(
91
101
  `${DM_API}/conversation/${conversationId}.json?context=FETCH_DM_CONVERSATION&${DM_PARAMS}${page}`,
102
+ signal ? { signal } : {},
92
103
  );
93
104
  return body?.conversation_timeline ?? fail("Conversation is unavailable");
94
105
  }
@@ -294,6 +305,7 @@ export function xDirectMessagesProgram() {
294
305
  }
295
306
  async function send(input) {
296
307
  const self = account();
308
+ const signal = AbortSignal.timeout(SEND_TIMEOUT_MS);
297
309
  const conversationId = String(input.conversation_id ?? "");
298
310
  if (!CONVERSATION_ID.test(conversationId))
299
311
  fail("conversation_id must be an exact X DM conversation id");
@@ -308,41 +320,64 @@ export function xDirectMessagesProgram() {
308
320
  typeof input.idempotency_key === "string" ? input.idempotency_key : "";
309
321
  if (!idempotencyKey) fail("idempotency_key is required");
310
322
  const requestId = await requestIdOf(self, conversationId, idempotencyKey);
323
+ const delivered = (prior) => ({
324
+ sent: true,
325
+ deduplicated: true,
326
+ id: prior.id,
327
+ message_id: prior.message_id,
328
+ conversation_id: conversationId,
329
+ occurred_at: prior.occurred_at,
330
+ });
331
+ const readConversation = () => {
332
+ if (account() !== self) fail("X account changed before the send read");
333
+ return conversation(conversationId, undefined, signal);
334
+ };
311
335
  // Only an existing conversation the account can read is a send target.
312
- const before = await conversation(conversationId);
336
+ const before = await readConversation();
313
337
  const prior = earlierAttempt(before, self, requestId, text);
314
- if (prior) {
315
- return {
316
- sent: true,
317
- deduplicated: true,
318
- id: prior.id,
319
- message_id: prior.message_id,
320
- conversation_id: conversationId,
321
- occurred_at: prior.occurred_at,
322
- };
338
+ if (prior) return delivered(prior);
339
+ let response;
340
+ for (const delay of [...UNAVAILABLE_SEND_RETRY_DELAYS_MS, null]) {
341
+ if (account() !== self) fail("X account changed before the send");
342
+ try {
343
+ response = await request(`${DM_API}/new2.json`, {
344
+ method: "POST",
345
+ signal,
346
+ headers: { "content-type": "application/json" },
347
+ body: JSON.stringify({
348
+ conversation_id: conversationId,
349
+ recipient_ids: false,
350
+ request_id: requestId,
351
+ text,
352
+ cards_platform: "Web-12",
353
+ include_cards: 1,
354
+ include_quote_count: true,
355
+ dm_users: false,
356
+ }),
357
+ });
358
+ break;
359
+ } catch (error) {
360
+ if (error?.status !== 503) throw error;
361
+ signal.throwIfAborted();
362
+ if (delay !== null)
363
+ await new Promise((resolve) => setTimeout(resolve, delay));
364
+ const landed = earlierAttempt(
365
+ await readConversation(),
366
+ self,
367
+ requestId,
368
+ text,
369
+ );
370
+ if (landed) return delivered(landed);
371
+ if (delay === null) throw error;
372
+ }
323
373
  }
324
- if (account() !== self) fail("X account changed before the send");
325
- const response = await request(`${DM_API}/new2.json`, {
326
- method: "POST",
327
- headers: { "content-type": "application/json" },
328
- body: JSON.stringify({
329
- conversation_id: conversationId,
330
- recipient_ids: false,
331
- request_id: requestId,
332
- text,
333
- cards_platform: "Web-12",
334
- include_cards: 1,
335
- include_quote_count: true,
336
- dm_users: false,
337
- }),
338
- });
339
374
  const created = messagesOf(response).find(
340
375
  (message) => String(message.conversation_id) === conversationId,
341
376
  );
342
377
  const messageId = created ? String(created.id ?? "") : "";
343
378
  if (!/^[0-9]+$/.test(messageId))
344
379
  fail("X accepted the send but returned no message id");
345
- const after = await conversation(conversationId);
380
+ const after = await readConversation();
346
381
  const landed = rowsOf(after, self).find(
347
382
  (row) => row.message_id === messageId && row.from_me,
348
383
  );
@@ -75,12 +75,14 @@ export const xIdentityModule: ConnectorIdentityModule = {
75
75
  * X's direct-message sender model. Numeric user ids are unique across X, so
76
76
  * there is no tenant axis: `teamId` is ignored and the scope is global.
77
77
  *
78
- * No login extractor is registered for this descriptor. The chat link offered
79
- * in a direct message proves the sender within the workspace that issued it.
78
+ * Signing in with X proves it: Better Auth's X provider is `twitter`, and the
79
+ * account id it stores is the same numeric user id a direct message carries.
80
+ * The chat link offered in a direct message proves it too, within the
81
+ * workspace that issued it.
80
82
  */
81
83
  export const xChatUserIdentity: ChatUserIdentity = {
82
84
  platform: 'x',
83
- providerId: 'x',
85
+ providerId: 'twitter',
84
86
  namespace: X_IDENTITY.CHAT_USER_ID,
85
87
  buildUserKey(_teamId, platformUserId) {
86
88
  return normalizeXUserId(platformUserId);
@@ -5,7 +5,7 @@
5
5
  "server": "dist/server.bundle.mjs",
6
6
  "embeddingsServer": "dist/embeddings-server.mjs"
7
7
  },
8
- "version": "23.0.0",
8
+ "version": "24.1.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": "23.0.0",
19
+ "version": "24.1.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": "23.0.0",
27
+ "version": "24.1.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": "23.0.0",
35
+ "version": "24.1.0",
36
36
  "verify": "dist/verify.mjs"
37
37
  }
38
38
  }
@@ -172,14 +172,21 @@ const ticket = defineEntityType({
172
172
  name: "Ticket",
173
173
  required: ["subject"],
174
174
  properties: {
175
- subject: { type: "string", "x-table-label": "Subject", "x-table-column": true },
176
- status: { type: "string", enum: ["open", "closed"], "x-table-label": "Status", "x-table-column": true },
175
+ subject: { type: "string", title: "Subject", "x-table-label": "Subject", "x-table-column": true },
176
+ status: { type: "string", title: "Status", enum: ["open", "closed"], "x-table-label": "Status", "x-table-column": true },
177
+ contacts: {
178
+ type: "array",
179
+ title: "Contacts",
180
+ items: { type: "object", properties: { email: { type: "string", title: "Email" } } },
181
+ },
177
182
  },
178
183
  });
179
184
  ```
180
185
 
181
186
  Each property is a JSON Schema fragment. `"x-table-column": true` surfaces it as a
182
- column in the admin UI.
187
+ column in the admin UI. The same schema renders the record page form: give every
188
+ array `items` and every object `properties` (bare ones render as raw JSON), put the
189
+ label in `title` and help text in `description`, and mark derived fields `readOnly: true`.
183
190
 
184
191
  ### Connection (a bundled connector — preferred)
185
192
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/cli",
3
- "version": "23.0.0",
3
+ "version": "24.1.0",
4
4
  "description": "CLI for deploying and managing AI agents on Lobu",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/connector-sdk",
3
- "version": "23.0.0",
3
+ "version": "24.1.0",
4
4
  "description": "Lobu memory SDK — build pluggable connectors for Lobu memory",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,6 @@
1
1
  /**
2
- * The turn's gateway tools: `ask_user`, `send_message`, `suggest_actions` and
3
- * the rest of `@lobu/plugin-conversations`.
2
+ * The turn's gateway tools: `ask_user`, `send_message` and the rest of
3
+ * `@lobu/plugin-conversations`.
4
4
  *
5
5
  * GUEST code, bundled with the agent entry, so the same portability rules as
6
6
  * `workspace.ts` apply: no `node:` import, no host module, no root
@@ -1,6 +1,6 @@
1
1
  /**
2
- * The turn's gateway tools: `ask_user`, `send_message`, `suggest_actions` and
3
- * the rest of `@lobu/plugin-conversations`.
2
+ * The turn's gateway tools: `ask_user`, `send_message` and the rest of
3
+ * `@lobu/plugin-conversations`.
4
4
  *
5
5
  * GUEST code, bundled with the agent entry, so the same portability rules as
6
6
  * `workspace.ts` apply: no `node:` import, no host module, no root