@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.
- package/CHANGELOG.md +30 -0
- package/README.md +18 -26
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/options/options.js +43 -86
- package/dist/esm/options/options.js.map +1 -1
- package/dist/esm/options/schema.js +14 -55
- package/dist/esm/options/schema.js.map +1 -1
- package/dist/esm/options/types.js +0 -9
- package/dist/esm/options/types.js.map +1 -1
- package/dist/esm/options/with-options.js +31 -89
- package/dist/esm/options/with-options.js.map +1 -1
- package/dist/esm/setup-framework.js +45 -62
- package/dist/esm/setup-framework.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/options/options.d.ts +24 -84
- package/dist/types/options/schema.d.ts +13 -28
- package/dist/types/options/types.d.ts +19 -36
- package/dist/types/options/with-options.d.ts +13 -26
- package/dist/types/setup-framework.d.ts +13 -27
- package/dist/types/version.d.ts +1 -1
- package/package.json +5 -5
- package/src/index.ts +1 -1
- package/src/options/options.ts +55 -109
- package/src/options/schema.ts +14 -63
- package/src/options/types.ts +19 -37
- package/src/options/with-options.ts +38 -130
- package/src/setup-framework.ts +52 -88
- package/src/version.ts +1 -1
- package/tsconfig.json +3 -0
|
@@ -1,72 +1,55 @@
|
|
|
1
1
|
import { enableAI } from '@equinor/fusion-framework-module-ai';
|
|
2
|
-
import {
|
|
3
|
-
import { ModulesConfigurator } from '@equinor/fusion-framework-module';
|
|
2
|
+
import { initializeFramework, FusionEnv } from '@equinor/fusion-framework-cli/bin';
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
4
|
+
* Creates a Fusion Framework instance with the AI module enabled.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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 -
|
|
12
|
-
* @
|
|
13
|
-
* @
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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,
|
|
1
|
+
{"version":3,"file":"setup-framework.js","sourceRoot":"","sources":["../../src/setup-framework.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAG/D,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAOnF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,OAAkB,EAAwC,EAAE;IAC/F,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;IAErC,iBAAiB;IACjB,wEAAwE;IACxE,+DAA+D;IAC/D,MAAM,IAAI,GAAoC,OAAO,CAAC,KAAK;QACzD,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE;QAC1B,CAAC,CAAC,EAAE,iBAAiB,EAAE,IAAI,EA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