@krak-stack/assets 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +230 -2
- package/dist/chunks.d.ts +11 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +36 -0
- package/dist/chunks.js.map +1 -0
- package/dist/index.d.ts +182 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +390 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations/0001_assets.d.ts +5 -0
- package/dist/migrations/0001_assets.d.ts.map +1 -0
- package/dist/migrations/0001_assets.js +33 -0
- package/dist/migrations/0001_assets.js.map +1 -0
- package/dist/migrations/0002_chunks.d.ts +5 -0
- package/dist/migrations/0002_chunks.d.ts.map +1 -0
- package/dist/migrations/0002_chunks.js +24 -0
- package/dist/migrations/0002_chunks.js.map +1 -0
- package/dist/migrations.d.ts +6 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +29 -0
- package/dist/migrations.js.map +1 -0
- package/dist/processing.d.ts +19 -0
- package/dist/processing.d.ts.map +1 -0
- package/dist/processing.js +56 -0
- package/dist/processing.js.map +1 -0
- package/dist/retrieval.d.ts +75 -0
- package/dist/retrieval.d.ts.map +1 -0
- package/dist/retrieval.js +155 -0
- package/dist/retrieval.js.map +1 -0
- package/dist/schema.d.ts +287 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +206 -0
- package/dist/schema.js.map +1 -0
- package/dist/text.d.ts +10 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +23 -0
- package/dist/text.js.map +1 -0
- package/dist/workflow.d.ts +9 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +12 -0
- package/dist/workflow.js.map +1 -0
- package/dist/workflows.d.ts +4 -0
- package/dist/workflows.d.ts.map +1 -0
- package/dist/workflows.js +50 -0
- package/dist/workflows.js.map +1 -0
- package/package.json +73 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Krak Consultants
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,231 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Assets
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Organization-scoped uploads, downloads, deletion, durable document processing,
|
|
4
|
+
and searchable passages through one Effect `Assets` service.
|
|
5
|
+
Published as `@krak-stack/assets`, independently of application HTTP and auth layers.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun add @krak-stack/assets@0.1.1 @effect/sql-pg@4.0.0 effect@4.0.0
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
See the [Assets guide](https://krakstack.net/docs/assets) for application setup
|
|
12
|
+
and retrieval examples. This README covers package boundaries, operations, and upgrades.
|
|
13
|
+
|
|
14
|
+
## Boundaries
|
|
15
|
+
|
|
16
|
+
- Import `Assets` from `@krak-stack/assets` and schemas from `@krak-stack/assets/schema`.
|
|
17
|
+
- The package owns `assets`, `asset_processings`, `asset_chunks`, and `asset_migrations`.
|
|
18
|
+
- The application owns HTTP contracts and handlers, route registration,
|
|
19
|
+
authentication, trusted scope,
|
|
20
|
+
permission policies, UI, database configuration,
|
|
21
|
+
workflow-engine configuration, and references from its own domain entities.
|
|
22
|
+
- Dependencies are declared here: Effect, Effect Postgres, KrakStack S3, and Xberg.
|
|
23
|
+
Xberg is called directly; there is no extraction-service wrapper.
|
|
24
|
+
- Retrieval uses one chunk table with English/French PostgreSQL full-text indexes.
|
|
25
|
+
No vector database, embedding provider, or separate job system is required.
|
|
26
|
+
|
|
27
|
+
## Service wiring
|
|
28
|
+
|
|
29
|
+
`Assets.layer` runs pending asset migrations before providing the asset service.
|
|
30
|
+
It does not register HTTP routes or depend on an authentication implementation.
|
|
31
|
+
Provide `SqlClient` and `S3Service`;
|
|
32
|
+
operations that enqueue processing also require `WorkflowEngine`.
|
|
33
|
+
The SQL client must transform camel-case query names to snake case, snake-case
|
|
34
|
+
result names to camel case, and leave JSON keys unchanged (`transformJson: false`).
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { Assets } from "@krak-stack/assets";
|
|
38
|
+
import { assetProcessingWorkflowLayer } from "@krak-stack/assets/workflows";
|
|
39
|
+
import { S3Service } from "@krak-stack/registry/service-s3";
|
|
40
|
+
import { Layer } from "effect";
|
|
41
|
+
|
|
42
|
+
const assetsLayer = Assets.layer.pipe(
|
|
43
|
+
Layer.provide(S3Service.layer),
|
|
44
|
+
Layer.provide(databaseLayer),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const runtimeLayer = assetProcessingWorkflowLayer.pipe(
|
|
48
|
+
Layer.provideMerge(assetsLayer),
|
|
49
|
+
Layer.provide(workflowEngineLayer),
|
|
50
|
+
);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`databaseLayer` and `workflowEngineLayer` are application-owned layers. Reference
|
|
54
|
+
assets from your domain tables with foreign keys using `ON DELETE RESTRICT`.
|
|
55
|
+
Postgres enforces deletion safety, including concurrent reference writes; there is
|
|
56
|
+
no usage callback or separate references service. A foreign-key violation from the
|
|
57
|
+
asset DELETE becomes `AssetInUse`; other SQL errors are preserved. Owned processing
|
|
58
|
+
rows use `ON DELETE CASCADE`. The storage object is deleted only after the database
|
|
59
|
+
transaction commits.
|
|
60
|
+
|
|
61
|
+
Servers, workers, scripts, and service tests use the same `Assets.layer` or
|
|
62
|
+
`Assets.layerWith(processingOptions)` without HTTP or auth dependencies.
|
|
63
|
+
|
|
64
|
+
## API composition
|
|
65
|
+
|
|
66
|
+
The application defines its HTTP group and handlers, importing reusable schemas
|
|
67
|
+
from `@krak-stack/assets/schema` and calling `Assets` directly. The package has no
|
|
68
|
+
HTTP adapter or API exports.
|
|
69
|
+
|
|
70
|
+
Derive trusted organization and actor IDs from authentication, apply permission
|
|
71
|
+
checks, and map service errors at the application's HTTP boundary. Never trust
|
|
72
|
+
organization or actor IDs supplied by a browser as scope. Register the group in
|
|
73
|
+
the application's root API to expose typed clients, OpenAPI, MCP, or CLI tools.
|
|
74
|
+
|
|
75
|
+
## Migrations
|
|
76
|
+
|
|
77
|
+
`Assets.layer` and `Assets.layerWith(...)` automatically apply pending migrations
|
|
78
|
+
before constructing the service. A migration failure fails layer initialization;
|
|
79
|
+
dependent handlers and workflows cannot start against an unmigrated schema.
|
|
80
|
+
The runner uses its own `public.asset_migrations` ledger and a transaction-scoped
|
|
81
|
+
advisory lock, making repeated and concurrent startup safe. It requires only the
|
|
82
|
+
configured SQL client; no filesystem, process-spawner, or Bun services are needed.
|
|
83
|
+
|
|
84
|
+
For deployments with a separate migration step or a restricted application role,
|
|
85
|
+
run `migrateAssets` from `@krak-stack/assets/migrations` using a migration-capable SQL
|
|
86
|
+
client, then use `Assets.layerWithoutMigrations` or
|
|
87
|
+
`Assets.layerWithoutMigrationsWith(processingOptions)` at runtime:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { Assets } from "@krak-stack/assets";
|
|
91
|
+
import { migrateAssets } from "@krak-stack/assets/migrations";
|
|
92
|
+
import { S3Service } from "@krak-stack/registry/service-s3";
|
|
93
|
+
import { Effect, Layer } from "effect";
|
|
94
|
+
|
|
95
|
+
await Effect.runPromise(
|
|
96
|
+
migrateAssets.pipe(Effect.provide(migrationDatabaseLayer)),
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const assetsLayer = Assets.layerWithoutMigrations.pipe(
|
|
100
|
+
Layer.provide(S3Service.layer),
|
|
101
|
+
Layer.provide(databaseLayer),
|
|
102
|
+
);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Migration modules are compiled JavaScript; there are no SQL files to locate at
|
|
106
|
+
runtime. The initial migration creates the asset tables and does not adopt
|
|
107
|
+
preexisting unmanaged tables.
|
|
108
|
+
|
|
109
|
+
If an application already owns asset tables, it must perform a verified,
|
|
110
|
+
application-specific adoption before acquiring `Assets.layer`. Verify schema
|
|
111
|
+
compatibility before recording the initial package baseline, preserve application
|
|
112
|
+
data and migration history, and coordinate adoption with the package runner's
|
|
113
|
+
advisory lock (`478341933`). Do not mark an incompatible schema as migrated.
|
|
114
|
+
After adoption, the package runs its own subsequent migrations.
|
|
115
|
+
|
|
116
|
+
Add future asset migrations under `src/migrations/` and register them in
|
|
117
|
+
`src/migrations.ts` with increasing IDs. Do not edit applied migrations.
|
|
118
|
+
|
|
119
|
+
## Processing
|
|
120
|
+
|
|
121
|
+
Uploads are verified against their byte size and SHA-256 digest. Supported document
|
|
122
|
+
types are processed asynchronously by `ProcessAssetDocumentV2` using versioned
|
|
123
|
+
extraction and persistence activities. Xberg produces Markdown and native
|
|
124
|
+
structure-aware chunks. The complete extracted text is stored in
|
|
125
|
+
`asset_processings`; chunks and their heading/page/byte provenance are stored in
|
|
126
|
+
`asset_chunks`. Chunk insertion and completion are atomic, idempotent, and reject
|
|
127
|
+
stale inputs after replacement. Images and video remain uploadable but are not automatically
|
|
128
|
+
sent through OCR or transcription in this initial version.
|
|
129
|
+
|
|
130
|
+
Defaults: 100 MiB upload limit, 20 MiB extraction input, 20 MiB extracted text,
|
|
131
|
+
two concurrent extractions per service instance, and a 30-second Xberg timeout.
|
|
132
|
+
Oversized output fails explicitly; clipped text is never marked successfully indexed.
|
|
133
|
+
The legacy `readText` preview method still accepts a byte budget, but agents should
|
|
134
|
+
use the retrieval methods below, not that prefix-only method.
|
|
135
|
+
Xberg's native libraries and any optional OCR models must be
|
|
136
|
+
available in the deployment environment.
|
|
137
|
+
|
|
138
|
+
Use `Assets.layerWith(...)` to customize processing:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
const assetsLayer = Assets.layerWith({
|
|
142
|
+
processorVersion: 5,
|
|
143
|
+
maxOutputBytes: 30 * 1024 * 1024,
|
|
144
|
+
extraction: { extractionTimeoutSecs: 60 },
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`extraction` accepts Xberg's `ExtractionConfig`, merged over the package defaults.
|
|
149
|
+
Bump `processorVersion` whenever changing extraction configuration or output
|
|
150
|
+
semantics: completed and failed runs are cached by input identity and version.
|
|
151
|
+
Version 4 replaces the old 512 KiB extraction cache with full text and indexed chunks.
|
|
152
|
+
Reading the overview of a legacy asset lazily enqueues a new version-4 processing run
|
|
153
|
+
from the original S3 object. Version-3 text is not indexed or returned as current evidence.
|
|
154
|
+
V1 workflow registration is retained so old queued work can terminate explicitly;
|
|
155
|
+
new runs use V2 names and schemas. Never change persisted V2 payload/activity contracts
|
|
156
|
+
in place: introduce a new version for incompatible changes.
|
|
157
|
+
|
|
158
|
+
Native defaults request Markdown-aware chunks of 4,000 characters with 200-character
|
|
159
|
+
overlap, heading context, and repeated table headers. Xberg 1.0.14's shipped binding
|
|
160
|
+
may emit smaller chunks, omit flattened headings, or omit repeated headers. The
|
|
161
|
+
package preserves native boundaries and source offsets while recovering heading
|
|
162
|
+
context and continuation table headers. Missing page numbers remain null. Invalid,
|
|
163
|
+
missing, or excessively large chunks fail indexing rather than silently losing text.
|
|
164
|
+
|
|
165
|
+
## Agent retrieval
|
|
166
|
+
|
|
167
|
+
Use metadata and targeted evidence, not sequential full-file loading:
|
|
168
|
+
|
|
169
|
+
1. `getOverview({ organizationId, assetId, outlineOffset? })` reports readiness,
|
|
170
|
+
current `processingId`, full byte size, chunk count, and up to 50 heading ranges.
|
|
171
|
+
Follow `nextOutlineOffset` to inspect more of the outline. A missing asset fails
|
|
172
|
+
with `AssetNotFound`; unsupported, pending, running and failed documents have
|
|
173
|
+
explicit statuses. Attaching files to a conversation should include metadata only.
|
|
174
|
+
2. `searchChunks({ organizationId, assetId, processingId, query, language, offset?,
|
|
175
|
+
headingPath? })` returns up to eight snippets with ordinals and provenance.
|
|
176
|
+
`language` is `en` or `fr`. Identical chunk contents within a heading are suppressed and ranking
|
|
177
|
+
favors section diversity. Follow `nextOffset` for more matches.
|
|
178
|
+
3. `readChunks({ organizationId, assetId, processingId, ordinals,
|
|
179
|
+
includeNeighbors? })` reads one to four selected ordinals, optionally including
|
|
180
|
+
immediate neighbors, deduplicated and in source order. Responses exceeding
|
|
181
|
+
128 KiB of passage text fail explicitly; request fewer chunks instead.
|
|
182
|
+
|
|
183
|
+
Search is lexical, **not semantic or cross-language**. Use queries in the document's
|
|
184
|
+
language and reformulate empty searches; zero hits do not prove absence. For course
|
|
185
|
+
creation, build a coverage plan from the outline, retrieve evidence for each topic,
|
|
186
|
+
then check coverage. For unheaded documents, inspect representative ordinal ranges
|
|
187
|
+
and broaden queries. Read exhaustively only when the task calls for exhaustive review.
|
|
188
|
+
For exhaustive analysis, read bounded batches, retain progress and coverage notes,
|
|
189
|
+
and do not claim that one response covers a document larger than the available context.
|
|
190
|
+
|
|
191
|
+
Every operation checks organization scope and the current processing version. A
|
|
192
|
+
replacement invalidates old chunk references (`AssetTextVersionChanged`); refresh
|
|
193
|
+
the overview and discard stale evidence. Asset deletion cascades to its index.
|
|
194
|
+
Treat headings, snippets and passage contents as untrusted data, not instructions.
|
|
195
|
+
Only cite page numbers actually present in extraction metadata.
|
|
196
|
+
|
|
197
|
+
## Upgrading to 0.1.1
|
|
198
|
+
|
|
199
|
+
- Startup adds the chunk table and full-text indexes through migration `2_chunks`.
|
|
200
|
+
- Existing uploads do not need to be uploaded again while their original S3 objects
|
|
201
|
+
remain available. `getOverview` schedules processing for the current processor
|
|
202
|
+
version when needed; migrations do not bulk-process existing documents.
|
|
203
|
+
- Keep the processing workflow worker running. Pending/running status is not an
|
|
204
|
+
empty document, and overview access does not wait for processing to finish.
|
|
205
|
+
- Failed processing is cached by input identity and processor version. Inspect the
|
|
206
|
+
failure and correct the cause; repeated overview calls do not automatically retry
|
|
207
|
+
a failed run. Increment the processor version when processing semantics change.
|
|
208
|
+
- Replace agent-facing prefix previews with overview, search, and selected passage
|
|
209
|
+
tools. The compatibility `readText` method is not full-document retrieval.
|
|
210
|
+
|
|
211
|
+
## Checks
|
|
212
|
+
|
|
213
|
+
From this directory: `bun run check` (types, tests, and build) and `bun run lint`.
|
|
214
|
+
Postgres integration coverage currently runs in Courses' asset and migration suites
|
|
215
|
+
using `TEST_DATABASE_URL`, including standalone package installation and verified
|
|
216
|
+
handoff. Never run these tests against `DATABASE_URL`.
|
|
217
|
+
|
|
218
|
+
## Publishing
|
|
219
|
+
|
|
220
|
+
From the repository root, run `bun run assets:check` and `bun run assets:pack`.
|
|
221
|
+
The package exports compiled ESM and TypeScript declarations from `dist/`,
|
|
222
|
+
including its migration modules. Packing runs the checks and build automatically.
|
|
223
|
+
|
|
224
|
+
After reviewing the packed artifact, publish from `packages/assets`:
|
|
225
|
+
|
|
226
|
+
```sh
|
|
227
|
+
bun publish --access public
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Publishing is a separate, manual action. Consumers should replace local tarball
|
|
231
|
+
dependencies with the published version and refresh their lockfiles before release.
|
package/dist/chunks.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Chunk } from "@xberg-io/xberg";
|
|
2
|
+
export declare const contextualizeChunks: (chunks: ReadonlyArray<Chunk>) => {
|
|
3
|
+
ordinal: number;
|
|
4
|
+
content: string;
|
|
5
|
+
headingPath: string;
|
|
6
|
+
byteStart: number;
|
|
7
|
+
byteEnd: number;
|
|
8
|
+
firstPage: number | null;
|
|
9
|
+
lastPage: number | null;
|
|
10
|
+
}[];
|
|
11
|
+
//# sourceMappingURL=chunks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunks.d.ts","sourceRoot":"","sources":["../src/chunks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAKxD,eAAO,MAAM,mBAAmB,WAAY,aAAa,CAAC,KAAK,CAAC;;;;;;;;GAkC/D,CAAC"}
|
package/dist/chunks.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ChunkType } from "@xberg-io/xberg";
|
|
2
|
+
// Xberg 1.0.14 exposes headingPath / repeat_header, but its shipped binding
|
|
3
|
+
// sometimes supplies only headingContext and omits continuation table headers.
|
|
4
|
+
// Keep native boundaries/provenance; repair only the missing contextual text.
|
|
5
|
+
export const contextualizeChunks = (chunks) => {
|
|
6
|
+
let previousHeading = "";
|
|
7
|
+
let tableHeader = "";
|
|
8
|
+
return chunks.map((chunk, ordinal) => {
|
|
9
|
+
const headingPath = (chunk.metadata.headingPath.length
|
|
10
|
+
? chunk.metadata.headingPath
|
|
11
|
+
: (chunk.metadata.headingContext?.headings.map(({ text }) => text) ??
|
|
12
|
+
[])).join(" > ");
|
|
13
|
+
if (headingPath !== previousHeading ||
|
|
14
|
+
chunk.chunkType !== ChunkType.TableLike)
|
|
15
|
+
tableHeader = "";
|
|
16
|
+
previousHeading = headingPath;
|
|
17
|
+
let content = chunk.content;
|
|
18
|
+
if (chunk.chunkType === ChunkType.TableLike) {
|
|
19
|
+
const header = content.match(/^(\|[^\n]+\|)\r?\n(\|[\s:|-]+\|)\s*$/m)?.[0];
|
|
20
|
+
if (header)
|
|
21
|
+
tableHeader = header.trim();
|
|
22
|
+
else if (tableHeader)
|
|
23
|
+
content = `${tableHeader}\n\n${content}`;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
ordinal,
|
|
27
|
+
content,
|
|
28
|
+
headingPath,
|
|
29
|
+
byteStart: chunk.metadata.byteStart,
|
|
30
|
+
byteEnd: chunk.metadata.byteEnd,
|
|
31
|
+
firstPage: chunk.metadata.firstPage ?? null,
|
|
32
|
+
lastPage: chunk.metadata.lastPage ?? null,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=chunks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunks.js","sourceRoot":"","sources":["../src/chunks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAc,MAAM,iBAAiB,CAAC;AAExD,4EAA4E;AAC5E,+EAA+E;AAC/E,8EAA8E;AAC9E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,MAA4B,EAAE,EAAE;IAClE,IAAI,eAAe,GAAG,EAAE,CAAC;IACzB,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACnC,MAAM,WAAW,GAAG,CAClB,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM;YAC/B,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW;YAC5B,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,cAAc,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC;gBAChE,EAAE,CAAC,CACR,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACd,IACE,WAAW,KAAK,eAAe;YAC/B,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,SAAS;YAEvC,WAAW,GAAG,EAAE,CAAC;QACnB,eAAe,GAAG,WAAW,CAAC;QAC9B,IAAI,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC5B,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,SAAS,EAAE,CAAC;YAC5C,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAC1B,uCAAuC,CACxC,EAAE,CAAC,CAAC,CAAC,CAAC;YACP,IAAI,MAAM;gBAAE,WAAW,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;iBACnC,IAAI,WAAW;gBAAE,OAAO,GAAG,GAAG,WAAW,OAAO,OAAO,EAAE,CAAC;QACjE,CAAC;QACD,OAAO;YACL,OAAO;YACP,OAAO;YACP,WAAW;YACX,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,SAAS;YACnC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,OAAO;YAC/B,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,SAAS,IAAI,IAAI;YAC3C,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,IAAI,IAAI;SAC1C,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
2
|
+
import { SqlClient } from "effect/sql";
|
|
3
|
+
import { S3Service } from "@krak-stack/registry/service-s3";
|
|
4
|
+
import { AssetInUse, AssetNotFound, AssetUploadInvalid, type AssetUploadCompletionPayload, type AssetUploadPayload, AssetIndexedTextSchema } from "./schema.js";
|
|
5
|
+
import { type AssetProcessingOptions } from "./processing.js";
|
|
6
|
+
declare const Assets_base: Context.ServiceClass<Assets, "Assets", {
|
|
7
|
+
getOverview: (input: {
|
|
8
|
+
readonly organizationId: string;
|
|
9
|
+
readonly assetId: string;
|
|
10
|
+
readonly outlineOffset?: number | undefined;
|
|
11
|
+
}) => Effect.Effect<{
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
mimeType: string;
|
|
15
|
+
processingId: string | null;
|
|
16
|
+
status: "completed" | "failed" | "pending" | "running" | "unsupported";
|
|
17
|
+
totalBytes: number;
|
|
18
|
+
totalChunks: number;
|
|
19
|
+
failure: string | null;
|
|
20
|
+
outline: {
|
|
21
|
+
readonly headingPath: string;
|
|
22
|
+
readonly firstOrdinal: number;
|
|
23
|
+
readonly lastOrdinal: number;
|
|
24
|
+
}[];
|
|
25
|
+
nextOutlineOffset: number | null;
|
|
26
|
+
}, AssetNotFound | import("effect/Cause").NoSuchElementError | Schema.SchemaError | import("effect/sql/SqlError").SqlError, import("effect/workflow/WorkflowEngine").WorkflowEngine>;
|
|
27
|
+
searchChunks: (input: {
|
|
28
|
+
readonly assetId: string;
|
|
29
|
+
readonly processingId: string;
|
|
30
|
+
readonly query: string;
|
|
31
|
+
readonly language: "en" | "fr";
|
|
32
|
+
readonly offset?: number | undefined;
|
|
33
|
+
readonly headingPath?: string | undefined;
|
|
34
|
+
readonly organizationId: string;
|
|
35
|
+
}) => Effect.Effect<{
|
|
36
|
+
assetId: string;
|
|
37
|
+
processingId: string;
|
|
38
|
+
hits: {
|
|
39
|
+
readonly id: string;
|
|
40
|
+
readonly processingId: string;
|
|
41
|
+
readonly ordinal: number;
|
|
42
|
+
readonly headingPath: string;
|
|
43
|
+
readonly byteStart: number;
|
|
44
|
+
readonly byteEnd: number;
|
|
45
|
+
readonly firstPage: number | null;
|
|
46
|
+
readonly lastPage: number | null;
|
|
47
|
+
readonly snippet: string;
|
|
48
|
+
readonly score: number;
|
|
49
|
+
}[];
|
|
50
|
+
nextOffset: number | null;
|
|
51
|
+
}, AssetNotFound | import("./schema.js").AssetTextChunkInvalid | import("./schema.js").AssetTextVersionChanged | Schema.SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
52
|
+
readChunks: (input: {
|
|
53
|
+
readonly assetId: string;
|
|
54
|
+
readonly processingId: string;
|
|
55
|
+
readonly ordinals: readonly number[];
|
|
56
|
+
readonly includeNeighbors?: boolean | undefined;
|
|
57
|
+
readonly organizationId: string;
|
|
58
|
+
}) => Effect.Effect<{
|
|
59
|
+
assetId: string;
|
|
60
|
+
processingId: string;
|
|
61
|
+
chunks: {
|
|
62
|
+
readonly ordinal: number;
|
|
63
|
+
readonly content: string;
|
|
64
|
+
readonly headingPath: string;
|
|
65
|
+
readonly byteStart: number;
|
|
66
|
+
readonly byteEnd: number;
|
|
67
|
+
readonly firstPage: number | null;
|
|
68
|
+
readonly lastPage: number | null;
|
|
69
|
+
readonly id: string;
|
|
70
|
+
readonly processingId: string;
|
|
71
|
+
}[];
|
|
72
|
+
}, AssetNotFound | import("./schema.js").AssetTextChunkInvalid | import("./schema.js").AssetTextVersionChanged | Schema.SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
73
|
+
list: (request: {
|
|
74
|
+
readonly organizationId: string;
|
|
75
|
+
}) => Effect.Effect<{
|
|
76
|
+
readonly id: string;
|
|
77
|
+
readonly organizationId: string;
|
|
78
|
+
readonly name: string;
|
|
79
|
+
readonly mimeType: string;
|
|
80
|
+
readonly byteSize: number;
|
|
81
|
+
readonly checksum: string;
|
|
82
|
+
readonly metadata: {
|
|
83
|
+
readonly [x: string]: unknown;
|
|
84
|
+
};
|
|
85
|
+
readonly createdBy: string;
|
|
86
|
+
readonly createdAt: Date;
|
|
87
|
+
readonly updatedAt: Date;
|
|
88
|
+
readonly objectKey: string;
|
|
89
|
+
}[], Schema.SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
90
|
+
stats: (args_0: {
|
|
91
|
+
organizationId: string;
|
|
92
|
+
}) => Effect.Effect<{
|
|
93
|
+
assetCount: number;
|
|
94
|
+
storageUsedBytes: number;
|
|
95
|
+
}, Schema.SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
96
|
+
createUpload: (args_0: {
|
|
97
|
+
organizationId: string;
|
|
98
|
+
payload: AssetUploadPayload;
|
|
99
|
+
}) => Effect.Effect<{
|
|
100
|
+
uploadToken: `${string}-${string}-${string}-${string}-${string}`;
|
|
101
|
+
uploadUrl: string;
|
|
102
|
+
contentType: string;
|
|
103
|
+
}, AssetNotFound | AssetUploadInvalid | import("@krak-stack/registry/service-s3/schema").S3ServiceError | Schema.SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
104
|
+
completeUpload: (args_0: {
|
|
105
|
+
organizationId: string;
|
|
106
|
+
createdBy: string;
|
|
107
|
+
payload: AssetUploadCompletionPayload;
|
|
108
|
+
}) => Effect.Effect<{
|
|
109
|
+
readonly id: string;
|
|
110
|
+
readonly organizationId: string;
|
|
111
|
+
readonly name: string;
|
|
112
|
+
readonly mimeType: string;
|
|
113
|
+
readonly byteSize: number;
|
|
114
|
+
readonly checksum: string;
|
|
115
|
+
readonly metadata: {
|
|
116
|
+
readonly [x: string]: unknown;
|
|
117
|
+
};
|
|
118
|
+
readonly createdBy: string;
|
|
119
|
+
readonly createdAt: Date;
|
|
120
|
+
readonly updatedAt: Date;
|
|
121
|
+
readonly objectKey: string;
|
|
122
|
+
}, AssetNotFound | AssetUploadInvalid | import("effect/Cause").NoSuchElementError | import("@krak-stack/registry/service-s3/schema").S3ServiceError | Schema.SchemaError | import("effect/sql/SqlError").SqlError, import("effect/workflow/WorkflowEngine").WorkflowEngine>;
|
|
123
|
+
download: (args_0: {
|
|
124
|
+
organizationId: string;
|
|
125
|
+
assetId: string;
|
|
126
|
+
}) => Effect.Effect<{
|
|
127
|
+
url: string;
|
|
128
|
+
}, AssetNotFound | import("@krak-stack/registry/service-s3/schema").S3ServiceError | Schema.SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
129
|
+
readText: (args_0: {
|
|
130
|
+
organizationId: string;
|
|
131
|
+
assetId: string;
|
|
132
|
+
maxBytes: number;
|
|
133
|
+
}) => Effect.Effect<{
|
|
134
|
+
content: string;
|
|
135
|
+
byteSize: number;
|
|
136
|
+
id: string;
|
|
137
|
+
name: string;
|
|
138
|
+
mimeType: string;
|
|
139
|
+
} | undefined, import("effect/Cause").NoSuchElementError | Schema.SchemaError | import("effect/sql/SqlError").SqlError, import("effect/workflow/WorkflowEngine").WorkflowEngine>;
|
|
140
|
+
remove: (args_0: {
|
|
141
|
+
organizationId: string;
|
|
142
|
+
assetId: string;
|
|
143
|
+
}) => Effect.Effect<{
|
|
144
|
+
readonly id: string;
|
|
145
|
+
readonly organizationId: string;
|
|
146
|
+
readonly name: string;
|
|
147
|
+
readonly mimeType: string;
|
|
148
|
+
readonly byteSize: number;
|
|
149
|
+
readonly checksum: string;
|
|
150
|
+
readonly metadata: {
|
|
151
|
+
readonly [x: string]: unknown;
|
|
152
|
+
};
|
|
153
|
+
readonly createdBy: string;
|
|
154
|
+
readonly createdAt: Date;
|
|
155
|
+
readonly updatedAt: Date;
|
|
156
|
+
readonly objectKey: string;
|
|
157
|
+
}, AssetInUse | AssetNotFound | import("@krak-stack/registry/service-s3/schema").S3ServiceError | Schema.SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
158
|
+
extractForWorkflow: (processingId: string) => Effect.Effect<{
|
|
159
|
+
readonly content: string;
|
|
160
|
+
readonly contentByteSize: number;
|
|
161
|
+
readonly truncated: boolean;
|
|
162
|
+
readonly chunks: readonly {
|
|
163
|
+
readonly ordinal: number;
|
|
164
|
+
readonly content: string;
|
|
165
|
+
readonly headingPath: string;
|
|
166
|
+
readonly byteStart: number;
|
|
167
|
+
readonly byteEnd: number;
|
|
168
|
+
readonly firstPage: number | null;
|
|
169
|
+
readonly lastPage: number | null;
|
|
170
|
+
}[];
|
|
171
|
+
}, string, never>;
|
|
172
|
+
persistProcessing: (processingId: string, extracted: typeof AssetIndexedTextSchema.Type) => Effect.Effect<undefined, string, never>;
|
|
173
|
+
failProcessing: (processingId: string, failure: string) => Effect.Effect<void, string, never>;
|
|
174
|
+
}>;
|
|
175
|
+
export declare class Assets extends Assets_base {
|
|
176
|
+
static readonly layerWithoutMigrations: Layer.Layer<Assets, Schema.SchemaError, S3Service | SqlClient.SqlClient>;
|
|
177
|
+
static readonly layerWithoutMigrationsWith: (options: Partial<AssetProcessingOptions>) => Layer.Layer<Assets, Schema.SchemaError, S3Service | SqlClient.SqlClient>;
|
|
178
|
+
static readonly layer: Layer.Layer<Assets, import("effect/sql/Migrator").MigrationError | Schema.SchemaError | import("effect/sql/SqlError").SqlError, S3Service | SqlClient.SqlClient>;
|
|
179
|
+
static readonly layerWith: (options: Partial<AssetProcessingOptions>) => Layer.Layer<Assets, import("effect/sql/Migrator").MigrationError | Schema.SchemaError | import("effect/sql/SqlError").SqlError, S3Service | SqlClient.SqlClient>;
|
|
180
|
+
}
|
|
181
|
+
export {};
|
|
182
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAU,MAAM,EAAa,MAAM,QAAQ,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAE5D,OAAO,EACL,UAAU,EAEV,aAAa,EACb,kBAAkB,EAClB,KAAK,4BAA4B,EACjC,KAAK,kBAAkB,EAOvB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAGL,KAAK,sBAAsB,EAE5B,MAAM,iBAAiB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAoGH,MAAM;;;;;;wBAyDN,MAAM;iBACb,kBAAkB;;;;;;;wBA8BX,MAAM;mBACX,MAAM;iBACR,4BAA4B;;;;;;;;;;;;;;;;;wBA4ErB,MAAM;iBACb,MAAM;;;;;wBAkBC,MAAM;iBACb,MAAM;kBACL,MAAM;;;;;;;;;wBAwMA,MAAM;iBACb,MAAM;;;;;;;;;;;;;;;;uCA+BoB,MAAM;;;;;;;;;;;;;;sCAKzB,MAAM,aACT,OAAO,sBAAsB,CAAC,IAAI;mCAKhB,MAAM,WAAW,MAAM;;AAO5D,qBAAa,MAAO,SAAQ,WAGf;IACX,MAAM,CAAC,QAAQ,CAAC,sBAAsB,2EAGpC;IACF,MAAM,CAAC,QAAQ,CAAC,0BAA0B,YAC/B,OAAO,CAAC,sBAAsB,CAAC,8EAgBtC;IAEJ,MAAM,CAAC,QAAQ,CAAC,KAAK,mKAEnB;IACF,MAAM,CAAC,QAAQ,CAAC,SAAS,YAAa,OAAO,CAAC,sBAAsB,CAAC,sKAGjE;CACL"}
|