llm-large-files 0.4.0 → 0.5.0
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/CHANGELOG.md +205 -0
- package/README.md +48 -8
- package/dist/anthropic/adapter.d.ts +106 -0
- package/dist/anthropic/adapter.d.ts.map +1 -0
- package/dist/anthropic/adapter.js +391 -0
- package/dist/anthropic/adapter.js.map +1 -0
- package/dist/anthropic/index.d.ts +3 -0
- package/dist/anthropic/index.d.ts.map +1 -0
- package/dist/anthropic/index.js +2 -0
- package/dist/anthropic/index.js.map +1 -0
- package/dist/ask.d.ts +144 -0
- package/dist/ask.d.ts.map +1 -0
- package/dist/ask.js +540 -0
- package/dist/ask.js.map +1 -0
- package/dist/budget.d.ts +23 -0
- package/dist/budget.d.ts.map +1 -0
- package/dist/budget.js +64 -0
- package/dist/budget.js.map +1 -0
- package/dist/cache.d.ts +11 -2
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +36 -7
- package/dist/cache.js.map +1 -1
- package/dist/errors.d.ts +21 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +44 -0
- package/dist/errors.js.map +1 -0
- package/dist/evidence.d.ts +40 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +137 -0
- package/dist/evidence.js.map +1 -0
- package/dist/gemini/adapter.d.ts +50 -0
- package/dist/gemini/adapter.d.ts.map +1 -0
- package/dist/gemini/adapter.js +179 -0
- package/dist/gemini/adapter.js.map +1 -0
- package/dist/gemini/chat.d.ts +32 -71
- package/dist/gemini/chat.d.ts.map +1 -1
- package/dist/gemini/chat.js +38 -284
- package/dist/gemini/chat.js.map +1 -1
- package/dist/gemini/errors.d.ts +11 -0
- package/dist/gemini/errors.d.ts.map +1 -0
- package/dist/gemini/errors.js +14 -0
- package/dist/gemini/errors.js.map +1 -0
- package/dist/gemini/generate.d.ts +12 -13
- package/dist/gemini/generate.d.ts.map +1 -1
- package/dist/gemini/generate.js +62 -26
- package/dist/gemini/generate.js.map +1 -1
- package/dist/gemini/index.d.ts +3 -1
- package/dist/gemini/index.d.ts.map +1 -1
- package/dist/gemini/index.js +2 -1
- package/dist/gemini/index.js.map +1 -1
- package/dist/gemini/sse.d.ts +1 -2
- package/dist/gemini/sse.d.ts.map +1 -1
- package/dist/gemini/sse.js +1 -38
- package/dist/gemini/sse.js.map +1 -1
- package/dist/http.d.ts +20 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +55 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -4
- package/dist/index.js.map +1 -1
- package/dist/library.d.ts +50 -5
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +56 -26
- package/dist/library.js.map +1 -1
- package/dist/map-reduce.d.ts +15 -0
- package/dist/map-reduce.d.ts.map +1 -1
- package/dist/map-reduce.js +58 -27
- package/dist/map-reduce.js.map +1 -1
- package/dist/model.d.ts +196 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +41 -0
- package/dist/model.js.map +1 -0
- package/dist/openai/adapter.d.ts +85 -0
- package/dist/openai/adapter.d.ts.map +1 -0
- package/dist/openai/adapter.js +293 -0
- package/dist/openai/adapter.js.map +1 -0
- package/dist/openai/index.d.ts +3 -0
- package/dist/openai/index.d.ts.map +1 -0
- package/dist/openai/index.js +2 -0
- package/dist/openai/index.js.map +1 -0
- package/dist/output-limit.d.ts +30 -0
- package/dist/output-limit.d.ts.map +1 -0
- package/dist/output-limit.js +92 -0
- package/dist/output-limit.js.map +1 -0
- package/dist/plan.d.ts +20 -4
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +44 -7
- package/dist/plan.js.map +1 -1
- package/dist/ranged.d.ts +2 -2
- package/dist/ranged.d.ts.map +1 -1
- package/dist/ranged.js +11 -4
- package/dist/ranged.js.map +1 -1
- package/dist/retry.d.ts +54 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +111 -0
- package/dist/retry.js.map +1 -0
- package/dist/search.d.ts +16 -2
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +109 -26
- package/dist/search.js.map +1 -1
- package/dist/sse.d.ts +3 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +39 -0
- package/dist/sse.js.map +1 -0
- package/dist/stores.d.ts +5 -1
- package/dist/stores.d.ts.map +1 -1
- package/dist/stores.js +58 -15
- package/dist/stores.js.map +1 -1
- package/dist/text.d.ts +12 -1
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +43 -15
- package/dist/text.js.map +1 -1
- package/dist/tools.d.ts +23 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +115 -35
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +33 -3
- package/dist/types.d.ts.map +1 -1
- package/docs/api.md +253 -28
- package/docs/configuration.md +89 -10
- package/docs/getting-started.md +69 -16
- package/docs/how-it-works.md +46 -4
- package/docs/security.md +36 -3
- package/package.json +21 -3
- package/src/anthropic/adapter.ts +454 -0
- package/src/anthropic/index.ts +2 -0
- package/src/ask.ts +675 -0
- package/src/budget.ts +71 -0
- package/src/cache.ts +32 -8
- package/src/errors.ts +42 -0
- package/src/evidence.ts +162 -0
- package/src/gemini/adapter.ts +218 -0
- package/src/gemini/chat.ts +62 -333
- package/src/gemini/errors.ts +15 -0
- package/src/gemini/generate.ts +72 -30
- package/src/gemini/index.ts +3 -1
- package/src/gemini/sse.ts +1 -34
- package/src/http.ts +59 -0
- package/src/index.ts +34 -4
- package/src/library.ts +102 -29
- package/src/map-reduce.ts +52 -23
- package/src/model.ts +200 -0
- package/src/openai/adapter.ts +345 -0
- package/src/openai/index.ts +2 -0
- package/src/output-limit.ts +99 -0
- package/src/plan.ts +46 -7
- package/src/ranged.ts +13 -6
- package/src/retry.ts +132 -0
- package/src/search.ts +116 -25
- package/src/sse.ts +34 -0
- package/src/stores.ts +51 -15
- package/src/text.ts +39 -12
- package/src/tools.ts +127 -38
- package/src/types.ts +29 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gemini/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACpL,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACxG,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjE,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gemini/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACpL,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACxG,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/F,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjE,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACrK,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACnG,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/gemini/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { askGemini, DocumentsNotFoundError, EXPLORER_INSTRUCTION, FINAL_ANSWER_AFTER_PAGES, FINAL_ANSWER_REQUEST, FINAL_ANSWER_WITHOUT_TOOLS, GeminiRequestError } from "./chat.js";
|
|
2
|
+
export { fromGeminiContents, gemini, GEMINI_PAGE_TOKENS, geminiToolTurns } from "./adapter.js";
|
|
2
3
|
export { geminiApi, vertexAi, vertexHost } from "./endpoints.js";
|
|
3
|
-
export { createGeminiGenerateText, geminiFunctionResponses, geminiFunctionResponseTurns, toGeminiTools } from "./generate.js";
|
|
4
|
+
export { createGeminiGenerateText, geminiFunctionResponses, geminiFunctionResponseTurns, THINKING_OUTPUT_TOKENS, toGeminiTools, usageOfGemini } from "./generate.js";
|
|
4
5
|
export { parseSseJson } from "./sse.js";
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/dist/gemini/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gemini/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEpL,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gemini/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEpL,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/F,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAErK,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/gemini/sse.d.ts
CHANGED
package/dist/gemini/sse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/gemini/sse.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/gemini/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/gemini/sse.js
CHANGED
|
@@ -1,39 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export async function* parseSseJson(stream) {
|
|
3
|
-
const reader = stream.getReader();
|
|
4
|
-
const decoder = new TextDecoder();
|
|
5
|
-
let buffer = "";
|
|
6
|
-
const parse = (block) => {
|
|
7
|
-
const data = block
|
|
8
|
-
.split("\n")
|
|
9
|
-
.filter((line) => line.startsWith("data:"))
|
|
10
|
-
.map((line) => line.slice(5).trimStart())
|
|
11
|
-
.join("\n");
|
|
12
|
-
return data && data !== "[DONE]" ? JSON.parse(data) : undefined;
|
|
13
|
-
};
|
|
14
|
-
try {
|
|
15
|
-
while (true) {
|
|
16
|
-
const { done, value } = await reader.read();
|
|
17
|
-
buffer += decoder.decode(value, { stream: !done });
|
|
18
|
-
buffer = buffer.replace(/\r\n/g, "\n");
|
|
19
|
-
let boundary = buffer.indexOf("\n\n");
|
|
20
|
-
while (boundary >= 0) {
|
|
21
|
-
const event = parse(buffer.slice(0, boundary));
|
|
22
|
-
buffer = buffer.slice(boundary + 2);
|
|
23
|
-
if (event !== undefined)
|
|
24
|
-
yield event;
|
|
25
|
-
boundary = buffer.indexOf("\n\n");
|
|
26
|
-
}
|
|
27
|
-
if (done)
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
const last = buffer.trim() ? parse(buffer.trim()) : undefined;
|
|
31
|
-
if (last !== undefined)
|
|
32
|
-
yield last;
|
|
33
|
-
}
|
|
34
|
-
finally {
|
|
35
|
-
await reader.cancel().catch(() => undefined);
|
|
36
|
-
reader.releaseLock();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
1
|
+
export { parseSseJson } from "../sse.js";
|
|
39
2
|
//# sourceMappingURL=sse.js.map
|
package/dist/gemini/sse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../src/gemini/sse.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../src/gemini/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Request headers, or a function returning them: called for each request, so a token can be renewed. */
|
|
2
|
+
export type HeaderSource = Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
3
|
+
export declare function resolveHeaderSource(source: HeaderSource | undefined): Promise<Record<string, string>>;
|
|
4
|
+
/** A secret, or a function returning it: called for each request. */
|
|
5
|
+
export type SecretSource = string | (() => string | Promise<string>);
|
|
6
|
+
export declare function resolveSecret(source: SecretSource | undefined): Promise<string | undefined>;
|
|
7
|
+
export declare function base64(bytes: Uint8Array): string;
|
|
8
|
+
/** The reason a request never got an answer, without the stack of the HTTP client. */
|
|
9
|
+
export declare function unreachableReason(error: unknown): string;
|
|
10
|
+
/**
|
|
11
|
+
* Arguments of a tool call that arrived as JSON text, and, when the text is not a JSON object,
|
|
12
|
+
* why the call cannot be run: a model that is told so sends the call again.
|
|
13
|
+
*/
|
|
14
|
+
export declare function readArguments(text: unknown): {
|
|
15
|
+
args: Record<string, unknown>;
|
|
16
|
+
problem?: string;
|
|
17
|
+
};
|
|
18
|
+
/** Arguments of a tool call that arrived as JSON text. Text that is no JSON object gives none. */
|
|
19
|
+
export declare function parseArguments(text: unknown): Record<string, unknown>;
|
|
20
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAEA,yGAAyG;AACzG,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;AAErH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAE3G;AAED,qEAAqE;AACrE,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AAErE,wBAAsB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAEjG;AAID,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAOhD;AAED,sFAAsF;AACtF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAExD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAUhG;AAED,kGAAkG;AAClG,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASrE"}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Small things every adapter needs for its HTTP requests.
|
|
2
|
+
export async function resolveHeaderSource(source) {
|
|
3
|
+
return typeof source === "function" ? source() : source ?? {};
|
|
4
|
+
}
|
|
5
|
+
export async function resolveSecret(source) {
|
|
6
|
+
return typeof source === "function" ? source() : source;
|
|
7
|
+
}
|
|
8
|
+
/** Base64 of bytes, worked out once for each array: the pages of a PDF are sent again with every later request. */
|
|
9
|
+
const encoded = new WeakMap();
|
|
10
|
+
export function base64(bytes) {
|
|
11
|
+
let text = encoded.get(bytes);
|
|
12
|
+
if (text === undefined) {
|
|
13
|
+
text = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
|
|
14
|
+
encoded.set(bytes, text);
|
|
15
|
+
}
|
|
16
|
+
return text;
|
|
17
|
+
}
|
|
18
|
+
/** The reason a request never got an answer, without the stack of the HTTP client. */
|
|
19
|
+
export function unreachableReason(error) {
|
|
20
|
+
return error instanceof Error && error.message ? ` (${error.message})` : "";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Arguments of a tool call that arrived as JSON text, and, when the text is not a JSON object,
|
|
24
|
+
* why the call cannot be run: a model that is told so sends the call again.
|
|
25
|
+
*/
|
|
26
|
+
export function readArguments(text) {
|
|
27
|
+
if (text && typeof text === "object" && !Array.isArray(text))
|
|
28
|
+
return { args: text };
|
|
29
|
+
if (typeof text !== "string" || !text.trim())
|
|
30
|
+
return { args: {} };
|
|
31
|
+
try {
|
|
32
|
+
const value = JSON.parse(text);
|
|
33
|
+
if (value && typeof value === "object" && !Array.isArray(value))
|
|
34
|
+
return { args: value };
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Reported below.
|
|
38
|
+
}
|
|
39
|
+
return { args: {}, problem: `The arguments of this call were not a JSON object, and it was not run: ${text.slice(0, 300)}. Send the call again.` };
|
|
40
|
+
}
|
|
41
|
+
/** Arguments of a tool call that arrived as JSON text. Text that is no JSON object gives none. */
|
|
42
|
+
export function parseArguments(text) {
|
|
43
|
+
if (text && typeof text === "object" && !Array.isArray(text))
|
|
44
|
+
return text;
|
|
45
|
+
if (typeof text !== "string" || !text.trim())
|
|
46
|
+
return {};
|
|
47
|
+
try {
|
|
48
|
+
const value = JSON.parse(text);
|
|
49
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAK1D,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,MAAgC;IACxE,OAAO,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC;AAChE,CAAC;AAKD,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAgC;IAClE,OAAO,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;AAC1D,CAAC;AAED,mHAAmH;AACnH,MAAM,OAAO,GAAG,IAAI,OAAO,EAAsB,CAAC;AAClD,MAAM,UAAU,MAAM,CAAC,KAAiB;IAC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AAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,wBAAwB,EAAE,CAAC;AACrJ,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,cAAc,CAAC,IAAa;IAC1C,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,IAA+B,CAAC;IACrG,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC;IACxD,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY,CAAC;QAC1C,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAgC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7G,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
export { createLargeFiles,
|
|
1
|
+
export { createLargeFiles, DEFAULT_CACHE_BYTES, DEFAULT_WHOLE_DOCUMENT_BYTES, isDocumentId, NEVER_EXPIRES, toDocumentSummary } from "./library.js";
|
|
2
2
|
export type { AccessOptions, IngestInput, LargeFiles, LargeFilesOptions, PrepareOptions, ToolOptions } from "./library.js";
|
|
3
|
+
export { DEFAULT_BUDGET, resolveBudget } from "./budget.js";
|
|
4
|
+
export type { ModelLimits } from "./budget.js";
|
|
5
|
+
export { askWithFiles, EXPLORER_INSTRUCTION, FINAL_ANSWER_AFTER_PAGES, FINAL_ANSWER_REQUEST, FINAL_ANSWER_WITHOUT_TOOLS } from "./ask.js";
|
|
6
|
+
export type { AskLimits, AskOptions, AskResult } from "./ask.js";
|
|
7
|
+
export { DocumentsNotFoundError, ModelRequestError, UsageMeter } from "./model.js";
|
|
8
|
+
export type { ChatMessage, ChatTurn, ModelAdapter, ModelCapabilities, ModelMessage, ModelPart, ModelReply, ModelRequest, ModelTextMessage, ModelToolRound, ModelUsage, SendHooks, ToolAnswer, ToolCall, ToolTurn, UsageTotals, } from "./model.js";
|
|
9
|
+
export { evidenceOf, mergeRanges, stubResult } from "./evidence.js";
|
|
10
|
+
export type { Evidence, NumberRange } from "./evidence.js";
|
|
11
|
+
export { isRetryableStatus, retryAfterMs, withRetry } from "./retry.js";
|
|
12
|
+
export type { RetryOptions } from "./retry.js";
|
|
13
|
+
export { parseSseJson } from "./sse.js";
|
|
14
|
+
export { DocumentStoreError } from "./errors.js";
|
|
3
15
|
export { FileDocumentStore, MemoryDocumentStore, DOCUMENT_ID_PATTERN } from "./stores.js";
|
|
4
16
|
export { createPdfExtractor, defaultExtractors, detectFormat } from "./extract.js";
|
|
5
17
|
export type { PdfExtractorOptions } from "./extract.js";
|
|
6
18
|
export { estimateTokens, utf8Bytes, jsonBytes } from "./text.js";
|
|
7
|
-
export { MAX_VIEW_PAGES, TOOL_NAMES, toolResultSummary } from "./tools.js";
|
|
19
|
+
export { MAX_VIEW_PAGES, MAX_WHOLE_DOCUMENT_READS, REGEX_BUDGET_MS, TOOL_NAMES, toolResultSummary } from "./tools.js";
|
|
8
20
|
export type * from "./types.js";
|
|
9
21
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACnJ,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,U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AAO,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,eAAe,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACtH,mBAAmB,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
// Core: provider-neutral.
|
|
2
|
-
//
|
|
3
|
-
|
|
1
|
+
// Core: provider-neutral. The tool loop is `askWithFiles`, and a model provider is an adapter:
|
|
2
|
+
// "llm-large-files/gemini", "llm-large-files/openai", "llm-large-files/anthropic", or your own.
|
|
3
|
+
// Node HTTP handlers are in "llm-large-files/node".
|
|
4
|
+
export { createLargeFiles, DEFAULT_CACHE_BYTES, DEFAULT_WHOLE_DOCUMENT_BYTES, isDocumentId, NEVER_EXPIRES, toDocumentSummary } from "./library.js";
|
|
5
|
+
export { DEFAULT_BUDGET, resolveBudget } from "./budget.js";
|
|
6
|
+
export { askWithFiles, EXPLORER_INSTRUCTION, FINAL_ANSWER_AFTER_PAGES, FINAL_ANSWER_REQUEST, FINAL_ANSWER_WITHOUT_TOOLS } from "./ask.js";
|
|
7
|
+
export { DocumentsNotFoundError, ModelRequestError, UsageMeter } from "./model.js";
|
|
8
|
+
export { evidenceOf, mergeRanges, stubResult } from "./evidence.js";
|
|
9
|
+
export { isRetryableStatus, retryAfterMs, withRetry } from "./retry.js";
|
|
10
|
+
export { parseSseJson } from "./sse.js";
|
|
11
|
+
export { DocumentStoreError } from "./errors.js";
|
|
4
12
|
export { FileDocumentStore, MemoryDocumentStore, DOCUMENT_ID_PATTERN } from "./stores.js";
|
|
5
13
|
export { createPdfExtractor, defaultExtractors, detectFormat } from "./extract.js";
|
|
6
14
|
export { estimateTokens, utf8Bytes, jsonBytes } from "./text.js";
|
|
7
|
-
export { MAX_VIEW_PAGES, TOOL_NAMES, toolResultSummary } from "./tools.js";
|
|
15
|
+
export { MAX_VIEW_PAGES, MAX_WHOLE_DOCUMENT_READS, REGEX_BUDGET_MS, TOOL_NAMES, toolResultSummary } from "./tools.js";
|
|
8
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,gGAAgG;AAChG,oDAAoD;AACpD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEnJ,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAE1I,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAmBnF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEpE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAExE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEnF,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,eAAe,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/library.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
import { type ModelLimits } from "./budget.js";
|
|
2
|
+
import type { RetryOptions } from "./retry.js";
|
|
1
3
|
import type { Budget, DocumentFormat, DocumentMeta, DocumentStore, DocumentSummary, Extractor, GenerateText, PreparedContext, ProgressListener, ToolSet } from "./types.js";
|
|
2
|
-
|
|
3
|
-
export declare const DEFAULT_BUDGET: Budget;
|
|
4
|
+
export { DEFAULT_BUDGET } from "./budget.js";
|
|
4
5
|
export type LargeFilesOptions = {
|
|
5
6
|
/** Where extracted text is kept: `new FileDocumentStore(dir)`, `new MemoryDocumentStore()`, or your own. */
|
|
6
7
|
store: DocumentStore;
|
|
7
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Your model's limits. What is left out follows `contextTokens` (see `resolveBudget`), which is
|
|
10
|
+
* 1M tokens unless you set it: for a model with a smaller window, setting that one number is
|
|
11
|
+
* enough. Values that cannot work together are an error.
|
|
12
|
+
*/
|
|
8
13
|
budget?: Partial<Budget>;
|
|
9
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* How long uploaded documents are kept. Defaults to 72 hours. `Infinity` keeps them until they
|
|
16
|
+
* are deleted: their `expiresAt` is then `NEVER_EXPIRES`.
|
|
17
|
+
*/
|
|
10
18
|
ttlMs?: number;
|
|
11
19
|
/** Largest accepted upload. Defaults to 100 MB. */
|
|
12
20
|
maxUploadBytes?: number;
|
|
@@ -32,7 +40,11 @@ export type LargeFilesOptions = {
|
|
|
32
40
|
* deleted or expired on another server sharing the store is never served from memory here.
|
|
33
41
|
*/
|
|
34
42
|
cacheBytes?: number;
|
|
35
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Also caps the number of documents kept (the only limit before 0.4). Unset: no cap on the
|
|
45
|
+
* number. The pieces kept of a document that is read by range are not counted, and go when
|
|
46
|
+
* their document does.
|
|
47
|
+
*/
|
|
36
48
|
cacheSize?: number;
|
|
37
49
|
/**
|
|
38
50
|
* Documents whose text is at most this many bytes are loaded whole into memory (and kept there
|
|
@@ -64,6 +76,11 @@ export type AccessOptions = {
|
|
|
64
76
|
owner?: string;
|
|
65
77
|
};
|
|
66
78
|
export type PrepareOptions = AccessOptions & {
|
|
79
|
+
/**
|
|
80
|
+
* The budget of this request, when it is not the library's own: the fields to change, as in
|
|
81
|
+
* `LargeFilesOptions.budget`. `askWithFiles` passes the budget that fits the model it was given.
|
|
82
|
+
*/
|
|
83
|
+
budget?: Partial<Budget>;
|
|
67
84
|
/**
|
|
68
85
|
* Say that your tool loop can pass files to the model (see `ToolOptions.viewPages`). The result
|
|
69
86
|
* then lists the PDFs whose pages can be shown in `viewable`, and the instruction and the cards
|
|
@@ -77,6 +94,23 @@ export type ToolOptions = {
|
|
|
77
94
|
/** Progress of whole-document reads, for status messages. */
|
|
78
95
|
onProgress?: ProgressListener;
|
|
79
96
|
signal?: AbortSignal;
|
|
97
|
+
/**
|
|
98
|
+
* The most time, in milliseconds, that the regex searches of this tool set may take together.
|
|
99
|
+
* Past it, a regex search answers with an error that tells the model to search another way.
|
|
100
|
+
* Defaults to 6,000. One search still stops after 3,000, and at once at a line its pattern
|
|
101
|
+
* cannot get past.
|
|
102
|
+
*/
|
|
103
|
+
regexBudgetMs?: number;
|
|
104
|
+
/**
|
|
105
|
+
* How many times each document may be read whole (`analyze_whole_document`) by this tool set.
|
|
106
|
+
* A call past it answers with an error that tells the model to use what it has. Defaults to 1:
|
|
107
|
+
* make one tool set for each question, as `askWithFiles` does.
|
|
108
|
+
*/
|
|
109
|
+
maxWholeDocumentReads?: number;
|
|
110
|
+
/** How a model request of a whole-document read that failed is sent again. Defaults to three more tries, with a wait that doubles. */
|
|
111
|
+
retry?: RetryOptions;
|
|
112
|
+
/** The budget of these tools, when it is not the library's own: the fields to change. Use the one you planned the request with. */
|
|
113
|
+
budget?: Partial<Budget>;
|
|
80
114
|
/**
|
|
81
115
|
* Offers `view_pages`, which hands the model real pages of a PDF whose original file is kept
|
|
82
116
|
* (see `keepOriginals`). The pages come back as a file, so turn this on only when your loop
|
|
@@ -89,6 +123,12 @@ export type ToolOptions = {
|
|
|
89
123
|
export interface LargeFiles {
|
|
90
124
|
/** The effective budget (defaults merged with your overrides). */
|
|
91
125
|
readonly budget: Budget;
|
|
126
|
+
/**
|
|
127
|
+
* The budget for one request: the library's, with `overrides` in place of its fields, made to
|
|
128
|
+
* fit `limits` (a model's context window and request size, when they are smaller). Fields that
|
|
129
|
+
* neither the library nor `overrides` set follow the context window that results.
|
|
130
|
+
*/
|
|
131
|
+
budgetFor(overrides?: Partial<Budget>, limits?: ModelLimits): Budget;
|
|
92
132
|
readonly maxUploadBytes: number;
|
|
93
133
|
/** Extracts, normalizes, profiles, and stores a file. Throws a user-readable Error on bad input. */
|
|
94
134
|
ingest(input: IngestInput): Promise<DocumentMeta>;
|
|
@@ -118,6 +158,11 @@ export declare function toDocumentSummary(meta: DocumentMeta): DocumentSummary;
|
|
|
118
158
|
* not be able to start a new line of the prompt or disguise its extension.
|
|
119
159
|
*/
|
|
120
160
|
export declare function cleanFileName(raw: string): string;
|
|
161
|
+
/**
|
|
162
|
+
* The `expiresAt` of a document that never expires (`ttlMs: Infinity`): the last instant of the
|
|
163
|
+
* year 9999. A date, so that every comparison, and a server of an older version, reads it as any other.
|
|
164
|
+
*/
|
|
165
|
+
export declare const NEVER_EXPIRES = "9999-12-31T23:59:59.999Z";
|
|
121
166
|
/** Default for `cacheBytes`. */
|
|
122
167
|
export declare const DEFAULT_CACHE_BYTES: number;
|
|
123
168
|
/** Default for `wholeDocumentBytes`. */
|
package/dist/library.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":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ze.js";
|
|
3
|
+
import { givenBudget, resolveBudget } from "./budget.js";
|
|
3
4
|
import { DocumentCache, documentVersion } from "./cache.js";
|
|
5
|
+
import { DocumentStoreError } from "./errors.js";
|
|
4
6
|
import { detectFormat, extractText } from "./extract.js";
|
|
5
7
|
import { Limiter } from "./limiter.js";
|
|
6
|
-
import { CARD_LINES, documentToolsInstruction, formatBytes, planDocuments, renderCard, renderInline } from "./plan.js";
|
|
8
|
+
import { canBeReadWhole, CARD_LINES, documentToolsInstruction, formatBytes, planDocuments, renderCard, renderInline } from "./plan.js";
|
|
7
9
|
import { openRangedDocument, pieceKey } from "./ranged.js";
|
|
8
10
|
import { numberLines, SearchableDocument } from "./search.js";
|
|
9
11
|
import { DOCUMENT_ID_PATTERN } from "./stores.js";
|
|
10
12
|
import { buildTextIndex, canSerialize, serializeTextIndex } from "./text-index.js";
|
|
11
|
-
import { estimateTokens, normalizeText,
|
|
13
|
+
import { estimateTokens, normalizeText, textSizes, wrapLongLines } from "./text.js";
|
|
12
14
|
import { createDocumentTools } from "./tools.js";
|
|
13
|
-
|
|
14
|
-
export const DEFAULT_BUDGET = {
|
|
15
|
-
contextTokens: 1_000_000,
|
|
16
|
-
maxRequestBytes: 10_000_000,
|
|
17
|
-
inlineTokens: 200_000,
|
|
18
|
-
reservedTokens: 64_000,
|
|
19
|
-
mapChunkTokens: 100_000,
|
|
20
|
-
maxMapChunks: 30,
|
|
21
|
-
toolResultCharacters: 24_000,
|
|
22
|
-
};
|
|
15
|
+
export { DEFAULT_BUDGET } from "./budget.js";
|
|
23
16
|
export function isDocumentId(value) {
|
|
24
17
|
return typeof value === "string" && DOCUMENT_ID_PATTERN.test(value);
|
|
25
18
|
}
|
|
@@ -51,6 +44,23 @@ export function cleanFileName(raw) {
|
|
|
51
44
|
.trim()
|
|
52
45
|
.slice(0, 255) || "file";
|
|
53
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* A read of the store. Whatever it throws is passed on as a `DocumentStoreError`: a store that
|
|
49
|
+
* could not be read is not a document that is gone, and its own error names paths or hosts.
|
|
50
|
+
*/
|
|
51
|
+
async function reading(read) {
|
|
52
|
+
try {
|
|
53
|
+
return await read();
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw error instanceof DocumentStoreError ? error : new DocumentStoreError(error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The `expiresAt` of a document that never expires (`ttlMs: Infinity`): the last instant of the
|
|
61
|
+
* year 9999. A date, so that every comparison, and a server of an older version, reads it as any other.
|
|
62
|
+
*/
|
|
63
|
+
export const NEVER_EXPIRES = "9999-12-31T23:59:59.999Z";
|
|
54
64
|
function allowed(meta, access) {
|
|
55
65
|
return meta.owner === undefined || meta.owner === access?.owner;
|
|
56
66
|
}
|
|
@@ -59,7 +69,10 @@ export const DEFAULT_CACHE_BYTES = 256 * 1024 * 1024;
|
|
|
59
69
|
/** Default for `wholeDocumentBytes`. */
|
|
60
70
|
export const DEFAULT_WHOLE_DOCUMENT_BYTES = 2 * 1024 * 1024;
|
|
61
71
|
export function createLargeFiles(options) {
|
|
62
|
-
|
|
72
|
+
/** The fields the application set. The others follow the context window, whichever it is for a request. */
|
|
73
|
+
const ownBudget = givenBudget(options.budget);
|
|
74
|
+
const budget = resolveBudget(ownBudget);
|
|
75
|
+
const budgetFor = (overrides, limits) => (overrides || limits ? resolveBudget({ ...ownBudget, ...givenBudget(overrides) }, limits) : budget);
|
|
63
76
|
const ttlMs = options.ttlMs ?? 72 * 60 * 60 * 1000;
|
|
64
77
|
const maxUploadBytes = options.maxUploadBytes ?? 100 * 1024 * 1024;
|
|
65
78
|
const now = options.now ?? (() => new Date());
|
|
@@ -75,7 +88,13 @@ export function createLargeFiles(options) {
|
|
|
75
88
|
/** Documents being opened, so that calls arriving together open each one once. */
|
|
76
89
|
const opening = new Map();
|
|
77
90
|
/** The store, when large documents can be read from it by range rather than loaded whole. */
|
|
78
|
-
const ranged = typeof store.readTextRange === "function" ?
|
|
91
|
+
const ranged = typeof store.readTextRange === "function" ? {
|
|
92
|
+
readTextRange: (id, start, end) => reading(() => store.readTextRange(id, start, end)),
|
|
93
|
+
...(store.getIndex ? { getIndex: (id) => reading(() => store.getIndex(id)) } : {}),
|
|
94
|
+
...(store.putIndex ? { putIndex: (id, index) => store.putIndex(id, index) } : {}),
|
|
95
|
+
} : undefined;
|
|
96
|
+
/** The uploaded file of a document, when the store keeps such files. */
|
|
97
|
+
const loadOriginal = store.getOriginal ? (id) => reading(() => store.getOriginal(id)) : undefined;
|
|
79
98
|
const wholeDocumentBytes = Math.max(0, options.wholeDocumentBytes ?? DEFAULT_WHOLE_DOCUMENT_BYTES);
|
|
80
99
|
/** Documents whose saved index did not match their text: the next opening builds it from the text. */
|
|
81
100
|
const rebuildIndex = new Set();
|
|
@@ -88,7 +107,8 @@ export function createLargeFiles(options) {
|
|
|
88
107
|
},
|
|
89
108
|
pieces: {
|
|
90
109
|
get: (key, version) => cache.get(key, version),
|
|
91
|
-
|
|
110
|
+
// A piece belongs to its document: it is not one of the `cacheSize` documents, and leaves with it.
|
|
111
|
+
set: (key, version, piece) => cache.set(key, version, piece, key.slice(0, key.indexOf("#"))),
|
|
92
112
|
// A quarter of the cache: a few documents can be kept, and no one pushes out all the rest.
|
|
93
113
|
maxDocumentBytes: cacheBytes / 4,
|
|
94
114
|
},
|
|
@@ -104,7 +124,7 @@ export function createLargeFiles(options) {
|
|
|
104
124
|
async function currentMeta(id) {
|
|
105
125
|
if (!isDocumentId(id))
|
|
106
126
|
return undefined;
|
|
107
|
-
const meta = await
|
|
127
|
+
const meta = await reading(() => store.getMeta(id));
|
|
108
128
|
if (!meta || Date.parse(meta.expiresAt) <= now().getTime()) {
|
|
109
129
|
forget(id);
|
|
110
130
|
return undefined;
|
|
@@ -141,14 +161,14 @@ export function createLargeFiles(options) {
|
|
|
141
161
|
const rebuild = rebuildIndex.delete(id);
|
|
142
162
|
return openRangedDocument(ranged, meta, scan, { ignoreSavedIndex: rebuild });
|
|
143
163
|
}
|
|
144
|
-
const stored = await store.get(id);
|
|
164
|
+
const stored = await reading(() => store.get(id));
|
|
145
165
|
return stored ? new SearchableDocument(stored) : undefined;
|
|
146
166
|
}
|
|
147
167
|
/**
|
|
148
168
|
* What a document contributes to the prompt: its text, or its card. Undefined when it is gone
|
|
149
169
|
* by now. A copy found to disagree with the store is opened again once.
|
|
150
170
|
*/
|
|
151
|
-
async function block(id, meta, whole, viewable) {
|
|
171
|
+
async function block(id, meta, whole, viewable, readableWhole) {
|
|
152
172
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
153
173
|
const document = await load(id, attempt === 0 ? meta : undefined);
|
|
154
174
|
if (!document)
|
|
@@ -156,7 +176,7 @@ export function createLargeFiles(options) {
|
|
|
156
176
|
try {
|
|
157
177
|
return whole
|
|
158
178
|
? renderInline(document.meta, await document.readText())
|
|
159
|
-
: renderCard(document.meta, numberLines(await document.readLines(1, CARD_LINES), 1), viewable);
|
|
179
|
+
: renderCard(document.meta, numberLines(await document.readLines(1, CARD_LINES), 1), viewable, readableWhole);
|
|
160
180
|
}
|
|
161
181
|
catch (error) {
|
|
162
182
|
if (!document.broken) {
|
|
@@ -175,6 +195,7 @@ export function createLargeFiles(options) {
|
|
|
175
195
|
}
|
|
176
196
|
return {
|
|
177
197
|
budget,
|
|
198
|
+
budgetFor,
|
|
178
199
|
maxUploadBytes,
|
|
179
200
|
async ingest(input) {
|
|
180
201
|
const name = cleanFileName(input.name);
|
|
@@ -201,6 +222,8 @@ export function createLargeFiles(options) {
|
|
|
201
222
|
if (format === "text" && looksLikeLog(lines))
|
|
202
223
|
format = "log";
|
|
203
224
|
const created = now();
|
|
225
|
+
const expires = created.getTime() + ttlMs;
|
|
226
|
+
const sizes = textSizes(text);
|
|
204
227
|
const keepOriginal = keeps(format);
|
|
205
228
|
const meta = {
|
|
206
229
|
id: `doc_${randomUUID().replaceAll("-", "")}`,
|
|
@@ -209,7 +232,8 @@ export function createLargeFiles(options) {
|
|
|
209
232
|
mimeType,
|
|
210
233
|
format,
|
|
211
234
|
bytes: input.bytes.byteLength,
|
|
212
|
-
textBytes:
|
|
235
|
+
textBytes: sizes.utf8,
|
|
236
|
+
jsonBytes: sizes.json,
|
|
213
237
|
characters: text.length,
|
|
214
238
|
lines: lines.length,
|
|
215
239
|
estimatedTokens: estimateTokens(text),
|
|
@@ -219,7 +243,8 @@ export function createLargeFiles(options) {
|
|
|
219
243
|
outline: buildOutline(lines, format),
|
|
220
244
|
...(format === "log" ? { logProfile: buildLogProfile(lines) } : {}),
|
|
221
245
|
createdAt: created.toISOString(),
|
|
222
|
-
|
|
246
|
+
// Never, for a time to live without end (or one that runs past what a date can hold).
|
|
247
|
+
expiresAt: expires >= Date.parse(NEVER_EXPIRES) ? NEVER_EXPIRES : new Date(expires).toISOString(),
|
|
223
248
|
};
|
|
224
249
|
// The line index, so that the text can be read by range: a few bytes a line, built from the
|
|
225
250
|
// UTF-8 bytes the store writes. Kept by any store that can keep it, even one this library
|
|
@@ -247,7 +272,7 @@ export function createLargeFiles(options) {
|
|
|
247
272
|
getMeta: metaFor,
|
|
248
273
|
async getOriginal(id, access) {
|
|
249
274
|
const meta = await metaFor(id, access);
|
|
250
|
-
return meta?.originalKept ?
|
|
275
|
+
return meta?.originalKept ? loadOriginal?.(id) : undefined;
|
|
251
276
|
},
|
|
252
277
|
async delete(id, access) {
|
|
253
278
|
if (!await metaFor(id, access))
|
|
@@ -259,6 +284,7 @@ export function createLargeFiles(options) {
|
|
|
259
284
|
return options.store.sweep?.(now()) ?? 0;
|
|
260
285
|
},
|
|
261
286
|
async prepare(ids, base, access) {
|
|
287
|
+
const budget = budgetFor(access?.budget);
|
|
262
288
|
const unique = [...new Set(ids)];
|
|
263
289
|
let documents = [];
|
|
264
290
|
const missing = [];
|
|
@@ -284,22 +310,24 @@ export function createLargeFiles(options) {
|
|
|
284
310
|
const blocks = new Map();
|
|
285
311
|
const gone = [];
|
|
286
312
|
for (const meta of documents) {
|
|
287
|
-
const text = await block(meta.id, meta, inline.has(meta.id), shown.has(meta.id));
|
|
313
|
+
const text = await block(meta.id, meta, inline.has(meta.id), shown.has(meta.id), canBeReadWhole(meta, budget));
|
|
288
314
|
if (text === undefined)
|
|
289
315
|
gone.push(meta.id);
|
|
290
316
|
else
|
|
291
317
|
blocks.set(meta.id, text);
|
|
292
318
|
}
|
|
293
319
|
if (gone.length === 0) {
|
|
294
|
-
|
|
320
|
+
// A whole-document read is named only when one of the files is small enough for it.
|
|
321
|
+
const wholeReads = plan.searchable.some((meta) => canBeReadWhole(meta, budget));
|
|
322
|
+
return { plan, blocks, instruction: documentToolsInstruction(plan.searchable, viewable, wholeReads), missing, viewable };
|
|
295
323
|
}
|
|
296
324
|
missing.push(...gone);
|
|
297
325
|
documents = documents.filter((meta) => !gone.includes(meta.id));
|
|
298
326
|
}
|
|
299
327
|
},
|
|
300
328
|
tools(documents, toolOptions = {}) {
|
|
301
|
-
const { viewPages, ...rest } = toolOptions;
|
|
302
|
-
const
|
|
329
|
+
const { viewPages, budget: overrides, ...rest } = toolOptions;
|
|
330
|
+
const budget = budgetFor(overrides);
|
|
303
331
|
const viewable = (loadOriginal ? (viewPages === true ? documents : viewPages || []) : [])
|
|
304
332
|
.filter((meta) => meta.format === "pdf" && meta.originalKept);
|
|
305
333
|
return createDocumentTools({
|
|
@@ -308,6 +336,8 @@ export function createLargeFiles(options) {
|
|
|
308
336
|
names: Object.fromEntries([...documents, ...viewable].map((meta) => [meta.id, meta.name])),
|
|
309
337
|
budget,
|
|
310
338
|
...(loadOriginal && viewable.length > 0 ? { viewableIds: viewable.map((meta) => meta.id), loadOriginal } : {}),
|
|
339
|
+
// `analyze_whole_document` is declared only when it can read at least one of the documents.
|
|
340
|
+
wholeReads: documents.some((meta) => canBeReadWhole(meta, budget)),
|
|
311
341
|
...rest,
|
|
312
342
|
});
|
|
313
343
|
},
|