@ponraaj/dimple-sdk 0.0.0-alpha.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 (101) hide show
  1. package/dist/config.d.ts +13 -0
  2. package/dist/dimple.d.ts +101 -0
  3. package/dist/errors.d.ts +63 -0
  4. package/dist/index.d.ts +4 -0
  5. package/dist/index.js +8430 -0
  6. package/dist/indexer.d.ts +43 -0
  7. package/dist/internal/config/index.d.ts +4 -0
  8. package/dist/internal/config/loader.d.ts +9 -0
  9. package/dist/internal/config/schema.d.ts +176 -0
  10. package/dist/internal/config/service.d.ts +10 -0
  11. package/dist/internal/core/core.d.ts +95 -0
  12. package/dist/internal/core/index.d.ts +3 -0
  13. package/dist/internal/core/layer.d.ts +21 -0
  14. package/dist/internal/embedder/index.d.ts +4 -0
  15. package/dist/internal/embedder/openai.d.ts +8 -0
  16. package/dist/internal/embedder/provider.d.ts +29 -0
  17. package/dist/internal/embedder/registry.d.ts +10 -0
  18. package/dist/internal/embedder/transformers.d.ts +18 -0
  19. package/dist/internal/extractor/code-extractor.d.ts +15 -0
  20. package/dist/internal/extractor/content-handler.d.ts +17 -0
  21. package/dist/internal/extractor/index.d.ts +4 -0
  22. package/dist/internal/extractor/languages/index.d.ts +24 -0
  23. package/dist/internal/extractor/languages/javascript.d.ts +22 -0
  24. package/dist/internal/extractor/languages/typescript.d.ts +20 -0
  25. package/dist/internal/extractor/models/extraction.d.ts +53 -0
  26. package/dist/internal/llm/dream-classifier.d.ts +14 -0
  27. package/dist/internal/llm/index.d.ts +4 -0
  28. package/dist/internal/llm/llm.d.ts +54 -0
  29. package/dist/internal/llm/provider.d.ts +14 -0
  30. package/dist/internal/llm/service.d.ts +29 -0
  31. package/dist/internal/logger/format.d.ts +6 -0
  32. package/dist/internal/logger/index.d.ts +4 -0
  33. package/dist/internal/logger/ring.d.ts +33 -0
  34. package/dist/internal/logger/service.d.ts +50 -0
  35. package/dist/internal/logger/types.d.ts +39 -0
  36. package/dist/internal/parser/code-parser.d.ts +12 -0
  37. package/dist/internal/parser/index.d.ts +7 -0
  38. package/dist/internal/parser/language-store.d.ts +12 -0
  39. package/dist/internal/parser/models/parseRequest.d.ts +17 -0
  40. package/dist/internal/parser/models/treeHandle.d.ts +23 -0
  41. package/dist/internal/parser/tree-sitter-engine.d.ts +15 -0
  42. package/dist/internal/retriever/hybrid.d.ts +48 -0
  43. package/dist/internal/retriever/index.d.ts +3 -0
  44. package/dist/internal/retriever/rrf.d.ts +11 -0
  45. package/dist/internal/shared/errors/index.d.ts +2 -0
  46. package/dist/internal/shared/errors/parser.d.ts +21 -0
  47. package/dist/internal/shared/errors/wasm.d.ts +28 -0
  48. package/dist/internal/shared/types/index.d.ts +1 -0
  49. package/dist/internal/shared/types/language.d.ts +3 -0
  50. package/dist/internal/store/audit.d.ts +21 -0
  51. package/dist/internal/store/db-backend.d.ts +111 -0
  52. package/dist/internal/store/drizzle-schema.d.ts +1 -0
  53. package/dist/internal/store/error.d.ts +19 -0
  54. package/dist/internal/store/fnv1a32.d.ts +14 -0
  55. package/dist/internal/store/generated-migrations.d.ts +15 -0
  56. package/dist/internal/store/graph/candidates.d.ts +93 -0
  57. package/dist/internal/store/graph/concepts.d.ts +169 -0
  58. package/dist/internal/store/graph/dream.d.ts +171 -0
  59. package/dist/internal/store/graph/errors.d.ts +25 -0
  60. package/dist/internal/store/graph/index.d.ts +15 -0
  61. package/dist/internal/store/graph/observability.d.ts +37 -0
  62. package/dist/internal/store/graph/repair.d.ts +85 -0
  63. package/dist/internal/store/graph/retrieval-post-pass.d.ts +58 -0
  64. package/dist/internal/store/graph/traversal.d.ts +39 -0
  65. package/dist/internal/store/index.d.ts +38 -0
  66. package/dist/internal/store/libsql-backend.d.ts +18 -0
  67. package/dist/internal/store/models.d.ts +122 -0
  68. package/dist/internal/store/schema/graph.d.ts +970 -0
  69. package/dist/internal/store/schema/index.d.ts +7 -0
  70. package/dist/internal/store/schema/libsql.d.ts +2356 -0
  71. package/dist/internal/store/schema/metadata.d.ts +51 -0
  72. package/dist/internal/store/schema/topics.d.ts +1966 -0
  73. package/dist/internal/store/service.d.ts +162 -0
  74. package/dist/internal/store/store.d.ts +70 -0
  75. package/dist/internal/store/topics/errors.d.ts +39 -0
  76. package/dist/internal/store/topics/index.d.ts +24 -0
  77. package/dist/internal/store/topics/jobs.d.ts +149 -0
  78. package/dist/internal/store/topics/lifecycle.d.ts +126 -0
  79. package/dist/internal/store/topics/maintenance.d.ts +110 -0
  80. package/dist/internal/store/topics/observability.d.ts +102 -0
  81. package/dist/internal/store/topics/query.d.ts +43 -0
  82. package/dist/internal/store/topics/routing.d.ts +90 -0
  83. package/dist/internal/store/topics/topic-vectors.d.ts +24 -0
  84. package/dist/internal/store/topics/tree.d.ts +181 -0
  85. package/dist/internal/wasm/grammar-store.d.ts +14 -0
  86. package/dist/internal/wasm/index.d.ts +5 -0
  87. package/dist/internal/wasm/wasm-cache.d.ts +17 -0
  88. package/dist/internal/wasm/wasm-downloader.d.ts +10 -0
  89. package/dist/internal/wasm/wasm-registry.d.ts +16 -0
  90. package/dist/internal/workflow/config.d.ts +39 -0
  91. package/dist/internal/workflow/engine.d.ts +54 -0
  92. package/dist/internal/workflow/errors.d.ts +77 -0
  93. package/dist/internal/workflow/executor.d.ts +53 -0
  94. package/dist/internal/workflow/index.d.ts +13 -0
  95. package/dist/internal/workflow/persistence.d.ts +122 -0
  96. package/dist/internal/workflow/queue-store.d.ts +5 -0
  97. package/dist/internal/workflow/queue.d.ts +298 -0
  98. package/dist/internal/workflow/registry.d.ts +57 -0
  99. package/dist/internal/workflow/runtime.d.ts +161 -0
  100. package/dist/make.d.ts +27 -0
  101. package/package.json +45 -0
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Durable WorkflowEngine — libSQL-backed, replay-based, cross-process
3
+ * resumable.
4
+ *
5
+ * Mirrors Effect's `WorkflowEngine.layerMemory` (in-memory impl) but swaps the
6
+ * Maps for a `PersistenceStore` over the same libSQL instance as the queue
7
+ * (jobs.db). Suspended workflows, deferred results, and activity results
8
+ * survive process restarts and can be resumed by any process.
9
+ *
10
+ * Validated semantics:
11
+ * - result persisted ONLY on Complete (never Suspended)
12
+ * - interrupted flags NOT persisted
13
+ * - replay = re-execute workflow from start; activities served from persisted
14
+ * results (never re-run); suspend when deferred result absent
15
+ * - workflow registry + in-flight fibers stay process-local (handlers are
16
+ * registered at startup; nothing to persist)
17
+ *
18
+ * Cross-process resume:
19
+ * - `{executionId}/record` persists `{ workflowTag, payload }` on first
20
+ * submission — a new process reconstructs execution state from it
21
+ * - `deferredDone` offers a durable resume signal (`dimple/resume` queue,
22
+ * idempotent by executionId) so any process's drainer can resume
23
+ * - `resume`/`execute` reconstruct from the record when the execution is not
24
+ * in this process
25
+ *
26
+ * Storage split: deferred/activity/result/payload all
27
+ * live in one `PersistenceStore` (storeId "dimple/jobs") with
28
+ * `Schema.Unknown` Persistable keys — see persistence.ts for why.
29
+ */
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";
34
+ type SqlError = SqlErrorNamespace.SqlError;
35
+ /**
36
+ * Durable WorkflowEngine layer.
37
+ *
38
+ * Requires `Persistence` (deferred/activity/result/payload store) +
39
+ * `PersistedQueueFactory` (resume-signal queue). Mirrors `layerMemory`'s shape
40
+ * (same `Encoded` contract into `makeUnsafe`).
41
+ */
42
+ export declare const layerDurable: Layer.Layer<WorkflowEngine.WorkflowEngine, never, PersistedQueue.PersistedQueueFactory | PersistenceNamespace.Persistence>;
43
+ export declare const libsqlStack: (options: {
44
+ readonly url: string;
45
+ }) => Layer.Layer<PersistedQueue.PersistedQueueFactory | PersistenceNamespace.Persistence, SqlErrorNamespace.SqlError, never>;
46
+ /**
47
+ * Convenience layer: durable engine + SQL persistence + resume queue + libSQL
48
+ * client, all sharing one libSQL instance. Surfaces `SqlError` from the
49
+ * backing store. Provides `WorkflowEngine` only (deps hidden).
50
+ */
51
+ export declare const layerDurableLibsql: (options: {
52
+ readonly url: string;
53
+ }) => Layer.Layer<WorkflowEngine.WorkflowEngine, SqlError>;
54
+ export {};
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Tagged errors for `@dimple/workflow`.
3
+ *
4
+ * Two groups:
5
+ * - **Facade-boundary errors**: `QueueError`, `UnknownJobType`,
6
+ * `RegistryError`, `ShutdownError` — infrastructure concerns surfaced by
7
+ * the runtime/registry.
8
+ * - **Job-outcome errors**: `JobFailed`, `JobTimeout`, `JobCancelled` —
9
+ * what `wait`/`submit` fail with when a job doesn't succeed.
10
+ */
11
+ import { Schema } from "effect";
12
+ declare const QueueError_base: Schema.Class<QueueError, Schema.TaggedStruct<"QueueError", {
13
+ readonly message: Schema.String;
14
+ readonly cause: Schema.optional<Schema.Defect>;
15
+ }>, import("effect/Cause").YieldableError>;
16
+ /**
17
+ * Infrastructure failure at the facade boundary — wraps PersistedQueue /
18
+ * SqlClient / persistence failures surfaced by the runtime.
19
+ *
20
+ * Part of `JobsError`: `wait`/`enqueue` fail with this when the underlying
21
+ * store/queue misbehaves (as opposed to the job itself failing).
22
+ */
23
+ export declare class QueueError extends QueueError_base {
24
+ }
25
+ declare const UnknownJobType_base: Schema.Class<UnknownJobType, Schema.TaggedStruct<"UnknownJobType", {
26
+ readonly type: Schema.String;
27
+ }>, import("effect/Cause").YieldableError>;
28
+ /** Registry resolve failed — no handler registered for `type`. */
29
+ export declare class UnknownJobType extends UnknownJobType_base {
30
+ }
31
+ declare const RegistryError_base: Schema.Class<RegistryError, Schema.TaggedStruct<"RegistryError", {
32
+ readonly type: Schema.String;
33
+ readonly message: Schema.String;
34
+ }>, import("effect/Cause").YieldableError>;
35
+ /** Duplicate registration — a handler for `type` already exists. */
36
+ export declare class RegistryError extends RegistryError_base {
37
+ }
38
+ declare const ShutdownError_base: Schema.Class<ShutdownError, Schema.TaggedStruct<"ShutdownError", {
39
+ readonly message: Schema.String;
40
+ }>, import("effect/Cause").YieldableError>;
41
+ /** Operation attempted after runtime shutdown (reserved). */
42
+ export declare class ShutdownError extends ShutdownError_base {
43
+ }
44
+ /**
45
+ * Base error of the facade boundary hierarchy — the union of every tagged
46
+ * error the runtime can surface at its boundaries.
47
+ */
48
+ export type JobRuntimeError = QueueError | UnknownJobType | RegistryError | ShutdownError;
49
+ declare const JobFailed_base: Schema.Class<JobFailed, Schema.TaggedStruct<"JobFailed", {
50
+ readonly jobId: Schema.String;
51
+ readonly message: Schema.String;
52
+ }>, import("effect/Cause").YieldableError>;
53
+ /** The job's workflow completed with a failure exit (handler error). */
54
+ export declare class JobFailed extends JobFailed_base {
55
+ }
56
+ declare const JobTimeout_base: Schema.Class<JobTimeout, Schema.TaggedStruct<"JobTimeout", {
57
+ readonly jobId: Schema.String;
58
+ readonly timeout: Schema.Duration;
59
+ }>, import("effect/Cause").YieldableError>;
60
+ /** `wait` exceeded its timeout; the `${jobId}/timed_out` marker was written. */
61
+ export declare class JobTimeout extends JobTimeout_base {
62
+ }
63
+ declare const JobCancelled_base: Schema.Class<JobCancelled, Schema.TaggedStruct<"JobCancelled", {
64
+ readonly jobId: Schema.String;
65
+ }>, import("effect/Cause").YieldableError>;
66
+ /** The job was cancelled via `cancel` before completing. */
67
+ export declare class JobCancelled extends JobCancelled_base {
68
+ }
69
+ /**
70
+ * The `JobRuntime` error channel — job outcome errors plus infrastructure
71
+ * (`QueueError` wraps persistence/queue failures).
72
+ *
73
+ * `wait`/`submit` fail with `JobFailed` | `JobTimeout` | `JobCancelled`;
74
+ * `enqueue` and the other facade methods additionally surface `QueueError`.
75
+ */
76
+ export type JobsError = JobFailed | JobTimeout | JobCancelled | QueueError;
77
+ export {};
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Execution modes — the executor decides who runs handlers and when.
3
+ * Same queues, same handlers, same config — only the composition differs.
4
+ *
5
+ * - `background` — `DurableQueue.worker` layers: workers run in-process,
6
+ * supervised, replicated by concurrency, shut down with the scope.
7
+ * - `inline` — run the worker in the same fiber scope as the submit.
8
+ * - `external` — no worker layer; a cron/drainer calls `processPending`
9
+ * (bounded window) — cross-process resume via the durable signal queue.
10
+ *
11
+ * Worker handlers come from the `JobRegistry` (registered by job type at
12
+ * layer composition). The worker runs the business handler with the decoded
13
+ * payload; the `DurableQueue` machinery completes the job's deferred, which
14
+ * resumes the awaiting workflow (facade `submit`) and persists the result.
15
+ */
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";
21
+ import { Service as JobRegistry } from "./registry.ts";
22
+ import { Service as JobRuntime } from "./runtime.ts";
23
+ export declare const workerLayer: (defs: readonly JobDefinition.Any[], options?: {
24
+ readonly concurrency?: number;
25
+ /** Bounded handler retries (total ~`maxAttempts × 300ms`); 1 = no
26
+ * retry (the durable retry contract, see runHandler). Clamped to
27
+ * [1, 100]. */
28
+ readonly maxAttempts?: number;
29
+ 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
+ /**
32
+ * Inline mode — run the worker in the same fiber scope as the submit.
33
+ *
34
+ * Forks the worker, enqueues the job, then **waits for the result** — the
35
+ * wait keeps the scope alive until the worker completes the deferred and the
36
+ * workflow resumes, so the process exits cleanly with work done.
37
+ *
38
+ * Requires the full stack (JobRuntime + engine + queue + registry); use
39
+ * `workerLayer` for persistent processes instead.
40
+ */
41
+ export declare const inline: (def: JobDefinition.Any, payload: unknown, options?: {
42
+ readonly concurrency?: number;
43
+ readonly maxAttempts?: number;
44
+ }) => Effect.Effect<unknown, unknown, WorkflowEngine.WorkflowEngine | PersistedQueue.PersistedQueueFactory | JobRegistry | JobRuntime>;
45
+ /**
46
+ * External mode — bounded drain of pending work for a window. The runtime's
47
+ * `processPending` (resume signals) is the companion hook for cross-process
48
+ * resume; this drains the job queues themselves.
49
+ */
50
+ export declare const processQueues: (defs: readonly JobDefinition.Any[], options?: {
51
+ readonly window?: Duration.Input;
52
+ readonly maxAttempts?: number;
53
+ }) => Effect.Effect<number, unknown, WorkflowEngine.WorkflowEngine | PersistedQueue.PersistedQueueFactory | JobRegistry>;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @dimple/workflow — Effect-native durable job runtime.
3
+ *
4
+ * Barrel: named exports with aliases (project convention).
5
+ */
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";
11
+ export { JobsConfig, JobsConfigDefaults, resolveJobsConfig } from "./config.ts";
12
+ export { QueueError, UnknownJobType, RegistryError, ShutdownError, JobFailed, JobTimeout, JobCancelled, type JobRuntimeError, type JobsError, } from "./errors.ts";
13
+ export { STORE_ID, RESUME_QUEUE, ResumeSignal, ExecutionRecord, encodedKey, resultCodecFor, payloadCodecFor, } from "./persistence.ts";
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Shared persistence layer for the durable engine and the JobRuntime facade.
3
+ *
4
+ * One `PersistenceStore` (storeId {@link STORE_ID}) holds ALL durable state in
5
+ * jobs.db. Keys are `Persistable` instances with `Schema.Unknown` codecs.
6
+ *
7
+ * ### Why `Schema.Unknown`?
8
+ *
9
+ * Everything stored at this boundary is **already schema-encoded JSON**:
10
+ * - activity results arrive from `executeEncoded` (JSON-encoded)
11
+ * - deferred exits arrive from `makeUnsafe.deferredDone` as
12
+ * `Schema.encodeEffect(deferred.exitSchema)` output (an Exit instance with
13
+ * JSON-serializable fields)
14
+ * - results are encoded with the per-workflow `resultCodecFor`
15
+ * - payloads/records are plain objects
16
+ *
17
+ * The store's `serializeExit`/`deserializeExit` then performs an identity
18
+ * JSON round-trip. Typed schemas here would **double-encode** (the value is
19
+ * already encoded when it reaches this boundary) — verified empirically:
20
+ * `Schema.Duration`-style transforms fail and the workflow hangs.
21
+ *
22
+ * ### Key layout (per executionId)
23
+ *
24
+ * ```
25
+ * {executionId}/record — { workflowTag, payload } (replay source)
26
+ * {executionId}/{deferredName} — deferred result Exit (JSON)
27
+ * {executionId}/{activity.name}/{attempt} — activity result Exit (JSON)
28
+ * {executionId}/result — encoded Workflow.Result (Complete only)
29
+ * {jobId}/timed_out — wait-timeout marker
30
+ * {jobId}/cancelled — cancel marker
31
+ * ```
32
+ *
33
+ */
34
+ import { Effect, Exit, Option, Schema } from "effect";
35
+ import { Persistable, Persistence as PersistenceNamespace } from "effect/unstable/persistence";
36
+ type PersistenceStore = PersistenceNamespace.PersistenceStore;
37
+ import { Workflow } from "effect/unstable/workflow";
38
+ /** Single store id shared by engine + facade (one table partition in jobs.db). */
39
+ export declare const STORE_ID = "dimple/jobs";
40
+ /**
41
+ * Resume-signal queue name — `deferredDone` offers `{ executionId }` here so
42
+ * any process's drainer (`JobRuntime.processPending`) can resume a suspended
43
+ * execution whose deferred completed elsewhere (cross-process wakeup).
44
+ */
45
+ export declare const RESUME_QUEUE = "dimple/resume";
46
+ /** Payload of a resume signal: just the executionId to replay. */
47
+ export declare const ResumeSignal: Schema.Struct<{
48
+ readonly executionId: Schema.String;
49
+ }>;
50
+ export interface ResumeSignal extends Schema.Schema.Type<typeof ResumeSignal> {
51
+ }
52
+ /**
53
+ * Execution record persisted on first submission — a new process reconstructs
54
+ * execution state from it (cross-process replay source). `payload` is the
55
+ * envelope object (`{ token, payload, traceId }`).
56
+ */
57
+ export declare const ExecutionRecord: Schema.Struct<{
58
+ readonly workflowTag: Schema.String;
59
+ readonly payload: Schema.$Record<Schema.String, Schema.Unknown>;
60
+ }>;
61
+ export interface ExecutionRecord extends Schema.Schema.Type<typeof ExecutionRecord> {
62
+ }
63
+ /**
64
+ * A `Persistable` for already-encoded JSON values — a `PrimaryKey` (string
65
+ * key via `PrimaryKey.symbol`) plus `Schema.Unknown` success/error codecs.
66
+ *
67
+ * This is the erased identity codec: `store.set/get` round-trips whatever
68
+ * JSON-safe value was stored without interpreting it.
69
+ */
70
+ export type EncodedPersistable = Persistable.Persistable<Schema.Unknown, Schema.Unknown>;
71
+ /**
72
+ * Builds an {@link EncodedPersistable} for a raw string key.
73
+ *
74
+ * The object satisfies `Persistable` structurally (computed symbol keys
75
+ * resolve) — no cast needed.
76
+ */
77
+ export declare const encodedKey: (key: string) => EncodedPersistable;
78
+ /** Persisted-key helpers — `${executionId}/…` namespaces. */
79
+ export declare const resultKey: (executionId: string) => string;
80
+ export declare const payloadKey: (executionId: string) => string;
81
+ export declare const recordKey: (executionId: string) => string;
82
+ export declare const deferredKey: (executionId: string, deferredName: string) => string;
83
+ export declare const activityKey: (executionId: string, activityName: string, attempt: number) => string;
84
+ export declare const markerKey: (jobId: string, marker: string) => string;
85
+ /**
86
+ * Reads a raw persisted Exit (`undefined` when absent). Defects on
87
+ * persistence/schema errors — callers treat store failures as infrastructure
88
+ * defects (`Effect.orDie` semantics).
89
+ */
90
+ export declare const getEncodedExit: (store: PersistenceStore, key: string) => Effect.Effect<Exit.Exit<unknown, unknown> | undefined, never, never>;
91
+ /**
92
+ * Writes a raw Exit under a key. The store JSON-round-trips it; the read side
93
+ * (`getEncodedExit`) returns an **Exit instance** (not the raw JSON), which is
94
+ * what `makeUnsafe`'s `deferredResult` expects (`toJsonExit(exit.value)` maps
95
+ * over the Option's payload).
96
+ */
97
+ export declare const setEncodedExit: (store: PersistenceStore, key: string, exit: Exit.Exit<unknown, unknown>) => Effect.Effect<void, never, never>;
98
+ /**
99
+ * Reads a boolean marker (e.g. `${jobId}/timed_out`, `${jobId}/cancelled`).
100
+ */
101
+ export declare const readMarker: (store: PersistenceStore, jobId: string, marker: string) => Effect.Effect<boolean, never, never>;
102
+ /**
103
+ * Writes a boolean marker — the only "cancel" mechanism available (the SQL
104
+ * store cannot remove queue items).
105
+ */
106
+ export declare const writeMarker: (store: PersistenceStore, jobId: string, marker: string) => Effect.Effect<void, never, never>;
107
+ /**
108
+ * Per-workflow result codec (see {@link eraseServices} for the service
109
+ * erasure rationale). Decoded type is `Workflow.Result<unknown, unknown>`.
110
+ */
111
+ export declare const resultCodecFor: (workflow: Workflow.Any) => Schema.Codec<Workflow.Result<unknown, unknown>, unknown, never, never>;
112
+ /** Per-workflow payload codec (JSON round-trip of the payload schema). */
113
+ export declare const payloadCodecFor: (workflow: Workflow.Any) => Schema.Codec<unknown, unknown, never, never>;
114
+ /**
115
+ * Reads a persisted workflow result for an execution.
116
+ *
117
+ * Returns `None` while the execution is pending/suspended; `Some(Complete)`
118
+ * once it finished (success or failure). The workflow argument supplies the
119
+ * per-workflow result codec.
120
+ */
121
+ export declare const readWorkflowResult: (store: PersistenceStore, workflow: Workflow.Any, executionId: string) => Effect.Effect<Option.None<Workflow.Result<unknown, unknown>> | Option.Some<Workflow.Result<unknown, unknown>>, never, never>;
122
+ export {};
@@ -0,0 +1,5 @@
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>;
@@ -0,0 +1,298 @@
1
+ /**
2
+ * Job definitions — the schema-typed contract for one job type.
3
+ *
4
+ * A `JobDefinition` pairs two Effect primitives that share one schema set:
5
+ *
6
+ * - **`queue`** — a `DurableQueue.DurableQueue` carrying the *caller's*
7
+ * payload schema. Workers take items from this queue (via the executor's
8
+ * `workerLayer`/`inline`/`processQueues`), run the registered business
9
+ * handler, and complete the job's deferred with the handler's result.
10
+ * - **`workflow`** — a one-shot `Workflow` (tag `` `JobRuntime/${name}` ``)
11
+ * carrying an *envelope* schema `{ token, payload, traceId }`. The facade
12
+ * (`JobRuntime.enqueue`) executes this workflow in discard mode; the
13
+ * workflow body calls `DurableQueue.process`, which offers the payload to
14
+ * the queue and suspends until the worker completes the deferred.
15
+ *
16
+ * ### Why two schemas?
17
+ *
18
+ * `Workflow.executionId` validates the *envelope*, and the envelope's `token`
19
+ * is the workflow's idempotency key — so re-enqueueing the same payload
20
+ * yields the same deterministic `jobId` (executionId) and dedupes queue
21
+ * offers. The queue itself keeps the raw payload schema so workers receive
22
+ * the caller's data directly.
23
+ *
24
+ * ### Error contract (important)
25
+ *
26
+ * The workflow's error schema **is** the queue's error schema. Do NOT wrap
27
+ * handler errors in a different type here — `JobRuntime.wait` decodes the
28
+ * persisted result with the workflow's `error` schema, so a mismatched error
29
+ * object breaks result encoding (see the `resultCodecFor` docs).
30
+ *
31
+ */
32
+ import { Effect, Schema, Scope } from "effect";
33
+ import { DurableQueue, Workflow, WorkflowEngine } from "effect/unstable/workflow";
34
+ import { PersistedQueue } from "effect/unstable/persistence";
35
+ /**
36
+ * Envelope schema factory — wraps a job's payload schema with the runtime
37
+ * fields the workflow machinery needs.
38
+ *
39
+ * - `token` — the idempotency key (`JobDefinition.idempotencyKey(payload)`);
40
+ * the workflow's executionId is derived from the envelope, so
41
+ * the same token+payload ⇒ same jobId.
42
+ * - `payload` — the caller's payload (the definition's `payloadSchema`).
43
+ * - `traceId` — optional observability correlation id ("" when unset).
44
+ */
45
+ export declare const Envelope: <Payload extends Workflow.AnyStructSchema>(payload: Payload) => Schema.Struct<{
46
+ readonly token: Schema.String;
47
+ readonly payload: Payload;
48
+ readonly traceId: Schema.optional<Schema.String>;
49
+ }>;
50
+ /** The schema type produced by {@link Envelope} for a given payload schema. */
51
+ export type EnvelopeSchema<Payload extends Workflow.AnyStructSchema> = ReturnType<typeof Envelope<Payload>>;
52
+ /**
53
+ * A job definition — a schema-typed `DurableQueue` + one-shot `Workflow` pair.
54
+ *
55
+ * Create with {@link JobDefinition.make}; the generic parameters track the
56
+ * concrete payload/success/error schemas so `enqueue`/`submit`/`register`
57
+ * stay fully typed. For heterogeneous collections (facades, executors) use
58
+ * the erased {@link JobDefinition.Any} form.
59
+ */
60
+ export declare class JobDefinition<Payload extends Workflow.AnyStructSchema = Workflow.AnyStructSchema, Success extends Schema.Top = Schema.Void, Error extends Schema.Top = Schema.Never> {
61
+ /** Job type name (e.g. `"topic.split"`). */
62
+ readonly name: string;
63
+ /** The durable queue workers consume; carries the raw payload schema. */
64
+ readonly queue: DurableQueue.DurableQueue<Payload, Success, Error>;
65
+ /** The one-shot workflow (tag `` `JobRuntime/${name}` ``) the facade executes. */
66
+ readonly workflow: Workflow.Workflow<`JobRuntime/${string}`, EnvelopeSchema<Payload>, Success, Error>;
67
+ /** The caller's payload schema. */
68
+ readonly payloadSchema: Payload;
69
+ /** The job's success schema. */
70
+ readonly successSchema: Success;
71
+ /** The job's error schema (matches the queue's error schema — do not wrap). */
72
+ readonly errorSchema: Error;
73
+ /** Maps a payload to its idempotency token (stable ⇒ dedupe). */
74
+ readonly idempotencyKey: (payload: Payload["Type"]) => string;
75
+ /**
76
+ * Decodes an envelope back to `{ payload }`. Built in `make` where the
77
+ * schema types are concrete; the erased `Any` form widens the result.
78
+ */
79
+ readonly decodeEnvelope: (envelope: unknown) => Effect.Effect<{
80
+ readonly payload: Payload["Type"];
81
+ }, never, Payload["DecodingServices"] | Payload["EncodingServices"]>;
82
+ constructor(args: {
83
+ readonly name: string;
84
+ readonly queue: DurableQueue.DurableQueue<Payload, Success, Error>;
85
+ readonly workflow: Workflow.Workflow<`JobRuntime/${string}`, EnvelopeSchema<Payload>, Success, Error>;
86
+ readonly payloadSchema: Payload;
87
+ readonly successSchema: Success;
88
+ readonly errorSchema: Error;
89
+ readonly idempotencyKey: (payload: Payload["Type"]) => string;
90
+ readonly decodeEnvelope: (envelope: unknown) => Effect.Effect<{
91
+ readonly payload: Payload["Type"];
92
+ }, never, Payload["DecodingServices"] | Payload["EncodingServices"]>;
93
+ });
94
+ /**
95
+ * Creates a job definition from a schema set.
96
+ *
97
+ * @param name job type name — also prefixes the workflow tag
98
+ * (`JobRuntime/<name>`) and the queue name (`DurableQueue/<name>`)
99
+ * @param options.payload the caller's payload struct fields
100
+ * @param options.success job success schema (default `Schema.Void`)
101
+ * @param options.error job error schema (default `Schema.Never`)
102
+ * @param options.idempotencyKey deterministic payload → token function
103
+ *
104
+ * @returns a fully-typed `JobDefinition<Schema.Struct<Payload>, Success, Error>`
105
+ */
106
+ static make: <const Name extends string, Payload_1 extends Schema.Struct.Fields, Success_1 extends Schema.Top = Schema.Void, Error_1 extends Schema.Top = Schema.Never>(name: Name, options: {
107
+ readonly payload: Payload_1;
108
+ readonly success: Success_1;
109
+ readonly error: Error_1;
110
+ readonly idempotencyKey: (payload: Schema.Struct.Type<Payload_1>) => string;
111
+ }) => JobDefinition<Schema.Struct<Payload_1>, Success_1, Error_1>;
112
+ /**
113
+ * Registers this definition's workflow with a `WorkflowEngine`.
114
+ *
115
+ * The registered handler decodes the envelope and forwards `env.payload` to
116
+ * `DurableQueue.process` — a workflow-native primitive that offers the item
117
+ * to the durable queue and suspends (via `Workflow.suspend`) until a worker
118
+ * completes the deferred.
119
+ *
120
+ * **Do not call per-job.** `JobRuntime.layer` registers all definitions at
121
+ * layer build (app-lifetime scope); re-registering is idempotent
122
+ * (`Map.set` overwrites) but wasteful.
123
+ *
124
+ * @param engine the (durable) WorkflowEngine service
125
+ * @returns `Effect<void, never, Scope | PersistedQueueFactory | schema services>`
126
+ * — the requirements are satisfied by the engine layer composition.
127
+ */
128
+ register(engine: WorkflowEngine.WorkflowEngine["Service"]): Effect.Effect<void, never, Scope.Scope | PersistedQueue.PersistedQueueFactory | Payload["DecodingServices"] | Payload["EncodingServices"] | Success["DecodingServices"] | Success["EncodingServices"] | Error["DecodingServices"] | Error["EncodingServices"]>;
129
+ }
130
+ export declare namespace JobDefinition {
131
+ /**
132
+ * Type-erased job definition for generic dispatch over heterogeneous
133
+ * definitions (runtime facades, executor loops).
134
+ *
135
+ * Erasure uses `any` type arguments exactly like the effect library's own
136
+ * `Workflow.Any` — the concrete schemas live on the value. Typed access
137
+ * flows through the generic `enqueue`/`submit`/`register` methods instead;
138
+ * prefer those over reading the erased fields directly.
139
+ */
140
+ interface Any {
141
+ readonly name: string;
142
+ readonly queue: DurableQueue.DurableQueue<any, any, any>;
143
+ readonly workflow: Workflow.AnyWithProps;
144
+ readonly payloadSchema: Schema.Top;
145
+ readonly successSchema: Schema.Top;
146
+ readonly errorSchema: Schema.Top;
147
+ readonly idempotencyKey: (payload: any) => string;
148
+ readonly decodeEnvelope: (envelope: unknown) => Effect.Effect<{
149
+ readonly payload: unknown;
150
+ }, never, unknown>;
151
+ readonly register: (engine: WorkflowEngine.WorkflowEngine["Service"]) => Effect.Effect<void, never, Scope.Scope | PersistedQueue.PersistedQueueFactory>;
152
+ }
153
+ }
154
+ /**
155
+ * Topic-tree split job — `topic.split`. The overflow maintenance path: the
156
+ * store's `enqueueSplit` seam (or the split handler's `onUnevenSplit`
157
+ * counterpart) posts it; the worker runs `topicSplitHandler`
158
+ * (`@dimple/store` topics/jobs.ts).
159
+ */
160
+ export declare const TopicSplit: JobDefinition<Schema.Struct<{
161
+ topicId: Schema.String;
162
+ modelKey: Schema.String;
163
+ }>, Schema.Void, Schema.String>;
164
+ /**
165
+ * Embedding backfill job — `memory.embed`. The multi-model lifecycle path:
166
+ * re-embeds one memory with a target model and routes it into that model's
167
+ * tree; the worker runs `memoryEmbedHandler` (topics/lifecycle.ts).
168
+ */
169
+ export declare const MemoryEmbed: JobDefinition<Schema.Struct<{
170
+ memoryId: Schema.String;
171
+ modelKey: Schema.String;
172
+ }>, Schema.Void, Schema.String>;
173
+ /** Underflow maintenance job — `topic.merge` (borrow-then-merge). */
174
+ export declare const TopicMerge: JobDefinition<Schema.Struct<{
175
+ topicId: Schema.String;
176
+ modelKey: Schema.String;
177
+ }>, Schema.Void, Schema.String>;
178
+ /** Sibling-balance maintenance job — `topic.rebalance`. */
179
+ export declare const TopicRebalance: JobDefinition<Schema.Struct<{
180
+ topicId: Schema.String;
181
+ modelKey: Schema.String;
182
+ }>, Schema.Void, Schema.String>;
183
+ /**
184
+ * Inductive concept clustering job — `concept.cluster`. Two modes:
185
+ * `{ modelKey, topicKey }` clusters ONE topic leaf's members;
186
+ * `{ modelKey }` (no topicKey) runs the corpus pass over a deterministic
187
+ * sample of the memory store. The worker runs `conceptClusterHandler`
188
+ * (`@dimple/store` graph/concepts.ts); the idempotency token is
189
+ * `concept:<modelKey>:<topicKey|corpus>` so both modes dedupe independently.
190
+ */
191
+ export declare const ConceptCluster: JobDefinition<Schema.Struct<{
192
+ modelKey: Schema.String;
193
+ topicKey: Schema.optional<Schema.String>;
194
+ }>, Schema.Void, Schema.String>;
195
+ /**
196
+ * Consolidation dream job — `memory.dream`. One run per model key: gather
197
+ * candidate pairs, judge them with the injected LLM classifier, persist
198
+ * relations + derived memories, and advance the model's `dream_state`
199
+ * watermark. The worker runs `graphDreamHandler` (`@dimple/store`
200
+ * graph/dream.ts). The idempotency token is `dream:<modelKey>[:<runId>]` —
201
+ * the SDK facade passes a fresh `runId` per call so every dream RUNS
202
+ * (a permanent token would make the job one-shot per model: later calls
203
+ * would only replay the first result). Callers that want in-flight
204
+ * coalescing reuse a runId while a run is pending.
205
+ */
206
+ export declare const MemoryDream: JobDefinition<Schema.Struct<{
207
+ modelKey: Schema.String;
208
+ runId: Schema.optional<Schema.String>;
209
+ }>, Schema.Void, Schema.String>;
210
+ /**
211
+ * Graph repair job — `graph.repair`. One pass per model key: removes
212
+ * orphaned `artifact_edges` rows and stale `memory_concepts` annotations
213
+ * (left-join sweeps over rows whose endpoint is gone), and — only when the
214
+ * handler was built with `includePurgeExpired` — hard-purges soft-deleted
215
+ * edges older than the grace window. The worker runs `graphRepairHandler`
216
+ * (`@dimple/store` graph/repair.ts). The idempotency token is
217
+ * `repair:<modelKey>[:<runId>]` — same per-run semantics as `memory.dream`.
218
+ */
219
+ export declare const GraphRepair: JobDefinition<Schema.Struct<{
220
+ modelKey: Schema.String;
221
+ runId: Schema.optional<Schema.String>;
222
+ }>, Schema.Void, Schema.String>;
223
+ /**
224
+ * One retrieval-audit row (the `retrieval_log` shape). Structural mirror
225
+ * of `@dimple/store`'s `RetrievalAuditRow` — the workflow package cannot
226
+ * import the store, and the queue schema decodes the store-built row
227
+ * as-is. The `audit.write` job moves audit writes OFF the query path:
228
+ * `Store.searchVector` enqueues the row (the store's `enqueueAudit` seam,
229
+ * wired by the app root) and the worker performs the insert.
230
+ */
231
+ export declare const AuditRow: Schema.Struct<{
232
+ readonly id: Schema.String;
233
+ readonly queryHash: Schema.String;
234
+ readonly queryText: Schema.String;
235
+ readonly namespace: Schema.String;
236
+ readonly mode: Schema.String;
237
+ readonly queryProfile: Schema.optional<Schema.Union<readonly [Schema.String, Schema.Null]>>;
238
+ readonly sources: Schema.optional<Schema.Union<readonly [Schema.String, Schema.Null]>>;
239
+ readonly resultCount: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.Null]>>;
240
+ readonly latencyMs: Schema.Number;
241
+ readonly createdAt: Schema.Number;
242
+ }>;
243
+ export type AuditRow = Schema.Schema.Type<typeof AuditRow>;
244
+ /** Retrieval-audit write job — `audit.write`. */
245
+ /** The idempotency key covers the WHOLE batch (all row ids, in payload
246
+ * order) — a key from `rows[0]` alone would silently dedupe two distinct
247
+ * batches sharing their first row (the second batch's rows would never be
248
+ * written). Identical batches still dedupe to one job. */
249
+ export declare const AuditWrite: JobDefinition<Schema.Struct<{
250
+ rows: Schema.$Array<Schema.Struct<{
251
+ readonly id: Schema.String;
252
+ readonly queryHash: Schema.String;
253
+ readonly queryText: Schema.String;
254
+ readonly namespace: Schema.String;
255
+ readonly mode: Schema.String;
256
+ readonly queryProfile: Schema.optional<Schema.Union<readonly [Schema.String, Schema.Null]>>;
257
+ readonly sources: Schema.optional<Schema.Union<readonly [Schema.String, Schema.Null]>>;
258
+ readonly resultCount: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.Null]>>;
259
+ readonly latencyMs: Schema.Number;
260
+ readonly createdAt: Schema.Number;
261
+ }>>;
262
+ }>, Schema.Void, Schema.String>;
263
+ /** All built-in job definitions, for bulk registration/worker composition. */
264
+ export declare const queues: readonly [JobDefinition<Schema.Struct<{
265
+ topicId: Schema.String;
266
+ modelKey: Schema.String;
267
+ }>, Schema.Void, Schema.String>, JobDefinition<Schema.Struct<{
268
+ memoryId: Schema.String;
269
+ modelKey: Schema.String;
270
+ }>, Schema.Void, Schema.String>, JobDefinition<Schema.Struct<{
271
+ topicId: Schema.String;
272
+ modelKey: Schema.String;
273
+ }>, Schema.Void, Schema.String>, JobDefinition<Schema.Struct<{
274
+ topicId: Schema.String;
275
+ modelKey: Schema.String;
276
+ }>, Schema.Void, Schema.String>, JobDefinition<Schema.Struct<{
277
+ modelKey: Schema.String;
278
+ topicKey: Schema.optional<Schema.String>;
279
+ }>, Schema.Void, Schema.String>, JobDefinition<Schema.Struct<{
280
+ modelKey: Schema.String;
281
+ runId: Schema.optional<Schema.String>;
282
+ }>, Schema.Void, Schema.String>, JobDefinition<Schema.Struct<{
283
+ modelKey: Schema.String;
284
+ runId: Schema.optional<Schema.String>;
285
+ }>, Schema.Void, Schema.String>, JobDefinition<Schema.Struct<{
286
+ rows: Schema.$Array<Schema.Struct<{
287
+ readonly id: Schema.String;
288
+ readonly queryHash: Schema.String;
289
+ readonly queryText: Schema.String;
290
+ readonly namespace: Schema.String;
291
+ readonly mode: Schema.String;
292
+ readonly queryProfile: Schema.optional<Schema.Union<readonly [Schema.String, Schema.Null]>>;
293
+ readonly sources: Schema.optional<Schema.Union<readonly [Schema.String, Schema.Null]>>;
294
+ readonly resultCount: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.Null]>>;
295
+ readonly latencyMs: Schema.Number;
296
+ readonly createdAt: Schema.Number;
297
+ }>>;
298
+ }>, Schema.Void, Schema.String>];