hypercore-cli 1.1.2 → 1.4.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 (162) hide show
  1. package/LICENSE +92 -21
  2. package/README.md +8 -1
  3. package/dist/App-YMX7FSXR.js +1 -0
  4. package/dist/api-ELP6F4NC.js +1 -0
  5. package/dist/auth-SICBMA3P.js +1 -0
  6. package/dist/auth-X6CUT3DW.js +1 -0
  7. package/dist/background-ACODXSUG.js +1 -0
  8. package/dist/backlog-JD2IM336.js +1 -0
  9. package/dist/chunk-2QI2IU2V.js +1 -0
  10. package/dist/chunk-3KFRDIPQ.js +1 -0
  11. package/dist/chunk-42C5J7PN.js +1 -0
  12. package/dist/chunk-4D7XVJ7Q.js +1 -0
  13. package/dist/chunk-5KUSGQP2.js +1 -0
  14. package/dist/chunk-5OEFAGD5.js +1 -0
  15. package/dist/chunk-AUQ64BK2.js +1 -0
  16. package/dist/chunk-AV244H5C.js +1 -0
  17. package/dist/chunk-BQVBEFS4.js +1 -0
  18. package/dist/chunk-BYWQLFP2.js +1 -0
  19. package/dist/chunk-C6YL7UHE.js +1 -0
  20. package/dist/chunk-COITWWZJ.js +1 -0
  21. package/dist/chunk-CR7UUJVX.js +1 -0
  22. package/dist/chunk-E3MULLBX.js +1 -0
  23. package/dist/chunk-EZHYVJGQ.js +1 -0
  24. package/dist/chunk-FAMURNNH.js +1 -0
  25. package/dist/chunk-FGP56E4W.js +1 -0
  26. package/dist/chunk-FHGATV5B.js +1 -0
  27. package/dist/chunk-I2G27Y5P.js +1 -0
  28. package/dist/chunk-IKF43TX2.js +1 -0
  29. package/dist/chunk-INSPHCBN.js +1 -0
  30. package/dist/chunk-JHMV366T.js +1 -0
  31. package/dist/chunk-L52HX5SX.js +1 -0
  32. package/dist/chunk-LQMDUKIE.js +1 -0
  33. package/dist/chunk-M3MTKGA5.js +1 -0
  34. package/dist/chunk-MPO54FU3.js +1 -0
  35. package/dist/chunk-PVKCZI6A.js +1 -0
  36. package/dist/chunk-Q7KEPCYL.js +1 -0
  37. package/dist/chunk-ROBZ6PAL.js +1 -0
  38. package/dist/chunk-RXB5BS2N.js +1 -0
  39. package/dist/chunk-RZ3HNYMT.js +1 -0
  40. package/dist/chunk-UCGLRMTG.js +1 -0
  41. package/dist/chunk-UEHJVRKB.js +1 -0
  42. package/dist/chunk-UZYX5GGF.js +1 -0
  43. package/dist/chunk-XQJBB725.js +1 -0
  44. package/dist/chunk-YXCRL6K3.js +1 -0
  45. package/dist/claude-US2QPRBA.js +1 -0
  46. package/dist/commands-EKPWCB3T.js +1 -0
  47. package/dist/commands-GYNKP5WV.js +1 -0
  48. package/dist/commands-QHJLREPM.js +1 -0
  49. package/dist/config-2OUL5FLS.js +1 -0
  50. package/dist/config-loader-N7IBWN2P.js +1 -0
  51. package/dist/diagnose-NLHN4SAJ.js +1 -0
  52. package/dist/display-RYAW2GFB.js +1 -0
  53. package/dist/extractor-3KTM2IUL.js +1 -0
  54. package/dist/feature-flag-VVIF5FJG.js +1 -0
  55. package/dist/history-3R2UHRDQ.js +1 -0
  56. package/dist/index.js +1 -402
  57. package/dist/instance-registry-I5AIVJE2.js +1 -0
  58. package/dist/keybindings-RN3A7CRW.js +1 -0
  59. package/dist/loader-3IKPXP4R.js +1 -0
  60. package/dist/network-K5HRJE44.js +1 -0
  61. package/dist/notify-O6FNVHC4.js +1 -0
  62. package/dist/openai-compat-IPCMINVF.js +1 -0
  63. package/dist/panels-2R5YEFXH.js +1 -0
  64. package/dist/permissions-5O7KVAXU.js +1 -0
  65. package/dist/prompt-VWFPFM4N.js +1 -0
  66. package/dist/quality-GPQD25UL.js +1 -0
  67. package/dist/repl-CL4SYHU4.js +1 -0
  68. package/dist/roadmap-QRZODSNJ.js +1 -0
  69. package/dist/server-PKOHK5M2.js +1 -0
  70. package/dist/session-5HDDQQP6.js +1 -0
  71. package/dist/skills-DXWSVJSU.js +1 -0
  72. package/dist/store-WXXTKTTL.js +1 -0
  73. package/dist/team-N2GF4YYS.js +1 -0
  74. package/dist/telemetry-NT4UZLBS.js +1 -0
  75. package/dist/test-runner-F6B6RH3S.js +1 -0
  76. package/dist/theme-JJJ6ABR2.js +1 -0
  77. package/dist/upgrade-RUG3R7R5.js +1 -0
  78. package/dist/verify-6OGRY2PR.js +1 -0
  79. package/dist/version-4RHTDUNQ.js +1 -0
  80. package/dist/web/static/app.js +1 -562
  81. package/dist/web/static/index.html +114 -126
  82. package/dist/web/static/mirror.css +1 -1001
  83. package/dist/web/static/mirror.html +155 -178
  84. package/dist/web/static/mirror.js +1 -1125
  85. package/dist/web/static/onboard.css +1 -302
  86. package/dist/web/static/onboard.html +121 -145
  87. package/dist/web/static/onboard.js +1 -300
  88. package/dist/web/static/style.css +1 -602
  89. package/dist/web/static/utils.js +1 -0
  90. package/dist/web/static/workspace.css +1 -1568
  91. package/dist/web/static/workspace.html +369 -402
  92. package/dist/web/static/workspace.js +1 -1683
  93. package/dist/web-CIC7ZKBM.js +1 -0
  94. package/package.json +26 -4
  95. package/dist/api-JHHOZTL6.js +0 -162
  96. package/dist/auth-5QFJLW7J.js +0 -21
  97. package/dist/background-2EGCAAQH.js +0 -14
  98. package/dist/backlog-Q2NZCLNY.js +0 -24
  99. package/dist/chunk-2CMSCWQW.js +0 -162
  100. package/dist/chunk-4DVYJAJL.js +0 -57
  101. package/dist/chunk-5GDYH676.js +0 -271
  102. package/dist/chunk-5NLVGLD7.js +0 -66
  103. package/dist/chunk-6XTEAFZQ.js +0 -575
  104. package/dist/chunk-AQBSMYLT.js +0 -2025
  105. package/dist/chunk-BE46C7JW.js +0 -46
  106. package/dist/chunk-CLKIMCXZ.js +0 -139
  107. package/dist/chunk-DN4ASQ26.js +0 -167
  108. package/dist/chunk-DUWREZXK.js +0 -173
  109. package/dist/chunk-FCW3K6F2.js +0 -263
  110. package/dist/chunk-GFORWAMW.js +0 -251
  111. package/dist/chunk-GH7E2OJE.js +0 -223
  112. package/dist/chunk-GU2FZQ6A.js +0 -69
  113. package/dist/chunk-I7WI3BMB.js +0 -161
  114. package/dist/chunk-IOPKN5GD.js +0 -190
  115. package/dist/chunk-LBVHDGZE.js +0 -133
  116. package/dist/chunk-MGLJ53QN.js +0 -219
  117. package/dist/chunk-NETIY5UB.js +0 -134
  118. package/dist/chunk-NP47L7LG.js +0 -288
  119. package/dist/chunk-O6MG7TOH.js +0 -58
  120. package/dist/chunk-OPZYEVYR.js +0 -150
  121. package/dist/chunk-R3GPQC7I.js +0 -393
  122. package/dist/chunk-R5T3A2NQ.js +0 -166
  123. package/dist/chunk-RKB2JOV2.js +0 -43
  124. package/dist/chunk-RNG3K465.js +0 -80
  125. package/dist/chunk-TGTYKBGC.js +0 -86
  126. package/dist/chunk-UCX4VZCT.js +0 -681
  127. package/dist/chunk-WHLVZCQY.js +0 -245
  128. package/dist/chunk-Y6HMJZDJ.js +0 -1505
  129. package/dist/chunk-ZSBHUGWR.js +0 -262
  130. package/dist/claude-4BX3MJSK.js +0 -12
  131. package/dist/commands-2X4OB5RF.js +0 -128
  132. package/dist/commands-GLBCEVQK.js +0 -1044
  133. package/dist/commands-IINRNBYX.js +0 -232
  134. package/dist/config-RSNQJQPS.js +0 -8
  135. package/dist/config-loader-SXO674TF.js +0 -24
  136. package/dist/diagnose-7UPLS7I4.js +0 -12
  137. package/dist/display-IIUBEYWN.js +0 -58
  138. package/dist/extractor-D3XWOAXI.js +0 -129
  139. package/dist/history-6I6FADAU.js +0 -180
  140. package/dist/index.d.ts +0 -1
  141. package/dist/instance-registry-J7UJ7U4Z.js +0 -15
  142. package/dist/keybindings-PDXIOV3O.js +0 -15
  143. package/dist/loader-GKEYT6Y7.js +0 -58
  144. package/dist/network-JYGHQXAR.js +0 -279
  145. package/dist/notify-HPTALZDC.js +0 -14
  146. package/dist/openai-compat-R7EKWG6Z.js +0 -12
  147. package/dist/permissions-JUKXMNDH.js +0 -10
  148. package/dist/prompt-UWHSZU4P.js +0 -166
  149. package/dist/quality-ST7PPNFR.js +0 -16
  150. package/dist/repl-QHIZ2JGF.js +0 -3374
  151. package/dist/roadmap-5OBEKROY.js +0 -17
  152. package/dist/server-HCNIP7ZQ.js +0 -57
  153. package/dist/session-5EBECDUP.js +0 -21
  154. package/dist/skills-HBQQTYO4.js +0 -175
  155. package/dist/store-FKUTR7GW.js +0 -25
  156. package/dist/team-7BBBP5YQ.js +0 -385
  157. package/dist/telemetry-6R4EIE6O.js +0 -30
  158. package/dist/test-runner-AUAGIBNM.js +0 -619
  159. package/dist/theme-3SYJ3UQA.js +0 -14
  160. package/dist/upgrade-MZFH7OCN.js +0 -83
  161. package/dist/verify-JUDKTPKZ.js +0 -14
  162. package/dist/web-KS3FUGJA.js +0 -39
@@ -1,271 +0,0 @@
1
- import {
2
- hookManager
3
- } from "./chunk-CLKIMCXZ.js";
4
-
5
- // src/llm/openai-compat.ts
6
- import OpenAI from "openai";
7
- function createOpenAIClient(config) {
8
- return new OpenAI({
9
- apiKey: config.apiKey,
10
- baseURL: config.baseURL
11
- });
12
- }
13
- async function triggerToolHook(event, context) {
14
- try {
15
- return await hookManager.trigger(event, context);
16
- } catch {
17
- return { intercepted: false };
18
- }
19
- }
20
- async function callOpenAILLM(client, options) {
21
- const {
22
- systemPrompt,
23
- userPrompt,
24
- tools,
25
- model = "gemini-2.5-flash",
26
- maxTokens = 8192,
27
- onText,
28
- onToolCall,
29
- onThinking,
30
- onToolCallDone
31
- } = options;
32
- const toolDefinitions = tools.map((t) => ({
33
- type: "function",
34
- function: {
35
- name: t.definition.name,
36
- description: t.definition.description,
37
- parameters: t.definition.input_schema
38
- }
39
- }));
40
- const messages = [
41
- { role: "system", content: systemPrompt },
42
- { role: "user", content: userPrompt }
43
- ];
44
- let totalOutput = "";
45
- let currentRoundText = "";
46
- const allToolCalls = [];
47
- let totalInputTokens = 0;
48
- let totalOutputTokens = 0;
49
- let maxIterations = 10;
50
- while (maxIterations-- > 0) {
51
- currentRoundText = "";
52
- const response = await client.chat.completions.create({
53
- model,
54
- max_tokens: maxTokens,
55
- messages,
56
- tools: toolDefinitions.length > 0 ? toolDefinitions : void 0
57
- });
58
- if (response.usage) {
59
- totalInputTokens += response.usage.prompt_tokens || 0;
60
- totalOutputTokens += response.usage.completion_tokens || 0;
61
- }
62
- const choice = response.choices[0];
63
- if (!choice) break;
64
- const message = choice.message;
65
- if (message.content) {
66
- totalOutput += message.content;
67
- currentRoundText += message.content;
68
- onText?.(message.content);
69
- }
70
- if (message.tool_calls && message.tool_calls.length > 0) {
71
- if (currentRoundText.trim()) {
72
- onThinking?.(currentRoundText.trim());
73
- }
74
- messages.push(message);
75
- for (const toolCall of message.tool_calls) {
76
- const fn = toolCall.function;
77
- const fnName = fn.name;
78
- let fnArgs = {};
79
- try {
80
- fnArgs = JSON.parse(fn.arguments || "{}");
81
- } catch {
82
- }
83
- const toolInputText = JSON.stringify(fnArgs);
84
- onToolCall?.(fnName, fnArgs);
85
- const tool = tools.find((t) => t.definition.name === fnName);
86
- let result;
87
- const toolStart = Date.now();
88
- const hookResult = await triggerToolHook("onToolCall", {
89
- model,
90
- toolName: fnName,
91
- toolInput: toolInputText
92
- });
93
- if (hookResult.intercepted) {
94
- result = `Error: Hook intercepted tool call - ${hookResult.reason || "blocked"}`;
95
- } else if (tool) {
96
- try {
97
- result = await tool.handler(fnArgs);
98
- } catch (err) {
99
- result = `Error: ${err instanceof Error ? err.message : String(err)}`;
100
- }
101
- } else {
102
- result = `Error: Tool "${fnName}" not found`;
103
- }
104
- const toolDuration = Date.now() - toolStart;
105
- onToolCallDone?.(fnName, toolDuration);
106
- await triggerToolHook("onToolResult", {
107
- model,
108
- toolName: fnName,
109
- toolInput: toolInputText,
110
- toolResult: result
111
- });
112
- allToolCalls.push({
113
- toolName: fnName,
114
- input: fnArgs,
115
- output: result
116
- });
117
- messages.push({
118
- role: "tool",
119
- tool_call_id: toolCall.id,
120
- content: result
121
- });
122
- }
123
- continue;
124
- }
125
- break;
126
- }
127
- return {
128
- output: totalOutput,
129
- responseText: allToolCalls.length > 0 ? currentRoundText : totalOutput,
130
- toolCalls: allToolCalls,
131
- tokenUsage: {
132
- inputTokens: totalInputTokens,
133
- outputTokens: totalOutputTokens
134
- }
135
- };
136
- }
137
- async function streamOpenAIChat(client, messages, options) {
138
- const { model, tools = [], onChunk, onToolCall, onThinking, onToolCallDone } = options;
139
- const toolDefinitions = tools.map((t) => ({
140
- type: "function",
141
- function: {
142
- name: t.definition.name,
143
- description: t.definition.description,
144
- parameters: t.definition.input_schema
145
- }
146
- }));
147
- let totalContent = "";
148
- let currentRoundContent = "";
149
- let hasCalledTools = false;
150
- let totalInputTokens = 0;
151
- let totalOutputTokens = 0;
152
- let maxIterations = 10;
153
- while (maxIterations-- > 0) {
154
- currentRoundContent = "";
155
- let stream;
156
- let lastError;
157
- for (let retry = 0; retry < 5; retry++) {
158
- try {
159
- stream = await client.chat.completions.create({
160
- model,
161
- max_tokens: 4096,
162
- messages,
163
- tools: toolDefinitions.length > 0 ? toolDefinitions : void 0,
164
- stream: true
165
- });
166
- lastError = null;
167
- break;
168
- } catch (err) {
169
- lastError = err;
170
- const status = err.status;
171
- if (status === 429) {
172
- const wait = (retry + 1) * 5e3;
173
- process.stdout.write(`\x1B[2m \u23F3 API \u9650\u6D41\uFF0C${wait / 1e3}s \u540E\u91CD\u8BD5...\x1B[0m
174
- `);
175
- await new Promise((r) => setTimeout(r, wait));
176
- continue;
177
- }
178
- throw err;
179
- }
180
- }
181
- if (lastError) throw lastError;
182
- let chunkContent = "";
183
- const toolCalls = /* @__PURE__ */ new Map();
184
- for await (const chunk of stream) {
185
- const delta = chunk.choices[0]?.delta;
186
- if (!delta) continue;
187
- if (delta.content) {
188
- chunkContent += delta.content;
189
- totalContent += delta.content;
190
- currentRoundContent += delta.content;
191
- onChunk?.(delta.content);
192
- }
193
- if (delta.tool_calls) {
194
- for (const tc of delta.tool_calls) {
195
- const existing = toolCalls.get(tc.index) || { id: "", name: "", args: "" };
196
- if (tc.id) existing.id = tc.id;
197
- if (tc.function?.name) existing.name = tc.function.name;
198
- if (tc.function?.arguments) existing.args += tc.function.arguments;
199
- toolCalls.set(tc.index, existing);
200
- }
201
- }
202
- if (chunk.usage) {
203
- totalInputTokens += chunk.usage.prompt_tokens || 0;
204
- totalOutputTokens += chunk.usage.completion_tokens || 0;
205
- }
206
- }
207
- if (toolCalls.size === 0) break;
208
- hasCalledTools = true;
209
- if (chunkContent.trim()) {
210
- onThinking?.(chunkContent.trim());
211
- }
212
- const assistantMessage = {
213
- role: "assistant",
214
- content: chunkContent || null,
215
- tool_calls: Array.from(toolCalls.values()).map((tc) => ({
216
- id: tc.id,
217
- type: "function",
218
- function: { name: tc.name, arguments: tc.args }
219
- }))
220
- };
221
- messages.push(assistantMessage);
222
- for (const [, tc] of toolCalls) {
223
- let fnArgs = {};
224
- try {
225
- fnArgs = JSON.parse(tc.args || "{}");
226
- } catch {
227
- }
228
- onToolCall?.(tc.name, fnArgs);
229
- const toolInputText = JSON.stringify(fnArgs);
230
- const tool = tools.find((t) => t.definition.name === tc.name);
231
- let result;
232
- const toolStart = Date.now();
233
- const hookResult = await triggerToolHook("onToolCall", {
234
- model,
235
- toolName: tc.name,
236
- toolInput: toolInputText
237
- });
238
- if (hookResult.intercepted) {
239
- result = `Error: Hook intercepted tool call - ${hookResult.reason || "blocked"}`;
240
- } else if (tool) {
241
- try {
242
- result = await tool.handler(fnArgs);
243
- } catch (err) {
244
- result = `Error: ${err instanceof Error ? err.message : String(err)}`;
245
- }
246
- } else {
247
- result = `Error: Tool "${tc.name}" not found`;
248
- }
249
- const toolDuration = Date.now() - toolStart;
250
- onToolCallDone?.(tc.name, toolDuration);
251
- await triggerToolHook("onToolResult", {
252
- model,
253
- toolName: tc.name,
254
- toolInput: toolInputText,
255
- toolResult: result
256
- });
257
- messages.push({ role: "tool", tool_call_id: tc.id, content: result });
258
- }
259
- }
260
- return {
261
- content: totalContent,
262
- responseContent: hasCalledTools ? currentRoundContent : totalContent,
263
- tokenUsage: { inputTokens: totalInputTokens, outputTokens: totalOutputTokens }
264
- };
265
- }
266
-
267
- export {
268
- createOpenAIClient,
269
- callOpenAILLM,
270
- streamOpenAIChat
271
- };
@@ -1,66 +0,0 @@
1
- import {
2
- HYPERCORE_DIR
3
- } from "./chunk-I7WI3BMB.js";
4
-
5
- // src/team/auth.ts
6
- import { randomBytes } from "crypto";
7
- import { readFile, writeFile, mkdir } from "fs/promises";
8
- import { existsSync } from "fs";
9
- import { join } from "path";
10
- function generateId() {
11
- return randomBytes(4).toString("hex");
12
- }
13
- function generateToken() {
14
- return randomBytes(8).toString("hex");
15
- }
16
- function generateJoinCode() {
17
- const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
18
- let code = "";
19
- const bytes = randomBytes(6);
20
- for (let i = 0; i < 6; i++) {
21
- code += chars[bytes[i] % chars.length];
22
- }
23
- return code;
24
- }
25
- function validateToken(team, token) {
26
- return team.members.find((m) => m.token === token) || null;
27
- }
28
- function isOwner(member) {
29
- return member.role === "owner";
30
- }
31
- var TOKEN_FILE = "team-token.json";
32
- function getTokenPath() {
33
- return join(HYPERCORE_DIR, TOKEN_FILE);
34
- }
35
- async function saveLocalToken(token) {
36
- await mkdir(HYPERCORE_DIR, { recursive: true });
37
- await writeFile(getTokenPath(), JSON.stringify(token, null, 2), "utf-8");
38
- }
39
- async function loadLocalToken() {
40
- const p = getTokenPath();
41
- if (!existsSync(p)) return null;
42
- try {
43
- const data = await readFile(p, "utf-8");
44
- return JSON.parse(data);
45
- } catch {
46
- return null;
47
- }
48
- }
49
- async function clearLocalToken() {
50
- const p = getTokenPath();
51
- if (existsSync(p)) {
52
- const { unlink } = await import("fs/promises");
53
- await unlink(p);
54
- }
55
- }
56
-
57
- export {
58
- generateId,
59
- generateToken,
60
- generateJoinCode,
61
- validateToken,
62
- isOwner,
63
- saveLocalToken,
64
- loadLocalToken,
65
- clearLocalToken
66
- };