@spenceriam/impulse 0.15.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 +194 -0
- package/dist/api/client.d.ts +53 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +271 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/index.d.ts +6 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +7 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/stream.d.ts +98 -0
- package/dist/api/stream.d.ts.map +1 -0
- package/dist/api/stream.js +202 -0
- package/dist/api/stream.js.map +1 -0
- package/dist/api/types.d.ts +1353 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +143 -0
- package/dist/api/types.js.map +1 -0
- package/dist/bash.txt +28 -0
- package/dist/bus/bus.d.ts +21 -0
- package/dist/bus/bus.d.ts.map +1 -0
- package/dist/bus/bus.js +22 -0
- package/dist/bus/bus.js.map +1 -0
- package/dist/bus/events.d.ts +100 -0
- package/dist/bus/events.d.ts.map +1 -0
- package/dist/bus/events.js +45 -0
- package/dist/bus/events.js.map +1 -0
- package/dist/bus/index.d.ts +3 -0
- package/dist/bus/index.d.ts.map +1 -0
- package/dist/bus/index.js +3 -0
- package/dist/bus/index.js.map +1 -0
- package/dist/file-edit.txt +21 -0
- package/dist/file-read.txt +18 -0
- package/dist/file-write.txt +16 -0
- package/dist/glob.txt +19 -0
- package/dist/global.d.ts +8 -0
- package/dist/global.d.ts.map +1 -0
- package/dist/global.js +14 -0
- package/dist/global.js.map +1 -0
- package/dist/grep.txt +20 -0
- package/dist/highlights-eq9cgrbb.scm +604 -0
- package/dist/highlights-ghv9g403.scm +205 -0
- package/dist/highlights-hk7bwhj4.scm +284 -0
- package/dist/highlights-r812a2qc.scm +150 -0
- package/dist/highlights-x6tmsnaa.scm +115 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62122 -0
- package/dist/index.js.map +1 -0
- package/dist/index.jsx +5 -0
- package/dist/index.jsx.map +1 -0
- package/dist/injections-73j83es3.scm +27 -0
- package/dist/input/at-refs.d.ts +42 -0
- package/dist/input/at-refs.d.ts.map +1 -0
- package/dist/input/at-refs.js +154 -0
- package/dist/input/at-refs.js.map +1 -0
- package/dist/input/history.d.ts +26 -0
- package/dist/input/history.d.ts.map +1 -0
- package/dist/input/history.js +109 -0
- package/dist/input/history.js.map +1 -0
- package/dist/input/index.d.ts +5 -0
- package/dist/input/index.d.ts.map +1 -0
- package/dist/input/index.js +5 -0
- package/dist/input/index.js.map +1 -0
- package/dist/input/paste.d.ts +19 -0
- package/dist/input/paste.d.ts.map +1 -0
- package/dist/input/paste.js +75 -0
- package/dist/input/paste.js.map +1 -0
- package/dist/input/shortcuts.d.ts +6 -0
- package/dist/input/shortcuts.d.ts.map +1 -0
- package/dist/input/shortcuts.js +84 -0
- package/dist/input/shortcuts.js.map +1 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/manager.d.ts +51 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +158 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/types.d.ts +18 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +5 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/session/todo.d.ts +24 -0
- package/dist/session/todo.d.ts.map +1 -0
- package/dist/session/todo.js +39 -0
- package/dist/session/todo.js.map +1 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/storage.d.ts +13 -0
- package/dist/storage/storage.d.ts.map +1 -0
- package/dist/storage/storage.js +84 -0
- package/dist/storage/storage.js.map +1 -0
- package/dist/task.txt +26 -0
- package/dist/todo-read.txt +14 -0
- package/dist/todo-write.txt +166 -0
- package/dist/tools/bash.d.ts +22 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +70 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/file-edit.d.ts +22 -0
- package/dist/tools/file-edit.d.ts.map +1 -0
- package/dist/tools/file-edit.js +67 -0
- package/dist/tools/file-edit.js.map +1 -0
- package/dist/tools/file-read.d.ts +19 -0
- package/dist/tools/file-read.d.ts.map +1 -0
- package/dist/tools/file-read.js +70 -0
- package/dist/tools/file-read.js.map +1 -0
- package/dist/tools/file-write.d.ts +16 -0
- package/dist/tools/file-write.d.ts.map +1 -0
- package/dist/tools/file-write.js +45 -0
- package/dist/tools/file-write.js.map +1 -0
- package/dist/tools/glob.d.ts +16 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +45 -0
- package/dist/tools/glob.js.map +1 -0
- package/dist/tools/grep.d.ts +19 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +65 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/index.d.ts +11 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +11 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +22 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +75 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/task.d.ts +19 -0
- package/dist/tools/task.d.ts.map +1 -0
- package/dist/tools/task.js +51 -0
- package/dist/tools/task.js.map +1 -0
- package/dist/tools/todo-read.d.ts +7 -0
- package/dist/tools/todo-read.d.ts.map +1 -0
- package/dist/tools/todo-read.js +56 -0
- package/dist/tools/todo-read.js.map +1 -0
- package/dist/tools/todo-write.d.ts +38 -0
- package/dist/tools/todo-write.d.ts.map +1 -0
- package/dist/tools/todo-write.js +40 -0
- package/dist/tools/todo-write.js.map +1 -0
- package/dist/tree-sitter-javascript-nd0q4pe9.wasm +0 -0
- package/dist/tree-sitter-markdown-411r6y9b.wasm +0 -0
- package/dist/tree-sitter-markdown_inline-j5349f42.wasm +0 -0
- package/dist/tree-sitter-typescript-zxjzwt75.wasm +0 -0
- package/dist/tree-sitter-zig-e78zbjpm.wasm +0 -0
- package/dist/ui/App.d.ts +6 -0
- package/dist/ui/App.d.ts.map +1 -0
- package/dist/ui/App.jsx +37 -0
- package/dist/ui/App.jsx.map +1 -0
- package/dist/ui/components/Autocomplete.d.ts +24 -0
- package/dist/ui/components/Autocomplete.d.ts.map +1 -0
- package/dist/ui/components/Autocomplete.jsx +67 -0
- package/dist/ui/components/Autocomplete.jsx.map +1 -0
- package/dist/ui/components/ChatView.d.ts +14 -0
- package/dist/ui/components/ChatView.d.ts.map +1 -0
- package/dist/ui/components/ChatView.jsx +11 -0
- package/dist/ui/components/ChatView.jsx.map +1 -0
- package/dist/ui/components/InputArea.d.ts +18 -0
- package/dist/ui/components/InputArea.d.ts.map +1 -0
- package/dist/ui/components/InputArea.jsx +35 -0
- package/dist/ui/components/InputArea.jsx.map +1 -0
- package/dist/ui/components/MessageBlock.d.ts +21 -0
- package/dist/ui/components/MessageBlock.d.ts.map +1 -0
- package/dist/ui/components/MessageBlock.jsx +94 -0
- package/dist/ui/components/MessageBlock.jsx.map +1 -0
- package/dist/ui/components/Overlay.d.ts +28 -0
- package/dist/ui/components/Overlay.d.ts.map +1 -0
- package/dist/ui/components/Overlay.jsx +102 -0
- package/dist/ui/components/Overlay.jsx.map +1 -0
- package/dist/ui/components/ProgressBar.d.ts +9 -0
- package/dist/ui/components/ProgressBar.d.ts.map +1 -0
- package/dist/ui/components/ProgressBar.jsx +17 -0
- package/dist/ui/components/ProgressBar.jsx.map +1 -0
- package/dist/ui/components/Sidebar.d.ts +22 -0
- package/dist/ui/components/Sidebar.d.ts.map +1 -0
- package/dist/ui/components/Sidebar.jsx +96 -0
- package/dist/ui/components/Sidebar.jsx.map +1 -0
- package/dist/ui/components/StatusLine.d.ts +6 -0
- package/dist/ui/components/StatusLine.d.ts.map +1 -0
- package/dist/ui/components/StatusLine.jsx +32 -0
- package/dist/ui/components/StatusLine.jsx.map +1 -0
- package/dist/ui/components/ThinkingBlock.d.ts +15 -0
- package/dist/ui/components/ThinkingBlock.d.ts.map +1 -0
- package/dist/ui/components/ThinkingBlock.jsx +33 -0
- package/dist/ui/components/ThinkingBlock.jsx.map +1 -0
- package/dist/ui/components/TodoItem.d.ts +22 -0
- package/dist/ui/components/TodoItem.d.ts.map +1 -0
- package/dist/ui/components/TodoItem.jsx +11 -0
- package/dist/ui/components/TodoItem.jsx.map +1 -0
- package/dist/ui/components/ToolBlock.d.ts +27 -0
- package/dist/ui/components/ToolBlock.d.ts.map +1 -0
- package/dist/ui/components/ToolBlock.jsx +76 -0
- package/dist/ui/components/ToolBlock.jsx.map +1 -0
- package/dist/ui/components/index.d.ts +12 -0
- package/dist/ui/components/index.d.ts.map +1 -0
- package/dist/ui/components/index.js +12 -0
- package/dist/ui/components/index.js.map +1 -0
- package/dist/ui/context/index.d.ts +4 -0
- package/dist/ui/context/index.d.ts.map +1 -0
- package/dist/ui/context/index.js +4 -0
- package/dist/ui/context/index.js.map +1 -0
- package/dist/ui/context/mode.d.ts +24 -0
- package/dist/ui/context/mode.d.ts.map +1 -0
- package/dist/ui/context/mode.jsx +53 -0
- package/dist/ui/context/mode.jsx.map +1 -0
- package/dist/ui/context/session.d.ts +43 -0
- package/dist/ui/context/session.d.ts.map +1 -0
- package/dist/ui/context/session.jsx +63 -0
- package/dist/ui/context/session.jsx.map +1 -0
- package/dist/ui/context/todo.d.ts +32 -0
- package/dist/ui/context/todo.d.ts.map +1 -0
- package/dist/ui/context/todo.jsx +75 -0
- package/dist/ui/context/todo.jsx.map +1 -0
- package/dist/ui/design.d.ts +182 -0
- package/dist/ui/design.d.ts.map +1 -0
- package/dist/ui/design.js +189 -0
- package/dist/ui/design.js.map +1 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +3 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/util/config.d.ts +22 -0
- package/dist/util/config.d.ts.map +1 -0
- package/dist/util/config.js +55 -0
- package/dist/util/config.js.map +1 -0
- package/dist/util/instructions.d.ts +39 -0
- package/dist/util/instructions.d.ts.map +1 -0
- package/dist/util/instructions.js +96 -0
- package/dist/util/instructions.js.map +1 -0
- package/dist/util/lock.d.ts +18 -0
- package/dist/util/lock.d.ts.map +1 -0
- package/dist/util/lock.js +65 -0
- package/dist/util/lock.js.map +1 -0
- package/dist/util/logger.d.ts +8 -0
- package/dist/util/logger.d.ts.map +1 -0
- package/dist/util/logger.js +81 -0
- package/dist/util/logger.js.map +1 -0
- package/package.json +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# IMPULSE
|
|
2
|
+
|
|
3
|
+
> Terminal-based AI coding agent powered by Z.ai's Coding Plan
|
|
4
|
+
|
|
5
|
+
A brutally minimal terminal interface for AI-assisted software development. Built with OpenTUI + SolidJS for flicker-free 60fps rendering. Powered by Z.ai's Coding Plan and their GLM-4.x models - the best cost/engineering ratio for builders.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **GLM-4.x Models** - Z.ai's flagship models with thinking mode
|
|
10
|
+
- **5 Modes** - AUTO, AGENT, PLANNER, PLAN-PRD, DEBUG
|
|
11
|
+
- **MCP Integration** - Vision, Web Search, Web Reader, Zread, Context7
|
|
12
|
+
- **Git Checkpoints** - Per-message undo/redo
|
|
13
|
+
- **Auto-Compact** - AI summarization at 85% context
|
|
14
|
+
- **Auto-Save** - Sessions persist automatically
|
|
15
|
+
- **Express Mode** - Skip permission prompts in trusted environments
|
|
16
|
+
- **Interactive Overlays** - Model picker, session loader, question prompts
|
|
17
|
+
|
|
18
|
+
## Visual Preview
|
|
19
|
+
|
|
20
|
+
**Welcome Screen:**
|
|
21
|
+
```
|
|
22
|
+
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
|
23
|
+
┃ ┃
|
|
24
|
+
┃ ██╗███╗ ███╗██████╗ ██╗ ██╗██╗ ███████╗███████╗ ┃
|
|
25
|
+
┃ ██║████╗ ████║██╔══██╗██║ ██║██║ ██╔════╝██╔════╝ ┃
|
|
26
|
+
┃ ██║██╔████╔██║██████╔╝██║ ██║██║ ███████╗█████╗ ┃
|
|
27
|
+
┃ ██║██║╚██╔╝██║██╔═══╝ ██║ ██║██║ ╚════██║██╔══╝ ┃
|
|
28
|
+
┃ ██║██║ ╚═╝ ██║██║ ╚██████╔╝███████╗███████║███████╗ ┃
|
|
29
|
+
┃ ╚═╝╚═╝ ╚═╝╚═╝ ╚═════╝ ╚══════╝╚══════╝╚══════╝ ┃
|
|
30
|
+
┃ ┃
|
|
31
|
+
┃ v0.14.0 GLM-4.7 ┃
|
|
32
|
+
┃ built 01-23-2026 ~/project ┃
|
|
33
|
+
┃ ┃
|
|
34
|
+
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
|
35
|
+
|
|
36
|
+
┌─ AUTO ─────────────────────────────────────────────────────────────────────┐
|
|
37
|
+
│ > _ │
|
|
38
|
+
└────────────────────────────────────────────────────────────────────────────┘
|
|
39
|
+
GLM-4.7 | ~/project | main | MCP: ● | 01-23-2026
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Session View:**
|
|
43
|
+
```
|
|
44
|
+
[IMPULSE] | Implementing API client
|
|
45
|
+
────────────────────────────────────────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
You 12:34 PM
|
|
48
|
+
Can you help me implement the API client?
|
|
49
|
+
|
|
50
|
+
GLM-4.7 [AGENT] 12:34 PM
|
|
51
|
+
I'll help you implement the API client.
|
|
52
|
+
|
|
53
|
+
▶ file_write src/api/types.ts [OK]
|
|
54
|
+
▶ file_write src/api/client.ts [OK]
|
|
55
|
+
|
|
56
|
+
┌─ AGENT ────────────────────────────────────────────────────────────────────┐
|
|
57
|
+
│ > _ │
|
|
58
|
+
└────────────────────────────────────────────────────────────────────────────┘
|
|
59
|
+
GLM-4.7 | AGENT | [██████░░░░] 62% | ~/project | main | MCP: ● | 01-23-2026
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Quick Start
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Install
|
|
66
|
+
bun install -g impulse
|
|
67
|
+
|
|
68
|
+
# Set API key
|
|
69
|
+
export GLM_API_KEY=your_key_here
|
|
70
|
+
|
|
71
|
+
# Run
|
|
72
|
+
impulse
|
|
73
|
+
|
|
74
|
+
# Run with Express mode (skip permission prompts)
|
|
75
|
+
impulse --express
|
|
76
|
+
# or
|
|
77
|
+
impulse -e
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Modes
|
|
81
|
+
|
|
82
|
+
| Mode | Key | Purpose |
|
|
83
|
+
|------|-----|---------|
|
|
84
|
+
| AUTO | - | AI decides based on prompt |
|
|
85
|
+
| AGENT | Tab | Full execution with all tools |
|
|
86
|
+
| PLANNER | Tab | Generate project documentation |
|
|
87
|
+
| PLAN-PRD | Tab | Quick PRD via Q&A |
|
|
88
|
+
| DEBUG | Tab | 7-step systematic debugging |
|
|
89
|
+
|
|
90
|
+
## Commands
|
|
91
|
+
|
|
92
|
+
| Command | Description |
|
|
93
|
+
|---------|-------------|
|
|
94
|
+
| `/new` | New session (clears current) |
|
|
95
|
+
| `/clear` | Clear session (alias for /new) |
|
|
96
|
+
| `/save` | Save session |
|
|
97
|
+
| `/load` | Interactive session picker |
|
|
98
|
+
| `/undo` | Revert last change |
|
|
99
|
+
| `/redo` | Restore undone |
|
|
100
|
+
| `/compact` | Manually compact context |
|
|
101
|
+
| `/model` | Interactive model picker |
|
|
102
|
+
| `/mode` | Switch mode |
|
|
103
|
+
| `/think` | Toggle thinking mode |
|
|
104
|
+
| `/express` | Toggle Express mode (skip permissions) |
|
|
105
|
+
| `/init` | Analyze project, create AGENTS.md |
|
|
106
|
+
| `/stats` | Session statistics |
|
|
107
|
+
| `/help` | Show help |
|
|
108
|
+
| `/quit` | Exit with summary |
|
|
109
|
+
|
|
110
|
+
## Keyboard
|
|
111
|
+
|
|
112
|
+
| Key | Action |
|
|
113
|
+
|-----|--------|
|
|
114
|
+
| `Tab` | Cycle modes |
|
|
115
|
+
| `Shift+Tab` | Cycle reverse |
|
|
116
|
+
| `Enter` | Submit |
|
|
117
|
+
| `Shift+Enter` | New line |
|
|
118
|
+
| `Up/Down` | Message history |
|
|
119
|
+
| `@` | File autocomplete |
|
|
120
|
+
| `Esc` (2x) | Cancel operation |
|
|
121
|
+
| `Ctrl+C` (2x) | Exit with summary |
|
|
122
|
+
| `Ctrl+P` | Command palette |
|
|
123
|
+
| `Ctrl+M` | MCP status |
|
|
124
|
+
|
|
125
|
+
## Models
|
|
126
|
+
|
|
127
|
+
| Model | Type | Best For |
|
|
128
|
+
|-------|------|----------|
|
|
129
|
+
| `glm-4.7` | Text | Complex coding (default) |
|
|
130
|
+
| `glm-4.7-flash` | Text | Fast coding |
|
|
131
|
+
| `glm-4.6` | Text | Previous flagship |
|
|
132
|
+
| `glm-4.6v` | Vision | Image understanding |
|
|
133
|
+
| `glm-4.5` | Text | General tasks |
|
|
134
|
+
| `glm-4.5-air` | Text | Lightweight |
|
|
135
|
+
| `glm-4.5-flash` | Text | Ultra-fast |
|
|
136
|
+
| `glm-4.5v` | Vision | Quick image tasks |
|
|
137
|
+
|
|
138
|
+
## MCP Servers
|
|
139
|
+
|
|
140
|
+
IMPULSE integrates with 5 MCP servers out of the box:
|
|
141
|
+
|
|
142
|
+
| Server | Type | Tools |
|
|
143
|
+
|--------|------|-------|
|
|
144
|
+
| **Vision** | Local (stdio) | Image analysis, UI screenshots, diagrams |
|
|
145
|
+
| **Web Search** | Remote (HTTP) | Web search |
|
|
146
|
+
| **Web Reader** | Remote (HTTP) | Fetch and parse web pages |
|
|
147
|
+
| **Zread** | Remote (HTTP) | Search docs, read GitHub repos |
|
|
148
|
+
| **Context7** | Remote (HTTP) | Library/framework documentation |
|
|
149
|
+
|
|
150
|
+
The agent discovers MCP tools on-demand to keep context lean.
|
|
151
|
+
|
|
152
|
+
## Configuration
|
|
153
|
+
|
|
154
|
+
Config file: `~/.config/impulse/config.json`
|
|
155
|
+
|
|
156
|
+
```json
|
|
157
|
+
{
|
|
158
|
+
"apiKey": "your_key_here",
|
|
159
|
+
"defaultModel": "glm-4.7",
|
|
160
|
+
"defaultMode": "AUTO",
|
|
161
|
+
"thinking": true,
|
|
162
|
+
"express": false
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Or use environment variable:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
export GLM_API_KEY=your_key_here
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Project Instructions
|
|
173
|
+
|
|
174
|
+
IMPULSE loads project-specific instructions from these files (first found wins):
|
|
175
|
+
|
|
176
|
+
1. `.impulse/instructions.md`
|
|
177
|
+
2. `AGENTS.md`
|
|
178
|
+
3. `CLAUDE.md`
|
|
179
|
+
4. `GEMINI.md`
|
|
180
|
+
5. `QWEN.md`
|
|
181
|
+
6. `KIMI.md`
|
|
182
|
+
7. `COPILOT.md`
|
|
183
|
+
8. `.cursorrules`
|
|
184
|
+
9. `.windsurfrules`
|
|
185
|
+
|
|
186
|
+
## Requirements
|
|
187
|
+
|
|
188
|
+
- Bun 1.0+ or Node.js 20+
|
|
189
|
+
- Git (for undo/redo)
|
|
190
|
+
- Terminal with 256 colors
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ChatCompletionRequest, ChatCompletionResponse, ChatCompletionChunk, GLMModel, ChatMessage, ToolDefinition } from "./types";
|
|
2
|
+
export declare class GLMClientError extends Error {
|
|
3
|
+
readonly code?: string | undefined;
|
|
4
|
+
readonly statusCode?: number | undefined;
|
|
5
|
+
constructor(message: string, code?: string | undefined, statusCode?: number | undefined);
|
|
6
|
+
}
|
|
7
|
+
export declare class GLMAuthError extends GLMClientError {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class GLMRateLimitError extends GLMClientError {
|
|
11
|
+
readonly retryAfter?: number | undefined;
|
|
12
|
+
constructor(message: string, retryAfter?: number | undefined);
|
|
13
|
+
}
|
|
14
|
+
interface CompletionOptions {
|
|
15
|
+
model?: GLMModel;
|
|
16
|
+
messages: ChatMessage[];
|
|
17
|
+
temperature?: number;
|
|
18
|
+
top_p?: number;
|
|
19
|
+
max_tokens?: number;
|
|
20
|
+
stop?: string | string[];
|
|
21
|
+
tools?: ToolDefinition[];
|
|
22
|
+
tool_choice?: ChatCompletionRequest["tool_choice"];
|
|
23
|
+
stream?: false;
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
}
|
|
26
|
+
interface StreamCompletionOptions extends Omit<CompletionOptions, "stream"> {
|
|
27
|
+
stream: true;
|
|
28
|
+
}
|
|
29
|
+
declare class GLMClientImpl {
|
|
30
|
+
private client;
|
|
31
|
+
private apiKey;
|
|
32
|
+
private getClient;
|
|
33
|
+
private sleep;
|
|
34
|
+
private calculateBackoff;
|
|
35
|
+
private isRetryableError;
|
|
36
|
+
private executeWithRetry;
|
|
37
|
+
/**
|
|
38
|
+
* Create a chat completion (non-streaming)
|
|
39
|
+
*/
|
|
40
|
+
complete(options: CompletionOptions): Promise<ChatCompletionResponse>;
|
|
41
|
+
/**
|
|
42
|
+
* Create a streaming chat completion
|
|
43
|
+
* Returns an async iterable of chunks
|
|
44
|
+
*/
|
|
45
|
+
stream(options: Omit<StreamCompletionOptions, "stream">): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* Reset the client (useful when API key changes)
|
|
48
|
+
*/
|
|
49
|
+
reset(): void;
|
|
50
|
+
}
|
|
51
|
+
export declare const GLMClient: GLMClientImpl;
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,QAAQ,EACR,WAAW,EACX,cAAc,EACf,MAAM,SAAS,CAAC;AAkBjB,qBAAa,cAAe,SAAQ,KAAK;aAGrB,IAAI,CAAC,EAAE,MAAM;aACb,UAAU,CAAC,EAAE,MAAM;gBAFnC,OAAO,EAAE,MAAM,EACC,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,UAAU,CAAC,EAAE,MAAM,YAAA;CAKtC;AAED,qBAAa,YAAa,SAAQ,cAAc;gBAClC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,iBAAkB,SAAQ,cAAc;aACN,UAAU,CAAC,EAAE,MAAM;gBAApD,OAAO,EAAE,MAAM,EAAkB,UAAU,CAAC,EAAE,MAAM,YAAA;CAIjE;AAED,UAAU,iBAAiB;IACzB,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,qBAAqB,CAAC,aAAa,CAAC,CAAC;IACnD,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,UAAU,uBAAwB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC;IACzE,MAAM,EAAE,IAAI,CAAC;CACd;AAED,cAAM,aAAa;IACjB,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,MAAM,CAAuB;YAEvB,SAAS;YAqBT,KAAK;IAInB,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,gBAAgB;YAWV,gBAAgB;IA0D9B;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAqE3E;;;OAGG;IACI,MAAM,CACX,OAAO,EAAE,IAAI,CAAC,uBAAuB,EAAE,QAAQ,CAAC,GAC/C,cAAc,CAAC,mBAAmB,EAAE,IAAI,EAAE,OAAO,CAAC;IA6ErD;;OAEG;IACH,KAAK,IAAI,IAAI;CAId;AAGD,eAAO,MAAM,SAAS,eAAsB,CAAC"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import { load as loadConfig } from "../util/config";
|
|
3
|
+
import * as logger from "../util/logger";
|
|
4
|
+
/**
|
|
5
|
+
* GLM API Client
|
|
6
|
+
* OpenAI-compatible client for Z.AI Coding Plan API
|
|
7
|
+
*/
|
|
8
|
+
// Z.AI Coding Plan API endpoint (required - no fallback)
|
|
9
|
+
const BASE_URL = "https://api.z.ai/api/coding/paas/v4/";
|
|
10
|
+
// Retry configuration
|
|
11
|
+
const MAX_RETRIES = 5;
|
|
12
|
+
const INITIAL_BACKOFF_MS = 1000;
|
|
13
|
+
const MAX_BACKOFF_MS = 32000;
|
|
14
|
+
// Retryable HTTP status codes
|
|
15
|
+
const RETRYABLE_STATUS_CODES = new Set([408, 429, 500, 502, 503, 504]);
|
|
16
|
+
export class GLMClientError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
statusCode;
|
|
19
|
+
constructor(message, code, statusCode) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.code = code;
|
|
22
|
+
this.statusCode = statusCode;
|
|
23
|
+
this.name = "GLMClientError";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export class GLMAuthError extends GLMClientError {
|
|
27
|
+
constructor(message) {
|
|
28
|
+
super(message, "auth_error", 401);
|
|
29
|
+
this.name = "GLMAuthError";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class GLMRateLimitError extends GLMClientError {
|
|
33
|
+
retryAfter;
|
|
34
|
+
constructor(message, retryAfter) {
|
|
35
|
+
super(message, "rate_limit", 429);
|
|
36
|
+
this.retryAfter = retryAfter;
|
|
37
|
+
this.name = "GLMRateLimitError";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class GLMClientImpl {
|
|
41
|
+
client = null;
|
|
42
|
+
apiKey = null;
|
|
43
|
+
async getClient() {
|
|
44
|
+
if (this.client && this.apiKey) {
|
|
45
|
+
return this.client;
|
|
46
|
+
}
|
|
47
|
+
const config = await loadConfig();
|
|
48
|
+
if (!config.apiKey) {
|
|
49
|
+
throw new GLMAuthError("API key not configured. Set GLM_API_KEY environment variable or configure in ~/.config/glm-cli/config.json");
|
|
50
|
+
}
|
|
51
|
+
this.apiKey = config.apiKey;
|
|
52
|
+
this.client = new OpenAI({
|
|
53
|
+
apiKey: config.apiKey,
|
|
54
|
+
baseURL: BASE_URL,
|
|
55
|
+
maxRetries: 0, // We handle retries ourselves
|
|
56
|
+
});
|
|
57
|
+
return this.client;
|
|
58
|
+
}
|
|
59
|
+
async sleep(ms) {
|
|
60
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
61
|
+
}
|
|
62
|
+
calculateBackoff(attempt) {
|
|
63
|
+
const backoff = INITIAL_BACKOFF_MS * Math.pow(2, attempt);
|
|
64
|
+
const jitter = Math.random() * 0.3 * backoff; // 30% jitter
|
|
65
|
+
return Math.min(backoff + jitter, MAX_BACKOFF_MS);
|
|
66
|
+
}
|
|
67
|
+
isRetryableError(error) {
|
|
68
|
+
if (error instanceof OpenAI.APIError) {
|
|
69
|
+
return RETRYABLE_STATUS_CODES.has(error.status);
|
|
70
|
+
}
|
|
71
|
+
// Network errors are retryable
|
|
72
|
+
if (error instanceof Error && error.message.includes("fetch")) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
async executeWithRetry(operation, signal) {
|
|
78
|
+
let lastError = null;
|
|
79
|
+
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
|
80
|
+
// Check for abort before each attempt
|
|
81
|
+
if (signal?.aborted) {
|
|
82
|
+
throw new GLMClientError("Request aborted", "aborted");
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
return await operation();
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
89
|
+
// Don't retry auth errors
|
|
90
|
+
if (error instanceof OpenAI.AuthenticationError) {
|
|
91
|
+
throw new GLMAuthError(error.message);
|
|
92
|
+
}
|
|
93
|
+
// Handle rate limiting
|
|
94
|
+
if (error instanceof OpenAI.RateLimitError) {
|
|
95
|
+
const retryAfter = parseInt(error.headers?.["retry-after"] ?? "60", 10);
|
|
96
|
+
if (attempt === MAX_RETRIES - 1) {
|
|
97
|
+
throw new GLMRateLimitError(error.message, retryAfter);
|
|
98
|
+
}
|
|
99
|
+
await logger.warn(`Rate limited, waiting ${retryAfter}s before retry`);
|
|
100
|
+
await this.sleep(retryAfter * 1000);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
// Only retry on retryable errors
|
|
104
|
+
if (!this.isRetryableError(error)) {
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
// Last attempt, throw
|
|
108
|
+
if (attempt === MAX_RETRIES - 1) {
|
|
109
|
+
await logger.error(`All ${MAX_RETRIES} retry attempts failed`);
|
|
110
|
+
throw lastError;
|
|
111
|
+
}
|
|
112
|
+
const backoff = this.calculateBackoff(attempt);
|
|
113
|
+
await logger.warn(`Request failed, retrying in ${Math.round(backoff)}ms (attempt ${attempt + 1}/${MAX_RETRIES})`);
|
|
114
|
+
await this.sleep(backoff);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
throw lastError ?? new GLMClientError("Unknown error during retry");
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Create a chat completion (non-streaming)
|
|
121
|
+
*/
|
|
122
|
+
async complete(options) {
|
|
123
|
+
const client = await this.getClient();
|
|
124
|
+
const config = await loadConfig();
|
|
125
|
+
const response = await this.executeWithRetry(async () => {
|
|
126
|
+
// Build request with only defined properties (exactOptionalPropertyTypes)
|
|
127
|
+
const request = {
|
|
128
|
+
model: options.model ?? config.defaultModel,
|
|
129
|
+
messages: options.messages,
|
|
130
|
+
stream: false,
|
|
131
|
+
};
|
|
132
|
+
if (options.temperature !== undefined)
|
|
133
|
+
request.temperature = options.temperature;
|
|
134
|
+
if (options.top_p !== undefined)
|
|
135
|
+
request.top_p = options.top_p;
|
|
136
|
+
if (options.max_tokens !== undefined)
|
|
137
|
+
request.max_tokens = options.max_tokens;
|
|
138
|
+
if (options.stop !== undefined)
|
|
139
|
+
request.stop = options.stop;
|
|
140
|
+
if (options.tools !== undefined) {
|
|
141
|
+
request.tools = options.tools;
|
|
142
|
+
}
|
|
143
|
+
if (options.tool_choice !== undefined) {
|
|
144
|
+
request.tool_choice = options.tool_choice;
|
|
145
|
+
}
|
|
146
|
+
const result = await client.chat.completions.create(request);
|
|
147
|
+
return result;
|
|
148
|
+
}, options.signal);
|
|
149
|
+
// Transform to our type
|
|
150
|
+
return {
|
|
151
|
+
id: response.id,
|
|
152
|
+
object: "chat.completion",
|
|
153
|
+
created: response.created,
|
|
154
|
+
model: response.model,
|
|
155
|
+
choices: response.choices.map((choice) => {
|
|
156
|
+
// Map finish_reason, filtering out deprecated "function_call"
|
|
157
|
+
const finishReason = choice.finish_reason === "function_call"
|
|
158
|
+
? "tool_calls"
|
|
159
|
+
: choice.finish_reason;
|
|
160
|
+
return {
|
|
161
|
+
index: choice.index,
|
|
162
|
+
message: {
|
|
163
|
+
role: choice.message.role,
|
|
164
|
+
content: choice.message.content,
|
|
165
|
+
tool_calls: choice.message.tool_calls?.map((tc) => ({
|
|
166
|
+
id: tc.id,
|
|
167
|
+
type: "function",
|
|
168
|
+
function: {
|
|
169
|
+
name: tc.function.name,
|
|
170
|
+
arguments: tc.function.arguments,
|
|
171
|
+
},
|
|
172
|
+
})),
|
|
173
|
+
// Extract reasoning_content if present (GLM-specific)
|
|
174
|
+
reasoning_content: choice.message.reasoning_content,
|
|
175
|
+
},
|
|
176
|
+
finish_reason: finishReason,
|
|
177
|
+
};
|
|
178
|
+
}),
|
|
179
|
+
usage: response.usage ? {
|
|
180
|
+
prompt_tokens: response.usage.prompt_tokens,
|
|
181
|
+
completion_tokens: response.usage.completion_tokens,
|
|
182
|
+
total_tokens: response.usage.total_tokens,
|
|
183
|
+
} : undefined,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Create a streaming chat completion
|
|
188
|
+
* Returns an async iterable of chunks
|
|
189
|
+
*/
|
|
190
|
+
async *stream(options) {
|
|
191
|
+
const client = await this.getClient();
|
|
192
|
+
const config = await loadConfig();
|
|
193
|
+
const stream = await this.executeWithRetry(async () => {
|
|
194
|
+
// Build request with only defined properties (exactOptionalPropertyTypes)
|
|
195
|
+
const request = {
|
|
196
|
+
model: options.model ?? config.defaultModel,
|
|
197
|
+
messages: options.messages,
|
|
198
|
+
stream: true,
|
|
199
|
+
};
|
|
200
|
+
if (options.temperature !== undefined)
|
|
201
|
+
request.temperature = options.temperature;
|
|
202
|
+
if (options.top_p !== undefined)
|
|
203
|
+
request.top_p = options.top_p;
|
|
204
|
+
if (options.max_tokens !== undefined)
|
|
205
|
+
request.max_tokens = options.max_tokens;
|
|
206
|
+
if (options.stop !== undefined)
|
|
207
|
+
request.stop = options.stop;
|
|
208
|
+
if (options.tools !== undefined) {
|
|
209
|
+
request.tools = options.tools;
|
|
210
|
+
}
|
|
211
|
+
if (options.tool_choice !== undefined) {
|
|
212
|
+
request.tool_choice = options.tool_choice;
|
|
213
|
+
}
|
|
214
|
+
return client.chat.completions.create(request);
|
|
215
|
+
}, options.signal);
|
|
216
|
+
for await (const chunk of stream) {
|
|
217
|
+
// Check abort signal during streaming
|
|
218
|
+
if (options.signal?.aborted) {
|
|
219
|
+
stream.controller.abort();
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
// Transform to our chunk type
|
|
223
|
+
yield {
|
|
224
|
+
id: chunk.id,
|
|
225
|
+
object: "chat.completion.chunk",
|
|
226
|
+
created: chunk.created,
|
|
227
|
+
model: chunk.model,
|
|
228
|
+
choices: chunk.choices.map((choice) => {
|
|
229
|
+
// Map finish_reason, filtering out deprecated "function_call"
|
|
230
|
+
const finishReason = choice.finish_reason === "function_call"
|
|
231
|
+
? "tool_calls"
|
|
232
|
+
: choice.finish_reason;
|
|
233
|
+
return {
|
|
234
|
+
index: choice.index,
|
|
235
|
+
delta: {
|
|
236
|
+
role: choice.delta.role,
|
|
237
|
+
content: choice.delta.content,
|
|
238
|
+
// Extract reasoning_content if present (GLM-specific)
|
|
239
|
+
reasoning_content: choice.delta.reasoning_content,
|
|
240
|
+
tool_calls: choice.delta.tool_calls?.map((tc) => ({
|
|
241
|
+
index: tc.index,
|
|
242
|
+
id: tc.id,
|
|
243
|
+
type: tc.type,
|
|
244
|
+
function: tc.function ? {
|
|
245
|
+
name: tc.function.name,
|
|
246
|
+
arguments: tc.function.arguments,
|
|
247
|
+
} : undefined,
|
|
248
|
+
})),
|
|
249
|
+
},
|
|
250
|
+
finish_reason: finishReason,
|
|
251
|
+
};
|
|
252
|
+
}),
|
|
253
|
+
usage: chunk.usage ? {
|
|
254
|
+
prompt_tokens: chunk.usage.prompt_tokens,
|
|
255
|
+
completion_tokens: chunk.usage.completion_tokens,
|
|
256
|
+
total_tokens: chunk.usage.total_tokens,
|
|
257
|
+
} : null,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Reset the client (useful when API key changes)
|
|
263
|
+
*/
|
|
264
|
+
reset() {
|
|
265
|
+
this.client = null;
|
|
266
|
+
this.apiKey = null;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// Singleton instance
|
|
270
|
+
export const GLMClient = new GLMClientImpl();
|
|
271
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AAUzC;;;GAGG;AAEH,yDAAyD;AACzD,MAAM,QAAQ,GAAG,sCAAsC,CAAC;AAExD,sBAAsB;AACtB,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,MAAM,cAAc,GAAG,KAAK,CAAC;AAE7B,8BAA8B;AAC9B,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAEvE,MAAM,OAAO,cAAe,SAAQ,KAAK;IAGrB;IACA;IAHlB,YACE,OAAe,EACC,IAAa,EACb,UAAmB;QAEnC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAS;QACb,eAAU,GAAV,UAAU,CAAS;QAGnC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,cAAc;IAC9C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG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E,KAAK,CAAC,KAAK,CAAC,aAAa;oBACxC,iBAAiB,EAAE,KAAK,CAAC,KAAK,CAAC,iBAAiB;oBAChD,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,YAAY;iBACvC,CAAC,CAAC,CAAC,IAAI;aACT,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACrB,CAAC;CACF;AAED,qBAAqB;AACrB,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { GLMClient, GLMClientError, GLMAuthError, GLMRateLimitError } from "./client";
|
|
2
|
+
export { StreamProcessor, processStream, processChunk, createStreamState, stateToMessage, getToolCalls, } from "./stream";
|
|
3
|
+
export type { StreamState, StreamEvent, StreamEventHandler, } from "./stream";
|
|
4
|
+
export type { GLMModel, MessageRole, ChatMessage, MessageContent, ToolCall, ToolDefinition, ChatCompletionRequest, ChatCompletionResponse, ChatCompletionChunk, ChatCompletionChoice, StreamChoice, StreamDelta, Usage, APIError, } from "./types";
|
|
5
|
+
export { GLMModel as GLMModelSchema, MessageRole as MessageRoleSchema, ChatMessage as ChatMessageSchema, ChatCompletionRequest as ChatCompletionRequestSchema, ChatCompletionResponse as ChatCompletionResponseSchema, ChatCompletionChunk as ChatCompletionChunkSchema, } from "./types";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGtF,OAAO,EACL,eAAe,EACf,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,YAAY,GACb,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,WAAW,EACX,WAAW,EACX,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAGlB,YAAY,EACV,QAAQ,EACR,WAAW,EACX,WAAW,EACX,cAAc,EACd,QAAQ,EACR,cAAc,EACd,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,WAAW,EACX,KAAK,EACL,QAAQ,GACT,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,QAAQ,IAAI,cAAc,EAC1B,WAAW,IAAI,iBAAiB,EAChC,WAAW,IAAI,iBAAiB,EAChC,qBAAqB,IAAI,2BAA2B,EACpD,sBAAsB,IAAI,4BAA4B,EACtD,mBAAmB,IAAI,yBAAyB,GACjD,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// GLM API Client
|
|
2
|
+
export { GLMClient, GLMClientError, GLMAuthError, GLMRateLimitError } from "./client";
|
|
3
|
+
// Streaming
|
|
4
|
+
export { StreamProcessor, processStream, processChunk, createStreamState, stateToMessage, getToolCalls, } from "./stream";
|
|
5
|
+
// Schemas (for validation)
|
|
6
|
+
export { GLMModel as GLMModelSchema, MessageRole as MessageRoleSchema, ChatMessage as ChatMessageSchema, ChatCompletionRequest as ChatCompletionRequestSchema, ChatCompletionResponse as ChatCompletionResponseSchema, ChatCompletionChunk as ChatCompletionChunkSchema, } from "./types";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAEtF,YAAY;AACZ,OAAO,EACL,eAAe,EACf,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,YAAY,GACb,MAAM,UAAU,CAAC;AA0BlB,2BAA2B;AAC3B,OAAO,EACL,QAAQ,IAAI,cAAc,EAC1B,WAAW,IAAI,iBAAiB,EAChC,WAAW,IAAI,iBAAiB,EAChC,qBAAqB,IAAI,2BAA2B,EACpD,sBAAsB,IAAI,4BAA4B,EACtD,mBAAmB,IAAI,yBAAyB,GACjD,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { ChatCompletionChunk, ChatMessage, ToolCall } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Streaming Handler
|
|
4
|
+
* Processes SSE chunks and aggregates content/reasoning
|
|
5
|
+
*/
|
|
6
|
+
export interface StreamState {
|
|
7
|
+
content: string;
|
|
8
|
+
reasoningContent: string;
|
|
9
|
+
role: ChatMessage["role"] | null;
|
|
10
|
+
toolCalls: Map<number, PartialToolCall>;
|
|
11
|
+
finishReason: "stop" | "length" | "tool_calls" | "content_filter" | null;
|
|
12
|
+
usage: {
|
|
13
|
+
promptTokens: number;
|
|
14
|
+
completionTokens: number;
|
|
15
|
+
totalTokens: number;
|
|
16
|
+
} | null;
|
|
17
|
+
}
|
|
18
|
+
interface PartialToolCall {
|
|
19
|
+
id: string;
|
|
20
|
+
functionName: string;
|
|
21
|
+
functionArguments: string;
|
|
22
|
+
}
|
|
23
|
+
export type StreamEvent = {
|
|
24
|
+
type: "content";
|
|
25
|
+
delta: string;
|
|
26
|
+
} | {
|
|
27
|
+
type: "reasoning";
|
|
28
|
+
delta: string;
|
|
29
|
+
} | {
|
|
30
|
+
type: "tool_call_start";
|
|
31
|
+
index: number;
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
} | {
|
|
35
|
+
type: "tool_call_delta";
|
|
36
|
+
index: number;
|
|
37
|
+
arguments: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: "done";
|
|
40
|
+
state: StreamState;
|
|
41
|
+
};
|
|
42
|
+
export type StreamEventHandler = (event: StreamEvent) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Create a new stream state
|
|
45
|
+
*/
|
|
46
|
+
export declare function createStreamState(): StreamState;
|
|
47
|
+
/**
|
|
48
|
+
* Process a single chunk and update state
|
|
49
|
+
* Returns events generated from this chunk
|
|
50
|
+
*/
|
|
51
|
+
export declare function processChunk(chunk: ChatCompletionChunk, state: StreamState): StreamEvent[];
|
|
52
|
+
/**
|
|
53
|
+
* Convert accumulated tool calls to final format
|
|
54
|
+
*/
|
|
55
|
+
export declare function getToolCalls(state: StreamState): ToolCall[];
|
|
56
|
+
/**
|
|
57
|
+
* Convert stream state to a complete ChatMessage
|
|
58
|
+
*/
|
|
59
|
+
export declare function stateToMessage(state: StreamState): ChatMessage;
|
|
60
|
+
/**
|
|
61
|
+
* High-level stream processor that handles async iteration
|
|
62
|
+
*/
|
|
63
|
+
export declare class StreamProcessor {
|
|
64
|
+
private state;
|
|
65
|
+
private eventHandler;
|
|
66
|
+
private abortController;
|
|
67
|
+
constructor();
|
|
68
|
+
/**
|
|
69
|
+
* Set event handler for real-time updates
|
|
70
|
+
*/
|
|
71
|
+
onEvent(handler: StreamEventHandler): this;
|
|
72
|
+
/**
|
|
73
|
+
* Get the current accumulated state
|
|
74
|
+
*/
|
|
75
|
+
getState(): StreamState;
|
|
76
|
+
/**
|
|
77
|
+
* Get abort signal for cancellation
|
|
78
|
+
*/
|
|
79
|
+
getAbortSignal(): AbortSignal;
|
|
80
|
+
/**
|
|
81
|
+
* Abort the stream
|
|
82
|
+
*/
|
|
83
|
+
abort(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Process an async iterable of chunks
|
|
86
|
+
*/
|
|
87
|
+
process(chunks: AsyncIterable<ChatCompletionChunk>): Promise<StreamState>;
|
|
88
|
+
/**
|
|
89
|
+
* Reset for reuse
|
|
90
|
+
*/
|
|
91
|
+
reset(): void;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Convenience function to process a stream and return the final message
|
|
95
|
+
*/
|
|
96
|
+
export declare function processStream(chunks: AsyncIterable<ChatCompletionChunk>, onEvent?: StreamEventHandler): Promise<ChatMessage>;
|
|
97
|
+
export {};
|
|
98
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/api/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE1E;;;GAGG;AAGH,MAAM,WAAW,WAAW;IAE1B,OAAO,EAAE,MAAM,CAAC;IAEhB,gBAAgB,EAAE,MAAM,CAAC;IAEzB,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IAEjC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAExC,YAAY,EAAE,MAAM,GAAG,QAAQ,GAAG,YAAY,GAAG,gBAAgB,GAAG,IAAI,CAAC;IAEzE,KAAK,EAAE;QACL,YAAY,EAAE,MAAM,CAAC;QACrB,gBAAgB,EAAE,MAAM,CAAC;QACzB,WAAW,EAAE,MAAM,CAAC;KACrB,GAAG,IAAI,CAAC;CACV;AAGD,UAAU,eAAe;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAGD,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACpE;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,KAAK,EAAE,MAAM,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