@jini-ai/agent-runtime 0.6.15-rc.2 → 0.6.16
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 +12 -0
- package/dist/agent-protocol/acp/rpc.js +4 -8
- package/dist/agent-protocol/acp/session.js +33 -37
- package/dist/agent-protocol/acp/text-suppression.js +10 -7
- package/dist/agent-protocol/acp/updates.js +4 -5
- package/dist/agent-protocol/core/json-line-stream.d.ts +6 -3
- package/dist/agent-protocol/core/json-line-stream.js +9 -10
- package/dist/agent-protocol/pi-rpc/events.js +27 -27
- package/dist/agent-protocol/pi-rpc/models.js +13 -11
- package/dist/agent-protocol/pi-rpc/session.js +7 -7
- package/dist/ai-trace/classify.js +4 -1
- package/dist/ai-trace/recorder.d.ts +2 -3
- package/dist/ai-trace/recorder.js +2 -3
- package/dist/ai-trace/sinks.js +19 -3
- package/dist/ai-trace/usage.js +3 -1
- package/dist/anthropic-live-models.js +0 -0
- package/dist/auth.js +20 -17
- package/dist/claude-code-models.js +29 -17
- package/dist/claude-filesystem-policy.d.ts +4 -3
- package/dist/claude-filesystem-policy.js +39 -12
- package/dist/claude-stream.js +65 -47
- package/dist/core/model-discovery-shared.js +4 -2
- package/dist/core/omit-keys.d.ts +7 -0
- package/dist/core/omit-keys.js +12 -0
- package/dist/defs/aider.d.ts +1 -1
- package/dist/defs/amp.d.ts +1 -1
- package/dist/defs/amp.js +2 -2
- package/dist/defs/amr.js +5 -9
- package/dist/defs/antigravity-event-stream.d.ts +19 -0
- package/dist/defs/antigravity-event-stream.js +83 -0
- package/dist/defs/antigravity.d.ts +4 -0
- package/dist/defs/antigravity.js +27 -15
- package/dist/defs/auggie.d.ts +3 -3
- package/dist/defs/claude.d.ts +3 -3
- package/dist/defs/cline.d.ts +3 -3
- package/dist/defs/codebuddy.d.ts +1 -1
- package/dist/defs/codex.js +3 -2
- package/dist/defs/crush.d.ts +1 -1
- package/dist/defs/cursor-agent.d.ts +3 -1
- package/dist/defs/cursor-agent.js +8 -6
- package/dist/defs/deepseek.d.ts +1 -1
- package/dist/defs/devin.d.ts +3 -3
- package/dist/defs/droid.d.ts +1 -1
- package/dist/defs/goose.d.ts +3 -3
- package/dist/defs/grok-build.js +7 -5
- package/dist/defs/hermes.d.ts +3 -3
- package/dist/defs/index.d.ts +0 -1
- package/dist/defs/index.js +0 -1
- package/dist/defs/kilo.d.ts +3 -3
- package/dist/defs/kimi.d.ts +3 -3
- package/dist/defs/kiro.d.ts +3 -3
- package/dist/defs/mimo.d.ts +1 -1
- package/dist/defs/opencode.d.ts +1 -1
- package/dist/defs/pi.d.ts +1 -1
- package/dist/defs/qoder.d.ts +1 -1
- package/dist/defs/qwen.d.ts +1 -1
- package/dist/defs/reasonix.d.ts +3 -3
- package/dist/defs/trae-cli.d.ts +3 -3
- package/dist/defs/vibe.d.ts +3 -3
- package/dist/detection.js +22 -2
- package/dist/executables.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/json-event-stream.d.ts +1 -2
- package/dist/json-event-stream.js +10 -9
- package/dist/launch.js +2 -1
- package/dist/metadata.js +0 -4
- package/dist/model-catalog-cache.js +6 -4
- package/dist/model-contracts.d.ts +29 -0
- package/dist/model-contracts.js +2 -0
- package/dist/model-discovery-adapters.js +47 -24
- package/dist/model-discovery-config.js +8 -5
- package/dist/model-discovery-sdk.d.ts +0 -29
- package/dist/model-discovery-sdk.js +0 -32
- package/dist/model-discovery-types.d.ts +3 -3
- package/dist/model-discovery-yaml.d.ts +9 -0
- package/dist/model-discovery-yaml.js +98 -0
- package/dist/model-discovery.js +10 -3
- package/dist/model-registry.js +2 -1
- package/dist/native-tool-policy.d.ts +28 -0
- package/dist/native-tool-policy.js +42 -0
- package/dist/opencode-log.js +13 -10
- package/dist/pi-models.js +13 -11
- package/dist/probe-scheduler.js +13 -5
- package/dist/providers/aihubmix.js +6 -7
- package/dist/providers/anthropic-messages.d.ts +7 -4
- package/dist/providers/anthropic-messages.js +22 -24
- package/dist/providers/azure-chat.d.ts +1 -1
- package/dist/providers/azure-chat.js +7 -10
- package/dist/providers/connection-guard.js +2 -1
- package/dist/providers/connection-test.js +16 -10
- package/dist/providers/google-messages.d.ts +1 -1
- package/dist/providers/google-messages.js +33 -35
- package/dist/providers/google.js +3 -4
- package/dist/providers/model-catalog.js +10 -7
- package/dist/providers/ollama-chat.d.ts +0 -8
- package/dist/providers/ollama-chat.js +17 -19
- package/dist/providers/openai-chat.d.ts +6 -3
- package/dist/providers/openai-chat.js +24 -22
- package/dist/providers/operation-schema.d.ts +2 -3
- package/dist/providers/operation-schema.js +25 -22
- package/dist/providers/provider-tool-policy.d.ts +13 -0
- package/dist/providers/provider-tool-policy.js +2 -0
- package/dist/providers/tool-loop-verdict.d.ts +22 -0
- package/dist/providers/tool-loop-verdict.js +17 -0
- package/dist/providers/tool-turn-types.d.ts +2 -12
- package/dist/providers/tool-turn.js +7 -2
- package/dist/registry.d.ts +1 -1
- package/dist/registry.js +2 -3
- package/dist/resolution.d.ts +21 -0
- package/dist/resolution.js +22 -1
- package/dist/role-marker-guard.d.ts +1 -1
- package/dist/role-marker-guard.js +1 -1
- package/dist/types.d.ts +8 -27
- package/package.json +14 -22
- package/dist/copilot-stream.d.ts +0 -65
- package/dist/copilot-stream.js +0 -123
- package/dist/defs/copilot.d.ts +0 -34
- package/dist/defs/copilot.js +0 -96
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @module json-event-stream
|
|
2
2
|
* Multi-CLI JSON event parsing with per-handler stream state. */
|
|
3
3
|
import { sanitizeUntrustedText } from '@jini-ai/core/text';
|
|
4
|
+
import { handleAntigravityEvent } from './defs/antigravity-event-stream.js';
|
|
4
5
|
function isRecord(value) {
|
|
5
6
|
return value != null && typeof value === 'object' && !Array.isArray(value);
|
|
6
7
|
}
|
|
@@ -418,7 +419,7 @@ function normalizeTodoStatus(value) {
|
|
|
418
419
|
const rule = TODO_STATUS_RULES.find((candidate) => candidate.exact.includes(status) || candidate.prefixes.some((prefix) => status.startsWith(prefix)));
|
|
419
420
|
return rule ? rule.status : 'pending';
|
|
420
421
|
}
|
|
421
|
-
/**
|
|
422
|
+
/** Text fields of a to-do item in precedence order; the first string-typed one wins, even when empty. */
|
|
422
423
|
const TODO_CONTENT_FIELDS = ['content', 'label', 'description', 'text'];
|
|
423
424
|
function todoFromItem(raw) {
|
|
424
425
|
if (!isRecord(raw))
|
|
@@ -519,11 +520,7 @@ function flushPendingArtifactText(state, onEvent) {
|
|
|
519
520
|
function isFileWriteToolUse(toolName, input) {
|
|
520
521
|
if (!isRecord(input))
|
|
521
522
|
return false;
|
|
522
|
-
const path =
|
|
523
|
-
? input.file_path
|
|
524
|
-
: typeof input.path === 'string'
|
|
525
|
-
? input.path
|
|
526
|
-
: '';
|
|
523
|
+
const path = [input.file_path, input.path].find((value) => typeof value === 'string') ?? '';
|
|
527
524
|
const writesFile = toolName === 'write_file' ||
|
|
528
525
|
toolName === 'write' ||
|
|
529
526
|
toolName === 'replace' ||
|
|
@@ -663,13 +660,15 @@ function handleCodexItemUpdated(item, onEvent, state) {
|
|
|
663
660
|
function completeCodexFileChange(item, onEvent, state) {
|
|
664
661
|
// Codex reports direct patches as file_change, rather than command_execution. Surface paths
|
|
665
662
|
// through the SAME native-tool event channel so audit sees edits without persisting patches.
|
|
666
|
-
if (
|
|
667
|
-
|
|
663
|
+
if (claimCodexToolUse(state, item.id))
|
|
664
|
+
emitCodexFileChange(item, onEvent);
|
|
665
|
+
return true;
|
|
666
|
+
}
|
|
667
|
+
function emitCodexFileChange(item, onEvent) {
|
|
668
668
|
const changes = Array.isArray(item.changes) ? item.changes : [];
|
|
669
669
|
onEvent({ type: 'tool_use', id: item.id, name: 'apply_patch',
|
|
670
670
|
input: { paths: changes.filter(isRecord).map(change => change.path).filter(path => typeof path === 'string') } });
|
|
671
671
|
onEvent({ type: 'tool_result', toolUseId: item.id, content: 'File change reported by Codex.', isError: item.status === 'failed' });
|
|
672
|
-
return true;
|
|
673
672
|
}
|
|
674
673
|
function completeCodexCommand(item, onEvent, state) {
|
|
675
674
|
resetCodexAgentMessageBoundary(state);
|
|
@@ -938,6 +937,7 @@ function emitModelReceipts(obj, onEvent) {
|
|
|
938
937
|
}
|
|
939
938
|
}
|
|
940
939
|
const PARSERS_BY_KIND = new Map([
|
|
940
|
+
['antigravity', (frame, emit, state) => handleAntigravityEvent({ frame, emit, state: state.antigravity })],
|
|
941
941
|
['opencode', handleOpenCodeEvent],
|
|
942
942
|
['legacy-google-stream-json', handleLegacyGoogleStreamEvent],
|
|
943
943
|
['kimi', handleKimiEvent],
|
|
@@ -947,6 +947,7 @@ const PARSERS_BY_KIND = new Map([
|
|
|
947
947
|
export function createJsonEventStreamHandler({ kind, onEvent }) {
|
|
948
948
|
let buffer = '';
|
|
949
949
|
const state = {
|
|
950
|
+
antigravity: { textEmitted: false, toolUses: new Set(), toolResults: new Set() },
|
|
950
951
|
cursorTextSoFar: '',
|
|
951
952
|
cursorTurnStart: 0,
|
|
952
953
|
openCodeToolUses: new Set(),
|
package/dist/launch.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { accessSync, closeSync, constants, openSync, readdirSync, readSync, realpathSync, statSync } from 'node:fs';
|
|
6
6
|
import path, { delimiter } from 'node:path';
|
|
7
7
|
import { inspectAgentExecutableResolution, userToolchainBinDirs } from './executables.js';
|
|
8
|
+
import { trimCharsEnd } from '@jini-ai/core/text';
|
|
8
9
|
export function resolveAgentLaunch({ def }, options = {}) {
|
|
9
10
|
const resolution = inspectAgentExecutableResolution({ def: def }, options);
|
|
10
11
|
if (!resolution.selectedPath) {
|
|
@@ -61,7 +62,7 @@ function pathEnvKey(env) {
|
|
|
61
62
|
return Object.keys(env).find((k) => k.toLowerCase() === 'path') ?? 'PATH';
|
|
62
63
|
}
|
|
63
64
|
function normalizePathEntry(p) {
|
|
64
|
-
const trimmed =
|
|
65
|
+
const trimmed = trimCharsEnd({ text: p, chars: '/\\' });
|
|
65
66
|
return process.platform === 'win32' ? trimmed.toLowerCase() : trimmed;
|
|
66
67
|
}
|
|
67
68
|
// Keep the first spelling of each directory (trailing separators ignored,
|
package/dist/metadata.js
CHANGED
|
@@ -43,10 +43,6 @@ export const DEFAULT_AGENT_INSTALL_LINKS = {
|
|
|
43
43
|
installUrl: 'https://qoder.com/download',
|
|
44
44
|
docsUrl: 'https://docs.qoder.com',
|
|
45
45
|
},
|
|
46
|
-
copilot: {
|
|
47
|
-
installUrl: 'https://github.com/github/copilot-cli',
|
|
48
|
-
docsUrl: 'https://docs.github.com/en/copilot/how-tos/use-copilot-extensions/use-in-cli',
|
|
49
|
-
},
|
|
50
46
|
pi: {
|
|
51
47
|
docsUrl: 'https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/README.md',
|
|
52
48
|
},
|
|
@@ -22,10 +22,12 @@ export class ModelCatalogCache {
|
|
|
22
22
|
state = { inFlight: null, expiresAt: -Infinity, live: null };
|
|
23
23
|
this.states.set(key, state);
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
// An in-flight load is awaited; otherwise an expired entry starts a refresh.
|
|
26
|
+
const pending = state.inFlight;
|
|
27
|
+
const refreshDue = !pending && state.expiresAt <= this.required.clock.nowMs();
|
|
28
|
+
if (pending)
|
|
29
|
+
await pending;
|
|
30
|
+
if (refreshDue) {
|
|
29
31
|
state.expiresAt = this.required.clock.nowMs() + this.ttlMs;
|
|
30
32
|
const current = state;
|
|
31
33
|
const discover = options.discover ?? this.required.discover;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type ModelIdentityKind = 'concrete' | 'alias' | 'routing-mode';
|
|
2
|
+
export type RuntimeEnv = NodeJS.ProcessEnv | Record<string, string>;
|
|
3
|
+
export type RuntimeModelOption = {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
identityKind?: ModelIdentityKind;
|
|
7
|
+
resolvedId?: string;
|
|
8
|
+
/**
|
|
9
|
+
* The reasoning-effort levels THIS model supports, when the runtime's own catalog reports them
|
|
10
|
+
* per model rather than per agent.
|
|
11
|
+
*
|
|
12
|
+
* Present only where a live source actually carries the data — Codex's `debug models` catalog
|
|
13
|
+
* does (`supported_reasoning_levels`), and the levels genuinely differ between models on the same
|
|
14
|
+
* CLI: verified live against codex-cli 0.153.4, where `gpt-6-astra` offers
|
|
15
|
+
* low/medium/high/xhigh/max/ultra while `gpt-5.5` stops at `xhigh`. A single agent-level
|
|
16
|
+
* `RuntimeAgentDef.reasoningOptions` list cannot be correct for both, which is why this is a
|
|
17
|
+
* property of the model row rather than of the def.
|
|
18
|
+
*
|
|
19
|
+
* Consumed by `RuntimeAgentDef.deriveReasoningOptions` to compute the agent-level list a picker
|
|
20
|
+
* renders. Left `undefined` by every runtime whose effort vocabulary really is uniform, and by
|
|
21
|
+
* every static fallback list — an absent value means "nothing catalog-specific to say", never
|
|
22
|
+
* "this model supports no effort levels".
|
|
23
|
+
*/
|
|
24
|
+
reasoning?: readonly RuntimeReasoningOption[];
|
|
25
|
+
};
|
|
26
|
+
/** A reasoning-effort choice; same shape as a model option. */
|
|
27
|
+
export interface RuntimeReasoningOption extends RuntimeModelOption {
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=model-contracts.d.ts.map
|
|
@@ -9,7 +9,7 @@ import { CLAUDE_CODE_INITIALIZE_ARGS, CLAUDE_CODE_INITIALIZE_REQUEST } from './c
|
|
|
9
9
|
import { listProviderModels } from './providers/model-catalog.js';
|
|
10
10
|
import { execAgentFile } from './invocation.js';
|
|
11
11
|
import { scheduleProbeProcess } from './probe-scheduler.js';
|
|
12
|
-
import {
|
|
12
|
+
import { probeDroidSdk } from './model-discovery-sdk.js';
|
|
13
13
|
import { parseSettingsJson, readModelConfiguration } from './model-discovery-config.js';
|
|
14
14
|
import { ModelProbeError, modelIdentityKind, withModelProbeTimeout } from './core/model-discovery-shared.js';
|
|
15
15
|
const ACP_ARGS = {
|
|
@@ -22,7 +22,7 @@ const CLI_ARGS = {
|
|
|
22
22
|
amp: ['plugins', 'show-agent-options', '--json'], crush: ['models'], deepseek: ['models'], qoder: ['--list-models'],
|
|
23
23
|
};
|
|
24
24
|
export function modelProbeTimeoutMs(agentId) {
|
|
25
|
-
if (ACP_ARGS[agentId] || ['claude', 'codebuddy', 'pi', '
|
|
25
|
+
if (ACP_ARGS[agentId] || ['claude', 'codebuddy', 'pi', 'droid'].includes(agentId))
|
|
26
26
|
return 15_000;
|
|
27
27
|
return 10_000;
|
|
28
28
|
}
|
|
@@ -33,7 +33,9 @@ export async function probeCliSubcommand(context, config, deps, signal) {
|
|
|
33
33
|
const models = config.parse?.({ stdout });
|
|
34
34
|
if (!models)
|
|
35
35
|
throw new ModelProbeError('malformed-response');
|
|
36
|
-
|
|
36
|
+
// The bracketed class is `\s` minus line terminators, so neither end of the line can slide into
|
|
37
|
+
// a neighbouring line (which is what made the plain `\s*` version backtrack quadratically).
|
|
38
|
+
const defaultSelectionId = stdout.match(/^[\t\v\f \u00a0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]*Default model:\s*(\S+)[\t\v\f \u00a0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]*$/mi)?.[1];
|
|
37
39
|
return { models, source: 'cli', coverage: 'account', ...(defaultSelectionId ? { defaultSelectionId } : {}) };
|
|
38
40
|
}
|
|
39
41
|
/** ACP can create CLI session state/start services. It never sends a user prompt. */
|
|
@@ -60,14 +62,27 @@ function claudeInitializeRows(line) {
|
|
|
60
62
|
return Array.isArray(rows) ? rows : null;
|
|
61
63
|
}
|
|
62
64
|
/** One selection row, plus its concrete resolved row when the selection is an alias. */
|
|
65
|
+
/** A selection that resolves to another id is an alias; an unresolved one is classified by shape. */
|
|
66
|
+
function selectionIdentityKind(id, resolvedId) {
|
|
67
|
+
return resolvedId ? 'alias' : modelIdentityKind(id);
|
|
68
|
+
}
|
|
63
69
|
function claudeSelectionModels(id, resolvedId, displayName) {
|
|
64
70
|
const label = typeof displayName === 'string' && displayName.trim() ? displayName.trim() : resolvedId || id;
|
|
65
|
-
const identityKind = id === resolvedId ? 'concrete' :
|
|
71
|
+
const identityKind = id === resolvedId ? 'concrete' : selectionIdentityKind(id, resolvedId);
|
|
66
72
|
const selection = { id, label, identityKind, ...(resolvedId ? { resolvedId } : {}) };
|
|
67
73
|
if (!resolvedId || id === resolvedId)
|
|
68
74
|
return [selection];
|
|
69
75
|
return [selection, { id: resolvedId, label, identityKind: modelIdentityKind(resolvedId) }];
|
|
70
76
|
}
|
|
77
|
+
/** The picker rows one initialize row contributes; the `default` row also names the default selection. */
|
|
78
|
+
function claudeRowModels(id, resolvedId, displayName) {
|
|
79
|
+
if (id !== 'default')
|
|
80
|
+
return { models: claudeSelectionModels(id, resolvedId, displayName) };
|
|
81
|
+
// This displayName describes the CLI's default policy, not the model it resolves to.
|
|
82
|
+
if (!resolvedId || modelIdentityKind(resolvedId) !== 'concrete')
|
|
83
|
+
return { models: [] };
|
|
84
|
+
return { models: [{ id: resolvedId, label: resolvedId, identityKind: 'concrete' }], defaultId: resolvedId };
|
|
85
|
+
}
|
|
71
86
|
function claudeInitializeResult(rows) {
|
|
72
87
|
const models = [];
|
|
73
88
|
let defaultSelectionId;
|
|
@@ -76,15 +91,10 @@ function claudeInitializeResult(rows) {
|
|
|
76
91
|
continue;
|
|
77
92
|
const id = row.value.trim();
|
|
78
93
|
const resolvedId = typeof row.resolvedModel === 'string' ? row.resolvedModel.trim() : undefined;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// This displayName describes the CLI's default policy, not the model it resolves to.
|
|
84
|
-
if (resolvedId && modelIdentityKind(resolvedId) === 'concrete') {
|
|
85
|
-
defaultSelectionId = resolvedId;
|
|
86
|
-
models.push({ id: resolvedId, label: resolvedId, identityKind: 'concrete' });
|
|
87
|
-
}
|
|
94
|
+
const rowResult = claudeRowModels(id, resolvedId, row.displayName);
|
|
95
|
+
models.push(...rowResult.models);
|
|
96
|
+
if (rowResult.defaultId)
|
|
97
|
+
defaultSelectionId = rowResult.defaultId;
|
|
88
98
|
}
|
|
89
99
|
return { models, source: 'rpc', coverage: 'account', ...withDefaultSelection(defaultSelectionId) };
|
|
90
100
|
}
|
|
@@ -106,7 +116,9 @@ export async function probeClaudeInitialize(context, deps, signal) {
|
|
|
106
116
|
if (context.settingSources)
|
|
107
117
|
args.push('--setting-sources', context.settingSources.join(','));
|
|
108
118
|
// The last settings argument must still disable hooks; the probe never executes hooks.
|
|
109
|
-
|
|
119
|
+
// Inline JSON is used as is; anything else names a settings file to read.
|
|
120
|
+
const inlineSettings = context.settings?.trim().startsWith('{') ? context.settings : null;
|
|
121
|
+
const raw = inlineSettings ?? (context.settings ? await deps.fs.read(context.settings, { signal }) : null);
|
|
110
122
|
const settings = raw ? parseSettingsJson(raw) : undefined;
|
|
111
123
|
if (settings)
|
|
112
124
|
args.push('--settings', JSON.stringify({ ...settings, disableAllHooks: true }));
|
|
@@ -164,10 +176,14 @@ function configurationCacheModels(entries) {
|
|
|
164
176
|
if (!Array.isArray(entries))
|
|
165
177
|
return [];
|
|
166
178
|
return entries.flatMap((row) => {
|
|
167
|
-
const id =
|
|
179
|
+
const id = firstString(row?.slug, row?.value, row?.id);
|
|
168
180
|
return id ? [{ id, label: row.display_name || row.displayName || id, identityKind: modelIdentityKind(id) }] : [];
|
|
169
181
|
});
|
|
170
182
|
}
|
|
183
|
+
/** The first argument that is a string, or `undefined` when none is. */
|
|
184
|
+
function firstString(...values) {
|
|
185
|
+
return values.find((value) => typeof value === 'string');
|
|
186
|
+
}
|
|
171
187
|
function parseGenericCliModels(stdout) {
|
|
172
188
|
let parsed;
|
|
173
189
|
try {
|
|
@@ -181,12 +197,12 @@ function parseGenericCliModels(stdout) {
|
|
|
181
197
|
const entries = Array.isArray(parsed) ? parsed : object.models;
|
|
182
198
|
if (Array.isArray(entries))
|
|
183
199
|
return entries.flatMap((row) => {
|
|
184
|
-
const id =
|
|
200
|
+
const id = firstString(row, row?.id, row?.model);
|
|
185
201
|
return id ? [{ id, label: typeof row?.name === 'string' ? row.name : id, identityKind: modelIdentityKind(id) }] : [];
|
|
186
202
|
});
|
|
187
203
|
}
|
|
188
204
|
return stdout.split('\n').flatMap((line) => {
|
|
189
|
-
const match = line.trim().match(/^(?:[-*•]\s*)?(
|
|
205
|
+
const match = line.trim().match(/^(?:[-*•]\s*)?(\w[\w./:[\]-]*)(?:\s+-\s+(\S.*))?$/);
|
|
190
206
|
if (!match || /^(models|available|provider|model)$/i.test(match[1]))
|
|
191
207
|
return [];
|
|
192
208
|
return [{ id: match[1], label: match[2] || match[1], identityKind: modelIdentityKind(match[1]) }];
|
|
@@ -219,7 +235,7 @@ async function probeCodeBuddyCatalog(agentId, context, deps, signal) {
|
|
|
219
235
|
/** Agents with a dedicated discovery category, checked before any declared listing command. */
|
|
220
236
|
const AGENT_PROBES = new Map([
|
|
221
237
|
['claude', probeClaudeCatalog],
|
|
222
|
-
['pi', probeRpc], ['
|
|
238
|
+
['pi', probeRpc], ['droid', probeRpc],
|
|
223
239
|
// UNVERIFIED CLI-owned effective credential adapters; OAuth/unknown endpoints require host ports.
|
|
224
240
|
['aider', probeProviderApi], ['qwen', probeProviderApi], ['mimo', probeProviderApi],
|
|
225
241
|
['codebuddy', probeCodeBuddyCatalog],
|
|
@@ -300,6 +316,13 @@ function runProcess(input) {
|
|
|
300
316
|
const invocation = createCommandInvocation({ command: input.context.executable, args: [...input.args], env: input.context.env });
|
|
301
317
|
const tree = input.terminateProcessTree && process.platform !== 'win32';
|
|
302
318
|
let treeTimer;
|
|
319
|
+
/** Settles the probe with the exec outcome; an error only rejects when nothing completed first. */
|
|
320
|
+
const settle = (error, stdout, stderr) => {
|
|
321
|
+
if (error && !completed)
|
|
322
|
+
reject(error);
|
|
323
|
+
else
|
|
324
|
+
resolve({ stdout: String(stdout), stderr: String(stderr) });
|
|
325
|
+
};
|
|
303
326
|
const killTree = () => { if (tree && child.pid) {
|
|
304
327
|
try {
|
|
305
328
|
process.kill(-child.pid, 'SIGKILL');
|
|
@@ -318,11 +341,12 @@ function runProcess(input) {
|
|
|
318
341
|
input.signal.removeEventListener('abort', killTree);
|
|
319
342
|
if (error)
|
|
320
343
|
killTree();
|
|
321
|
-
|
|
344
|
+
// Wait for a still-running child to close before settling; otherwise settle now.
|
|
345
|
+
const settleOutcome = settle.bind(undefined, error, stdout, stderr);
|
|
322
346
|
if (child.pid && child.exitCode === null && child.signalCode === null)
|
|
323
|
-
child.once('close',
|
|
347
|
+
child.once('close', settleOutcome);
|
|
324
348
|
else
|
|
325
|
-
|
|
349
|
+
settleOutcome();
|
|
326
350
|
});
|
|
327
351
|
if (tree) {
|
|
328
352
|
input.signal.addEventListener('abort', killTree, { once: true });
|
|
@@ -407,8 +431,6 @@ export const defaultModelDiscoveryDeps = {
|
|
|
407
431
|
acp: createAcpDiscoveryAdapter({ probe: nativeAcpModelProbe }),
|
|
408
432
|
rpc: { async probe({ agentId, context, signal }) {
|
|
409
433
|
// UNVERIFIED locally: use official prompt-free SDK interfaces, not invented CLI flags.
|
|
410
|
-
if (agentId === 'copilot')
|
|
411
|
-
return scheduleProbeProcess({ work: () => probeCopilotSdk(context, signal) }, { signal });
|
|
412
434
|
if (agentId === 'droid')
|
|
413
435
|
return probeDroidSdk(context, defaultModelDiscoveryDeps, signal);
|
|
414
436
|
if (agentId !== 'pi')
|
|
@@ -468,9 +490,10 @@ export function parsePiRpcMetadata(stdout) {
|
|
|
468
490
|
export function getRuntimeModelDiscoveryDeps({ state }, _optional = {}) {
|
|
469
491
|
if (state === defaultRuntimeState)
|
|
470
492
|
return defaultModelDiscoveryDeps;
|
|
471
|
-
|
|
493
|
+
state.discoveryDeps ??= { ...defaultModelDiscoveryDeps, cache: state.modelCatalog,
|
|
472
494
|
acp: createAcpDiscoveryAdapter({ probe: state.acpModelProbe ?? nativeAcpModelProbe }),
|
|
473
495
|
};
|
|
496
|
+
return state.discoveryDeps;
|
|
474
497
|
}
|
|
475
498
|
/** Adapt the existing ACP port to catalog metadata; array-only transports cannot claim a default.
|
|
476
499
|
* Keeps invocation normalization, cancellation and the shared process budget in the native adapter.
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
|
+
import { yamlModelCapture } from './model-discovery-yaml.js';
|
|
4
|
+
/** JSON path of the model setting in the Qoder and Qwen settings files. */
|
|
5
|
+
const MODEL_NAME_PATH = 'model.name';
|
|
3
6
|
const json = (path, key = 'model') => ({ path, format: 'json', key });
|
|
4
7
|
function codexConfigFiles({ env, context, user, local }) {
|
|
5
8
|
const root = env.CODEX_HOME || user('.codex');
|
|
@@ -24,11 +27,10 @@ const CONFIG_FILES = new Map([
|
|
|
24
27
|
// UNVERIFIED locally: the survey documents these settings, not installed schema behavior.
|
|
25
28
|
['grok-build', ({ user }) => [{ path: user('.grok/config.toml'), format: 'toml', key: 'models.model' }]],
|
|
26
29
|
['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
30
|
['cursor-agent', ({ user }) => [json(user('.cursor/cli-config.json'))]],
|
|
29
31
|
['droid', ({ user }) => [json(user('.factory/settings.json'), 'sessionDefaultSettings.model')]],
|
|
30
|
-
['qoder', ({ env, user, local }) => [json(join(env.QODER_CONFIG_DIR || user('.qoder'), 'settings.json'),
|
|
31
|
-
['qwen', ({ user, local }) => [json(user('.qwen/settings.json'),
|
|
32
|
+
['qoder', ({ env, user, local }) => [json(join(env.QODER_CONFIG_DIR || user('.qoder'), 'settings.json'), MODEL_NAME_PATH), json(local('.qoder/settings.json'), MODEL_NAME_PATH), json(local('.qoder/settings.local.json'), MODEL_NAME_PATH)]],
|
|
33
|
+
['qwen', ({ user, local }) => [json(user('.qwen/settings.json'), MODEL_NAME_PATH), json(local('.qwen/settings.json'), MODEL_NAME_PATH)]],
|
|
32
34
|
['deepseek', ({ user }) => [{ path: user('.deepseek/config.toml'), format: 'toml' }, { path: user('.codewhale/config.toml'), format: 'toml' }]],
|
|
33
35
|
['mimo', ({ configHome, local }) => [json(join(configHome, 'mimocode/mimocode.json')), json(local('.mimocode/mimocode.jsonc'))]],
|
|
34
36
|
['crush', ({ configHome, local }) => [json(join(configHome, 'crush/crush.json'), 'models.large.model'), json(local('crush.json'), 'models.large.model')]],
|
|
@@ -102,7 +104,7 @@ export function parseConfiguredModel(file, raw, profile) {
|
|
|
102
104
|
if (file.format === 'json')
|
|
103
105
|
return parseJsonModel(file, raw);
|
|
104
106
|
if (file.format === 'yaml')
|
|
105
|
-
return scalar(raw
|
|
107
|
+
return scalar(yamlModelCapture(raw));
|
|
106
108
|
return parseTomlModel(file, raw, profile);
|
|
107
109
|
}
|
|
108
110
|
const MODEL_ENV = {
|
|
@@ -150,7 +152,8 @@ export async function readModelConfiguration(agentId, context, deps, signal) {
|
|
|
150
152
|
const settingsRaw = await claudeSettingsRaw(agentId, context, deps, signal);
|
|
151
153
|
const settingsModel = settingsRaw ? scalar(parseSettingsJson(settingsRaw)?.model) : undefined;
|
|
152
154
|
// Precedence, strongest first: launch model, Claude --settings, model env, inline config content, config files.
|
|
153
|
-
const
|
|
155
|
+
const launchSelection = context.model || settingsModel;
|
|
156
|
+
const selection = launchSelection || envSelection(agentId, context.env) || inlineSelection(agentId, context.env) || fileSelection(agentId, contents, context.profile);
|
|
154
157
|
// Material is hashed by the orchestration layer and is never exposed over HTTP.
|
|
155
158
|
return { ...(selection ? { selection } : {}), fingerprintMaterial: JSON.stringify([contents.map(({ file, raw }) => [file.path, raw]), settingsRaw || '']) };
|
|
156
159
|
}
|
|
@@ -1,32 +1,3 @@
|
|
|
1
1
|
import type { ModelDiscoveryContext, ModelDiscoveryDeps, ModelProbeResult } from './model-discovery-types.js';
|
|
2
|
-
/** UNVERIFIED locally. The host may install the official SDK or inject the RPC port.
|
|
3
|
-
* Use the CLI's authenticated server, not an unrelated HTTP token or an inference prompt.
|
|
4
|
-
* https://github.com/github/copilot-sdk/blob/main/nodejs/src/client.ts */
|
|
5
|
-
export interface CopilotMetadataClient {
|
|
6
|
-
start(): Promise<unknown>;
|
|
7
|
-
listModels(): Promise<{
|
|
8
|
-
id: string;
|
|
9
|
-
name?: string;
|
|
10
|
-
}[]>;
|
|
11
|
-
forceStop(): Promise<unknown>;
|
|
12
|
-
}
|
|
13
|
-
export declare function probeCopilotSdk(context: ModelDiscoveryContext, signal: AbortSignal, optional?: {
|
|
14
|
-
createClient?: (context: ModelDiscoveryContext) => Promise<CopilotMetadataClient>;
|
|
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>;
|
|
31
2
|
export declare function probeDroidSdk(context: ModelDiscoveryContext, deps: ModelDiscoveryDeps, signal: AbortSignal): Promise<ModelProbeResult>;
|
|
32
3
|
//# sourceMappingURL=model-discovery-sdk.d.ts.map
|
|
@@ -1,36 +1,4 @@
|
|
|
1
1
|
import { ModelProbeError, modelIdentityKind } from './model-discovery-shared.js';
|
|
2
|
-
export async function probeCopilotSdk(context, signal, optional = {}) {
|
|
3
|
-
const client = await (optional.createClient ?? createCopilotMetadataClient)(context);
|
|
4
|
-
if (signal.aborted) {
|
|
5
|
-
await client.forceStop().catch(() => { });
|
|
6
|
-
throw new ModelProbeError('timeout');
|
|
7
|
-
}
|
|
8
|
-
const stop = () => { void Promise.resolve(client.forceStop()).catch(() => { }); };
|
|
9
|
-
signal.addEventListener('abort', stop, { once: true });
|
|
10
|
-
try {
|
|
11
|
-
await client.start();
|
|
12
|
-
if (signal.aborted)
|
|
13
|
-
throw new ModelProbeError('timeout');
|
|
14
|
-
const rows = await client.listModels();
|
|
15
|
-
return { models: rows.map((row) => ({ id: row.id, label: row.name || row.id, identityKind: modelIdentityKind(row.id) })), source: 'rpc', coverage: 'account' };
|
|
16
|
-
}
|
|
17
|
-
finally {
|
|
18
|
-
signal.removeEventListener('abort', stop);
|
|
19
|
-
// forceStop also closes the child when a failed handshake never reached connected state.
|
|
20
|
-
await client.forceStop().catch(() => { });
|
|
21
|
-
}
|
|
22
|
-
}
|
|
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');
|
|
27
|
-
const env = Object.fromEntries(Object.entries(context.env).filter((entry) => typeof entry[1] === 'string'));
|
|
28
|
-
// RuntimeConnection is the current SDK API; older SDKs expose cliPath/cwd/useStdio.
|
|
29
|
-
const connection = sdk.RuntimeConnection?.forStdio({ path: context.executable, env });
|
|
30
|
-
return new sdk.CopilotClient(connection
|
|
31
|
-
? { connection, workingDirectory: context.cwd, autoRestart: false }
|
|
32
|
-
: { cliPath: context.executable, cwd: context.cwd, env, useStdio: true, autoRestart: false });
|
|
33
|
-
}
|
|
34
2
|
/** UNVERIFIED locally. Official Python SDK metadata bridge; no session/inference call.
|
|
35
3
|
* SDK installation belongs to the host's Python environment.
|
|
36
4
|
* https://docs.factory.com/sdk/python#discover-available-models */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { RuntimeEnv, RuntimeModelOption } from './
|
|
1
|
+
import type { RuntimeEnv, RuntimeModelOption, ModelIdentityKind } from './model-contracts.js';
|
|
2
2
|
import type { ProviderModelsInput } from './providers/model-catalog.js';
|
|
3
|
+
export type { ModelIdentityKind } from './model-contracts.js';
|
|
3
4
|
export type ModelSource = 'cli' | 'rpc' | 'provider-api' | 'cli-cache' | 'config-file' | 'offline-fallback';
|
|
4
|
-
export type ModelIdentityKind = 'concrete' | 'alias' | 'routing-mode';
|
|
5
5
|
export interface DiscoveredModel extends RuntimeModelOption {
|
|
6
6
|
identityKind: ModelIdentityKind;
|
|
7
7
|
resolvedId?: string;
|
|
@@ -123,7 +123,7 @@ export interface ModelDiscoveryDeps {
|
|
|
123
123
|
signal: AbortSignal;
|
|
124
124
|
}): Promise<ModelProbeResult>;
|
|
125
125
|
};
|
|
126
|
-
/**
|
|
126
|
+
/** Droid SDK ports: no undocumented CLI flags or inference prompts. */
|
|
127
127
|
rpc: {
|
|
128
128
|
probe(input: {
|
|
129
129
|
agentId: string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The `model:` value of a YAML agent config, read without a regex. The pattern this replaces,
|
|
3
|
+
* `/^model\s*:\s*["']?([^\n"'#]+)["']?\s*(?:#.*)?$/m`, backtracks super-linearly on long
|
|
4
|
+
* whitespace runs; `yamlModelCapture` returns exactly what its group captured, in time linear in
|
|
5
|
+
* the input for each `model` key it tries.
|
|
6
|
+
*/
|
|
7
|
+
/** First `model:` capture of `/^model\s*:\s*["']?([^\n"'#]+)["']?\s*(?:#.*)?$/m` in `raw`. */
|
|
8
|
+
export declare function yamlModelCapture(raw: string): string | undefined;
|
|
9
|
+
//# sourceMappingURL=model-discovery-yaml.d.ts.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The `model:` value of a YAML agent config, read without a regex. The pattern this replaces,
|
|
3
|
+
* `/^model\s*:\s*["']?([^\n"'#]+)["']?\s*(?:#.*)?$/m`, backtracks super-linearly on long
|
|
4
|
+
* whitespace runs; `yamlModelCapture` returns exactly what its group captured, in time linear in
|
|
5
|
+
* the input for each `model` key it tries.
|
|
6
|
+
*/
|
|
7
|
+
// `/^model\s*:\s*["']?([^\n"'#]+)["']?\s*(?:#.*)?$/m`'s capture, as a linear scan. Two regex
|
|
8
|
+
// details survive: the group may end early at an in-run line terminator (`\r`, U+2028, U+2029,
|
|
9
|
+
// before which `$` matches), and it may start inside the whitespace after the colon (the regex
|
|
10
|
+
// backtracks out of `\s*` one character at a time when the value itself does not match).
|
|
11
|
+
const YAML_LINE_TERMINATORS = '\n\r\u2028\u2029';
|
|
12
|
+
const YAML_GROUP_STOPS = '\n"\'#';
|
|
13
|
+
const isYamlSpace = (ch) => ch !== undefined && /\s/.test(ch);
|
|
14
|
+
const isYamlQuote = (ch) => ch === '"' || ch === "'";
|
|
15
|
+
const isYamlTerminator = (ch) => ch !== undefined && YAML_LINE_TERMINATORS.includes(ch);
|
|
16
|
+
function yamlSpaceEnd(raw, index) {
|
|
17
|
+
let i = index;
|
|
18
|
+
while (isYamlSpace(raw[i]))
|
|
19
|
+
i += 1;
|
|
20
|
+
return i;
|
|
21
|
+
}
|
|
22
|
+
/** End of the run of group characters (anything but a newline, quote or `#`) from `index`. */
|
|
23
|
+
function yamlRunEnd(raw, index) {
|
|
24
|
+
let i = index;
|
|
25
|
+
while (i < raw.length && !YAML_GROUP_STOPS.includes(raw[i]))
|
|
26
|
+
i += 1;
|
|
27
|
+
return i;
|
|
28
|
+
}
|
|
29
|
+
/** Whether `["']?\s*(?:#.*)?$` matches at `index`. */
|
|
30
|
+
function yamlTailMatches(raw, index) {
|
|
31
|
+
const from = isYamlQuote(raw[index]) ? index + 1 : index;
|
|
32
|
+
const end = yamlSpaceEnd(raw, from);
|
|
33
|
+
if (end === raw.length || raw[end] === '#')
|
|
34
|
+
return true;
|
|
35
|
+
for (let i = from; i < end; i += 1)
|
|
36
|
+
if (isYamlTerminator(raw[i]))
|
|
37
|
+
return true;
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
/** Last line terminator strictly inside `(start, end)`, or -1. */
|
|
41
|
+
function yamlLastTerminator(raw, start, end) {
|
|
42
|
+
for (let i = end - 1; i > start; i -= 1)
|
|
43
|
+
if (isYamlTerminator(raw[i]))
|
|
44
|
+
return i;
|
|
45
|
+
return -1;
|
|
46
|
+
}
|
|
47
|
+
/** The group captured when it starts at `start` inside `run`, or undefined. */
|
|
48
|
+
function yamlGroupFrom(raw, start, run) {
|
|
49
|
+
if (run.end === start)
|
|
50
|
+
return undefined;
|
|
51
|
+
if (run.tailMatches)
|
|
52
|
+
return raw.slice(start, run.end);
|
|
53
|
+
return run.cut === -1 ? undefined : raw.slice(start, run.cut);
|
|
54
|
+
}
|
|
55
|
+
/** The capture for a `model` key whose colon ends just before `afterColon`, or undefined. */
|
|
56
|
+
function yamlModelValue(raw, afterColon) {
|
|
57
|
+
const valueStart = yamlSpaceEnd(raw, afterColon);
|
|
58
|
+
if (isYamlQuote(raw[valueStart])) {
|
|
59
|
+
const quotedEnd = yamlRunEnd(raw, valueStart + 1);
|
|
60
|
+
const quotedRun = { end: quotedEnd, tailMatches: yamlTailMatches(raw, quotedEnd), cut: yamlLastTerminator(raw, valueStart + 1, quotedEnd) };
|
|
61
|
+
const quoted = yamlGroupFrom(raw, valueStart + 1, quotedRun);
|
|
62
|
+
if (quoted !== undefined)
|
|
63
|
+
return quoted;
|
|
64
|
+
}
|
|
65
|
+
// Walk left from the value through the whitespace after the colon, updating the current run
|
|
66
|
+
// in O(1) per step: a newline ends the run to its left (and `$` matches before it), and each
|
|
67
|
+
// step can only add a new last-terminator candidate when the run has none yet.
|
|
68
|
+
const runEnd = yamlRunEnd(raw, valueStart);
|
|
69
|
+
const run = { end: runEnd, tailMatches: yamlTailMatches(raw, runEnd), cut: yamlLastTerminator(raw, valueStart, runEnd) };
|
|
70
|
+
for (let start = valueStart; start >= afterColon; start -= 1) {
|
|
71
|
+
const group = raw[start] === '\n' ? undefined : yamlGroupFrom(raw, start, run);
|
|
72
|
+
if (group !== undefined)
|
|
73
|
+
return group;
|
|
74
|
+
yamlExtendRunLeft(raw, start, run);
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
/** Moves `run` to start one character left of `start`. */
|
|
79
|
+
function yamlExtendRunLeft(raw, start, run) {
|
|
80
|
+
if (raw[start] === '\n') {
|
|
81
|
+
Object.assign(run, { end: start, tailMatches: true, cut: -1 });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (run.cut === -1 && start < run.end && isYamlTerminator(raw[start]))
|
|
85
|
+
run.cut = start;
|
|
86
|
+
}
|
|
87
|
+
/** First `model:` capture of `/^model\s*:\s*["']?([^\n"'#]+)["']?\s*(?:#.*)?$/m` in `raw`. */
|
|
88
|
+
export function yamlModelCapture(raw) {
|
|
89
|
+
for (let lineStart = 0; lineStart <= raw.length; lineStart += 1) {
|
|
90
|
+
const atLineStart = lineStart === 0 || isYamlTerminator(raw[lineStart - 1]);
|
|
91
|
+
const colon = atLineStart && raw.startsWith('model', lineStart) ? yamlSpaceEnd(raw, lineStart + 5) : -1;
|
|
92
|
+
const value = raw[colon] === ':' ? yamlModelValue(raw, colon + 1) : undefined;
|
|
93
|
+
if (value !== undefined)
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=model-discovery-yaml.js.map
|
package/dist/model-discovery.js
CHANGED
|
@@ -23,8 +23,12 @@ async function boundedProbe(deps, work, signal) {
|
|
|
23
23
|
if (pool.active >= 1) {
|
|
24
24
|
await new Promise((resolve, reject) => {
|
|
25
25
|
const ready = () => { signal?.removeEventListener('abort', abort); resolve(); };
|
|
26
|
-
const abort = () => {
|
|
27
|
-
pool.queue.
|
|
26
|
+
const abort = () => {
|
|
27
|
+
const index = pool.queue.indexOf(ready);
|
|
28
|
+
if (index >= 0)
|
|
29
|
+
pool.queue.splice(index, 1);
|
|
30
|
+
reject(new ProbeTimeout('Probe cancelled'));
|
|
31
|
+
};
|
|
28
32
|
pool.queue.push(ready);
|
|
29
33
|
if (signal?.aborted)
|
|
30
34
|
abort();
|
|
@@ -54,9 +58,12 @@ const DIAGNOSTIC_MESSAGES = {
|
|
|
54
58
|
'malformed-response': 'Native metadata contained no usable catalog.',
|
|
55
59
|
offline: 'Model discovery could not reach its source.',
|
|
56
60
|
};
|
|
61
|
+
function probeErrorCode(error) {
|
|
62
|
+
return error instanceof ModelProbeError ? error.code : 'offline';
|
|
63
|
+
}
|
|
57
64
|
function diagnostic(error) {
|
|
58
65
|
// Never stringify vendor errors: stderr/HTTP bodies may include credentials or OAuth URLs.
|
|
59
|
-
const code = error instanceof ProbeTimeout ? 'timeout' : error
|
|
66
|
+
const code = error instanceof ProbeTimeout ? 'timeout' : probeErrorCode(error);
|
|
60
67
|
return { code, message: DIAGNOSTIC_MESSAGES[code] };
|
|
61
68
|
}
|
|
62
69
|
function isUnexpired(snapshot, now) {
|
package/dist/model-registry.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { trimCharsEnd } from '@jini-ai/core/text';
|
|
1
2
|
/**
|
|
2
3
|
* Resolves a provider's credential status for display. A provider that
|
|
3
4
|
* doesn't require credentials is always `available`; otherwise the status
|
|
@@ -51,7 +52,7 @@ export function modelCatalogCacheKey({ providerId, baseUrl, credential }, { vari
|
|
|
51
52
|
throw new TypeError('Model catalog variant must be a string');
|
|
52
53
|
return [
|
|
53
54
|
providerId,
|
|
54
|
-
baseUrl.trim()
|
|
55
|
+
trimCharsEnd({ text: baseUrl.trim(), chars: '/' }),
|
|
55
56
|
fingerprintCredential({ value: credential.trim() }),
|
|
56
57
|
variant.trim(),
|
|
57
58
|
].join('\n');
|