aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/chatbot/tools')
-rw-r--r--src/client/views/nodes/chatbot/tools/BaseTool.ts4
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts59
-rw-r--r--src/client/views/nodes/chatbot/tools/SearchTool.ts3
-rw-r--r--src/client/views/nodes/chatbot/tools/ToolTypes.ts30
-rw-r--r--src/client/views/nodes/chatbot/tools/WikipediaTool.ts2
5 files changed, 64 insertions, 34 deletions
diff --git a/src/client/views/nodes/chatbot/tools/BaseTool.ts b/src/client/views/nodes/chatbot/tools/BaseTool.ts
index 58cd514d9..b6091af6c 100644
--- a/src/client/views/nodes/chatbot/tools/BaseTool.ts
+++ b/src/client/views/nodes/chatbot/tools/BaseTool.ts
@@ -1,5 +1,5 @@
import { Observation } from '../types/types';
-import { Parameter, Tool, ParametersType } from './ToolTypes';
+import { Parameter, ParametersType } from './ToolTypes';
/**
* @file BaseTool.ts
@@ -14,7 +14,7 @@ import { Parameter, Tool, ParametersType } from './ToolTypes';
* It is generic over a type parameter `P`, which extends `ReadonlyArray<Parameter>`.
* This means `P` is a readonly array of `Parameter` objects that cannot be modified (immutable).
*/
-export abstract class BaseTool<P extends ReadonlyArray<Parameter>> implements Tool<P> {
+export abstract class BaseTool<P extends ReadonlyArray<Parameter>> {
// The name of the tool (e.g., "calculate", "searchTool")
name: string;
// A description of the tool's functionality
diff --git a/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts b/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts
new file mode 100644
index 000000000..fa978bdc3
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts
@@ -0,0 +1,59 @@
+import { v4 as uuidv4 } from 'uuid';
+import { Networking } from '../../../../Network';
+import { BaseTool } from './BaseTool';
+import { Observation } from '../types/types';
+import { ParametersType } from './ToolTypes';
+import { DocumentOptions } from '../../../../documents/Documents';
+
+const createTextDocToolParams = [
+ {
+ name: 'text_content',
+ type: 'string',
+ description: 'The text content that the document will display',
+ required: true,
+ },
+ {
+ name: 'title',
+ type: 'string',
+ description: 'The title of the document',
+ required: true,
+ },
+ {
+ name: 'background_color',
+ type: 'string',
+ description: 'The background color of the document as a hex string',
+ required: false,
+ },
+ {
+ name: 'font_color',
+ type: 'string',
+ description: 'The font color of the document as a hex string',
+ required: false,
+ },
+] as const;
+
+type CreateTextDocToolParamsType = typeof createTextDocToolParams;
+
+export class CreateTextDocTool extends BaseTool<CreateTextDocToolParamsType> {
+ private _addLinkedTextDoc: (text_content: string, options: DocumentOptions, id: string) => void;
+
+ constructor(addLinkedTextDoc: (text_content: string, options: DocumentOptions, id: string) => void) {
+ super(
+ 'createTextDoc',
+ 'Creates a text document with the provided content and title (and of specified other options if wanted)',
+ createTextDocToolParams,
+ 'Provide the text content and title (and optionally color) for the document.',
+ 'Creates a text document with the provided content and title (and of specified other options if wanted). Use if the user wants to create a textbox or text document of some sort. Can use after a search or other tool to save information.'
+ );
+ this._addLinkedTextDoc = addLinkedTextDoc;
+ }
+
+ async execute(args: ParametersType<CreateTextDocToolParamsType>): Promise<Observation[]> {
+ try {
+ this._addLinkedTextDoc(args.text_content, { title: args.title, backgroundColor: args.background_color, text_fontColor: args.font_color }, uuidv4());
+ return [{ type: 'text', text: 'Created text document.' }];
+ } catch (error) {
+ return [{ type: 'text', text: 'Error creating text document, ' + error }];
+ }
+ }
+}
diff --git a/src/client/views/nodes/chatbot/tools/SearchTool.ts b/src/client/views/nodes/chatbot/tools/SearchTool.ts
index fd5144dd6..267dab6ff 100644
--- a/src/client/views/nodes/chatbot/tools/SearchTool.ts
+++ b/src/client/views/nodes/chatbot/tools/SearchTool.ts
@@ -44,9 +44,10 @@ export class SearchTool extends BaseTool<SearchToolParamsType> {
});
const data = results.map((result: { url: string; snippet: string }) => {
const id = uuidv4();
+ this._addLinkedUrlDoc(result.url, id);
return {
type: 'text',
- text: `<chunk chunk_id="${id}" chunk_type="text"><url>${result.url}</url><overview>${result.snippet}</overview></chunk>`,
+ text: `<chunk chunk_id="${id}" chunk_type="url"><url>${result.url}</url><overview>${result.snippet}</overview></chunk>`,
};
});
return data;
diff --git a/src/client/views/nodes/chatbot/tools/ToolTypes.ts b/src/client/views/nodes/chatbot/tools/ToolTypes.ts
index d47a38952..cc29d70f1 100644
--- a/src/client/views/nodes/chatbot/tools/ToolTypes.ts
+++ b/src/client/views/nodes/chatbot/tools/ToolTypes.ts
@@ -1,34 +1,4 @@
import { Observation } from '../types/types';
-
-/**
- * The `Tool` interface represents a generic tool in the system.
- * It is generic over a type parameter `P`, which extends `ReadonlyArray<Parameter>`.
- * @template P - An array of `Parameter` objects defining the tool's parameters.
- */
-export interface Tool<P extends ReadonlyArray<Parameter>> {
- // The name of the tool (e.g., "calculate", "searchTool")
- name: string;
- // A description of the tool's functionality
- description: string;
- // An array of parameter definitions for the tool
- parameterRules: P;
- // Guidelines for how to handle citations when using the tool
- citationRules: string;
- // A brief summary of the tool's purpose
- briefSummary: string;
- /**
- * Executes the tool's main functionality.
- * @param args - The arguments for execution, with types inferred from `ParametersType<P>`.
- * @returns A promise that resolves to an array of `Observation` objects.
- */
- execute: (args: ParametersType<P>) => Promise<Observation[]>;
- /**
- * Generates an action rule object that describes the tool's usage.
- * @returns An object representing the tool's action rules.
- */
- getActionRule: () => Record<string, unknown>;
-}
-
/**
* The `Parameter` type defines the structure of a parameter configuration.
*/
diff --git a/src/client/views/nodes/chatbot/tools/WikipediaTool.ts b/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
index 4fcffe2ed..966ca7708 100644
--- a/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
+++ b/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
@@ -38,7 +38,7 @@ export class WikipediaTool extends BaseTool<WikipediaToolParamsType> {
return [
{
type: 'text',
- text: `<chunk chunk_id="${id}" chunk_type="text"> ${text} </chunk>`,
+ text: `<chunk chunk_id="${id}" chunk_type="url"> ${text} </chunk>`,
},
];
} catch (error) {