@lobu/runtime-device 21.2.1 → 23.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 (233) 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/bundled-skills/lobu/SKILL.md +1 -1
  6. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +5 -6
  7. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +1 -0
  8. package/vendor/cli/dist/commands/_lib/apply/client.js +26 -7
  9. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +9 -1
  10. package/vendor/cli/dist/commands/_lib/apply/diff.d.ts +1 -0
  11. package/vendor/cli/dist/commands/_lib/apply/diff.js +46 -4
  12. package/vendor/cli/dist/commands/_lib/apply/map-config.js +18 -38
  13. package/vendor/cli/dist/commands/_lib/init-from-org/bootstrap.js +5 -17
  14. package/vendor/cli/dist/commands/init.d.ts +0 -2
  15. package/vendor/cli/dist/commands/init.js +0 -27
  16. package/vendor/cli/dist/commands/login.d.ts +17 -0
  17. package/vendor/cli/dist/commands/login.js +43 -17
  18. package/vendor/cli/dist/commands/memory/_lib/errors.d.ts +0 -8
  19. package/vendor/cli/dist/commands/memory/_lib/errors.js +0 -12
  20. package/vendor/cli/dist/commands/memory/_lib/mcp.js +6 -6
  21. package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +4 -10
  22. package/vendor/cli/dist/config/define.d.ts +21 -15
  23. package/vendor/cli/dist/config/define.js +2 -2
  24. package/vendor/cli/dist/connectors/README.md +21 -6
  25. package/vendor/cli/dist/connectors/_google/actions.ts +270 -0
  26. package/vendor/cli/dist/connectors/_google/discovery/calendar_v3.json +1 -0
  27. package/vendor/cli/dist/connectors/_google/discovery/chat_v1.json +1 -0
  28. package/vendor/cli/dist/connectors/_google/discovery/docs_v1.json +1 -0
  29. package/vendor/cli/dist/connectors/_google/discovery/drive_v3.json +1 -0
  30. package/vendor/cli/dist/connectors/_google/discovery/gmail_v1.json +1 -0
  31. package/vendor/cli/dist/connectors/_google/discovery/people_v1.json +1 -0
  32. package/vendor/cli/dist/connectors/_google/discovery/sheets_v4.json +1 -0
  33. package/vendor/cli/dist/connectors/_google/discovery/tasks_v1.json +1 -0
  34. package/vendor/cli/dist/connectors/_google/discovery/youtube_v3.json +1 -0
  35. package/vendor/cli/dist/connectors/_google/discovery.ts +442 -0
  36. package/vendor/cli/dist/connectors/_google/errors.ts +91 -0
  37. package/vendor/cli/dist/connectors/_google/list-feed.ts +223 -0
  38. package/vendor/cli/dist/connectors/_google/policies.ts +127 -0
  39. package/vendor/cli/dist/connectors/agentid.ts +43 -0
  40. package/vendor/cli/dist/connectors/chat-user-identity.ts +2 -1
  41. package/vendor/cli/dist/connectors/github-automation-events.ts +9 -0
  42. package/vendor/cli/dist/connectors/github-identity.ts +28 -3
  43. package/vendor/cli/dist/connectors/github.ts +101 -59
  44. package/vendor/cli/dist/connectors/google_calendar.ts +207 -719
  45. package/vendor/cli/dist/connectors/google_drive.ts +16 -2
  46. package/vendor/cli/dist/connectors/google_gmail.ts +52 -33
  47. package/vendor/cli/dist/connectors/herdr.ts +406 -0
  48. package/vendor/cli/dist/connectors/jira-helpers.ts +313 -0
  49. package/vendor/cli/dist/connectors/jira.ts +35 -227
  50. package/vendor/cli/dist/connectors/linear.ts +7 -4
  51. package/vendor/cli/dist/connectors/linkedin-browser-script.ts +13 -0
  52. package/vendor/cli/dist/connectors/linkedin-draft-page.js +104 -0
  53. package/vendor/cli/dist/connectors/linkedin-drafts.ts +73 -0
  54. package/vendor/cli/dist/connectors/linkedin-identity.ts +32 -0
  55. package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +1185 -0
  56. package/vendor/cli/dist/connectors/linkedin-inbox.ts +156 -0
  57. package/vendor/cli/dist/connectors/linkedin-like.ts +114 -0
  58. package/vendor/cli/dist/connectors/linkedin-takeout.ts +577 -0
  59. package/vendor/cli/dist/connectors/linkedin.ts +3998 -0
  60. package/vendor/cli/dist/connectors/postgres.ts +27 -2
  61. package/vendor/cli/dist/connectors/takeout-utils.ts +240 -0
  62. package/vendor/cli/dist/connectors/tiktok-inbox-page.js +230 -0
  63. package/vendor/cli/dist/connectors/tiktok-web-page.js +217 -0
  64. package/vendor/cli/dist/connectors/tiktok_web.ts +319 -0
  65. package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +285 -567
  66. package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +74 -455
  67. package/vendor/cli/dist/connectors/whatsapp-web-identity.ts +135 -0
  68. package/vendor/cli/dist/connectors/whatsapp_web.ts +159 -618
  69. package/vendor/cli/dist/connectors/x-dm-adapter.js +556 -0
  70. package/vendor/cli/dist/connectors/x-identity.ts +31 -2
  71. package/vendor/cli/dist/connectors/x.ts +539 -253
  72. package/vendor/cli/dist/index.js +1 -37
  73. package/vendor/cli/dist/internal/context.d.ts +10 -0
  74. package/vendor/cli/dist/internal/context.js +26 -16
  75. package/vendor/cli/dist/internal/node-version.d.ts +1 -1
  76. package/vendor/cli/dist/internal/node-version.js +1 -1
  77. package/vendor/cli/dist/internal/oauth.d.ts +3 -1
  78. package/vendor/cli/dist/internal/oauth.js +4 -3
  79. package/vendor/cli/dist/internal/runtime-components.d.ts +9 -0
  80. package/vendor/cli/dist/internal/runtime-components.js +67 -2
  81. package/vendor/cli/dist/mac-auth.js +17 -1
  82. package/vendor/cli/dist/providers.json +1 -1
  83. package/vendor/cli/dist/runtime-components.json +4 -4
  84. package/vendor/cli/dist/templates/AGENTS.md.tmpl +12 -5
  85. package/vendor/cli/dist/templates/README.md.tmpl +1 -1
  86. package/vendor/cli/dist/vendor/ora/.bun-tag-fde20e9a6df212fa +0 -0
  87. package/vendor/cli/dist/vendor/ora/index.d.ts +332 -0
  88. package/vendor/cli/dist/vendor/ora/index.js +424 -0
  89. package/vendor/cli/dist/vendor/ora/license +9 -0
  90. package/vendor/cli/dist/vendor/ora/package.json +64 -0
  91. package/vendor/cli/dist/vendor/ora/readme.md +329 -0
  92. package/vendor/cli/package.json +2 -2
  93. package/vendor/connector-sdk/dist/browser-handoff-banner.d.ts +39 -0
  94. package/vendor/connector-sdk/dist/browser-handoff-banner.js +175 -0
  95. package/vendor/connector-sdk/dist/browser-requirement.d.ts +36 -0
  96. package/vendor/connector-sdk/dist/browser-requirement.js +60 -0
  97. package/vendor/connector-sdk/dist/browser-source-read.d.ts +52 -0
  98. package/vendor/connector-sdk/dist/browser-source-read.js +107 -0
  99. package/vendor/connector-sdk/dist/connector-runtime.d.ts +3 -1
  100. package/vendor/connector-sdk/dist/connector-runtime.js +10 -0
  101. package/vendor/connector-sdk/dist/connector-types.d.ts +169 -45
  102. package/vendor/connector-sdk/dist/define-connector.d.ts +4 -2
  103. package/vendor/connector-sdk/dist/define-connector.js +3 -0
  104. package/vendor/connector-sdk/dist/index.d.ts +8 -2
  105. package/vendor/connector-sdk/dist/index.js +3 -0
  106. package/vendor/connector-sdk/dist/reaction-client-types.d.ts +16 -21
  107. package/vendor/connector-sdk/dist/reaction-client-types.typecheck.d.ts +5 -0
  108. package/vendor/connector-sdk/package.json +13 -1
  109. package/vendor/connector-worker/dist/agent-turn/guest-entry.js +43 -30
  110. package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +416 -330
  111. package/vendor/connector-worker/dist/agent-turn/memory.d.ts +3 -2
  112. package/vendor/connector-worker/dist/agent-turn/memory.js +3 -20
  113. package/vendor/connector-worker/dist/agent-turn/types.d.ts +3 -15
  114. package/vendor/connector-worker/dist/agent-turn/workspace.d.ts +2 -2
  115. package/vendor/connector-worker/dist/agent-turn/workspace.js +2 -4
  116. package/vendor/connector-worker/dist/daemon/action-monitor.d.ts +12 -0
  117. package/vendor/connector-worker/dist/daemon/action-monitor.js +25 -0
  118. package/vendor/connector-worker/dist/daemon/agent-turn.js +0 -9
  119. package/vendor/connector-worker/dist/daemon/automation.d.ts +4 -11
  120. package/vendor/connector-worker/dist/daemon/automation.js +6 -6
  121. package/vendor/connector-worker/dist/daemon/builtins/index.d.ts +12 -0
  122. package/vendor/connector-worker/dist/daemon/builtins/index.js +61 -1
  123. package/vendor/connector-worker/dist/daemon/builtins/os-shell.d.ts +2 -1
  124. package/vendor/connector-worker/dist/daemon/builtins/os-shell.js +40 -27
  125. package/vendor/connector-worker/dist/daemon/client.d.ts +6 -4
  126. package/vendor/connector-worker/dist/daemon/client.js +3 -3
  127. package/vendor/connector-worker/dist/daemon/device-concurrency.d.ts +8 -0
  128. package/vendor/connector-worker/dist/daemon/device-concurrency.js +13 -0
  129. package/vendor/connector-worker/dist/daemon/executor.d.ts +1 -1
  130. package/vendor/connector-worker/dist/daemon/executor.js +48 -120
  131. package/vendor/connector-worker/dist/daemon/log.d.ts +2 -0
  132. package/vendor/connector-worker/dist/daemon/log.js +23 -2
  133. package/vendor/connector-worker/dist/daemon/mac-device-daemon.d.ts +23 -6
  134. package/vendor/connector-worker/dist/daemon/mac-device-daemon.js +57 -23
  135. package/vendor/connector-worker/dist/daemon/native-bridge/client.d.ts +6 -0
  136. package/vendor/connector-worker/dist/daemon/native-bridge/client.js +15 -0
  137. package/vendor/connector-worker/dist/daemon/native-bridge/executor.js +29 -25
  138. package/vendor/connector-worker/dist/daemon/native-bridge/protocol.d.ts +1 -1
  139. package/vendor/connector-worker/dist/daemon/native-bridge/protocol.js +1 -0
  140. package/vendor/connector-worker/dist/daemon/poll-loop.d.ts +3 -0
  141. package/vendor/connector-worker/dist/daemon/poll-loop.js +5 -1
  142. package/vendor/connector-worker/dist/daemon/start.d.ts +1 -0
  143. package/vendor/connector-worker/dist/daemon/start.js +15 -20
  144. package/vendor/connector-worker/dist/daemon/terminal-failure.js +0 -11
  145. package/vendor/connector-worker/dist/daemon/worker-id.d.ts +17 -0
  146. package/vendor/connector-worker/dist/daemon/worker-id.js +22 -0
  147. package/vendor/connector-worker/dist/executor/interface.d.ts +34 -2
  148. package/vendor/connector-worker/dist/executor/isolate.js +66 -15
  149. package/vendor/connector-worker/dist/executor/redact.d.ts +1 -0
  150. package/vendor/connector-worker/dist/executor/redact.js +97 -26
  151. package/vendor/connector-worker/dist/executor/runtime.d.ts +7 -0
  152. package/vendor/connector-worker/dist/executor/runtime.js +26 -0
  153. package/vendor/connector-worker/dist/isolate/bridge.js +3 -1
  154. package/vendor/connector-worker/dist/mac-device-daemon.js +24 -29
  155. package/vendor/connector-worker/package.json +2 -2
  156. package/vendor/core/dist/agent-policy.js +1 -1
  157. package/vendor/core/dist/agent-store.d.ts +2 -0
  158. package/vendor/core/dist/agent-tooling.d.ts +1 -1
  159. package/vendor/core/dist/agent-tooling.js +1 -1
  160. package/vendor/core/dist/capabilities.d.ts +1 -1
  161. package/vendor/core/dist/capabilities.js +2 -1
  162. package/vendor/core/dist/connector-query-errors.d.ts +32 -0
  163. package/vendor/core/dist/connector-query-errors.js +41 -1
  164. package/vendor/core/dist/contracts/agent-settings.d.ts +0 -11
  165. package/vendor/core/dist/contracts/agent-settings.js +1 -7
  166. package/vendor/core/dist/contracts/tools/collection-presentation.d.ts +93 -0
  167. package/vendor/core/dist/contracts/tools/collection-presentation.js +88 -0
  168. package/vendor/core/dist/contracts/tools/collection-selection.d.ts +47 -0
  169. package/vendor/core/dist/contracts/tools/collection-selection.js +74 -0
  170. package/vendor/core/dist/contracts/tools/manage-agents.d.ts +10 -4
  171. package/vendor/core/dist/contracts/tools/manage-auth-profiles.d.ts +1 -1
  172. package/vendor/core/dist/contracts/tools/manage-auth-profiles.js +5 -1
  173. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +19 -4
  174. package/vendor/core/dist/contracts/tools/manage-automations.js +25 -8
  175. package/vendor/core/dist/contracts/tools/manage-connections.d.ts +1 -0
  176. package/vendor/core/dist/contracts/tools/manage-connections.js +3 -0
  177. package/vendor/core/dist/contracts/tools/manage-conversations.js +2 -2
  178. package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +11 -0
  179. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +42 -3
  180. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +181 -152
  181. package/vendor/core/dist/contracts/tools/manage-entity.js +118 -162
  182. package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +14 -0
  183. package/vendor/core/dist/contracts/tools/manage-feeds.js +17 -0
  184. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +41 -3
  185. package/vendor/core/dist/contracts/tools/manage-operations.js +40 -2
  186. package/vendor/core/dist/contracts/tools/manage-views.d.ts +182 -7
  187. package/vendor/core/dist/contracts/tools/manage-views.js +49 -13
  188. package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +11 -2
  189. package/vendor/core/dist/contracts/tools/read-knowledge.js +23 -3
  190. package/vendor/core/dist/contracts/tools/save-memory.d.ts +3 -6
  191. package/vendor/core/dist/contracts/tools/save-memory.js +2 -6
  192. package/vendor/core/dist/contracts/tools/view-attach.d.ts +2 -1
  193. package/vendor/core/dist/contracts/tools/view-attach.js +7 -2
  194. package/vendor/core/dist/contracts/worker/protocol.d.ts +130 -159
  195. package/vendor/core/dist/contracts/worker/protocol.js +88 -76
  196. package/vendor/core/dist/device-pin-tombstones.d.ts +44 -0
  197. package/vendor/core/dist/device-pin-tombstones.js +57 -0
  198. package/vendor/core/dist/index.d.ts +5 -5
  199. package/vendor/core/dist/index.js +4 -6
  200. package/vendor/core/dist/json-template.d.ts +6 -10
  201. package/vendor/core/dist/json-template.js +5 -9
  202. package/vendor/core/dist/logger.js +17 -26
  203. package/vendor/core/dist/shell-safety.d.ts +9 -0
  204. package/vendor/core/dist/shell-safety.js +154 -0
  205. package/vendor/core/dist/suggestions.d.ts +1 -1
  206. package/vendor/core/dist/suggestions.js +1 -1
  207. package/vendor/core/dist/tool-trace-summary.d.ts +1 -1
  208. package/vendor/core/dist/tool-trace-summary.js +1 -1
  209. package/vendor/core/dist/types.d.ts +1 -3
  210. package/vendor/core/dist/utils/diagnostic-scrubber.d.ts +7 -0
  211. package/vendor/core/dist/utils/diagnostic-scrubber.js +437 -0
  212. package/vendor/core/dist/worker/auth.d.ts +44 -6
  213. package/vendor/core/dist/worker/auth.js +44 -11
  214. package/vendor/core/dist/worker/wire.d.ts +0 -10
  215. package/vendor/core/package.json +20 -11
  216. package/vendor/ora/.bun-tag-fde20e9a6df212fa +0 -0
  217. package/vendor/ora/index.d.ts +332 -0
  218. package/vendor/ora/index.js +424 -0
  219. package/vendor/ora/license +9 -0
  220. package/vendor/ora/package.json +53 -0
  221. package/vendor/ora/readme.md +329 -0
  222. package/vendor/cli/dist/commands/telemetry.d.ts +0 -10
  223. package/vendor/cli/dist/commands/telemetry.js +0 -66
  224. package/vendor/connector-worker/dist/daemon/device-chat.d.ts +0 -9
  225. package/vendor/connector-worker/dist/daemon/device-chat.js +0 -61
  226. package/vendor/core/dist/contracts/worker/device-chat.d.ts +0 -4
  227. package/vendor/core/dist/contracts/worker/device-chat.js +0 -26
  228. package/vendor/core/dist/sentry.d.ts +0 -26
  229. package/vendor/core/dist/sentry.js +0 -133
  230. package/vendor/core/dist/tool-policy.d.ts +0 -74
  231. package/vendor/core/dist/tool-policy.js +0 -305
  232. package/vendor/core/dist/utils/sentry-scrubber.d.ts +0 -29
  233. package/vendor/core/dist/utils/sentry-scrubber.js +0 -228
@@ -0,0 +1,223 @@
1
+ /**
2
+ * Feeds over a Google `*.list` method, driven by its Discovery description.
3
+ *
4
+ * Discovery supplies the URL, the page-size parameter, the items array and
5
+ * whether the method supports `syncToken`; a feed declares only what Google
6
+ * cannot know — which filters a full traversal uses, how an item becomes an
7
+ * event, and what invalidates the checkpoint.
8
+ *
9
+ * The syncToken strategy (Calendar events/calendarList/acl/settings, People
10
+ * connections/otherContacts/contactGroups) follows Google's documented
11
+ * protocol:
12
+ * - A full traversal applies the feed's filters; Google forbids most of them
13
+ * alongside a `syncToken`, so an incremental traversal sends only the token.
14
+ * - `nextSyncToken` arrives on the LAST page only, so the feed cannot go
15
+ * incremental until a traversal reaches it.
16
+ * - Every page commits with a parked checkpoint (its continuation and the
17
+ * exact query that minted it); a page token is valid only against that query.
18
+ * - A rejected token (410 GONE, or a scope-insufficient 403 from a token
19
+ * minted under a previous grant) drops both tokens and re-traverses once.
20
+ * Stable `origin_id`s make the replay a supersede, not a duplicate.
21
+ */
22
+ import type {
23
+ EventEnvelope,
24
+ FeedReadContext,
25
+ FeedReadResult,
26
+ HttpClient,
27
+ SyncContext,
28
+ SyncResult,
29
+ } from '@lobu/connector-sdk';
30
+ import { buildGoogleRequest, type DiscoveryDocument, type DiscoveryMethod, findMethod } from './discovery';
31
+ import { classifyGoogleError, type GoogleErrorCode } from './errors';
32
+
33
+ type Params = Record<string, string>;
34
+ type Item = Record<string, unknown>;
35
+
36
+ export interface ListMethod {
37
+ doc: DiscoveryDocument;
38
+ method: DiscoveryMethod;
39
+ /** Response property holding the page's records, e.g. `items`, `connections`. */
40
+ itemsKey: string;
41
+ /** `maxResults` or `pageSize`, whichever the method takes. */
42
+ pageSizeParam: string;
43
+ supportsSyncToken: boolean;
44
+ }
45
+
46
+ /**
47
+ * Resolve a list method's shape from Discovery. The items array is `items`
48
+ * when the response has one (Calendar's `Events` also has a `defaultReminders`
49
+ * array, which is not the page), otherwise its only array of records. Two
50
+ * candidates and no `items` is refused rather than guessed.
51
+ */
52
+ export function listMethod(doc: DiscoveryDocument, methodId: string): ListMethod {
53
+ const method = findMethod(doc, methodId);
54
+ const response = method.response ? doc.schemas?.[method.response.$ref] : undefined;
55
+ const recordArrays = Object.entries(response?.properties ?? {}).filter(
56
+ ([, p]) => p.type === 'array' && p.items?.$ref !== undefined
57
+ );
58
+ const itemsKey = recordArrays.some(([name]) => name === 'items')
59
+ ? 'items'
60
+ : recordArrays.length === 1
61
+ ? recordArrays[0][0]
62
+ : undefined;
63
+ if (!itemsKey) {
64
+ throw new Error(
65
+ `${methodId} has ${recordArrays.length} record arrays in its response; declare which one is the page`
66
+ );
67
+ }
68
+ const params = method.parameters ?? {};
69
+ const pageSizeParam = 'maxResults' in params ? 'maxResults' : 'pageSize';
70
+ if (!(pageSizeParam in params) || !('pageToken' in params)) {
71
+ throw new Error(`${methodId} is not a paginated list method`);
72
+ }
73
+ return {
74
+ doc,
75
+ method,
76
+ itemsKey,
77
+ pageSizeParam,
78
+ supportsSyncToken: 'syncToken' in params || 'requestSyncToken' in params,
79
+ };
80
+ }
81
+
82
+ export interface SyncTokenFeed<F> {
83
+ list: ListMethod;
84
+ /** Path parameters, e.g. `{ calendarId }`. */
85
+ path(config: F): Record<string, string>;
86
+ /** Filters for a full traversal. */
87
+ bootstrap(config: F, now: Date): Params;
88
+ /** Parameters sent alongside the syncToken (must be ones Google allows there). */
89
+ incremental?(config: F): Params;
90
+ /** Page size requested from Google. */
91
+ pageSize: number;
92
+ /** A change discards the stored cursors and re-runs the bootstrap. */
93
+ scope(config: F): unknown[];
94
+ /** Records one bootstrap run collects before yielding `more`. */
95
+ budget(config: F): number;
96
+ /** Fail closed when a traversal ends without a replacement token. */
97
+ requireSyncToken?: boolean;
98
+ toEnvelope(item: Item): EventEnvelope | null;
99
+ }
100
+
101
+ interface SyncTokenCheckpoint {
102
+ scope?: string;
103
+ sync_token?: string;
104
+ last_sync_at?: string;
105
+ pending?: { params: string; page_token: string };
106
+ }
107
+
108
+ /** Error codes meaning "the stored token is unusable", not "the request is wrong". */
109
+ const TOKEN_REJECTIONS: GoogleErrorCode[] = ['cursor_expired', 'scope_insufficient'];
110
+ const MAX_SYNC_PAGES = 200;
111
+
112
+ export async function syncTokenSync<F>(
113
+ feed: SyncTokenFeed<F>,
114
+ ctx: SyncContext<Record<string, unknown>, F>,
115
+ http: HttpClient
116
+ ): Promise<SyncResult> {
117
+ const { list } = feed;
118
+ const checkpoint = (ctx.checkpoint ?? {}) as SyncTokenCheckpoint;
119
+ const scope = JSON.stringify(feed.scope(ctx.config));
120
+ const resumable = checkpoint.scope === scope;
121
+ const syncToken = resumable ? checkpoint.sync_token : undefined;
122
+ const pending = resumable ? checkpoint.pending : undefined;
123
+ const pageSize = { [list.pageSizeParam]: String(feed.pageSize) };
124
+
125
+ const params = pending
126
+ ? new URLSearchParams(pending.params)
127
+ : new URLSearchParams(
128
+ syncToken
129
+ ? { ...pageSize, syncToken, ...feed.incremental?.(ctx.config) }
130
+ : { ...pageSize, ...feed.bootstrap(ctx.config, new Date()) }
131
+ );
132
+ const baseParams = params.toString();
133
+ const baseUrl = buildGoogleRequest(list.doc, list.method, feed.path(ctx.config)).url;
134
+
135
+ const parked = (token: string): SyncTokenCheckpoint => ({
136
+ scope,
137
+ ...(syncToken ? { sync_token: syncToken, last_sync_at: checkpoint.last_sync_at } : {}),
138
+ pending: { params: baseParams, page_token: token },
139
+ });
140
+
141
+ let collected = 0;
142
+ let pageToken = pending?.page_token;
143
+ const seenTokens = new Set<string>();
144
+ for (let page = 0; ; page++) {
145
+ if (pageToken) {
146
+ seenTokens.add(pageToken);
147
+ params.set('pageToken', pageToken);
148
+ }
149
+ const response = await http.raw(`${baseUrl}?${params.toString()}`);
150
+ if (!response.ok) {
151
+ const body = await response.text();
152
+ if (syncToken && TOKEN_REJECTIONS.includes(classifyGoogleError(response.status, body).code)) {
153
+ // Bounded to one retry: the recursive call carries no token, so a
154
+ // genuinely missing scope fails the full traversal and propagates.
155
+ return syncTokenSync(feed, { ...ctx, checkpoint: { scope } }, http);
156
+ }
157
+ throw new Error(`${list.method.id} error (${response.status}): ${body}`);
158
+ }
159
+
160
+ const data = (await response.json()) as Record<string, unknown>;
161
+ const items = (data[list.itemsKey] as Item[] | undefined) ?? [];
162
+ // A provider page is atomic: the budget bounds how much a run STARTS,
163
+ // never how much of a fetched page is stored.
164
+ const events = items.map(feed.toEnvelope).filter((e): e is EventEnvelope => e !== null);
165
+ const next = data.nextPageToken as string | undefined;
166
+
167
+ if (!next) {
168
+ const token = data.nextSyncToken as string | undefined;
169
+ if (feed.requireSyncToken && !token) {
170
+ throw new Error(`${list.method.id} traversal completed without a durable sync token.`);
171
+ }
172
+ await ctx.commit(events, {
173
+ ...(token ? { sync_token: token } : {}),
174
+ last_sync_at: new Date().toISOString(),
175
+ scope,
176
+ } as Record<string, unknown>);
177
+ return { status: 'complete' };
178
+ }
179
+ if (seenTokens.has(next)) throw new Error(`${list.method.id} returned a repeated page token.`);
180
+ pageToken = next;
181
+ await ctx.commit(events, parked(pageToken) as Record<string, unknown>);
182
+ collected += events.length;
183
+ if ((!syncToken && collected >= feed.budget(ctx.config)) || items.length === 0 || page + 1 >= MAX_SYNC_PAGES) {
184
+ return { status: 'more' };
185
+ }
186
+ }
187
+ }
188
+
189
+ export interface ListRead<F> {
190
+ list: ListMethod;
191
+ path(config: F): Record<string, string>;
192
+ /** Query parameters for this read; validate the caller's sort/offset here. */
193
+ params(ctx: FeedReadContext<F>): Params;
194
+ /** Upper bound on the page size Google accepts. */
195
+ maxPageSize: number;
196
+ toRow(item: Item): Record<string, unknown> | null;
197
+ columns: Array<{ name: string; type: string }>;
198
+ }
199
+
200
+ /** One live page of a list method. Nothing is persisted. */
201
+ export async function listRead<F>(
202
+ read: ListRead<F>,
203
+ ctx: FeedReadContext<F>,
204
+ http: HttpClient
205
+ ): Promise<FeedReadResult> {
206
+ const { list } = read;
207
+ const params = new URLSearchParams({
208
+ [list.pageSizeParam]: String(Math.min(read.maxPageSize, Math.max(1, Math.trunc(ctx.limit ?? 50)))),
209
+ ...read.params(ctx),
210
+ });
211
+ if (ctx.cursor) params.set('pageToken', ctx.cursor);
212
+ const url = `${buildGoogleRequest(list.doc, list.method, read.path(ctx.config)).url}?${params.toString()}`;
213
+ const response = await http.raw(url);
214
+ if (!response.ok) {
215
+ throw new Error(`${list.method.id} error (${response.status}): ${await response.text()}`);
216
+ }
217
+ const data = (await response.json()) as Record<string, unknown>;
218
+ const rows = ((data[list.itemsKey] as Item[] | undefined) ?? [])
219
+ .map(read.toRow)
220
+ .filter((row): row is Record<string, unknown> => row !== null);
221
+ const next = data.nextPageToken as string | undefined;
222
+ return { rows, columns: read.columns, nextCursor: next, hasMore: Boolean(next) };
223
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * What Discovery cannot say about each Google API.
3
+ *
4
+ * Kept as data so a change in coverage is a reviewable one-line diff. A method
5
+ * absent from every list below is exposed exactly as Discovery describes it.
6
+ */
7
+ import type { GoogleApiPolicy } from './actions';
8
+
9
+ const auth = (scope: string) => `https://www.googleapis.com/auth/${scope}`;
10
+
11
+ export const GOOGLE_API_POLICIES: Record<string, GoogleApiPolicy> = {
12
+ calendar_v3: {
13
+ scopeLadder: [
14
+ auth('calendar.readonly'),
15
+ auth('calendar.events'),
16
+ auth('calendar.calendarlist'),
17
+ auth('calendar.acls'),
18
+ auth('calendar.calendars'),
19
+ auth('calendar'),
20
+ ],
21
+ // Hands the calendar to another account; not reversible by this user.
22
+ blockedMethods: ['calendar.calendars.transferOwnership'],
23
+ readMethods: ['calendar.freebusy.query'],
24
+ destructiveMethods: ['calendar.calendars.clear'],
25
+ defaults: { calendarId: 'primary' },
26
+ },
27
+ gmail_v1: {
28
+ scopeLadder: [
29
+ auth('gmail.readonly'),
30
+ auth('gmail.labels'),
31
+ auth('gmail.send'),
32
+ auth('gmail.compose'),
33
+ auth('gmail.insert'),
34
+ auth('gmail.modify'),
35
+ auth('gmail.settings.basic'),
36
+ // Not `gmail.settings.sharing`: Google grants it only to service accounts
37
+ // with domain-wide delegation, so the sendAs/forwarding methods that
38
+ // accept nothing else cannot be authorized by a user's OAuth consent.
39
+ 'https://mail.google.com/',
40
+ ],
41
+ // compose covers drafts.create AND messages.send, so it is the single write
42
+ // scope for the hand-written create_draft/reply/send_email. It must be
43
+ // granted at connect: an upgrade is requested only when a caller asks.
44
+ connectScopes: [auth('gmail.readonly'), auth('gmail.compose')],
45
+ // Delegation grants another account full mailbox access.
46
+ blockedPrefixes: ['gmail.users.settings.delegates.'],
47
+ // Permanent, bypassing the trash (`trash`/`untrash` are reversible).
48
+ destructiveMethods: ['gmail.users.messages.batchDelete'],
49
+ defaults: { userId: 'me' },
50
+ },
51
+ drive_v3: {
52
+ scopeLadder: [auth('drive.readonly'), auth('drive.file'), auth('drive')],
53
+ blockedPrefixes: ['drive.apps.'],
54
+ readMethods: ['drive.files.download'],
55
+ // Without these, a file in a shared drive answers 404 and lists omit it.
56
+ defaults: { supportsAllDrives: true, includeItemsFromAllDrives: true },
57
+ },
58
+ sheets_v4: {
59
+ scopeLadder: [auth('spreadsheets.readonly'), auth('spreadsheets')],
60
+ readMethods: [
61
+ 'sheets.spreadsheets.getByDataFilter',
62
+ 'sheets.spreadsheets.values.batchGetByDataFilter',
63
+ 'sheets.spreadsheets.developerMetadata.search',
64
+ ],
65
+ destructiveMethods: [
66
+ 'sheets.spreadsheets.values.clear',
67
+ 'sheets.spreadsheets.values.batchClear',
68
+ 'sheets.spreadsheets.values.batchClearByDataFilter',
69
+ ],
70
+ },
71
+ docs_v1: {
72
+ scopeLadder: [auth('documents.readonly'), auth('documents')],
73
+ },
74
+ people_v1: {
75
+ scopeLadder: [
76
+ auth('contacts.readonly'),
77
+ auth('contacts.other.readonly'),
78
+ auth('directory.readonly'),
79
+ auth('contacts'),
80
+ ],
81
+ destructiveMethods: ['people.people.batchDeleteContacts'],
82
+ },
83
+ tasks_v1: {
84
+ scopeLadder: [auth('tasks.readonly'), auth('tasks')],
85
+ defaults: { tasklist: '@default' },
86
+ },
87
+ youtube_v3: {
88
+ scopeLadder: [
89
+ auth('youtube.readonly'),
90
+ auth('youtube.upload'),
91
+ auth('youtube'),
92
+ auth('youtube.force-ssl'),
93
+ ],
94
+ blockedMethods: ['youtube.abuseReports.insert', 'youtube.tests.insert'],
95
+ blockedPrefixes: ['youtube.thirdPartyLinks.'],
96
+ },
97
+ // User-authorized Chat only. Methods that accept nothing but app (`chat.app.*`,
98
+ // `chat.bot`) or admin (`chat.admin.*`) scopes fall outside the ladder.
99
+ chat_v1: {
100
+ scopeLadder: [
101
+ 'spaces.readonly',
102
+ 'memberships.readonly',
103
+ 'messages.readonly',
104
+ 'messages.reactions.readonly',
105
+ 'customemojis.readonly',
106
+ 'spaces.pins.readonly',
107
+ 'users.readstate.readonly',
108
+ 'users.sections.readonly',
109
+ 'users.availability.readonly',
110
+ 'messages.create',
111
+ 'messages.reactions.create',
112
+ 'spaces.create',
113
+ 'messages',
114
+ 'messages.reactions',
115
+ 'memberships',
116
+ 'spaces',
117
+ 'customemojis',
118
+ 'spaces.pins',
119
+ 'users.readstate',
120
+ 'users.spacesettings',
121
+ 'users.sections',
122
+ 'users.availability',
123
+ 'delete',
124
+ ].map((scope) => auth(`chat.${scope}`)),
125
+ blockedMethods: ['chat.spaces.completeImport'],
126
+ },
127
+ };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Login-only AgentID declaration, consumed by the gateway's genericOAuth path.
3
+ * It declares no feeds or device runtime. Owner claims are not mapped into
4
+ * Lobu's user profile; these scopes identify the agent without requesting the
5
+ * human owner's name or email. See https://www.agentid.com/docs/custom.
6
+ */
7
+
8
+ import {
9
+ type ConnectorDefinition,
10
+ IntegrationConnector,
11
+ } from "@lobu/connector-sdk";
12
+
13
+ export default class AgentIdConnector extends IntegrationConnector {
14
+ readonly definition: ConnectorDefinition = {
15
+ key: "agentid",
16
+ kind: "integration",
17
+ name: "AgentID",
18
+ description:
19
+ "Sign in with AgentID to create or access your Lobu account using your agent's verified identity.",
20
+ version: "1.0.0",
21
+ faviconDomain: "agentid.com",
22
+ authSchema: {
23
+ methods: [
24
+ {
25
+ type: "oauth",
26
+ provider: "agentid",
27
+ loginScopes: ["openid", "email", "profile"],
28
+ requiredScopes: [],
29
+ authorizationUrl: "https://auth.agentid.com/v0/authorize",
30
+ tokenUrl: "https://auth.agentid.com/v0/token",
31
+ userinfoUrl: "https://auth.agentid.com/v0/userinfo",
32
+ clientIdKey: "AGENTID_CLIENT_ID",
33
+ clientSecretKey: "AGENTID_CLIENT_SECRET",
34
+ tokenEndpointAuthMethod: "client_secret_basic",
35
+ usePkce: true,
36
+ required: false,
37
+ description:
38
+ "Sign in with AgentID to create or access your Lobu account using your agent's verified identity.",
39
+ },
40
+ ],
41
+ },
42
+ };
43
+ }
@@ -37,7 +37,8 @@ export interface ChatUserIdentity {
37
37
  /**
38
38
  * The Better Auth `providerId` whose sign-in PROVES this identity. The login
39
39
  * writer stamps the namespace only after a successful OAuth exchange with
40
- * this provider; nothing else may mint the link.
40
+ * this provider. Other trusted chat-link flows must also prove control of
41
+ * this account before writing the namespace.
41
42
  */
42
43
  providerId: string;
43
44
  /** `entity_identities` namespace the key is stored under. */
@@ -50,6 +50,15 @@ export const GITHUB_AUTOMATION_EVENTS: ConnectorAutomationEvent[] = [
50
50
  },
51
51
  }),
52
52
  ),
53
+ {
54
+ key: "stargazer",
55
+ label: "A repository is starred",
56
+ description:
57
+ "Runs for each new star on a tracked repository, recorded live from the star webhook or by the stargazers poll, whichever sees it first.",
58
+ // Derived record signals carry resource_type = the event kind.
59
+ resourceType: "stargazer",
60
+ defaults: { execution: "turn", activeRun: "queue", output: "silent" },
61
+ },
53
62
  {
54
63
  key: "commits.updated",
55
64
  label: "Repository commits change",
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * GitHub connector identity namespaces and normalization.
3
3
  *
4
- * Single source of truth for github_login / github_user_id / github_repo_* rules.
5
- * The connector, app-webhook actor resolution, repo ACL graph, and server
6
- * entity-link ingestion all import from here — not from connector-sdk.
4
+ * Single source of truth for github_login / github_user_id / github_repo_* rules
5
+ * and the connection's token precedence. The connector, app-webhook actor
6
+ * resolution, repo ACL graph and sync, and server entity-link ingestion all
7
+ * import from here — not from connector-sdk.
7
8
  */
8
9
 
9
10
  import type {
@@ -72,6 +73,30 @@ export function normalizeGithubIdentityValue(
72
73
  }
73
74
  }
74
75
 
76
+ function nonEmptyString(value: unknown): string | undefined {
77
+ return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
78
+ }
79
+
80
+ /**
81
+ * The token a GitHub connection authorizes: the resolved OAuth / App access
82
+ * token first, then a configured `GITHUB_TOKEN` PAT. The connector runtime and
83
+ * the server's repo ACL sync both resolve through this, so they spend the same
84
+ * authority.
85
+ */
86
+ export function resolveGithubToken(
87
+ accessToken: string | undefined,
88
+ config: { env_overrides?: Record<string, unknown> },
89
+ ): string | null {
90
+ const fields = config as Record<string, unknown>;
91
+ return (
92
+ nonEmptyString(accessToken) ??
93
+ nonEmptyString(config.env_overrides?.GITHUB_TOKEN) ??
94
+ nonEmptyString(fields.GITHUB_TOKEN) ??
95
+ nonEmptyString(fields.github_token) ??
96
+ null
97
+ );
98
+ }
99
+
75
100
  /** Stable `github_user_id:ID` / `github_login:login` key used by poll + webhooks. */
76
101
  export function githubUserIdentityKey(params: {
77
102
  userId?: string | number | null;