@openpalm/lib 0.9.8 → 0.10.1

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 (56) hide show
  1. package/README.md +31 -71
  2. package/package.json +1 -1
  3. package/src/control-plane/audit.ts +4 -4
  4. package/src/control-plane/backup.ts +31 -0
  5. package/src/control-plane/channels.ts +88 -156
  6. package/src/control-plane/cleanup-guardrails.test.ts +289 -0
  7. package/src/control-plane/compose-args.test.ts +170 -0
  8. package/src/control-plane/compose-args.ts +57 -0
  9. package/src/control-plane/config-persistence.ts +270 -0
  10. package/src/control-plane/core-assets.ts +58 -234
  11. package/src/control-plane/crypto.ts +14 -0
  12. package/src/control-plane/docker.ts +94 -204
  13. package/src/control-plane/env-schema-validation.test.ts +118 -0
  14. package/src/control-plane/extends-support.test.ts +105 -0
  15. package/src/control-plane/home.ts +133 -0
  16. package/src/control-plane/install-edge-cases.test.ts +314 -717
  17. package/src/control-plane/lifecycle.ts +215 -233
  18. package/src/control-plane/lock.test.ts +194 -0
  19. package/src/control-plane/lock.ts +176 -0
  20. package/src/control-plane/memory-config.ts +34 -160
  21. package/src/control-plane/opencode-client.test.ts +154 -0
  22. package/src/control-plane/opencode-client.ts +113 -0
  23. package/src/control-plane/provider-config.ts +34 -0
  24. package/src/control-plane/redact-schema.ts +50 -0
  25. package/src/control-plane/registry-components.test.ts +313 -0
  26. package/src/control-plane/registry.test.ts +414 -0
  27. package/src/control-plane/registry.ts +418 -0
  28. package/src/control-plane/rollback.ts +128 -0
  29. package/src/control-plane/scheduler.ts +18 -190
  30. package/src/control-plane/secret-backend.test.ts +359 -0
  31. package/src/control-plane/secret-backend.ts +322 -0
  32. package/src/control-plane/secret-mappings.ts +185 -0
  33. package/src/control-plane/secrets.ts +186 -112
  34. package/src/control-plane/setup-config.schema.json +306 -0
  35. package/src/control-plane/setup-status.ts +15 -8
  36. package/src/control-plane/setup-validation.ts +90 -0
  37. package/src/control-plane/setup.test.ts +336 -929
  38. package/src/control-plane/setup.ts +159 -849
  39. package/src/control-plane/spec-to-env.test.ts +100 -0
  40. package/src/control-plane/spec-to-env.ts +195 -0
  41. package/src/control-plane/spec-validator.ts +159 -0
  42. package/src/control-plane/stack-spec.test.ts +150 -0
  43. package/src/control-plane/stack-spec.ts +101 -22
  44. package/src/control-plane/types.ts +6 -99
  45. package/src/control-plane/validate.ts +107 -0
  46. package/src/index.ts +101 -159
  47. package/src/provider-constants.ts +2 -31
  48. package/src/control-plane/connection-mapping.ts +0 -191
  49. package/src/control-plane/connection-migration-flags.ts +0 -40
  50. package/src/control-plane/connection-profiles.ts +0 -317
  51. package/src/control-plane/core-asset-provider.ts +0 -21
  52. package/src/control-plane/fs-asset-provider.ts +0 -65
  53. package/src/control-plane/fs-registry-provider.ts +0 -46
  54. package/src/control-plane/paths.ts +0 -77
  55. package/src/control-plane/registry-provider.ts +0 -19
  56. package/src/control-plane/staging.ts +0 -399
package/src/index.ts CHANGED
@@ -9,15 +9,7 @@
9
9
  // ── Provider Constants ──────────────────────────────────────────────────
10
10
  export {
11
11
  LLM_PROVIDERS,
12
- PROVIDER_DEFAULT_URLS,
13
- PROVIDER_KEY_MAP,
14
12
  EMBEDDING_DIMS,
15
- PROVIDER_LABELS,
16
- mem0ProviderName,
17
- mem0BaseUrlConfig,
18
- OLLAMA_DEFAULT_MODELS,
19
- OLLAMA_INSTACK_URL,
20
- LOCAL_PROVIDER_HELP,
21
13
  } from "./provider-constants.js";
22
14
 
23
15
  // ── Logger ──────────────────────────────────────────────────────────────
@@ -31,45 +23,58 @@ export type {
31
23
  AccessScope,
32
24
  ChannelInfo,
33
25
  CallerType,
34
- ConnectionKind,
35
- ConnectionAuthMode,
36
26
  ArtifactMeta,
37
27
  AuditEntry,
38
- RequiredCapability,
39
- OptionalCapability,
40
- Capability,
41
- LlmAssignment,
42
- EmbeddingsAssignment,
43
- RerankerAssignment,
44
- TtsAssignment,
45
- SttAssignment,
46
- CapabilityAssignments,
47
- CanonicalConnectionProfile,
48
- CanonicalConnectionsDocument,
49
28
  } from "./control-plane/types.js";
50
29
  export {
51
30
  CORE_SERVICES,
52
31
  OPTIONAL_SERVICES,
53
- CONNECTION_KINDS,
54
- REQUIRED_CAPABILITIES,
55
- OPTIONAL_CAPABILITIES,
56
32
  } from "./control-plane/types.js";
57
33
 
58
- // ── Interfaces ──────────────────────────────────────────────────────────
59
- export type { CoreAssetProvider } from "./control-plane/core-asset-provider.js";
60
- export type { RegistryProvider } from "./control-plane/registry-provider.js";
34
+ // ── Backups ───────────────────────────────────────────────────────────────
35
+ export {
36
+ backupOpenPalmHome,
37
+ } from "./control-plane/backup.js";
61
38
 
62
- // ── Filesystem Providers ────────────────────────────────────────────────
63
- export { FilesystemAssetProvider } from "./control-plane/fs-asset-provider.js";
64
- export { FilesystemRegistryProvider } from "./control-plane/fs-registry-provider.js";
39
+ // ── Registry Catalog ─────────────────────────────────────────────────────
40
+ export type {
41
+ AddonMutationResult,
42
+ RegistryAutomationEntry,
43
+ RegistryComponentEntry,
44
+ RegistryAddonConfig,
45
+ RegistryCatalogVerification,
46
+ } from "./control-plane/registry.js";
47
+ export {
48
+ materializeRegistryCatalog,
49
+ refreshRegistryCatalog,
50
+ verifyRegistryCatalog,
51
+ discoverRegistryComponents,
52
+ discoverRegistryAutomations,
53
+ getRegistryAutomation,
54
+ getRegistryAddonConfig,
55
+ getAddonServiceNames,
56
+ listAvailableAddonIds,
57
+ listEnabledAddonIds,
58
+ enableAddon,
59
+ disableAddonByName,
60
+ setAddonEnabled,
61
+ installAutomationFromRegistry,
62
+ uninstallAutomation,
63
+ } from "./control-plane/registry.js";
65
64
 
66
- // ── Paths ───────────────────────────────────────────────────────────────
65
+ // ── Home Layout (v0.10.0) ───────────────────────────────────────────────
67
66
  export {
68
- resolveConfigHome,
69
- resolveStateHome,
70
- resolveDataHome,
71
- ensureXdgDirs,
72
- } from "./control-plane/paths.js";
67
+ resolveOpenPalmHome,
68
+ resolveConfigDir,
69
+ resolveVaultDir,
70
+ resolveDataDir,
71
+ resolveLogsDir,
72
+ resolveCacheHome,
73
+ resolveRegistryDir,
74
+ resolveRegistryAddonsDir,
75
+ resolveRegistryAutomationsDir,
76
+ ensureHomeDirs,
77
+ } from "./control-plane/home.js";
73
78
 
74
79
  // ── Env ─────────────────────────────────────────────────────────────────
75
80
  export {
@@ -81,24 +86,26 @@ export {
81
86
  // ── Audit ───────────────────────────────────────────────────────────────
82
87
  export { appendAudit } from "./control-plane/audit.js";
83
88
 
89
+ // ── OpenCode Client ─────────────────────────────────────────────────────
90
+ export { createOpenCodeClient } from "./control-plane/opencode-client.js";
91
+ export type { ProxyResult, OpenCodeProvider } from "./control-plane/opencode-client.js";
92
+
84
93
  // ── Secrets ─────────────────────────────────────────────────────────────
85
94
  export {
86
- ALLOWED_CONNECTION_KEYS,
87
- REQUIRED_LLM_PROVIDER_KEYS,
88
95
  PLAIN_CONFIG_KEYS,
89
96
  ensureSecrets,
90
97
  updateSecretsEnv,
91
- readSecretsEnvFile,
98
+ readStackEnv,
92
99
  patchSecretsEnvFile,
93
- maskConnectionValue,
94
- loadSecretsEnvFile,
100
+ maskSecretValue,
95
101
  ensureOpenCodeConfig,
96
102
  } from "./control-plane/secrets.js";
97
-
103
+ export {
104
+ detectSecretBackend,
105
+ validatePassEntryName,
106
+ } from "./control-plane/secret-backend.js";
98
107
  // ── Setup Status ────────────────────────────────────────────────────────
99
108
  export {
100
- readSecretsKeys,
101
- detectUserId,
102
109
  isSetupComplete,
103
110
  } from "./control-plane/setup-status.js";
104
111
 
@@ -107,61 +114,12 @@ export {
107
114
  discoverChannels,
108
115
  isAllowedService,
109
116
  isValidChannel,
110
- installChannelFromRegistry,
111
- uninstallChannel,
112
- installAutomationFromRegistry,
113
- uninstallAutomation,
117
+ isChannelAddon,
114
118
  } from "./control-plane/channels.js";
115
119
 
116
- // ── Connection Profiles ─────────────────────────────────────────────────
117
- export {
118
- getConnectionProfilesDir,
119
- getConnectionProfilesPath,
120
- writeConnectionProfilesDocument,
121
- readConnectionProfilesDocument,
122
- ensureConnectionProfilesStore,
123
- writeConnectionsDocument,
124
- listConnectionProfiles,
125
- getCapabilityAssignments,
126
- createConnectionProfile,
127
- updateConnectionProfile,
128
- deleteConnectionProfile,
129
- saveCapabilityAssignments,
130
- } from "./control-plane/connection-profiles.js";
131
- export type { WriteConnectionsInput } from "./control-plane/connection-profiles.js";
132
-
133
- // ── Connection Mapping ──────────────────────────────────────────────────
134
- export {
135
- buildOpenCodeMapping,
136
- writeOpenCodeProviderConfig,
137
- buildMem0Mapping,
138
- resolveApiKeyRef,
139
- buildMem0MappingFromProfiles,
140
- } from "./control-plane/connection-mapping.js";
141
- export type {
142
- OpenCodeConnectionMappingInput,
143
- OpenCodeConnectionMapping,
144
- Mem0ConnectionMappingInput,
145
- Mem0ConnectionMapping,
146
- } from "./control-plane/connection-mapping.js";
147
-
148
- // ── Connection Migration Flags ──────────────────────────────────────────
149
- export type {
150
- ConnectionMigrationFlags,
151
- ConnectionCompatibilityMode,
152
- } from "./control-plane/connection-migration-flags.js";
153
- export {
154
- readConnectionMigrationFlags,
155
- detectConnectionCompatibilityMode,
156
- } from "./control-plane/connection-migration-flags.js";
157
-
158
120
  // ── Memory Config ───────────────────────────────────────────────────────
159
121
  export type {
160
122
  MemoryConfig,
161
- ModelDiscoveryReason,
162
- ProviderModelsResult,
163
- VectorDimensionResult,
164
- QdrantDimensionResult,
165
123
  } from "./control-plane/memory-config.js";
166
124
  export {
167
125
  EMBED_PROVIDERS,
@@ -171,80 +129,70 @@ export {
171
129
  readMemoryConfig,
172
130
  writeMemoryConfig,
173
131
  ensureMemoryConfig,
174
- resolveConfigForPush,
175
132
  checkVectorDimensions,
176
- checkQdrantDimensions,
177
133
  resetVectorStore,
178
- resetQdrantCollection,
179
- pushConfigToMemory,
180
- fetchConfigFromMemory,
181
134
  provisionMemoryUser,
182
135
  } from "./control-plane/memory-config.js";
183
136
 
184
137
  // ── Core Assets ─────────────────────────────────────────────────────────
185
138
  export {
186
- PUBLIC_ACCESS_IMPORT,
187
- LAN_ONLY_IMPORT,
188
- ensureCoreCaddyfile,
189
- readCoreCaddyfile,
190
- ensureSecretsSchema,
191
- ensureStackSchema,
192
- detectAccessScope,
193
- setCoreCaddyAccessScope,
139
+ ensureUserEnvSchema,
140
+ ensureSystemEnvSchema,
194
141
  ensureMemoryDir,
195
142
  ensureCoreCompose,
196
143
  readCoreCompose,
197
- ensureOllamaCompose,
198
- readOllamaCompose,
199
- ensureAdminCompose,
200
- readAdminCompose,
201
144
  ensureOpenCodeSystemConfig,
202
- ensureAdminOpenCodeConfig,
203
- ensureCoreAutomations,
204
145
  refreshCoreAssets,
205
146
  } from "./control-plane/core-assets.js";
206
147
 
207
- // ── Staging ─────────────────────────────────────────────────────────────
148
+ // ── Configuration Persistence ────────────────────────────────────────────
208
149
  export {
209
150
  sha256,
210
151
  randomHex,
211
- isOllamaEnabled,
212
- isAdminEnabled,
213
- stagedEnvFile,
214
- stagedStackEnvFile,
215
152
  buildEnvFiles,
216
- discoverStagedChannelYmls,
217
- stageArtifacts,
218
- buildArtifactMeta,
219
- persistArtifacts,
220
- withDefaultLanOnly,
221
- stageChannelCaddyfiles,
222
- stageChannelYmlFiles,
223
- stageSecretsEnv,
224
- stageAutomationFiles,
225
- } from "./control-plane/staging.js";
153
+ discoverStackOverlays,
154
+ resolveRuntimeFiles,
155
+ buildRuntimeFileMeta,
156
+ writeRuntimeFiles,
157
+ writeSystemEnv,
158
+ readChannelSecrets,
159
+ writeChannelSecrets,
160
+ } from "./control-plane/config-persistence.js";
161
+
162
+ // ── Rollback ─────────────────────────────────────────────────────────────
163
+ export {
164
+ restoreSnapshot,
165
+ hasSnapshot,
166
+ snapshotTimestamp,
167
+ } from "./control-plane/rollback.js";
168
+
169
+ // ── Validation ───────────────────────────────────────────────────────────
170
+ export {
171
+ validateProposedState,
172
+ } from "./control-plane/validate.js";
226
173
 
227
174
  // ── Lifecycle ───────────────────────────────────────────────────────────
228
175
  export {
229
176
  createState,
230
- writeSetupTokenFile,
231
177
  applyInstall,
232
178
  applyUpdate,
233
179
  applyUninstall,
234
180
  applyUpgrade,
181
+ performUpgrade,
235
182
  updateStackEnvToLatestImageTag,
236
183
  buildComposeFileList,
237
184
  buildManagedServices,
238
185
  normalizeCaller,
239
- isAllowedAction,
240
- validateEnvironment,
241
186
  } from "./control-plane/lifecycle.js";
187
+ export type { UpgradeResult } from "./control-plane/lifecycle.js";
242
188
 
243
189
  // ── Docker ──────────────────────────────────────────────────────────────
244
190
  export type { DockerResult } from "./control-plane/docker.js";
245
191
  export {
246
192
  checkDocker,
247
193
  checkDockerCompose,
194
+ resolveComposeProjectName,
195
+ composePreflight,
248
196
  composeUp,
249
197
  composeDown,
250
198
  composeRestart,
@@ -252,7 +200,6 @@ export {
252
200
  composeStart,
253
201
  composePs,
254
202
  composeLogs,
255
- caddyReload,
256
203
  composePullService,
257
204
  composePull,
258
205
  composeStats,
@@ -269,57 +216,52 @@ export type {
269
216
  } from "./control-plane/scheduler.js";
270
217
  export {
271
218
  SCHEDULE_PRESETS,
272
- SAFE_PATH_RE,
273
219
  resolveSchedule,
274
220
  parseAutomationYaml,
275
221
  loadAutomations,
276
222
  executeAction,
277
- startScheduler,
278
- stopScheduler,
279
- reloadScheduler,
280
- getSchedulerStatus,
281
- getExecutionLog,
282
- getAllExecutionLogs,
283
223
  } from "./control-plane/scheduler.js";
284
224
 
285
225
  // ── Model Runner (local provider detection) ─────────────────────────────
286
226
  export type { LocalProviderDetection } from "./control-plane/model-runner.js";
287
227
  export { detectLocalProviders } from "./control-plane/model-runner.js";
288
228
 
289
- // ── Stack Spec ───────────────────────────────────────────────────────────
229
+ // ── Compose Arguments ────────────────────────────────────────────────────
230
+ export {
231
+ buildComposeOptions,
232
+ buildComposeCliArgs,
233
+ } from "./control-plane/compose-args.js";
234
+
235
+ // ── Stack Spec (v2) ──────────────────────────────────────────────────────
290
236
  export type {
291
237
  StackSpec,
292
- StackSpecConnection,
293
- StackSpecAssignments,
238
+ StackSpecCapabilities,
239
+ StackSpecEmbeddings,
240
+ StackSpecMemory,
241
+ StackSpecTts,
242
+ StackSpecStt,
243
+ StackSpecReranker,
294
244
  } from "./control-plane/stack-spec.js";
295
245
  export {
296
246
  STACK_SPEC_FILENAME,
297
- stackSpecPath,
298
247
  writeStackSpec,
299
248
  readStackSpec,
249
+ updateCapability,
250
+ parseCapabilityString,
251
+ formatCapabilityString,
300
252
  } from "./control-plane/stack-spec.js";
301
253
 
254
+ // ── Spec-to-Env Derivation ──────────────────────────────────────────────
255
+ export {
256
+ writeCapabilityVars,
257
+ } from "./control-plane/spec-to-env.js";
258
+
302
259
  // ── Setup ────────────────────────────────────────────────────────────────
303
260
  export type {
261
+ SetupSpec,
304
262
  SetupConnection,
305
- SetupAssignments,
306
- SetupInput,
307
263
  SetupResult,
308
- DetectedProvider,
309
- SetupConfig,
310
- SetupConfigAssignments,
311
- ChannelCredentials,
312
- ServiceConfig,
313
264
  } from "./control-plane/setup.js";
314
265
  export {
315
- validateSetupInput,
316
- buildSecretsFromSetup,
317
- buildConnectionEnvVarMap,
318
266
  performSetup,
319
- detectProviders,
320
- CHANNEL_CREDENTIAL_ENV_MAP,
321
- validateSetupConfig,
322
- normalizeToSetupInput,
323
- performSetupFromConfig,
324
- buildChannelCredentialEnvVars,
325
267
  } from "./control-plane/setup.js";
@@ -9,7 +9,7 @@
9
9
  export const LLM_PROVIDERS = [
10
10
  "openai", "anthropic", "ollama", "groq", "together",
11
11
  "mistral", "deepseek", "xai", "lmstudio", "model-runner",
12
- "google", "huggingface"
12
+ "google", "huggingface", "openai-compatible",
13
13
  ] as const;
14
14
 
15
15
  /** Default base URLs per provider. */
@@ -67,38 +67,9 @@ export const PROVIDER_LABELS: Record<string, string> = {
67
67
  "model-runner": "Docker Model Runner",
68
68
  google: "Google AI",
69
69
  huggingface: "Hugging Face",
70
+ "openai-compatible": "Custom (OpenAI-compatible)",
70
71
  };
71
72
 
72
- /**
73
- * Map provider name → memory-package-compatible provider name.
74
- * The memory package (@openpalm/memory) has native adapters for openai,
75
- * ollama, and lmstudio. model-runner speaks OpenAI protocol so it maps
76
- * to "openai". Ollama has its own adapter. LM Studio has its own adapter
77
- * that avoids response_format (which LM Studio doesn't reliably support).
78
- */
79
- export function mem0ProviderName(provider: string): string {
80
- if (provider === "model-runner") return "openai";
81
- if (provider === "ollama") return "ollama";
82
- if (provider === "lmstudio") return "lmstudio";
83
- return provider;
84
- }
85
-
86
- /**
87
- * Map provider/base URL input to the mem0 config key/value pair.
88
- * All local providers (Ollama, Model Runner, LM Studio) use the OpenAI-compatible
89
- * endpoint, so we always set openai_base_url with a /v1 suffix.
90
- */
91
- export function mem0BaseUrlConfig(
92
- _provider: string,
93
- baseUrl: string
94
- ): { key: "openai_base_url"; value: string } | null {
95
- const trimmed = baseUrl.trim();
96
- if (!trimmed) return null;
97
-
98
- const normalized = trimmed.replace(/\/+$/, "").replace(/\/v1$/, "");
99
- return { key: "openai_base_url", value: `${normalized}/v1` };
100
- }
101
-
102
73
  /** Default models to pull when enabling Ollama from the wizard. */
103
74
  export const OLLAMA_DEFAULT_MODELS = {
104
75
  chat: "llama3.2:latest",
@@ -1,191 +0,0 @@
1
- import { mkdirSync, writeFileSync, readFileSync } from 'node:fs';
2
- import { mem0BaseUrlConfig, mem0ProviderName } from '../provider-constants.js';
3
- import type { MemoryConfig } from './memory-config.js';
4
- import type { CanonicalConnectionProfile } from './types.js';
5
-
6
- export type OpenCodeConnectionMappingInput = {
7
- provider: string;
8
- baseUrl: string;
9
- systemModel: string;
10
- smallModel?: string;
11
- };
12
-
13
- export type OpenCodeConnectionMapping = {
14
- provider: string;
15
- model: string;
16
- smallModel: string;
17
- options?: {
18
- baseURL?: string;
19
- };
20
- };
21
-
22
- export type Mem0ConnectionMappingInput = {
23
- llm: {
24
- provider: string;
25
- baseUrl: string;
26
- model: string;
27
- apiKeyRef: string;
28
- };
29
- embedder: {
30
- provider: string;
31
- baseUrl: string;
32
- model: string;
33
- apiKeyRef: string;
34
- };
35
- embeddingDims: number;
36
- customInstructions: string;
37
- };
38
-
39
- export type Mem0ConnectionMapping = MemoryConfig;
40
-
41
- export function buildOpenCodeMapping(input: OpenCodeConnectionMappingInput): OpenCodeConnectionMapping {
42
- const normalizedBaseUrl = input.baseUrl.trim();
43
- return {
44
- provider: input.provider,
45
- model: input.systemModel,
46
- smallModel: input.smallModel ?? input.systemModel,
47
- ...(normalizedBaseUrl ? { options: { baseURL: normalizedBaseUrl } } : {}),
48
- };
49
- }
50
-
51
- export function writeOpenCodeProviderConfig(
52
- configDir: string,
53
- mapping: OpenCodeConnectionMapping,
54
- ): void {
55
- const assistantDir = `${configDir}/assistant`;
56
- mkdirSync(assistantDir, { recursive: true });
57
-
58
- const configPath = `${assistantDir}/opencode.json`;
59
-
60
- let existing: Record<string, unknown> = { $schema: 'https://opencode.ai/config.json' };
61
- let raw: string | undefined;
62
- try {
63
- raw = readFileSync(configPath, 'utf-8');
64
- } catch (err) {
65
- const nodeErr = err as NodeJS.ErrnoException;
66
- if (nodeErr.code !== 'ENOENT') {
67
- return;
68
- }
69
- }
70
-
71
- if (raw !== undefined) {
72
- try {
73
- existing = JSON.parse(raw) as Record<string, unknown>;
74
- } catch {
75
- return;
76
- }
77
- }
78
-
79
- const existingProviders =
80
- (existing as { providers?: Record<string, unknown> }).providers ?? {};
81
- const existingProviderConfig =
82
- (existingProviders as Record<string, unknown>)[mapping.provider] ?? {};
83
- const existingOptions =
84
- (existingProviderConfig as { options?: Record<string, unknown> }).options ?? {};
85
- const updatedOptions: Record<string, unknown> = { ...existingOptions };
86
- const mappingBaseUrl = mapping.options?.baseURL?.trim();
87
-
88
- if (mappingBaseUrl) {
89
- updatedOptions.baseURL = mappingBaseUrl;
90
- } else {
91
- delete (updatedOptions as { baseURL?: unknown }).baseURL;
92
- }
93
-
94
- const updatedProviderConfig: Record<string, unknown> = {
95
- ...existingProviderConfig as Record<string, unknown>,
96
- ...(Object.keys(updatedOptions).length > 0 ? { options: updatedOptions } : {}),
97
- };
98
-
99
- const updated = {
100
- ...existing,
101
- model: mapping.model,
102
- smallModel: mapping.smallModel,
103
- providers: {
104
- ...existingProviders,
105
- [mapping.provider]: updatedProviderConfig,
106
- },
107
- };
108
-
109
- writeFileSync(configPath, JSON.stringify(updated, null, 2) + '\n');
110
- }
111
-
112
- export function buildMem0Mapping(input: Mem0ConnectionMappingInput): Mem0ConnectionMapping {
113
- const llmConfig: Record<string, unknown> = {
114
- model: input.llm.model,
115
- temperature: 0.1,
116
- max_tokens: 2000,
117
- api_key: input.llm.apiKeyRef,
118
- };
119
-
120
- const llmBaseUrlConfig = mem0BaseUrlConfig(input.llm.provider, input.llm.baseUrl);
121
- if (llmBaseUrlConfig) {
122
- llmConfig[llmBaseUrlConfig.key] = llmBaseUrlConfig.value;
123
- }
124
-
125
- const embedConfig: Record<string, unknown> = {
126
- model: input.embedder.model,
127
- api_key: input.embedder.apiKeyRef,
128
- };
129
-
130
- const embedBaseUrlConfig = mem0BaseUrlConfig(input.embedder.provider, input.embedder.baseUrl);
131
- if (embedBaseUrlConfig) {
132
- embedConfig[embedBaseUrlConfig.key] = embedBaseUrlConfig.value;
133
- }
134
-
135
- return {
136
- mem0: {
137
- llm: {
138
- provider: mem0ProviderName(input.llm.provider),
139
- config: llmConfig,
140
- },
141
- embedder: {
142
- provider: mem0ProviderName(input.embedder.provider),
143
- config: embedConfig,
144
- },
145
- vector_store: {
146
- provider: 'sqlite-vec',
147
- config: {
148
- collection_name: 'memory',
149
- db_path: '/data/memory.db',
150
- embedding_model_dims: input.embeddingDims,
151
- },
152
- },
153
- },
154
- memory: {
155
- custom_instructions: input.customInstructions,
156
- },
157
- };
158
- }
159
-
160
- export function resolveApiKeyRef(profile: CanonicalConnectionProfile): string {
161
- if (profile.auth.mode === 'api_key' && profile.auth.apiKeySecretRef) {
162
- return profile.auth.apiKeySecretRef;
163
- }
164
- return 'not-needed';
165
- }
166
-
167
- export function buildMem0MappingFromProfiles(
168
- llmProfile: CanonicalConnectionProfile,
169
- embedProfile: CanonicalConnectionProfile,
170
- llmModel: string,
171
- embedModel: string,
172
- embeddingDims: number,
173
- customInstructions: string,
174
- ): Mem0ConnectionMapping {
175
- return buildMem0Mapping({
176
- llm: {
177
- provider: llmProfile.provider,
178
- baseUrl: llmProfile.baseUrl,
179
- model: llmModel,
180
- apiKeyRef: resolveApiKeyRef(llmProfile),
181
- },
182
- embedder: {
183
- provider: embedProfile.provider,
184
- baseUrl: embedProfile.baseUrl,
185
- model: embedModel,
186
- apiKeyRef: resolveApiKeyRef(embedProfile),
187
- },
188
- embeddingDims,
189
- customInstructions,
190
- });
191
- }
@@ -1,40 +0,0 @@
1
- type ConnectionCompatibilityMode =
2
- | 'legacy_patch'
3
- | 'legacy_unified'
4
- | 'canonical_dto';
5
-
6
- export type ConnectionMigrationFlags = {
7
- enabled: boolean;
8
- dualRead: boolean;
9
- dualWrite: boolean;
10
- preferLegacyRead: boolean;
11
- annotateAudit: boolean;
12
- };
13
-
14
- function envFlag(name: string, fallback: boolean): boolean {
15
- const raw = process.env[name];
16
- if (!raw) return fallback;
17
- return ['1', 'true', 'yes', 'on'].includes(raw.toLowerCase());
18
- }
19
-
20
- export function readConnectionMigrationFlags(): ConnectionMigrationFlags {
21
- return {
22
- enabled: envFlag('OPENPALM_CONNECTION_MIGRATION_ENABLED', true),
23
- dualRead: envFlag('OPENPALM_CONNECTION_MIGRATION_DUAL_READ', true),
24
- dualWrite: envFlag('OPENPALM_CONNECTION_MIGRATION_DUAL_WRITE', true),
25
- preferLegacyRead: envFlag('OPENPALM_CONNECTION_MIGRATION_PREFER_LEGACY_READ', false),
26
- annotateAudit: envFlag('OPENPALM_CONNECTION_MIGRATION_AUDIT_ANNOTATION', true),
27
- };
28
- }
29
-
30
- export function detectConnectionCompatibilityMode(body: Record<string, unknown>): ConnectionCompatibilityMode {
31
- if (Array.isArray(body.profiles) && typeof body.assignments === 'object' && body.assignments !== null) {
32
- return 'canonical_dto';
33
- }
34
- if (typeof body.provider === 'string') {
35
- return 'legacy_unified';
36
- }
37
- return 'legacy_patch';
38
- }
39
-
40
- export type { ConnectionCompatibilityMode };