@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,57 @@
1
+ /**
2
+ * Job registry — maps job types to business handlers.
3
+ *
4
+ * The registry holds the *work* for each job type. The executor's workers
5
+ * resolve the handler by type and run it with the decoded payload; the
6
+ * handler's result completes the job's `DurableDeferred` (via the
7
+ * `DurableQueue` worker machinery), which resumes the awaiting workflow and
8
+ * persists the result.
9
+ */
10
+ import { Context, Effect, Layer, Schema } from "effect";
11
+ import { RegistryError, UnknownJobType } from "./errors.ts";
12
+ declare const JobFailure_base: Schema.Class<JobFailure, Schema.TaggedStruct<"JobFailure", {
13
+ readonly jobId: Schema.String;
14
+ readonly message: Schema.String;
15
+ }>, import("effect/Cause").YieldableError>;
16
+ /**
17
+ * Handler failure surfaced by registered job handlers.
18
+ */
19
+ export declare class JobFailure extends JobFailure_base {
20
+ }
21
+ /**
22
+ * Context passed to registered handlers alongside the decoded payload.
23
+ */
24
+ export interface JobContext {
25
+ readonly jobId: string;
26
+ }
27
+ /**
28
+ * Type-erased job handler — registered per job type. The handler receives the
29
+ * decoded payload and returns the job's success value (or fails with
30
+ * `JobFailure`); the runtime owns retries/leases.
31
+ */
32
+ export type Handler = (payload: unknown, ctx: JobContext) => Effect.Effect<unknown, JobFailure>;
33
+ /**
34
+ * JobRegistry service contract.
35
+ *
36
+ * - `register` — idempotency-free: a duplicate type fails `RegistryError`.
37
+ * Call at app startup (layer composition), before workers start.
38
+ * - `resolve` — fails `UnknownJobType` when no handler is registered.
39
+ */
40
+ export interface Interface {
41
+ readonly register: (type: string, handler: Handler) => Effect.Effect<void, RegistryError>;
42
+ readonly resolve: (type: string) => Effect.Effect<Handler, UnknownJobType>;
43
+ }
44
+ declare const Service_base: Context.ServiceClass<Service, "@dimple/workflow/JobRegistry", Interface>;
45
+ /**
46
+ * JobRegistry service tag — access via `yield* JobRegistry` (after providing
47
+ * `registryLayer`).
48
+ */
49
+ export declare class Service extends Service_base {
50
+ }
51
+ /**
52
+ * Process-local registry of job type → handler. Registration happens at layer
53
+ * composition; a duplicate registration fails with `RegistryError`, an
54
+ * unknown resolve fails with `UnknownJobType`.
55
+ */
56
+ export declare const layer: Layer.Layer<Service, never, never>;
57
+ export {};
@@ -0,0 +1,161 @@
1
+ /**
2
+ * JobRuntime facade — the public API of `@dimple/workflow`.
3
+ *
4
+ * The facade is the **only** surface application code should touch:
5
+ *
6
+ * - {@link Interface.enqueue} — submit a job without waiting. Returns the
7
+ * deterministic `jobId` (= executionId). Payload is validated against the
8
+ * definition's schema and wrapped in the envelope
9
+ * `{ token, payload, traceId }`. Discard-mode workflow execute: returns
10
+ * immediately; a worker (or a later `processPending` drain) does the work.
11
+ * - {@link Interface.wait} — poll a job's persisted `${jobId}/result` until
12
+ * it completes. On timeout writes the `${jobId}/timed_out` marker and fails
13
+ * `JobTimeout`. Cross-process safe: reads the store, not local state.
14
+ * - {@link Interface.submit} — `enqueue` + `wait` (blocking convenience).
15
+ * - {@link Interface.status} — `pending | running | succeeded | failed |
16
+ * timed_out | cancelled`.
17
+ * - {@link Interface.cancel} — marker-only (the SQL store cannot remove queue
18
+ * items); `wait` observes the marker and fails `JobCancelled`.
19
+ * - {@link Interface.processPending} — bounded-window drain of the durable
20
+ * resume-signal queue (external/cron mode; cross-process resume trigger).
21
+ *
22
+ * ### How a job completes (the happy path)
23
+ *
24
+ * ```
25
+ * enqueue(def, payload)
26
+ * → def.workflow.execute(envelope, discard) (registers + runs one-shot workflow)
27
+ * → workflow body: DurableQueue.process(queue, payload)
28
+ * → offer {token, payload} to durable queue → suspend (await deferred)
29
+ * worker (workerLayer/inline/processQueues)
30
+ * → queue.take → registry.resolve(def.name) → runHandler(payload)
31
+ * → DurableDeferred.done(exit) → engine.deferredDone
32
+ * → persist deferred exit + offer resume signal + resume execution
33
+ * replay: workflow re-runs → deferredResult finds persisted exit
34
+ * → workflow completes (success or failure) → result persisted
35
+ * wait(jobId) → reads `${jobId}/result` → returns success value or JobFailed
36
+ * ```
37
+ *
38
+ * ### Error channel
39
+ *
40
+ * `JobsError = JobFailed | JobTimeout | JobCancelled | QueueError`.
41
+ * `QueueError` wraps infrastructure failures (persistence/queue); the other
42
+ * three are job-outcome errors.
43
+ *
44
+ * ### Layer composition (see also `engine.ts` docs)
45
+ *
46
+ * - `layer(defs)` — facade over an externally-provided stack
47
+ * (`WorkflowEngine | Persistence | PersistedQueueFactory`).
48
+ * - `layerLibsql(defs, { url })` — dep-free convenience: facade + durable
49
+ * engine + SQL persistence + resume queue over one libSQL instance.
50
+ * Pair with `workerLayer(defs)` (executor) + `registryLayer` for a full app.
51
+ *
52
+ */
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";
58
+ import { type JobsError } from "./errors.ts";
59
+ type SqlError = SqlErrorNamespace.SqlError;
60
+ /**
61
+ * Lifecycle of a job from the caller's perspective.
62
+ *
63
+ * - `pending` — enqueued, no persisted result yet
64
+ * - `running` — reserved (not currently distinguished from pending)
65
+ * - `succeeded` — result persisted with a success exit
66
+ * - `failed` — result persisted with a failure exit
67
+ * - `timed_out` — `wait` exceeded its timeout (marker written)
68
+ * - `cancelled` — `cancel` was called (marker written)
69
+ *
70
+ * Note: `running` is part of the API for future use; today non-terminal jobs
71
+ * report `pending`.
72
+ */
73
+ export type JobStatus = "pending" | "running" | "succeeded" | "failed" | "timed_out" | "cancelled";
74
+ /**
75
+ * JobRuntime service contract.
76
+ *
77
+ * `enqueue`/`submit` are generic over the definition's schemas — the payload
78
+ * is `P["Type"]` and the schema services appear in `R` (they are `never` for
79
+ * plain struct schemas). `wait` cannot infer a result schema from a jobId
80
+ * alone, so it returns `unknown` (the persisted success value).
81
+ */
82
+ export interface Interface {
83
+ /** Submit a job without waiting. Returns the deterministic jobId. */
84
+ readonly enqueue: <P extends Workflow.AnyStructSchema, S extends Schema.Top, E extends Schema.Top>(def: JobDefinition<P, S, E>, payload: P["Type"]) => Effect.Effect<string, JobsError, P["DecodingServices"] | P["EncodingServices"] | S["DecodingServices"] | S["EncodingServices"] | E["DecodingServices"] | E["EncodingServices"]>;
85
+ /**
86
+ * Poll a job's persisted result until completion or timeout.
87
+ *
88
+ * @param jobId the value returned by `enqueue`/`submit`
89
+ * @param options.timeout default 5 minutes
90
+ * @param options.pollInterval default 250ms
91
+ * @returns the job's success value; fails `JobTimeout` (marker written),
92
+ * `JobCancelled` (if cancelled), or `JobFailed` (handler failure).
93
+ */
94
+ readonly wait: (jobId: string, options?: {
95
+ readonly timeout?: Duration.Input;
96
+ readonly pollInterval?: Duration.Input;
97
+ }) => Effect.Effect<unknown, JobsError>;
98
+ /** `enqueue` + `wait` — blocking convenience for inline/embedded use. */
99
+ readonly submit: <P extends Workflow.AnyStructSchema, S extends Schema.Top, E extends Schema.Top>(def: JobDefinition<P, S, E>, payload: P["Type"]) => Effect.Effect<unknown, JobsError, P["DecodingServices"] | P["EncodingServices"] | S["DecodingServices"] | S["EncodingServices"] | E["DecodingServices"] | E["EncodingServices"]>;
100
+ /** Current {@link JobStatus} of a job. */
101
+ readonly status: (jobId: string) => Effect.Effect<JobStatus, JobsError>;
102
+ /** Marker-only cancellation; `wait` on the job then fails `JobCancelled`. */
103
+ readonly cancel: (jobId: string) => Effect.Effect<boolean, JobsError>;
104
+ /**
105
+ * Bounded drain of the resume-signal queue — call from a cron/external
106
+ * trigger to let THIS process resume executions whose deferreds completed
107
+ * elsewhere. Returns the number of resumed executions.
108
+ *
109
+ * @param options.window how long to keep draining (default 30s). Pass a
110
+ * short window when you only want to catch up on pending signals.
111
+ */
112
+ readonly processPending: (options?: {
113
+ readonly window?: Duration.Input;
114
+ }) => Effect.Effect<number, JobsError>;
115
+ }
116
+ declare const Service_base: Context.ServiceClass<Service, "@dimple/workflow/JobRuntime", Interface>;
117
+ /**
118
+ * JobRuntime service tag — access via `yield* JobRuntime` (after providing
119
+ * `layer` or `layerLibsql`).
120
+ */
121
+ export declare class Service extends Service_base {
122
+ }
123
+ /**
124
+ * JobRuntime live layer.
125
+ *
126
+ * Takes the registered queue definitions; **registers their one-shot
127
+ * workflows at layer construction** (capturing the layer's long-lived scope,
128
+ * so workflow fibers live as long as the app). Captures a scoped
129
+ * `PersistenceStore` for result/marker reads and writes.
130
+ *
131
+ * Requires `WorkflowEngine` (durable), `Persistence` (store), and
132
+ * `PersistedQueueFactory` (resume-signal drain + `DurableQueue.process`).
133
+ *
134
+ * @see {@link layerLibsql} for the dep-free convenience composition
135
+ */
136
+ export declare const layer: (defs: readonly JobDefinition.Any[]) => Layer.Layer<Service, never, WorkflowEngine.WorkflowEngine | PersistenceNamespace.Persistence | PersistedQueue.PersistedQueueFactory>;
137
+ /**
138
+ * Convenience layer — the full JobRuntime stack over one libSQL instance.
139
+ *
140
+ * Dep-free (dependencies declared at layer definition, not
141
+ * usage sites): engine + SQL persistence + resume-queue store are provided
142
+ * internally. Exposes `Service` plus the underlying `WorkflowEngine`,
143
+ * `Persistence`, and `PersistedQueueFactory` (via `provideMerge`) so executor
144
+ * workers can be composed alongside.
145
+ *
146
+ * @param defs job definitions to register + serve
147
+ * @param options.url libSQL URL (file: or remote Turso)
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * const App = Layer.mergeAll(
152
+ * layerLibsql([TopicSplit, MemoryEmbed], { url: "file:./.dimple/jobs.db" }),
153
+ * registryLayer,
154
+ * workerLayer([TopicSplit, MemoryEmbed], { concurrency: 2 }),
155
+ * )
156
+ * ```
157
+ */
158
+ export declare const layerLibsql: (defs: readonly JobDefinition.Any[], options: {
159
+ readonly url: string;
160
+ }) => Layer.Layer<Service | WorkflowEngine.WorkflowEngine | PersistenceNamespace.Persistence | PersistedQueue.PersistedQueueFactory, SqlError>;
161
+ export {};
package/dist/make.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { type CoreOptions } from "./internal/core/index.js";
2
+ import { type ConfigInput } from "./config.ts";
3
+ import { type Dimple } from "./dimple.ts";
4
+ /**
5
+ * What `makeDimple` accepts:
6
+ * - `{ config }` — a `dimple.jsonc` FILE PATH or an inline config OBJECT
7
+ * (typed as `DimpleConfig`; validated + defaults filled). The embedding
8
+ * section is mandatory (models come from it, embedders are built by
9
+ * provider).
10
+ * - `{ core }` — full `CoreOptions` directly (power users / tests with
11
+ * injected embedders).
12
+ */
13
+ export type MakeDimpleOptions = {
14
+ readonly config: ConfigInput;
15
+ readonly migrationFolder?: string;
16
+ } | {
17
+ readonly core: CoreOptions;
18
+ };
19
+ /**
20
+ * Create the Dimple facade — resolves once the composed system is fully
21
+ * booted. One runtime is built from the application layer; `runPromise`
22
+ * bridges each promise-facing edge, and `dispose` closes the scope.
23
+ * Boot failures reject with the same closed `DimpleError` surface as the
24
+ * facade methods (never raw Effect internals) and close the owned
25
+ * resources (scope + runtime) before rethrowing.
26
+ */
27
+ export declare const makeDimple: (options: MakeDimpleOptions) => Promise<Dimple>;
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@ponraaj/dimple-sdk",
3
+ "version": "0.0.0-alpha.1",
4
+ "private": false,
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "type": "module",
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "./errors": {
18
+ "types": "./dist/errors.d.ts",
19
+ "import": "./dist/errors.js",
20
+ "default": "./dist/errors.js"
21
+ }
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
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
+ "dependencies": {
32
+ "@ai-sdk/openai-compatible": "^1.0.0",
33
+ "@huggingface/transformers": "^4.2.0",
34
+ "@libsql/client": "^0.17.4",
35
+ "ai": "^5.0.0",
36
+ "drizzle-orm": "^1.0.0-rc.4",
37
+ "effect": "4.0.0-beta.103",
38
+ "jsonc-parser": "^3.3.1",
39
+ "web-tree-sitter": "^0.26.9",
40
+ "zod": "^4.4.3"
41
+ },
42
+ "peerDependencies": {
43
+ "typescript": "^5"
44
+ }
45
+ }