@octopi-agent/engine 0.102.10 → 0.121.10

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 (317) hide show
  1. package/dist/builtin-model-info.js +28 -7
  2. package/dist/config-admin/agent-presets.d.ts +32 -0
  3. package/dist/config-admin/agent-presets.js +133 -0
  4. package/dist/config-admin/discover.d.ts +33 -4
  5. package/dist/config-admin/discover.js +101 -6
  6. package/dist/config-admin/env.d.ts +11 -0
  7. package/dist/config-admin/env.js +41 -0
  8. package/dist/config-admin/error-copy.d.ts +106 -0
  9. package/dist/config-admin/error-copy.js +287 -0
  10. package/dist/config-admin/i18n.d.ts +21 -0
  11. package/dist/config-admin/i18n.js +19 -0
  12. package/dist/config-admin/index.d.ts +6 -2
  13. package/dist/config-admin/index.js +3 -1
  14. package/dist/config-admin/model-presets.d.ts +14 -0
  15. package/dist/config-admin/model-presets.js +595 -70
  16. package/dist/config-admin/onboarding-apply.d.ts +71 -0
  17. package/dist/config-admin/onboarding-apply.js +235 -0
  18. package/dist/config-admin/onboarding.d.ts +154 -0
  19. package/dist/config-admin/onboarding.js +270 -0
  20. package/dist/config-admin/redact.d.ts +42 -9
  21. package/dist/config-admin/redact.js +69 -5
  22. package/dist/config-schema/agent.d.ts +5 -1
  23. package/dist/config-schema/agent.js +20 -2
  24. package/dist/config-schema/browser.d.ts +62 -0
  25. package/dist/config-schema/browser.js +89 -0
  26. package/dist/config-schema/context.d.ts +7 -2
  27. package/dist/config-schema/context.js +6 -3
  28. package/dist/config-schema/engine.d.ts +86 -7
  29. package/dist/config-schema/engine.js +9 -2
  30. package/dist/config-schema/governance.d.ts +12 -1
  31. package/dist/config-schema/governance.js +10 -2
  32. package/dist/config-schema/models.d.ts +12 -8
  33. package/dist/config-schema/models.js +16 -1
  34. package/dist/config-schema/run.d.ts +4 -0
  35. package/dist/config-schema/run.js +10 -0
  36. package/dist/config-schema/shared.d.ts +1 -0
  37. package/dist/config-schema/shared.js +4 -2
  38. package/dist/config-schema/substrate.d.ts +5 -0
  39. package/dist/config-schema/substrate.js +8 -0
  40. package/dist/config.d.ts +116 -10
  41. package/dist/config.js +109 -13
  42. package/dist/file-mode.d.ts +67 -0
  43. package/dist/file-mode.js +182 -0
  44. package/dist/fork-child.d.ts +82 -0
  45. package/dist/fork-child.js +123 -0
  46. package/dist/harness/activation/delegated-run.d.ts +42 -0
  47. package/dist/harness/activation/delegated-run.js +71 -0
  48. package/dist/harness/activation/dispatcher.js +4 -0
  49. package/dist/harness/activation/index.d.ts +1 -0
  50. package/dist/harness/activation/run-backend.d.ts +92 -0
  51. package/dist/harness/activation/run-backend.js +16 -0
  52. package/dist/harness/activation/run-protocol.d.ts +392 -0
  53. package/dist/harness/activation/run-protocol.js +19 -0
  54. package/dist/harness/activation/runtime.d.ts +33 -0
  55. package/dist/harness/activation/runtime.js +119 -28
  56. package/dist/harness/activation/types.d.ts +19 -2
  57. package/dist/harness/agent/builder.d.ts +12 -0
  58. package/dist/harness/agent/builder.js +78 -22
  59. package/dist/harness/agent/config-bridge.d.ts +10 -1
  60. package/dist/harness/agent/config-bridge.js +15 -3
  61. package/dist/harness/agent/registered-tool-adapter.d.ts +27 -0
  62. package/dist/harness/agent/registered-tool-adapter.js +67 -0
  63. package/dist/harness/agent/wire-agent-builder.d.ts +2 -0
  64. package/dist/harness/agent/wire-agent-builder.js +9 -2
  65. package/dist/harness/capabilities/document/backends/plain.js +2 -1
  66. package/dist/harness/capabilities/document/legacy/factory.js +3 -2
  67. package/dist/harness/collaboration/autonomous-subsystem/audit/reader.d.ts +17 -0
  68. package/dist/harness/collaboration/autonomous-subsystem/audit/reader.js +66 -36
  69. package/dist/harness/collaboration/autonomous-subsystem/audit/writer.d.ts +6 -2
  70. package/dist/harness/collaboration/autonomous-subsystem/audit/writer.js +27 -7
  71. package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +13 -0
  72. package/dist/harness/collaboration/autonomous-subsystem/loader.js +1 -0
  73. package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +11 -0
  74. package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -0
  75. package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +13 -3
  76. package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +48 -39
  77. package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -0
  78. package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +4 -0
  79. package/dist/harness/collaboration/delegation/child-run.d.ts +9 -0
  80. package/dist/harness/collaboration/delegation/child-run.js +34 -2
  81. package/dist/harness/collaboration/delegation/registry-types.d.ts +2 -0
  82. package/dist/harness/collaboration/delegation/service.d.ts +9 -4
  83. package/dist/harness/collaboration/delegation/service.js +33 -12
  84. package/dist/harness/collaboration/delegation/store.d.ts +2 -0
  85. package/dist/harness/collaboration/delegation/store.js +1 -0
  86. package/dist/harness/collaboration/delegation/types.d.ts +11 -0
  87. package/dist/harness/collaboration/delegation/wiring.d.ts +2 -0
  88. package/dist/harness/collaboration/delegation/wiring.js +1 -0
  89. package/dist/harness/context/capabilities/compact/engine.d.ts +44 -5
  90. package/dist/harness/context/capabilities/compact/engine.js +127 -39
  91. package/dist/harness/context/capabilities/compact/index.d.ts +2 -1
  92. package/dist/harness/context/capabilities/compact/index.js +1 -1
  93. package/dist/harness/context/capabilities/compact/types.d.ts +59 -9
  94. package/dist/harness/context/capabilities/summary/gate.d.ts +19 -2
  95. package/dist/harness/context/capabilities/summary/gate.js +53 -6
  96. package/dist/harness/context/capabilities/summary/registry.js +20 -0
  97. package/dist/harness/context/capabilities/summary/tool-binding.js +16 -12
  98. package/dist/harness/context/capabilities/summary/tool-bindings.d.ts +13 -0
  99. package/dist/harness/context/capabilities/summary/tool-bindings.js +22 -0
  100. package/dist/harness/context/capabilities/summary/types.d.ts +16 -0
  101. package/dist/harness/context/constitution/default-agents.md +85 -0
  102. package/dist/harness/context/context-size-ledger.js +8 -1
  103. package/dist/harness/context/default-context-engine.d.ts +100 -6
  104. package/dist/harness/context/default-context-engine.js +382 -89
  105. package/dist/harness/context/index.d.ts +2 -1
  106. package/dist/harness/context/index.js +1 -0
  107. package/dist/harness/context/layer-health.d.ts +4 -0
  108. package/dist/harness/context/layer-health.js +4 -0
  109. package/dist/harness/context/layer-types.d.ts +57 -0
  110. package/dist/harness/context/layer-types.js +73 -1
  111. package/dist/harness/context/layers.d.ts +3 -0
  112. package/dist/harness/context/layers.js +13 -6
  113. package/dist/harness/context/prefix-fingerprint.d.ts +46 -0
  114. package/dist/harness/context/prefix-fingerprint.js +52 -0
  115. package/dist/harness/context/summarize.js +18 -0
  116. package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
  117. package/dist/harness/context/system-prompt-assembler.js +5 -2
  118. package/dist/harness/context/tool-result-aging.d.ts +104 -16
  119. package/dist/harness/context/tool-result-aging.js +211 -57
  120. package/dist/harness/context/types.d.ts +71 -4
  121. package/dist/harness/context/types.js +25 -1
  122. package/dist/harness/extension/execution-environment/effect-policy.d.ts +4 -3
  123. package/dist/harness/extension/execution-environment/effect-policy.js +2 -2
  124. package/dist/harness/extension/execution-environment/privileged-exec.js +4 -1
  125. package/dist/harness/extension/execution-environment/workspace.js +1 -1
  126. package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +27 -1
  127. package/dist/harness/extension/plugin-ecosystem/channel-types.js +11 -2
  128. package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +12 -0
  129. package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +25 -0
  130. package/dist/harness/extension/plugin-ecosystem/commands/builtin.js +28 -1
  131. package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
  132. package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
  133. package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +168 -1
  134. package/dist/harness/extension/plugin-ecosystem/plugins/api.js +156 -15
  135. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.d.ts +95 -0
  136. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.js +170 -0
  137. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.d.ts +178 -0
  138. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.js +314 -0
  139. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +40 -5
  140. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +45 -26
  141. package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -1
  142. package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +11 -1
  143. package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +42 -76
  144. package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +30 -1
  145. package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +46 -0
  146. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +9 -0
  147. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +19 -14
  148. package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +3 -1
  149. package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +1 -1
  150. package/dist/harness/extension/plugin-ecosystem/tools/browser-types.d.ts +333 -0
  151. package/dist/harness/extension/plugin-ecosystem/tools/browser-types.js +16 -0
  152. package/dist/harness/extension/plugin-ecosystem/tools/browser.d.ts +64 -0
  153. package/dist/harness/extension/plugin-ecosystem/tools/browser.js +692 -0
  154. package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +0 -37
  155. package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +108 -4
  156. package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -0
  157. package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +34 -0
  158. package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +0 -6
  159. package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +57 -4
  160. package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +81 -13
  161. package/dist/harness/extension/plugin-ecosystem/tools/http.js +5 -0
  162. package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +13 -7
  163. package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +126 -14
  164. package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +1 -1
  165. package/dist/harness/extension/plugin-ecosystem/tools/platform.js +44 -5
  166. package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +10 -24
  167. package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +7 -0
  168. package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +4 -0
  169. package/dist/harness/governance/credentials/db.d.ts +9 -0
  170. package/dist/harness/governance/credentials/db.js +122 -31
  171. package/dist/harness/governance/credentials/store.d.ts +68 -7
  172. package/dist/harness/governance/credentials/store.js +177 -64
  173. package/dist/harness/governance/credentials/types.d.ts +13 -2
  174. package/dist/harness/governance/index.d.ts +1 -0
  175. package/dist/harness/governance/index.js +1 -0
  176. package/dist/harness/governance/registry/db.d.ts +32 -0
  177. package/dist/harness/governance/registry/db.js +142 -0
  178. package/dist/harness/governance/registry/index.d.ts +9 -0
  179. package/dist/harness/governance/registry/index.js +9 -0
  180. package/dist/harness/governance/registry/service.d.ts +381 -0
  181. package/dist/harness/governance/registry/service.js +825 -0
  182. package/dist/harness/governance/registry/types.d.ts +77 -0
  183. package/dist/harness/governance/registry/types.js +7 -0
  184. package/dist/harness/governance/security/default-security-guard.d.ts +3 -0
  185. package/dist/harness/governance/security/default-security-guard.js +12 -1
  186. package/dist/harness/governance/security/risk-evaluator.d.ts +13 -3
  187. package/dist/harness/governance/security/risk-evaluator.js +307 -21
  188. package/dist/harness/governance/security/shell-parser-treesitter.js +12 -4
  189. package/dist/harness/governance/session-acl/tool-rights.d.ts +1 -0
  190. package/dist/harness/index.d.ts +5 -3
  191. package/dist/harness/index.js +2 -2
  192. package/dist/harness/knowledge/boot-config.d.ts +2 -0
  193. package/dist/harness/knowledge/boot-config.js +2 -0
  194. package/dist/harness/knowledge/client.d.ts +53 -7
  195. package/dist/harness/knowledge/client.js +77 -20
  196. package/dist/harness/knowledge/db.d.ts +16 -0
  197. package/dist/harness/knowledge/db.js +107 -41
  198. package/dist/harness/knowledge/engine-thread.js +5 -7
  199. package/dist/harness/knowledge/grounding.js +4 -1
  200. package/dist/harness/knowledge/http-app.d.ts +15 -0
  201. package/dist/harness/knowledge/http-app.js +82 -21
  202. package/dist/harness/knowledge/http-bridge.d.ts +15 -0
  203. package/dist/harness/knowledge/http-bridge.js +19 -0
  204. package/dist/harness/knowledge/knowledge-serve-child.js +2 -3
  205. package/dist/harness/knowledge/query-service.d.ts +12 -2
  206. package/dist/harness/knowledge/query-service.js +75 -41
  207. package/dist/harness/knowledge/query-worker-client.d.ts +5 -1
  208. package/dist/harness/knowledge/query-worker-client.js +4 -1
  209. package/dist/harness/knowledge/query-worker.js +5 -3
  210. package/dist/harness/knowledge/read-http.d.ts +2 -0
  211. package/dist/harness/knowledge/read-http.js +9 -2
  212. package/dist/harness/knowledge/retriever.d.ts +1 -1
  213. package/dist/harness/knowledge/retriever.js +1 -2
  214. package/dist/harness/knowledge/serve.d.ts +6 -1
  215. package/dist/harness/knowledge/serve.js +5 -6
  216. package/dist/harness/knowledge/source-store.d.ts +101 -5
  217. package/dist/harness/knowledge/source-store.js +297 -71
  218. package/dist/harness/knowledge/start-service-process.d.ts +27 -8
  219. package/dist/harness/knowledge/start-service-process.js +49 -90
  220. package/dist/harness/knowledge/tenant-gate.d.ts +81 -0
  221. package/dist/harness/knowledge/tenant-gate.js +167 -0
  222. package/dist/harness/knowledge/writer-service.d.ts +18 -2
  223. package/dist/harness/knowledge/writer-service.js +80 -16
  224. package/dist/harness/knowledge/writer-worker-client.d.ts +9 -2
  225. package/dist/harness/knowledge/writer-worker-client.js +20 -3
  226. package/dist/harness/knowledge/writer-worker.js +11 -4
  227. package/dist/harness/memory/backfill-trigger.d.ts +10 -3
  228. package/dist/harness/memory/backfill-trigger.js +19 -19
  229. package/dist/harness/memory/cognition-seeds.d.ts +45 -0
  230. package/dist/harness/memory/cognition-seeds.js +67 -0
  231. package/dist/harness/memory/cognition.d.ts +12 -3
  232. package/dist/harness/memory/cognition.js +55 -35
  233. package/dist/harness/memory/conceptualizer.d.ts +11 -1
  234. package/dist/harness/memory/conceptualizer.js +10 -1
  235. package/dist/harness/memory/context-slice.d.ts +42 -0
  236. package/dist/harness/memory/context-slice.js +197 -0
  237. package/dist/harness/memory/health-probe.d.ts +8 -2
  238. package/dist/harness/memory/health-probe.js +10 -13
  239. package/dist/harness/memory/index.d.ts +5 -1
  240. package/dist/harness/memory/index.js +3 -1
  241. package/dist/harness/memory/sqlite/agent-db.d.ts +1 -0
  242. package/dist/harness/memory/sqlite/agent-db.js +9 -8
  243. package/dist/harness/memory/sqlite/cognition-store.d.ts +26 -3
  244. package/dist/harness/memory/sqlite/cognition-store.js +103 -45
  245. package/dist/harness/memory/sqlite/memory-store.js +4 -0
  246. package/dist/harness/memory/sqlite/sqlite-vec.d.ts +24 -1
  247. package/dist/harness/memory/sqlite/sqlite-vec.js +37 -1
  248. package/dist/harness/memory/types.d.ts +18 -2
  249. package/dist/harness/observability/observer/hub.d.ts +10 -0
  250. package/dist/harness/observability/observer/hub.js +95 -2
  251. package/dist/harness/run/agent/agent.js +3 -2
  252. package/dist/harness/run/concurrency/tool-validator.js +4 -3
  253. package/dist/harness/run/reliability/run-agent.d.ts +22 -0
  254. package/dist/harness/run/reliability/run-agent.js +79 -10
  255. package/dist/harness/run/run-host.d.ts +302 -0
  256. package/dist/harness/run/run-host.js +978 -0
  257. package/dist/harness/run/run-scope.d.ts +11 -0
  258. package/dist/harness/run/run-scope.js +19 -1
  259. package/dist/harness/run/runner.d.ts +149 -22
  260. package/dist/harness/run/runner.js +352 -35
  261. package/dist/harness/session/in-memory-store.js +13 -1
  262. package/dist/harness/session/schedules/service.d.ts +10 -2
  263. package/dist/harness/session/schedules/service.js +13 -2
  264. package/dist/harness/session/tasks/tools.js +12 -0
  265. package/dist/harness/session/types.d.ts +10 -14
  266. package/dist/harness/shared/events/agent-event-map.d.ts +29 -0
  267. package/dist/harness/shared/types/agent-definition.d.ts +6 -0
  268. package/dist/index.d.ts +3 -2
  269. package/dist/index.js +2 -1
  270. package/dist/integration/agent-runtime/channel-message-source.d.ts +3 -1
  271. package/dist/integration/agent-runtime/channel-message-source.js +4 -3
  272. package/dist/integration/browser/camoufox.d.ts +40 -0
  273. package/dist/integration/browser/camoufox.js +80 -0
  274. package/dist/integration/browser/index.d.ts +91 -0
  275. package/dist/integration/browser/index.js +110 -0
  276. package/dist/integration/browser/install.d.ts +47 -0
  277. package/dist/integration/browser/install.js +214 -0
  278. package/dist/integration/browser/playwright.d.ts +224 -0
  279. package/dist/integration/browser/playwright.js +925 -0
  280. package/dist/integration/browser/service.d.ts +41 -0
  281. package/dist/integration/browser/service.js +181 -0
  282. package/dist/integration/browser/stealth.d.ts +42 -0
  283. package/dist/integration/browser/stealth.js +104 -0
  284. package/dist/integration/providers/anthropic-message-normalize.d.ts +20 -0
  285. package/dist/integration/providers/anthropic-message-normalize.js +48 -0
  286. package/dist/integration/providers/anthropic.js +27 -2
  287. package/dist/integration/providers/fetch-timeout.d.ts +17 -0
  288. package/dist/integration/providers/fetch-timeout.js +24 -0
  289. package/dist/integration/providers/openai.d.ts +8 -0
  290. package/dist/integration/providers/openai.js +41 -1
  291. package/dist/integration/providers/wire-dump-diff.js +2 -1
  292. package/dist/integration/providers/wire-dump.d.ts +56 -2
  293. package/dist/integration/providers/wire-dump.js +119 -6
  294. package/dist/integration/storage/archive-manager.d.ts +14 -2
  295. package/dist/integration/storage/archive-manager.js +24 -8
  296. package/dist/integration/storage/atomic-tmp.d.ts +12 -0
  297. package/dist/integration/storage/atomic-tmp.js +36 -0
  298. package/dist/integration/storage/jsonl.d.ts +9 -0
  299. package/dist/integration/storage/jsonl.js +137 -38
  300. package/dist/integration/storage/session-index.d.ts +5 -0
  301. package/dist/integration/storage/session-index.js +25 -4
  302. package/dist/integration/tools/assemble.d.ts +50 -0
  303. package/dist/integration/tools/assemble.js +137 -0
  304. package/dist/paths.d.ts +18 -0
  305. package/dist/paths.js +36 -0
  306. package/dist/subsystems/cognition-steward/conceptualize/config.yaml +3 -1
  307. package/dist/subsystems/cognition-steward/conceptualize/handler.js +74 -5
  308. package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +3 -2
  309. package/dist/subsystems/cognition-steward/consolidate/config.yaml +11 -2
  310. package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +6 -3
  311. package/dist/subsystems/cognition-steward/consolidate/handler.js +266 -28
  312. package/dist/subsystems/memory-steward/backfill/handler.js +3 -2
  313. package/dist/subsystems/memory-steward/govern/config.yaml +6 -1
  314. package/dist/subsystems/wisdom-steward/attribute/config.yaml +5 -1
  315. package/dist/subsystems/wisdom-steward/formation/config.yaml +3 -0
  316. package/dist/subsystems/wisdom-steward/govern/config.yaml +6 -1
  317. package/package.json +5 -3
@@ -13,7 +13,12 @@
13
13
  * key = 模型名称(支持前缀匹配的精确名称)
14
14
  */
15
15
  const BUILTIN_MODEL_INFO = {
16
- // ── OpenAI ──
16
+ // ── OpenAI(2026-11 官方模型页:四个 GPT-6 系均 1,050,000 / 128,000) ──
17
+ 'gpt-6.2-astra': { contextWindow: 1050000, maxOutputTokens: 128000 },
18
+ 'gpt-6.2-sol': { contextWindow: 1050000, maxOutputTokens: 128000 },
19
+ 'gpt-6.1-terra': { contextWindow: 1050000, maxOutputTokens: 128000 },
20
+ 'gpt-6-luna': { contextWindow: 1050000, maxOutputTokens: 128000 },
21
+ // 旧代际仍在 full catalog,保留兜底
17
22
  'gpt-5.5': { contextWindow: 256000, maxOutputTokens: 32768 },
18
23
  'gpt-5.5-mini': { contextWindow: 128000, maxOutputTokens: 16384 },
19
24
  'gpt-4o': { contextWindow: 128000, maxOutputTokens: 16384 },
@@ -24,22 +29,38 @@ const BUILTIN_MODEL_INFO = {
24
29
  'o3': { contextWindow: 200000, maxOutputTokens: 100000 },
25
30
  'o3-mini': { contextWindow: 200000, maxOutputTokens: 100000 },
26
31
  'o4-mini': { contextWindow: 200000, maxOutputTokens: 100000 },
27
- // ── Anthropic ──
32
+ // ── Anthropic(Claude 5.5 代:1M / 128K) ──
33
+ 'claude-opus-5-5': { contextWindow: 1000000, maxOutputTokens: 128000 },
34
+ 'claude-sonnet-5-5': { contextWindow: 1000000, maxOutputTokens: 128000 },
35
+ 'claude-haiku-5-5': { contextWindow: 1000000, maxOutputTokens: 128000 },
28
36
  'claude-opus-4-6': { contextWindow: 200000, maxOutputTokens: 32000 },
29
37
  'claude-sonnet-4-6': { contextWindow: 200000, maxOutputTokens: 16000 },
30
38
  'claude-haiku-4-5': { contextWindow: 200000, maxOutputTokens: 8192 },
31
39
  'claude-3.5-sonnet': { contextWindow: 200000, maxOutputTokens: 8192 },
32
40
  'claude-3.5-haiku': { contextWindow: 200000, maxOutputTokens: 8192 },
33
41
  'claude-3-opus': { contextWindow: 200000, maxOutputTokens: 4096 },
34
- // ── Google ──
42
+ // ── Google(Gemini 4:1M / 64K) ──
43
+ 'gemini-4-carbon': { contextWindow: 1048576, maxOutputTokens: 65536 },
44
+ 'gemini-4-neon': { contextWindow: 1048576, maxOutputTokens: 65536 },
45
+ 'gemini-4-hydrogen': { contextWindow: 1048576, maxOutputTokens: 65536 },
46
+ 'gemini-4-argon': { contextWindow: 1048576, maxOutputTokens: 65536 },
35
47
  'gemini-2.5-pro': { contextWindow: 1000000, maxOutputTokens: 65536 },
36
48
  'gemini-2.5-flash': { contextWindow: 1000000, maxOutputTokens: 65536 },
37
49
  'gemini-2.0-pro': { contextWindow: 2000000, maxOutputTokens: 8192 },
38
50
  'gemini-2.0-flash': { contextWindow: 1000000, maxOutputTokens: 8192 },
39
- // ── DeepSeek ──
40
- 'deepseek-chat': { contextWindow: 64000, maxOutputTokens: 8192 },
41
- 'deepseek-reasoner': { contextWindow: 64000, maxOutputTokens: 8192 },
42
- // ── Qwen(含 Ollama 本地常见族;tag 如 :2b/:7b 会在查询时剥离) ──
51
+ // ── DeepSeek(官方:1M / 384K) ──
52
+ 'deepseek-flash': { contextWindow: 1048576, maxOutputTokens: 393216 },
53
+ 'deepseek-v4-pro': { contextWindow: 1048576, maxOutputTokens: 393216 },
54
+ // ── Qwen / Kimi / GLM(2026-11 当前主力) ──
55
+ 'qwen4-max': { contextWindow: 1000000, maxOutputTokens: 131072 },
56
+ 'qwen3.7-plus': { contextWindow: 1000000, maxOutputTokens: 131072 },
57
+ 'qwen3.8-flash': { contextWindow: 1000000, maxOutputTokens: 131072 },
58
+ 'kimi-k3.1-pro': { contextWindow: 1048576, maxOutputTokens: 131072 },
59
+ 'kimi-k3.1-pro-highspeed': { contextWindow: 1048576, maxOutputTokens: 131072 },
60
+ 'kimi-k3': { contextWindow: 1048576, maxOutputTokens: 131072 },
61
+ 'glm-5.3': { contextWindow: 1000000, maxOutputTokens: 131072 },
62
+ 'glm-5.3-flash': { contextWindow: 1000000, maxOutputTokens: 131072 },
63
+ // ── Qwen 旧代际(含 Ollama 本地常见族;tag 如 :2b/:7b 会在查询时剥离) ──
43
64
  'qwen-max': { contextWindow: 32000, maxOutputTokens: 8192 },
44
65
  'qwen-plus': { contextWindow: 131072, maxOutputTokens: 8192 },
45
66
  'qwen-turbo': { contextWindow: 131072, maxOutputTokens: 8192 },
@@ -9,6 +9,26 @@
9
9
  */
10
10
  /** 安全组推荐(effectPolicy.mode 四选一) */
11
11
  export type EffectMode = 'workspace' | 'project' | 'host' | 'untrusted';
12
+ /** 类型模板技能套装条目(物化为 `skills/<id>/SKILL.md`) */
13
+ export interface AgentRoleSkill {
14
+ /** skill id = SKILL.md 目录名 */
15
+ id: string;
16
+ /** frontmatter.name */
17
+ name: string;
18
+ /** frontmatter.description(system prompt 索引用,LLM 面) */
19
+ description: string;
20
+ /** SKILL.md 正文(不含 frontmatter) */
21
+ content: string;
22
+ /** frontmatter.tools 白名单(可选) */
23
+ tools?: string[];
24
+ }
25
+ /** persona/ 目录补充件(物化进 agent home/persona/) */
26
+ export interface AgentRolePersonaFile {
27
+ /** 文件名(*.md,数字前缀定序,如 '10-style.md') */
28
+ file: string;
29
+ /** 补充 persona 正文 */
30
+ content: string;
31
+ }
12
32
  /** agent 角色模板 */
13
33
  export interface AgentRolePreset {
14
34
  /** 角色 id */
@@ -17,8 +37,16 @@ export interface AgentRolePreset {
17
37
  label: string;
18
38
  /** 角色说明(向导卡片) */
19
39
  description: string;
40
+ /** 展示名本地化(缺省回落 label) */
41
+ labels?: import('./i18n.js').LocalizedText;
42
+ /** 说明本地化(缺省回落 description) */
43
+ descriptions?: import('./i18n.js').LocalizedText;
20
44
  /** AGENTS.md 模板(含 {{agentName}} / {{addressToUser}} 插槽) */
21
45
  template: string;
46
+ /** persona/ 目录补充件(类型模板包;创建时物化,模板不进运行时) */
47
+ personaFiles?: AgentRolePersonaFile[];
48
+ /** 技能套装(类型模板包;创建时物化为 skills/<id>/SKILL.md) */
49
+ skills?: AgentRoleSkill[];
22
50
  /** 推荐安全组(effectPolicy.mode) */
23
51
  recommendedEffectMode: EffectMode;
24
52
  /** 推荐默认模型档(models.level 名,可选) */
@@ -37,6 +65,10 @@ export interface AgentRoleSlots {
37
65
  export interface RenderedAgentRole {
38
66
  /** 渲染后的 AGENTS.md 全文(可继续手改后落盘) */
39
67
  agentsMd: string;
68
+ /** persona/ 补充件(物化用,深拷贝) */
69
+ personaFiles: AgentRolePersonaFile[];
70
+ /** 技能套装(物化用,深拷贝) */
71
+ skills: AgentRoleSkill[];
40
72
  recommendedEffectMode: EffectMode;
41
73
  recommendedModelLevel?: string;
42
74
  recommendedTraits?: string[];
@@ -13,6 +13,8 @@ export const BUILTIN_AGENT_ROLE_PRESETS = [
13
13
  id: 'general',
14
14
  label: '通用助手',
15
15
  description: '全能型日常助手:问答、写作、整理、轻量任务,性格亲切可靠。',
16
+ labels: { en: 'General Assistant' },
17
+ descriptions: { en: 'Everyday all-rounder: Q&A, writing, organizing, light tasks — friendly and reliable.' },
16
18
  recommendedEffectMode: 'workspace',
17
19
  recommendedModelLevel: 'standard',
18
20
  recommendedTraits: ['generalist'],
@@ -44,6 +46,32 @@ You are **{{agentName}}**, a general-purpose AI assistant. Reliable, friendly, a
44
46
  id: 'researcher',
45
47
  label: '研究员',
46
48
  description: '深度调研与资料分析:检索、比对、综述、溯源引用,结论谨慎可核查。',
49
+ labels: { en: 'Researcher' },
50
+ descriptions: {
51
+ en: 'Deep research and analysis: retrieval, cross-checking, synthesis, traceable citations.',
52
+ },
53
+ skills: [
54
+ {
55
+ id: 'source-trail',
56
+ name: 'Source Trail',
57
+ description: 'Keep a claim-to-source trail so every finding is verifiable.',
58
+ content: `# Source Trail
59
+
60
+ For every non-trivial claim you make, keep a trail entry:
61
+
62
+ - **Claim** — one sentence, atomic.
63
+ - **Source** — document / URL / dataset + exact locator (page, section, line).
64
+ - **Confidence** — documented (source states it) | inferred (derived) | unknown.
65
+
66
+ ## Rules
67
+
68
+ - Present findings as: conclusion → evidence → caveats.
69
+ - Contradictory sources: report both with locators; never silently pick one.
70
+ - If a claim has no source, label it "inferred" or drop it.
71
+ - When asked "where did this come from", answer with the trail entry, not a paraphrase.
72
+ `,
73
+ },
74
+ ],
47
75
  recommendedEffectMode: 'workspace',
48
76
  recommendedModelLevel: 'pro',
49
77
  recommendedTraits: ['research', 'analysis'],
@@ -74,6 +102,39 @@ You are **{{agentName}}**, a research analyst. You dig into sources, cross-check
74
102
  id: 'coder',
75
103
  label: '工程师',
76
104
  description: '软件工程主力:设计、实现、调试、重构,重视根因与可维护性。',
105
+ labels: { en: 'Software Engineer' },
106
+ descriptions: { en: 'Main engineering force: design, implement, debug, refactor — root causes first.' },
107
+ personaFiles: [
108
+ {
109
+ file: '10-engineering-mindset.md',
110
+ content: `# Engineering Mindset
111
+
112
+ - **Semantics are contracts**: never blur data categories or smuggle one thing through another's channel.
113
+ - **Causal chains**: state symptom ← mechanism ← root cause before fixing; a fix that only suppresses the symptom is not a fix.
114
+ - **Evidence, not vibes**: verify with tests and real runs; green tests are evidence, not proof.
115
+ - **Consumers and blast radius**: a change is done when its farthest consumer still behaves correctly.
116
+ - **Widen the view**: if the next fix needs a workaround for the previous fix, the analysis is at the wrong altitude — re-derive.
117
+ `,
118
+ },
119
+ ],
120
+ skills: [
121
+ {
122
+ id: 'debug-playbook',
123
+ name: 'Debug Playbook',
124
+ description: 'A disciplined loop for root-cause debugging: reproduce, localize, hypothesize, verify, fix.',
125
+ content: `# Debug Playbook
126
+
127
+ 1. **Reproduce** — get a reliable repro before touching anything; note exact inputs and environment.
128
+ 2. **Localize** — bisect the surface (last known good vs first bad); read the actual error, not a paraphrase.
129
+ 3. **Hypothesize** — state symptom ← mechanism ← root cause as a testable chain.
130
+ 4. **Verify the cause** — prove the mechanism (log, probe, minimal repro) BEFORE fixing.
131
+ 5. **Fix the root cause** — remove the cause AND keep intended behavior complete; hiding symptoms is not a fix.
132
+ 6. **Regression anchor** — add a test that fails on the old code and passes on the new.
133
+
134
+ If a fix needs a workaround for a previous fix, stop and re-derive from the design.
135
+ `,
136
+ },
137
+ ],
77
138
  recommendedEffectMode: 'project',
78
139
  recommendedModelLevel: 'pro',
79
140
  recommendedTraits: ['engineering', 'debugging'],
@@ -106,6 +167,29 @@ You are **{{agentName}}**, a senior software engineer. You design, implement, de
106
167
  id: 'reviewer',
107
168
  label: '审查员',
108
169
  description: '代码/文档审查专精:逐行挑毛病、验证声明、按严重度输出 findings。',
170
+ labels: { en: 'Reviewer' },
171
+ descriptions: { en: 'Code/document review specialist: line-by-line findings, verified claims, severity-rated.' },
172
+ skills: [
173
+ {
174
+ id: 'review-checklist',
175
+ name: 'Review Checklist',
176
+ description: 'Severity-rated review discipline: verify claims, quote lines, cover correctness/contracts/security.',
177
+ content: `# Review Checklist
178
+
179
+ Output = findings, not fixes. For every finding: **severity** (blocker/major/minor/nit) + **location** (exact line quoted) + **what is wrong** + **why it matters** + **suggested fix**.
180
+
181
+ ## Sweep
182
+
183
+ - Correctness: logic, edge cases, error paths, race conditions.
184
+ - Contracts: does every consumer of changed data still behave (incl. historical data)?
185
+ - Symmetry: parallel values with unexplained asymmetry usually signal a missed extraction.
186
+ - Security: auth, containment, injection, secret leakage.
187
+ - Honesty: stubbed returns, swallowed errors, silent truncation.
188
+
189
+ A review report is claims to verify, not orders to obey — check each finding against the code first. If context is insufficient, list it as "to verify"; never guess.
190
+ `,
191
+ },
192
+ ],
109
193
  recommendedEffectMode: 'workspace',
110
194
  recommendedModelLevel: 'pro',
111
195
  recommendedTraits: ['review', 'quality'],
@@ -136,6 +220,31 @@ You are **{{agentName}}**, a rigorous reviewer. Your output is findings, not fix
136
220
  id: 'writer',
137
221
  label: '写作助手',
138
222
  description: '文字打磨:起草、润色、翻译、结构化表达,风格可调。',
223
+ labels: { en: 'Writing Assistant' },
224
+ descriptions: { en: 'Writing specialist: drafting, polishing, translation, structured expression — adjustable style.' },
225
+ skills: [
226
+ {
227
+ id: 'tone-match',
228
+ name: 'Tone Match',
229
+ description: 'Match and preserve voice: diagnose register, cut filler, keep the author identity intact.',
230
+ content: `# Tone Match
231
+
232
+ Before drafting or editing, diagnose the target register (formal / casual / technical / marketing) and audience. When unclear, ask.
233
+
234
+ ## Editing rules
235
+
236
+ - Preserve the author's voice: improve clarity, never rewrite identity.
237
+ - Cut filler ruthlessly; every sentence earns its place.
238
+ - Keep terminology consistent within a document; maintain a tiny glossary for long pieces.
239
+ - For headlines and openings, offer 2–3 phrasings with different registers.
240
+
241
+ ## Drafting rules
242
+
243
+ - Lead with the point; support with evidence; end with the ask.
244
+ - Match sentence rhythm to register: short for punch, long for nuance.
245
+ `,
246
+ },
247
+ ],
139
248
  recommendedEffectMode: 'workspace',
140
249
  recommendedModelLevel: 'standard',
141
250
  recommendedTraits: ['writing', 'editing'],
@@ -166,6 +275,28 @@ You are **{{agentName}}**, a writing assistant. You draft, edit, translate, and
166
275
  id: 'analyst',
167
276
  label: '数据分析师',
168
277
  description: '数据视角:指标拆解、趋势解读、报表与洞察,结论量化可追溯。',
278
+ labels: { en: 'Data Analyst' },
279
+ descriptions: { en: 'Data perspective: metric breakdown, trend reading, reports and insights — quantified and traceable.' },
280
+ skills: [
281
+ {
282
+ id: 'metric-breakdown',
283
+ name: 'Metric Breakdown',
284
+ description: 'Define before analyzing: decomposition trees, assumption ledger, re-derivable calculations.',
285
+ content: `# Metric Breakdown
286
+
287
+ Before analyzing any metric, define it: what exactly is counted, over what window, with what exclusions.
288
+
289
+ ## Discipline
290
+
291
+ - **Decompose**: break a metric into a tree (e.g. revenue = users × conversion × ARPU) before explaining movement.
292
+ - **Assumption ledger**: list every assumption explicitly; separate correlation from causation.
293
+ - **Re-derivable**: show the calculation path for every number; a reader must be able to re-derive it.
294
+ - **Honest precision**: round to what the data supports; never fake decimals.
295
+
296
+ Present as: insight → evidence → caveats. Tables over raw dumps.
297
+ `,
298
+ },
299
+ ],
169
300
  recommendedEffectMode: 'workspace',
170
301
  recommendedModelLevel: 'pro',
171
302
  recommendedTraits: ['data', 'analysis'],
@@ -236,6 +367,8 @@ export function renderRolePreset(preset, slots) {
236
367
  .replaceAll('{{addressToUser}}', addressToUser);
237
368
  return {
238
369
  agentsMd,
370
+ personaFiles: (preset.personaFiles ?? []).map((f) => ({ ...f })),
371
+ skills: (preset.skills ?? []).map((s) => ({ ...s, tools: s.tools ? [...s.tools] : undefined })),
239
372
  recommendedEffectMode: preset.recommendedEffectMode,
240
373
  recommendedModelLevel: preset.recommendedModelLevel,
241
374
  recommendedTraits: preset.recommendedTraits ? [...preset.recommendedTraits] : undefined,
@@ -1,9 +1,18 @@
1
1
  /**
2
2
  * 模型清单拉取式发现(arch/config-hot-reload.md §5.1,P1)
3
3
  *
4
- * 连通测试 = 拉取模型列表:成功即证明 baseUrl/key 有效,顺手填充表单清单。
5
- * openai-completions → `GET {baseUrl}/models`(Bearer);
6
- * anthropic-messages → `GET {baseUrl}/v1/models`(x-api-key + anthropic-version)。
4
+ * 首选免费路径:`GET {base}/models`(openai-completions)/ `GET {base}/v1/models`
5
+ * (anthropic-messages,x-api-key + anthropic-version)。
6
+ *
7
+ * **`/models` 不是任何兼容面的承诺路由**,且缺失时状态码不可靠:
8
+ * - MiMo 的 Anthropic 端点(`https://api.xiaomimimo.com/anthropic`)没有
9
+ * `/v1/models` → 404;
10
+ * - 火山方舟(`https://ark.cn-beijing.volces.com/api/plan`)**先鉴权后路由**,
11
+ * 任何路径未带 key 都是 401,无论路由是否存在 → 401 不能直接判成「key 无效」。
12
+ *
13
+ * 因此模型清单拿不到时(非 2xx),只要调用方给了 `probeModel`,就用一次最小对话
14
+ * 请求(`max_tokens: 1`)判定真实连通性,把「清单可用」与「端点+鉴权可用」两件事
15
+ * 分开报:对话成功 → `ok: true` + `degraded: true`;对话 401/403 → 真鉴权失败。
7
16
  *
8
17
  * @module
9
18
  */
@@ -14,17 +23,37 @@ export interface DiscoverModelsRequest {
14
23
  api: 'openai-completions' | 'anthropic-messages';
15
24
  /** 超时(毫秒),缺省 10s */
16
25
  timeoutMs?: number;
26
+ /**
27
+ * 模型清单拉不到时用于最小对话探针的模型 id。
28
+ * 缺省则不做回退,原样返回清单请求的失败(无模型可探)。
29
+ */
30
+ probeModel?: string;
31
+ /**
32
+ * 调用方已配置的模型清单:degraded 结果回填它,
33
+ * 让 UI 拿到「已配置的模型」而不是只有探针那一条。
34
+ */
35
+ knownModels?: Array<{
36
+ id: string;
37
+ name?: string;
38
+ }>;
17
39
  }
18
40
  /** 发现结果(失败不抛错:UI 需要展示原因) */
19
41
  export interface DiscoverModelsResult {
20
42
  ok: boolean;
21
- /** 发现的模型 id 清单(ok=false 时为空) */
43
+ /** 发现的模型 id 清单(ok=false 时为空;degraded 时为已知清单或探针模型) */
22
44
  models: Array<{
23
45
  id: string;
24
46
  name?: string;
25
47
  }>;
26
48
  /** 失败原因(ok=true 时 undefined) */
27
49
  error?: string;
50
+ /**
51
+ * 连通已确认但清单拉不到:端点没有 `/models` 路由(或该路由受网关策略拦截),
52
+ * 仅用最小对话请求验证过端点与鉴权。调用方应提示用户手填模型参数。
53
+ */
54
+ degraded?: boolean;
55
+ /** degraded 时的人类可读说明 */
56
+ note?: string;
28
57
  }
29
58
  /** 拉取模型清单(连通测试同源) */
30
59
  export declare function discoverProviderModels(req: DiscoverModelsRequest): Promise<DiscoverModelsResult>;
@@ -1,18 +1,89 @@
1
1
  /**
2
2
  * 模型清单拉取式发现(arch/config-hot-reload.md §5.1,P1)
3
3
  *
4
- * 连通测试 = 拉取模型列表:成功即证明 baseUrl/key 有效,顺手填充表单清单。
5
- * openai-completions → `GET {baseUrl}/models`(Bearer);
6
- * anthropic-messages → `GET {baseUrl}/v1/models`(x-api-key + anthropic-version)。
4
+ * 首选免费路径:`GET {base}/models`(openai-completions)/ `GET {base}/v1/models`
5
+ * (anthropic-messages,x-api-key + anthropic-version)。
6
+ *
7
+ * **`/models` 不是任何兼容面的承诺路由**,且缺失时状态码不可靠:
8
+ * - MiMo 的 Anthropic 端点(`https://api.xiaomimimo.com/anthropic`)没有
9
+ * `/v1/models` → 404;
10
+ * - 火山方舟(`https://ark.cn-beijing.volces.com/api/plan`)**先鉴权后路由**,
11
+ * 任何路径未带 key 都是 401,无论路由是否存在 → 401 不能直接判成「key 无效」。
12
+ *
13
+ * 因此模型清单拿不到时(非 2xx),只要调用方给了 `probeModel`,就用一次最小对话
14
+ * 请求(`max_tokens: 1`)判定真实连通性,把「清单可用」与「端点+鉴权可用」两件事
15
+ * 分开报:对话成功 → `ok: true` + `degraded: true`;对话 401/403 → 真鉴权失败。
7
16
  *
8
17
  * @module
9
18
  */
19
+ /** 各协议的最小对话请求形态 */
20
+ function buildProbeRequest(api, base, apiKey, model) {
21
+ if (api === 'anthropic-messages') {
22
+ const headers = {
23
+ 'content-type': 'application/json',
24
+ 'anthropic-version': '2023-06-01',
25
+ };
26
+ if (apiKey)
27
+ headers['x-api-key'] = apiKey;
28
+ return {
29
+ url: `${base}/v1/messages`,
30
+ headers,
31
+ body: JSON.stringify({ model, max_tokens: 1, messages: [{ role: 'user', content: 'hi' }] }),
32
+ };
33
+ }
34
+ const headers = { 'content-type': 'application/json' };
35
+ if (apiKey)
36
+ headers['Authorization'] = `Bearer ${apiKey}`;
37
+ return {
38
+ url: `${base}/chat/completions`,
39
+ headers,
40
+ body: JSON.stringify({
41
+ model,
42
+ messages: [{ role: 'user', content: 'ping' }],
43
+ max_tokens: 1,
44
+ stream: false,
45
+ }),
46
+ };
47
+ }
48
+ /**
49
+ * 用一次最小对话请求验证 baseUrl/key
50
+ *
51
+ * @param api - 协议(决定路径与鉴权头)
52
+ * @param base - 已去掉尾斜杠的 baseUrl
53
+ * @param apiKey - 明文 key(空串则不带鉴权头)
54
+ * @param model - 探针模型 id
55
+ * @param timeoutMs - 超时(毫秒)
56
+ * @returns 探针结论;400/422 视为连通成立(鉴权已过,只是请求本身被模型层拒绝)
57
+ */
58
+ async function probeChat(api, base, apiKey, model, timeoutMs) {
59
+ const { url, headers, body } = buildProbeRequest(api, base, apiKey, model);
60
+ const controller = new AbortController();
61
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
62
+ try {
63
+ const res = await fetch(url, { method: 'POST', headers, body, signal: controller.signal });
64
+ if (res.status === 401 || res.status === 403)
65
+ return { kind: 'auth', status: res.status };
66
+ // 400 / 422 = 鉴权与路由都通,只是请求内容(如模型名)被拒;连通成立。
67
+ if (res.ok || res.status === 400 || res.status === 422)
68
+ return { kind: 'ok' };
69
+ return { kind: 'error', status: res.status };
70
+ }
71
+ catch {
72
+ // 网络层异常(DNS / TLS / abort)与 HTTP 错误在调用方都归为「不可用」,
73
+ // 这里只需区分「鉴权失败」与「其它」,原因由调用方拼进 error 文案。
74
+ return { kind: 'error', status: 0 };
75
+ }
76
+ finally {
77
+ clearTimeout(timer);
78
+ }
79
+ }
10
80
  /** 拉取模型清单(连通测试同源) */
11
81
  export async function discoverProviderModels(req) {
12
82
  const base = req.baseUrl.replace(/\/+$/, '');
13
- const url = req.api === 'anthropic-messages' ? `${base}/v1/models` : `${base}/models`;
83
+ const isAnthropic = req.api === 'anthropic-messages';
84
+ const url = isAnthropic ? `${base}/v1/models` : `${base}/models`;
14
85
  const headers = {};
15
- if (req.api === 'anthropic-messages') {
86
+ if (isAnthropic) {
16
87
  if (req.apiKey)
17
88
  headers['x-api-key'] = req.apiKey;
18
89
  headers['anthropic-version'] = '2023-06-01';
@@ -20,11 +91,35 @@ export async function discoverProviderModels(req) {
20
91
  else if (req.apiKey) {
21
92
  headers['Authorization'] = `Bearer ${req.apiKey}`;
22
93
  }
94
+ const timeoutMs = req.timeoutMs ?? 10_000;
23
95
  const controller = new AbortController();
24
- const timer = setTimeout(() => controller.abort(), req.timeoutMs ?? 10_000);
96
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
25
97
  try {
26
98
  const res = await fetch(url, { headers, signal: controller.signal });
27
99
  if (!res.ok) {
100
+ // 只有状态码有歧义时才回退:404 缺路由、401/403 可能是网关先鉴权后路由、
101
+ // 405 是不允许该方法。5xx / 429 是端点自身状态,照实报,不拿探针掩盖。
102
+ const ambiguous = res.status === 404 || res.status === 401
103
+ || res.status === 403 || res.status === 405;
104
+ if (ambiguous && req.probeModel) {
105
+ const probe = await probeChat(req.api, base, req.apiKey, req.probeModel, timeoutMs);
106
+ if (probe.kind === 'ok') {
107
+ const known = req.knownModels?.length ? req.knownModels : [{ id: req.probeModel }];
108
+ return {
109
+ ok: true,
110
+ models: known,
111
+ degraded: true,
112
+ note: `该端点未提供模型清单接口(${url} 返回 HTTP ${res.status}),已用最小对话请求(${req.probeModel})确认端点与鉴权可用;模型参数请以官方文档为准`,
113
+ };
114
+ }
115
+ return {
116
+ ok: false,
117
+ models: [],
118
+ error: probe.kind === 'auth'
119
+ ? `HTTP ${probe.status}(清单接口 ${res.status};对话探针鉴权失败,请检查 key 与 baseUrl 所属区域)`
120
+ : `HTTP ${probe.status || 'network error'}(清单接口 ${res.status};对话探针同样失败,请检查 baseUrl)`,
121
+ };
122
+ }
28
123
  return { ok: false, models: [], error: `HTTP ${res.status} ${res.statusText}` };
29
124
  }
30
125
  const body = (await res.json());
@@ -4,6 +4,17 @@
4
4
  *
5
5
  * @module
6
6
  */
7
+ /**
8
+ * 加载 `OCTOPI_HOME/.env` 进 `process.env`(不覆盖已有变量;文件权限 0600 由写入方保证)。
9
+ *
10
+ * 幂等:文件不存在即跳过(无 .env 是常态);重复调用无副作用(已存在的键不覆盖)。
11
+ * 时机约束:必须在 `${ENV}` 展开(loadConfig / 热应用)之前调用;
12
+ * 守护进程 fork 的子进程通过继承 `process.env` 获得,无需各自加载。
13
+ *
14
+ * @param octopiHome - OCTOPI_HOME 目录
15
+ * @returns 实际写入的变量名列表(供诊断;未加载返回 [])
16
+ */
17
+ export declare function loadOctopiEnvFile(octopiHome: string): string[];
7
18
  /**
8
19
  * 展开文本中的 `${ENV_VAR}` / `${ENV_VAR:-default}` 占位符
9
20
  *
@@ -4,7 +4,48 @@
4
4
  *
5
5
  * @module
6
6
  */
7
+ import { readFileSync } from 'node:fs';
8
+ import { join } from 'node:path';
7
9
  const ENV_PATTERN = /\$\{(\w+)(?::-(.*?))?\}/g;
10
+ /**
11
+ * 加载 `OCTOPI_HOME/.env` 进 `process.env`(不覆盖已有变量;文件权限 0600 由写入方保证)。
12
+ *
13
+ * 幂等:文件不存在即跳过(无 .env 是常态);重复调用无副作用(已存在的键不覆盖)。
14
+ * 时机约束:必须在 `${ENV}` 展开(loadConfig / 热应用)之前调用;
15
+ * 守护进程 fork 的子进程通过继承 `process.env` 获得,无需各自加载。
16
+ *
17
+ * @param octopiHome - OCTOPI_HOME 目录
18
+ * @returns 实际写入的变量名列表(供诊断;未加载返回 [])
19
+ */
20
+ export function loadOctopiEnvFile(octopiHome) {
21
+ let text;
22
+ try {
23
+ text = readFileSync(join(octopiHome, '.env'), 'utf8');
24
+ }
25
+ catch {
26
+ return []; // 仅「文件不存在/不可读」可达;.env 缺省不部署
27
+ }
28
+ const applied = [];
29
+ for (const rawLine of text.split(/\r?\n/)) {
30
+ const line = rawLine.trim();
31
+ if (!line || line.startsWith('#'))
32
+ continue;
33
+ const eq = line.indexOf('=');
34
+ if (eq <= 0)
35
+ continue; // 非 KEY=VALUE 行跳过(.env 语法本就宽容)
36
+ const key = line.slice(0, eq).trim();
37
+ let value = line.slice(eq + 1).trim();
38
+ if ((value.startsWith('"') && value.endsWith('"') && value.length >= 2) ||
39
+ (value.startsWith("'") && value.endsWith("'") && value.length >= 2)) {
40
+ value = value.slice(1, -1);
41
+ }
42
+ if (process.env[key] === undefined) {
43
+ process.env[key] = value;
44
+ applied.push(key);
45
+ }
46
+ }
47
+ return applied;
48
+ }
8
49
  /**
9
50
  * 展开文本中的 `${ENV_VAR}` / `${ENV_VAR:-default}` 占位符
10
51
  *
@@ -0,0 +1,106 @@
1
+ /**
2
+ * 错误分类与人话文案单源(批 3-2:批 2 登记项「错误映射四份单源化」;本批扩展为域×档)。
3
+ *
4
+ * 收敛前四份各自维护:engine `classifyProbeError`(分类)、webui `probeCopy`、
5
+ * CLI `probeLabels`、webui `error-classify`(文案)——码集漂移(server vs context)
6
+ * 与口径漂移正是两处真相病。本模块是唯一实现:
7
+ *
8
+ * - **分类**:`classifyErrorKind` —— probe 与运行期共用一套关键词规则
9
+ * - **码集**:`auth | network | timeout | rate_limit | model | context | server`
10
+ * - **来源域**:`provider`(模型服务)| `tool`(工具执行)| `app`(界面/会话操作)——
11
+ * 工具错误与 app 错误不是模型服务错误,不共用 provider 分类器(语义即契约)
12
+ * - **处置档**:`self-heal`(可自愈,不进错误卡)| `user-action`(卡+出路)| `support`(卡+诊断 ID)
13
+ * - **文案**:probe 语境(向导,有「上一步」)与 run 语境(对话流,有「去设置」)
14
+ * 各一张表,zh/en 双语——UI 只做渲染与 CTA 装配,不再自持文案
15
+ *
16
+ * @module
17
+ */
18
+ /** 错误分类码(probe 语境不含 'context'——上下文超限不发生在探针) */
19
+ export type ErrorKind = 'auth' | 'network' | 'timeout' | 'rate_limit' | 'model' | 'context' | 'server';
20
+ /** probe 语境分类码 */
21
+ export type ProbeErrorKind = Exclude<ErrorKind, 'context'>;
22
+ /** 错误来源域(决定走哪张分类/文案表) */
23
+ export type ErrorDomain = 'provider' | 'tool' | 'app';
24
+ /** 工具错误分类码 */
25
+ export type ToolErrorKind = 'blocked' | 'failed' | 'internal';
26
+ /** app 错误分类码(会话/界面操作失败) */
27
+ export type AppErrorKind = 'failed';
28
+ /** 处置档:self-heal 不进错误卡;user-action 卡+出路;support 卡+诊断 ID */
29
+ export type ErrorLevel = 'self-heal' | 'user-action' | 'support';
30
+ /** 人话文案(title + detail;UI 自行附加 CTA/level) */
31
+ export interface ErrorCopy {
32
+ title: string;
33
+ detail: string;
34
+ }
35
+ /** 域分类结果(level 与 copy 由域×码决定) */
36
+ export interface ClassifiedError {
37
+ domain: ErrorDomain;
38
+ kind: ErrorKind | ToolErrorKind | AppErrorKind;
39
+ level: ErrorLevel;
40
+ copy: ErrorCopy;
41
+ }
42
+ /**
43
+ * 错误文本 → 分类码(probe 与运行期共用;关键词规则唯一实现)。
44
+ *
45
+ * @param raw - 原始错误文本
46
+ * @returns 分类码(无法归类时 'server')
47
+ */
48
+ export declare function classifyErrorKind(raw: string): ErrorKind;
49
+ /**
50
+ * 守卫 violation 文本判定(单源:classifyToolErrorKind 的 blocked 与
51
+ * securityBlockedCopy 共用)。真实工具阻断文本是 violation description
52
+ * (`工具 "shell" download pipe to interpreter (remote code execution)`),
53
+ * 只有 afterToolCall 输出扫描才带 `Blocked by SecurityGuard:` 前缀。
54
+ */
55
+ export declare function securityViolationKind(text: string): 'rce' | 'disk_wipe' | 'injection' | 'protected_path' | 'secret' | null;
56
+ /**
57
+ * 工具错误 → 分类码(启发式)。
58
+ *
59
+ * - `blocked`:守卫拦截(模型收到后换方案即可,可自愈)
60
+ * - `internal`:BUG 级内部异常(堆栈帧落在 octopi 包内)→ 该找支持
61
+ * - `failed`:其余执行失败(参数错误、路径不存在、exit≠0…)→ 模型可自救
62
+ *
63
+ * @param raw - 工具错误原文
64
+ * @returns 分类码
65
+ */
66
+ export declare function classifyToolErrorKind(raw: string): ToolErrorKind;
67
+ /**
68
+ * 域分类主入口:按来源域分流到对应分类器与文案表,并给出处置档。
69
+ *
70
+ * - `provider`:`classifyErrorKind` 七类码;`server` 兜底 → support,其余 user-action
71
+ * - `tool`:`classifyToolErrorKind`;`internal` → support,其余 self-heal(模型可自救)
72
+ * - `app`:操作失败 → user-action
73
+ *
74
+ * @param raw - 原始错误文本
75
+ * @param domain - 来源域
76
+ * @param lang - 语言
77
+ * @returns 域分类结果(level + 人话文案)
78
+ */
79
+ export declare function classifyError(raw: string, domain: ErrorDomain, lang?: 'zh' | 'en'): ClassifiedError;
80
+ /**
81
+ * 守卫拦截消息人话化(security.blocked 的 reason 是审计语,不直接给用户)。
82
+ *
83
+ * @param reason - violation description 原文
84
+ * @param lang - 语言
85
+ * @returns 标题与详情(UI 可在详情后附注 reason 保留可诊断性)
86
+ */
87
+ export declare function securityBlockedCopy(reason: string, lang?: 'zh' | 'en'): ErrorCopy;
88
+ /**
89
+ * probe 语境文案(向导)。
90
+ *
91
+ * @param kind - 分类码(不含 'context')
92
+ * @param lang - 语言
93
+ * @returns 标题与详情
94
+ */
95
+ export declare function probeErrorCopy(kind: ProbeErrorKind, lang?: 'zh' | 'en'): ErrorCopy;
96
+ export declare const PROBE_ERROR_KINDS: readonly ProbeErrorKind[];
97
+ /** 诊断 ID(support 档展示与反馈对账用) */
98
+ export declare function makeDiagnosticId(): string;
99
+ /**
100
+ * 运行期语境文案(对话流错误卡)。
101
+ *
102
+ * @param kind - 分类码
103
+ * @param lang - 语言
104
+ * @returns 标题与详情
105
+ */
106
+ export declare function runtimeErrorCopy(kind: ErrorKind, lang?: 'zh' | 'en'): ErrorCopy;