@promptbook/wizard 0.100.0-14 → 0.100.0-16
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/esm/index.es.js +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +14 -0
- package/esm/typings/src/_packages/types.index.d.ts +28 -0
- package/esm/typings/src/book-2.0/agent-source/parseAgentSource.d.ts +30 -0
- package/esm/typings/src/book-2.0/agent-source/parseAgentSource.test.d.ts +1 -0
- package/esm/typings/src/book-2.0/agent-source/string_agent_source.d.ts +42 -0
- package/esm/typings/src/book-2.0/commitments/ACTION/ACTION.d.ts +30 -0
- package/esm/typings/src/book-2.0/commitments/FORMAT/FORMAT.d.ts +31 -0
- package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/FrontendRAGService.d.ts +48 -0
- package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +43 -0
- package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/RAGService.d.ts +54 -0
- package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/processors/BaseKnowledgeProcessor.d.ts +45 -0
- package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/processors/PdfProcessor.d.ts +31 -0
- package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/processors/ProcessorFactory.d.ts +23 -0
- package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/processors/TextProcessor.d.ts +18 -0
- package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/types.d.ts +56 -0
- package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/utils/ragHelper.d.ts +34 -0
- package/esm/typings/src/book-2.0/commitments/META_IMAGE/META_IMAGE.d.ts +36 -0
- package/esm/typings/src/book-2.0/commitments/META_LINK/META_LINK.d.ts +48 -0
- package/esm/typings/src/book-2.0/commitments/MODEL/MODEL.d.ts +31 -0
- package/esm/typings/src/book-2.0/commitments/NOTE/NOTE.d.ts +41 -0
- package/esm/typings/src/book-2.0/commitments/PERSONA/PERSONA.d.ts +38 -0
- package/esm/typings/src/book-2.0/commitments/RULE/RULE.d.ts +36 -0
- package/esm/typings/src/book-2.0/commitments/SAMPLE/SAMPLE.d.ts +36 -0
- package/esm/typings/src/book-2.0/commitments/STYLE/STYLE.d.ts +30 -0
- package/esm/typings/src/book-2.0/commitments/_base/BaseCommitmentDefinition.d.ts +43 -0
- package/esm/typings/src/book-2.0/commitments/_base/BookCommitment.d.ts +5 -0
- package/esm/typings/src/book-2.0/commitments/_base/CommitmentDefinition.d.ts +37 -0
- package/esm/typings/src/book-2.0/commitments/_base/NotYetImplementedCommitmentDefinition.d.ts +15 -0
- package/esm/typings/src/book-2.0/commitments/_base/createEmptyAgentModelRequirements.d.ts +19 -0
- package/esm/typings/src/book-2.0/commitments/_misc/AgentModelRequirements.d.ts +37 -0
- package/esm/typings/src/book-2.0/commitments/_misc/AgentSourceParseResult.d.ts +18 -0
- package/esm/typings/src/book-2.0/commitments/_misc/ParsedCommitment.d.ts +22 -0
- package/esm/typings/src/book-2.0/commitments/_misc/createAgentModelRequirements.d.ts +61 -0
- package/esm/typings/src/book-2.0/commitments/_misc/createAgentModelRequirementsWithCommitments.d.ts +35 -0
- package/esm/typings/src/book-2.0/commitments/_misc/createCommitmentRegex.d.ts +20 -0
- package/esm/typings/src/book-2.0/commitments/_misc/parseAgentSourceWithCommitments.d.ts +24 -0
- package/esm/typings/src/book-2.0/commitments/_misc/removeCommentsFromSystemMessage.d.ts +11 -0
- package/esm/typings/src/book-2.0/commitments/index.d.ts +54 -0
- package/esm/typings/src/book-2.0/utils/profileImageUtils.d.ts +39 -0
- package/esm/typings/src/types/typeAliases.d.ts +6 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +1 -1
package/esm/index.es.js
CHANGED
@@ -38,7 +38,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
38
38
|
* @generated
|
39
39
|
* @see https://github.com/webgptorg/promptbook
|
40
40
|
*/
|
41
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-
|
41
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-16';
|
42
42
|
/**
|
43
43
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
44
44
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
@@ -1,4 +1,11 @@
|
|
1
1
|
import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../version';
|
2
|
+
import { parseAgentSource } from '../book-2.0/agent-source/parseAgentSource';
|
3
|
+
import { isAgentSource } from '../book-2.0/agent-source/string_agent_source';
|
4
|
+
import { validateAgentSource } from '../book-2.0/agent-source/string_agent_source';
|
5
|
+
import { createEmptyAgentModelRequirements } from '../book-2.0/commitments/_base/createEmptyAgentModelRequirements';
|
6
|
+
import { createBasicAgentModelRequirements } from '../book-2.0/commitments/_base/createEmptyAgentModelRequirements';
|
7
|
+
import { NotYetImplementedCommitmentDefinition } from '../book-2.0/commitments/_base/NotYetImplementedCommitmentDefinition';
|
8
|
+
import { createAgentModelRequirements } from '../book-2.0/commitments/_misc/createAgentModelRequirements';
|
2
9
|
import { collectionToJson } from '../collection/collectionToJson';
|
3
10
|
import { createCollectionFromJson } from '../collection/constructors/createCollectionFromJson';
|
4
11
|
import { createCollectionFromPromise } from '../collection/constructors/createCollectionFromPromise';
|
@@ -148,6 +155,13 @@ import { SectionTypes } from '../types/SectionType';
|
|
148
155
|
import { TaskTypes } from '../types/TaskType';
|
149
156
|
import { REMOTE_SERVER_URLS } from '../../servers';
|
150
157
|
export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION };
|
158
|
+
export { parseAgentSource };
|
159
|
+
export { isAgentSource };
|
160
|
+
export { validateAgentSource };
|
161
|
+
export { createEmptyAgentModelRequirements };
|
162
|
+
export { createBasicAgentModelRequirements };
|
163
|
+
export { NotYetImplementedCommitmentDefinition };
|
164
|
+
export { createAgentModelRequirements };
|
151
165
|
export { collectionToJson };
|
152
166
|
export { createCollectionFromJson };
|
153
167
|
export { createCollectionFromPromise };
|
@@ -1,3 +1,16 @@
|
|
1
|
+
import type { AgentSourceBasicInformation } from '../book-2.0/agent-source/parseAgentSource';
|
2
|
+
import type { string_agent_source } from '../book-2.0/agent-source/string_agent_source';
|
3
|
+
import type { BookCommitment } from '../book-2.0/commitments/_base/BookCommitment';
|
4
|
+
import type { CommitmentDefinition } from '../book-2.0/commitments/_base/CommitmentDefinition';
|
5
|
+
import type { AgentModelRequirements } from '../book-2.0/commitments/_misc/AgentModelRequirements';
|
6
|
+
import type { AgentSourceParseResult } from '../book-2.0/commitments/_misc/AgentSourceParseResult';
|
7
|
+
import type { ParsedCommitment } from '../book-2.0/commitments/_misc/ParsedCommitment';
|
8
|
+
import type { KnowledgeSourceFormat } from '../book-2.0/commitments/KNOWLEDGE/types';
|
9
|
+
import type { KnowledgeSourceMetadata } from '../book-2.0/commitments/KNOWLEDGE/types';
|
10
|
+
import type { KnowledgeChunk } from '../book-2.0/commitments/KNOWLEDGE/types';
|
11
|
+
import type { KnowledgeBase } from '../book-2.0/commitments/KNOWLEDGE/types';
|
12
|
+
import type { RetrievalResult } from '../book-2.0/commitments/KNOWLEDGE/types';
|
13
|
+
import type { RAGConfig } from '../book-2.0/commitments/KNOWLEDGE/types';
|
1
14
|
import type { PipelineCollection } from '../collection/PipelineCollection';
|
2
15
|
import type { Command } from '../commands/_common/types/Command';
|
3
16
|
import type { CommandParser } from '../commands/_common/types/CommandParser';
|
@@ -177,6 +190,7 @@ import type { InputParameters } from '../types/typeAliases';
|
|
177
190
|
import type { string_reserved_parameter_name } from '../types/typeAliases';
|
178
191
|
import type { ReservedParameters } from '../types/typeAliases';
|
179
192
|
import type { string_title } from '../types/typeAliases';
|
193
|
+
import type { string_agent_name } from '../types/typeAliases';
|
180
194
|
import type { string_persona_description } from '../types/typeAliases';
|
181
195
|
import type { string_model_description } from '../types/typeAliases';
|
182
196
|
import type { string_knowledge_source_content } from '../types/typeAliases';
|
@@ -302,6 +316,19 @@ import type { TODO_any } from '../utils/organization/TODO_any';
|
|
302
316
|
import type { CheckSerializableAsJsonOptions } from '../utils/serialization/checkSerializableAsJson';
|
303
317
|
import type { ExportJsonOptions } from '../utils/serialization/exportJson';
|
304
318
|
import type { string_promptbook_version } from '../version';
|
319
|
+
export type { AgentSourceBasicInformation };
|
320
|
+
export type { string_agent_source };
|
321
|
+
export type { BookCommitment };
|
322
|
+
export type { CommitmentDefinition };
|
323
|
+
export type { AgentModelRequirements };
|
324
|
+
export type { AgentSourceParseResult };
|
325
|
+
export type { ParsedCommitment };
|
326
|
+
export type { KnowledgeSourceFormat };
|
327
|
+
export type { KnowledgeSourceMetadata };
|
328
|
+
export type { KnowledgeChunk };
|
329
|
+
export type { KnowledgeBase };
|
330
|
+
export type { RetrievalResult };
|
331
|
+
export type { RAGConfig };
|
305
332
|
export type { PipelineCollection };
|
306
333
|
export type { Command };
|
307
334
|
export type { CommandParser };
|
@@ -481,6 +508,7 @@ export type { InputParameters };
|
|
481
508
|
export type { string_reserved_parameter_name };
|
482
509
|
export type { ReservedParameters };
|
483
510
|
export type { string_title };
|
511
|
+
export type { string_agent_name };
|
484
512
|
export type { string_persona_description };
|
485
513
|
export type { string_model_description };
|
486
514
|
export type { string_knowledge_source_content };
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import type { string_agent_name } from '../../types/typeAliases';
|
2
|
+
import type { string_url_image } from '../../types/typeAliases';
|
3
|
+
import type { string_agent_source } from './string_agent_source';
|
4
|
+
export interface AgentSourceBasicInformation {
|
5
|
+
/**
|
6
|
+
* Name of the agent
|
7
|
+
* This is the first line of the agent source
|
8
|
+
*/
|
9
|
+
agentName: string_agent_name | null;
|
10
|
+
/**
|
11
|
+
* Optional description of the agent
|
12
|
+
* This is the line starting with "PERSONA"
|
13
|
+
*/
|
14
|
+
personaDescription: string | null;
|
15
|
+
/**
|
16
|
+
* Optional profile image URL
|
17
|
+
* This is the line starting with "META IMAGE"
|
18
|
+
*/
|
19
|
+
profileImageUrl: string_url_image;
|
20
|
+
}
|
21
|
+
/**
|
22
|
+
* Parses basic information from agent source
|
23
|
+
*
|
24
|
+
* There are 2 similar functions:
|
25
|
+
* - `parseAgentSource` which is a lightweight parser for agent source, it parses basic information and its purpose is to be quick and synchronous. The commitments there are hardcoded.
|
26
|
+
* - `createAgentModelRequirements` which is an asynchronous function that creates model requirements it applies each commitment one by one and works asynchronously.
|
27
|
+
*
|
28
|
+
* @public exported from `@promptbook/core`
|
29
|
+
*/
|
30
|
+
export declare function parseAgentSource(agentSource: string_agent_source): AgentSourceBasicInformation;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,42 @@
|
|
1
|
+
/**
|
2
|
+
* Branded type for agent source strings
|
3
|
+
*
|
4
|
+
* This ensures type safety when working with agent source data throughout the application.
|
5
|
+
* Agent source strings contain structured data in a specific format:
|
6
|
+
* - First line: Agent name
|
7
|
+
* - PERSONA line: Agent persona/description (optional)
|
8
|
+
* - META IMAGE line: Profile image URL (optional)
|
9
|
+
* - Remaining content: System message (after removing META IMAGE line)
|
10
|
+
*/
|
11
|
+
export type string_agent_source = string & {
|
12
|
+
readonly __brand: 'agent_source';
|
13
|
+
};
|
14
|
+
/**
|
15
|
+
* Type guard to check if a string is a valid agent source
|
16
|
+
*
|
17
|
+
* @public exported from `@promptbook/core`
|
18
|
+
*/
|
19
|
+
export declare function isAgentSource(value: string): value is string_agent_source;
|
20
|
+
/**
|
21
|
+
* Creates a branded agent source string from a regular string
|
22
|
+
* Performs basic validation to ensure the string is suitable as agent source
|
23
|
+
*
|
24
|
+
* @private
|
25
|
+
* @deprecated Use `validateAgentSource` instead - these functions are now equivalent
|
26
|
+
*/
|
27
|
+
export declare function createAgentSource(source: string): string_agent_source;
|
28
|
+
/**
|
29
|
+
* Safely converts a string to agent source with fallback
|
30
|
+
*
|
31
|
+
* @private
|
32
|
+
* @deprecated Use `validateAgentSource` instead - these functions are now equivalent
|
33
|
+
*/
|
34
|
+
export declare function toAgentSource(source: string, fallback?: string): string_agent_source;
|
35
|
+
/**
|
36
|
+
* Validates and converts a string to agent source branded type
|
37
|
+
* This function should be used when you have a string that you know represents agent source
|
38
|
+
* but need to convert it to the branded type for type safety
|
39
|
+
*
|
40
|
+
* @public exported from `@promptbook/core`
|
41
|
+
*/
|
42
|
+
export declare function validateAgentSource(source: string): string_agent_source;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { BaseCommitmentDefinition } from '../_base/BaseCommitmentDefinition';
|
2
|
+
import type { AgentModelRequirements } from '../_misc/AgentModelRequirements';
|
3
|
+
/**
|
4
|
+
* ACTION commitment definition
|
5
|
+
*
|
6
|
+
* The ACTION commitment defines specific actions or capabilities that the agent can perform.
|
7
|
+
* This helps define what the agent is capable of doing and how it should approach tasks.
|
8
|
+
*
|
9
|
+
* Example usage in agent source:
|
10
|
+
*
|
11
|
+
* ```book
|
12
|
+
* ACTION Can generate code snippets and explain programming concepts
|
13
|
+
* ACTION Able to analyze data and provide insights
|
14
|
+
* ```
|
15
|
+
*
|
16
|
+
* @private [🪔] Maybe export the commitments through some package
|
17
|
+
*/
|
18
|
+
export declare class ActionCommitmentDefinition extends BaseCommitmentDefinition {
|
19
|
+
constructor();
|
20
|
+
applyToAgentModelRequirements(requirements: AgentModelRequirements, content: string): AgentModelRequirements;
|
21
|
+
}
|
22
|
+
/**
|
23
|
+
* Singleton instance of the ACTION commitment definition
|
24
|
+
*
|
25
|
+
* @private [🪔] Maybe export the commitments through some package
|
26
|
+
*/
|
27
|
+
export declare const ActionCommitment: ActionCommitmentDefinition;
|
28
|
+
/**
|
29
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
30
|
+
*/
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { BaseCommitmentDefinition } from '../_base/BaseCommitmentDefinition';
|
2
|
+
import type { AgentModelRequirements } from '../_misc/AgentModelRequirements';
|
3
|
+
/**
|
4
|
+
* FORMAT commitment definition
|
5
|
+
*
|
6
|
+
* The FORMAT commitment defines the specific output structure and formatting
|
7
|
+
* that the agent should use in its responses. This includes data formats,
|
8
|
+
* response templates, and structural requirements.
|
9
|
+
*
|
10
|
+
* Example usage in agent source:
|
11
|
+
*
|
12
|
+
* ```book
|
13
|
+
* FORMAT Always respond in JSON format with 'status' and 'data' fields
|
14
|
+
* FORMAT Use markdown formatting for all code blocks
|
15
|
+
* ```
|
16
|
+
*
|
17
|
+
* @private [🪔] Maybe export the commitments through some package
|
18
|
+
*/
|
19
|
+
export declare class FormatCommitmentDefinition extends BaseCommitmentDefinition {
|
20
|
+
constructor();
|
21
|
+
applyToAgentModelRequirements(requirements: AgentModelRequirements, content: string): AgentModelRequirements;
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* Singleton instance of the FORMAT commitment definition
|
25
|
+
*
|
26
|
+
* @private [🪔] Maybe export the commitments through some package
|
27
|
+
*/
|
28
|
+
export declare const FormatCommitment: FormatCommitmentDefinition;
|
29
|
+
/**
|
30
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
31
|
+
*/
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import type { string_url } from '../../../types/typeAliases';
|
2
|
+
import type { RAGConfig } from './types';
|
3
|
+
import type { RetrievalResult } from './types';
|
4
|
+
/**
|
5
|
+
* Frontend RAG Service that uses backend APIs for processing
|
6
|
+
* This avoids Node.js dependencies in the frontend
|
7
|
+
*
|
8
|
+
* @private - TODO: [🧠] Maybe should be public?
|
9
|
+
*/
|
10
|
+
export declare class FrontendRAGService {
|
11
|
+
private chunks;
|
12
|
+
private sources;
|
13
|
+
private config;
|
14
|
+
private isInitialized;
|
15
|
+
constructor(config?: Partial<RAGConfig>);
|
16
|
+
/**
|
17
|
+
* Initialize knowledge sources by processing them on the backend
|
18
|
+
*/
|
19
|
+
initializeKnowledgeSources(sources: string_url[]): Promise<void>;
|
20
|
+
/**
|
21
|
+
* Get relevant context for a user query
|
22
|
+
*/
|
23
|
+
getContextForQuery(query: string): Promise<string>;
|
24
|
+
/**
|
25
|
+
* Get relevant chunks for a query (for debugging/inspection)
|
26
|
+
*/
|
27
|
+
getRelevantChunks(query: string): Promise<RetrievalResult[]>;
|
28
|
+
/**
|
29
|
+
* Get knowledge base statistics
|
30
|
+
*/
|
31
|
+
getStats(): {
|
32
|
+
sources: number;
|
33
|
+
chunks: number;
|
34
|
+
isInitialized: boolean;
|
35
|
+
};
|
36
|
+
/**
|
37
|
+
* Check if the service is ready to use
|
38
|
+
*/
|
39
|
+
isReady(): boolean;
|
40
|
+
/**
|
41
|
+
* Clear all knowledge sources
|
42
|
+
*/
|
43
|
+
clearKnowledgeBase(): void;
|
44
|
+
/**
|
45
|
+
* Add a single knowledge source (for incremental updates)
|
46
|
+
*/
|
47
|
+
addKnowledgeSource(url: string_url): Promise<void>;
|
48
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { BaseCommitmentDefinition } from '../_base/BaseCommitmentDefinition';
|
2
|
+
import type { AgentModelRequirements } from '../_misc/AgentModelRequirements';
|
3
|
+
import { FrontendRAGService } from './FrontendRAGService';
|
4
|
+
/**
|
5
|
+
* KNOWLEDGE commitment definition
|
6
|
+
*
|
7
|
+
* The KNOWLEDGE commitment adds specific knowledge, facts, or context to the agent
|
8
|
+
* using RAG (Retrieval-Augmented Generation) approach for external sources.
|
9
|
+
*
|
10
|
+
* Supports both direct text knowledge and external sources like PDFs.
|
11
|
+
*
|
12
|
+
* Example usage in agent source:
|
13
|
+
*
|
14
|
+
* ```book
|
15
|
+
* KNOWLEDGE The company was founded in 2020 and specializes in AI-powered solutions
|
16
|
+
* KNOWLEDGE https://example.com/company-handbook.pdf
|
17
|
+
* KNOWLEDGE https://example.com/product-documentation.pdf
|
18
|
+
* ```
|
19
|
+
*
|
20
|
+
* @private [🪔] Maybe export the commitments through some package
|
21
|
+
*/
|
22
|
+
export declare class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
|
23
|
+
private ragService;
|
24
|
+
constructor();
|
25
|
+
applyToAgentModelRequirements(requirements: AgentModelRequirements, content: string): AgentModelRequirements;
|
26
|
+
/**
|
27
|
+
* Check if content is a URL
|
28
|
+
*/
|
29
|
+
private isUrl;
|
30
|
+
/**
|
31
|
+
* Get RAG service instance for retrieving context during chat
|
32
|
+
*/
|
33
|
+
getRagService(): FrontendRAGService;
|
34
|
+
}
|
35
|
+
/**
|
36
|
+
* Singleton instance of the KNOWLEDGE commitment definition
|
37
|
+
*
|
38
|
+
* @private [🪔] Maybe export the commitments through some package
|
39
|
+
*/
|
40
|
+
export declare const KnowledgeCommitment: KnowledgeCommitmentDefinition;
|
41
|
+
/**
|
42
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
43
|
+
*/
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import type { string_url } from '../../../types/typeAliases';
|
2
|
+
import type { RAGConfig } from './types';
|
3
|
+
import type { RetrievalResult } from './types';
|
4
|
+
/**
|
5
|
+
* RAG (Retrieval-Augmented Generation) Service
|
6
|
+
* Handles knowledge source processing and retrieval
|
7
|
+
*
|
8
|
+
* @private
|
9
|
+
*/
|
10
|
+
export declare class RAGService {
|
11
|
+
private knowledgeBase;
|
12
|
+
private config;
|
13
|
+
constructor(config?: Partial<RAGConfig>);
|
14
|
+
/**
|
15
|
+
* Add a knowledge source from URL
|
16
|
+
*/
|
17
|
+
addKnowledgeSource(url: string_url): Promise<void>;
|
18
|
+
/**
|
19
|
+
* Retrieve relevant chunks for a query
|
20
|
+
*/
|
21
|
+
retrieveRelevantChunks(query: string): RetrievalResult[];
|
22
|
+
/**
|
23
|
+
* Get formatted context for the agent
|
24
|
+
*/
|
25
|
+
getContextForQuery(query: string): string;
|
26
|
+
/**
|
27
|
+
* Get knowledge base statistics
|
28
|
+
*/
|
29
|
+
getStats(): {
|
30
|
+
sources: number;
|
31
|
+
chunks: number;
|
32
|
+
lastUpdated: Date;
|
33
|
+
};
|
34
|
+
/**
|
35
|
+
* Clear all knowledge sources
|
36
|
+
*/
|
37
|
+
clearKnowledgeBase(): void;
|
38
|
+
/**
|
39
|
+
* Tokenize query into words for relevance scoring
|
40
|
+
*/
|
41
|
+
private tokenizeQuery;
|
42
|
+
/**
|
43
|
+
* Calculate relevance score between content and query words
|
44
|
+
* Simple keyword matching - in production, use embeddings
|
45
|
+
*/
|
46
|
+
private calculateRelevanceScore;
|
47
|
+
/**
|
48
|
+
* Generate content hash for caching
|
49
|
+
*/
|
50
|
+
private generateContentHash;
|
51
|
+
}
|
52
|
+
/**
|
53
|
+
* TODO: !!!! use the already existing RAG instead of this
|
54
|
+
*/
|
@@ -0,0 +1,45 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
import type { TODO_any } from '../../../../utils/organization/TODO_any';
|
4
|
+
import type { string_url } from '../../../../types/typeAliases';
|
5
|
+
import type { KnowledgeChunk } from '../types';
|
6
|
+
import type { KnowledgeSourceFormat } from '../types';
|
7
|
+
import type { RAGConfig } from '../types';
|
8
|
+
/**
|
9
|
+
* Base class for knowledge source processors
|
10
|
+
* Provides common functionality for all knowledge processors
|
11
|
+
*
|
12
|
+
* @private
|
13
|
+
*/
|
14
|
+
export declare abstract class BaseKnowledgeProcessor {
|
15
|
+
protected readonly config: RAGConfig;
|
16
|
+
constructor(config?: Partial<RAGConfig>);
|
17
|
+
/**
|
18
|
+
* The format this processor supports
|
19
|
+
*/
|
20
|
+
abstract readonly supportedFormat: KnowledgeSourceFormat;
|
21
|
+
/**
|
22
|
+
* Process a buffer and return knowledge chunks
|
23
|
+
*/
|
24
|
+
abstract processBuffer(buffer: Buffer, sourceUrl: string_url): Promise<KnowledgeChunk[]>;
|
25
|
+
/**
|
26
|
+
* Generate a content hash for caching purposes
|
27
|
+
*/
|
28
|
+
protected generateContentHash(content: string): string;
|
29
|
+
/**
|
30
|
+
* Generate a unique chunk ID
|
31
|
+
*/
|
32
|
+
protected generateChunkId(sourceUrl: string_url, chunkIndex: number): string;
|
33
|
+
/**
|
34
|
+
* Split text into sentences for better chunking
|
35
|
+
*/
|
36
|
+
protected splitIntoSentences(text: string): string[];
|
37
|
+
/**
|
38
|
+
* Get overlap text from the end of current chunk
|
39
|
+
*/
|
40
|
+
protected getOverlapText(text: string, overlapSize: number): string;
|
41
|
+
/**
|
42
|
+
* Create chunks from text with proper overlap handling
|
43
|
+
*/
|
44
|
+
protected createChunksFromText(text: string, sourceUrl: string_url, additionalMetadata?: Record<string, TODO_any>): KnowledgeChunk[];
|
45
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
import type { string_url } from '../../../../types/typeAliases';
|
4
|
+
import type { KnowledgeChunk } from '../types';
|
5
|
+
import { BaseKnowledgeProcessor } from './BaseKnowledgeProcessor';
|
6
|
+
/**
|
7
|
+
* PDF knowledge source processor
|
8
|
+
* Handles extraction and chunking of PDF documents
|
9
|
+
*
|
10
|
+
* @private
|
11
|
+
*/
|
12
|
+
export declare class PdfProcessor extends BaseKnowledgeProcessor {
|
13
|
+
readonly supportedFormat: "pdf";
|
14
|
+
/**
|
15
|
+
* Process PDF buffer and extract text content
|
16
|
+
*/
|
17
|
+
processBuffer(buffer: Buffer, sourceUrl: string_url): Promise<KnowledgeChunk[]>;
|
18
|
+
/**
|
19
|
+
* Extract title from PDF text (first meaningful line)
|
20
|
+
*/
|
21
|
+
private extractTitleFromText;
|
22
|
+
/**
|
23
|
+
* Create chunks from PDF text with page awareness
|
24
|
+
*/
|
25
|
+
protected createChunksFromText(text: string, sourceUrl: string_url, pdfInfo: {
|
26
|
+
totalPages: number;
|
27
|
+
}): KnowledgeChunk[];
|
28
|
+
}
|
29
|
+
/**
|
30
|
+
* TODO: !!!! Implement this through standard knowledge scraper
|
31
|
+
*/
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import type { string_url } from '../../../../types/typeAliases';
|
2
|
+
import type { KnowledgeSourceFormat } from '../types';
|
3
|
+
import type { RAGConfig } from '../types';
|
4
|
+
import { BaseKnowledgeProcessor } from './BaseKnowledgeProcessor';
|
5
|
+
/**
|
6
|
+
* Factory for creating knowledge source processors
|
7
|
+
*
|
8
|
+
* @private
|
9
|
+
*/
|
10
|
+
export declare class ProcessorFactory {
|
11
|
+
/**
|
12
|
+
* Get processor for a specific format
|
13
|
+
*/
|
14
|
+
static getProcessor(format: KnowledgeSourceFormat, config?: Partial<RAGConfig>): BaseKnowledgeProcessor;
|
15
|
+
/**
|
16
|
+
* Detect format from URL
|
17
|
+
*/
|
18
|
+
static detectFormat(url: string_url): KnowledgeSourceFormat;
|
19
|
+
/**
|
20
|
+
* Get all supported formats
|
21
|
+
*/
|
22
|
+
static getSupportedFormats(): KnowledgeSourceFormat[];
|
23
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
import type { string_url } from '../../../../types/typeAliases';
|
4
|
+
import type { KnowledgeChunk } from '../types';
|
5
|
+
import { BaseKnowledgeProcessor } from './BaseKnowledgeProcessor';
|
6
|
+
/**
|
7
|
+
* Text knowledge source processor
|
8
|
+
* Handles plain text documents
|
9
|
+
*
|
10
|
+
* @private
|
11
|
+
*/
|
12
|
+
export declare class TextProcessor extends BaseKnowledgeProcessor {
|
13
|
+
readonly supportedFormat: "text";
|
14
|
+
/**
|
15
|
+
* Process text buffer and extract content
|
16
|
+
*/
|
17
|
+
processBuffer(buffer: Buffer, sourceUrl: string_url): Promise<KnowledgeChunk[]>;
|
18
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import type { string_url } from '../../../types/typeAliases';
|
2
|
+
/**
|
3
|
+
* Supported knowledge source formats
|
4
|
+
*/
|
5
|
+
export type KnowledgeSourceFormat = 'pdf' | 'text' | 'markdown' | 'html';
|
6
|
+
/**
|
7
|
+
* Knowledge source metadata
|
8
|
+
*/
|
9
|
+
export interface KnowledgeSourceMetadata {
|
10
|
+
readonly url: string_url;
|
11
|
+
readonly format: KnowledgeSourceFormat;
|
12
|
+
readonly title?: string;
|
13
|
+
readonly lastFetched?: Date;
|
14
|
+
readonly contentHash?: string;
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* Processed knowledge chunk for RAG
|
18
|
+
*/
|
19
|
+
export interface KnowledgeChunk {
|
20
|
+
readonly id: string;
|
21
|
+
readonly sourceUrl: string_url;
|
22
|
+
readonly content: string;
|
23
|
+
readonly metadata: {
|
24
|
+
readonly pageNumber?: number;
|
25
|
+
readonly section?: string;
|
26
|
+
readonly chunkIndex: number;
|
27
|
+
readonly totalChunks: number;
|
28
|
+
};
|
29
|
+
}
|
30
|
+
/**
|
31
|
+
* Knowledge base containing all processed knowledge sources
|
32
|
+
*/
|
33
|
+
export interface KnowledgeBase {
|
34
|
+
readonly sources: KnowledgeSourceMetadata[];
|
35
|
+
readonly chunks: KnowledgeChunk[];
|
36
|
+
readonly lastUpdated: Date;
|
37
|
+
}
|
38
|
+
/**
|
39
|
+
* RAG retrieval result
|
40
|
+
*/
|
41
|
+
export interface RetrievalResult {
|
42
|
+
readonly chunk: KnowledgeChunk;
|
43
|
+
readonly relevanceScore: number;
|
44
|
+
}
|
45
|
+
/**
|
46
|
+
* Configuration for RAG processing
|
47
|
+
*/
|
48
|
+
export interface RAGConfig {
|
49
|
+
readonly maxChunkSize: number;
|
50
|
+
readonly chunkOverlap: number;
|
51
|
+
readonly maxRetrievedChunks: number;
|
52
|
+
readonly minRelevanceScore: number;
|
53
|
+
}
|
54
|
+
/**
|
55
|
+
* [💞] Ignore a discrepancy between file name and entity name
|
56
|
+
*/
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import type { AgentModelRequirements } from '../../_misc/AgentModelRequirements';
|
2
|
+
import { FrontendRAGService } from '../FrontendRAGService';
|
3
|
+
/**
|
4
|
+
* Helper utilities for RAG processing in chat systems
|
5
|
+
*
|
6
|
+
* @private
|
7
|
+
*/
|
8
|
+
export declare class RAGHelper {
|
9
|
+
/**
|
10
|
+
* Initialize knowledge sources from agent requirements
|
11
|
+
* This should be called when starting a chat session
|
12
|
+
*/
|
13
|
+
static initializeKnowledgeSources(requirements: AgentModelRequirements): Promise<FrontendRAGService | null>;
|
14
|
+
/**
|
15
|
+
* Get relevant context for a user query
|
16
|
+
* This should be called before sending the query to the AI model
|
17
|
+
*/
|
18
|
+
static getRelevantContext(ragService: FrontendRAGService | null, userQuery: string): Promise<string>;
|
19
|
+
/**
|
20
|
+
* Update system message with relevant context for a query
|
21
|
+
*/
|
22
|
+
static updateSystemMessageWithContext(requirements: AgentModelRequirements, ragService: FrontendRAGService | null, userQuery: string): Promise<AgentModelRequirements>;
|
23
|
+
/**
|
24
|
+
* Get statistics about the knowledge base
|
25
|
+
*/
|
26
|
+
static getKnowledgeStats(ragService: FrontendRAGService | null): {
|
27
|
+
sources: number;
|
28
|
+
chunks: number;
|
29
|
+
isInitialized: boolean;
|
30
|
+
} | null;
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
34
|
+
*/
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { BaseCommitmentDefinition } from '../_base/BaseCommitmentDefinition';
|
2
|
+
import type { AgentModelRequirements } from '../_misc/AgentModelRequirements';
|
3
|
+
/**
|
4
|
+
* META IMAGE commitment definition
|
5
|
+
*
|
6
|
+
* The META IMAGE commitment sets the agent's avatar/profile image URL.
|
7
|
+
* This commitment is special because it doesn't affect the system message,
|
8
|
+
* but is handled separately in the parsing logic.
|
9
|
+
*
|
10
|
+
* Example usage in agent source:
|
11
|
+
*
|
12
|
+
* ```book
|
13
|
+
* META IMAGE https://example.com/avatar.jpg
|
14
|
+
* META IMAGE /assets/agent-avatar.png
|
15
|
+
* ```
|
16
|
+
*
|
17
|
+
* @private [🪔] Maybe export the commitments through some package
|
18
|
+
*/
|
19
|
+
export declare class MetaImageCommitmentDefinition extends BaseCommitmentDefinition {
|
20
|
+
constructor();
|
21
|
+
applyToAgentModelRequirements(requirements: AgentModelRequirements, content: string): AgentModelRequirements;
|
22
|
+
/**
|
23
|
+
* Extracts the profile image URL from the content
|
24
|
+
* This is used by the parsing logic
|
25
|
+
*/
|
26
|
+
extractProfileImageUrl(content: string): string | null;
|
27
|
+
}
|
28
|
+
/**
|
29
|
+
* Singleton instance of the META IMAGE commitment definition
|
30
|
+
*
|
31
|
+
* @private [🪔] Maybe export the commitments through some package
|
32
|
+
*/
|
33
|
+
export declare const MetaImageCommitment: MetaImageCommitmentDefinition;
|
34
|
+
/**
|
35
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
36
|
+
*/
|