@lobu/runtime-device 21.2.1 → 22.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +91 -83
  3. package/npm-shrinkwrap.json +492 -438
  4. package/package.json +12 -2
  5. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +5 -6
  6. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +1 -0
  7. package/vendor/cli/dist/commands/_lib/apply/client.js +26 -7
  8. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +9 -1
  9. package/vendor/cli/dist/commands/_lib/apply/diff.d.ts +1 -0
  10. package/vendor/cli/dist/commands/_lib/apply/diff.js +46 -4
  11. package/vendor/cli/dist/commands/_lib/apply/map-config.js +18 -38
  12. package/vendor/cli/dist/commands/_lib/init-from-org/bootstrap.js +5 -17
  13. package/vendor/cli/dist/commands/init.d.ts +0 -2
  14. package/vendor/cli/dist/commands/init.js +0 -27
  15. package/vendor/cli/dist/commands/login.d.ts +17 -0
  16. package/vendor/cli/dist/commands/login.js +43 -17
  17. package/vendor/cli/dist/commands/memory/_lib/errors.d.ts +0 -8
  18. package/vendor/cli/dist/commands/memory/_lib/errors.js +0 -12
  19. package/vendor/cli/dist/commands/memory/_lib/mcp.js +6 -6
  20. package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +4 -10
  21. package/vendor/cli/dist/config/define.d.ts +21 -15
  22. package/vendor/cli/dist/config/define.js +2 -2
  23. package/vendor/cli/dist/connectors/README.md +7 -5
  24. package/vendor/cli/dist/connectors/_google/actions.ts +270 -0
  25. package/vendor/cli/dist/connectors/_google/discovery/calendar_v3.json +1 -0
  26. package/vendor/cli/dist/connectors/_google/discovery/chat_v1.json +1 -0
  27. package/vendor/cli/dist/connectors/_google/discovery/docs_v1.json +1 -0
  28. package/vendor/cli/dist/connectors/_google/discovery/drive_v3.json +1 -0
  29. package/vendor/cli/dist/connectors/_google/discovery/gmail_v1.json +1 -0
  30. package/vendor/cli/dist/connectors/_google/discovery/people_v1.json +1 -0
  31. package/vendor/cli/dist/connectors/_google/discovery/sheets_v4.json +1 -0
  32. package/vendor/cli/dist/connectors/_google/discovery/tasks_v1.json +1 -0
  33. package/vendor/cli/dist/connectors/_google/discovery/youtube_v3.json +1 -0
  34. package/vendor/cli/dist/connectors/_google/discovery.ts +442 -0
  35. package/vendor/cli/dist/connectors/_google/errors.ts +91 -0
  36. package/vendor/cli/dist/connectors/_google/list-feed.ts +223 -0
  37. package/vendor/cli/dist/connectors/_google/policies.ts +127 -0
  38. package/vendor/cli/dist/connectors/agentid.ts +43 -0
  39. package/vendor/cli/dist/connectors/chat-user-identity.ts +2 -1
  40. package/vendor/cli/dist/connectors/github-automation-events.ts +9 -0
  41. package/vendor/cli/dist/connectors/github-identity.ts +28 -3
  42. package/vendor/cli/dist/connectors/github.ts +101 -59
  43. package/vendor/cli/dist/connectors/google_calendar.ts +207 -719
  44. package/vendor/cli/dist/connectors/google_drive.ts +16 -2
  45. package/vendor/cli/dist/connectors/google_gmail.ts +51 -33
  46. package/vendor/cli/dist/connectors/herdr.ts +406 -0
  47. package/vendor/cli/dist/connectors/jira.ts +6 -6
  48. package/vendor/cli/dist/connectors/linear.ts +7 -4
  49. package/vendor/cli/dist/connectors/postgres.ts +27 -2
  50. package/vendor/cli/dist/connectors/tiktok-inbox-page.js +230 -0
  51. package/vendor/cli/dist/connectors/tiktok-web-page.js +211 -0
  52. package/vendor/cli/dist/connectors/tiktok_web.ts +286 -0
  53. package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +228 -10
  54. package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +47 -14
  55. package/vendor/cli/dist/connectors/whatsapp-web-identity.ts +121 -0
  56. package/vendor/cli/dist/connectors/whatsapp_web.ts +170 -29
  57. package/vendor/cli/dist/connectors/x.ts +276 -136
  58. package/vendor/cli/dist/index.js +1 -37
  59. package/vendor/cli/dist/internal/context.d.ts +10 -0
  60. package/vendor/cli/dist/internal/context.js +26 -16
  61. package/vendor/cli/dist/internal/node-version.d.ts +1 -1
  62. package/vendor/cli/dist/internal/node-version.js +1 -1
  63. package/vendor/cli/dist/internal/oauth.d.ts +3 -1
  64. package/vendor/cli/dist/internal/oauth.js +4 -3
  65. package/vendor/cli/dist/internal/runtime-components.d.ts +9 -0
  66. package/vendor/cli/dist/internal/runtime-components.js +67 -2
  67. package/vendor/cli/dist/mac-auth.js +17 -1
  68. package/vendor/cli/dist/providers.json +1 -1
  69. package/vendor/cli/dist/runtime-components.json +4 -4
  70. package/vendor/cli/dist/templates/AGENTS.md.tmpl +11 -4
  71. package/vendor/cli/dist/templates/README.md.tmpl +1 -1
  72. package/vendor/cli/dist/vendor/ora/.bun-tag-fde20e9a6df212fa +0 -0
  73. package/vendor/cli/dist/vendor/ora/index.d.ts +332 -0
  74. package/vendor/cli/dist/vendor/ora/index.js +424 -0
  75. package/vendor/cli/dist/vendor/ora/license +9 -0
  76. package/vendor/cli/dist/vendor/ora/package.json +64 -0
  77. package/vendor/cli/dist/vendor/ora/readme.md +329 -0
  78. package/vendor/cli/package.json +2 -2
  79. package/vendor/connector-sdk/dist/browser-requirement.d.ts +36 -0
  80. package/vendor/connector-sdk/dist/browser-requirement.js +60 -0
  81. package/vendor/connector-sdk/dist/connector-runtime.d.ts +3 -1
  82. package/vendor/connector-sdk/dist/connector-runtime.js +10 -0
  83. package/vendor/connector-sdk/dist/connector-types.d.ts +159 -45
  84. package/vendor/connector-sdk/dist/define-connector.d.ts +4 -2
  85. package/vendor/connector-sdk/dist/define-connector.js +3 -0
  86. package/vendor/connector-sdk/dist/index.d.ts +5 -2
  87. package/vendor/connector-sdk/dist/index.js +1 -0
  88. package/vendor/connector-sdk/dist/reaction-client-types.d.ts +16 -21
  89. package/vendor/connector-sdk/dist/reaction-client-types.typecheck.d.ts +5 -0
  90. package/vendor/connector-sdk/package.json +5 -1
  91. package/vendor/connector-worker/dist/agent-turn/guest-entry.js +31 -27
  92. package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +131 -185
  93. package/vendor/connector-worker/dist/agent-turn/memory.d.ts +3 -2
  94. package/vendor/connector-worker/dist/agent-turn/memory.js +3 -20
  95. package/vendor/connector-worker/dist/agent-turn/types.d.ts +3 -15
  96. package/vendor/connector-worker/dist/agent-turn/workspace.d.ts +2 -2
  97. package/vendor/connector-worker/dist/agent-turn/workspace.js +2 -4
  98. package/vendor/connector-worker/dist/daemon/action-monitor.d.ts +12 -0
  99. package/vendor/connector-worker/dist/daemon/action-monitor.js +25 -0
  100. package/vendor/connector-worker/dist/daemon/agent-turn.js +0 -9
  101. package/vendor/connector-worker/dist/daemon/builtins/index.d.ts +12 -0
  102. package/vendor/connector-worker/dist/daemon/builtins/index.js +61 -1
  103. package/vendor/connector-worker/dist/daemon/builtins/os-shell.d.ts +2 -1
  104. package/vendor/connector-worker/dist/daemon/builtins/os-shell.js +40 -27
  105. package/vendor/connector-worker/dist/daemon/client.d.ts +5 -1
  106. package/vendor/connector-worker/dist/daemon/client.js +3 -0
  107. package/vendor/connector-worker/dist/daemon/device-concurrency.d.ts +8 -0
  108. package/vendor/connector-worker/dist/daemon/device-concurrency.js +13 -0
  109. package/vendor/connector-worker/dist/daemon/executor.d.ts +1 -1
  110. package/vendor/connector-worker/dist/daemon/executor.js +48 -117
  111. package/vendor/connector-worker/dist/daemon/log.d.ts +2 -0
  112. package/vendor/connector-worker/dist/daemon/log.js +23 -2
  113. package/vendor/connector-worker/dist/daemon/mac-device-daemon.d.ts +20 -4
  114. package/vendor/connector-worker/dist/daemon/mac-device-daemon.js +53 -13
  115. package/vendor/connector-worker/dist/daemon/native-bridge/client.d.ts +6 -0
  116. package/vendor/connector-worker/dist/daemon/native-bridge/client.js +15 -0
  117. package/vendor/connector-worker/dist/daemon/native-bridge/executor.js +2 -0
  118. package/vendor/connector-worker/dist/daemon/native-bridge/protocol.d.ts +1 -1
  119. package/vendor/connector-worker/dist/daemon/native-bridge/protocol.js +1 -0
  120. package/vendor/connector-worker/dist/daemon/poll-loop.d.ts +3 -0
  121. package/vendor/connector-worker/dist/daemon/poll-loop.js +5 -1
  122. package/vendor/connector-worker/dist/daemon/start.d.ts +1 -0
  123. package/vendor/connector-worker/dist/daemon/start.js +12 -5
  124. package/vendor/connector-worker/dist/executor/interface.d.ts +34 -2
  125. package/vendor/connector-worker/dist/executor/isolate.js +66 -15
  126. package/vendor/connector-worker/dist/executor/redact.d.ts +1 -0
  127. package/vendor/connector-worker/dist/executor/redact.js +97 -26
  128. package/vendor/connector-worker/dist/executor/runtime.d.ts +7 -0
  129. package/vendor/connector-worker/dist/executor/runtime.js +26 -0
  130. package/vendor/connector-worker/dist/isolate/bridge.js +3 -1
  131. package/vendor/connector-worker/dist/mac-device-daemon.js +10 -3
  132. package/vendor/connector-worker/package.json +2 -2
  133. package/vendor/core/dist/agent-policy.js +1 -1
  134. package/vendor/core/dist/agent-store.d.ts +2 -0
  135. package/vendor/core/dist/agent-tooling.d.ts +1 -1
  136. package/vendor/core/dist/agent-tooling.js +1 -1
  137. package/vendor/core/dist/capabilities.js +2 -0
  138. package/vendor/core/dist/contracts/agent-settings.d.ts +0 -11
  139. package/vendor/core/dist/contracts/agent-settings.js +1 -7
  140. package/vendor/core/dist/contracts/tools/collection-presentation.d.ts +93 -0
  141. package/vendor/core/dist/contracts/tools/collection-presentation.js +88 -0
  142. package/vendor/core/dist/contracts/tools/collection-selection.d.ts +47 -0
  143. package/vendor/core/dist/contracts/tools/collection-selection.js +74 -0
  144. package/vendor/core/dist/contracts/tools/manage-agents.d.ts +10 -4
  145. package/vendor/core/dist/contracts/tools/manage-auth-profiles.d.ts +1 -1
  146. package/vendor/core/dist/contracts/tools/manage-auth-profiles.js +5 -1
  147. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +19 -4
  148. package/vendor/core/dist/contracts/tools/manage-automations.js +25 -8
  149. package/vendor/core/dist/contracts/tools/manage-connections.d.ts +1 -0
  150. package/vendor/core/dist/contracts/tools/manage-connections.js +3 -0
  151. package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +11 -0
  152. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +42 -3
  153. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +181 -152
  154. package/vendor/core/dist/contracts/tools/manage-entity.js +118 -162
  155. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +41 -3
  156. package/vendor/core/dist/contracts/tools/manage-operations.js +40 -2
  157. package/vendor/core/dist/contracts/tools/manage-views.d.ts +182 -7
  158. package/vendor/core/dist/contracts/tools/manage-views.js +49 -13
  159. package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +11 -2
  160. package/vendor/core/dist/contracts/tools/read-knowledge.js +23 -3
  161. package/vendor/core/dist/contracts/tools/save-memory.d.ts +3 -6
  162. package/vendor/core/dist/contracts/tools/save-memory.js +2 -6
  163. package/vendor/core/dist/contracts/tools/view-attach.d.ts +2 -1
  164. package/vendor/core/dist/contracts/tools/view-attach.js +7 -2
  165. package/vendor/core/dist/contracts/worker/protocol.d.ts +122 -28
  166. package/vendor/core/dist/contracts/worker/protocol.js +81 -17
  167. package/vendor/core/dist/index.d.ts +3 -4
  168. package/vendor/core/dist/index.js +3 -6
  169. package/vendor/core/dist/json-template.d.ts +6 -10
  170. package/vendor/core/dist/json-template.js +5 -9
  171. package/vendor/core/dist/logger.js +11 -5
  172. package/vendor/core/dist/shell-safety.d.ts +9 -0
  173. package/vendor/core/dist/shell-safety.js +154 -0
  174. package/vendor/core/dist/suggestions.d.ts +1 -1
  175. package/vendor/core/dist/suggestions.js +1 -1
  176. package/vendor/core/dist/tool-trace-summary.d.ts +1 -1
  177. package/vendor/core/dist/tool-trace-summary.js +1 -1
  178. package/vendor/core/dist/types.d.ts +1 -3
  179. package/vendor/core/dist/utils/diagnostic-scrubber.d.ts +7 -0
  180. package/vendor/core/dist/utils/{sentry-scrubber.js → diagnostic-scrubber.js} +25 -53
  181. package/vendor/core/dist/worker/auth.d.ts +44 -6
  182. package/vendor/core/dist/worker/auth.js +44 -11
  183. package/vendor/core/package.json +15 -6
  184. package/vendor/ora/.bun-tag-fde20e9a6df212fa +0 -0
  185. package/vendor/ora/index.d.ts +332 -0
  186. package/vendor/ora/index.js +424 -0
  187. package/vendor/ora/license +9 -0
  188. package/vendor/ora/package.json +53 -0
  189. package/vendor/ora/readme.md +329 -0
  190. package/vendor/cli/dist/commands/telemetry.d.ts +0 -10
  191. package/vendor/cli/dist/commands/telemetry.js +0 -66
  192. package/vendor/core/dist/sentry.d.ts +0 -26
  193. package/vendor/core/dist/sentry.js +0 -133
  194. package/vendor/core/dist/tool-policy.d.ts +0 -74
  195. package/vendor/core/dist/tool-policy.js +0 -305
  196. package/vendor/core/dist/utils/sentry-scrubber.d.ts +0 -29
@@ -40,6 +40,19 @@ import {
40
40
  type SyncContext,
41
41
  type SyncResult,
42
42
  } from '@lobu/connector-sdk';
43
+ import { compileGoogleActions, executeGoogleAction, oauthScopes } from './_google/actions';
44
+ import type { DiscoveryDocument } from './_google/discovery';
45
+ import driveDiscovery from './_google/discovery/drive_v3.json';
46
+ import { GOOGLE_API_POLICIES } from './_google/policies';
47
+
48
+ /**
49
+ * Supported Drive API methods as actions, compiled from the pinned Discovery
50
+ * document. `download_file` and `get_file` stay hand-written: the first picks
51
+ * `files.export` or `alt=media` by MIME type, the second returns the feed's row
52
+ * shape — work the raw methods leave to the caller.
53
+ */
54
+ const DRIVE_POLICY = GOOGLE_API_POLICIES.drive_v3;
55
+ const DRIVE = compileGoogleActions(driveDiscovery as unknown as DiscoveryDocument, DRIVE_POLICY);
43
56
 
44
57
  // ---------------------------------------------------------------------------
45
58
  // Drive API types
@@ -325,7 +338,7 @@ export default class GoogleDriveConnector extends ConnectorRuntime<
325
338
  {
326
339
  type: 'oauth',
327
340
  provider: 'google',
328
- requiredScopes: ['https://www.googleapis.com/auth/drive.readonly'],
341
+ ...oauthScopes(DRIVE_POLICY),
329
342
  loginScopes: ['openid', 'email', 'profile'],
330
343
  clientIdKey: 'GOOGLE_CLIENT_ID',
331
344
  clientSecretKey: 'GOOGLE_CLIENT_SECRET',
@@ -405,6 +418,7 @@ export default class GoogleDriveConnector extends ConnectorRuntime<
405
418
  },
406
419
  },
407
420
  actions: {
421
+ ...DRIVE.actions,
408
422
  download_file: {
409
423
  key: 'download_file',
410
424
  kind: 'read',
@@ -831,7 +845,7 @@ export default class GoogleDriveConnector extends ConnectorRuntime<
831
845
  case 'get_file':
832
846
  return await this.getFile(http, ctx.input);
833
847
  default:
834
- return { success: false, error: `Unknown action: ${ctx.actionKey}` };
848
+ return await executeGoogleAction(DRIVE, ctx, http);
835
849
  }
836
850
  } catch (error) {
837
851
  return {
@@ -23,8 +23,21 @@ import {
23
23
  type SyncContext,
24
24
  type SyncResult,
25
25
  } from '@lobu/connector-sdk';
26
+ import { compileGoogleActions, executeGoogleAction, oauthScopes } from './_google/actions';
27
+ import type { DiscoveryDocument } from './_google/discovery';
28
+ import gmailDiscovery from './_google/discovery/gmail_v1.json';
29
+ import { GOOGLE_API_POLICIES } from './_google/policies';
26
30
  import TurndownService from 'turndown';
27
31
 
32
+ /**
33
+ * Supported Gmail API methods as actions, compiled from the pinned Discovery
34
+ * document. The hand-written actions below stay: they compose several calls
35
+ * or decode MIME (`get_thread` returns readable bodies, `send_email` builds the
36
+ * RFC 2822 message) — work the raw methods leave to the caller.
37
+ */
38
+ const GMAIL_POLICY = GOOGLE_API_POLICIES.gmail_v1;
39
+ const GMAIL = compileGoogleActions(gmailDiscovery as unknown as DiscoveryDocument, GMAIL_POLICY);
40
+
28
41
  function createEmailBodyConverter(): TurndownService {
29
42
  const converter = new TurndownService({
30
43
  headingStyle: 'atx',
@@ -167,15 +180,7 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
167
180
  {
168
181
  type: 'oauth',
169
182
  provider: 'google',
170
- requiredScopes: [
171
- 'https://www.googleapis.com/auth/gmail.readonly',
172
- // compose covers drafts.create AND messages.send, so it is the single
173
- // write scope for create_draft/reply/send_email. It must be required
174
- // (not optional) — optional scopes are only requested when the caller
175
- // explicitly asks for them, so an unadorned connect() would omit it
176
- // and every write op would 403 insufficient-scope.
177
- 'https://www.googleapis.com/auth/gmail.compose',
178
- ],
183
+ ...oauthScopes(GMAIL_POLICY),
179
184
  loginScopes: ['openid', 'email', 'profile'],
180
185
  clientIdKey: 'GOOGLE_CLIENT_ID',
181
186
  clientSecretKey: 'GOOGLE_CLIENT_SECRET',
@@ -323,6 +328,7 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
323
328
  },
324
329
  },
325
330
  actions: {
331
+ ...GMAIL.actions,
326
332
  send_email: {
327
333
  key: 'send_email',
328
334
  name: 'Send Email',
@@ -535,16 +541,10 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
535
541
  for (const threadStub of threads) {
536
542
  inspected++;
537
543
  try {
538
- const response = await http.raw(`${this.BASE_URL}/threads/${threadStub.id}?format=full`);
539
- // A thread deleted between list and get has nothing left to sync.
540
- // Other failures must fail the run so the same window is retried
541
- // rather than checkpointed as complete.
542
- if (response.status === 404) continue;
543
- if (!response.ok) {
544
- throw new Error(`Gmail threads.get error (${response.status}): ${await response.text()}`);
545
- }
546
- const thread = (await response.json()) as GmailThreadGetResponse;
547
- if (!thread.messages?.length) throw new Error('Gmail returned a thread without messages');
544
+ const thread = await this.loadThread(http, threadStub.id);
545
+ // A thread deleted between list and index has nothing left to sync.
546
+ // A failure fetching any indexed message must retry the whole thread.
547
+ if (!thread) continue;
548
548
  const messages = [...thread.messages].sort((a, b) => Number(a.internalDate) - Number(b.internalDate));
549
549
  const firstMessage = messages[0];
550
550
  const latestMessage = messages[messages.length - 1];
@@ -637,7 +637,7 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
637
637
  case 'download_attachment':
638
638
  return await this.downloadAttachment(http, ctx.input);
639
639
  default:
640
- return { success: false, error: `Unknown action: ${ctx.actionKey}` };
640
+ return await executeGoogleAction(GMAIL, ctx, http);
641
641
  }
642
642
  } catch (error) {
643
643
  return {
@@ -1009,19 +1009,9 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
1009
1009
  return { success: false, error: 'thread_id is required.' };
1010
1010
  }
1011
1011
 
1012
- const url = `${this.BASE_URL}/threads/${threadId}?format=full`;
1013
- const response = await http.raw(url);
1014
-
1015
- if (!response.ok) {
1016
- const errText = await response.text();
1017
- return { success: false, error: `Gmail thread error (${response.status}): ${errText}` };
1018
- }
1019
-
1020
- const thread = (await response.json()) as GmailThreadGetResponse;
1021
- const subject =
1022
- thread.messages.length > 0
1023
- ? this.getHeader(thread.messages[0], 'Subject') || '(no subject)'
1024
- : '(no subject)';
1012
+ const thread = await this.loadThread(http, threadId);
1013
+ if (!thread) return { success: false, error: 'Gmail thread error (404): thread not found' };
1014
+ const subject = this.getHeader(thread.messages[0], 'Subject') || '(no subject)';
1025
1015
 
1026
1016
  const messages = [];
1027
1017
  for (const msg of thread.messages) {
@@ -1055,6 +1045,34 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
1055
1045
  // Helpers
1056
1046
  // -------------------------------------------------------------------------
1057
1047
 
1048
+ /** Keep each HTTP response bounded by one message, even for long threads. */
1049
+ private async loadThread(http: HttpClient, threadId: string): Promise<GmailThreadGetResponse | null> {
1050
+ const params = new URLSearchParams({ format: 'minimal', fields: 'id,historyId,messages(id)' });
1051
+ const response = await http.raw(`${this.BASE_URL}/threads/${encodeURIComponent(threadId)}?${params}`);
1052
+ if (response.status === 404) return null;
1053
+ if (!response.ok) throw new Error(`Gmail threads.get error (${response.status}): ${await response.text()}`);
1054
+ const index = await response.json() as { id: string; historyId: string; messages?: Array<{ id: string }> };
1055
+ if (index.id !== threadId || !index.messages?.length) throw new Error('Gmail returned a thread without valid identity or messages');
1056
+ const ids = index.messages.map(message => message.id);
1057
+ if (ids.some(id => typeof id !== 'string' || !id) || new Set(ids).size !== ids.length) {
1058
+ throw new Error('Gmail returned malformed message identities');
1059
+ }
1060
+ const messages: GmailMessage[] = [];
1061
+ // Bound provider concurrency without serializing dozens of independent reads.
1062
+ for (let start = 0; start < ids.length; start += 4) {
1063
+ messages.push(...await Promise.all(ids.slice(start, start + 4).map(async id => {
1064
+ const result = await http.raw(`${this.BASE_URL}/messages/${encodeURIComponent(id)}?format=full`);
1065
+ if (!result.ok) throw new Error(`Gmail messages.get error (${result.status}): ${await result.text()}`);
1066
+ const message = await result.json() as GmailMessage;
1067
+ if (message.id !== id || message.threadId !== threadId || !message.payload) {
1068
+ throw new Error('Gmail returned malformed message identity or payload');
1069
+ }
1070
+ return message;
1071
+ })));
1072
+ }
1073
+ return { id: index.id, historyId: index.historyId, messages };
1074
+ }
1075
+
1058
1076
  private feedScope(config: GmailConfig): string {
1059
1077
  const labels = Array.isArray(config.labels)
1060
1078
  ? config.labels.filter((label) => typeof label === 'string' && label.trim()).map((label) => label.trim())
@@ -0,0 +1,406 @@
1
+ import {
2
+ ConnectorRuntime,
3
+ type ActionContext,
4
+ type ActionDefinition,
5
+ type ActionResult,
6
+ type RuntimeConnectorDefinition,
7
+ } from '@lobu/connector-sdk';
8
+
9
+ const target = {
10
+ type: 'string',
11
+ minLength: 1,
12
+ maxLength: 128,
13
+ pattern: '^[a-zA-Z0-9][a-zA-Z0-9:_-]*$',
14
+ description:
15
+ 'Explicit agent name or pane id returned by Herdr. Never targets the focused pane implicitly.',
16
+ };
17
+ const pane = { ...target, description: 'Explicit pane id returned by Herdr.' };
18
+ const workspace = { ...target, description: 'Explicit workspace id returned by Herdr.' };
19
+ const timeout = { type: 'integer', minimum: 100, maximum: 120000, default: 30000 };
20
+ const until = {
21
+ type: 'array',
22
+ maxItems: 5,
23
+ items: { type: 'string', enum: ['idle', 'working', 'blocked', 'done', 'unknown'] },
24
+ };
25
+ const read = {
26
+ source: {
27
+ type: 'string',
28
+ enum: ['visible', 'recent', 'recent-unwrapped', 'detection'],
29
+ default: 'visible',
30
+ },
31
+ lines: { type: 'integer', minimum: 1, maximum: 500, default: 80 },
32
+ };
33
+ function action(
34
+ key: string,
35
+ name: string,
36
+ description: string,
37
+ kind: 'read' | 'write',
38
+ properties: Record<string, unknown> = {},
39
+ required: string[] = [],
40
+ ): ActionDefinition {
41
+ return {
42
+ key,
43
+ name,
44
+ description,
45
+ kind,
46
+ inputSchema: { type: 'object', properties, required, additionalProperties: false },
47
+ annotations: {
48
+ destructiveHint: kind === 'write',
49
+ openWorldHint: kind === 'write',
50
+ idempotentHint: kind === 'read',
51
+ },
52
+ };
53
+ }
54
+
55
+ /** Shell only transports argv; all Herdr protocol and command semantics stay here. */
56
+ function quote(value: unknown): string {
57
+ if (typeof value !== 'string' || value.includes('\0'))
58
+ throw new Error('Expected a string without NUL bytes');
59
+ return "'" + value.replaceAll("'", "'\\''") + "'";
60
+ }
61
+ function text(input: Record<string, unknown>, key: string): string {
62
+ const value = input[key];
63
+ if (typeof value !== 'string' || !value.length || value.includes('\0'))
64
+ throw new Error(`${key} is required`);
65
+ return value;
66
+ }
67
+ function id(input: Record<string, unknown>, key = 'target'): string {
68
+ const value = text(input, key);
69
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9:_-]{0,127}$/.test(value))
70
+ throw new Error(`${key} must be an explicit Herdr identifier`);
71
+ return value;
72
+ }
73
+ function integer(value: unknown, fallback: number, maximum: number, minimum = 1): number {
74
+ if (value === undefined) return fallback;
75
+ if (typeof value !== 'number' || !Number.isInteger(value) || value < minimum || value > maximum)
76
+ throw new Error('Invalid numeric limit');
77
+ return value;
78
+ }
79
+ function waitOptions(input: Record<string, unknown>): string[] {
80
+ const states = input.until ?? [];
81
+ if (
82
+ !Array.isArray(states) ||
83
+ states.length > 5 ||
84
+ states.some((s) => !['idle', 'working', 'blocked', 'done', 'unknown'].includes(s))
85
+ )
86
+ throw new Error('Invalid wait states');
87
+ return [
88
+ '--timeout',
89
+ String(integer(input.timeout_ms, 30000, 120000)),
90
+ ...states.flatMap((s) => ['--until', s]),
91
+ ];
92
+ }
93
+ function readOptions(input: Record<string, unknown>): string[] {
94
+ const source = input.source ?? 'visible';
95
+ if (!['visible', 'recent', 'recent-unwrapped', 'detection'].includes(String(source)))
96
+ throw new Error('Invalid snapshot source');
97
+ return [
98
+ '--source',
99
+ String(source),
100
+ '--lines',
101
+ String(integer(input.lines, 80, 500)),
102
+ '--format',
103
+ 'text',
104
+ ];
105
+ }
106
+ function commandFor(
107
+ key: string,
108
+ input: Record<string, unknown>,
109
+ ): { argv: string[]; json: boolean; budget: number } {
110
+ let argv: string[];
111
+ let budget = 15000;
112
+ let json = true;
113
+ switch (key) {
114
+ case 'snapshot':
115
+ argv = ['api', 'snapshot'];
116
+ break;
117
+ case 'process_info':
118
+ argv = ['pane', 'process-info', '--pane', id(input, 'pane_id')];
119
+ break;
120
+ case 'pane_read':
121
+ argv = ['pane', 'read', id(input, 'pane_id'), ...readOptions(input)];
122
+ json = false;
123
+ break;
124
+ case 'workspace_create': {
125
+ const cwd = text(input, 'cwd');
126
+ if (!cwd.startsWith('/'))
127
+ throw new Error('cwd must be an absolute path on the selected device');
128
+ argv = ['workspace', 'create', '--cwd', cwd, '--label', text(input, 'label'), '--no-focus'];
129
+ break;
130
+ }
131
+ case 'workspace_close':
132
+ argv = ['workspace', 'close', id(input, 'workspace_id')];
133
+ break;
134
+ case 'agent_list':
135
+ argv = ['agent', 'list'];
136
+ break;
137
+ case 'agent_get':
138
+ argv = ['agent', 'get', id(input)];
139
+ break;
140
+ case 'agent_start': {
141
+ const name = text(input, 'name');
142
+ if (!/^[a-z][a-z0-9_-]{0,31}$/.test(name)) throw new Error('Invalid agent name');
143
+ const args = input.args ?? [];
144
+ if (
145
+ !Array.isArray(args) ||
146
+ args.length > 16 ||
147
+ args.some((a) => typeof a !== 'string' || a.length > 512)
148
+ )
149
+ throw new Error('Invalid agent arguments');
150
+ budget = integer(input.timeout_ms, 30000, 120000, 3001) + 5000;
151
+ argv = [
152
+ 'agent',
153
+ 'start',
154
+ name,
155
+ '--kind',
156
+ id(input, 'kind'),
157
+ '--pane',
158
+ id(input, 'pane_id'),
159
+ '--timeout',
160
+ String(budget - 5000),
161
+ '--',
162
+ ...args,
163
+ ];
164
+ break;
165
+ }
166
+ case 'agent_prompt': {
167
+ if (input.wait !== true && (input.timeout_ms !== undefined || input.until !== undefined))
168
+ throw new Error('timeout_ms and until require wait: true');
169
+ // Herdr takes positionals literally and accepts --timeout/--until only with --wait.
170
+ const wait = input.wait === true;
171
+ if (wait) budget = integer(input.timeout_ms, 30000, 120000) + 5000;
172
+ argv = [
173
+ 'agent',
174
+ 'prompt',
175
+ id(input),
176
+ text(input, 'text'),
177
+ ...(wait ? ['--wait', ...waitOptions(input)] : []),
178
+ ];
179
+ break;
180
+ }
181
+ case 'agent_wait':
182
+ budget = integer(input.timeout_ms, 30000, 120000) + 5000;
183
+ argv = ['agent', 'wait', id(input), ...waitOptions(input)];
184
+ break;
185
+ case 'agent_read':
186
+ argv = ['agent', 'read', id(input), ...readOptions(input)];
187
+ json = false;
188
+ break;
189
+ case 'agent_interrupt':
190
+ argv = ['agent', 'send-keys', id(input), 'ctrl+c'];
191
+ break;
192
+ default:
193
+ throw new Error(`Unknown Herdr operation: ${key}`);
194
+ }
195
+ return { argv, json, budget };
196
+ }
197
+
198
+ export default class HerdrConnector extends ConnectorRuntime {
199
+ readonly definition: RuntimeConnectorDefinition = {
200
+ key: 'herdr',
201
+ name: 'Herdr',
202
+ version: '1.0.0',
203
+ faviconDomain: 'herdr.dev',
204
+ description:
205
+ 'Inspect terminal workspaces and create, prompt, monitor or interrupt agents through an existing Shell connection. Requires Herdr 0.9+ installed and running on that device. Select shell_connection_id in connection settings; leave this connector on the server.',
206
+ authSchema: { methods: [{ type: 'none' }] },
207
+ feeds: {},
208
+ optionsSchema: {
209
+ type: 'object',
210
+ required: ['shell_connection_id'],
211
+ properties: {
212
+ shell_connection_id: {
213
+ type: 'integer',
214
+ minimum: 1,
215
+ title: 'Shell connection ID',
216
+ description:
217
+ 'Discover the existing os.shell connection with operations.listAvailable. Its device and policies govern all commands.',
218
+ },
219
+ binary: {
220
+ type: 'string',
221
+ minLength: 1,
222
+ title: 'Herdr executable',
223
+ default: 'herdr',
224
+ description: 'Executable name or absolute path on the selected device.',
225
+ },
226
+ },
227
+ additionalProperties: false,
228
+ },
229
+ actions: {
230
+ snapshot: action(
231
+ 'snapshot',
232
+ 'Workspace snapshot',
233
+ 'Structured workspaces, panes and agents from the running Herdr instance.',
234
+ 'read',
235
+ ),
236
+ process_info: action(
237
+ 'process_info',
238
+ 'Pane process',
239
+ 'Inspect the foreground process in an explicit pane.',
240
+ 'read',
241
+ { pane_id: pane },
242
+ ['pane_id'],
243
+ ),
244
+ pane_read: action(
245
+ 'pane_read',
246
+ 'Read pane',
247
+ 'Read bounded terminal output. Visible is passive; recent history may temporarily scroll idle terminals.',
248
+ 'read',
249
+ { pane_id: pane, ...read },
250
+ ['pane_id'],
251
+ ),
252
+ workspace_create: action(
253
+ 'workspace_create',
254
+ 'Create workspace',
255
+ 'Create an unfocused workspace and return its root pane. Start an agent in that pane with agent_start.',
256
+ 'write',
257
+ {
258
+ cwd: { type: 'string', pattern: '^/' },
259
+ label: { type: 'string', minLength: 1, maxLength: 100 },
260
+ },
261
+ ['cwd', 'label'],
262
+ ),
263
+ workspace_close: action(
264
+ 'workspace_close',
265
+ 'Close workspace',
266
+ 'Close the specified workspace and its running processes. Use only for a workspace you intend to tear down.',
267
+ 'write',
268
+ { workspace_id: workspace },
269
+ ['workspace_id'],
270
+ ),
271
+ agent_list: action(
272
+ 'agent_list',
273
+ 'List agents',
274
+ 'List registered agents and their state.',
275
+ 'read',
276
+ ),
277
+ agent_get: action(
278
+ 'agent_get',
279
+ 'Agent status',
280
+ 'Inspect one agent by its returned name or pane id.',
281
+ 'read',
282
+ { target },
283
+ ['target'],
284
+ ),
285
+ agent_start: action(
286
+ 'agent_start',
287
+ 'Start agent',
288
+ 'Start an installed interactive agent in an existing idle shell pane. Returns when that agent is detected and ready.',
289
+ 'write',
290
+ {
291
+ name: { type: 'string', pattern: '^[a-z][a-z0-9_-]{0,31}$' },
292
+ kind: { ...target, description: 'Installed Herdr agent kind to start.' },
293
+ pane_id: pane,
294
+ timeout_ms: { ...timeout, minimum: 3001 },
295
+ args: { type: 'array', maxItems: 16, items: { type: 'string', maxLength: 512 } },
296
+ },
297
+ ['name', 'kind', 'pane_id'],
298
+ ),
299
+ agent_prompt: action(
300
+ 'agent_prompt',
301
+ 'Prompt agent',
302
+ 'Submit a prompt or follow-up. timeout_ms and until require wait: true. Start from idle for reliable wait semantics: Herdr tracks terminal states, not turns. After timeout/stall, inspect before retrying; input may already have been delivered.',
303
+ 'write',
304
+ {
305
+ target,
306
+ text: { type: 'string', minLength: 1, maxLength: 10000 },
307
+ wait: { type: 'boolean', default: false },
308
+ timeout_ms: timeout,
309
+ until,
310
+ },
311
+ ['target', 'text'],
312
+ ),
313
+ agent_wait: action(
314
+ 'agent_wait',
315
+ 'Wait for agent',
316
+ 'Bounded state wait; already matching states return immediately. Cancelling this wait does not interrupt the persistent agent.',
317
+ 'read',
318
+ { target, timeout_ms: timeout, until },
319
+ ['target'],
320
+ ),
321
+ agent_read: action(
322
+ 'agent_read',
323
+ 'Read agent',
324
+ 'Read bounded terminal output to verify the actual result of a turn.',
325
+ 'read',
326
+ { target, ...read },
327
+ ['target'],
328
+ ),
329
+ agent_interrupt: action(
330
+ 'agent_interrupt',
331
+ 'Interrupt agent',
332
+ 'Send Ctrl+C to the explicitly selected agent. Inspect its state afterward.',
333
+ 'write',
334
+ { target },
335
+ ['target'],
336
+ ),
337
+ },
338
+ };
339
+
340
+ async execute(ctx: ActionContext): Promise<ActionResult> {
341
+ if (!ctx.operations)
342
+ return {
343
+ success: false,
344
+ error:
345
+ 'This Lobu host does not support connector operation delegation. Update the Lobu server.',
346
+ };
347
+ const connectionId = ctx.config.shell_connection_id;
348
+ if (typeof connectionId !== 'number' || !Number.isSafeInteger(connectionId) || connectionId < 1)
349
+ return {
350
+ success: false,
351
+ error: 'Configure shell_connection_id with an existing os.shell connection.',
352
+ };
353
+ const command = commandFor(ctx.actionKey, ctx.input);
354
+ const binary = ctx.config.binary ?? 'herdr';
355
+ const receipt = await ctx.operations.execute({
356
+ connection_id: connectionId,
357
+ operation_key: 'run',
358
+ idempotency_key: 'herdr-command',
359
+ input: {
360
+ command: [binary, ...command.argv].map(quote).join(' '),
361
+ timeout_ms: command.budget,
362
+ },
363
+ });
364
+ if ('error' in receipt) return { success: false, error: receipt.error };
365
+ if (receipt.status === 'pending_approval' || receipt.status === 'in_progress')
366
+ return { success: true, output: { ...receipt } };
367
+ if (receipt.status !== 'completed') return { success: false, error: JSON.stringify(receipt) };
368
+ const shell = receipt.output as {
369
+ exit_code?: number;
370
+ timed_out?: boolean;
371
+ stdout?: string;
372
+ stderr?: string;
373
+ };
374
+ let result: unknown = shell?.stdout ?? '';
375
+ if (command.json && typeof result === 'string' && shell?.exit_code === 0 && !shell?.timed_out) {
376
+ try {
377
+ result = JSON.parse(result);
378
+ } catch {
379
+ return {
380
+ success: false,
381
+ error: `Herdr returned invalid JSON (shell run ${receipt.run_id}); inspect that run before retrying.`,
382
+ };
383
+ }
384
+ }
385
+ if (
386
+ !shell ||
387
+ shell.exit_code !== 0 ||
388
+ shell.timed_out ||
389
+ (typeof result === 'object' && result !== null && 'error' in result)
390
+ ) {
391
+ return {
392
+ success: false,
393
+ error: JSON.stringify({
394
+ run_id: receipt.run_id,
395
+ exit_code: shell?.exit_code,
396
+ timed_out: shell?.timed_out,
397
+ result,
398
+ stderr: shell?.stderr?.slice(-2000),
399
+ message:
400
+ 'Inspect this run before retrying. A command or prompt may already have been delivered.',
401
+ }),
402
+ };
403
+ }
404
+ return { success: true, output: { status: 'completed', run_id: receipt.run_id, result } };
405
+ }
406
+ }
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Jira Connector (V1 runtime)
3
3
  *
4
- * Reads Jira Cloud issues via JQL and can sync them into events. Real-time
5
- * issue/comment deliveries can arrive through the app-level webhook path; raw
6
- * deliveries land downstream (extract-load).
4
+ * Reads Jira Cloud issues via JQL and can sync them into events. App-level
5
+ * webhook deliveries are verified and routed to the owning install, but the
6
+ * connector declares no webhook event type, so they trigger nothing yet.
7
7
  */
8
8
 
9
9
  import { randomBytes } from 'node:crypto';
@@ -304,8 +304,8 @@ export default class JiraConnector extends ConnectorRuntime<JiraCheckpoint, Jira
304
304
  key: 'jira',
305
305
  name: 'Jira',
306
306
  description:
307
- 'Syncs and live-reads Jira Cloud issues via JQL, and receives real-time issue/comment webhooks.',
308
- version: '1.1.4',
307
+ 'Syncs and live-reads Jira Cloud issues via JQL.',
308
+ version: '1.1.5',
309
309
  faviconDomain: 'atlassian.com',
310
310
  webhook: {
311
311
  // Jira Connect app webhooks HMAC-sign the raw body with the installation
@@ -612,7 +612,7 @@ export default class JiraConnector extends ConnectorRuntime<JiraCheckpoint, Jira
612
612
  }
613
613
 
614
614
  // -------------------------------------------------------------------------
615
- // Webhooks (subscription lifecycle — raw deliveries land downstream)
615
+ // Webhooks (subscription lifecycle — per-connection deliveries are stored raw)
616
616
  // -------------------------------------------------------------------------
617
617
 
618
618
  async registerWebhook(
@@ -2,8 +2,8 @@
2
2
  * Linear Connector (V1 runtime)
3
3
  *
4
4
  * Reads Linear issues via GraphQL and can sync them into events.
5
- * Real-time Issue/Comment deliveries arrive via app webhooks; raw deliveries
6
- * land downstream (extract-load).
5
+ * Real-time Issue/Comment deliveries mark the issues feed due, so the poll
6
+ * fetches the changed issues.
7
7
  */
8
8
 
9
9
  import { randomBytes } from 'node:crypto';
@@ -152,7 +152,7 @@ export default class LinearConnector extends ConnectorRuntime<LinearCheckpoint,
152
152
  name: 'Linear',
153
153
  description:
154
154
  'Syncs and live-reads Linear issues via GraphQL, and receives real-time issue/comment webhooks.',
155
- version: '1.1.1',
155
+ version: '1.2.0',
156
156
  faviconDomain: 'linear.app',
157
157
  webhook: {
158
158
  signatureHeader: 'linear-signature',
@@ -160,6 +160,7 @@ export default class LinearConnector extends ConnectorRuntime<LinearCheckpoint,
160
160
  // Linear signs the raw body with HMAC-SHA256 and sends a bare hex digest
161
161
  // (no `sha256=` prefix). It does not send a stable delivery id header, so
162
162
  // dedupe falls back to a body hash (no `dedupeHeader`).
163
+ eventType: { path: 'type' },
163
164
  // App-installation delivery: one webhook configured ONCE on the Linear app;
164
165
  // every delivery carries the workspace `organizationId` — that's the tenant.
165
166
  delivery: 'app_installation',
@@ -193,6 +194,8 @@ export default class LinearConnector extends ConnectorRuntime<LinearCheckpoint,
193
194
  sync: (ctx) => this.syncFeed(ctx),
194
195
  read: (ctx) => this.readFeed(ctx),
195
196
  readWindowAxis: 'updated_at',
197
+ // A comment also moves its issue's updatedAt, so both wake the poll.
198
+ webhook: { events: ['Issue', 'Comment'] },
196
199
  configSchema: {
197
200
  type: 'object',
198
201
  properties: {
@@ -397,7 +400,7 @@ export default class LinearConnector extends ConnectorRuntime<LinearCheckpoint,
397
400
  }
398
401
 
399
402
  // -------------------------------------------------------------------------
400
- // Webhooks (subscription lifecycle — raw deliveries land downstream)
403
+ // Webhooks (subscription lifecycle; the platform dispatches deliveries)
401
404
  // -------------------------------------------------------------------------
402
405
 
403
406
  async registerWebhook(