@lobu/runtime-device 24.3.0 → 24.5.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 (96) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +66 -68
  3. package/dist/verify.mjs +1 -1
  4. package/npm-shrinkwrap.json +165 -181
  5. package/package.json +2 -2
  6. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +23 -5
  7. package/vendor/cli/dist/bundled-skills/lobu-connect/SKILL.md +6 -0
  8. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +20 -13
  9. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +48 -100
  10. package/vendor/cli/dist/commands/_lib/apply/client.js +76 -27
  11. package/vendor/cli/dist/commands/_lib/apply/deployment.js +1 -1
  12. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +7 -11
  13. package/vendor/cli/dist/commands/_lib/apply/desired-state.js +9 -40
  14. package/vendor/cli/dist/commands/_lib/apply/diff.d.ts +4 -4
  15. package/vendor/cli/dist/commands/_lib/apply/diff.js +37 -33
  16. package/vendor/cli/dist/commands/_lib/apply/map-config.d.ts +1 -1
  17. package/vendor/cli/dist/commands/_lib/apply/map-config.js +79 -92
  18. package/vendor/cli/dist/commands/_lib/apply/shared.d.ts +3 -6
  19. package/vendor/cli/dist/commands/_lib/apply/shared.js +8 -19
  20. package/vendor/cli/dist/commands/dev.js +21 -7
  21. package/vendor/cli/dist/commands/doctor.js +1 -8
  22. package/vendor/cli/dist/commands/init.js +4 -5
  23. package/vendor/cli/dist/config/define.d.ts +27 -28
  24. package/vendor/cli/dist/config/define.js +4 -5
  25. package/vendor/cli/dist/connectors/postgres.ts +77 -48
  26. package/vendor/cli/dist/internal/api-client.d.ts +2 -0
  27. package/vendor/cli/dist/internal/api-client.js +6 -1
  28. package/vendor/cli/dist/internal/node-binary.d.ts +22 -0
  29. package/vendor/cli/dist/internal/node-binary.js +73 -0
  30. package/vendor/cli/dist/internal/node-version.d.ts +7 -12
  31. package/vendor/cli/dist/internal/node-version.js +16 -20
  32. package/vendor/cli/dist/runtime-components.json +4 -4
  33. package/vendor/cli/dist/templates/AGENTS.md.tmpl +2 -2
  34. package/vendor/cli/package.json +2 -2
  35. package/vendor/connector-sdk/dist/reaction-client-types.d.ts +8 -2
  36. package/vendor/connector-sdk/dist/reaction-sdk.d.ts +5 -1
  37. package/vendor/connector-sdk/package.json +1 -1
  38. package/vendor/connector-worker/dist/daemon/acp-adapters/claude.js +1 -1
  39. package/vendor/connector-worker/dist/daemon/agent-turn.js +69 -3
  40. package/vendor/connector-worker/dist/daemon/client.d.ts +25 -8
  41. package/vendor/connector-worker/dist/daemon/client.js +32 -4
  42. package/vendor/connector-worker/dist/daemon/log.js +2 -1
  43. package/vendor/connector-worker/dist/daemon/mac-device-daemon.js +7 -1
  44. package/vendor/connector-worker/dist/daemon/poll-loop.d.ts +17 -0
  45. package/vendor/connector-worker/dist/daemon/poll-loop.js +101 -13
  46. package/vendor/connector-worker/dist/daemon/resource-admission.d.ts +19 -0
  47. package/vendor/connector-worker/dist/daemon/resource-admission.js +59 -0
  48. package/vendor/connector-worker/dist/daemon/resources.d.ts +20 -0
  49. package/vendor/connector-worker/dist/daemon/resources.js +163 -0
  50. package/vendor/connector-worker/dist/daemon/start.js +29 -4
  51. package/vendor/connector-worker/dist/daemon/worker.d.ts +2 -0
  52. package/vendor/connector-worker/dist/daemon/worker.js +4 -0
  53. package/vendor/connector-worker/dist/executor/select.d.ts +1 -1
  54. package/vendor/connector-worker/dist/executor/select.js +1 -1
  55. package/vendor/connector-worker/dist/isolate/ivm-types.d.ts +1 -2
  56. package/vendor/connector-worker/dist/isolate/ivm-types.js +1 -2
  57. package/vendor/connector-worker/dist/isolate/load.d.ts +10 -12
  58. package/vendor/connector-worker/dist/isolate/load.js +23 -27
  59. package/vendor/connector-worker/dist/self-check/index.d.ts +2 -2
  60. package/vendor/connector-worker/dist/self-check/index.js +2 -2
  61. package/vendor/connector-worker/package.json +3 -4
  62. package/vendor/core/dist/contracts/agent-settings.d.ts +61 -6
  63. package/vendor/core/dist/contracts/agent-settings.js +10 -7
  64. package/vendor/core/dist/contracts/tools/manage-agents.d.ts +473 -98
  65. package/vendor/core/dist/contracts/tools/manage-agents.js +111 -2
  66. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +21 -18
  67. package/vendor/core/dist/contracts/tools/manage-automations.js +15 -15
  68. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +2 -2
  69. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +45 -20
  70. package/vendor/core/dist/contracts/tools/manage-entity.js +17 -5
  71. package/vendor/core/dist/contracts/tools/manage-inference-providers.d.ts +445 -0
  72. package/vendor/core/dist/contracts/tools/manage-inference-providers.js +133 -0
  73. package/vendor/core/dist/contracts/tools/manage-views.d.ts +4 -4
  74. package/vendor/core/dist/contracts/tools/manage-views.js +5 -3
  75. package/vendor/core/dist/contracts/worker/device-automation.js +4 -2
  76. package/vendor/core/dist/error-report.d.ts +73 -0
  77. package/vendor/core/dist/error-report.js +346 -0
  78. package/vendor/core/dist/index.d.ts +4 -1
  79. package/vendor/core/dist/index.js +7 -1
  80. package/vendor/core/dist/logger.js +15 -6
  81. package/vendor/core/dist/otel-fetch.d.ts +19 -0
  82. package/vendor/core/dist/otel-fetch.js +96 -0
  83. package/vendor/core/dist/otel.d.ts +22 -2
  84. package/vendor/core/dist/otel.js +95 -48
  85. package/vendor/core/dist/reserved.d.ts +1 -1
  86. package/vendor/core/dist/reserved.js +6 -4
  87. package/vendor/core/dist/tool-result.d.ts +8 -0
  88. package/vendor/core/dist/tool-result.js +61 -0
  89. package/vendor/core/dist/trace-context.d.ts +12 -0
  90. package/vendor/core/dist/trace-context.js +50 -0
  91. package/vendor/core/dist/utils/diagnostic-scrubber.js +1 -1
  92. package/vendor/core/dist/worker/auth.js +4 -0
  93. package/vendor/core/package.json +6 -1
  94. /package/vendor/cli/dist/vendor/ora/{.bun-tag-fde20e9a6df212fa → .bun-tag-77bb9b258a474a18} +0 -0
  95. /package/vendor/ora/{.bun-tag-fde20e9a6df212fa → .bun-tag-77bb9b258a474a18} +0 -0
  96. /package/vendor/postgres/{.bun-tag-22d644c2873790db → .bun-tag-c81dacd34e959a7a} +0 -0
@@ -1,9 +1,9 @@
1
1
  import type { ConnectorDefinition, EntityMetrics } from "@lobu/connector-sdk";
2
2
  import type { AgentSettings } from "@lobu/core";
3
- import type { AutomationEventTrigger, AutomationScheduleTrigger, AutomationWorkspaceEventTrigger } from "@lobu/core/contracts/tools/manage-automations";
4
3
  import type { CollectionPresentation } from "@lobu/core/contracts/tools/collection-presentation";
4
+ import type { AutomationEventTrigger, AutomationScheduleTrigger, AutomationWorkspaceEventTrigger, ManageAutomationsArgs } from "@lobu/core/contracts/tools/manage-automations";
5
5
  import type { RetainedSource } from "@lobu/core/contracts/tools/source-files";
6
- import type { InferenceCapabilityBlock, InferenceModality, Project } from "../../../config/index.js";
6
+ import type { Automation, InferenceCapabilityBlock, InferenceModality, Project } from "../../../config/index.js";
7
7
  import { type AutomationSource, type EntityBacking, type RelationshipRule } from "./shared.js";
8
8
  export interface DesiredAgentMetadata {
9
9
  agentId: string;
@@ -71,13 +71,9 @@ export interface DesiredRelationshipType {
71
71
  }
72
72
  export interface DesiredAutomation {
73
73
  slug: string;
74
- /** Owning agent id. Every automation belongs to exactly one agent. */
75
- agent: string;
76
- executor?: {
77
- kind: "script";
78
- source: string;
79
- params?: Record<string, unknown>;
80
- } | null;
74
+ executionConfig?: Automation["executionConfig"];
75
+ /** Managed agent identity, independent of device placement. */
76
+ agent: string | null;
81
77
  name?: string;
82
78
  description?: string;
83
79
  triggers?: DesiredAutomationTrigger[];
@@ -127,8 +123,8 @@ export interface DesiredAutomation {
127
123
  minCooldownSeconds?: number;
128
124
  /** Free-form tags for filtering. */
129
125
  tags?: string[];
130
- /** Optional agent-kind override (e.g. "background", "notifier"). */
131
- agentKind?: string;
126
+ /** Optional agent runtime override. */
127
+ agentKind?: NonNullable<ManageAutomationsArgs["agent_kind"]>;
132
128
  /** Named durable outputs; explicit null clears existing declarations. */
133
129
  outputs?: Record<string, unknown> | null;
134
130
  }
@@ -135,8 +135,7 @@ async function readMarkdown(agentDir) {
135
135
  for (const [key, filename] of files) {
136
136
  try {
137
137
  const content = await readFile(join(agentDir, filename), "utf-8");
138
- if (content.trim())
139
- result[key] = content.trim();
138
+ result[key] = content.trim();
140
139
  }
141
140
  catch {
142
141
  // missing file is fine
@@ -679,9 +678,11 @@ export async function loadDesiredStateFromConfig(opts) {
679
678
  return;
680
679
  const agentDir = resolve(opts.cwd, agent.dir ?? join("agents", agent.id));
681
680
  const markdown = await readMarkdown(agentDir);
682
- const localSkills = await resolveAgentSkills(agent.skills ?? [], opts.cwd);
681
+ const localSkills = agent.skills === undefined
682
+ ? undefined
683
+ : await resolveAgentSkills(agent.skills, opts.cwd);
683
684
  mergeAgentDirArtifacts(settings, markdown, localSkills);
684
- skillsByAgentId.set(agent.id, localSkills);
685
+ skillsByAgentId.set(agent.id, settings.skillsConfig?.skills ?? []);
685
686
  }));
686
687
  // Resolve each Automation's `skills[]` to {name, content} snapshots against the
687
688
  // owning agent's library. This happens BEFORE the diff reads them, so a change
@@ -691,44 +692,13 @@ export async function loadDesiredStateFromConfig(opts) {
691
692
  // The bodies are no longer folded into `prompt`: the prompt is the author's
692
693
  // task statement (or empty), and skills ride alongside as pinned files.
693
694
  for (const automation of state.automations) {
694
- automation.skillSnapshots = resolveAutomationSkills(automation, skillsByAgentId.get(automation.agent) ?? []);
695
+ automation.skillSnapshots = resolveAutomationSkills(automation, automation.agent ? (skillsByAgentId.get(automation.agent) ?? []) : []);
695
696
  }
696
- // Automation executor and reaction scripts: sibling `.ts` files referenced
697
+ // Automation lifecycle modules: sibling `.ts` files referenced
697
698
  // by path. The mapper stays pure; resolve + read each raw source here for the
698
699
  // server to compile. state.automations[i] aligns with
699
700
  // typedProject.automations[i] (the mapper maps them in order).
700
701
  (typedProject.automations ?? []).forEach((automation, i) => {
701
- if (automation.executor !== undefined && automation.executor !== "agent") {
702
- const desired = state.automations[i];
703
- if (!desired)
704
- return;
705
- if (!automation.executor ||
706
- typeof automation.executor !== "object" ||
707
- automation.executor.kind !== "scriptSource" ||
708
- typeof automation.executor.path !== "string") {
709
- throw new ValidationError(`Automation "${automation.slug}": use scriptFromFile("./job.ts") for a script executor.`);
710
- }
711
- if (automation.executor.params !== undefined &&
712
- !isRecord(automation.executor.params)) {
713
- throw new ValidationError(`Automation "${automation.slug}": scriptFromFile params must be an object, not an array.`);
714
- }
715
- const script = resolveLocalSourceFile({
716
- cwd: opts.cwd,
717
- owner: `Automation ${JSON.stringify(automation.slug)}`,
718
- field: "executor",
719
- example: 'scriptFromFile("./job.ts")',
720
- rel: automation.executor.path,
721
- maxBytes: 131072,
722
- sizeHint: "Automation scripts must stay within the sandbox source limit",
723
- });
724
- desired.executor = {
725
- kind: "script",
726
- source: script.sourceCode,
727
- ...(automation.executor.params
728
- ? { params: automation.executor.params }
729
- : {}),
730
- };
731
- }
732
702
  // Gate on absence, not truthiness — a present-but-empty
733
703
  // `reactionFromFile("")` must reach the validator (which rejects it),
734
704
  // matching parseAutomation.
@@ -738,9 +708,8 @@ export async function loadDesiredStateFromConfig(opts) {
738
708
  if (!dw)
739
709
  return;
740
710
  // Explicit `null` removes a previously installed reaction. Carried through
741
- // the diff as declared and applied via set_reaction_script("") AFTER the
742
- // executor install, so a reaction-driven job switching to a script
743
- // executor never runs both paths. Omitted (`undefined`) preserves.
711
+ // the diff as declared and applied via set_reaction_script("").
712
+ // Omitted (`undefined`) preserves.
744
713
  if (automation.reaction === null) {
745
714
  dw.reactionScript = null;
746
715
  return;
@@ -1,7 +1,7 @@
1
1
  import { type AgentSettings } from "@lobu/core";
2
2
  import type { InferenceModality } from "../../../config/define.js";
3
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";
4
+ import type { DesiredAgent, DesiredAuthProfile, DesiredAutomation, DesiredAutomationTrigger, DesiredConnection, DesiredConnectorDefinition, DesiredEntityType, DesiredFeed, DesiredOrgProvider, DesiredRelationshipType, DesiredState, 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 {
@@ -226,7 +226,7 @@ interface FieldTable<D, R, P, F extends string> {
226
226
  * BYO chat connections never reach `updateConnection` (apply routes them to the
227
227
  * secret-aware chat-upsert), so the BYO branches below only govern diffing.
228
228
  */
229
- declare const CONNECTION_FIELDS: FieldTable<DesiredConnection, RemoteConnection, UpdateConnectionPayload, "config" | "name" | "auth" | "app_auth" | "device_worker_id">;
229
+ declare const CONNECTION_FIELDS: FieldTable<DesiredConnection, RemoteConnection, UpdateConnectionPayload, "config" | "name" | "device_worker_id" | "auth" | "app_auth">;
230
230
  /** Every updatable feed field. See {@link CONNECTION_FIELDS}. */
231
231
  declare const FEED_FIELDS: FieldTable<DesiredFeed, RemoteFeed, UpdateFeedPayload, "config" | "name" | "schedule">;
232
232
  export type ConnectionField = keyof typeof CONNECTION_FIELDS.fields;
@@ -239,7 +239,7 @@ export type FeedField = keyof typeof FEED_FIELDS.fields;
239
239
  export declare function buildUpdatePayload<D, R, P, F extends string>(table: FieldTable<D, R, P, F>, changedFields: readonly F[] | undefined, desired: D): Partial<P>;
240
240
  /** The connection and feed field tables, for apply to build payloads from. */
241
241
  export declare const UPDATE_FIELD_TABLES: {
242
- readonly connection: FieldTable<DesiredConnection, RemoteConnection, UpdateConnectionPayload, "config" | "name" | "auth" | "app_auth" | "device_worker_id">;
242
+ readonly connection: FieldTable<DesiredConnection, RemoteConnection, UpdateConnectionPayload, "config" | "name" | "device_worker_id" | "auth" | "app_auth">;
243
243
  readonly feed: FieldTable<DesiredFeed, RemoteFeed, UpdateFeedPayload, "config" | "name" | "schedule">;
244
244
  };
245
245
  /**
@@ -282,7 +282,7 @@ export interface RelationshipTypeFacets {
282
282
  */
283
283
  export declare const effectiveRelationshipTypeAfterApply: (d: DesiredRelationshipType, r: RemoteRelationshipType | undefined) => RelationshipTypeFacets;
284
284
  interface AutomationProjection {
285
- executor?: unknown;
285
+ executionConfig?: RemoteAutomation["execution_config"];
286
286
  agent?: string | null;
287
287
  name?: string | null;
288
288
  description?: string | null;
@@ -77,18 +77,19 @@ const CONNECTION_FIELDS = defineFieldTable()({
77
77
  // payload (`apply_chat_connection` only persists slug/connector/name/config),
78
78
  // and a BYO chat declaration can't even set them (map-config rejects them).
79
79
  // Never diff them for BYO, or a remote row carrying a stray value would
80
- // report a perpetual "update" that apply can't clear.
80
+ // report a perpetual "update" that apply can't clear. Undeclared is not a
81
+ // difference, same rule as `name` and `config`: an omitted pin is unmanaged.
81
82
  auth: {
82
- changed: (d, r) => d.credentialMode === "byo"
83
- ? false
84
- : (d.authProfileSlug ?? null) !== (r.auth_profile_slug ?? null),
85
- payload: (d) => ({ authProfileSlug: d.authProfileSlug ?? null }),
83
+ changed: (d, r) => d.credentialMode !== "byo" &&
84
+ d.authProfileSlug !== undefined &&
85
+ d.authProfileSlug !== (r.auth_profile_slug ?? null),
86
+ payload: (d) => ({ authProfileSlug: d.authProfileSlug }),
86
87
  },
87
88
  app_auth: {
88
- changed: (d, r) => d.credentialMode === "byo"
89
- ? false
90
- : (d.appAuthProfileSlug ?? null) !== (r.app_auth_profile_slug ?? null),
91
- payload: (d) => ({ appAuthProfileSlug: d.appAuthProfileSlug ?? null }),
89
+ changed: (d, r) => d.credentialMode !== "byo" &&
90
+ d.appAuthProfileSlug !== undefined &&
91
+ d.appAuthProfileSlug !== (r.app_auth_profile_slug ?? null),
92
+ payload: (d) => ({ appAuthProfileSlug: d.appAuthProfileSlug }),
92
93
  },
93
94
  config: {
94
95
  // A BYO chat connection's config holds a resolved secret (plaintext) on the
@@ -109,11 +110,11 @@ const CONNECTION_FIELDS = defineFieldTable()({
109
110
  payload: (d) => ({ config: d.config }),
110
111
  },
111
112
  device_worker_id: {
112
- changed: (d, r) => d.credentialMode === "byo"
113
- ? false
114
- : (d.deviceWorkerId ?? null) !== (r.device_worker_id ?? null),
115
- // null unpins to the server, a uuid moves it to that device.
116
- payload: (d) => ({ deviceWorkerId: d.deviceWorkerId ?? null }),
113
+ changed: (d, r) => d.credentialMode !== "byo" &&
114
+ d.deviceWorkerId !== undefined &&
115
+ d.deviceWorkerId !== (r.device_worker_id ?? null),
116
+ // A declared uuid moves the connection to that device.
117
+ payload: (d) => ({ deviceWorkerId: d.deviceWorkerId }),
117
118
  },
118
119
  });
119
120
  /** Every updatable feed field. See {@link CONNECTION_FIELDS}. */
@@ -858,9 +859,9 @@ function remoteOnlyDefinitionRow(kind, remote, baseline, prune, unchangedSinceBa
858
859
  * use the same defaults as `diffAutomation`.
859
860
  */
860
861
  export const projectDesiredAutomation = (d, remote) => ({
861
- executor: d.executor !== undefined
862
- ? d.executor
863
- : (remote?.execution_config?.executor ?? null),
862
+ executionConfig: d.executionConfig !== undefined
863
+ ? d.executionConfig
864
+ : (remote?.execution_config ?? null),
864
865
  agent: d.agent ?? null,
865
866
  // Name/description are optional in config; the server defaults name to the
866
867
  // slug. Inherit live remote when omitted so a second apply does not
@@ -879,11 +880,13 @@ export const projectDesiredAutomation = (d, remote) => ({
879
880
  deviceWorkerId: d.deviceWorkerId !== undefined
880
881
  ? d.deviceWorkerId
881
882
  : (remote?.device_worker_id ?? null),
882
- model: d.model !== undefined
883
- ? d.model
884
- : typeof remote?.execution_config?.model === "string"
885
- ? remote.execution_config.model
886
- : null,
883
+ model: d.executionConfig !== undefined
884
+ ? (d.executionConfig?.model ?? null)
885
+ : d.model !== undefined
886
+ ? d.model
887
+ : typeof remote?.execution_config?.model === "string"
888
+ ? remote.execution_config.model
889
+ : null,
887
890
  minCooldownSeconds: d.minCooldownSeconds !== undefined
888
891
  ? d.minCooldownSeconds
889
892
  : (remote?.min_cooldown_seconds ?? null),
@@ -893,7 +896,7 @@ export const projectDesiredAutomation = (d, remote) => ({
893
896
  outputs: d.outputs ?? null,
894
897
  });
895
898
  const projectRemoteAutomation = (w) => ({
896
- executor: w.execution_config?.executor ?? null,
899
+ executionConfig: w.execution_config ?? null,
897
900
  agent: w.managed_agent_id ?? null,
898
901
  // `?? null` mirrors projectDesiredAutomation: an unnamed remote Automation must
899
902
  // compare EQUAL to the desired side that inherited it, or deepEqual(null,
@@ -1020,7 +1023,7 @@ function diffAutomation(desired, remote) {
1020
1023
  if (!deepEqual(desired.triggers ?? [], remote.triggers ?? [])) {
1021
1024
  scalar.push("triggers");
1022
1025
  }
1023
- if (desired.agent !== (remote.managed_agent_id ?? "")) {
1026
+ if (desired.agent !== (remote.managed_agent_id ?? null)) {
1024
1027
  scalar.push("managed_agent_id");
1025
1028
  }
1026
1029
  if (desired.deviceWorkerId !== undefined &&
@@ -1039,10 +1042,10 @@ function diffAutomation(desired, remote) {
1039
1042
  desired.agentKind !== (remote.agent_kind ?? undefined)) {
1040
1043
  scalar.push("agent_kind");
1041
1044
  }
1042
- if ((desired.model !== undefined &&
1043
- desired.model !== (remote.execution_config?.model ?? null)) ||
1044
- (desired.executor !== undefined &&
1045
- !deepEqual(desired.executor, remote.execution_config?.executor ?? null))) {
1045
+ if ((desired.executionConfig !== undefined &&
1046
+ !deepEqual(desired.executionConfig, remote.execution_config ?? null)) ||
1047
+ (desired.model !== undefined &&
1048
+ desired.model !== (remote.execution_config?.model ?? null))) {
1046
1049
  scalar.push("execution_config");
1047
1050
  }
1048
1051
  const versionBound = [];
@@ -1120,16 +1123,15 @@ function diffConnectorDefinition(desired, installedKeys) {
1120
1123
  const id = connectorDefinitionId(desired);
1121
1124
  // The CLI can't compare source hashes (the server compiles, and the stored
1122
1125
  // hash is of the *compiled* output) — so we always emit a "sync" row;
1123
- // `install_connector` is idempotent and reports `updated:false` on apply
1124
- // when the code is byte-identical, so this never churns remote state.
1126
+ // The server preserves identical retained versions and enforces version bumps
1127
+ // for source changes. Installed definitions use the version-checked update.
1125
1128
  // Local files have no resolved key during planning; the static hint lets
1126
1129
  // the plan recognise an installed definition without compiling the source.
1127
1130
  const key = desired.key ?? desired.declaredKeyHint;
1128
1131
  const installedRemotely = key ? installedKeys.has(key) : false;
1129
1132
  return {
1130
1133
  kind: "connector-definition",
1131
- // "update" (re-push) when already installed; `install_connector` is
1132
- // idempotent and reports `updated:false` if the code is unchanged.
1134
+ // Installed definitions reuse update_connector_source with the read version.
1133
1135
  verb: installedRemotely ? "update" : "create",
1134
1136
  id,
1135
1137
  desired,
@@ -1154,7 +1156,9 @@ function diffAuthProfile(desired, remote) {
1154
1156
  throw new ValidationError(`${desired.sourceFile}: auth_profile "${desired.slug}" is bound to ${remote.connector_key}/${remote.profile_kind} remotely, but the manifest declares ${desired.connector}/${desired.kind} — delete it manually or use a new slug`);
1155
1157
  }
1156
1158
  const changed = [];
1157
- if ((desired.name ?? "") !== (remote.display_name ?? "")) {
1159
+ // An omitted name is unmanaged; apply never sends it.
1160
+ if (desired.name !== undefined &&
1161
+ desired.name !== (remote.display_name ?? "")) {
1158
1162
  changed.push("name");
1159
1163
  }
1160
1164
  // Credentials can't be read back from the server (write-only secrets). For
@@ -28,7 +28,7 @@ export interface AgentMarkdown {
28
28
  * config. Packages come from the agent (`nixConfig`, already in `settings`) or
29
29
  * connector `agentTooling`, never from skills.
30
30
  */
31
- export declare function mergeAgentDirArtifacts(settings: Partial<AgentSettings>, markdown: AgentMarkdown, localSkills: LocalSkills): void;
31
+ export declare function mergeAgentDirArtifacts(settings: Partial<AgentSettings>, markdown: AgentMarkdown, localSkills?: LocalSkills): void;
32
32
  /**
33
33
  * Translate an authoring project into the apply `DesiredState`. When `only` is
34
34
  * set, connector definitions/connections/auth-profiles are skipped (and their
@@ -9,32 +9,12 @@
9
9
  */
10
10
  import { validateEntityMetrics } from "@lobu/connector-sdk/metrics";
11
11
  import { isChatPlatform, normalizeEntityTypeSlug, } from "@lobu/core";
12
+ import { AgentSettingsPatchSchema } from "@lobu/core/contracts/agent-settings";
12
13
  import { parseCollectionPresentation } from "@lobu/core/contracts/tools/collection-presentation";
13
- import { normalizeWorkspaceEventTrigger, resolvedEventExecution, } from "@lobu/core/contracts/tools/manage-automations";
14
+ import { AutomationExecutionConfigSchema, ManageAutomationsSchema, normalizeWorkspaceEventTrigger, resolvedEventExecution, } from "@lobu/core/contracts/tools/manage-automations";
14
15
  import { InvalidEntityResolutionPolicyError, parseEntityResolutionPolicy, } from "@lobu/core/contracts/tools/manage-entity-schema";
15
- /**
16
- * Marker for each stored field's declarative status. Also exhaustive over the
17
- * same key set, so a new field with no policy entry also fails to compile.
18
- * - "mapped": produced by this converter
19
- * - "unsupported": not declarable in lobu.config.ts (intentional)
20
- * - "post-load": filled later by mergeAgentDirArtifacts
21
- */
22
- const AGENT_SETTINGS_FIELD_POLICY = {
23
- models: "mapped",
24
- networkConfig: "mapped",
25
- nixConfig: "mapped",
26
- soulMd: "post-load",
27
- userMd: "post-load",
28
- identityMd: "post-load",
29
- skillsConfig: "post-load",
30
- guardrails: "mapped",
31
- guardrailsInline: "unsupported",
32
- sandboxId: "unsupported",
33
- verboseLogging: "unsupported",
34
- showToolCalls: "unsupported",
35
- starters: "mapped",
36
- };
37
- void AGENT_SETTINGS_FIELD_POLICY;
16
+ import { InferenceModalitySchema, InferenceProviderSlugSchema, } from "@lobu/core/contracts/tools/manage-inference-providers";
17
+ import { Value } from "@sinclair/typebox/value";
38
18
  import { CronExpressionParser } from "cron-parser";
39
19
  import { isSecretRef, UNRESOLVED_MODEL_SUFFIX } from "../../../config/index.js";
40
20
  import { ValidationError } from "../../memory/_lib/errors.js";
@@ -80,22 +60,10 @@ function envRefName(value) {
80
60
  function providerId(provider) {
81
61
  return (provider.id ?? "").trim();
82
62
  }
83
- /**
84
- * Org-provider slug rules — MUST match the DB CHECK in the inference_providers
85
- * migration exactly (`^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$`): lowercase
86
- * alphanumeric + hyphen, 1-63 chars, no leading/trailing hyphen. Kept in lockstep
87
- * so `lobu apply` rejects a bad slug up front instead of the server 500ing on the
88
- * CHECK. Single-char slugs are allowed; a trailing hyphen (`myvllm-`) is not.
89
- */
90
- const ORG_PROVIDER_SLUG_PATTERN = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
63
+ /** Use the same provider-slug bounds as REST and MCP. */
64
+ const ORG_PROVIDER_SLUG_PATTERN = new RegExp(InferenceProviderSlugSchema.pattern);
91
65
  /** Modalities the server accepts for an inference-provider capability block. */
92
- const INFERENCE_MODALITIES = new Set([
93
- "text",
94
- "image",
95
- "stt",
96
- "tts",
97
- "embedding",
98
- ]);
66
+ const INFERENCE_MODALITIES = new Set(InferenceModalitySchema.anyOf.map((modality) => modality.const));
99
67
  /**
100
68
  * Map an org-owned inference provider (`defineConfig({ providers })`) to its
101
69
  * `DesiredOrgProvider`. Resolves the API key from its `secret()` / `$VAR` ref
@@ -115,7 +83,7 @@ function mapOrgProvider(provider, required, env) {
115
83
  const capabilities = {};
116
84
  for (const [modality, block] of Object.entries(provider.capabilities ?? {})) {
117
85
  if (!INFERENCE_MODALITIES.has(modality)) {
118
- throw new ValidationError(`provider "${provider.slug}" declares unknown modality "${modality}" (expected text|image|stt|tts|embedding)`);
86
+ throw new ValidationError(`provider "${provider.slug}" declares unknown modality "${modality}" (expected ${[...INFERENCE_MODALITIES].join("|")})`);
119
87
  }
120
88
  if (block)
121
89
  capabilities[modality] = block;
@@ -182,19 +150,41 @@ function resolveConnectionConfigValue(value, required, env) {
182
150
  * connector `agentTooling`, never from skills.
183
151
  */
184
152
  export function mergeAgentDirArtifacts(settings, markdown, localSkills) {
185
- if (markdown.soulMd)
186
- settings.soulMd = markdown.soulMd;
187
- if (markdown.identityMd)
188
- settings.identityMd = markdown.identityMd;
189
- if (markdown.userMd)
190
- settings.userMd = markdown.userMd;
191
- if (localSkills.length > 0) {
153
+ for (const key of ["soulMd", "identityMd", "userMd"]) {
154
+ if (markdown[key] === undefined)
155
+ continue;
156
+ if (settings[key] !== undefined) {
157
+ throw new ValidationError(`Declare ${key} either in settings or in its Markdown file, not both`);
158
+ }
159
+ settings[key] = markdown[key];
160
+ }
161
+ if (localSkills !== undefined) {
162
+ if (settings.skillsConfig !== undefined) {
163
+ throw new ValidationError("Declare either skills or settings.skillsConfig, not both");
164
+ }
192
165
  settings.skillsConfig = { skills: localSkills };
193
166
  }
194
167
  }
195
168
  function mapAgent(agent, env, required) {
196
- const settings = {};
197
- if (agent.providers?.length) {
169
+ if (agent.settings !== undefined &&
170
+ !Value.Check(AgentSettingsPatchSchema, agent.settings)) {
171
+ const error = Value.Errors(AgentSettingsPatchSchema, agent.settings).First();
172
+ throw new ValidationError(`Agent "${agent.id}" settings${error?.path ?? ""}: ${error?.message ?? "invalid settings"}`);
173
+ }
174
+ const settings = { ...agent.settings };
175
+ for (const [helper, key] of [
176
+ ["providers", "models"],
177
+ ["network", "networkConfig"],
178
+ ["nixPackages", "nixConfig"],
179
+ ["guardrails", "guardrails"],
180
+ ["starters", "starters"],
181
+ ["skills", "skillsConfig"],
182
+ ]) {
183
+ if (agent[helper] !== undefined && settings[key] !== undefined) {
184
+ throw new ValidationError(`Agent "${agent.id}" must declare either ${helper} or settings.${key}, not both`);
185
+ }
186
+ }
187
+ if (agent.providers !== undefined) {
198
188
  // Each declared provider becomes one explicit ref in the ordered `models`
199
189
  // list (index 0 = the primary/default). A provider WITH a concrete model
200
190
  // emits `<providerId>/<model>` (never `<providerId>/auto` — auto is gone);
@@ -218,18 +208,19 @@ function mapAgent(agent, env, required) {
218
208
  return model.startsWith(`${id}/`) ? model : `${id}/${model}`;
219
209
  });
220
210
  }
221
- const allowed = agent.network?.allowed ?? [];
222
- const denied = agent.network?.denied ?? [];
223
- if (allowed.length > 0 || denied.length > 0) {
211
+ if (agent.network !== undefined) {
212
+ const { allowed, denied } = agent.network;
224
213
  settings.networkConfig = {
225
- ...(allowed.length > 0 ? { allowedDomains: [...new Set(allowed)] } : {}),
226
- ...(denied.length > 0 ? { deniedDomains: [...new Set(denied)] } : {}),
214
+ ...(allowed !== undefined
215
+ ? { allowedDomains: [...new Set(allowed)] }
216
+ : {}),
217
+ ...(denied !== undefined ? { deniedDomains: [...new Set(denied)] } : {}),
227
218
  };
228
219
  }
229
- if (agent.guardrails?.length) {
220
+ if (agent.guardrails !== undefined) {
230
221
  settings.guardrails = [...new Set(agent.guardrails)];
231
222
  }
232
- if (agent.nixPackages?.length) {
223
+ if (agent.nixPackages !== undefined) {
233
224
  settings.nixConfig = { packages: [...new Set(agent.nixPackages)] };
234
225
  }
235
226
  if (agent.starters !== undefined) {
@@ -266,32 +257,8 @@ function mapAgent(agent, env, required) {
266
257
  agentId: agent.id,
267
258
  name: agent.name ?? agent.id,
268
259
  };
269
- if (agent.description)
260
+ if (agent.description !== undefined)
270
261
  metadata.description = agent.description;
271
- // Exhaustiveness guard (compile-time): construct a projection object that
272
- // includes EVERY stored key (mapped → the computed value, unsupported/post-
273
- // load → undefined) and assert it satisfies AgentSettingsProjection. If a
274
- // field is added to AgentSettingsStoredSchema without an entry here, tsc
275
- // fails with "Property X is missing". This makes "declarative layer forgot
276
- // to wire a field" a compile error — the whole point of the schema. The
277
- // projection object is discarded; the real `settings` (Partial, only the
278
- // non-undefined fields) is what flows to apply.
279
- const _exhaustive = {
280
- models: settings.models,
281
- networkConfig: settings.networkConfig,
282
- nixConfig: settings.nixConfig,
283
- soulMd: settings.soulMd,
284
- userMd: settings.userMd,
285
- identityMd: settings.identityMd,
286
- skillsConfig: settings.skillsConfig,
287
- guardrails: settings.guardrails,
288
- guardrailsInline: settings.guardrailsInline,
289
- sandboxId: settings.sandboxId,
290
- verboseLogging: settings.verboseLogging,
291
- showToolCalls: settings.showToolCalls,
292
- starters: settings.starters,
293
- };
294
- void _exhaustive;
295
262
  return { metadata, settings, providerKeys };
296
263
  }
297
264
  function mapEntityType(entity) {
@@ -416,7 +383,7 @@ const MAX_AUTOMATION_SKILLS = 5;
416
383
  * content (the incoming message/event), so it may run with zero instructions on
417
384
  * the built-in default. Everything else — schedule triggers, event triggers with
418
385
  * execution "window", and Automations with no triggers at all (manual runs) —
419
- * needs a prompt, at least one skill, a reaction script, or a script executor.
386
+ * needs a prompt, at least one skill, a code module.
420
387
  *
421
388
  * This CLI preflight mirrors the server rule, catching the error against the
422
389
  * config file (naming the slug) rather than as a 422 mid-apply. When both
@@ -445,7 +412,7 @@ function assertAutomationSkills(automation, instructionSourceDeclared) {
445
412
  // Any instruction source satisfies the rule. An Automation
446
413
  // whose whole job is "run this skill" has no task statement to write, one
447
414
  // that spells its task out inline needs no skill, and one that runs entirely
448
- // as a reaction or executor script needs neither — demanding two would be
415
+ // as a code module needs neither — demanding two would be
449
416
  // stricter than the server and would reject configs the API accepts. The
450
417
  // mapper runs BEFORE the loader reads either file, so this boolean is the
451
418
  // config marker; the loader validates the file and the server enforces the
@@ -454,10 +421,30 @@ function assertAutomationSkills(automation, instructionSourceDeclared) {
454
421
  skills.length === 0 &&
455
422
  !automation.prompt.trim() &&
456
423
  !instructionSourceDeclared) {
457
- throw new ValidationError(`Automation "${automation.slug}" needs instructions: schedule triggers, event triggers with execution "window", and Automations with no triggers run on stored instructions alone, so give it a "prompt", at least one skill, a reaction script, or a script executor. Only event triggers with execution "turn" may omit all instruction sources.`);
424
+ throw new ValidationError(`Automation "${automation.slug}" needs instructions: schedule triggers, event triggers with execution "window", and Automations with no triggers run on stored instructions alone, so give it a "prompt", at least one skill, a code module. Only event triggers with execution "turn" may omit all instruction sources.`);
458
425
  }
459
426
  }
460
427
  function mapAutomation(automation) {
428
+ if (Object.hasOwn(automation, "executor")) {
429
+ throw new ValidationError(`Automation "${automation.slug}": executor is retired; use reactionFromFile("./job.ts") and clear a legacy configuration explicitly with executionConfig: null.`);
430
+ }
431
+ if (automation.executionConfig !== undefined) {
432
+ if (automation.model !== undefined) {
433
+ throw new ValidationError(`Automation "${automation.slug}" must declare either executionConfig or the model helper, not both`);
434
+ }
435
+ if (automation.executionConfig !== null &&
436
+ !Value.Check(AutomationExecutionConfigSchema, automation.executionConfig)) {
437
+ const error = Value.Errors(AutomationExecutionConfigSchema, automation.executionConfig).First();
438
+ throw new ValidationError(`Automation "${automation.slug}" executionConfig${error?.path ?? ""}: ${error?.message ?? "invalid execution options"}`);
439
+ }
440
+ }
441
+ let agentKind;
442
+ if (automation.agentKind !== undefined) {
443
+ if (!Value.Check(ManageAutomationsSchema.properties.agent_kind, automation.agentKind)) {
444
+ throw new ValidationError(`Automation "${automation.slug}" has an invalid agentKind: ${automation.agentKind}`);
445
+ }
446
+ agentKind = automation.agentKind;
447
+ }
461
448
  const sources = automation.sources
462
449
  ? Object.entries(automation.sources).map(([name, value]) => {
463
450
  if (typeof value === "string")
@@ -525,8 +512,7 @@ function mapAutomation(automation) {
525
512
  });
526
513
  return {
527
514
  slug: automation.slug,
528
- agent: agentId(automation.agent),
529
- ...(automation.executor === "agent" ? { executor: null } : {}),
515
+ agent: automation.agent == null ? null : agentId(automation.agent),
530
516
  // The author's task statement, carried straight through. Skill BODIES are
531
517
  // no longer folded in here — the loader resolves them into `skillSnapshots`
532
518
  // (see `resolveAutomationSkills` in desired-state.ts), because the mapper is
@@ -552,11 +538,14 @@ function mapAutomation(automation) {
552
538
  ...(automation.reactionsGuidance
553
539
  ? { reactionsGuidance: automation.reactionsGuidance }
554
540
  : {}),
555
- ...(automation.agentKind ? { agentKind: automation.agentKind } : {}),
541
+ ...(agentKind ? { agentKind } : {}),
556
542
  ...(automation.deviceWorkerId !== undefined
557
543
  ? { deviceWorkerId: automation.deviceWorkerId }
558
544
  : {}),
559
545
  ...(automation.model !== undefined ? { model: automation.model } : {}),
546
+ ...(automation.executionConfig !== undefined
547
+ ? { executionConfig: automation.executionConfig }
548
+ : {}),
560
549
  };
561
550
  }
562
551
  function mapAuthProfile(profile, required, env) {
@@ -752,7 +741,7 @@ export function mapProjectToDesiredState(project, env = process.env, only) {
752
741
  const automation = automations[i];
753
742
  if (!automation)
754
743
  continue;
755
- if (!agentIds.has(automation.agent)) {
744
+ if (automation.agent != null && !agentIds.has(automation.agent)) {
756
745
  throw new ValidationError(`Automation "${automation.slug}" names agent "${automation.agent}", but no agent with that id is declared in lobu.config.ts`);
757
746
  }
758
747
  // The config's `reaction` marker (from `reactionFromFile(path)`) drives the
@@ -760,10 +749,8 @@ export function mapProjectToDesiredState(project, env = process.env, only) {
760
749
  // later by the loader. `automations` is index-aligned with
761
750
  // `project.automations` (the mapper maps in order). An explicit
762
751
  // `reaction: null` is a removal, not an instruction source.
763
- assertAutomationSkills(automation, (project.automations?.[i]?.reaction !== undefined &&
764
- project.automations?.[i]?.reaction !== null) ||
765
- (project.automations?.[i]?.executor !== undefined &&
766
- project.automations?.[i]?.executor !== "agent"));
752
+ assertAutomationSkills(automation, project.automations?.[i]?.reaction !== undefined &&
753
+ project.automations?.[i]?.reaction !== null);
767
754
  for (const trigger of automation.triggers ?? []) {
768
755
  if (trigger.kind !== "event" ||
769
756
  trigger.source === "workspace" ||
@@ -1,3 +1,4 @@
1
+ import type { AutomationExecutionConfig, LegacyAutomationExecutionConfig } from "@lobu/core/contracts/tools/manage-automations";
1
2
  /**
2
3
  * Shared structural types + tiny helpers used across the apply pipeline
3
4
  * (desired-state IR, wire client, diff, apply-cmd).
@@ -30,12 +31,8 @@ export interface AutomationSource {
30
31
  context?: boolean;
31
32
  }
32
33
  export declare function isRecord(value: unknown): value is Record<string, unknown>;
33
- /** Apply declared model/executor fields while preserving unmanaged execution options. */
34
- export declare function automationExecutionConfig(model: string | null | undefined, remote?: Record<string, unknown> | null, executor?: {
35
- kind: "script";
36
- source: string;
37
- params?: Record<string, unknown>;
38
- } | null): Record<string, unknown> | null;
34
+ /** Preserve omitted options; replacing a legacy definition must be explicit. */
35
+ export declare function automationExecutionConfig(model: string | null | undefined, remote?: LegacyAutomationExecutionConfig | null, declared?: AutomationExecutionConfig | null): LegacyAutomationExecutionConfig | null;
39
36
  /**
40
37
  * Keys of locally-declared connector definitions whose key is already known.
41
38
  * A `null` key (an auto-discovered `*.connector.ts` the server compiles) can't