glm-acp-agent 1.1.3 → 1.1.4

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.
Files changed (36) hide show
  1. package/README.md +102 -47
  2. package/dist/llm/glm-client.d.ts +11 -0
  3. package/dist/llm/glm-client.d.ts.map +1 -1
  4. package/dist/llm/glm-client.js +32 -0
  5. package/dist/llm/glm-client.js.map +1 -1
  6. package/dist/protocol/agent.d.ts +9 -2
  7. package/dist/protocol/agent.d.ts.map +1 -1
  8. package/dist/protocol/agent.js +343 -49
  9. package/dist/protocol/agent.js.map +1 -1
  10. package/dist/protocol/image-preprocessor.js +1 -1
  11. package/dist/protocol/image-preprocessor.js.map +1 -1
  12. package/dist/protocol/session-store.d.ts +7 -1
  13. package/dist/protocol/session-store.d.ts.map +1 -1
  14. package/dist/protocol/session-store.js +16 -6
  15. package/dist/protocol/session-store.js.map +1 -1
  16. package/dist/protocol/system-prompt.d.ts.map +1 -1
  17. package/dist/protocol/system-prompt.js +1 -3
  18. package/dist/protocol/system-prompt.js.map +1 -1
  19. package/dist/tests/agent.test.js +220 -4
  20. package/dist/tests/agent.test.js.map +1 -1
  21. package/dist/tests/executor.test.js +69 -2
  22. package/dist/tests/executor.test.js.map +1 -1
  23. package/dist/tests/glm-client.test.js +23 -1
  24. package/dist/tests/glm-client.test.js.map +1 -1
  25. package/dist/tests/integration.test.js +50 -0
  26. package/dist/tests/integration.test.js.map +1 -1
  27. package/dist/tools/executor.d.ts +10 -1
  28. package/dist/tools/executor.d.ts.map +1 -1
  29. package/dist/tools/executor.js +77 -53
  30. package/dist/tools/executor.js.map +1 -1
  31. package/dist/tools/session-mcp-client.js +3 -1
  32. package/dist/tools/session-mcp-client.js.map +1 -1
  33. package/dist/tools/vision-mcp-client.d.ts.map +1 -1
  34. package/dist/tools/vision-mcp-client.js +6 -2
  35. package/dist/tools/vision-mcp-client.js.map +1 -1
  36. package/package.json +7 -3
package/README.md CHANGED
@@ -28,12 +28,13 @@ Built-in web tools use Coding Plan-compatible MCP endpoints, not the general `/a
28
28
  - **Streaming** – assistant text and reasoning tokens are forwarded as incremental ACP chunks
29
29
  - **Tool calling** – agentic loop with up to 20 turns of GLM function calling
30
30
  - **Thinking mode** – GLM's `reasoning_content` tokens are surfaced as `agent_thought_chunk` blocks so the client can show the model's chain of thought
31
+ - **Session permission modes** – supports `default`, `accept_edits`, and `bypass_permissions` via `session/set_mode`. Clients like DevFlow can use this to toggle between prompting for every edit, auto-approving edits while prompting for commands, or bypassing permissions entirely.
31
32
  - **Per-session model switching** – `session/set_model` lets clients change the active GLM model mid-conversation; `session/new` returns the curated `availableModels` list
32
- - **Image input via Coding Plan Vision MCP** – `promptCapabilities.image` is advertised; pasted ACP image blocks are routed through Z.AI Vision MCP (`@z_ai/mcp-server`) and the resulting analysis is fed into the main coding model. Direct chat-image (e.g. `glm-4v-plus`) calls are intentionally not used.
33
+ - **Image input via Coding Plan-native vision or Vision MCP** – `promptCapabilities.image` is advertised; `glm-5v-turbo` sessions send supported image parts directly to the model, while non-native coding models route pasted ACP image blocks through Z.AI Vision MCP (`@z_ai/mcp-server`). Direct chat-image-only models (e.g. `glm-4v-plus`) are intentionally not used.
33
34
  - **Session persistence** – conversations are written to `~/.local/state/glm-acp-agent/sessions/` and can be reloaded via `session/load`, branched via `session/fork`, or resumed without replay via `session/resume`
34
35
  - **Six built-in tools** (see below)
35
36
  - **Self-sufficient local tools** – file reads/writes, directory listings, and shell commands run in the agent process, so they do not depend on ACP client `fs` or `terminal` capabilities
36
- - **Permissioned writes / commands** – every `write_file` and `run_command` call asks the user via `session/request_permission` before doing anything
37
+ - **Configurable permissions** – `write_file` and `run_command` behavior depends on the active session mode (prompts by default)
37
38
  - **Protocol-correct stop reasons** – maps model and runtime conditions to ACP `end_turn`, `max_tokens`, `max_turn_requests`, `refusal`, and `cancelled`
38
39
  - **Protocol-correct tool statuses** – `pending` → `in_progress` → `completed` / `failed`
39
40
  - **Token usage reporting** – aggregated usage is returned on the `session/prompt` response
@@ -65,15 +66,27 @@ The agent process needs network access to `api.z.ai` for chat completions and We
65
66
 
66
67
  ## Available Tools
67
68
 
68
- | Tool | Runs on | Requires client capability | Description |
69
- |------|---------|----------------------------|-------------|
70
- | `read_file` | Agent process | – | Read the text content of a file |
71
- | `write_file` | Agent process | ACP permission prompt | Write or overwrite a text file (asks for permission) |
72
- | `list_files` | Agent process | – | List a directory using Node filesystem APIs |
73
- | `run_command` | Agent process | ACP permission prompt | Run an arbitrary shell command via `sh -c` in the session cwd (asks for permission) |
74
- | `web_search` | Agent (Z.AI Coding Plan MCP) | – | Search the web — returns titles, URLs, and summaries |
75
- | `web_reader` | Agent (Z.AI Coding Plan MCP) | – | Fetch and parse a web page (markdown or plain text) |
76
- | `image_analysis` | Agent (Z.AI Vision MCP, stdio) | – | Analyze a local image path or remote URL using `@z_ai/mcp-server` |
69
+ | Tool | Runs on | Permission behavior | Description |
70
+ |------|---------|---------------------|-------------|
71
+ | `read_file` | Agent process | Always silent | Read the text content of a file |
72
+ | `write_file` | Agent process | Mode-dependent | Write or overwrite a text file. Silent in `accept_edits` and `bypass_permissions`. |
73
+ | `list_files` | Agent process | Always silent | List a directory using Node filesystem APIs |
74
+ | `run_command` | Agent process | Mode-dependent | Run an arbitrary shell command. Silent only in `bypass_permissions`. |
75
+ | `web_search` | Agent (Z.AI Coding Plan MCP) | Always silent | Search the web — returns titles, URLs, and summaries |
76
+ | `web_reader` | Agent (Z.AI Coding Plan MCP) | Always silent | Fetch and parse a web page (markdown or plain text) |
77
+ | `image_analysis` | Agent (Z.AI Vision MCP, stdio) | Always silent | Analyze a local image path or remote URL using `@z_ai/mcp-server` |
78
+
79
+ ### Session Modes
80
+
81
+ Clients can use `session/set_mode` to drive the permission policy:
82
+
83
+ | Mode ID | Name | `write_file` | `run_command` |
84
+ |---|---|---|---|
85
+ | `default` | Ask for permission | **Prompt** | **Prompt** |
86
+ | `accept_edits` | Auto-approve edits | Silent | **Prompt** |
87
+ | `bypass_permissions` | Bypass all permissions | Silent | Silent |
88
+
89
+ Reads, listings, and MCP tool calls are always silent across all modes.
77
90
 
78
91
  ---
79
92
 
@@ -87,6 +100,27 @@ The agent process needs network access to `api.z.ai` for chat completions and We
87
100
 
88
101
  ## Installation
89
102
 
103
+ ### Quick Start
104
+
105
+ Install the published package globally to get the `glm-acp-agent` command on your `PATH`:
106
+
107
+ ```bash
108
+ npm install -g glm-acp-agent@latest
109
+ ```
110
+
111
+ Then either export your Z.AI API key and run it directly:
112
+
113
+ ```bash
114
+ export Z_AI_API_KEY=your_key_here
115
+ glm-acp-agent
116
+ ```
117
+
118
+ …or run the interactive setup once to persist the key to disk (see [One-time setup](#one-time-setup)) and point any ACP-compatible client at the `glm-acp-agent` command.
119
+
120
+ ### From Source (Development)
121
+
122
+ Clone the repository if you want to hack on the agent or pin a specific commit:
123
+
90
124
  ```bash
91
125
  git clone https://github.com/stefandevo/glm-acp-agent.git
92
126
  cd glm-acp-agent
@@ -94,6 +128,8 @@ npm install
94
128
  npm run build
95
129
  ```
96
130
 
131
+ The build output lands in `dist/`; the rest of this README uses `node dist/index.js` whenever it refers to the source-build entry point.
132
+
97
133
  ---
98
134
 
99
135
  ## Configuration
@@ -117,13 +153,15 @@ The agent reads its configuration from environment variables, plus an optional c
117
153
  If you'd rather not pass `Z_AI_API_KEY` through your ACP client's environment block, run the interactive setup once and the agent will read the key from disk on subsequent launches:
118
154
 
119
155
  ```bash
120
- # From the project directory (after npm run build)
121
- node dist/index.js --setup
122
-
123
- # Or, if you installed globally
124
156
  glm-acp-agent --setup
125
157
  ```
126
158
 
159
+ If you're working from a source clone instead of the published package, use the build output directly:
160
+
161
+ ```bash
162
+ node dist/index.js --setup
163
+ ```
164
+
127
165
  The key is written to `$XDG_CONFIG_HOME/glm-acp-agent/credentials.json` (default: `~/.config/glm-acp-agent/credentials.json`) with `0600` permissions. The `Z_AI_API_KEY` environment variable, when set, always wins over the file.
128
166
 
129
167
  ### Supported models
@@ -134,18 +172,23 @@ The agent advertises only the models on the current Z.AI Coding Plan allowlist:
134
172
  |-------|-------|
135
173
  | `glm-5.1` | **Default.** Long-horizon coding model; thinking mode auto-enabled |
136
174
  | `glm-5-turbo` | Faster Coding Plan reasoning model |
175
+ | `glm-5v-turbo` | Multimodal Coding Plan model; native image understanding for jpg / jpeg / png inputs |
137
176
  | `glm-4.7` | 200K-context reasoning model |
138
177
  | `glm-4.5-air` | Lightweight, lower-latency model |
139
178
 
140
- `ACP_GLM_AVAILABLE_MODELS` still lets you advertise custom IDs, but custom IDs sit outside the supported Coding Plan list — the Coding Plan endpoint will reject any model code Z.AI hasn't whitelisted (business code `1211`).
179
+ `ACP_GLM_AVAILABLE_MODELS` still lets you advertise custom IDs, but custom IDs sit outside the supported Coding Plan list — the Coding Plan endpoint will reject any model code Z.AI hasn't whitelisted (business code `1211`). If you override the model list, include `glm-5v-turbo` yourself to keep it visible in the picker.
180
+
181
+ Vision-only chat models (`glm-4v-plus` etc.) are **not** advertised. The multimodal coding model `glm-5v-turbo` is advertised because it is on the Coding Plan and receives supported ACP image blocks directly as native `image_url` content parts. Other advertised models keep using the [Vision MCP](#vision-mcp) path for image analysis.
141
182
 
142
- Vision (`glm-4v-plus` etc.) is **not** advertised as a chat model: vision on the Coding Plan flows through the [Vision MCP](#vision-mcp) section below instead.
183
+ When the model name matches `glm-4.5`, `glm-4.6`, `glm-4.7`, or the `glm-5` family, the agent enables Z.AI's `thinking: { type: "enabled" }` extension and forwards reasoning tokens to the client as `agent_thought_chunk` blocks. This includes `glm-5v-turbo`. Override with `ACP_GLM_THINKING=false` if you want plain completions only.
143
184
 
144
- When the model name matches `glm-4.5`, `glm-4.6`, `glm-4.7`, or `glm-5.x`, the agent enables Z.AI's `thinking: { type: "enabled" }` extension and forwards reasoning tokens to the client as `agent_thought_chunk` blocks. Override with `ACP_GLM_THINKING=false` if you want plain completions only.
185
+ `ACP_GLM_PROMPT_IMAGES=false` still hides the image-attachment capability at session startup. With that flag set, users can pick `glm-5v-turbo` for text work but clients should not offer image attachments.
145
186
 
146
187
  ### Vision MCP
147
188
 
148
- Pasted ACP image blocks are not sent to the chat-completions endpoint. Instead, the agent boots `@z_ai/mcp-server` over stdio (via `npx -y @z_ai/mcp-server@latest`) and calls its `image_analysis` tool. The text result is spliced into the user message as `<image_analysis index="N">…</image_analysis>` so the regular Coding Plan model can reason about it.
189
+ For `glm-5v-turbo`, pasted ACP image blocks with `image/jpeg`, `image/jpg`, or `image/png` are sent directly to chat completions as `image_url` content parts. HTTPS image URLs are forwarded as URLs; inline base64 data is sent as a `data:<mime>;base64,...` URI. Unsupported image MIME types are rejected client-side with an inline `<image_unsupported_format>` annotation so the prompt can continue without a provider 4xx.
190
+
191
+ For non-native models, pasted ACP image blocks are not sent to the chat-completions endpoint. Instead, the agent boots `@z_ai/mcp-server` over stdio (via `npx -y @z_ai/mcp-server@latest`) and calls its `image_analysis` tool. The text result is spliced into the user message as `<image_analysis index="N">…</image_analysis>` so the regular Coding Plan model can reason about it.
149
192
 
150
193
  Prerequisites:
151
194
 
@@ -160,23 +203,26 @@ The model can also call `image_analysis` explicitly with `{ image_source: "/path
160
203
 
161
204
  ### Standalone (stdio)
162
205
 
206
+ If you installed the published package globally, just run the CLI:
207
+
163
208
  ```bash
164
209
  export Z_AI_API_KEY=your_key_here
165
- node dist/index.js
210
+ glm-acp-agent
166
211
  ```
167
212
 
168
- The agent speaks the ACP newline-delimited JSON protocol over stdin/stdout. You can connect any ACP-compatible client to it.
169
-
170
- ### As a global CLI
213
+ If you built from source, invoke the entry point directly:
171
214
 
172
215
  ```bash
173
- npm install -g .
174
216
  export Z_AI_API_KEY=your_key_here
175
- glm-acp-agent
217
+ node dist/index.js
176
218
  ```
177
219
 
220
+ The agent speaks the ACP newline-delimited JSON protocol over stdin/stdout. You can connect any ACP-compatible client to it.
221
+
178
222
  ### Development mode (watch)
179
223
 
224
+ When working from a source clone, run `tsc` in watch mode so `dist/` rebuilds on every save:
225
+
180
226
  ```bash
181
227
  export Z_AI_API_KEY=your_key_here
182
228
  npm run dev # tsc --watch
@@ -196,20 +242,16 @@ npm run dev # tsc --watch
196
242
  - Node.js 20 or later on your `PATH` (`node --version`)
197
243
  - A Z.AI API key — create one at <https://z.ai/manage-apikey/apikey-list>
198
244
 
199
- #### 2. Build the agent
245
+ #### 2. Install the agent
200
246
 
201
- ```bash
202
- git clone https://github.com/stefandevo/glm-acp-agent.git
203
- cd glm-acp-agent
204
- npm install
205
- npm run build
206
- ```
247
+ Follow either path from the [Installation](#installation) section above:
207
248
 
208
- Take note of the absolute path to the freshly built entry point — Zed needs it (no `~`, no `$HOME` shortcuts):
249
+ - **Quick Start** — `npm install -g glm-acp-agent@latest`. Zed can then spawn the agent with `"command": "glm-acp-agent"`.
250
+ - **From source** — clone, `npm install`, `npm run build`. Zed needs the absolute path to the built entry point (no `~`, no `$HOME` shortcuts):
209
251
 
210
- ```bash
211
- echo "$(pwd)/dist/index.js"
212
- ```
252
+ ```bash
253
+ echo "$(pwd)/dist/index.js"
254
+ ```
213
255
 
214
256
  #### 3. Wire it into Zed
215
257
 
@@ -217,6 +259,19 @@ Open (or create) `~/.config/zed/settings.json` and add an `agent_servers` entry.
217
259
 
218
260
  **Option A — inline `env` block (simplest):**
219
261
 
262
+ ```json
263
+ {
264
+ "agent_servers": {
265
+ "glm": {
266
+ "command": "glm-acp-agent",
267
+ "env": { "Z_AI_API_KEY": "sk-…" }
268
+ }
269
+ }
270
+ }
271
+ ```
272
+
273
+ If you installed from source instead of the published package, replace `command` / `args` with the absolute path to the build output:
274
+
220
275
  ```json
221
276
  {
222
277
  "agent_servers": {
@@ -231,26 +286,21 @@ Open (or create) `~/.config/zed/settings.json` and add an `agent_servers` entry.
231
286
 
232
287
  **Option B — credentials file (no key in your editor settings):**
233
288
 
234
- Run the interactive setup once. From the project directory:
235
-
236
- ```bash
237
- node dist/index.js --setup
238
- ```
239
-
240
- …or, if you `npm install -g .`'d the package:
289
+ Run the interactive setup once:
241
290
 
242
291
  ```bash
243
292
  glm-acp-agent --setup
244
293
  ```
245
294
 
295
+ If you're working from a source clone, use the build output directly: `node dist/index.js --setup`.
296
+
246
297
  The key is written to `~/.config/glm-acp-agent/credentials.json` with `0600` permissions. Then drop the `env` block from the Zed entry — the agent will read the file on launch:
247
298
 
248
299
  ```json
249
300
  {
250
301
  "agent_servers": {
251
302
  "glm": {
252
- "command": "node",
253
- "args": ["/absolute/path/to/glm-acp-agent/dist/index.js"]
303
+ "command": "glm-acp-agent"
254
304
  }
255
305
  }
256
306
  }
@@ -288,7 +338,12 @@ For a tighter inner loop, run `npm run dev` in a terminal so `dist/` rebuilds on
288
338
 
289
339
  ### Neovim / VS Code / JetBrains / any ACP client
290
340
 
291
- Any client that supports configuring an ACP agent via a `command` + `args` invocation works the same way: point it at `node /absolute/path/to/glm-acp-agent/dist/index.js` and supply `Z_AI_API_KEY` in the environment.
341
+ Any client that supports configuring an ACP agent via a `command` + `args` invocation works the same way:
342
+
343
+ - If you installed via `npm install -g glm-acp-agent@latest`, set `command` to `glm-acp-agent` (no args required).
344
+ - If you built from source, set `command` to `node` and `args` to `["/absolute/path/to/glm-acp-agent/dist/index.js"]`.
345
+
346
+ Supply `Z_AI_API_KEY` in the environment, or run `glm-acp-agent --setup` once so the agent reads the key from disk on launch.
292
347
 
293
348
  ### Authentication
294
349
 
@@ -353,7 +408,7 @@ The test suite covers:
353
408
 
354
409
  ## Troubleshooting
355
410
 
356
- - **`No API key found.`** — either set `Z_AI_API_KEY` in the environment, or run `node dist/index.js --setup` (or `glm-acp-agent --setup` if installed globally) once to store the key on disk.
411
+ - **`No API key found.`** — either set `Z_AI_API_KEY` in the environment, or run `glm-acp-agent --setup` (or `node dist/index.js --setup` from a source clone) once to store the key on disk.
357
412
  - **`HTTP 401: Invalid API key`** — your key is wrong or expired; rotate it on <https://z.ai/manage-apikey/apikey-list>.
358
413
  - **Writes or commands never get to run.** — make sure your ACP client supports `session/request_permission` and that you approve the prompt for the specific tool call.
359
414
 
@@ -35,6 +35,17 @@ export interface StreamChatOptions {
35
35
  }
36
36
  /** Default GLM model when neither client nor user has chosen one. */
37
37
  export declare const DEFAULT_MODEL = "glm-5.1";
38
+ /**
39
+ * Z.AI / Zhipu AI error code returned when the total prompt length (messages +
40
+ * tools) exceeds the model's context window.
41
+ */
42
+ export declare const ERR_CONTEXT_OVERFLOW = 1261;
43
+ export declare function isVisionNativeModel(modelId: string): boolean;
44
+ /**
45
+ * Resolve the context window size for a given model ID. Falls back to a safe
46
+ * default (128K) for uncatalogued models.
47
+ */
48
+ export declare function getContextWindow(modelId: string): number;
38
49
  /**
39
50
  * Resolve the list of advertised models, allowing the user to override the
40
51
  * built-in list via `ACP_GLM_AVAILABLE_MODELS`.
@@ -1 +1 @@
1
- {"version":3,"file":"glm-client.d.ts","sourceRoot":"","sources":["../../src/llm/glm-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAsB,MAAM,2BAA2B,CAAC;AAChG,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAoB,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAIhF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,iCAAiC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE;QACT,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,oDAAoD;IACpD,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,kCAAkC;IAClC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,4BAA4B;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qDAAqD;AACr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I,CAAC,EAAE,OAAO,CAAC;IACf,4BAA4B;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qDAAqD;AACrD,MAAM,WAAW,iBAAiB;IAChC,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;CAC1B;AAKD,qEAAqE;AACrE,eAAO,MAAM,aAAa,YAAY,CAAC;AAsCvC;;;GAGG;AACH,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAgBzC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,SAAS,EAAE,CAYhD;AAED,uEAAuE;AACvE,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;;;;;;GAOG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAS;;IAgB1B;;;;;;OAMG;IACI,UAAU,CACf,QAAQ,EAAE,UAAU,EAAE,EACtB,MAAM,CAAC,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,cAAc,CAAC,cAAc,CAAC;CA6IlC"}
@@ -25,6 +25,11 @@ const BUILTIN_AVAILABLE_MODELS = [
25
25
  name: "GLM-5 Turbo",
26
26
  description: "Faster Coding Plan reasoning model",
27
27
  },
28
+ {
29
+ modelId: "glm-5v-turbo",
30
+ name: "GLM-5V Turbo",
31
+ description: "Multimodal Coding Plan model with native vision",
32
+ },
28
33
  {
29
34
  modelId: "glm-4.7",
30
35
  name: "GLM-4.7",
@@ -36,6 +41,33 @@ const BUILTIN_AVAILABLE_MODELS = [
36
41
  description: "Lightweight, lower-latency model",
37
42
  },
38
43
  ];
44
+ /**
45
+ * Z.AI / Zhipu AI error code returned when the total prompt length (messages +
46
+ * tools) exceeds the model's context window.
47
+ */
48
+ export const ERR_CONTEXT_OVERFLOW = 1261;
49
+ /**
50
+ * Context window sizes (in tokens) for GLM series models.
51
+ */
52
+ const MODEL_METADATA = {
53
+ "glm-5.1": { contextWindow: 128_000 },
54
+ "glm-5-turbo": { contextWindow: 128_000 },
55
+ "glm-5v-turbo": { contextWindow: 200_000 },
56
+ "glm-4.7": { contextWindow: 200_000 },
57
+ "glm-4.5-air": { contextWindow: 128_000 },
58
+ };
59
+ /** Models that accept image content parts directly through chat completions. */
60
+ const VISION_NATIVE_MODELS = new Set(["glm-5v-turbo"]);
61
+ export function isVisionNativeModel(modelId) {
62
+ return VISION_NATIVE_MODELS.has(modelId.toLowerCase());
63
+ }
64
+ /**
65
+ * Resolve the context window size for a given model ID. Falls back to a safe
66
+ * default (128K) for uncatalogued models.
67
+ */
68
+ export function getContextWindow(modelId) {
69
+ return MODEL_METADATA[modelId]?.contextWindow ?? 128_000;
70
+ }
39
71
  /**
40
72
  * Resolve the list of advertised models, allowing the user to override the
41
73
  * built-in list via `ACP_GLM_AVAILABLE_MODELS`.
@@ -1 +1 @@
1
- {"version":3,"file":"glm-client.js","sourceRoot":"","sources":["../../src/llm/glm-client.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,OAAO,EAAE,gBAAgB,EAAuB,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAqC3C,qFAAqF;AACrF,MAAM,gBAAgB,GAAG,qCAAqC,CAAC;AAE/D,qEAAqE;AACrE,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,wBAAwB,GAAgB;IAC5C;QACE,OAAO,EAAE,SAAS;QAClB,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,+C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C/D,CAAC;IACD,OAAO,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC5C,CAAC"}
@@ -2,6 +2,11 @@ import type { Agent, AgentSideConnection, InitializeRequest, InitializeResponse,
2
2
  import { type GlmMessage, type GlmStreamChunk, type StreamChatOptions } from "../llm/glm-client.js";
3
3
  import { SessionStore } from "./session-store.js";
4
4
  import { type VisionMcpClient } from "../tools/vision-mcp-client.js";
5
+ /**
6
+ * ACP session mode identifiers. These control when the agent requests user
7
+ * permission for tool calls that mutate state.
8
+ */
9
+ export type SessionModeId = "default" | "accept_edits" | "bypass_permissions";
5
10
  /**
6
11
  * Optional dependencies for tests.
7
12
  */
@@ -47,12 +52,14 @@ export declare class GlmAcpAgent implements Agent {
47
52
  private get glm();
48
53
  private get visionClient();
49
54
  initialize(params: InitializeRequest): Promise<InitializeResponse>;
50
- authenticate(_params: AuthenticateRequest): Promise<AuthenticateResponse>;
55
+ authenticate(params: AuthenticateRequest): Promise<AuthenticateResponse>;
51
56
  newSession(params: NewSessionRequest): Promise<NewSessionResponse>;
52
57
  unstable_setSessionModel(params: SetSessionModelRequest): Promise<SetSessionModelResponse>;
53
58
  /** Build the SessionModelState we advertise on session create/load/resume/fork. */
54
59
  private modelsState;
55
- setSessionMode(_params: SetSessionModeRequest): Promise<SetSessionModeResponse>;
60
+ /** Build the SessionModeState we advertise on session create/load/resume/fork. */
61
+ private modesState;
62
+ setSessionMode(params: SetSessionModeRequest): Promise<SetSessionModeResponse>;
56
63
  prompt(params: PromptRequest): Promise<PromptResponse>;
57
64
  cancel(params: CancelNotification): Promise<void>;
58
65
  closeSession(params: CloseSessionRequest): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/protocol/agent.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,KAAK,EACL,mBAAmB,EAEnB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,E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