@krak-stack/assets 0.1.0 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,eAAO,MAAM,eAAe,0BAE1B,CAAC;AAKH,eAAO,MAAM,aAAa,0JAkBxB,CAAC"}
1
+ {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvC,eAAO,MAAM,eAAe,0BAG1B,CAAC;AAKH,eAAO,MAAM,aAAa,0JAkBxB,CAAC"}
@@ -2,8 +2,10 @@ import { PgMigrator } from "@effect/sql-pg";
2
2
  import { Effect } from "effect";
3
3
  import { SqlClient } from "effect/sql";
4
4
  import initialMigration from "./migrations/0001_assets.js";
5
+ import chunksMigration from "./migrations/0002_chunks.js";
5
6
  export const assetMigrations = PgMigrator.fromRecord({
6
7
  "1_assets": initialMigration,
8
+ "2_chunks": chunksMigration,
7
9
  });
8
10
  // No schema dump is requested, so layer startup needs only the SQL client.
9
11
  const runMigrations = PgMigrator.make({});
@@ -1 +1 @@
1
- {"version":3,"file":"migrations.js","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAA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AAE,eAAe;CAC5B,CAAC,CAAC;AAEH,2EAA2E;AAC3E,MAAM,aAAa,GAAG,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAE1C,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC/C,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC;IACvC,OAAO,KAAK,CAAC,CAAC,GAAG,CAAC,eAAe,CAC/B,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAClB,KAAK,CAAC,CAAC,GAAG,CAAA,yCAAyC,CAAC;QACpD,KAAK,CAAC,CAAC,GAAG,CAAA,iCAAiC,CAAC;QAC5C,4EAA4E;QAC5E,KAAK,CAAC,CAAC,GAAG,CAAA;;;;MAIV,CAAC;QACD,OAAO,KAAK,CAAC,CAAC,aAAa,CAAC;YAC1B,KAAK,EAAE,kBAAkB;YACzB,MAAM,EAAE,eAAe;SACxB,CAAC,CAAC;IACL,CAAC,CAAC,CACH,CAAC;AACJ,CAAC,CAAC,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { type ExtractionConfig } from "@xberg-io/xberg";
2
- export declare const ASSET_PROCESSOR_VERSION = 3;
2
+ import { Schema } from "effect";
3
+ export declare const ASSET_PROCESSOR_VERSION = 4;
3
4
  export interface AssetProcessingOptions {
4
5
  readonly processorVersion: number;
5
6
  readonly maxInputBytes: number;
@@ -7,6 +8,12 @@ export interface AssetProcessingOptions {
7
8
  readonly concurrency: number;
8
9
  readonly extraction: ExtractionConfig;
9
10
  }
11
+ export declare const AssetProcessingLimitsSchema: Schema.Struct<{
12
+ readonly processorVersion: Schema.Int;
13
+ readonly maxInputBytes: Schema.Int;
14
+ readonly maxOutputBytes: Schema.Int;
15
+ readonly concurrency: Schema.Int;
16
+ }>;
10
17
  export declare const defaultAssetProcessingOptions: AssetProcessingOptions;
11
18
  export declare const PROCESSABLE_MIME_TYPES: Set<string>;
12
19
  //# sourceMappingURL=processing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"processing.d.ts","sourceRoot":"","sources":["../src/processing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEtE,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;CACvC;AAED,eAAO,MAAM,6BAA6B,EAAE,sBAuB3C,CAAC;AAEF,eAAO,MAAM,sBAAsB,aAYjC,CAAC"}
1
+ {"version":3,"file":"processing.d.ts","sourceRoot":"","sources":["../src/processing.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;CACvC;AAGD,eAAO,MAAM,2BAA2B;;;;;EASY,CAAC;AAErD,eAAO,MAAM,6BAA6B,EAAE,sBA+B3C,CAAC;AAEF,eAAO,MAAM,sBAAsB,aAYjC,CAAC"}
@@ -1,12 +1,28 @@
1
- import { OutputFormat } from "@xberg-io/xberg";
2
- export const ASSET_PROCESSOR_VERSION = 3;
1
+ import { ChunkerType, OutputFormat, TableChunkingMode, } from "@xberg-io/xberg";
2
+ import { Schema } from "effect";
3
+ export const ASSET_PROCESSOR_VERSION = 4;
4
+ const PositiveInt = Schema.Int.check(Schema.isGreaterThan(0));
5
+ export const AssetProcessingLimitsSchema = Schema.Struct({
6
+ processorVersion: PositiveInt,
7
+ maxInputBytes: PositiveInt.check(Schema.isLessThanOrEqualTo(100 * 1024 * 1024)),
8
+ maxOutputBytes: PositiveInt.check(Schema.isLessThanOrEqualTo(100 * 1024 * 1024)),
9
+ concurrency: PositiveInt.check(Schema.isLessThanOrEqualTo(64)),
10
+ }).annotate({ identifier: "AssetProcessingLimits" });
3
11
  export const defaultAssetProcessingOptions = {
4
12
  processorVersion: ASSET_PROCESSOR_VERSION,
5
13
  maxInputBytes: 20 * 1024 * 1024,
6
- maxOutputBytes: 512 * 1024,
14
+ maxOutputBytes: 20 * 1024 * 1024,
7
15
  concurrency: 2,
8
16
  extraction: {
9
17
  outputFormat: OutputFormat.Markdown,
18
+ pages: { extractPages: true },
19
+ chunking: {
20
+ chunkerType: ChunkerType.Markdown,
21
+ maxCharacters: 4000,
22
+ overlap: 200,
23
+ prependHeadingContext: true,
24
+ tableChunking: TableChunkingMode.RepeatHeader,
25
+ },
10
26
  extractionTimeoutSecs: 30,
11
27
  maxConcurrentExtractions: 1,
12
28
  maxEmbeddedFileBytes: 10 * 1024 * 1024,
@@ -17,7 +33,7 @@ export const defaultAssetProcessingOptions = {
17
33
  maxFilesInArchive: 1000,
18
34
  maxNestingDepth: 50,
19
35
  maxEntityLength: 1024 * 1024,
20
- maxContentSize: 2 * 1024 * 1024,
36
+ maxContentSize: 20 * 1024 * 1024,
21
37
  maxIterations: 1_000_000,
22
38
  maxXmlDepth: 50,
23
39
  maxTableCells: 100_000,
@@ -1 +1 @@
1
- {"version":3,"file":"processing.js","sourceRoot":"","sources":["../src/processing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,MAAM,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C,mBAAmB,EAAE,GAAG;YACxB,iBAAiB,EAAE,IAAI;YACvB,eAAe,EAAE,EAAE;YACnB,eAAe,EAAE,IAAI,GAAG,IAAI;YAC5B,cAAc,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;YAChC,aAAa,EAAE,SAAS;YACxB,WAAW,EAAE,EAAE;YACf,aAAa,EAAE,OAAO;SACvB;KACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC;IAC5C,UAAU;IACV,iBAAiB;IACjB,yEAAyE;IACzE,2EAA2E;IAC3E,mEAAmE;IACnE,YAAY;IACZ,eAAe;IACf,UAAU;IACV,kBAAkB;IAClB,iBAAiB;IACjB,UAAU;CACX,CAAC,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { SqlClient } from "effect/sql";
3
+ import { AssetNotFound, AssetRowSchema, AssetTextChunkInvalid, AssetTextVersionChanged } from "./schema.js";
4
+ export declare const makeRetrieval: <E, R>({ processorVersion, startProcessing, }: {
5
+ processorVersion: number;
6
+ startProcessing: (asset: typeof AssetRowSchema.Type) => Effect.Effect<void, E, R>;
7
+ }) => Effect.Effect<{
8
+ getOverview: (input: {
9
+ readonly organizationId: string;
10
+ readonly assetId: string;
11
+ readonly outlineOffset?: number | undefined;
12
+ }) => Effect.Effect<{
13
+ id: string;
14
+ name: string;
15
+ mimeType: string;
16
+ processingId: string | null;
17
+ status: "completed" | "failed" | "pending" | "running" | "unsupported";
18
+ totalBytes: number;
19
+ totalChunks: number;
20
+ failure: string | null;
21
+ outline: {
22
+ readonly headingPath: string;
23
+ readonly firstOrdinal: number;
24
+ readonly lastOrdinal: number;
25
+ }[];
26
+ nextOutlineOffset: number | null;
27
+ }, E | AssetNotFound | import("effect/Cause").NoSuchElementError | Schema.SchemaError | import("effect/sql/SqlError").SqlError, R>;
28
+ searchChunks: (input: {
29
+ readonly assetId: string;
30
+ readonly processingId: string;
31
+ readonly query: string;
32
+ readonly language: "en" | "fr";
33
+ readonly offset?: number | undefined;
34
+ readonly headingPath?: string | undefined;
35
+ readonly organizationId: string;
36
+ }) => Effect.Effect<{
37
+ assetId: string;
38
+ processingId: string;
39
+ hits: {
40
+ readonly id: string;
41
+ readonly processingId: string;
42
+ readonly ordinal: number;
43
+ readonly headingPath: string;
44
+ readonly byteStart: number;
45
+ readonly byteEnd: number;
46
+ readonly firstPage: number | null;
47
+ readonly lastPage: number | null;
48
+ readonly snippet: string;
49
+ readonly score: number;
50
+ }[];
51
+ nextOffset: number | null;
52
+ }, AssetNotFound | AssetTextChunkInvalid | AssetTextVersionChanged | Schema.SchemaError | import("effect/sql/SqlError").SqlError, never>;
53
+ readChunks: (input: {
54
+ readonly assetId: string;
55
+ readonly processingId: string;
56
+ readonly ordinals: readonly number[];
57
+ readonly includeNeighbors?: boolean | undefined;
58
+ readonly organizationId: string;
59
+ }) => Effect.Effect<{
60
+ assetId: string;
61
+ processingId: string;
62
+ chunks: {
63
+ readonly ordinal: number;
64
+ readonly content: string;
65
+ readonly headingPath: string;
66
+ readonly byteStart: number;
67
+ readonly byteEnd: number;
68
+ readonly firstPage: number | null;
69
+ readonly lastPage: number | null;
70
+ readonly id: string;
71
+ readonly processingId: string;
72
+ }[];
73
+ }, AssetNotFound | AssetTextChunkInvalid | AssetTextVersionChanged | Schema.SchemaError | import("effect/sql/SqlError").SqlError, never>;
74
+ }, never, SqlClient.SqlClient>;
75
+ //# sourceMappingURL=retrieval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retrieval.d.ts","sourceRoot":"","sources":["../src/retrieval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAClD,OAAO,EAEL,aAAa,EAKb,cAAc,EAId,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,aAAa,CAAC;AAIrB,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,CAAC,0CAG/B;IACD,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,CACf,KAAK,EAAE,OAAO,cAAc,CAAC,IAAI,KAC9B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;CAChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BAiMG,CAAC"}
@@ -0,0 +1,155 @@
1
+ import { Effect, Option, Schema } from "effect";
2
+ import { SqlClient, SqlSchema } from "effect/sql";
3
+ import { AssetChunkSchema, AssetNotFound, AssetOverviewSchema, AssetOutlineEntrySchema, AssetScopedReadChunksRequestSchema, AssetRequestSchema, AssetRowSchema, AssetSearchHitSchema, AssetScopedSearchRequestSchema, AssetOverviewRequestSchema, AssetTextChunkInvalid, AssetTextVersionChanged, } from "./schema.js";
4
+ import { PROCESSABLE_MIME_TYPES } from "./processing.js";
5
+ // Internal service implementation, not a separate service or auth boundary.
6
+ export const makeRetrieval = ({ processorVersion, startProcessing, }) => Effect.gen(function* () {
7
+ const sql = yield* SqlClient.SqlClient;
8
+ const readCurrent = (lock) => SqlSchema.findOneOption({
9
+ Request: AssetRequestSchema,
10
+ Result: AssetOverviewSchema,
11
+ execute: ({ organizationId, assetId }) => sql `
12
+ SELECT a.id, a.name, a.mime_type, p.id AS processing_id,
13
+ CASE WHEN p.status = 'completed' AND p.truncated IS DISTINCT FROM false THEN 'failed'
14
+ ELSE COALESCE(p.status, 'pending') END AS status,
15
+ COALESCE(p.content_byte_size, 0) AS total_bytes,
16
+ (SELECT count(*)::integer FROM asset_chunks c WHERE c.processing_id = p.id) AS total_chunks,
17
+ CASE WHEN p.status = 'completed' AND p.truncated IS DISTINCT FROM false
18
+ THEN 'Incomplete extraction requires reprocessing' ELSE p.failure END AS failure
19
+ FROM assets a LEFT JOIN asset_processings p ON p.asset_id = a.id
20
+ AND p.checksum = a.checksum AND p.filename = a.name AND p.mime_type = a.mime_type
21
+ AND p.processor_version = ${processorVersion}
22
+ WHERE a.id = ${assetId} AND a.organization_id = ${organizationId}
23
+ ${lock ? sql `FOR SHARE OF a` : sql ``}
24
+ `,
25
+ });
26
+ const current = readCurrent(true);
27
+ const inspectCurrent = readCurrent(false);
28
+ const overview = Effect.fn("Assets.getOverview")((input) => Effect.gen(function* () {
29
+ const request = yield* Schema.decodeUnknownEffect(AssetOverviewRequestSchema)(input);
30
+ const { outlineOffset = 0 } = request;
31
+ let found = yield* inspectCurrent(request);
32
+ if (Option.isNone(found))
33
+ return yield* new AssetNotFound({ assetId: request.assetId });
34
+ if (!PROCESSABLE_MIME_TYPES.has(found.value.mimeType))
35
+ return {
36
+ ...found.value,
37
+ status: "unsupported",
38
+ outline: [],
39
+ nextOutlineOffset: null,
40
+ };
41
+ if (!found.value.processingId || found.value.status === "pending") {
42
+ const asset = yield* SqlSchema.findOne({
43
+ Request: AssetRequestSchema,
44
+ Result: AssetRowSchema,
45
+ execute: ({ assetId, organizationId }) => sql `SELECT * FROM assets WHERE id = ${assetId} AND organization_id = ${organizationId}`,
46
+ })(request);
47
+ yield* startProcessing(asset);
48
+ found = yield* inspectCurrent(request);
49
+ }
50
+ if (Option.isNone(found))
51
+ return yield* new AssetNotFound({ assetId: request.assetId });
52
+ const row = found.value;
53
+ const outline = row.status !== "completed"
54
+ ? []
55
+ : yield* SqlSchema.findAll({
56
+ Request: Schema.Void,
57
+ Result: AssetOutlineEntrySchema,
58
+ execute: () => sql `
59
+ WITH sections AS (
60
+ SELECT heading_path, ordinal,
61
+ ordinal - row_number() OVER (PARTITION BY heading_path ORDER BY ordinal)::integer AS section_group
62
+ FROM asset_chunks WHERE processing_id = ${row.processingId}
63
+ )
64
+ SELECT heading_path, min(ordinal)::integer AS first_ordinal, max(ordinal)::integer AS last_ordinal
65
+ FROM sections GROUP BY heading_path, section_group ORDER BY min(ordinal)
66
+ LIMIT 51 OFFSET ${outlineOffset}
67
+ `,
68
+ })();
69
+ return {
70
+ ...row,
71
+ outline: outline.slice(0, 50),
72
+ nextOutlineOffset: outline.length > 50 ? outlineOffset + 50 : null,
73
+ };
74
+ }));
75
+ const requireCurrent = Effect.fn("Assets.requireCurrentIndex")(function* (input) {
76
+ const found = yield* current(input);
77
+ if (Option.isNone(found))
78
+ return yield* new AssetNotFound({ assetId: input.assetId });
79
+ if (found.value.processingId !== input.processingId)
80
+ return yield* new AssetTextVersionChanged({ assetId: input.assetId });
81
+ if (found.value.status !== "completed" || found.value.totalChunks === 0)
82
+ return yield* new AssetTextChunkInvalid({
83
+ message: "Asset index is not ready; inspect its overview",
84
+ });
85
+ return found.value;
86
+ });
87
+ const searchChunks = Effect.fn("Assets.searchChunks")((input) => sql.withTransaction(Effect.gen(function* () {
88
+ const request = yield* Schema.decodeUnknownEffect(AssetScopedSearchRequestSchema)(input);
89
+ yield* requireCurrent(request);
90
+ const offset = request.offset ?? 0;
91
+ const vector = request.language === "fr" ? sql `c.search_fr` : sql `c.search_en`;
92
+ const config = request.language === "fr"
93
+ ? sql `'french'::regconfig`
94
+ : sql `'english'::regconfig`;
95
+ const hits = yield* SqlSchema.findAll({
96
+ Request: Schema.Void,
97
+ Result: AssetSearchHitSchema,
98
+ execute: () => sql `
99
+ WITH raw_matches AS (
100
+ SELECT c.*, ts_rank_cd(${vector}, q.query)::float8 AS score
101
+ FROM asset_chunks c, websearch_to_tsquery(${config}, ${request.query}) AS q(query)
102
+ WHERE c.processing_id = ${request.processingId} AND ${vector} @@ q.query
103
+ ${request.headingPath === undefined ? sql `` : sql `AND c.heading_path = ${request.headingPath}`}
104
+ ), matches AS (
105
+ SELECT DISTINCT ON (heading_path, md5(content)) * FROM raw_matches
106
+ ORDER BY heading_path, md5(content), score DESC, ordinal
107
+ ), diverse AS (
108
+ SELECT *, row_number() OVER (PARTITION BY heading_path ORDER BY score DESC, ordinal) AS section_rank
109
+ FROM matches
110
+ )
111
+ SELECT id, processing_id, ordinal, heading_path, byte_start, byte_end, first_page, last_page, score,
112
+ substring(ts_headline(${config}, content, websearch_to_tsquery(${config}, ${request.query}),
113
+ 'StartSel=, StopSel=, MaxWords=60, MinWords=15, MaxFragments=2') FROM 1 FOR 1600) AS snippet
114
+ FROM diverse ORDER BY section_rank, score DESC, ordinal LIMIT 9 OFFSET ${offset}
115
+ `,
116
+ })();
117
+ return {
118
+ assetId: request.assetId,
119
+ processingId: request.processingId,
120
+ hits: hits.slice(0, 8),
121
+ nextOffset: hits.length > 8 ? offset + 8 : null,
122
+ };
123
+ })));
124
+ const readChunks = Effect.fn("Assets.readChunks")((input) => sql.withTransaction(Effect.gen(function* () {
125
+ const request = yield* Schema.decodeUnknownEffect(AssetScopedReadChunksRequestSchema)(input);
126
+ const overview = yield* requireCurrent(request);
127
+ if (request.ordinals.some((ordinal) => ordinal >= overview.totalChunks))
128
+ return yield* new AssetTextChunkInvalid({
129
+ message: "Chunk ordinal is beyond the document",
130
+ });
131
+ const ordinals = [
132
+ ...new Set(request.ordinals.flatMap((ordinal) => request.includeNeighbors
133
+ ? [ordinal - 1, ordinal, ordinal + 1]
134
+ : [ordinal])),
135
+ ].filter((ordinal) => ordinal >= 0 && ordinal < overview.totalChunks);
136
+ const chunks = yield* SqlSchema.findAll({
137
+ Request: Schema.Void,
138
+ Result: AssetChunkSchema,
139
+ execute: () => sql `SELECT id, processing_id, ordinal, content, heading_path, byte_start, byte_end, first_page, last_page
140
+ FROM asset_chunks WHERE processing_id = ${request.processingId} AND ${sql.in("ordinal", ordinals)} ORDER BY ordinal`,
141
+ })();
142
+ if (chunks.reduce((size, chunk) => size + new TextEncoder().encode(chunk.content).byteLength, 0) >
143
+ 128 * 1024)
144
+ return yield* new AssetTextChunkInvalid({
145
+ message: "Passage response exceeds the budget; request fewer chunks or omit neighbors",
146
+ });
147
+ return {
148
+ assetId: request.assetId,
149
+ processingId: request.processingId,
150
+ chunks,
151
+ };
152
+ })));
153
+ return { getOverview: overview, searchChunks, readChunks };
154
+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BACtB,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,CAAC,CAAC;gBACrC,CAAC,CAAC,CAAC,OAAO,CAAC,CACd,CACF;SACF,CAAC,MAAM,CACN,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,IAAI,CAAC,IAAI,OAAO,GAAG,QAAQ,CAAC,WAAW,CAC5D,CAAC;QACF,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC;YACtC,OAAO,EAAE,MAAM,CAAC,IAAI;YACpB,MAAM,EAAE,gBAAgB;YACxB,OAAO,EACL,GAAG,EAAE,CAAC,GAAG,CAAA;kDACyB,OAAO,CAAC,YAAY,QAAQ,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,mBAAmB;SAC/G,CAAC,EAAE,CAAC;QACL,IACE,MAAM,CAAC,MAAM,CACX,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACd,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,UAAU,EAC3D,CAAC,CACF;YACD,GAAG,GAAG,IAAI;YAEV,OAAO,KAAK,CAAC,CAAC,IAAI,qBAAqB,CAAC;gBACtC,OAAO,EACL,6EAA6E;aAChF,CAAC,CAAC;QACL,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,MAAM;SACP,CAAC;IACJ,CAAC,CAAC,CACH,CACJ,CAAC;IACF,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;AAC7D,CAAC,CAAC,CAAC"}
package/dist/schema.d.ts CHANGED
@@ -64,6 +64,160 @@ export declare const AssetExtractedTextSchema: Schema.Struct<{
64
64
  readonly contentByteSize: Schema.Int;
65
65
  readonly truncated: Schema.Boolean;
66
66
  }>;
67
+ export declare const AssetExtractedChunkSchema: Schema.Struct<{
68
+ readonly ordinal: Schema.Int;
69
+ readonly content: Schema.NonEmptyString;
70
+ readonly headingPath: Schema.String;
71
+ readonly byteStart: Schema.Int;
72
+ readonly byteEnd: Schema.Int;
73
+ readonly firstPage: Schema.NullOr<Schema.Int>;
74
+ readonly lastPage: Schema.NullOr<Schema.Int>;
75
+ }>;
76
+ export declare const AssetIndexedTextSchema: Schema.Struct<{
77
+ readonly content: Schema.String;
78
+ readonly contentByteSize: Schema.Int;
79
+ readonly truncated: Schema.Boolean;
80
+ readonly chunks: Schema.$Array<Schema.Struct<{
81
+ readonly ordinal: Schema.Int;
82
+ readonly content: Schema.NonEmptyString;
83
+ readonly headingPath: Schema.String;
84
+ readonly byteStart: Schema.Int;
85
+ readonly byteEnd: Schema.Int;
86
+ readonly firstPage: Schema.NullOr<Schema.Int>;
87
+ readonly lastPage: Schema.NullOr<Schema.Int>;
88
+ }>>;
89
+ }>;
90
+ export declare const AssetChunkSchema: Schema.Struct<{
91
+ readonly ordinal: Schema.Int;
92
+ readonly content: Schema.NonEmptyString;
93
+ readonly headingPath: Schema.String;
94
+ readonly byteStart: Schema.Int;
95
+ readonly byteEnd: Schema.Int;
96
+ readonly firstPage: Schema.NullOr<Schema.Int>;
97
+ readonly lastPage: Schema.NullOr<Schema.Int>;
98
+ readonly id: Schema.String;
99
+ readonly processingId: Schema.String;
100
+ }>;
101
+ export declare const AssetOutlineEntrySchema: Schema.Struct<{
102
+ readonly headingPath: Schema.String;
103
+ readonly firstOrdinal: Schema.Int;
104
+ readonly lastOrdinal: Schema.Int;
105
+ }>;
106
+ export declare const AssetOverviewSchema: Schema.Struct<{
107
+ readonly id: Schema.String;
108
+ readonly name: Schema.String;
109
+ readonly mimeType: Schema.String;
110
+ readonly processingId: Schema.NullOr<Schema.String>;
111
+ readonly status: Schema.Literals<readonly ["pending", "running", "completed", "failed", "unsupported"]>;
112
+ readonly totalBytes: Schema.Int;
113
+ readonly totalChunks: Schema.Int;
114
+ readonly failure: Schema.NullOr<Schema.String>;
115
+ }>;
116
+ export declare const AssetOverviewResponseSchema: Schema.Struct<{
117
+ readonly id: Schema.String;
118
+ readonly name: Schema.String;
119
+ readonly mimeType: Schema.String;
120
+ readonly processingId: Schema.NullOr<Schema.String>;
121
+ readonly status: Schema.Literals<readonly ["pending", "running", "completed", "failed", "unsupported"]>;
122
+ readonly totalBytes: Schema.Int;
123
+ readonly totalChunks: Schema.Int;
124
+ readonly failure: Schema.NullOr<Schema.String>;
125
+ readonly outline: Schema.$Array<Schema.Struct<{
126
+ readonly headingPath: Schema.String;
127
+ readonly firstOrdinal: Schema.Int;
128
+ readonly lastOrdinal: Schema.Int;
129
+ }>>;
130
+ readonly nextOutlineOffset: Schema.NullOr<Schema.Int>;
131
+ }>;
132
+ export declare const AssetOverviewRequestSchema: Schema.Struct<{
133
+ readonly organizationId: Schema.String;
134
+ readonly assetId: Schema.String;
135
+ readonly outlineOffset: Schema.optional<Schema.Int>;
136
+ }>;
137
+ export declare const AssetSearchRequestSchema: Schema.Struct<{
138
+ readonly assetId: Schema.String;
139
+ readonly processingId: Schema.String;
140
+ readonly query: Schema.NonEmptyString;
141
+ readonly language: Schema.Literals<readonly ["en", "fr"]>;
142
+ readonly offset: Schema.optional<Schema.Int>;
143
+ readonly headingPath: Schema.optional<Schema.String>;
144
+ }>;
145
+ export declare const AssetScopedSearchRequestSchema: Schema.Struct<{
146
+ readonly assetId: Schema.String;
147
+ readonly processingId: Schema.String;
148
+ readonly query: Schema.NonEmptyString;
149
+ readonly language: Schema.Literals<readonly ["en", "fr"]>;
150
+ readonly offset: Schema.optional<Schema.Int>;
151
+ readonly headingPath: Schema.optional<Schema.String>;
152
+ readonly organizationId: Schema.String;
153
+ }>;
154
+ export declare const AssetSearchHitSchema: Schema.Struct<{
155
+ readonly id: Schema.String;
156
+ readonly processingId: Schema.String;
157
+ readonly ordinal: Schema.Int;
158
+ readonly headingPath: Schema.String;
159
+ readonly byteStart: Schema.Int;
160
+ readonly byteEnd: Schema.Int;
161
+ readonly firstPage: Schema.NullOr<Schema.Int>;
162
+ readonly lastPage: Schema.NullOr<Schema.Int>;
163
+ readonly snippet: Schema.String;
164
+ readonly score: Schema.Number;
165
+ }>;
166
+ export declare const AssetSearchResponseSchema: Schema.Struct<{
167
+ readonly assetId: Schema.String;
168
+ readonly processingId: Schema.String;
169
+ readonly hits: Schema.$Array<Schema.Struct<{
170
+ readonly id: Schema.String;
171
+ readonly processingId: Schema.String;
172
+ readonly ordinal: Schema.Int;
173
+ readonly headingPath: Schema.String;
174
+ readonly byteStart: Schema.Int;
175
+ readonly byteEnd: Schema.Int;
176
+ readonly firstPage: Schema.NullOr<Schema.Int>;
177
+ readonly lastPage: Schema.NullOr<Schema.Int>;
178
+ readonly snippet: Schema.String;
179
+ readonly score: Schema.Number;
180
+ }>>;
181
+ readonly nextOffset: Schema.NullOr<Schema.Int>;
182
+ }>;
183
+ export declare const AssetReadChunksRequestSchema: Schema.Struct<{
184
+ readonly assetId: Schema.String;
185
+ readonly processingId: Schema.String;
186
+ readonly ordinals: Schema.$Array<Schema.Int>;
187
+ readonly includeNeighbors: Schema.optional<Schema.Boolean>;
188
+ }>;
189
+ export declare const AssetScopedReadChunksRequestSchema: Schema.Struct<{
190
+ readonly assetId: Schema.String;
191
+ readonly processingId: Schema.String;
192
+ readonly ordinals: Schema.$Array<Schema.Int>;
193
+ readonly includeNeighbors: Schema.optional<Schema.Boolean>;
194
+ readonly organizationId: Schema.String;
195
+ }>;
196
+ export declare const AssetReadChunksResponseSchema: Schema.Struct<{
197
+ readonly assetId: Schema.String;
198
+ readonly processingId: Schema.String;
199
+ readonly chunks: Schema.$Array<Schema.Struct<{
200
+ readonly ordinal: Schema.Int;
201
+ readonly content: Schema.NonEmptyString;
202
+ readonly headingPath: Schema.String;
203
+ readonly byteStart: Schema.Int;
204
+ readonly byteEnd: Schema.Int;
205
+ readonly firstPage: Schema.NullOr<Schema.Int>;
206
+ readonly lastPage: Schema.NullOr<Schema.Int>;
207
+ readonly id: Schema.String;
208
+ readonly processingId: Schema.String;
209
+ }>>;
210
+ }>;
211
+ declare const AssetTextChunkInvalid_base: Schema.Class<AssetTextChunkInvalid, Schema.TaggedStruct<"AssetTextChunkInvalid", {
212
+ readonly message: Schema.String;
213
+ }>, import("effect/Cause").YieldableError>;
214
+ export declare class AssetTextChunkInvalid extends AssetTextChunkInvalid_base {
215
+ }
216
+ declare const AssetTextVersionChanged_base: Schema.Class<AssetTextVersionChanged, Schema.TaggedStruct<"AssetTextVersionChanged", {
217
+ readonly assetId: Schema.String;
218
+ }>, import("effect/Cause").YieldableError>;
219
+ export declare class AssetTextVersionChanged extends AssetTextVersionChanged_base {
220
+ }
67
221
  declare const AssetExtractionFailed_base: Schema.Class<AssetExtractionFailed, Schema.TaggedStruct<"AssetExtractionFailed", {
68
222
  readonly message: Schema.String;
69
223
  }>, import("effect/Cause").YieldableError>;
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,iCAAiC;;EAGY,CAAC;AAE3D,eAAO,MAAM,WAAW;;;;;;;;;;;EAWY,CAAC;AAErC,eAAO,MAAM,wBAAwB;;;;;;EAMY,CAAC;AAElD,eAAO,MAAM,iBAAiB;;;;EAIY,CAAC;AAE3C,eAAO,MAAM,kCAAkC;;;;;;;EAGY,CAAC;AAE5D,eAAO,MAAM,iBAAiB;;EAEY,CAAC;AAE3C,eAAO,MAAM,qBAAqB;;EAIY,CAAC;AAE/C,MAAM,MAAM,eAAe,GAAG,OAAO,qBAAqB,CAAC,IAAI,CAAC;AAChE,MAAM,MAAM,KAAK,GAAG,OAAO,WAAW,CAAC,IAAI,CAAC;AAE5C,eAAO,MAAM,uBAAuB;;;;;;EAWY,CAAC;AAEjD,eAAO,MAAM,mBAAmB;;EAEY,CAAC;AAE7C,eAAO,MAAM,eAAe;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MAAM,4BAA4B,GACtC,OAAO,kCAAkC,CAAC,IAAI,CAAC;AAEjD,eAAO,MAAM,cAAc;;;;;;;;;;;;EAGY,CAAC;AAExC,eAAO,MAAM,8BAA8B;;EAEY,CAAC;AAExD,eAAO,MAAM,kBAAkB;;;EAGY,CAAC;AAE5C,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;EAeY,CAAC;AAE/C,eAAO,MAAM,uBAAuB;;EAEY,CAAC"}
package/dist/schema.js CHANGED
@@ -62,6 +62,105 @@ export const AssetExtractedTextSchema = Schema.Struct({
62
62
  contentByteSize: Schema.Int,
63
63
  truncated: Schema.Boolean,
64
64
  }).annotate({ identifier: "AssetExtractedText" });
65
+ const NonNegativeInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
66
+ export const AssetExtractedChunkSchema = Schema.Struct({
67
+ ordinal: NonNegativeInt,
68
+ content: Schema.NonEmptyString.check(Schema.isMaxLength(16384)),
69
+ headingPath: Schema.String.check(Schema.isMaxLength(1000)),
70
+ byteStart: NonNegativeInt,
71
+ byteEnd: NonNegativeInt,
72
+ firstPage: Schema.NullOr(Schema.Int),
73
+ lastPage: Schema.NullOr(Schema.Int),
74
+ }).annotate({ identifier: "AssetExtractedChunk" });
75
+ export const AssetIndexedTextSchema = Schema.Struct({
76
+ ...AssetExtractedTextSchema.fields,
77
+ chunks: Schema.Array(AssetExtractedChunkSchema).check(Schema.isMinLength(1), Schema.isMaxLength(100000)),
78
+ }).annotate({ identifier: "AssetIndexedText" });
79
+ export const AssetChunkSchema = Schema.Struct({
80
+ ...AssetExtractedChunkSchema.fields,
81
+ id: Schema.String.check(Schema.isUUID()),
82
+ processingId: Schema.String.check(Schema.isUUID()),
83
+ }).annotate({ identifier: "AssetChunk" });
84
+ export const AssetOutlineEntrySchema = Schema.Struct({
85
+ headingPath: Schema.String,
86
+ firstOrdinal: NonNegativeInt,
87
+ lastOrdinal: NonNegativeInt,
88
+ }).annotate({ identifier: "AssetOutlineEntry" });
89
+ export const AssetOverviewSchema = Schema.Struct({
90
+ id: Schema.String.check(Schema.isUUID()),
91
+ name: Schema.String,
92
+ mimeType: Schema.String,
93
+ processingId: Schema.NullOr(Schema.String.check(Schema.isUUID())),
94
+ status: Schema.Literals([
95
+ "pending",
96
+ "running",
97
+ "completed",
98
+ "failed",
99
+ "unsupported",
100
+ ]),
101
+ totalBytes: NonNegativeInt,
102
+ totalChunks: NonNegativeInt,
103
+ failure: Schema.NullOr(Schema.String),
104
+ }).annotate({ identifier: "AssetOverview" });
105
+ export const AssetOverviewResponseSchema = Schema.Struct({
106
+ ...AssetOverviewSchema.fields,
107
+ outline: Schema.Array(AssetOutlineEntrySchema),
108
+ nextOutlineOffset: Schema.NullOr(NonNegativeInt),
109
+ }).annotate({ identifier: "AssetOverviewResponse" });
110
+ export const AssetOverviewRequestSchema = Schema.Struct({
111
+ organizationId: Schema.String,
112
+ assetId: Schema.String.check(Schema.isUUID()),
113
+ outlineOffset: Schema.optional(NonNegativeInt.check(Schema.isLessThanOrEqualTo(100000))),
114
+ }).annotate({ identifier: "AssetOverviewRequest" });
115
+ export const AssetSearchRequestSchema = Schema.Struct({
116
+ assetId: Schema.String.check(Schema.isUUID()),
117
+ processingId: Schema.String.check(Schema.isUUID()),
118
+ query: Schema.NonEmptyString.check(Schema.isMaxLength(500)),
119
+ language: Schema.Literals(["en", "fr"]),
120
+ offset: Schema.optional(NonNegativeInt.check(Schema.isLessThanOrEqualTo(100000))),
121
+ headingPath: Schema.optional(Schema.String.check(Schema.isMaxLength(1000))),
122
+ }).annotate({ identifier: "AssetSearchRequest" });
123
+ export const AssetScopedSearchRequestSchema = Schema.Struct({
124
+ ...AssetSearchRequestSchema.fields,
125
+ organizationId: Schema.String,
126
+ }).annotate({ identifier: "AssetScopedSearchRequest" });
127
+ export const AssetSearchHitSchema = Schema.Struct({
128
+ id: AssetChunkSchema.fields.id,
129
+ processingId: AssetChunkSchema.fields.processingId,
130
+ ordinal: AssetChunkSchema.fields.ordinal,
131
+ headingPath: AssetChunkSchema.fields.headingPath,
132
+ byteStart: AssetChunkSchema.fields.byteStart,
133
+ byteEnd: AssetChunkSchema.fields.byteEnd,
134
+ firstPage: AssetChunkSchema.fields.firstPage,
135
+ lastPage: AssetChunkSchema.fields.lastPage,
136
+ snippet: Schema.String,
137
+ score: Schema.Number,
138
+ }).annotate({ identifier: "AssetSearchHit" });
139
+ export const AssetSearchResponseSchema = Schema.Struct({
140
+ assetId: Schema.String.check(Schema.isUUID()),
141
+ processingId: Schema.String.check(Schema.isUUID()),
142
+ hits: Schema.Array(AssetSearchHitSchema),
143
+ nextOffset: Schema.NullOr(NonNegativeInt),
144
+ }).annotate({ identifier: "AssetSearchResponse" });
145
+ export const AssetReadChunksRequestSchema = Schema.Struct({
146
+ assetId: Schema.String.check(Schema.isUUID()),
147
+ processingId: Schema.String.check(Schema.isUUID()),
148
+ ordinals: Schema.Array(NonNegativeInt.check(Schema.isLessThanOrEqualTo(100000))).check(Schema.isMinLength(1), Schema.isMaxLength(4)),
149
+ includeNeighbors: Schema.optional(Schema.Boolean),
150
+ }).annotate({ identifier: "AssetReadChunksRequest" });
151
+ export const AssetScopedReadChunksRequestSchema = Schema.Struct({
152
+ ...AssetReadChunksRequestSchema.fields,
153
+ organizationId: Schema.String,
154
+ }).annotate({ identifier: "AssetScopedReadChunksRequest" });
155
+ export const AssetReadChunksResponseSchema = Schema.Struct({
156
+ assetId: Schema.String.check(Schema.isUUID()),
157
+ processingId: Schema.String.check(Schema.isUUID()),
158
+ chunks: Schema.Array(AssetChunkSchema),
159
+ }).annotate({ identifier: "AssetReadChunksResponse" });
160
+ export class AssetTextChunkInvalid extends Schema.TaggedError()("AssetTextChunkInvalid", { message: Schema.String }, { httpApiStatus: 400 }) {
161
+ }
162
+ export class AssetTextVersionChanged extends Schema.TaggedError()("AssetTextVersionChanged", { assetId: Schema.String }, { httpApiStatus: 409 }) {
163
+ }
65
164
  export class AssetExtractionFailed extends Schema.TaggedError()("AssetExtractionFailed", { message: Schema.String }) {
66
165
  }
67
166
  export const AssetStatsSchema = Schema.Struct({