@auto-engineer/cli 0.11.16 → 0.11.17
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 +11 -0
- package/dist/src/server/config-loader.d.ts +1 -3
- package/dist/src/server/config-loader.d.ts.map +1 -1
- package/dist/src/server/config-loader.js +56 -59
- package/dist/src/server/config-loader.js.map +1 -1
- package/dist/src/server/file-syncer/crypto/jwe-encryptor.d.ts +15 -0
- package/dist/src/server/file-syncer/crypto/jwe-encryptor.d.ts.map +1 -0
- package/dist/src/server/file-syncer/crypto/jwe-encryptor.js +72 -0
- package/dist/src/server/file-syncer/crypto/jwe-encryptor.js.map +1 -0
- package/dist/src/server/file-syncer/crypto/provider-resolver.d.ts +24 -0
- package/dist/src/server/file-syncer/crypto/provider-resolver.d.ts.map +1 -0
- package/dist/src/server/file-syncer/crypto/provider-resolver.js +71 -0
- package/dist/src/server/file-syncer/crypto/provider-resolver.js.map +1 -0
- package/dist/src/server/file-syncer/discovery/bareImports.d.ts +1 -1
- package/dist/src/server/file-syncer/discovery/bareImports.d.ts.map +1 -1
- package/dist/src/server/file-syncer/discovery/dts.d.ts +1 -1
- package/dist/src/server/file-syncer/discovery/dts.d.ts.map +1 -1
- package/dist/src/server/file-syncer/index.d.ts +1 -0
- package/dist/src/server/file-syncer/index.d.ts.map +1 -1
- package/dist/src/server/file-syncer/index.js +57 -13
- package/dist/src/server/file-syncer/index.js.map +1 -1
- package/dist/src/server/file-syncer/sync/resolveSyncFileSet.d.ts +1 -1
- package/dist/src/server/file-syncer/sync/resolveSyncFileSet.d.ts.map +1 -1
- package/dist/src/server/file-syncer/utils/hash.d.ts +1 -1
- package/dist/src/server/file-syncer/utils/hash.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @auto-engineer/cli
|
|
2
2
|
|
|
3
|
+
## 0.11.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Separate node functionality from platform agnostic functionality
|
|
8
|
+
|
|
9
|
+
- Updated dependencies []:
|
|
10
|
+
- @auto-engineer/file-store@0.11.17
|
|
11
|
+
- @auto-engineer/message-bus@0.11.17
|
|
12
|
+
- @auto-engineer/message-store@0.11.17
|
|
13
|
+
|
|
3
14
|
## 0.11.16
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -6,13 +6,11 @@ export interface AutoConfig extends ConfigDefinition {
|
|
|
6
6
|
dir?: string;
|
|
7
7
|
extensions?: string[];
|
|
8
8
|
};
|
|
9
|
+
token?: string;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* Load and parse the auto.config.ts file
|
|
12
13
|
*/
|
|
13
14
|
export declare function loadAutoConfig(configPath: string): Promise<AutoConfig>;
|
|
14
|
-
/**
|
|
15
|
-
* Load message bus configuration and register handlers
|
|
16
|
-
*/
|
|
17
15
|
export declare function loadMessageBusConfig(configPath: string, server: MessageBusServer): Promise<void>;
|
|
18
16
|
//# sourceMappingURL=config-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../../src/server/config-loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAMjD,MAAM,WAAW,UAAW,SAAQ,gBAAgB;IAClD,QAAQ,CAAC,EAAE;QACT,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;KACvB,CAAC;
|
|
1
|
+
{"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../../src/server/config-loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAMjD,MAAM,WAAW,UAAW,SAAQ,gBAAgB;IAClD,QAAQ,CAAC,EAAE;QACT,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;KACvB,CAAC;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID;;GAEG;AACH,wBAAsB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAiC5E;AAsED,wBAAsB,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAatG"}
|
|
@@ -39,70 +39,67 @@ export async function loadAutoConfig(configPath) {
|
|
|
39
39
|
configLoading = false;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
async function loadAndRegisterPlugins(configPath, config, server) {
|
|
43
|
+
if (config.plugins === undefined || config.plugins.length === 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
debug('Loading plugins for metadata:', config.plugins);
|
|
48
|
+
const { PluginLoader } = await import('../plugin-loader.js');
|
|
49
|
+
const pluginLoader = new PluginLoader();
|
|
50
|
+
await pluginLoader.loadPlugins(configPath);
|
|
51
|
+
const unifiedHandlers = pluginLoader.getUnifiedHandlers();
|
|
52
|
+
const commandHandlers = Array.from(unifiedHandlers.values());
|
|
53
|
+
if (commandHandlers.length > 0) {
|
|
54
|
+
debug('Registering %d unified command handlers from plugins', commandHandlers.length);
|
|
55
|
+
server.registerCommandHandlers(commandHandlers);
|
|
56
|
+
}
|
|
57
|
+
debug('Loaded %d unified handlers from plugins', unifiedHandlers.size);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
debug('Failed to load plugin metadata:', error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function registerDslRegistration(registration, server) {
|
|
64
|
+
if (registration.type === 'on') {
|
|
65
|
+
debug('Registering event handler:', registration.eventType);
|
|
66
|
+
server.registerEventHandler(registration);
|
|
67
|
+
}
|
|
68
|
+
else if (registration.type === 'fold') {
|
|
69
|
+
debug('Registering fold:', registration.eventType);
|
|
70
|
+
server.registerFold(registration);
|
|
71
|
+
}
|
|
72
|
+
else if (registration.type === 'on-settled') {
|
|
73
|
+
debug('Registering settled handler:', registration.commandTypes);
|
|
74
|
+
server.registerSettledHandler(registration);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function executePipelineAndRegister(config, server) {
|
|
78
|
+
if (config.pipeline === undefined || typeof config.pipeline !== 'function') {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
debug('Executing pipeline function to collect DSL registrations');
|
|
48
82
|
getRegistrations();
|
|
49
83
|
getPendingDispatches();
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const pluginLoader = new PluginLoader();
|
|
57
|
-
await pluginLoader.loadPlugins(configPath);
|
|
58
|
-
// Register unified command handlers from plugin loader
|
|
59
|
-
const unifiedHandlers = pluginLoader.getUnifiedHandlers();
|
|
60
|
-
const commandHandlers = Array.from(unifiedHandlers.values());
|
|
61
|
-
if (commandHandlers.length > 0) {
|
|
62
|
-
debug('Registering %d unified command handlers from plugins', commandHandlers.length);
|
|
63
|
-
server.registerCommandHandlers(commandHandlers);
|
|
64
|
-
}
|
|
65
|
-
debug('Loaded %d unified handlers from plugins', unifiedHandlers.size);
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
debug('Failed to load plugin metadata:', error);
|
|
69
|
-
}
|
|
84
|
+
config.pipeline();
|
|
85
|
+
const registrations = getRegistrations();
|
|
86
|
+
debug('Collected %d registrations from pipeline', registrations.length);
|
|
87
|
+
server.setDslRegistrations(registrations);
|
|
88
|
+
for (const registration of registrations) {
|
|
89
|
+
registerDslRegistration(registration, server);
|
|
70
90
|
}
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
debug('
|
|
74
|
-
// Clear any previous registrations
|
|
75
|
-
getRegistrations();
|
|
76
|
-
getPendingDispatches();
|
|
77
|
-
// Execute the pipeline function
|
|
78
|
-
config.pipeline();
|
|
79
|
-
// Get and process registrations collected during pipeline execution
|
|
80
|
-
const registrations = getRegistrations();
|
|
81
|
-
debug('Collected %d registrations from pipeline', registrations.length);
|
|
82
|
-
// Store registrations in server for pipeline graph generation
|
|
83
|
-
server.setDslRegistrations(registrations);
|
|
84
|
-
for (const registration of registrations) {
|
|
85
|
-
if (registration.type === 'on') {
|
|
86
|
-
debug('Registering event handler:', registration.eventType);
|
|
87
|
-
server.registerEventHandler(registration);
|
|
88
|
-
}
|
|
89
|
-
else if (registration.type === 'fold') {
|
|
90
|
-
debug('Registering fold:', registration.eventType);
|
|
91
|
-
server.registerFold(registration);
|
|
92
|
-
}
|
|
93
|
-
else if (registration.type === 'on-settled') {
|
|
94
|
-
debug('Registering settled handler:', registration.commandTypes);
|
|
95
|
-
server.registerSettledHandler(registration);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
// Process any pending dispatches (shouldn't be any at config time)
|
|
99
|
-
const dispatches = getPendingDispatches();
|
|
100
|
-
if (dispatches.length > 0) {
|
|
101
|
-
debug('Warning: Found pending dispatches at config time:', dispatches.length);
|
|
102
|
-
}
|
|
91
|
+
const dispatches = getPendingDispatches();
|
|
92
|
+
if (dispatches.length > 0) {
|
|
93
|
+
debug('Warning: Found pending dispatches at config time:', dispatches.length);
|
|
103
94
|
}
|
|
95
|
+
}
|
|
96
|
+
export async function loadMessageBusConfig(configPath, server) {
|
|
97
|
+
getRegistrations();
|
|
98
|
+
getPendingDispatches();
|
|
99
|
+
const config = await loadAutoConfig(configPath);
|
|
100
|
+
await loadAndRegisterPlugins(configPath, config, server);
|
|
101
|
+
executePipelineAndRegister(config, server);
|
|
104
102
|
debug('Message bus configuration loaded and registered');
|
|
105
|
-
// Set up HTTP routes now that DSL registrations are available
|
|
106
103
|
server.setupRoutes();
|
|
107
104
|
debug('HTTP routes configured with DSL registrations');
|
|
108
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../../../src/server/config-loader.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,MAAM,CAAC;AAC9B,OAAO,WAAW,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAGhE,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAErC,MAAM,KAAK,GAAG,WAAW,CAAC,wBAAwB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../../../src/server/config-loader.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,MAAM,CAAC;AAC9B,OAAO,WAAW,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAGhE,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAErC,MAAM,KAAK,GAAG,WAAW,CAAC,wBAAwB,CAAC,CAAC;AAWpD,IAAI,aAAa,GAAG,KAAK,CAAC;AAE1B;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,UAAkB;IACrD,IAAI,aAAa,EAAE,CAAC;QAClB,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACxD,OAA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AAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface TokenPayload {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
provider: 'openai' | 'anthropic' | 'google' | 'xai' | 'custom';
|
|
4
|
+
model?: string;
|
|
5
|
+
custom?: {
|
|
6
|
+
name: string;
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
defaultModel: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare function createJWE(payload: TokenPayload & {
|
|
12
|
+
roomId: string;
|
|
13
|
+
}): Promise<string>;
|
|
14
|
+
export declare function clearPublicKeyCache(): void;
|
|
15
|
+
//# sourceMappingURL=jwe-encryptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwe-encryptor.d.ts","sourceRoot":"","sources":["../../../../../src/server/file-syncer/crypto/jwe-encryptor.ts"],"names":[],"mappings":"AAyDA,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,CAAC;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;CAClE;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAuB3F;AAED,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { EncryptJWT, importJWK } from 'jose';
|
|
2
|
+
import fetch from 'node-fetch';
|
|
3
|
+
import createDebug from 'debug';
|
|
4
|
+
const debug = createDebug('auto:cli:jwe-encryptor');
|
|
5
|
+
const PUBLIC_JWKS_URL = 'https://sync-sandbox.rami-632.workers.dev/.well-known/jwks.json';
|
|
6
|
+
const PUBLIC_KEY_CACHE_TTL_MS = 60 * 60 * 300; // 1h
|
|
7
|
+
const JWE_TTL_SECONDS = 1800;
|
|
8
|
+
const AUDIENCE = 'cf-worker-ai';
|
|
9
|
+
let cached = null;
|
|
10
|
+
async function fetchJWKS() {
|
|
11
|
+
debug('Fetching JWKS: %s', PUBLIC_JWKS_URL);
|
|
12
|
+
const res = await fetch(PUBLIC_JWKS_URL, { headers: { accept: 'application/json' } });
|
|
13
|
+
if (!res.ok)
|
|
14
|
+
throw new Error(`Failed JWKS fetch: ${res.status} ${res.statusText}`);
|
|
15
|
+
return (await res.json());
|
|
16
|
+
}
|
|
17
|
+
function pickEncryptionKey(jwks) {
|
|
18
|
+
const candidate = jwks.keys.find((k) => k.kty === 'RSA' &&
|
|
19
|
+
(k.use === 'enc' || k.use === undefined) &&
|
|
20
|
+
(k.alg === undefined || k.alg === 'RSA-OAEP' || k.alg === 'RSA-OAEP-256') &&
|
|
21
|
+
k.n !== undefined &&
|
|
22
|
+
k.e !== undefined &&
|
|
23
|
+
k.kid !== undefined);
|
|
24
|
+
if (candidate === undefined)
|
|
25
|
+
throw new Error('No suitable RSA encryption key in JWKS');
|
|
26
|
+
return candidate;
|
|
27
|
+
}
|
|
28
|
+
async function getCachedPublicKey() {
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
if (cached !== null && now - cached.fetchedAt < PUBLIC_KEY_CACHE_TTL_MS) {
|
|
31
|
+
debug('Using cached JWKS key (kid=%s)', cached.jwk.kid);
|
|
32
|
+
return cached;
|
|
33
|
+
}
|
|
34
|
+
const jwks = await fetchJWKS();
|
|
35
|
+
const jwk = pickEncryptionKey(jwks);
|
|
36
|
+
const alg = jwk.alg ?? 'RSA-OAEP-256';
|
|
37
|
+
const imported = await importJWK(jwk, alg);
|
|
38
|
+
const keyLike = imported instanceof Uint8Array ? imported : imported;
|
|
39
|
+
if (!keyLike.type) {
|
|
40
|
+
throw new Error('importJWK did not return a valid KeyLike');
|
|
41
|
+
}
|
|
42
|
+
const newCached = { keyLike: keyLike, jwk, fetchedAt: now };
|
|
43
|
+
cached = newCached;
|
|
44
|
+
debug('Cached new JWKS key (kid=%s, alg=%s)', jwk.kid, alg);
|
|
45
|
+
return newCached;
|
|
46
|
+
}
|
|
47
|
+
export async function createJWE(payload) {
|
|
48
|
+
const { keyLike, jwk } = await getCachedPublicKey();
|
|
49
|
+
const now = Math.floor(Date.now() / 1000);
|
|
50
|
+
const jwt = new EncryptJWT({
|
|
51
|
+
apiKey: payload.apiKey,
|
|
52
|
+
provider: payload.provider,
|
|
53
|
+
roomId: payload.roomId,
|
|
54
|
+
model: payload.model,
|
|
55
|
+
custom: payload.custom,
|
|
56
|
+
})
|
|
57
|
+
.setProtectedHeader({
|
|
58
|
+
alg: jwk.alg ?? 'RSA-OAEP-256',
|
|
59
|
+
enc: 'A256GCM',
|
|
60
|
+
kid: jwk.kid,
|
|
61
|
+
})
|
|
62
|
+
.setIssuedAt(now)
|
|
63
|
+
.setExpirationTime(now + JWE_TTL_SECONDS)
|
|
64
|
+
.setAudience(AUDIENCE);
|
|
65
|
+
const jwe = await jwt.encrypt(keyLike);
|
|
66
|
+
debug('Created JWE (kid=%s, exp in %ss)', jwk.kid, JWE_TTL_SECONDS);
|
|
67
|
+
return jwe;
|
|
68
|
+
}
|
|
69
|
+
export function clearPublicKeyCache() {
|
|
70
|
+
cached = null;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=jwe-encryptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwe-encryptor.js","sourceRoot":"","sources":["../../../../../src/server/file-syncer/crypto/jwe-encryptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAqB,MAAM,MAAM,CAAC;AAChE,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,WAAW,MAAM,OAAO,CAAC;AAEhC,MAAM,KA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IAE1C,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC;QACzB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC;SACC,kBAAkB,CAAC;QAClB,GAAG,EAAG,GAAG,CAAC,GAAc,IAAI,cAAc;QAC1C,GAAG,EAAE,SAAS;QACd,GAAG,EAAE,GAAG,CAAC,GAAa;KACvB,CAAC;SACD,WAAW,CAAC,GAAG,CAAC;SAChB,iBAAiB,CAAC,GAAG,GAAG,eAAe,CAAC;SACxC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAEzB,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,KAAK,CAAC,kCAAkC,EAAE,GAAG,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IACpE,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,MAAM,GAAG,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare enum AIProvider {
|
|
2
|
+
OpenAI = "openai",
|
|
3
|
+
Anthropic = "anthropic",
|
|
4
|
+
Google = "google",
|
|
5
|
+
XAI = "xai",
|
|
6
|
+
Custom = "custom"
|
|
7
|
+
}
|
|
8
|
+
export type ActiveProvider = {
|
|
9
|
+
provider: Exclude<AIProvider, AIProvider.Custom>;
|
|
10
|
+
apiKey: string;
|
|
11
|
+
model?: string;
|
|
12
|
+
} | {
|
|
13
|
+
provider: AIProvider.Custom;
|
|
14
|
+
apiKey: string;
|
|
15
|
+
model?: string;
|
|
16
|
+
custom: {
|
|
17
|
+
name: string;
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
defaultModel: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export declare function getActiveProvider(): ActiveProvider | null;
|
|
23
|
+
export declare function getProviderEnvHash(): string;
|
|
24
|
+
//# sourceMappingURL=provider-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-resolver.d.ts","sourceRoot":"","sources":["../../../../../src/server/file-syncer/crypto/provider-resolver.ts"],"names":[],"mappings":"AAIA,oBAAY,UAAU;IACpB,MAAM,WAAW;IACjB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,GAAG,QAAQ;IACX,MAAM,WAAW;CAClB;AAED,MAAM,MAAM,cAAc,GACtB;IAAE,QAAQ,EAAE,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GACpF;IACE,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;CACjE,CAAC;AA6BN,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,IAAI,CAoBzD;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAe3C"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
export var AIProvider;
|
|
5
|
+
(function (AIProvider) {
|
|
6
|
+
AIProvider["OpenAI"] = "openai";
|
|
7
|
+
AIProvider["Anthropic"] = "anthropic";
|
|
8
|
+
AIProvider["Google"] = "google";
|
|
9
|
+
AIProvider["XAI"] = "xai";
|
|
10
|
+
AIProvider["Custom"] = "custom";
|
|
11
|
+
})(AIProvider || (AIProvider = {}));
|
|
12
|
+
let envLoaded = false;
|
|
13
|
+
function ensureEnv() {
|
|
14
|
+
if (envLoaded)
|
|
15
|
+
return;
|
|
16
|
+
dotenv.config({ path: resolve(process.cwd(), '.env') });
|
|
17
|
+
envLoaded = true;
|
|
18
|
+
}
|
|
19
|
+
function resolveCustom() {
|
|
20
|
+
const name = process.env.CUSTOM_PROVIDER_NAME;
|
|
21
|
+
const baseUrl = process.env.CUSTOM_PROVIDER_BASE_URL;
|
|
22
|
+
const apiKey = process.env.CUSTOM_PROVIDER_API_KEY;
|
|
23
|
+
const defaultModel = process.env.CUSTOM_PROVIDER_DEFAULT_MODEL;
|
|
24
|
+
if (name !== undefined &&
|
|
25
|
+
name.length > 0 &&
|
|
26
|
+
baseUrl !== undefined &&
|
|
27
|
+
baseUrl.length > 0 &&
|
|
28
|
+
apiKey !== undefined &&
|
|
29
|
+
apiKey.length > 0 &&
|
|
30
|
+
defaultModel !== undefined &&
|
|
31
|
+
defaultModel.length > 0) {
|
|
32
|
+
return { provider: AIProvider.Custom, apiKey, custom: { name, baseUrl, defaultModel } };
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
export function getActiveProvider() {
|
|
37
|
+
ensureEnv();
|
|
38
|
+
const model = process.env.DEFAULT_AI_MODEL ?? undefined;
|
|
39
|
+
const probes = [
|
|
40
|
+
[AIProvider.Anthropic, 'ANTHROPIC_API_KEY'],
|
|
41
|
+
[AIProvider.OpenAI, 'OPENAI_API_KEY'],
|
|
42
|
+
[AIProvider.Google, 'GEMINI_API_KEY'],
|
|
43
|
+
[AIProvider.XAI, 'XAI_API_KEY'],
|
|
44
|
+
];
|
|
45
|
+
for (const [provider, envVar] of probes) {
|
|
46
|
+
const apiKey = process.env[envVar];
|
|
47
|
+
if (apiKey !== undefined)
|
|
48
|
+
return { provider, apiKey, model };
|
|
49
|
+
}
|
|
50
|
+
const custom = resolveCustom();
|
|
51
|
+
if (custom !== null)
|
|
52
|
+
return { ...custom, model };
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
export function getProviderEnvHash() {
|
|
56
|
+
ensureEnv();
|
|
57
|
+
const keys = [
|
|
58
|
+
'ANTHROPIC_API_KEY',
|
|
59
|
+
'OPENAI_API_KEY',
|
|
60
|
+
'GEMINI_API_KEY',
|
|
61
|
+
'XAI_API_KEY',
|
|
62
|
+
'CUSTOM_PROVIDER_NAME',
|
|
63
|
+
'CUSTOM_PROVIDER_BASE_URL',
|
|
64
|
+
'CUSTOM_PROVIDER_API_KEY',
|
|
65
|
+
'CUSTOM_PROVIDER_DEFAULT_MODEL',
|
|
66
|
+
'DEFAULT_AI_MODEL',
|
|
67
|
+
];
|
|
68
|
+
const joined = keys.map((k) => process.env[k] ?? '').join('|');
|
|
69
|
+
return crypto.createHash('md5').update(joined).digest('hex');
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=provider-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-resolver.js","sourceRoot":"","sources":["../../../../../src/server/file-syncer/crypto/provider-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,MAAM,CAAN,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,+BAAiB,CAAA;IACjB,qCAAuB,CAAA;IACvB,+BAAiB,CAAA;IACjB,yBAAW,CAAA;IACX,+BAAiB,CAAA;AACnB,CAAC,EANW,UAAU,KAAV,UAAU,QAMrB;AAWD,IAAI,SAAS,GAAG,KAAK,CAAC;AACtB,SAAS,SAAS;IAChB,IAAI,SAAS;QAAE,OAAO;IACtB,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IACxD,SAAS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C,CAAC;QACnC,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAC/D,CAAC;IAED,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;IAC/B,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC;IAEjD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,SAAS,EAAE,CAAC;IACZ,MAAM,IAAI,GAAG;QACX,mBAAmB;QACnB,gBAAgB;QAChB,gBAAgB;QAChB,aAAa;QACb,sBAAsB;QACtB,0BAA0B;QAC1B,yBAAyB;QACzB,+BAA+B;QAC/B,kBAAkB;KACnB,CAAC;IACF,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/D,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { NodeFileStore } from '@auto-engineer/file-store';
|
|
1
|
+
import { NodeFileStore } from '@auto-engineer/file-store/node';
|
|
2
2
|
export declare function collectBareImportsFromFiles(files: string[], vfs: NodeFileStore): Promise<string[]>;
|
|
3
3
|
//# sourceMappingURL=bareImports.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bareImports.d.ts","sourceRoot":"","sources":["../../../../../src/server/file-syncer/discovery/bareImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"bareImports.d.ts","sourceRoot":"","sources":["../../../../../src/server/file-syncer/discovery/bareImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAiB/D,wBAAsB,2BAA2B,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAkBxG"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NodeFileStore } from '@auto-engineer/file-store';
|
|
1
|
+
import { NodeFileStore } from '@auto-engineer/file-store/node';
|
|
2
2
|
export declare function readJsonIfExists(vfs: NodeFileStore, p: string): Promise<Record<string, unknown> | null>;
|
|
3
3
|
export declare function exists(vfs: NodeFileStore, p: string): Promise<boolean>;
|
|
4
4
|
export declare function typesAlias(pkg: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dts.d.ts","sourceRoot":"","sources":["../../../../../src/server/file-syncer/discovery/dts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"dts.d.ts","sourceRoot":"","sources":["../../../../../src/server/file-syncer/discovery/dts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAM/D,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,aAAa,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAQ7G;AAED,wBAAsB,MAAM,CAAC,GAAG,EAAE,aAAa,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAO5E;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM9C;AAED,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,SAAI,GAAG,MAAM,EAAE,CAYpE;AAED,yEAAyE;AACzE,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAoBjH;AAED,iGAAiG;AACjG,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,aAAa,EAClB,OAAO,EAAE,MAAM,EAAE,EACjB,IAAI,EAAE,MAAM,EAAE,GACb,OAAO,CAAC,MAAM,EAAE,CAAC,CAuCnB"}
|
|
@@ -13,6 +13,7 @@ export declare class FileSyncer {
|
|
|
13
13
|
private pendingInitialFiles;
|
|
14
14
|
private autoConfigHash;
|
|
15
15
|
private autoConfigContent;
|
|
16
|
+
private providerEnvHash;
|
|
16
17
|
constructor(io: SocketIOServer, watchDir?: string, _extensions?: string[]);
|
|
17
18
|
start(): void;
|
|
18
19
|
private findAutoConfigFile;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/file-syncer/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/file-syncer/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,WAAW,CAAC;AAe1D,qBAAa,UAAU;IACrB,OAAO,CAAC,EAAE,CAAiB;IAC3B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,GAAG,CAAgB;IAC3B,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,OAAO,CAAC,CAAqB;IACrC,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,kBAAkB,CAA+B;IACzD,OAAO,CAAC,eAAe,CAAa;IACpC,OAAO,CAAC,gBAAgB,CAA4B;IACpD,OAAO,CAAC,mBAAmB,CAAqC;IAChE,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,iBAAiB,CAAiB;IAC1C,OAAO,CAAC,eAAe,CAAuB;gBAElC,EAAE,EAAE,cAAc,EAAE,QAAQ,SAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE;IAQtE,KAAK,IAAI,IAAI;YA8VC,kBAAkB;IAiBhC,IAAI,IAAI,IAAI;CAWb"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import chokidar from 'chokidar';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import createDebug from 'debug';
|
|
4
|
-
import { NodeFileStore } from '@auto-engineer/file-store';
|
|
4
|
+
import { NodeFileStore } from '@auto-engineer/file-store/node';
|
|
5
5
|
import { resolveSyncFileSet } from './sync/resolveSyncFileSet.js';
|
|
6
6
|
import { loadAutoConfig } from '../config-loader.js';
|
|
7
7
|
import { md5, readBase64, statSize } from './utils/hash.js';
|
|
8
8
|
import { toWirePath, fromWirePath, rebuildWirePathCache } from './utils/path.js';
|
|
9
|
+
import { createJWE } from './crypto/jwe-encryptor.js';
|
|
10
|
+
import { getActiveProvider, getProviderEnvHash } from './crypto/provider-resolver.js';
|
|
9
11
|
const debug = createDebug('auto:cli:file-syncer');
|
|
10
12
|
export class FileSyncer {
|
|
11
13
|
constructor(io, watchDir = '.', _extensions) {
|
|
@@ -16,6 +18,7 @@ export class FileSyncer {
|
|
|
16
18
|
this.pendingInitialFiles = null;
|
|
17
19
|
this.autoConfigHash = null;
|
|
18
20
|
this.autoConfigContent = null;
|
|
21
|
+
this.providerEnvHash = null;
|
|
19
22
|
this.io = io;
|
|
20
23
|
this.watchDir = path.resolve(watchDir);
|
|
21
24
|
this.projectRoot = path.dirname(this.watchDir);
|
|
@@ -23,13 +26,41 @@ export class FileSyncer {
|
|
|
23
26
|
this.active = new Map();
|
|
24
27
|
}
|
|
25
28
|
start() {
|
|
26
|
-
const serializeConfig =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
const serializeConfig = async (cfg, fileId) => {
|
|
30
|
+
let configWithCreds = cfg;
|
|
31
|
+
try {
|
|
32
|
+
const active = getActiveProvider();
|
|
33
|
+
if (active !== null) {
|
|
34
|
+
const jwe = await createJWE({
|
|
35
|
+
provider: active.provider,
|
|
36
|
+
apiKey: active.apiKey,
|
|
37
|
+
model: active.model,
|
|
38
|
+
custom: active.provider === 'custom' ? active.custom : undefined,
|
|
39
|
+
roomId: fileId,
|
|
40
|
+
});
|
|
41
|
+
if (typeof cfg === 'object' && cfg !== null) {
|
|
42
|
+
configWithCreds = {
|
|
43
|
+
...cfg,
|
|
44
|
+
token: jwe,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
debug('Added token to config for provider: %s', active.provider);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
debug('No active provider found, skipping credential encryption');
|
|
51
|
+
}
|
|
30
52
|
}
|
|
31
|
-
|
|
32
|
-
|
|
53
|
+
catch (error) {
|
|
54
|
+
debug('Failed to encrypt credentials, continuing without: %O', error);
|
|
55
|
+
}
|
|
56
|
+
return JSON.stringify(configWithCreds, (key, value) => {
|
|
57
|
+
if (typeof value === 'function') {
|
|
58
|
+
const funcName = value.name;
|
|
59
|
+
return `[Function: ${funcName != null ? funcName : 'anonymous'}]`;
|
|
60
|
+
}
|
|
61
|
+
return value;
|
|
62
|
+
}, 2);
|
|
63
|
+
};
|
|
33
64
|
const getVirtualConfigWirePath = () => {
|
|
34
65
|
const virtualPath = path.join(this.watchDir, 'auto.config.json');
|
|
35
66
|
return toWirePath(virtualPath, this.projectRoot);
|
|
@@ -69,7 +100,9 @@ export class FileSyncer {
|
|
|
69
100
|
files.push({ path: wire, content });
|
|
70
101
|
}
|
|
71
102
|
if (this.autoConfigContent !== null) {
|
|
72
|
-
const
|
|
103
|
+
const configWithFileId = this.autoConfigContent;
|
|
104
|
+
const serializedConfig = await serializeConfig(this.autoConfigContent, configWithFileId.fileId);
|
|
105
|
+
const virtualContent = Buffer.from(serializedConfig, 'utf8').toString('base64');
|
|
73
106
|
files.push({ path: getVirtualConfigWirePath(), content: virtualContent });
|
|
74
107
|
debug('Added virtual auto.config.json to initial sync');
|
|
75
108
|
}
|
|
@@ -159,25 +192,36 @@ export class FileSyncer {
|
|
|
159
192
|
if (autoConfigPath === null) {
|
|
160
193
|
if (this.autoConfigContent !== null) {
|
|
161
194
|
debug('Auto config removed, emitting delete');
|
|
162
|
-
// Create the virtual auto.config.json path relative to watchDir like regular files
|
|
163
195
|
const virtualPath = path.join(this.watchDir, 'auto.config.json');
|
|
164
196
|
const virtualWirePath = toWirePath(virtualPath, this.projectRoot);
|
|
165
197
|
this.io.emit('file-change', { event: 'delete', path: virtualWirePath });
|
|
166
198
|
this.autoConfigContent = null;
|
|
167
199
|
this.autoConfigHash = null;
|
|
200
|
+
this.providerEnvHash = null;
|
|
168
201
|
}
|
|
169
202
|
return;
|
|
170
203
|
}
|
|
171
204
|
const currentHash = await md5(this.vfs, autoConfigPath);
|
|
172
|
-
|
|
205
|
+
const currentProviderEnvHash = getProviderEnvHash();
|
|
206
|
+
const configChanged = currentHash !== null && currentHash !== this.autoConfigHash;
|
|
207
|
+
const envChanged = currentProviderEnvHash !== this.providerEnvHash;
|
|
208
|
+
if (!configChanged && !envChanged) {
|
|
173
209
|
return;
|
|
174
210
|
}
|
|
175
|
-
|
|
211
|
+
if (configChanged) {
|
|
212
|
+
debug('Auto config changed, executing and syncing');
|
|
213
|
+
}
|
|
214
|
+
if (envChanged) {
|
|
215
|
+
debug('Provider environment changed, regenerating token');
|
|
216
|
+
}
|
|
176
217
|
const config = await loadAutoConfig(autoConfigPath);
|
|
177
|
-
const wasPresent = this.autoConfigContent !== null;
|
|
218
|
+
const wasPresent = this.autoConfigContent !== null;
|
|
178
219
|
this.autoConfigContent = config;
|
|
179
220
|
this.autoConfigHash = currentHash;
|
|
180
|
-
|
|
221
|
+
this.providerEnvHash = currentProviderEnvHash;
|
|
222
|
+
const configWithFileId = config;
|
|
223
|
+
const serializedConfig = await serializeConfig(config, configWithFileId.fileId);
|
|
224
|
+
const virtualContent = Buffer.from(serializedConfig, 'utf8').toString('base64');
|
|
181
225
|
const virtualWirePath = getVirtualConfigWirePath();
|
|
182
226
|
const eventType = wasPresent ? 'change' : 'add';
|
|
183
227
|
this.io.emit('file-change', {
|