@anvia/core 1.0.0-rc.1 → 1.0.0-rc.3
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/README.md +344 -85
- package/dist/agent/index.d.ts +33 -18
- package/dist/agent/index.js +42 -17
- package/dist/agent-CXScUOpX.d.ts +150 -0
- package/dist/{chunk-R2LJSQUW.js → chunk-3CMWKK32.js} +260 -104
- package/dist/chunk-3CMWKK32.js.map +1 -0
- package/dist/chunk-3RM57ZT2.js +31 -0
- package/dist/chunk-3RM57ZT2.js.map +1 -0
- package/dist/chunk-5MK3BISB.js +704 -0
- package/dist/chunk-5MK3BISB.js.map +1 -0
- package/dist/chunk-AI5JMUW7.js +45 -0
- package/dist/chunk-AI5JMUW7.js.map +1 -0
- package/dist/{chunk-FNQB2JEH.js → chunk-AZB6N7P4.js} +94 -65
- package/dist/chunk-AZB6N7P4.js.map +1 -0
- package/dist/chunk-BEYBU7VJ.js +53 -0
- package/dist/chunk-BEYBU7VJ.js.map +1 -0
- package/dist/chunk-BY4OMNIU.js +4699 -0
- package/dist/chunk-BY4OMNIU.js.map +1 -0
- package/dist/chunk-D2ECOWN5.js +515 -0
- package/dist/chunk-D2ECOWN5.js.map +1 -0
- package/dist/{chunk-A3UBYTJT.js → chunk-FN7HLLAZ.js} +60 -6
- package/dist/chunk-FN7HLLAZ.js.map +1 -0
- package/dist/chunk-GKDERULJ.js +50 -0
- package/dist/chunk-GKDERULJ.js.map +1 -0
- package/dist/chunk-GQL5KRAH.js +331 -0
- package/dist/chunk-GQL5KRAH.js.map +1 -0
- package/dist/{chunk-5XKDW36Z.js → chunk-KFR4CDGK.js} +70 -75
- package/dist/chunk-KFR4CDGK.js.map +1 -0
- package/dist/chunk-KV6QCRQ4.js +171 -0
- package/dist/chunk-KV6QCRQ4.js.map +1 -0
- package/dist/{chunk-DMPUP4R3.js → chunk-LXMAFD23.js} +5 -5
- package/dist/{chunk-I6G7BC42.js → chunk-MGNTXGTX.js} +2 -6
- package/dist/chunk-MGNTXGTX.js.map +1 -0
- package/dist/chunk-PK5LKOFL.js +239 -0
- package/dist/chunk-PK5LKOFL.js.map +1 -0
- package/dist/chunk-QOUPWOGW.js +29 -0
- package/dist/chunk-QOUPWOGW.js.map +1 -0
- package/dist/chunk-TRQ3XRFD.js +54 -0
- package/dist/chunk-TRQ3XRFD.js.map +1 -0
- package/dist/chunk-VKYZZXP5.js +323 -0
- package/dist/chunk-VKYZZXP5.js.map +1 -0
- package/dist/chunk-ZCPOIDAQ.js +127 -0
- package/dist/chunk-ZCPOIDAQ.js.map +1 -0
- package/dist/client-DvUatElp.d.ts +84 -0
- package/dist/completion/index.d.ts +5 -4
- package/dist/completion/index.js +25 -28
- package/dist/documents/index.d.ts +34 -0
- package/dist/documents/index.js +315 -0
- package/dist/documents/index.js.map +1 -0
- package/dist/{dynamic-tools-i9woysFa.d.ts → dynamic-tools-AEBOTgu1.d.ts} +21 -9
- package/dist/embeddings/index.d.ts +11 -9
- package/dist/embeddings/index.js +3 -3
- package/dist/evals/index.d.ts +53 -25
- package/dist/evals/index.js +153 -103
- package/dist/evals/index.js.map +1 -1
- package/dist/extractor/index.d.ts +23 -26
- package/dist/extractor/index.js +7 -8
- package/dist/guardrails/index.d.ts +7 -129
- package/dist/guardrails/index.js +1 -1
- package/dist/image-generation/index.d.ts +18 -16
- package/dist/image-generation/index.js +2 -2
- package/dist/index.d.ts +26 -23
- package/dist/index.js +71 -48
- package/dist/interactions-csssHYcN.d.ts +174 -0
- package/dist/internal/agent.d.ts +36 -29
- package/dist/internal/agent.js +48 -15
- package/dist/internal/agent.js.map +1 -1
- package/dist/mcp/index.d.ts +19 -13
- package/dist/mcp/index.js +14 -348
- package/dist/mcp/index.js.map +1 -1
- package/dist/memory/index.d.ts +20 -6
- package/dist/memory/index.js +10 -10
- package/dist/message-schema-B2M7AYzR.d.ts +52 -0
- package/dist/model-call-options-CZkSw_xN.d.ts +6 -0
- package/dist/model-listing/index.d.ts +3 -1
- package/dist/observability/index.d.ts +21 -6
- package/dist/observability/index.js +8 -5
- package/dist/observability/index.js.map +1 -1
- package/dist/pipeline/index.d.ts +106 -57
- package/dist/pipeline/index.js +419 -236
- package/dist/pipeline/index.js.map +1 -1
- package/dist/{retry-D3Ruy-ba.d.ts → retry-CjvSlKGW.d.ts} +2 -1
- package/dist/skills/index.d.ts +5 -4
- package/dist/skills/index.js +8 -7
- package/dist/speech-generation/index.d.ts +37 -0
- package/dist/speech-generation/index.js +8 -0
- package/dist/text-C_6eKrbC.d.ts +32 -0
- package/dist/{think-tool-DZqZj2LV.d.ts → think-tool-D8frXxwV.d.ts} +16 -2
- package/dist/tool/index.d.ts +9 -7
- package/dist/tool/index.js +12 -10
- package/dist/{tool-C_8GudXn.d.ts → tool-r62gf3QY.d.ts} +17 -8
- package/dist/transcription/index.d.ts +23 -14
- package/dist/transcription/index.js +2 -2
- package/dist/types-C3gv9EX6.d.ts +130 -0
- package/dist/{index-DxB74ybJ.d.ts → types-CElwurHZ.d.ts} +139 -88
- package/dist/types-CIPaIbZo.d.ts +105 -0
- package/dist/types-Cr4uiYo5.d.ts +99 -0
- package/dist/types-D9rKQ_as.d.ts +341 -0
- package/dist/types-DbolvLtZ.d.ts +155 -0
- package/dist/{types-DhQfwiZn.d.ts → types-RT3cuyRk.d.ts} +1 -1
- package/dist/vector-store/index.d.ts +33 -34
- package/dist/vector-store/index.js +7 -6
- package/package.json +10 -14
- package/dist/agent-DGYY_onS.d.ts +0 -145
- package/dist/audio-generation/index.d.ts +0 -31
- package/dist/audio-generation/index.js +0 -8
- package/dist/chunk-5XKDW36Z.js.map +0 -1
- package/dist/chunk-6WGGTJE6.js +0 -139
- package/dist/chunk-6WGGTJE6.js.map +0 -1
- package/dist/chunk-A3UBYTJT.js.map +0 -1
- package/dist/chunk-ADH7NNCS.js +0 -512
- package/dist/chunk-ADH7NNCS.js.map +0 -1
- package/dist/chunk-DZ3CKYTH.js +0 -267
- package/dist/chunk-DZ3CKYTH.js.map +0 -1
- package/dist/chunk-FNQB2JEH.js.map +0 -1
- package/dist/chunk-I6G7BC42.js.map +0 -1
- package/dist/chunk-IL3ZSNJI.js +0 -3748
- package/dist/chunk-IL3ZSNJI.js.map +0 -1
- package/dist/chunk-J6GNQART.js +0 -122
- package/dist/chunk-J6GNQART.js.map +0 -1
- package/dist/chunk-M3IOWB4Y.js +0 -280
- package/dist/chunk-M3IOWB4Y.js.map +0 -1
- package/dist/chunk-QY5GZ7HR.js +0 -39
- package/dist/chunk-QY5GZ7HR.js.map +0 -1
- package/dist/chunk-R2LJSQUW.js.map +0 -1
- package/dist/chunk-RFDVKCIE.js +0 -12
- package/dist/chunk-RFDVKCIE.js.map +0 -1
- package/dist/chunk-RMUBRRSK.js +0 -34
- package/dist/chunk-RMUBRRSK.js.map +0 -1
- package/dist/chunk-RXKHOYEH.js +0 -466
- package/dist/chunk-RXKHOYEH.js.map +0 -1
- package/dist/chunk-XDRSPSR7.js +0 -38
- package/dist/chunk-XDRSPSR7.js.map +0 -1
- package/dist/chunk-XWUC7CIT.js +0 -1
- package/dist/chunk-XWUC7CIT.js.map +0 -1
- package/dist/errors-CYKUcU89.d.ts +0 -17
- package/dist/json-Zo7K3xmt.d.ts +0 -40
- package/dist/loaders/index.d.ts +0 -86
- package/dist/loaders/index.js +0 -299
- package/dist/loaders/index.js.map +0 -1
- package/dist/middleware-KynLg_RW.d.ts +0 -56
- package/dist/types-B3A4YxaA.d.ts +0 -354
- package/dist/types-BBEGKB9m.d.ts +0 -119
- package/dist/types-DT3nEemY.d.ts +0 -79
- package/dist/types-DulRCYdB.d.ts +0 -70
- package/dist/types-p55Jc-sr.d.ts +0 -47
- package/dist/ui/index.d.ts +0 -107
- package/dist/ui/index.js +0 -10
- package/dist/ui/index.js.map +0 -1
- /package/dist/{chunk-DMPUP4R3.js.map → chunk-LXMAFD23.js.map} +0 -0
- /package/dist/{audio-generation → speech-generation}/index.js.map +0 -0
package/dist/loaders/index.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { D as Document } from '../types-B3A4YxaA.js';
|
|
2
|
-
|
|
3
|
-
type LoaderResult<T> = {
|
|
4
|
-
ok: true;
|
|
5
|
-
value: T;
|
|
6
|
-
} | {
|
|
7
|
-
ok: false;
|
|
8
|
-
error: unknown;
|
|
9
|
-
};
|
|
10
|
-
type LoaderValue<T> = T extends {
|
|
11
|
-
ok: true;
|
|
12
|
-
value: infer Value;
|
|
13
|
-
} ? Value : never;
|
|
14
|
-
type UnwrapLoaderResult<T> = [LoaderValue<T>] extends [never] ? T : LoaderValue<T>;
|
|
15
|
-
type FileSource = {
|
|
16
|
-
path: string;
|
|
17
|
-
} | {
|
|
18
|
-
path: "<memory>";
|
|
19
|
-
bytes: Uint8Array;
|
|
20
|
-
};
|
|
21
|
-
type FileReadWithPath = {
|
|
22
|
-
path: string;
|
|
23
|
-
text: string;
|
|
24
|
-
};
|
|
25
|
-
type FileMode = "source" | "read" | "readWithPath";
|
|
26
|
-
type PdfSource = {
|
|
27
|
-
path: string;
|
|
28
|
-
} | {
|
|
29
|
-
path: "<memory>";
|
|
30
|
-
bytes: Uint8Array;
|
|
31
|
-
};
|
|
32
|
-
type PdfReadWithPath = {
|
|
33
|
-
path: string;
|
|
34
|
-
text: string;
|
|
35
|
-
};
|
|
36
|
-
type PdfPage = {
|
|
37
|
-
pageNumber: number;
|
|
38
|
-
text: string;
|
|
39
|
-
};
|
|
40
|
-
type PdfPageWithPath = {
|
|
41
|
-
path: string;
|
|
42
|
-
pageNumber: number;
|
|
43
|
-
text: string;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
declare function fileToDocument(file: FileReadWithPath): Document;
|
|
47
|
-
declare function fileLoaderToDocuments(loader: AsyncIterable<FileReadWithPath>): Promise<Document[]>;
|
|
48
|
-
declare function pdfToDocument(pdf: PdfReadWithPath): Document;
|
|
49
|
-
declare function pdfLoaderToDocuments(loader: AsyncIterable<PdfReadWithPath>): Promise<Document[]>;
|
|
50
|
-
declare function pdfPageToDocument(page: PdfPageWithPath): Document;
|
|
51
|
-
declare function pdfPageLoaderToDocuments(loader: AsyncIterable<PdfPageWithPath>): Promise<Document[]>;
|
|
52
|
-
|
|
53
|
-
declare class FileLoader<T = LoaderResult<FileSource>> implements AsyncIterable<T> {
|
|
54
|
-
private readonly source;
|
|
55
|
-
private readonly mode;
|
|
56
|
-
private readonly skipErrors;
|
|
57
|
-
private constructor();
|
|
58
|
-
static withGlob(pattern: string): FileLoader<LoaderResult<FileSource>>;
|
|
59
|
-
static withDir(directory: string): FileLoader<LoaderResult<FileSource>>;
|
|
60
|
-
static fromBytes(bytes: Uint8Array | ArrayBuffer): FileLoader<LoaderResult<FileSource>>;
|
|
61
|
-
static fromBytesMany(bytes: Array<Uint8Array | ArrayBuffer>): FileLoader<LoaderResult<FileSource>>;
|
|
62
|
-
read(): FileLoader<LoaderResult<string>>;
|
|
63
|
-
readWithPath(): FileLoader<LoaderResult<FileReadWithPath>>;
|
|
64
|
-
ignoreErrors(): FileLoader<UnwrapLoaderResult<T>>;
|
|
65
|
-
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
declare class PdfFileLoader<T = LoaderResult<PdfSource>> implements AsyncIterable<T> {
|
|
69
|
-
private readonly source;
|
|
70
|
-
private readonly mode;
|
|
71
|
-
private readonly skipErrors;
|
|
72
|
-
private constructor();
|
|
73
|
-
static withGlob(pattern: string): PdfFileLoader<LoaderResult<PdfSource>>;
|
|
74
|
-
static withDir(directory: string): PdfFileLoader<LoaderResult<PdfSource>>;
|
|
75
|
-
static fromBytes(bytes: Uint8Array | ArrayBuffer): PdfFileLoader<LoaderResult<PdfSource>>;
|
|
76
|
-
static fromBytesMany(bytes: Array<Uint8Array | ArrayBuffer>): PdfFileLoader<LoaderResult<PdfSource>>;
|
|
77
|
-
read(): PdfFileLoader<LoaderResult<string>>;
|
|
78
|
-
readWithPath(): PdfFileLoader<LoaderResult<PdfReadWithPath>>;
|
|
79
|
-
byPage(this: PdfFileLoader<LoaderResult<PdfReadWithPath>>): PdfFileLoader<LoaderResult<PdfPageWithPath>>;
|
|
80
|
-
byPage(this: PdfFileLoader<PdfReadWithPath>): PdfFileLoader<PdfPageWithPath>;
|
|
81
|
-
byPage(): PdfFileLoader<LoaderResult<PdfPage>>;
|
|
82
|
-
ignoreErrors(): PdfFileLoader<UnwrapLoaderResult<T>>;
|
|
83
|
-
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export { FileLoader, type FileMode, type FileReadWithPath, type FileSource, type LoaderResult, type LoaderValue, PdfFileLoader, type PdfPage, type PdfPageWithPath, type PdfReadWithPath, type PdfSource, type UnwrapLoaderResult, fileLoaderToDocuments, fileToDocument, pdfLoaderToDocuments, pdfPageLoaderToDocuments, pdfPageToDocument, pdfToDocument };
|
package/dist/loaders/index.js
DELETED
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
// src/loaders/documents.ts
|
|
2
|
-
function fileToDocument(file) {
|
|
3
|
-
return {
|
|
4
|
-
id: file.path,
|
|
5
|
-
text: file.text,
|
|
6
|
-
additionalProps: {
|
|
7
|
-
source: file.path,
|
|
8
|
-
mediaType: "text/plain"
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
async function fileLoaderToDocuments(loader) {
|
|
13
|
-
const documents = [];
|
|
14
|
-
for await (const file of loader) {
|
|
15
|
-
documents.push(fileToDocument(file));
|
|
16
|
-
}
|
|
17
|
-
return documents;
|
|
18
|
-
}
|
|
19
|
-
function pdfToDocument(pdf) {
|
|
20
|
-
return {
|
|
21
|
-
id: pdf.path,
|
|
22
|
-
text: pdf.text,
|
|
23
|
-
additionalProps: {
|
|
24
|
-
source: pdf.path,
|
|
25
|
-
mediaType: "application/pdf"
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
async function pdfLoaderToDocuments(loader) {
|
|
30
|
-
const documents = [];
|
|
31
|
-
for await (const pdf of loader) {
|
|
32
|
-
documents.push(pdfToDocument(pdf));
|
|
33
|
-
}
|
|
34
|
-
return documents;
|
|
35
|
-
}
|
|
36
|
-
function pdfPageToDocument(page) {
|
|
37
|
-
return {
|
|
38
|
-
id: `${page.path}#page=${page.pageNumber}`,
|
|
39
|
-
text: page.text,
|
|
40
|
-
additionalProps: {
|
|
41
|
-
source: page.path,
|
|
42
|
-
mediaType: "application/pdf",
|
|
43
|
-
pageNumber: String(page.pageNumber)
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
async function pdfPageLoaderToDocuments(loader) {
|
|
48
|
-
const documents = [];
|
|
49
|
-
for await (const page of loader) {
|
|
50
|
-
documents.push(pdfPageToDocument(page));
|
|
51
|
-
}
|
|
52
|
-
return documents;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// src/loaders/file.ts
|
|
56
|
-
import { readdir, readFile } from "fs/promises";
|
|
57
|
-
import { join } from "path";
|
|
58
|
-
|
|
59
|
-
// src/loaders/shared.ts
|
|
60
|
-
import { isAbsolute } from "path";
|
|
61
|
-
import { glob } from "tinyglobby";
|
|
62
|
-
function ok(value) {
|
|
63
|
-
return { ok: true, value };
|
|
64
|
-
}
|
|
65
|
-
function err(error) {
|
|
66
|
-
return { ok: false, error };
|
|
67
|
-
}
|
|
68
|
-
async function sortedGlob(pattern) {
|
|
69
|
-
return (await glob(pattern, { absolute: isAbsolute(pattern), onlyFiles: true })).sort(
|
|
70
|
-
(left, right) => left.localeCompare(right)
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
function toUint8Array(bytes) {
|
|
74
|
-
if (bytes instanceof Uint8Array) {
|
|
75
|
-
return new Uint8Array(
|
|
76
|
-
bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength)
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
return new Uint8Array(bytes);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// src/loaders/file.ts
|
|
83
|
-
var FileLoader = class _FileLoader {
|
|
84
|
-
constructor(source, mode, skipErrors) {
|
|
85
|
-
this.source = source;
|
|
86
|
-
this.mode = mode;
|
|
87
|
-
this.skipErrors = skipErrors;
|
|
88
|
-
}
|
|
89
|
-
source;
|
|
90
|
-
mode;
|
|
91
|
-
skipErrors;
|
|
92
|
-
static withGlob(pattern) {
|
|
93
|
-
return new _FileLoader(
|
|
94
|
-
async function* () {
|
|
95
|
-
for (const path of await sortedGlob(pattern)) {
|
|
96
|
-
yield ok({ path });
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
"source",
|
|
100
|
-
false
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
static withDir(directory) {
|
|
104
|
-
return new _FileLoader(
|
|
105
|
-
async function* () {
|
|
106
|
-
const entries = await readdir(directory, { withFileTypes: true });
|
|
107
|
-
const files = entries.filter((entry) => entry.isFile()).map((entry) => join(directory, entry.name)).sort((left, right) => left.localeCompare(right));
|
|
108
|
-
for (const path of files) {
|
|
109
|
-
yield ok({ path });
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
"source",
|
|
113
|
-
false
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
static fromBytes(bytes) {
|
|
117
|
-
return _FileLoader.fromBytesMany([bytes]);
|
|
118
|
-
}
|
|
119
|
-
static fromBytesMany(bytes) {
|
|
120
|
-
return new _FileLoader(
|
|
121
|
-
async function* () {
|
|
122
|
-
for (const value of bytes) {
|
|
123
|
-
yield ok({ path: "<memory>", bytes: toUint8Array(value) });
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
"source",
|
|
127
|
-
false
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
read() {
|
|
131
|
-
return new _FileLoader(this.source, "read", this.skipErrors);
|
|
132
|
-
}
|
|
133
|
-
readWithPath() {
|
|
134
|
-
return new _FileLoader(this.source, "readWithPath", this.skipErrors);
|
|
135
|
-
}
|
|
136
|
-
ignoreErrors() {
|
|
137
|
-
return new _FileLoader(this.source, this.mode, true);
|
|
138
|
-
}
|
|
139
|
-
async *[Symbol.asyncIterator]() {
|
|
140
|
-
for await (const item of this.source()) {
|
|
141
|
-
const result = await mapFileResult(item, this.mode);
|
|
142
|
-
if (!result.ok && this.skipErrors) {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
yield this.skipErrors && result.ok ? result.value : result;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
async function mapFileResult(item, mode) {
|
|
150
|
-
if (!item.ok) {
|
|
151
|
-
return item;
|
|
152
|
-
}
|
|
153
|
-
if (mode === "source") {
|
|
154
|
-
return item;
|
|
155
|
-
}
|
|
156
|
-
try {
|
|
157
|
-
const text = await readFileSource(item.value);
|
|
158
|
-
return mode === "read" ? ok(text) : ok({ path: item.value.path, text });
|
|
159
|
-
} catch (error) {
|
|
160
|
-
return err(error);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
async function readFileSource(source) {
|
|
164
|
-
if ("bytes" in source) {
|
|
165
|
-
return new TextDecoder().decode(source.bytes);
|
|
166
|
-
}
|
|
167
|
-
return readFile(source.path, "utf8");
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// src/loaders/pdf.ts
|
|
171
|
-
import { readdir as readdir2, readFile as readFile2 } from "fs/promises";
|
|
172
|
-
import { join as join2 } from "path";
|
|
173
|
-
var PdfFileLoader = class _PdfFileLoader {
|
|
174
|
-
constructor(source, mode, skipErrors) {
|
|
175
|
-
this.source = source;
|
|
176
|
-
this.mode = mode;
|
|
177
|
-
this.skipErrors = skipErrors;
|
|
178
|
-
}
|
|
179
|
-
source;
|
|
180
|
-
mode;
|
|
181
|
-
skipErrors;
|
|
182
|
-
static withGlob(pattern) {
|
|
183
|
-
return new _PdfFileLoader(
|
|
184
|
-
async function* () {
|
|
185
|
-
for (const path of await sortedGlob(pattern)) {
|
|
186
|
-
yield ok({ path });
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
"source",
|
|
190
|
-
false
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
static withDir(directory) {
|
|
194
|
-
return new _PdfFileLoader(
|
|
195
|
-
async function* () {
|
|
196
|
-
const entries = await readdir2(directory, { withFileTypes: true });
|
|
197
|
-
const files = entries.filter((entry) => entry.isFile()).map((entry) => join2(directory, entry.name)).sort((left, right) => left.localeCompare(right));
|
|
198
|
-
for (const path of files) {
|
|
199
|
-
yield ok({ path });
|
|
200
|
-
}
|
|
201
|
-
},
|
|
202
|
-
"source",
|
|
203
|
-
false
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
static fromBytes(bytes) {
|
|
207
|
-
return _PdfFileLoader.fromBytesMany([bytes]);
|
|
208
|
-
}
|
|
209
|
-
static fromBytesMany(bytes) {
|
|
210
|
-
return new _PdfFileLoader(
|
|
211
|
-
async function* () {
|
|
212
|
-
for (const value of bytes) {
|
|
213
|
-
yield ok({ path: "<memory>", bytes: toUint8Array(value) });
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
"source",
|
|
217
|
-
false
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
read() {
|
|
221
|
-
return new _PdfFileLoader(this.source, "read", this.skipErrors);
|
|
222
|
-
}
|
|
223
|
-
readWithPath() {
|
|
224
|
-
return new _PdfFileLoader(this.source, "readWithPath", this.skipErrors);
|
|
225
|
-
}
|
|
226
|
-
byPage() {
|
|
227
|
-
const mode = this.mode === "readWithPath" ? "byPageWithPath" : "byPage";
|
|
228
|
-
return new _PdfFileLoader(this.source, mode, this.skipErrors);
|
|
229
|
-
}
|
|
230
|
-
ignoreErrors() {
|
|
231
|
-
return new _PdfFileLoader(this.source, this.mode, true);
|
|
232
|
-
}
|
|
233
|
-
async *[Symbol.asyncIterator]() {
|
|
234
|
-
for await (const item of this.source()) {
|
|
235
|
-
const results = await mapPdfResult(item, this.mode);
|
|
236
|
-
for (const result of results) {
|
|
237
|
-
if (!result.ok && this.skipErrors) {
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
yield this.skipErrors && result.ok ? result.value : result;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
async function mapPdfResult(item, mode) {
|
|
246
|
-
if (!item.ok) {
|
|
247
|
-
return [item];
|
|
248
|
-
}
|
|
249
|
-
if (mode === "source") {
|
|
250
|
-
return [item];
|
|
251
|
-
}
|
|
252
|
-
try {
|
|
253
|
-
const pages = await readPdfPages(item.value);
|
|
254
|
-
if (mode === "read") {
|
|
255
|
-
return [ok(pages.map((page) => page.text).join(""))];
|
|
256
|
-
}
|
|
257
|
-
if (mode === "readWithPath") {
|
|
258
|
-
return [ok({ path: item.value.path, text: pages.map((page) => page.text).join("") })];
|
|
259
|
-
}
|
|
260
|
-
if (mode === "byPageWithPath") {
|
|
261
|
-
return pages.map((page) => ok({ path: item.value.path, ...page }));
|
|
262
|
-
}
|
|
263
|
-
return pages.map(ok);
|
|
264
|
-
} catch (error) {
|
|
265
|
-
return [err(error)];
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
async function readPdfPages(source) {
|
|
269
|
-
const pdfjs = await import("pdfjs-dist/legacy/build/pdf.mjs");
|
|
270
|
-
const bytes = "bytes" in source ? source.bytes : toUint8Array(await readFile2(source.path));
|
|
271
|
-
const loadingTask = pdfjs.getDocument({ data: bytes });
|
|
272
|
-
const document = await loadingTask.promise;
|
|
273
|
-
const pages = [];
|
|
274
|
-
try {
|
|
275
|
-
for (let index = 1; index <= document.numPages; index += 1) {
|
|
276
|
-
const page = await document.getPage(index);
|
|
277
|
-
const content = await page.getTextContent();
|
|
278
|
-
const text = content.items.flatMap(
|
|
279
|
-
(item) => typeof item === "object" && item !== null && "str" in item ? [String(item.str)] : []
|
|
280
|
-
).join("\n");
|
|
281
|
-
pages.push({ pageNumber: index - 1, text: text.length > 0 ? `${text}
|
|
282
|
-
` : "" });
|
|
283
|
-
}
|
|
284
|
-
} finally {
|
|
285
|
-
await loadingTask.destroy();
|
|
286
|
-
}
|
|
287
|
-
return pages;
|
|
288
|
-
}
|
|
289
|
-
export {
|
|
290
|
-
FileLoader,
|
|
291
|
-
PdfFileLoader,
|
|
292
|
-
fileLoaderToDocuments,
|
|
293
|
-
fileToDocument,
|
|
294
|
-
pdfLoaderToDocuments,
|
|
295
|
-
pdfPageLoaderToDocuments,
|
|
296
|
-
pdfPageToDocument,
|
|
297
|
-
pdfToDocument
|
|
298
|
-
};
|
|
299
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/loaders/documents.ts","../../src/loaders/file.ts","../../src/loaders/shared.ts","../../src/loaders/pdf.ts"],"sourcesContent":["import type { Document } from \"../completion\";\nimport type { FileReadWithPath, PdfPageWithPath, PdfReadWithPath } from \"./types\";\n\nexport function fileToDocument(file: FileReadWithPath): Document {\n return {\n id: file.path,\n text: file.text,\n additionalProps: {\n source: file.path,\n mediaType: \"text/plain\",\n },\n };\n}\n\nexport async function fileLoaderToDocuments(\n loader: AsyncIterable<FileReadWithPath>,\n): Promise<Document[]> {\n const documents: Document[] = [];\n for await (const file of loader) {\n documents.push(fileToDocument(file));\n }\n return documents;\n}\n\nexport function pdfToDocument(pdf: PdfReadWithPath): Document {\n return {\n id: pdf.path,\n text: pdf.text,\n additionalProps: {\n source: pdf.path,\n mediaType: \"application/pdf\",\n },\n };\n}\n\nexport async function pdfLoaderToDocuments(\n loader: AsyncIterable<PdfReadWithPath>,\n): Promise<Document[]> {\n const documents: Document[] = [];\n for await (const pdf of loader) {\n documents.push(pdfToDocument(pdf));\n }\n return documents;\n}\n\nexport function pdfPageToDocument(page: PdfPageWithPath): Document {\n return {\n id: `${page.path}#page=${page.pageNumber}`,\n text: page.text,\n additionalProps: {\n source: page.path,\n mediaType: \"application/pdf\",\n pageNumber: String(page.pageNumber),\n },\n };\n}\n\nexport async function pdfPageLoaderToDocuments(\n loader: AsyncIterable<PdfPageWithPath>,\n): Promise<Document[]> {\n const documents: Document[] = [];\n for await (const page of loader) {\n documents.push(pdfPageToDocument(page));\n }\n return documents;\n}\n","import { readdir, readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { err, ok, sortedGlob, toUint8Array } from \"./shared\";\nimport type {\n FileMode,\n FileReadWithPath,\n FileSource,\n LoaderResult,\n UnwrapLoaderResult,\n} from \"./types\";\n\nexport class FileLoader<T = LoaderResult<FileSource>> implements AsyncIterable<T> {\n private constructor(\n private readonly source: () => AsyncIterable<LoaderResult<FileSource>>,\n private readonly mode: FileMode,\n private readonly skipErrors: boolean,\n ) {}\n\n static withGlob(pattern: string): FileLoader<LoaderResult<FileSource>> {\n return new FileLoader(\n async function* () {\n for (const path of await sortedGlob(pattern)) {\n yield ok({ path });\n }\n },\n \"source\",\n false,\n );\n }\n\n static withDir(directory: string): FileLoader<LoaderResult<FileSource>> {\n return new FileLoader(\n async function* () {\n const entries = await readdir(directory, { withFileTypes: true });\n const files = entries\n .filter((entry) => entry.isFile())\n .map((entry) => join(directory, entry.name))\n .sort((left, right) => left.localeCompare(right));\n for (const path of files) {\n yield ok({ path });\n }\n },\n \"source\",\n false,\n );\n }\n\n static fromBytes(bytes: Uint8Array | ArrayBuffer): FileLoader<LoaderResult<FileSource>> {\n return FileLoader.fromBytesMany([bytes]);\n }\n\n static fromBytesMany(\n bytes: Array<Uint8Array | ArrayBuffer>,\n ): FileLoader<LoaderResult<FileSource>> {\n return new FileLoader(\n async function* () {\n for (const value of bytes) {\n yield ok({ path: \"<memory>\", bytes: toUint8Array(value) });\n }\n },\n \"source\",\n false,\n );\n }\n\n read(): FileLoader<LoaderResult<string>> {\n return new FileLoader(this.source, \"read\", this.skipErrors);\n }\n\n readWithPath(): FileLoader<LoaderResult<FileReadWithPath>> {\n return new FileLoader(this.source, \"readWithPath\", this.skipErrors);\n }\n\n ignoreErrors(): FileLoader<UnwrapLoaderResult<T>> {\n return new FileLoader(this.source, this.mode, true) as FileLoader<UnwrapLoaderResult<T>>;\n }\n\n async *[Symbol.asyncIterator](): AsyncIterator<T> {\n for await (const item of this.source()) {\n const result = await mapFileResult(item, this.mode);\n if (!result.ok && this.skipErrors) {\n continue;\n }\n yield (this.skipErrors && result.ok ? result.value : result) as T;\n }\n }\n}\n\nasync function mapFileResult(\n item: LoaderResult<FileSource>,\n mode: FileMode,\n): Promise<LoaderResult<FileSource | string | FileReadWithPath>> {\n if (!item.ok) {\n return item;\n }\n if (mode === \"source\") {\n return item;\n }\n try {\n const text = await readFileSource(item.value);\n return mode === \"read\" ? ok(text) : ok({ path: item.value.path, text });\n } catch (error) {\n return err(error);\n }\n}\n\nasync function readFileSource(source: FileSource): Promise<string> {\n if (\"bytes\" in source) {\n return new TextDecoder().decode(source.bytes);\n }\n return readFile(source.path, \"utf8\");\n}\n","import { isAbsolute } from \"node:path\";\nimport { glob } from \"tinyglobby\";\nimport type { LoaderResult } from \"./types\";\n\nexport function ok<T>(value: T): LoaderResult<T> {\n return { ok: true, value };\n}\n\nexport function err(error: unknown): LoaderResult<never> {\n return { ok: false, error };\n}\n\nexport async function sortedGlob(pattern: string): Promise<string[]> {\n return (await glob(pattern, { absolute: isAbsolute(pattern), onlyFiles: true })).sort(\n (left, right) => left.localeCompare(right),\n );\n}\n\nexport function toUint8Array(bytes: Uint8Array | ArrayBuffer): Uint8Array {\n if (bytes instanceof Uint8Array) {\n return new Uint8Array(\n bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength),\n );\n }\n return new Uint8Array(bytes);\n}\n","import { readdir, readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { err, ok, sortedGlob, toUint8Array } from \"./shared\";\nimport type {\n LoaderResult,\n PdfPage,\n PdfPageWithPath,\n PdfReadWithPath,\n PdfSource,\n UnwrapLoaderResult,\n} from \"./types\";\n\ntype PdfMode = \"source\" | \"read\" | \"readWithPath\" | \"byPage\" | \"byPageWithPath\";\n\nexport class PdfFileLoader<T = LoaderResult<PdfSource>> implements AsyncIterable<T> {\n private constructor(\n private readonly source: () => AsyncIterable<LoaderResult<PdfSource>>,\n private readonly mode: PdfMode,\n private readonly skipErrors: boolean,\n ) {}\n\n static withGlob(pattern: string): PdfFileLoader<LoaderResult<PdfSource>> {\n return new PdfFileLoader(\n async function* () {\n for (const path of await sortedGlob(pattern)) {\n yield ok({ path });\n }\n },\n \"source\",\n false,\n );\n }\n\n static withDir(directory: string): PdfFileLoader<LoaderResult<PdfSource>> {\n return new PdfFileLoader(\n async function* () {\n const entries = await readdir(directory, { withFileTypes: true });\n const files = entries\n .filter((entry) => entry.isFile())\n .map((entry) => join(directory, entry.name))\n .sort((left, right) => left.localeCompare(right));\n for (const path of files) {\n yield ok({ path });\n }\n },\n \"source\",\n false,\n );\n }\n\n static fromBytes(bytes: Uint8Array | ArrayBuffer): PdfFileLoader<LoaderResult<PdfSource>> {\n return PdfFileLoader.fromBytesMany([bytes]);\n }\n\n static fromBytesMany(\n bytes: Array<Uint8Array | ArrayBuffer>,\n ): PdfFileLoader<LoaderResult<PdfSource>> {\n return new PdfFileLoader(\n async function* () {\n for (const value of bytes) {\n yield ok({ path: \"<memory>\", bytes: toUint8Array(value) });\n }\n },\n \"source\",\n false,\n );\n }\n\n read(): PdfFileLoader<LoaderResult<string>> {\n return new PdfFileLoader(this.source, \"read\", this.skipErrors);\n }\n\n readWithPath(): PdfFileLoader<LoaderResult<PdfReadWithPath>> {\n return new PdfFileLoader(this.source, \"readWithPath\", this.skipErrors);\n }\n\n byPage(\n this: PdfFileLoader<LoaderResult<PdfReadWithPath>>,\n ): PdfFileLoader<LoaderResult<PdfPageWithPath>>;\n byPage(this: PdfFileLoader<PdfReadWithPath>): PdfFileLoader<PdfPageWithPath>;\n byPage(): PdfFileLoader<LoaderResult<PdfPage>>;\n byPage(): PdfFileLoader<LoaderResult<PdfPage> | LoaderResult<PdfPageWithPath> | PdfPageWithPath> {\n const mode = this.mode === \"readWithPath\" ? \"byPageWithPath\" : \"byPage\";\n return new PdfFileLoader(this.source, mode, this.skipErrors);\n }\n\n ignoreErrors(): PdfFileLoader<UnwrapLoaderResult<T>> {\n return new PdfFileLoader(this.source, this.mode, true) as PdfFileLoader<UnwrapLoaderResult<T>>;\n }\n\n async *[Symbol.asyncIterator](): AsyncIterator<T> {\n for await (const item of this.source()) {\n const results = await mapPdfResult(item, this.mode);\n for (const result of results) {\n if (!result.ok && this.skipErrors) {\n continue;\n }\n yield (this.skipErrors && result.ok ? result.value : result) as T;\n }\n }\n }\n}\n\nasync function mapPdfResult(\n item: LoaderResult<PdfSource>,\n mode: PdfMode,\n): Promise<Array<LoaderResult<PdfSource | string | PdfReadWithPath | PdfPage | PdfPageWithPath>>> {\n if (!item.ok) {\n return [item];\n }\n if (mode === \"source\") {\n return [item];\n }\n try {\n const pages = await readPdfPages(item.value);\n if (mode === \"read\") {\n return [ok(pages.map((page) => page.text).join(\"\"))];\n }\n if (mode === \"readWithPath\") {\n return [ok({ path: item.value.path, text: pages.map((page) => page.text).join(\"\") })];\n }\n if (mode === \"byPageWithPath\") {\n return pages.map((page) => ok({ path: item.value.path, ...page }));\n }\n return pages.map(ok);\n } catch (error) {\n return [err(error)];\n }\n}\n\nasync function readPdfPages(source: PdfSource): Promise<PdfPage[]> {\n const pdfjs = await import(\"pdfjs-dist/legacy/build/pdf.mjs\");\n const bytes = \"bytes\" in source ? source.bytes : toUint8Array(await readFile(source.path));\n const loadingTask = pdfjs.getDocument({ data: bytes });\n const document = await loadingTask.promise;\n const pages: PdfPage[] = [];\n try {\n for (let index = 1; index <= document.numPages; index += 1) {\n const page = await document.getPage(index);\n const content = await page.getTextContent();\n const text = content.items\n .flatMap((item) =>\n typeof item === \"object\" && item !== null && \"str\" in item ? [String(item.str)] : [],\n )\n .join(\"\\n\");\n pages.push({ pageNumber: index - 1, text: text.length > 0 ? `${text}\\n` : \"\" });\n }\n } finally {\n await loadingTask.destroy();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B,aAAO,MAAM,IAAI,CAAC,SAAS,GAAG,EAAE,MAAM,KAAK,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC;AAAA,IACnE;AACA,WAAO,MAAM,IAAI,EAAE;AAAA,EACrB,SAAS,OAAO;AACd,WAAO,CAAC,IAAI,KAAK,CAAC;AAAA,EACpB;AACF;AAEA,eAAe,aAAa,QAAuC;AACjE,QAAM,QAAQ,MAAM,OAAO,iCAAiC;AAC5D,QAAM,QAAQ,WAAW,SAAS,OAAO,QAAQ,aAAa,MAAMC,UAAS,OAAO,IAAI,CAAC;AACzF,QAAM,cAAc,MAAM,YAAY,EAAE,MAAM,MAAM,CAAC;AACrD,QAAM,WAAW,MAAM,YAAY;AACnC,QAAM,QAAmB,CAAC;AAC1B,MAAI;AACF,aAAS,QAAQ,GAAG,SAAS,SAAS,UAAU,SAAS,GAAG;AAC1D,YAAM,OAAO,MAAM,SAAS,QAAQ,KAAK;AACzC,YAAM,UAAU,MAAM,KAAK,eAAe;AAC1C,YAAM,OAAO,QAAQ,MAClB;AAAA,QAAQ,CAAC,SACR,OAAO,SAAS,YAAY,SAAS,QAAQ,SAAS,OAAO,CAAC,OAAO,KAAK,GAAG,CAAC,IAAI,CAAC;AAAA,MACrF,EACC,KAAK,IAAI;AACZ,YAAM,KAAK,EAAE,YAAY,QAAQ,GAAG,MAAM,KAAK,SAAS,IAAI,GAAG,IAAI;AAAA,IAAO,GAAG,CAAC;AAAA,IAChF;AAAA,EACF,UAAE;AACA,UAAM,YAAY,QAAQ;AAAA,EAC5B;AACA,SAAO;AACT;","names":["readdir","readFile","join","readdir","join","readFile"]}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { f as CompletionRequest, g as CompletionResponse, l as JsonValue, u as ToolResultContent } from './types-B3A4YxaA.js';
|
|
2
|
-
import { M as MaybePromise } from './type-utils-CtHVDRn_.js';
|
|
3
|
-
|
|
4
|
-
type CompletionRequestMiddlewareArgs = {
|
|
5
|
-
turn: number;
|
|
6
|
-
request: CompletionRequest;
|
|
7
|
-
originalRequest: CompletionRequest;
|
|
8
|
-
};
|
|
9
|
-
type CompletionRequestMiddlewareResult = {
|
|
10
|
-
request: CompletionRequest;
|
|
11
|
-
} | undefined;
|
|
12
|
-
type CompletionResponseMiddlewareArgs<RawResponse = unknown> = {
|
|
13
|
-
turn: number;
|
|
14
|
-
request: CompletionRequest;
|
|
15
|
-
response: CompletionResponse<RawResponse>;
|
|
16
|
-
originalResponse: CompletionResponse<RawResponse>;
|
|
17
|
-
};
|
|
18
|
-
type CompletionResponseMiddlewareResult<RawResponse = unknown> = {
|
|
19
|
-
response: CompletionResponse<RawResponse>;
|
|
20
|
-
} | undefined;
|
|
21
|
-
type ToolInputMiddlewareArgs = {
|
|
22
|
-
toolName: string;
|
|
23
|
-
args: string;
|
|
24
|
-
originalArgs: string;
|
|
25
|
-
turn: number;
|
|
26
|
-
toolCallId?: string | undefined;
|
|
27
|
-
internalCallId: string;
|
|
28
|
-
};
|
|
29
|
-
type ToolInputMiddlewareResult = {
|
|
30
|
-
args: JsonValue | string;
|
|
31
|
-
} | undefined;
|
|
32
|
-
type ToolResultMiddlewareArgs = {
|
|
33
|
-
toolName: string;
|
|
34
|
-
args: string;
|
|
35
|
-
result: string;
|
|
36
|
-
originalResult: string;
|
|
37
|
-
structuredResult?: ToolResultContent[] | undefined;
|
|
38
|
-
originalStructuredResult?: ToolResultContent[] | undefined;
|
|
39
|
-
turn: number;
|
|
40
|
-
toolCallId?: string | undefined;
|
|
41
|
-
internalCallId: string;
|
|
42
|
-
};
|
|
43
|
-
type ToolOutputMiddlewareArgs = ToolResultMiddlewareArgs;
|
|
44
|
-
type ToolOutputMiddlewareResult = string | {
|
|
45
|
-
result?: string | undefined;
|
|
46
|
-
structuredResult?: ToolResultContent[] | undefined;
|
|
47
|
-
} | undefined;
|
|
48
|
-
interface AgentMiddleware<RawResponse = unknown> {
|
|
49
|
-
onCompletionRequest?(args: CompletionRequestMiddlewareArgs): MaybePromise<CompletionRequestMiddlewareResult>;
|
|
50
|
-
onCompletionResponse?(args: CompletionResponseMiddlewareArgs<RawResponse>): MaybePromise<CompletionResponseMiddlewareResult<RawResponse>>;
|
|
51
|
-
onToolInput?(args: ToolInputMiddlewareArgs): MaybePromise<ToolInputMiddlewareResult>;
|
|
52
|
-
onToolOutput?(args: ToolOutputMiddlewareArgs): MaybePromise<ToolOutputMiddlewareResult>;
|
|
53
|
-
}
|
|
54
|
-
declare function createMiddleware<RawResponse = unknown>(middleware: AgentMiddleware<RawResponse>): AgentMiddleware<RawResponse>;
|
|
55
|
-
|
|
56
|
-
export { type AgentMiddleware as A, type CompletionRequestMiddlewareArgs as C, type ToolInputMiddlewareArgs as T, type CompletionRequestMiddlewareResult as a, type CompletionResponseMiddlewareArgs as b, type CompletionResponseMiddlewareResult as c, type ToolInputMiddlewareResult as d, type ToolOutputMiddlewareArgs as e, type ToolOutputMiddlewareResult as f, type ToolResultMiddlewareArgs as g, createMiddleware as h };
|