zcode-acp-server 0.87.0 → 0.88.1

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/README.md CHANGED
@@ -336,6 +336,7 @@ See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for the full architecture docum
336
336
 
337
337
  - [Architecture](docs/ARCHITECTURE.md) — event stream, dual-path deduplication, module responsibilities
338
338
  - [Protocol](docs/PROTOCOL.md) — ZCode JSON-RPC protocol details
339
+ - [Config Options](docs/CONFIG-OPTIONS.md) — configOptions, model value encoding, `_meta.zcode` provider metadata (ACP client guide)
339
340
  - [Sandbox](docs/SANDBOX.md) — full sandbox manual (switches, whitelist, popups, verification)
340
341
  - [Remote Access](docs/REMOTE.md) — hub, discovery API, tunnels, remote session-create
341
342
  - [Unified CLI](docs/CLI.md) — interactive TUI, quota cards, hub/server subcommands
@@ -356,7 +357,7 @@ Thanks to everyone who has contributed (updated automatically from the
356
357
  <a href="https://github.com/william0wang/zcode-acp/graphs/contributors">
357
358
  <!-- release-please re-stamps &v= on every release: the new URL busts the
358
359
  contrib.rocks and GitHub camo image caches. -->
359
- <img src="https://contrib.rocks/image?repo=william0wang/zcode-acp&v=0.87.0" alt="Contributors" /> <!-- x-release-please-version -->
360
+ <img src="https://contrib.rocks/image?repo=william0wang/zcode-acp&v=0.88.1" alt="Contributors" /> <!-- x-release-please-version -->
360
361
  </a>
361
362
 
362
363
  ## Related Projects
package/README.zh-CN.md CHANGED
@@ -229,6 +229,7 @@ CI 会在每次 push 和 pull request 时运行 `typecheck`、`lint`、`build`
229
229
 
230
230
  - [架构](docs/ARCHITECTURE.md) —— 事件流、双路径去重、模块职责
231
231
  - [协议](docs/PROTOCOL.md) —— ZCode JSON-RPC 协议细节
232
+ - [配置选项](docs/CONFIG-OPTIONS.md) —— configOptions、model 值编码、`_meta.zcode` provider 元数据(ACP 客户端集成指南)
232
233
  - [沙箱](docs/SANDBOX.md) —— 沙箱完整手册(开关、白名单、弹窗、验证)
233
234
  - [远程访问](docs/REMOTE.md) —— hub、发现 API、隧道、远程创建会话
234
235
  - [统一 CLI](docs/CLI.md) —— REPL、配额卡片、hub/server 子命令
@@ -1,4 +1,4 @@
1
1
  {
2
- "fingerprint": "124652316a9cc75bc206fa69c5ff4031e154aade5eae2341a66e5c6a7149f8a1",
3
- "fileCount": 131
2
+ "fingerprint": "bf5f069ad79e9405f947dfb6842adbd6f78dccb1b0c3f13476109cb850843052",
3
+ "fileCount": 132
4
4
  }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Unified inbound model-value resolution (#403).
3
+ *
4
+ * Model values arrive from several dialects and eras: the bridge's own
5
+ * `providerId\modelId` configOption encoding, the `custom:<urlencoded>:<model>`
6
+ * agent-definition spelling, a `/`-separated provider ref (the string form the
7
+ * backend itself parses, provider-registry-selection.ts), a legacy bare
8
+ * modelId, and provider ids in either the config dialect (`builtin:…`) or the
9
+ * registry dialect (`account:…`). The backend registry validates selections by
10
+ * EXACT string match on (providerId, modelId) — no alias resolution exists at
11
+ * that layer — so every inbound value must be normalized against a registry
12
+ * snapshot before `session/setModel`, or a stale id ("GLM-5.3" from a frozen
13
+ * config.json, a `builtin:`-prefixed id from an older advertisement) fails with
14
+ * "Provider Registry 中不存在 Model" and clients abort the session open
15
+ * (observed with T3 Code, issue #403).
16
+ *
17
+ * Resolution is deterministic only: separator/dialect/case folding, mirroring
18
+ * upstream's frozen one-way maps (`legacy-model-provider-identity.ts`,
19
+ * `official-glm-model-id.ts`). No cross-family substitution — a provider id
20
+ * that folds to nothing in the snapshot fails rather than silently billing a
21
+ * different plan family (upstream explicitly declines such mapping:
22
+ * session-model-unavailable-admission.md "不在范围").
23
+ */
24
+ /** Structural shape of a `server.modelAvailability` entry (registry dialect). */
25
+ export interface RegistryModelEntry {
26
+ providerId?: string;
27
+ modelId?: string;
28
+ }
29
+ export interface ResolvedModelTarget {
30
+ /** Registry dialect (`account:…` for coding plans). */
31
+ providerId: string;
32
+ modelId: string;
33
+ /** How the target was found — "unverified" means no snapshot was available. */
34
+ via: "exact" | "dialect" | "case-fold" | "unique" | "unverified";
35
+ }
36
+ export type ModelResolution = {
37
+ ok: true;
38
+ target: ResolvedModelTarget;
39
+ } | {
40
+ ok: false;
41
+ reason: string;
42
+ };
43
+ export interface ParsedModelRef {
44
+ /** Undefined for a legacy bare modelId (no provider qualification). */
45
+ providerId?: string;
46
+ modelId: string;
47
+ /** True for `custom:`/`\`/`/` qualified forms — a bare modelId is not encoded. */
48
+ encoded: boolean;
49
+ }
50
+ /**
51
+ * Split an inbound model value into its syntactic parts. Pure syntax — no
52
+ * config files, no snapshot. Extends `parseModelValue` (options.ts) with the
53
+ * `/`-separated provider ref dialect; that function's bare-id branch resolves
54
+ * against local config and stays where it is.
55
+ */
56
+ export declare function parseModelRefValue(value: string): ParsedModelRef;
57
+ /**
58
+ * Resolve an inbound model value against a registry snapshot.
59
+ *
60
+ * Order per provider candidate: exact model id, then case-folded (mirrors
61
+ * upstream `normalizeOfficialGlmModelId` without freezing a local model list —
62
+ * the snapshot itself is the vocabulary). A bare modelId resolves only when it
63
+ * names exactly ONE model across the snapshot. Without a snapshot, a provider-
64
+ * qualified ref passes through dialect-folded ("unverified" — the backend
65
+ * stays the final authority); a bare id cannot resolve.
66
+ */
67
+ export declare function resolveModelTarget(value: string, snapshot: readonly RegistryModelEntry[] | undefined): ModelResolution;
68
+ //# sourceMappingURL=model-resolution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-resolution.d.ts","sourceRoot":"","sources":["../../src/config/model-resolution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,iFAAiF;AACjF,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,GAAG,EAAE,OAAO,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,YAAY,CAAC;CAClE;AAED,MAAM,MAAM,eAAe,GACzB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,mBAAmB,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5E,MAAM,WAAW,cAAc;IAC7B,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,kFAAkF;IAClF,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAyBhE;AAmBD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,SAAS,kBAAkB,EAAE,GAAG,SAAS,GAClD,eAAe,CA4EjB"}
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Unified inbound model-value resolution (#403).
3
+ *
4
+ * Model values arrive from several dialects and eras: the bridge's own
5
+ * `providerId\modelId` configOption encoding, the `custom:<urlencoded>:<model>`
6
+ * agent-definition spelling, a `/`-separated provider ref (the string form the
7
+ * backend itself parses, provider-registry-selection.ts), a legacy bare
8
+ * modelId, and provider ids in either the config dialect (`builtin:…`) or the
9
+ * registry dialect (`account:…`). The backend registry validates selections by
10
+ * EXACT string match on (providerId, modelId) — no alias resolution exists at
11
+ * that layer — so every inbound value must be normalized against a registry
12
+ * snapshot before `session/setModel`, or a stale id ("GLM-5.3" from a frozen
13
+ * config.json, a `builtin:`-prefixed id from an older advertisement) fails with
14
+ * "Provider Registry 中不存在 Model" and clients abort the session open
15
+ * (observed with T3 Code, issue #403).
16
+ *
17
+ * Resolution is deterministic only: separator/dialect/case folding, mirroring
18
+ * upstream's frozen one-way maps (`legacy-model-provider-identity.ts`,
19
+ * `official-glm-model-id.ts`). No cross-family substitution — a provider id
20
+ * that folds to nothing in the snapshot fails rather than silently billing a
21
+ * different plan family (upstream explicitly declines such mapping:
22
+ * session-model-unavailable-admission.md "不在范围").
23
+ */
24
+ import { accountProviderIdFor, configProviderIdFor } from "./account-provider.js";
25
+ /**
26
+ * Split an inbound model value into its syntactic parts. Pure syntax — no
27
+ * config files, no snapshot. Extends `parseModelValue` (options.ts) with the
28
+ * `/`-separated provider ref dialect; that function's bare-id branch resolves
29
+ * against local config and stays where it is.
30
+ */
31
+ export function parseModelRefValue(value) {
32
+ const custom = /^custom:([^:]+):(.+)$/.exec(value);
33
+ if (custom) {
34
+ try {
35
+ return { providerId: decodeURIComponent(custom[1]), modelId: custom[2], encoded: true };
36
+ }
37
+ catch {
38
+ // malformed encoding — fall through to the legacy spellings
39
+ }
40
+ }
41
+ const backslash = value.indexOf("\\");
42
+ if (backslash > 0) {
43
+ return {
44
+ providerId: value.slice(0, backslash),
45
+ modelId: value.slice(backslash + 1),
46
+ encoded: true,
47
+ };
48
+ }
49
+ // `/`-separated provider ref (the backend's own string form): only when the
50
+ // prefix looks like a provider id (contains ":"), so a bare modelId that
51
+ // merely contains a slash is not torn apart.
52
+ const slash = value.indexOf("/");
53
+ if (slash > 0 && value.slice(0, slash).includes(":")) {
54
+ return { providerId: value.slice(0, slash), modelId: value.slice(slash + 1), encoded: true };
55
+ }
56
+ return { modelId: value, encoded: false };
57
+ }
58
+ /** Provider id candidates for a parsed ref: the id itself plus both dialects. */
59
+ function providerCandidates(providerId) {
60
+ const out = [];
61
+ for (const candidate of [
62
+ providerId,
63
+ accountProviderIdFor(providerId),
64
+ configProviderIdFor(providerId),
65
+ ]) {
66
+ if (candidate && !out.includes(candidate))
67
+ out.push(candidate);
68
+ }
69
+ return out;
70
+ }
71
+ function lower(s) {
72
+ return s.toLowerCase();
73
+ }
74
+ /**
75
+ * Resolve an inbound model value against a registry snapshot.
76
+ *
77
+ * Order per provider candidate: exact model id, then case-folded (mirrors
78
+ * upstream `normalizeOfficialGlmModelId` without freezing a local model list —
79
+ * the snapshot itself is the vocabulary). A bare modelId resolves only when it
80
+ * names exactly ONE model across the snapshot. Without a snapshot, a provider-
81
+ * qualified ref passes through dialect-folded ("unverified" — the backend
82
+ * stays the final authority); a bare id cannot resolve.
83
+ */
84
+ export function resolveModelTarget(value, snapshot) {
85
+ const parsed = parseModelRefValue(value);
86
+ const snapshotPresent = Array.isArray(snapshot) && snapshot.length > 0;
87
+ if (!snapshotPresent) {
88
+ if (parsed.providerId) {
89
+ return {
90
+ ok: true,
91
+ target: {
92
+ providerId: accountProviderIdFor(parsed.providerId),
93
+ modelId: parsed.modelId,
94
+ via: "unverified",
95
+ },
96
+ };
97
+ }
98
+ return { ok: false, reason: `bare model id "${value}" with no registry snapshot` };
99
+ }
100
+ if (parsed.providerId) {
101
+ const candidates = providerCandidates(parsed.providerId);
102
+ for (const pid of candidates) {
103
+ for (const entry of snapshot) {
104
+ if (entry.providerId === pid && entry.modelId === parsed.modelId) {
105
+ return {
106
+ ok: true,
107
+ target: {
108
+ providerId: pid,
109
+ modelId: parsed.modelId,
110
+ via: pid === parsed.providerId ? "exact" : "dialect",
111
+ },
112
+ };
113
+ }
114
+ }
115
+ }
116
+ for (const pid of candidates) {
117
+ for (const entry of snapshot) {
118
+ if (entry.providerId === pid && lower(entry.modelId ?? "") === lower(parsed.modelId)) {
119
+ return {
120
+ ok: true,
121
+ target: { providerId: pid, modelId: entry.modelId, via: "case-fold" },
122
+ };
123
+ }
124
+ }
125
+ }
126
+ const tried = candidates.join(", ");
127
+ return {
128
+ ok: false,
129
+ reason: `"${value}" matches no model in the session registry (providers tried: ${tried})`,
130
+ };
131
+ }
132
+ // Bare model id: exact match first, then case-folded; unique provider only.
133
+ for (const fold of [false, true]) {
134
+ const hits = snapshot.filter((e) => e.providerId && e.modelId
135
+ ? fold
136
+ ? lower(e.modelId) === lower(parsed.modelId)
137
+ : e.modelId === parsed.modelId
138
+ : false);
139
+ const providers = new Set(hits.map((e) => e.providerId));
140
+ if (providers.size === 1) {
141
+ const hit = hits[0];
142
+ return {
143
+ ok: true,
144
+ target: {
145
+ providerId: hit.providerId,
146
+ modelId: hit.modelId,
147
+ via: fold ? "case-fold" : "unique",
148
+ },
149
+ };
150
+ }
151
+ }
152
+ return {
153
+ ok: false,
154
+ reason: `bare model id "${value}" is not uniquely present in the session registry`,
155
+ };
156
+ }
157
+ //# sourceMappingURL=model-resolution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-resolution.js","sourceRoot":"","sources":["../../src/config/model-resolution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AA2BlF;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,MAAM,MAAM,GAAG,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnD,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,CAAC;YACH,OAAO,EAAE,UAAU,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC5F,CAAC;QAAC,MAAM,CAAC;YACP,4DAA4D;QAC9D,CAAC;IACH,CAAC;IACD,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QAClB,OAAO;YACL,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC;YACrC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC;YACnC,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;IACD,4EAA4E;IA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E,EAAE,KAAK;QACT,MAAM,EAAE,kBAAkB,KAAK,mDAAmD;KACnF,CAAC;AACJ,CAAC"}
@@ -67,6 +67,14 @@ export interface ModelRef {
67
67
  * local baseURL (llama.cpp/ollama-style providers work keyless).
68
68
  */
69
69
  export declare function providerSelectable(pid: string, p: ProviderEntry | undefined): boolean;
70
+ /**
71
+ * Why a provider entry is NOT selectable (null = selectable) — the reason
72
+ * taxonomy exported to ACP clients as `unselectableReason` in
73
+ * `_meta.zcode.providers` (#400), so a client can render "link account in the
74
+ * desktop app" instead of silently omitting the provider.
75
+ */
76
+ export type ProviderUnselectableReason = "disabled" | "keyless-builtin" | "non-local-keyless";
77
+ export declare function providerUnselectableReason(pid: string, p: ProviderEntry | undefined): ProviderUnselectableReason | null;
70
78
  /**
71
79
  * Collect models from config.json for the dropdown, UNIONED with the desktop's
72
80
  * provider_config.json (3.12+): models the user added in the desktop app land
@@ -78,6 +86,47 @@ export declare function providerSelectable(pid: string, p: ProviderEntry | undef
78
86
  * provider, plus whole providers it describes and config.json does not.
79
87
  */
80
88
  export declare function loadAllModels(): ModelRef[];
89
+ /** One provider entry in the ACP-facing `_meta.zcode.providers` list. */
90
+ export interface ProviderMetadataEntry {
91
+ /**
92
+ * Config-dialect provider id (`builtin:…` slug / custom UUID) — NOT the
93
+ * registry's `account:` spelling, so it matches the other config.json-sourced
94
+ * fields a client sees.
95
+ */
96
+ id: string;
97
+ /** Display name (the desktop app's providerName; the raw id when unnamed). */
98
+ name: string;
99
+ /** Whether the model dropdown offers this provider's models. */
100
+ selectable: boolean;
101
+ /** Present only when selectable is false — why the dropdown skips it. */
102
+ unselectableReason?: ProviderUnselectableReason;
103
+ /**
104
+ * The modelId the dropdown lists first for the provider — what a session
105
+ * started on it actually runs (`loadZcodeCredentials` dispatches the first
106
+ * config.json key, same order the dropdown derives from).
107
+ */
108
+ defaultModel?: string;
109
+ }
110
+ /** The `_meta.zcode` payload on the model configOption and session/new responses. */
111
+ export interface ProviderMetaPayload {
112
+ providers: ProviderMetadataEntry[];
113
+ /** Config dialect of the current provider (`account:` refs fold to `builtin:`). */
114
+ currentProviderId: string;
115
+ }
116
+ /**
117
+ * The provider list ACP clients render a provider picker from (#400) —
118
+ * without mirroring `providerSelectable` and the config scan in their own
119
+ * code. Selectable providers come FIRST, derived from the SAME
120
+ * `loadAllModels()` output the model dropdown offers (pass `models` when the
121
+ * caller already holds it), so metadata and dropdown can never disagree —
122
+ * including the ZCODE_PROVIDER pin and entitled coding plans. Unselectable
123
+ * config.json / personal-only entries follow with a reason code, so a client
124
+ * can render "keyless — link account in the desktop app" instead of a
125
+ * silent gap.
126
+ */
127
+ export declare function providerMetadataList(models?: ModelRef[]): ProviderMetadataEntry[];
128
+ /** Assemble the `_meta.zcode` payload; the current provider id normalizes to the config dialect. */
129
+ export declare function buildProviderMeta(currentProviderId: string, models?: ModelRef[]): ProviderMetaPayload;
81
130
  /** Look up a provider entry by id (any provider, not just enabled).
82
131
  *
83
132
  * 3.12+ registries spell coding-plan providers `account:<family>-<plan>` while
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/config/options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,KAAK,GAAG,MAAM,0BAA0B,CAAC;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAmB,MAAM,qBAAqB,CAAC;AAW9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAWnD,UAAU,kBAAkB;IAC1B,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,KAAK,CAAC,EAAE;YAAE,OAAO,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,GAAG,SAAS,CAAC;CACjE;AAOD,0EAA0E;AAC1E,UAAU,aAAa;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC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AO,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC,CAiOpC;AAgED,qFAAqF;AACrF,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,OAAO,EACrB,MAAM,EAAE,iBAAiB,GAAG,IAAI,GAC/B,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC,CAqCpC;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC;IAAE,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CA2B9E;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1C,IAAI,CAWN;AAED;;;;;;;;;;;;;;;;;;;;yDAoByD;AACzD,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,cAAc,EACtB,EAAE,EAAE,GAAG,CAAC,YAAY,EACpB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,GACjC,OAAO,CAAC;IAAE,OAAO,EAAE,GAAG,CAAC,mBAAmB,EAAE,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAyDzE"}
@@ -107,17 +107,27 @@ export const DEFAULT_MODEL_ID = "GLM-5.3";
107
107
  * local baseURL (llama.cpp/ollama-style providers work keyless).
108
108
  */
109
109
  export function providerSelectable(pid, p) {
110
+ return providerUnselectableReason(pid, p) === null;
111
+ }
112
+ export function providerUnselectableReason(pid, p) {
110
113
  if (!p)
111
- return false;
112
- if (isBuiltinProvider(pid))
113
- return p.enabled === true && Boolean(p.options?.apiKey);
114
+ return "disabled";
115
+ if (isBuiltinProvider(pid)) {
116
+ if (p.enabled !== true)
117
+ return "disabled";
118
+ if (!p.options?.apiKey)
119
+ return "keyless-builtin";
120
+ return null;
121
+ }
114
122
  if (p.enabled === false)
115
- return false;
123
+ return "disabled";
116
124
  if (p.options?.apiKey)
117
- return true;
125
+ return null;
118
126
  if (p.options?.apiKeyRequired === false)
119
- return true;
120
- return isLocalBaseURL(p.options?.baseURL);
127
+ return null;
128
+ if (isLocalBaseURL(p.options?.baseURL))
129
+ return null;
130
+ return "non-local-keyless";
121
131
  }
122
132
  /** localhost-style baseURL (llama.cpp / Ollama / LM Studio run keyless). */
123
133
  function isLocalBaseURL(url) {
@@ -131,6 +141,45 @@ function isLocalBaseURL(url) {
131
141
  return false;
132
142
  }
133
143
  }
144
+ /** Synthesize a config.json-shaped provider entry from a personal rule. */
145
+ function personalRuleEntry(rule) {
146
+ return {
147
+ name: rule.providerName,
148
+ enabled: rule.enabled,
149
+ options: {
150
+ apiKey: rule.config?.access?.apiKey,
151
+ baseURL: rule.config?.api?.baseUrl,
152
+ },
153
+ };
154
+ }
155
+ /**
156
+ * A config.json entry with the 3.12+ personal rule overlaid — custom
157
+ * providers toggled/updated in the desktop app write their new `enabled` /
158
+ * `apiKey` / `baseUrl` only to provider_config.json, leaving legacy
159
+ * config.json frozen at its pre-3.12 state. Without the overlay a provider
160
+ * disabled in 3.12+ stays selectable via config.json.
161
+ */
162
+ function effectiveProviderEntry(pid, p, personal) {
163
+ const personalRule = !isBuiltinProvider(pid)
164
+ ? personal?.providers.find((entry) => entry.pid === pid)?.rule
165
+ : undefined;
166
+ if (!p || !personalRule)
167
+ return p;
168
+ return {
169
+ ...p,
170
+ name: personalRule.providerName ?? p.name,
171
+ enabled: personalRule.enabled ?? p.enabled,
172
+ options: {
173
+ ...p.options,
174
+ ...(personalRule.config?.access?.apiKey !== undefined
175
+ ? { apiKey: personalRule.config.access.apiKey }
176
+ : {}),
177
+ ...(personalRule.config?.api?.baseUrl !== undefined
178
+ ? { baseURL: personalRule.config.api.baseUrl }
179
+ : {}),
180
+ },
181
+ };
182
+ }
134
183
  /**
135
184
  * Append providers that exist ONLY in provider_config.json — added in the
136
185
  * desktop app after config.json stopped syncing. Credentials come from the
@@ -144,15 +193,7 @@ function appendPersonalOnlyProviders(out, personal, pinned) {
144
193
  continue;
145
194
  if (pinned && pid !== pinned)
146
195
  continue;
147
- const synthesized = {
148
- name: rule.providerName,
149
- enabled: rule.enabled,
150
- options: {
151
- apiKey: rule.config?.access?.apiKey,
152
- baseURL: rule.config?.api?.baseUrl,
153
- },
154
- };
155
- if (!providerSelectable(pid, synthesized))
196
+ if (!providerSelectable(pid, personalRuleEntry(rule)))
156
197
  continue;
157
198
  const providerName = rule.providerName ?? pid;
158
199
  for (const modelId of personal.modelsByProvider.get(pid) ?? []) {
@@ -214,30 +255,7 @@ export function loadAllModels() {
214
255
  for (const [pid, p] of Object.entries(cfg.provider ?? {})) {
215
256
  if (pinned && pid !== pinned)
216
257
  continue;
217
- // Custom providers toggled or updated in the 3.12+ desktop app write
218
- // their new `enabled` / `apiKey` / `baseUrl` / `providerName` only to
219
- // `provider_config.json`, leaving legacy `config.json` frozen at its
220
- // pre-3.12 state. Overlay the personal rule before checking selectability
221
- // so a provider disabled in 3.12+ does not stay selectable via config.json.
222
- const personalRule = !isBuiltinProvider(pid)
223
- ? personal?.providers.find((entry) => entry.pid === pid)?.rule
224
- : undefined;
225
- const effective = p && personalRule
226
- ? {
227
- ...p,
228
- name: personalRule.providerName ?? p.name,
229
- enabled: personalRule.enabled ?? p.enabled,
230
- options: {
231
- ...p.options,
232
- ...(personalRule.config?.access?.apiKey !== undefined
233
- ? { apiKey: personalRule.config.access.apiKey }
234
- : {}),
235
- ...(personalRule.config?.api?.baseUrl !== undefined
236
- ? { baseURL: personalRule.config.api.baseUrl }
237
- : {}),
238
- },
239
- }
240
- : p;
258
+ const effective = effectiveProviderEntry(pid, p, personal);
241
259
  if (!providerSelectable(pid, effective))
242
260
  continue;
243
261
  const providerName = effective?.name ?? pid;
@@ -298,6 +316,66 @@ function entitledOrDefaultModels(pinned) {
298
316
  },
299
317
  ];
300
318
  }
319
+ /**
320
+ * The provider list ACP clients render a provider picker from (#400) —
321
+ * without mirroring `providerSelectable` and the config scan in their own
322
+ * code. Selectable providers come FIRST, derived from the SAME
323
+ * `loadAllModels()` output the model dropdown offers (pass `models` when the
324
+ * caller already holds it), so metadata and dropdown can never disagree —
325
+ * including the ZCODE_PROVIDER pin and entitled coding plans. Unselectable
326
+ * config.json / personal-only entries follow with a reason code, so a client
327
+ * can render "keyless — link account in the desktop app" instead of a
328
+ * silent gap.
329
+ */
330
+ export function providerMetadataList(models = loadAllModels()) {
331
+ const pinned = process.env.ZCODE_PROVIDER;
332
+ const out = [];
333
+ const seen = new Set();
334
+ for (const m of models) {
335
+ if (seen.has(m.providerId))
336
+ continue;
337
+ seen.add(m.providerId);
338
+ out.push({ id: m.providerId, name: m.providerName, selectable: true, defaultModel: m.modelId });
339
+ }
340
+ const personal = loadPersonalModels();
341
+ const appendConfigDialect = (pid, entry, name) => {
342
+ if (seen.has(pid))
343
+ return;
344
+ seen.add(pid);
345
+ const reason = providerUnselectableReason(pid, entry);
346
+ // A "selectable" verdict here means the provider is usable but carries no
347
+ // models (empty models map) — loadAllModels never listed it. Stay honest
348
+ // rather than inventing a reason.
349
+ out.push(reason === null
350
+ ? { id: pid, name, selectable: true }
351
+ : { id: pid, name, selectable: false, unselectableReason: reason });
352
+ };
353
+ try {
354
+ const cfg = readConfig();
355
+ for (const [pid, p] of Object.entries(cfg.provider ?? {})) {
356
+ if (pinned && pid !== pinned)
357
+ continue;
358
+ const effective = effectiveProviderEntry(pid, p, personal);
359
+ appendConfigDialect(pid, effective, effective?.name ?? pid);
360
+ }
361
+ }
362
+ catch {
363
+ // unreadable config.json — the selectable set from loadAllModels stands alone
364
+ }
365
+ for (const { pid, rule } of personal?.providers ?? []) {
366
+ if (pinned && pid !== pinned)
367
+ continue;
368
+ appendConfigDialect(pid, personalRuleEntry(rule), rule.providerName ?? pid);
369
+ }
370
+ return out;
371
+ }
372
+ /** Assemble the `_meta.zcode` payload; the current provider id normalizes to the config dialect. */
373
+ export function buildProviderMeta(currentProviderId, models = loadAllModels()) {
374
+ return {
375
+ providers: providerMetadataList(models),
376
+ currentProviderId: configProviderIdFor(currentProviderId),
377
+ };
378
+ }
301
379
  /** Look up a provider entry by id (any provider, not just enabled).
302
380
  *
303
381
  * 3.12+ registries spell coding-plan providers `account:<family>-<plan>` while
@@ -645,6 +723,11 @@ export async function buildConfigOptions(server, zcodeSid, receiverRoot) {
645
723
  type: "select",
646
724
  currentValue: currentModel,
647
725
  options: modelOptions,
726
+ // Provider metadata for ACP clients (#400). The model option is the
727
+ // refresh vehicle: every rebuild (switch, credential change, config_
728
+ // option_update) re-attaches it, so the provider list stays live for
729
+ // the whole session lifetime. See docs/CONFIG-OPTIONS.md.
730
+ _meta: { zcode: buildProviderMeta(currentProvider, localModels) },
648
731
  },
649
732
  {
650
733
  id: "mode",
@@ -797,12 +880,17 @@ export async function buildInitialConfigOptions(server, receiverRoot, result) {
797
880
  */
798
881
  export async function setConfigOption(server, zcodeSid, configId, value, acpSid) {
799
882
  if (configId === "model") {
800
- const { applyModelSwitch } = await import("./runtime-model.js");
883
+ const { applyModelSwitch, lastSwitchedModelValue } = await import("./runtime-model.js");
801
884
  const ok = await applyModelSwitch(server, zcodeSid, value);
802
885
  if (!ok)
803
886
  return null;
804
- rememberModelChoice(server, acpSid, zcodeSid, { model: value });
805
- return { kind: "model", currentValue: value };
887
+ // Remember the registry-dialect identity the switch LANDED on (#403) —
888
+ // the inbound value may be a stale-dialect ref that only resolved via
889
+ // model-resolution, and the post-resume re-assert replays this record.
890
+ rememberModelChoice(server, acpSid, zcodeSid, {
891
+ model: lastSwitchedModelValue(server, zcodeSid) ?? value,
892
+ });
893
+ return { kind: "model", currentValue: lastSwitchedModelValue(server, zcodeSid) ?? value };
806
894
  }
807
895
  const dispatch = CONFIG_DISPATCH[configId];
808
896
  if (!dispatch)