chat-agent-toolkit 1.2.300 → 1.2.301

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.
@@ -8,7 +8,9 @@ export interface ChatTurnMessage {
8
8
  /** A `[role, content]` tuple used for few-shot prompt examples. */
9
9
  export type FewShotExample = [role: "user" | "assistant", content: string];
10
10
  export interface MetaSearchAgentType {
11
- searchAndAnswer: (message: string, history: ChatTurnMessage[], llm: LanguageModel, optimizationMode: "speed" | "balanced" | "quality", fileIds: string[], systemInstructions: string, category?: string, sourceExtractionEnabled?: boolean, thinkingTimeLimit?: number) => Promise<EventEmitter>;
11
+ searchAndAnswer: (message: string, history: ChatTurnMessage[], llm: LanguageModel, optimizationMode: "speed" | "balanced" | "quality", fileIds: string[], systemInstructions: string, category?: string, sourceExtractionEnabled?: boolean, thinkingTimeLimit?: number,
12
+ /** User-authored replacement for the focus mode's query-expansion prompt. */
13
+ queryExpansionPrompt?: string) => Promise<EventEmitter>;
12
14
  }
13
15
  /** Emitted on the EventEmitter data channel to report live search progress. */
14
16
  export interface SearchingEvent {
@@ -16,6 +16,6 @@ declare class MetaSearchAgent implements MetaSearchAgentType {
16
16
  * "response", "searching", "end", and "error" events on the emitter.
17
17
  */
18
18
  private runPipeline;
19
- searchAndAnswer(message: string, history: ChatTurnMessage[], llm: LanguageModel, optimizationMode: "speed" | "balanced" | "quality", fileIds: string[], systemInstructions: string, category?: string, sourceExtractionEnabled?: boolean, thinkingTimeLimit?: number): Promise<EventEmitter<any>>;
19
+ searchAndAnswer(message: string, history: ChatTurnMessage[], llm: LanguageModel, optimizationMode: "speed" | "balanced" | "quality", fileIds: string[], systemInstructions: string, category?: string, sourceExtractionEnabled?: boolean, thinkingTimeLimit?: number, queryExpansionPrompt?: string): Promise<EventEmitter<any>>;
20
20
  }
21
21
  export default MetaSearchAgent;
@@ -3,6 +3,12 @@ import { ChatTurnMessage } from './meta-search-types';
3
3
  type SuggestionGeneratorInput = {
4
4
  chat_history: ChatTurnMessage[];
5
5
  maxQuestions?: number;
6
+ /**
7
+ * Optional user-authored replacement for {@link followUpSuggestionsPrompt}
8
+ * (edited in Settings → Search Settings). Blank or whitespace-only values
9
+ * fall back to the built-in template.
10
+ */
11
+ promptTemplate?: string;
6
12
  };
7
13
  declare const generateSuggestions: (input: SuggestionGeneratorInput, llm: LanguageModel) => Promise<string[]>;
8
14
  export default generateSuggestions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chat-agent-toolkit",
3
- "version": "1.2.300",
3
+ "version": "1.2.301",
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": "rights.institute/PROSPER",
@@ -98,7 +98,7 @@
98
98
  "html-entities": "^2.6.0",
99
99
  "manage-storage": "^0.0.47",
100
100
  "marked": "^18.0.12",
101
- "qwksearch-api-client": "^0.9.242",
101
+ "qwksearch-api-client": "^0.9.243",
102
102
  "write-language": "^0.1.153",
103
103
  "zod": "^4.5.4"
104
104
  },
@@ -92,6 +92,30 @@ https://example.com
92
92
  ],
93
93
  ];
94
94
 
95
+ /**
96
+ * Default template for generating follow-up question suggestions after an
97
+ * answer. Interpolated with `{maxQuestions}` and `{chat_history}`.
98
+ *
99
+ * Exported (rather than inlined in the suggestion agent) so the settings UI can
100
+ * show the live default in an editable textarea and users can override it.
101
+ */
102
+ export const followUpSuggestionsPrompt = `
103
+ You are an AI suggestion generator for an AI powered search engine. You will be given a conversation below. You need to generate {maxQuestions} suggestions based on the conversation. The suggestion should be relevant to the conversation that can be used by the user to ask the chat model for more information.
104
+ You need to make sure the suggestions are relevant to the conversation and are helpful to the user. Keep a note that the user might use these suggestions to ask a chat model for more information.
105
+ Make sure the suggestions are medium in length and are informative and relevant to the conversation.
106
+
107
+ Provide these suggestions separated by newlines between the XML tags <suggestions> and </suggestions>. For example:
108
+
109
+ <suggestions>
110
+ Tell me more about SpaceX and their recent projects
111
+ What is the latest news on SpaceX?
112
+ Who is the CEO of SpaceX?
113
+ </suggestions>
114
+
115
+ Conversation:
116
+ {chat_history}
117
+ `;
118
+
95
119
  export const webSearchResponsePrompt = `
96
120
  You are QwkSearch, an AI model skilled in web search and crafting detailed, engaging, and well-structured answers. You excel at summarizing web pages and extracting relevant information to create professional, blog-style responses.
97
121
 
@@ -163,4 +187,5 @@ export default {
163
187
  webSearchRetrieverPrompt,
164
188
  webSearchRetrieverFewShots,
165
189
  writingAssistantPrompt,
190
+ followUpSuggestionsPrompt,
166
191
  };
@@ -25,6 +25,8 @@ export interface MetaSearchAgentType {
25
25
  category?: string,
26
26
  sourceExtractionEnabled?: boolean,
27
27
  thinkingTimeLimit?: number,
28
+ /** User-authored replacement for the focus mode's query-expansion prompt. */
29
+ queryExpansionPrompt?: string,
28
30
  ) => Promise<EventEmitter>;
29
31
  }
30
32
 
@@ -88,11 +88,19 @@ class MetaSearchAgent implements MetaSearchAgentType {
88
88
  sourceExtractionEnabled = false,
89
89
  thinkingTimeLimit = 0,
90
90
  emitter?: EventEmitter,
91
+ queryGeneratorPromptOverride?: string,
91
92
  ): Promise<{ query: string; docs: Document[] }> {
93
+ // A user-authored query-expansion prompt (Settings → Search Settings)
94
+ // replaces the focus mode's built-in one. Blank or whitespace-only text
95
+ // means "use the built-in prompt".
96
+ const queryGeneratorPrompt = queryGeneratorPromptOverride?.trim()
97
+ ? queryGeneratorPromptOverride
98
+ : this.config.queryGeneratorPrompt;
99
+
92
100
  const { text: retrieverOutput } = await generateText({
93
101
  model: llm,
94
102
  temperature: 0,
95
- system: this.config.queryGeneratorPrompt,
103
+ system: queryGeneratorPrompt,
96
104
  messages: [
97
105
  ...this.config.queryGeneratorFewShots.map(([role, content]) => ({
98
106
  role,
@@ -333,6 +341,7 @@ class MetaSearchAgent implements MetaSearchAgentType {
333
341
  category: string,
334
342
  sourceExtractionEnabled: boolean,
335
343
  thinkingTimeLimit: number,
344
+ queryExpansionPrompt?: string,
336
345
  ): Promise<void> {
337
346
  try {
338
347
  let docs: Document[] | null = null;
@@ -347,6 +356,7 @@ class MetaSearchAgent implements MetaSearchAgentType {
347
356
  sourceExtractionEnabled,
348
357
  thinkingTimeLimit,
349
358
  emitter,
359
+ queryExpansionPrompt,
350
360
  );
351
361
  query = result.query;
352
362
  docs = result.docs;
@@ -454,6 +464,7 @@ class MetaSearchAgent implements MetaSearchAgentType {
454
464
  category: string = "general",
455
465
  sourceExtractionEnabled = false,
456
466
  thinkingTimeLimit = 0,
467
+ queryExpansionPrompt?: string,
457
468
  ) {
458
469
  const emitter = new EventEmitter();
459
470
 
@@ -471,6 +482,7 @@ class MetaSearchAgent implements MetaSearchAgentType {
471
482
  category,
472
483
  sourceExtractionEnabled,
473
484
  thinkingTimeLimit,
485
+ queryExpansionPrompt,
474
486
  );
475
487
  }, 0);
476
488
 
@@ -6,28 +6,18 @@
6
6
  import { generateText, type LanguageModel } from "ai";
7
7
  import { LineListOutputParser } from "../../utils/outputParser";
8
8
  import { formatChatHistoryAsString } from "../../utils";
9
+ import { followUpSuggestionsPrompt } from "../../prompts/search-prompts";
9
10
  import type { ChatTurnMessage } from "./meta-search-types";
10
11
 
11
- const createSuggestionGeneratorPrompt = (maxQuestions: number = 4) => `
12
- You are an AI suggestion generator for an AI powered search engine. You will be given a conversation below. You need to generate ${maxQuestions} suggestions based on the conversation. The suggestion should be relevant to the conversation that can be used by the user to ask the chat model for more information.
13
- You need to make sure the suggestions are relevant to the conversation and are helpful to the user. Keep a note that the user might use these suggestions to ask a chat model for more information.
14
- Make sure the suggestions are medium in length and are informative and relevant to the conversation.
15
-
16
- Provide these suggestions separated by newlines between the XML tags <suggestions> and </suggestions>. For example:
17
-
18
- <suggestions>
19
- Tell me more about SpaceX and their recent projects
20
- What is the latest news on SpaceX?
21
- Who is the CEO of SpaceX?
22
- </suggestions>
23
-
24
- Conversation:
25
- {chat_history}
26
- `;
27
-
28
12
  type SuggestionGeneratorInput = {
29
13
  chat_history: ChatTurnMessage[];
30
14
  maxQuestions?: number;
15
+ /**
16
+ * Optional user-authored replacement for {@link followUpSuggestionsPrompt}
17
+ * (edited in Settings → Search Settings). Blank or whitespace-only values
18
+ * fall back to the built-in template.
19
+ */
20
+ promptTemplate?: string;
31
21
  };
32
22
 
33
23
  const outputParser = new LineListOutputParser({
@@ -39,10 +29,15 @@ const generateSuggestions = async (
39
29
  llm: LanguageModel,
40
30
  ): Promise<string[]> => {
41
31
  const maxQuestions = input.maxQuestions ?? 4;
42
- const prompt = createSuggestionGeneratorPrompt(maxQuestions).replace(
43
- "{chat_history}",
44
- formatChatHistoryAsString(input.chat_history),
45
- );
32
+ const template = input.promptTemplate?.trim()
33
+ ? input.promptTemplate
34
+ : followUpSuggestionsPrompt;
35
+
36
+ const prompt = template
37
+ .split("{maxQuestions}")
38
+ .join(String(maxQuestions))
39
+ .split("{chat_history}")
40
+ .join(formatChatHistoryAsString(input.chat_history));
46
41
 
47
42
  const { text } = await generateText({
48
43
  model: llm,