@lobu/runtime-device 20.1.0 → 21.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 (121) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +46 -40
  3. package/npm-shrinkwrap.json +283 -237
  4. package/package.json +1 -1
  5. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.d.ts +7 -2
  6. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +77 -75
  7. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +40 -25
  8. package/vendor/cli/dist/commands/_lib/apply/client.js +31 -39
  9. package/vendor/cli/dist/commands/_lib/apply/deployment.d.ts +1 -1
  10. package/vendor/cli/dist/commands/_lib/apply/deployment.js +2 -2
  11. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +47 -11
  12. package/vendor/cli/dist/commands/_lib/apply/desired-state.js +106 -7
  13. package/vendor/cli/dist/commands/_lib/apply/diff.d.ts +14 -6
  14. package/vendor/cli/dist/commands/_lib/apply/diff.js +42 -23
  15. package/vendor/cli/dist/commands/_lib/apply/map-config.js +2 -3
  16. package/vendor/cli/dist/commands/_lib/apply/render.js +2 -0
  17. package/vendor/cli/dist/commands/_lib/apply/rollback-cmd.js +3 -3
  18. package/vendor/cli/dist/commands/_lib/connector-loader.d.ts +5 -1
  19. package/vendor/cli/dist/commands/_lib/connector-loader.js +1 -1
  20. package/vendor/cli/dist/commands/_lib/ensure-deps-installed.d.ts +15 -26
  21. package/vendor/cli/dist/commands/_lib/ensure-deps-installed.js +227 -136
  22. package/vendor/cli/dist/commands/_lib/view-bundler.d.ts +33 -0
  23. package/vendor/cli/dist/commands/_lib/view-bundler.js +207 -0
  24. package/vendor/cli/dist/commands/_lib/view-reapply.d.ts +60 -0
  25. package/vendor/cli/dist/commands/_lib/view-reapply.js +182 -0
  26. package/vendor/cli/dist/commands/dev.d.ts +14 -5
  27. package/vendor/cli/dist/commands/dev.js +56 -8
  28. package/vendor/cli/dist/commands/init.d.ts +1 -1
  29. package/vendor/cli/dist/commands/init.js +4 -4
  30. package/vendor/cli/dist/commands/login.js +3 -0
  31. package/vendor/cli/dist/config/define.d.ts +25 -8
  32. package/vendor/cli/dist/config/define.js +24 -0
  33. package/vendor/cli/dist/connectors/README.md +15 -16
  34. package/vendor/cli/dist/connectors/chat-user-identity.ts +41 -0
  35. package/vendor/cli/dist/connectors/github.ts +15 -9
  36. package/vendor/cli/dist/connectors/google-identity.ts +11 -0
  37. package/vendor/cli/dist/connectors/google_calendar.ts +21 -31
  38. package/vendor/cli/dist/connectors/google_drive.ts +106 -131
  39. package/vendor/cli/dist/connectors/google_gmail.ts +53 -30
  40. package/vendor/cli/dist/connectors/hackernews.ts +2 -5
  41. package/vendor/cli/dist/connectors/jira.ts +62 -27
  42. package/vendor/cli/dist/connectors/linear.ts +55 -21
  43. package/vendor/cli/dist/connectors/microsoft_outlook.ts +151 -110
  44. package/vendor/cli/dist/connectors/postgres.ts +19 -11
  45. package/vendor/cli/dist/connectors/producthunt.ts +8 -6
  46. package/vendor/cli/dist/connectors/reddit.ts +2 -2
  47. package/vendor/cli/dist/connectors/rss.ts +2 -2
  48. package/vendor/cli/dist/connectors/slack-identity.ts +19 -0
  49. package/vendor/cli/dist/connectors/whatsapp_web.ts +5 -4
  50. package/vendor/cli/dist/connectors/x.ts +32 -17
  51. package/vendor/cli/dist/connectors/youtube.ts +18 -5
  52. package/vendor/cli/dist/internal/connector-compiler.d.ts +1 -1
  53. package/vendor/cli/dist/internal/connector-compiler.js +216 -17
  54. package/vendor/cli/dist/internal/credentials.js +5 -1
  55. package/vendor/cli/dist/internal/oauth.d.ts +15 -1
  56. package/vendor/cli/dist/internal/oauth.js +9 -1
  57. package/vendor/cli/dist/runtime-components.json +4 -4
  58. package/vendor/cli/package.json +2 -1
  59. package/vendor/connector-sdk/dist/connector-runtime.d.ts +4 -6
  60. package/vendor/connector-sdk/dist/connector-runtime.js +3 -5
  61. package/vendor/connector-sdk/dist/connector-types.d.ts +28 -13
  62. package/vendor/connector-sdk/dist/define-connector.d.ts +4 -1
  63. package/vendor/connector-sdk/dist/define-connector.js +4 -1
  64. package/vendor/connector-sdk/dist/http-client.d.ts +18 -7
  65. package/vendor/connector-sdk/dist/http-client.js +15 -13
  66. package/vendor/connector-sdk/dist/index.d.ts +1 -1
  67. package/vendor/connector-sdk/dist/retry.d.ts +15 -3
  68. package/vendor/connector-sdk/dist/retry.js +40 -64
  69. package/vendor/connector-sdk/package.json +1 -1
  70. package/vendor/connector-worker/dist/agent-turn/guest-entry.js +122 -10
  71. package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +78 -10
  72. package/vendor/connector-worker/dist/agent-turn/types.d.ts +34 -4
  73. package/vendor/connector-worker/dist/compile/index.d.ts +21 -2
  74. package/vendor/connector-worker/dist/compile/index.js +41 -8
  75. package/vendor/connector-worker/dist/compile/source-capture.d.ts +10 -0
  76. package/vendor/connector-worker/dist/compile/source-capture.js +108 -0
  77. package/vendor/connector-worker/dist/daemon/agent-turn.js +97 -10
  78. package/vendor/connector-worker/dist/daemon/automation-process.d.ts +32 -0
  79. package/vendor/connector-worker/dist/daemon/automation-process.js +102 -1
  80. package/vendor/connector-worker/dist/daemon/automation.d.ts +1 -1
  81. package/vendor/connector-worker/dist/daemon/builtins/index.js +8 -0
  82. package/vendor/connector-worker/dist/daemon/builtins/os-shell.d.ts +13 -1
  83. package/vendor/connector-worker/dist/daemon/builtins/os-shell.js +28 -2
  84. package/vendor/connector-worker/dist/daemon/executor.d.ts +0 -1
  85. package/vendor/connector-worker/dist/daemon/executor.js +42 -51
  86. package/vendor/connector-worker/dist/daemon/start.js +5 -1
  87. package/vendor/connector-worker/dist/executor/interface.d.ts +12 -8
  88. package/vendor/connector-worker/dist/executor/isolate.js +45 -28
  89. package/vendor/connector-worker/dist/self-check/index.js +15 -13
  90. package/vendor/connector-worker/package.json +1 -1
  91. package/vendor/core/dist/agent-policy.js +3 -0
  92. package/vendor/core/dist/connector-query-errors.d.ts +3 -3
  93. package/vendor/core/dist/connector-query-errors.js +8 -3
  94. package/vendor/core/dist/contracts/tools/manage-connections.d.ts +24 -0
  95. package/vendor/core/dist/contracts/tools/manage-connections.js +13 -0
  96. package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +15 -25
  97. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +3 -5
  98. package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +11 -0
  99. package/vendor/core/dist/contracts/tools/manage-feeds.js +12 -1
  100. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +47 -6
  101. package/vendor/core/dist/contracts/tools/manage-operations.js +36 -1
  102. package/vendor/core/dist/contracts/tools/manage-views.d.ts +293 -0
  103. package/vendor/core/dist/contracts/tools/manage-views.js +203 -0
  104. package/vendor/core/dist/contracts/tools/source-files-schema.d.ts +7 -0
  105. package/vendor/core/dist/contracts/tools/source-files-schema.js +19 -0
  106. package/vendor/core/dist/contracts/tools/source-files.d.ts +14 -0
  107. package/vendor/core/dist/contracts/tools/source-files.js +55 -0
  108. package/vendor/core/dist/contracts/tools/view-content-hash.d.ts +37 -0
  109. package/vendor/core/dist/contracts/tools/view-content-hash.js +58 -0
  110. package/vendor/core/dist/contracts/tools/view-path.d.ts +18 -0
  111. package/vendor/core/dist/contracts/tools/view-path.js +24 -0
  112. package/vendor/core/dist/contracts/worker/protocol.d.ts +73 -8
  113. package/vendor/core/dist/contracts/worker/protocol.js +58 -9
  114. package/vendor/core/dist/credentials.d.ts +16 -1
  115. package/vendor/core/dist/credentials.js +10 -1
  116. package/vendor/core/dist/reserved.d.ts +3 -3
  117. package/vendor/core/dist/reserved.js +9 -1
  118. package/vendor/core/dist/utils/secret-redaction.js +2 -0
  119. package/vendor/core/package.json +25 -5
  120. package/vendor/core/dist/contracts/tools/manage-view-templates.d.ts +0 -165
  121. package/vendor/core/dist/contracts/tools/manage-view-templates.js +0 -130
@@ -31,6 +31,13 @@ import {
31
31
  type SyncResult,
32
32
  } from '@lobu/connector-sdk';
33
33
 
34
+ /** What one YouTube sync gathers before it is committed. */
35
+ type YouTubeSyncPage = {
36
+ events: EventEnvelope[];
37
+ checkpoint: Record<string, unknown>;
38
+ metadata?: SyncResult['metadata'];
39
+ };
40
+
34
41
  // ---------------------------------------------------------------------------
35
42
  // YouTube API types
36
43
  // ---------------------------------------------------------------------------
@@ -613,6 +620,12 @@ export default class YouTubeConnector extends ConnectorRuntime {
613
620
  // -------------------------------------------------------------------------
614
621
 
615
622
  private async syncFeed(ctx: SyncContext): Promise<SyncResult> {
623
+ const page = await this.collectFeed(ctx);
624
+ await ctx.commit(page.events, page.checkpoint);
625
+ return { status: 'complete', ...(page.metadata ? { metadata: page.metadata } : {}) };
626
+ }
627
+
628
+ private async collectFeed(ctx: SyncContext): Promise<YouTubeSyncPage> {
616
629
  const auth = this.resolveAuth(ctx);
617
630
 
618
631
  switch (ctx.feedKey) {
@@ -800,7 +813,7 @@ export default class YouTubeConnector extends ConnectorRuntime {
800
813
  // Feed: liked_videos
801
814
  // -------------------------------------------------------------------------
802
815
 
803
- private async syncLikedVideos(ctx: SyncContext, auth: YouTubeAuth): Promise<SyncResult> {
816
+ private async syncLikedVideos(ctx: SyncContext, auth: YouTubeAuth): Promise<YouTubeSyncPage> {
804
817
  this.requireOAuth(auth, 'liked_videos');
805
818
  const maxResults = Math.min(Math.max((ctx.config.max_results as number) ?? 500, 1), 5000);
806
819
  const likesPlaylistId = await this.fetchLikesPlaylistId(auth);
@@ -820,7 +833,7 @@ export default class YouTubeConnector extends ConnectorRuntime {
820
833
  // Feed: playlists
821
834
  // -------------------------------------------------------------------------
822
835
 
823
- private async syncPlaylists(ctx: SyncContext, auth: YouTubeAuth): Promise<SyncResult> {
836
+ private async syncPlaylists(ctx: SyncContext, auth: YouTubeAuth): Promise<YouTubeSyncPage> {
824
837
  this.requireOAuth(auth, 'playlists');
825
838
  const maxPlaylists = Math.min(Math.max((ctx.config.max_playlists as number) ?? 100, 1), 500);
826
839
  const includeItems = (ctx.config.include_items as boolean) ?? true;
@@ -894,7 +907,7 @@ export default class YouTubeConnector extends ConnectorRuntime {
894
907
  // Feed: subscriptions
895
908
  // -------------------------------------------------------------------------
896
909
 
897
- private async syncSubscriptions(ctx: SyncContext, auth: YouTubeAuth): Promise<SyncResult> {
910
+ private async syncSubscriptions(ctx: SyncContext, auth: YouTubeAuth): Promise<YouTubeSyncPage> {
898
911
  this.requireOAuth(auth, 'subscriptions');
899
912
  const maxResults = Math.min(Math.max((ctx.config.max_results as number) ?? 1000, 1), 5000);
900
913
  const events: EventEnvelope[] = [];
@@ -964,7 +977,7 @@ export default class YouTubeConnector extends ConnectorRuntime {
964
977
  // Feed: videos (keyword search)
965
978
  // -------------------------------------------------------------------------
966
979
 
967
- private async syncSearchVideos(ctx: SyncContext, auth: YouTubeAuth): Promise<SyncResult> {
980
+ private async syncSearchVideos(ctx: SyncContext, auth: YouTubeAuth): Promise<YouTubeSyncPage> {
968
981
  const searchQuery = ctx.config.search_query as string;
969
982
  if (!searchQuery) {
970
983
  throw new Error('search_query is required.');
@@ -1250,7 +1263,7 @@ export default class YouTubeConnector extends ConnectorRuntime {
1250
1263
  return events;
1251
1264
  }
1252
1265
 
1253
- private buildListCheckpointResult(events: EventEnvelope[]): SyncResult {
1266
+ private buildListCheckpointResult(events: EventEnvelope[]): YouTubeSyncPage {
1254
1267
  events.sort((a, b) => b.occurred_at.getTime() - a.occurred_at.getTime());
1255
1268
  const latest = events.length > 0 ? events[0].occurred_at.toISOString() : undefined;
1256
1269
  return {
@@ -1,2 +1,2 @@
1
- export { createIsolateConnectorCompiler, findBundledConnectorFile, } from "@lobu/connector-worker/compile";
1
+ export { createIsolateConnectorCompiler, createSourceCapture, findBundledConnectorFile, } from "@lobu/connector-worker/compile";
2
2
  //# sourceMappingURL=connector-compiler.d.ts.map
@@ -1,9 +1,84 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ try {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ } catch (e) {
11
+ throw mod = 0, e;
12
+ }
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+
31
+ // packages/core/dist/contracts/tools/source-files.js
32
+ var require_source_files = __commonJS({
33
+ "packages/core/dist/contracts/tools/source-files.js"(exports) {
34
+ "use strict";
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.SOURCE_MAX_FILES = exports.SOURCE_MAX_BYTES = void 0;
37
+ exports.assertSourcePath = assertSourcePath2;
38
+ exports.validateRetainedSource = validateRetainedSource2;
39
+ exports.SOURCE_MAX_BYTES = 1e6;
40
+ exports.SOURCE_MAX_FILES = 128;
41
+ function assertSourcePath2(path) {
42
+ const parts = path.split("/");
43
+ if (!path || path.length > 240 || /[\\:%]/.test(path) || path.includes("\0") || parts.some((part) => !part || part === "." || part === ".." || part === "node_modules" || part === ".git" || part === ".lobu" || part === ".npmrc" || part.startsWith(".env"))) {
44
+ throw new Error(`Source path must be a portable project file: ${path}`);
45
+ }
46
+ }
47
+ function validateRetainedSource2(sourceCode, sourceFiles, dependencies) {
48
+ assertSourcePath2(sourceFiles.entrypoint);
49
+ const files = Object.entries(sourceFiles.files);
50
+ if (files.length === 0 || files.length > exports.SOURCE_MAX_FILES) {
51
+ throw new Error(`Source must contain between 1 and ${exports.SOURCE_MAX_FILES} files`);
52
+ }
53
+ for (const [path, contents] of files) {
54
+ assertSourcePath2(path);
55
+ if (typeof contents !== "string")
56
+ throw new Error(`Source file must be text: ${path}`);
57
+ }
58
+ if (!Object.keys(sourceFiles.files).includes(sourceFiles.entrypoint) || sourceFiles.files[sourceFiles.entrypoint] !== sourceCode) {
59
+ throw new Error("Source entrypoint must match source_code exactly");
60
+ }
61
+ const packages = Object.entries(dependencies);
62
+ if (packages.length > exports.SOURCE_MAX_FILES)
63
+ throw new Error("Too many source dependencies");
64
+ for (const [name, version] of packages) {
65
+ if (!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(name) || !/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(version)) {
66
+ throw new Error(`Source dependency requires a package name and exact version: ${name}`);
67
+ }
68
+ }
69
+ if (new TextEncoder().encode(JSON.stringify({ sourceFiles, dependencies })).length > exports.SOURCE_MAX_BYTES) {
70
+ throw new Error(`Source files exceed ${exports.SOURCE_MAX_BYTES} bytes`);
71
+ }
72
+ }
73
+ }
74
+ });
75
+
1
76
  // packages/connector-worker/dist/compile/index.js
2
77
  import { existsSync } from "node:fs";
3
78
  import { mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
4
79
  import { createRequire } from "node:module";
5
80
  import { tmpdir } from "node:os";
6
- import { join, resolve } from "node:path";
81
+ import { join as join2, resolve as resolve2 } from "node:path";
7
82
  import { build } from "esbuild";
8
83
 
9
84
  // packages/connector-worker/dist/isolate/eligibility.js
@@ -44,6 +119,103 @@ function computeCompileConfigHash(external) {
44
119
  }
45
120
  var COMPILE_CONFIG_HASH = computeCompileConfigHash(EXTERNAL_RUNTIME_DEPS);
46
121
 
122
+ // packages/connector-worker/dist/compile/source-capture.js
123
+ var import_source_files = __toESM(require_source_files(), 1);
124
+ import { readFileSync, realpathSync } from "node:fs";
125
+ import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
126
+ function within(root, file) {
127
+ const path = relative(root, file);
128
+ return path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path);
129
+ }
130
+ function packageAt(file) {
131
+ let root = dirname(file);
132
+ for (; ; ) {
133
+ try {
134
+ const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
135
+ if (typeof pkg.name === "string" && typeof pkg.version === "string") {
136
+ return { root, name: pkg.name, version: pkg.version };
137
+ }
138
+ } catch {
139
+ }
140
+ const parent = dirname(root);
141
+ if (parent === root)
142
+ return null;
143
+ root = parent;
144
+ }
145
+ }
146
+ function createSourceCapture(entry, projectRoot) {
147
+ const root = realpathSync(projectRoot);
148
+ const entrypoint = relative(root, realpathSync(entry)).split(sep).join("/");
149
+ (0, import_source_files.assertSourcePath)(entrypoint);
150
+ const files = /* @__PURE__ */ Object.create(null);
151
+ const dependencies = /* @__PURE__ */ Object.create(null);
152
+ const packageRoots = /* @__PURE__ */ new Set();
153
+ const resolving = /* @__PURE__ */ Symbol("source-capture-resolve");
154
+ const isDependency = (file) => [...packageRoots].some((base) => within(base, file));
155
+ const isProjectFile = (file) => within(root, file) && !isDependency(file);
156
+ const source = () => {
157
+ const sourceFiles = { entrypoint, files: { ...files } };
158
+ (0, import_source_files.validateRetainedSource)(files[entrypoint] ?? "", sourceFiles, dependencies);
159
+ return { sourceFiles, dependencies: { ...dependencies } };
160
+ };
161
+ const plugin = {
162
+ name: "retain-project-source",
163
+ setup(build2) {
164
+ build2.onResolve({ filter: /.*/ }, async (args) => {
165
+ if (args.pluginData?.[resolving])
166
+ return;
167
+ const found = await build2.resolve(args.path, {
168
+ importer: args.importer,
169
+ resolveDir: args.resolveDir,
170
+ kind: args.kind,
171
+ namespace: args.namespace,
172
+ pluginData: { ...args.pluginData, [resolving]: true }
173
+ });
174
+ if (found.pluginData?.[resolving]) {
175
+ found.pluginData = { ...found.pluginData };
176
+ delete found.pluginData[resolving];
177
+ }
178
+ if (found.errors.length || found.external || found.namespace !== "file")
179
+ return found;
180
+ const file = realpathSync(found.path);
181
+ const fromProject = !args.importer || isProjectFile(args.importer);
182
+ const bare = !isAbsolute(args.path) && !args.path.startsWith(".");
183
+ if (bare) {
184
+ const pkg = packageAt(file);
185
+ if (pkg && pkg.root !== root) {
186
+ packageRoots.add(pkg.root);
187
+ if (fromProject) {
188
+ if (dependencies[pkg.name] && dependencies[pkg.name] !== pkg.version) {
189
+ throw new Error(`Conflicting source dependency versions: ${pkg.name}`);
190
+ }
191
+ dependencies[pkg.name] = pkg.version;
192
+ }
193
+ }
194
+ } else if (fromProject && !within(root, file)) {
195
+ throw new Error(`Source import leaves the project: ${args.path}`);
196
+ }
197
+ return found;
198
+ });
199
+ build2.onLoad({ filter: /.*/, namespace: "file" }, (args) => {
200
+ const file = realpathSync(args.path);
201
+ if (isDependency(file))
202
+ return;
203
+ if (!within(root, file))
204
+ throw new Error("Source file leaves the project");
205
+ const path = relative(root, file).split(sep).join("/");
206
+ (0, import_source_files.assertSourcePath)(path);
207
+ const contents = files[path] ?? readFileSync(file, "utf8");
208
+ files[path] = contents;
209
+ if (Buffer.byteLength(JSON.stringify(files), "utf8") > import_source_files.SOURCE_MAX_BYTES) {
210
+ throw new Error(`Source files exceed ${import_source_files.SOURCE_MAX_BYTES} bytes`);
211
+ }
212
+ return { contents, loader: "default", resolveDir: dirname(resolve(file)) };
213
+ });
214
+ }
215
+ };
216
+ return { plugin, source };
217
+ }
218
+
47
219
  // packages/connector-worker/dist/compile/index.js
48
220
  var CONNECTOR_KEY_RE = /^[a-z][a-z0-9]*(?:[._][a-z0-9]+)*$/;
49
221
  function findBundledConnectorFile(key, candidateDirs) {
@@ -55,7 +227,7 @@ function findBundledConnectorFile(key, candidateDirs) {
55
227
  ];
56
228
  for (const dir of candidateDirs) {
57
229
  for (const fileName of candidates) {
58
- const filePath = resolve(dir, fileName);
230
+ const filePath = resolve2(dir, fileName);
59
231
  if (!filePath.startsWith(`${dir}/`))
60
232
  continue;
61
233
  if (existsSync(filePath))
@@ -76,6 +248,10 @@ var ISOLATE_LANE_BUILD_OPTIONS = {
76
248
  supported: { "dynamic-import": false },
77
249
  external: []
78
250
  };
251
+ var RETAINED_SOURCE_BUILD_OPTIONS = {
252
+ minify: true,
253
+ legalComments: "none"
254
+ };
79
255
  function createNpmSpecifierPlugin(options) {
80
256
  return {
81
257
  name: "npm-specifier",
@@ -120,10 +296,10 @@ function resolveSdkFile(specifier) {
120
296
  if (!subpath)
121
297
  return root;
122
298
  const candidates = [
123
- join(rootDir, "dist", `${subpath}.js`),
124
- join(rootDir, "dist", `${subpath}/index.js`),
125
- join(rootDir, "src", `${subpath}.ts`),
126
- join(rootDir, "src", `${subpath}/index.ts`)
299
+ join2(rootDir, "dist", `${subpath}.js`),
300
+ join2(rootDir, "dist", `${subpath}/index.js`),
301
+ join2(rootDir, "src", `${subpath}.ts`),
302
+ join2(rootDir, "src", `${subpath}/index.ts`)
127
303
  ];
128
304
  for (const cand of candidates) {
129
305
  if (existsSync(cand))
@@ -196,12 +372,12 @@ function createIsolateConnectorCompiler(options) {
196
372
  cache.delete(oldest);
197
373
  }
198
374
  }
199
- async function bundleConnectorForIsolate(filePath) {
375
+ async function bundleConnectorForIsolate(filePath, capture) {
200
376
  let mtimeMs = null;
201
377
  try {
202
378
  mtimeMs = (await stat(filePath)).mtimeMs;
203
379
  const cached = cache.get(filePath);
204
- if (cached && cached.mtimeMs === mtimeMs) {
380
+ if (!capture && cached && cached.mtimeMs === mtimeMs) {
205
381
  touch(filePath, cached);
206
382
  return cached.bundle;
207
383
  }
@@ -214,16 +390,17 @@ function createIsolateConnectorCompiler(options) {
214
390
  write: false,
215
391
  metafile: true,
216
392
  minify: false,
393
+ ...capture && RETAINED_SOURCE_BUILD_OPTIONS,
217
394
  sourcemap: false,
218
395
  logLevel: "silent",
219
- plugins
396
+ plugins: capture ? [capture.plugin, ...plugins] : plugins
220
397
  });
221
398
  const code = result.outputFiles[0]?.text ?? "";
222
399
  const bundle = {
223
400
  code,
224
401
  builtins: builtinsFromMetafile(result.metafile)
225
402
  };
226
- if (mtimeMs !== null)
403
+ if (!capture && mtimeMs !== null)
227
404
  touch(filePath, { mtimeMs, bundle });
228
405
  return bundle;
229
406
  }
@@ -233,11 +410,19 @@ function createIsolateConnectorCompiler(options) {
233
410
  throw new IsolateLaneIneligibleError(bundle.builtins, filePath);
234
411
  return bundle.code;
235
412
  }
236
- async function bundleConnectorForIsolateFromSource(sourceCode) {
237
- const tmpDir = await mkdtemp(join(tmpdir(), "lobu-connector-isolate-"));
238
- const sourcePath = join(tmpDir, "source.ts");
413
+ async function compileConnectorArtifactFromFile(filePath, projectRoot) {
414
+ const capture = createSourceCapture(filePath, projectRoot);
415
+ const bundle = await bundleConnectorForIsolate(filePath, capture);
416
+ if (bundle.builtins.length > 0)
417
+ throw new IsolateLaneIneligibleError(bundle.builtins, filePath);
418
+ return { compiledCode: bundle.code, ...capture.source() };
419
+ }
420
+ async function bundleConnectorForIsolateFromSource(sourceCode, retainSource = false, portableOutput = retainSource) {
421
+ const tmpDir = await mkdtemp(join2(tmpdir(), "lobu-connector-isolate-"));
422
+ const sourcePath = join2(tmpDir, "source.ts");
239
423
  try {
240
424
  await writeFile(sourcePath, sourceCode, "utf-8");
425
+ const capture = retainSource ? createSourceCapture(sourcePath, tmpDir) : void 0;
241
426
  const result = await build({
242
427
  ...ISOLATE_LANE_BUILD_OPTIONS,
243
428
  entryPoints: [sourcePath],
@@ -245,33 +430,47 @@ function createIsolateConnectorCompiler(options) {
245
430
  write: false,
246
431
  metafile: true,
247
432
  minify: false,
433
+ ...portableOutput && RETAINED_SOURCE_BUILD_OPTIONS,
434
+ // Uploaded artifacts already have portable identifiers. Renaming them
435
+ // again changes their hash on every normalization pass.
436
+ ...portableOutput && !retainSource && { minify: false, minifyWhitespace: true, minifySyntax: true },
248
437
  sourcemap: false,
249
438
  logLevel: "silent",
250
- nodePaths: [resolve(process.cwd(), "node_modules")],
251
- plugins
439
+ nodePaths: [resolve2(process.cwd(), "node_modules")],
440
+ plugins: [...capture ? [capture.plugin] : [], ...plugins]
252
441
  });
253
442
  const code = result.outputFiles[0]?.text ?? "";
254
443
  return {
255
444
  code,
445
+ ...capture?.source() ?? {},
256
446
  builtins: builtinsFromMetafile(result.metafile)
257
447
  };
258
448
  } finally {
259
449
  await rm(tmpDir, { recursive: true, force: true });
260
450
  }
261
451
  }
262
- async function compileConnectorForIsolateFromSource(sourceCode) {
263
- const bundle = await bundleConnectorForIsolateFromSource(sourceCode);
452
+ async function compileConnectorArtifactFromSource(sourceCode) {
453
+ const bundle = await bundleConnectorForIsolateFromSource(sourceCode, true);
454
+ if (bundle.builtins.length > 0)
455
+ throw new IsolateLaneIneligibleError(bundle.builtins, "<source>");
456
+ return { compiledCode: bundle.code, sourceFiles: bundle.sourceFiles, dependencies: bundle.dependencies };
457
+ }
458
+ async function compileConnectorForIsolateFromSource(sourceCode, portableOutput = false) {
459
+ const bundle = await bundleConnectorForIsolateFromSource(sourceCode, false, portableOutput);
264
460
  if (bundle.builtins.length > 0)
265
461
  throw new IsolateLaneIneligibleError(bundle.builtins, "<source>");
266
462
  return bundle.code;
267
463
  }
268
464
  return {
269
465
  bundleConnectorForIsolate,
466
+ compileConnectorArtifactFromFile,
467
+ compileConnectorArtifactFromSource,
270
468
  compileConnectorForIsolateFromFile,
271
469
  compileConnectorForIsolateFromSource
272
470
  };
273
471
  }
274
472
  export {
275
473
  createIsolateConnectorCompiler,
474
+ createSourceCapture,
276
475
  findBundledConnectorFile
277
476
  };
@@ -250,7 +250,11 @@ async function doRefreshCredentials(target, existing) {
250
250
  async function attemptRefresh(target, creds) {
251
251
  if (!credentialCanRefresh(creds))
252
252
  return null;
253
- const refreshed = await refreshTokens(creds.oauth.tokenEndpoint, { clientId: creds.oauth.clientId, clientSecret: creds.oauth.clientSecret }, creds.refreshToken);
253
+ const refreshed = await refreshTokens(creds.oauth.tokenEndpoint, { clientId: creds.oauth.clientId, clientSecret: creds.oauth.clientSecret }, creds.refreshToken,
254
+ // Replay the RFC 8707 indicator the grant was minted with. Without it the
255
+ // issuer rejects a resource-scoped refresh outright (invalid_grant). An
256
+ // unbound grant must send no indicator at all, so pass nothing.
257
+ ...(creds.oauth.resource ? [{ resource: creds.oauth.resource }] : []));
254
258
  if (!refreshed)
255
259
  return null;
256
260
  const updated = {
@@ -34,6 +34,12 @@ interface TokenResponse {
34
34
  accessToken: string;
35
35
  refreshToken?: string;
36
36
  expiresIn?: number;
37
+ /**
38
+ * RFC 8707 resource the issuer bound these tokens to, echoed back on the
39
+ * token response. Persisted with the credential so every later refresh can
40
+ * replay it — a resource-scoped grant refreshed without it is rejected.
41
+ */
42
+ resource?: string;
37
43
  }
38
44
  interface UserInfo {
39
45
  sub: string;
@@ -76,7 +82,15 @@ type DevicePollResult = {
76
82
  * `error` for terminal failures.
77
83
  */
78
84
  export declare function pollDeviceToken(tokenEndpoint: string, client: RegisteredClient, deviceCode: string): Promise<DevicePollResult>;
79
- export declare function refreshTokens(tokenEndpoint: string, client: RegisteredClient, refreshToken: string): Promise<TokenResponse | null>;
85
+ /**
86
+ * RFC 6749 §6 refresh grant. `options.resource` MUST carry the RFC 8707
87
+ * indicator the grant was minted with: the Lobu issuer compares it against the
88
+ * resource stored on the refresh row and answers `invalid_grant` when it is
89
+ * absent or different, so a resource-scoped login cannot be renewed without it.
90
+ */
91
+ export declare function refreshTokens(tokenEndpoint: string, client: RegisteredClient, refreshToken: string, options?: {
92
+ resource?: string;
93
+ }): Promise<TokenResponse | null>;
80
94
  export declare function fetchUserInfo(userinfoEndpoint: string, accessToken: string): Promise<UserInfo | null>;
81
95
  /** RFC 7009 — best-effort. Network failures are intentionally swallowed. */
82
96
  export declare function revokeToken(revocationEndpoint: string, client: RegisteredClient, token: string, hint: "access_token" | "refresh_token"): Promise<void>;
@@ -130,10 +130,17 @@ export async function pollDeviceToken(tokenEndpoint, client, deviceCode) {
130
130
  `Token endpoint returned ${body.status}.`,
131
131
  };
132
132
  }
133
- export async function refreshTokens(tokenEndpoint, client, refreshToken) {
133
+ /**
134
+ * RFC 6749 §6 refresh grant. `options.resource` MUST carry the RFC 8707
135
+ * indicator the grant was minted with: the Lobu issuer compares it against the
136
+ * resource stored on the refresh row and answers `invalid_grant` when it is
137
+ * absent or different, so a resource-scoped login cannot be renewed without it.
138
+ */
139
+ export async function refreshTokens(tokenEndpoint, client, refreshToken, options = {}) {
134
140
  const body = await postJson(tokenEndpoint, withClient(client, {
135
141
  grant_type: GRANT_REFRESH_TOKEN,
136
142
  refresh_token: refreshToken,
143
+ ...(options.resource ? { resource: options.resource } : {}),
137
144
  }));
138
145
  if (!body.ok || typeof body.data.access_token !== "string")
139
146
  return null;
@@ -182,6 +189,7 @@ function parseTokenResponse(data) {
182
189
  accessToken,
183
190
  refreshToken: pickString(data, "refresh_token"),
184
191
  expiresIn: pickNumber(data, "expires_in"),
192
+ resource: pickString(data, "resource"),
185
193
  };
186
194
  }
187
195
  async function postJson(url, body) {
@@ -5,7 +5,7 @@
5
5
  "server": "dist/server.bundle.mjs",
6
6
  "embeddingsServer": "dist/embeddings-server.mjs"
7
7
  },
8
- "version": "20.1.0",
8
+ "version": "21.0.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": "20.1.0",
19
+ "version": "21.0.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": "20.1.0",
27
+ "version": "21.0.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": "20.1.0",
35
+ "version": "21.0.0",
36
36
  "verify": "dist/verify.mjs"
37
37
  }
38
38
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/cli",
3
- "version": "20.1.0",
3
+ "version": "21.0.0",
4
4
  "description": "CLI for deploying and managing AI agents on Lobu",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -45,6 +45,7 @@
45
45
  "ora": "^8.0.1",
46
46
  "postgres": "file:../postgres",
47
47
  "tar": "^7.4.3",
48
+ "tinyglobby": "0.2.16",
48
49
  "yaml": "^2.7.1",
49
50
  "proper-lockfile": "4.1.2",
50
51
  "ajv": "^8.17.1",
@@ -38,15 +38,13 @@ export declare abstract class ConnectorRuntime<C = Record<string, unknown>, F =
38
38
  /**
39
39
  * Sync data from the connected service.
40
40
  *
41
- * Called by the worker when a sync run is executed.
42
- * Should return events to ingest and an updated checkpoint.
43
- * Long-running connectors may optionally use `ctx.emitEvents()` and
44
- * `ctx.updateCheckpoint()` to stream progress before returning.
41
+ * Called by the worker when a sync run is executed. Commit each page of
42
+ * events with its checkpoint through `ctx.commit` as it is fetched, then
43
+ * return how the pass ended.
45
44
  *
46
45
  * @param ctx - Sync context with feed config, checkpoint, and credentials
47
- * @returns Events and updated checkpoint
48
46
  */
49
- sync(ctx: SyncContext<C, F>): Promise<SyncResult<C>>;
47
+ sync(ctx: SyncContext<C, F>): Promise<SyncResult>;
50
48
  /**
51
49
  * Read one configured feed directly from its source. Feed handlers own native
52
50
  * filtering and pagination; the platform never infers semantics from a feed
@@ -36,13 +36,11 @@ export class ConnectorRuntime {
36
36
  /**
37
37
  * Sync data from the connected service.
38
38
  *
39
- * Called by the worker when a sync run is executed.
40
- * Should return events to ingest and an updated checkpoint.
41
- * Long-running connectors may optionally use `ctx.emitEvents()` and
42
- * `ctx.updateCheckpoint()` to stream progress before returning.
39
+ * Called by the worker when a sync run is executed. Commit each page of
40
+ * events with its checkpoint through `ctx.commit` as it is fetched, then
41
+ * return how the pass ended.
43
42
  *
44
43
  * @param ctx - Sync context with feed config, checkpoint, and credentials
45
- * @returns Events and updated checkpoint
46
44
  */
47
45
  async sync(ctx) {
48
46
  const handler = this.definition.feeds?.[ctx.feedKey]?.sync;
@@ -803,10 +803,22 @@ export interface SyncContext<C = Record<string, unknown>, F = Record<string, unk
803
803
  sessionState?: Record<string, unknown> | null;
804
804
  /** App-installation context when this connection is backed by an App install. */
805
805
  installation?: ConnectorInstallationContext;
806
- /** Optional hook for streaming event chunks while sync is in progress */
807
- emitEvents?: (events: EventEnvelope[]) => Promise<void>;
808
- /** Optional hook for persisting progress checkpoints during long syncs */
809
- updateCheckpoint?: (checkpoint: C | null) => Promise<void>;
806
+ /**
807
+ * Durably store `events`, then move the feed's checkpoint to `checkpoint`.
808
+ * The returned promise resolves only after both have committed and rejects
809
+ * (failing the run) on either failure. A large page may be stored in chunks,
810
+ * but its checkpoint moves only with the final chunk, so a failed commit may
811
+ * leave deduplicable events behind but never skips an unstored event. Commit
812
+ * as you go, once per source page, awaiting each call before the next: a run
813
+ * that stops resumes from the last checkpoint that resolved.
814
+ *
815
+ * Pass `null` to store events without moving the checkpoint, and an empty
816
+ * `events` array to record progress over a page that yielded nothing (a
817
+ * continuation token past filtered-out items). The checkpoint is opaque to
818
+ * the platform; the next run receives the last committed one as
819
+ * `ctx.checkpoint`.
820
+ */
821
+ commit: (events: EventEnvelope[], checkpoint: C | null) => Promise<void>;
810
822
  }
811
823
  /**
812
824
  * The credential a run is handed. On the isolate lane `accessToken` is a
@@ -824,15 +836,18 @@ export interface SyncCredentials {
824
836
  scope?: string | null;
825
837
  }
826
838
  /**
827
- * Result from ConnectorRuntime.sync().
828
- *
829
- * Generic parameter `C` matches the connector's checkpoint shape.
839
+ * How a sync pass ended. Its events and checkpoints were already committed
840
+ * through `ctx.commit`; the result only says what should happen next.
830
841
  */
831
- export interface SyncResult<C = Record<string, unknown>> {
832
- /** Events to write to the events table */
833
- events: EventEnvelope[];
834
- /** Updated checkpoint to persist */
835
- checkpoint: C | null;
842
+ export interface SyncResult {
843
+ /**
844
+ * `complete` — the source is caught up; the next run follows the feed's
845
+ * schedule. `more` — the pass stopped early at a committed boundary (a time
846
+ * or size budget) with work remaining, so the platform starts the next run
847
+ * right away instead of waiting for the schedule. `more` is honored only
848
+ * when the run committed a checkpoint.
849
+ */
850
+ status: 'complete' | 'more';
836
851
  /** Updated auth state to persist on the linked auth profile (browser cookies, etc.) */
837
852
  auth_update?: Record<string, unknown> | null;
838
853
  /** Optional metadata about the sync */
@@ -925,7 +940,7 @@ export interface FeedReadResult {
925
940
  /** Required for a windowed read; absence means the reader cannot honor it. */
926
941
  window?: FeedReadWindowCoverage;
927
942
  }
928
- export type FeedSyncHandler<C = Record<string, unknown>, F = Record<string, unknown>> = (ctx: SyncContext<C, F>) => Promise<SyncResult<C>>;
943
+ export type FeedSyncHandler<C = Record<string, unknown>, F = Record<string, unknown>> = (ctx: SyncContext<C, F>) => Promise<SyncResult>;
929
944
  export type FeedReadHandler<F = Record<string, unknown>> = (ctx: FeedReadContext<F>) => Promise<FeedReadResult>;
930
945
  /** Executable feed definition held only inside a connector runtime. */
931
946
  export interface RuntimeFeedDefinition<C = Record<string, unknown>, F = Record<string, unknown>> extends Omit<FeedDefinition, 'operations'> {
@@ -21,7 +21,10 @@
21
21
  * ```ts
22
22
  * export default defineConnector({
23
23
  * key: 'github', name: 'GitHub', version: '1.0.0',
24
- * feeds: { stars: { name: 'Stars', sync: async (ctx) => ({ events, checkpoint }) } },
24
+ * feeds: { stars: { name: 'Stars', sync: async (ctx) => {
25
+ * await ctx.commit(events, checkpoint);
26
+ * return { status: 'complete' };
27
+ * } } },
25
28
  * actions: { star_repo: { name: 'Star', execute: async (ctx) => ({ success: true }) } },
26
29
  * });
27
30
  * ```
@@ -21,7 +21,10 @@
21
21
  * ```ts
22
22
  * export default defineConnector({
23
23
  * key: 'github', name: 'GitHub', version: '1.0.0',
24
- * feeds: { stars: { name: 'Stars', sync: async (ctx) => ({ events, checkpoint }) } },
24
+ * feeds: { stars: { name: 'Stars', sync: async (ctx) => {
25
+ * await ctx.commit(events, checkpoint);
26
+ * return { status: 'complete' };
27
+ * } } },
25
28
  * actions: { star_repo: { name: 'Star', execute: async (ctx) => ({ success: true }) } },
26
29
  * });
27
30
  * ```