@ponraaj/dimple-sdk 0.0.0-alpha.1 → 0.0.0-alpha.11

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 (83) hide show
  1. package/README.md +99 -0
  2. package/dist/dimple.d.ts +116 -5
  3. package/dist/errors.d.ts +24 -2
  4. package/dist/errors.js +8218 -0
  5. package/dist/index.d.ts +3 -2
  6. package/dist/index.js +3584 -1999
  7. package/dist/indexer.d.ts +9 -0
  8. package/dist/internal/config/index.d.ts +1 -1
  9. package/dist/internal/config/schema.d.ts +87 -0
  10. package/dist/internal/config/service.d.ts +4 -0
  11. package/dist/internal/core/core.d.ts +8 -8
  12. package/dist/internal/core/hosted-embedding.d.ts +33 -0
  13. package/dist/internal/core/index.d.ts +6 -0
  14. package/dist/internal/core/layer.d.ts +17 -8
  15. package/dist/internal/embedder/auto-install.d.ts +28 -0
  16. package/dist/internal/embedder/index.d.ts +2 -3
  17. package/dist/internal/embedder/registry.d.ts +7 -0
  18. package/dist/internal/embedder/transformers.d.ts +40 -2
  19. package/dist/internal/extractor/code-extractor.d.ts +11 -1
  20. package/dist/internal/extractor/index.d.ts +1 -1
  21. package/dist/internal/extractor/languages/index.d.ts +1 -1
  22. package/dist/internal/extractor/languages/javascript.d.ts +1 -1
  23. package/dist/internal/extractor/languages/typescript.d.ts +1 -1
  24. package/dist/internal/extractor/models/extraction.d.ts +14 -0
  25. package/dist/internal/installer/index.d.ts +37 -0
  26. package/dist/internal/llm/dream-classifier.d.ts +1 -1
  27. package/dist/internal/llm/index.d.ts +1 -1
  28. package/dist/internal/llm/service.d.ts +7 -1
  29. package/dist/internal/logger/index.d.ts +1 -1
  30. package/dist/internal/logger/service.d.ts +44 -14
  31. package/dist/internal/logger/types.d.ts +15 -3
  32. package/dist/internal/parser/code-parser.d.ts +12 -2
  33. package/dist/internal/parser/index.d.ts +3 -3
  34. package/dist/internal/parser/language-store.d.ts +3 -3
  35. package/dist/internal/parser/tree-sitter-engine.d.ts +1 -1
  36. package/dist/internal/retriever/hybrid.d.ts +21 -7
  37. package/dist/internal/retriever/index.d.ts +1 -1
  38. package/dist/internal/shared/effect/node.d.ts +155 -0
  39. package/dist/internal/shared/file-database.d.ts +17 -0
  40. package/dist/internal/shared/file-lock.d.ts +20 -0
  41. package/dist/internal/shared/schema/defaults.d.ts +13 -0
  42. package/dist/internal/store/audit.d.ts +8 -2
  43. package/dist/internal/store/db-backend.d.ts +48 -10
  44. package/dist/internal/store/graph/candidates.d.ts +3 -1
  45. package/dist/internal/store/graph/concepts.d.ts +16 -7
  46. package/dist/internal/store/graph/dream.d.ts +9 -3
  47. package/dist/internal/store/graph/errors.d.ts +1 -1
  48. package/dist/internal/store/graph/repair.d.ts +9 -3
  49. package/dist/internal/store/graph/traversal.d.ts +1 -1
  50. package/dist/internal/store/index.d.ts +4 -3
  51. package/dist/internal/store/libsql-backend.d.ts +1 -1
  52. package/dist/internal/store/models.d.ts +4 -3
  53. package/dist/internal/store/schema/graph.d.ts +7 -7
  54. package/dist/internal/store/schema/libsql.d.ts +4 -4
  55. package/dist/internal/store/schema/metadata.d.ts +4 -1
  56. package/dist/internal/store/schema/topics.d.ts +0 -12
  57. package/dist/internal/store/service.d.ts +85 -5
  58. package/dist/internal/store/store.d.ts +24 -5
  59. package/dist/internal/store/topics/errors.d.ts +1 -1
  60. package/dist/internal/store/topics/jobs.d.ts +9 -3
  61. package/dist/internal/store/topics/lifecycle.d.ts +9 -3
  62. package/dist/internal/store/topics/maintenance.d.ts +10 -4
  63. package/dist/internal/store/topics/query.d.ts +1 -1
  64. package/dist/internal/store/topics/routing.d.ts +34 -1
  65. package/dist/internal/store/topics/topic-vectors.d.ts +11 -4
  66. package/dist/internal/store/topics/tree.d.ts +15 -9
  67. package/dist/internal/workflow/engine.d.ts +27 -3
  68. package/dist/internal/workflow/executor.d.ts +20 -6
  69. package/dist/internal/workflow/index.d.ts +4 -4
  70. package/dist/internal/workflow/persistence.d.ts +3 -3
  71. package/dist/internal/workflow/queue.d.ts +8 -5
  72. package/dist/internal/workflow/registry.d.ts +11 -1
  73. package/dist/internal/workflow/runtime.d.ts +22 -4
  74. package/dist/internal/workflow/signals.d.ts +21 -0
  75. package/dist/make.d.ts +27 -0
  76. package/package.json +34 -10
  77. package/dist/internal/embedder/openai.d.ts +0 -8
  78. package/dist/internal/wasm/grammar-store.d.ts +0 -14
  79. package/dist/internal/wasm/index.d.ts +0 -5
  80. package/dist/internal/wasm/wasm-cache.d.ts +0 -17
  81. package/dist/internal/wasm/wasm-downloader.d.ts +0 -10
  82. package/dist/internal/wasm/wasm-registry.d.ts +0 -16
  83. package/dist/internal/workflow/queue-store.d.ts +0 -5
@@ -38,7 +38,7 @@
38
38
  * transaction-aware vector methods, move the upserts onto the tx.
39
39
  */
40
40
  import { Effect } from "effect";
41
- import type { EmbeddingModelConfig } from "./internal/config/index.js";
41
+ import type { EmbeddingModelConfig } from "../../config/index.js";
42
42
  import { Service as DbBackend } from "../db-backend.ts";
43
43
  import type { TopicConfig } from "../schema/topics.ts";
44
44
  import type { TopicError } from "./errors.ts";
@@ -88,3 +88,36 @@ export declare const routeInsert: (memoryId: string, vector: ReadonlyArray<numbe
88
88
  topicKey: string;
89
89
  overflow: boolean;
90
90
  }, TopicError | StoreError, DbBackend>;
91
+ /**
92
+ * Batch routing — the bulk-ingest path (`Store.updateEmbeddingMany`).
93
+ *
94
+ * Sequential `routeInsert` re-reads the WHOLE tree (all topics, all
95
+ * relations, all centroid sum-vectors) and commits its own transaction
96
+ * PER UNIT — measured ~42 ms/unit under bulk ingest, dominating the
97
+ * write path. This variant:
98
+ *
99
+ * 1. Reads the tree structure + sum-vectors ONCE.
100
+ * 2. Routes every entry against an IN-MEMORY mirror of the tree state,
101
+ * applying each unit's CF updates locally before the next descent —
102
+ * so the descents are bit-identical to sequential routeInsert calls
103
+ * against the DB (same reads, same writes, same order).
104
+ * 3. Applies ALL membership inserts + topic CF updates in ONE
105
+ * transaction (per-topic deltas accumulated in memory).
106
+ * 4. Writes the derived sum vectors in ONE batched upsert (backend
107
+ * `upsertTopicVectors`), still after commit (backend not
108
+ * transaction-aware — see module docs).
109
+ *
110
+ * Contract differences vs sequential: all-or-nothing (a validation
111
+ * failure or structural corruption rejects the whole batch), and the
112
+ * batch does NOT handle re-embedding (no membership decrement path) —
113
+ * it is for NEW memories; re-embedding existing ones goes through
114
+ * `routeInsert`/`Store.updateEmbedding`.
115
+ */
116
+ export declare const routeInsertMany: (entries: readonly {
117
+ readonly memoryId: string;
118
+ readonly vector: ReadonlyArray<number>;
119
+ }[], model: EmbeddingModelConfig, config: TopicConfig) => Effect.Effect<readonly {
120
+ readonly memoryId: string;
121
+ readonly topicKey: string;
122
+ readonly overflow: boolean;
123
+ }[], TopicError | StoreError, DbBackend>;
@@ -4,15 +4,22 @@
4
4
  * dynamic (not Drizzle tables), so every writer goes through this raw-SQL
5
5
  * helper — one canonical place for the table name + conversion function.
6
6
  */
7
- import type { EmbeddingModelConfig } from "./internal/config/index.js";
7
+ import type { EmbeddingModelConfig } from "../../config/index.js";
8
8
  import { type SQLWrapper } from "drizzle-orm";
9
9
  /** Per-model topic vector table name (mirrors libsql-backend.ts — canonical). */
10
10
  export declare const topicVectorTableName: (model: EmbeddingModelConfig) => string;
11
11
  /** vectorType → libSQL conversion function for the sum-vector column. */
12
- export declare const VECTOR_CONVERT_FNS: Readonly<Record<string, string>>;
13
- /** Anything with a `.run(sql)` — a Drizzle tx or the db handle. */
12
+ export declare const VECTOR_CONVERT_FNS: {
13
+ readonly float32: "vector32";
14
+ readonly float16: "vector16";
15
+ readonly float8: "vector8";
16
+ readonly float1bit: "vector1bit";
17
+ };
18
+ /** Anything with a `.run(sql)` — a Drizzle tx or the db handle. The raw
19
+ * result is discarded by every caller (DELETE statements only), so the
20
+ * contract is fire-and-forget. */
14
21
  export interface SqlRunner {
15
- readonly run: (query: string | SQLWrapper<unknown>) => unknown;
22
+ readonly run: (query: string | SQLWrapper<unknown>) => void;
16
23
  }
17
24
  /** Delete one topic's sum-vector row (merge absorbs the sibling's row). */
18
25
  export declare const deleteTopicVectorRow: (runner: SqlRunner, model: EmbeddingModelConfig, topicKey: string) => Promise<void>;
@@ -91,10 +91,13 @@ export declare const canonicalOrder: (vectors: readonly Float32Array[]) => reado
91
91
  * For fewer than 2 vectors returns `{ a: 0, b: 0 }` (degenerate — callers
92
92
  * guard on counts before splitting). Never mutates input.
93
93
  */
94
- export declare const farthestPair: (vectors: readonly Float32Array[]) => {
95
- a: number;
96
- b: number;
97
- };
94
+ /** The farthest-seed pair — `a` is fixed by the canonical order; `b` is
95
+ * the vector with the lowest dot product against `a`. */
96
+ export interface FarthestPair {
97
+ readonly a: number;
98
+ readonly b: number;
99
+ }
100
+ export declare const farthestPair: (vectors: readonly Float32Array[]) => FarthestPair;
98
101
  /**
99
102
  * Assign every vector to group 0 or 1 by higher dot product against the
100
103
  * seed vectors at `seedA` / `seedB`; ties go to group 0 (smaller index).
@@ -119,11 +122,14 @@ export declare const assignNearest: (vectors: readonly Float32Array[], seedA: nu
119
122
  *
120
123
  * Never mutates inputs.
121
124
  */
122
- export declare const lloydRefine: (vectors: readonly Float32Array[], groups: Uint8Array, passes: number) => {
123
- groups: Uint8Array;
124
- leftCf: CfTriplet;
125
- rightCf: CfTriplet;
126
- };
125
+ /** Outcome of the Lloyd refinement — the assignment plus each group's
126
+ * CF triplet (the split-plan acceptance gates read these). */
127
+ export interface LloydRefineResult {
128
+ readonly groups: Uint8Array;
129
+ readonly leftCf: CfTriplet;
130
+ readonly rightCf: CfTriplet;
131
+ }
132
+ export declare const lloydRefine: (vectors: readonly Float32Array[], groups: Uint8Array, passes: number) => LloydRefineResult;
127
133
  /** Outcome of {@link splitPlan} — accepted splits plus the acceptance gate diagnostics. */
128
134
  export interface SplitPlanResult {
129
135
  readonly accepted: boolean;
@@ -28,9 +28,9 @@
28
28
  * `Schema.Unknown` Persistable keys — see persistence.ts for why.
29
29
  */
30
30
  import { Layer } from "effect";
31
- import { WorkflowEngine } from "effect/unstable/workflow";
32
- import { Persistence as PersistenceNamespace, PersistedQueue } from "effect/unstable/persistence";
33
- import { SqlError as SqlErrorNamespace } from "effect/unstable/sql";
31
+ import { WorkflowEngine } from "effect/workflow";
32
+ import { Persistence as PersistenceNamespace, PersistedQueue } from "effect/persistence";
33
+ import { SqlError as SqlErrorNamespace } from "effect/sql";
34
34
  type SqlError = SqlErrorNamespace.SqlError;
35
35
  /**
36
36
  * Durable WorkflowEngine layer.
@@ -40,6 +40,14 @@ type SqlError = SqlErrorNamespace.SqlError;
40
40
  * (same `Encoded` contract into `makeUnsafe`).
41
41
  */
42
42
  export declare const layerDurable: Layer.Layer<WorkflowEngine.WorkflowEngine, never, PersistedQueue.PersistedQueueFactory | PersistenceNamespace.Persistence>;
43
+ /**
44
+ * Shared libSQL stack: SQL persistence + resume-queue store over one
45
+ * `LibsqlClient`. Provides `Persistence | PersistedQueueFactory`, dep-free.
46
+ *
47
+ * The single libSQL connection is shared by the engine's store and the
48
+ * resume queue — both `Persistence.layerSql` and `PersistedQueue.layerStoreSql`
49
+ * create their own tables in the same file.
50
+ */
43
51
  export declare const libsqlStack: (options: {
44
52
  readonly url: string;
45
53
  }) => Layer.Layer<PersistedQueue.PersistedQueueFactory | PersistenceNamespace.Persistence, SqlErrorNamespace.SqlError, never>;
@@ -51,4 +59,20 @@ export declare const libsqlStack: (options: {
51
59
  export declare const layerDurableLibsql: (options: {
52
60
  readonly url: string;
53
61
  }) => Layer.Layer<WorkflowEngine.WorkflowEngine, SqlError>;
62
+ /**
63
+ * OpenCode-style node declarations for the two libSQL-backed layers above.
64
+ *
65
+ * The convention's single `configured` name is per-layer, and this module
66
+ * exposes two, so each is declared under its layer's name; the shape
67
+ * (`make({ name, layer })`, empty `deps` — the root wires the runtime, the
68
+ * registry and the store) is unchanged. Neither gets a default `node`: both
69
+ * require a `url`, and a node that guessed one would silently point a
70
+ * durable engine at the wrong database.
71
+ */
72
+ export declare const libsqlStackConfigured: (options: {
73
+ readonly url: string;
74
+ }) => import("../core/index.js").LayerProvider<PersistedQueue.PersistedQueueFactory | PersistenceNamespace.Persistence, SqlErrorNamespace.SqlError, undefined>;
75
+ export declare const layerDurableLibsqlConfigured: (options: {
76
+ readonly url: string;
77
+ }) => import("../core/index.js").LayerProvider<WorkflowEngine.WorkflowEngine, SqlErrorNamespace.SqlError, undefined>;
54
78
  export {};
@@ -14,10 +14,11 @@
14
14
  * resumes the awaiting workflow (facade `submit`) and persists the result.
15
15
  */
16
16
  import { Duration, Effect, Layer } from "effect";
17
- import { WorkflowEngine } from "effect/unstable/workflow";
18
- import { PersistedQueue } from "effect/unstable/persistence";
19
- import { type LogConfig } from "./internal/logger/index.js";
20
- import type { JobDefinition } from "./queue.ts";
17
+ import { WorkflowEngine } from "effect/workflow";
18
+ import { PersistedQueue } from "effect/persistence";
19
+ import { type LogConfig } from "../logger/index.js";
20
+ import { type Graph } from "../shared/effect/node.js";
21
+ import { type JobDefinition } from "./queue.ts";
21
22
  import { Service as JobRegistry } from "./registry.ts";
22
23
  import { Service as JobRuntime } from "./runtime.ts";
23
24
  export declare const workerLayer: (defs: readonly JobDefinition.Any[], options?: {
@@ -27,7 +28,20 @@ export declare const workerLayer: (defs: readonly JobDefinition.Any[], options?:
27
28
  * [1, 100]. */
28
29
  readonly maxAttempts?: number;
29
30
  readonly logging?: LogConfig;
30
- }) => Layer.Layer<never, never, PersistedQueue.PersistedQueueFactory | JobRegistry | WorkflowEngine.WorkflowEngine> | Layer.Layer<import("./internal/logger/index.js").Logging, never, PersistedQueue.PersistedQueueFactory | import("effect/Scope").Scope | JobRegistry | WorkflowEngine.WorkflowEngine>;
31
+ }) => Layer.Layer<never, never, PersistedQueue.PersistedQueueFactory | JobRegistry | WorkflowEngine.WorkflowEngine>;
32
+ /**
33
+ * OpenCode-style node declaration for {@link workerLayer}.
34
+ *
35
+ * Workers need `WorkflowEngine` + `PersistedQueueFactory` (the job stack) and
36
+ * `JobRegistry`, and those providers are root-owned state: a package default
37
+ * would build a SECOND job stack and bind the worker to it, so there is no
38
+ * `node` export here — the caller passes them as the `deps` tuple and `make`
39
+ * checks that they cover the layer's requirements. The tuple elements may be
40
+ * any graph that provides at least the named services, and their build errors
41
+ * are preserved on the node. The options type is read off `workerLayer` so the
42
+ * declaration cannot drift from the layer it wraps.
43
+ */
44
+ export declare const configured: <const RuntimeE, const RegistryE>(defs: readonly JobDefinition.Any[], options: Parameters<typeof workerLayer>[1], deps: readonly [Graph<PersistedQueue.PersistedQueueFactory | WorkflowEngine.WorkflowEngine, RuntimeE>, Graph<JobRegistry, RegistryE>]) => import("../core/index.js").LayerProvider<never, RegistryE | RuntimeE, undefined>;
31
45
  /**
32
46
  * Inline mode — run the worker in the same fiber scope as the submit.
33
47
  *
@@ -38,7 +52,7 @@ export declare const workerLayer: (defs: readonly JobDefinition.Any[], options?:
38
52
  * Requires the full stack (JobRuntime + engine + queue + registry); use
39
53
  * `workerLayer` for persistent processes instead.
40
54
  */
41
- export declare const inline: (def: JobDefinition.Any, payload: unknown, options?: {
55
+ export declare const inline: <P>(def: JobDefinition.Any, payload: P, options?: {
42
56
  readonly concurrency?: number;
43
57
  readonly maxAttempts?: number;
44
58
  }) => Effect.Effect<unknown, unknown, WorkflowEngine.WorkflowEngine | PersistedQueue.PersistedQueueFactory | JobRegistry | JobRuntime>;
@@ -4,10 +4,10 @@
4
4
  * Barrel: named exports with aliases (project convention).
5
5
  */
6
6
  export { JobDefinition, Envelope, TopicSplit, MemoryEmbed, TopicMerge, TopicRebalance, ConceptCluster, MemoryDream, GraphRepair, AuditWrite, type AuditRow, queues, type EnvelopeSchema, } from "./queue.ts";
7
- export { Service as JobRuntime, layer as jobRuntimeLayer, type Interface as JobRuntimeInterface, type JobStatus, } from "./runtime.ts";
8
- export { layerDurable, layerDurableLibsql } from "./engine.ts";
9
- export { Service as JobRegistry, layer as jobRegistryLayer, JobFailure, type Handler, type JobContext, } from "./registry.ts";
10
- export { workerLayer, inline, processQueues } from "./executor.ts";
7
+ export { Service as JobRuntime, layer as jobRuntimeLayer, configured as jobRuntimeConfigured, node as jobRuntimeNode, type Interface as JobRuntimeInterface, type JobStatus, } from "./runtime.ts";
8
+ export { layerDurable, layerDurableLibsql, libsqlStackConfigured, layerDurableLibsqlConfigured, } from "./engine.ts";
9
+ export { Service as JobRegistry, layer as jobRegistryLayer, configured as jobRegistryConfigured, node as jobRegistryNode, JobFailure, type Handler, type JobContext, } from "./registry.ts";
10
+ export { workerLayer, configured as workersConfigured, inline, processQueues } from "./executor.ts";
11
11
  export { JobsConfig, JobsConfigDefaults, resolveJobsConfig } from "./config.ts";
12
12
  export { QueueError, UnknownJobType, RegistryError, ShutdownError, JobFailed, JobTimeout, JobCancelled, type JobRuntimeError, type JobsError, } from "./errors.ts";
13
13
  export { STORE_ID, RESUME_QUEUE, ResumeSignal, ExecutionRecord, encodedKey, resultCodecFor, payloadCodecFor, } from "./persistence.ts";
@@ -32,9 +32,9 @@
32
32
  *
33
33
  */
34
34
  import { Effect, Exit, Option, Schema } from "effect";
35
- import { Persistable, Persistence as PersistenceNamespace } from "effect/unstable/persistence";
35
+ import { Persistable, Persistence as PersistenceNamespace } from "effect/persistence";
36
36
  type PersistenceStore = PersistenceNamespace.PersistenceStore;
37
- import { Workflow } from "effect/unstable/workflow";
37
+ import { Workflow } from "effect/workflow";
38
38
  /** Single store id shared by engine + facade (one table partition in jobs.db). */
39
39
  export declare const STORE_ID = "dimple/jobs";
40
40
  /**
@@ -56,7 +56,7 @@ export interface ResumeSignal extends Schema.Schema.Type<typeof ResumeSignal> {
56
56
  */
57
57
  export declare const ExecutionRecord: Schema.Struct<{
58
58
  readonly workflowTag: Schema.String;
59
- readonly payload: Schema.$Record<Schema.String, Schema.Unknown>;
59
+ readonly payload: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
60
60
  }>;
61
61
  export interface ExecutionRecord extends Schema.Schema.Type<typeof ExecutionRecord> {
62
62
  }
@@ -30,8 +30,8 @@
30
30
  *
31
31
  */
32
32
  import { Effect, Schema, Scope } from "effect";
33
- import { DurableQueue, Workflow, WorkflowEngine } from "effect/unstable/workflow";
34
- import { PersistedQueue } from "effect/unstable/persistence";
33
+ import { DurableQueue, Workflow, WorkflowEngine } from "effect/workflow";
34
+ import { PersistedQueue } from "effect/persistence";
35
35
  /**
36
36
  * Envelope schema factory — wraps a job's payload schema with the runtime
37
37
  * fields the workflow machinery needs.
@@ -75,8 +75,11 @@ export declare class JobDefinition<Payload extends Workflow.AnyStructSchema = Wo
75
75
  /**
76
76
  * Decodes an envelope back to `{ payload }`. Built in `make` where the
77
77
  * schema types are concrete; the erased `Any` form widens the result.
78
+ * The engine delivers the workflow payload per its `register` contract
79
+ * (the decoded envelope type); the runtime decode below re-validates it
80
+ * against the envelope schema before the payload reaches the queue.
78
81
  */
79
- readonly decodeEnvelope: (envelope: unknown) => Effect.Effect<{
82
+ readonly decodeEnvelope: (envelope: EnvelopeSchema<Payload>["Type"]) => Effect.Effect<{
80
83
  readonly payload: Payload["Type"];
81
84
  }, never, Payload["DecodingServices"] | Payload["EncodingServices"]>;
82
85
  constructor(args: {
@@ -87,7 +90,7 @@ export declare class JobDefinition<Payload extends Workflow.AnyStructSchema = Wo
87
90
  readonly successSchema: Success;
88
91
  readonly errorSchema: Error;
89
92
  readonly idempotencyKey: (payload: Payload["Type"]) => string;
90
- readonly decodeEnvelope: (envelope: unknown) => Effect.Effect<{
93
+ readonly decodeEnvelope: (envelope: EnvelopeSchema<Payload>["Type"]) => Effect.Effect<{
91
94
  readonly payload: Payload["Type"];
92
95
  }, never, Payload["DecodingServices"] | Payload["EncodingServices"]>;
93
96
  });
@@ -145,7 +148,7 @@ export declare namespace JobDefinition {
145
148
  readonly successSchema: Schema.Top;
146
149
  readonly errorSchema: Schema.Top;
147
150
  readonly idempotencyKey: (payload: any) => string;
148
- readonly decodeEnvelope: (envelope: unknown) => Effect.Effect<{
151
+ readonly decodeEnvelope: (envelope: any) => Effect.Effect<{
149
152
  readonly payload: unknown;
150
153
  }, never, unknown>;
151
154
  readonly register: (engine: WorkflowEngine.WorkflowEngine["Service"]) => Effect.Effect<void, never, Scope.Scope | PersistedQueue.PersistedQueueFactory>;
@@ -29,7 +29,7 @@ export interface JobContext {
29
29
  * decoded payload and returns the job's success value (or fails with
30
30
  * `JobFailure`); the runtime owns retries/leases.
31
31
  */
32
- export type Handler = (payload: unknown, ctx: JobContext) => Effect.Effect<unknown, JobFailure>;
32
+ export type Handler = (payload: any, ctx: JobContext) => Effect.Effect<unknown, JobFailure>;
33
33
  /**
34
34
  * JobRegistry service contract.
35
35
  *
@@ -54,4 +54,14 @@ export declare class Service extends Service_base {
54
54
  * unknown resolve fails with `UnknownJobType`.
55
55
  */
56
56
  export declare const layer: Layer.Layer<Service, never, never>;
57
+ /**
58
+ * OpenCode-style node declaration for the {@link layer} job registry.
59
+ *
60
+ * `deps` is empty: the registry is dependency-free by construction (handlers
61
+ * are registered by the composition root, which owns the runtime and the
62
+ * store they need).
63
+ */
64
+ export declare const configured: () => import("../core/index.js").LayerProvider<Service, never, undefined>;
65
+ /** The default registry node — the one the app graph always wires. */
66
+ export declare const node: import("../core/index.js").LayerProvider<Service, never, undefined>;
57
67
  export {};
@@ -51,10 +51,10 @@
51
51
  *
52
52
  */
53
53
  import { Context, Duration, Effect, Layer, Schema } from "effect";
54
- import { Workflow, WorkflowEngine } from "effect/unstable/workflow";
55
- import { PersistedQueue, Persistence as PersistenceNamespace } from "effect/unstable/persistence";
56
- import { SqlError as SqlErrorNamespace } from "effect/unstable/sql";
57
- import type { JobDefinition } from "./queue.ts";
54
+ import { Workflow, WorkflowEngine } from "effect/workflow";
55
+ import { PersistedQueue, Persistence as PersistenceNamespace } from "effect/persistence";
56
+ import { SqlError as SqlErrorNamespace } from "effect/sql";
57
+ import { type JobDefinition } from "./queue.ts";
58
58
  import { type JobsError } from "./errors.ts";
59
59
  type SqlError = SqlErrorNamespace.SqlError;
60
60
  /**
@@ -158,4 +158,22 @@ export declare const layer: (defs: readonly JobDefinition.Any[]) => Layer.Layer<
158
158
  export declare const layerLibsql: (defs: readonly JobDefinition.Any[], options: {
159
159
  readonly url: string;
160
160
  }) => Layer.Layer<Service | WorkflowEngine.WorkflowEngine | PersistenceNamespace.Persistence | PersistedQueue.PersistedQueueFactory, SqlError>;
161
+ /**
162
+ * OpenCode-style node declaration for {@link layerLibsql}.
163
+ *
164
+ * `deps` is empty: the libSQL client, the durable engine, persistence and
165
+ * the queue factory all arrive from the node's own layer; the root only adds
166
+ * what the *consumers* (workers, the store's job seams) need.
167
+ */
168
+ export declare const configured: (defs: readonly JobDefinition.Any[], options: {
169
+ readonly url: string;
170
+ }) => import("../core/index.js").LayerProvider<PersistedQueue.PersistedQueueFactory | PersistenceNamespace.Persistence | Service | WorkflowEngine.WorkflowEngine, SqlErrorNamespace.SqlError, undefined>;
171
+ /**
172
+ * The default job-stack node — every built-in definition over the package's
173
+ * documented jobs database default (`JobsConfigDefaults.dbUrl`,
174
+ * `file:./.dimple/jobs.db`), the same value `resolveJobsConfig` fills when
175
+ * the `jobs` section omits `dbUrl`. Nothing is connected at import: the
176
+ * node only holds a lazily-built layer.
177
+ */
178
+ export declare const node: import("../core/index.js").LayerProvider<PersistedQueue.PersistedQueueFactory | PersistenceNamespace.Persistence | Service | WorkflowEngine.WorkflowEngine, SqlErrorNamespace.SqlError, undefined>;
161
179
  export {};
@@ -0,0 +1,21 @@
1
+ /**
2
+ * In-process execution-completion signals — the event side of `Runtime.wait`.
3
+ *
4
+ * `wait` used to poll the persisted `${jobId}/result` key every 250ms. The
5
+ * engine knows the exact completion moment, so it now notifies a per-
6
+ * executionId set of Deferreds; `wait` races the signal against its poll
7
+ * interval (the poll stays as the fallback for cross-process waits, where
8
+ * the completing engine lives in another process).
9
+ *
10
+ * Plain module-level Map — no Effect service: the signal is a fire-and-
11
+ * forget wakeup, and the subscribers are runtime-layer Deferreds. Cleanup
12
+ * on unsubscribe keeps the map from leaking job ids.
13
+ */
14
+ import { Deferred, Effect } from "effect";
15
+ /** Subscribe to one execution's completion. */
16
+ export declare const onExecutionDone: (executionId: string, deferred: Deferred.Deferred<void>) => void;
17
+ /** Unsubscribe (wait's finally — the poll fallback may still be running). */
18
+ export declare const offExecutionDone: (executionId: string, deferred: Deferred.Deferred<void>) => void;
19
+ /** Fire every subscriber's deferred (the engine's completion tap) — an
20
+ * Effect the caller forks, so no Effect.run* leaks into package code. */
21
+ export declare const notifyExecutionDone: (executionId: string) => Effect.Effect<void>;
package/dist/make.d.ts CHANGED
@@ -16,6 +16,12 @@ export type MakeDimpleOptions = {
16
16
  } | {
17
17
  readonly core: CoreOptions;
18
18
  };
19
+ /** What changed between the live config and the resolved one. */
20
+ export interface ConfigDiff {
21
+ readonly storeUrl: boolean;
22
+ readonly jobsUrl: boolean;
23
+ readonly rest: boolean;
24
+ }
19
25
  /**
20
26
  * Create the Dimple facade — resolves once the composed system is fully
21
27
  * booted. One runtime is built from the application layer; `runPromise`
@@ -23,5 +29,26 @@ export type MakeDimpleOptions = {
23
29
  * Boot failures reject with the same closed `DimpleError` surface as the
24
30
  * facade methods (never raw Effect internals) and close the owned
25
31
  * resources (scope + runtime) before rethrowing.
32
+ *
33
+ * ### Reload (see `Dimple.reload`)
34
+ *
35
+ * The facade owns a mutable `LiveStack` cell. A reload:
36
+ *
37
+ * 1. re-resolves the config source TYPED (schema errors reject before
38
+ * anything pauses — a bad config has zero impact);
39
+ * 2. pauses: new calls wait on the gate, calls already in flight settle on
40
+ * the OLD stack;
41
+ * 3. boots a fresh stack from the re-resolved config;
42
+ * 4. drains (waits the in-flight count to zero, bounded by
43
+ * `RELOAD_DRAIN_MS`), then swaps the cell and disposes the old stack
44
+ * (worker fleet stops, clients close);
45
+ * 5. releases the gate. Boot or drain failure leaves the old stack
46
+ * untouched — the reload rejects and the system keeps serving the
47
+ * previous config (blue-green).
48
+ *
49
+ * Durable jobs make the pause safe: a handler interrupted by the old
50
+ * stack's disposal has its lease expire and is re-claimed after boot;
51
+ * handlers are idempotent by design (transactions roll back, watermarks
52
+ * advance only on success).
26
53
  */
27
54
  export declare const makeDimple: (options: MakeDimpleOptions) => Promise<Dimple>;
package/package.json CHANGED
@@ -1,7 +1,25 @@
1
1
  {
2
2
  "name": "@ponraaj/dimple-sdk",
3
- "version": "0.0.0-alpha.1",
3
+ "version": "0.0.0-alpha.11",
4
4
  "private": false,
5
+ "description": "Local-first memory for AI agents: durable text and code memories with hybrid semantic and lexical retrieval.",
6
+ "keywords": [
7
+ "ai-agents",
8
+ "embeddings",
9
+ "libsql",
10
+ "local-first",
11
+ "memory",
12
+ "semantic-search"
13
+ ],
14
+ "homepage": "https://dimple.ponraaj.me",
15
+ "bugs": {
16
+ "url": "https://github.com/Ponraaj/dimple/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/Ponraaj/dimple.git",
21
+ "directory": "packages/sdk"
22
+ },
5
23
  "files": [
6
24
  "dist"
7
25
  ],
@@ -23,23 +41,29 @@
23
41
  "publishConfig": {
24
42
  "access": "public"
25
43
  },
26
- "scripts": {
27
- "build": "rm -rf dist && bun build ./src/index.ts --outdir ./dist --target node --format esm --external effect --external zod --external ai --external \"@ai-sdk/*\" --external @libsql/client --external drizzle-orm --external jsonc-parser --external \"@huggingface/transformers\" --external web-tree-sitter && tsgo -p tsconfig.build.json --outDir dist/.raw && bun scripts/internalize-dts.ts",
28
- "prepack": "bun run build",
29
- "typecheck": "tsgo --noEmit"
30
- },
31
44
  "dependencies": {
32
- "@ai-sdk/openai-compatible": "^1.0.0",
33
- "@huggingface/transformers": "^4.2.0",
45
+ "@ai-sdk/amazon-bedrock": "^5.0.46",
46
+ "@ai-sdk/cohere": "^3",
47
+ "@ai-sdk/google": "^2",
48
+ "@ai-sdk/openai-compatible": "^3.0.21",
34
49
  "@libsql/client": "^0.17.4",
35
- "ai": "^5.0.0",
50
+ "ai": "^7.0.50",
36
51
  "drizzle-orm": "^1.0.0-rc.4",
37
- "effect": "4.0.0-beta.103",
52
+ "effect": "4.0.0",
38
53
  "jsonc-parser": "^3.3.1",
39
54
  "web-tree-sitter": "^0.26.9",
40
55
  "zod": "^4.4.3"
41
56
  },
42
57
  "peerDependencies": {
58
+ "@huggingface/transformers": "^4.0.0",
43
59
  "typescript": "^5"
60
+ },
61
+ "peerDependenciesMeta": {
62
+ "@huggingface/transformers": {
63
+ "optional": true
64
+ }
65
+ },
66
+ "engines": {
67
+ "node": ">=22"
44
68
  }
45
69
  }
@@ -1,8 +0,0 @@
1
- import { type EmbeddingModel } from "./provider.ts";
2
- export interface OpenAIOptions {
3
- readonly modelId: string;
4
- readonly model: string;
5
- readonly dimensions: number;
6
- readonly apiKey: string;
7
- }
8
- export declare const makeOpenAIModel: (options: OpenAIOptions) => EmbeddingModel;
@@ -1,14 +0,0 @@
1
- import { Context, Effect, Layer } from "effect";
2
- import { GrammarProvisionError } from "@dimple/shared/errors";
3
- import { Service as TreeSitterRegistry } from "./wasm-registry";
4
- import { Service as WasmDownloader } from "./wasm-downloader";
5
- import { Service as WasmCache } from "./wasm-cache";
6
- export interface Interface {
7
- readonly ensure: (lang: string) => Effect.Effect<string, GrammarProvisionError>;
8
- }
9
- declare const Service_base: Context.ServiceClass<Service, "@dimple/wasm/GrammarStore", Interface>;
10
- export declare class Service extends Service_base {
11
- }
12
- export declare const layer: Layer.Layer<Service, never, TreeSitterRegistry | WasmDownloader | WasmCache>;
13
- export declare const allLive: Layer.Layer<TreeSitterRegistry | WasmDownloader | WasmCache | Service, never, never>;
14
- export {};
@@ -1,5 +0,0 @@
1
- export { Service as TreeSitterRegistry } from "./wasm-registry";
2
- export type { GrammarMetaData } from "./wasm-registry";
3
- export { Service as WasmDownloader } from "./wasm-downloader";
4
- export { Service as WasmCache, layer as wasmCacheLayer } from "./wasm-cache";
5
- export { Service as GrammarStore, layer as grammarStoreLayer, allLive as GrammarStoreAllLive, } from "./grammar-store";
@@ -1,17 +0,0 @@
1
- import { Context, Effect, Layer } from "effect";
2
- import { WasmCacheError } from "@dimple/shared/errors";
3
- /**
4
- * Grammar WASM cache — downloads are staged to a temp file and renamed
5
- * into place (an interrupted download never leaves a corrupt parser).
6
- * Plain `node:fs` (NOT @effect/platform-bun): the bundled SDK runs on
7
- * Node too (the CLI's shebang spawns node), so Bun-specific filesystem
8
- * layers are off the table.
9
- */
10
- export interface Interface {
11
- readonly ensure: (lang: string, version: string, download: Effect.Effect<Uint8Array>) => Effect.Effect<string, WasmCacheError>;
12
- }
13
- declare const Service_base: Context.ServiceClass<Service, "@dimple/wasm/WasmCache", Interface>;
14
- export declare class Service extends Service_base {
15
- }
16
- export declare const layer: Layer.Layer<Service, never, never>;
17
- export {};
@@ -1,10 +0,0 @@
1
- import { Context, Effect, Layer } from "effect";
2
- import { WasmDownloadError } from "@dimple/shared/errors";
3
- export interface Interface {
4
- readonly download: (url: string) => Effect.Effect<Uint8Array, WasmDownloadError>;
5
- }
6
- declare const Service_base: Context.ServiceClass<Service, "@dimple/wasm/WasmDownloader", Interface>;
7
- export declare class Service extends Service_base {
8
- static readonly layer: Layer.Layer<Service, never, never>;
9
- }
10
- export {};
@@ -1,16 +0,0 @@
1
- import { Context, Effect, Layer, Schema } from "effect";
2
- import { RegistryError } from "@dimple/shared/errors";
3
- declare const GrammarMetaDataSchema: Schema.Struct<{
4
- readonly lang: Schema.String;
5
- readonly version: Schema.String;
6
- readonly url: Schema.String;
7
- }>;
8
- export type GrammarMetaData = typeof GrammarMetaDataSchema.Type;
9
- export interface Interface {
10
- readonly resolve: (lang: string) => Effect.Effect<GrammarMetaData, RegistryError>;
11
- }
12
- declare const Service_base: Context.ServiceClass<Service, "@dimple/wasm/TreeSitterRegistry", Interface>;
13
- export declare class Service extends Service_base {
14
- static readonly layer: Layer.Layer<Service, never, never>;
15
- }
16
- export {};
@@ -1,5 +0,0 @@
1
- import { Layer } from "effect";
2
- import { PersistedQueue } from "effect/unstable/persistence";
3
- import { SqlClient, SqlError } from "effect/unstable/sql";
4
- /** Provide the FIXED store to effect's `PersistedQueue.layer`. */
5
- export declare const storeSqliteLayer: Layer.Layer<PersistedQueue.PersistedQueueStore, SqlError.SqlError, SqlClient.SqlClient>;