@openpalm/lib 0.9.4
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.
- package/README.md +83 -0
- package/package.json +30 -0
- package/src/control-plane/audit.ts +40 -0
- package/src/control-plane/channels.ts +196 -0
- package/src/control-plane/connection-mapping.ts +191 -0
- package/src/control-plane/connection-migration-flags.ts +40 -0
- package/src/control-plane/connection-profiles.ts +317 -0
- package/src/control-plane/core-asset-provider.ts +20 -0
- package/src/control-plane/core-assets.ts +292 -0
- package/src/control-plane/docker.ts +448 -0
- package/src/control-plane/env.ts +70 -0
- package/src/control-plane/fs-asset-provider.ts +61 -0
- package/src/control-plane/fs-registry-provider.ts +46 -0
- package/src/control-plane/lifecycle.ts +373 -0
- package/src/control-plane/memory-config.ts +424 -0
- package/src/control-plane/model-runner.ts +101 -0
- package/src/control-plane/paths.ts +77 -0
- package/src/control-plane/registry-provider.ts +19 -0
- package/src/control-plane/scheduler.ts +498 -0
- package/src/control-plane/secrets.ts +177 -0
- package/src/control-plane/setup-status.ts +31 -0
- package/src/control-plane/setup.test.ts +476 -0
- package/src/control-plane/setup.ts +474 -0
- package/src/control-plane/staging.ts +376 -0
- package/src/control-plane/types.ts +165 -0
- package/src/index.ts +295 -0
- package/src/logger.ts +14 -0
- package/src/provider-constants.ts +106 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @openpalm/lib — shared control-plane library.
|
|
3
|
+
*
|
|
4
|
+
* All portable control-plane logic lives here. Both CLI and admin
|
|
5
|
+
* import from this package. Admin is a thin SvelteKit UI layer;
|
|
6
|
+
* the CLI calls these functions directly.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// ── Provider Constants ──────────────────────────────────────────────────
|
|
10
|
+
export {
|
|
11
|
+
LLM_PROVIDERS,
|
|
12
|
+
PROVIDER_DEFAULT_URLS,
|
|
13
|
+
PROVIDER_KEY_MAP,
|
|
14
|
+
EMBEDDING_DIMS,
|
|
15
|
+
PROVIDER_LABELS,
|
|
16
|
+
mem0ProviderName,
|
|
17
|
+
mem0BaseUrlConfig,
|
|
18
|
+
OLLAMA_DEFAULT_MODELS,
|
|
19
|
+
OLLAMA_INSTACK_URL,
|
|
20
|
+
LOCAL_PROVIDER_HELP,
|
|
21
|
+
} from "./provider-constants.js";
|
|
22
|
+
|
|
23
|
+
// ── Logger ──────────────────────────────────────────────────────────────
|
|
24
|
+
export { createLogger } from "./logger.js";
|
|
25
|
+
|
|
26
|
+
// ── Types ───────────────────────────────────────────────────────────────
|
|
27
|
+
export type {
|
|
28
|
+
ControlPlaneState,
|
|
29
|
+
CoreServiceName,
|
|
30
|
+
OptionalServiceName,
|
|
31
|
+
AccessScope,
|
|
32
|
+
ChannelInfo,
|
|
33
|
+
CallerType,
|
|
34
|
+
ConnectionKind,
|
|
35
|
+
ConnectionAuthMode,
|
|
36
|
+
ArtifactMeta,
|
|
37
|
+
AuditEntry,
|
|
38
|
+
RequiredCapability,
|
|
39
|
+
OptionalCapability,
|
|
40
|
+
Capability,
|
|
41
|
+
LlmAssignment,
|
|
42
|
+
EmbeddingsAssignment,
|
|
43
|
+
RerankerAssignment,
|
|
44
|
+
TtsAssignment,
|
|
45
|
+
SttAssignment,
|
|
46
|
+
CapabilityAssignments,
|
|
47
|
+
CanonicalConnectionProfile,
|
|
48
|
+
CanonicalConnectionsDocument,
|
|
49
|
+
} from "./control-plane/types.js";
|
|
50
|
+
export {
|
|
51
|
+
CORE_SERVICES,
|
|
52
|
+
OPTIONAL_SERVICES,
|
|
53
|
+
CONNECTION_KINDS,
|
|
54
|
+
REQUIRED_CAPABILITIES,
|
|
55
|
+
OPTIONAL_CAPABILITIES,
|
|
56
|
+
} from "./control-plane/types.js";
|
|
57
|
+
|
|
58
|
+
// ── Interfaces ──────────────────────────────────────────────────────────
|
|
59
|
+
export type { CoreAssetProvider } from "./control-plane/core-asset-provider.js";
|
|
60
|
+
export type { RegistryProvider } from "./control-plane/registry-provider.js";
|
|
61
|
+
|
|
62
|
+
// ── Filesystem Providers ────────────────────────────────────────────────
|
|
63
|
+
export { FilesystemAssetProvider } from "./control-plane/fs-asset-provider.js";
|
|
64
|
+
export { FilesystemRegistryProvider } from "./control-plane/fs-registry-provider.js";
|
|
65
|
+
|
|
66
|
+
// ── Paths ───────────────────────────────────────────────────────────────
|
|
67
|
+
export {
|
|
68
|
+
resolveConfigHome,
|
|
69
|
+
resolveStateHome,
|
|
70
|
+
resolveDataHome,
|
|
71
|
+
ensureXdgDirs,
|
|
72
|
+
} from "./control-plane/paths.js";
|
|
73
|
+
|
|
74
|
+
// ── Env ─────────────────────────────────────────────────────────────────
|
|
75
|
+
export {
|
|
76
|
+
parseEnvContent,
|
|
77
|
+
parseEnvFile,
|
|
78
|
+
mergeEnvContent,
|
|
79
|
+
} from "./control-plane/env.js";
|
|
80
|
+
|
|
81
|
+
// ── Audit ───────────────────────────────────────────────────────────────
|
|
82
|
+
export { appendAudit } from "./control-plane/audit.js";
|
|
83
|
+
|
|
84
|
+
// ── Secrets ─────────────────────────────────────────────────────────────
|
|
85
|
+
export {
|
|
86
|
+
ALLOWED_CONNECTION_KEYS,
|
|
87
|
+
REQUIRED_LLM_PROVIDER_KEYS,
|
|
88
|
+
PLAIN_CONFIG_KEYS,
|
|
89
|
+
ensureSecrets,
|
|
90
|
+
updateSecretsEnv,
|
|
91
|
+
readSecretsEnvFile,
|
|
92
|
+
patchSecretsEnvFile,
|
|
93
|
+
maskConnectionValue,
|
|
94
|
+
loadSecretsEnvFile,
|
|
95
|
+
ensureOpenCodeConfig,
|
|
96
|
+
} from "./control-plane/secrets.js";
|
|
97
|
+
|
|
98
|
+
// ── Setup Status ────────────────────────────────────────────────────────
|
|
99
|
+
export {
|
|
100
|
+
readSecretsKeys,
|
|
101
|
+
detectUserId,
|
|
102
|
+
isSetupComplete,
|
|
103
|
+
} from "./control-plane/setup-status.js";
|
|
104
|
+
|
|
105
|
+
// ── Channels ────────────────────────────────────────────────────────────
|
|
106
|
+
export {
|
|
107
|
+
discoverChannels,
|
|
108
|
+
isAllowedService,
|
|
109
|
+
isValidChannel,
|
|
110
|
+
installChannelFromRegistry,
|
|
111
|
+
uninstallChannel,
|
|
112
|
+
installAutomationFromRegistry,
|
|
113
|
+
uninstallAutomation,
|
|
114
|
+
} from "./control-plane/channels.js";
|
|
115
|
+
|
|
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
|
+
// ── Memory Config ───────────────────────────────────────────────────────
|
|
159
|
+
export type {
|
|
160
|
+
MemoryConfig,
|
|
161
|
+
ModelDiscoveryReason,
|
|
162
|
+
ProviderModelsResult,
|
|
163
|
+
VectorDimensionResult,
|
|
164
|
+
QdrantDimensionResult,
|
|
165
|
+
} from "./control-plane/memory-config.js";
|
|
166
|
+
export {
|
|
167
|
+
EMBED_PROVIDERS,
|
|
168
|
+
resolveApiKey,
|
|
169
|
+
fetchProviderModels,
|
|
170
|
+
getDefaultConfig,
|
|
171
|
+
readMemoryConfig,
|
|
172
|
+
writeMemoryConfig,
|
|
173
|
+
ensureMemoryConfig,
|
|
174
|
+
resolveConfigForPush,
|
|
175
|
+
checkVectorDimensions,
|
|
176
|
+
checkQdrantDimensions,
|
|
177
|
+
resetVectorStore,
|
|
178
|
+
resetQdrantCollection,
|
|
179
|
+
pushConfigToMemory,
|
|
180
|
+
fetchConfigFromMemory,
|
|
181
|
+
provisionMemoryUser,
|
|
182
|
+
} from "./control-plane/memory-config.js";
|
|
183
|
+
|
|
184
|
+
// ── Core Assets ─────────────────────────────────────────────────────────
|
|
185
|
+
export {
|
|
186
|
+
PUBLIC_ACCESS_IMPORT,
|
|
187
|
+
LAN_ONLY_IMPORT,
|
|
188
|
+
ensureCoreCaddyfile,
|
|
189
|
+
readCoreCaddyfile,
|
|
190
|
+
ensureSecretsSchema,
|
|
191
|
+
ensureStackSchema,
|
|
192
|
+
detectAccessScope,
|
|
193
|
+
setCoreCaddyAccessScope,
|
|
194
|
+
ensureMemoryDir,
|
|
195
|
+
ensureCoreCompose,
|
|
196
|
+
readCoreCompose,
|
|
197
|
+
ensureOllamaCompose,
|
|
198
|
+
readOllamaCompose,
|
|
199
|
+
ensureOpenCodeSystemConfig,
|
|
200
|
+
ensureAdminOpenCodeConfig,
|
|
201
|
+
ensureCoreAutomations,
|
|
202
|
+
refreshCoreAssets,
|
|
203
|
+
} from "./control-plane/core-assets.js";
|
|
204
|
+
|
|
205
|
+
// ── Staging ─────────────────────────────────────────────────────────────
|
|
206
|
+
export {
|
|
207
|
+
sha256,
|
|
208
|
+
randomHex,
|
|
209
|
+
isOllamaEnabled,
|
|
210
|
+
stagedEnvFile,
|
|
211
|
+
stagedStackEnvFile,
|
|
212
|
+
buildEnvFiles,
|
|
213
|
+
discoverStagedChannelYmls,
|
|
214
|
+
stageArtifacts,
|
|
215
|
+
buildArtifactMeta,
|
|
216
|
+
persistArtifacts,
|
|
217
|
+
} from "./control-plane/staging.js";
|
|
218
|
+
|
|
219
|
+
// ── Lifecycle ───────────────────────────────────────────────────────────
|
|
220
|
+
export {
|
|
221
|
+
createState,
|
|
222
|
+
writeSetupTokenFile,
|
|
223
|
+
applyInstall,
|
|
224
|
+
applyUpdate,
|
|
225
|
+
applyUninstall,
|
|
226
|
+
applyUpgrade,
|
|
227
|
+
updateStackEnvToLatestImageTag,
|
|
228
|
+
buildComposeFileList,
|
|
229
|
+
buildManagedServices,
|
|
230
|
+
normalizeCaller,
|
|
231
|
+
isAllowedAction,
|
|
232
|
+
validateEnvironment,
|
|
233
|
+
} from "./control-plane/lifecycle.js";
|
|
234
|
+
|
|
235
|
+
// ── Docker ──────────────────────────────────────────────────────────────
|
|
236
|
+
export type { DockerResult } from "./control-plane/docker.js";
|
|
237
|
+
export {
|
|
238
|
+
checkDocker,
|
|
239
|
+
checkDockerCompose,
|
|
240
|
+
composeUp,
|
|
241
|
+
composeDown,
|
|
242
|
+
composeRestart,
|
|
243
|
+
composeStop,
|
|
244
|
+
composeStart,
|
|
245
|
+
composePs,
|
|
246
|
+
composeLogs,
|
|
247
|
+
caddyReload,
|
|
248
|
+
composePullService,
|
|
249
|
+
composePull,
|
|
250
|
+
composeStats,
|
|
251
|
+
getDockerEvents,
|
|
252
|
+
selfRecreateAdmin,
|
|
253
|
+
} from "./control-plane/docker.js";
|
|
254
|
+
|
|
255
|
+
// ── Scheduler ───────────────────────────────────────────────────────────
|
|
256
|
+
export type {
|
|
257
|
+
ActionType,
|
|
258
|
+
AutomationAction,
|
|
259
|
+
AutomationConfig,
|
|
260
|
+
ExecutionLogEntry,
|
|
261
|
+
} from "./control-plane/scheduler.js";
|
|
262
|
+
export {
|
|
263
|
+
SCHEDULE_PRESETS,
|
|
264
|
+
SAFE_PATH_RE,
|
|
265
|
+
resolveSchedule,
|
|
266
|
+
parseAutomationYaml,
|
|
267
|
+
loadAutomations,
|
|
268
|
+
executeAction,
|
|
269
|
+
startScheduler,
|
|
270
|
+
stopScheduler,
|
|
271
|
+
reloadScheduler,
|
|
272
|
+
getSchedulerStatus,
|
|
273
|
+
getExecutionLog,
|
|
274
|
+
getAllExecutionLogs,
|
|
275
|
+
} from "./control-plane/scheduler.js";
|
|
276
|
+
|
|
277
|
+
// ── Model Runner (local provider detection) ─────────────────────────────
|
|
278
|
+
export type { LocalProviderDetection } from "./control-plane/model-runner.js";
|
|
279
|
+
export { detectLocalProviders } from "./control-plane/model-runner.js";
|
|
280
|
+
|
|
281
|
+
// ── Setup ────────────────────────────────────────────────────────────────
|
|
282
|
+
export type {
|
|
283
|
+
SetupConnection,
|
|
284
|
+
SetupAssignments,
|
|
285
|
+
SetupInput,
|
|
286
|
+
SetupResult,
|
|
287
|
+
DetectedProvider,
|
|
288
|
+
} from "./control-plane/setup.js";
|
|
289
|
+
export {
|
|
290
|
+
validateSetupInput,
|
|
291
|
+
buildSecretsFromSetup,
|
|
292
|
+
buildConnectionEnvVarMap,
|
|
293
|
+
performSetup,
|
|
294
|
+
detectProviders,
|
|
295
|
+
} from "./control-plane/setup.js";
|
package/src/logger.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
2
|
+
|
|
3
|
+
export function createLogger(service: string) {
|
|
4
|
+
function log(level: LogLevel, msg: string, extra?: Record<string, unknown>): void {
|
|
5
|
+
const entry = { ts: new Date().toISOString(), level, service, msg, ...(extra ? { extra } : {}) };
|
|
6
|
+
(level === 'error' || level === 'warn' ? console.error : console.log)(JSON.stringify(entry));
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
info: (msg: string, extra?: Record<string, unknown>) => log('info', msg, extra),
|
|
10
|
+
warn: (msg: string, extra?: Record<string, unknown>) => log('warn', msg, extra),
|
|
11
|
+
error: (msg: string, extra?: Record<string, unknown>) => log('error', msg, extra),
|
|
12
|
+
debug: (msg: string, extra?: Record<string, unknown>) => log('debug', msg, extra),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared LLM provider constants.
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for provider configuration used by both
|
|
5
|
+
* server-side endpoints and client-side Svelte components.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Supported LLM providers. */
|
|
9
|
+
export const LLM_PROVIDERS = [
|
|
10
|
+
"openai", "anthropic", "ollama", "groq", "together",
|
|
11
|
+
"mistral", "deepseek", "xai", "lmstudio", "model-runner"
|
|
12
|
+
] as const;
|
|
13
|
+
|
|
14
|
+
/** Default base URLs per provider. */
|
|
15
|
+
export const PROVIDER_DEFAULT_URLS: Record<string, string> = {
|
|
16
|
+
openai: "https://api.openai.com",
|
|
17
|
+
groq: "https://api.groq.com/openai",
|
|
18
|
+
mistral: "https://api.mistral.ai",
|
|
19
|
+
together: "https://api.together.xyz",
|
|
20
|
+
deepseek: "https://api.deepseek.com",
|
|
21
|
+
xai: "https://api.x.ai",
|
|
22
|
+
lmstudio: "http://host.docker.internal:1234",
|
|
23
|
+
ollama: "http://host.docker.internal:11434",
|
|
24
|
+
"model-runner": "http://model-runner.docker.internal/engines",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** Map provider name → env var for the API key. */
|
|
28
|
+
export const PROVIDER_KEY_MAP: Record<string, string> = {
|
|
29
|
+
openai: "OPENAI_API_KEY",
|
|
30
|
+
anthropic: "ANTHROPIC_API_KEY",
|
|
31
|
+
groq: "GROQ_API_KEY",
|
|
32
|
+
mistral: "MISTRAL_API_KEY",
|
|
33
|
+
google: "GOOGLE_API_KEY",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** Known embedding model dimensions (cloud providers). */
|
|
37
|
+
export const EMBEDDING_DIMS: Record<string, number> = {
|
|
38
|
+
"openai/text-embedding-3-small": 1536,
|
|
39
|
+
"openai/text-embedding-3-large": 3072,
|
|
40
|
+
"openai/text-embedding-ada-002": 1536,
|
|
41
|
+
"ollama/nomic-embed-text": 768,
|
|
42
|
+
"ollama/mxbai-embed-large": 1024,
|
|
43
|
+
"ollama/all-minilm": 384,
|
|
44
|
+
"ollama/snowflake-arctic-embed": 1024,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Provider display labels for UI. */
|
|
48
|
+
export const PROVIDER_LABELS: Record<string, string> = {
|
|
49
|
+
openai: "OpenAI",
|
|
50
|
+
anthropic: "Anthropic",
|
|
51
|
+
ollama: "Ollama",
|
|
52
|
+
groq: "Groq",
|
|
53
|
+
together: "Together AI",
|
|
54
|
+
mistral: "Mistral",
|
|
55
|
+
deepseek: "DeepSeek",
|
|
56
|
+
xai: "xAI (Grok)",
|
|
57
|
+
lmstudio: "LM Studio",
|
|
58
|
+
"model-runner": "Docker Model Runner",
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Map provider name → mem0-compatible provider name.
|
|
63
|
+
* mem0 doesn't know "model-runner" or "lmstudio" — both speak OpenAI protocol.
|
|
64
|
+
* Ollama also maps to "openai" because Ollama exposes an OpenAI-compatible API
|
|
65
|
+
* at /v1, and using provider "ollama" in mem0 requires the `ollama` Python
|
|
66
|
+
* package which we don't install in the memory container.
|
|
67
|
+
*/
|
|
68
|
+
export function mem0ProviderName(provider: string): string {
|
|
69
|
+
if (provider === "model-runner" || provider === "lmstudio" || provider === "ollama") return "openai";
|
|
70
|
+
return provider;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Map provider/base URL input to the mem0 config key/value pair.
|
|
75
|
+
* All local providers (Ollama, Model Runner, LM Studio) use the OpenAI-compatible
|
|
76
|
+
* endpoint, so we always set openai_base_url with a /v1 suffix.
|
|
77
|
+
*/
|
|
78
|
+
export function mem0BaseUrlConfig(
|
|
79
|
+
_provider: string,
|
|
80
|
+
baseUrl: string
|
|
81
|
+
): { key: "openai_base_url"; value: string } | null {
|
|
82
|
+
const trimmed = baseUrl.trim();
|
|
83
|
+
if (!trimmed) return null;
|
|
84
|
+
|
|
85
|
+
const normalized = trimmed.replace(/\/+$/, "");
|
|
86
|
+
return { key: "openai_base_url", value: `${normalized}/v1` };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Default models to pull when enabling Ollama from the wizard. */
|
|
90
|
+
export const OLLAMA_DEFAULT_MODELS = {
|
|
91
|
+
chat: "llama3.2:latest",
|
|
92
|
+
embedding: "nomic-embed-text",
|
|
93
|
+
} as const;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Base URL for Ollama when running as an in-stack compose service.
|
|
97
|
+
* Uses Docker network name instead of host.docker.internal.
|
|
98
|
+
*/
|
|
99
|
+
export const OLLAMA_INSTACK_URL = "http://ollama:11434";
|
|
100
|
+
|
|
101
|
+
/** Contextual help for local/self-hosted providers. */
|
|
102
|
+
export const LOCAL_PROVIDER_HELP: Record<string, string> = {
|
|
103
|
+
"model-runner": "Add models with: docker model pull ai/model-name",
|
|
104
|
+
ollama: "Add models with: ollama pull model-name",
|
|
105
|
+
lmstudio: "Download models from the LM Studio Discover tab.",
|
|
106
|
+
};
|