@defai.digital/provider-detection 13.0.3
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/LICENSE +214 -0
- package/dist/detection-adapter.d.ts +27 -0
- package/dist/detection-adapter.d.ts.map +1 -0
- package/dist/detection-adapter.js +208 -0
- package/dist/detection-adapter.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
AutomatosX Open Source Edition - Apache License 2.0
|
|
2
|
+
|
|
3
|
+
This license applies ONLY to the AutomatosX Open Source Edition code
|
|
4
|
+
published on GitHub at https://github.com/defai-digital/automatosx
|
|
5
|
+
|
|
6
|
+
This license does NOT apply to:
|
|
7
|
+
- AutomatosX Pro Edition (proprietary software - separate EULA)
|
|
8
|
+
- AutomatosX Enterprise Edition (proprietary software - separate agreement)
|
|
9
|
+
|
|
10
|
+
For commercial editions, see COMMERCIAL-LICENSE.md
|
|
11
|
+
|
|
12
|
+
===============================================================================
|
|
13
|
+
|
|
14
|
+
Apache License
|
|
15
|
+
Version 2.0, January 2004
|
|
16
|
+
http://www.apache.org/licenses/
|
|
17
|
+
|
|
18
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
19
|
+
|
|
20
|
+
1. Definitions.
|
|
21
|
+
|
|
22
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
23
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
24
|
+
|
|
25
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
26
|
+
the copyright owner that is granting the License.
|
|
27
|
+
|
|
28
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
29
|
+
other entities that control, are controlled by, or are under common
|
|
30
|
+
control with that entity. For the purposes of this definition,
|
|
31
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
32
|
+
direction or management of such entity, whether by contract or
|
|
33
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
34
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
35
|
+
|
|
36
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
37
|
+
exercising permissions granted by this License.
|
|
38
|
+
|
|
39
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
40
|
+
including but not limited to software source code, documentation
|
|
41
|
+
source, and configuration files.
|
|
42
|
+
|
|
43
|
+
"Object" form shall mean any form resulting from mechanical
|
|
44
|
+
transformation or translation of a Source form, including but
|
|
45
|
+
not limited to compiled object code, generated documentation,
|
|
46
|
+
and conversions to other media types.
|
|
47
|
+
|
|
48
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
49
|
+
Object form, made available under the License, as indicated by a
|
|
50
|
+
copyright notice that is included in or attached to the work
|
|
51
|
+
(an example is provided in the Appendix below).
|
|
52
|
+
|
|
53
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
54
|
+
form, that is based on (or derived from) the Work and for which the
|
|
55
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
56
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
57
|
+
of this License, Derivative Works shall not include works that remain
|
|
58
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
59
|
+
the Work and Derivative Works thereof.
|
|
60
|
+
|
|
61
|
+
"Contribution" shall mean any work of authorship, including
|
|
62
|
+
the original version of the Work and any modifications or additions
|
|
63
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
64
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
65
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
66
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
67
|
+
means any form of electronic, verbal, or written communication sent
|
|
68
|
+
to the Licensor or its representatives, including but not limited to
|
|
69
|
+
communication on electronic mailing lists, source code control systems,
|
|
70
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
71
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
72
|
+
excluding communication that is conspicuously marked or otherwise
|
|
73
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
74
|
+
|
|
75
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
76
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
77
|
+
subsequently incorporated within the Work.
|
|
78
|
+
|
|
79
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
80
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
81
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
82
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
83
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
84
|
+
Work and such Derivative Works in Source or Object form.
|
|
85
|
+
|
|
86
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
87
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
88
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
89
|
+
(except as stated in this section) patent license to make, have made,
|
|
90
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
91
|
+
where such license applies only to those patent claims licensable
|
|
92
|
+
by such Contributor that are necessarily infringed by their
|
|
93
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
94
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
95
|
+
institute patent litigation against any entity (including a
|
|
96
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
97
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
98
|
+
or contributory patent infringement, then any patent licenses
|
|
99
|
+
granted to You under this License for that Work shall terminate
|
|
100
|
+
as of the date such litigation is filed.
|
|
101
|
+
|
|
102
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
103
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
104
|
+
modifications, and in Source or Object form, provided that You
|
|
105
|
+
meet the following conditions:
|
|
106
|
+
|
|
107
|
+
(a) You must give any other recipients of the Work or
|
|
108
|
+
Derivative Works a copy of this License; and
|
|
109
|
+
|
|
110
|
+
(b) You must cause any modified files to carry prominent notices
|
|
111
|
+
stating that You changed the files; and
|
|
112
|
+
|
|
113
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
114
|
+
that You distribute, all copyright, patent, trademark, and
|
|
115
|
+
attribution notices from the Source form of the Work,
|
|
116
|
+
excluding those notices that do not pertain to any part of
|
|
117
|
+
the Derivative Works; and
|
|
118
|
+
|
|
119
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
120
|
+
distribution, then any Derivative Works that You distribute must
|
|
121
|
+
include a readable copy of the attribution notices contained
|
|
122
|
+
within such NOTICE file, excluding those notices that do not
|
|
123
|
+
pertain to any part of the Derivative Works, in at least one
|
|
124
|
+
of the following places: within a NOTICE text file distributed
|
|
125
|
+
as part of the Derivative Works; within the Source form or
|
|
126
|
+
documentation, if provided along with the Derivative Works; or,
|
|
127
|
+
within a display generated by the Derivative Works, if and
|
|
128
|
+
wherever such third-party notices normally appear. The contents
|
|
129
|
+
of the NOTICE file are for informational purposes only and
|
|
130
|
+
do not modify the License. You may add Your own attribution
|
|
131
|
+
notices within Derivative Works that You distribute, alongside
|
|
132
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
133
|
+
that such additional attribution notices cannot be construed
|
|
134
|
+
as modifying the License.
|
|
135
|
+
|
|
136
|
+
You may add Your own copyright statement to Your modifications and
|
|
137
|
+
may provide additional or different license terms and conditions
|
|
138
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
139
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
140
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
141
|
+
the conditions stated in this License.
|
|
142
|
+
|
|
143
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
144
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
145
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
146
|
+
this License, without any additional terms or conditions.
|
|
147
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
148
|
+
the terms of any separate license agreement you may have executed
|
|
149
|
+
with Licensor regarding such Contributions.
|
|
150
|
+
|
|
151
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
152
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
153
|
+
except as required for reasonable and customary use in describing the
|
|
154
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
155
|
+
|
|
156
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
157
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
158
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
159
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
160
|
+
implied, including, without limitation, any warranties or conditions
|
|
161
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
162
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
163
|
+
appropriateness of using or redistributing the Work and assume any
|
|
164
|
+
risks associated with Your exercise of permissions under this License.
|
|
165
|
+
|
|
166
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
167
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
168
|
+
unless required by applicable law (such as deliberate and grossly
|
|
169
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
170
|
+
liable to You for damages, including any direct, indirect, special,
|
|
171
|
+
incidental, or consequential damages of any character arising as a
|
|
172
|
+
result of this License or out of the use or inability to use the
|
|
173
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
174
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
175
|
+
other commercial damages or losses), even if such Contributor
|
|
176
|
+
has been advised of the possibility of such damages.
|
|
177
|
+
|
|
178
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
179
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
180
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
181
|
+
or other liability obligations and/or rights consistent with this
|
|
182
|
+
License. However, in accepting such obligations, You may act only
|
|
183
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
184
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
185
|
+
defend, and hold each Contributor harmless for any liability
|
|
186
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
187
|
+
of your accepting any such warranty or additional liability.
|
|
188
|
+
|
|
189
|
+
END OF TERMS AND CONDITIONS
|
|
190
|
+
|
|
191
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
192
|
+
|
|
193
|
+
To apply the Apache License to your work, attach the following
|
|
194
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
195
|
+
replaced with your own identifying information. (Don't include
|
|
196
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
197
|
+
comment syntax for the file format. We also recommend that a
|
|
198
|
+
file or class name and description of purpose be included on the
|
|
199
|
+
same "printed page" as the copyright notice for easier
|
|
200
|
+
identification within third-party archives.
|
|
201
|
+
|
|
202
|
+
Copyright 2024-2025 DEFAI Private Limited
|
|
203
|
+
|
|
204
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
205
|
+
you may not use this file except in compliance with the License.
|
|
206
|
+
You may obtain a copy of the License at
|
|
207
|
+
|
|
208
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
209
|
+
|
|
210
|
+
Unless required by applicable law or agreed to in writing, software
|
|
211
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
212
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
213
|
+
See the License for the specific language governing permissions and
|
|
214
|
+
limitations under the License.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Detection Adapter
|
|
3
|
+
*
|
|
4
|
+
* Implements the ProviderDetectionPort interface for detecting installed provider CLIs.
|
|
5
|
+
*
|
|
6
|
+
* Invariants:
|
|
7
|
+
* - INV-CFG-ADP-002: Detection times out after 5s
|
|
8
|
+
* - INV-CFG-ADP-003: No network calls during detection
|
|
9
|
+
*
|
|
10
|
+
* Note: AutomatosX does NOT check authentication.
|
|
11
|
+
* All CLIs handle their own authentication internally.
|
|
12
|
+
*/
|
|
13
|
+
import type { ProviderDetectionPort, DetectionOptions } from '@defai.digital/config-domain';
|
|
14
|
+
/**
|
|
15
|
+
* Provider detection adapter
|
|
16
|
+
*
|
|
17
|
+
* Implements the ProviderDetectionPort interface for the config domain.
|
|
18
|
+
*
|
|
19
|
+
* Note: AutomatosX is a pure orchestrator.
|
|
20
|
+
* All CLIs handle their own authentication internally.
|
|
21
|
+
*/
|
|
22
|
+
export declare const providerDetectionAdapter: ProviderDetectionPort;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a provider detection adapter with custom options
|
|
25
|
+
*/
|
|
26
|
+
export declare function createProviderDetectionAdapter(defaultOptions?: DetectionOptions): ProviderDetectionPort;
|
|
27
|
+
//# sourceMappingURL=detection-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detection-adapter.d.ts","sourceRoot":"","sources":["../src/detection-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAyM5F;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,EAAE,qBAGtC,CAAC;AAEF;;GAEG;AACH,wBAAgB,8BAA8B,CAC5C,cAAc,CAAC,EAAE,gBAAgB,GAChC,qBAAqB,CAUvB"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Detection Adapter
|
|
3
|
+
*
|
|
4
|
+
* Implements the ProviderDetectionPort interface for detecting installed provider CLIs.
|
|
5
|
+
*
|
|
6
|
+
* Invariants:
|
|
7
|
+
* - INV-CFG-ADP-002: Detection times out after 5s
|
|
8
|
+
* - INV-CFG-ADP-003: No network calls during detection
|
|
9
|
+
*
|
|
10
|
+
* Note: AutomatosX does NOT check authentication.
|
|
11
|
+
* All CLIs handle their own authentication internally.
|
|
12
|
+
*/
|
|
13
|
+
import { exec } from 'node:child_process';
|
|
14
|
+
import { promisify } from 'node:util';
|
|
15
|
+
import { KNOWN_PROVIDERS, PROVIDER_DEFAULTS, createDetectionSummary, TIMEOUT_HEALTH_CHECK, TIMEOUT_FORCE_KILL, } from '@defai.digital/contracts';
|
|
16
|
+
const execAsync = promisify(exec);
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Constants
|
|
19
|
+
// ============================================================================
|
|
20
|
+
/**
|
|
21
|
+
* Default detection timeout
|
|
22
|
+
* INV-CFG-ADP-002: Detection times out after 5s
|
|
23
|
+
*/
|
|
24
|
+
const DEFAULT_TIMEOUT = TIMEOUT_HEALTH_CHECK;
|
|
25
|
+
/**
|
|
26
|
+
* Timeout for individual command check
|
|
27
|
+
*/
|
|
28
|
+
const COMMAND_CHECK_TIMEOUT = TIMEOUT_FORCE_KILL;
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// Helper Functions
|
|
31
|
+
// ============================================================================
|
|
32
|
+
/**
|
|
33
|
+
* Validates a command name to prevent command injection
|
|
34
|
+
* Only allows alphanumeric characters, hyphens, underscores, and dots
|
|
35
|
+
*
|
|
36
|
+
* @param command - The command to validate
|
|
37
|
+
* @returns true if the command is safe, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
function isValidCommandName(command) {
|
|
40
|
+
// Must be non-empty and contain only safe characters
|
|
41
|
+
// Allows: letters, numbers, hyphens, underscores, dots (for extensions like .exe)
|
|
42
|
+
return /^[a-zA-Z0-9_.-]+$/.test(command);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Checks if a CLI command is available on the system PATH
|
|
46
|
+
*/
|
|
47
|
+
async function isCommandAvailable(command) {
|
|
48
|
+
// Validate command to prevent command injection
|
|
49
|
+
if (!isValidCommandName(command)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const whichCommand = process.platform === 'win32' ? 'where' : 'which';
|
|
54
|
+
await execAsync(`${whichCommand} ${command}`, { timeout: COMMAND_CHECK_TIMEOUT });
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Gets the version of a CLI command
|
|
63
|
+
*/
|
|
64
|
+
async function getCommandVersion(command) {
|
|
65
|
+
// Validate command to prevent command injection
|
|
66
|
+
if (!isValidCommandName(command)) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const { stdout } = await execAsync(`${command} --version`, {
|
|
71
|
+
timeout: COMMAND_CHECK_TIMEOUT,
|
|
72
|
+
});
|
|
73
|
+
// Extract version number from output
|
|
74
|
+
const versionMatch = /(\d+\.\d+\.\d+(?:-[a-zA-Z0-9.]+)?)/.exec(stdout);
|
|
75
|
+
return versionMatch?.[1];
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// ============================================================================
|
|
82
|
+
// Detection Adapter Implementation
|
|
83
|
+
// ============================================================================
|
|
84
|
+
/**
|
|
85
|
+
* Detects a single provider
|
|
86
|
+
*
|
|
87
|
+
* Note: AutomatosX does NOT check authentication.
|
|
88
|
+
* All CLIs handle their own auth internally.
|
|
89
|
+
* If a CLI is detected, it's considered ready to use.
|
|
90
|
+
*/
|
|
91
|
+
async function detectProvider(providerId) {
|
|
92
|
+
const defaults = PROVIDER_DEFAULTS[providerId];
|
|
93
|
+
if (defaults === undefined) {
|
|
94
|
+
return {
|
|
95
|
+
providerId,
|
|
96
|
+
detected: false,
|
|
97
|
+
command: providerId, // Use providerId as fallback command name
|
|
98
|
+
error: `Unknown provider: ${providerId}`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const command = defaults.command;
|
|
102
|
+
// Check if command is available
|
|
103
|
+
const detected = await isCommandAvailable(command);
|
|
104
|
+
if (!detected) {
|
|
105
|
+
return {
|
|
106
|
+
providerId,
|
|
107
|
+
detected: false,
|
|
108
|
+
command,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
// Get command version
|
|
112
|
+
const version = await getCommandVersion(command);
|
|
113
|
+
return {
|
|
114
|
+
providerId,
|
|
115
|
+
detected: true,
|
|
116
|
+
command,
|
|
117
|
+
version,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Detects all known providers in parallel
|
|
122
|
+
*/
|
|
123
|
+
async function detectAllProviders(options) {
|
|
124
|
+
const providersToDetect = options?.providers ?? [...KNOWN_PROVIDERS];
|
|
125
|
+
const timeout = options?.timeout ?? DEFAULT_TIMEOUT;
|
|
126
|
+
// Track partial results as they complete
|
|
127
|
+
const partialResults = new Map();
|
|
128
|
+
// Create a timeout promise
|
|
129
|
+
let timeoutId;
|
|
130
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
131
|
+
timeoutId = setTimeout(() => {
|
|
132
|
+
reject(new Error(`Detection timed out after ${timeout}ms`));
|
|
133
|
+
}, timeout);
|
|
134
|
+
});
|
|
135
|
+
// Detect all providers in parallel, tracking partial results
|
|
136
|
+
const detectionPromise = Promise.all(providersToDetect.map(async (providerId) => {
|
|
137
|
+
try {
|
|
138
|
+
const result = await detectProvider(providerId);
|
|
139
|
+
partialResults.set(providerId, result);
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
const defaults = PROVIDER_DEFAULTS[providerId];
|
|
144
|
+
const result = {
|
|
145
|
+
providerId,
|
|
146
|
+
detected: false,
|
|
147
|
+
command: defaults?.command ?? providerId,
|
|
148
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
149
|
+
};
|
|
150
|
+
partialResults.set(providerId, result);
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
}));
|
|
154
|
+
try {
|
|
155
|
+
const results = await Promise.race([detectionPromise, timeoutPromise]);
|
|
156
|
+
clearTimeout(timeoutId);
|
|
157
|
+
return createDetectionSummary(results);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
clearTimeout(timeoutId);
|
|
161
|
+
// On timeout, return partial results collected so far
|
|
162
|
+
const results = providersToDetect.map((providerId) => {
|
|
163
|
+
const partialResult = partialResults.get(providerId);
|
|
164
|
+
if (partialResult !== undefined) {
|
|
165
|
+
return partialResult;
|
|
166
|
+
}
|
|
167
|
+
// Provider detection was still in progress when timeout occurred
|
|
168
|
+
const defaults = PROVIDER_DEFAULTS[providerId];
|
|
169
|
+
return {
|
|
170
|
+
providerId,
|
|
171
|
+
detected: false,
|
|
172
|
+
command: defaults?.command ?? providerId,
|
|
173
|
+
error: error instanceof Error ? error.message : 'Detection timed out',
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
return createDetectionSummary(results);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// ============================================================================
|
|
180
|
+
// Exported Adapter
|
|
181
|
+
// ============================================================================
|
|
182
|
+
/**
|
|
183
|
+
* Provider detection adapter
|
|
184
|
+
*
|
|
185
|
+
* Implements the ProviderDetectionPort interface for the config domain.
|
|
186
|
+
*
|
|
187
|
+
* Note: AutomatosX is a pure orchestrator.
|
|
188
|
+
* All CLIs handle their own authentication internally.
|
|
189
|
+
*/
|
|
190
|
+
export const providerDetectionAdapter = {
|
|
191
|
+
detectProvider,
|
|
192
|
+
detectAllProviders,
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Creates a provider detection adapter with custom options
|
|
196
|
+
*/
|
|
197
|
+
export function createProviderDetectionAdapter(defaultOptions) {
|
|
198
|
+
return {
|
|
199
|
+
detectProvider,
|
|
200
|
+
async detectAllProviders(options) {
|
|
201
|
+
return detectAllProviders({
|
|
202
|
+
...defaultOptions,
|
|
203
|
+
...options,
|
|
204
|
+
});
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=detection-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detection-adapter.js","sourceRoot":"","sources":["../src/detection-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAIL,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAElC,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAElC,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,eAAe,GAAG,oBAAoB,CAAC;AAE7C;;GAEG;AACH,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAEjD,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,OAAe;IACzC,qDAAqD;IACrD,kFAAkF;IAClF,OAAO,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,kBAAkB,CAAC,OAAe;IAC/C,gDAAgD;IAChD,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;QACtE,MAAM,SAAS,CAAC,GAAG,YAAY,IAAI,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,qBAAqB,EAAE,CAAC,CAAC;QAClF,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CA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;QACL,cAAc;QACd,KAAK,CAAC,kBAAkB,CAAC,OAA0B;YACjD,OAAO,kBAAkB,CAAC;gBACxB,GAAG,cAAc;gBACjB,GAAG,OAAO;aACX,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @defai.digital/provider-detection
|
|
3
|
+
*
|
|
4
|
+
* Provider CLI detection adapter for AutomatosX.
|
|
5
|
+
*
|
|
6
|
+
* This adapter implements the ProviderDetectionPort interface from config-domain,
|
|
7
|
+
* detecting installed provider CLIs and their authentication status.
|
|
8
|
+
*
|
|
9
|
+
* Design:
|
|
10
|
+
* - Uses local filesystem and PATH checks only
|
|
11
|
+
* - No network calls during detection (INV-CFG-ADP-003)
|
|
12
|
+
* - Times out after 5s (INV-CFG-ADP-002)
|
|
13
|
+
*/
|
|
14
|
+
export { providerDetectionAdapter, createProviderDetectionAdapter, } from './detection-adapter.js';
|
|
15
|
+
export type { ProviderDetectionPort, DetectionOptions, } from '@defai.digital/config-domain';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,wBAAwB,EACxB,8BAA8B,GAC/B,MAAM,wBAAwB,CAAC;AAGhC,YAAY,EACV,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,8BAA8B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @defai.digital/provider-detection
|
|
3
|
+
*
|
|
4
|
+
* Provider CLI detection adapter for AutomatosX.
|
|
5
|
+
*
|
|
6
|
+
* This adapter implements the ProviderDetectionPort interface from config-domain,
|
|
7
|
+
* detecting installed provider CLIs and their authentication status.
|
|
8
|
+
*
|
|
9
|
+
* Design:
|
|
10
|
+
* - Uses local filesystem and PATH checks only
|
|
11
|
+
* - No network calls during detection (INV-CFG-ADP-003)
|
|
12
|
+
* - Times out after 5s (INV-CFG-ADP-002)
|
|
13
|
+
*/
|
|
14
|
+
export { providerDetectionAdapter, createProviderDetectionAdapter, } from './detection-adapter.js';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,wBAAwB,EACxB,8BAA8B,GAC/B,MAAM,wBAAwB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@defai.digital/provider-detection",
|
|
3
|
+
"version": "13.0.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Provider CLI detection adapter for AutomatosX",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "DEFAI Private Limited",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/defai-digital/automatosx.git",
|
|
11
|
+
"directory": "packages/adapters/provider-detection"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/defai-digital/automatosx#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/defai-digital/automatosx/issues"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=20.0.0"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@defai.digital/config-domain": "13.0.3",
|
|
34
|
+
"@defai.digital/contracts": "13.0.3",
|
|
35
|
+
"@defai.digital/provider-adapters": "13.0.3"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"typescript": "^5.7.2"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc --build",
|
|
42
|
+
"clean": "rm -rf dist"
|
|
43
|
+
}
|
|
44
|
+
}
|