chat-agent-toolkit 1.2.379 → 1.2.381

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 CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  <!-- template-git-repo:badges:start -->
6
6
  <p align="center">
7
- <a href="https://qwksearch.com/api/docs"><img src="https://img.shields.io/badge/Docs-blue?logo=ReadTheDocs&logoColor=white" alt="Documentation" /></a>
7
+ <a href="https://qwksearch.com/api"><img src="https://img.shields.io/badge/Docs-blue?logo=ReadTheDocs&logoColor=white" alt="Documentation" /></a>
8
8
  <br />
9
9
  <a href="https://github.com/OpenSourceAGI/qwksearch-research-agent/stargazers"><img src="https://img.shields.io/github/stars/OpenSourceAGI/qwksearch-research-agent" alt="GitHub Stars" /></a>
10
10
  <a href="https://www.npmjs.com/package/chat-agent-toolkit"><img src="https://img.shields.io/npm/dm/chat-agent-toolkit.svg" alt="NPM Monthly Downloads" /></a>
@@ -81,8 +81,8 @@ export declare const AGENT_TOOLS: ({
81
81
  bypassCaptcha: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
82
82
  sessionId: z.ZodDefault<z.ZodOptional<z.ZodString>>;
83
83
  format: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
84
- html: "html";
85
84
  json: "json";
85
+ html: "html";
86
86
  }>>>;
87
87
  scraperUrl: z.ZodOptional<z.ZodString>;
88
88
  scraperApiKey: z.ZodOptional<z.ZodString>;
@@ -35,11 +35,42 @@ export type UploadFileLoader = (fileId: string) => Promise<LoadedUpload | null>;
35
35
  * the S3-credentials fallback.
36
36
  */
37
37
  export declare function registerUploadFileLoader(loader: UploadFileLoader): void;
38
+ /**
39
+ * Resolves every uploaded fileId once, in order.
40
+ *
41
+ * Two things here are deliberate, and both are about the 128MB an edge isolate
42
+ * gets. An attachment arrives as a JSON object whose `image` field is a data
43
+ * URL, so an 8MB picture is ~11MB of base64 that exists twice while it is
44
+ * parsed — and a request may carry ten of them. So: resolved **sequentially**,
45
+ * to keep one raw payload live at a time rather than ten; and resolved **once**
46
+ * per request, with the result shared by the reranker and the image loader,
47
+ * which between them used to fetch and parse every attachment twice over.
48
+ *
49
+ * Duplicate ids in the list collapse to one fetch. A file that cannot be
50
+ * resolved is dropped, exactly as before.
51
+ */
52
+ export declare function loadUploads(fileIds: string[], r2Credentials?: R2CredentialsInput): Promise<LoadedUpload[]>;
53
+ /**
54
+ * Picks the image attachments out of already-resolved uploads, ready to be
55
+ * passed to the LLM as image content parts. Documents and images stored
56
+ * without inline data carry no `image`, so they drop out here.
57
+ */
58
+ export declare function selectUploadImages(uploads: LoadedUpload[]): UploadImageAttachment[];
38
59
  /**
39
60
  * Resolves image attachments for the given uploaded fileIds so they can be
40
61
  * passed to the LLM as image content parts. Non-image uploads (documents) and
41
62
  * images stored without inline data are skipped.
63
+ *
64
+ * Pass `preloaded` when the uploads have already been resolved for this
65
+ * request — {@link loadUploads} explains why fetching them twice is worth
66
+ * avoiding.
67
+ */
68
+ export declare function loadUploadImages(fileIds: string[], r2Credentials?: R2CredentialsInput, preloaded?: LoadedUpload[]): Promise<UploadImageAttachment[]>;
69
+ /**
70
+ * Builds the answer context: uploaded file content first, then web results.
71
+ *
72
+ * Pass `preloaded` when the uploads have already been resolved for this
73
+ * request — see {@link loadUploads}.
42
74
  */
43
- export declare function loadUploadImages(fileIds: string[], r2Credentials?: R2CredentialsInput): Promise<UploadImageAttachment[]>;
44
- export declare function rerankDocs(query: string, docs: Document[], fileIds: string[], optimizationMode: "speed" | "balanced" | "quality", r2Credentials?: R2CredentialsInput): Promise<Document[]>;
75
+ export declare function rerankDocs(query: string, docs: Document[], fileIds: string[], optimizationMode: "speed" | "balanced" | "quality", r2Credentials?: R2CredentialsInput, preloaded?: LoadedUpload[]): Promise<Document[]>;
45
76
  export declare function processDocs(docs: Document[]): string;
@@ -3,11 +3,11 @@
3
3
  * @description Meta search agent tools for AI-powered web search and research
4
4
  */
5
5
  export { default as MetaSearchAgent } from './metaSearchAgent';
6
- export type { MetaSearchAgentType, Config, ChatTurnMessage, SearchingEvent, FewShotExample } from './meta-search-types';
6
+ export type { MetaSearchAgentType, Config, ChatTurnMessage, DrainableEmitter, SearchingEvent, FewShotExample } from './meta-search-types';
7
7
  export { searchHandlers, createSearchHandlers } from './search-handlers';
8
8
  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, registerUploadFileLoader, loadUploadImages } from './doc-utils';
12
+ export { buildFallbackDocs, rerankDocs, processDocs, normalizeSourcesOutput, registerUploadFileLoader, loadUploads, loadUploadImages, selectUploadImages } from './doc-utils';
13
13
  export type { UploadFileLoader, LoadedUpload, UploadImageAttachment } from './doc-utils';
@@ -7,10 +7,23 @@ export interface ChatTurnMessage {
7
7
  }
8
8
  /** A `[role, content]` tuple used for few-shot prompt examples. */
9
9
  export type FewShotExample = [role: "user" | "assistant", content: string];
10
+ /**
11
+ * The pipeline's event emitter, plus the hook a consumer uses to push back.
12
+ *
13
+ * `emit()` is synchronous, so the answer loop would otherwise pull the entire
14
+ * model stream into memory at the model's pace while the consumer writes it
15
+ * out at the client's pace. A consumer that can be slow (an HTTP response
16
+ * stream, say) assigns `waitForDrain`; the loop awaits it between chunks and
17
+ * so advances no faster than the consumer does. Leaving it unset keeps the
18
+ * unthrottled behaviour, which is what an in-process consumer wants.
19
+ */
20
+ export interface DrainableEmitter extends EventEmitter {
21
+ waitForDrain?: () => Promise<void>;
22
+ }
10
23
  export interface MetaSearchAgentType {
11
24
  searchAndAnswer: (message: string, history: ChatTurnMessage[], llm: LanguageModel, optimizationMode: "speed" | "balanced" | "quality", fileIds: string[], systemInstructions: string, category?: string, sourceExtractionEnabled?: boolean, thinkingTimeLimit?: number,
12
25
  /** User-authored replacement for the focus mode's query-expansion prompt. */
13
- queryExpansionPrompt?: string) => Promise<EventEmitter>;
26
+ queryExpansionPrompt?: string) => Promise<DrainableEmitter>;
14
27
  }
15
28
  /** Emitted on the EventEmitter data channel to report live search progress. */
16
29
  export interface SearchingEvent {
@@ -1,7 +1,7 @@
1
1
  import { LanguageModel } from 'ai';
2
2
  import { default as EventEmitter } from 'events';
3
3
  import { Config, ChatTurnMessage, MetaSearchAgentType } from './meta-search-types';
4
- export type { MetaSearchAgentType, Config } from './meta-search-types';
4
+ export type { MetaSearchAgentType, Config, DrainableEmitter } from './meta-search-types';
5
5
  declare class MetaSearchAgent implements MetaSearchAgentType {
6
6
  private config;
7
7
  constructor(config: Config);