@equinor/fusion-framework-cli-plugin-ai-base 1.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 +51 -0
- package/LICENSE +21 -0
- package/README.md +76 -0
- package/dist/esm/config.js +58 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/options/index.js +4 -0
- package/dist/esm/options/index.js.map +1 -0
- package/dist/esm/options/options.js +60 -0
- package/dist/esm/options/options.js.map +1 -0
- package/dist/esm/options/schema.js +62 -0
- package/dist/esm/options/schema.js.map +1 -0
- package/dist/esm/options/types.js +2 -0
- package/dist/esm/options/types.js.map +1 -0
- package/dist/esm/options/with-options.js +105 -0
- package/dist/esm/options/with-options.js.map +1 -0
- package/dist/esm/register.js +34 -0
- package/dist/esm/register.js.map +1 -0
- package/dist/esm/setup-framework.js +72 -0
- package/dist/esm/setup-framework.js.map +1 -0
- package/dist/esm/version.js +3 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/config.d.ts +62 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/options/index.d.ts +4 -0
- package/dist/types/options/options.d.ts +57 -0
- package/dist/types/options/schema.d.ts +52 -0
- package/dist/types/options/types.d.ts +32 -0
- package/dist/types/options/with-options.d.ts +37 -0
- package/dist/types/register.d.ts +25 -0
- package/dist/types/setup-framework.d.ts +33 -0
- package/dist/types/version.d.ts +1 -0
- package/package.json +64 -0
- package/src/config.ts +87 -0
- package/src/index.ts +19 -0
- package/src/options/index.ts +4 -0
- package/src/options/options.ts +92 -0
- package/src/options/schema.ts +71 -0
- package/src/options/types.ts +32 -0
- package/src/options/with-options.ts +161 -0
- package/src/register.ts +38 -0
- package/src/setup-framework.ts +107 -0
- package/src/version.ts +2 -0
- package/tsconfig.json +21 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @equinor/fusion-framework-cli-plugin-ai-base
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [`e2d2a76`](https://github.com/equinor/fusion-framework/commit/e2d2a76d08b86c3a9d8783fed1606551df9d5633) Thanks [@odinr](https://github.com/odinr)! - Add new base plugin package for AI CLI plugins providing shared utilities and configuration.
|
|
8
|
+
|
|
9
|
+
This package provides shared utilities and options used across multiple AI CLI plugins including framework setup, AI configuration, and command option handling.
|
|
10
|
+
|
|
11
|
+
**Features:**
|
|
12
|
+
|
|
13
|
+
- Shared AI options and configuration schema
|
|
14
|
+
- Framework setup utilities
|
|
15
|
+
- Common command option handling
|
|
16
|
+
- Type-safe AI configuration interfaces
|
|
17
|
+
|
|
18
|
+
**Quick Usage:**
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { createCommand } from "commander";
|
|
22
|
+
import {
|
|
23
|
+
withOptions,
|
|
24
|
+
type AiOptions,
|
|
25
|
+
} from "@equinor/fusion-framework-cli-plugin-ai-base/command-options";
|
|
26
|
+
import { setupFramework } from "@equinor/fusion-framework-cli-plugin-ai-base";
|
|
27
|
+
|
|
28
|
+
const command = createCommand("my-ai-command").description("My AI command");
|
|
29
|
+
|
|
30
|
+
// Add AI options to the command
|
|
31
|
+
const enhancedCommand = withOptions(command, {
|
|
32
|
+
includeChat: true,
|
|
33
|
+
includeEmbedding: true,
|
|
34
|
+
includeSearch: true,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
enhancedCommand.action(async (options: AiOptions) => {
|
|
38
|
+
// Initialize framework with AI module
|
|
39
|
+
const framework = await setupFramework(options);
|
|
40
|
+
|
|
41
|
+
// Use framework.modules.ai for AI operations
|
|
42
|
+
const aiService = framework.modules.ai;
|
|
43
|
+
// ... your command logic
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [[`e2d2a76`](https://github.com/equinor/fusion-framework/commit/e2d2a76d08b86c3a9d8783fed1606551df9d5633), [`e2d2a76`](https://github.com/equinor/fusion-framework/commit/e2d2a76d08b86c3a9d8783fed1606551df9d5633)]:
|
|
50
|
+
- @equinor/fusion-framework-cli@13.0.0
|
|
51
|
+
- @equinor/fusion-framework-module-ai@2.0.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Equinor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# AI Base Plugin Package
|
|
2
|
+
|
|
3
|
+
> [!DANGER]
|
|
4
|
+
> **⚠️ INTERNAL USE ONLY**
|
|
5
|
+
> This package provides shared utilities and options for AI CLI plugins within Equinor's Fusion Framework ecosystem. External consumers should use the higher-level AI CLI plugins instead.
|
|
6
|
+
|
|
7
|
+
## Purpose
|
|
8
|
+
|
|
9
|
+
Provides common functionality for AI CLI plugins to avoid code duplication:
|
|
10
|
+
- Shared AI command options (model, temperature, tokens, etc.)
|
|
11
|
+
- Fusion Framework setup with AI module configuration
|
|
12
|
+
- Configuration file loading and validation
|
|
13
|
+
- Type definitions for AI options and configuration
|
|
14
|
+
|
|
15
|
+
Used by:
|
|
16
|
+
- `@equinor/fusion-framework-cli-plugin-ai-chat`
|
|
17
|
+
- `@equinor/fusion-framework-cli-plugin-ai-search`
|
|
18
|
+
- `@equinor/fusion-framework-cli-plugin-ai-index`
|
|
19
|
+
|
|
20
|
+
Changes here affect all consuming plugins, so coordinate updates carefully.
|
|
21
|
+
|
|
22
|
+
## Usage in Consuming Plugins
|
|
23
|
+
|
|
24
|
+
### Install as Dependency
|
|
25
|
+
|
|
26
|
+
**For monorepo packages:**
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@equinor/fusion-framework-cli-plugin-ai-base": "workspace:*"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Import from Base Package
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
// Import AI options from command-options export
|
|
39
|
+
import { withOptions, type AiOptions, AiOptionsSchema } from '@equinor/fusion-framework-cli-plugin-ai-base/command-options';
|
|
40
|
+
|
|
41
|
+
// Import framework utilities from main export
|
|
42
|
+
import { setupFramework, registerAiPlugin, loadFusionAIConfig } from '@equinor/fusion-framework-cli-plugin-ai-base';
|
|
43
|
+
|
|
44
|
+
// Or import everything from main export
|
|
45
|
+
import {
|
|
46
|
+
setupFramework,
|
|
47
|
+
registerAiPlugin,
|
|
48
|
+
loadFusionAIConfig,
|
|
49
|
+
type FrameworkInstance,
|
|
50
|
+
type FusionAIConfig
|
|
51
|
+
} from '@equinor/fusion-framework-cli-plugin-ai-base';
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Exports
|
|
55
|
+
|
|
56
|
+
- `./command-options` - AI command options, validation schemas, and option helpers
|
|
57
|
+
- `withOptions` - Function to add AI options to a Commander command
|
|
58
|
+
- `options` - Default export containing all option definitions
|
|
59
|
+
- `AiOptionsSchema` - Zod schema for validating AI options
|
|
60
|
+
- `AiOptionsType` - Type inferred from the schema
|
|
61
|
+
- `AiOptions` - TypeScript interface for AI options
|
|
62
|
+
- `.` - Main export containing:
|
|
63
|
+
- `setupFramework` - Initialize and configure Fusion Framework with AI module
|
|
64
|
+
- `registerAiPlugin` - Register AI plugin commands with CLI program
|
|
65
|
+
- `loadFusionAIConfig` - Load Fusion AI configuration from file
|
|
66
|
+
- `configureFusionAI` - Configuration factory function
|
|
67
|
+
- `FrameworkInstance` - Type for initialized framework instance
|
|
68
|
+
- `FusionAIConfig` - Base configuration interface
|
|
69
|
+
- `LoadFusionAIConfigOptions` - Options for loading configuration
|
|
70
|
+
|
|
71
|
+
## Development
|
|
72
|
+
|
|
73
|
+
- Build: `pnpm build` (type checking only, no bundling needed)
|
|
74
|
+
- Changesets should be created for versioning and changelog tracking
|
|
75
|
+
- Breaking changes affect all consuming plugins, so coordinate updates carefully
|
|
76
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { importConfig } from '@equinor/fusion-imports';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration factory function for Fusion AI operations.
|
|
4
|
+
*
|
|
5
|
+
* This helper function provides type safety and consistency for creating AI configuration
|
|
6
|
+
* functions. It accepts a function that returns configuration (either synchronously or
|
|
7
|
+
* asynchronously) and returns it unchanged, providing a typed interface for consumers.
|
|
8
|
+
*
|
|
9
|
+
* @param fn - Function that returns Fusion AI configuration (sync or async)
|
|
10
|
+
* @returns The same configuration function, typed for use with loadFusionAIConfig
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // fusion-ai.config.ts
|
|
15
|
+
* export default configureFusionAI(async () => ({
|
|
16
|
+
* apiKey: process.env.OPENAI_API_KEY,
|
|
17
|
+
* deployment: 'gpt-4',
|
|
18
|
+
* }));
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const configureFusionAI = (fn) => fn;
|
|
22
|
+
/**
|
|
23
|
+
* Loads and resolves Fusion AI configuration from a file.
|
|
24
|
+
*
|
|
25
|
+
* The config file should export a function (via `configureFusionAI`) that returns
|
|
26
|
+
* the configuration object. The function can be synchronous or asynchronous.
|
|
27
|
+
*
|
|
28
|
+
* @param configPath - Path to the config file without extension (default: 'fusion-ai.config')
|
|
29
|
+
* @param options - Optional parameters for loading the configuration
|
|
30
|
+
* @returns Promise resolving to the loaded and executed configuration
|
|
31
|
+
* @throws {Error} If the config file cannot be found or loaded
|
|
32
|
+
* @throws {Error} If the config file does not export a valid configuration function
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const config = await loadFusionAIConfig('fusion-ai.config', {
|
|
37
|
+
* baseDir: process.cwd(),
|
|
38
|
+
* extensions: ['.ts', '.js'],
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export async function loadFusionAIConfig(configPath = 'fusion-ai.config', options = {}) {
|
|
43
|
+
const { baseDir = process.cwd(), extensions } = options;
|
|
44
|
+
// Load configuration - config file exports a function for dynamic configuration
|
|
45
|
+
const result = await importConfig(configPath, {
|
|
46
|
+
baseDir,
|
|
47
|
+
extensions,
|
|
48
|
+
});
|
|
49
|
+
// Execute the configuration function (handles both sync and async)
|
|
50
|
+
const configFn = result.config;
|
|
51
|
+
if (typeof configFn === 'function') {
|
|
52
|
+
return await configFn();
|
|
53
|
+
}
|
|
54
|
+
// If config is not a function, treat it as the config object directly
|
|
55
|
+
return configFn;
|
|
56
|
+
}
|
|
57
|
+
export default loadFusionAIConfig;
|
|
58
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAcvD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAA2B,EAAwB,EAAE,EAAE,CAAC,EAAE,CAAC;AAY5F;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,aAAqB,kBAAkB,EACvC,UAAqC,EAAE;IAEvC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAExD,gFAAgF;IAChF,MAAM,MAAM,GAAG,MAAM,YAAY,CAAuB,UAAU,EAAE;QAClE,OAAO;QACP,UAAU;KACX,CAAC,CAAC;IAEH,mEAAmE;IACnE,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/B,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;QACnC,OAAO,MAAM,QAAQ,EAAE,CAAC;IAC1B,CAAC;IACD,sEAAsE;IACtE,OAAO,QAAa,CAAC;AACvB,CAAC;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base AI plugin package for Fusion Framework CLI
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This package provides shared utilities and configuration for AI-related CLI plugins.
|
|
6
|
+
* It is an internal base package and should not be used standalone. Consuming plugins
|
|
7
|
+
* should import from this package as a dependency.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
export { configureFusionAI, loadFusionAIConfig, } from './config.js';
|
|
12
|
+
export { setupFramework } from './setup-framework.js';
|
|
13
|
+
export { registerAiPlugin } from './register.js';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAGL,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAqB,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/options/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAsB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createOption } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* Option for specifying the Azure OpenAI API key.
|
|
4
|
+
* Required for authentication with Azure OpenAI services.
|
|
5
|
+
*/
|
|
6
|
+
export const apiKeyOption = createOption('--openai-api-key <key>', 'API key for Azure OpenAI services').env('AZURE_OPENAI_API_KEY');
|
|
7
|
+
/**
|
|
8
|
+
* Option for specifying the Azure OpenAI API version.
|
|
9
|
+
* Defaults to the latest stable version if not provided.
|
|
10
|
+
*/
|
|
11
|
+
export const apiVersionOption = createOption('--openai-api-version <version>', 'Azure OpenAI API version')
|
|
12
|
+
.env('AZURE_OPENAI_API_VERSION')
|
|
13
|
+
.default('2024-02-15-preview');
|
|
14
|
+
/**
|
|
15
|
+
* Option for specifying the Azure OpenAI instance name.
|
|
16
|
+
* Required for Azure OpenAI service endpoint construction.
|
|
17
|
+
*/
|
|
18
|
+
export const apiInstanceOption = createOption('--openai-instance <name>', 'Azure OpenAI instance name').env('AZURE_OPENAI_INSTANCE_NAME');
|
|
19
|
+
/**
|
|
20
|
+
* Option for specifying the Azure OpenAI deployment name for chat models.
|
|
21
|
+
* Required for chat completions API calls.
|
|
22
|
+
*/
|
|
23
|
+
export const chatDeploymentOption = createOption('--openai-chat-deployment <name>', 'Azure OpenAI chat deployment name').env('AZURE_OPENAI_CHAT_DEPLOYMENT_NAME');
|
|
24
|
+
/**
|
|
25
|
+
* Option for specifying the Azure OpenAI deployment name for embedding models.
|
|
26
|
+
* Required for embeddings API calls.
|
|
27
|
+
*/
|
|
28
|
+
export const embeddingDeploymentOption = createOption('--openai-embedding-deployment <name>', 'Azure OpenAI embedding deployment name').env('AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME');
|
|
29
|
+
/**
|
|
30
|
+
* Option for specifying the Azure Search endpoint URL.
|
|
31
|
+
* Required for Azure Cognitive Search operations.
|
|
32
|
+
*/
|
|
33
|
+
export const azureSearchEndpointOption = createOption('--azure-search-endpoint <url>', 'Azure Search endpoint URL').env('AZURE_SEARCH_ENDPOINT');
|
|
34
|
+
/**
|
|
35
|
+
* Option for specifying the Azure Search API key.
|
|
36
|
+
* Required for authentication with Azure Cognitive Search.
|
|
37
|
+
*/
|
|
38
|
+
export const azureSearchApiKeyOption = createOption('--azure-search-api-key <key>', 'Azure Search API key').env('AZURE_SEARCH_API_KEY');
|
|
39
|
+
/**
|
|
40
|
+
* Option for specifying the Azure Search index name.
|
|
41
|
+
* Required for search operations on a specific index.
|
|
42
|
+
*/
|
|
43
|
+
export const azureSearchIndexNameOption = createOption('--azure-search-index-name <name>', 'Azure Search index name').env('AZURE_SEARCH_INDEX_NAME');
|
|
44
|
+
/**
|
|
45
|
+
* Default export containing all AI-related command options.
|
|
46
|
+
*
|
|
47
|
+
* Provides convenient access to all option definitions for use in CLI commands.
|
|
48
|
+
* Each option can also be imported individually for more granular control.
|
|
49
|
+
*/
|
|
50
|
+
export default {
|
|
51
|
+
apiKeyOption,
|
|
52
|
+
apiVersionOption,
|
|
53
|
+
apiInstanceOption,
|
|
54
|
+
chatDeploymentOption,
|
|
55
|
+
embeddingDeploymentOption,
|
|
56
|
+
azureSearchEndpointOption,
|
|
57
|
+
azureSearchApiKeyOption,
|
|
58
|
+
azureSearchIndexNameOption,
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/options/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,YAAY,CACtC,wBAAwB,EACxB,mCAAmC,CACpC,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAE9B;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAC1C,gCAAgC,EAChC,0BAA0B,CAC3B;KACE,GAAG,CAAC,0BAA0B,CAAC;KAC/B,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAEjC;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,YAAY,CAC3C,0BAA0B,EAC1B,4BAA4B,CAC7B,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAEpC;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAC9C,iCAAiC,EACjC,mCAAmC,CACpC,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AAE3C;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,YAAY,CACnD,sCAAsC,EACtC,wCAAwC,CACzC,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;AAEhD;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,YAAY,CACnD,+BAA+B,EAC/B,2BAA2B,CAC5B,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAE/B;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,YAAY,CACjD,8BAA8B,EAC9B,sBAAsB,CACvB,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAE9B;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,YAAY,CACpD,kCAAkC,EAClC,yBAAyB,CAC1B,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAEjC;;;;;GAKG;AACH,eAAe;IACb,YAAY;IACZ,gBAAgB;IAChB,iBAAiB;IACjB,oBAAoB;IACpB,yBAAyB;IACzB,yBAAyB;IACzB,uBAAuB;IACvB,0BAA0B;CAC3B,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Base Zod schema for AI-related command options.
|
|
4
|
+
*
|
|
5
|
+
* This schema defines the validation rules for all AI options. Other AI plugins
|
|
6
|
+
* can extend this schema to add their own command-specific options.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { AiOptionsSchema } from '@equinor/fusion-framework-cli-plugin-ai-base';
|
|
11
|
+
* import { z } from 'zod';
|
|
12
|
+
*
|
|
13
|
+
* const MyCommandOptionsSchema = AiOptionsSchema.extend({
|
|
14
|
+
* myOption: z.string(),
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export const AiOptionsSchema = z
|
|
19
|
+
.object({
|
|
20
|
+
// Required AI options
|
|
21
|
+
openaiApiKey: z
|
|
22
|
+
.string({ message: 'Azure OpenAI API key is required and must be a non-empty string.' })
|
|
23
|
+
.min(1, 'API key must be a non-empty string.')
|
|
24
|
+
.describe('Azure OpenAI API key for authentication'),
|
|
25
|
+
openaiApiVersion: z
|
|
26
|
+
.string({ message: 'Azure OpenAI API version is required and must be a non-empty string.' })
|
|
27
|
+
.min(1, 'API version must be a non-empty string.')
|
|
28
|
+
.describe('Azure OpenAI API version'),
|
|
29
|
+
openaiInstance: z
|
|
30
|
+
.string({ message: 'Azure OpenAI instance name is required and must be a non-empty string.' })
|
|
31
|
+
.min(1, 'Instance name must be a non-empty string.')
|
|
32
|
+
.describe('Azure OpenAI instance name'),
|
|
33
|
+
// Optional AI options
|
|
34
|
+
openaiChatDeployment: z
|
|
35
|
+
.string()
|
|
36
|
+
.min(1, 'Chat deployment name must be a non-empty string.')
|
|
37
|
+
.optional()
|
|
38
|
+
.describe('Azure OpenAI chat deployment name'),
|
|
39
|
+
openaiEmbeddingDeployment: z
|
|
40
|
+
.string()
|
|
41
|
+
.min(1, 'Embedding deployment name must be a non-empty string.')
|
|
42
|
+
.optional()
|
|
43
|
+
.describe('Azure OpenAI embedding deployment name'),
|
|
44
|
+
azureSearchEndpoint: z
|
|
45
|
+
.string()
|
|
46
|
+
.url('Azure Search endpoint must be a valid URL.')
|
|
47
|
+
.min(1, 'Azure Search endpoint must be a non-empty string.')
|
|
48
|
+
.optional()
|
|
49
|
+
.describe('Azure Search endpoint URL'),
|
|
50
|
+
azureSearchApiKey: z
|
|
51
|
+
.string()
|
|
52
|
+
.min(1, 'Azure Search API key must be a non-empty string.')
|
|
53
|
+
.optional()
|
|
54
|
+
.describe('Azure Search API key'),
|
|
55
|
+
azureSearchIndexName: z
|
|
56
|
+
.string()
|
|
57
|
+
.min(1, 'Azure Search index name must be a non-empty string.')
|
|
58
|
+
.optional()
|
|
59
|
+
.describe('Azure Search index name'),
|
|
60
|
+
})
|
|
61
|
+
.describe('Base AI-related command options');
|
|
62
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/options/schema.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC;KAC7B,MAAM,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CAAC,yBAAyB,CAAC;CACvC,CAAC;KACD,QAAQ,CAAC,iCAAiC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/options/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { InvalidOptionArgumentError } from 'commander';
|
|
2
|
+
import { apiInstanceOption, apiKeyOption, apiVersionOption, azureSearchApiKeyOption, azureSearchEndpointOption, azureSearchIndexNameOption, chatDeploymentOption, embeddingDeploymentOption, } from './options.js';
|
|
3
|
+
/**
|
|
4
|
+
* Enhances a Commander command with AI-related options and validation.
|
|
5
|
+
*
|
|
6
|
+
* This function adds Azure OpenAI and Azure Cognitive Search options to the provided
|
|
7
|
+
* command, along with pre-action validation hooks to ensure required options are provided.
|
|
8
|
+
* The function allows selective inclusion of chat, embedding, and search capabilities
|
|
9
|
+
* based on the command's requirements.
|
|
10
|
+
*
|
|
11
|
+
* Options added:
|
|
12
|
+
* - Core: `openaiApiKey`, `openaiApiVersion`, `openaiInstance` (always included)
|
|
13
|
+
* - Chat: `openaiChatDeployment` (if includeChat is true)
|
|
14
|
+
* - Embedding: `openaiEmbeddingDeployment` (if includeEmbedding is true)
|
|
15
|
+
* - Search: `azureSearchEndpoint`, `azureSearchApiKey`, `azureSearchIndexName` (if includeSearch is true)
|
|
16
|
+
*
|
|
17
|
+
* @param command - The Commander command instance to enhance with AI options
|
|
18
|
+
* @param args - Optional configuration object for selective feature inclusion
|
|
19
|
+
* @param args.includeEmbedding - Whether to include and require embedding deployment option (default: false)
|
|
20
|
+
* @param args.includeChat - Whether to include and require chat deployment option (default: false)
|
|
21
|
+
* @param args.includeSearch - Whether to include and require Azure Search options (default: false)
|
|
22
|
+
* @returns The enhanced command with AI options and validation hooks attached
|
|
23
|
+
* @throws {InvalidOptionArgumentError} During command execution if required options are missing or invalid
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const chatCommand = createCommand('chat')
|
|
28
|
+
* .description('Start a chat session');
|
|
29
|
+
*
|
|
30
|
+
* withOptions(chatCommand, { includeChat: true });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const withOptions = (command, args) => {
|
|
34
|
+
// Core authentication options
|
|
35
|
+
command.addOption(apiKeyOption);
|
|
36
|
+
command.addOption(apiVersionOption);
|
|
37
|
+
command.addOption(apiInstanceOption);
|
|
38
|
+
// Deployment options
|
|
39
|
+
if (args?.includeChat === true) {
|
|
40
|
+
command.addOption(chatDeploymentOption);
|
|
41
|
+
}
|
|
42
|
+
if (args?.includeEmbedding === true) {
|
|
43
|
+
command.addOption(embeddingDeploymentOption);
|
|
44
|
+
}
|
|
45
|
+
// Azure Search options
|
|
46
|
+
if (args?.includeSearch === true) {
|
|
47
|
+
command.addOption(azureSearchEndpointOption);
|
|
48
|
+
command.addOption(azureSearchApiKeyOption);
|
|
49
|
+
command.addOption(azureSearchIndexNameOption);
|
|
50
|
+
}
|
|
51
|
+
// Validation hook
|
|
52
|
+
command.hook('preAction', (thisCommand) => {
|
|
53
|
+
const options = thisCommand.opts();
|
|
54
|
+
// Validate API key
|
|
55
|
+
if (!options.openaiApiKey ||
|
|
56
|
+
typeof options.openaiApiKey !== 'string' ||
|
|
57
|
+
options.openaiApiKey.trim() === '') {
|
|
58
|
+
throw new InvalidOptionArgumentError('API key is required and must be a non-empty string.');
|
|
59
|
+
}
|
|
60
|
+
// Validate API version
|
|
61
|
+
if (!options.openaiApiVersion || typeof options.openaiApiVersion !== 'string') {
|
|
62
|
+
throw new InvalidOptionArgumentError('API version must be a non-empty string.');
|
|
63
|
+
}
|
|
64
|
+
// Validate instance name
|
|
65
|
+
if (!options.openaiInstance ||
|
|
66
|
+
typeof options.openaiInstance !== 'string' ||
|
|
67
|
+
options.openaiInstance.trim() === '') {
|
|
68
|
+
throw new InvalidOptionArgumentError('API instance name is required and must be a non-empty string.');
|
|
69
|
+
}
|
|
70
|
+
if (args?.includeChat === true) {
|
|
71
|
+
if (!options.openaiChatDeployment ||
|
|
72
|
+
typeof options.openaiChatDeployment !== 'string' ||
|
|
73
|
+
options.openaiChatDeployment.trim() === '') {
|
|
74
|
+
throw new InvalidOptionArgumentError('Chat deployment name is required and must be a non-empty string.');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (args?.includeEmbedding === true) {
|
|
78
|
+
if (!options.openaiEmbeddingDeployment ||
|
|
79
|
+
typeof options.openaiEmbeddingDeployment !== 'string' ||
|
|
80
|
+
options.openaiEmbeddingDeployment.trim() === '') {
|
|
81
|
+
throw new InvalidOptionArgumentError('Embedding deployment name is required and must be a non-empty string.');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (args?.includeSearch === true) {
|
|
85
|
+
if (!options.azureSearchEndpoint ||
|
|
86
|
+
typeof options.azureSearchEndpoint !== 'string' ||
|
|
87
|
+
options.azureSearchEndpoint.trim() === '') {
|
|
88
|
+
throw new InvalidOptionArgumentError('Azure Search endpoint is required and must be a non-empty string.');
|
|
89
|
+
}
|
|
90
|
+
if (!options.azureSearchApiKey ||
|
|
91
|
+
typeof options.azureSearchApiKey !== 'string' ||
|
|
92
|
+
options.azureSearchApiKey.trim() === '') {
|
|
93
|
+
throw new InvalidOptionArgumentError('Azure Search API key is required and must be a non-empty string.');
|
|
94
|
+
}
|
|
95
|
+
if (!options.azureSearchIndexName ||
|
|
96
|
+
typeof options.azureSearchIndexName !== 'string' ||
|
|
97
|
+
options.azureSearchIndexName.trim() === '') {
|
|
98
|
+
throw new InvalidOptionArgumentError('Azure Search index name is required and must be a non-empty string.');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return command;
|
|
103
|
+
};
|
|
104
|
+
export default withOptions;
|
|
105
|
+
//# sourceMappingURL=with-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-options.js","sourceRoot":"","sources":["../../../src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;gBAC/C,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,KAAK,EAAE,EACzC,CAAC;gBACD,MAAM,IAAI,0BAA0B,CAClC,mEAAmE,CACpE,CAAC;YACJ,CAAC;YAED,IACE,CAAC,OAAO,CAAC,iBAAiB;gBAC1B,OAAO,OAAO,CAAC,iBAAiB,KAAK,QAAQ;gBAC7C,OAAO,CAAC,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,EACvC,CAAC;gBACD,MAAM,IAAI,0BAA0B,CAClC,kEAAkE,CACnE,CAAC;YACJ,CAAC;YAED,IACE,CAAC,OAAO,CAAC,oBAAoB;gBAC7B,OAAO,OAAO,CAAC,oBAAoB,KAAK,QAAQ;gBAChD,OAAO,CAAC,oBAAoB,CAAC,IAAI,EAAE,KAAK,EAAE,EAC1C,CAAC;gBACD,MAAM,IAAI,0BAA0B,CAClC,qEAAqE,CACtE,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createCommand } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* Registers an AI plugin command with the CLI program.
|
|
4
|
+
*
|
|
5
|
+
* This function ensures the 'ai' command group exists in the CLI program and adds
|
|
6
|
+
* the provided command as a subcommand. If the 'ai' group doesn't exist, it creates
|
|
7
|
+
* it with a standard description. This allows multiple AI-related plugins to register
|
|
8
|
+
* their commands under a common namespace.
|
|
9
|
+
*
|
|
10
|
+
* @param program - The Commander program instance to register commands with
|
|
11
|
+
* @param command - The command to add to the 'ai' command group
|
|
12
|
+
* @returns void
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const myAiCommand = createCommand('chat')
|
|
17
|
+
* .description('Start an AI chat session')
|
|
18
|
+
* .action(() => { ... });
|
|
19
|
+
*
|
|
20
|
+
* registerAiPlugin(program, myAiCommand);
|
|
21
|
+
* // Results in: fusion-cli ai chat
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function registerAiPlugin(program, command) {
|
|
25
|
+
// Create 'ai' command group if it doesn't exist
|
|
26
|
+
let aiCommand = program.commands.find((cmd) => cmd.name() === 'ai');
|
|
27
|
+
if (!aiCommand) {
|
|
28
|
+
aiCommand = createCommand('ai').description('Commands for interacting with AI models and Azure OpenAI services');
|
|
29
|
+
program.addCommand(aiCommand);
|
|
30
|
+
}
|
|
31
|
+
aiCommand.addCommand(command);
|
|
32
|
+
}
|
|
33
|
+
export default registerAiPlugin;
|
|
34
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/register.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAgB,EAAE,OAAgB;IACjE,gDAAgD;IAChD,IAAI,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,IAAI,CAAC,CAAC;IACpE,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,SAAS,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,WAAW,CACzC,mEAAmE,CACpE,CAAC;QACF,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;IACD,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { enableAI } from '@equinor/fusion-framework-module-ai';
|
|
2
|
+
import { AzureOpenAiEmbed, AzureOpenAIModel, AzureVectorStore, } from '@equinor/fusion-framework-module-ai/azure';
|
|
3
|
+
import { ModulesConfigurator } from '@equinor/fusion-framework-module';
|
|
4
|
+
/**
|
|
5
|
+
* Initializes and configures the Fusion Framework with AI module capabilities.
|
|
6
|
+
*
|
|
7
|
+
* Sets up the framework with Azure OpenAI chat models, embedding services, and
|
|
8
|
+
* optionally Azure Cognitive Search vector stores. The function handles the complete
|
|
9
|
+
* initialization process including service registration and dependency injection.
|
|
10
|
+
*
|
|
11
|
+
* @param options - AI configuration options
|
|
12
|
+
* @param options.openaiApiKey - Azure OpenAI API key for authentication
|
|
13
|
+
* @param options.openaiApiVersion - Azure OpenAI API version (e.g., '2024-02-15-preview')
|
|
14
|
+
* @param options.openaiInstance - Azure OpenAI instance name
|
|
15
|
+
* @param options.openaiChatDeployment - Optional chat model deployment name
|
|
16
|
+
* @param options.openaiEmbeddingDeployment - Optional embedding model deployment name
|
|
17
|
+
* @param options.azureSearchEndpoint - Optional Azure Search service endpoint URL
|
|
18
|
+
* @param options.azureSearchApiKey - Optional Azure Search API key
|
|
19
|
+
* @param options.azureSearchIndexName - Optional Azure Search index name
|
|
20
|
+
* @returns Promise resolving to an initialized framework instance with AI module configured
|
|
21
|
+
* @throws {Error} If embedding deployment is required but not provided when configuring vector store
|
|
22
|
+
* @throws {Error} If embedding service cannot be retrieved for vector store configuration
|
|
23
|
+
*/
|
|
24
|
+
export const setupFramework = async (options) => {
|
|
25
|
+
// Create a new module configurator for the framework
|
|
26
|
+
const configurator = new ModulesConfigurator();
|
|
27
|
+
// Configure AI module with provided options
|
|
28
|
+
enableAI(configurator, (aiConfig) => {
|
|
29
|
+
// Configure chat model if deployment name is provided
|
|
30
|
+
if (options.openaiChatDeployment) {
|
|
31
|
+
aiConfig.setModel(options.openaiChatDeployment, new AzureOpenAIModel({
|
|
32
|
+
azureOpenAIApiKey: options.openaiApiKey,
|
|
33
|
+
azureOpenAIApiDeploymentName: options.openaiChatDeployment,
|
|
34
|
+
azureOpenAIApiInstanceName: options.openaiInstance,
|
|
35
|
+
azureOpenAIApiVersion: options.openaiApiVersion,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
// Configure embedding model if deployment name is provided
|
|
39
|
+
if (options.openaiEmbeddingDeployment) {
|
|
40
|
+
aiConfig.setEmbedding(options.openaiEmbeddingDeployment, new AzureOpenAiEmbed({
|
|
41
|
+
azureOpenAIApiKey: options.openaiApiKey,
|
|
42
|
+
azureOpenAIApiDeploymentName: options.openaiEmbeddingDeployment,
|
|
43
|
+
azureOpenAIApiInstanceName: options.openaiInstance,
|
|
44
|
+
azureOpenAIApiVersion: options.openaiApiVersion,
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
// Configure vector store if Azure Search options are provided
|
|
48
|
+
// Vector store requires an embedding service to generate embeddings for documents
|
|
49
|
+
if (options.azureSearchEndpoint && options.azureSearchApiKey && options.azureSearchIndexName) {
|
|
50
|
+
if (!options.openaiEmbeddingDeployment) {
|
|
51
|
+
throw new Error('Embedding deployment is required to configure the vector store');
|
|
52
|
+
}
|
|
53
|
+
// Retrieve the embedding service to pass to the vector store
|
|
54
|
+
// The vector store uses embeddings to index and search documents
|
|
55
|
+
const embeddingService = aiConfig.getService('embeddings', options.openaiEmbeddingDeployment);
|
|
56
|
+
// Check that the embedding service was successfully retrieved
|
|
57
|
+
if (!embeddingService) {
|
|
58
|
+
throw new Error(`Embedding service '${options.openaiEmbeddingDeployment}' not found for vector store configuration`);
|
|
59
|
+
}
|
|
60
|
+
aiConfig.setVectorStore(options.azureSearchIndexName, new AzureVectorStore(embeddingService, {
|
|
61
|
+
endpoint: options.azureSearchEndpoint,
|
|
62
|
+
key: options.azureSearchApiKey,
|
|
63
|
+
indexName: options.azureSearchIndexName,
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
// Initialize the framework with all configured modules
|
|
68
|
+
const framework = await configurator.initialize();
|
|
69
|
+
return framework;
|
|
70
|
+
};
|
|
71
|
+
export default setupFramework;
|
|
72
|
+
//# sourceMappingURL=setup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