zcode-acp-server 0.1.0 → 0.2.0
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 +98 -1
- package/README.zh-CN.md +81 -1
- package/dist/backend/client.d.ts +12 -4
- package/dist/backend/client.d.ts.map +1 -1
- package/dist/backend/client.js +72 -7
- package/dist/backend/client.js.map +1 -1
- package/dist/backend/credentials.d.ts.map +1 -1
- package/dist/backend/credentials.js +2 -1
- package/dist/backend/credentials.js.map +1 -1
- package/dist/backend/listener.d.ts +12 -4
- package/dist/backend/listener.d.ts.map +1 -1
- package/dist/backend/listener.js +68 -12
- package/dist/backend/listener.js.map +1 -1
- package/dist/backend/types.d.ts +1 -1
- package/dist/backend/types.d.ts.map +1 -1
- package/dist/bin/quota.d.ts +54 -0
- package/dist/bin/quota.d.ts.map +1 -0
- package/dist/bin/quota.js +333 -0
- package/dist/bin/quota.js.map +1 -0
- package/dist/config/auto-compact.d.ts +23 -0
- package/dist/config/auto-compact.d.ts.map +1 -0
- package/dist/config/auto-compact.js +67 -0
- package/dist/config/auto-compact.js.map +1 -0
- package/dist/config/mcp-discovery.d.ts +34 -0
- package/dist/config/mcp-discovery.d.ts.map +1 -0
- package/dist/config/mcp-discovery.js +153 -0
- package/dist/config/mcp-discovery.js.map +1 -0
- package/dist/config/model-cache.d.ts +12 -1
- package/dist/config/model-cache.d.ts.map +1 -1
- package/dist/config/model-cache.js +30 -8
- package/dist/config/model-cache.js.map +1 -1
- package/dist/config/options.d.ts +87 -9
- package/dist/config/options.d.ts.map +1 -1
- package/dist/config/options.js +248 -45
- package/dist/config/options.js.map +1 -1
- package/dist/config/plugin-commands.d.ts +24 -0
- package/dist/config/plugin-commands.d.ts.map +1 -0
- package/dist/config/plugin-commands.js +107 -0
- package/dist/config/plugin-commands.js.map +1 -0
- package/dist/config/provider-registry.d.ts +60 -0
- package/dist/config/provider-registry.d.ts.map +1 -0
- package/dist/config/provider-registry.js +128 -0
- package/dist/config/provider-registry.js.map +1 -0
- package/dist/config/runtime-model.d.ts +54 -18
- package/dist/config/runtime-model.d.ts.map +1 -1
- package/dist/config/runtime-model.js +105 -61
- package/dist/config/runtime-model.js.map +1 -1
- package/dist/config/skill-discovery.d.ts +35 -0
- package/dist/config/skill-discovery.d.ts.map +1 -0
- package/dist/config/skill-discovery.js +188 -0
- package/dist/config/skill-discovery.js.map +1 -0
- package/dist/handlers/background-tasks.d.ts +72 -0
- package/dist/handlers/background-tasks.d.ts.map +1 -0
- package/dist/handlers/background-tasks.js +330 -0
- package/dist/handlers/background-tasks.js.map +1 -0
- package/dist/handlers/dispatch.d.ts.map +1 -1
- package/dist/handlers/dispatch.js +134 -22
- package/dist/handlers/dispatch.js.map +1 -1
- package/dist/handlers/extensions.d.ts +15 -0
- package/dist/handlers/extensions.d.ts.map +1 -1
- package/dist/handlers/extensions.js +43 -27
- package/dist/handlers/extensions.js.map +1 -1
- package/dist/handlers/io.d.ts +11 -2
- package/dist/handlers/io.d.ts.map +1 -1
- package/dist/handlers/io.js +51 -7
- package/dist/handlers/io.js.map +1 -1
- package/dist/handlers/server-requests.d.ts +20 -4
- package/dist/handlers/server-requests.d.ts.map +1 -1
- package/dist/handlers/server-requests.js +293 -63
- package/dist/handlers/server-requests.js.map +1 -1
- package/dist/handlers/session.d.ts +113 -10
- package/dist/handlers/session.d.ts.map +1 -1
- package/dist/handlers/session.js +876 -220
- package/dist/handlers/session.js.map +1 -1
- package/dist/handlers/slash.d.ts +14 -0
- package/dist/handlers/slash.d.ts.map +1 -1
- package/dist/handlers/slash.js +80 -6
- package/dist/handlers/slash.js.map +1 -1
- package/dist/index.js +38 -4
- package/dist/index.js.map +1 -1
- package/dist/interaction/adapter.d.ts +19 -33
- package/dist/interaction/adapter.d.ts.map +1 -1
- package/dist/interaction/adapter.js +80 -79
- package/dist/interaction/adapter.js.map +1 -1
- package/dist/lazy-sessions.d.ts +35 -0
- package/dist/lazy-sessions.d.ts.map +1 -0
- package/dist/lazy-sessions.js +98 -0
- package/dist/lazy-sessions.js.map +1 -0
- package/dist/quota/cache.d.ts +18 -0
- package/dist/quota/cache.d.ts.map +1 -0
- package/dist/quota/cache.js +32 -0
- package/dist/quota/cache.js.map +1 -0
- package/dist/quota/client.d.ts +30 -0
- package/dist/quota/client.d.ts.map +1 -0
- package/dist/quota/client.js +57 -0
- package/dist/quota/client.js.map +1 -0
- package/dist/quota/color.d.ts +58 -0
- package/dist/quota/color.d.ts.map +1 -0
- package/dist/quota/color.js +95 -0
- package/dist/quota/color.js.map +1 -0
- package/dist/quota/combined.d.ts +66 -0
- package/dist/quota/combined.d.ts.map +1 -0
- package/dist/quota/combined.js +179 -0
- package/dist/quota/combined.js.map +1 -0
- package/dist/quota/format.d.ts +105 -0
- package/dist/quota/format.d.ts.map +1 -0
- package/dist/quota/format.js +219 -0
- package/dist/quota/format.js.map +1 -0
- package/dist/quota/index.d.ts +23 -0
- package/dist/quota/index.d.ts.map +1 -0
- package/dist/quota/index.js +42 -0
- package/dist/quota/index.js.map +1 -0
- package/dist/quota/opencode-go/cache.d.ts +17 -0
- package/dist/quota/opencode-go/cache.d.ts.map +1 -0
- package/dist/quota/opencode-go/cache.js +31 -0
- package/dist/quota/opencode-go/cache.js.map +1 -0
- package/dist/quota/opencode-go/client.d.ts +28 -0
- package/dist/quota/opencode-go/client.d.ts.map +1 -0
- package/dist/quota/opencode-go/client.js +48 -0
- package/dist/quota/opencode-go/client.js.map +1 -0
- package/dist/quota/opencode-go/config.d.ts +37 -0
- package/dist/quota/opencode-go/config.d.ts.map +1 -0
- package/dist/quota/opencode-go/config.js +58 -0
- package/dist/quota/opencode-go/config.js.map +1 -0
- package/dist/quota/opencode-go/format.d.ts +36 -0
- package/dist/quota/opencode-go/format.d.ts.map +1 -0
- package/dist/quota/opencode-go/format.js +87 -0
- package/dist/quota/opencode-go/format.js.map +1 -0
- package/dist/quota/opencode-go/index.d.ts +30 -0
- package/dist/quota/opencode-go/index.d.ts.map +1 -0
- package/dist/quota/opencode-go/index.js +108 -0
- package/dist/quota/opencode-go/index.js.map +1 -0
- package/dist/quota/opencode-go/parse.d.ts +41 -0
- package/dist/quota/opencode-go/parse.d.ts.map +1 -0
- package/dist/quota/opencode-go/parse.js +75 -0
- package/dist/quota/opencode-go/parse.js.map +1 -0
- package/dist/quota/opencode-go/types.d.ts +48 -0
- package/dist/quota/opencode-go/types.d.ts.map +1 -0
- package/dist/quota/opencode-go/types.js +11 -0
- package/dist/quota/opencode-go/types.js.map +1 -0
- package/dist/quota/parse.d.ts +33 -0
- package/dist/quota/parse.d.ts.map +1 -0
- package/dist/quota/parse.js +200 -0
- package/dist/quota/parse.js.map +1 -0
- package/dist/quota/types.d.ts +72 -0
- package/dist/quota/types.d.ts.map +1 -0
- package/dist/quota/types.js +10 -0
- package/dist/quota/types.js.map +1 -0
- package/dist/server.d.ts +104 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +119 -2
- package/dist/server.js.map +1 -1
- package/dist/tasks-index.d.ts +14 -4
- package/dist/tasks-index.d.ts.map +1 -1
- package/dist/tasks-index.js +145 -46
- package/dist/tasks-index.js.map +1 -1
- package/dist/translators/event-translator.d.ts +33 -0
- package/dist/translators/event-translator.d.ts.map +1 -1
- package/dist/translators/event-translator.js +101 -0
- package/dist/translators/event-translator.js.map +1 -1
- package/dist/translators/index.d.ts +1 -1
- package/dist/translators/index.d.ts.map +1 -1
- package/dist/translators/index.js +1 -1
- package/dist/translators/index.js.map +1 -1
- package/dist/translators/projection-differ.d.ts +8 -0
- package/dist/translators/projection-differ.d.ts.map +1 -1
- package/dist/translators/projection-differ.js +19 -9
- package/dist/translators/projection-differ.js.map +1 -1
- package/dist/translators/tool-helpers.d.ts +28 -0
- package/dist/translators/tool-helpers.d.ts.map +1 -1
- package/dist/translators/tool-helpers.js +104 -0
- package/dist/translators/tool-helpers.js.map +1 -1
- package/dist/translators/types.d.ts +38 -1
- package/dist/translators/types.d.ts.map +1 -1
- package/dist/translators/types.js.map +1 -1
- package/dist/utils.d.ts +35 -6
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +52 -4
- package/dist/utils.js.map +1 -1
- package/docs/ARCHITECTURE.md +96 -38
- package/docs/BACKLOG.md +57 -0
- package/docs/DEVELOPMENT.md +5 -0
- package/docs/PROTOCOL.md +270 -5
- package/docs/TROUBLESHOOTING.md +98 -14
- package/docs/agents/domain.md +51 -0
- package/docs/agents/issue-tracker.md +22 -0
- package/docs/agents/triage-labels.md +15 -0
- package/package.json +6 -5
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP server discovery — reads MCP server configurations from the same sources
|
|
3
|
+
* ZCode uses, so `/mcp` can show users exactly which servers are available.
|
|
4
|
+
*
|
|
5
|
+
* Sources:
|
|
6
|
+
* 1. ~/.zcode/cli/config.json → mcp.servers (user-configured)
|
|
7
|
+
* 2. Enabled plugin .mcp.json files (two formats: flat and nested)
|
|
8
|
+
*
|
|
9
|
+
* The ZCode backend loads these automatically and exposes their tools to the
|
|
10
|
+
* model. This module is purely informational — it lists what's configured so
|
|
11
|
+
* users know what's available without needing the TUI.
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
import { compareVersions, log } from "../utils.js";
|
|
17
|
+
const HOME = homedir();
|
|
18
|
+
const CLI_CONFIG_PATH = path.join(HOME, ".zcode", "cli", "config.json");
|
|
19
|
+
const PLUGIN_CACHE_DIR = path.join(HOME, ".zcode", "cli", "plugins", "cache");
|
|
20
|
+
/**
|
|
21
|
+
* Discover all MCP servers from config.json and enabled plugins.
|
|
22
|
+
*
|
|
23
|
+
* Best-effort: failures are logged and swallowed.
|
|
24
|
+
*/
|
|
25
|
+
export function loadMcpServers() {
|
|
26
|
+
const results = [];
|
|
27
|
+
let config = null;
|
|
28
|
+
try {
|
|
29
|
+
if (existsSync(CLI_CONFIG_PATH)) {
|
|
30
|
+
config = JSON.parse(readFileSync(CLI_CONFIG_PATH, "utf8"));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
log(`mcp-discovery: config read failed (${e instanceof Error ? e.message : String(e)})`);
|
|
35
|
+
return results;
|
|
36
|
+
}
|
|
37
|
+
// 1. User-configured servers from config.json.
|
|
38
|
+
const servers = config?.mcp?.servers ?? {};
|
|
39
|
+
for (const [name, cfg] of Object.entries(servers)) {
|
|
40
|
+
results.push({
|
|
41
|
+
name,
|
|
42
|
+
type: cfg.type ?? "stdio",
|
|
43
|
+
command: cfg.command,
|
|
44
|
+
args: cfg.args,
|
|
45
|
+
url: cfg.url,
|
|
46
|
+
source: "config",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// 2. Plugin-provided servers from .mcp.json files.
|
|
50
|
+
const enabledPlugins = config?.plugins?.enabledPlugins ?? {};
|
|
51
|
+
for (const [pluginKey, enabledFlag] of Object.entries(enabledPlugins)) {
|
|
52
|
+
if (!enabledFlag)
|
|
53
|
+
continue;
|
|
54
|
+
const atIdx = pluginKey.indexOf("@");
|
|
55
|
+
if (atIdx <= 0)
|
|
56
|
+
continue;
|
|
57
|
+
const pluginName = pluginKey.slice(0, atIdx);
|
|
58
|
+
const marketplace = pluginKey.slice(atIdx + 1);
|
|
59
|
+
const pluginDir = path.join(PLUGIN_CACHE_DIR, marketplace, pluginName);
|
|
60
|
+
if (!existsSync(pluginDir))
|
|
61
|
+
continue;
|
|
62
|
+
// Find the latest version directory.
|
|
63
|
+
let latestVersion = "";
|
|
64
|
+
try {
|
|
65
|
+
for (const entry of readdirSync(pluginDir)) {
|
|
66
|
+
const vDir = path.join(pluginDir, entry);
|
|
67
|
+
if (statSync(vDir).isDirectory() && compareVersions(entry, latestVersion) > 0) {
|
|
68
|
+
latestVersion = entry;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!latestVersion)
|
|
76
|
+
continue;
|
|
77
|
+
const mcpFile = path.join(pluginDir, latestVersion, ".mcp.json");
|
|
78
|
+
if (!existsSync(mcpFile))
|
|
79
|
+
continue;
|
|
80
|
+
try {
|
|
81
|
+
const mcpConfig = JSON.parse(readFileSync(mcpFile, "utf8"));
|
|
82
|
+
// Two formats:
|
|
83
|
+
// Flat: { "server-name": { "command": "..." } }
|
|
84
|
+
// Nested: { "mcpServers": { "server-name": { ... } } }
|
|
85
|
+
const serverMap = mcpConfig["mcpServers"] ?? mcpConfig;
|
|
86
|
+
for (const [name, cfg] of Object.entries(serverMap)) {
|
|
87
|
+
results.push({
|
|
88
|
+
name,
|
|
89
|
+
type: cfg.type ?? "stdio",
|
|
90
|
+
command: cfg.command,
|
|
91
|
+
args: cfg.args,
|
|
92
|
+
url: cfg.url,
|
|
93
|
+
source: `plugin: ${pluginName}`,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
log(`mcp-discovery: failed to read ${mcpFile} (${e instanceof Error ? e.message : String(e)})`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
log(`mcp-discovery: found ${results.length} MCP server(s)`);
|
|
102
|
+
return results;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Format MCP servers into a human-readable card for the `/mcp` command.
|
|
106
|
+
*
|
|
107
|
+
* Groups by source (config vs plugins) and aligns columns for readability.
|
|
108
|
+
*/
|
|
109
|
+
export function formatMcpServers(servers) {
|
|
110
|
+
if (servers.length === 0) {
|
|
111
|
+
return "📡 No MCP servers configured.\nUse the ZCode desktop app to add MCP servers.";
|
|
112
|
+
}
|
|
113
|
+
const configServers = servers.filter((s) => s.source === "config");
|
|
114
|
+
const pluginServers = servers.filter((s) => s.source !== "config");
|
|
115
|
+
const lines = [`📡 MCP Servers (${servers.length})`];
|
|
116
|
+
if (configServers.length > 0) {
|
|
117
|
+
lines.push("", "From config.json:");
|
|
118
|
+
for (const s of configServers) {
|
|
119
|
+
lines.push(` ${pad(s.name, 16)} ${pad(s.type, 6)} ${formatEndpoint(s)}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (pluginServers.length > 0) {
|
|
123
|
+
lines.push("", "From plugins:");
|
|
124
|
+
for (const s of pluginServers) {
|
|
125
|
+
const pluginLabel = `[${s.source.replace("plugin: ", "")}]`;
|
|
126
|
+
lines.push(` ${pad(s.name, 16)} ${pad(s.type, 6)} ${formatEndpoint(s)} ${pluginLabel}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
lines.push("", "MCP tools are auto-invoked by the model when needed.");
|
|
130
|
+
return lines.join("\n");
|
|
131
|
+
}
|
|
132
|
+
/** Format the endpoint/command string for display. */
|
|
133
|
+
function formatEndpoint(s) {
|
|
134
|
+
if (s.url) {
|
|
135
|
+
try {
|
|
136
|
+
const u = new URL(s.url);
|
|
137
|
+
return u.host + u.pathname;
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return s.url;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (s.command) {
|
|
144
|
+
const args = s.args?.length ? " " + s.args.join(" ") : "";
|
|
145
|
+
return s.command + args;
|
|
146
|
+
}
|
|
147
|
+
return "?";
|
|
148
|
+
}
|
|
149
|
+
/** Pad a string to the given width for column alignment. */
|
|
150
|
+
function pad(s, width) {
|
|
151
|
+
return s.length >= width ? s : s + " ".repeat(width - s.length);
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=mcp-discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-discovery.js","sourceRoot":"","sources":["../../src/config/mcp-discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAA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,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,sDAAsD;AACtD,SAAS,cAAc,CAAC,CAAgB;IACtC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC;QACV,IAAI,CAAC;YACH,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACzB,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,CAAC,GAAG,CAAC;QACf,CAAC;IACH,CAAC;IACD,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;QACd,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1D,OAAO,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC;IAC1B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,4DAA4D;AAC5D,SAAS,GAAG,CAAC,CAAS,EAAE,KAAa;IACnC,OAAO,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -9,12 +9,23 @@
|
|
|
9
9
|
import type * as acp from "@agentclientprotocol/sdk";
|
|
10
10
|
import type { ZcodeAcpServer } from "../server.js";
|
|
11
11
|
import type { ProjectionDiffer } from "../translators/projection-differ.js";
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Read the session's current model as an encoded `"providerId\modelId"` string,
|
|
14
|
+
* with a per-session cache. Returns the encoded form so callers can resolve the
|
|
15
|
+
* provider (for context-window lookup / model switching) without a second read.
|
|
16
|
+
*/
|
|
13
17
|
export declare function currentModelCached(server: ZcodeAcpServer, zcodeSid: string): Promise<string>;
|
|
14
18
|
/**
|
|
15
19
|
* Emit an initial usage_update after resume/load so the editor shows the
|
|
16
20
|
* context bar. Skips when there's no token data (resume before any turn → 0).
|
|
17
21
|
* Also syncs the differ's usage baseline so the first turn won't re-emit it.
|
|
22
|
+
*
|
|
23
|
+
* Note: the backend's `projection.contextUsed` is 0 after resume — it only
|
|
24
|
+
* updates after a new turn completes. So a resumed session with history won't
|
|
25
|
+
* show a context bar until the first post-resume message. That's acceptable:
|
|
26
|
+
* we don't have a reliable way to estimate the pre-resume context size, and
|
|
27
|
+
* guessing wrong (e.g. from per-turn token totals that include re-sent history)
|
|
28
|
+
* is worse than showing nothing.
|
|
18
29
|
*/
|
|
19
30
|
export declare function emitInitialUsage(server: ZcodeAcpServer, cx: acp.AgentContext, acpSid: string, zcodeSid: string, differ: ProjectionDiffer | undefined): Promise<void>;
|
|
20
31
|
//# sourceMappingURL=model-cache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-cache.d.ts","sourceRoot":"","sources":["../../src/config/model-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,GAAG,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"model-cache.d.ts","sourceRoot":"","sources":["../../src/config/model-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,GAAG,MAAM,0BAA0B,CAAC;AAYrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAE5E;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAsBjB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,cAAc,EACtB,EAAE,EAAE,GAAG,CAAC,YAAY,EACpB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,gBAAgB,GAAG,SAAS,GACnC,OAAO,CAAC,IAAI,CAAC,CA4Bf"}
|
|
@@ -6,32 +6,52 @@
|
|
|
6
6
|
* after resume/load so the editor shows the context bar immediately (only when
|
|
7
7
|
* there's actual token data — resume before any turn has 0, which we skip).
|
|
8
8
|
*/
|
|
9
|
-
import { modelContextWindow } from "./options.js";
|
|
9
|
+
import { DEFAULT_MODEL_ID, DEFAULT_PROVIDER_ID, formatModelValue, loadAllModels, modelContextWindow, parseModelValue, } from "./options.js";
|
|
10
10
|
import { log } from "../utils.js";
|
|
11
11
|
import { dispatchEvent } from "../handlers/dispatch.js";
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Read the session's current model as an encoded `"providerId\modelId"` string,
|
|
14
|
+
* with a per-session cache. Returns the encoded form so callers can resolve the
|
|
15
|
+
* provider (for context-window lookup / model switching) without a second read.
|
|
16
|
+
*/
|
|
13
17
|
export async function currentModelCached(server, zcodeSid) {
|
|
14
18
|
const cached = server.modelCache.get(zcodeSid);
|
|
15
19
|
if (cached)
|
|
16
20
|
return cached;
|
|
17
|
-
let
|
|
21
|
+
let providerId = "";
|
|
22
|
+
let modelId = DEFAULT_MODEL_ID;
|
|
18
23
|
try {
|
|
19
24
|
const read = await sessionRead(server, zcodeSid);
|
|
20
25
|
const settings = (read.settings ?? {});
|
|
21
|
-
const cur = settings.model
|
|
26
|
+
const cur = settings.model
|
|
27
|
+
?.current;
|
|
28
|
+
if (cur?.providerId)
|
|
29
|
+
providerId = cur.providerId;
|
|
22
30
|
if (cur?.modelId)
|
|
23
31
|
modelId = cur.modelId;
|
|
24
32
|
}
|
|
25
33
|
catch (e) {
|
|
26
34
|
log(`model-cache: session/read failed (${e instanceof Error ? e.message : String(e)})`);
|
|
27
35
|
}
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
if (!providerId) {
|
|
37
|
+
// Legacy session without a providerId — resolve to the first enabled provider.
|
|
38
|
+
providerId = loadAllModels()[0]?.providerId ?? DEFAULT_PROVIDER_ID;
|
|
39
|
+
}
|
|
40
|
+
const encoded = formatModelValue(providerId, modelId);
|
|
41
|
+
server.modelCache.set(zcodeSid, encoded);
|
|
42
|
+
return encoded;
|
|
30
43
|
}
|
|
31
44
|
/**
|
|
32
45
|
* Emit an initial usage_update after resume/load so the editor shows the
|
|
33
46
|
* context bar. Skips when there's no token data (resume before any turn → 0).
|
|
34
47
|
* Also syncs the differ's usage baseline so the first turn won't re-emit it.
|
|
48
|
+
*
|
|
49
|
+
* Note: the backend's `projection.contextUsed` is 0 after resume — it only
|
|
50
|
+
* updates after a new turn completes. So a resumed session with history won't
|
|
51
|
+
* show a context bar until the first post-resume message. That's acceptable:
|
|
52
|
+
* we don't have a reliable way to estimate the pre-resume context size, and
|
|
53
|
+
* guessing wrong (e.g. from per-turn token totals that include re-sent history)
|
|
54
|
+
* is worse than showing nothing.
|
|
35
55
|
*/
|
|
36
56
|
export async function emitInitialUsage(server, cx, acpSid, zcodeSid, differ) {
|
|
37
57
|
try {
|
|
@@ -43,8 +63,10 @@ export async function emitInitialUsage(server, cx, acpSid, zcodeSid, differ) {
|
|
|
43
63
|
if (!used)
|
|
44
64
|
return; // resume before any turn: skip to avoid showing 0.
|
|
45
65
|
let size = proj.contextWindow ?? 0;
|
|
46
|
-
if (!size)
|
|
47
|
-
|
|
66
|
+
if (!size) {
|
|
67
|
+
const { providerId, modelId } = parseModelValue(await currentModelCached(server, zcodeSid));
|
|
68
|
+
size = modelContextWindow(providerId, modelId);
|
|
69
|
+
}
|
|
48
70
|
await dispatchEvent(server, cx, acpSid, { kind: "UsageDelta", used, size }, `init_${zcodeSid.slice(0, 8)}`);
|
|
49
71
|
differ?.setLastUsage(used);
|
|
50
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-cache.js","sourceRoot":"","sources":["../../src/config/model-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,
|
|
1
|
+
{"version":3,"file":"model-cache.js","sourceRoot":"","sources":["../../src/config/model-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAsB,EACtB,QAAgB;IAEhB,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAC1B,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,IAAI,OAAO,GAAG,gBAAgB,CAAC;IAC/B,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACjD,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAA4B,CAAC;QAClE,MAAM,GAAG,GAAI,QAAQ,CAAC,KAAiE;YACrF,EAAE,OAAO,CAAC;QACZ,IAAI,GAAG,EAAE,UAAU;YAAE,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC;QACjD,IAAI,GAAG,EAAE,OAAO;YAAE,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;IAC1C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,GAAG,CAAC,qCAAqC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,C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AC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAC/B,CAAC;QACF,MAAM,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,GAAG,CAAC,2CAA2C,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAChG,CAAC;AACH,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,MAAsB,EAAE,QAAgB;IACjE,MAAM,OAAO,GAAG,MAAM,CAAC,aAAa,EAAE,CAAC;IACvC,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAChC,MAAM,CAAC,MAAM,EAAE,EACf,cAAc,EACd,EAAE,SAAS,EAAE,QAAQ,EAAE,EACvB,IAAI,CACL,CAAC;IACF,IAAI,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACpD,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAoB,CAAC;AAChD,CAAC"}
|
package/dist/config/options.d.ts
CHANGED
|
@@ -11,14 +11,87 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import type * as acp from "@agentclientprotocol/sdk";
|
|
13
13
|
import type { ZcodeAcpServer } from "../server.js";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
interface ProviderModelsJson {
|
|
15
|
+
[modelId: string]: {
|
|
16
|
+
limit?: {
|
|
17
|
+
context?: number;
|
|
18
|
+
};
|
|
19
|
+
} | undefined;
|
|
20
|
+
}
|
|
21
|
+
/** A single provider's entry in config.json (`provider.<providerId>`). */
|
|
22
|
+
interface ProviderEntry {
|
|
23
|
+
name?: string;
|
|
24
|
+
kind?: string;
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
options?: {
|
|
27
|
+
baseURL?: string;
|
|
28
|
+
apiKey?: string;
|
|
29
|
+
};
|
|
30
|
+
models?: ProviderModelsJson;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Fallback defaults for when config.json is unreadable or has no enabled
|
|
34
|
+
* provider — keeps a freshly-installed editor functional. Must stay in sync
|
|
35
|
+
* with the model the app ships first in its provider list.
|
|
36
|
+
*/
|
|
37
|
+
export declare const DEFAULT_PROVIDER_ID = "builtin:bigmodel-coding-plan";
|
|
38
|
+
export declare const DEFAULT_PROVIDER_NAME = "BigModel";
|
|
39
|
+
export declare const DEFAULT_MODEL_ID = "GLM-5.3";
|
|
40
|
+
/** A model selectable in the dropdown, with its owning provider. */
|
|
41
|
+
export interface ModelRef {
|
|
42
|
+
providerId: string;
|
|
43
|
+
providerName: string;
|
|
44
|
+
modelId: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Collect models from config.json for the dropdown.
|
|
48
|
+
*
|
|
49
|
+
* Builtin providers (id prefix `builtin:`) must be `enabled: true` — they
|
|
50
|
+
* reflect the plans the user activated in the ZCode desktop app. Custom
|
|
51
|
+
* (third-party) providers are included UNLESS explicitly `enabled: false`:
|
|
52
|
+
* the newer CLI leaves the flag unset on active third-party providers, so
|
|
53
|
+
* treating "absent" as enabled keeps them in the dropdown while still
|
|
54
|
+
* honoring an explicit disable.
|
|
55
|
+
*/
|
|
56
|
+
export declare function loadAllModels(): ModelRef[];
|
|
57
|
+
/** Look up a provider entry by id (any provider, not just enabled). */
|
|
58
|
+
export declare function findProviderConfig(providerId: string): ProviderEntry | null;
|
|
59
|
+
/** Read the context-window size for a provider+model from config.json. */
|
|
60
|
+
export declare function modelContextWindow(providerId: string, modelId: string): number;
|
|
61
|
+
/** Builtin providerIds are prefixed with `builtin:` (e.g. `builtin:bigmodel`). */
|
|
62
|
+
export declare function isBuiltinProvider(providerId: string): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Encode a provider+model pair into a configOption `value` string.
|
|
65
|
+
*
|
|
66
|
+
* Builtin providers encode as the bare modelId (legacy form, keeps the dropdown
|
|
67
|
+
* clean for the common case). Third-party providers encode as
|
|
68
|
+
* `providerId\modelId` — `\` is unambiguous because providerIds (UUIDs) and
|
|
69
|
+
* modelIds (`/`-separated) never contain it.
|
|
70
|
+
*/
|
|
71
|
+
export declare function formatModelValue(providerId: string, modelId: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Parse a configOption `value` back into { providerId, modelId }.
|
|
74
|
+
*
|
|
75
|
+
* A value without `\` is a builtin modelId (legacy form) → resolve to the first
|
|
76
|
+
* enabled builtin provider. A value with `\` is a third-party provider+model.
|
|
77
|
+
*/
|
|
78
|
+
export declare function parseModelValue(value: string): {
|
|
79
|
+
providerId: string;
|
|
80
|
+
modelId: string;
|
|
81
|
+
};
|
|
82
|
+
/** Build the ACP SessionModeState ({currentModeId, availableModes}).
|
|
83
|
+
* zcodeSid null = pending session (session/new not yet materialized) — skip
|
|
84
|
+
* the backend read and return defaults. */
|
|
85
|
+
export declare function buildModes(server: ZcodeAcpServer, zcodeSid: string | null): Promise<acp.SessionModeState>;
|
|
86
|
+
export declare function orderThoughtVariants(variants: string[]): Array<{
|
|
87
|
+
value: string;
|
|
88
|
+
name: string;
|
|
89
|
+
}>;
|
|
90
|
+
/** Build the ACP configOptions array (3 items: model/mode/thought).
|
|
91
|
+
* zcodeSid null = pending session — skip the backend read and use defaults;
|
|
92
|
+
* mode defaults to "yolo" (the mode session/create hardcodes) so the dropdown
|
|
93
|
+
* matches the mode indicator for a fresh session. */
|
|
94
|
+
export declare function buildConfigOptions(server: ZcodeAcpServer, zcodeSid: string | null): Promise<acp.SessionConfigOption[]>;
|
|
22
95
|
/**
|
|
23
96
|
* Dispatch session/set_config_option. mode/thought forward to setMode/
|
|
24
97
|
* setThoughtLevel; model routes through applyModelSwitch (runtime-model.ts).
|
|
@@ -31,6 +104,11 @@ export declare function setConfigOption(server: ZcodeAcpServer, zcodeSid: string
|
|
|
31
104
|
currentValue: string;
|
|
32
105
|
} | null>;
|
|
33
106
|
/** Emit a config_option_update (+ current_mode_update for mode) after a change.
|
|
34
|
-
* Returns the rebuilt options so the caller can include them in the response.
|
|
107
|
+
* Returns the rebuilt options so the caller can include them in the response.
|
|
108
|
+
*
|
|
109
|
+
* For model switches, also emit a usage_update with the NEW model's context
|
|
110
|
+
* window (from config.json) so the editor's context bar refreshes immediately
|
|
111
|
+
* instead of waiting for the next turn's UsageDelta. */
|
|
35
112
|
export declare function emitConfigOptionUpdate(server: ZcodeAcpServer, cx: acp.AgentContext, acpSid: string, zcodeSid: string, kind: "model" | "mode" | "thought"): Promise<acp.SessionConfigOption[]>;
|
|
113
|
+
export {};
|
|
36
114
|
//# sourceMappingURL=options.d.ts.map
|
|
@@ -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;AAIrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
|
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;AAIrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnD,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,CAA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