@jini-ai/agent-runtime 0.4.11 → 0.4.12
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 +4 -0
- package/dist/acp-model-probe.d.ts +2 -20
- package/dist/agent-protocol/acp/json.js +46 -37
- package/dist/agent-protocol/acp/models.js +91 -73
- package/dist/agent-protocol/acp/rpc.d.ts +3 -2
- package/dist/agent-protocol/acp/rpc.js +3 -2
- package/dist/agent-protocol/acp/session-params.d.ts +1 -1
- package/dist/agent-protocol/acp/session-params.js +33 -30
- package/dist/agent-protocol/acp/session.d.ts +3 -1
- package/dist/agent-protocol/acp/session.js +62 -24
- package/dist/agent-protocol/acp/updates.js +49 -35
- package/dist/agent-protocol/pi-rpc/session.js +3 -1
- package/dist/anthropic-live-models.d.ts +12 -4
- package/dist/anthropic-live-models.js +0 -0
- package/dist/auth.js +84 -91
- package/dist/claude-code-models.d.ts +6 -5
- package/dist/claude-code-models.js +19 -12
- package/dist/claude-segment-usage.d.ts +3 -3
- package/dist/claude-segment-usage.js +63 -29
- package/dist/claude-stream.js +12 -5
- package/dist/copilot-stream.js +42 -50
- package/dist/defs/aider.js +3 -4
- package/dist/defs/amr.js +52 -61
- package/dist/defs/antigravity.d.ts +6 -5
- package/dist/defs/antigravity.js +48 -34
- package/dist/defs/auggie.d.ts +1 -1
- package/dist/defs/claude-compatible-args.d.ts +19 -0
- package/dist/defs/claude-compatible-args.js +42 -0
- package/dist/defs/claude.d.ts +7 -2
- package/dist/defs/claude.js +96 -85
- package/dist/defs/cline.d.ts +1 -1
- package/dist/defs/codebuddy.d.ts +1 -1
- package/dist/defs/codebuddy.js +29 -46
- package/dist/defs/codex.d.ts +15 -3
- package/dist/defs/codex.js +143 -108
- package/dist/defs/cursor-agent.d.ts +9 -7
- package/dist/defs/cursor-agent.js +53 -51
- package/dist/defs/devin.d.ts +1 -1
- package/dist/defs/goose.d.ts +1 -1
- package/dist/defs/hermes.d.ts +1 -1
- package/dist/defs/kilo.d.ts +1 -1
- package/dist/defs/kimi.d.ts +1 -1
- package/dist/defs/kiro.d.ts +1 -1
- package/dist/defs/opencode.d.ts +5 -4
- package/dist/defs/opencode.js +26 -32
- package/dist/defs/pi.d.ts +6 -5
- package/dist/defs/pi.js +24 -26
- package/dist/defs/qoder.d.ts +4 -3
- package/dist/defs/qoder.js +25 -25
- package/dist/defs/reasonix.d.ts +1 -1
- package/dist/defs/shared.d.ts +12 -3
- package/dist/defs/shared.js +19 -13
- package/dist/defs/trae-cli.d.ts +1 -1
- package/dist/defs/vibe.d.ts +1 -1
- package/dist/detection.d.ts +13 -20
- package/dist/detection.js +129 -111
- package/dist/env.js +56 -41
- package/dist/executables.js +103 -114
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/json-event-stream.js +611 -527
- package/dist/launch.js +44 -37
- package/dist/model-discovery-adapters.d.ts +17 -0
- package/dist/model-discovery-adapters.js +223 -164
- package/dist/model-discovery-config.js +107 -87
- package/dist/model-discovery-sdk.d.ts +16 -2
- package/dist/model-discovery-sdk.js +4 -3
- package/dist/model-discovery-shared.d.ts +14 -0
- package/dist/model-discovery-shared.js +50 -15
- package/dist/model-discovery-types.d.ts +2 -0
- package/dist/model-discovery.js +219 -117
- package/dist/models.d.ts +14 -1
- package/dist/models.js +75 -19
- package/dist/native-tool-policy.d.ts +29 -0
- package/dist/native-tool-policy.js +36 -0
- package/dist/opencode-log.js +46 -30
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +3 -3
- package/dist/providers/aihubmix.js +13 -18
- package/dist/providers/anthropic-messages.d.ts +7 -0
- package/dist/providers/anthropic-messages.js +45 -21
- package/dist/providers/azure-chat.d.ts +5 -0
- package/dist/providers/azure-chat.js +13 -5
- package/dist/providers/connection-guard.d.ts +2 -45
- package/dist/providers/connection-guard.js +11 -10
- package/dist/providers/connection-test.d.ts +4 -0
- package/dist/providers/connection-test.js +127 -110
- package/dist/providers/elevenlabs.js +4 -1
- package/dist/providers/google-messages.d.ts +4 -0
- package/dist/providers/google-messages.js +48 -23
- package/dist/providers/google-schema.js +17 -23
- package/dist/providers/model-catalog.js +160 -145
- package/dist/providers/oauth-callback-server.js +37 -34
- package/dist/providers/oauth-credentials.js +23 -23
- package/dist/providers/oauth-tokens.js +16 -24
- package/dist/providers/openai-chat.d.ts +42 -0
- package/dist/providers/openai-chat.js +80 -10
- package/dist/providers/operation-schema.d.ts +25 -0
- package/dist/providers/operation-schema.js +226 -0
- package/dist/providers/response-text.d.ts +10 -0
- package/dist/providers/response-text.js +23 -0
- package/dist/providers/tool-turn-types.d.ts +35 -9
- package/dist/providers/tool-turn.d.ts +7 -0
- package/dist/providers/tool-turn.js +113 -32
- package/dist/qoder-stream.js +93 -80
- package/dist/registry.d.ts +45 -0
- package/dist/registry.js +39 -0
- package/dist/runtime-state.d.ts +1 -1
- package/dist/types.d.ts +43 -1
- package/package.json +16 -7
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
const json = (path, key = 'model') => ({ path, format: 'json', key });
|
|
4
|
+
function codexConfigFiles({ env, context, user, local }) {
|
|
5
|
+
const root = env.CODEX_HOME || user('.codex');
|
|
6
|
+
return [{ path: join(root, 'config.toml'), format: 'toml' },
|
|
7
|
+
...(context.profile ? [{ path: join(root, `${context.profile}.config.toml`), format: 'toml' }] : []),
|
|
8
|
+
{ path: local('.codex/config.toml'), format: 'toml' }];
|
|
9
|
+
}
|
|
10
|
+
function claudeConfigFiles({ env, context, user, root }) {
|
|
11
|
+
const claudeRoot = env.CLAUDE_CONFIG_DIR || user('.claude');
|
|
12
|
+
const sources = context.settingSources ?? ['user', 'project', 'local'];
|
|
13
|
+
return [...(sources.includes('user') ? [json(join(claudeRoot, 'settings.json'))] : []),
|
|
14
|
+
...(sources.includes('project') ? [json(root('.claude/settings.json'))] : []),
|
|
15
|
+
...(sources.includes('local') ? [json(root('.claude/settings.local.json'))] : [])];
|
|
16
|
+
}
|
|
17
|
+
const CONFIG_FILES = new Map([
|
|
18
|
+
['codex', codexConfigFiles],
|
|
19
|
+
['claude', claudeConfigFiles],
|
|
20
|
+
['antigravity', ({ user }) => [json(user('.gemini/antigravity-cli/settings.json'))]],
|
|
21
|
+
['opencode', ({ env, user, configHome, root, local }) => [json(join(env.XDG_STATE_HOME || user('.local/state'), 'opencode/model.json'), 'recent'), json(join(configHome, 'opencode/opencode.json')), json(join(configHome, 'opencode/opencode.jsonc')), json(root('opencode.json')), json(root('opencode.jsonc')), json(local('opencode.json')), json(local('opencode.jsonc'))]],
|
|
22
|
+
['pi', ({ env, user, local }) => [json(join(env.PI_CODING_AGENT_DIR || user('.pi/agent'), 'settings.json'), 'defaultModel'), json(local('.pi/settings.json'), 'defaultModel')]],
|
|
23
|
+
['aider', ({ context, user, root, local }) => context.configPath ? [{ path: context.configPath, format: 'yaml' }] : [{ path: user('.aider.conf.yml'), format: 'yaml' }, { path: root('.aider.conf.yml'), format: 'yaml' }, { path: local('.aider.conf.yml'), format: 'yaml' }]],
|
|
24
|
+
// UNVERIFIED locally: the survey documents these settings, not installed schema behavior.
|
|
25
|
+
['grok-build', ({ user }) => [{ path: user('.grok/config.toml'), format: 'toml', key: 'models.model' }]],
|
|
26
|
+
['codebuddy', ({ user, local }) => [json(user('.codebuddy/settings.json')), json(local('.codebuddy/settings.json')), json(local('.codebuddy/settings.local.json'))]],
|
|
27
|
+
['copilot', ({ user }) => [json(user('.copilot/config.json'))]],
|
|
28
|
+
['cursor-agent', ({ user }) => [json(user('.cursor/cli-config.json'))]],
|
|
29
|
+
['droid', ({ user }) => [json(user('.factory/settings.json'), 'sessionDefaultSettings.model')]],
|
|
30
|
+
['qoder', ({ env, user, local }) => [json(join(env.QODER_CONFIG_DIR || user('.qoder'), 'settings.json'), 'model.name'), json(local('.qoder/settings.json'), 'model.name'), json(local('.qoder/settings.local.json'), 'model.name')]],
|
|
31
|
+
['qwen', ({ user, local }) => [json(user('.qwen/settings.json'), 'model.name'), json(local('.qwen/settings.json'), 'model.name')]],
|
|
32
|
+
['deepseek', ({ user }) => [{ path: user('.deepseek/config.toml'), format: 'toml' }, { path: user('.codewhale/config.toml'), format: 'toml' }]],
|
|
33
|
+
['mimo', ({ configHome, local }) => [json(join(configHome, 'mimocode/mimocode.json')), json(local('.mimocode/mimocode.jsonc'))]],
|
|
34
|
+
['crush', ({ configHome, local }) => [json(join(configHome, 'crush/crush.json'), 'models.large.model'), json(local('crush.json'), 'models.large.model')]],
|
|
35
|
+
]);
|
|
4
36
|
/** Config-file resolvers read only settings, never auth-store contents. Precedence is applied
|
|
5
37
|
* from global to workspace/local. Unknown native priorities remain unresolved, not invented. */
|
|
6
38
|
export function modelConfigFiles(agentId, context) {
|
|
@@ -10,37 +42,7 @@ export function modelConfigFiles(agentId, context) {
|
|
|
10
42
|
const local = (name) => join(context.cwd, name);
|
|
11
43
|
const root = (name) => join(context.projectRoot || context.cwd, name);
|
|
12
44
|
const configHome = env.XDG_CONFIG_HOME || user('.config');
|
|
13
|
-
|
|
14
|
-
case 'codex': {
|
|
15
|
-
const root = env.CODEX_HOME || user('.codex');
|
|
16
|
-
return [{ path: join(root, 'config.toml'), format: 'toml' },
|
|
17
|
-
...(context.profile ? [{ path: join(root, `${context.profile}.config.toml`), format: 'toml' }] : []),
|
|
18
|
-
{ path: local('.codex/config.toml'), format: 'toml' }];
|
|
19
|
-
}
|
|
20
|
-
case 'claude': {
|
|
21
|
-
const claudeRoot = env.CLAUDE_CONFIG_DIR || user('.claude');
|
|
22
|
-
const sources = context.settingSources ?? ['user', 'project', 'local'];
|
|
23
|
-
return [...(sources.includes('user') ? [json(join(claudeRoot, 'settings.json'))] : []),
|
|
24
|
-
...(sources.includes('project') ? [json(root('.claude/settings.json'))] : []),
|
|
25
|
-
...(sources.includes('local') ? [json(root('.claude/settings.local.json'))] : [])];
|
|
26
|
-
}
|
|
27
|
-
case 'antigravity': return [json(user('.gemini/antigravity-cli/settings.json'))];
|
|
28
|
-
case 'opencode': return [json(join(env.XDG_STATE_HOME || user('.local/state'), 'opencode/model.json'), 'recent'), json(join(configHome, 'opencode/opencode.json')), json(join(configHome, 'opencode/opencode.jsonc')), json(root('opencode.json')), json(root('opencode.jsonc')), json(local('opencode.json')), json(local('opencode.jsonc'))];
|
|
29
|
-
case 'pi': return [json(join(env.PI_CODING_AGENT_DIR || user('.pi/agent'), 'settings.json'), 'defaultModel'), json(local('.pi/settings.json'), 'defaultModel')];
|
|
30
|
-
case 'aider': return context.configPath ? [{ path: context.configPath, format: 'yaml' }] : [{ path: user('.aider.conf.yml'), format: 'yaml' }, { path: root('.aider.conf.yml'), format: 'yaml' }, { path: local('.aider.conf.yml'), format: 'yaml' }];
|
|
31
|
-
// UNVERIFIED locally: the survey documents these settings, not installed schema behavior.
|
|
32
|
-
case 'grok-build': return [{ path: user('.grok/config.toml'), format: 'toml', key: 'models.model' }];
|
|
33
|
-
case 'codebuddy': return [json(user('.codebuddy/settings.json')), json(local('.codebuddy/settings.json')), json(local('.codebuddy/settings.local.json'))];
|
|
34
|
-
case 'copilot': return [json(user('.copilot/config.json'))];
|
|
35
|
-
case 'cursor-agent': return [json(user('.cursor/cli-config.json'))];
|
|
36
|
-
case 'droid': return [json(user('.factory/settings.json'), 'sessionDefaultSettings.model')];
|
|
37
|
-
case 'qoder': return [json(join(env.QODER_CONFIG_DIR || user('.qoder'), 'settings.json'), 'model.name'), json(local('.qoder/settings.json'), 'model.name'), json(local('.qoder/settings.local.json'), 'model.name')];
|
|
38
|
-
case 'qwen': return [json(user('.qwen/settings.json'), 'model.name'), json(local('.qwen/settings.json'), 'model.name')];
|
|
39
|
-
case 'deepseek': return [{ path: user('.deepseek/config.toml'), format: 'toml' }, { path: user('.codewhale/config.toml'), format: 'toml' }];
|
|
40
|
-
case 'mimo': return [json(join(configHome, 'mimocode/mimocode.json')), json(local('.mimocode/mimocode.jsonc'))];
|
|
41
|
-
case 'crush': return [json(join(configHome, 'crush/crush.json'), 'models.large.model'), json(local('crush.json'), 'models.large.model')];
|
|
42
|
-
default: return [];
|
|
43
|
-
}
|
|
45
|
+
return CONFIG_FILES.get(agentId)?.({ env, context, configHome, user, local, root }) ?? [];
|
|
44
46
|
}
|
|
45
47
|
export function parseSettingsJson(raw) {
|
|
46
48
|
try {
|
|
@@ -57,29 +59,27 @@ function scalar(value) { return typeof value === 'string' && value.trim() ? valu
|
|
|
57
59
|
function dotted(value, key) {
|
|
58
60
|
return key.split('.').reduce((item, part) => item && typeof item === 'object' ? item[part] : undefined, value);
|
|
59
61
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// Cursor's model object subkeys are undocumented: never guess which one is the effective id.
|
|
71
|
-
const id = scalar(model);
|
|
72
|
-
if (file.key === 'defaultModel' && id) {
|
|
73
|
-
const provider = scalar(settings?.defaultProvider);
|
|
74
|
-
return provider ? `${provider}/${id}` : undefined;
|
|
75
|
-
}
|
|
76
|
-
return id;
|
|
62
|
+
/** "provider/id" when both parts are present; a bare id is never guessed into a provider. */
|
|
63
|
+
function qualified(provider, id) {
|
|
64
|
+
return provider && id ? `${provider}/${id}` : undefined;
|
|
65
|
+
}
|
|
66
|
+
function parseJsonModel(file, raw) {
|
|
67
|
+
const settings = parseSettingsJson(raw);
|
|
68
|
+
const model = dotted(settings, file.key || 'model');
|
|
69
|
+
if (file.key === 'recent' && Array.isArray(model)) {
|
|
70
|
+
const first = model[0];
|
|
71
|
+
return qualified(scalar(first?.providerID), scalar(first?.modelID));
|
|
77
72
|
}
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
// Cursor's model object subkeys are undocumented: never guess which one is the effective id.
|
|
74
|
+
const id = scalar(model);
|
|
75
|
+
if (file.key === 'defaultModel' && id)
|
|
76
|
+
return qualified(scalar(settings?.defaultProvider), id);
|
|
77
|
+
return id;
|
|
78
|
+
}
|
|
79
|
+
/** Every quoted `model = "..."` assignment with the TOML section it appears in. */
|
|
80
|
+
function tomlModelAssignments(raw) {
|
|
80
81
|
let section = '';
|
|
81
|
-
|
|
82
|
-
let profileChoice;
|
|
82
|
+
const assignments = [];
|
|
83
83
|
for (const line of raw.split('\n')) {
|
|
84
84
|
const header = line.match(/^\s*\[([^\]]+)\]/);
|
|
85
85
|
if (header) {
|
|
@@ -87,51 +87,71 @@ export function parseConfiguredModel(file, raw, profile) {
|
|
|
87
87
|
continue;
|
|
88
88
|
}
|
|
89
89
|
const match = line.match(/^\s*model\s*=\s*["']([^"']+)["']/);
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
if (profile && section === `profiles.${profile}`)
|
|
93
|
-
profileChoice = match[1];
|
|
94
|
-
if (section === (file.key === 'models.model' ? 'models' : ''))
|
|
95
|
-
chosen = match[1];
|
|
90
|
+
if (match)
|
|
91
|
+
assignments.push({ section, model: match[1] });
|
|
96
92
|
}
|
|
97
|
-
return
|
|
93
|
+
return assignments;
|
|
94
|
+
}
|
|
95
|
+
function parseTomlModel(file, raw, profile) {
|
|
96
|
+
const assignments = tomlModelAssignments(raw);
|
|
97
|
+
const lastIn = (section) => assignments.filter((row) => row.section === section).pop()?.model;
|
|
98
|
+
const profileChoice = profile ? lastIn(`profiles.${profile}`) : undefined;
|
|
99
|
+
return profileChoice || lastIn(file.key === 'models.model' ? 'models' : '');
|
|
100
|
+
}
|
|
101
|
+
export function parseConfiguredModel(file, raw, profile) {
|
|
102
|
+
if (file.format === 'json')
|
|
103
|
+
return parseJsonModel(file, raw);
|
|
104
|
+
if (file.format === 'yaml')
|
|
105
|
+
return scalar(raw.match(/^model\s*:\s*["']?([^\n"'#]+)["']?\s*(?:#.*)?$/m)?.[1]);
|
|
106
|
+
return parseTomlModel(file, raw, profile);
|
|
98
107
|
}
|
|
99
108
|
const MODEL_ENV = {
|
|
100
109
|
claude: ['ANTHROPIC_MODEL'], aider: ['AIDER_MODEL'], amr: ['VELA_DEFAULT_MODEL'],
|
|
101
110
|
deepseek: ['CODEWHALE_MODEL', 'DEEPSEEK_MODEL'], qwen: ['QWEN_MODEL', 'OPENAI_MODEL', 'ANTHROPIC_MODEL', 'GEMINI_MODEL'],
|
|
102
111
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
112
|
+
const PROJECT_ROOT_AGENTS = new Set(['claude', 'aider', 'opencode']);
|
|
113
|
+
const INLINE_CONFIG_ENV = new Map([['opencode', 'OPENCODE_CONFIG_CONTENT'], ['mimo', 'MIMOCODE_CONFIG_CONTENT']]);
|
|
114
|
+
async function withProjectRoot(agentId, context, deps, signal) {
|
|
115
|
+
if (context.projectRoot || !PROJECT_ROOT_AGENTS.has(agentId) || !deps.fs.projectRoot)
|
|
116
|
+
return context;
|
|
117
|
+
const projectRoot = await deps.fs.projectRoot({ cwd: context.cwd, signal });
|
|
118
|
+
return projectRoot ? { ...context, projectRoot } : context;
|
|
119
|
+
}
|
|
120
|
+
/** Later files override earlier ones; Pi merges its files so provider and model may be split. */
|
|
121
|
+
function fileSelection(agentId, contents, profile) {
|
|
122
|
+
if (agentId === 'pi') {
|
|
123
|
+
const effective = Object.assign({}, ...contents.map(({ raw }) => raw ? parseSettingsJson(raw) || {} : {}));
|
|
124
|
+
return qualified(scalar(effective.defaultProvider), scalar(effective.defaultModel));
|
|
108
125
|
}
|
|
109
|
-
const files = modelConfigFiles(agentId, context);
|
|
110
|
-
const contents = await Promise.all(files.map(async (file) => ({ file, raw: await deps.fs.read(file.path, { signal }) })));
|
|
111
|
-
let extraMaterial = '';
|
|
112
126
|
let selection;
|
|
113
127
|
for (const { file, raw } of contents)
|
|
114
128
|
if (raw !== null)
|
|
115
|
-
selection = parseConfiguredModel(file, raw,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
selection = parseConfiguredModel(file, raw, profile) || selection;
|
|
130
|
+
return selection;
|
|
131
|
+
}
|
|
132
|
+
function inlineSelection(agentId, env) {
|
|
133
|
+
const key = INLINE_CONFIG_ENV.get(agentId);
|
|
134
|
+
const inline = key ? env[key] : undefined;
|
|
135
|
+
return inline ? scalar(parseSettingsJson(inline)?.model) : undefined;
|
|
136
|
+
}
|
|
137
|
+
/** The first listed model variable with a value wins. */
|
|
138
|
+
function envSelection(agentId, env) {
|
|
139
|
+
return (MODEL_ENV[agentId] || []).map((key) => scalar(env[key])).find(Boolean);
|
|
140
|
+
}
|
|
141
|
+
async function claudeSettingsRaw(agentId, context, deps, signal) {
|
|
142
|
+
if (agentId !== 'claude' || !context.settings)
|
|
143
|
+
return null;
|
|
144
|
+
return context.settings.trim().startsWith('{') ? context.settings : deps.fs.read(context.settings, { signal });
|
|
145
|
+
}
|
|
146
|
+
export async function readModelConfiguration(agentId, context, deps, signal) {
|
|
147
|
+
context = await withProjectRoot(agentId, context, deps, signal);
|
|
148
|
+
const files = modelConfigFiles(agentId, context);
|
|
149
|
+
const contents = await Promise.all(files.map(async (file) => ({ file, raw: await deps.fs.read(file.path, { signal }) })));
|
|
150
|
+
const settingsRaw = await claudeSettingsRaw(agentId, context, deps, signal);
|
|
151
|
+
const settingsModel = settingsRaw ? scalar(parseSettingsJson(settingsRaw)?.model) : undefined;
|
|
152
|
+
// Precedence, strongest first: launch model, Claude --settings, model env, inline config content, config files.
|
|
153
|
+
const selection = context.model || settingsModel || envSelection(agentId, context.env) || inlineSelection(agentId, context.env) || fileSelection(agentId, contents, context.profile);
|
|
134
154
|
// Material is hashed by the orchestration layer and is never exposed over HTTP.
|
|
135
|
-
return { ...(selection ? { selection } : {}), fingerprintMaterial: JSON.stringify([contents.map(({ file, raw }) => [file.path, raw]),
|
|
155
|
+
return { ...(selection ? { selection } : {}), fingerprintMaterial: JSON.stringify([contents.map(({ file, raw }) => [file.path, raw]), settingsRaw || '']) };
|
|
136
156
|
}
|
|
137
157
|
//# sourceMappingURL=model-discovery-config.js.map
|
|
@@ -2,7 +2,7 @@ import type { ModelDiscoveryContext, ModelDiscoveryDeps, ModelProbeResult } from
|
|
|
2
2
|
/** UNVERIFIED locally. The host may install the official SDK or inject the RPC port.
|
|
3
3
|
* Use the CLI's authenticated server, not an unrelated HTTP token or an inference prompt.
|
|
4
4
|
* https://github.com/github/copilot-sdk/blob/main/nodejs/src/client.ts */
|
|
5
|
-
interface CopilotMetadataClient {
|
|
5
|
+
export interface CopilotMetadataClient {
|
|
6
6
|
start(): Promise<unknown>;
|
|
7
7
|
listModels(): Promise<{
|
|
8
8
|
id: string;
|
|
@@ -13,6 +13,20 @@ interface CopilotMetadataClient {
|
|
|
13
13
|
export declare function probeCopilotSdk(context: ModelDiscoveryContext, signal: AbortSignal, optional?: {
|
|
14
14
|
createClient?: (context: ModelDiscoveryContext) => Promise<CopilotMetadataClient>;
|
|
15
15
|
}): Promise<ModelProbeResult>;
|
|
16
|
+
/** The slice of `@github/copilot-sdk` this probe constructs a metadata client from. */
|
|
17
|
+
export interface CopilotSdkModule {
|
|
18
|
+
readonly RuntimeConnection?: {
|
|
19
|
+
forStdio(input: {
|
|
20
|
+
path: string;
|
|
21
|
+
env: Record<string, string>;
|
|
22
|
+
}): unknown;
|
|
23
|
+
};
|
|
24
|
+
readonly CopilotClient: new (options: Record<string, unknown>) => CopilotMetadataClient;
|
|
25
|
+
}
|
|
26
|
+
/** Builds the metadata client from the host-installed SDK. `importSdk` is the module-loading port
|
|
27
|
+
* (Node's dynamic import by default), injectable so both SDK API generations are testable. */
|
|
28
|
+
export declare function createCopilotMetadataClient(context: ModelDiscoveryContext, { importSdk }?: {
|
|
29
|
+
importSdk?: (name: string) => Promise<CopilotSdkModule>;
|
|
30
|
+
}): Promise<CopilotMetadataClient>;
|
|
16
31
|
export declare function probeDroidSdk(context: ModelDiscoveryContext, deps: ModelDiscoveryDeps, signal: AbortSignal): Promise<ModelProbeResult>;
|
|
17
|
-
export {};
|
|
18
32
|
//# sourceMappingURL=model-discovery-sdk.d.ts.map
|
|
@@ -20,9 +20,10 @@ export async function probeCopilotSdk(context, signal, optional = {}) {
|
|
|
20
20
|
await client.forceStop().catch(() => { });
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
/** Builds the metadata client from the host-installed SDK. `importSdk` is the module-loading port
|
|
24
|
+
* (Node's dynamic import by default), injectable so both SDK API generations are testable. */
|
|
25
|
+
export async function createCopilotMetadataClient(context, { importSdk = (name) => import(name) } = {}) {
|
|
26
|
+
const sdk = await importSdk('@github/copilot-sdk');
|
|
26
27
|
const env = Object.fromEntries(Object.entries(context.env).filter((entry) => typeof entry[1] === 'string'));
|
|
27
28
|
// RuntimeConnection is the current SDK API; older SDKs expose cliPath/cwd/useStdio.
|
|
28
29
|
const connection = sdk.RuntimeConnection?.forStdio({ path: context.executable, env });
|
|
@@ -3,6 +3,19 @@ import type { RuntimeModelOption } from './types.js';
|
|
|
3
3
|
import type { DiscoveredModel, ModelCatalogSnapshot } from './model-discovery-types.js';
|
|
4
4
|
export declare function modelIdentityKind(id: string): DiscoveredModel['identityKind'];
|
|
5
5
|
export declare function normalizeDiscoveredModels(models: readonly RuntimeModelOption[]): DiscoveredModel[];
|
|
6
|
+
type DefaultResolutionLike = {
|
|
7
|
+
status: string;
|
|
8
|
+
id?: string;
|
|
9
|
+
};
|
|
10
|
+
/** Concrete picker choices, shared with server-side selection validation.
|
|
11
|
+
* Aliases contribute their resolved ID; routing modes never become launch IDs.
|
|
12
|
+
* Preserves first position and upgrades raw labels. Pure; O(rows) time and space.
|
|
13
|
+
*/
|
|
14
|
+
export declare function concreteModelOptions({ models, supportsConcreteModelSelection, defaultModelResolution }: {
|
|
15
|
+
models?: readonly RuntimeModelOption[];
|
|
16
|
+
supportsConcreteModelSelection?: boolean;
|
|
17
|
+
defaultModelResolution?: DefaultResolutionLike;
|
|
18
|
+
}, _options?: {}): RuntimeModelOption[];
|
|
6
19
|
export declare class ProbeTimeout extends Error {
|
|
7
20
|
}
|
|
8
21
|
/** Cancellation always reaches the effect port. A broken port cannot hold callers indefinitely. */
|
|
@@ -11,4 +24,5 @@ export declare class ModelProbeError extends Error {
|
|
|
11
24
|
readonly code: ModelCatalogSnapshot['diagnostics'][number]['code'];
|
|
12
25
|
constructor(code: ModelCatalogSnapshot['diagnostics'][number]['code']);
|
|
13
26
|
}
|
|
27
|
+
export {};
|
|
14
28
|
//# sourceMappingURL=model-discovery-shared.d.ts.map
|
|
@@ -13,9 +13,50 @@ export function normalizeDiscoveredModels(models) {
|
|
|
13
13
|
return [];
|
|
14
14
|
seen.add(row.id);
|
|
15
15
|
const model = row;
|
|
16
|
-
return [{ ...row, identityKind: model.identityKind ?? modelIdentityKind(row.id)
|
|
16
|
+
return [{ ...row, identityKind: model.identityKind ?? modelIdentityKind(row.id) }];
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
+
/** The concrete launch id a catalog row contributes, or undefined when it contributes none. */
|
|
20
|
+
function concreteRowId({ row }) {
|
|
21
|
+
const id = row.resolvedId || (row.identityKind === 'routing-mode' || row.identityKind === 'alias' ? undefined : row.id);
|
|
22
|
+
return id && modelIdentityKind(id) === 'concrete' ? id : undefined;
|
|
23
|
+
}
|
|
24
|
+
/** Add one row's concrete choice; first position wins, a raw-id label is upgraded later. */
|
|
25
|
+
function addConcreteChoice({ choices, row }) {
|
|
26
|
+
const id = concreteRowId({ row });
|
|
27
|
+
if (!id)
|
|
28
|
+
return;
|
|
29
|
+
// Older cached inventories can attach a default-policy label to a resolved concrete ID.
|
|
30
|
+
const label = row.id === 'default' || /^default\b/i.test(row.label) ? id : row.label;
|
|
31
|
+
const existing = choices.get(id);
|
|
32
|
+
if (!existing)
|
|
33
|
+
choices.set(id, { ...row, id, label, identityKind: 'concrete' });
|
|
34
|
+
else if (existing.label === id && label !== id)
|
|
35
|
+
choices.set(id, { ...existing, label });
|
|
36
|
+
}
|
|
37
|
+
/** The resolved concrete default id when it is missing from `choices`, else undefined. */
|
|
38
|
+
function missingResolvedDefaultId({ choices }, { resolution } = {}) {
|
|
39
|
+
if (resolution?.status !== 'resolved' || !resolution.id)
|
|
40
|
+
return undefined;
|
|
41
|
+
return modelIdentityKind(resolution.id) === 'concrete' && !choices.has(resolution.id) ? resolution.id : undefined;
|
|
42
|
+
}
|
|
43
|
+
/** Concrete picker choices, shared with server-side selection validation.
|
|
44
|
+
* Aliases contribute their resolved ID; routing modes never become launch IDs.
|
|
45
|
+
* Preserves first position and upgrades raw labels. Pure; O(rows) time and space.
|
|
46
|
+
*/
|
|
47
|
+
export function concreteModelOptions({ models = [], supportsConcreteModelSelection, defaultModelResolution }, _options = {}) {
|
|
48
|
+
if (supportsConcreteModelSelection === false)
|
|
49
|
+
return [];
|
|
50
|
+
const choices = new Map();
|
|
51
|
+
for (const row of models)
|
|
52
|
+
addConcreteChoice({ choices, row });
|
|
53
|
+
const options = [...choices.values()];
|
|
54
|
+
// A host may publish a resolved default outside its visible catalog. Preserve its concrete ID.
|
|
55
|
+
const hiddenDefaultId = missingResolvedDefaultId({ choices }, { resolution: defaultModelResolution });
|
|
56
|
+
if (hiddenDefaultId)
|
|
57
|
+
options.unshift({ id: hiddenDefaultId, label: hiddenDefaultId, identityKind: 'concrete' });
|
|
58
|
+
return options;
|
|
59
|
+
}
|
|
19
60
|
export class ProbeTimeout extends Error {
|
|
20
61
|
}
|
|
21
62
|
/** Cancellation always reaches the effect port. A broken port cannot hold callers indefinitely. */
|
|
@@ -23,24 +64,18 @@ export async function withModelProbeTimeout(work, timeoutMs, parent) {
|
|
|
23
64
|
if (parent?.aborted)
|
|
24
65
|
throw new ProbeTimeout('Probe cancelled');
|
|
25
66
|
const controller = new AbortController();
|
|
26
|
-
let
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
else
|
|
33
|
-
parent?.addEventListener('abort', abortListener, { once: true });
|
|
34
|
-
timer = setTimeout(() => { controller.abort(); reject(new ProbeTimeout('Probe timed out')); }, timeoutMs);
|
|
35
|
-
});
|
|
67
|
+
let rejectStopped;
|
|
68
|
+
const stopped = new Promise((_resolve, reject) => { rejectStopped = reject; });
|
|
69
|
+
// `parent` was not aborted above and nothing has awaited since, so listening is enough.
|
|
70
|
+
const abortListener = () => { controller.abort(); rejectStopped(new ProbeTimeout('Probe cancelled')); };
|
|
71
|
+
parent?.addEventListener('abort', abortListener, { once: true });
|
|
72
|
+
const timer = setTimeout(() => { controller.abort(); rejectStopped(new ProbeTimeout('Probe timed out')); }, timeoutMs);
|
|
36
73
|
try {
|
|
37
74
|
return await Promise.race([work(controller.signal), stopped]);
|
|
38
75
|
}
|
|
39
76
|
finally {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (abortListener)
|
|
43
|
-
parent?.removeEventListener('abort', abortListener);
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
parent?.removeEventListener('abort', abortListener);
|
|
44
79
|
}
|
|
45
80
|
}
|
|
46
81
|
export class ModelProbeError extends Error {
|
|
@@ -142,6 +142,8 @@ export interface AgentDiscoveryConfiguration {
|
|
|
142
142
|
stdout: string;
|
|
143
143
|
}) => RuntimeModelOption[] | null;
|
|
144
144
|
args?: readonly string[];
|
|
145
|
+
/** Listing budget requested by the definition, bounded by the outer discovery timeout. */
|
|
146
|
+
timeoutMs?: number;
|
|
145
147
|
}
|
|
146
148
|
/** Host composition selects native probes or substitutes another discovery mechanism. */
|
|
147
149
|
export interface ModelDiscoveryProbes {
|