@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.
Files changed (46) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/LICENSE +21 -0
  3. package/README.md +76 -0
  4. package/dist/esm/config.js +58 -0
  5. package/dist/esm/config.js.map +1 -0
  6. package/dist/esm/index.js +14 -0
  7. package/dist/esm/index.js.map +1 -0
  8. package/dist/esm/options/index.js +4 -0
  9. package/dist/esm/options/index.js.map +1 -0
  10. package/dist/esm/options/options.js +60 -0
  11. package/dist/esm/options/options.js.map +1 -0
  12. package/dist/esm/options/schema.js +62 -0
  13. package/dist/esm/options/schema.js.map +1 -0
  14. package/dist/esm/options/types.js +2 -0
  15. package/dist/esm/options/types.js.map +1 -0
  16. package/dist/esm/options/with-options.js +105 -0
  17. package/dist/esm/options/with-options.js.map +1 -0
  18. package/dist/esm/register.js +34 -0
  19. package/dist/esm/register.js.map +1 -0
  20. package/dist/esm/setup-framework.js +72 -0
  21. package/dist/esm/setup-framework.js.map +1 -0
  22. package/dist/esm/version.js +3 -0
  23. package/dist/esm/version.js.map +1 -0
  24. package/dist/tsconfig.tsbuildinfo +1 -0
  25. package/dist/types/config.d.ts +62 -0
  26. package/dist/types/index.d.ts +13 -0
  27. package/dist/types/options/index.d.ts +4 -0
  28. package/dist/types/options/options.d.ts +57 -0
  29. package/dist/types/options/schema.d.ts +52 -0
  30. package/dist/types/options/types.d.ts +32 -0
  31. package/dist/types/options/with-options.d.ts +37 -0
  32. package/dist/types/register.d.ts +25 -0
  33. package/dist/types/setup-framework.d.ts +33 -0
  34. package/dist/types/version.d.ts +1 -0
  35. package/package.json +64 -0
  36. package/src/config.ts +87 -0
  37. package/src/index.ts +19 -0
  38. package/src/options/index.ts +4 -0
  39. package/src/options/options.ts +92 -0
  40. package/src/options/schema.ts +71 -0
  41. package/src/options/types.ts +32 -0
  42. package/src/options/with-options.ts +161 -0
  43. package/src/register.ts +38 -0
  44. package/src/setup-framework.ts +107 -0
  45. package/src/version.ts +2 -0
  46. package/tsconfig.json +21 -0
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Base configuration interface for Fusion AI operations.
3
+ *
4
+ * This interface serves as the base type for all Fusion AI configuration objects.
5
+ * Implementations should extend this interface with specific configuration properties
6
+ * relevant to their use case. The configuration is typically created using
7
+ * `configureFusionAI` and loaded via `loadFusionAIConfig`.
8
+ */
9
+ export interface FusionAIConfig {
10
+ [key: string]: unknown;
11
+ }
12
+ /**
13
+ * Configuration factory function for Fusion AI operations.
14
+ *
15
+ * This helper function provides type safety and consistency for creating AI configuration
16
+ * functions. It accepts a function that returns configuration (either synchronously or
17
+ * asynchronously) and returns it unchanged, providing a typed interface for consumers.
18
+ *
19
+ * @param fn - Function that returns Fusion AI configuration (sync or async)
20
+ * @returns The same configuration function, typed for use with loadFusionAIConfig
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * // fusion-ai.config.ts
25
+ * export default configureFusionAI(async () => ({
26
+ * apiKey: process.env.OPENAI_API_KEY,
27
+ * deployment: 'gpt-4',
28
+ * }));
29
+ * ```
30
+ */
31
+ export declare const configureFusionAI: <T extends FusionAIConfig>(fn: () => Promise<T> | T) => () => Promise<T> | T;
32
+ /**
33
+ * Options for loading Fusion AI configuration
34
+ */
35
+ export interface LoadFusionAIConfigOptions {
36
+ /** Base directory to resolve the config file from (default: process.cwd()) */
37
+ baseDir?: string;
38
+ /** File extensions to consider when resolving the config file (default: ['.ts', '.mjs', '.js', '.json']) */
39
+ extensions?: string[];
40
+ }
41
+ /**
42
+ * Loads and resolves Fusion AI configuration from a file.
43
+ *
44
+ * The config file should export a function (via `configureFusionAI`) that returns
45
+ * the configuration object. The function can be synchronous or asynchronous.
46
+ *
47
+ * @param configPath - Path to the config file without extension (default: 'fusion-ai.config')
48
+ * @param options - Optional parameters for loading the configuration
49
+ * @returns Promise resolving to the loaded and executed configuration
50
+ * @throws {Error} If the config file cannot be found or loaded
51
+ * @throws {Error} If the config file does not export a valid configuration function
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * const config = await loadFusionAIConfig('fusion-ai.config', {
56
+ * baseDir: process.cwd(),
57
+ * extensions: ['.ts', '.js'],
58
+ * });
59
+ * ```
60
+ */
61
+ export declare function loadFusionAIConfig<T extends FusionAIConfig = FusionAIConfig>(configPath?: string, options?: LoadFusionAIConfigOptions): Promise<T>;
62
+ export default loadFusionAIConfig;
@@ -0,0 +1,13 @@
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 { type FusionAIConfig, type LoadFusionAIConfigOptions, configureFusionAI, loadFusionAIConfig, } from './config.js';
12
+ export { setupFramework, FrameworkInstance } from './setup-framework.js';
13
+ export { registerAiPlugin } from './register.js';
@@ -0,0 +1,4 @@
1
+ export { default as options } from './options.js';
2
+ export { withOptions } from './with-options.js';
3
+ export { AiOptionsSchema, type AiOptionsType } from './schema.js';
4
+ export type { AiOptions } from './types.js';
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Option for specifying the Azure OpenAI API key.
3
+ * Required for authentication with Azure OpenAI services.
4
+ */
5
+ export declare const apiKeyOption: import("commander").Option;
6
+ /**
7
+ * Option for specifying the Azure OpenAI API version.
8
+ * Defaults to the latest stable version if not provided.
9
+ */
10
+ export declare const apiVersionOption: import("commander").Option;
11
+ /**
12
+ * Option for specifying the Azure OpenAI instance name.
13
+ * Required for Azure OpenAI service endpoint construction.
14
+ */
15
+ export declare const apiInstanceOption: import("commander").Option;
16
+ /**
17
+ * Option for specifying the Azure OpenAI deployment name for chat models.
18
+ * Required for chat completions API calls.
19
+ */
20
+ export declare const chatDeploymentOption: import("commander").Option;
21
+ /**
22
+ * Option for specifying the Azure OpenAI deployment name for embedding models.
23
+ * Required for embeddings API calls.
24
+ */
25
+ export declare const embeddingDeploymentOption: import("commander").Option;
26
+ /**
27
+ * Option for specifying the Azure Search endpoint URL.
28
+ * Required for Azure Cognitive Search operations.
29
+ */
30
+ export declare const azureSearchEndpointOption: import("commander").Option;
31
+ /**
32
+ * Option for specifying the Azure Search API key.
33
+ * Required for authentication with Azure Cognitive Search.
34
+ */
35
+ export declare const azureSearchApiKeyOption: import("commander").Option;
36
+ /**
37
+ * Option for specifying the Azure Search index name.
38
+ * Required for search operations on a specific index.
39
+ */
40
+ export declare const azureSearchIndexNameOption: import("commander").Option;
41
+ /**
42
+ * Default export containing all AI-related command options.
43
+ *
44
+ * Provides convenient access to all option definitions for use in CLI commands.
45
+ * Each option can also be imported individually for more granular control.
46
+ */
47
+ declare const _default: {
48
+ apiKeyOption: import("commander").Option;
49
+ apiVersionOption: import("commander").Option;
50
+ apiInstanceOption: import("commander").Option;
51
+ chatDeploymentOption: import("commander").Option;
52
+ embeddingDeploymentOption: import("commander").Option;
53
+ azureSearchEndpointOption: import("commander").Option;
54
+ azureSearchApiKeyOption: import("commander").Option;
55
+ azureSearchIndexNameOption: import("commander").Option;
56
+ };
57
+ export default _default;
@@ -0,0 +1,52 @@
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 declare const AiOptionsSchema: z.ZodObject<{
19
+ openaiApiKey: z.ZodString;
20
+ openaiApiVersion: z.ZodString;
21
+ openaiInstance: z.ZodString;
22
+ openaiChatDeployment: z.ZodOptional<z.ZodString>;
23
+ openaiEmbeddingDeployment: z.ZodOptional<z.ZodString>;
24
+ azureSearchEndpoint: z.ZodOptional<z.ZodString>;
25
+ azureSearchApiKey: z.ZodOptional<z.ZodString>;
26
+ azureSearchIndexName: z.ZodOptional<z.ZodString>;
27
+ }, "strip", z.ZodTypeAny, {
28
+ openaiApiKey: string;
29
+ openaiApiVersion: string;
30
+ openaiInstance: string;
31
+ openaiChatDeployment?: string | undefined;
32
+ openaiEmbeddingDeployment?: string | undefined;
33
+ azureSearchEndpoint?: string | undefined;
34
+ azureSearchApiKey?: string | undefined;
35
+ azureSearchIndexName?: string | undefined;
36
+ }, {
37
+ openaiApiKey: string;
38
+ openaiApiVersion: string;
39
+ openaiInstance: string;
40
+ openaiChatDeployment?: string | undefined;
41
+ openaiEmbeddingDeployment?: string | undefined;
42
+ azureSearchEndpoint?: string | undefined;
43
+ azureSearchApiKey?: string | undefined;
44
+ azureSearchIndexName?: string | undefined;
45
+ }>;
46
+ /**
47
+ * Type representing the validated AI options.
48
+ *
49
+ * This type is inferred from the Zod schema and should be used throughout AI plugins
50
+ * to ensure type safety and consistency with the schema.
51
+ */
52
+ export type AiOptionsType = z.infer<typeof AiOptionsSchema>;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Configuration options for AI-related CLI commands.
3
+ *
4
+ * This interface defines all available options for configuring Azure OpenAI services
5
+ * and Azure Cognitive Search integration. Required fields must be provided either
6
+ * via command-line arguments or environment variables. Optional fields enable
7
+ * specific features (chat, embeddings, vector search) when provided.
8
+ *
9
+ * @remarks
10
+ * - All required fields (apiKey, apiVersion, instance) must be provided for any AI operation
11
+ * - Chat operations require `openaiChatDeployment`
12
+ * - Embedding operations require `openaiEmbeddingDeployment`
13
+ * - Vector search requires all three Azure Search fields plus `openaiEmbeddingDeployment`
14
+ */
15
+ export interface AiOptions {
16
+ /** Azure OpenAI API key for authentication with Azure OpenAI services */
17
+ openaiApiKey: string;
18
+ /** Azure OpenAI API version (e.g., '2024-02-15-preview') */
19
+ openaiApiVersion: string;
20
+ /** Azure OpenAI instance name (the resource name in Azure) */
21
+ openaiInstance: string;
22
+ /** Azure OpenAI chat model deployment name. Required for chat operations */
23
+ openaiChatDeployment?: string;
24
+ /** Azure OpenAI embedding model deployment name. Required for embedding and vector search operations */
25
+ openaiEmbeddingDeployment?: string;
26
+ /** Azure Cognitive Search endpoint URL. Required for vector search operations */
27
+ azureSearchEndpoint?: string;
28
+ /** Azure Cognitive Search API key. Required for vector search operations */
29
+ azureSearchApiKey?: string;
30
+ /** Azure Cognitive Search index name. Required for vector search operations */
31
+ azureSearchIndexName?: string;
32
+ }
@@ -0,0 +1,37 @@
1
+ import { type Command } from 'commander';
2
+ /**
3
+ * Enhances a Commander command with AI-related options and validation.
4
+ *
5
+ * This function adds Azure OpenAI and Azure Cognitive Search options to the provided
6
+ * command, along with pre-action validation hooks to ensure required options are provided.
7
+ * The function allows selective inclusion of chat, embedding, and search capabilities
8
+ * based on the command's requirements.
9
+ *
10
+ * Options added:
11
+ * - Core: `openaiApiKey`, `openaiApiVersion`, `openaiInstance` (always included)
12
+ * - Chat: `openaiChatDeployment` (if includeChat is true)
13
+ * - Embedding: `openaiEmbeddingDeployment` (if includeEmbedding is true)
14
+ * - Search: `azureSearchEndpoint`, `azureSearchApiKey`, `azureSearchIndexName` (if includeSearch is true)
15
+ *
16
+ * @param command - The Commander command instance to enhance with AI options
17
+ * @param args - Optional configuration object for selective feature inclusion
18
+ * @param args.includeEmbedding - Whether to include and require embedding deployment option (default: false)
19
+ * @param args.includeChat - Whether to include and require chat deployment option (default: false)
20
+ * @param args.includeSearch - Whether to include and require Azure Search options (default: false)
21
+ * @returns The enhanced command with AI options and validation hooks attached
22
+ * @throws {InvalidOptionArgumentError} During command execution if required options are missing or invalid
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const chatCommand = createCommand('chat')
27
+ * .description('Start a chat session');
28
+ *
29
+ * withOptions(chatCommand, { includeChat: true });
30
+ * ```
31
+ */
32
+ export declare const withOptions: (command: Command, args?: Partial<{
33
+ includeEmbedding: boolean;
34
+ includeChat: boolean;
35
+ includeSearch: boolean;
36
+ }>) => Command;
37
+ export default withOptions;
@@ -0,0 +1,25 @@
1
+ import type { Command } 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 declare function registerAiPlugin(program: Command, command: Command): void;
25
+ export default registerAiPlugin;
@@ -0,0 +1,33 @@
1
+ import { type AIModule } from '@equinor/fusion-framework-module-ai';
2
+ import type { AiOptions } from './options/index.js';
3
+ import { type ModulesInstance } from '@equinor/fusion-framework-module';
4
+ /**
5
+ * Framework instance with AI module capabilities.
6
+ *
7
+ * This type represents an initialized Fusion Framework instance that includes
8
+ * the AI module, providing access to chat models, embedding services, and
9
+ * vector stores configured via the setup process.
10
+ */
11
+ export type FrameworkInstance = ModulesInstance<[AIModule]>;
12
+ /**
13
+ * Initializes and configures the Fusion Framework with AI module capabilities.
14
+ *
15
+ * Sets up the framework with Azure OpenAI chat models, embedding services, and
16
+ * optionally Azure Cognitive Search vector stores. The function handles the complete
17
+ * initialization process including service registration and dependency injection.
18
+ *
19
+ * @param options - AI configuration options
20
+ * @param options.openaiApiKey - Azure OpenAI API key for authentication
21
+ * @param options.openaiApiVersion - Azure OpenAI API version (e.g., '2024-02-15-preview')
22
+ * @param options.openaiInstance - Azure OpenAI instance name
23
+ * @param options.openaiChatDeployment - Optional chat model deployment name
24
+ * @param options.openaiEmbeddingDeployment - Optional embedding model deployment name
25
+ * @param options.azureSearchEndpoint - Optional Azure Search service endpoint URL
26
+ * @param options.azureSearchApiKey - Optional Azure Search API key
27
+ * @param options.azureSearchIndexName - Optional Azure Search index name
28
+ * @returns Promise resolving to an initialized framework instance with AI module configured
29
+ * @throws {Error} If embedding deployment is required but not provided when configuring vector store
30
+ * @throws {Error} If embedding service cannot be retrieved for vector store configuration
31
+ */
32
+ export declare const setupFramework: (options: AiOptions) => Promise<FrameworkInstance>;
33
+ export default setupFramework;
@@ -0,0 +1 @@
1
+ export declare const version = "1.0.0";
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@equinor/fusion-framework-cli-plugin-ai-base",
3
+ "version": "1.0.0",
4
+ "description": "Base AI plugin package for Fusion Framework CLI",
5
+ "type": "module",
6
+ "main": "dist/esm/index.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/esm/index.js",
11
+ "types": "./dist/types/index.d.ts"
12
+ },
13
+ "./command-options": {
14
+ "import": "./dist/esm/options/index.js",
15
+ "types": "./dist/types/options/index.d.ts"
16
+ }
17
+ },
18
+ "typesVersions": {
19
+ "*": {
20
+ ".": [
21
+ "dist/types/index.d.ts"
22
+ ],
23
+ "./command-options": [
24
+ "dist/types/options/index.d.ts"
25
+ ]
26
+ }
27
+ },
28
+ "keywords": [
29
+ "fusion-framework",
30
+ "cli",
31
+ "plugin",
32
+ "llm",
33
+ "ai"
34
+ ],
35
+ "author": "",
36
+ "license": "ISC",
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/equinor/fusion-framework.git",
43
+ "directory": "packages/cli-plugins/ai-base"
44
+ },
45
+ "dependencies": {
46
+ "commander": "^14.0.1",
47
+ "zod": "^3.23.8",
48
+ "@equinor/fusion-framework-module-ai": "2.0.0",
49
+ "@equinor/fusion-framework-module": "5.0.5",
50
+ "@equinor/fusion-imports": "1.1.8"
51
+ },
52
+ "peerDependencies": {
53
+ "@equinor/fusion-framework-cli": "13.0.0"
54
+ },
55
+ "devDependencies": {
56
+ "typescript": "^5.8.2",
57
+ "vitest": "^3.2.4"
58
+ },
59
+ "scripts": {
60
+ "build": "tsc -b",
61
+ "build:types": "tsc -b",
62
+ "test": "vitest"
63
+ }
64
+ }
package/src/config.ts ADDED
@@ -0,0 +1,87 @@
1
+ import { importConfig } from '@equinor/fusion-imports';
2
+
3
+ /**
4
+ * Base configuration interface for Fusion AI operations.
5
+ *
6
+ * This interface serves as the base type for all Fusion AI configuration objects.
7
+ * Implementations should extend this interface with specific configuration properties
8
+ * relevant to their use case. The configuration is typically created using
9
+ * `configureFusionAI` and loaded via `loadFusionAIConfig`.
10
+ */
11
+ export interface FusionAIConfig {
12
+ [key: string]: unknown;
13
+ }
14
+
15
+ /**
16
+ * Configuration factory function for Fusion AI operations.
17
+ *
18
+ * This helper function provides type safety and consistency for creating AI configuration
19
+ * functions. It accepts a function that returns configuration (either synchronously or
20
+ * asynchronously) and returns it unchanged, providing a typed interface for consumers.
21
+ *
22
+ * @param fn - Function that returns Fusion AI configuration (sync or async)
23
+ * @returns The same configuration function, typed for use with loadFusionAIConfig
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * // fusion-ai.config.ts
28
+ * export default configureFusionAI(async () => ({
29
+ * apiKey: process.env.OPENAI_API_KEY,
30
+ * deployment: 'gpt-4',
31
+ * }));
32
+ * ```
33
+ */
34
+ export const configureFusionAI = <T extends FusionAIConfig>(fn: () => Promise<T> | T) => fn;
35
+
36
+ /**
37
+ * Options for loading Fusion AI configuration
38
+ */
39
+ export interface LoadFusionAIConfigOptions {
40
+ /** Base directory to resolve the config file from (default: process.cwd()) */
41
+ baseDir?: string;
42
+ /** File extensions to consider when resolving the config file (default: ['.ts', '.mjs', '.js', '.json']) */
43
+ extensions?: string[];
44
+ }
45
+
46
+ /**
47
+ * Loads and resolves Fusion AI configuration from a file.
48
+ *
49
+ * The config file should export a function (via `configureFusionAI`) that returns
50
+ * the configuration object. The function can be synchronous or asynchronous.
51
+ *
52
+ * @param configPath - Path to the config file without extension (default: 'fusion-ai.config')
53
+ * @param options - Optional parameters for loading the configuration
54
+ * @returns Promise resolving to the loaded and executed configuration
55
+ * @throws {Error} If the config file cannot be found or loaded
56
+ * @throws {Error} If the config file does not export a valid configuration function
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const config = await loadFusionAIConfig('fusion-ai.config', {
61
+ * baseDir: process.cwd(),
62
+ * extensions: ['.ts', '.js'],
63
+ * });
64
+ * ```
65
+ */
66
+ export async function loadFusionAIConfig<T extends FusionAIConfig = FusionAIConfig>(
67
+ configPath: string = 'fusion-ai.config',
68
+ options: LoadFusionAIConfigOptions = {},
69
+ ): Promise<T> {
70
+ const { baseDir = process.cwd(), extensions } = options;
71
+
72
+ // Load configuration - config file exports a function for dynamic configuration
73
+ const result = await importConfig<() => Promise<T> | T>(configPath, {
74
+ baseDir,
75
+ extensions,
76
+ });
77
+
78
+ // Execute the configuration function (handles both sync and async)
79
+ const configFn = result.config;
80
+ if (typeof configFn === 'function') {
81
+ return await configFn();
82
+ }
83
+ // If config is not a function, treat it as the config object directly
84
+ return configFn as T;
85
+ }
86
+
87
+ export default loadFusionAIConfig;
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
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
+
12
+ export {
13
+ type FusionAIConfig,
14
+ type LoadFusionAIConfigOptions,
15
+ configureFusionAI,
16
+ loadFusionAIConfig,
17
+ } from './config.js';
18
+ export { setupFramework, FrameworkInstance } from './setup-framework.js';
19
+ export { registerAiPlugin } from './register.js';
@@ -0,0 +1,4 @@
1
+ export { default as options } from './options.js';
2
+ export { withOptions } from './with-options.js';
3
+ export { AiOptionsSchema, type AiOptionsType } from './schema.js';
4
+ export type { AiOptions } from './types.js';
@@ -0,0 +1,92 @@
1
+ import { createOption } from 'commander';
2
+
3
+ /**
4
+ * Option for specifying the Azure OpenAI API key.
5
+ * Required for authentication with Azure OpenAI services.
6
+ */
7
+ export const apiKeyOption = createOption(
8
+ '--openai-api-key <key>',
9
+ 'API key for Azure OpenAI services',
10
+ ).env('AZURE_OPENAI_API_KEY');
11
+
12
+ /**
13
+ * Option for specifying the Azure OpenAI API version.
14
+ * Defaults to the latest stable version if not provided.
15
+ */
16
+ export const apiVersionOption = createOption(
17
+ '--openai-api-version <version>',
18
+ 'Azure OpenAI API version',
19
+ )
20
+ .env('AZURE_OPENAI_API_VERSION')
21
+ .default('2024-02-15-preview');
22
+
23
+ /**
24
+ * Option for specifying the Azure OpenAI instance name.
25
+ * Required for Azure OpenAI service endpoint construction.
26
+ */
27
+ export const apiInstanceOption = createOption(
28
+ '--openai-instance <name>',
29
+ 'Azure OpenAI instance name',
30
+ ).env('AZURE_OPENAI_INSTANCE_NAME');
31
+
32
+ /**
33
+ * Option for specifying the Azure OpenAI deployment name for chat models.
34
+ * Required for chat completions API calls.
35
+ */
36
+ export const chatDeploymentOption = createOption(
37
+ '--openai-chat-deployment <name>',
38
+ 'Azure OpenAI chat deployment name',
39
+ ).env('AZURE_OPENAI_CHAT_DEPLOYMENT_NAME');
40
+
41
+ /**
42
+ * Option for specifying the Azure OpenAI deployment name for embedding models.
43
+ * Required for embeddings API calls.
44
+ */
45
+ export const embeddingDeploymentOption = createOption(
46
+ '--openai-embedding-deployment <name>',
47
+ 'Azure OpenAI embedding deployment name',
48
+ ).env('AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME');
49
+
50
+ /**
51
+ * Option for specifying the Azure Search endpoint URL.
52
+ * Required for Azure Cognitive Search operations.
53
+ */
54
+ export const azureSearchEndpointOption = createOption(
55
+ '--azure-search-endpoint <url>',
56
+ 'Azure Search endpoint URL',
57
+ ).env('AZURE_SEARCH_ENDPOINT');
58
+
59
+ /**
60
+ * Option for specifying the Azure Search API key.
61
+ * Required for authentication with Azure Cognitive Search.
62
+ */
63
+ export const azureSearchApiKeyOption = createOption(
64
+ '--azure-search-api-key <key>',
65
+ 'Azure Search API key',
66
+ ).env('AZURE_SEARCH_API_KEY');
67
+
68
+ /**
69
+ * Option for specifying the Azure Search index name.
70
+ * Required for search operations on a specific index.
71
+ */
72
+ export const azureSearchIndexNameOption = createOption(
73
+ '--azure-search-index-name <name>',
74
+ 'Azure Search index name',
75
+ ).env('AZURE_SEARCH_INDEX_NAME');
76
+
77
+ /**
78
+ * Default export containing all AI-related command options.
79
+ *
80
+ * Provides convenient access to all option definitions for use in CLI commands.
81
+ * Each option can also be imported individually for more granular control.
82
+ */
83
+ export default {
84
+ apiKeyOption,
85
+ apiVersionOption,
86
+ apiInstanceOption,
87
+ chatDeploymentOption,
88
+ embeddingDeploymentOption,
89
+ azureSearchEndpointOption,
90
+ azureSearchApiKeyOption,
91
+ azureSearchIndexNameOption,
92
+ };
@@ -0,0 +1,71 @@
1
+ import z from 'zod';
2
+
3
+ /**
4
+ * Base Zod schema for AI-related command options.
5
+ *
6
+ * This schema defines the validation rules for all AI options. Other AI plugins
7
+ * can extend this schema to add their own command-specific options.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { AiOptionsSchema } from '@equinor/fusion-framework-cli-plugin-ai-base';
12
+ * import { z } from 'zod';
13
+ *
14
+ * const MyCommandOptionsSchema = AiOptionsSchema.extend({
15
+ * myOption: z.string(),
16
+ * });
17
+ * ```
18
+ */
19
+ export const AiOptionsSchema = z
20
+ .object({
21
+ // Required AI options
22
+ openaiApiKey: z
23
+ .string({ message: 'Azure OpenAI API key is required and must be a non-empty string.' })
24
+ .min(1, 'API key must be a non-empty string.')
25
+ .describe('Azure OpenAI API key for authentication'),
26
+ openaiApiVersion: z
27
+ .string({ message: 'Azure OpenAI API version is required and must be a non-empty string.' })
28
+ .min(1, 'API version must be a non-empty string.')
29
+ .describe('Azure OpenAI API version'),
30
+ openaiInstance: z
31
+ .string({ message: 'Azure OpenAI instance name is required and must be a non-empty string.' })
32
+ .min(1, 'Instance name must be a non-empty string.')
33
+ .describe('Azure OpenAI instance name'),
34
+
35
+ // Optional AI options
36
+ openaiChatDeployment: z
37
+ .string()
38
+ .min(1, 'Chat deployment name must be a non-empty string.')
39
+ .optional()
40
+ .describe('Azure OpenAI chat deployment name'),
41
+ openaiEmbeddingDeployment: z
42
+ .string()
43
+ .min(1, 'Embedding deployment name must be a non-empty string.')
44
+ .optional()
45
+ .describe('Azure OpenAI embedding deployment name'),
46
+ azureSearchEndpoint: z
47
+ .string()
48
+ .url('Azure Search endpoint must be a valid URL.')
49
+ .min(1, 'Azure Search endpoint must be a non-empty string.')
50
+ .optional()
51
+ .describe('Azure Search endpoint URL'),
52
+ azureSearchApiKey: z
53
+ .string()
54
+ .min(1, 'Azure Search API key must be a non-empty string.')
55
+ .optional()
56
+ .describe('Azure Search API key'),
57
+ azureSearchIndexName: z
58
+ .string()
59
+ .min(1, 'Azure Search index name must be a non-empty string.')
60
+ .optional()
61
+ .describe('Azure Search index name'),
62
+ })
63
+ .describe('Base AI-related command options');
64
+
65
+ /**
66
+ * Type representing the validated AI options.
67
+ *
68
+ * This type is inferred from the Zod schema and should be used throughout AI plugins
69
+ * to ensure type safety and consistency with the schema.
70
+ */
71
+ export type AiOptionsType = z.infer<typeof AiOptionsSchema>;