@equinor/fusion-framework-cli-plugin-ai-base 2.0.1 → 3.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 +16 -0
- package/README.md +18 -26
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/options/options.js +38 -86
- package/dist/esm/options/options.js.map +1 -1
- package/dist/esm/options/schema.js +13 -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 +30 -89
- package/dist/esm/options/with-options.js.map +1 -1
- package/dist/esm/setup-framework.js +72 -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 +21 -84
- package/dist/types/options/schema.d.ts +12 -28
- package/dist/types/options/types.d.ts +17 -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 +54 -114
- package/src/options/schema.ts +13 -63
- package/src/options/types.ts +17 -37
- package/src/options/with-options.ts +36 -130
- package/src/setup-framework.ts +79 -84
- package/src/version.ts +1 -1
- package/tsconfig.json +3 -0
|
@@ -1,72 +1,82 @@
|
|
|
1
1
|
import { enableAI } from '@equinor/fusion-framework-module-ai';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { initializeFramework, FusionEnv } from '@equinor/fusion-framework-cli/bin';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Check whether an error (possibly wrapped in a cause chain) is an
|
|
6
|
+
* authentication-related failure that may be recoverable via interactive login.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
const isAuthError = (error) => {
|
|
11
|
+
let current = error;
|
|
12
|
+
while (current) {
|
|
13
|
+
if (current instanceof Error) {
|
|
14
|
+
if (current.name === 'NoAccountsError' ||
|
|
15
|
+
current.name === 'SilentTokenAcquisitionError' ||
|
|
16
|
+
current.message.includes('No accounts found')) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
current = current.cause;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Creates a Fusion Framework instance with the AI module enabled.
|
|
10
26
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* @param options
|
|
17
|
-
* @
|
|
18
|
-
* @
|
|
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
|
|
27
|
+
* Initialises the Fusion Framework with service discovery and MSAL auth,
|
|
28
|
+
* resolves the `'ai'` service endpoint, and pre-caches a bearer token.
|
|
29
|
+
* If MSAL has no cached credentials, the CLI's interactive `auth login`
|
|
30
|
+
* flow is spawned automatically before retrying.
|
|
31
|
+
*
|
|
32
|
+
* @param options - CLI options resolved by {@link withOptions}.
|
|
33
|
+
* @returns A fully initialised framework instance with the AI module.
|
|
34
|
+
* @throws {Error} When authentication fails after the interactive retry.
|
|
23
35
|
*/
|
|
24
36
|
export const setupFramework = async (options) => {
|
|
25
|
-
//
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
//
|
|
39
|
-
if
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
endpoint: options.azureSearchEndpoint,
|
|
62
|
-
key: options.azureSearchApiKey,
|
|
63
|
-
indexName: options.azureSearchIndexName,
|
|
64
|
-
}));
|
|
37
|
+
// Service-discovery mode: resolve URL + scopes from Fusion service registry
|
|
38
|
+
const auth = options.token
|
|
39
|
+
? { token: options.token }
|
|
40
|
+
: {
|
|
41
|
+
tenantId: options.tenantId ?? '3aa4a235-b6e2-48d5-9195-7fcf05b459b0',
|
|
42
|
+
clientId: options.clientId ?? 'a318b8e1-0295-4e17-98d5-35f67dfeba14',
|
|
43
|
+
};
|
|
44
|
+
const env = options.env ?? FusionEnv.ContinuesIntegration;
|
|
45
|
+
/** Initialise the framework, resolve the AI service, and pre-cache tokens. */
|
|
46
|
+
const initAndSetup = async () => {
|
|
47
|
+
const framework = await initializeFramework({ env, auth }, (configurator) => {
|
|
48
|
+
enableAI(configurator);
|
|
49
|
+
});
|
|
50
|
+
// resolveService makes an authenticated HTTP call — will throw
|
|
51
|
+
// NoAccountsError if the user has never logged in.
|
|
52
|
+
const service = await framework.serviceDiscovery.resolveService('ai');
|
|
53
|
+
const scopes = service.scopes ?? service.defaultScopes ?? [];
|
|
54
|
+
// Pre-cache a token for the AI service scopes so strategy callbacks
|
|
55
|
+
// don't attempt (and fail) a silent acquisition later.
|
|
56
|
+
const token = await framework.auth.acquireAccessToken({ request: { scopes } });
|
|
57
|
+
if (!token)
|
|
58
|
+
throw new Error('Failed to acquire access token for the AI service.');
|
|
59
|
+
return framework;
|
|
60
|
+
};
|
|
61
|
+
try {
|
|
62
|
+
return await initAndSetup();
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
// If the failure is auth-related and we're not using a static token,
|
|
66
|
+
// spawn the CLI's own `auth login` (starts local server + browser)
|
|
67
|
+
// and retry the full init sequence.
|
|
68
|
+
if (!isAuthError(error) || options.token)
|
|
69
|
+
throw error;
|
|
70
|
+
const cliEntry = process.argv[1];
|
|
71
|
+
if (!cliEntry) {
|
|
72
|
+
throw new Error('Failed to acquire access token and could not determine CLI path for interactive login.');
|
|
65
73
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
console.log('No cached credentials — launching interactive login…');
|
|
75
|
+
execFileSync(process.execPath, [cliEntry, 'auth', 'login'], {
|
|
76
|
+
stdio: 'inherit',
|
|
77
|
+
});
|
|
78
|
+
return await initAndSetup();
|
|
79
|
+
}
|
|
70
80
|
};
|
|
71
81
|
export default setupFramework;
|
|
72
82
|
//# 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;AAInF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKlD;;;;;GAKG;AACH,MAAM,WAAW,GAAG,CAAC,KAAc,EAAW,EAAE;IAC9C,IAAI,OAAO,GAAY,KAAK,CAAC;IAC7B,OAAO,OAAO,EAAE,CAAC;QACf,IAAI,OAAO,YAAY,KAAK,EAAE,CAAC;YAC7B,IACE,OAAO,CAAC,IAAI,KAAK,iBAAiB;gBAClC,OAAO,CAAC,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