@uncarved/jade 0.2.1 → 0.3.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 (213) hide show
  1. package/README.md +64 -2
  2. package/assets/logo.svg +1 -0
  3. package/bin/jade.js +4 -0
  4. package/dist/api.d.ts +5 -250
  5. package/dist/api.js +5 -7
  6. package/dist/api.js.map +1 -1
  7. package/dist/fetch.d.ts +8 -0
  8. package/dist/fetch.js +19 -17
  9. package/dist/fetch.js.map +1 -1
  10. package/dist/host.d.ts +12 -1
  11. package/dist/host.js +49 -1
  12. package/dist/host.js.map +1 -1
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.js +1 -1
  15. package/dist/index.js.map +1 -1
  16. package/dist/main.js +26 -4
  17. package/dist/main.js.map +1 -1
  18. package/dist/remote.js +4 -0
  19. package/dist/remote.js.map +1 -1
  20. package/dist/session.d.ts +2 -0
  21. package/dist/session.js +133 -13
  22. package/dist/session.js.map +1 -1
  23. package/dist/source.d.ts +2 -10
  24. package/dist/source.js.map +1 -1
  25. package/dist/update.d.ts +8 -20
  26. package/dist/update.js +12 -1
  27. package/dist/update.js.map +1 -1
  28. package/package.json +4 -2
  29. package/plugins/approval/index.ts +233 -85
  30. package/plugins/approval/plugin.json +1 -1
  31. package/plugins/approval/policy.ts +2 -1
  32. package/plugins/approval/review.ts +1 -1
  33. package/plugins/ask/index.ts +2 -2
  34. package/plugins/budget/index.ts +1 -1
  35. package/plugins/checks/checks.ts +3 -2
  36. package/plugins/checks/index.ts +2 -5
  37. package/plugins/commands/index.ts +2 -44
  38. package/plugins/compact/compact.ts +8 -3
  39. package/plugins/compact/index.ts +13 -16
  40. package/plugins/continue/index.ts +1 -1
  41. package/plugins/cost/index.ts +143 -0
  42. package/plugins/cost/plugin.json +13 -0
  43. package/plugins/custom-commands/index.ts +85 -0
  44. package/plugins/custom-commands/plugin.json +8 -0
  45. package/plugins/editor/index.ts +88 -0
  46. package/plugins/editor/plugin.json +17 -0
  47. package/plugins/fs/fs.ts +33 -6
  48. package/plugins/fs/grep.ts +6 -4
  49. package/plugins/fs/index.ts +2 -3
  50. package/plugins/fs/renderers.ts +1 -1
  51. package/plugins/hooks/index.ts +152 -0
  52. package/plugins/hooks/plugin.json +14 -0
  53. package/plugins/keys/index.ts +2 -18
  54. package/plugins/mcp/index.ts +40 -12
  55. package/plugins/mcp/install.ts +139 -0
  56. package/plugins/mcp/mcp.ts +2 -1
  57. package/plugins/mcp/plugin.json +1 -1
  58. package/plugins/mcp/project.ts +37 -1
  59. package/plugins/memory/index.ts +4 -9
  60. package/plugins/memory/plugin.json +1 -1
  61. package/plugins/mentions/index.ts +2 -2
  62. package/plugins/models/configure.ts +258 -150
  63. package/plugins/models/context.ts +2 -2
  64. package/plugins/models/index.ts +35 -42
  65. package/plugins/models/plugin.json +1 -1
  66. package/plugins/models/provider.ts +22 -4
  67. package/plugins/models/saved.ts +8 -4
  68. package/plugins/modes/index.ts +2 -17
  69. package/plugins/plugins/index.ts +2 -2
  70. package/plugins/print/index.ts +36 -6
  71. package/plugins/print/plugin.json +1 -0
  72. package/plugins/prompts/index.ts +22 -14
  73. package/plugins/{memory → prompts}/notes.ts +21 -9
  74. package/plugins/prompts/plugin.json +8 -2
  75. package/plugins/prompts/prompts.ts +5 -4
  76. package/plugins/renderers/index.ts +2 -43
  77. package/plugins/repeats/index.ts +1 -1
  78. package/plugins/schedule/index.ts +2 -2
  79. package/plugins/scratch/index.ts +2 -3
  80. package/plugins/screenshot/index.ts +26 -13
  81. package/plugins/screenshot/plugin.json +1 -1
  82. package/plugins/sessions/index.ts +2 -17
  83. package/plugins/shell/index.ts +56 -6
  84. package/plugins/shell/plugin.json +3 -1
  85. package/plugins/shell/renderers.ts +1 -1
  86. package/plugins/shell/service.ts +2 -13
  87. package/plugins/shell/shell.ts +31 -16
  88. package/plugins/skills/index.ts +172 -37
  89. package/plugins/skills/install.ts +212 -0
  90. package/plugins/skills/plugin.json +3 -2
  91. package/plugins/skills/project.ts +38 -1
  92. package/plugins/skills/skills.ts +28 -9
  93. package/plugins/steer/index.ts +142 -0
  94. package/plugins/steer/plugin.json +8 -0
  95. package/plugins/suggest/index.ts +16 -11
  96. package/plugins/suggest/plugin.json +1 -1
  97. package/plugins/task/index.ts +7 -16
  98. package/plugins/task/plugin.json +9 -2
  99. package/plugins/task/subagent.ts +23 -5
  100. package/plugins/todo/index.ts +2 -2
  101. package/plugins/tui/editor.ts +10 -2
  102. package/plugins/tui/frontend.ts +103 -21
  103. package/plugins/tui/index.ts +3 -8
  104. package/plugins/tui/markdown.ts +51 -6
  105. package/plugins/tui/mascot.ts +505 -0
  106. package/plugins/tui/plugin.json +2 -2
  107. package/plugins/tui/screen.ts +6 -0
  108. package/plugins/tui/transcript.ts +17 -2
  109. package/plugins/tui/tui.ts +321 -90
  110. package/plugins/undo/checkpoint.ts +2 -2
  111. package/plugins/undo/index.ts +84 -26
  112. package/plugins/undo/plugin.json +8 -2
  113. package/plugins/undo/snapshot.ts +129 -0
  114. package/plugins/update/index.ts +11 -15
  115. package/plugins/update/plugin.json +2 -1
  116. package/plugins/web/index.ts +2 -5
  117. package/plugins/web/renderers.ts +1 -1
  118. package/plugins-dist/approval/index.js +217 -51
  119. package/plugins-dist/approval/plugin.json +1 -1
  120. package/plugins-dist/ask/index.js +1 -1
  121. package/plugins-dist/budget/index.js +1 -1
  122. package/plugins-dist/checks/checks.js +2 -1
  123. package/plugins-dist/checks/index.js +1 -1
  124. package/plugins-dist/commands/index.js +1 -1
  125. package/plugins-dist/compact/compact.js +6 -1
  126. package/plugins-dist/compact/index.js +12 -8
  127. package/plugins-dist/continue/index.js +1 -1
  128. package/plugins-dist/cost/index.js +135 -0
  129. package/plugins-dist/cost/plugin.json +16 -0
  130. package/plugins-dist/custom-commands/index.js +86 -0
  131. package/plugins-dist/custom-commands/plugin.json +12 -0
  132. package/plugins-dist/editor/index.js +89 -0
  133. package/plugins-dist/editor/plugin.json +21 -0
  134. package/plugins-dist/fs/fs.js +34 -6
  135. package/plugins-dist/fs/grep.js +5 -3
  136. package/plugins-dist/fs/index.js +1 -1
  137. package/plugins-dist/hooks/index.js +145 -0
  138. package/plugins-dist/hooks/plugin.json +19 -0
  139. package/plugins-dist/keys/index.js +1 -1
  140. package/plugins-dist/mcp/index.js +41 -9
  141. package/plugins-dist/mcp/install.js +160 -0
  142. package/plugins-dist/mcp/mcp.js +2 -1
  143. package/plugins-dist/mcp/plugin.json +2 -1
  144. package/plugins-dist/mcp/project.js +42 -1
  145. package/plugins-dist/memory/index.js +3 -5
  146. package/plugins-dist/memory/plugin.json +1 -1
  147. package/plugins-dist/mentions/index.js +1 -1
  148. package/plugins-dist/models/configure.js +252 -151
  149. package/plugins-dist/models/context.js +2 -2
  150. package/plugins-dist/models/index.js +37 -14
  151. package/plugins-dist/models/plugin.json +1 -1
  152. package/plugins-dist/models/provider.js +4 -2
  153. package/plugins-dist/models/saved.js +9 -4
  154. package/plugins-dist/modes/index.js +1 -1
  155. package/plugins-dist/plugins/index.js +1 -1
  156. package/plugins-dist/print/index.js +37 -3
  157. package/plugins-dist/print/plugin.json +3 -0
  158. package/plugins-dist/prompts/index.js +22 -3
  159. package/plugins-dist/{memory → prompts}/notes.js +10 -7
  160. package/plugins-dist/prompts/plugin.json +8 -2
  161. package/plugins-dist/prompts/prompts.js +5 -4
  162. package/plugins-dist/renderers/index.js +1 -1
  163. package/plugins-dist/repeats/index.js +1 -1
  164. package/plugins-dist/schedule/index.js +1 -1
  165. package/plugins-dist/scratch/index.js +1 -1
  166. package/plugins-dist/screenshot/index.js +25 -11
  167. package/plugins-dist/screenshot/plugin.json +1 -1
  168. package/plugins-dist/sessions/index.js +1 -1
  169. package/plugins-dist/shell/index.js +55 -3
  170. package/plugins-dist/shell/plugin.json +3 -1
  171. package/plugins-dist/shell/shell.js +26 -8
  172. package/plugins-dist/skills/index.js +184 -35
  173. package/plugins-dist/skills/install.js +178 -0
  174. package/plugins-dist/skills/plugin.json +6 -2
  175. package/plugins-dist/skills/project.js +43 -1
  176. package/plugins-dist/skills/skills.js +27 -10
  177. package/plugins-dist/steer/index.js +135 -0
  178. package/plugins-dist/steer/plugin.json +12 -0
  179. package/plugins-dist/suggest/index.js +15 -9
  180. package/plugins-dist/suggest/plugin.json +1 -1
  181. package/plugins-dist/task/index.js +6 -4
  182. package/plugins-dist/task/plugin.json +10 -2
  183. package/plugins-dist/task/subagent.js +20 -5
  184. package/plugins-dist/todo/index.js +1 -1
  185. package/plugins-dist/tui/editor.js +7 -2
  186. package/plugins-dist/tui/frontend.js +107 -13
  187. package/plugins-dist/tui/index.js +2 -1
  188. package/plugins-dist/tui/markdown.js +48 -6
  189. package/plugins-dist/tui/mascot.js +439 -0
  190. package/plugins-dist/tui/plugin.json +3 -2
  191. package/plugins-dist/tui/screen.js +2 -0
  192. package/plugins-dist/tui/transcript.js +16 -1
  193. package/plugins-dist/tui/tui.js +302 -81
  194. package/plugins-dist/undo/checkpoint.js +1 -1
  195. package/plugins-dist/undo/index.js +91 -24
  196. package/plugins-dist/undo/plugin.json +10 -3
  197. package/plugins-dist/undo/snapshot.js +111 -0
  198. package/plugins-dist/update/index.js +9 -10
  199. package/plugins-dist/update/plugin.json +4 -1
  200. package/plugins-dist/web/index.js +1 -1
  201. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  202. package/sdk/python/jade_plugin.py +8 -0
  203. package/src/api.ts +7 -262
  204. package/src/fetch.ts +18 -16
  205. package/src/host.ts +49 -1
  206. package/src/index.ts +1 -1
  207. package/src/main.ts +23 -5
  208. package/src/remote.ts +2 -0
  209. package/src/session.ts +134 -15
  210. package/src/source.ts +2 -11
  211. package/src/update.ts +16 -10
  212. package/plugins/undo/notes.ts +0 -43
  213. package/plugins-dist/undo/notes.js +0 -36
@@ -6,7 +6,7 @@
6
6
  import { readFile, rm, writeFile } from "node:fs/promises";
7
7
  import { hasProvider, parseTokens } from "./config.js";
8
8
  import { contextWindow } from "./context.js";
9
- import { EFFORTS, isBuiltinKind, KEY_KEY, listModels, MODEL_KEY, providerInfo, providerKind, rpmFromEnv, URL_KEY, visionFromEnv } from "./provider.js";
9
+ import { EFFORTS, isBuiltinKind, jsonObject, KEY_KEY, listModels, MODEL_KEY, providerInfo, providerKind, rpmFromEnv, URL_KEY, visionFromEnv } from "./provider.js";
10
10
  import { MODEL_SETTINGS, readSavedServices, updateEnvFile, writeSavedServices } from "./saved.js";
11
11
  const PROVIDERS = [
12
12
  { kind: "openai-compat", label: "OpenAI-compatible service", hint: "any /chat/completions endpoint" },
@@ -29,7 +29,7 @@ function visionHint(env, kind) {
29
29
  return v === undefined ? `${isBuiltinKind(kind) && kind !== "openai-compat" ? "yes" : "no"} (default)` : v ? "yes" : "no";
30
30
  }
31
31
  /** 一个服务包含的变量(不含模型名) */
32
- const serviceKeys = (kind) => ["JADE_PROVIDER", URL_KEY[kind], KEY_KEY[kind], ...(kind === "openai-compat" ? ["OPENAI_COMPAT_EXTRA_BODY"] : [])];
32
+ const serviceKeys = (kind) => ["JADE_PROVIDER", URL_KEY[kind], KEY_KEY[kind]];
33
33
  const pick = (env, keys) => {
34
34
  const out = {};
35
35
  for (const k of keys)
@@ -37,6 +37,14 @@ const pick = (env, keys) => {
37
37
  out[k] = env[k];
38
38
  return out;
39
39
  };
40
+ /** keys 里明确清掉(设成默认)的那些:空字符串表示"不设",写进 models.json 时删掉;env 里没提到的不算 */
41
+ const blank = (env, keys) => {
42
+ const out = {};
43
+ for (const k of keys)
44
+ if (k in env && env[k] === undefined)
45
+ out[k] = "";
46
+ return out;
47
+ };
40
48
  /** 服务的类型、地址和密钥都相同的算同一个;配置无效时返回 undefined */
41
49
  function serviceId(env) {
42
50
  try {
@@ -59,25 +67,28 @@ function describeService(service) {
59
67
  catch { }
60
68
  return [i.kind, host].filter(Boolean).join(" · ");
61
69
  }
62
- /** 选择列表里一组模型的说明:前几个名字 */
63
- function modelNames(models) {
64
- const names = models.slice(0, 3).map((m) => m.name).join(", ");
65
- return models.length > 3 ? `${names} +${models.length - 3}` : names;
70
+ /** 保存过的、不是当前的模型,按服务分组:当前服务的在前 */
71
+ function otherModels(services, currentId, currentModel) {
72
+ return [...services.filter((s) => serviceId(s.env) === currentId), ...services.filter((s) => serviceId(s.env) !== currentId)].flatMap((s) => s.models.filter((m) => !(serviceId(s.env) === currentId && m.name === currentModel)).map((m) => ({ service: s, model: m })));
66
73
  }
67
- /** 主菜单里设置那一项的简要说明,例如 "64K out · 1M ctx · images" */
68
- function settingsSummary(env, kind, window) {
69
- const images = visionSetting(env) ?? (isBuiltinKind(kind) && kind !== "openai-compat");
74
+ /** Claude 不设输出上限时用的值:和 @uncarved/provider-anthropic 里的默认值一致(不从那里导入:加载它的 SDK 要一百多毫秒) */
75
+ const ANTHROPIC_DEFAULT_MAX_TOKENS = 64000;
76
+ /** 选项说明里放不下的长文本截短 */
77
+ const shorten = (text, max = 40) => (text.length > max ? `${text.slice(0, max - 1)}…` : text);
78
+ const errorText = (err) => (err instanceof Error ? err.message : String(err));
79
+ /** 模型设置那一项的简要说明,例如 "64K out · 1M ctx · images";settings 是这个模型自己的设置变量 */
80
+ function settingsSummary(settings, kind, window) {
81
+ const images = visionSetting({ JADE_VISION: settings.JADE_VISION }) ?? (isBuiltinKind(kind) && kind !== "openai-compat");
70
82
  return [
71
- env.JADE_MAX_TOKENS && `${env.JADE_MAX_TOKENS} out`,
72
- env.JADE_EFFORT && `${env.JADE_EFFORT} effort`,
73
- `${env.JADE_CONTEXT_WINDOW ?? window} ctx`,
74
- env.JADE_RPM && `${env.JADE_RPM}/min`,
83
+ settings.JADE_MAX_TOKENS && `${settings.JADE_MAX_TOKENS} out`,
84
+ settings.JADE_EFFORT && `${settings.JADE_EFFORT} effort`,
85
+ `${settings.JADE_CONTEXT_WINDOW ?? window} ctx`,
86
+ settings.JADE_RPM && `${settings.JADE_RPM}/min`,
75
87
  images ? "images" : "no images",
76
88
  ]
77
89
  .filter(Boolean)
78
90
  .join(" · ");
79
91
  }
80
- const errorText = (err) => (err instanceof Error ? err.message : String(err));
81
92
  export function configurator(opts) {
82
93
  const { ui, envFile, modelsFile } = opts;
83
94
  const report = (text) => opts.report(text);
@@ -158,7 +169,7 @@ export function configurator(opts) {
158
169
  return applyConfig(updates);
159
170
  }
160
171
  /**
161
- * 在当前的服务上换成 model:用过的带上它自己的设置;新的模型沿用输出上限和思考力度,
172
+ * 在当前的服务上换成 model:用过的带上它自己的设置;新的模型沿用输出上限、思考力度和额外请求参数,
162
173
  * 上下文窗口不沿用(不同模型差别很大),按模型名推断
163
174
  */
164
175
  async function switchModel(model) {
@@ -175,15 +186,18 @@ export function configurator(opts) {
175
186
  }
176
187
  return applyConfig({ [MODEL_KEY[kind]]: model, JADE_CONTEXT_WINDOW: undefined });
177
188
  }
178
- /** 选模型:服务能列出模型时从列表里选,否则手动输入 */
189
+ /** 选模型:服务能列出模型时从列表里选,否则手动输入。选 Back 和取消一样返回 undefined */
179
190
  async function chooseModel(env, current, saved = []) {
180
191
  const models = await listModels(env, opts.fetch);
192
+ const BACK = "\0back";
181
193
  if (models.length > 0) {
182
194
  const OTHER = "\0other";
183
195
  const picked = await ui.select({
184
196
  title: "Choose a model",
185
- options: [...models.map((m) => ({ label: m, value: m, ...(m === current ? { hint: "current" } : saved.includes(m) ? { hint: "saved" } : {}) })), { label: "Enter a name…", value: OTHER }],
197
+ options: [...models.map((m) => ({ label: m, value: m, ...(m === current ? { hint: "current" } : saved.includes(m) ? { hint: "saved" } : {}) })), { label: "Enter a name…", value: OTHER }, { label: "Back", value: BACK }],
186
198
  }, opts.signal);
199
+ if (picked === BACK)
200
+ return undefined;
187
201
  if (picked !== OTHER)
188
202
  return picked;
189
203
  }
@@ -229,11 +243,6 @@ export function configurator(opts) {
229
243
  return false;
230
244
  const key = answer || known;
231
245
  const serviceEnv = { JADE_PROVIDER: kind, [URL_KEY[kind]]: baseURL, [KEY_KEY[kind]]: key };
232
- if (kind === "openai-compat") {
233
- // 额外的请求参数跟着服务走:同一个服务保留,换了服务用保存过的那份
234
- const saved = services.find((s) => serviceId(s.env) === serviceId(serviceEnv));
235
- serviceEnv.OPENAI_COMPAT_EXTRA_BODY = saved ? saved.env.OPENAI_COMPAT_EXTRA_BODY : sameAddress(env) ? env.OPENAI_COMPAT_EXTRA_BODY : undefined;
236
- }
237
246
  const target = services.find((s) => serviceId(s.env) === serviceId(serviceEnv));
238
247
  const model = await chooseModel({ ...env, ...serviceEnv }, same ? current?.model : undefined, target?.models.map((m) => m.name));
239
248
  if (!model)
@@ -243,11 +252,15 @@ export function configurator(opts) {
243
252
  if (target && saved)
244
253
  return useSaved({ ...target, env: { ...target.env, ...pick(serviceEnv, serviceKeys(kind)) } }, saved);
245
254
  const updates = { ...serviceEnv, [MODEL_KEY[kind]]: model, JADE_CONTEXT_WINDOW: undefined };
246
- // 思考力度的取值每种服务不同
247
- if (!same)
248
- updates.JADE_EFFORT = undefined;
255
+ // 换了服务的新模型从新服务的默认值开始:思考力度、额外请求参数各服务写法不同,限速、输出上限、
256
+ // 能不能看图也是跟着服务和模型走的,沿用当前的容易错(例如免费服务的限速带到付费服务上)。
257
+ // 同一个服务(只换了密钥)照旧沿用
258
+ const sameService = same && sameAddress(env);
259
+ if (!sameService)
260
+ for (const k of MODEL_SETTINGS)
261
+ updates[k] = undefined;
249
262
  // 其他服务常常默认只给 4096 个输出 token,带思考的模型很容易用完
250
- if (kind !== "anthropic" && !env.JADE_MAX_TOKENS) {
263
+ if (kind !== "anthropic" && !(sameService && env.JADE_MAX_TOKENS)) {
251
264
  const max = await ui.input({ title: "Output limit per reply in tokens, e.g. 32000, 64K (empty for the service default)", initial: "32K" }, opts.signal);
252
265
  if (max === undefined || !tokensInput("Output limit", max))
253
266
  return false;
@@ -255,160 +268,248 @@ export function configurator(opts) {
255
268
  updates.JADE_MAX_TOKENS = max;
256
269
  }
257
270
  // 同一个地址只换了密钥:原来的服务下的模型归到新的密钥下
258
- const rekeyed = same && currentId !== undefined && sameAddress(env) && key !== env[KEY_KEY[kind]];
271
+ const rekeyed = sameService && currentId !== undefined && key !== env[KEY_KEY[kind]];
259
272
  return applyConfig(updates, rekeyed ? currentId : undefined);
260
273
  }
261
- /** 当前模型自己的设置(切换模型时跟着换):输出上限、思考力度、上下文窗口、限速、能不能看图 */
262
- async function configureSettings() {
263
- const env = opts.env();
264
- const info = providerInfo(env);
265
- const efforts = isBuiltinKind(info.kind) ? EFFORTS[info.kind] : undefined;
266
- const action = await ui.select({
267
- title: `Settings for ${info.model}`,
268
- options: [
269
- { label: "Output limit per reply", value: "max", hint: env.JADE_MAX_TOKENS ? `${env.JADE_MAX_TOKENS} tokens` : "service default" },
270
- ...(efforts ? [{ label: "Reasoning effort", value: "effort", hint: env.JADE_EFFORT ?? (info.kind === "anthropic" ? "high (default)" : "service default") }] : []),
271
- { label: "Context window", value: "window", hint: `${contextWindow(info.model, env)} tokens${env.JADE_CONTEXT_WINDOW ? "" : " (default)"}` },
272
- { label: "Requests per minute", value: "rpm", hint: env.JADE_RPM ? `${env.JADE_RPM}/min` : "no limit (slows down after being rate limited)" },
273
- { label: "Can see images", value: "vision", hint: visionHint(env, info.kind) },
274
- ],
275
- }, opts.signal);
276
- if (action === "max") {
277
- const max = await ui.input({ title: "Output limit per reply in tokens, e.g. 32000, 64K (empty for the service default)", initial: env.JADE_MAX_TOKENS ?? "32K" }, opts.signal);
278
- if (max !== undefined && tokensInput("Output limit", max))
279
- await applyConfig({ JADE_MAX_TOKENS: max || undefined });
280
- }
281
- else if (action === "effort" && efforts) {
282
- const DEFAULT = "\0default";
283
- const effort = await ui.select({
284
- title: "Reasoning effort",
285
- options: [...efforts.map((e) => ({ label: e, value: e, ...(e === env.JADE_EFFORT ? { hint: "current" } : {}) })), { label: "Default", value: DEFAULT, hint: info.kind === "anthropic" ? "high" : "service default" }],
286
- }, opts.signal);
287
- if (effort !== undefined)
288
- await applyConfig({ JADE_EFFORT: effort === DEFAULT ? undefined : effort });
289
- }
290
- else if (action === "rpm") {
291
- const n = await ui.input({ title: "Requests per minute, e.g. 20 for most free models (empty for no limit)", initial: env.JADE_RPM ?? "" }, opts.signal);
292
- if (n === undefined)
293
- return;
294
- try {
295
- rpmFromEnv({ JADE_RPM: n });
296
- }
297
- catch (err) {
298
- return report(errorText(err));
299
- }
300
- await applyConfig({ JADE_RPM: n.trim() || undefined });
301
- }
302
- else if (action === "vision") {
303
- const DEFAULT = "\0default";
304
- const current = visionSetting(env);
305
- const choice = await ui.select({
306
- title: "Can this model see images (screenshots, image files)?",
274
+ /**
275
+ * 某个模型的设置(输出上限、思考力度、上下文窗口、限速、能不能看图,openai-compat 还有额外请求参数)。
276
+ * 改完一项回到这个菜单接着改(重新读一遍,显示的是改过的值);Back 或 Esc 才离开
277
+ */
278
+ async function configureSettings(target) {
279
+ const { title, kind, model } = target;
280
+ const efforts = isBuiltinKind(kind) ? EFFORTS[kind] : undefined;
281
+ while (true) {
282
+ const env = await target.read();
283
+ const action = await ui.select({
284
+ title: `Settings for ${title}`,
307
285
  options: [
308
- { label: "Yes", value: "on", hint: current === true ? "current" : "images are sent to the model" },
309
- { label: "No", value: "off", hint: current === false ? "current" : "images are replaced with a note" },
310
- { label: "Default", value: DEFAULT, hint: isBuiltinKind(info.kind) && info.kind !== "openai-compat" ? "yes" : "no" },
286
+ { label: "Output limit per reply", value: "max", hint: env.JADE_MAX_TOKENS ? `${env.JADE_MAX_TOKENS} tokens` : kind === "anthropic" ? `${ANTHROPIC_DEFAULT_MAX_TOKENS} tokens (default)` : "service default" },
287
+ ...(efforts ? [{ label: "Reasoning effort", value: "effort", hint: env.JADE_EFFORT ?? (kind === "anthropic" ? "high (default)" : "service default") }] : []),
288
+ { label: "Context window", value: "window", hint: `${contextWindow(model, env)} tokens${env.JADE_CONTEXT_WINDOW ? "" : " (default)"}` },
289
+ { label: "Requests per minute", value: "rpm", hint: env.JADE_RPM ? `${env.JADE_RPM}/min` : "no limit (slows down after being rate limited)" },
290
+ { label: "Can see images", value: "vision", hint: visionHint(env, kind) },
291
+ ...(kind === "openai-compat" ? [{ label: "Extra request body", value: "extra", hint: env.OPENAI_COMPAT_EXTRA_BODY ? shorten(env.OPENAI_COMPAT_EXTRA_BODY) : "none" }] : []),
292
+ { label: "Back", value: "back" },
311
293
  ],
312
294
  }, opts.signal);
313
- if (choice === undefined)
295
+ if (action === undefined || action === "back")
314
296
  return;
315
- if (await applyConfig({ JADE_VISION: choice === DEFAULT ? undefined : choice })) {
316
- report(visionFromEnv(opts.env()) ? "Images will be sent to the model." : "Images will be replaced with a note.");
297
+ // 每一项里按 Esc 或者输入有误:什么都不改,回到这个菜单
298
+ if (action === "max") {
299
+ const max = await ui.input({ title: "Output limit per reply in tokens, e.g. 32000, 64K (empty for the service default)", initial: env.JADE_MAX_TOKENS ?? "32K" }, opts.signal);
300
+ if (max !== undefined && tokensInput("Output limit", max))
301
+ await target.update({ JADE_MAX_TOKENS: max || undefined });
302
+ }
303
+ else if (action === "effort" && efforts) {
304
+ const DEFAULT = "\0default";
305
+ const effort = await ui.select({
306
+ title: "Reasoning effort",
307
+ options: [...efforts.map((e) => ({ label: e, value: e, ...(e === env.JADE_EFFORT ? { hint: "current" } : {}) })), { label: "Default", value: DEFAULT, hint: kind === "anthropic" ? "high" : "service default" }],
308
+ }, opts.signal);
309
+ if (effort !== undefined)
310
+ await target.update({ JADE_EFFORT: effort === DEFAULT ? undefined : effort });
311
+ }
312
+ else if (action === "rpm") {
313
+ const n = await ui.input({ title: "Requests per minute, e.g. 20 for most free models (empty for no limit)", initial: env.JADE_RPM ?? "" }, opts.signal);
314
+ if (n === undefined)
315
+ continue;
316
+ try {
317
+ rpmFromEnv({ JADE_RPM: n });
318
+ }
319
+ catch (err) {
320
+ report(errorText(err));
321
+ continue;
322
+ }
323
+ await target.update({ JADE_RPM: n.trim() || undefined });
324
+ }
325
+ else if (action === "vision") {
326
+ const DEFAULT = "\0default";
327
+ const current = visionSetting(env);
328
+ const choice = await ui.select({
329
+ title: "Can this model see images (screenshots, image files)?",
330
+ options: [
331
+ { label: "Yes", value: "on", hint: current === true ? "current" : "images are sent to the model" },
332
+ { label: "No", value: "off", hint: current === false ? "current" : "images are replaced with a note" },
333
+ { label: "Default", value: DEFAULT, hint: isBuiltinKind(kind) && kind !== "openai-compat" ? "yes" : "no" },
334
+ ],
335
+ }, opts.signal);
336
+ if (choice === undefined)
337
+ continue;
338
+ if (await target.update({ JADE_VISION: choice === DEFAULT ? undefined : choice })) {
339
+ const on = choice === DEFAULT ? isBuiltinKind(kind) && kind !== "openai-compat" : choice === "on";
340
+ report(on ? "Images will be sent to the model." : "Images will be replaced with a note.");
341
+ }
342
+ }
343
+ else if (action === "window") {
344
+ const n = await ui.input({ title: "Context window in tokens, e.g. 128000, 512K, 1M (empty to infer it from the model name, or 256K if unknown)", initial: env.JADE_CONTEXT_WINDOW ?? "" }, opts.signal);
345
+ if (n !== undefined && tokensInput("Context window", n))
346
+ await target.update({ JADE_CONTEXT_WINDOW: n || undefined });
347
+ }
348
+ else if (action === "extra" && kind === "openai-compat") {
349
+ const text = await ui.input({ title: 'JSON merged into every request for this model, e.g. {"enable_thinking":true} (empty for none)', initial: env.OPENAI_COMPAT_EXTRA_BODY ?? "" }, opts.signal);
350
+ if (text === undefined)
351
+ continue;
352
+ if (text.trim()) {
353
+ try {
354
+ jsonObject("Extra request body", text);
355
+ }
356
+ catch (err) {
357
+ report(errorText(err));
358
+ continue;
359
+ }
360
+ }
361
+ await target.update({ OPENAI_COMPAT_EXTRA_BODY: text.trim() || undefined });
317
362
  }
318
363
  }
319
- else if (action === "window") {
320
- const n = await ui.input({ title: "Context window in tokens, e.g. 128000, 512K, 1M (empty to infer it from the model name, or 128K if unknown)", initial: env.JADE_CONTEXT_WINDOW ?? "" }, opts.signal);
321
- if (n !== undefined && tokensInput("Context window", n))
322
- await applyConfig({ JADE_CONTEXT_WINDOW: n || undefined });
364
+ }
365
+ /** 把模型的设置写进 models.json 里那一个模型;.env 不变(当前用的还是原来的模型)。改回默认值的设置从 settings 里删掉 */
366
+ async function writeSavedModel(service, model, settings) {
367
+ const id = serviceId(service.env);
368
+ const all = await readSavedServices(modelsFile);
369
+ const mine = id === undefined ? undefined : all.find((s) => serviceId(s.env) === id);
370
+ if (!mine) {
371
+ report(`Not saved: ${describeService(service)} is no longer in ${modelsFile}.`);
372
+ return false;
323
373
  }
374
+ const mineIndex = all.indexOf(mine);
375
+ const modelIndex = mine.models.findIndex((m) => m.name === model.name);
376
+ // 在文件里现在的设置上改:菜单打开之后 models.json 可能被别的会话改过
377
+ const merged = { ...(mine.models[modelIndex]?.settings ?? model.settings), ...pick(settings, MODEL_SETTINGS), ...blank(settings, MODEL_SETTINGS) };
378
+ const next = { name: model.name, settings: Object.fromEntries(Object.entries(merged).filter(([, v]) => v !== undefined && v !== "")) };
379
+ const models = modelIndex === -1 ? [next, ...mine.models] : [...mine.models.slice(0, modelIndex), next, ...mine.models.slice(modelIndex + 1)];
380
+ await writeSavedServices(modelsFile, [...all.slice(0, mineIndex), { ...mine, models }, ...all.slice(mineIndex + 1)]);
381
+ report(`Settings for ${model.name} (${describeService(mine)}) saved to ${modelsFile}.`);
382
+ return true;
383
+ }
384
+ /** 把保存过的模型从 models.json 里删掉;服务下没有模型了就连服务(和它的密钥)一起删掉 */
385
+ async function forgetModel(service, model) {
386
+ const id = serviceId(service.env);
387
+ if (!id)
388
+ return;
389
+ const rest = (await readSavedServices(modelsFile))
390
+ .map((s) => (serviceId(s.env) === id ? { ...s, models: s.models.filter((m) => m.name !== model.name) } : s))
391
+ .filter((s) => s.models.length > 0);
392
+ await writeSavedServices(modelsFile, rest);
393
+ report(`Removed ${model.name} (${describeService(service)}).`);
324
394
  }
325
395
  /**
326
- * 从几个服务里选一个保存过的模型:只有一个服务时直接列它的模型,否则先选服务。
327
- * keep 过滤可选的模型;取消时返回 undefined
396
+ * 选中主菜单里一个模型后:切换、配置它(不用先切到它)、把它删掉或返回主菜单。
397
+ * 当前的模型只能配置(切换没意义;删掉了下次进 /model 又会被记回来)。从设置里出来回到这个菜单;
398
+ * 切换、删除、Back 或 Esc 回到主菜单
328
399
  */
329
- async function pickSaved(from, title, keep = () => true) {
330
- const groups = from.map((s) => ({ service: s, models: s.models.filter((m) => keep(s, m)) })).filter((g) => g.models.length > 0);
331
- let group = groups[0];
332
- if (groups.length > 1) {
333
- const chosen = await ui.select({ title, options: groups.map((g, i) => ({ label: describeService(g.service), value: String(i), hint: modelNames(g.models) })) }, opts.signal);
334
- if (chosen === undefined)
335
- return undefined;
336
- group = groups[Number(chosen)];
400
+ async function pickModelAction(o, isCurrent) {
401
+ const kind = providerKind(o.service.env);
402
+ // 当前的模型改 .env 就好——applyConfig 里的 remember 会把改完的 .env 写回 models.json;
403
+ // 其他保存过的模型只改 models.json 里的那一个
404
+ const read = isCurrent ? async () => pick(opts.env(), MODEL_SETTINGS) : () => savedSettings(o.service, o.model);
405
+ while (true) {
406
+ const settings = await read();
407
+ const action = await ui.select({
408
+ title: o.model.name,
409
+ options: [
410
+ ...(isCurrent
411
+ ? []
412
+ : [{ label: "Switch to it", value: "switch", hint: serviceId(o.service.env) === serviceId(opts.env()) ? "this service" : describeService(o.service) }]),
413
+ { label: "Settings…", value: "settings", hint: settingsSummary(settings, kind, contextWindow(o.model.name, settings)) },
414
+ ...(isCurrent ? [] : [{ label: "Remove", value: "forget" }]),
415
+ { label: "Back", value: "back" },
416
+ ],
417
+ }, opts.signal);
418
+ if (action === "settings") {
419
+ await configureSettings({
420
+ title: o.model.name,
421
+ kind,
422
+ model: o.model.name,
423
+ read,
424
+ update: (updates) => (isCurrent ? applyConfig(updates) : writeSavedModel(o.service, o.model, updates)),
425
+ });
426
+ continue;
427
+ }
428
+ // 用刚读到的设置切换:在这个菜单里改过的也带上
429
+ if (action === "switch")
430
+ await useSaved(o.service, { ...o.model, settings });
431
+ else if (action === "forget")
432
+ await forgetModel(o.service, o.model);
433
+ return;
337
434
  }
338
- if (!group)
339
- return undefined;
340
- const chosen = await ui.select({ title: `Model (${describeService(group.service)})`, options: group.models.map((m, i) => ({ label: m.name, value: String(i) })) }, opts.signal);
341
- if (chosen === undefined)
342
- return undefined;
343
- const model = group.models[Number(chosen)];
344
- return model && { service: group.service, model };
435
+ }
436
+ /** 保存过的模型在 models.json 里现在的设置;找不到时用 fallback 那份 */
437
+ async function savedSettings(service, fallback) {
438
+ const id = serviceId(service.env);
439
+ const mine = id === undefined ? undefined : (await readSavedServices(modelsFile)).find((s) => serviceId(s.env) === id);
440
+ return mine?.models.find((m) => m.name === fallback.name)?.settings ?? fallback.settings;
345
441
  }
346
442
  async function configureModel(arg) {
347
443
  const env = opts.env();
348
444
  // 还没有配置模型:没有"当前的服务"可以换模型,先选服务
349
445
  if (!hasProvider(env))
350
446
  return void (await configureProvider());
351
- const info = providerInfo(env);
352
447
  // 之前只有 .env 时配置的模型也记下来,之后换了不会丢
353
448
  await remember().catch(() => { });
354
- const currentId = serviceId(env);
355
- const services = await savedServices();
356
- /** 保存过的、不是当前的模型,按服务分组:当前服务的在前 */
357
- const others = [...services.filter((s) => serviceId(s.env) === currentId), ...services.filter((s) => serviceId(s.env) !== currentId)].flatMap((s) => s.models.filter((m) => !(serviceId(s.env) === currentId && m.name === info.model)).map((m) => ({ service: s, model: m })));
358
449
  if (arg) {
359
450
  // 保存过的模型按名字切换(当前服务的优先),否则换当前服务的模型
360
- const saved = others.find((o) => o.model.name === arg);
451
+ const saved = otherModels(await savedServices(), serviceId(env), providerInfo(env).model).find((o) => o.model.name === arg);
361
452
  return void (await (saved ? useSaved(saved.service, saved.model) : switchModel(arg)));
362
453
  }
363
- // 主菜单只管切换:保存过的模型全部直接列出(当前的在最前,然后是同一服务的),选中就换;
364
- // 添加模型、当前模型的设置、删除各占一项,细节进子菜单再看
365
- const here = describeService({ env: isBuiltinKind(providerKind(env)) ? pick(env, serviceKeys(providerKind(env))) : {}, models: [] });
366
- const multi = services.length > 1;
367
- const action = await ui.select({
368
- title: "Switch model",
369
- options: [
370
- { label: info.model, value: "current", hint: multi ? `current · ${here}` : "current" },
371
- ...others.map((o, i) => ({ label: o.model.name, value: `saved:${i}`, ...(multi ? { hint: describeService(o.service) } : {}) })),
372
- { label: "Add a model…", value: "add", hint: "from this service or another one" },
373
- { label: `Settings for ${info.model}…`, value: "settings", hint: settingsSummary(env, info.kind, contextWindow(info.model, env)) },
374
- ...(others.length ? [{ label: "Remove a saved model…", value: "forget" }] : []),
375
- ],
376
- }, opts.signal);
377
- if (action?.startsWith("saved:")) {
378
- const o = others[Number(action.slice(6))];
379
- await useSaved(o.service, o.model);
380
- }
381
- else if (action === "add") {
382
- const where = await ui.select({
383
- title: "Add a model from",
454
+ // 主菜单循环:保存过的模型全部直接列出(当前的在最前,然后是同一服务的),选中出一个子菜单
455
+ // (切换 / 设置 / 删除 / 返回);配置某个模型、把它删掉都不用先切到它,做完回到主菜单再选。
456
+ // 每一轮都重读当前配置:切换、配置之后模型和它的设置可能都变了
457
+ while (true) {
458
+ const env = opts.env();
459
+ const id = serviceId(env);
460
+ const kind = providerKind(env);
461
+ const kindKnown = isBuiltinKind(kind);
462
+ const info = providerInfo(env);
463
+ const here = describeService({ env: kindKnown ? pick(env, serviceKeys(kind)) : {}, models: [] });
464
+ const services = await savedServices();
465
+ const multi = services.length > 1;
466
+ const others = otherModels(services, id, info.model);
467
+ const action = await ui.select({
468
+ title: "Switch model",
384
469
  options: [
385
- { label: "This service", value: "model", hint: here },
386
- { label: "Another service…", value: "provider", hint: "or change this one's base URL / API key" },
470
+ {
471
+ label: info.model,
472
+ value: "current",
473
+ hint: `${multi ? `${here} · ` : ""}current · ${settingsSummary(env, info.kind, contextWindow(info.model, env))}`,
474
+ },
475
+ ...others.map((o, i) => ({
476
+ label: o.model.name,
477
+ value: `saved:${i}`,
478
+ hint: `${multi ? `${describeService(o.service)} · ` : ""}${settingsSummary(o.model.settings, providerKind(o.service.env), contextWindow(o.model.name, o.model.settings))}`,
479
+ })),
480
+ { label: "Add a model…", value: "add", hint: "from this service or another one" },
387
481
  ],
388
482
  }, opts.signal);
389
- if (where === "model") {
390
- const saved = services.find((s) => serviceId(s.env) === currentId)?.models.map((m) => m.name);
391
- const model = await chooseModel(env, info.model, saved);
392
- if (model && model !== info.model)
393
- await switchModel(model);
483
+ if (action === undefined)
484
+ return; // Esc:整个 /model 结束
485
+ if (action === "current") {
486
+ const service = { env: kindKnown ? { ...pick(env, serviceKeys(kind)), JADE_PROVIDER: kind } : { JADE_PROVIDER: kind }, models: [] };
487
+ await pickModelAction({ service, model: { name: info.model, settings: pick(env, MODEL_SETTINGS) } }, true);
488
+ }
489
+ else if (action.startsWith("saved:")) {
490
+ const o = others[Number(action.slice(6))];
491
+ if (o)
492
+ await pickModelAction(o, false);
493
+ }
494
+ else if (action === "add") {
495
+ const where = await ui.select({
496
+ title: "Add a model from",
497
+ options: [
498
+ { label: "This service", value: "model", hint: here },
499
+ { label: "Another service…", value: "provider", hint: "or change this one's base URL / API key" },
500
+ { label: "Back", value: "back" },
501
+ ],
502
+ }, opts.signal);
503
+ // 做完、Back、Esc 或没填完,都回到主菜单
504
+ if (where === "model") {
505
+ const saved = services.find((s) => serviceId(s.env) === id)?.models.map((m) => m.name);
506
+ const model = await chooseModel(env, info.model, saved);
507
+ if (model && model !== info.model)
508
+ await switchModel(model);
509
+ }
510
+ else if (where === "provider")
511
+ await configureProvider();
394
512
  }
395
- else if (where === "provider")
396
- await configureProvider();
397
- }
398
- else if (action === "settings")
399
- await configureSettings();
400
- else if (action === "forget") {
401
- const owners = services.filter((s) => others.some((o) => o.service === s));
402
- const gone = await pickSaved(owners, "Remove a model from which service?", (s, m) => !(serviceId(s.env) === currentId && m.name === info.model));
403
- if (!gone)
404
- return;
405
- const id = serviceId(gone.service.env);
406
- // 服务下没有模型了就连服务(和它的密钥)一起删掉;认不出的服务原样保留
407
- const rest = (await readSavedServices(modelsFile))
408
- .map((s) => (serviceId(s.env) === id ? { ...s, models: s.models.filter((m) => m.name !== gone.model.name) } : s))
409
- .filter((s) => s.models.length > 0);
410
- await writeSavedServices(modelsFile, rest);
411
- report(`Removed ${gone.model.name} (${describeService(gone.service)}).`);
412
513
  }
413
514
  }
414
515
  return { provider: configureProvider, model: configureModel };
@@ -1,9 +1,9 @@
1
1
  // 模型的上下文窗口(最大输入 token 数)。前端显示上下文用量,以后的 jade/compact 据此决定什么时候压缩。
2
2
  //
3
- // 窗口优先取 JADE_CONTEXT_WINDOW;不设时按模型名在一张小表里找(只收录确定的、取偏小的值),找不到用 128000。
3
+ // 窗口优先取 JADE_CONTEXT_WINDOW;不设时按模型名在一张小表里找(只收录确定的、取偏小的值),找不到用 256000。
4
4
  import { parseTokens } from "./config.js";
5
5
  /** 认不出模型时的窗口 */
6
- export const DEFAULT_CONTEXT_WINDOW = 128_000;
6
+ export const DEFAULT_CONTEXT_WINDOW = 256_000;
7
7
  /** 模型名(不区分大小写,可以带 "anthropic/" 这类前缀)→ 窗口;按顺序取第一个匹配的 */
8
8
  const KNOWN_WINDOWS = [
9
9
  [/claude/i, 200_000],
@@ -4,12 +4,12 @@
4
4
  // /model 改了配置之后不用重开会话:provider@1 给核心的是一个转发到当前 provider 的壳(设计第 10 节),
5
5
  // 下一次请求就用新的。
6
6
  import path from "node:path";
7
- import { definePlugin } from "../../dist/api.js";
7
+ import { definePlugin } from "@uncarved/jade-api";
8
8
  import { contextWindow } from "./context.js";
9
9
  import { envWithFile, hasProvider, parseTokens } from "./config.js";
10
10
  import { configurator } from "./configure.js";
11
11
  import { isBuiltinKind, listModels, MODEL_KEY, providerFromEnv, providerInfo, providerKind, RateGate, rpmFromEnv, visionFromEnv, withRetry } from "./provider.js";
12
- import { readSavedServices } from "./saved.js";
12
+ import { MODEL_SETTINGS, readSavedServices } from "./saved.js";
13
13
  export default definePlugin({
14
14
  async process(ctx) {
15
15
  const envFile = path.join(ctx.home, ".env");
@@ -60,27 +60,38 @@ export default definePlugin({
60
60
  };
61
61
  /** 保存过的模型的 provider,按配置缓存:models.json 里的密钥或设置改了就另建一份 */
62
62
  const savedProviders = new Map();
63
+ const cachedBuild = (snapshot) => {
64
+ const key = JSON.stringify(snapshot);
65
+ const cached = savedProviders.get(key);
66
+ if (cached)
67
+ return cached;
68
+ const p = build(snapshot);
69
+ savedProviders.set(key, p);
70
+ // 创建失败时下次重试
71
+ p.catch(() => savedProviders.delete(key));
72
+ return p;
73
+ };
63
74
  const saved = async (name) => {
64
75
  for (const s of await readSavedServices(modelsFile)) {
65
76
  const m = s.models.find((x) => x.name === name);
66
77
  const kind = providerKind(s.env);
67
78
  if (!m || !isBuiltinKind(kind))
68
79
  continue;
69
- const snapshot = { ...s.env, ...m.settings, JADE_PROVIDER: kind, [MODEL_KEY[kind]]: m.name };
70
- const key = JSON.stringify(snapshot);
71
- const cached = savedProviders.get(key);
72
- if (cached)
73
- return cached;
74
- const p = build(snapshot);
75
- savedProviders.set(key, p);
76
- // 创建失败时下次重试
77
- p.catch(() => savedProviders.delete(key));
78
- return p;
80
+ return cachedBuild({ ...s.env, ...m.settings, JADE_PROVIDER: kind, [MODEL_KEY[kind]]: m.name });
79
81
  }
82
+ if (!hasProvider(env))
83
+ throw notConfigured();
80
84
  // 只写在 .env 里、没保存过的当前模型
81
- if (hasProvider(env) && providerInfo(env).model === name)
85
+ if (providerInfo(env).model === name)
82
86
  return provider();
83
- throw new Error(`model ${JSON.stringify(name)} is not one of the models saved by /model (${modelsFile})`);
87
+ // 当前服务上的另一个模型(没保存过):用这个服务的地址和密钥,不带当前模型自己的设置,用服务的默认值
88
+ const kind = providerKind(env);
89
+ if (!isBuiltinKind(kind))
90
+ throw new Error(`model ${JSON.stringify(name)} is not one of the models saved by /model (${modelsFile})`);
91
+ const snapshot = { ...env, JADE_PROVIDER: kind, [MODEL_KEY[kind]]: name };
92
+ for (const k of MODEL_SETTINGS)
93
+ delete snapshot[k];
94
+ return cachedBuild(snapshot);
84
95
  };
85
96
  const current = (request, options) => provider().then((p) => p.complete(request, options));
86
97
  const complete = (request, { model, ...options }) => (model ? saved(model).then((p) => p.complete(request, options)) : current(request, options));
@@ -162,6 +173,18 @@ export default definePlugin({
162
173
  },
163
174
  });
164
175
  },
176
+ session(ctx) {
177
+ // 重试过的请求:把每次失败写进会话日志,事后能查到为什么慢、为什么重新输出(插件事件,不进上下文)
178
+ ctx.kernel.hook({
179
+ kind: "observe",
180
+ point: "model.after",
181
+ fn: async (res, hook) => {
182
+ const retries = res.retries;
183
+ if (retries?.length)
184
+ await hook.emit("retried", { retries });
185
+ },
186
+ });
187
+ },
165
188
  });
166
189
  function via(kind, baseURL) {
167
190
  const host = baseURL ? safeHost(baseURL) : undefined;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "jade/models",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "api": "^1",
5
5
  "entry": "./index.js",
6
6
  "provides": [