chat-agent-toolkit 1.2.11 → 1.2.13

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.
@@ -7,5 +7,20 @@ export interface R2CredentialsInput {
7
7
  }
8
8
  export declare function buildFallbackDocs(query: string): Document[];
9
9
  export declare function normalizeSourcesOutput(output: unknown, query: string): Document[];
10
+ /**
11
+ * Resolves an uploaded fileId to its extracted `{ title, content }` payload.
12
+ * Hosts register a loader (e.g. reading the native R2 binding) so the search
13
+ * pipeline does not depend on filesystem or credential-based access.
14
+ */
15
+ export type UploadFileLoader = (fileId: string) => Promise<{
16
+ title: string;
17
+ content: string;
18
+ } | null>;
19
+ /**
20
+ * Registers the loader used by {@link rerankDocs} to resolve uploaded
21
+ * fileIds to extracted content. The registered loader takes precedence over
22
+ * the S3-credentials fallback.
23
+ */
24
+ export declare function registerUploadFileLoader(loader: UploadFileLoader): void;
10
25
  export declare function rerankDocs(query: string, docs: Document[], fileIds: string[], optimizationMode: "speed" | "balanced" | "quality", r2Credentials?: R2CredentialsInput): Promise<Document[]>;
11
26
  export declare function processDocs(docs: Document[]): string;
@@ -9,4 +9,5 @@ export { default as generateSuggestions } from './suggestionGeneratorAgent';
9
9
  export { groupAndSummarizeDocs } from './link-summarizer';
10
10
  export type { Document } from './document';
11
11
  export { splitTextIntoChunks } from './document';
12
- export { buildFallbackDocs, rerankDocs, processDocs, normalizeSourcesOutput } from './doc-utils';
12
+ export { buildFallbackDocs, rerankDocs, processDocs, normalizeSourcesOutput, registerUploadFileLoader } from './doc-utils';
13
+ export type { UploadFileLoader } from './doc-utils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chat-agent-toolkit",
3
- "version": "1.2.11",
3
+ "version": "1.2.13",
4
4
  "description": "Multi-provider AI agent toolkit: generate language responses, search the web, extract content, and manage memory across 10+ LLM providers.",
5
5
  "author": "vtempest <grokthiscontact@gmail.com>",
6
6
  "license": "AGPL-3.0",
@@ -36,6 +36,26 @@ export function normalizeSourcesOutput(output: unknown, query: string): Document
36
36
  return buildFallbackDocs(query);
37
37
  }
38
38
 
39
+ /**
40
+ * Resolves an uploaded fileId to its extracted `{ title, content }` payload.
41
+ * Hosts register a loader (e.g. reading the native R2 binding) so the search
42
+ * pipeline does not depend on filesystem or credential-based access.
43
+ */
44
+ export type UploadFileLoader = (
45
+ fileId: string,
46
+ ) => Promise<{ title: string; content: string } | null>;
47
+
48
+ let uploadFileLoader: UploadFileLoader | null = null;
49
+
50
+ /**
51
+ * Registers the loader used by {@link rerankDocs} to resolve uploaded
52
+ * fileIds to extracted content. The registered loader takes precedence over
53
+ * the S3-credentials fallback.
54
+ */
55
+ export function registerUploadFileLoader(loader: UploadFileLoader): void {
56
+ uploadFileLoader = loader;
57
+ }
58
+
39
59
  async function downloadExtractedContent(fileId: string, r2Credentials: R2CredentialsInput): Promise<{ title: string; content: string } | null> {
40
60
  try {
41
61
  const { manageStorage } = await import("manage-storage");
@@ -69,9 +89,25 @@ export async function rerankDocs(
69
89
 
70
90
  let filesData: { title: string; content: string }[] = [];
71
91
 
72
- if (fileIds.length > 0 && r2Credentials) {
92
+ if (fileIds.length > 0) {
73
93
  const results = await Promise.all(
74
- fileIds.map((fileId) => downloadExtractedContent(fileId, r2Credentials))
94
+ fileIds.map(async (fileId) => {
95
+ if (uploadFileLoader) {
96
+ try {
97
+ const loaded = await uploadFileLoader(fileId);
98
+ if (loaded) return loaded;
99
+ } catch (error) {
100
+ console.error(
101
+ `[rerankDocs] Registered upload loader failed for fileId ${fileId}:`,
102
+ error,
103
+ );
104
+ }
105
+ }
106
+ if (r2Credentials) {
107
+ return downloadExtractedContent(fileId, r2Credentials);
108
+ }
109
+ return null;
110
+ }),
75
111
  );
76
112
  filesData = results.filter((r) => r !== null);
77
113
  }
@@ -10,4 +10,5 @@ export { default as generateSuggestions } from "./suggestionGeneratorAgent";
10
10
  export { groupAndSummarizeDocs } from "./link-summarizer";
11
11
  export type { Document } from "./document";
12
12
  export { splitTextIntoChunks } from "./document";
13
- export { buildFallbackDocs, rerankDocs, processDocs, normalizeSourcesOutput } from "./doc-utils";
13
+ export { buildFallbackDocs, rerankDocs, processDocs, normalizeSourcesOutput, registerUploadFileLoader } from "./doc-utils";
14
+ export type { UploadFileLoader } from "./doc-utils";