@capybara-hq/kernel 0.1.0-rc.65 → 0.1.0-rc.67

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 (177) hide show
  1. package/bootstrap.json +0 -8
  2. package/dist/admin/admin.schemas.d.ts +3 -0
  3. package/dist/agents/admin-agents.d.ts +2 -2
  4. package/dist/agents/admin-agents.js +2 -1
  5. package/dist/agents/agent-lookup.js +2 -1
  6. package/dist/agents/agent-profile.service.d.ts +5 -2
  7. package/dist/agents/agent-profile.service.js +13 -2
  8. package/dist/agents/agents.controller.d.ts +4 -3
  9. package/dist/agents/agents.controller.js +7 -3
  10. package/dist/agents/agents.module.js +3 -0
  11. package/dist/agents/agents.schemas.d.ts +6 -6
  12. package/dist/agents/agents.service.d.ts +23 -2
  13. package/dist/agents/agents.service.js +61 -6
  14. package/dist/agents/avatar-view.d.ts +8 -0
  15. package/dist/agents/avatar-view.js +12 -0
  16. package/dist/agents/profile.d.ts +38 -13
  17. package/dist/agents/profile.js +31 -20
  18. package/dist/attribution/platform-attribution.d.ts +15 -6
  19. package/dist/attribution/platform-attribution.js +31 -14
  20. package/dist/background/poll.job.d.ts +1 -1
  21. package/dist/background/poll.job.js +8 -6
  22. package/dist/background/tasks.service.js +1 -1
  23. package/dist/catalog/catalog-content.d.ts +6 -3
  24. package/dist/catalog/catalog-content.js +7 -8
  25. package/dist/catalog/claude/translate.js +1 -1
  26. package/dist/catalog/marketplaces.service.d.ts +1 -1
  27. package/dist/catalog/marketplaces.service.js +2 -1
  28. package/dist/catalog/plugin-package.d.ts +3 -2
  29. package/dist/channels/file-delivery.d.ts +2 -0
  30. package/dist/channels/file-delivery.js +1 -1
  31. package/dist/channels/inbound.d.ts +8 -4
  32. package/dist/channels/inbound.js +14 -7
  33. package/dist/channels/outbound.js +11 -5
  34. package/dist/channels/phrases.d.ts +21 -13
  35. package/dist/channels/phrases.js +21 -14
  36. package/dist/client/client-files.js +1 -1
  37. package/dist/config/product-name.d.ts +8 -0
  38. package/dist/config/product-name.js +9 -0
  39. package/dist/config/schema.d.ts +1 -0
  40. package/dist/config/schema.js +17 -4
  41. package/dist/conversations/conversations.service.d.ts +4 -3
  42. package/dist/conversations/conversations.service.js +15 -2
  43. package/dist/ctx/create-ctx.js +5 -2
  44. package/dist/ctx/device-provider-check.d.ts +7 -0
  45. package/dist/ctx/device-provider-check.js +21 -0
  46. package/dist/db/kernel-schema.d.ts +7 -0
  47. package/dist/devices/access.d.ts +16 -46
  48. package/dist/devices/access.js +26 -62
  49. package/dist/devices/access.module.js +2 -2
  50. package/dist/devices/conversation-devices.d.ts +38 -18
  51. package/dist/devices/conversation-devices.js +69 -51
  52. package/dist/devices/default-provider-setting.d.ts +45 -0
  53. package/dist/devices/default-provider-setting.js +59 -0
  54. package/dist/devices/device-projects.service.js +7 -2
  55. package/dist/devices/device-provider-selection.d.ts +37 -0
  56. package/dist/devices/device-provider-selection.js +86 -0
  57. package/dist/devices/device-provider-selection.module.d.ts +3 -0
  58. package/dist/devices/device-provider-selection.module.js +22 -0
  59. package/dist/devices/devices.controller.d.ts +8 -5
  60. package/dist/devices/devices.controller.js +7 -4
  61. package/dist/devices/devices.module.js +3 -1
  62. package/dist/devices/devices.schemas.js +2 -2
  63. package/dist/devices/devices.service.d.ts +72 -83
  64. package/dist/devices/devices.service.js +139 -248
  65. package/dist/devices/dto.d.ts +9 -0
  66. package/dist/devices/dto.js +15 -2
  67. package/dist/devices/label.d.ts +3 -5
  68. package/dist/devices/label.js +3 -14
  69. package/dist/devices/legacy-cleanup.job.d.ts +2 -2
  70. package/dist/devices/legacy-cleanup.job.js +6 -6
  71. package/dist/errors.d.ts +15 -1
  72. package/dist/errors.js +15 -1
  73. package/dist/extensions/guide-places.d.ts +2 -1
  74. package/dist/extensions/guide-places.js +8 -2
  75. package/dist/extensions/locks.d.ts +1 -1
  76. package/dist/extensions/locks.js +1 -1
  77. package/dist/extensions/org-config.d.ts +20 -4
  78. package/dist/extensions/org-config.js +23 -6
  79. package/dist/extensions/permission-view.d.ts +2 -2
  80. package/dist/extensions/permission-view.js +2 -2
  81. package/dist/extensions/plugin-guides.d.ts +1 -1
  82. package/dist/extensions/plugin-guides.js +11 -3
  83. package/dist/extensions/point-defaults.d.ts +14 -0
  84. package/dist/extensions/point-defaults.js +70 -47
  85. package/dist/extensions/resolve.js +7 -2
  86. package/dist/git/gateway.d.ts +9 -0
  87. package/dist/git/gateway.js +36 -17
  88. package/dist/git/gateway.route.d.ts +1 -1
  89. package/dist/git/gateway.route.js +1 -3
  90. package/dist/http/app.d.ts +1 -1
  91. package/dist/identity/app-auth.d.ts +4 -3
  92. package/dist/identity/app-auth.js +7 -8
  93. package/dist/identity/settings.d.ts +8 -0
  94. package/dist/identity/settings.js +30 -3
  95. package/dist/identity/sso.d.ts +13 -7
  96. package/dist/identity/sso.js +21 -7
  97. package/dist/infra/config/kernel-config.service.js +3 -1
  98. package/dist/lifecycle/kernel-lifecycle.js +7 -6
  99. package/dist/local-devices/device-routes.d.ts +1 -1
  100. package/dist/local-devices/device-routes.js +2 -2
  101. package/dist/local-devices/local-device-provider.d.ts +14 -11
  102. package/dist/local-devices/local-device-provider.js +14 -0
  103. package/dist/local-devices/local-devices.module.d.ts +4 -4
  104. package/dist/local-devices/local-devices.module.js +5 -3
  105. package/dist/local-devices/owner-report.js +2 -1
  106. package/dist/local-devices/targets.d.ts +2 -0
  107. package/dist/local-devices/targets.js +10 -0
  108. package/dist/orgs/offboarding.js +9 -0
  109. package/dist/orgs/settings.service.d.ts +26 -1
  110. package/dist/orgs/settings.service.js +44 -3
  111. package/dist/platform/ops/admin.ops.js +8 -3
  112. package/dist/platform/ops/agents.ops.d.ts +6 -1
  113. package/dist/platform/ops/agents.ops.js +38 -11
  114. package/dist/platform/ops/devices.ops.js +25 -20
  115. package/dist/platform/ops/orgs.ops.js +1 -0
  116. package/dist/platform/ops/platform-icons.ops.js +4 -4
  117. package/dist/platform/ops/platform.ops.js +2 -1
  118. package/dist/platform/ops/themes.ops.js +1 -1
  119. package/dist/runtime/plugin-context.service.js +1 -12
  120. package/dist/sandbox/cloud-permission-snapshot.d.ts +2 -2
  121. package/dist/sandbox/cloud-permission-snapshot.js +3 -3
  122. package/dist/sandbox/device-reports.d.ts +50 -0
  123. package/dist/sandbox/device-reports.js +157 -0
  124. package/dist/sandbox/held-operations.d.ts +8 -8
  125. package/dist/sandbox/leases.d.ts +1 -1
  126. package/dist/sandbox/leases.js +1 -1
  127. package/dist/sandbox/operation-authority.d.ts +5 -2
  128. package/dist/sandbox/operation-authority.js +12 -11
  129. package/dist/sandbox/operation-reconcile.job.d.ts +2 -2
  130. package/dist/sandbox/operation-reconcile.job.js +5 -5
  131. package/dist/sandbox/permission-availability.d.ts +2 -2
  132. package/dist/sandbox/permission-call-types.d.ts +5 -0
  133. package/dist/sandbox/permission-facts.d.ts +2 -2
  134. package/dist/sandbox/permission-facts.js +5 -5
  135. package/dist/sandbox/providers.d.ts +23 -24
  136. package/dist/sandbox/providers.js +38 -46
  137. package/dist/sandbox/providers.module.js +3 -3
  138. package/dist/sandbox/review/classifier.d.ts +6 -0
  139. package/dist/sandbox/review/classifier.js +12 -1
  140. package/dist/sandbox/review/index.d.ts +1 -1
  141. package/dist/sandbox/review/index.js +1 -1
  142. package/dist/sandbox/sandbox.module.d.ts +1 -1
  143. package/dist/sandbox/sandbox.module.js +7 -2
  144. package/dist/sandbox/sandbox.service.d.ts +95 -68
  145. package/dist/sandbox/sandbox.service.js +212 -208
  146. package/dist/setup/setup-guides.service.d.ts +4 -1
  147. package/dist/setup/setup-guides.service.js +6 -1
  148. package/dist/themes/avatar-preset-key.d.ts +6 -0
  149. package/dist/themes/avatar-preset-key.js +9 -0
  150. package/dist/themes/platform-icon.service.js +1 -1
  151. package/dist/themes/theme-delivery.service.d.ts +10 -2
  152. package/dist/themes/theme-delivery.service.js +26 -11
  153. package/dist/themes/theme-state.d.ts +43 -2
  154. package/dist/themes/theme-state.js +61 -4
  155. package/dist/themes/themes-public.controller.d.ts +3 -3
  156. package/dist/themes/themes-public.controller.js +3 -3
  157. package/dist/themes/themes.service.d.ts +28 -1
  158. package/dist/themes/themes.service.js +36 -2
  159. package/dist/tools/builtins/image/generate.d.ts +3 -0
  160. package/dist/tools/builtins/image/generate.js +21 -11
  161. package/dist/tools/builtins/image/index.d.ts +1 -1
  162. package/dist/tools/builtins/image/index.js +1 -1
  163. package/dist/tools/builtins/platform.js +25 -17
  164. package/dist/tools/builtins/sandbox/common.d.ts +37 -13
  165. package/dist/tools/builtins/sandbox/common.js +63 -19
  166. package/dist/tools/builtins/sandbox/read.d.ts +5 -2
  167. package/dist/tools/builtins/sandbox/read.js +9 -6
  168. package/dist/tools/builtins/sandbox/task-output.d.ts +2 -2
  169. package/dist/tools/builtins/sandbox/task-output.js +6 -5
  170. package/dist/tools/builtins/skill-load.js +13 -4
  171. package/dist/tools/connectors.service.js +2 -1
  172. package/dist/tools/oauth/discovery.d.ts +2 -0
  173. package/dist/tools/oauth/discovery.js +3 -1
  174. package/dist/until-aborted.d.ts +5 -0
  175. package/dist/until-aborted.js +16 -0
  176. package/package.json +4 -4
  177. package/src/migrations/0176_device_report.sql +6 -0
@@ -2,6 +2,7 @@
2
2
  * 机器人在 IM 里说的固定话术(全部集中在这里,zh / en 同步). Chosen per recipient (run context spec
3
3
  * §3.4): the sender's platform language, else their latest web language, else the org's.
4
4
  * 模型回复不经过这里,原样转换为 IM 富文本、不翻译。
5
+ * `{product}` is the platform name (`platform.name`): {@link phrase} requires it for those phrases.
5
6
  */
6
7
  export const CHANNEL_PHRASES = {
7
8
  /** 私聊 `/new` 之后。 */
@@ -23,10 +24,10 @@ export const CHANNEL_PHRASES = {
23
24
  },
24
25
  /** `/device <name>` names an existing device that is unavailable now (`{list}` as in deviceList). */
25
26
  deviceUnavailable: {
26
- zh: "设备「{name}」当前不可用(它的文件由未启用的沙箱提供方保存)。你的设备:\n{list}",
27
- en: "The device \u201c{name}\u201d is unavailable: its files are kept by a sandbox provider that is not active. Your devices:\n{list}",
27
+ zh: "设备「{name}」当前不可用(它的设备提供方在该组织未启用或未安装,文件仍保留)。你的设备:\n{list}",
28
+ en: "The device \u201c{name}\u201d is unavailable: its device provider is off in this organization or not installed (its files are kept). Your devices:\n{list}",
28
29
  },
29
- /** Direct message `/device` when the person has no usable device (no cloud sandbox in the deployment). */
30
+ /** Direct message `/device` when the person has no usable device (no device provider on in the org). */
30
31
  deviceNone: {
31
32
  zh: "你目前没有可用的设备。",
32
33
  en: "You have no usable devices.",
@@ -35,13 +36,13 @@ export const CHANNEL_PHRASES = {
35
36
  deviceCurrent: { zh: "(当前)", en: " (current)" },
36
37
  /** 未绑定的人在私聊里发消息:附绑定卡片。 */
37
38
  bindPrompt: {
38
- zh: "请先绑定你的 Capybara 账号,再与我对话。",
39
- en: "Please link your Capybara account before chatting with me.",
39
+ zh: "请先绑定你的 {product} 账号,再与我对话。",
40
+ en: "Please link your {product} account before chatting with me.",
40
41
  },
41
42
  /** 未绑定的人在群里 @ 机器人:绑定链接只在私聊里发(群里谁都能点)。 */
42
43
  bindInDm: {
43
- zh: "请先私聊我,绑定你的 Capybara 账号。",
44
- en: "Please send me a direct message to link your Capybara account first.",
44
+ zh: "请先私聊我,绑定你的 {product} 账号。",
45
+ en: "Please send me a direct message to link your {product} account first.",
45
46
  },
46
47
  /** 无法生成绑定链接(部署未配置 http.publicUrl)。 */
47
48
  bindUnavailable: {
@@ -186,8 +187,8 @@ export const CHANNEL_PHRASES = {
186
187
  },
187
188
  /** 部署未配置 http.publicUrl,无法给出网页链接与卡片时的退回文本。 */
188
189
  handleOnWeb: {
189
- zh: "有一条请求需要你到 Capybara 网页上处理。",
190
- en: "A request is waiting for you in Capybara on the web.",
190
+ zh: "有一条请求需要你到 {product} 网页上处理。",
191
+ en: "A request is waiting for you in {product} on the web.",
191
192
  },
192
193
  /**
193
194
  * Phase D: `/name args` named an invocable skill, but the kernel refused to render it
@@ -237,8 +238,8 @@ export const CHANNEL_PHRASES = {
237
238
  },
238
239
  /** The same without a web link (no public base URL configured). */
239
240
  fileOnWebNoLink: {
240
- zh: "{name}({size})已交付,请在网页上打开 Capybara 中的这个会话获取。",
241
- en: "{name} ({size}) was delivered; open the conversation in Capybara on the web to get it.",
241
+ zh: "{name}({size})已交付,请在网页上打开 {product} 中的这个会话获取。",
242
+ en: "{name} ({size}) was delivered; open the conversation in {product} on the web to get it.",
242
243
  },
243
244
  /**
244
245
  * The root message of a native file delivery (a scheduled group run's first post); `{name}` is
@@ -254,7 +255,13 @@ export const CHANNEL_PHRASES = {
254
255
  en: "Sorry, something went wrong. Please try again later.",
255
256
  },
256
257
  };
257
- /** 取一条话术。 */
258
- export function phrase(key, locale) {
259
- return CHANNEL_PHRASES[key][locale];
258
+ /**
259
+ * One phrase in `locale`. A phrase that names the platform takes its name (`productName(config)`,
260
+ * read at each use: `platform.name` is hot), which replaces `{product}`.
261
+ */
262
+ export function phrase(key, locale, ...product) {
263
+ const text = CHANNEL_PHRASES[key][locale];
264
+ const name = product[0];
265
+ // a function replacement: `$&` in a name is text, not a pattern
266
+ return name === undefined ? text : text.replaceAll("{product}", () => name);
260
267
  }
@@ -78,7 +78,7 @@ export function checkClientFiles(section, files) {
78
78
  }
79
79
  if (section.apiVersion > CLIENT_API_VERSION) {
80
80
  throw new ApiError("client.api_unsupported", `The plugin's client code was built for client API ${section.apiVersion}; this deployment ` +
81
- `supports ${CLIENT_API_VERSION}. Upgrade Capybara, or build the plugin against ` +
81
+ `supports ${CLIENT_API_VERSION}. Upgrade the platform, or build the plugin against ` +
82
82
  `@capybara-hq/plugin-client for client API ${CLIENT_API_VERSION}.`, [{ apiVersion: section.apiVersion, supported: CLIENT_API_VERSION }]);
83
83
  }
84
84
  const styles = section.styles ?? [];
@@ -0,0 +1,8 @@
1
+ import type { KernelConfig } from "./schema.js";
2
+ /** The product name when the deployment sets no `platform.name`. */
3
+ export declare const DEFAULT_PRODUCT_NAME = "Capybara";
4
+ /**
5
+ * The name people see for this deployment (`platform.name`, else {@link DEFAULT_PRODUCT_NAME}).
6
+ * `platform.name` is hot: read it per use, never cache it.
7
+ */
8
+ export declare function productName(config: Pick<KernelConfig, "platform">): string;
@@ -0,0 +1,9 @@
1
+ /** The product name when the deployment sets no `platform.name`. */
2
+ export const DEFAULT_PRODUCT_NAME = "Capybara";
3
+ /**
4
+ * The name people see for this deployment (`platform.name`, else {@link DEFAULT_PRODUCT_NAME}).
5
+ * `platform.name` is hot: read it per use, never cache it.
6
+ */
7
+ export function productName(config) {
8
+ return config.platform.name ?? DEFAULT_PRODUCT_NAME;
9
+ }
@@ -283,6 +283,7 @@ export declare const KernelConfigSchema: z.ZodObject<{
283
283
  allowed: "allowed";
284
284
  off: "off";
285
285
  }>>;
286
+ defaultProvider: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>>;
286
287
  network: z.ZodPrefault<z.ZodObject<{
287
288
  default: z.ZodOptional<z.ZodEnum<{
288
289
  allowlist: "allowlist";
@@ -1,5 +1,5 @@
1
1
  import { isIP } from "node:net";
2
- import { CATALOG_ITEM_NAME_RE, DOCUMENT_MEDIA_TYPES, IMAGE_MEDIA_TYPES, validateAllowHost, } from "@capybara-hq/plugin-sdk";
2
+ import { CATALOG_ITEM_NAME_RE, DOCUMENT_MEDIA_TYPES, EXTENSION_NAME_RE, IMAGE_MEDIA_TYPES, validateAllowHost, } from "@capybara-hq/plugin-sdk";
3
3
  import { z } from "zod";
4
4
  import { LOG_FORMATS, LOG_LEVELS } from "../log.js";
5
5
  import { noProxyEntryProblem, proxyUrlProblem } from "../net/proxy.js";
@@ -315,7 +315,7 @@ export const KernelConfigSchema = z.strictObject({
315
315
  .optional()
316
316
  .meta(meta({
317
317
  hot: true,
318
- description: "The platform's display name (1 to 64 characters), shown by native clients and the installed web app before sign-in (GET /api/v1/meta); unset: clients show their own name",
318
+ description: "The platform's display name (1 to 64 characters): the product name people see in the web app, the installed web app and native clients (GET /api/v1/meta), IM bot replies, git gateway messages, OAuth client registrations and the attribution defaults; unset: Capybara",
319
319
  })),
320
320
  })
321
321
  .prefault({}),
@@ -1343,7 +1343,7 @@ export const KernelConfigSchema = z.strictObject({
1343
1343
  .optional()
1344
1344
  .meta(meta({
1345
1345
  hot: true,
1346
- description: "The trailer an agent ends the message of a git commit it creates with; an empty string turns it off. Overridable per agent; unset follows the admin console's value, else 'Co-Authored-By: Capybara <noreply@capybarahq.com>'",
1346
+ description: "The trailer an agent ends the message of a git commit it creates with; an empty string turns it off. Overridable per agent; unset follows the admin console's value, else 'Co-Authored-By: <platform.name> <noreply@capybarahq.com>'",
1347
1347
  })),
1348
1348
  pr: z
1349
1349
  .string()
@@ -1352,7 +1352,7 @@ export const KernelConfigSchema = z.strictObject({
1352
1352
  .optional()
1353
1353
  .meta(meta({
1354
1354
  hot: true,
1355
- description: "The line an agent ends the body of a pull request it opens with; an empty string turns it off. Overridable per agent; unset follows the admin console's value, else '🤖 Generated with [Capybara](https://github.com/capybara-hq/core)'",
1355
+ description: "The line an agent ends the body of a pull request it opens with; an empty string turns it off. Overridable per agent; unset follows the admin console's value, else '🤖 Generated with [Capybara](https://github.com/capybara-hq/core)' ('🤖 Generated with <platform.name>' when platform.name is set to another name)",
1356
1356
  })),
1357
1357
  sessionUrl: z
1358
1358
  .boolean()
@@ -1659,6 +1659,19 @@ export const KernelConfigSchema = z.strictObject({
1659
1659
  hot: true,
1660
1660
  description: "Whether a device may be granted running a call outside its sandbox (default allowed): a person, the review model or Auto then approves such an escalation per call, within the organization's and the device owner's settings; off refuses every escalation, and devices only run in their sandbox. An organization may turn it off and follow the platform. Set here, it is read-only in the admin console. Replaces devices.fullAccess (CAPYBARA_DEVICES__FULL_ACCESS) and devices.autoMode, which are refused: rename them (the same values; off also needs devices.network.ceiling: allowlist to keep devices on the allowlist), or convert a config file with capybara config migrate-permissions",
1661
1661
  })),
1662
+ /**
1663
+ * The device provider that makes a person's default device (several `device-provider@1`
1664
+ * extensions may coexist). Also a deployment setting the super admin changes in the admin
1665
+ * console (`devicesDefaultProvider`); the startup config wins over it, so this field is
1666
+ * optional with no schema default. An empty string means none. An org may override it.
1667
+ */
1668
+ defaultProvider: z
1669
+ .union([z.literal(""), z.string().regex(EXTENSION_NAME_RE)])
1670
+ .optional()
1671
+ .meta(meta({
1672
+ hot: true,
1673
+ description: "The name of the device provider extension that makes a person's default device, needed with a single device provider too (default none: nobody gets a default device, and creating a device needs an explicit provider). An empty string means none. An organization may choose another provider that is on in it. Set here, it is read-only in the admin console",
1674
+ })),
1662
1675
  /**
1663
1676
  * The platform's device sandbox network (approval-only profiles design, "Settings model"):
1664
1677
  * the default mode and the widest mode an org or device may choose, `open` (the public
@@ -1,7 +1,7 @@
1
1
  import type { ConversationSource } from "@capybara-hq/plugin-sdk";
2
2
  import { AgentLookup } from "../agents/agent-lookup.js";
3
3
  import type { ModelRef } from "../agents/definition.js";
4
- import type { AgentAvatar } from "../agents/profile.js";
4
+ import type { AgentAvatarView } from "../agents/profile.js";
5
5
  import type { TitleSource } from "../db/kernel-schema.js";
6
6
  import { ConversationDevices, type NewConversationDevice } from "../devices/conversation-devices.js";
7
7
  import { DeviceProjectsService } from "../devices/device-projects.service.js";
@@ -97,7 +97,7 @@ export interface ConversationGroup {
97
97
  id: string;
98
98
  name: string;
99
99
  profile: {
100
- avatar: AgentAvatar;
100
+ avatar: AgentAvatarView;
101
101
  updatedAt: string;
102
102
  };
103
103
  };
@@ -371,7 +371,8 @@ export declare class ConversationsService {
371
371
  * checks the owner and the device's current mode (refused with `device.not_found`,
372
372
  * `device.projects_unsupported`, `device.project_not_found` or `device.project_outside_mode`).
373
373
  * Called inside the transaction that writes the conversation. A conversation without a device
374
- * (no cloud provider, an anonymous IM sender) cannot have one. Undefined name: free mode.
374
+ * (no default device provider on in the org, an anonymous IM sender) cannot have one. Undefined
375
+ * name: free mode.
375
376
  */
376
377
  private bindingFor;
377
378
  /**
@@ -11,6 +11,7 @@ import { randomUUID } from "node:crypto";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { sql } from "kysely";
13
13
  import { AgentLookup, visibleTo } from "../agents/agent-lookup.js";
14
+ import { avatarView } from "../agents/avatar-view.js";
14
15
  import { unbindConversation } from "../channels/threads.js";
15
16
  import { ConversationDevices, } from "../devices/conversation-devices.js";
16
17
  import { DeviceProjectsService } from "../devices/device-projects.service.js";
@@ -344,7 +345,8 @@ let ConversationsService = class ConversationsService {
344
345
  * checks the owner and the device's current mode (refused with `device.not_found`,
345
346
  * `device.projects_unsupported`, `device.project_not_found` or `device.project_outside_mode`).
346
347
  * Called inside the transaction that writes the conversation. A conversation without a device
347
- * (no cloud provider, an anonymous IM sender) cannot have one. Undefined name: free mode.
348
+ * (no default device provider on in the org, an anonymous IM sender) cannot have one. Undefined
349
+ * name: free mode.
348
350
  */
349
351
  async bindingFor(orgId, accountId, deviceId, name) {
350
352
  if (name === undefined)
@@ -676,7 +678,7 @@ let ConversationsService = class ConversationsService {
676
678
  id: r.agent_id,
677
679
  name: r.agent_name ?? "",
678
680
  profile: {
679
- avatar: r.profile_avatar,
681
+ avatar: avatarView(r.profile_avatar),
680
682
  updatedAt: r.profile_updated_at.toISOString(),
681
683
  },
682
684
  },
@@ -1287,6 +1289,17 @@ let ConversationsService = class ConversationsService {
1287
1289
  // terminal transaction
1288
1290
  await this.holdTree(conversationId);
1289
1291
  await runs.requestAbort(run.id, accountId);
1292
+ // the suspend handshake (`WaitsService.suspend`): a run that became `waiting` after the read
1293
+ // above may have checked the marker before it was set and ended its job, so nobody hears the
1294
+ // broadcast; check `waiting` again after setting the marker and end it as a waiting run
1295
+ const now = await this.db
1296
+ .selectFrom("runs")
1297
+ .select("status")
1298
+ .where("id", "=", run.id)
1299
+ .executeTakeFirst();
1300
+ if (now?.status === "waiting" && (await runs.abortWaiting(conversationId, run.id, accountId))) {
1301
+ await runs.ensureRunAfterCommit(conversationId);
1302
+ }
1290
1303
  return run.id;
1291
1304
  }
1292
1305
  };
@@ -1,4 +1,4 @@
1
- import { EXTENSION_POINTS, ExtensionPermissionError, ExtensionPointUnavailableError, FILE_PREVIEW_EXTENSION_POINT, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, resolveUiSlots, SETUP_CHECK_ID_RE, SETUP_GUIDE_PLACES, validateFilePreviewProvider, validateToolSpec, } from "@capybara-hq/plugin-sdk";
1
+ import { DEVICE_PROVIDER_EXTENSION_POINT, EXTENSION_POINTS, ExtensionPermissionError, ExtensionPointUnavailableError, FILE_PREVIEW_EXTENSION_POINT, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, resolveUiSlots, SETUP_CHECK_ID_RE, SETUP_GUIDE_PLACES, validateFilePreviewProvider, validateToolSpec, } from "@capybara-hq/plugin-sdk";
2
2
  import { Command, ConnectionBuilder, ControlledTransactionBuilder, Kysely, TransactionBuilder, } from "kysely";
3
3
  import { conversationTopic } from "../conversations/event-log.js";
4
4
  import { kernelDb } from "../db/kernel-schema.js";
@@ -10,6 +10,7 @@ import { audit } from "../identity/audit.js";
10
10
  import { PrefixedStorage } from "../storage/storage.service.js";
11
11
  import { canUseSlot, orgUiTopic, PLATFORM_UI_TOPIC, PluginUiRegistration, } from "../ui/registry.js";
12
12
  import { createBus } from "./bus.js";
13
+ import { checkDeviceProvider } from "./device-provider-check.js";
13
14
  import { createKv } from "./kv.js";
14
15
  import { createLock } from "./lock.js";
15
16
  import { createExtensionNet } from "./net.js";
@@ -658,7 +659,9 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
658
659
  }
659
660
  const served = extensionPoint === FILE_PREVIEW_EXTENSION_POINT
660
661
  ? checkFilePreviewProvider(manifest, impl, uiResolution, deps.log)
661
- : impl;
662
+ : extensionPoint === DEVICE_PROVIDER_EXTENSION_POINT
663
+ ? checkDeviceProvider(name, impl)
664
+ : impl;
662
665
  provided.set(extensionPoint, served);
663
666
  ledger.add({
664
667
  kind: "provide",
@@ -0,0 +1,7 @@
1
+ import type { DeviceProvider } from "@capybara-hq/plugin-sdk";
2
+ /**
3
+ * Checks a plugin's `device-provider@1` implementation when it is provided: the declarations
4
+ * (`networkAllowlist`, `concurrentExec`) must be `true` and the required methods must exist. A
5
+ * failure fails the plugin's setup, so it never loads.
6
+ */
7
+ export declare function checkDeviceProvider(plugin: string, impl: unknown): DeviceProvider;
@@ -0,0 +1,21 @@
1
+ const REQUIRED_FUNCTIONS = ["report", "killTagged", "exec", "create", "createFileSystem"];
2
+ /**
3
+ * Checks a plugin's `device-provider@1` implementation when it is provided: the declarations
4
+ * (`networkAllowlist`, `concurrentExec`) must be `true` and the required methods must exist. A
5
+ * failure fails the plugin's setup, so it never loads.
6
+ */
7
+ export function checkDeviceProvider(plugin, impl) {
8
+ const p = (impl ?? {});
9
+ const need = (member) => {
10
+ throw new Error(`plugin ${plugin}: device-provider@1 requires ${member}`);
11
+ };
12
+ if (p.networkAllowlist !== true)
13
+ need("networkAllowlist");
14
+ if (p.concurrentExec !== true)
15
+ need("concurrentExec");
16
+ for (const m of REQUIRED_FUNCTIONS) {
17
+ if (typeof p[m] !== "function")
18
+ need(m);
19
+ }
20
+ return impl;
21
+ }
@@ -1139,6 +1139,13 @@ export interface DevicesTable {
1139
1139
  network_mode: ColumnType<"open" | "allowlist" | "none" | null, "open" | "allowlist" | "none" | null | undefined, "open" | "allowlist" | "none" | null>;
1140
1140
  /** 0165: a cloud device's allowlist hosts (a JSON array), used while the mode is `allowlist`. */
1141
1141
  network_hosts: ColumnType<string[], string | undefined, string>;
1142
+ /**
1143
+ * 0176: what the device's provider last reported (a `DeviceReport` as JSON; read back through
1144
+ * `parseDeviceReport`, see `DeviceReports`); null until the first create or resume stores one.
1145
+ */
1146
+ report: ColumnType<unknown, string | null | undefined, string | null>;
1147
+ /** 0176: when {@link report} was stored. */
1148
+ report_at: TsNullable;
1142
1149
  created_at: Ts;
1143
1150
  updated_at: Ts;
1144
1151
  deleted_at: TsNullable;
@@ -1,49 +1,16 @@
1
1
  import { ApiError } from "../errors.js";
2
2
  import { KernelDb } from "../infra/database/kernel-db.js";
3
- import { SandboxProviders } from "../sandbox/providers.js";
4
- /** What decides a device's provider: its own record and its instance row's (if any). */
5
- export interface ProviderFacts {
6
- /** `devices.provider`: the provider current when it was created. */
7
- provider: string | null;
8
- /** `device_instances.provider`; null without an instance row. */
9
- instanceProvider: string | null;
10
- /** The instance row's `fs_status`; null without an instance row. */
11
- fsStatus: "none" | "ready" | "lost" | null;
12
- /** The instance row records an instance handle. */
13
- hasInstance: boolean;
14
- }
15
- /**
16
- * The provider a device works with: a kernel-internal one (`@local`) as recorded; for a
17
- * cloud device the one keeping its files or instance once it has any (they are never
18
- * migrated, spec §4.2 item 13); before that, the current cloud provider (its first use creates
19
- * them there), else the one recorded at creation. The same rule as `SandboxService`'s use.
20
- */
21
- export declare function deviceProvider(f: ProviderFacts, current: string | undefined): string | null;
22
- /** It has files or an instance at some provider (a file system, even a lost one, or a handle). */
23
- export declare const holdsResources: (f: ProviderFacts) => boolean;
24
- /** `device_instances.status`. */
25
- export type InstanceStatus = "none" | "creating" | "running" | "suspended" | "destroyed";
3
+ import { DeviceProviderSelection } from "./device-provider-selection.js";
26
4
  /**
27
- * For replacing a default (which one is the person's default): it holds healthy files or an
28
- * instance, or an instance row is under way (`creating`, `running`, `suspended`: a first use may
29
- * be creating the instance before any file system or handle is recorded). Lost files count as
30
- * none here, unlike {@link holdsResources}, which decides the provider.
5
+ * The device's provider is off in its org or not installed, or the device has none (503). Its
6
+ * files and instance are kept: nothing is demoted, recreated or moved to another provider.
31
7
  */
32
- export declare const inUseForDefault: (f: ProviderFacts & {
33
- status: InstanceStatus | null;
34
- }) => boolean;
35
- /**
36
- * The provider a former default belongs to (its label and the provider whose switch back restores
37
- * it): the one holding its resources once it holds any, else the one it was demoted from (the
38
- * marker). A former default demoted while empty and used afterwards keeps a stale marker; its
39
- * resources decide. null for a device that is not a former default.
40
- */
41
- export declare function demotedProvider(marker: string | null, f: ProviderFacts): string | null;
8
+ export declare const deviceUnavailable: (provider: string | null) => ApiError;
42
9
  /**
43
- * The device's provider is not the current one, or there is no provider (503); for an
44
- * internal provider (`@local`), this kernel does not serve it.
10
+ * The device's instance row names another provider than the device's own (503): never written by
11
+ * this kernel (a device is bound to its provider for life), so nothing is taken over.
45
12
  */
46
- export declare const deviceUnavailable: (provider: string | null) => ApiError;
13
+ export declare const deviceInstanceForeign: (provider: string, instanceProvider: string) => ApiError;
47
14
  /**
48
15
  * Who may use a device (spec §4.2 item 12): in phase 1 only the owner of a personal
49
16
  * device. Anyone else gets `device.not_found`, never `forbidden`, so ids cannot be
@@ -51,16 +18,19 @@ export declare const deviceUnavailable: (provider: string | null) => ApiError;
51
18
  */
52
19
  export declare class DeviceAccess {
53
20
  private readonly db;
54
- private readonly providers;
55
- constructor(db: KernelDb, providers: Pick<SandboxProviders, "cloud" | "forName">);
21
+ private readonly selection;
22
+ constructor(db: KernelDb, selection: Pick<DeviceProviderSelection, "isOnInOrg">);
56
23
  /**
57
24
  * The device if `accountId` may use it in `orgId` now: `device.not_found` when it is
58
- * missing, deleted, in another org or someone else's; `device.unavailable` when its
59
- * provider is not the current one (or there is none). A local device is usable while
60
- * `@local` is registered: whether its machine is online is the relay's concern, not access.
25
+ * missing, deleted, in another org or someone else's; `device.unavailable` when it has no
26
+ * provider, its provider (`devices.provider`, fixed at creation) does not serve the org now
27
+ * ({@link DeviceProviderSelection.isOnInOrg}: off in the org, not installed, invalid config;
28
+ * `@local` not registered), or its instance row names another provider (never written by this
29
+ * kernel). A local device is usable while `@local` is registered: whether its machine is online
30
+ * is the relay's concern, not access.
61
31
  */
62
32
  usable(orgId: string, accountId: string, deviceId: string): Promise<{
63
33
  id: string;
64
- provider: string | null;
34
+ provider: string;
65
35
  }>;
66
36
  }
@@ -10,52 +10,20 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { Inject, Injectable } from "@nestjs/common";
11
11
  import { ApiError } from "../errors.js";
12
12
  import { KernelDb } from "../infra/database/kernel-db.js";
13
- import { isInternalProvider, SandboxProviders } from "../sandbox/providers.js";
13
+ import { DeviceProviderSelection } from "./device-provider-selection.js";
14
14
  import { deviceNotFound } from "./errors.js";
15
15
  /**
16
- * The provider a device works with: a kernel-internal one (`@local`) as recorded; for a
17
- * cloud device the one keeping its files or instance once it has any (they are never
18
- * migrated, spec §4.2 item 13); before that, the current cloud provider (its first use creates
19
- * them there), else the one recorded at creation. The same rule as `SandboxService`'s use.
16
+ * The device's provider is off in its org or not installed, or the device has none (503). Its
17
+ * files and instance are kept: nothing is demoted, recreated or moved to another provider.
20
18
  */
21
- export function deviceProvider(f, current) {
22
- if (f.provider !== null && isInternalProvider(f.provider))
23
- return f.provider;
24
- if (holdsResources(f))
25
- return f.instanceProvider;
26
- return current ?? f.provider;
27
- }
28
- /** It has files or an instance at some provider (a file system, even a lost one, or a handle). */
29
- export const holdsResources = (f) => f.fsStatus !== null && (f.fsStatus !== "none" || f.hasInstance);
30
- /**
31
- * For replacing a default (which one is the person's default): it holds healthy files or an
32
- * instance, or an instance row is under way (`creating`, `running`, `suspended`: a first use may
33
- * be creating the instance before any file system or handle is recorded). Lost files count as
34
- * none here, unlike {@link holdsResources}, which decides the provider.
35
- */
36
- export const inUseForDefault = (f) => f.fsStatus === "ready" ||
37
- f.hasInstance ||
38
- (f.status !== null && f.status !== "none" && f.status !== "destroyed");
39
- /**
40
- * The provider a former default belongs to (its label and the provider whose switch back restores
41
- * it): the one holding its resources once it holds any, else the one it was demoted from (the
42
- * marker). A former default demoted while empty and used afterwards keeps a stale marker; its
43
- * resources decide. null for a device that is not a former default.
44
- */
45
- export function demotedProvider(marker, f) {
46
- if (marker === null)
47
- return null;
48
- return (holdsResources(f) ? f.instanceProvider : null) ?? marker;
49
- }
19
+ export const deviceUnavailable = (provider) => new ApiError("device.unavailable", provider === null
20
+ ? "This device has no provider; delete it and create a new one"
21
+ : `This device's provider ${provider} is off in this organization or not installed; its files are kept, and the device works again once an org admin switches the provider back on`);
50
22
  /**
51
- * The device's provider is not the current one, or there is no provider (503); for an
52
- * internal provider (`@local`), this kernel does not serve it.
23
+ * The device's instance row names another provider than the device's own (503): never written by
24
+ * this kernel (a device is bound to its provider for life), so nothing is taken over.
53
25
  */
54
- export const deviceUnavailable = (provider) => new ApiError("device.unavailable", provider === null
55
- ? "No cloud sandbox is available in this deployment; ask the super admin to enable a sandbox plugin"
56
- : isInternalProvider(provider)
57
- ? `This device runs on a connected machine (${provider}), which this deployment does not serve`
58
- : `This device is kept by the sandbox provider ${provider}, which is not the current provider; it can be used again once ${provider} is the deployment's sandbox provider`);
26
+ export const deviceInstanceForeign = (provider, instanceProvider) => new ApiError("device.unavailable", `This device's provider is ${provider}, but its instance was made by ${instanceProvider}; it cannot be used as it is: delete it and create a new one`);
59
27
  /**
60
28
  * Who may use a device (spec §4.2 item 12): in phase 1 only the owner of a personal
61
29
  * device. Anyone else gets `device.not_found`, never `forbidden`, so ids cannot be
@@ -63,22 +31,25 @@ export const deviceUnavailable = (provider) => new ApiError("device.unavailable"
63
31
  */
64
32
  let DeviceAccess = class DeviceAccess {
65
33
  db;
66
- providers;
67
- constructor(db, providers) {
34
+ selection;
35
+ constructor(db, selection) {
68
36
  this.db = db;
69
- this.providers = providers;
37
+ this.selection = selection;
70
38
  }
71
39
  /**
72
40
  * The device if `accountId` may use it in `orgId` now: `device.not_found` when it is
73
- * missing, deleted, in another org or someone else's; `device.unavailable` when its
74
- * provider is not the current one (or there is none). A local device is usable while
75
- * `@local` is registered: whether its machine is online is the relay's concern, not access.
41
+ * missing, deleted, in another org or someone else's; `device.unavailable` when it has no
42
+ * provider, its provider (`devices.provider`, fixed at creation) does not serve the org now
43
+ * ({@link DeviceProviderSelection.isOnInOrg}: off in the org, not installed, invalid config;
44
+ * `@local` not registered), or its instance row names another provider (never written by this
45
+ * kernel). A local device is usable while `@local` is registered: whether its machine is online
46
+ * is the relay's concern, not access.
76
47
  */
77
48
  async usable(orgId, accountId, deviceId) {
78
49
  const row = await this.db
79
50
  .selectFrom("devices as e")
80
51
  .leftJoin("device_instances as i", "i.device_id", "e.id")
81
- .select(["e.id", "e.provider", "i.provider as instance_provider", "i.fs_status", "i.handle"])
52
+ .select(["e.id", "e.provider", "i.provider as instance_provider"])
82
53
  .where("e.id", "=", deviceId)
83
54
  .where("e.org_id", "=", orgId)
84
55
  .where("e.owner_kind", "=", "personal")
@@ -87,20 +58,13 @@ let DeviceAccess = class DeviceAccess {
87
58
  .executeTakeFirst();
88
59
  if (!row)
89
60
  throw deviceNotFound();
90
- if (row.provider !== null && isInternalProvider(row.provider)) {
91
- if (this.providers.forName(row.provider) === undefined) {
92
- throw deviceUnavailable(row.provider);
93
- }
94
- return { id: row.id, provider: row.provider };
61
+ const provider = row.provider;
62
+ if (provider === null)
63
+ throw deviceUnavailable(null);
64
+ if (row.instance_provider !== null && row.instance_provider !== provider) {
65
+ throw deviceInstanceForeign(provider, row.instance_provider);
95
66
  }
96
- const current = this.providers.cloud()?.plugin;
97
- const provider = deviceProvider({
98
- provider: row.provider,
99
- instanceProvider: row.instance_provider,
100
- fsStatus: row.fs_status,
101
- hasInstance: row.handle !== null,
102
- }, current);
103
- if (current === undefined || provider !== current)
67
+ if (!(await this.selection.isOnInOrg(orgId, provider)))
104
68
  throw deviceUnavailable(provider);
105
69
  return { id: row.id, provider };
106
70
  }
@@ -108,6 +72,6 @@ let DeviceAccess = class DeviceAccess {
108
72
  DeviceAccess = __decorate([
109
73
  Injectable(),
110
74
  __param(0, Inject(KernelDb)),
111
- __param(1, Inject(SandboxProviders))
75
+ __param(1, Inject(DeviceProviderSelection))
112
76
  ], DeviceAccess);
113
77
  export { DeviceAccess };
@@ -5,13 +5,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { Module } from "@nestjs/common";
8
- import { SandboxProviderRegistryModule } from "../sandbox/providers.module.js";
9
8
  import { DeviceAccess } from "./access.js";
9
+ import { DeviceProviderSelectionModule } from "./device-provider-selection.module.js";
10
10
  let DeviceAccessModule = class DeviceAccessModule {
11
11
  };
12
12
  DeviceAccessModule = __decorate([
13
13
  Module({
14
- imports: [SandboxProviderRegistryModule],
14
+ imports: [DeviceProviderSelectionModule],
15
15
  providers: [DeviceAccess],
16
16
  exports: [DeviceAccess],
17
17
  })