@equinor/fusion-framework-cli-plugin-ai-chat 1.0.5 → 2.0.0
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/CHANGELOG.md +60 -2
- package/README.md +107 -78
- package/dist/esm/chat.js +12 -2
- package/dist/esm/chat.js.map +1 -1
- package/dist/esm/index.js +15 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/system-message-template.js +22 -5
- package/dist/esm/system-message-template.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/chat.d.ts +12 -2
- package/dist/types/index.d.ts +15 -2
- package/dist/types/system-message-template.d.ts +22 -5
- package/dist/types/version.d.ts +1 -1
- package/package.json +8 -7
- package/src/chat.ts +52 -52
- package/src/index.ts +15 -2
- package/src/system-message-template.ts +22 -5
- package/src/version.ts +1 -1
package/dist/types/chat.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Fully configured Commander command for `ffc ai chat`.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the base `_command` with shared AI options (chat, embedding, and
|
|
5
|
+
* search) from `@equinor/fusion-framework-cli-plugin-ai-base` via
|
|
6
|
+
* {@link withAiOptions}. This is the value imported by
|
|
7
|
+
* {@link registerChatPlugin} when mounting the command onto the CLI tree.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { command } from '@equinor/fusion-framework-cli-plugin-ai-chat/chat';
|
|
12
|
+
* program.addCommand(command);
|
|
13
|
+
* ```
|
|
4
14
|
*/
|
|
5
15
|
export declare const command: import("commander").Command;
|
|
6
16
|
export default command;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import type { Command } from 'commander';
|
|
2
2
|
/**
|
|
3
|
-
* Registers the
|
|
4
|
-
*
|
|
3
|
+
* Registers the `ai chat` CLI plugin command with the Fusion Framework CLI program.
|
|
4
|
+
*
|
|
5
|
+
* Call this function from a CLI plugin entry point to add the interactive
|
|
6
|
+
* AI chat command (`ffc ai chat`) to the CLI command tree. The function
|
|
7
|
+
* delegates to {@link registerAiPlugin} from `@equinor/fusion-framework-cli-plugin-ai-base`
|
|
8
|
+
* to wire up shared AI options (Azure OpenAI, Azure Cognitive Search) and
|
|
9
|
+
* attach the chat-specific sub-command.
|
|
10
|
+
*
|
|
11
|
+
* @param program - The root `Commander` {@link Command} instance that owns the CLI command tree
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { registerChatPlugin } from '@equinor/fusion-framework-cli-plugin-ai-chat';
|
|
16
|
+
* registerChatPlugin(program);
|
|
17
|
+
* ```
|
|
5
18
|
*/
|
|
6
19
|
export declare function registerChatPlugin(program: Command): void;
|
|
7
20
|
export default registerChatPlugin;
|
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Creates the system message prompt for the Fusion Framework AI chat assistant.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Builds a system-role message that instructs the LLM to prioritise
|
|
5
|
+
* Fusion-specific knowledge from the provided RAG context. The returned
|
|
6
|
+
* string is used as the first message in the chat completion request so the
|
|
7
|
+
* model grounds its answers in retrieved Fusion documentation, code examples,
|
|
8
|
+
* and API references.
|
|
6
9
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
10
|
+
* Use this when constructing the message array for an Azure OpenAI chat
|
|
11
|
+
* completion call inside the `ai chat` command.
|
|
12
|
+
*
|
|
13
|
+
* @param context - Concatenated page content retrieved from the Azure Cognitive Search
|
|
14
|
+
* vector store. Each document's text is joined with newlines before being passed here.
|
|
15
|
+
* @returns A formatted system message string ready to be used as the `content` of a
|
|
16
|
+
* `ChatMessage` with `role: 'system'`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const systemMsg = createSystemMessage(retrievedDocs);
|
|
21
|
+
* const messages: ChatMessage[] = [
|
|
22
|
+
* { role: 'system', content: systemMsg },
|
|
23
|
+
* { role: 'user', content: userQuestion },
|
|
24
|
+
* ];
|
|
25
|
+
* ```
|
|
9
26
|
*/
|
|
10
27
|
export declare function createSystemMessage(context: string): string;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "
|
|
1
|
+
export declare const version = "2.0.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-cli-plugin-ai-chat",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "AI chat plugin for Fusion Framework CLI providing interactive chat with AI models",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -40,16 +40,17 @@
|
|
|
40
40
|
"@langchain/core": "^1.0.1",
|
|
41
41
|
"commander": "^14.0.1",
|
|
42
42
|
"rxjs": "^7.8.1",
|
|
43
|
-
"@equinor/fusion-framework-cli-plugin-ai-base": "
|
|
44
|
-
"@equinor/fusion-framework-module-ai": "
|
|
45
|
-
"@equinor/fusion-framework-module": "
|
|
43
|
+
"@equinor/fusion-framework-cli-plugin-ai-base": "2.0.0",
|
|
44
|
+
"@equinor/fusion-framework-module-ai": "3.0.0",
|
|
45
|
+
"@equinor/fusion-framework-module": "6.0.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@equinor/fusion-framework-cli": "^
|
|
48
|
+
"@equinor/fusion-framework-cli": "^14.0.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"typescript": "^5.
|
|
52
|
-
"vitest": "^
|
|
51
|
+
"typescript": "^5.9.3",
|
|
52
|
+
"vitest": "^4.1.0",
|
|
53
|
+
"@equinor/fusion-framework-cli": "^14.0.0"
|
|
53
54
|
},
|
|
54
55
|
"scripts": {
|
|
55
56
|
"build": "tsc -b",
|
package/src/chat.ts
CHANGED
|
@@ -17,69 +17,59 @@ import {
|
|
|
17
17
|
import { StringOutputParser } from '@langchain/core/output_parsers';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* CLI command
|
|
20
|
+
* CLI command definition for `ffc ai chat`.
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* Provides an interactive, readline-based chat session with an Azure OpenAI
|
|
23
|
+
* model. Each user message triggers a Retrieval-Augmented Generation (RAG)
|
|
24
|
+
* pipeline that:
|
|
24
25
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* - Automatic vector store context retrieval for enhanced responses
|
|
30
|
-
* - Special commands: exit, quit, clear, help
|
|
31
|
-
* - Support for Azure OpenAI models and Azure Cognitive Search
|
|
32
|
-
* - Live typing effect for AI responses
|
|
33
|
-
* - Configurable context retrieval limits
|
|
26
|
+
* 1. Retrieves relevant documents from an Azure Cognitive Search vector store.
|
|
27
|
+
* 2. Injects the retrieved context into a system prompt via {@link createSystemMessage}.
|
|
28
|
+
* 3. Streams the model's response token-by-token to stdout using a
|
|
29
|
+
* {@link RunnableSequence} LangChain chain.
|
|
34
30
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
31
|
+
* The command also manages conversation history with automatic AI-based
|
|
32
|
+
* compression: when the history reaches 10 messages the oldest 5 are
|
|
33
|
+
* summarised into a single assistant message, keeping token usage bounded
|
|
34
|
+
* while preserving conversational context.
|
|
37
35
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* --openai-chat-deployment <name> Azure OpenAI chat deployment name
|
|
43
|
-
* --openai-embedding-deployment <name> Azure OpenAI embedding deployment name
|
|
44
|
-
* --azure-search-endpoint <url> Azure Search endpoint URL
|
|
45
|
-
* --azure-search-api-key <key> Azure Search API key
|
|
46
|
-
* --azure-search-index-name <name> Azure Search index name
|
|
47
|
-
* --use-context Use vector store context (default: true)
|
|
48
|
-
* --context-limit <number> Max context documents to retrieve (default: 5)
|
|
49
|
-
* --history-limit <number> Max messages to keep in conversation history (default: 20, auto-compresses at 10)
|
|
50
|
-
* --verbose Enable verbose output
|
|
36
|
+
* @remarks
|
|
37
|
+
* Requires `--openai-chat-deployment` and `--azure-search-index-name` at
|
|
38
|
+
* minimum. All options can alternatively be supplied as environment variables
|
|
39
|
+
* (see {@link CommandOptions}).
|
|
51
40
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* AZURE_OPENAI_CHAT_DEPLOYMENT_NAME Chat deployment name
|
|
57
|
-
* AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME Embedding deployment name
|
|
58
|
-
* AZURE_SEARCH_ENDPOINT Azure Search endpoint
|
|
59
|
-
* AZURE_SEARCH_API_KEY Azure Search API key
|
|
60
|
-
* AZURE_SEARCH_INDEX_NAME Azure Search index name
|
|
41
|
+
* @example
|
|
42
|
+
* ```sh
|
|
43
|
+
* # Basic interactive chat
|
|
44
|
+
* ffc ai chat
|
|
61
45
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
46
|
+
* # With explicit deployment and search config
|
|
47
|
+
* ffc ai chat \
|
|
48
|
+
* --openai-chat-deployment gpt-4o \
|
|
49
|
+
* --azure-search-endpoint https://my.search.windows.net \
|
|
50
|
+
* --azure-search-index-name fusion-docs
|
|
67
51
|
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* $ ffc ai chat --history-limit 100
|
|
72
|
-
* $ ffc ai chat --verbose --azure-search-endpoint https://my-search.search.windows.net
|
|
52
|
+
* # Increase context window and enable verbose logging
|
|
53
|
+
* ffc ai chat --context-limit 10 --verbose
|
|
54
|
+
* ```
|
|
73
55
|
*/
|
|
56
|
+
|
|
74
57
|
/**
|
|
75
|
-
*
|
|
58
|
+
* Merged option set for the `ai chat` command.
|
|
59
|
+
*
|
|
60
|
+
* Extends the shared {@link AiOptions} from
|
|
61
|
+
* `@equinor/fusion-framework-cli-plugin-ai-base` with chat-specific flags
|
|
62
|
+
* for verbose logging, context retrieval depth, and conversation history size.
|
|
63
|
+
*
|
|
64
|
+
* Every option can be supplied via the corresponding `AZURE_*` / `OPENAI_*`
|
|
65
|
+
* environment variable instead of a CLI flag.
|
|
76
66
|
*/
|
|
77
67
|
type CommandOptions = AiOptions & {
|
|
78
|
-
/** Enable verbose output for debugging */
|
|
68
|
+
/** Enable verbose output for debugging. */
|
|
79
69
|
verbose?: boolean;
|
|
80
|
-
/** Maximum number of context documents to retrieve from vector store */
|
|
70
|
+
/** Maximum number of context documents to retrieve from the vector store (default `5`). */
|
|
81
71
|
contextLimit?: number;
|
|
82
|
-
/** Maximum number of messages to keep in conversation history */
|
|
72
|
+
/** Maximum number of messages to keep in conversation history before compression (default `20`). */
|
|
83
73
|
historyLimit?: number;
|
|
84
74
|
};
|
|
85
75
|
|
|
@@ -417,8 +407,18 @@ Summary:`;
|
|
|
417
407
|
});
|
|
418
408
|
|
|
419
409
|
/**
|
|
420
|
-
*
|
|
421
|
-
*
|
|
410
|
+
* Fully configured Commander command for `ffc ai chat`.
|
|
411
|
+
*
|
|
412
|
+
* Wraps the base `_command` with shared AI options (chat, embedding, and
|
|
413
|
+
* search) from `@equinor/fusion-framework-cli-plugin-ai-base` via
|
|
414
|
+
* {@link withAiOptions}. This is the value imported by
|
|
415
|
+
* {@link registerChatPlugin} when mounting the command onto the CLI tree.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```ts
|
|
419
|
+
* import { command } from '@equinor/fusion-framework-cli-plugin-ai-chat/chat';
|
|
420
|
+
* program.addCommand(command);
|
|
421
|
+
* ```
|
|
422
422
|
*/
|
|
423
423
|
export const command = withAiOptions(_command, {
|
|
424
424
|
includeChat: true,
|
package/src/index.ts
CHANGED
|
@@ -3,8 +3,21 @@ import { registerAiPlugin } from '@equinor/fusion-framework-cli-plugin-ai-base';
|
|
|
3
3
|
import { command as chatCommand } from './chat.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Registers the
|
|
7
|
-
*
|
|
6
|
+
* Registers the `ai chat` CLI plugin command with the Fusion Framework CLI program.
|
|
7
|
+
*
|
|
8
|
+
* Call this function from a CLI plugin entry point to add the interactive
|
|
9
|
+
* AI chat command (`ffc ai chat`) to the CLI command tree. The function
|
|
10
|
+
* delegates to {@link registerAiPlugin} from `@equinor/fusion-framework-cli-plugin-ai-base`
|
|
11
|
+
* to wire up shared AI options (Azure OpenAI, Azure Cognitive Search) and
|
|
12
|
+
* attach the chat-specific sub-command.
|
|
13
|
+
*
|
|
14
|
+
* @param program - The root `Commander` {@link Command} instance that owns the CLI command tree
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { registerChatPlugin } from '@equinor/fusion-framework-cli-plugin-ai-chat';
|
|
19
|
+
* registerChatPlugin(program);
|
|
20
|
+
* ```
|
|
8
21
|
*/
|
|
9
22
|
export function registerChatPlugin(program: Command): void {
|
|
10
23
|
registerAiPlugin(program, chatCommand);
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Creates the system message prompt for the Fusion Framework AI chat assistant.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Builds a system-role message that instructs the LLM to prioritise
|
|
5
|
+
* Fusion-specific knowledge from the provided RAG context. The returned
|
|
6
|
+
* string is used as the first message in the chat completion request so the
|
|
7
|
+
* model grounds its answers in retrieved Fusion documentation, code examples,
|
|
8
|
+
* and API references.
|
|
6
9
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
10
|
+
* Use this when constructing the message array for an Azure OpenAI chat
|
|
11
|
+
* completion call inside the `ai chat` command.
|
|
12
|
+
*
|
|
13
|
+
* @param context - Concatenated page content retrieved from the Azure Cognitive Search
|
|
14
|
+
* vector store. Each document's text is joined with newlines before being passed here.
|
|
15
|
+
* @returns A formatted system message string ready to be used as the `content` of a
|
|
16
|
+
* `ChatMessage` with `role: 'system'`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const systemMsg = createSystemMessage(retrievedDocs);
|
|
21
|
+
* const messages: ChatMessage[] = [
|
|
22
|
+
* { role: 'system', content: systemMsg },
|
|
23
|
+
* { role: 'user', content: userQuestion },
|
|
24
|
+
* ];
|
|
25
|
+
* ```
|
|
9
26
|
*/
|
|
10
27
|
export function createSystemMessage(context: string): string {
|
|
11
28
|
return `You are a helpful assistant specialized in the FUSION framework. Your primary goal is to use FUSION knowledge from the provided context to answer questions accurately and comprehensively.
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '
|
|
2
|
+
export const version = '2.0.0';
|