cortico 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -0
  3. package/package.json +43 -0
  4. package/src/boot.ts +46 -0
  5. package/src/bot.ts +1342 -0
  6. package/src/config-file.ts +41 -0
  7. package/src/core/README.md +92 -0
  8. package/src/core/billing.ts +26 -0
  9. package/src/core/blobs.ts +106 -0
  10. package/src/core/bus.ts +311 -0
  11. package/src/core/config-schema.ts +201 -0
  12. package/src/core/config.ts +262 -0
  13. package/src/core/core.ts +699 -0
  14. package/src/core/cost.ts +244 -0
  15. package/src/core/event-store.ts +304 -0
  16. package/src/core/fork.ts +113 -0
  17. package/src/core/generation.ts +118 -0
  18. package/src/core/instance-lock.ts +215 -0
  19. package/src/core/ipc-logger.ts +105 -0
  20. package/src/core/language.ts +62 -0
  21. package/src/core/log-context.ts +38 -0
  22. package/src/core/loop.ts +1858 -0
  23. package/src/core/markers.ts +48 -0
  24. package/src/core/prefix.ts +121 -0
  25. package/src/core/run.ts +95 -0
  26. package/src/core/secrets.ts +18 -0
  27. package/src/core/session.ts +56 -0
  28. package/src/core/sessions.ts +261 -0
  29. package/src/core/state.ts +104 -0
  30. package/src/core/template.ts +72 -0
  31. package/src/core/timers.ts +129 -0
  32. package/src/core/tool-log.ts +135 -0
  33. package/src/core/transcript.ts +92 -0
  34. package/src/core/truncate.ts +121 -0
  35. package/src/core/types.ts +1140 -0
  36. package/src/core/usage-log.ts +79 -0
  37. package/src/core/util.ts +386 -0
  38. package/src/deploy-listing.ts +160 -0
  39. package/src/deploy.ts +162 -0
  40. package/src/extensions/README.md +72 -0
  41. package/src/extensions/dry-mount.ts +390 -0
  42. package/src/extensions/manifest.ts +153 -0
  43. package/src/extensions/runtime.ts +42 -0
  44. package/src/extensions.ts +519 -0
  45. package/src/launcher.ts +285 -0
  46. package/src/paths.ts +155 -0
  47. package/src/protocol/open-responses/LICENSE +201 -0
  48. package/src/protocol/open-responses/README.md +14 -0
  49. package/src/protocol/open-responses/context-helpers.ts +27 -0
  50. package/src/protocol/open-responses/context-log.ts +59 -0
  51. package/src/protocol/open-responses/context.ts +89 -0
  52. package/src/protocol/open-responses/generated.ts +115 -0
  53. package/src/protocol/open-responses/index.ts +33 -0
  54. package/src/protocol/open-responses/openapi.json +4230 -0
  55. package/src/protocol/open-responses/stream.ts +146 -0
  56. package/src/protocol/open-responses/tokens.ts +31 -0
  57. package/src/providers/README.md +86 -0
  58. package/src/providers/base.ts +111 -0
  59. package/src/providers/configuration.ts +97 -0
  60. package/src/providers/console/config.ts +21 -0
  61. package/src/providers/console/settings.ts +443 -0
  62. package/src/providers/console/strings.ts +74 -0
  63. package/src/providers/console/types.ts +11 -0
  64. package/src/providers/llamacpp/archive.ts +148 -0
  65. package/src/providers/llamacpp/catalog.ts +247 -0
  66. package/src/providers/llamacpp/config.ts +36 -0
  67. package/src/providers/llamacpp/console/client.ts +6 -0
  68. package/src/providers/llamacpp/console/models-panel.ts +120 -0
  69. package/src/providers/llamacpp/console/runtime-panel.ts +173 -0
  70. package/src/providers/llamacpp/console/server.ts +153 -0
  71. package/src/providers/llamacpp/index.ts +95 -0
  72. package/src/providers/llamacpp/native.ts +51 -0
  73. package/src/providers/llamacpp/options.ts +117 -0
  74. package/src/providers/llamacpp/runtime-store.ts +139 -0
  75. package/src/providers/llamacpp/runtime.ts +214 -0
  76. package/src/providers/llamacpp/server.ts +286 -0
  77. package/src/providers/llamacpp/strings.ts +230 -0
  78. package/src/providers/openai-responses-compat/config.ts +20 -0
  79. package/src/providers/openai-responses-compat/index.ts +89 -0
  80. package/src/providers/openai-responses-compat/native.ts +127 -0
  81. package/src/providers/openai-responses-compat/strings.ts +19 -0
  82. package/src/providers/pricebook.ts +75 -0
  83. package/src/providers/registry.ts +137 -0
  84. package/src/providers/strings.ts +71 -0
  85. package/src/providers/transport/chat.ts +156 -0
  86. package/src/providers/transport/errors.ts +48 -0
  87. package/src/providers/transport/history.ts +68 -0
  88. package/src/providers/transport/native-input.ts +83 -0
  89. package/src/providers/transport/native-types.ts +13 -0
  90. package/src/providers/transport/response-assembly.ts +191 -0
  91. package/src/providers/transport/response-http.ts +196 -0
  92. package/src/providers/transport/response-meters.ts +27 -0
  93. package/src/providers/transport/responses-input.ts +56 -0
  94. package/src/web/README.md +84 -0
  95. package/src/web/client/console-pages/builtins/llm-settings/panel.ts +625 -0
  96. package/src/web/client/console-pages/builtins/llm-settings/pricing-panel.ts +168 -0
  97. package/src/web/client/console-pages/builtins/llm-settings/strings.ts +213 -0
  98. package/src/web/client/console-pages/builtins.ts +10 -0
  99. package/src/web/client/console-pages/context.ts +135 -0
  100. package/src/web/client/console-pages/host.ts +633 -0
  101. package/src/web/client/console-pages/loader.ts +132 -0
  102. package/src/web/client/console-pages/strings.ts +90 -0
  103. package/src/web/client/console-pages/tools/strings.ts +49 -0
  104. package/src/web/client/console-pages/tools/view.ts +215 -0
  105. package/src/web/client/core/api.ts +200 -0
  106. package/src/web/client/core/language.ts +56 -0
  107. package/src/web/client/core/lifecycle.ts +132 -0
  108. package/src/web/client/core/router.ts +199 -0
  109. package/src/web/client/core/stream.ts +157 -0
  110. package/src/web/client/core/websocket.ts +82 -0
  111. package/src/web/client/features/appearance/index.ts +333 -0
  112. package/src/web/client/features/appearance/strings.ts +87 -0
  113. package/src/web/client/features/config/index.ts +11 -0
  114. package/src/web/client/features/config/strings.ts +41 -0
  115. package/src/web/client/features/config/view.ts +428 -0
  116. package/src/web/client/features/core/events.ts +197 -0
  117. package/src/web/client/features/core/index.ts +254 -0
  118. package/src/web/client/features/core/run.ts +56 -0
  119. package/src/web/client/features/core/runlog.ts +214 -0
  120. package/src/web/client/features/core/sessions.ts +53 -0
  121. package/src/web/client/features/core/strings.ts +157 -0
  122. package/src/web/client/features/extensions/index.ts +422 -0
  123. package/src/web/client/features/extensions/strings.ts +164 -0
  124. package/src/web/client/features/feature.ts +93 -0
  125. package/src/web/client/features/live/context.ts +280 -0
  126. package/src/web/client/features/live/fork.ts +156 -0
  127. package/src/web/client/features/live/index.ts +392 -0
  128. package/src/web/client/features/live/onboarding.ts +113 -0
  129. package/src/web/client/features/live/protocol.ts +122 -0
  130. package/src/web/client/features/live/sessions.ts +71 -0
  131. package/src/web/client/features/live/status.ts +68 -0
  132. package/src/web/client/features/live/strings.ts +252 -0
  133. package/src/web/client/features/live/timeline.ts +590 -0
  134. package/src/web/client/features/prompts/editor.ts +292 -0
  135. package/src/web/client/features/prompts/index.ts +346 -0
  136. package/src/web/client/features/prompts/strings.ts +136 -0
  137. package/src/web/client/features/prompts/view.ts +256 -0
  138. package/src/web/client/features/providers/index.ts +100 -0
  139. package/src/web/client/features/providers/strings.ts +23 -0
  140. package/src/web/client/features/settings/general.ts +28 -0
  141. package/src/web/client/features/settings/index.ts +82 -0
  142. package/src/web/client/features/settings/strings.ts +33 -0
  143. package/src/web/client/features/storage/index.ts +1 -0
  144. package/src/web/client/features/storage/strings.ts +45 -0
  145. package/src/web/client/features/storage/view.ts +154 -0
  146. package/src/web/client/features/usage/chart.ts +486 -0
  147. package/src/web/client/features/usage/index.ts +407 -0
  148. package/src/web/client/features/usage/labels.ts +46 -0
  149. package/src/web/client/features/usage/range.ts +36 -0
  150. package/src/web/client/features/usage/state.ts +37 -0
  151. package/src/web/client/features/usage/strings.ts +191 -0
  152. package/src/web/client/features/usage/tooltip.ts +86 -0
  153. package/src/web/client/features/usage/types.ts +96 -0
  154. package/src/web/client/features/worlds/index.ts +424 -0
  155. package/src/web/client/features/worlds/strings.ts +121 -0
  156. package/src/web/client/main.ts +273 -0
  157. package/src/web/client/shell/avatar.ts +233 -0
  158. package/src/web/client/shell/index.ts +549 -0
  159. package/src/web/client/shell/strings.ts +89 -0
  160. package/src/web/client/theme/handoff.ts +43 -0
  161. package/src/web/client/theme/palette.ts +109 -0
  162. package/src/web/client/theme/registry.ts +130 -0
  163. package/src/web/client/theme/storage.ts +72 -0
  164. package/src/web/client/theme/strings.ts +123 -0
  165. package/src/web/client/theme/studio.ts +366 -0
  166. package/src/web/client/ui/actions.ts +109 -0
  167. package/src/web/client/ui/data.ts +185 -0
  168. package/src/web/client/ui/dom.ts +23 -0
  169. package/src/web/client/ui/fields.ts +191 -0
  170. package/src/web/client/ui/format.ts +75 -0
  171. package/src/web/client/ui/icons.ts +183 -0
  172. package/src/web/client/ui/images.ts +91 -0
  173. package/src/web/client/ui/index.ts +89 -0
  174. package/src/web/client/ui/lamp.ts +125 -0
  175. package/src/web/client/ui/log.ts +98 -0
  176. package/src/web/client/ui/overlay.ts +184 -0
  177. package/src/web/client/ui/page.ts +8 -0
  178. package/src/web/client/ui/prompt-input.tsx +311 -0
  179. package/src/web/client/ui/sheet.ts +131 -0
  180. package/src/web/client/ui/strings.ts +71 -0
  181. package/src/web/console-pages.ts +367 -0
  182. package/src/web/files.ts +107 -0
  183. package/src/web/path-picker.ts +296 -0
  184. package/src/web/public/index.html +17 -0
  185. package/src/web/public/styles.css +1715 -0
  186. package/src/web/server.ts +1883 -0
  187. package/src/web/shared/client-panel.ts +603 -0
  188. package/src/web/shared/console-protocol.ts +560 -0
  189. package/src/web/shared/css.d.ts +1 -0
  190. package/src/web/shared/path-picker.ts +23 -0
  191. package/src/web/shared/theme.ts +256 -0
  192. package/src/web/theme-store.ts +37 -0
  193. package/src/world.ts +449 -0
  194. package/src/worlds/bilibili/ENV_PROMPT.md +5 -0
  195. package/src/worlds/bilibili/README.md +176 -0
  196. package/src/worlds/bilibili/audience-admission.ts +995 -0
  197. package/src/worlds/bilibili/client.ts +528 -0
  198. package/src/worlds/bilibili/coalescing-buffer.ts +125 -0
  199. package/src/worlds/bilibili/config.ts +185 -0
  200. package/src/worlds/bilibili/console/client.ts +202 -0
  201. package/src/worlds/bilibili/definition.ts +35 -0
  202. package/src/worlds/bilibili/gift-frame.ts +131 -0
  203. package/src/worlds/bilibili/normalize.ts +452 -0
  204. package/src/worlds/bilibili/overlay/announcement.ts +76 -0
  205. package/src/worlds/bilibili/overlay/assets.ts +82 -0
  206. package/src/worlds/bilibili/overlay/model.ts +494 -0
  207. package/src/worlds/bilibili/overlay/project.ts +202 -0
  208. package/src/worlds/bilibili/overlay/server.ts +286 -0
  209. package/src/worlds/bilibili/overlay/types.ts +217 -0
  210. package/src/worlds/bilibili/overlay/web/app.js +690 -0
  211. package/src/worlds/bilibili/overlay/web/editor.css +297 -0
  212. package/src/worlds/bilibili/overlay/web/editor.html +102 -0
  213. package/src/worlds/bilibili/overlay/web/editor.js +2116 -0
  214. package/src/worlds/bilibili/overlay/web/overlay.html +13 -0
  215. package/src/worlds/bilibili/overlay/web/styles.css +258 -0
  216. package/src/worlds/bilibili/protobuf.ts +123 -0
  217. package/src/worlds/bilibili/wire.ts +94 -0
  218. package/src/worlds/bilibili/world.ts +1389 -0
  219. package/src/worlds/console-fixture/ENV_PROMPT.md +1 -0
  220. package/src/worlds/console-fixture/console/client.ts +72 -0
  221. package/src/worlds/console-fixture/world.ts +73 -0
  222. package/src/worlds/index.ts +15 -0
  223. package/src/worlds/minecraft/ENV_PROMPT.md +32 -0
  224. package/src/worlds/minecraft/ENV_PROMPT_CAMERA.md +2 -0
  225. package/src/worlds/minecraft/LICENSE-mineflayer-pathfinder.txt +21 -0
  226. package/src/worlds/minecraft/README.md +917 -0
  227. package/src/worlds/minecraft/blueprint-plan.ts +915 -0
  228. package/src/worlds/minecraft/blueprint-registry.ts +566 -0
  229. package/src/worlds/minecraft/blueprint-repair.ts +236 -0
  230. package/src/worlds/minecraft/blueprint-resource.ts +272 -0
  231. package/src/worlds/minecraft/blueprint.ts +492 -0
  232. package/src/worlds/minecraft/body-lease.ts +340 -0
  233. package/src/worlds/minecraft/bridge.ts +749 -0
  234. package/src/worlds/minecraft/check.ts +651 -0
  235. package/src/worlds/minecraft/chests.ts +292 -0
  236. package/src/worlds/minecraft/client-launch.ts +272 -0
  237. package/src/worlds/minecraft/client-options.ts +85 -0
  238. package/src/worlds/minecraft/client-skins.ts +164 -0
  239. package/src/worlds/minecraft/client-window.ps1 +91 -0
  240. package/src/worlds/minecraft/client.ts +423 -0
  241. package/src/worlds/minecraft/combat-context.ts +109 -0
  242. package/src/worlds/minecraft/combat.ts +1552 -0
  243. package/src/worlds/minecraft/config.ts +499 -0
  244. package/src/worlds/minecraft/console/access.ts +218 -0
  245. package/src/worlds/minecraft/console/client.ts +244 -0
  246. package/src/worlds/minecraft/console/log.ts +110 -0
  247. package/src/worlds/minecraft/console/mount.ts +420 -0
  248. package/src/worlds/minecraft/console/skin.ts +257 -0
  249. package/src/worlds/minecraft/console/style.css +154 -0
  250. package/src/worlds/minecraft/console/world.ts +449 -0
  251. package/src/worlds/minecraft/deaths.ts +135 -0
  252. package/src/worlds/minecraft/definition.ts +18 -0
  253. package/src/worlds/minecraft/engine-child.ts +274 -0
  254. package/src/worlds/minecraft/engine-ipc.ts +98 -0
  255. package/src/worlds/minecraft/entity-facts.ts +132 -0
  256. package/src/worlds/minecraft/escape.ts +407 -0
  257. package/src/worlds/minecraft/executor.ts +14494 -0
  258. package/src/worlds/minecraft/explored.ts +156 -0
  259. package/src/worlds/minecraft/geometry.ts +205 -0
  260. package/src/worlds/minecraft/goal-plan.ts +647 -0
  261. package/src/worlds/minecraft/item-break.ts +126 -0
  262. package/src/worlds/minecraft/item-facts.ts +146 -0
  263. package/src/worlds/minecraft/item-pick.ts +67 -0
  264. package/src/worlds/minecraft/level-dat.ts +176 -0
  265. package/src/worlds/minecraft/log.ts +132 -0
  266. package/src/worlds/minecraft/mineflayer-fixes.ts +1180 -0
  267. package/src/worlds/minecraft/names.ts +377 -0
  268. package/src/worlds/minecraft/pathfinder-lib.d.ts +13 -0
  269. package/src/worlds/minecraft/pathfinder-perf.ts +796 -0
  270. package/src/worlds/minecraft/piglin.ts +49 -0
  271. package/src/worlds/minecraft/policy.ts +547 -0
  272. package/src/worlds/minecraft/precheck.ts +655 -0
  273. package/src/worlds/minecraft/proxy.ts +445 -0
  274. package/src/worlds/minecraft/ranged.ts +635 -0
  275. package/src/worlds/minecraft/readouts.ts +102 -0
  276. package/src/worlds/minecraft/round.ts +26 -0
  277. package/src/worlds/minecraft/search-observation.ts +92 -0
  278. package/src/worlds/minecraft/server-config.ts +467 -0
  279. package/src/worlds/minecraft/server.ts +658 -0
  280. package/src/worlds/minecraft/show.ts +84 -0
  281. package/src/worlds/minecraft/skills.ts +1763 -0
  282. package/src/worlds/minecraft/terrain.ts +1735 -0
  283. package/src/worlds/minecraft/window.ts +96 -0
  284. package/src/worlds/minecraft/works.ts +179 -0
  285. package/src/worlds/minecraft/world.ts +6438 -0
  286. package/src/worlds/qq/ENV_PROMPT.md +5 -0
  287. package/src/worlds/qq/config.ts +108 -0
  288. package/src/worlds/qq/console/client.ts +126 -0
  289. package/src/worlds/qq/console/events.ts +155 -0
  290. package/src/worlds/qq/console/gate.ts +232 -0
  291. package/src/worlds/qq/console/roster.ts +203 -0
  292. package/src/worlds/qq/console/style.css +65 -0
  293. package/src/worlds/qq/conversation.ts +28 -0
  294. package/src/worlds/qq/definition.ts +62 -0
  295. package/src/worlds/qq/driver.ts +375 -0
  296. package/src/worlds/qq/history-tools.ts +209 -0
  297. package/src/worlds/qq/normalize.ts +323 -0
  298. package/src/worlds/qq/qface-map.ts +282 -0
  299. package/src/worlds/qq/vision-prompt.ts +27 -0
  300. package/src/worlds/qq/vision.ts +642 -0
  301. package/src/worlds/qq/vlm.ts +142 -0
  302. package/src/worlds/qq/world.ts +1503 -0
  303. package/src/worlds/terminal/ENV_PROMPT.md +11 -0
  304. package/src/worlds/terminal/config.ts +9 -0
  305. package/src/worlds/terminal/definition.ts +14 -0
  306. package/src/worlds/terminal/world.ts +700 -0
  307. package/src/worlds/websearch/ENV_PROMPT.md +1 -0
  308. package/src/worlds/websearch/brave-client.ts +261 -0
  309. package/src/worlds/websearch/config.ts +75 -0
  310. package/src/worlds/websearch/definition.ts +20 -0
  311. package/src/worlds/websearch/world.ts +171 -0
@@ -0,0 +1,285 @@
1
+ /**
2
+ * 读取部署的 deployment.json,加载其 bot 字段指定的 BotDefinition。
3
+ * 部署根由 src/paths.ts 解析,代码包来自 bots/ 或已安装的 bot 扩展。
4
+ */
5
+ import { spawn } from 'node:child_process';
6
+ import { existsSync, readdirSync } from 'node:fs';
7
+ import { resolve } from 'node:path';
8
+ import { fileURLToPath } from 'node:url';
9
+ import { webAssetsProblem } from '../bin/web-assets.mjs';
10
+ import { LOG_LEVEL_RANK, type CoreConfig, type LogLevel } from './core/types.ts';
11
+ import type { BotDefinition } from './bot.ts';
12
+ import { createBot } from './bot.ts';
13
+ import { createDeployment, ensureDeployment, listBots, loadDeployment } from './deploy.ts';
14
+ import { buildListing, type BotDefaults } from './deploy-listing.ts';
15
+ import { secretReader } from './core/secrets.ts';
16
+ import { announceDataDir, consumeBootFlags } from './boot.ts';
17
+ import { extensionsDir, importBotDefinition, loadExtensions, locateBotPackage, readInstalled, type ActiveBotPackage } from './extensions.ts';
18
+ import { withWorlds } from './world.ts';
19
+ import { BUILTIN_WORLDS } from './worlds/index.ts';
20
+ import { providerModules, registerProviderModules } from './providers/registry.ts';
21
+ import { deploymentDir, deploymentRoot, mainRepoRoot, packageDir, providerDir, providersRoot, readDeploymentManifest, repoRoot } from './paths.ts';
22
+
23
+ /**
24
+ * botPackage 仅在部署引用扩展 bot 包时返回。
25
+ */
26
+ async function loadBotDefinition(
27
+ name: string,
28
+ ): Promise<{ definition: BotDefinition<CoreConfig>; deployDir: string; pkgDir: string; botPackage?: ActiveBotPackage }> {
29
+ const deployDir = deploymentDir(name);
30
+ const manifest = readDeploymentManifest(name);
31
+ if (!manifest) {
32
+ throw new Error(`${resolve(deployDir, 'deployment.json')} 不存在`);
33
+ }
34
+ const location = locateBotPackage(repoRoot(), manifest.bot, packageDir(manifest.bot));
35
+ const definition = await importBotDefinition(location, {
36
+ treeHas: (id) => existsSync(resolve(packageDir(id), 'index.ts')),
37
+ });
38
+ return {
39
+ definition,
40
+ deployDir,
41
+ pkgDir: location.pkgDir,
42
+ ...(location.source === 'extension' ? { botPackage: { name: location.name, id: definition.id } } : {}),
43
+ };
44
+ }
45
+
46
+ /** 浏览器启动失败时保留终端已输出的地址。 */
47
+ function openBrowser(url: string): void {
48
+ try {
49
+ const p = process.platform;
50
+ const [cmd, args] =
51
+ p === 'win32' ? ['cmd', ['/c', 'start', '', url]]
52
+ : p === 'darwin' ? ['open', [url]]
53
+ : ['xdg-open', [url]];
54
+ spawn(cmd as string, args as string[], { detached: true, stdio: 'ignore' }).unref();
55
+ } catch { /* 地址已在终端输出。 */ }
56
+ }
57
+
58
+ function pickBotName(): string {
59
+ const fromArgv = process.argv.slice(2).find((a) => !a.startsWith('-'));
60
+ const name = fromArgv || process.env.CORTICO_BOT || '';
61
+ const available = listBots();
62
+ if (available.length === 0) throw new Error(`${deploymentRoot()} 下没有含 deployment.json 的部署目录`);
63
+ if (!name) {
64
+ if (available.length === 1) return available[0];
65
+ throw new Error(`请指定部署:pnpm start <${available.join(' | ')}>`);
66
+ }
67
+ if (!available.includes(name)) {
68
+ throw new Error(`没有这个部署: ${name}。可选:${available.join(' / ')}`);
69
+ }
70
+ return name;
71
+ }
72
+
73
+ /** 代码包的默认值:展示名与它选的配色方案 id。 */
74
+ async function botDefaults(bot: string): Promise<BotDefaults> {
75
+ const location = locateBotPackage(repoRoot(), bot, packageDir(bot));
76
+ const definition = await importBotDefinition(location, {
77
+ treeHas: (id) => existsSync(resolve(packageDir(id), 'index.ts')),
78
+ });
79
+ const defaults = definition.defaults();
80
+ return { displayName: defaults.displayName, scheme: defaults.web.theme };
81
+ }
82
+
83
+ /** 可以拿来建部署的代码包:仓内 `bots/<名>/`,加上装好的 bot 类扩展。 */
84
+ function botPackages(): Array<{ id: string; source: 'tree' | 'extension' }> {
85
+ const treeDir = resolve(mainRepoRoot(), 'bots');
86
+ const tree = existsSync(treeDir)
87
+ ? readdirSync(treeDir).filter((id) => existsSync(resolve(treeDir, id, 'index.ts')))
88
+ : [];
89
+ const installed = readInstalled(extensionsDir(repoRoot())).map((p) => p.name);
90
+ return [
91
+ ...tree.map((id) => ({ id, source: 'tree' as const })),
92
+ ...installed.filter((id) => !tree.includes(id)).map((id) => ({ id, source: 'extension' as const })),
93
+ ];
94
+ }
95
+
96
+ /** 命令行上 `--名=值` 的值;没给这个开关时为 null。 */
97
+ function flagValue(name: string): string | null {
98
+ const prefix = `--${name}=`;
99
+ const hit = process.argv.find((a) => a.startsWith(prefix));
100
+ return hit ? hit.slice(prefix.length) : null;
101
+ }
102
+
103
+ async function main(): Promise<void> {
104
+ if (process.argv.includes('--create-default')) {
105
+ process.stdout.write(ensureDeployment() + '\n');
106
+ return;
107
+ }
108
+
109
+ const created = flagValue('create-deployment');
110
+ if (created !== null) {
111
+ const bot = flagValue('bot');
112
+ if (!bot) throw new Error('--create-deployment 需要同时给 --bot=<代码包>');
113
+ const displayName = flagValue('display-name');
114
+ process.stdout.write(
115
+ createDeployment({ name: created, bot, ...(displayName ? { displayName } : {}) }) + '\n',
116
+ );
117
+ return;
118
+ }
119
+
120
+ if (process.argv.includes('--json')) {
121
+ const listing = await buildListing({
122
+ root: deploymentRoot(),
123
+ deployments: listBots(),
124
+ packages: botPackages(),
125
+ defaultsOf: botDefaults,
126
+ });
127
+ process.stdout.write(JSON.stringify(listing) + '\n');
128
+ return;
129
+ }
130
+
131
+ if (process.argv.includes('--list')) {
132
+ process.stdout.write(listBots().join('\n') + '\n');
133
+ return;
134
+ }
135
+
136
+ const botName = pickBotName();
137
+ const { definition: loadedDefinition, deployDir: botDir, pkgDir, botPackage } = await loadBotDefinition(botName);
138
+
139
+ // 扩展 provider 必须在 createBot 解析端点配置前注册。
140
+ const extensions = await loadExtensions(repoRoot(), {
141
+ reserved: BUILTIN_WORLDS.map((m) => m.id),
142
+ reservedProviders: providerModules.map((m) => m.id),
143
+ ...(botPackage ? { activeBot: botPackage } : {}),
144
+ });
145
+ registerProviderModules(extensions.providers);
146
+ const definition = withWorlds(loadedDefinition, [...BUILTIN_WORLDS, ...extensions.worlds]);
147
+
148
+ const loaded = loadDeployment(definition, botDir, repoRoot(), pkgDir, providersRoot());
149
+ const cfg = loaded.config;
150
+
151
+ announceDataDir(loaded.dataDir);
152
+
153
+ // 日志落盘门槛:--log-level=<级别> > CORTICO_LOG > config.json
154
+ const levelArg = process.argv.find((a) => a.startsWith('--log-level='))?.slice('--log-level='.length) ?? process.env.CORTICO_LOG;
155
+ if (levelArg) {
156
+ if (!(levelArg in LOG_LEVEL_RANK)) {
157
+ console.error(`无效日志级别: ${levelArg}(可选 ${Object.keys(LOG_LEVEL_RANK).join(' / ')})`);
158
+ process.exit(1);
159
+ }
160
+ cfg.logging.file = levelArg as LogLevel;
161
+ }
162
+
163
+ // 重启标志必须在装配与 session 加载之前处理
164
+ consumeBootFlags(loaded.dataDir);
165
+
166
+ const activeProvider = cfg.providers?.[cfg.activeProvider];
167
+ if (!activeProvider) {
168
+ console.error(
169
+ `activeProvider="${cfg.activeProvider}" 在 providers 段里不存在(现有: ${Object.keys(cfg.providers ?? {}).join(' / ') || '无'})`,
170
+ );
171
+ process.exit(1);
172
+ }
173
+ const endpointDir = providerDir(cfg.activeProvider);
174
+ const missingSecret =
175
+ activeProvider.secret && !secretReader(resolve(endpointDir, '.env'))(activeProvider.secret)
176
+ ? activeProvider.secret
177
+ : null;
178
+
179
+ const bot = createBot(loaded, definition, { extensions });
180
+
181
+ // 必须在启动主循环前暂停,避免首批事件提前投递。
182
+ const startPaused =
183
+ process.env.CORTICO_START_PAUSED === '1' ||
184
+ process.env.CORTICO_START_PAUSED === 'true' ||
185
+ process.argv.includes('--paused');
186
+ if (startPaused) bot.core.bus.setPaused(true);
187
+
188
+ const { port } = await bot.start();
189
+
190
+ console.log(`\n Bot: ${botName}${cfg.displayName && cfg.displayName !== botName ? ` (${cfg.displayName})` : ''}`);
191
+ if (port !== null) {
192
+ console.log(` 控制台: http://127.0.0.1:${port}/`);
193
+ const assetsProblem = webAssetsProblem(fileURLToPath(new URL('../dist/web', import.meta.url)));
194
+ if (assetsProblem) {
195
+ console.log(` ⚠ 控制台产物不完整(${assetsProblem});停止 bot 后运行 pnpm build:web`);
196
+ }
197
+ }
198
+ for (const slot of bot.assembly.slots) {
199
+ console.log(slot.mounted ? ` World: ${slot.id}` : ` World: ${slot.id} · 未激活`);
200
+ }
201
+ for (const entry of bot.assembly.missing) {
202
+ console.log(` World: ${entry.id} 不可用: ${entry.reason}`);
203
+ }
204
+ for (const ext of extensions.records) {
205
+ console.log(ext.loaded
206
+ ? ` 扩展: ${ext.name}@${ext.version} → ${ext.kind === 'provider' ? 'provider' : ext.kind === 'bot' ? 'bot' : 'World'} ${ext.worldId}`
207
+ : ext.idle
208
+ ? ` 扩展: ${ext.name}@${ext.version} · bot 包,本部署未引用`
209
+ : ` 扩展: ${ext.name} 未加载: ${ext.reason}`);
210
+ }
211
+ console.log(` 主模型: ${bot.core.mainSessionSpec().model}`);
212
+ if (missingSecret) {
213
+ const envFile = resolve(endpointDir, '.env');
214
+ const where = existsSync(envFile) ? `${envFile} 里也没有` : `${envFile} 不存在`;
215
+ console.log(` ⚠ 缺少 ${missingSecret}:进程环境里没有,${where};可在控制台「模型提供商」页修改密钥变量名或补填密钥`);
216
+ }
217
+ if (startPaused) {
218
+ console.log(' ⏸ 已暂停');
219
+ }
220
+ console.log('');
221
+
222
+ const openBrowserFlag =
223
+ process.env.CORTICO_OPEN_BROWSER === '1' ||
224
+ process.env.CORTICO_OPEN_BROWSER === 'true' ||
225
+ process.argv.includes('--open');
226
+ if (openBrowserFlag && port !== null) openBrowser(`http://127.0.0.1:${port}/`);
227
+
228
+ // 此时限覆盖整个关机流程;各步骤的时限由 bot.shutdown() 管理。
229
+ const SHUTDOWN_GRACE_MS = 35_000;
230
+ let shuttingDown = false;
231
+ const shutdown = async (sig: string) => {
232
+ if (shuttingDown) return;
233
+ shuttingDown = true;
234
+ console.log(`\n收到 ${sig},正在关机…`);
235
+ let code = 0;
236
+ try {
237
+ const report = await Promise.race([
238
+ bot.shutdown(sig),
239
+ new Promise<null>((r) => setTimeout(() => r(null), SHUTDOWN_GRACE_MS)),
240
+ ]);
241
+ if (!report) {
242
+ console.log(` 关机超过 ${SHUTDOWN_GRACE_MS / 1000} 秒,强制退出。`);
243
+ code = 1;
244
+ } else {
245
+ for (const step of report.steps) {
246
+ console.log(` ${step.ok ? '✓' : '✗'} ${step.label}${step.ok ? '' : ` — ${step.detail ?? '未完成'}`}`);
247
+ }
248
+ for (const check of report.externalChecks) {
249
+ if (check.status === 'verified-ended') {
250
+ console.log(` ✓ ${check.label} — ${check.detail}`);
251
+ continue;
252
+ }
253
+ console.log(` ⚠ [P0] ${check.label} — ${check.status}: ${check.detail}`);
254
+ console.log(` 人工动作: ${check.manualAction}`);
255
+ }
256
+ if (!report.complete) code = 1;
257
+ }
258
+ } catch (e) {
259
+ console.error('关机失败:', e instanceof Error ? e.message : e);
260
+ code = 1;
261
+ } finally {
262
+ process.exit(code);
263
+ }
264
+ };
265
+ process.on('SIGINT', () => void shutdown('SIGINT'));
266
+ process.on('SIGTERM', () => void shutdown('SIGTERM'));
267
+ // Windows 关闭窗口触发 SIGHUP,Ctrl+Break 触发 SIGBREAK;系统的退出时限可能短于关机流程。
268
+ process.on('SIGHUP', () => void shutdown('SIGHUP(窗口被关闭)'));
269
+ if (process.platform === 'win32') {
270
+ process.on('SIGBREAK', () => void shutdown('SIGBREAK(Ctrl+Break)'));
271
+ }
272
+ const processLog = bot.core.runlog.logger('process');
273
+ process.on('uncaughtException', (err) => {
274
+ processLog.emit('error', '未捕获异常,正在关机', { event: 'uncaught-exception', err });
275
+ void shutdown('uncaughtException');
276
+ });
277
+ process.on('unhandledRejection', (reason) => {
278
+ processLog.emit('error', '未处理的 promise 拒绝', { event: 'unhandled-rejection', err: reason });
279
+ });
280
+ }
281
+
282
+ main().catch((e) => {
283
+ console.error('启动失败:', e instanceof Error ? e.message : e);
284
+ process.exit(1);
285
+ });
package/src/paths.ts ADDED
@@ -0,0 +1,155 @@
1
+ /**
2
+ * repoRoot() 返回当前代码检出目录,mainRepoRoot() 返回所属主仓库目录。
3
+ * deploymentRoot() 解析运行数据根;每份部署的 deployment.json 指定 bot 代码包,
4
+ * 同一代码包可供多个部署使用。
5
+ */
6
+ import { execFileSync } from 'node:child_process';
7
+ import { existsSync } from 'node:fs';
8
+ import { dirname, isAbsolute, resolve } from 'node:path';
9
+ import { readTextFile } from './core/util.ts';
10
+
11
+ /** 默认部署目录,相对主仓库根;该目录不纳入版本控制。 */
12
+ const DEFAULT_DEPLOYMENT_DIRNAME = 'deployments';
13
+
14
+ /** 仓内 bot 代码包目录名,相对主仓库根;不受 CORTICO_HOME 影响。 */
15
+ const PACKAGES_DIRNAME = 'bots';
16
+
17
+ /** 共享端点目录名,相对部署根;没有 deployment.json,因此不列为部署。 */
18
+ const PROVIDERS_DIRNAME = 'providers';
19
+
20
+ /** 外部运行程序与模型文件的共享目录名,相对部署根。 */
21
+ const RUNTIMES_DIRNAME = 'runtimes';
22
+ const MODELS_DIRNAME = 'models';
23
+
24
+ /** 部署根的环境变量名。进程环境与仓库根 `.env` 用同一个名字。 */
25
+ export const DEPLOYMENT_ROOT_ENV = 'CORTICO_HOME';
26
+
27
+ let repoRootCache: string | null = null;
28
+ let mainRepoRootCache: string | null = null;
29
+ let deploymentRootCache: string | null = null;
30
+
31
+ /** 这份代码包所在的检出根(src/ 的上一级)。 */
32
+ export function repoRoot(): string {
33
+ if (repoRootCache === null) repoRootCache = resolve(import.meta.dirname, '..');
34
+ return repoRootCache;
35
+ }
36
+
37
+ /**
38
+ * 根据 git --git-common-dir 解析主仓库根;worktree 使用共享 .git 的父目录。
39
+ * Git 不可用或目录不属于仓库时返回 from。
40
+ */
41
+ export function resolveMainRepoRoot(from: string): string {
42
+ try {
43
+ const out = execFileSync('git', ['rev-parse', '--git-common-dir'], {
44
+ cwd: from,
45
+ encoding: 'utf8',
46
+ stdio: ['ignore', 'pipe', 'ignore'],
47
+ }).trim();
48
+ if (!out) return from;
49
+ return dirname(isAbsolute(out) ? resolve(out) : resolve(from, out));
50
+ } catch {
51
+ return from;
52
+ }
53
+ }
54
+
55
+ /** 主仓库的根。worktree 里指回主检出,不是当前 worktree。 */
56
+ export function mainRepoRoot(): string {
57
+ if (mainRepoRootCache === null) mainRepoRootCache = resolveMainRepoRoot(repoRoot());
58
+ return mainRepoRootCache;
59
+ }
60
+
61
+ /** 读取当前检出根 .env 中的 CORTICO_HOME,支持引号与包含空格的路径。 */
62
+ function readDeploymentRootFromEnvFile(checkoutRoot: string): string {
63
+ const file = resolve(checkoutRoot, '.env');
64
+ if (!existsSync(file)) return '';
65
+ const m = new RegExp(`^[ \\t]*${DEPLOYMENT_ROOT_ENV}[ \\t]*=[ \\t]*(.*)$`, 'm').exec(
66
+ readTextFile(file),
67
+ );
68
+ const raw = m ? m[1].trim() : '';
69
+ return raw.length >= 2 && (raw.startsWith('"') || raw.startsWith("'")) && raw.endsWith(raw[0])
70
+ ? raw.slice(1, -1).trim()
71
+ : raw;
72
+ }
73
+
74
+ /**
75
+ * 依次使用进程 CORTICO_HOME、当前检出根 .env、默认目录名。
76
+ * 相对路径以主仓库根为基准,绝对路径规范化后使用。
77
+ */
78
+ export function resolveDeploymentRoot(
79
+ env: NodeJS.ProcessEnv,
80
+ checkoutRoot: string,
81
+ mainRoot: string,
82
+ ): string {
83
+ const raw = (env[DEPLOYMENT_ROOT_ENV] ?? '').trim() || readDeploymentRootFromEnvFile(checkoutRoot);
84
+ if (!raw) return resolve(mainRoot, DEFAULT_DEPLOYMENT_DIRNAME);
85
+ return isAbsolute(raw) ? resolve(raw) : resolve(mainRoot, raw);
86
+ }
87
+
88
+ /** 部署根:所有部署目录的父目录。进程内解析一次。 */
89
+ export function deploymentRoot(): string {
90
+ if (deploymentRootCache === null) {
91
+ deploymentRootCache = resolveDeploymentRoot(process.env, repoRoot(), mainRepoRoot());
92
+ }
93
+ return deploymentRootCache;
94
+ }
95
+
96
+ /** 部署目录,包含 deployment.json、配置、密钥和运行数据。 */
97
+ export function deploymentDir(name: string): string {
98
+ return resolve(deploymentRoot(), name);
99
+ }
100
+
101
+ /** 同一部署根下共用的 provider 端点目录。 */
102
+ export function providersRoot(): string {
103
+ return resolve(deploymentRoot(), PROVIDERS_DIRNAME);
104
+ }
105
+
106
+ /**
107
+ * 端点目录以 config.providers 的键命名;同一 provider 模块可有多个端点。
108
+ * 目录内部结构由 provider 管理。
109
+ */
110
+ export function providerDir(name: string): string {
111
+ return resolve(providersRoot(), name);
112
+ }
113
+
114
+ /**
115
+ * 运行时根:`<部署根>/runtimes/<运行时 id>/<版本>/`,一个版本一个目录,可并存。
116
+ * 目录内部的布局归下载它的那个模块。
117
+ */
118
+ export function runtimesRoot(): string {
119
+ return resolve(deploymentRoot(), RUNTIMES_DIRNAME);
120
+ }
121
+
122
+ /** 模型文件根:`<部署根>/models/<owner>/`,owner 是 provider id 或 World id。 */
123
+ export function modelsRoot(): string {
124
+ return resolve(deploymentRoot(), MODELS_DIRNAME);
125
+ }
126
+
127
+ /** 仓内 bot 代码包目录;扩展包由扩展装载器另行定位。 */
128
+ export function packageDir(bot: string): string {
129
+ return resolve(mainRepoRoot(), PACKAGES_DIRNAME, bot);
130
+ }
131
+
132
+ /** 一份部署的 `deployment.json`。 */
133
+ export interface DeploymentManifest {
134
+ /** 这份部署引用哪个 bot 代码包。 */
135
+ bot: string;
136
+ }
137
+
138
+ /**
139
+ * 读一份部署的 `deployment.json`。文件不在回 null;文件在而读不成一个带 `bot` 的对象就抛,
140
+ * 消息里带上是哪一步不成。
141
+ */
142
+ export function readDeploymentManifest(name: string): DeploymentManifest | null {
143
+ const file = resolve(deploymentDir(name), 'deployment.json');
144
+ if (!existsSync(file)) return null;
145
+ let raw: { bot?: unknown };
146
+ try {
147
+ raw = JSON.parse(readTextFile(file)) as { bot?: unknown };
148
+ } catch (err) {
149
+ throw new Error(`${file} 不是合法 JSON: ${err instanceof Error ? err.message : String(err)}`);
150
+ }
151
+ if (typeof raw.bot !== 'string' || !raw.bot.trim()) {
152
+ throw new Error(`${file} 没有 bot 字段`);
153
+ }
154
+ return { bot: raw.bot.trim() };
155
+ }
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,14 @@
1
+ <!-- Owner: src/protocol/open-responses/index.ts -->
2
+
3
+ # Open Responses
4
+
5
+ `openapi.json` is the published 2026-04-24 schema from
6
+ https://www.openresponses.org/openapi/2026-04-24/openapi.json.
7
+ The upstream revision recorded at import is
8
+ `92c12d96d7b61d6d15e2214daa5e9c6000ab6e1c`.
9
+ The upstream schema is licensed under Apache-2.0; see LICENSE.
10
+
11
+ Regenerate types with `pnpm exec tsx scripts/generate-open-responses.ts`.
12
+ Use `--check` to verify the generated file and embedded schema digest.
13
+ Type generation preserves the published unions, including fields whose upstream
14
+ type is intentionally open. Stream lifecycle validation is implemented separately.