@zds-ai/cli 0.1.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.
Files changed (204) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +497 -0
  3. package/dist/agent/grok-agent.d.ts +250 -0
  4. package/dist/agent/grok-agent.js +2480 -0
  5. package/dist/agent/grok-agent.js.map +1 -0
  6. package/dist/agent/index.d.ts +14 -0
  7. package/dist/agent/index.js +136 -0
  8. package/dist/agent/index.js.map +1 -0
  9. package/dist/commands/mcp.d.ts +2 -0
  10. package/dist/commands/mcp.js +239 -0
  11. package/dist/commands/mcp.js.map +1 -0
  12. package/dist/grok/client.d.ts +55 -0
  13. package/dist/grok/client.js +276 -0
  14. package/dist/grok/client.js.map +1 -0
  15. package/dist/grok/tools.d.ts +8 -0
  16. package/dist/grok/tools.js +878 -0
  17. package/dist/grok/tools.js.map +1 -0
  18. package/dist/hooks/use-enhanced-input.d.ts +38 -0
  19. package/dist/hooks/use-enhanced-input.js +228 -0
  20. package/dist/hooks/use-enhanced-input.js.map +1 -0
  21. package/dist/hooks/use-input-handler.d.ts +36 -0
  22. package/dist/hooks/use-input-handler.js +1099 -0
  23. package/dist/hooks/use-input-handler.js.map +1 -0
  24. package/dist/hooks/use-input-history.d.ts +9 -0
  25. package/dist/hooks/use-input-history.js +61 -0
  26. package/dist/hooks/use-input-history.js.map +1 -0
  27. package/dist/index.d.ts +2 -0
  28. package/dist/index.js +869 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/mcp/client.d.ts +41 -0
  31. package/dist/mcp/client.js +224 -0
  32. package/dist/mcp/client.js.map +1 -0
  33. package/dist/mcp/config.d.ts +13 -0
  34. package/dist/mcp/config.js +56 -0
  35. package/dist/mcp/config.js.map +1 -0
  36. package/dist/mcp/transports.d.ts +53 -0
  37. package/dist/mcp/transports.js +256 -0
  38. package/dist/mcp/transports.js.map +1 -0
  39. package/dist/tools/character-tool.d.ts +27 -0
  40. package/dist/tools/character-tool.js +194 -0
  41. package/dist/tools/character-tool.js.map +1 -0
  42. package/dist/tools/clear-cache-tool.d.ts +14 -0
  43. package/dist/tools/clear-cache-tool.js +82 -0
  44. package/dist/tools/clear-cache-tool.js.map +1 -0
  45. package/dist/tools/confirmation-tool.d.ts +16 -0
  46. package/dist/tools/confirmation-tool.js +72 -0
  47. package/dist/tools/confirmation-tool.js.map +1 -0
  48. package/dist/tools/env-tool.d.ts +17 -0
  49. package/dist/tools/env-tool.js +89 -0
  50. package/dist/tools/env-tool.js.map +1 -0
  51. package/dist/tools/file-conversion-tool.d.ts +16 -0
  52. package/dist/tools/file-conversion-tool.js +181 -0
  53. package/dist/tools/file-conversion-tool.js.map +1 -0
  54. package/dist/tools/image-tool.d.ts +22 -0
  55. package/dist/tools/image-tool.js +268 -0
  56. package/dist/tools/image-tool.js.map +1 -0
  57. package/dist/tools/index.d.ts +14 -0
  58. package/dist/tools/index.js +15 -0
  59. package/dist/tools/index.js.map +1 -0
  60. package/dist/tools/internet-tool.d.ts +11 -0
  61. package/dist/tools/internet-tool.js +108 -0
  62. package/dist/tools/internet-tool.js.map +1 -0
  63. package/dist/tools/introspect-tool.d.ts +11 -0
  64. package/dist/tools/introspect-tool.js +243 -0
  65. package/dist/tools/introspect-tool.js.map +1 -0
  66. package/dist/tools/morph-editor.d.ts +38 -0
  67. package/dist/tools/morph-editor.js +318 -0
  68. package/dist/tools/morph-editor.js.map +1 -0
  69. package/dist/tools/restart-tool.d.ts +7 -0
  70. package/dist/tools/restart-tool.js +24 -0
  71. package/dist/tools/restart-tool.js.map +1 -0
  72. package/dist/tools/search.d.ts +71 -0
  73. package/dist/tools/search.js +340 -0
  74. package/dist/tools/search.js.map +1 -0
  75. package/dist/tools/task-tool.d.ts +19 -0
  76. package/dist/tools/task-tool.js +115 -0
  77. package/dist/tools/task-tool.js.map +1 -0
  78. package/dist/tools/text-editor.d.ts +35 -0
  79. package/dist/tools/text-editor.js +669 -0
  80. package/dist/tools/text-editor.js.map +1 -0
  81. package/dist/tools/tool-discovery.d.ts +20 -0
  82. package/dist/tools/tool-discovery.js +45 -0
  83. package/dist/tools/tool-discovery.js.map +1 -0
  84. package/dist/tools/zsh.d.ts +13 -0
  85. package/dist/tools/zsh.js +168 -0
  86. package/dist/tools/zsh.js.map +1 -0
  87. package/dist/types/index.d.ts +31 -0
  88. package/dist/types/index.js +2 -0
  89. package/dist/types/index.js.map +1 -0
  90. package/dist/ui/app.d.ts +7 -0
  91. package/dist/ui/app.js +99 -0
  92. package/dist/ui/app.js.map +1 -0
  93. package/dist/ui/components/active-task-status.d.ts +7 -0
  94. package/dist/ui/components/active-task-status.js +37 -0
  95. package/dist/ui/components/active-task-status.js.map +1 -0
  96. package/dist/ui/components/api-key-input.d.ts +7 -0
  97. package/dist/ui/components/api-key-input.js +80 -0
  98. package/dist/ui/components/api-key-input.js.map +1 -0
  99. package/dist/ui/components/backend-status.d.ts +7 -0
  100. package/dist/ui/components/backend-status.js +85 -0
  101. package/dist/ui/components/backend-status.js.map +1 -0
  102. package/dist/ui/components/chat-history.d.ts +8 -0
  103. package/dist/ui/components/chat-history.js +187 -0
  104. package/dist/ui/components/chat-history.js.map +1 -0
  105. package/dist/ui/components/chat-input.d.ts +9 -0
  106. package/dist/ui/components/chat-input.js +63 -0
  107. package/dist/ui/components/chat-input.js.map +1 -0
  108. package/dist/ui/components/chat-interface.d.ts +9 -0
  109. package/dist/ui/components/chat-interface.js +389 -0
  110. package/dist/ui/components/chat-interface.js.map +1 -0
  111. package/dist/ui/components/command-suggestions.d.ts +17 -0
  112. package/dist/ui/components/command-suggestions.js +22 -0
  113. package/dist/ui/components/command-suggestions.js.map +1 -0
  114. package/dist/ui/components/confirmation-dialog.d.ts +11 -0
  115. package/dist/ui/components/confirmation-dialog.js +105 -0
  116. package/dist/ui/components/confirmation-dialog.js.map +1 -0
  117. package/dist/ui/components/context-status.d.ts +7 -0
  118. package/dist/ui/components/context-status.js +36 -0
  119. package/dist/ui/components/context-status.js.map +1 -0
  120. package/dist/ui/components/diff-renderer.d.ts +13 -0
  121. package/dist/ui/components/diff-renderer.js +206 -0
  122. package/dist/ui/components/diff-renderer.js.map +1 -0
  123. package/dist/ui/components/loading-spinner.d.ts +8 -0
  124. package/dist/ui/components/loading-spinner.js +64 -0
  125. package/dist/ui/components/loading-spinner.js.map +1 -0
  126. package/dist/ui/components/mcp-status.d.ts +5 -0
  127. package/dist/ui/components/mcp-status.js +57 -0
  128. package/dist/ui/components/mcp-status.js.map +1 -0
  129. package/dist/ui/components/model-selection.d.ts +12 -0
  130. package/dist/ui/components/model-selection.js +17 -0
  131. package/dist/ui/components/model-selection.js.map +1 -0
  132. package/dist/ui/components/mood-status.d.ts +7 -0
  133. package/dist/ui/components/mood-status.js +34 -0
  134. package/dist/ui/components/mood-status.js.map +1 -0
  135. package/dist/ui/components/persona-status.d.ts +7 -0
  136. package/dist/ui/components/persona-status.js +34 -0
  137. package/dist/ui/components/persona-status.js.map +1 -0
  138. package/dist/ui/shared/max-sized-box.d.ts +8 -0
  139. package/dist/ui/shared/max-sized-box.js +6 -0
  140. package/dist/ui/shared/max-sized-box.js.map +1 -0
  141. package/dist/ui/utils/code-colorizer.d.ts +2 -0
  142. package/dist/ui/utils/code-colorizer.js +7 -0
  143. package/dist/ui/utils/code-colorizer.js.map +1 -0
  144. package/dist/ui/utils/colors.d.ts +14 -0
  145. package/dist/ui/utils/colors.js +15 -0
  146. package/dist/ui/utils/colors.js.map +1 -0
  147. package/dist/ui/utils/markdown-renderer.d.ts +4 -0
  148. package/dist/ui/utils/markdown-renderer.js +40 -0
  149. package/dist/ui/utils/markdown-renderer.js.map +1 -0
  150. package/dist/utils/auth-helper.d.ts +63 -0
  151. package/dist/utils/auth-helper.js +129 -0
  152. package/dist/utils/auth-helper.js.map +1 -0
  153. package/dist/utils/chat-history-manager-sqlite.d.ts +92 -0
  154. package/dist/utils/chat-history-manager-sqlite.js +334 -0
  155. package/dist/utils/chat-history-manager-sqlite.js.map +1 -0
  156. package/dist/utils/chat-history-manager.d.ts +87 -0
  157. package/dist/utils/chat-history-manager.js +273 -0
  158. package/dist/utils/chat-history-manager.js.map +1 -0
  159. package/dist/utils/chat-history-manager.json-backup.d.ts +69 -0
  160. package/dist/utils/chat-history-manager.json-backup.js +215 -0
  161. package/dist/utils/chat-history-manager.json-backup.js.map +1 -0
  162. package/dist/utils/confirmation-service.d.ts +46 -0
  163. package/dist/utils/confirmation-service.js +165 -0
  164. package/dist/utils/confirmation-service.js.map +1 -0
  165. package/dist/utils/custom-instructions.d.ts +1 -0
  166. package/dist/utils/custom-instructions.js +30 -0
  167. package/dist/utils/custom-instructions.js.map +1 -0
  168. package/dist/utils/database-connection.d.ts +27 -0
  169. package/dist/utils/database-connection.js +81 -0
  170. package/dist/utils/database-connection.js.map +1 -0
  171. package/dist/utils/database-schema.d.ts +17 -0
  172. package/dist/utils/database-schema.js +93 -0
  173. package/dist/utils/database-schema.js.map +1 -0
  174. package/dist/utils/error-logger.d.ts +13 -0
  175. package/dist/utils/error-logger.js +56 -0
  176. package/dist/utils/error-logger.js.map +1 -0
  177. package/dist/utils/hook-executor.d.ts +59 -0
  178. package/dist/utils/hook-executor.js +351 -0
  179. package/dist/utils/hook-executor.js.map +1 -0
  180. package/dist/utils/model-config.d.ts +28 -0
  181. package/dist/utils/model-config.js +42 -0
  182. package/dist/utils/model-config.js.map +1 -0
  183. package/dist/utils/path-utils.d.ts +4 -0
  184. package/dist/utils/path-utils.js +12 -0
  185. package/dist/utils/path-utils.js.map +1 -0
  186. package/dist/utils/settings-manager.d.ts +169 -0
  187. package/dist/utils/settings-manager.js +403 -0
  188. package/dist/utils/settings-manager.js.map +1 -0
  189. package/dist/utils/settings.d.ts +1 -0
  190. package/dist/utils/settings.js +4 -0
  191. package/dist/utils/settings.js.map +1 -0
  192. package/dist/utils/slash-commands.d.ts +25 -0
  193. package/dist/utils/slash-commands.js +454 -0
  194. package/dist/utils/slash-commands.js.map +1 -0
  195. package/dist/utils/startup-hook.d.ts +13 -0
  196. package/dist/utils/startup-hook.js +44 -0
  197. package/dist/utils/startup-hook.js.map +1 -0
  198. package/dist/utils/text-utils.d.ts +80 -0
  199. package/dist/utils/text-utils.js +182 -0
  200. package/dist/utils/text-utils.js.map +1 -0
  201. package/dist/utils/token-counter.d.ts +33 -0
  202. package/dist/utils/token-counter.js +78 -0
  203. package/dist/utils/token-counter.js.map +1 -0
  204. package/package.json +102 -0
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Text manipulation utilities for terminal input handling
3
+ * Inspired by Gemini CLI's text processing capabilities
4
+ */
5
+ /**
6
+ * Check if a character is a word boundary
7
+ */
8
+ export function isWordBoundary(char) {
9
+ if (!char)
10
+ return true;
11
+ return /\s/.test(char) || /[^\w]/.test(char);
12
+ }
13
+ /**
14
+ * Find the start of the current word at the given position
15
+ */
16
+ export function findWordStart(text, position) {
17
+ if (position <= 0)
18
+ return 0;
19
+ let pos = position - 1;
20
+ while (pos > 0 && !isWordBoundary(text[pos])) {
21
+ pos--;
22
+ }
23
+ // If we stopped at a word boundary, move forward to the actual word start
24
+ if (pos > 0 && isWordBoundary(text[pos])) {
25
+ pos++;
26
+ }
27
+ return pos;
28
+ }
29
+ /**
30
+ * Find the end of the current word at the given position
31
+ */
32
+ export function findWordEnd(text, position) {
33
+ if (position >= text.length)
34
+ return text.length;
35
+ let pos = position;
36
+ while (pos < text.length && !isWordBoundary(text[pos])) {
37
+ pos++;
38
+ }
39
+ return pos;
40
+ }
41
+ /**
42
+ * Move cursor to the previous word boundary
43
+ */
44
+ export function moveToPreviousWord(text, position) {
45
+ if (position <= 0)
46
+ return 0;
47
+ let pos = position - 1;
48
+ // Skip whitespace
49
+ while (pos > 0 && isWordBoundary(text[pos])) {
50
+ pos--;
51
+ }
52
+ // Find start of the word
53
+ while (pos > 0 && !isWordBoundary(text[pos - 1])) {
54
+ pos--;
55
+ }
56
+ return pos;
57
+ }
58
+ /**
59
+ * Move cursor to the next word boundary
60
+ */
61
+ export function moveToNextWord(text, position) {
62
+ if (position >= text.length)
63
+ return text.length;
64
+ let pos = position;
65
+ // Skip current word
66
+ while (pos < text.length && !isWordBoundary(text[pos])) {
67
+ pos++;
68
+ }
69
+ // Skip whitespace
70
+ while (pos < text.length && isWordBoundary(text[pos])) {
71
+ pos++;
72
+ }
73
+ return pos;
74
+ }
75
+ /**
76
+ * Delete the word before the cursor
77
+ */
78
+ export function deleteWordBefore(text, position) {
79
+ const wordStart = moveToPreviousWord(text, position);
80
+ const newText = text.slice(0, wordStart) + text.slice(position);
81
+ return {
82
+ text: newText,
83
+ position: wordStart,
84
+ };
85
+ }
86
+ /**
87
+ * Delete the word after the cursor
88
+ */
89
+ export function deleteWordAfter(text, position) {
90
+ const wordEnd = moveToNextWord(text, position);
91
+ const newText = text.slice(0, position) + text.slice(wordEnd);
92
+ return {
93
+ text: newText,
94
+ position,
95
+ };
96
+ }
97
+ /**
98
+ * Get the current line and column from text position
99
+ */
100
+ export function getTextPosition(text, index) {
101
+ const lines = text.slice(0, index).split('\n');
102
+ return {
103
+ index,
104
+ line: lines.length - 1,
105
+ column: lines[lines.length - 1].length,
106
+ };
107
+ }
108
+ /**
109
+ * Move to the beginning of the current line
110
+ */
111
+ export function moveToLineStart(text, position) {
112
+ const beforeCursor = text.slice(0, position);
113
+ const lastNewlineIndex = beforeCursor.lastIndexOf('\n');
114
+ return lastNewlineIndex === -1 ? 0 : lastNewlineIndex + 1;
115
+ }
116
+ /**
117
+ * Move to the end of the current line
118
+ */
119
+ export function moveToLineEnd(text, position) {
120
+ const afterCursor = text.slice(position);
121
+ const nextNewlineIndex = afterCursor.indexOf('\n');
122
+ return nextNewlineIndex === -1 ? text.length : position + nextNewlineIndex;
123
+ }
124
+ /**
125
+ * Handle proper Unicode-aware character deletion
126
+ */
127
+ export function deleteCharBefore(text, position) {
128
+ if (position <= 0) {
129
+ return { text, position };
130
+ }
131
+ // Handle surrogate pairs and combining characters
132
+ let deleteCount = 1;
133
+ const charBefore = text.charAt(position - 1);
134
+ // Check for high surrogate (first part of surrogate pair)
135
+ if (position >= 2) {
136
+ const charBeforeBefore = text.charAt(position - 2);
137
+ if (charBeforeBefore >= '\uD800' && charBeforeBefore <= '\uDBFF' &&
138
+ charBefore >= '\uDC00' && charBefore <= '\uDFFF') {
139
+ deleteCount = 2;
140
+ }
141
+ }
142
+ const newText = text.slice(0, position - deleteCount) + text.slice(position);
143
+ return {
144
+ text: newText,
145
+ position: position - deleteCount,
146
+ };
147
+ }
148
+ /**
149
+ * Handle proper Unicode-aware character deletion forward
150
+ */
151
+ export function deleteCharAfter(text, position) {
152
+ if (position >= text.length) {
153
+ return { text, position };
154
+ }
155
+ // Handle surrogate pairs and combining characters
156
+ let deleteCount = 1;
157
+ const charAfter = text.charAt(position);
158
+ // Check for high surrogate (first part of surrogate pair)
159
+ if (position + 1 < text.length) {
160
+ const charAfterAfter = text.charAt(position + 1);
161
+ if (charAfter >= '\uD800' && charAfter <= '\uDBFF' &&
162
+ charAfterAfter >= '\uDC00' && charAfterAfter <= '\uDFFF') {
163
+ deleteCount = 2;
164
+ }
165
+ }
166
+ const newText = text.slice(0, position) + text.slice(position + deleteCount);
167
+ return {
168
+ text: newText,
169
+ position,
170
+ };
171
+ }
172
+ /**
173
+ * Insert text at the given position with proper Unicode handling
174
+ */
175
+ export function insertText(text, position, insert) {
176
+ const newText = text.slice(0, position) + insert + text.slice(position);
177
+ return {
178
+ text: newText,
179
+ position: position + insert.length,
180
+ };
181
+ }
182
+ //# sourceMappingURL=text-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-utils.js","sourceRoot":"","sources":["../../src/utils/text-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAaH;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,IAAwB;IACrD,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAA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I,cAAc,IAAI,QAAQ,EAAE,CAAC;YAC7D,WAAW,GAAG,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,WAAW,CAAC,CAAC;IAC7E,OAAO;QACL,IAAI,EAAE,OAAO;QACb,QAAQ;KACT,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,QAAgB,EAAE,MAAc;IACvE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACxE,OAAO;QACL,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM;KACnC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,33 @@
1
+ export declare class TokenCounter {
2
+ private encoder;
3
+ constructor(model?: string);
4
+ /**
5
+ * Count tokens in a string
6
+ */
7
+ countTokens(text: string): number;
8
+ /**
9
+ * Count tokens in messages array (for chat completions)
10
+ */
11
+ countMessageTokens(messages: Array<{
12
+ role: string;
13
+ content: string | null;
14
+ [key: string]: any;
15
+ }>): number;
16
+ /**
17
+ * Estimate tokens for streaming content
18
+ * This is an approximation since we don't have the full response yet
19
+ */
20
+ estimateStreamingTokens(accumulatedContent: string): number;
21
+ /**
22
+ * Clean up resources
23
+ */
24
+ dispose(): void;
25
+ }
26
+ /**
27
+ * Format token count for display (e.g., 1.2k for 1200)
28
+ */
29
+ export declare function formatTokenCount(count: number): string;
30
+ /**
31
+ * Create a token counter instance
32
+ */
33
+ export declare function createTokenCounter(model?: string): TokenCounter;
@@ -0,0 +1,78 @@
1
+ import { get_encoding, encoding_for_model } from 'tiktoken';
2
+ export class TokenCounter {
3
+ encoder;
4
+ constructor(model = 'gpt-4') {
5
+ try {
6
+ // Try to get encoding for specific model
7
+ this.encoder = encoding_for_model(model);
8
+ }
9
+ catch {
10
+ // Fallback to cl100k_base (used by GPT-4 and most modern models)
11
+ this.encoder = get_encoding('cl100k_base');
12
+ }
13
+ }
14
+ /**
15
+ * Count tokens in a string
16
+ */
17
+ countTokens(text) {
18
+ if (!text)
19
+ return 0;
20
+ return this.encoder.encode(text, "all").length;
21
+ }
22
+ /**
23
+ * Count tokens in messages array (for chat completions)
24
+ */
25
+ countMessageTokens(messages) {
26
+ let totalTokens = 0;
27
+ for (const message of messages) {
28
+ // Every message follows <|start|>{role/name}\n{content}<|end|\>\n
29
+ totalTokens += 3; // Base tokens per message
30
+ if (message.content && typeof message.content === 'string') {
31
+ totalTokens += this.countTokens(message.content);
32
+ }
33
+ if (message.role) {
34
+ totalTokens += this.countTokens(message.role);
35
+ }
36
+ // Add extra tokens for tool calls if present
37
+ if (message.tool_calls) {
38
+ totalTokens += this.countTokens(JSON.stringify(message.tool_calls));
39
+ }
40
+ }
41
+ totalTokens += 3; // Every reply is primed with <|start|>assistant<|message|>
42
+ return totalTokens;
43
+ }
44
+ /**
45
+ * Estimate tokens for streaming content
46
+ * This is an approximation since we don't have the full response yet
47
+ */
48
+ estimateStreamingTokens(accumulatedContent) {
49
+ return this.countTokens(accumulatedContent);
50
+ }
51
+ /**
52
+ * Clean up resources
53
+ */
54
+ dispose() {
55
+ this.encoder.free();
56
+ }
57
+ }
58
+ /**
59
+ * Format token count for display (e.g., 1.2k for 1200)
60
+ */
61
+ export function formatTokenCount(count) {
62
+ if (count <= 999) {
63
+ return count.toString();
64
+ }
65
+ if (count < 1_000_000) {
66
+ const k = count / 1000;
67
+ return k % 1 === 0 ? `${k}k` : `${k.toFixed(1)}k`;
68
+ }
69
+ const m = count / 1_000_000;
70
+ return m % 1 === 0 ? `${m}m` : `${m.toFixed(1)}m`;
71
+ }
72
+ /**
73
+ * Create a token counter instance
74
+ */
75
+ export function createTokenCounter(model) {
76
+ return new TokenCounter(model);
77
+ }
78
+ //# sourceMappingURL=token-counter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-counter.js","sourceRoot":"","sources":["../../src/utils/token-counter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAY,MAAM,UAAU,CAAC;AAEtE,MAAM,OAAO,YAAY;IACf,OAAO,CAAW;IAE1B,YAAY,QAAgB,OAAO;QACjC,IAAI,CAAC;YACH,yCAAyC;YACzC,IAAI,CAAC,OAAO,GAAG,kBAAkB,CAAC,KAAY,CAAC,CAAC;QAClD,CAAC;QAAC,MAAM,CAAC;YACP,iEAAiE;YACjE,IAAI,CAAC,OAAO,GAAG,YAAY,CAAC,aAAa,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,WAAW,CAAC,IAAY;QACtB,IAAI,CAAC,IAAI;YAAE,OAAO,CAAC,CAAC;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,kBAAkB,CAAC,QAA6E;QAC9F,IAAI,WAAW,GAAG,CAAC,CAAC;QAEpB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,kEAAkE;YAClE,WAAW,IAAI,CAAC,CAAC,CAAC,0BAA0B;YAE5C,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;gBAC3D,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACnD,CAAC;YAED,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;gBACjB,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAChD,CAAC;YAED,6CAA6C;YAC7C,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;gB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porting OpenAI, Anthropic, Grok, Ollama, and more.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
13
+ "bin": {
14
+ "zai-cli": "dist/index.js"
15
+ },
16
+ "scripts": {
17
+ "build": "tsc",
18
+ "build:bun": "bun run tsc",
19
+ "dev": "bun run src/index.ts",
20
+ "dev:node": "tsx src/index.ts",
21
+ "start": "node dist/index.js",
22
+ "start:bun": "bun run dist/index.js",
23
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
24
+ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
25
+ "test:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --coverage",
26
+ "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
27
+ "typecheck": "tsc --noEmit",
28
+ "install:bun": "bun install"
29
+ },
30
+ "keywords": [
31
+ "agent",
32
+ "ai",
33
+ "archgw",
34
+ "arliai",
35
+ "cli",
36
+ "grok",
37
+ "multi-backend",
38
+ "nanogpt",
39
+ "ollama",
40
+ "openai",
41
+ "openrouter",
42
+ "venice"
43
+ ],
44
+ "author": "The ZDS Group",
45
+ "license": "MIT",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/ziquid/zds-ai-cli.git"
49
+ },
50
+ "bugs": {
51
+ "url": "https://github.com/ziquid/zds-ai-cli/issues"
52
+ },
53
+ "homepage": "https://github.com/ziquid/zds-ai-cli#readme",
54
+ "files": [
55
+ "dist",
56
+ "README.md",
57
+ "LICENSE"
58
+ ],
59
+ "dependencies": {
60
+ "@modelcontextprotocol/sdk": "^1.17.0",
61
+ "axios": "^1.7.0",
62
+ "cfonts": "^3.3.0",
63
+ "chalk": "^5.3.0",
64
+ "commander": "^12.0.0",
65
+ "dotenv": "^16.4.0",
66
+ "enquirer": "^2.4.1",
67
+ "fs-extra": "^11.2.0",
68
+ "ink": "^4.4.1",
69
+ "ink-spawn": "^0.1.4",
70
+ "marked": "^15.0.12",
71
+ "marked-terminal": "^7.3.0",
72
+ "openai": "^5.10.1",
73
+ "prompts": "^2.4.2",
74
+ "react": "^18.3.1",
75
+ "ripgrep-node": "^1.0.0",
76
+ "tiktoken": "^1.0.21"
77
+ },
78
+ "devDependencies": {
79
+ "@types/fs-extra": "^11.0.2",
80
+ "@types/jest": "^30.0.0",
81
+ "@types/node": "^20.8.0",
82
+ "@types/prompts": "^2.4.9",
83
+ "@types/react": "^18.3.3",
84
+ "@typescript-eslint/eslint-plugin": "^8.37.0",
85
+ "@typescript-eslint/parser": "^8.37.0",
86
+ "eslint": "^9.39.1",
87
+ "jest": "^30.2.0",
88
+ "ts-jest": "^29.4.5",
89
+ "tsx": "^4.0.0",
90
+ "typescript": "^5.3.3"
91
+ },
92
+ "engines": {
93
+ "node": ">=18.0.0",
94
+ "bun": ">=1.0.0"
95
+ },
96
+ "packageManager": "bun@1.1.0",
97
+ "preferGlobal": true,
98
+ "overrides": {
99
+ "js-yaml": "^4.1.1",
100
+ "glob": "^10.5.0"
101
+ }
102
+ }