@equinor/fusion-framework-cli-plugin-ai-base 2.0.1 → 4.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.
@@ -1,72 +1,55 @@
1
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';
2
+ import { initializeFramework, FusionEnv } from '@equinor/fusion-framework-cli/bin';
4
3
  /**
5
- * Initializes and configures the Fusion Framework with AI module capabilities.
4
+ * Creates a Fusion Framework instance with the AI module enabled.
6
5
  *
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.
6
+ * Uses Azure Identity's `DefaultAzureCredential` by default, which resolves
7
+ * credentials from the environment (OIDC, managed identity, Azure CLI, etc.).
8
+ * When an explicit token is provided via `--token` or `FUSION_TOKEN`, that
9
+ * token is used directly instead.
10
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
11
+ * @param options - CLI options resolved by {@link withOptions}.
12
+ * @returns A fully initialised framework instance with the AI module.
13
+ * @throws {Error} When authentication fails after the interactive retry.
23
14
  */
24
15
  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
- }));
16
+ const debug = options.debug ?? false;
17
+ // Auth strategy:
18
+ // 1. Explicit token (--token / FUSION_TOKEN) → direct token passthrough
19
+ // 2. Everything else → Azure Identity (DefaultAzureCredential)
20
+ const auth = options.token
21
+ ? { token: options.token }
22
+ : { defaultCredential: true };
23
+ const env = options.env ?? FusionEnv.ContinuesIntegration;
24
+ if (debug) {
25
+ console.debug('[debug] Environment:', env);
26
+ console.debug('[debug] Auth mode:', options.token ? 'static-token' : 'azure-identity');
27
+ }
28
+ /** Initialise the framework, resolve the AI service, and pre-cache tokens. */
29
+ const initAndSetup = async () => {
30
+ if (debug)
31
+ console.debug('[debug] Initializing framework with AI module…');
32
+ const framework = await initializeFramework({ env, auth }, (configurator) => {
33
+ enableAI(configurator);
34
+ });
35
+ // resolveService makes an authenticated HTTP call — will throw
36
+ // NoAccountsError if the user has never logged in.
37
+ const service = await framework.serviceDiscovery.resolveService('ai');
38
+ const scopes = service.scopes ?? service.defaultScopes ?? [];
39
+ if (debug) {
40
+ console.debug('[debug] AI service URL:', service.uri);
41
+ console.debug('[debug] AI service scopes:', scopes);
37
42
  }
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;
43
+ // Pre-cache a token for the AI service scopes so strategy callbacks
44
+ // don't attempt (and fail) a silent acquisition later.
45
+ const token = await framework.auth.acquireAccessToken({ request: { scopes } });
46
+ if (!token)
47
+ throw new Error('Failed to acquire access token for the AI service.');
48
+ if (debug)
49
+ console.debug('[debug] Token acquired successfully');
50
+ return framework;
51
+ };
52
+ return await initAndSetup();
70
53
  };
71
54
  export default setupFramework;
72
55
  //# sourceMappingURL=setup-framework.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"setup-framework.js","sourceRoot":"","sources":["../../src/setup-framework.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAuC,MAAM,qCAAqC,CAAC;AAEpG,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,2CAA2C,CAAC;AAGnD,OAAO,EAAE,mBAAmB,EAAwB,MAAM,kCAAkC,CAAC;AAW7F;;;;;;;;;;;;;;;;;;;GAmB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