@kedem/okdb 2.3.5 → 2.4.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 (59) hide show
  1. package/CHANGELOG.md +349 -0
  2. package/algorithm-worker-thread.js +1 -1
  3. package/bin/okdb.js +1 -1
  4. package/docs/auth-and-sync.md +28 -4
  5. package/docs/auth-permissions.md +19 -6
  6. package/docs/change-log.md +79 -59
  7. package/docs/data-model.md +20 -18
  8. package/docs/deployment.md +25 -0
  9. package/docs/diagnostics.md +59 -17
  10. package/docs/embeddings.md +57 -6
  11. package/docs/fts.md +50 -5
  12. package/docs/functions.md +21 -8
  13. package/docs/http-api.md +139 -98
  14. package/docs/http-cluster.md +30 -8
  15. package/docs/indexes.md +5 -4
  16. package/docs/logging.md +18 -0
  17. package/docs/migration.md +94 -2
  18. package/docs/pipelines.md +6 -1
  19. package/docs/plugins.md +12 -18
  20. package/docs/process-registry.md +50 -39
  21. package/docs/processors.md +40 -22
  22. package/docs/querying.md +50 -36
  23. package/docs/queue.md +110 -14
  24. package/docs/subscriptions.md +35 -24
  25. package/docs/sync.md +96 -37
  26. package/docs/time-machine.md +23 -17
  27. package/docs/transactions.md +11 -19
  28. package/docs/ttl.md +118 -67
  29. package/docs/upgrade-2.0.md +2 -2
  30. package/docs/views.md +71 -52
  31. package/okdb-functions-sandbox-worker.js +1 -1
  32. package/okdb-http-worker-child.js +1 -1
  33. package/okdb-views-bootstrap-worker.js +1 -1
  34. package/okdb.js +1 -1
  35. package/package.json +1 -1
  36. package/public/sections/db/parts/type-viewer.ok.js +1 -1
  37. package/public/sections/embeddings/parts/engines-overview.ok.js +1 -1
  38. package/public/sections/queue/parts/queue-jobs.ok.js +1 -1
  39. package/public/sections/system/modals/data-ops-modal.ok.js +1 -1
  40. package/types/environment.d.ts +320 -52
  41. package/types/features/admin.d.ts +8 -2
  42. package/types/features/api.d.ts +10 -16
  43. package/types/features/auth.d.ts +135 -16
  44. package/types/features/embeddings.d.ts +639 -31
  45. package/types/features/engines.d.ts +368 -14
  46. package/types/features/files.d.ts +0 -3
  47. package/types/features/fts.d.ts +98 -26
  48. package/types/features/functions.d.ts +175 -15
  49. package/types/features/mcp.d.ts +23 -10
  50. package/types/features/pipelines.d.ts +268 -9
  51. package/types/features/queue.d.ts +230 -34
  52. package/types/features/sync.d.ts +177 -14
  53. package/types/features/time-machine.d.ts +117 -16
  54. package/types/features/views.d.ts +230 -39
  55. package/types/index.d.ts +357 -254
  56. package/types/okdb.d.ts +377 -0
  57. package/types/options.d.ts +309 -48
  58. package/public/test-cron-input.html +0 -60
  59. package/public/test-json-input.html +0 -280
@@ -1,23 +1,183 @@
1
+ /** Runtime limits of a stored function (normalized; defaults come from the `functions` constructor option). */
2
+ export interface OKDBFunctionRuntime {
3
+ /** Run deadline in ms (default 5000). Exposed to the script as `ctx.signal`. */
4
+ timeoutMs: number;
5
+ /** Sandbox heap cap in MB (default 32). */
6
+ memoryMb: number;
7
+ /** Whether the script may use `fetch` (default true). */
8
+ allowFetch: boolean;
9
+ pool: string | null;
10
+ }
11
+
12
+ /** Input accepted by `create()`, `update()` (as a patch) and `preview()`. */
1
13
  export interface OKDBFunctionDefinition {
14
+ /** Must match `/^[A-Za-z0-9._-]+$/`. Required for `create()`; `update()` uses its `name` argument. */
15
+ name?: string;
16
+ /**
17
+ * Script source: a single function expression `[async] (ctx) => { ... }` (max 64 KiB; must not
18
+ * reference `require`/`import`/`console`/`module`/`exports`/`process`). Allowed `ctx` props:
19
+ * payload, info, signal, log, env, job, processor, materializer (+ `okdb` when `unsafe: true`).
20
+ */
21
+ source?: string;
22
+ /** Alternative to `source` (`script.source` wins). */
23
+ script?: { source?: string };
24
+ runtime?: Partial<OKDBFunctionRuntime>;
25
+ /** Grants `ctx.okdb` (privileged root facade with cross-env access). Default false. */
26
+ unsafe?: boolean;
27
+ /** Default true. A disabled function throws `FUNCTION_DISABLED` on `run()` / `preview()`. */
28
+ enabled?: boolean;
29
+ /** Explicit version; defaults to 1 on create and previous + 1 on update. */
30
+ version?: number;
31
+ metadata?: {
32
+ description?: string | null;
33
+ tags?: string[];
34
+ createdBy?: string | null;
35
+ updatedBy?: string | null;
36
+ [key: string]: unknown;
37
+ };
38
+ }
39
+
40
+ /** Stored function record (`~functions` type in the owning env). */
41
+ export interface OKDBFunctionRecord {
2
42
  name: string;
3
- source: string;
4
- runtime?: string;
5
- timeout?: number;
6
- [key: string]: unknown;
43
+ /** Always `'env'`. */
44
+ scope: 'env';
45
+ unsafe: boolean;
46
+ enabled: boolean;
47
+ version: number;
48
+ /** `sha256:<hex>` of the normalized source. */
49
+ hash: string;
50
+ runtime: OKDBFunctionRuntime;
51
+ script: { language: 'javascript'; source: string; bytes: number };
52
+ metadata: {
53
+ description: string | null;
54
+ tags: string[];
55
+ createdAt: number;
56
+ updatedAt: number;
57
+ createdBy: string | null;
58
+ updatedBy: string | null;
59
+ /** Engine/pipeline linkage, set when a function is owned by an engine or pipeline. */
60
+ owner_engine?: unknown;
61
+ pipeline?: unknown;
62
+ };
63
+ }
64
+
65
+ /** Row shape returned by `list()` / `listRuns()`. */
66
+ export interface OKDBFunctionRegistryEntry<T> {
67
+ key: string;
68
+ value: T;
69
+ version: number;
70
+ }
71
+
72
+ export type OKDBFunctionRunStatus = 'queued' | 'running' | 'success' | 'error' | 'timeout' | 'killed';
73
+
74
+ export interface OKDBFunctionLogEntry {
75
+ level: string;
76
+ msg: string;
77
+ meta: Record<string, unknown> | null;
78
+ context: unknown;
79
+ ts: number;
7
80
  }
8
81
 
9
- export interface OKDBFunctionCallOptions {
10
- timeout?: number;
11
- env?: string;
12
- args?: unknown[];
13
- [key: string]: unknown;
82
+ export interface OKDBFunctionDryRunAction {
83
+ scope: string;
84
+ method: string;
85
+ envName: string | null;
86
+ args: unknown[];
14
87
  }
15
88
 
89
+ /** A function run record (`~function_runs` type in the owning env). */
90
+ export interface OKDBFunctionRun {
91
+ id: string;
92
+ functionName: string;
93
+ /** `'global'` only appears on legacy records. */
94
+ scope: 'env' | 'global';
95
+ status: OKDBFunctionRunStatus;
96
+ request: { payload: unknown; trigger: string; requestedAt: number };
97
+ execution: {
98
+ runnerId: string | null;
99
+ startedAt: number | null;
100
+ finishedAt: number | null;
101
+ durationMs: number | null;
102
+ timeoutMs: number | null;
103
+ memoryMb: number | null;
104
+ };
105
+ result: {
106
+ /** The script's return value (JSON-cloned). */
107
+ value?: unknown;
108
+ truncated: boolean;
109
+ /** Only on `dryRun` runs: the writes the script attempted (captured, not executed). */
110
+ dryRunActions?: OKDBFunctionDryRunAction[];
111
+ };
112
+ logs: OKDBFunctionLogEntry[];
113
+ error: { message: string; code: string | null; details: unknown; stack: string | null } | null;
114
+ metadata: { env: string | null; functionVersion: number | null; preview: boolean };
115
+ }
116
+
117
+ export interface OKDBFunctionRunOptions {
118
+ /** Capture writes into `result.dryRunActions` instead of committing them. Reads still execute. */
119
+ dryRun?: boolean;
120
+ /** Which runs to persist to `~function_runs` (default `'all'`). */
121
+ recordRuns?: 'all' | 'errors' | 'none';
122
+ /** Recorded as `request.trigger` / `ctx.info.trigger` (default `'sdk'`). */
123
+ trigger?: string;
124
+ /**
125
+ * Per-call run deadline in ms, overriding the stored `runtime.timeoutMs` for this run only
126
+ * (drives `ctx.signal` and the sandbox watchdog; recorded as `execution.timeoutMs`). Must be a
127
+ * positive finite number (else `FUNCTION_INVALID_TIMEOUT`); capped at 600 000 ms
128
+ * (`OKDB_FN_MAX_TIMEOUT_MS`).
129
+ */
130
+ timeoutMs?: number;
131
+ }
132
+
133
+ export interface OKDBFunctionPreviewOptions {
134
+ dryRun?: boolean;
135
+ /** Recorded as `request.trigger` (default `'preview'`). */
136
+ trigger?: string;
137
+ runId?: string;
138
+ /** Name used when the draft definition has none (default `'__draft__'`). */
139
+ functionName?: string;
140
+ /** Filename used in compile-error stack traces. */
141
+ filename?: string;
142
+ }
143
+
144
+ /**
145
+ * Stored, versioned, validated JavaScript functions, executed on the calling node in its
146
+ * per-process sandbox thread.
147
+ *
148
+ * Attached as `env.functions` (registry = that env) and `db.functions` (registry = the `~system`
149
+ * env). Both expose the same surface; run records go to the owning env's `~function_runs`.
150
+ *
151
+ * Removed: `register`, `unregister`, `call` (not part of the 2.x API; use `create`, `remove`, `run`).
152
+ */
16
153
  export declare class OKDBFunctions {
17
- register(definition: OKDBFunctionDefinition): Promise<void>;
18
- unregister(name: string): Promise<void>;
19
- call(name: string, args?: unknown[], options?: OKDBFunctionCallOptions): Promise<unknown>;
20
- get(name: string): OKDBFunctionDefinition | null;
21
- list(): OKDBFunctionDefinition[];
22
- stop(): Promise<void>;
154
+ /** Name of the env that owns this registry (`'~system'` for `db.functions`). */
155
+ readonly envName: string | null;
156
+
157
+ /** All stored functions (empty until the first `create()`). */
158
+ list(): Promise<Array<OKDBFunctionRegistryEntry<OKDBFunctionRecord>>>;
159
+ get(name: string): Promise<OKDBFunctionRecord | null>;
160
+ /** Validates and stores a new function. Throws if the name already exists or the script is invalid. */
161
+ create(definition: OKDBFunctionDefinition & { name: string }): Promise<OKDBFunctionRecord>;
162
+ /** Patches an existing function; fields not given are kept, version bumps. Throws if missing. */
163
+ update(name: string, patch?: OKDBFunctionDefinition): Promise<OKDBFunctionRecord>;
164
+ /** Resolves false if the function did not exist. */
165
+ remove(name: string): Promise<boolean>;
166
+
167
+ /**
168
+ * Runs a stored function and resolves with the final run record (`result.value` = return value).
169
+ * Rejects on script error / timeout (`err.code` e.g. `FUNCTION_TIMEOUT`, `FUNCTION_DISABLED`).
170
+ */
171
+ run(name: string, payload?: unknown, options?: OKDBFunctionRunOptions): Promise<OKDBFunctionRun>;
172
+ /** Validates and runs an unsaved draft. Persists neither the definition nor a run record. */
173
+ preview(
174
+ definition: OKDBFunctionDefinition,
175
+ payload?: unknown,
176
+ options?: OKDBFunctionPreviewOptions,
177
+ ): Promise<OKDBFunctionRun>;
178
+
179
+ listRuns(options?: { functionName?: string | null }): Promise<Array<OKDBFunctionRegistryEntry<OKDBFunctionRun>>>;
180
+ getRun(runId: string): Promise<OKDBFunctionRun | null>;
181
+ /** Low-level: normalizes and writes a run record to `~function_runs` (`run()` does this itself). */
182
+ recordRun(run?: Partial<OKDBFunctionRun>): Promise<OKDBFunctionRun>;
23
183
  }
@@ -1,17 +1,30 @@
1
+ /** A tool entry as advertised by the MCP `tools/list` JSON-RPC method. */
1
2
  export interface OKDBMcpTool {
3
+ /** e.g. `okdb_data`, `okdb_queue` (one per capability), standalone route tools, and `okdb_api`. */
2
4
  name: string;
3
5
  description?: string;
4
- inputSchema?: Record<string, unknown>;
5
- [key: string]: unknown;
6
- }
7
-
8
- export interface OKDBMcpOptions {
9
- tools?: OKDBMcpTool[];
10
- [key: string]: unknown;
6
+ /** JSON Schema of the tool arguments. Capability tools take `{ action, ...args }`. */
7
+ inputSchema: Record<string, unknown>;
8
+ annotations?: {
9
+ title?: string;
10
+ readOnlyHint?: boolean;
11
+ destructiveHint?: boolean;
12
+ idempotentHint?: boolean;
13
+ openWorldHint?: boolean;
14
+ };
11
15
  }
12
16
 
17
+ /**
18
+ * Model Context Protocol server, attached as `db.mcp`. It has no public JavaScript methods: it is
19
+ * consumed over HTTP once `db.http.listen(port)` is called — `POST /mcp` (JSON-RPC 2.0:
20
+ * `initialize`, `tools/list`, `tools/call`, ...), `GET /mcp` (SSE notification stream), plus the
21
+ * legacy `/mcp/sse` + `/mcp/messages` transport. Requests need `Authorization: Bearer <token>`
22
+ * unless open mode / the bootstrap window applies. Tools are projected from the HTTP operation
23
+ * registry (routes carrying `mcp: { capability, action }` metadata). CORS headers are sent only
24
+ * when the `mcp.allowedOrigins` constructor option (array of origins, or `'*'`) is set.
25
+ *
26
+ * Removed: `configure`, `listTools`, `callTool` (not part of the 2.x JS API; use the HTTP endpoint).
27
+ */
13
28
  export declare class OKDBMcp {
14
- configure(options: OKDBMcpOptions): void;
15
- listTools(): OKDBMcpTool[];
16
- callTool(name: string, input: unknown): Promise<unknown>;
29
+ private constructor();
17
30
  }
@@ -1,19 +1,278 @@
1
+ import type { OKDBEnvironment } from '../environment';
2
+ import type { OKDBEngine, OKDBEngineStatus } from './engines';
3
+ import type { OKDBEmbeddingsVectorSpace } from './embeddings';
4
+
5
+ // ─── Records ──────────────────────────────────────────────────────────────────
6
+
7
+ export type OKDBPipelineStatus = 'active' | 'stopped';
8
+
9
+ /** A member reference: an existing engine playing a named role. Order is meaningful. */
10
+ export interface OKDBPipelineMemberRef {
11
+ /** Engine type (e.g. `'indexer'`, `'queue-worker'`). */
12
+ type: string;
13
+ /** Engine name. */
14
+ name: string;
15
+ /** Role within the pipeline (e.g. `'embedder'`, `'indexer'`, `'search'`, `'worker'`). */
16
+ role: string;
17
+ }
18
+
19
+ /**
20
+ * Input to `env.pipelines.create()` / `validate()`. Every referenced engine must
21
+ * already exist. Strings are trimmed.
22
+ */
1
23
  export interface OKDBPipelineDefinition {
2
24
  name: string;
3
- sourceType: string;
4
- steps: OKDBPipelineStep[];
25
+ /** Must be `null` (V1). */
26
+ template?: null;
27
+ /** Default `'active'`. */
28
+ status?: OKDBPipelineStatus;
29
+ /**
30
+ * Plain object. Known keys: `label`, `family` (`'embeddings'` for embeddings
31
+ * pipelines), `templateId`, `lifecycleSkipRoles` (roles excluded from
32
+ * start/stop, e.g. a shared `embedder`).
33
+ */
34
+ meta?: Record<string, unknown>;
35
+ /** Non-empty, ordered. */
36
+ engines: OKDBPipelineMemberRef[];
37
+ created?: number;
38
+ updated?: number;
39
+ }
40
+
41
+ /** The normalized record stored in the env's `~pipelines` type (key = `name`). */
42
+ export interface OKDBPipelineRecord {
43
+ name: string;
44
+ template: null;
45
+ status: OKDBPipelineStatus;
46
+ meta: Record<string, unknown>;
47
+ created: number;
48
+ updated: number;
49
+ engines: OKDBPipelineMemberRef[];
50
+ }
51
+
52
+ /** Patch for `env.pipelines.update()`. Only `status` / `meta` may change; `engines` must equal the current topology. */
53
+ export interface OKDBPipelineUpdatePatch {
54
+ status?: OKDBPipelineStatus;
55
+ meta?: Record<string, unknown>;
56
+ /** Accepted only if identical to the current members (topology is immutable). */
57
+ engines?: OKDBPipelineMemberRef[];
5
58
  [key: string]: unknown;
6
59
  }
7
60
 
8
- export interface OKDBPipelineStep {
9
- type: string;
61
+ /** Raw record entry from `listRecords()`; `env` is set only on the `db.pipelines` aggregate. */
62
+ export interface OKDBPipelineRecordEntry {
63
+ env?: string;
64
+ key: string;
65
+ value: OKDBPipelineRecord;
66
+ version: number;
67
+ }
68
+
69
+ // ─── Inspection ───────────────────────────────────────────────────────────────
70
+
71
+ /**
72
+ * Per-member state: an engine runtime status, `'remote'` (durable record present
73
+ * but not running in this process — e.g. an `engines: false` node), or
74
+ * `'missing'` (no engine anywhere).
75
+ */
76
+ export type OKDBPipelineMemberState = OKDBEngineStatus | 'remote' | 'missing';
77
+
78
+ /** `'stopped'` if the record is stopped; `'online'` if every member is online/remote; `'error'`; else `'degraded'`. */
79
+ export type OKDBPipelineHealth = 'online' | 'degraded' | 'error' | 'stopped';
80
+
81
+ /** A member as returned by `get()` / `list()` — the ref plus live/durable inspection data. */
82
+ export interface OKDBPipelineMemberInfo extends OKDBPipelineMemberRef {
83
+ /** `<type>@<name>`, or `null` when missing. */
84
+ key: string | null;
85
+ state: OKDBPipelineMemberState;
86
+ exists: boolean;
87
+ isRunning: boolean;
88
+ status: OKDBEngineStatus | null;
89
+ reason: string | null;
90
+ config: Record<string, unknown> | null;
91
+ meta: Record<string, unknown> | null;
92
+ error: string | null;
93
+ /** Env holding the engine's `~engines` record (live engines only). */
94
+ storeEnv: string | null;
95
+ /** True if the engine is stored in the pipeline's own env. */
96
+ owned: boolean;
97
+ /** Member `api.status()`/`api.stats()` result, durable stats fallback, or the engine's runtimeState. */
98
+ runtime: Record<string, unknown> | null;
99
+ lastClock: number | null;
100
+ headClock: number | null;
101
+ lag: number | null;
102
+ progress: unknown;
103
+ paused: boolean;
104
+ cursorKey: string | null;
105
+ }
106
+
107
+ /** An inspected pipeline, as returned by `get()` / `list()`. */
108
+ export interface OKDBPipelineInfo extends Omit<OKDBPipelineRecord, 'engines'> {
109
+ /** Record key (the pipeline name). */
110
+ key: string;
111
+ /** Record version from `list()`; always `null` from `get()`. */
112
+ version: number | null;
113
+ /** Owning env name. */
114
+ env: string | null;
115
+ health: OKDBPipelineHealth;
116
+ /**
117
+ * Embeddings pipelines: the embedder's model changed since the vectors were embedded — search
118
+ * serves the old vectors, new embeds are held until `rebuild()` ("Re-embed all").
119
+ */
120
+ stale?: boolean;
121
+ /** Embeddings pipelines: see `OKDBEmbeddingsVectorSpace`. */
122
+ vector_space?: OKDBEmbeddingsVectorSpace;
123
+ engines: OKDBPipelineMemberInfo[];
124
+ }
125
+
126
+ export interface OKDBPipelineRebuildResult {
127
+ pipeline: string;
128
+ /** Per member key (`<type>@<name>`): the member's `api.rebuild()` result. */
129
+ results: Record<string, unknown>;
130
+ /** Member keys without a rebuild API (or not running here). */
131
+ skipped: string[];
132
+ }
133
+
134
+ export interface OKDBPipelineRemoveResult {
135
+ /** `false` if no such pipeline. */
136
+ removed: boolean;
137
+ /** Env-owned members uninstalled with the pipeline (`<type>@<name>`). */
138
+ enginesRemoved: string[];
139
+ /** Members kept: shared/global, referenced by another pipeline in the env, or not resolvable here. */
140
+ enginesPreserved: string[];
141
+ }
142
+
143
+ /** Result of `findOwner()`. */
144
+ export interface OKDBPipelineOwner {
145
+ env: string;
146
+ pipeline: string;
147
+ role: string | null;
148
+ }
149
+
150
+ // ─── Embeddings pipeline handle ───────────────────────────────────────────────
151
+
152
+ /** Options for `pipeline.api.search()` / `searchDocs()`; extra keys go to the ANN algorithm. */
153
+ export interface OKDBPipelineSearchOptions {
154
+ /** Default 10. For `searchDocs` it counts documents, for `search` chunks. */
155
+ limit?: number;
156
+ /** Minimum score (0–1). Default 0. */
157
+ threshold?: number;
10
158
  [key: string]: unknown;
11
159
  }
12
160
 
161
+ /** Chunk-level hit: `key` is the raw vec key (`docKey` or `docKey\tchunkHash` for chunked pipelines). */
162
+ export interface OKDBPipelineSearchHit {
163
+ key: string;
164
+ /** 0–1, higher = more similar. */
165
+ score: number;
166
+ }
167
+
168
+ /** Document-level hit: best chunk per source doc. */
169
+ export interface OKDBPipelineDocHit {
170
+ /** Source document key. */
171
+ key: string;
172
+ score: number;
173
+ /** Hash of the winning chunk (chunked pipelines only). */
174
+ chunkHash?: string;
175
+ }
176
+
177
+ /** `pipeline.api` — convenience API over an embeddings pipeline's members. */
178
+ export interface OKDBPipelineApi {
179
+ /** Chunk-level nearest-neighbour search. Text queries are embedded; vectors are used as-is. */
180
+ search(query: string | Float32Array | number[], opts?: OKDBPipelineSearchOptions): Promise<OKDBPipelineSearchHit[]>;
181
+ /** Document-level search: one row per source doc, over-fetching until `limit` docs are found. */
182
+ searchDocs(
183
+ query: string | Float32Array | number[],
184
+ opts?: OKDBPipelineSearchOptions,
185
+ ): Promise<OKDBPipelineDocHit[]>;
186
+ /**
187
+ * Wait (up to 30 s) for the indexer to catch up with the source type's head.
188
+ * Throws if the indexer is not running on this node.
189
+ */
190
+ flush(): Promise<void>;
191
+ /** Combined stats: embedder `health()`, indexer/worker/search `stats()` (`undefined` when not running here). */
192
+ stats(): Promise<{ embedder: unknown; indexer: unknown; worker: unknown; search: unknown }>;
193
+ }
194
+
195
+ /** Returned by `okdb.embeddings.createPipeline(name, config, meta?)`. */
196
+ export interface OKDBPipelineHandle {
197
+ embedder: OKDBEngine;
198
+ indexer: OKDBEngine;
199
+ /** Present only for `mode: 'queue'`. */
200
+ worker: OKDBEngine | null;
201
+ search: OKDBEngine;
202
+ api: OKDBPipelineApi;
203
+ }
204
+
205
+ // ─── OKDBPipelines ────────────────────────────────────────────────────────────
206
+
207
+ /**
208
+ * Generic pipeline registry: env-defined, synced `~pipelines` records grouping
209
+ * existing engines into an ordered, structurally immutable topology ("the
210
+ * pipeline is the engine"). Member add/remove is impossible at runtime; use
211
+ * `replaceMember()` for a same-type swap.
212
+ *
213
+ * Attached twice, one class:
214
+ * - `env.pipelines` — the env-local registry: full CRUD + lifecycle.
215
+ * - `db.pipelines` — coordinator: read-only aggregation across opened envs
216
+ * (`get`/`getRecord` take `(env, name)` or `(name)` → `'default'`; `list`/
217
+ * `listRecords` take `{ envName }`), plus `findOwner`. Mutating methods
218
+ * (`create`, `update`, `start`, `stop`, `restart`, `rebuild`,
219
+ * `replaceMember`, `remove`) throw here — call them on `db.env(name).pipelines`.
220
+ *
221
+ * Errors are plain `Error`s (no `code`), e.g. "Pipeline not found: …".
222
+ */
13
223
  export declare class OKDBPipelines {
14
- register(definition: OKDBPipelineDefinition): Promise<void>;
15
- unregister(name: string): Promise<void>;
16
- get(name: string): OKDBPipelineDefinition | null;
17
- list(): OKDBPipelineDefinition[];
18
- bootSyncedPipelines(): Promise<void>;
224
+ /** True on `db.pipelines`, false on `env.pipelines`. */
225
+ readonly isCoordinator: boolean;
226
+ /** Owning env name (`null` on the coordinator). */
227
+ readonly envName: string | null;
228
+
229
+ // ── Reads (both surfaces) ─────────────────────────────────────────────────
230
+
231
+ /** Inspected pipeline (members + health), or `null`. env: `get(name)`. */
232
+ get(name: string): Promise<OKDBPipelineInfo | null>;
233
+ /** db only: pipeline `name` in env `envName`. */
234
+ get(envName: string, name: string): Promise<OKDBPipelineInfo | null>;
235
+ /** All inspected pipelines. env: that env (options ignored); db: every opened env, or `options.envName`. */
236
+ list(options?: { envName?: string | null }): Promise<OKDBPipelineInfo[]>;
237
+ /** Raw stored record, or `null`. */
238
+ getRecord(name: string): Promise<OKDBPipelineRecord | null>;
239
+ /** db only: raw record `name` in env `envName`. */
240
+ getRecord(envName: string, name: string): Promise<OKDBPipelineRecord | null>;
241
+ /** Raw records. db entries carry `env`. */
242
+ listRecords(options?: { envName?: string | null }): Promise<OKDBPipelineRecordEntry[]>;
243
+ /** Normalize + validate a definition without persisting (throws on invalid input). */
244
+ validate(
245
+ definition: OKDBPipelineDefinition,
246
+ options?: { previous?: OKDBPipelineRecord | null },
247
+ ): OKDBPipelineRecord;
248
+ /** Which pipeline (in any opened user env) owns engine `type@name` as a member, or `null`. */
249
+ findOwner(type: string, name: string): OKDBPipelineOwner | null;
250
+ /** Ensure the `~pipelines` type exists (env: this env; db: `envName`, default `'default'`); returns the env. */
251
+ ensure(envName?: string): Promise<OKDBEnvironment>;
252
+
253
+ // ── Mutations (env.pipelines only) ────────────────────────────────────────
254
+
255
+ /** Persist a new record. Throws if it exists or references engines not found on this node. */
256
+ create(definition: OKDBPipelineDefinition): Promise<OKDBPipelineInfo>;
257
+ /** Update `status` / `meta`. Throws on any topology change. */
258
+ update(name: string, patch?: OKDBPipelineUpdatePatch): Promise<OKDBPipelineInfo>;
259
+ /** Start managed members (declaration order; `meta.lifecycleSkipRoles` excluded), set status `active`. */
260
+ start(name: string): Promise<OKDBPipelineInfo>;
261
+ /** Stop running managed members (reverse order), set status `stopped`. */
262
+ stop(name: string): Promise<OKDBPipelineInfo>;
263
+ /** `stop()` + `start()`. */
264
+ restart(name: string): Promise<OKDBPipelineInfo>;
265
+ /**
266
+ * Destructive re-derivation: call `api.rebuild()` on every member that has one,
267
+ * in member order (embeddings: wipe + re-embed, then reload the index).
268
+ */
269
+ rebuild(name: string): Promise<OKDBPipelineRebuildResult>;
270
+ /**
271
+ * Swap the member playing `role` for another existing engine of the same type;
272
+ * siblings whose `config[role]` named the old engine are re-pointed and restarted.
273
+ * Does not re-embed — follow with `rebuild()` if output changes.
274
+ */
275
+ replaceMember(name: string, role: string, newEngineName: string): Promise<OKDBPipelineInfo>;
276
+ /** Delete the record and uninstall env-owned members not referenced by another pipeline in the env. */
277
+ remove(name: string): Promise<OKDBPipelineRemoveResult>;
19
278
  }