forked from nexu-io/open-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamr-model-probe.ts
More file actions
71 lines (67 loc) · 2.04 KB
/
Copy pathamr-model-probe.ts
File metadata and controls
71 lines (67 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import {
applyAgentLaunchEnv,
getAgentDef,
resolveAgentLaunch,
spawnEnvForAgent,
} from '../agents.js';
import { agentCliEnvForAgent, type readAppConfig } from '../app-config.js';
import { readVelaCredentialRevision } from '../integrations/vela.js';
import type { VelaCredentialRevision } from '../integrations/vela.js';
export interface ResolveAmrModelProbeDeps {
dataDir: string;
env: NodeJS.ProcessEnv;
readAppConfig: typeof readAppConfig;
}
export interface BuildAmrModelCacheKeyInput {
launchPath: string;
env: NodeJS.ProcessEnv;
credentialRevision: VelaCredentialRevision;
}
export function buildAmrModelCacheKey({
launchPath,
env,
credentialRevision,
}: BuildAmrModelCacheKeyInput): string {
return JSON.stringify({
launchPath,
home: env.HOME ?? env.USERPROFILE ?? '',
openDesignAmrProfile: env.OPEN_DESIGN_AMR_PROFILE ?? '',
velaProfile: env.VELA_PROFILE ?? '',
velaLinkUrl: env.VELA_LINK_URL ?? '',
velaRuntimeKey: env.VELA_RUNTIME_KEY ?? '',
velaOpencodeBin: env.VELA_OPENCODE_BIN ?? '',
credentialRevision,
});
}
export async function resolveAmrModelProbe({
dataDir,
env: baseEnv,
readAppConfig,
}: ResolveAmrModelProbeDeps) {
const appConfig = await readAppConfig(dataDir);
const configuredEnv = agentCliEnvForAgent(appConfig.agentCliEnv, 'amr');
const def = getAgentDef('amr');
if (!def) throw new Error('AMR runtime definition is missing');
const agentLaunch = resolveAgentLaunch(def, configuredEnv);
const launchPath = agentLaunch.launchPath ?? agentLaunch.selectedPath;
if (!launchPath) throw new Error('AMR vela binary could not be resolved');
const env = applyAgentLaunchEnv(
spawnEnvForAgent(
def.id,
{
...baseEnv,
...(def.env || {}),
},
configuredEnv,
undefined,
),
agentLaunch,
);
const credentialRevision = readVelaCredentialRevision(baseEnv, configuredEnv);
const cacheKey = buildAmrModelCacheKey({
launchPath,
env,
credentialRevision,
});
return { launchPath, env, configuredEnv, cacheKey };
}