@lobu/runtime-device 20.2.0 → 21.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +44 -38
  3. package/npm-shrinkwrap.json +277 -231
  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 -79
  7. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +41 -29
  8. package/vendor/cli/dist/commands/_lib/apply/client.js +33 -47
  9. package/vendor/cli/dist/commands/_lib/apply/deployment.d.ts +1 -1
  10. package/vendor/cli/dist/commands/_lib/apply/deployment.js +2 -3
  11. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +47 -13
  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 -7
  14. package/vendor/cli/dist/commands/_lib/apply/diff.js +42 -29
  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 +211 -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/memory/_lib/schema.d.ts +0 -1
  31. package/vendor/cli/dist/commands/memory/_lib/schema.js +0 -9
  32. package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +0 -2
  33. package/vendor/cli/dist/config/define.d.ts +25 -8
  34. package/vendor/cli/dist/config/define.js +24 -0
  35. package/vendor/cli/dist/connectors/README.md +15 -16
  36. package/vendor/cli/dist/connectors/github.ts +274 -193
  37. package/vendor/cli/dist/connectors/google_calendar.ts +54 -160
  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 +71 -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 +11 -7
  46. package/vendor/cli/dist/connectors/reddit.ts +36 -6
  47. package/vendor/cli/dist/connectors/rss.ts +2 -2
  48. package/vendor/cli/dist/connectors/whatsapp_web.ts +5 -4
  49. package/vendor/cli/dist/connectors/x.ts +32 -17
  50. package/vendor/cli/dist/connectors/youtube.ts +18 -5
  51. package/vendor/cli/dist/internal/connector-compiler.d.ts +1 -1
  52. package/vendor/cli/dist/internal/connector-compiler.js +216 -17
  53. package/vendor/cli/dist/providers.json +0 -1
  54. package/vendor/cli/dist/runtime-components.json +4 -4
  55. package/vendor/cli/package.json +2 -1
  56. package/vendor/connector-sdk/dist/connector-runtime.d.ts +4 -6
  57. package/vendor/connector-sdk/dist/connector-runtime.js +3 -5
  58. package/vendor/connector-sdk/dist/connector-types.d.ts +28 -15
  59. package/vendor/connector-sdk/dist/define-connector.d.ts +4 -1
  60. package/vendor/connector-sdk/dist/define-connector.js +4 -1
  61. package/vendor/connector-sdk/dist/http-client.d.ts +18 -7
  62. package/vendor/connector-sdk/dist/http-client.js +15 -13
  63. package/vendor/connector-sdk/dist/index.d.ts +1 -1
  64. package/vendor/connector-sdk/dist/retry.d.ts +15 -3
  65. package/vendor/connector-sdk/dist/retry.js +40 -64
  66. package/vendor/connector-sdk/package.json +1 -1
  67. package/vendor/connector-worker/dist/agent-turn/guest-entry.js +122 -10
  68. package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +78 -10
  69. package/vendor/connector-worker/dist/agent-turn/types.d.ts +34 -4
  70. package/vendor/connector-worker/dist/compile/index.d.ts +21 -2
  71. package/vendor/connector-worker/dist/compile/index.js +41 -8
  72. package/vendor/connector-worker/dist/compile/source-capture.d.ts +10 -0
  73. package/vendor/connector-worker/dist/compile/source-capture.js +108 -0
  74. package/vendor/connector-worker/dist/daemon/agent-turn.js +97 -10
  75. package/vendor/connector-worker/dist/daemon/automation.d.ts +1 -1
  76. package/vendor/connector-worker/dist/daemon/client.d.ts +4 -1
  77. package/vendor/connector-worker/dist/daemon/client.js +3 -0
  78. package/vendor/connector-worker/dist/daemon/executor.d.ts +0 -1
  79. package/vendor/connector-worker/dist/daemon/executor.js +46 -51
  80. package/vendor/connector-worker/dist/daemon/start.js +6 -2
  81. package/vendor/connector-worker/dist/executor/interface.d.ts +19 -9
  82. package/vendor/connector-worker/dist/executor/isolate.js +85 -28
  83. package/vendor/connector-worker/dist/self-check/index.js +15 -13
  84. package/vendor/connector-worker/package.json +1 -1
  85. package/vendor/core/dist/agent-policy.js +3 -0
  86. package/vendor/core/dist/connector-query-errors.d.ts +3 -3
  87. package/vendor/core/dist/connector-query-errors.js +8 -3
  88. package/vendor/core/dist/contracts/tools/manage-auth-profiles.d.ts +14 -0
  89. package/vendor/core/dist/contracts/tools/manage-auth-profiles.js +12 -1
  90. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +0 -10
  91. package/vendor/core/dist/contracts/tools/manage-automations.js +0 -33
  92. package/vendor/core/dist/contracts/tools/manage-classifiers.d.ts +4 -34
  93. package/vendor/core/dist/contracts/tools/manage-classifiers.js +13 -44
  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-entity.d.ts +0 -9
  99. package/vendor/core/dist/contracts/tools/manage-entity.js +0 -6
  100. package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +11 -0
  101. package/vendor/core/dist/contracts/tools/manage-feeds.js +12 -1
  102. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +47 -6
  103. package/vendor/core/dist/contracts/tools/manage-operations.js +36 -1
  104. package/vendor/core/dist/contracts/tools/manage-views.d.ts +293 -0
  105. package/vendor/core/dist/contracts/tools/manage-views.js +203 -0
  106. package/vendor/core/dist/contracts/tools/source-files-schema.d.ts +7 -0
  107. package/vendor/core/dist/contracts/tools/source-files-schema.js +19 -0
  108. package/vendor/core/dist/contracts/tools/source-files.d.ts +14 -0
  109. package/vendor/core/dist/contracts/tools/source-files.js +55 -0
  110. package/vendor/core/dist/contracts/tools/view-attach.d.ts +20 -0
  111. package/vendor/core/dist/contracts/tools/view-attach.js +45 -0
  112. package/vendor/core/dist/contracts/tools/view-content-hash.d.ts +37 -0
  113. package/vendor/core/dist/contracts/tools/view-content-hash.js +58 -0
  114. package/vendor/core/dist/contracts/tools/view-path.d.ts +18 -0
  115. package/vendor/core/dist/contracts/tools/view-path.js +24 -0
  116. package/vendor/core/dist/contracts/worker/protocol.d.ts +90 -8
  117. package/vendor/core/dist/contracts/worker/protocol.js +70 -10
  118. package/vendor/core/dist/index.d.ts +1 -1
  119. package/vendor/core/dist/provider-config-types.d.ts +0 -9
  120. package/vendor/core/dist/reserved.d.ts +3 -3
  121. package/vendor/core/dist/reserved.js +9 -1
  122. package/vendor/core/dist/sdk-compat.d.ts +1 -1
  123. package/vendor/core/dist/utils/secret-redaction.js +2 -0
  124. package/vendor/core/package.json +30 -5
  125. package/vendor/core/dist/contracts/tools/manage-view-templates.d.ts +0 -165
  126. package/vendor/core/dist/contracts/tools/manage-view-templates.js +0 -130
@@ -1,6 +1,7 @@
1
1
  import type { ConnectorDefinition, EntityMetrics } from "@lobu/connector-sdk";
2
2
  import type { AgentSettings } from "@lobu/core";
3
3
  import type { AutomationEventTrigger, AutomationScheduleTrigger, AutomationWorkspaceEventTrigger } from "@lobu/core/contracts/tools/manage-automations";
4
+ import type { RetainedSource } from "@lobu/core/contracts/tools/source-files";
4
5
  import type { InferenceCapabilityBlock, InferenceModality, Project } from "../../../config/index.js";
5
6
  import { type AutomationSource, type EntityBacking, type RelationshipRule } from "./shared.js";
6
7
  export interface DesiredAgentMetadata {
@@ -37,14 +38,6 @@ export interface DesiredEntityType {
37
38
  sourcePath: string;
38
39
  sourceCode: string;
39
40
  };
40
- /**
41
- * Default view template (render-DSL root node) for this type's detail page.
42
- * Present only when declared. Applied via manage_view_templates set/clear and
43
- * diffed against the remote current default (which apply-cmd fetches per
44
- * relevant type — NOT streamed in the entity-type list). Prune-aware: under
45
- * prune an absent template clears the remote one; otherwise it is left alone.
46
- */
47
- viewTemplate?: Record<string, unknown>;
48
41
  metadata?: Record<string, unknown>;
49
42
  /**
50
43
  * Present only for derived (SQL-view-backed) entity types; absent ⇒ stored
@@ -130,8 +123,6 @@ export interface DesiredAutomation {
130
123
  agentKind?: string;
131
124
  /** Named durable outputs; explicit null clears existing declarations. */
132
125
  outputs?: Record<string, unknown> | null;
133
- /** Classifier definitions for extraction (server-side feature). */
134
- classifiers?: unknown[];
135
126
  }
136
127
  /** Apply-internal trigger form; `connectionSlug` is resolved before mutation. */
137
128
  export type DesiredAutomationEventTrigger = AutomationEventTrigger & {
@@ -208,17 +199,54 @@ export interface DesiredConnectorDefinition {
208
199
  declaredKeyHint?: string;
209
200
  /** Local `.ts` path (absolute) — mutually exclusive with `sourceUrl`. */
210
201
  sourcePath?: string;
202
+ /** Project boundary for collecting local source; never sent to the server. */
203
+ sourceRoot?: string;
211
204
  /** Remote URL — mutually exclusive with `sourcePath`. */
212
205
  sourceUrl?: string;
213
206
  /**
214
- * Raw TypeScript source read from `sourcePath`, pushed verbatim to the
215
- * server (which compiles, extracts metadata, and returns the real `key`).
216
- * Absent when `sourceUrl` is used.
207
+ * Raw TypeScript source used for static inspection. Local sources are
208
+ * compiled before upload; remote sources are compiled by the server.
217
209
  */
218
210
  sourceCode?: string;
211
+ /** Artifact and author files prepared while project dependencies are locked. */
212
+ compiledArtifact?: RetainedSource & {
213
+ compiledCode: string;
214
+ };
219
215
  /** For error messages — the `.connector.ts` file or `type: connector` doc. */
220
216
  sourceFile: string;
221
217
  }
218
+ /** One `viewFromFile` entry, bundled at load (apply reuses the artifacts). */
219
+ export interface DesiredView extends RetainedSource {
220
+ /**
221
+ * View key, re-derived from the module's own `defineView({ key })` at bundle
222
+ * time. The bundle pass refuses a mismatch with nothing to fall back to: a
223
+ * key is required, so the plan, the bundle and the action agree.
224
+ */
225
+ key: string;
226
+ /** Absolute path to the module. */
227
+ sourcePath: string;
228
+ /** Raw module source, pushed verbatim beside the bundle. */
229
+ sourceCode: string;
230
+ /**
231
+ * sha256 of source plus declared metadata plus the compiled artifact's
232
+ * digest, via the shared `@lobu/core/contracts/tools/view-content-hash` —
233
+ * the SAME function the server hashes with, so the diff's noop means the
234
+ * server will no-write. The bundle is an input (not just a payload)
235
+ * because it carries the relative imports and view npm deps the entry
236
+ * source alone does not name.
237
+ */
238
+ contentHash: string;
239
+ /** Config-relative path for messages. */
240
+ sourceFile: string;
241
+ /** Browser IIFE bundle (react, bridge, relative files, view npm deps). */
242
+ compiledCode: string;
243
+ /** Metadata extracted from the module itself. */
244
+ attach: Array<Record<string, unknown>>;
245
+ params: Record<string, unknown>;
246
+ actions: Record<string, {
247
+ emits: string;
248
+ }>;
249
+ }
222
250
  export interface DesiredAgent {
223
251
  metadata: DesiredAgentMetadata;
224
252
  /**
@@ -290,6 +318,12 @@ export interface DesiredState {
290
318
  authProfiles: DesiredAuthProfile[];
291
319
  connections: DesiredConnection[];
292
320
  };
321
+ /**
322
+ * View modules declared via `viewFromFile`. The key is provisional — read
323
+ * from the `defineView({ key })` literal when present, else derived from the
324
+ * path — and apply re-derives it from the bundle, refusing a mismatch.
325
+ */
326
+ views: DesiredView[];
293
327
  /**
294
328
  * Names of env vars referenced via `secret()` / `$VAR` (provider keys,
295
329
  * auth-profile + mcp credentials). The CLI surfaces these before mutating
@@ -4,6 +4,7 @@ import { basename, isAbsolute, join, relative, resolve, sep } from "node:path";
4
4
  import { fileURLToPath, pathToFileURL } from "node:url";
5
5
  import { createAjv } from "@lobu/core/ajv";
6
6
  import { ValidationError } from "../../memory/_lib/errors.js";
7
+ import { checkProjectDeps } from "../ensure-deps-installed.js";
7
8
  import { mapProjectToDesiredState, mergeAgentDirArtifacts, } from "./map-config.js";
8
9
  import { isRecord, } from "./shared.js";
9
10
  async function parseSkillFrontmatter(raw) {
@@ -435,12 +436,107 @@ function resolveConnectorSources(sources, cwd) {
435
436
  key: null,
436
437
  declaredKeyHint: extractDeclaredConnectorKey(sourceCode) ?? undefined,
437
438
  sourcePath: abs,
439
+ sourceRoot: baseDir,
438
440
  sourceCode,
439
441
  sourceFile: rel.replace(/^\.\//, ""),
440
442
  });
441
443
  }
442
444
  return defs.sort((a, b) => a.sourceFile.localeCompare(b.sourceFile));
443
445
  }
446
+ const VIEW_SOURCE_MAX_BYTES = 1_000_000;
447
+ /**
448
+ * Resolve `viewFromFile` entries to bundled views. Same containment shape as
449
+ * connector sources (relative POSIX path under the config directory, no
450
+ * `..`/absolute/backslash, must exist, under the server's source cap).
451
+ *
452
+ * Bundling happens HERE, not in executePlan, for one reason: the diff key
453
+ * must be the server's hash (source plus declared metadata plus the compiled
454
+ * artifact's digest, via the shared content-hash function), and the metadata
455
+ * only exists after the module's `view` export is read. The key comes from
456
+ * that export — there is no path fallback, because a required key has nothing
457
+ * to fall back to.
458
+ * ExecutePlan ships these artifacts verbatim; it never re-bundles.
459
+ *
460
+ * The esbuild + jiti-adjacent imports stay lazy (this async function is the
461
+ * only importer), so the bundler graph never rides the module-load path.
462
+ */
463
+ async function resolveViewSources(sources, cwd) {
464
+ const baseDir = resolve(cwd);
465
+ const views = [];
466
+ const seen = new Set();
467
+ const { bundleViewFromFile } = await import("../view-bundler.js");
468
+ const { contentHash } = await import("@lobu/core/contracts/tools/view-content-hash");
469
+ for (const src of sources) {
470
+ const rel = src.path.trim();
471
+ if (!rel ||
472
+ rel.startsWith("/") ||
473
+ rel.includes("\\") ||
474
+ rel.split("/").some((seg) => seg === "..")) {
475
+ throw new ValidationError(`viewFromFile(${JSON.stringify(src.path)}) must be a relative POSIX path under the config directory (./views/deal/pipeline.tsx)`);
476
+ }
477
+ if (!/\.tsx?$/.test(rel)) {
478
+ throw new ValidationError(`viewFromFile(${JSON.stringify(rel)}) must point at a \`.tsx\` or \`.ts\` file`);
479
+ }
480
+ const abs = resolve(baseDir, rel);
481
+ const relPath = relative(baseDir, abs);
482
+ if (relPath === ".." ||
483
+ relPath.startsWith(`..${sep}`) ||
484
+ isAbsolute(relPath)) {
485
+ throw new ValidationError(`viewFromFile(${JSON.stringify(rel)}) resolves outside the config directory (${abs})`);
486
+ }
487
+ let sourceCode;
488
+ try {
489
+ sourceCode = readFileSync(abs, "utf-8");
490
+ }
491
+ catch {
492
+ throw new ValidationError(`viewFromFile(${JSON.stringify(rel)}) does not exist (resolved to ${abs})`);
493
+ }
494
+ if (Buffer.byteLength(sourceCode, "utf8") > VIEW_SOURCE_MAX_BYTES) {
495
+ throw new ValidationError(`viewFromFile(${JSON.stringify(rel)}) is over the ${VIEW_SOURCE_MAX_BYTES} byte source cap`);
496
+ }
497
+ const bundled = await bundleViewFromFile(abs, baseDir);
498
+ sourceCode = bundled.sourceFiles.files[bundled.sourceFiles.entrypoint];
499
+ const key = bundled.metadata.key;
500
+ if (seen.has(key)) {
501
+ throw new ValidationError(`duplicate view key "${key}" in lobu.config.ts — each viewFromFile must resolve to a unique key`);
502
+ }
503
+ seen.add(key);
504
+ // Hash EXACTLY what the server will store: name defaults to the key,
505
+ // description defaults to empty, metadata JSON-round-tripped (the wire
506
+ // drops undefined, so hash post-round-trip or equivalent declarations
507
+ // compare differently), plus the digest of the bundle produced above
508
+ // (which carries the relative imports the entry source alone omits).
509
+ // Same function, same inputs: same hash.
510
+ const name = key;
511
+ const description = "";
512
+ const attach = JSON.parse(JSON.stringify(bundled.metadata.attach));
513
+ const params = JSON.parse(JSON.stringify(bundled.metadata.params));
514
+ const actions = JSON.parse(JSON.stringify(bundled.metadata.actions));
515
+ views.push({
516
+ key,
517
+ sourcePath: abs,
518
+ sourceCode,
519
+ contentHash: contentHash(sourceCode, {
520
+ name,
521
+ description,
522
+ attach,
523
+ params,
524
+ actions,
525
+ }, bundled.compiledCode, {
526
+ sourceFiles: bundled.sourceFiles,
527
+ dependencies: bundled.dependencies,
528
+ }),
529
+ sourceFile: rel.replace(/^\.\//, ""),
530
+ compiledCode: bundled.compiledCode,
531
+ sourceFiles: bundled.sourceFiles,
532
+ dependencies: bundled.dependencies,
533
+ attach,
534
+ params,
535
+ actions,
536
+ });
537
+ }
538
+ return views.sort((a, b) => a.sourceFile.localeCompare(b.sourceFile));
539
+ }
444
540
  const REACTION_SCRIPT_MAX_BYTES = 256 * 1024;
445
541
  const ENTITY_RULES_MAX_BYTES = 32 * 1024;
446
542
  /**
@@ -540,12 +636,8 @@ export async function loadProjectConfig(cwd) {
540
636
  throw new ValidationError(`No lobu.config.ts found in ${cwd}`);
541
637
  }
542
638
  const { createJiti } = await import("jiti");
543
- // Resolve the SDK imports the config will reference (`@lobu/cli/config`,
544
- // `@lobu/connector-sdk`) against the running CLI's own copies — not the
545
- // project's `node_modules`. This lets a freshly-scaffolded project
546
- // `validate`/`run` with zero install: the user has the CLI, that's enough.
547
- // Falls through silently if a symbol can't be resolved from here (the
548
- // catch-all error below still surfaces real problems).
639
+ // SDK config imports use the running CLI's copies. Ordinary project
640
+ // dependencies are checked before desired-state loading.
549
641
  const alias = {};
550
642
  for (const spec of ["@lobu/cli/config", "@lobu/connector-sdk"]) {
551
643
  try {
@@ -555,7 +647,9 @@ export async function loadProjectConfig(cwd) {
555
647
  // CLI dist may not expose this symbol in some packaging layouts; skip.
556
648
  }
557
649
  }
558
- const jiti = createJiti(pathToFileURL(configPath).href, Object.keys(alias).length > 0 ? { alias } : undefined);
650
+ const jiti = createJiti(pathToFileURL(configPath).href,
651
+ // Validation must not populate node_modules/.cache/jiti.
652
+ { alias, fsCache: false });
559
653
  let project;
560
654
  try {
561
655
  project = await jiti.import(configPath, { default: true });
@@ -578,6 +672,7 @@ export async function loadProjectConfig(cwd) {
578
672
  * reaction scripts, local connector source).
579
673
  */
580
674
  export async function loadDesiredStateFromConfig(opts) {
675
+ checkProjectDeps(opts.cwd);
581
676
  const env = opts.env ?? process.env;
582
677
  const { project: typedProject, configPath } = await loadProjectConfig(opts.cwd);
583
678
  const state = mapProjectToDesiredState(typedProject, env, opts.only);
@@ -690,6 +785,10 @@ export async function loadDesiredStateFromConfig(opts) {
690
785
  // ship local connector source for those runs either.
691
786
  if (!opts.only) {
692
787
  state.connectors.definitions = resolveConnectorSources(typedProject.connectors ?? [], opts.cwd);
788
+ // Views are neither agents nor memory: a targeted apply skips them too.
789
+ // Bundled here so the diff key is the server's hash (same function, same
790
+ // inputs); executePlan ships these artifacts verbatim.
791
+ state.views = await resolveViewSources(typedProject.views ?? [], opts.cwd);
693
792
  }
694
793
  // Surface load-time warnings to `lobu apply` (which prints them). #1010's
695
794
  // "ignored connectors because [memory] is disabled" case is obsolete here —
@@ -1,7 +1,7 @@
1
1
  import { type AgentSettings } from "@lobu/core";
2
2
  import type { InferenceModality } from "../../../config/define.js";
3
- import type { RemoteAgent, RemoteAuthProfile, RemoteAutomation, RemoteConnection, RemoteConnectorDefinition, RemoteEntityType, RemoteFeed, RemoteInferenceProvider, RemoteRelationshipType, UpdateConnectionPayload, UpdateFeedPayload } from "./client.js";
4
- import type { DesiredAgent, DesiredAuthProfile, DesiredAutomationTrigger, DesiredConnection, DesiredConnectorDefinition, DesiredEntityType, DesiredFeed, DesiredOrgProvider, DesiredRelationshipType, DesiredState, DesiredAutomation } from "./desired-state.js";
3
+ import type { RemoteAgent, RemoteAuthProfile, RemoteAutomation, RemoteConnection, RemoteConnectorDefinition, RemoteEntityType, RemoteFeed, RemoteInferenceProvider, RemoteRelationshipType, RemoteView, UpdateConnectionPayload, UpdateFeedPayload } from "./client.js";
4
+ import type { DesiredAgent, DesiredAuthProfile, DesiredAutomationTrigger, DesiredConnection, DesiredConnectorDefinition, DesiredEntityType, DesiredFeed, DesiredOrgProvider, DesiredRelationshipType, DesiredState, DesiredAutomation, DesiredView } from "./desired-state.js";
5
5
  import { type AutomationSource } from "./shared.js";
6
6
  type DiffVerb = "create" | "update" | "noop" | "drift" | "delete";
7
7
  interface BaseRow {
@@ -115,6 +115,13 @@ export interface InferenceProviderDiffRow extends ResourceRow<DesiredOrgProvider
115
115
  */
116
116
  capabilityModalities?: InferenceModality[];
117
117
  }
118
+ /** A `viewFromFile` module vs the org's applied view of the same key. */
119
+ export interface ViewDiffRow extends BaseRow {
120
+ kind: "view";
121
+ desired?: DesiredView;
122
+ /** Module key resolved at bundle time; the diff keys on the content hash. */
123
+ remote?: RemoteView;
124
+ }
118
125
  /**
119
126
  * A blocking drift item: either a field moved remotely or a remote-only
120
127
  * definition is not safe to delete. Apply must not converge over it — the
@@ -161,7 +168,7 @@ export interface Baseline {
161
168
  connectorVersions?: Record<string, string>;
162
169
  }
163
170
  export declare const ownedKey: (kind: string, id: number | string | undefined) => string;
164
- export type DiffRow = AgentDiffRow | SettingsDiffRow | EntityTypeDiffRow | RelationshipTypeDiffRow | AutomationDiffRow | ConnectorDefinitionDiffRow | AuthProfileDiffRow | ConnectionDiffRow | FeedDiffRow | InferenceProviderDiffRow | BlockingDriftRow;
171
+ export type DiffRow = AgentDiffRow | SettingsDiffRow | EntityTypeDiffRow | RelationshipTypeDiffRow | AutomationDiffRow | ConnectorDefinitionDiffRow | AuthProfileDiffRow | ConnectionDiffRow | FeedDiffRow | InferenceProviderDiffRow | ViewDiffRow | BlockingDriftRow;
165
172
  export interface DiffPlan {
166
173
  rows: DiffRow[];
167
174
  /** Aggregate counters for the summary line. */
@@ -247,7 +254,6 @@ export interface EntityTypeFacets {
247
254
  backing: unknown;
248
255
  metrics: unknown;
249
256
  eventKinds: unknown;
250
- viewTemplate: unknown;
251
257
  schemaExtras: Record<string, unknown>;
252
258
  }
253
259
  /**
@@ -260,7 +266,7 @@ export interface EntityTypeFacets {
260
266
  * Single source for BOTH the recorded attribution baseline and the
261
267
  * "already in sync?" test that lets an existing org establish its first
262
268
  * baseline: a second, prune-blind projection is what made prune-managed
263
- * eventKinds/viewTemplate/backing look inherited and recorded a phantom noop.
269
+ * eventKinds/backing look inherited and recorded a phantom noop.
264
270
  */
265
271
  export declare const effectiveEntityTypeAfterApply: (d: DesiredEntityType, r: RemoteEntityType | undefined, prune: boolean) => EntityTypeFacets;
266
272
  export interface RelationshipTypeFacets {
@@ -293,7 +299,6 @@ interface AutomationProjection {
293
299
  tags?: string[] | null;
294
300
  agentKind?: string | null;
295
301
  outputs?: Record<string, unknown> | null;
296
- classifiers?: unknown[] | null;
297
302
  }
298
303
  /**
299
304
  * Desired Automation → projection. For fields the two-way diff only compares
@@ -317,12 +322,14 @@ export interface RemoteSnapshot {
317
322
  feedsByConnectionId: Map<number, RemoteFeed[]>;
318
323
  /** Org-owned inference providers (from `GET /inference-providers`). */
319
324
  inferenceProviders: RemoteInferenceProvider[];
325
+ /** Applied views (`manage_views list`). Full-apply only. */
326
+ views: RemoteView[];
320
327
  }
321
328
  /**
322
329
  * The subset of {@link DesiredState} the diff consumes — everything except the
323
330
  * apply-only knobs (prune flag, org metadata, requiredSecrets).
324
331
  */
325
- type DesiredStateForDiff = Pick<DesiredState, "agents" | "memorySchema" | "automations" | "connectors" | "providers">;
332
+ type DesiredStateForDiff = Pick<DesiredState, "agents" | "memorySchema" | "automations" | "connectors" | "providers" | "views">;
326
333
  interface ComputeDiffOptions {
327
334
  /** Limit the diff to a subset of resource kinds. */
328
335
  only?: "agents" | "memory";
@@ -312,7 +312,7 @@ function diffEntityType(desired, remote, prune) {
312
312
  changed: (d, r) => !deepEqual(d.metrics, r.metrics),
313
313
  },
314
314
  {
315
- // event_kinds — prune-aware, like viewTemplate. event_kinds can be
315
+ // event_kinds — prune-aware. event_kinds can be
316
316
  // authored out-of-band via manage_entity_schema (a connector feed, the
317
317
  // UI, an agent), so a config that simply doesn't declare them must NOT
318
318
  // wipe them. Declared: diff and set on change. Omitted + prune: a
@@ -349,16 +349,6 @@ function diffEntityType(desired, remote, prune) {
349
349
  ? d.rulesSource.sourceCode !== (r.rulesSource ?? undefined)
350
350
  : prune && r.rulesSource != null,
351
351
  },
352
- {
353
- // View template — prune-aware. Declared: diff against the remote current
354
- // default (apply sets on change). Omitted + prune: a present remote
355
- // template is a removal (apply clears it). Omitted + no prune: unmanaged
356
- // (never churns), so a UI-authored template is left alone.
357
- name: "viewTemplate",
358
- changed: (d, r) => d.viewTemplate !== undefined
359
- ? !deepEqual(d.viewTemplate, r.viewTemplate)
360
- : prune && r.viewTemplate !== undefined,
361
- },
362
352
  ],
363
353
  });
364
354
  }
@@ -457,12 +447,6 @@ function compareEntityTypeThreeWay(desired, remote, attribution, prune) {
457
447
  remote: remote.eventKinds,
458
448
  attribution: attribution?.eventKinds,
459
449
  },
460
- {
461
- field: "viewTemplate",
462
- desired: desired.viewTemplate,
463
- remote: remote.viewTemplate,
464
- attribution: attribution?.viewTemplate,
465
- },
466
450
  {
467
451
  field: "resolutionPolicy",
468
452
  desired: desired.resolutionPolicy?.["x-lobu-resolution"],
@@ -490,7 +474,7 @@ function compareEntityTypeThreeWay(desired, remote, attribution, prune) {
490
474
  });
491
475
  }
492
476
  // Facets the config omits are UNMANAGED outside prune (the server keeps them
493
- // — eventKinds/viewTemplate/properties round-trip untouched). Only under
477
+ // — eventKinds/properties round-trip untouched). Only under
494
478
  // prune does omission mean "remove". Without this, an unchanged omitted facet
495
479
  // would be misclassified as config-moved and executePlan would clear it.
496
480
  // name/description are unmanaged under BOTH prune and non-prune: upsert
@@ -502,7 +486,6 @@ function compareEntityTypeThreeWay(desired, remote, attribution, prune) {
502
486
  "backing",
503
487
  "metrics",
504
488
  "eventKinds",
505
- "viewTemplate",
506
489
  "resolutionPolicy",
507
490
  "rules",
508
491
  ]);
@@ -564,7 +547,7 @@ function diffEntityTypeWithBaseline(desired, remote, baseline, prune) {
564
547
  // the remote. A definition the apply leaves untouched is a noop, so an
565
548
  // existing org can establish its first baseline without blocking. The test
566
549
  // is prune-aware because the projection is: under prune an omitted
567
- // eventKinds/viewTemplate/backing is a removal, so it does not compare
550
+ // eventKinds/backing is a removal, so it does not compare
568
551
  // equal and the ambiguity blocks instead of recording a phantom baseline.
569
552
  const inSync = deepEqual(effectiveEntityTypeAfterApply(desired, remote, prune), remoteEntityTypeFacets(remote));
570
553
  if (inSync) {
@@ -722,7 +705,6 @@ const normalizeEntityFacets = (e) => ({
722
705
  backing: e.backing,
723
706
  metrics: e.metrics,
724
707
  eventKinds: e.eventKinds,
725
- viewTemplate: e.viewTemplate,
726
708
  schemaExtras: e.schemaExtras ?? {},
727
709
  });
728
710
  /** The live remote entity type, in the comparable facet shape. */
@@ -737,7 +719,7 @@ const remoteEntityTypeFacets = (r) => normalizeEntityFacets(r);
737
719
  * Single source for BOTH the recorded attribution baseline and the
738
720
  * "already in sync?" test that lets an existing org establish its first
739
721
  * baseline: a second, prune-blind projection is what made prune-managed
740
- * eventKinds/viewTemplate/backing look inherited and recorded a phantom noop.
722
+ * eventKinds/backing look inherited and recorded a phantom noop.
741
723
  */
742
724
  export const effectiveEntityTypeAfterApply = (d, r, prune) => {
743
725
  // Outside prune, extras authored out-of-band survive; under prune the apply
@@ -773,7 +755,6 @@ export const effectiveEntityTypeAfterApply = (d, r, prune) => {
773
755
  backing: inherit(d.backing, r?.backing),
774
756
  metrics: inherit(d.metrics, r?.metrics),
775
757
  eventKinds: inherit(d.eventKinds, r?.eventKinds),
776
- viewTemplate: inherit(d.viewTemplate, r?.viewTemplate),
777
758
  schemaExtras,
778
759
  });
779
760
  };
@@ -880,7 +861,6 @@ export const projectDesiredAutomation = (d, remote) => ({
880
861
  agentKind: d.agentKind !== undefined ? d.agentKind : (remote?.agent_kind ?? null),
881
862
  // Config is declarative for outputs: omitting means "no durable outputs".
882
863
  outputs: d.outputs ?? null,
883
- classifiers: d.classifiers !== undefined ? d.classifiers : (remote?.classifiers ?? []),
884
864
  });
885
865
  const projectRemoteAutomation = (w) => ({
886
866
  executor: w.execution_config?.executor ?? null,
@@ -903,7 +883,6 @@ const projectRemoteAutomation = (w) => ({
903
883
  tags: w.tags ?? [],
904
884
  agentKind: w.agent_kind ?? null,
905
885
  outputs: w.outputs ?? null,
906
- classifiers: w.classifiers ?? [],
907
886
  });
908
887
  function diffAutomationWithBaseline(desired, remote, baseline) {
909
888
  if (!remote) {
@@ -1076,10 +1055,6 @@ function diffAutomation(desired, remote) {
1076
1055
  if (!deepEqual(desired.outputs ?? null, remote.outputs ?? null)) {
1077
1056
  versionBound.push("outputs");
1078
1057
  }
1079
- if (desired.classifiers !== undefined &&
1080
- !deepEqual(desired.classifiers, remote.classifiers ?? [])) {
1081
- versionBound.push("classifiers");
1082
- }
1083
1058
  const changed = [...scalar, ...versionBound];
1084
1059
  if (reactionScriptDeclared)
1085
1060
  changed.push("reaction_script");
@@ -1613,6 +1588,44 @@ export function computeDiff(desired, remote, opts = {}) {
1613
1588
  }
1614
1589
  }
1615
1590
  }
1591
+ // Views. Full-apply only (neither "agents" nor "memory"). Keyed on the
1592
+ // module's declared key; the change signal is the server's content hash
1593
+ // (source plus declared metadata plus the compiled artifact's digest,
1594
+ // computed at load with the same function the server hashes with — so a
1595
+ // diff noop means the server will no-write). Remote-only views are
1596
+ // config-owned only under prune; otherwise reported as drift.
1597
+ if (only === undefined) {
1598
+ // `?? []` mirrors the providers default above — test literals build a
1599
+ // partial DesiredStateForDiff.
1600
+ const desiredViews = desired.views ?? [];
1601
+ const remoteViews = remote.views ?? [];
1602
+ const remoteViewByKey = new Map(remoteViews.map((v) => [v.key, v]));
1603
+ const desiredViewKeys = new Set(desiredViews.map((v) => v.key));
1604
+ for (const view of desiredViews) {
1605
+ const r = remoteViewByKey.get(view.key);
1606
+ rows.push({
1607
+ kind: "view",
1608
+ id: view.key,
1609
+ desired: view,
1610
+ remote: r,
1611
+ verb: !r
1612
+ ? "create"
1613
+ : r.content_hash !== view.contentHash
1614
+ ? "update"
1615
+ : "noop",
1616
+ });
1617
+ }
1618
+ for (const r of remoteViews) {
1619
+ if (desiredViewKeys.has(r.key))
1620
+ continue;
1621
+ rows.push({
1622
+ kind: "view",
1623
+ id: r.key,
1624
+ remote: r,
1625
+ verb: prune ? "delete" : "drift",
1626
+ });
1627
+ }
1628
+ }
1616
1629
  const counts = { create: 0, update: 0, noop: 0, drift: 0, delete: 0 };
1617
1630
  for (const row of rows)
1618
1631
  counts[row.verb]++;
@@ -377,9 +377,6 @@ function mapEntityType(entity) {
377
377
  },
378
378
  }
379
379
  : {}),
380
- // View template included only when declared so absence never churns the diff
381
- // (a no-prune apply leaves any UI-authored template untouched).
382
- ...(entity.viewTemplate ? { viewTemplate: entity.viewTemplate } : {}),
383
380
  // metadata is carried for config-API compat (defineEntityType consumers may
384
381
  // attach it) but is neither diffed nor sent to the server.
385
382
  ...(entity.metadata ? { metadata: entity.metadata } : {}),
@@ -816,6 +813,8 @@ export function mapProjectToDesiredState(project, env = process.env, only) {
816
813
  memorySchema: { entityTypes, relationshipTypes },
817
814
  automations,
818
815
  connectors: { definitions: [], authProfiles, connections },
816
+ // View modules resolve in the loader (file IO): the mapper stays pure.
817
+ views: [],
819
818
  providers,
820
819
  requiredSecrets: [...required].sort(),
821
820
  };
@@ -13,6 +13,7 @@ const KIND_LABEL = {
13
13
  "relationship-type": "relationship-type",
14
14
  automation: "automation",
15
15
  "connector-definition": "connector-definition",
16
+ view: "view",
16
17
  "auth-profile": "auth-profile",
17
18
  connection: "connection",
18
19
  feed: "feed",
@@ -25,6 +26,7 @@ const KIND_HEADING = {
25
26
  "relationship-type": "relationship-types",
26
27
  automation: "automations",
27
28
  "connector-definition": "connector-definitions",
29
+ view: "views",
28
30
  "auth-profile": "auth-profiles",
29
31
  connection: "connections",
30
32
  feed: "feeds",
@@ -96,7 +96,7 @@ export function sanitizeSnapshotState(raw, remoteConnectionConfigs = new Map())
96
96
  export async function rollbackCommand(opts) {
97
97
  const cwd = opts.cwd ?? process.cwd();
98
98
  const newApplyId = mintApplyId();
99
- const { client, orgSlug } = await resolveApplyClient({
99
+ const { client, apiBaseUrl, orgSlug } = await resolveApplyClient({
100
100
  url: opts.url,
101
101
  org: opts.org,
102
102
  applyId: newApplyId,
@@ -207,7 +207,7 @@ export async function rollbackCommand(opts) {
207
207
  if (hasResourceWork) {
208
208
  printText(chalk.bold("\nApplying snapshot:"));
209
209
  const pendingAuth = [];
210
- await executePlan({ client, state: sanitized.state, plan, remote }, pendingAuth);
210
+ await executePlan({ client, state: sanitized.state, plan, remote, apiBaseUrl, orgSlug }, pendingAuth);
211
211
  }
212
212
  printText(chalk.green("\nRollback complete."));
213
213
  }
@@ -234,7 +234,7 @@ export async function rollbackCommand(opts) {
234
234
  let remoteForBaseline = remote;
235
235
  if (!rollbackErr) {
236
236
  try {
237
- remoteForBaseline = await fetchRemoteSnapshot(client, sanitized.state, undefined, false, orgId);
237
+ remoteForBaseline = await fetchRemoteSnapshot(client, sanitized.state, undefined, false);
238
238
  }
239
239
  catch {
240
240
  // Fall back to pre-rollback remote (over-blocks next prune, fail-closed).
@@ -1,3 +1,7 @@
1
1
  export declare function findBundledConnectorFile(key: string): string | null;
2
- export declare const compileConnectorForIsolateFromFile: (filePath: string) => Promise<string>;
2
+ export declare const compileConnectorArtifactFromFile: (filePath: string, projectRoot: string) => Promise<{
3
+ sourceFiles: import("@lobu/core/contracts/tools/source-files").SourceFiles;
4
+ dependencies: import("@lobu/core/contracts/tools/source-files").SourceDependencies;
5
+ compiledCode: string;
6
+ }>;
3
7
  //# sourceMappingURL=connector-loader.d.ts.map
@@ -37,5 +37,5 @@ export function findBundledConnectorFile(key) {
37
37
  // SDK as ESM for a forked Node child to resolve at runtime; that child is gone,
38
38
  // and a bundle shaped for it cannot load in an isolate at all.
39
39
  const compiler = createIsolateConnectorCompiler();
40
- export const compileConnectorForIsolateFromFile = compiler.compileConnectorForIsolateFromFile;
40
+ export const compileConnectorArtifactFromFile = compiler.compileConnectorArtifactFromFile;
41
41
  //# sourceMappingURL=connector-loader.js.map
@@ -1,29 +1,18 @@
1
- /**
2
- * Ensure a connector project's npm dependencies are installed before the CLI
3
- * compiles its connectors. esbuild bundles a connector's imports relative to
4
- * the connector file's directory, so the project's own `node_modules` (next to
5
- * `package.json`) must exist. We install when stale, preferring `bun` (faster,
6
- * if the user has it) and falling back to `npm` (always present with Node) so
7
- * the lobu CLI never forces a bun install on the user's machine.
8
- * `--ignore-scripts` keeps install-time supply-chain surface off the user's
9
- * machine — packages that need build scripts (native bindings) belong in
10
- * `runtime.nix.packages`, not bundled npm.
11
- */
12
- /**
13
- * Run the project's dependency install in `root` with the picked installer
14
- * (bun if available, else npm; `--ignore-scripts` always). Throws when the
15
- * install fails or the installer binary is missing — callers decide whether
16
- * that's fatal (`lobu apply` compile path) or a warning (`lobu init`).
17
- */
1
+ /** Owned by one apply or one running local stack, never a process-global cache. */
2
+ export type DependencySession = Map<string, string>;
3
+ type Mode = "create" | "frozen" | "read";
4
+ /** Read-only consumers must never install through desired-state loading. */
5
+ export declare function checkProjectDeps(cwd: string): void;
6
+ /** Hold the project lock through compilation so another Lobu install cannot race it. */
7
+ export declare function withProjectDependencies<T>(cwd: string, options: {
8
+ mode?: Mode;
9
+ session?: DependencySession;
10
+ log?: (message: string) => void;
11
+ stdio?: "inherit" | "pipe";
12
+ }, use: () => Promise<T>): Promise<T>;
13
+ /** Init alone may create/update the project's lockfile. */
18
14
  export declare function installProjectDeps(root: string, opts?: {
19
- /** "inherit" streams installer output to the terminal; "pipe" keeps it quiet. */
20
15
  stdio?: "inherit" | "pipe";
21
- }): {
22
- installer: string;
23
- };
24
- /**
25
- * Install the connector project's deps if missing/stale. No-op when the
26
- * connector has no `package.json` (no declared npm deps to bundle).
27
- */
28
- export declare function ensureProjectDepsInstalled(connectorFilePath: string, log: (message: string) => void): void;
16
+ }): Promise<void>;
17
+ export {};
29
18
  //# sourceMappingURL=ensure-deps-installed.d.ts.map