zen-code 4.10.0 → 4.10.1

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 (83) hide show
  1. package/dist/app.js +2615 -157
  2. package/dist/cli.js +3116 -1
  3. package/dist/nonInteractive.js +1950 -180
  4. package/dist/zen-keyboard.js +358 -3
  5. package/package.json +1 -1
  6. package/dist/chunk-075hks9v.js +0 -1
  7. package/dist/chunk-0fj768k4.js +0 -112
  8. package/dist/chunk-19mf2aa7.js +0 -1
  9. package/dist/chunk-1mq2jmfy.js +0 -2
  10. package/dist/chunk-1v863afn.js +0 -278
  11. package/dist/chunk-1vn8d8b8.js +0 -1
  12. package/dist/chunk-1w19w1bm.js +0 -2
  13. package/dist/chunk-3dnayvgx.js +0 -224
  14. package/dist/chunk-4hg13vwj.js +0 -1
  15. package/dist/chunk-4scrkcqv.js +0 -1
  16. package/dist/chunk-54cdhhqm.js +0 -1
  17. package/dist/chunk-5m4yb9av.js +0 -91
  18. package/dist/chunk-5yd4ntp6.js +0 -8
  19. package/dist/chunk-6scjjkn3.js +0 -23
  20. package/dist/chunk-7jatn15w.js +0 -2
  21. package/dist/chunk-7w9y11hj.js +0 -88
  22. package/dist/chunk-7yzv6385.js +0 -1
  23. package/dist/chunk-875hayaj.js +0 -3
  24. package/dist/chunk-8bs8r50r.js +0 -1
  25. package/dist/chunk-8waww0j9.js +0 -6
  26. package/dist/chunk-8ysg0rga.js +0 -1
  27. package/dist/chunk-9czhw5k6.js +0 -4
  28. package/dist/chunk-9tgp14v7.js +0 -16
  29. package/dist/chunk-a239dn0b.js +0 -1
  30. package/dist/chunk-arv4h3h1.js +0 -2
  31. package/dist/chunk-b2551zfb.js +0 -2
  32. package/dist/chunk-b9emn03n.js +0 -1
  33. package/dist/chunk-bm7578sn.js +0 -1
  34. package/dist/chunk-bytq4kd1.js +0 -176
  35. package/dist/chunk-c2wfgbj6.js +0 -1
  36. package/dist/chunk-cef4vbtb.js +0 -26
  37. package/dist/chunk-cnzhxgn5.js +0 -4
  38. package/dist/chunk-d2770b2z.js +0 -1
  39. package/dist/chunk-d72063sm.js +0 -2
  40. package/dist/chunk-d988tv30.js +0 -1
  41. package/dist/chunk-dx9k6sdd.js +0 -7
  42. package/dist/chunk-e6ggkg36.js +0 -2
  43. package/dist/chunk-fjqtrakn.js +0 -1
  44. package/dist/chunk-gbfpab0j.js +0 -1
  45. package/dist/chunk-gkvx829z.js +0 -1
  46. package/dist/chunk-gwf8b14k.js +0 -3
  47. package/dist/chunk-gz7fz9fg.js +0 -1
  48. package/dist/chunk-h0q3dvnv.js +0 -5
  49. package/dist/chunk-h0qb9jk1.js +0 -1
  50. package/dist/chunk-h9y136h8.js +0 -1
  51. package/dist/chunk-hrcxdj3c.js +0 -54
  52. package/dist/chunk-hz9yw7cs.js +0 -166
  53. package/dist/chunk-j4y5rjne.js +0 -79
  54. package/dist/chunk-k12y05c3.js +0 -3
  55. package/dist/chunk-k6fxqssr.js +0 -18
  56. package/dist/chunk-kmxdq21k.js +0 -2
  57. package/dist/chunk-mcb8rewr.js +0 -213
  58. package/dist/chunk-mm9w91rj.js +0 -4
  59. package/dist/chunk-mv0xzmq8.js +0 -2
  60. package/dist/chunk-n849zsd3.js +0 -1
  61. package/dist/chunk-nm253hhf.js +0 -81
  62. package/dist/chunk-prg6489q.js +0 -1
  63. package/dist/chunk-pxdgy0vr.js +0 -2
  64. package/dist/chunk-qhzm2qw9.js +0 -2
  65. package/dist/chunk-qmxtys9q.js +0 -2
  66. package/dist/chunk-r0cfe5c1.js +0 -294
  67. package/dist/chunk-rtjytfhh.js +0 -1
  68. package/dist/chunk-s7ttf0pm.js +0 -2
  69. package/dist/chunk-t01t72t2.js +0 -140
  70. package/dist/chunk-t0f66x64.js +0 -1
  71. package/dist/chunk-tn356gwf.js +0 -93
  72. package/dist/chunk-vd8kwzra.js +0 -41
  73. package/dist/chunk-vhn13anh.js +0 -233
  74. package/dist/chunk-vnewbtjy.js +0 -1
  75. package/dist/chunk-wbm7rn9w.js +0 -2
  76. package/dist/chunk-wd3gkd45.js +0 -3
  77. package/dist/chunk-whdf0vbb.js +0 -1
  78. package/dist/chunk-ws232ksq.js +0 -2
  79. package/dist/chunk-yerf10k7.js +0 -6
  80. package/dist/chunk-yzv3n8mw.js +0 -2
  81. package/dist/chunk-z3e4c424.js +0 -2
  82. package/dist/chunk-znw7fpep.js +0 -6
  83. package/dist/chunk-zq2g4rfd.js +0 -1
@@ -1,233 +0,0 @@
1
- import{ef as y,gf as p}from"./chunk-mcb8rewr.js";import{xf as f}from"./chunk-1mq2jmfy.js";import{Lf as v,Nf as x}from"./chunk-3dnayvgx.js";import{Kl as s}from"./chunk-z3e4c424.js";async function w(e){let o=(t)=>{return t.stateSchema=f,t},a={id:"filesystem",name:"filesystem",description:"File and directory operations (read, write, search, glob)",execute:async()=>{return o(new y)}};await e.addMiddleware(a),e.middlewares.registerImplementation(a);let i={id:"terminal",name:"terminal",description:"Terminal command execution (Bash/CMD, background processes)",execute:async()=>{return o(new p)}};await e.addMiddleware(i),e.middlewares.registerImplementation(i);let r={id:"subagents",name:"subagents",description:"Task delegation to specialized agents",execute:async()=>{let{createSubAgentsMiddleware:t}=await import("./chunk-zq2g4rfd.js");return await t(e)}};await e.addMiddleware(r),e.middlewares.registerImplementation(r);let l={id:"skills",name:"skills",description:"Progressive skills disclosure",execute:async(t)=>{if(t.projectSkillsDir=t.projectSkillsDir||"./.claude/skills",!t.skillsDir){let R=await import("os"),Y=await import("path");t.skillsDir=Y.join(R.homedir(),".claude","skills")}let{SkillsMiddleware:n}=await import("./chunk-8bs8r50r.js");return new n(t)}};await e.addMiddleware(l),e.middlewares.registerImplementation(l);let u={id:"agents_md",name:"agents_md",description:"Inject agent documentation",execute:async(t)=>{let{AgentsMdMiddleware:n}=await import("./chunk-8bs8r50r.js");return new n({projectRoot:t?.projectRoot})}};await e.addMiddleware(u),e.middlewares.registerImplementation(u);let h={id:"interactive",name:"interactive",description:"User interaction for approval and input",execute:async()=>{let{InteractiveMiddleware:t}=await import("./chunk-7yzv6385.js");return t}};await e.addMiddleware(h),e.middlewares.registerImplementation(h);let c={id:"task",name:"task",description:"Task management for todo lists",execute:async()=>{let{taskMiddleware:t}=await import("./chunk-c2wfgbj6.js");return t}};await e.addMiddleware(c),e.middlewares.registerImplementation(c);let d={id:"mcp",name:"mcp",description:"Task management for todo lists",execute:async()=>{let{MCPWithConfigMiddleware:t}=await import("./chunk-1vn8d8b8.js");return new t}};await e.addMiddleware(d),e.middlewares.registerImplementation(d);let m={id:"web",name:"web",description:"Fetch and extract readable content from URLs",execute:async()=>{let{WebMiddleware:t}=await import("./chunk-8ysg0rga.js");return t}};await e.addMiddleware(m),e.middlewares.registerImplementation(m)}var g=`# 架构师 - 任务派发协调者
2
-
3
- 你是一位**任务派发架构师**,核心职责是将用户需求分析并拆解为子任务,然后委派给合适的子 agent 执行。
4
-
5
- ## 核心职责
6
-
7
- **你的唯一任务**:
8
- 1. 理解用户需求
9
- 2. 拆解为可执行的子任务
10
- 3. 委派给合适的子 agent
11
- 4. 跟踪和汇总结果
12
-
13
- **不要做的事**:
14
- - ❌ 不要自己编写代码
15
- - ❌ 不要自己读取文件或搜索代码
16
- - ❌ 不要自己执行终端命令
17
- - ❌ 不要做具体的架构分析或设计文档
18
-
19
- ## 工作流程
20
-
21
- ### 步骤 1:需求分析
22
-
23
- 当收到用户请求时,快速判断:
24
-
25
- 1. **任务类型**:
26
- - 代码实现/修改 → 委派给 \`agents/default\`
27
- - 任务规划/协调 → 委派给 \`agents/manager\`
28
- - 复杂任务 → 先由 \`agents/manager\` 规划,再由 \`agents/default\` 执行
29
-
30
- 2. **任务规模**:
31
- - 单一任务 → 直接委派
32
- - 多任务 → 拆分后分别委派
33
-
34
- ### 步骤 2:任务拆解
35
-
36
- 使用 \`task\` 工具委派任务:
37
-
38
- \`\`\`typescript
39
- // 示例:委派代码实现任务
40
- {
41
- subagent_id: "agents/default",
42
- task_description: "实现用户认证功能,包括登录、注册、登出三个接口",
43
- data_transfer: {
44
- requirements: "使用 JWT 认证,密码需要加密存储",
45
- constraints: "使用现有的数据库连接池"
46
- }
47
- }
48
- \`\`\`
49
-
50
- ### 步骤 3:结果汇总
51
-
52
- 子 agent 完成后:
53
- 1. 检查执行结果
54
- 2. 如果有多个子任务,协调依赖关系
55
- 3. 向用户汇报整体进度和结果
56
-
57
- ## 委派策略
58
-
59
- ### 简单任务
60
-
61
- 用户请求单一功能时,直接委派:
62
-
63
- > 用户:添加一个日志工具函数
64
-
65
- → 委派给 \`agents/default\`,任务描述清晰完整
66
-
67
- ### 复杂任务
68
-
69
- 用户请求多功能时,拆分后委派:
70
-
71
- > 用户:重构用户模块并添加测试
72
-
73
- → 拆分为:
74
- 1. 委派 \`agents/default\`:重构用户模块代码
75
- 2. 等第一步完成后,委派 \`agents/default\`:为用户模块编写测试
76
-
77
- ### 规划任务
78
-
79
- 用户需要方案设计时:
80
-
81
- > 用户:设计一个新的权限系统
82
-
83
- → 委派 \`agents/manager\` 进行任务规划,然后按规划执行
84
-
85
- ## 输出格式
86
-
87
- ### 委派时
88
-
89
- \`\`\`markdown
90
- ## 任务分析
91
-
92
- **用户需求**:{用户原始请求}
93
-
94
- **任务拆解**:
95
- 1. 任务 A → 委派给 agents/default
96
- 2. 任务 B → 委派给 agents/manager
97
-
98
- **开始执行**...
99
- \`\`\`
100
-
101
- ### 汇报时
102
-
103
- \`\`\`markdown
104
- ## 执行结果
105
-
106
- **已完成**:
107
- - ✅ 任务 A:{简要结果}
108
- - ✅ 任务 B:{简要结果}
109
-
110
- **总结**:{整体结果摘要}
111
- \`\`\`
112
-
113
- ## 重要约束
114
-
115
- 1. **立即委派**:收到任务后,不要犹豫,立即分析并委派
116
- 2. **清晰描述**:给子 agent 的任务描述要完整、清晰
117
- 3. **传递上下文**:使用 \`data_transfer\` 传递必要的背景信息
118
- 4. **不要插手**:相信子 agent 的能力,不要自己动手做具体工作
119
- 5. **保持简洁**:你的输出应该简短,重点是协调和汇总
120
-
121
- ---
122
-
123
- **记住**:你是协调者,不是执行者。快速分析需求,立即委派任务,高效汇总结果。`;var b=({cwd:e,env:o})=>`You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
124
-
125
- IMPORTANT: Assist with defensive security tasks only. Refuse to create, modify, or improve code that may be used maliciously. Allow security analysis, detection rules, vulnerability explanations, defensive tools, and security documentation.
126
- IMPORTANT: You must NEVER generate or guess URLs for the user unless you are confident that the URLs are for helping the user with programming. You may use URLs provided by the user in their messages or local files.
127
-
128
- # Tone and style
129
- You should be concise, direct, and to the point.
130
- You MUST answer concisely with fewer than 4 lines (not including tool use or code generation), unless user asks for detail.
131
- IMPORTANT: You should minimize output tokens as much as possible while maintaining helpfulness, quality, and accuracy. Only address the specific query or task at hand, avoiding tangential information unless absolutely critical for completing the request. If you can answer in 1-3 sentences or a short paragraph, please do.
132
- IMPORTANT: You should NOT answer with unnecessary preamble or postamble (such as explaining your code or summarizing your action), unless the user asks you to.
133
- Do not add additional code explanation summary unless requested by the user. After working on a file, just stop, rather than providing an explanation of what you did.
134
- Answer the user's question directly, without elaboration, explanation, or details. One word answers are best. Avoid introductions, conclusions, and explanations. You MUST avoid text before/after your response, such as "The answer is <answer>.", "Here is the content of the file..." or "Based on the information provided, the answer is..." or "Here is what I will do next...". Here are some examples to demonstrate appropriate verbosity:
135
-
136
- <example>
137
- user: 2 + 2
138
- assistant: 4
139
- </example>
140
-
141
- <example>
142
- user: what is 2+2?
143
- assistant: 4
144
- </example>
145
-
146
- <example>
147
- user: is 11 a prime number?
148
- assistant: Yes
149
- </example>
150
-
151
- <example>
152
- user: what command should I run to list files in the current directory?
153
- assistant: ls
154
- </example>
155
-
156
- <example>
157
- user: what command should I run to watch files in the current directory?
158
- assistant: [runs ls to list the files in the current directory, then read docs/commands in the relevant file to find out how to watch files]
159
- npm run dev
160
- </example>
161
-
162
- <example>
163
- user: How many golf balls fit inside a jetta?
164
- assistant: 150000
165
- </example>
166
-
167
- <example>
168
- user: what files are in the directory src/?
169
- assistant: [runs ls and sees foo.c, bar.c, baz.c]
170
- user: which file contains the implementation of foo?
171
- assistant: src/foo.c
172
- </example>
173
-
174
- When you run a non-trivial bash command, you should explain what the command does and why you are running it, to make sure the user understands what you are doing (this is especially important when you are running a command that will make changes to the user's system).
175
-
176
- Remember that your output will be displayed on a command line interface. Your responses can use Github-flavored markdown for formatting, and will be rendered in a monospace font using the CommonMark specification.
177
-
178
- Output text to communicate with the user; all text you output outside of tool use is displayed to the user. Only use tools to complete tasks. Never use tools like Bash or code comments as means to communicate with the user during the session.
179
-
180
- If you cannot or will not help the user with something, please do not say why or what it could lead to, since this comes across as preachy and annoying. Please offer helpful alternatives if possible, and otherwise keep your response to 1-2 sentences.
181
-
182
- Only use emojis if the user explicitly requests it. Avoid using emojis in all communication unless asked.
183
-
184
- IMPORTANT: Keep your responses short, since they will be displayed on a command line interface.
185
-
186
- # Proactiveness
187
- You are allowed to be proactive, but only when the user asks you to do something. You should strive to strike a balance between:
188
- - Doing the right thing when asked, including taking actions and follow-up actions
189
- - Not surprising the user with actions you take without asking
190
- For example, if the user asks you how to approach something, you should do your best to answer their question first, and not immediately jump into taking actions.
191
-
192
- # Following conventions
193
- When making changes to files, first understand the file's code conventions. Mimic code style, use existing libraries and utilities, and follow existing patterns.
194
- - NEVER assume that a given library is available, even if it is well known. Whenever you write code that uses a library or framework, first check that this codebase already uses the given library. For example, you might look at neighboring files, or check the package.json (or cargo.toml, and so on depending on the language).
195
- - When you create a new component, first look at existing components to see how they're written; then consider framework choice, naming conventions, typing, and other conventions.
196
- - When you edit a piece of code, first look at the code's surrounding context (especially its imports) to understand the code's choice of frameworks and libraries. Then consider how to make the given change in a way that is most idiomatic.
197
- - Always follow security best practices. Never introduce code that exposes or logs secrets and keys. Never commit secrets or keys to the repository.
198
-
199
- # Doing tasks
200
- The user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended:
201
- - Use the TodoWrite tool to plan the task if required
202
- - Use the available search tools to understand the codebase and the user's query. You are encouraged to use the search tools extensively both in parallel and sequentially.
203
- - Implement the solution using all tools available to you
204
- - Verify the solution if possible with tests. NEVER assume specific test framework or test script. Check the README or search codebase to determine the testing approach.
205
- - VERY IMPORTANT: When you have completed a task, you MUST run the lint and typecheck commands (eg. npm run lint, npm run typecheck, ruff, etc.) with Bash if they were provided to you to ensure your code is correct. If you are unable to find the correct command, ask the user for the command to run and if they supply it, proactively suggest writing it to CLAUDE.md so that you will know to run it next time.
206
- NEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTANT to only commit when explicitly asked, otherwise the user will feel that you are being too proactive.
207
-
208
- # Tool usage policy
209
- - When doing file search, prefer to use the Task tool in order to reduce context usage.
210
- - You should proactively use the Task tool with specialized agents when the task at hand matches the agent's description.
211
- - When WebFetch returns a message about a redirect to a different host, you should immediately make a new WebFetch request with the redirect URL provided in the response.
212
- - You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. When making multiple bash tool calls, you MUST send a single message with multiple tools calls to run the calls in parallel. For example, if you need to run "git status" and "git diff", send a single message with two tool calls to run the calls in parallel.
213
-
214
- Here is useful information about the environment you are running in:
215
-
216
- <env>
217
- Working directory: ${e}
218
- Is directory a git repo: ${o.isGitRepo?"Yes":"No"}
219
- Platform: ${o.platform}
220
- OS Version: ${o.osVersion}
221
- Today's date: ${o.date}
222
- </env>
223
-
224
- # Code References
225
-
226
- When referencing specific functions or pieces of code include the pattern \`file_path:line_number\` to allow the user to easily navigate to the source code location.
227
-
228
- <example>
229
- user: Where are errors from the client handled?
230
- assistant: Clients are marked as failed in the \`connectToServer\` function in src/services/process.ts:712.
231
- </example>
232
- `;async function T(){let e=new x,o=new v(e);return await o.addModel({id:"glm-4.7",model_name:"glm-4.7",provider_id:process.env.MODEL_PROVIDER||"openai",stream_usage:!0,enable_thinking:!0,temperature:0.7,max_tokens:4096,top_p:1,frequency_penalty:0,presence_penalty:0}),await o.addPrompt({id:"prompts/default",name:"default"},b({cwd:process.cwd(),env:{isGitRepo:!0,platform:process.platform,osVersion:process.version,date:new Date().toISOString().split("T")[0]}})),await o.addPrompt({id:"prompts/manager",name:"manager"},g),await w(o),await o.addAgent({id:"agents/default",name:"Jarvis",description:"代码实现助手",system_prompt:"prompts/default",model:"glm-4.7",middlewares:{filesystem:!0,terminal:!0,agents_md:!0,skills:!0,subagents:!0,interactive:!0,task:!0,mcp:!0,web:!0}}),await o.addAgent({id:"agents/manager",name:"Manager",description:"任务管理员",system_prompt:"prompts/manager",model:"glm-4.7",middlewares:{filesystem:!0,terminal:!0,agents_md:!0,skills:!0,subagents:!0,interactive:!0,task:!0,mcp:!0,web:!0}}),o}var N=await T(),B=N;
233
- export{B as Ve};
@@ -1 +0,0 @@
1
- import{a as x,b as I}from"./chunk-yerf10k7.js";import"./chunk-qmxtys9q.js";import{Fg as C,Hg as T,Zg as b,_g as w,ah as v}from"./chunk-hz9yw7cs.js";import"./chunk-tn356gwf.js";import"./chunk-n849zsd3.js";import"./chunk-vd8kwzra.js";import"./chunk-arv4h3h1.js";import{Fl as K}from"./chunk-z3e4c424.js";var W=K(I(),1),g=[{index:"checkpoints",prefix:"checkpoint:",schema:{"$.thread_id":{type:"TAG",AS:"thread_id"},"$.checkpoint_ns":{type:"TAG",AS:"checkpoint_ns"},"$.checkpoint_id":{type:"TAG",AS:"checkpoint_id"},"$.parent_checkpoint_id":{type:"TAG",AS:"parent_checkpoint_id"},"$.checkpoint_ts":{type:"NUMERIC",AS:"checkpoint_ts"},"$.has_writes":{type:"TAG",AS:"has_writes"},"$.source":{type:"TAG",AS:"source"},"$.step":{type:"NUMERIC",AS:"step"}}},{index:"checkpoint_blobs",prefix:"checkpoint_blob:",schema:{"$.thread_id":{type:"TAG",AS:"thread_id"},"$.checkpoint_ns":{type:"TAG",AS:"checkpoint_ns"},"$.checkpoint_id":{type:"TAG",AS:"checkpoint_id"},"$.channel":{type:"TAG",AS:"channel"},"$.version":{type:"TAG",AS:"version"},"$.type":{type:"TAG",AS:"type"}}},{index:"checkpoint_writes",prefix:"checkpoint_write:",schema:{"$.thread_id":{type:"TAG",AS:"thread_id"},"$.checkpoint_ns":{type:"TAG",AS:"checkpoint_ns"},"$.checkpoint_id":{type:"TAG",AS:"checkpoint_id"},"$.task_id":{type:"TAG",AS:"task_id"},"$.idx":{type:"NUMERIC",AS:"idx"},"$.channel":{type:"TAG",AS:"channel"},"$.type":{type:"TAG",AS:"type"}}}],f=class z extends w{client;ttlConfig;constructor(G,J){super();this.client=G,this.ttlConfig=J}static async fromUrl(G,J){let Z=W.createClient({url:G});await Z.connect();let Q=new z(Z,J);return await Q.ensureIndexes(),Q}static async fromCluster(G,J){let Z=W.createCluster({rootNodes:G});await Z.connect();let Q=new z(Z,J);return await Q.ensureIndexes(),Q}async get(G){return(await this.getTuple(G))?.checkpoint}async getTuple(G){let J=G.configurable?.thread_id,Z=G.configurable?.checkpoint_ns??"",Q=G.configurable?.checkpoint_id;if(!J)return;let Y,E;if(Q)Y=`checkpoint:${J}:${Z}:${Q}`,E=await this.client.json.get(Y);else{let $=`checkpoint:${J}:${Z}:*`,_=await this.client.keys($);if(_.length===0)return;_.sort(),Y=_[_.length-1],E=await this.client.json.get(Y)}if(!E)return;if(this.ttlConfig?.refreshOnRead&&this.ttlConfig?.defaultTTL)await this.applyTTL(Y);let{checkpoint:F,pendingWrites:X}=await this.loadCheckpointWithWrites(E);return await this.createCheckpointTuple(E,F,X)}async put(G,J,Z,Q){await this.ensureIndexes();let Y=G.configurable?.thread_id,E=G.configurable?.checkpoint_ns??"",F=G.configurable?.checkpoint_id;if(!Y)throw Error("thread_id is required");let X=J.id||C(0),$=`checkpoint:${Y}:${E}:${X}`,_=b(J);if(_.channel_values&&Q!==void 0)if(Object.keys(Q).length===0)_.channel_values={};else{let U={};for(let B of Object.keys(Q))if(B in _.channel_values)U[B]=_.channel_values[B];_.channel_values=U}let H={thread_id:Y,checkpoint_ns:E===""?"__empty__":E,checkpoint_id:X,parent_checkpoint_id:F||null,checkpoint:_,metadata:Z,checkpoint_ts:Date.now(),has_writes:"false"};if(this.addSearchableMetadataFields(H,Z),await this.client.json.set($,"$",H),this.ttlConfig?.defaultTTL)await this.applyTTL($);return{configurable:{thread_id:Y,checkpoint_ns:E,checkpoint_id:X}}}async*list(G,J){if(await this.ensureIndexes(),J?.filter!==void 0){let Q=Object.values(J.filter).some((X)=>X===null),Y=[];if(G?.configurable?.thread_id){let X=G.configurable.thread_id.replace(/[-.@]/g,"\\$&");Y.push(`(@thread_id:{${X}})`)}if(G?.configurable?.checkpoint_ns!==void 0){let X=G.configurable.checkpoint_ns;if(X==="")Y.push("(@checkpoint_ns:{__empty__})");else{let $=X.replace(/[-.@]/g,"\\$&");Y.push(`(@checkpoint_ns:{${$}})`)}}if(!J?.before&&J?.filter){for(let[X,$]of Object.entries(J.filter))if($===void 0);else if($===null);else if(typeof $==="string"){let _=x(X),H=x($);Y.push(`(@${_}:{${H}})`)}else if(typeof $==="number"){let _=x(X);Y.push(`(@${_}:[${$} ${$}])`)}else if(typeof $==="object"&&Object.keys($).length===0);}if(Y.length===0)Y.push("*");let E=Y.join(" "),F=J?.limit??10;try{let X=J?.before&&!G?.configurable?.thread_id?1000:J?.before?F*10:F,$=(await this.client.ft.search("checkpoints",E,{LIMIT:{from:0,size:X},SORTBY:{BY:"checkpoint_ts",DIRECTION:"DESC"}})).documents,_=0;for(let H of $){if(_>=F)break;if(J?.before?.configurable?.checkpoint_id){if(H.value.checkpoint_id>=J.before.configurable.checkpoint_id)continue}let U=H.value,B=!0;if((Q||J?.before)&&J?.filter){for(let[M,O]of Object.entries(J.filter))if(O===null){if(U.metadata?.[M]!==null){B=!1;break}}else if(O!==void 0){let A=U.metadata?.[M];if(typeof O==="object"&&O!==null){if(q(A)!==q(O)){B=!1;break}}else if(A!==O){B=!1;break}}if(!B)continue}let{checkpoint:L,pendingWrites:R}=await this.loadCheckpointWithWrites(U);yield await this.createCheckpointTuple(U,L,R),_++}return}catch(X){if(X.message?.includes("no such index"));else throw X}if(G?.configurable?.thread_id){let X=G.configurable.thread_id,$=G.configurable.checkpoint_ns??"",_=`checkpoint:${X}:${$}:*`,H=await this.client.keys(_);H.sort().reverse();let U=H;if(J?.before?.configurable?.checkpoint_id){let R=`checkpoint:${J.before.configurable.thread_id||X}:${J.before.configurable.checkpoint_ns??$}:${J.before.configurable.checkpoint_id}`,M=H.indexOf(R);if(M>0)U=H.slice(M+1);else if(M===0)U=[]}let B=J?.limit??10,L=U.slice(0,B);for(let R of L){let M=await this.client.json.get(R);if(M){let O=!0;for(let[V,S]of Object.entries(J.filter)){let N=M.metadata?.[V];if(S===null){if(N!==null){O=!1;break}}else if(N!==S){O=!1;break}}if(!O)continue;let{checkpoint:A,pendingWrites:P}=await this.loadCheckpointWithWrites(M);yield await this.createCheckpointTuple(M,A,P)}}}else{let X=G?.configurable?.checkpoint_ns!==void 0?`checkpoint:*:${G.configurable.checkpoint_ns===""?"__empty__":G.configurable.checkpoint_ns}:*`:"checkpoint:*",$=await this.client.keys(X),_=[];for(let B of $){let L=await this.client.json.get(B);if(L)_.push({key:B,doc:L})}_.sort((B,L)=>L.doc.checkpoint_ts-B.doc.checkpoint_ts);let H=0,U=J?.limit??10;for(let{doc:B}of _){if(H>=U)break;if(J?.before?.configurable?.checkpoint_id){if(B.checkpoint_id>=J.before.configurable.checkpoint_id)continue}let L=!0;if(J?.filter){for(let[O,A]of Object.entries(J.filter))if(A===null){if(B.metadata?.[O]!==null){L=!1;break}}else if(A!==void 0){let P=B.metadata?.[O];if(typeof A==="object"&&A!==null){if(q(P)!==q(A)){L=!1;break}}else if(P!==A){L=!1;break}}if(!L)continue}let{checkpoint:R,pendingWrites:M}=await this.loadCheckpointWithWrites(B);yield await this.createCheckpointTuple(B,R,M),H++}}return}let Z={...J,filter:{}};yield*this.list(G,Z)}async putWrites(G,J,Z){await this.ensureIndexes();let Q=G.configurable?.thread_id,Y=G.configurable?.checkpoint_ns??"",E=G.configurable?.checkpoint_id;if(!Q||!E)throw Error("thread_id and checkpoint_id are required");let F=[],X=performance.now()*1000;for(let _=0;_<J.length;_++){let[H,U]=J[_],B=`checkpoint_write:${Q}:${Y}:${E}:${Z}:${_}`;F.push(B);let L={thread_id:Q,checkpoint_ns:Y,checkpoint_id:E,task_id:Z,idx:_,channel:H,type:typeof U==="object"?"json":"string",value:U,timestamp:X,global_idx:X+_};await this.client.json.set(B,"$",L)}if(F.length>0){let _=`write_keys_zset:${Q}:${Y}:${E}`,H={};if(F.forEach((U,B)=>{H[U]=X+B}),await this.client.zAdd(_,Object.entries(H).map(([U,B])=>({score:B,value:U}))),this.ttlConfig?.defaultTTL)await this.applyTTL(...F,_)}let $=`checkpoint:${Q}:${Y}:${E}`;if(await this.client.exists($)){let _=await this.client.json.get($);if(_)_.has_writes="true",await this.client.json.set($,"$",_)}}async deleteThread(G){let J=`checkpoint:${G}:*`,Z=await this.client.keys(J);if(Z.length>0)await this.client.del(Z);let Q=`writes:${G}:*`,Y=await this.client.keys(Q);if(Y.length>0)await this.client.del(Y)}async end(){await this.client.quit()}async loadPendingWrites(G,J,Z){let Q=`checkpoint_write:${G}:${J}:${Z}:*`,Y=await this.client.keys(Q);if(Y.length===0)return;let E=[];for(let X of Y){let $=await this.client.json.get(X);if($)E.push($)}E.sort((X,$)=>(X.global_idx||0)-($.global_idx||0));let F=[];for(let X of E){let $=await this.serde.loadsTyped("json",JSON.stringify(X.value));F.push([X.task_id,X.channel,$])}return F}async loadCheckpointWithWrites(G){let J=await this.serde.loadsTyped("json",JSON.stringify(G.checkpoint));if(J.v<4&&G.parent_checkpoint_id!=null){let Q=G.checkpoint_ns==="__empty__"?"":G.checkpoint_ns;await this.migratePendingSends(J,G.thread_id,Q,G.parent_checkpoint_id)}let Z;if(G.has_writes==="true"){let Q=G.checkpoint_ns==="__empty__"?"":G.checkpoint_ns;Z=await this.loadPendingWrites(G.thread_id,Q,G.checkpoint_id)}return{checkpoint:J,pendingWrites:Z}}async migratePendingSends(G,J,Z,Q){let Y=await this.loadPendingWrites(J,Z,Q);if(!Y||Y.length===0)return;let E=Y.filter(([,X])=>X===T);if(E.length===0)return;let F=[];for(let[,,X]of E)F.push(X);G.channel_values??={},G.channel_values[T]=F,G.channel_versions[T]=Object.keys(G.channel_versions).length>0?v(...Object.values(G.channel_versions)):1}async createCheckpointTuple(G,J,Z){let Q=G.checkpoint_ns==="__empty__"?"":G.checkpoint_ns,Y=await this.serde.loadsTyped("json",JSON.stringify(G.metadata));return{config:{configurable:{thread_id:G.thread_id,checkpoint_ns:Q,checkpoint_id:G.checkpoint_id}},checkpoint:J,metadata:Y,parentConfig:G.parent_checkpoint_id?{configurable:{thread_id:G.thread_id,checkpoint_ns:Q,checkpoint_id:G.parent_checkpoint_id}}:void 0,pendingWrites:Z}}addSearchableMetadataFields(G,J){if(!J)return;if("source"in J)G.source=J.source;if("step"in J)G.step=J.step;if("writes"in J)G.writes=typeof J.writes==="object"?JSON.stringify(J.writes):J.writes;if("score"in J)G.score=J.score}async applyTTL(...G){if(!this.ttlConfig?.defaultTTL)return;let J=Math.floor(this.ttlConfig.defaultTTL*60),Z=await Promise.allSettled(G.map((Q)=>this.client.expire(Q,J)));for(let Q=0;Q<Z.length;Q++)if(Z[Q].status==="rejected")console.warn(`Failed to set TTL for key ${G[Q]}:`,Z[Q].reason)}async ensureIndexes(){for(let G of g)try{await this.client.ft.create(G.index,G.schema,{ON:"JSON",PREFIX:G.prefix})}catch(J){if(!J.message?.includes("Index already exists"))console.error(`Failed to create index ${G.index}:`,J.message)}}};function q(z){if(z===null||typeof z!=="object")return JSON.stringify(z);if(Array.isArray(z))return JSON.stringify(z.map((Z)=>q(Z)));let G={},J=Object.keys(z).sort();for(let Z of J)G[Z]=z[Z];return JSON.stringify(G,(Z,Q)=>{if(Q!==null&&typeof Q==="object"&&!Array.isArray(Q)){let Y={},E=Object.keys(Q).sort();for(let F of E)Y[F]=Q[F];return Y}return Q})}export{f as RedisSaver};
@@ -1,2 +0,0 @@
1
- import{Jd as P,La as X,Nd as U,Ud as j,Vd as A,_ as T,lb as $}from"./chunk-cnzhxgn5.js";import{Kl as E}from"./chunk-z3e4c424.js";var Z=class{constructor(z){this.createDriver=z}createDriver;createQueryCompiler(){return new U}createAdapter(){return new A}createIntrospector(z){return new j(z)}},F=class{promise;resolve;async lock(){while(this.promise)await this.promise;this.promise=new Promise((z)=>{this.resolve=z})}unlock(){let z=this.resolve;this.promise=void 0,this.resolve=void 0,z?.()}};async function V(z,H,J,O,K){await J.executeQuery(K(X.createWithChildren([X.createWithSql(`${z} `),T.create(O)]),H()))}var _=class{mutex=new F;conn;savepoint;releaseSavepoint;rollbackToSavepoint;init;constructor(z){this.init=()=>import("./chunk-gbfpab0j.js").then(({createQueryId:H})=>{if(H)this.savepoint=V.bind(null,"savepoint",H),this.releaseSavepoint=V.bind(null,"release",H),this.rollbackToSavepoint=V.bind(null,"rollback to",H)}).then(z)}async acquireConnection(){return await this.mutex.lock(),this.conn}async beginTransaction(z){await z.executeQuery(P.raw("begin"))}async commitTransaction(z){await z.executeQuery(P.raw("commit"))}async rollbackTransaction(z){await z.executeQuery(P.raw("rollback"))}async releaseConnection(){this.mutex.unlock()}};function L(z){return async(H,J,O)=>{let K=await z.all(J,O);return H||K.length?{rows:K}:{rows:[],...await z.run("select 1")}}}function M(z){return z===void 0||z===null?void 0:BigInt(z)}var R=class extends _{db;constructor(z,H){super(async()=>{this.db=await z(),this.conn=new W(this.db),await H?.(this.conn)})}async destroy(){await this.db?.close()}},W=class{constructor(z){this.db=z}async*streamQuery({parameters:z,query:H,sql:J}){if(!this.db.iterator)throw Error("streamQuery() is not supported.");let O=this.db.iterator($.is(H),J,z);for await(let K of O)yield{rows:[K]}}async executeQuery({parameters:z,query:H,sql:J}){return await this.db.query($.is(H),J,z)}},b=class extends Z{constructor(z,H){super(()=>new R(z,H))}};
2
- export{Z as d,L as e,M as f,b as g};
@@ -1,3 +0,0 @@
1
- import{l as v,m as Z}from"./chunk-5yd4ntp6.js";import{Be as Q,Ce as G,Ke as M,Le as F,Pe as O,ye as k}from"./chunk-1v863afn.js";import"./chunk-mcb8rewr.js";import"./chunk-8waww0j9.js";import"./chunk-tn356gwf.js";import"./chunk-n849zsd3.js";import"./chunk-b2551zfb.js";import"./chunk-vd8kwzra.js";import"./chunk-qhzm2qw9.js";import"./chunk-arv4h3h1.js";import{Fl as Y}from"./chunk-z3e4c424.js";var N=Y(k(),1);var y=Y(k(),1);var J=Y(F(),1),h=({pid:z,onClose:A})=>{let[H,R]=y.useState({stdout:"",stderr:""});M((W,X)=>{if(X.escape)A()}),y.useEffect(()=>{let W=()=>{let _=Z.getProcessOutput(z);if(_)R(_)};W();let X=setInterval(W,500);return()=>clearInterval(X)},[z]);let $=I(H.stdout,20),U=I(H.stderr,20);return J.jsxDEV(Q,{flexDirection:"column",padding:1,children:[J.jsxDEV(Q,{justifyContent:"space-between",marginBottom:1,children:[J.jsxDEV(G,{bold:!0,color:"cyan",children:["进程 [",z,"] 输出"]},void 0,!0,void 0,this),J.jsxDEV(G,{dimColor:!0,children:"按 ESC 返回"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J.jsxDEV(Q,{flexDirection:"column",marginBottom:1,children:[J.jsxDEV(G,{color:"green",bold:!0,children:"STDOUT:"},void 0,!1,void 0,this),J.jsxDEV(Q,{borderStyle:"single",borderColor:"green",paddingX:1,children:J.jsxDEV(G,{children:$||"(空)"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J.jsxDEV(Q,{flexDirection:"column",children:[J.jsxDEV(G,{color:"red",bold:!0,children:"STDERR:"},void 0,!1,void 0,this),J.jsxDEV(Q,{borderStyle:"single",borderColor:"red",paddingX:1,children:J.jsxDEV(G,{children:U||"(空)"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)};function I(z,A){let H=z.split(`
2
- `);if(H.length<=A)return z;return`...${H.slice(-A).join(`
3
- `)}`}var g=h;var w=Y(F(),1),T=({onClose:z})=>{let[A,H]=N.useState([]),[R,$]=N.useState(null);N.useEffect(()=>{let q=async()=>{let b=await Z.getProcessList();H(b)};q();let K=setInterval(q,1000);return()=>clearInterval(K)},[]);let U=N.useCallback(async()=>{let q=await Z.getProcessList();H(q)},[]),W=N.useCallback((q,K,b)=>{let C=q.status==="running"?"\uD83D\uDFE2":"\uD83D\uDD34",B=f(q.duration);return w.jsxDEV(Q,{flexDirection:"column",children:[w.jsxDEV(Q,{children:[w.jsxDEV(G,{color:"cyan",children:[C," [",q.pid,"]"]},void 0,!0,void 0,this),w.jsxDEV(G,{children:[" ",P(q.command,40)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),w.jsxDEV(Q,{paddingLeft:3,children:[w.jsxDEV(G,{dimColor:!0,children:["⏱ ",B]},void 0,!0,void 0,this),w.jsxDEV(G,{dimColor:!0,children:[" | CPU: ",q.cpu.toFixed(1),"%"]},void 0,!0,void 0,this),w.jsxDEV(G,{dimColor:!0,children:[" | MEM: ",(q.memory/1024/1024).toFixed(1),"MB"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},[]),X=N.useCallback((q)=>{Z.killProcess(q.pid)},[]),_=N.useCallback((q)=>{$(q.pid)},[]),L=N.useCallback((q)=>{return w.jsxDEV(G,{dimColor:!0,children:["运行中: ",q.filter((K)=>K.status==="running").length," | 总计: ",q.length," | Enter 查看输出 | Backspace/Delete 关闭进程"]},void 0,!0,void 0,this)},[]),S=N.useMemo(()=>({id:"processes",title:"进程管理器",icon:"⚙️",dataSource:()=>Promise.resolve(A),searchable:!0,searchFields:["command"],renderItem:W,keyExtractor:(q)=>q.pid,onSelect:_,onDelete:X,itemHeight:2,statusInfo:L,keyMap:{r:()=>{U()}}}),[A,W,_,X,L,U]);return w.jsxDEV(w.Fragment,{children:R!==null?w.jsxDEV(v,{name:"ProcessOutputPanel",fallback:null,children:w.jsxDEV(g,{pid:R,onClose:()=>$(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):w.jsxDEV(O,{config:S,onClose:z},void 0,!1,void 0,this)},void 0,!1,void 0,this)};function f(z){let A=Math.floor(z/1000),H=Math.floor(A/60),R=Math.floor(H/60);if(R>0)return`${R}h ${H%60}m`;if(H>0)return`${H}m ${A%60}s`;return`${A}s`}function P(z,A){return z.length>A?z.slice(0,A-3)+"...":z}var n=T;export{n as default};
@@ -1 +0,0 @@
1
- import{D as f}from"./chunk-4hg13vwj.js";import"./chunk-kmxdq21k.js";import{W as C,Y as _}from"./chunk-dx9k6sdd.js";import{Be as X,Ce as Y,Le as K,Pe as M,ye as g}from"./chunk-1v863afn.js";import{Sf as w,Uf as A}from"./chunk-3dnayvgx.js";import"./chunk-8waww0j9.js";import"./chunk-h0q3dvnv.js";import"./chunk-hrcxdj3c.js";import"./chunk-9tgp14v7.js";import"./chunk-hz9yw7cs.js";import"./chunk-tn356gwf.js";import"./chunk-n849zsd3.js";import"./chunk-t01t72t2.js";import"./chunk-b2551zfb.js";import"./chunk-vd8kwzra.js";import"./chunk-qhzm2qw9.js";import"./chunk-arv4h3h1.js";import{Fl as Q}from"./chunk-z3e4c424.js";var F=Q(g(),1);import{join as R}from"path";function $({type:G,enabled:J=!0}){return C({queryKey:G==="memories"?_.knowledge.memories():_.knowledge.skills(),queryFn:async()=>{let L=R(process.cwd(),".claude",G),N=R(process.env.HOME||"",".deepagents/code",G);try{if(G==="memories")return A(N,L).map((W)=>({...W,type:"memory"}));else return w(N,L).map((W)=>({...W,type:"skill"}))}catch(O){return console.warn(`Failed to load ${G}:`,O),[]}},enabled:J,staleTime:120000})}var H=Q(K(),1),S=(G)=>{return G.length>80?G.slice(0,80)+"...":G},v=({onClose:G})=>{let[J,L]=F.useState("memories"),N=F.useRef(L);F.default.useEffect(()=>{N.current=L},[L]);let{data:O=[]}=$({type:"memories",enabled:J==="memories"}),{data:W=[]}=$({type:"skills",enabled:J==="skills"}),U=F.useCallback(async()=>{return J==="memories"?O:W},[J,O,W]),I=F.useCallback((z,E,Z)=>{let V=S(z.description);return H.jsxDEV(X,{flexDirection:"column",paddingY:1,children:[H.jsxDEV(X,{children:H.jsxDEV(Y,{bold:!0,color:Z?"cyan":"gray",children:[E+1,". ",z.name]},void 0,!0,void 0,this)},void 0,!1,void 0,this),H.jsxDEV(X,{paddingY:1,children:H.jsxDEV(Y,{color:Z?"white":"gray",children:V},void 0,!1,void 0,this)},void 0,!1,void 0,this),H.jsxDEV(X,{children:H.jsxDEV(Y,{color:"cyan",dimColor:!Z,children:[f(z.path),z.category&&H.jsxDEV(Y,{color:"yellow",children:[" ",z.category]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},z.path,!0,void 0,this)},[]),P=F.useCallback((z)=>{console.log("Selected knowledge item:",z.name)},[]),q=F.useMemo(()=>[{id:"memory",label:"记忆",predicate:(z)=>z.type==="memory"},{id:"skill",label:"技能",predicate:(z)=>z.type==="skill"}],[]),B=F.useMemo(()=>({h:(z)=>{N.current("memories"),z.setActiveFilter("memory")},s:(z)=>{N.current("skills"),z.setActiveFilter("skill")}}),[]),h=F.useMemo(()=>({id:"knowledge",title:"知识库",icon:"\uD83D\uDCDA",dataSource:U,searchable:!0,searchFields:["name","description"],searchPlaceholder:"搜索知识库 (名称/描述/分类)...",filterable:!0,filters:q,defaultFilter:J==="memories"?"memory":"skill",itemHeight:8,visibleCount:3,renderItem:I,showCount:!0,onSelect:P,keyMap:B}),[U,q,I,P,B,J]);return H.jsxDEV(M,{config:h,onClose:G},void 0,!1,void 0,this)},m=v;export{m as default};
@@ -1,2 +0,0 @@
1
- import{j as c}from"./chunk-d72063sm.js";import{W as R,Y as D}from"./chunk-dx9k6sdd.js";import{Be as B,Ce as q,Ke as x,Le as E,Me as m,ye as t}from"./chunk-1v863afn.js";import{Fl as S}from"./chunk-z3e4c424.js";var i=30000;function V(){let z=new AbortController,G=setTimeout(()=>{z.abort(),G=null},i);return{controller:z,cleanup:()=>{if(G!==null)clearTimeout(G),G=null}}}async function a(z,G){let{controller:N,cleanup:Q}=V();try{let H=await fetch(`${G}/models`,{method:"GET",headers:{Authorization:`Bearer ${z}`,"Content-Type":"application/json"},signal:N.signal});if(!H.ok){let Z=await H.text();throw Error(`OpenAI API error (${H.status}): ${H.statusText}`)}return(await H.json()).data.map((Z)=>({id:Z.id,name:Z.id,provider:"openai"})).sort((Z,g)=>Z.id.localeCompare(g.id))}catch(H){if(H.name==="AbortError")throw Error("OpenAI API request timeout (30s)");throw H}finally{Q()}}async function n(z,G){let{controller:N,cleanup:Q}=V();try{let H=await fetch(`${G}/v1/models`,{method:"GET",headers:{"x-api-key":z,"anthropic-version":"2023-06-01","Content-Type":"application/json"},signal:N.signal});if(!H.ok){let Z=await H.text();throw Error(`Anthropic API error (${H.status}): ${H.statusText}`)}return(await H.json()).data.map((Z)=>({id:Z.id,name:Z.display_name||Z.id,provider:"anthropic"}))}catch(H){if(H.name==="AbortError")throw Error("Anthropic API request timeout (30s)");throw H}finally{Q()}}async function d(z,G){let{controller:N,cleanup:Q}=V();try{let H=await fetch(G+"/v1beta/models",{method:"GET",headers:{Authorization:"Bearer "+z},signal:N.signal});if(!H.ok)throw Error(`Gemini API error (${H.status}): Invalid API key`);return(await H.json()).models.map((Z)=>({id:Z.name,name:Z.displayName||Z.name,provider:"gemini"}))}catch(H){if(H.name==="AbortError")throw Error("Gemini API request timeout (30s)");throw H}finally{Q()}}function zz({provider:z,enabled:G=!0}){return R({queryKey:D.models.list(z?.id||"unknown"),queryFn:async()=>{if(!z||!z.apiKey||!z.baseUrl)return[];try{if(z.type==="openai")return await a(z.apiKey,z.baseUrl);else if(z.type==="anthropic")return await n(z.apiKey,z.baseUrl);else if(z.type==="gemini")return await d(z.apiKey,z.baseUrl);return[]}catch(N){throw N}},enabled:G&&!!z&&!!z.apiKey&&!!z.baseUrl,staleTime:600000,retry:(N,Q)=>{if(Q?.message?.includes("timeout"))return N<2;if(Q?.name==="TypeError"||Q?.message?.includes("fetch"))return N<2;return!1}})}var J=S(t(),1);var $=S(E(),1),L=[{id:"openai",label:"OpenAI",defaultUrl:"https://api.openai.com/v1"},{id:"anthropic",label:"Anthropic",defaultUrl:"https://api.anthropic.com"},{id:"gemini",label:"Gemini",defaultUrl:"https://generativelanguage.googleapis.com/v1beta"}],_=[{key:"id",label:"ID",placeholder:"my-provider"},{key:"name",label:"Name",placeholder:"My Provider"},{key:"apiKey",label:"API Key",placeholder:"sk-xxx..."},{key:"url",label:"URL",placeholder:"https://api.xxx.com"}],o=({provider:z,onCancel:G,onSave:N})=>{let{config:Q}=c(),[H,O]=J.useState({id:z?.id||"",type:z?.type||"openai",name:z?.id||"",apiKey:z?.apiKey||"",baseUrl:z?.baseUrl||L[0].defaultUrl}),[Z,g]=J.useState({}),[U,v]=J.useState(0),w=J.useRef(H),C=J.useRef(U),f=J.useRef(Z);J.useEffect(()=>{w.current=H},[H]),J.useEffect(()=>{C.current=U},[U]),J.useEffect(()=>{f.current=Z},[Z]);let u=J.useMemo(()=>{return L.find((X)=>X.id===H.type)||L[0]},[H.type]),k=J.useCallback(()=>{let X=w.current,W={},A=Q?.providers||[];if(!X.id||X.id.length<3||X.id.length>32)W.id="ID 必须为 3-32 个字符";else if(!/^[a-zA-Z0-9_]+$/.test(X.id))W.id="ID 只能包含字母、数字和下划线";else if(A.some((M)=>M.id===X.id&&M.id!==z?.id))W.id="ID 已存在";if(!X.name||X.name.length<2||X.name.length>50)W.name="名称必须为 2-50 个字符";if(!X.apiKey)W.apiKey="API Key 不能为空";if(!X.baseUrl)W.baseUrl="Base URL 不能为空";else if(!X.baseUrl.startsWith("https://"))W.baseUrl="Base URL 必须以 https:// 开头";return g(W),Object.keys(W).length===0},[Q?.providers,z?.id]),h=J.useRef(k);J.useEffect(()=>{h.current=k},[k]);let K=J.useCallback(()=>{if(h.current())N(w.current)},[N]),P=J.useCallback(()=>{let X=w.current.type,A=(L.findIndex((Y)=>Y.id===X)+1)%L.length,M=L[A];O((Y)=>({...Y,type:M.id,baseUrl:Y.baseUrl||M.defaultUrl}))},[]),b=J.useCallback((X)=>{let W=C.current,A=X==="next"?(W+1)%_.length:(W-1+_.length)%_.length;v(A)},[]),p=(X)=>{let W=_[X];if(W.key==="url")return"baseUrl";return W.key},I=J.useRef(K),T=J.useRef(b),F=J.useRef(P),y=J.useRef(G);J.useEffect(()=>{I.current=K},[K]),J.useEffect(()=>{T.current=b},[b]),J.useEffect(()=>{F.current=P},[P]),J.useEffect(()=>{y.current=G},[G]),x((X,W)=>{if(W.return)I.current();else if(W.escape)y.current();else if(W.tab)T.current(W.shift?"prev":"next");else if(X===" ")F.current()},{isActive:!0});let j=(X)=>{let W=_[X],A=p(X),M=Z[A],Y=U===X;return $.jsxDEV(B,{marginBottom:0,children:[$.jsxDEV(q,{color:Y?"cyan":M?"red":"gray",children:[W.label,": "]},void 0,!0,void 0,this),Y?$.jsxDEV(B,{width:50,children:$.jsxDEV(m,{value:H[A],onChange:(l)=>O((s)=>({...s,[A]:l})),onSubmit:K,placeholder:W.placeholder,maxVisibleLines:1,showCursor:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this):$.jsxDEV(q,{children:H[A]||W.placeholder},void 0,!1,void 0,this),M&&$.jsxDEV(q,{color:"red",children:[" ",M]},void 0,!0,void 0,this)]},W.key,!0,void 0,this)};return $.jsxDEV(B,{flexDirection:"column",paddingX:2,children:[$.jsxDEV(B,{marginTop:1,flexDirection:"column",gap:1,children:[j(0),$.jsxDEV(B,{marginBottom:0,children:[$.jsxDEV(q,{color:U===0?"cyan":"gray",children:"Type: "},void 0,!1,void 0,this),$.jsxDEV(q,{color:"cyan",bold:!0,children:u.label},void 0,!1,void 0,this),$.jsxDEV(q,{color:"gray",children:" [空格切换]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j(1),j(2),j(3)]},void 0,!0,void 0,this),$.jsxDEV(B,{marginTop:1,children:$.jsxDEV(q,{color:"gray",dimColor:!0,children:[$.jsxDEV(q,{color:"cyan",children:"Enter"},void 0,!1,void 0,this)," 保存 ",$.jsxDEV(q,{color:"cyan",children:"Tab"},void 0,!1,void 0,this)," 切换字段"," ",$.jsxDEV(q,{color:"cyan",children:"Esc"},void 0,!1,void 0,this)," 取消"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},Nz=o;
2
- export{zz as h,Nz as i};