@capybara-hq/kernel 0.1.0-rc.6 → 0.1.0-rc.7

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 (331) hide show
  1. package/bootstrap.json +27 -3
  2. package/dist/admin/admin.controller.d.ts +8 -72
  3. package/dist/admin/admin.controller.js +21 -46
  4. package/dist/admin/admin.schemas.d.ts +57 -0
  5. package/dist/admin/admin.schemas.js +50 -0
  6. package/dist/admin/extensions.controller.d.ts +10 -0
  7. package/dist/admin/extensions.controller.js +18 -0
  8. package/dist/admin/extensions.schemas.d.ts +7 -0
  9. package/dist/admin/extensions.schemas.js +10 -0
  10. package/dist/admin/limit-defaults.d.ts +20 -0
  11. package/dist/admin/limit-defaults.js +10 -0
  12. package/dist/agents/agent-profile.service.d.ts +7 -5
  13. package/dist/agents/agent-profile.service.js +14 -9
  14. package/dist/agents/agents.controller.d.ts +7 -287
  15. package/dist/agents/agents.controller.js +7 -67
  16. package/dist/agents/agents.schemas.d.ts +389 -0
  17. package/dist/agents/agents.schemas.js +126 -0
  18. package/dist/agents/agents.service.d.ts +13 -5
  19. package/dist/agents/agents.service.js +67 -13
  20. package/dist/agents/definition.d.ts +47 -19
  21. package/dist/agents/definition.js +119 -38
  22. package/dist/agents/from-template.d.ts +2 -2
  23. package/dist/agents/from-template.js +76 -45
  24. package/dist/agents/from-template.service.d.ts +12 -0
  25. package/dist/agents/from-template.service.js +20 -3
  26. package/dist/agents/models.controller.d.ts +1 -2
  27. package/dist/agents/models.controller.js +1 -1
  28. package/dist/agents/org-templates.d.ts +13 -3
  29. package/dist/agents/org-templates.js +69 -28
  30. package/dist/agents/pending-connector-requests.d.ts +2 -0
  31. package/dist/agents/pending-connector-requests.js +1 -1
  32. package/dist/agents/pending-connectors.controller.d.ts +1 -1
  33. package/dist/agents/pending-connectors.controller.js +2 -2
  34. package/dist/agents/pending-connectors.service.d.ts +2 -2
  35. package/dist/agents/pending-connectors.service.js +19 -19
  36. package/dist/agents/profile.d.ts +18 -0
  37. package/dist/agents/profile.js +5 -1
  38. package/dist/agents/templates.controller.d.ts +8 -17
  39. package/dist/agents/templates.controller.js +13 -31
  40. package/dist/agents/templates.schemas.d.ts +20 -0
  41. package/dist/agents/templates.schemas.js +45 -0
  42. package/dist/background/background.controller.js +3 -2
  43. package/dist/background/background.schemas.d.ts +10 -0
  44. package/dist/background/background.schemas.js +16 -0
  45. package/dist/background/tasks.service.d.ts +1 -1
  46. package/dist/background/tasks.service.js +7 -2
  47. package/dist/catalog/admin-catalog.controller.d.ts +4 -57
  48. package/dist/catalog/admin-catalog.controller.js +8 -45
  49. package/dist/catalog/admin-catalog.schemas.d.ts +72 -0
  50. package/dist/catalog/admin-catalog.schemas.js +92 -0
  51. package/dist/catalog/catalog-content.d.ts +12 -2
  52. package/dist/catalog/catalog-scope.service.js +8 -2
  53. package/dist/catalog/catalog.service.d.ts +2 -0
  54. package/dist/catalog/catalog.service.js +3 -0
  55. package/dist/catalog/component-scope.controller.d.ts +3 -65
  56. package/dist/catalog/component-scope.controller.js +3 -56
  57. package/dist/catalog/component-scope.schemas.d.ts +114 -0
  58. package/dist/catalog/component-scope.schemas.js +97 -0
  59. package/dist/catalog/component-scope.service.d.ts +28 -4
  60. package/dist/catalog/component-scope.service.js +55 -3
  61. package/dist/catalog/component-state.d.ts +9 -2
  62. package/dist/catalog/component-state.js +22 -13
  63. package/dist/catalog/marketplaces.controller.d.ts +5 -35
  64. package/dist/catalog/marketplaces.controller.js +6 -34
  65. package/dist/catalog/marketplaces.schemas.d.ts +48 -0
  66. package/dist/catalog/marketplaces.schemas.js +53 -0
  67. package/dist/catalog/marketplaces.service.d.ts +15 -1
  68. package/dist/catalog/marketplaces.service.js +22 -1
  69. package/dist/catalog/org-catalog.controller.d.ts +6 -62
  70. package/dist/catalog/org-catalog.controller.js +12 -66
  71. package/dist/catalog/org-catalog.schemas.d.ts +79 -0
  72. package/dist/catalog/org-catalog.schemas.js +82 -0
  73. package/dist/catalog/org-catalog.service.d.ts +9 -2
  74. package/dist/catalog/org-catalog.service.js +38 -5
  75. package/dist/catalog/org-extension.controller.d.ts +1 -12
  76. package/dist/catalog/org-extension.controller.js +1 -10
  77. package/dist/catalog/org-extension.schemas.d.ts +15 -0
  78. package/dist/catalog/org-extension.schemas.js +22 -0
  79. package/dist/catalog/org-plugin-uploads.controller.d.ts +2 -19
  80. package/dist/catalog/org-plugin-uploads.controller.js +15 -28
  81. package/dist/catalog/org-plugin-uploads.schemas.d.ts +20 -0
  82. package/dist/catalog/org-plugin-uploads.schemas.js +32 -0
  83. package/dist/catalog/owned-items.d.ts +6 -2
  84. package/dist/catalog/owned-items.js +16 -4
  85. package/dist/catalog/platform-components.d.ts +2 -0
  86. package/dist/catalog/platform-components.js +2 -0
  87. package/dist/catalog/plugin-import.js +1 -0
  88. package/dist/catalog/plugin-install.js +1 -1
  89. package/dist/catalog/requests.service.d.ts +2 -1
  90. package/dist/catalog/requests.service.js +6 -2
  91. package/dist/channels/channels.schemas.d.ts +33 -0
  92. package/dist/channels/channels.schemas.js +34 -0
  93. package/dist/channels/connections.controller.d.ts +2 -29
  94. package/dist/channels/connections.controller.js +1 -23
  95. package/dist/channels/connections.service.d.ts +8 -2
  96. package/dist/channels/connections.service.js +23 -5
  97. package/dist/channels/inbound.js +4 -0
  98. package/dist/conversations/conversations.controller.d.ts +16 -37
  99. package/dist/conversations/conversations.controller.js +16 -56
  100. package/dist/conversations/conversations.schemas.d.ts +52 -0
  101. package/dist/conversations/conversations.schemas.js +79 -0
  102. package/dist/conversations/conversations.service.d.ts +9 -1
  103. package/dist/conversations/conversations.service.js +23 -18
  104. package/dist/conversations/events.d.ts +80 -6
  105. package/dist/conversations/events.js +60 -5
  106. package/dist/conversations/message-context.d.ts +28 -0
  107. package/dist/conversations/message-context.js +56 -0
  108. package/dist/conversations/queue.d.ts +2 -1
  109. package/dist/conversations/queue.js +11 -2
  110. package/dist/db/kernel-schema.d.ts +20 -0
  111. package/dist/environments/environments.schemas.d.ts +3 -0
  112. package/dist/environments/environments.schemas.js +14 -0
  113. package/dist/environments/environments.service.d.ts +16 -4
  114. package/dist/environments/environments.service.js +58 -13
  115. package/dist/errors.d.ts +3 -0
  116. package/dist/errors.js +3 -0
  117. package/dist/evals/evals.schemas.d.ts +110 -0
  118. package/dist/evals/evals.schemas.js +107 -0
  119. package/dist/evals/reconstruct.js +18 -11
  120. package/dist/evals/recorded-tools.d.ts +2 -1
  121. package/dist/evals/recorded-tools.js +11 -3
  122. package/dist/evals/run-replay.d.ts +8 -1
  123. package/dist/evals/run-replay.js +13 -0
  124. package/dist/evals/runs.controller.d.ts +2 -57
  125. package/dist/evals/runs.controller.js +1 -42
  126. package/dist/evals/runs.service.d.ts +6 -6
  127. package/dist/evals/runs.service.js +32 -18
  128. package/dist/evals/sets.controller.d.ts +2 -28
  129. package/dist/evals/sets.controller.js +1 -31
  130. package/dist/evals/sets.service.d.ts +7 -7
  131. package/dist/evals/sets.service.js +23 -17
  132. package/dist/evals/snapshot.d.ts +3 -2
  133. package/dist/evals/snapshot.js +17 -4
  134. package/dist/extensions/admin-ops.d.ts +5 -3
  135. package/dist/extensions/admin-ops.js +17 -12
  136. package/dist/extensions/deployment-config.d.ts +16 -1
  137. package/dist/extensions/deployment-config.js +83 -0
  138. package/dist/extensions/extensions.module.js +3 -0
  139. package/dist/extensions/host.d.ts +33 -2
  140. package/dist/extensions/host.js +107 -1
  141. package/dist/extensions/installs.d.ts +5 -0
  142. package/dist/extensions/installs.js +12 -0
  143. package/dist/extensions/org-config.d.ts +17 -2
  144. package/dist/extensions/org-config.js +23 -4
  145. package/dist/extensions/point-defaults.controller.d.ts +2 -8
  146. package/dist/extensions/point-defaults.controller.js +1 -3
  147. package/dist/extensions/point-defaults.d.ts +3 -1
  148. package/dist/extensions/point-defaults.js +4 -2
  149. package/dist/extensions/point-defaults.schemas.d.ts +9 -0
  150. package/dist/extensions/point-defaults.schemas.js +14 -0
  151. package/dist/extensions/unavailable.d.ts +49 -0
  152. package/dist/extensions/unavailable.js +113 -0
  153. package/dist/files/previewers.controller.js +2 -3
  154. package/dist/files/previewers.d.ts +1 -1
  155. package/dist/files/previewers.js +4 -4
  156. package/dist/files/previewers.schemas.d.ts +10 -0
  157. package/dist/files/previewers.schemas.js +9 -0
  158. package/dist/http/api.module.js +2 -0
  159. package/dist/identity/accounts.d.ts +43 -4
  160. package/dist/identity/accounts.js +74 -6
  161. package/dist/identity/auth.guard.js +10 -1
  162. package/dist/identity/cookies.d.ts +6 -0
  163. package/dist/identity/cookies.js +14 -0
  164. package/dist/identity/identity.module.js +3 -0
  165. package/dist/identity/initial-passwords.controller.d.ts +22 -0
  166. package/dist/identity/initial-passwords.controller.js +49 -0
  167. package/dist/identity/initial-passwords.d.ts +61 -0
  168. package/dist/identity/initial-passwords.job.d.ts +16 -0
  169. package/dist/identity/initial-passwords.job.js +46 -0
  170. package/dist/identity/initial-passwords.js +159 -0
  171. package/dist/identity/me.controller.d.ts +14 -0
  172. package/dist/identity/me.controller.js +39 -1
  173. package/dist/identity/principal.d.ts +8 -0
  174. package/dist/identity/principal.js +8 -0
  175. package/dist/identity/settings.d.ts +3 -1
  176. package/dist/identity/settings.js +6 -4
  177. package/dist/inbox/inbox.schemas.d.ts +8 -0
  178. package/dist/inbox/inbox.schemas.js +11 -0
  179. package/dist/inbox/platform-inbox.controller.d.ts +1 -1
  180. package/dist/inbox/platform-inbox.controller.js +2 -2
  181. package/dist/index.d.ts +4 -0
  182. package/dist/index.js +6 -0
  183. package/dist/lifecycle/kernel-lifecycle.js +4 -0
  184. package/dist/models/enablement.d.ts +2 -0
  185. package/dist/models/enablement.js +1 -0
  186. package/dist/models/org-models.schemas.d.ts +8 -0
  187. package/dist/models/org-models.schemas.js +22 -0
  188. package/dist/models/prices.d.ts +3 -1
  189. package/dist/models/prices.js +7 -5
  190. package/dist/models/purposes.d.ts +12 -2
  191. package/dist/models/purposes.js +22 -8
  192. package/dist/orgs/orgs.controller.d.ts +2 -5
  193. package/dist/orgs/orgs.controller.js +3 -6
  194. package/dist/orgs/orgs.schemas.d.ts +8 -0
  195. package/dist/orgs/orgs.schemas.js +16 -0
  196. package/dist/orgs/orgs.service.d.ts +3 -1
  197. package/dist/orgs/orgs.service.js +6 -4
  198. package/dist/orgs/settings.service.d.ts +9 -1
  199. package/dist/orgs/settings.service.js +20 -5
  200. package/dist/overrides.d.ts +4 -0
  201. package/dist/overrides.js +2 -0
  202. package/dist/platform/errors.d.ts +21 -4
  203. package/dist/platform/errors.js +45 -6
  204. package/dist/platform/exclusions.d.ts +2 -3
  205. package/dist/platform/exclusions.js +68 -849
  206. package/dist/platform/method.js +1 -1
  207. package/dist/platform/operation.d.ts +82 -5
  208. package/dist/platform/operation.js +62 -7
  209. package/dist/platform/ops/accounts.ops.d.ts +32 -0
  210. package/dist/platform/ops/accounts.ops.js +291 -0
  211. package/dist/platform/ops/admin.ops.d.ts +36 -0
  212. package/dist/platform/ops/admin.ops.js +389 -0
  213. package/dist/platform/ops/agent-skills.ops.d.ts +24 -0
  214. package/dist/platform/ops/agent-skills.ops.js +226 -0
  215. package/dist/platform/ops/agent-templates.ops.d.ts +4 -1
  216. package/dist/platform/ops/agent-templates.ops.js +194 -14
  217. package/dist/platform/ops/agents.ops.d.ts +19 -1
  218. package/dist/platform/ops/agents.ops.js +481 -58
  219. package/dist/platform/ops/approvals.ops.d.ts +30 -0
  220. package/dist/platform/ops/approvals.ops.js +116 -0
  221. package/dist/platform/ops/background.ops.d.ts +14 -0
  222. package/dist/platform/ops/background.ops.js +134 -0
  223. package/dist/platform/ops/catalog-admin.ops.d.ts +74 -0
  224. package/dist/platform/ops/catalog-admin.ops.js +587 -0
  225. package/dist/platform/ops/channels.ops.d.ts +16 -0
  226. package/dist/platform/ops/channels.ops.js +195 -0
  227. package/dist/platform/ops/components.ops.d.ts +46 -0
  228. package/dist/platform/ops/components.ops.js +853 -0
  229. package/dist/platform/ops/connectors.ops.d.ts +4 -2
  230. package/dist/platform/ops/connectors.ops.js +68 -6
  231. package/dist/platform/ops/conversations.ops.d.ts +30 -0
  232. package/dist/platform/ops/conversations.ops.js +470 -0
  233. package/dist/platform/ops/environments.ops.d.ts +26 -0
  234. package/dist/platform/ops/environments.ops.js +289 -0
  235. package/dist/platform/ops/errors.d.ts +10 -5
  236. package/dist/platform/ops/errors.js +19 -11
  237. package/dist/platform/ops/evals.ops.d.ts +28 -0
  238. package/dist/platform/ops/evals.ops.js +783 -0
  239. package/dist/platform/ops/extensions-admin.ops.d.ts +25 -0
  240. package/dist/platform/ops/extensions-admin.ops.js +344 -0
  241. package/dist/platform/ops/extensions.ops.d.ts +7 -1
  242. package/dist/platform/ops/extensions.ops.js +248 -17
  243. package/dist/platform/ops/inbox.ops.d.ts +25 -0
  244. package/dist/platform/ops/inbox.ops.js +378 -0
  245. package/dist/platform/ops/marketplaces.ops.d.ts +7 -1
  246. package/dist/platform/ops/marketplaces.ops.js +326 -17
  247. package/dist/platform/ops/models.ops.d.ts +25 -0
  248. package/dist/platform/ops/models.ops.js +232 -0
  249. package/dist/platform/ops/org-plugins.ops.d.ts +29 -0
  250. package/dist/platform/ops/org-plugins.ops.js +329 -0
  251. package/dist/platform/ops/org-settings.ops.d.ts +16 -0
  252. package/dist/platform/ops/org-settings.ops.js +102 -0
  253. package/dist/platform/ops/orgs.ops.d.ts +28 -0
  254. package/dist/platform/ops/orgs.ops.js +295 -0
  255. package/dist/platform/ops/other-orgs.d.ts +20 -0
  256. package/dist/platform/ops/other-orgs.js +72 -0
  257. package/dist/platform/ops/platform.ops.d.ts +4 -4
  258. package/dist/platform/ops/platform.ops.js +23 -24
  259. package/dist/platform/ops/plugins.ops.d.ts +10 -8
  260. package/dist/platform/ops/plugins.ops.js +176 -77
  261. package/dist/platform/ops/previewers.ops.d.ts +14 -0
  262. package/dist/platform/ops/previewers.ops.js +109 -0
  263. package/dist/platform/ops/requests.ops.js +57 -19
  264. package/dist/platform/ops/skills.ops.d.ts +5 -1
  265. package/dist/platform/ops/skills.ops.js +129 -11
  266. package/dist/platform/ops/unavailable.d.ts +23 -0
  267. package/dist/platform/ops/unavailable.js +111 -0
  268. package/dist/platform/parity.d.ts +33 -0
  269. package/dist/platform/parity.js +272 -0
  270. package/dist/platform/platform-ops.module.d.ts +32 -0
  271. package/dist/platform/platform-ops.module.js +78 -11
  272. package/dist/platform/route-schemas.d.ts +18 -0
  273. package/dist/platform/route-schemas.js +60 -0
  274. package/dist/roles/worker.module.js +2 -0
  275. package/dist/runtime/context/build.d.ts +2 -0
  276. package/dist/runtime/context/build.js +28 -2
  277. package/dist/runtime/context/compaction.js +10 -1
  278. package/dist/runtime/context/run-context.d.ts +65 -0
  279. package/dist/runtime/context/run-context.js +215 -0
  280. package/dist/runtime/model-call.js +2 -1
  281. package/dist/runtime/providers.js +8 -1
  282. package/dist/runtime/run-context.service.d.ts +65 -0
  283. package/dist/runtime/run-context.service.js +220 -0
  284. package/dist/runtime/run-worker.d.ts +5 -0
  285. package/dist/runtime/run-worker.js +31 -6
  286. package/dist/runtime/runtime.module.js +2 -0
  287. package/dist/runtime/subagents/definition.d.ts +15 -15
  288. package/dist/runtime/subagents/definition.js +46 -115
  289. package/dist/skills/changes.controller.js +2 -1
  290. package/dist/skills/changes.service.d.ts +1 -1
  291. package/dist/skills/changes.service.js +4 -4
  292. package/dist/skills/invocable.controller.d.ts +1 -1
  293. package/dist/skills/invocable.controller.js +2 -2
  294. package/dist/skills/invoke.d.ts +2 -2
  295. package/dist/skills/invoke.js +8 -1
  296. package/dist/skills/skills.controller.d.ts +4 -13
  297. package/dist/skills/skills.controller.js +8 -24
  298. package/dist/skills/skills.schemas.d.ts +48 -0
  299. package/dist/skills/skills.schemas.js +61 -0
  300. package/dist/skills/skills.service.d.ts +11 -1
  301. package/dist/skills/skills.service.js +37 -14
  302. package/dist/time-zone.d.ts +5 -0
  303. package/dist/time-zone.js +19 -0
  304. package/dist/tools/approvals.controller.js +2 -3
  305. package/dist/tools/approvals.schemas.d.ts +21 -0
  306. package/dist/tools/approvals.schemas.js +15 -0
  307. package/dist/tools/builtin-names.d.ts +10 -8
  308. package/dist/tools/builtin-names.js +16 -11
  309. package/dist/tools/builtins/builtin-tools.d.ts +3 -1
  310. package/dist/tools/builtins/builtin-tools.js +15 -3
  311. package/dist/tools/builtins/current-time.d.ts +26 -0
  312. package/dist/tools/builtins/current-time.js +99 -0
  313. package/dist/tools/builtins/platform.d.ts +19 -2
  314. package/dist/tools/builtins/platform.js +105 -16
  315. package/dist/tools/connectors.controller.d.ts +1 -2
  316. package/dist/tools/connectors.controller.js +1 -4
  317. package/dist/tools/connectors.schemas.d.ts +12 -0
  318. package/dist/tools/connectors.schemas.js +19 -0
  319. package/dist/tools/connectors.service.d.ts +5 -2
  320. package/dist/tools/connectors.service.js +7 -5
  321. package/dist/tools/org-tool-switches.d.ts +16 -2
  322. package/dist/tools/org-tool-switches.js +26 -9
  323. package/dist/tools/pipeline.js +3 -1
  324. package/dist/tools/registry.d.ts +48 -51
  325. package/dist/tools/registry.js +222 -233
  326. package/package.json +3 -3
  327. package/src/migrations/0090_initial_passwords.sql +27 -0
  328. package/src/migrations/0091_account_time_zone.sql +4 -0
  329. package/src/migrations/0092_tools_default_on.sql +27 -0
  330. package/dist/platform/redact-orgs.d.ts +0 -7
  331. package/dist/platform/redact-orgs.js +0 -52
@@ -243,6 +243,10 @@ let ChannelInbound = class ChannelInbound {
243
243
  const posted = await this.post(row.orgId, conversationId, accountId, {
244
244
  text: e.text,
245
245
  clientMessageId: `${connectionId}:${e.messageId}`,
246
+ // run context spec §7: an anonymous guest is named by their IM profile name; a bound
247
+ // person by their account's name (the kernel reads it)
248
+ ...(threadAccount === null &&
249
+ e.sender.displayName !== undefined && { senderName: e.sender.displayName }),
246
250
  });
247
251
  seq = posted.event.seq;
248
252
  // best-effort (batch 5 review m4): a failed note must not fail the job before the thread
@@ -6,6 +6,7 @@ import { type OrgContext } from "../orgs/org.guard.js";
6
6
  import { ConversationToolInfo, type ToolInfo } from "../tools/info.js";
7
7
  import type { AgentTreeNode } from "./agent-tree.js";
8
8
  import { type ArtifactPreview, ConversationArtifacts } from "./artifacts.js";
9
+ import { EventsQuery, FilesQuery, IdParams, ListQuery, PatchBody, SubagentsQuery } from "./conversations.schemas.js";
9
10
  import { type ConversationGroup, ConversationsService, type ConversationView, type SubagentView, type UsageTotals } from "./conversations.service.js";
10
11
  import { ConversationEnvironmentStatus } from "./environment-status.js";
11
12
  import type { ConversationEvent } from "./events.js";
@@ -13,19 +14,6 @@ import { ConversationFiles, type FileOutput } from "./files.js";
13
14
  import { ConversationOutputs, type OutputPage } from "./outputs-read.js";
14
15
  import type { QueueItem, QueuePauseReason } from "./queue.js";
15
16
  import { ConversationQueue } from "./queue.service.js";
16
- declare const ListQuery: z.ZodObject<{
17
- q: z.ZodOptional<z.ZodString>;
18
- state: z.ZodOptional<z.ZodEnum<{
19
- running: "running";
20
- waiting: "waiting";
21
- }>>;
22
- archived: z.ZodOptional<z.ZodEnum<{
23
- 1: "1";
24
- }>>;
25
- after: z.ZodOptional<z.ZodString>;
26
- limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
27
- agentId: z.ZodOptional<z.ZodString>;
28
- }, z.core.$strip>;
29
17
  declare const GroupsQuery: z.ZodObject<{
30
18
  q: z.ZodOptional<z.ZodString>;
31
19
  state: z.ZodOptional<z.ZodEnum<{
@@ -39,15 +27,6 @@ declare const GroupsQuery: z.ZodObject<{
39
27
  limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
40
28
  after: z.ZodOptional<z.ZodString>;
41
29
  }, z.core.$strip>;
42
- declare const SubagentsQuery: z.ZodObject<{
43
- after: z.ZodOptional<z.ZodString>;
44
- limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
45
- }, z.core.$strip>;
46
- declare const EventsQuery: z.ZodObject<{
47
- after: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
48
- before: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"end">, z.ZodCoercedNumber<unknown>]>>;
49
- limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
50
- }, z.core.$strip>;
51
30
  /** `?keys=a,b`: 1–100 comma-separated tool keys of 1–200 characters each. */
52
31
  declare const ToolsQuery: z.ZodObject<{
53
32
  keys: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string[], string>>, z.ZodArray<z.ZodString>>;
@@ -56,10 +35,6 @@ declare const OutputQuery: z.ZodObject<{
56
35
  offset: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
57
36
  limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
58
37
  }, z.core.$strip>;
59
- declare const FilesQuery: z.ZodObject<{
60
- after: z.ZodOptional<z.ZodString>;
61
- limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
62
- }, z.core.$strip>;
63
38
  declare const FileContentQuery: z.ZodObject<{
64
39
  limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
65
40
  }, z.core.$strip>;
@@ -93,6 +68,11 @@ declare const MessageBody: z.ZodObject<{
93
68
  skill: z.ZodOptional<z.ZodObject<{
94
69
  name: z.ZodString;
95
70
  }, z.core.$strict>>;
71
+ timeZone: z.ZodOptional<z.ZodString>;
72
+ locale: z.ZodOptional<z.ZodEnum<{
73
+ en: "en";
74
+ zh: "zh";
75
+ }>>;
96
76
  }, z.core.$strict>;
97
77
  /**
98
78
  * `POST /conversations`: `message` creates the conversation with its first message (create on
@@ -125,6 +105,11 @@ declare const CreateBody: z.ZodObject<{
125
105
  skill: z.ZodOptional<z.ZodObject<{
126
106
  name: z.ZodString;
127
107
  }, z.core.$strict>>;
108
+ timeZone: z.ZodOptional<z.ZodString>;
109
+ locale: z.ZodOptional<z.ZodEnum<{
110
+ en: "en";
111
+ zh: "zh";
112
+ }>>;
128
113
  clientMessageId: z.ZodString;
129
114
  }, z.core.$strict>>;
130
115
  }, z.core.$strict>;
@@ -152,23 +137,17 @@ declare const QueueBody: z.ZodObject<{
152
137
  skill: z.ZodOptional<z.ZodObject<{
153
138
  name: z.ZodString;
154
139
  }, z.core.$strict>>;
140
+ timeZone: z.ZodOptional<z.ZodString>;
141
+ locale: z.ZodOptional<z.ZodEnum<{
142
+ en: "en";
143
+ zh: "zh";
144
+ }>>;
155
145
  clientMessageId: z.ZodString;
156
146
  }, z.core.$strict>;
157
147
  /** `PATCH …/queue/:itemId`: only the text changes (the text rule is checked against the item). */
158
148
  declare const QueueEditBody: z.ZodObject<{
159
149
  text: z.ZodString;
160
150
  }, z.core.$strict>;
161
- /**
162
- * A rename: 1–120 characters counted in code points after trimming, with no control or format
163
- * (bidi, zero-width) characters, the same rule generated and tool titles follow.
164
- */
165
- declare const PatchBody: z.ZodObject<{
166
- title: z.ZodOptional<z.ZodString>;
167
- archived: z.ZodOptional<z.ZodBoolean>;
168
- }, z.core.$strict>;
169
- declare const IdParams: z.ZodObject<{
170
- id: z.ZodString;
171
- }, z.core.$strip>;
172
151
  /**
173
152
  * 会话(`/api/v1/orgs/:orgId/conversations`):`agents.use`(访客以上),只接受人类用户;
174
153
  * 服务令牌 → 403 `forbidden`。只有会话所有者可见,其他人一律 `conversation.not_found`。
@@ -14,28 +14,15 @@ import { CurrentPrincipal, requireUser } from "../identity/principal.js";
14
14
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
15
15
  import { ZBody, ZParam, ZQuery } from "../infra/validation/zod-params.js";
16
16
  import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
17
- import { CONTROL_OR_HIDDEN_RE } from "../text.js";
18
17
  import { MAX_ATTACHMENTS } from "../tools/connector-content.js";
19
18
  import { ConversationToolInfo, TOOL_INFO_KEY_MAX, TOOL_INFO_MAX_KEYS, } from "../tools/info.js";
20
19
  import { ARTIFACT_DOWNLOAD_CACHE_SECONDS, ConversationArtifacts, } from "./artifacts.js";
21
- import { CONVERSATION_TITLE_MAX_CHARS, ConversationsService, } from "./conversations.service.js";
20
+ import { EventsQuery, FilesQuery, IdParams, ListQuery, PatchBody, SubagentsQuery, searchFields, } from "./conversations.schemas.js";
21
+ import { ConversationsService, } from "./conversations.service.js";
22
22
  import { ConversationEnvironmentStatus } from "./environment-status.js";
23
- import { ConversationFiles, FILE_CONTENT_MAX_BYTES, FILES_PAGE_MAX, } from "./files.js";
23
+ import { ConversationFiles, FILE_CONTENT_MAX_BYTES } from "./files.js";
24
24
  import { ConversationOutputs, OUTPUT_PAGE_MAX_CHARS } from "./outputs-read.js";
25
25
  import { ConversationQueue } from "./queue.service.js";
26
- /** Shared by the list and groups queries: title search, run activity and the archived list. */
27
- const searchFields = {
28
- q: z.string().min(1).max(100).optional(),
29
- state: z.enum(["running", "waiting"]).optional(),
30
- archived: z.enum(["1"]).optional(),
31
- };
32
- const ListQuery = z.object({
33
- after: z.string().min(1).max(100).optional(),
34
- limit: z.coerce.number().int().min(1).max(200).default(50),
35
- /** Only this agent's conversations (the sidebar's per-group "More"). */
36
- agentId: z.string().min(1).max(100).optional(),
37
- ...searchFields,
38
- });
39
26
  const GroupsQuery = z.object({
40
27
  perGroup: z.coerce.number().int().min(1).max(20).default(5),
41
28
  limit: z.coerce.number().int().min(1).max(50).default(20),
@@ -43,22 +30,6 @@ const GroupsQuery = z.object({
43
30
  after: z.string().min(1).max(100).optional(),
44
31
  ...searchFields,
45
32
  });
46
- const SubagentsQuery = z.object({
47
- /** The previous page's last sub-agent id (`next`). */
48
- after: z.string().min(1).max(100).optional(),
49
- limit: z.coerce.number().int().min(1).max(100).default(50),
50
- });
51
- const EventsQuery = z
52
- .object({
53
- after: z.coerce.number().int().min(0).optional(),
54
- /** The page before this seq, or the log's last page (`end`); exclusive with `after`. */
55
- before: z.union([z.literal("end"), z.coerce.number().int().min(1)]).optional(),
56
- limit: z.coerce.number().int().min(1).max(500).default(500),
57
- })
58
- .refine((q) => q.after === undefined || q.before === undefined, {
59
- message: "after and before are exclusive",
60
- path: ["before"],
61
- });
62
33
  /** `?keys=a,b`: 1–100 comma-separated tool keys of 1–200 characters each. */
63
34
  const ToolsQuery = z.object({
64
35
  keys: z
@@ -71,10 +42,6 @@ const OutputQuery = z.object({
71
42
  offset: z.coerce.number().int().min(0).default(0),
72
43
  limit: z.coerce.number().int().min(1).max(OUTPUT_PAGE_MAX_CHARS).default(OUTPUT_PAGE_MAX_CHARS),
73
44
  });
74
- const FilesQuery = z.object({
75
- after: z.string().min(1).max(100).optional(),
76
- limit: z.coerce.number().int().min(1).max(FILES_PAGE_MAX).default(50),
77
- });
78
45
  const FileContentQuery = z.object({
79
46
  limit: z.coerce.number().int().min(1).max(FILE_CONTENT_MAX_BYTES).default(FILE_CONTENT_MAX_BYTES),
80
47
  });
@@ -114,6 +81,13 @@ const MessageFields = z.object({
114
81
  })
115
82
  .strict()
116
83
  .optional(),
84
+ /**
85
+ * The browser's IANA time zone (run context spec §3.4). An unknown name is ignored, never a
86
+ * 400; the sender's account setting overrides it.
87
+ */
88
+ timeZone: z.string().min(1).max(64).optional(),
89
+ /** The sender's UI language (run context spec §3.4). */
90
+ locale: z.enum(["zh", "en"]).optional(),
117
91
  });
118
92
  // The body of `@` resource i is `content[i + 1]`, so `content[0]` must be the user's text: with
119
93
  // `@` resources the text must not be empty. A skill invocation's `content[0]` is the rendered
@@ -155,26 +129,6 @@ const QueueBody = MessageFields.omit({ retryOf: true })
155
129
  .refine(...textRule);
156
130
  /** `PATCH …/queue/:itemId`: only the text changes (the text rule is checked against the item). */
157
131
  const QueueEditBody = z.object({ text: z.string().max(100_000) }).strict();
158
- /**
159
- * A rename: 1–120 characters counted in code points after trimming, with no control or format
160
- * (bidi, zero-width) characters, the same rule generated and tool titles follow.
161
- */
162
- const PatchBody = z
163
- .object({
164
- title: z
165
- .string()
166
- .max(CONVERSATION_TITLE_MAX_CHARS * 2 + 100)
167
- .trim()
168
- .refine((t) => t.length > 0, "title must not be empty")
169
- .refine((t) => Array.from(t).length <= CONVERSATION_TITLE_MAX_CHARS, `title must be at most ${CONVERSATION_TITLE_MAX_CHARS} characters`)
170
- .refine((t) => !CONTROL_OR_HIDDEN_RE.test(t), "title must not contain control or format characters")
171
- .optional(),
172
- /** true archives (hidden from the default lists), false unarchives. */
173
- archived: z.boolean().optional(),
174
- })
175
- .strict()
176
- .refine((b) => b.title !== undefined || b.archived !== undefined, "title or archived is required");
177
- const IdParams = z.object({ id: z.string().min(1).max(100) });
178
132
  class ConversationCreateBodyDto extends createZodDto(CreateBody, "ConversationCreateBody") {
179
133
  }
180
134
  class ConversationPatchBodyDto extends createZodDto(PatchBody, "ConversationPatchBody") {
@@ -248,6 +202,8 @@ let ConversationsController = class ConversationsController {
248
202
  ...(m.model !== undefined && { model: m.model }),
249
203
  ...(m.effort !== undefined && { effort: m.effort }),
250
204
  ...(m.skill !== undefined && { skill: m.skill }),
205
+ ...(m.timeZone !== undefined && { timeZone: m.timeZone }),
206
+ ...(m.locale !== undefined && { locale: m.locale }),
251
207
  }, pick);
252
208
  reply.status(out.created ? 201 : 200);
253
209
  return { conversation: out.conversation, event: out.event, events: out.events };
@@ -443,6 +399,8 @@ let ConversationsController = class ConversationsController {
443
399
  ...(body.effort !== undefined && { effort: body.effort }),
444
400
  ...(body.retryOf !== undefined && { retryOf: body.retryOf }),
445
401
  ...(body.skill !== undefined && { skill: body.skill }),
402
+ ...(body.timeZone !== undefined && { timeZone: body.timeZone }),
403
+ ...(body.locale !== undefined && { locale: body.locale }),
446
404
  }),
447
405
  };
448
406
  }
@@ -470,6 +428,8 @@ let ConversationsController = class ConversationsController {
470
428
  ...(body.model !== undefined && { model: body.model }),
471
429
  ...(body.effort !== undefined && { effort: body.effort }),
472
430
  ...(body.skill !== undefined && { skill: body.skill }),
431
+ ...(body.timeZone !== undefined && { timeZone: body.timeZone }),
432
+ ...(body.locale !== undefined && { locale: body.locale }),
473
433
  }),
474
434
  };
475
435
  }
@@ -0,0 +1,52 @@
1
+ import { z } from "zod";
2
+ import type { RouteSchemas } from "../platform/route-schemas.js";
3
+ /** Shared by the list and groups queries: title search, run activity and the archived list. */
4
+ export declare const searchFields: {
5
+ q: z.ZodOptional<z.ZodString>;
6
+ state: z.ZodOptional<z.ZodEnum<{
7
+ running: "running";
8
+ waiting: "waiting";
9
+ }>>;
10
+ archived: z.ZodOptional<z.ZodEnum<{
11
+ 1: "1";
12
+ }>>;
13
+ };
14
+ export declare const ListQuery: z.ZodObject<{
15
+ q: z.ZodOptional<z.ZodString>;
16
+ state: z.ZodOptional<z.ZodEnum<{
17
+ running: "running";
18
+ waiting: "waiting";
19
+ }>>;
20
+ archived: z.ZodOptional<z.ZodEnum<{
21
+ 1: "1";
22
+ }>>;
23
+ after: z.ZodOptional<z.ZodString>;
24
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
25
+ agentId: z.ZodOptional<z.ZodString>;
26
+ }, z.core.$strip>;
27
+ export declare const EventsQuery: z.ZodObject<{
28
+ after: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
29
+ before: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"end">, z.ZodCoercedNumber<unknown>]>>;
30
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
31
+ }, z.core.$strip>;
32
+ /**
33
+ * A rename: 1–120 characters counted in code points after trimming, with no control or format
34
+ * (bidi, zero-width) characters, the same rule generated and tool titles follow.
35
+ */
36
+ export declare const PatchBody: z.ZodObject<{
37
+ title: z.ZodOptional<z.ZodString>;
38
+ archived: z.ZodOptional<z.ZodBoolean>;
39
+ }, z.core.$strict>;
40
+ export declare const IdParams: z.ZodObject<{
41
+ id: z.ZodString;
42
+ }, z.core.$strip>;
43
+ export declare const SubagentsQuery: z.ZodObject<{
44
+ after: z.ZodOptional<z.ZodString>;
45
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
46
+ }, z.core.$strip>;
47
+ export declare const FilesQuery: z.ZodObject<{
48
+ after: z.ZodOptional<z.ZodString>;
49
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
50
+ }, z.core.$strip>;
51
+ /** The conversation routes a Platform operation mirrors (spec §14, conversations). */
52
+ export declare const CONVERSATION_ROUTES: readonly RouteSchemas[];
@@ -0,0 +1,79 @@
1
+ import { z } from "zod";
2
+ import { CONTROL_OR_HIDDEN_RE } from "../text.js";
3
+ import { CONVERSATION_TITLE_MAX_CHARS } from "./conversations.service.js";
4
+ import { FILES_PAGE_MAX } from "./files.js";
5
+ /** Shared by the list and groups queries: title search, run activity and the archived list. */
6
+ export const searchFields = {
7
+ q: z.string().min(1).max(100).optional(),
8
+ state: z.enum(["running", "waiting"]).optional(),
9
+ archived: z.enum(["1"]).optional(),
10
+ };
11
+ export const ListQuery = z.object({
12
+ after: z.string().min(1).max(100).optional(),
13
+ limit: z.coerce.number().int().min(1).max(200).default(50),
14
+ /** Only this agent's conversations (the sidebar's per-group "More"). */
15
+ agentId: z.string().min(1).max(100).optional(),
16
+ ...searchFields,
17
+ });
18
+ export const EventsQuery = z
19
+ .object({
20
+ after: z.coerce.number().int().min(0).optional(),
21
+ /** The page before this seq, or the log's last page (`end`); exclusive with `after`. */
22
+ before: z.union([z.literal("end"), z.coerce.number().int().min(1)]).optional(),
23
+ limit: z.coerce.number().int().min(1).max(500).default(500),
24
+ })
25
+ .refine((q) => q.after === undefined || q.before === undefined, {
26
+ message: "after and before are exclusive",
27
+ path: ["before"],
28
+ });
29
+ /**
30
+ * A rename: 1–120 characters counted in code points after trimming, with no control or format
31
+ * (bidi, zero-width) characters, the same rule generated and tool titles follow.
32
+ */
33
+ export const PatchBody = z
34
+ .object({
35
+ title: z
36
+ .string()
37
+ .max(CONVERSATION_TITLE_MAX_CHARS * 2 + 100)
38
+ .trim()
39
+ .refine((t) => t.length > 0, "title must not be empty")
40
+ .refine((t) => Array.from(t).length <= CONVERSATION_TITLE_MAX_CHARS, `title must be at most ${CONVERSATION_TITLE_MAX_CHARS} characters`)
41
+ .refine((t) => !CONTROL_OR_HIDDEN_RE.test(t), "title must not contain control or format characters")
42
+ .optional(),
43
+ /** true archives (hidden from the default lists), false unarchives. */
44
+ archived: z.boolean().optional(),
45
+ })
46
+ .strict()
47
+ .refine((b) => b.title !== undefined || b.archived !== undefined, "title or archived is required");
48
+ export const IdParams = z.object({ id: z.string().min(1).max(100) });
49
+ export const SubagentsQuery = z.object({
50
+ /** The previous page's last sub-agent id (`next`). */
51
+ after: z.string().min(1).max(100).optional(),
52
+ limit: z.coerce.number().int().min(1).max(100).default(50),
53
+ });
54
+ export const FilesQuery = z.object({
55
+ after: z.string().min(1).max(100).optional(),
56
+ limit: z.coerce.number().int().min(1).max(FILES_PAGE_MAX).default(50),
57
+ });
58
+ /** The conversation routes a Platform operation mirrors (spec §14, conversations). */
59
+ export const CONVERSATION_ROUTES = [
60
+ { route: "GET /api/v1/orgs/:orgId/conversations", query: ListQuery },
61
+ { route: "GET /api/v1/orgs/:orgId/conversations/:id", params: IdParams },
62
+ {
63
+ route: "GET /api/v1/orgs/:orgId/conversations/:id/events",
64
+ params: IdParams,
65
+ query: EventsQuery,
66
+ },
67
+ { route: "PATCH /api/v1/orgs/:orgId/conversations/:id", params: IdParams, body: PatchBody },
68
+ { route: "DELETE /api/v1/orgs/:orgId/conversations/:id", params: IdParams },
69
+ {
70
+ route: "GET /api/v1/orgs/:orgId/conversations/:id/subagents",
71
+ params: IdParams,
72
+ query: SubagentsQuery,
73
+ },
74
+ { route: "GET /api/v1/orgs/:orgId/conversations/:id/agent-tree", params: IdParams },
75
+ { route: "GET /api/v1/orgs/:orgId/conversations/:id/usage", params: IdParams },
76
+ { route: "GET /api/v1/orgs/:orgId/conversations/:id/files", params: IdParams, query: FilesQuery },
77
+ { route: "GET /api/v1/orgs/:orgId/conversations/:id/environment", params: IdParams },
78
+ { route: "POST /api/v1/orgs/:orgId/conversations/:id/abort", params: IdParams },
79
+ ];
@@ -161,6 +161,11 @@ export interface UserMessageInput {
161
161
  skill?: {
162
162
  name: string;
163
163
  };
164
+ /** The browser's IANA time zone and UI language (run context spec §3.4); IM sends none. */
165
+ timeZone?: string;
166
+ locale?: "zh" | "en";
167
+ /** An anonymous IM guest's IM profile name (run context spec §7); other senders: none. */
168
+ senderName?: string;
164
169
  }
165
170
  /**
166
171
  * 会话:只有所有者可见;每次访问都实时复核 agent 对所有者仍可用(spec 3.6 R5),
@@ -366,7 +371,10 @@ export declare class ConversationsService {
366
371
  * `text` 为空时(只发附件,HTTP 层保证此时有 `files` 且没有 `@` 资源)不写文本块。
367
372
  */
368
373
  postUserMessage(orgId: string, conversationId: string, accountId: string, input: UserMessageInput): Promise<ConversationEvent>;
369
- /** A message with files or a model switch: binds the files and writes it in one transaction. */
374
+ /**
375
+ * Writes a message in one transaction: binds its files, reads its sender context and appends it
376
+ * (after its `model_switched` when it switches).
377
+ */
370
378
  private postIn;
371
379
  /**
372
380
  * The selection a message switches to, or null when it changes nothing. A model equal to the
@@ -29,6 +29,7 @@ import { readAgentTree } from "./agent-tree.js";
29
29
  import { AttachmentsService } from "./attachments.service.js";
30
30
  import { EventLog } from "./event-log.js";
31
31
  import { userMessageIdemKey } from "./idem-keys.js";
32
+ import { readMessageContext } from "./message-context.js";
32
33
  import { NO_SELECTION, planSelection, readSelection } from "./selection.js";
33
34
  import { conversationTree } from "./tree.js";
34
35
  /** Escapes `\`, `%` and `_` so user text is matched literally by `LIKE … ESCAPE '\'`. */
@@ -245,7 +246,7 @@ let ConversationsService = class ConversationsService {
245
246
  if (!row)
246
247
  return undefined;
247
248
  const blocks = await this.bindIn(orgId, id, accountId, input.files ?? []);
248
- return this.writeMessage(id, accountId, input, next, extra, blocks, invoked);
249
+ return this.writeMessage(orgId, id, accountId, input, next, extra, blocks, invoked);
249
250
  }
250
251
  /**
251
252
  * The conversation (and its first event) an earlier first send with this id created. The id used
@@ -706,18 +707,12 @@ let ConversationsService = class ConversationsService {
706
707
  const invoked = agent === undefined
707
708
  ? undefined
708
709
  : await this.prepareSkill(orgId, conv.agentId, conversationId, agent, input);
709
- let event;
710
- if (files.length > 0 || next !== null) {
711
- event = await this.postIn(orgId, conversationId, accountId, input, next, extra, invoked);
712
- await this.eventLog.notify(conversationId, event.seq);
713
- if (next !== null)
714
- await this.eventLog.publishChanged(conversationId, "selection");
715
- }
716
- else {
717
- [event] = await this.eventLog.append(conversationId, [
718
- this.userMessage(accountId, input, extra, [], invoked),
719
- ]);
720
- }
710
+ // one transaction: the sender, time zone and language are read with the message's write
711
+ // (run context spec §3.2)
712
+ const event = await this.postIn(orgId, conversationId, accountId, input, next, extra, invoked);
713
+ await this.eventLog.notify(conversationId, event.seq);
714
+ if (next !== null)
715
+ await this.eventLog.publishChanged(conversationId, "selection");
721
716
  // The message is written: it brings an archived conversation back into the default lists
722
717
  if (conv.archivedAt !== null) {
723
718
  await this.db
@@ -730,11 +725,14 @@ let ConversationsService = class ConversationsService {
730
725
  await this.runs.ensureRun(conversationId);
731
726
  return event;
732
727
  }
733
- /** A message with files or a model switch: binds the files and writes it in one transaction. */
728
+ /**
729
+ * Writes a message in one transaction: binds its files, reads its sender context and appends it
730
+ * (after its `model_switched` when it switches).
731
+ */
734
732
  // its own transaction: the caller notifies and publishes after the commit
735
733
  async postIn(orgId, conversationId, accountId, input, next, extra, invoked) {
736
734
  const blocks = await this.bindIn(orgId, conversationId, accountId, input.files ?? []);
737
- const written = await this.writeMessage(conversationId, accountId, input, next, extra, blocks, invoked);
735
+ const written = await this.writeMessage(orgId, conversationId, accountId, input, next, extra, blocks, invoked);
738
736
  return written.at(-1);
739
737
  }
740
738
  /**
@@ -779,7 +777,7 @@ let ConversationsService = class ConversationsService {
779
777
  * `conversations.selection`; returns the events written, in seq order (the `user_message`
780
778
  * last). The caller notifies after commit.
781
779
  */
782
- async writeMessage(conversationId, accountId, input, next, extra, blocks, invoked) {
780
+ async writeMessage(orgId, conversationId, accountId, input, next, extra, blocks, invoked) {
783
781
  const events = [];
784
782
  if (next !== null) {
785
783
  events.push({
@@ -790,7 +788,13 @@ let ConversationsService = class ConversationsService {
790
788
  payload: { ...next, byAccountId: accountId, reason: "user" },
791
789
  });
792
790
  }
793
- events.push(this.userMessage(accountId, input, extra, blocks, invoked));
791
+ const context = await readMessageContext(this.db.db, {
792
+ orgId,
793
+ accountId,
794
+ senderName: input.senderName,
795
+ browser: { timeZone: input.timeZone, locale: input.locale },
796
+ });
797
+ events.push(this.userMessage(accountId, input, extra, blocks, invoked, context));
794
798
  const written = await this.eventLog.appendIn(conversationId, events);
795
799
  if (next !== null) {
796
800
  const t = this.db.db;
@@ -847,7 +851,7 @@ let ConversationsService = class ConversationsService {
847
851
  return [];
848
852
  return this.attachments.bindForMessage(orgId, conversationId, accountId, files);
849
853
  }
850
- userMessage(accountId, input, extra, fileBlocks, invoked) {
854
+ userMessage(accountId, input, extra, fileBlocks, invoked, context) {
851
855
  // a skill invocation's rendered text replaces the typed arguments as content[0]
852
856
  const text = invoked?.text ?? input.text;
853
857
  return {
@@ -864,6 +868,7 @@ let ConversationsService = class ConversationsService {
864
868
  ],
865
869
  ...(extra.attachments.length > 0 && { attachments: extra.attachments }),
866
870
  authorAccountId: accountId,
871
+ ...context,
867
872
  ...(input.clientMessageId !== undefined && { clientMessageId: input.clientMessageId }),
868
873
  ...(input.retryOf !== undefined && { retryOf: input.retryOf }),
869
874
  ...(invoked !== undefined && { skill: invoked.skill }),
@@ -145,6 +145,39 @@ export declare const SubagentFinishStatusSchema: z.ZodEnum<{
145
145
  max_steps: "max_steps";
146
146
  timed_out: "timed_out";
147
147
  }>;
148
+ /** The languages a run context names (the org `locale` values). */
149
+ export declare const RUN_CONTEXT_LOCALES: readonly ["zh", "en"];
150
+ /** `user_message.sender` (run context spec §3.2). */
151
+ export declare const MessageSenderSchema: z.ZodObject<{
152
+ name: z.ZodString;
153
+ role: z.ZodOptional<z.ZodEnum<{
154
+ admin: "admin";
155
+ guest: "guest";
156
+ member: "member";
157
+ owner: "owner";
158
+ }>>;
159
+ anonymous: z.ZodOptional<z.ZodLiteral<true>>;
160
+ }, z.core.$strip>;
161
+ /** `run_context` (run context spec §3.1): every field optional, a later event holds changes only. */
162
+ export declare const RunContextSchema: z.ZodObject<{
163
+ agent: z.ZodOptional<z.ZodObject<{
164
+ name: z.ZodString;
165
+ description: z.ZodOptional<z.ZodString>;
166
+ }, z.core.$strip>>;
167
+ org: z.ZodOptional<z.ZodObject<{
168
+ name: z.ZodString;
169
+ }, z.core.$strip>>;
170
+ date: z.ZodOptional<z.ZodString>;
171
+ timeZone: z.ZodOptional<z.ZodString>;
172
+ locale: z.ZodOptional<z.ZodEnum<{
173
+ en: "en";
174
+ zh: "zh";
175
+ }>>;
176
+ dispatchedBy: z.ZodOptional<z.ZodObject<{
177
+ agent: z.ZodString;
178
+ person: z.ZodString;
179
+ }, z.core.$strip>>;
180
+ }, z.core.$strip>;
148
181
  /**
149
182
  * 会话事件(`type` + `payload`)的判别联合。事件日志只追加,写入前用它校验 payload;
150
183
  * 读出时按写入时的形状原样返回。
@@ -217,6 +250,21 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
217
250
  name: z.ZodString;
218
251
  }, z.core.$strip>>>;
219
252
  authorAccountId: z.ZodString;
253
+ sender: z.ZodOptional<z.ZodObject<{
254
+ name: z.ZodString;
255
+ role: z.ZodOptional<z.ZodEnum<{
256
+ admin: "admin";
257
+ guest: "guest";
258
+ member: "member";
259
+ owner: "owner";
260
+ }>>;
261
+ anonymous: z.ZodOptional<z.ZodLiteral<true>>;
262
+ }, z.core.$strip>>;
263
+ timeZone: z.ZodOptional<z.ZodString>;
264
+ locale: z.ZodOptional<z.ZodEnum<{
265
+ en: "en";
266
+ zh: "zh";
267
+ }>>;
220
268
  clientMessageId: z.ZodOptional<z.ZodString>;
221
269
  retryOf: z.ZodOptional<z.ZodNumber>;
222
270
  skill: z.ZodOptional<z.ZodObject<{
@@ -241,18 +289,18 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
241
289
  task: "task";
242
290
  }>>;
243
291
  narrowed: z.ZodOptional<z.ZodObject<{
244
- tools: z.ZodArray<z.ZodPreprocess<z.ZodDiscriminatedUnion<[z.ZodObject<{
292
+ disabledTools: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
245
293
  kind: z.ZodLiteral<"builtin">;
246
294
  name: z.ZodString;
247
295
  }, z.core.$strict>, z.ZodObject<{
248
296
  kind: z.ZodLiteral<"plugin">;
249
297
  plugin: z.ZodString;
250
- name: z.ZodString;
298
+ tools: z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodArray<z.ZodString>]>;
251
299
  }, z.core.$strict>, z.ZodObject<{
252
300
  kind: z.ZodLiteral<"connector">;
253
301
  connectorId: z.ZodString;
254
302
  tools: z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodArray<z.ZodString>]>;
255
- }, z.core.$strict>], "kind">, unknown>>;
303
+ }, z.core.$strict>], "kind">>>;
256
304
  skills: z.ZodOptional<z.ZodObject<{
257
305
  orgSkills: z.ZodArray<z.ZodString>;
258
306
  pinned: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -439,6 +487,27 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
439
487
  step: z.ZodNumber;
440
488
  text: z.ZodString;
441
489
  }, z.core.$strip>;
490
+ }, z.core.$strip>, z.ZodObject<{
491
+ type: z.ZodLiteral<"run_context">;
492
+ payload: z.ZodObject<{
493
+ agent: z.ZodOptional<z.ZodObject<{
494
+ name: z.ZodString;
495
+ description: z.ZodOptional<z.ZodString>;
496
+ }, z.core.$strip>>;
497
+ org: z.ZodOptional<z.ZodObject<{
498
+ name: z.ZodString;
499
+ }, z.core.$strip>>;
500
+ date: z.ZodOptional<z.ZodString>;
501
+ timeZone: z.ZodOptional<z.ZodString>;
502
+ locale: z.ZodOptional<z.ZodEnum<{
503
+ en: "en";
504
+ zh: "zh";
505
+ }>>;
506
+ dispatchedBy: z.ZodOptional<z.ZodObject<{
507
+ agent: z.ZodString;
508
+ person: z.ZodString;
509
+ }, z.core.$strip>>;
510
+ }, z.core.$strip>;
442
511
  }, z.core.$strip>, z.ZodObject<{
443
512
  type: z.ZodLiteral<"tools_changed">;
444
513
  payload: z.ZodObject<{
@@ -697,6 +766,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
697
766
  }, z.core.$strip>;
698
767
  definition: z.ZodObject<{
699
768
  name: z.ZodString;
769
+ description: z.ZodOptional<z.ZodString>;
700
770
  avatarUrl: z.ZodDefault<z.ZodNullable<z.ZodURL>>;
701
771
  instructions: z.ZodDefault<z.ZodString>;
702
772
  instructionFiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
@@ -713,18 +783,22 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
713
783
  }, z.core.$strip>>>;
714
784
  modelParams: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
715
785
  fallbackParams: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
716
- tools: z.ZodDefault<z.ZodArray<z.ZodPreprocess<z.ZodDiscriminatedUnion<[z.ZodObject<{
786
+ disabledTools: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
717
787
  kind: z.ZodLiteral<"builtin">;
718
788
  name: z.ZodString;
719
789
  }, z.core.$strict>, z.ZodObject<{
720
790
  kind: z.ZodLiteral<"plugin">;
721
791
  plugin: z.ZodString;
722
- name: z.ZodString;
792
+ tools: z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodArray<z.ZodString>]>;
723
793
  }, z.core.$strict>, z.ZodObject<{
724
794
  kind: z.ZodLiteral<"connector">;
725
795
  connectorId: z.ZodString;
726
796
  tools: z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodArray<z.ZodString>]>;
727
- }, z.core.$strict>], "kind">, unknown>>>;
797
+ }, z.core.$strict>], "kind">>>;
798
+ subagentTools: z.ZodOptional<z.ZodObject<{
799
+ allow: z.ZodOptional<z.ZodArray<z.ZodString>>;
800
+ deny: z.ZodOptional<z.ZodArray<z.ZodString>>;
801
+ }, z.core.$strict>>;
728
802
  toolPolicies: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodEnum<{
729
803
  ask: "ask";
730
804
  deny: "deny";