llm-large-files 0.5.0 → 0.7.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 +1402 -467
- package/README.md +188 -60
- package/dist/analyze.d.ts +5 -0
- package/dist/analyze.d.ts.map +1 -1
- package/dist/analyze.js +96 -47
- package/dist/analyze.js.map +1 -1
- package/dist/anthropic/adapter.d.ts +14 -3
- package/dist/anthropic/adapter.d.ts.map +1 -1
- package/dist/anthropic/adapter.js +190 -39
- package/dist/anthropic/adapter.js.map +1 -1
- package/dist/ask.d.ts +60 -4
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +1068 -206
- package/dist/ask.js.map +1 -1
- package/dist/encoding.d.ts +17 -0
- package/dist/encoding.d.ts.map +1 -0
- package/dist/encoding.js +852 -0
- package/dist/encoding.js.map +1 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +15 -0
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +333 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +159 -0
- package/dist/events.js.map +1 -0
- package/dist/evidence.d.ts +2 -0
- package/dist/evidence.d.ts.map +1 -1
- package/dist/evidence.js +3 -2
- package/dist/evidence.js.map +1 -1
- package/dist/extract.d.ts +35 -3
- package/dist/extract.d.ts.map +1 -1
- package/dist/extract.js +626 -58
- package/dist/extract.js.map +1 -1
- package/dist/gemini/adapter.d.ts +17 -8
- package/dist/gemini/adapter.d.ts.map +1 -1
- package/dist/gemini/adapter.js +108 -61
- package/dist/gemini/adapter.js.map +1 -1
- package/dist/gemini/chat.d.ts +23 -3
- package/dist/gemini/chat.d.ts.map +1 -1
- package/dist/gemini/chat.js +6 -2
- package/dist/gemini/chat.js.map +1 -1
- package/dist/gemini/errors.d.ts +9 -4
- package/dist/gemini/errors.d.ts.map +1 -1
- package/dist/gemini/errors.js +32 -0
- package/dist/gemini/errors.js.map +1 -1
- package/dist/gemini/generate.d.ts +10 -2
- package/dist/gemini/generate.d.ts.map +1 -1
- package/dist/gemini/generate.js +13 -7
- package/dist/gemini/generate.js.map +1 -1
- package/dist/gemini/index.d.ts +3 -3
- package/dist/gemini/index.d.ts.map +1 -1
- package/dist/gemini/index.js +2 -2
- package/dist/gemini/index.js.map +1 -1
- package/dist/gemini/sse.d.ts +1 -1
- package/dist/gemini/sse.d.ts.map +1 -1
- package/dist/gemini/sse.js +1 -1
- package/dist/gemini/sse.js.map +1 -1
- package/dist/http.d.ts +116 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +347 -1
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +11 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/library.d.ts +67 -5
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +405 -85
- package/dist/library.js.map +1 -1
- package/dist/map-reduce.d.ts +28 -1
- package/dist/map-reduce.d.ts.map +1 -1
- package/dist/map-reduce.js +240 -52
- package/dist/map-reduce.js.map +1 -1
- package/dist/model.d.ts +84 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +182 -1
- package/dist/model.js.map +1 -1
- package/dist/node/handlers.d.ts +20 -4
- package/dist/node/handlers.d.ts.map +1 -1
- package/dist/node/handlers.js +122 -20
- package/dist/node/handlers.js.map +1 -1
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/sse.d.ts +59 -0
- package/dist/node/sse.d.ts.map +1 -0
- package/dist/node/sse.js +174 -0
- package/dist/node/sse.js.map +1 -0
- package/dist/openai/adapter.d.ts +29 -5
- package/dist/openai/adapter.d.ts.map +1 -1
- package/dist/openai/adapter.js +311 -37
- package/dist/openai/adapter.js.map +1 -1
- package/dist/output-limit.d.ts +14 -2
- package/dist/output-limit.d.ts.map +1 -1
- package/dist/output-limit.js +39 -10
- package/dist/output-limit.js.map +1 -1
- package/dist/pause.d.ts +24 -0
- package/dist/pause.d.ts.map +1 -0
- package/dist/pause.js +38 -0
- package/dist/pause.js.map +1 -0
- package/dist/pdf-pages.d.ts +32 -2
- package/dist/pdf-pages.d.ts.map +1 -1
- package/dist/pdf-pages.js +275 -14
- package/dist/pdf-pages.js.map +1 -1
- package/dist/pdf-pictures.d.ts +30 -3
- package/dist/pdf-pictures.d.ts.map +1 -1
- package/dist/pdf-pictures.js +50 -8
- package/dist/pdf-pictures.js.map +1 -1
- package/dist/pdf-work.d.ts +40 -0
- package/dist/pdf-work.d.ts.map +1 -0
- package/dist/pdf-work.js +734 -0
- package/dist/pdf-work.js.map +1 -0
- package/dist/plan.d.ts +22 -4
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +61 -12
- package/dist/plan.js.map +1 -1
- package/dist/retry.d.ts +23 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +33 -3
- package/dist/retry.js.map +1 -1
- package/dist/search.d.ts +8 -2
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +60 -10
- package/dist/search.js.map +1 -1
- package/dist/sse.d.ts +35 -2
- package/dist/sse.d.ts.map +1 -1
- package/dist/sse.js +145 -31
- package/dist/sse.js.map +1 -1
- package/dist/stores.d.ts.map +1 -1
- package/dist/stores.js +5 -2
- package/dist/stores.js.map +1 -1
- package/dist/text-index.d.ts +6 -0
- package/dist/text-index.d.ts.map +1 -1
- package/dist/text-index.js +25 -8
- package/dist/text-index.js.map +1 -1
- package/dist/text.d.ts +62 -2
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +314 -14
- package/dist/text.js.map +1 -1
- package/dist/tools.d.ts +61 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +269 -42
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +102 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/zip-directory.d.ts +43 -0
- package/dist/zip-directory.d.ts.map +1 -0
- package/dist/zip-directory.js +130 -0
- package/dist/zip-directory.js.map +1 -0
- package/docs/README.md +288 -0
- package/docs/api.md +37 -381
- package/docs/configuration.md +28 -558
- package/docs/getting-started.md +407 -223
- package/docs/guides/anthropic.md +590 -0
- package/docs/guides/conversations.md +629 -0
- package/docs/guides/costs-and-limits.md +726 -0
- package/docs/guides/deployment.md +654 -0
- package/docs/guides/errors-and-reliability.md +735 -0
- package/docs/guides/explorer-model.md +399 -0
- package/docs/guides/openai-compatible.md +602 -0
- package/docs/guides/own-adapter-and-loop.md +1169 -0
- package/docs/guides/pdfs.md +971 -0
- package/docs/guides/storage.md +731 -0
- package/docs/guides/testing.md +1199 -0
- package/docs/guides/vertex-and-gemini.md +717 -0
- package/docs/guides/web-app.md +1589 -0
- package/docs/how-it-works.md +1012 -164
- package/docs/measurements.md +881 -0
- package/docs/publishing.md +274 -46
- package/docs/reference/anthropic.md +427 -0
- package/docs/reference/ask.md +892 -0
- package/docs/reference/errors-and-retries.md +758 -0
- package/docs/reference/events.md +993 -0
- package/docs/reference/gemini.md +823 -0
- package/docs/reference/library.md +1467 -0
- package/docs/reference/node.md +528 -0
- package/docs/reference/openai.md +385 -0
- package/docs/reference/tools.md +883 -0
- package/docs/security.md +897 -103
- package/docs/troubleshooting.md +1390 -0
- package/package.json +2 -2
- package/src/analyze.ts +93 -42
- package/src/anthropic/adapter.ts +196 -39
- package/src/ask.ts +1087 -202
- package/src/encoding.ts +850 -0
- package/src/errors.ts +17 -0
- package/src/events.ts +442 -0
- package/src/evidence.ts +5 -2
- package/src/extract.ts +602 -62
- package/src/gemini/adapter.ts +118 -65
- package/src/gemini/chat.ts +28 -4
- package/src/gemini/errors.ts +34 -1
- package/src/gemini/generate.ts +23 -10
- package/src/gemini/index.ts +3 -3
- package/src/gemini/sse.ts +1 -1
- package/src/http.ts +376 -1
- package/src/index.ts +27 -5
- package/src/library.ts +459 -85
- package/src/map-reduce.ts +252 -51
- package/src/model.ts +236 -3
- package/src/node/handlers.ts +137 -22
- package/src/node/index.ts +2 -0
- package/src/node/sse.ts +198 -0
- package/src/openai/adapter.ts +306 -38
- package/src/output-limit.ts +44 -8
- package/src/pause.ts +41 -0
- package/src/pdf-pages.ts +268 -15
- package/src/pdf-pictures.ts +56 -9
- package/src/pdf-work.ts +722 -0
- package/src/plan.ts +68 -12
- package/src/retry.ts +49 -5
- package/src/search.ts +63 -10
- package/src/sse.ts +153 -28
- package/src/stores.ts +5 -2
- package/src/text-index.ts +26 -7
- package/src/text.ts +323 -13
- package/src/tools.ts +261 -42
- package/src/types.ts +107 -4
- package/src/zip-directory.ts +136 -0
|
@@ -18,9 +18,16 @@ export type GeminiToolFilePlacement = "inside" | "beside";
|
|
|
18
18
|
export type GeminiToolAnswer = ToolAnswer;
|
|
19
19
|
/** Gemini's `usageMetadata` in the terms every adapter reports: thoughts are output, cached tokens are input. */
|
|
20
20
|
export declare function usageOfGemini(usage: Record<string, unknown> | undefined): GenerateUsage;
|
|
21
|
-
|
|
21
|
+
/** One part of a Gemini turn, as the REST API takes it: `{ text }`, `{ functionCall }`, `{ inlineData }`… */
|
|
22
|
+
export type GeminiPart = Record<string, unknown>;
|
|
23
|
+
/** One turn of Gemini's `contents`. */
|
|
24
|
+
export type GeminiContent = {
|
|
25
|
+
role: "user" | "model";
|
|
26
|
+
parts: GeminiPart[];
|
|
27
|
+
};
|
|
28
|
+
/** A `user` turn: a `GeminiContent` that can go in `contents` as it is. */
|
|
29
|
+
type UserTurn = GeminiContent & {
|
|
22
30
|
role: "user";
|
|
23
|
-
parts: unknown[];
|
|
24
31
|
};
|
|
25
32
|
/**
|
|
26
33
|
* The `user` turn that answers a model turn's function calls, in call order. A file that a tool
|
|
@@ -53,6 +60,7 @@ export declare function createGeminiGenerateText(options: {
|
|
|
53
60
|
/** Request headers, or a function returning them. A function is called for every request: a whole-file read can outlast an access token. */
|
|
54
61
|
headers: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
55
62
|
fetchImpl?: typeof fetch;
|
|
63
|
+
/** The `generationConfig` of each request, from its output limit. Defaults to `{ maxOutputTokens }`. */
|
|
56
64
|
generationConfig?: (maxOutputTokens: number) => Record<string, unknown>;
|
|
57
65
|
timeoutMs?: number;
|
|
58
66
|
}): GenerateText;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/gemini/generate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/gemini/generate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIxD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AAGtG,8DAA8D;AAC9D,wBAAgB,aAAa,CAAC,YAAY,EAAE,eAAe,EAAE,GAAG;IAAE,oBAAoB,EAAE,eAAe,EAAE,CAAA;CAAE,CAE1G;AAED,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE1D,uEAAuE;AACvE,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC;AAE1C,iHAAiH;AACjH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,aAAa,CAQvF;AAED,6GAA6G;AAC7G,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACjD,uCAAuC;AACvC,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC;AAE5E,2EAA2E;AAC3E,KAAK,QAAQ,GAAG,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAuBjD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,QAAQ,CAE3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,gBAAgB,EAAE,EAAE,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,uBAAuB,CAAA;CAAO,GAAG,QAAQ,EAAE,CAQpI;AAED,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE5D;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,4IAA4I;IAC5I,OAAO,EAAE,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;IACnG,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,wGAAwG;IACxG,gBAAgB,CAAC,EAAE,CAAC,eAAe,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,YAAY,CAuDf"}
|
package/dist/gemini/generate.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { completeWithinLimit } from "../output-limit.js";
|
|
2
|
+
import { readJson } from "../http.js";
|
|
2
3
|
import { retryAfterMs } from "../retry.js";
|
|
3
|
-
import {
|
|
4
|
+
import { finishOfGemini, geminiFailure, notJson, unreachable } from "./errors.js";
|
|
4
5
|
/** Gemini accepts this package's JSON Schema subset as-is. */
|
|
5
6
|
export function toGeminiTools(declarations) {
|
|
6
7
|
return { functionDeclarations: declarations };
|
|
@@ -89,7 +90,8 @@ export function createGeminiGenerateText(options) {
|
|
|
89
90
|
body: JSON.stringify({
|
|
90
91
|
contents: [{ role: "user", parts: [{ text: prompt }] }],
|
|
91
92
|
systemInstruction: { role: "system", parts: [{ text: system }] },
|
|
92
|
-
|
|
93
|
+
// No temperature: Gemini 3.6 and later ignore it, and Google says later models will refuse it.
|
|
94
|
+
generationConfig: options.generationConfig?.(limit) ?? { maxOutputTokens: limit },
|
|
93
95
|
}),
|
|
94
96
|
});
|
|
95
97
|
}
|
|
@@ -99,11 +101,13 @@ export function createGeminiGenerateText(options) {
|
|
|
99
101
|
throw error;
|
|
100
102
|
throw unreachable(error);
|
|
101
103
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
// An error may have no JSON body. A reply must: one whose body could not be read is a
|
|
105
|
+
// connection that failed, and is sent again.
|
|
106
|
+
const data = response.ok
|
|
107
|
+
? await readJson(response, () => Boolean(signal?.aborted) || timeout.aborted, unreachable, undefined, (error) => notJson(response, error))
|
|
108
|
+
: await response.json().catch(() => null);
|
|
109
|
+
if (!response.ok)
|
|
110
|
+
throw geminiFailure(response.status, data, retryAfterMs(response.headers, data), `The model returned HTTP ${response.status}.`);
|
|
107
111
|
onUsage?.(usageOfGemini(data?.usageMetadata));
|
|
108
112
|
const candidate = data?.candidates?.[0];
|
|
109
113
|
const text = (candidate?.content?.parts ?? [])
|
|
@@ -114,6 +118,8 @@ export function createGeminiGenerateText(options) {
|
|
|
114
118
|
return {
|
|
115
119
|
text,
|
|
116
120
|
cutOff: candidate?.finishReason === "MAX_TOKENS",
|
|
121
|
+
// Stopped by the safety filters before its end: what it wrote is not all there is.
|
|
122
|
+
stopped: finishOfGemini(candidate?.finishReason) === "filtered",
|
|
117
123
|
...(candidate?.finishReason ? { reason: candidate.finishReason } : {}),
|
|
118
124
|
thoughts: typeof thoughts === "number" ? thoughts : 0,
|
|
119
125
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/gemini/generate.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAqB,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/gemini/generate.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAqB,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAElF,8DAA8D;AAC9D,MAAM,UAAU,aAAa,CAAC,YAA+B;IAC3D,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,CAAC;AAChD,CAAC;AAiBD,iHAAiH;AACjH,MAAM,UAAU,aAAa,CAAC,KAA0C;IACtE,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,CAAC,OAAO,KAAK,EAAE,CAAC,GAAG,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9F,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,kBAAkB,CAAC,GAAG,MAAM,CAAC,yBAAyB,CAAC;QAC3E,iBAAiB,EAAE,MAAM,CAAC,yBAAyB,CAAC;QACpD,YAAY,EAAE,MAAM,CAAC,sBAAsB,CAAC,GAAG,MAAM,CAAC,oBAAoB,CAAC;QAC3E,aAAa,EAAE,MAAM,CAAC,oBAAoB,CAAC;KAC5C,CAAC;AACJ,CAAC;AAUD,MAAM,MAAM,GAAG,CAAC,KAAiB,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAA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REQUEST, FINAL_ANSWER_WITHOUT_TOOLS, GeminiRequestError } from "./chat.js";
|
|
2
|
-
export type { AskGeminiOptions, AskGeminiResult, ChatTurn, GeminiContent, GeminiPart } from "./chat.js";
|
|
1
|
+
export { askGemini, DocumentsNotFoundError, EXPLORER_INSTRUCTION, FINAL_ANSWER_AFTER_PAGES, FINAL_ANSWER_REQUEST, FINAL_ANSWER_WITHOUT_TOOLS, GeminiRequestError, partialResultOf } from "./chat.js";
|
|
2
|
+
export type { AskEvent, AskGeminiOptions, AskGeminiResult, ChatTurn, GeminiContent, GeminiPart } from "./chat.js";
|
|
3
3
|
export { fromGeminiContents, gemini, GEMINI_PAGE_TOKENS, geminiToolTurns } from "./adapter.js";
|
|
4
4
|
export type { GeminiModelOptions } from "./adapter.js";
|
|
5
5
|
export { geminiApi, vertexAi, vertexHost } from "./endpoints.js";
|
|
6
6
|
export type { GeminiEndpoint } from "./endpoints.js";
|
|
7
7
|
export { createGeminiGenerateText, geminiFunctionResponses, geminiFunctionResponseTurns, THINKING_OUTPUT_TOKENS, toGeminiTools, usageOfGemini } from "./generate.js";
|
|
8
8
|
export type { GeminiFunctionCall, GeminiToolAnswer, GeminiToolFilePlacement } from "./generate.js";
|
|
9
|
-
export { parseSseJson } from "./sse.js";
|
|
9
|
+
export { parseSseJson, SseEventTooLongError } from "./sse.js";
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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;
|
|
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,eAAe,EAAE,MAAM,WAAW,CAAC;AACrM,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,eAAe,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAClH,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,oBAAoB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/gemini/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { askGemini, DocumentsNotFoundError, EXPLORER_INSTRUCTION, FINAL_ANSWER_AFTER_PAGES, FINAL_ANSWER_REQUEST, FINAL_ANSWER_WITHOUT_TOOLS, GeminiRequestError } from "./chat.js";
|
|
1
|
+
export { askGemini, DocumentsNotFoundError, EXPLORER_INSTRUCTION, FINAL_ANSWER_AFTER_PAGES, FINAL_ANSWER_REQUEST, FINAL_ANSWER_WITHOUT_TOOLS, GeminiRequestError, partialResultOf } from "./chat.js";
|
|
2
2
|
export { fromGeminiContents, gemini, GEMINI_PAGE_TOKENS, geminiToolTurns } from "./adapter.js";
|
|
3
3
|
export { geminiApi, vertexAi, vertexHost } from "./endpoints.js";
|
|
4
4
|
export { createGeminiGenerateText, geminiFunctionResponses, geminiFunctionResponseTurns, THINKING_OUTPUT_TOKENS, toGeminiTools, usageOfGemini } from "./generate.js";
|
|
5
|
-
export { parseSseJson } from "./sse.js";
|
|
5
|
+
export { parseSseJson, SseEventTooLongError } from "./sse.js";
|
|
6
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;
|
|
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,eAAe,EAAE,MAAM,WAAW,CAAC;AAErM,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,oBAAoB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/gemini/sse.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { parseSseJson } from "../sse.js";
|
|
1
|
+
export { parseSseJson, SseEventTooLongError } from "../sse.js";
|
|
2
2
|
//# sourceMappingURL=sse.d.ts.map
|
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,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/gemini/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/gemini/sse.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { parseSseJson } from "../sse.js";
|
|
1
|
+
export { parseSseJson, SseEventTooLongError } from "../sse.js";
|
|
2
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,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../src/gemini/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/http.d.ts
CHANGED
|
@@ -7,6 +7,122 @@ export declare function resolveSecret(source: SecretSource | undefined): Promise
|
|
|
7
7
|
export declare function base64(bytes: Uint8Array): string;
|
|
8
8
|
/** The reason a request never got an answer, without the stack of the HTTP client. */
|
|
9
9
|
export declare function unreachableReason(error: unknown): string;
|
|
10
|
+
/**
|
|
11
|
+
* The longest wait, by default, between two pieces of a reply once it has started to arrive: an
|
|
12
|
+
* event of a stream, a keep-alive, a piece of a body. A model that is writing sends something
|
|
13
|
+
* well within it.
|
|
14
|
+
*/
|
|
15
|
+
export declare const DEFAULT_IDLE_TIMEOUT_MS = 300000;
|
|
16
|
+
/**
|
|
17
|
+
* The longest wait, by default, for the first piece of a reply. Headers do not count: some servers
|
|
18
|
+
* send them at once. A model that thinks sends nothing while it does (Gemini without its thoughts,
|
|
19
|
+
* OpenAI's reasoning models), and a reply that is not streamed comes whole at the end, so this
|
|
20
|
+
* wait is long enough for a model that thinks long on a large request.
|
|
21
|
+
*/
|
|
22
|
+
export declare const DEFAULT_FIRST_BYTE_TIMEOUT_MS = 600000;
|
|
23
|
+
/** Watches a request for silence: see `idleWatch`. */
|
|
24
|
+
export type IdleWatch = {
|
|
25
|
+
/** The signal for `fetch`: it aborts when the caller's does, or when nothing arrived for the whole wait. */
|
|
26
|
+
readonly signal: AbortSignal | undefined;
|
|
27
|
+
/** A piece of the reply arrived: from now on the wait is the one between pieces, and it starts again. */
|
|
28
|
+
pulse(): void;
|
|
29
|
+
/** The reply is in, or failed: the watch ends. */
|
|
30
|
+
stop(): void;
|
|
31
|
+
/** True once a wait ran out with nothing arriving. The request was then aborted by the watch, not by the caller. */
|
|
32
|
+
readonly expired: boolean;
|
|
33
|
+
/** The wait that ran out, in milliseconds, for the message. */
|
|
34
|
+
readonly waitedMs: number;
|
|
35
|
+
};
|
|
36
|
+
/** How long an adapter waits: before the first piece of a reply, and between pieces. 0 waits without end. */
|
|
37
|
+
export type IdleWaits = {
|
|
38
|
+
firstByteTimeoutMs?: number | undefined;
|
|
39
|
+
idleTimeoutMs?: number | undefined;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* A watch on one model request: when nothing arrives for the wait (`firstByteTimeoutMs` before the
|
|
43
|
+
* first piece of the reply, `idleTimeoutMs` between pieces), the request is aborted, and `expired`
|
|
44
|
+
* tells that apart from the caller's own abort. There is no cap on the time of a reply that keeps
|
|
45
|
+
* arriving. A wait of 0 watches nothing.
|
|
46
|
+
*/
|
|
47
|
+
export declare function idleWatch(caller: AbortSignal | undefined, waits?: IdleWaits): IdleWatch;
|
|
48
|
+
/**
|
|
49
|
+
* How long, in milliseconds, the end of a streamed body is waited for once the reply said it is
|
|
50
|
+
* whole (OpenAI's `[DONE]`, Claude's `message_stop`). A server ends the body at once: the wait lets
|
|
51
|
+
* the connection be used again. One that leaves it open is not waited for longer.
|
|
52
|
+
*/
|
|
53
|
+
export declare const REPLY_END_GRACE_MS = 1000;
|
|
54
|
+
/** The end of a streamed reply, once it said it is whole: see `replyEnd`. */
|
|
55
|
+
export type ReplyEnd = {
|
|
56
|
+
/** The signal to read the stream with: the watch's, and the end of the grace that follows `reached`. */
|
|
57
|
+
readonly signal: AbortSignal;
|
|
58
|
+
/** The reply said it is whole: the watch ends, and the body is read for `REPLY_END_GRACE_MS` more at most. */
|
|
59
|
+
reached(): void;
|
|
60
|
+
/**
|
|
61
|
+
* True once the reply said it is whole (`reached`): a connection that breaks after that, rather
|
|
62
|
+
* than end, loses nothing of the reply.
|
|
63
|
+
*/
|
|
64
|
+
readonly whole: boolean;
|
|
65
|
+
/** True for the error of a body left after that grace: what came before it is the whole reply. */
|
|
66
|
+
left(error: unknown): boolean;
|
|
67
|
+
/** The reading is over: the grace is not waited for. */
|
|
68
|
+
dispose(): void;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* The end of a streamed reply. A server that says the reply is whole and then leaves the
|
|
72
|
+
* connection open would hold the request until the watch ran out, and fail it as silent, with the
|
|
73
|
+
* whole answer already shown.
|
|
74
|
+
*/
|
|
75
|
+
export declare function replyEnd(watch: Pick<IdleWatch, "signal" | "stop">): ReplyEnd;
|
|
76
|
+
/**
|
|
77
|
+
* A wait for `next` that ends with the signal's reason when the signal aborts first. The global
|
|
78
|
+
* `fetch` ends the body of a request whose signal aborts; another `fetch` (or a test's) may not,
|
|
79
|
+
* and a watch on the request must still end it. The tool loop waits for a model request the same
|
|
80
|
+
* way: an adapter of an application's own may not stop when the signal aborts, and one written in
|
|
81
|
+
* plain JavaScript may give back a value, or a thenable, rather than a promise.
|
|
82
|
+
*/
|
|
83
|
+
export declare function until<T>(next: T | PromiseLike<T>, signal: AbortSignal | undefined): Promise<T>;
|
|
84
|
+
/**
|
|
85
|
+
* The pieces of a body as they arrive: from a web stream (the global `fetch`), or from a Node
|
|
86
|
+
* stream (node-fetch and the like), which has no `getReader`. A reader that is left early is
|
|
87
|
+
* cancelled. When `signal` aborts, the next piece is not waited for.
|
|
88
|
+
*/
|
|
89
|
+
export declare function bodyPieces(body: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array | string>, signal?: AbortSignal): AsyncGenerator<Uint8Array>;
|
|
90
|
+
/**
|
|
91
|
+
* The body of a response that is not streamed, as JSON. A connection that fails while the body
|
|
92
|
+
* arrives is `unreachable(error)`, a request that got no answer, which is sent again like one that
|
|
93
|
+
* failed before the headers; it is noted as a reply cut off on its way (`isCutReply`), and so is a
|
|
94
|
+
* body that ended empty. A body that came whole but is not JSON (a gateway's HTML page) is
|
|
95
|
+
* `notJson(error)`: see `notJsonMessage`.
|
|
96
|
+
* With an `IdleWatch`, pass its `pulse` as `onData` (keep-alive blank lines count) and its signal.
|
|
97
|
+
*/
|
|
98
|
+
export declare function readJson<T>(response: Response, stopped: () => boolean, unreachable: (error: unknown) => Error, watch: Pick<IdleWatch, "pulse" | "signal"> | undefined, notJson: (error: unknown) => Error): Promise<T>;
|
|
99
|
+
/**
|
|
100
|
+
* The message of a reply that came with a status of success but is not JSON: most often a page of
|
|
101
|
+
* a proxy or a gateway (a sign-in page, an error page) that answered in the model's place. It is
|
|
102
|
+
* not sent again: the same page would most likely come back. `who` is "Gemini's", "Claude's"…
|
|
103
|
+
*/
|
|
104
|
+
export declare function notJsonMessage(who: string, response: Response): string;
|
|
105
|
+
/**
|
|
106
|
+
* Takes note that this error is that of a reply cut off on its way (a stream that closed before
|
|
107
|
+
* its end, a connection that failed while the reply arrived), not of a model that could not be
|
|
108
|
+
* reached at all. Returns the error.
|
|
109
|
+
*/
|
|
110
|
+
export declare function noteCutReply<E extends Error>(error: E): E;
|
|
111
|
+
/** Whether this is the error of a reply cut off on its way (see `noteCutReply`). */
|
|
112
|
+
export declare function isCutReply(error: unknown): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* How to read the body of a reply that was asked for as a stream: as server-sent events, or as
|
|
115
|
+
* JSON in one piece. A reply of type `text/event-stream` is events. Of any other type, its first
|
|
116
|
+
* characters tell: a gateway may stream under another type (`application/octet-stream`, or none),
|
|
117
|
+
* and a server may answer in one piece. A body that starts like neither (an HTML page), or with
|
|
118
|
+
* more than `LONGEST_BLANK_START` characters of white space, is read as JSON, which it is not: see
|
|
119
|
+
* `readJson`. The pieces read to tell are pulses of the watch, and the `response` returned holds
|
|
120
|
+
* the whole body again.
|
|
121
|
+
*/
|
|
122
|
+
export declare function streamedReply(response: Response, watch: Pick<IdleWatch, "pulse" | "signal">): Promise<{
|
|
123
|
+
events: boolean;
|
|
124
|
+
response: Response;
|
|
125
|
+
}>;
|
|
10
126
|
/**
|
|
11
127
|
* Arguments of a tool call that arrived as JSON text, and, when the text is not a JSON object,
|
|
12
128
|
* why the call cannot be run: a model that is told so sends the call again.
|
package/dist/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAGA,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;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