@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
@@ -84,7 +84,10 @@ export declare const setupWebPath: {
84
84
  memberConnections: () => string;
85
85
  template: (itemId: string) => string;
86
86
  };
87
- /** The blocks of a rendered guide as one Markdown document (checks as `- [check <id>]` lines). */
87
+ /**
88
+ * The blocks of a rendered guide as one Markdown document (checks as `- [check <id>]` lines, shell
89
+ * actions as `- [shell action <action>]` lines).
90
+ */
88
91
  export declare function guideMarkdown(title: string, blocks: readonly SetupGuideBlock[]): string;
89
92
  /**
90
93
  * The setup guides of an org as a person sees them (spec 2026-11-09-setup-guides-v2-design.md §12:
@@ -45,7 +45,10 @@ function fenceFor(text) {
45
45
  const longest = Math.max(0, ...[...text.matchAll(/`+/g)].map((m) => m[0].length));
46
46
  return "`".repeat(Math.max(3, longest + 1));
47
47
  }
48
- /** The blocks of a rendered guide as one Markdown document (checks as `- [check <id>]` lines). */
48
+ /**
49
+ * The blocks of a rendered guide as one Markdown document (checks as `- [check <id>]` lines, shell
50
+ * actions as `- [shell action <action>]` lines).
51
+ */
49
52
  export function guideMarkdown(title, blocks) {
50
53
  const parts = [`# ${title}`];
51
54
  for (const b of blocks) {
@@ -53,6 +56,8 @@ export function guideMarkdown(title, blocks) {
53
56
  parts.push(b.text.trimEnd());
54
57
  else if (b.kind === "check")
55
58
  parts.push(`- [check ${b.id}] ${b.label}`);
59
+ else if (b.kind === "shell-action")
60
+ parts.push(`- [shell action ${b.action}] ${b.label}`);
56
61
  else {
57
62
  const fence = fenceFor(b.text);
58
63
  const code = `${fence}${b.language}\n${b.text.replace(/\n$/, "")}\n${fence}`;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A theme avatar preset's key (theme brand coverage spec §4): `<plugin>/<theme file id>/<preset
3
+ * id>`, the plugin and theme ids as catalog item names, the preset id as {@link THEME_AVATAR_ID_RE}.
4
+ * A leaf module (SDK only): the themes and the agents both read it.
5
+ */
6
+ export declare const THEME_PRESET_KEY_RE: RegExp;
@@ -0,0 +1,9 @@
1
+ import { CATALOG_ITEM_NAME_RE, THEME_AVATAR_ID_RE } from "@capybara-hq/plugin-sdk";
2
+ /** A pattern's source without its `^` / `$` anchors. */
3
+ const body = (re) => re.source.replace(/^\^/, "").replace(/\$$/, "");
4
+ /**
5
+ * A theme avatar preset's key (theme brand coverage spec §4): `<plugin>/<theme file id>/<preset
6
+ * id>`, the plugin and theme ids as catalog item names, the preset id as {@link THEME_AVATAR_ID_RE}.
7
+ * A leaf module (SDK only): the themes and the agents both read it.
8
+ */
9
+ export const THEME_PRESET_KEY_RE = new RegExp(`^${body(CATALOG_ITEM_NAME_RE)}/${body(CATALOG_ITEM_NAME_RE)}/${body(THEME_AVATAR_ID_RE)}$`);
@@ -254,7 +254,7 @@ let PlatformIconService = class PlatformIconService {
254
254
  .where("purpose", "=", purpose)
255
255
  .executeTakeFirst();
256
256
  const notFound = () => new ApiError("platform_icon.not_found", v === undefined || row === undefined
257
- ? `No ${purpose} icon is uploaded; the built-in Capybara icon applies`
257
+ ? `No ${purpose} icon is uploaded; the built-in icon applies`
258
258
  : `The ${purpose} icon was replaced; read the current URL from the platform icon settings`);
259
259
  if (!row || (v !== undefined && v !== row.sha256))
260
260
  throw notFound();
@@ -1,6 +1,13 @@
1
+ import { type ParsedTheme } from "@capybara-hq/plugin-sdk";
1
2
  import { KernelDb } from "../infra/database/kernel-db.js";
2
3
  import type { KernelLogger } from "../log.js";
3
4
  import { StorageService } from "../storage/storage.service.js";
5
+ /**
6
+ * The asset paths a stored definition names ({@link themeAssetRefs}: fonts, logo files, avatar
7
+ * files), read defensively: the row is not re-parsed, so a field of the wrong shape names nothing
8
+ * rather than failing the request.
9
+ */
10
+ export declare function storedAssetRefs(def: ParsedTheme): string[];
4
11
  /** A theme asset's bytes and content type. */
5
12
  export interface ThemeAsset {
6
13
  contentType: string;
@@ -29,8 +36,9 @@ export declare class ThemeDeliveryService {
29
36
  stylesheet(id: string, version: string, revision: string): Promise<string>;
30
37
  /**
31
38
  * Asset `file` (a path inside the plugin, as stored: `fonts/MiSans.woff2`) of version `version`
32
- * of theme `id`: only a font or logo the version's definition names. Unknown theme, version or
33
- * file: 404 `theme.not_found`.
39
+ * of theme `id`: only a file the version's definition names ({@link themeAssetRefs}: fonts, logo
40
+ * files, avatar files), matched exactly against the stored path; never another file of the
41
+ * stored package. Unknown theme, version or file: 404 `theme.not_found`.
34
42
  */
35
43
  asset(id: string, version: string, file: string): Promise<ThemeAsset>;
36
44
  }
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
- import { isThemeAssetPath } from "@capybara-hq/plugin-sdk";
10
+ import { isThemeAssetPath, themeAssetRefs } from "@capybara-hq/plugin-sdk";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { ApiError } from "../errors.js";
13
13
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -20,12 +20,32 @@ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
20
20
  /** A version number as it appears in a delivery URL: a positive int4. */
21
21
  const VERSION_RE = /^[1-9]\d{0,9}$/;
22
22
  const INT4_MAX = 2_147_483_647;
23
- /** The content type of each asset kind a theme names (fonts and logos). */
23
+ /** The content type of each asset kind a theme names (fonts, logo and avatar files). */
24
24
  const ASSET_TYPES = [
25
25
  [/\.woff2$/i, "font/woff2"],
26
26
  [/\.svg$/i, "image/svg+xml"],
27
27
  [/\.png$/i, "image/png"],
28
28
  ];
29
+ /**
30
+ * The asset paths a stored definition names ({@link themeAssetRefs}: fonts, logo files, avatar
31
+ * files), read defensively: the row is not re-parsed, so a field of the wrong shape names nothing
32
+ * rather than failing the request.
33
+ */
34
+ export function storedAssetRefs(def) {
35
+ const isObject = (v) => v !== null && typeof v === "object";
36
+ if (!isObject(def))
37
+ return [];
38
+ const { fonts, logo, avatars, ...rest } = def;
39
+ const shaped = {
40
+ ...rest,
41
+ ...(Array.isArray(fonts) && { fonts: fonts.filter(isObject) }),
42
+ ...(isObject(logo) && { logo }),
43
+ ...(Array.isArray(avatars) && { avatars: avatars.filter(isObject) }),
44
+ };
45
+ return themeAssetRefs(shaped)
46
+ .map((r) => r.ref)
47
+ .filter((p) => typeof p === "string");
48
+ }
29
49
  /** 404 `theme.not_found`. */
30
50
  const notFound = (what) => new ApiError("theme.not_found", `${what} does not exist; reload the page to get the current theme`);
31
51
  /**
@@ -78,19 +98,14 @@ let ThemeDeliveryService = class ThemeDeliveryService {
78
98
  }
79
99
  /**
80
100
  * Asset `file` (a path inside the plugin, as stored: `fonts/MiSans.woff2`) of version `version`
81
- * of theme `id`: only a font or logo the version's definition names. Unknown theme, version or
82
- * file: 404 `theme.not_found`.
101
+ * of theme `id`: only a file the version's definition names ({@link themeAssetRefs}: fonts, logo
102
+ * files, avatar files), matched exactly against the stored path; never another file of the
103
+ * stored package. Unknown theme, version or file: 404 `theme.not_found`.
83
104
  */
84
105
  async asset(id, version, file) {
85
106
  const v = await this.version(id, version);
86
107
  const def = v.definition;
87
- const named = [
88
- ...(Array.isArray(def.fonts) ? def.fonts.map((f) => f?.file) : []),
89
- def.logo?.mark,
90
- def.logo?.favicon,
91
- ]
92
- .filter((p) => typeof p === "string")
93
- .map(packagePath);
108
+ const named = storedAssetRefs(def).map(packagePath);
94
109
  const type = ASSET_TYPES.find(([re]) => re.test(file))?.[1];
95
110
  if (v.objectPrefix === null ||
96
111
  type === undefined ||
@@ -1,4 +1,4 @@
1
- import { type LocalizedName, type ParsedTheme, type ThemeScheme } from "@capybara-hq/plugin-sdk";
1
+ import { type BuiltinAvatarPresetId, type LocalizedName, type ParsedTheme, type ThemeScheme } from "@capybara-hq/plugin-sdk";
2
2
  import { type ComponentRow } from "../catalog/component-state.js";
3
3
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
4
4
  import { ApiError } from "../errors.js";
@@ -18,12 +18,25 @@ export interface ThemeRef {
18
18
  schemes: ThemeScheme[];
19
19
  /** The only scheme of a single-scheme theme, else null. */
20
20
  singleScheme: ThemeScheme | null;
21
- /** null: the theme has no logo (the built-in mark and wordmark). */
21
+ /**
22
+ * null: the theme has no logo (the built-in mark and wordmark). Each URL is the asset's delivery
23
+ * URL ({@link themeUrl}), null when the theme does not name that file.
24
+ */
22
25
  logo: {
23
26
  markUrl: string | null;
24
27
  wordmark: string | null;
25
28
  faviconUrl: string | null;
29
+ illustrationUrl: string | null;
30
+ appIconUrl: string | null;
31
+ appIconMaskableUrl: string | null;
26
32
  } | null;
33
+ /** The background decoration of the sign-in pages (the theme file's `decoration`, default `dither`). */
34
+ decoration: "dither" | "none";
35
+ /**
36
+ * The merged `color.bg` of each scheme the theme defines (the theme's override, else the built-in
37
+ * value; canonical `#RRGGBB` / `rgba()`), computed at read from the stored definition.
38
+ */
39
+ background: Partial<Record<ThemeScheme, string>>;
27
40
  /** `/api/v1/themes/<id>/<version>/r<THEME_CSS_REVISION>/theme.css`. */
28
41
  cssUrl: string;
29
42
  }
@@ -55,6 +68,34 @@ export declare const THEME_CSS_REVISION = 2;
55
68
  * The one builder of these URLs: the listing, the stylesheet and the asset routes all use it.
56
69
  */
57
70
  export declare function themeUrl(id: string, version: string, asset?: string): string;
71
+ /** A theme avatar preset an org offers (theme brand coverage spec §4). */
72
+ export interface OrgAvatarPreset {
73
+ /** `<plugin>/<theme file id>/<preset id>` ({@link THEME_PRESET_KEY_RE}): what a client sends. */
74
+ key: string;
75
+ /** The theme file's name; a missing `zh` reads as `en`. */
76
+ name: LocalizedName;
77
+ /** The file's delivery URL ({@link themeUrl}; immutable, served after the theme changes). */
78
+ url: string;
79
+ /** What a stored `{ kind: "theme" }` avatar pins: theme, version, preset id and file path. */
80
+ themeId: string;
81
+ version: string;
82
+ preset: string;
83
+ file: string;
84
+ }
85
+ /** The avatar presets of an org's effective default theme: built-ins it hides, presets it adds. */
86
+ export interface OrgAvatars {
87
+ /** In the built-in order. */
88
+ hidden: BuiltinAvatarPresetId[];
89
+ /** In the theme file's order. */
90
+ presets: OrgAvatarPreset[];
91
+ }
92
+ /**
93
+ * The avatar presets of version `version` of theme `id` (spec §4). A stored definition is not
94
+ * re-parsed: entries outside the grammar (a preset whose file is not a theme asset path, an id
95
+ * that would not form a key, an unknown hidden id) are skipped. A row without provenance
96
+ * (`plugin` null) cannot form a key: it offers no presets, but its hidden list still applies.
97
+ */
98
+ export declare function themeAvatarPresets(id: string, version: string, def: ParsedTheme, plugin: string | null): OrgAvatars;
58
99
  /**
59
100
  * The {@link ThemeRef} of version `version` of theme `id` of plugin `plugin` (null only for a row
60
101
  * without provenance: the key is then the file id alone).
@@ -2,10 +2,11 @@
2
2
  // references the web reads, and the delivery URLs (§8). Plain functions in the caller's context (a
3
3
  // transaction's connection when there is one): the settings writers (deployment, org, person) and
4
4
  // `ThemesService` decide with the same predicates.
5
- import { mergeThemeSchemes, } from "@capybara-hq/plugin-sdk";
5
+ import { BUILTIN_AVATAR_PRESET_IDS, isThemeAssetPath, mergeThemeSchemes, } from "@capybara-hq/plugin-sdk";
6
6
  import { componentOn, listedIn, loadComponents, loadScopeState, pluginFactsOf, switchOf, } from "../catalog/component-state.js";
7
7
  import { ApiError } from "../errors.js";
8
8
  import { packagePath } from "../packages/tgz.js";
9
+ import { THEME_PRESET_KEY_RE } from "./avatar-preset-key.js";
9
10
  /** The schemes in the order they are listed. */
10
11
  const SCHEMES = ["dark", "light"];
11
12
  /**
@@ -30,12 +31,52 @@ export function themeUrl(id, version, asset) {
30
31
  ? `${base}/r${THEME_CSS_REVISION}/theme.css`
31
32
  : `${base}/assets/${encodeURIComponent(packagePath(asset))}`;
32
33
  }
34
+ /**
35
+ * The avatar presets of version `version` of theme `id` (spec §4). A stored definition is not
36
+ * re-parsed: entries outside the grammar (a preset whose file is not a theme asset path, an id
37
+ * that would not form a key, an unknown hidden id) are skipped. A row without provenance
38
+ * (`plugin` null) cannot form a key: it offers no presets, but its hidden list still applies.
39
+ */
40
+ export function themeAvatarPresets(id, version, def, plugin) {
41
+ const hide = def.hideAvatarPresets;
42
+ const hiddenSet = new Set(Array.isArray(hide) ? hide : []);
43
+ const hidden = BUILTIN_AVATAR_PRESET_IDS.filter((p) => hiddenSet.has(p));
44
+ const avatars = def.avatars;
45
+ const presets = [];
46
+ if (plugin !== null && Array.isArray(avatars)) {
47
+ for (const a of avatars) {
48
+ if (a === null || typeof a !== "object")
49
+ continue;
50
+ const { id: preset, name, file } = a;
51
+ if (typeof preset !== "string" || !isThemeAssetPath(file))
52
+ continue;
53
+ const key = `${plugin}/${def.id}/${preset}`;
54
+ if (!THEME_PRESET_KEY_RE.test(key) || name === null || typeof name !== "object")
55
+ continue;
56
+ const { en, zh } = name;
57
+ if (typeof en !== "string")
58
+ continue;
59
+ presets.push({
60
+ key,
61
+ name: { en, zh: typeof zh === "string" ? zh : en },
62
+ url: themeUrl(id, version, file),
63
+ themeId: id,
64
+ version,
65
+ preset,
66
+ file,
67
+ });
68
+ }
69
+ }
70
+ return { hidden, presets };
71
+ }
33
72
  /**
34
73
  * The {@link ThemeRef} of version `version` of theme `id` of plugin `plugin` (null only for a row
35
74
  * without provenance: the key is then the file id alone).
36
75
  */
37
76
  export function themeRefOf(id, version, def, plugin) {
38
- const url = (ref) => (ref === undefined ? null : themeUrl(id, version, ref));
77
+ // A stored definition is not re-parsed: a ref that is not a theme asset path gets no URL
78
+ const url = (ref) => (isThemeAssetPath(ref) ? themeUrl(id, version, ref) : null);
79
+ const logo = def.logo;
39
80
  return {
40
81
  id,
41
82
  key: plugin === null ? def.id : `${plugin}/${def.id}`,
@@ -43,16 +84,32 @@ export function themeRefOf(id, version, def, plugin) {
43
84
  name: def.name,
44
85
  schemes: SCHEMES.filter((s) => def.schemes[s] !== undefined),
45
86
  singleScheme: def.singleScheme,
46
- logo: def.logo === undefined
87
+ logo: def.logo === undefined || logo === null || typeof logo !== "object"
47
88
  ? null
48
89
  : {
49
90
  markUrl: url(def.logo.mark),
50
- wordmark: def.logo.wordmark ?? null,
91
+ wordmark: typeof def.logo.wordmark === "string" ? def.logo.wordmark : null,
51
92
  faviconUrl: url(def.logo.favicon),
93
+ illustrationUrl: url(def.logo.illustration),
94
+ appIconUrl: url(def.logo.appIcon),
95
+ appIconMaskableUrl: url(def.logo.appIconMaskable),
52
96
  },
97
+ decoration: def.decoration === "none" ? "none" : "dither",
98
+ background: themeBackground(def),
53
99
  cssUrl: themeUrl(id, version),
54
100
  };
55
101
  }
102
+ /** The merged `color.bg` of each scheme the theme defines ({@link ThemeRef.background}). */
103
+ function themeBackground(def) {
104
+ const out = {};
105
+ const merged = mergeThemeSchemes(def);
106
+ for (const s of SCHEMES) {
107
+ const bg = merged[s]?.color.bg;
108
+ if (def.schemes[s] !== undefined && bg !== undefined)
109
+ out[s] = bg;
110
+ }
111
+ return out;
112
+ }
56
113
  /**
57
114
  * The swatches of each scheme the theme defines: its overrides merged onto the current built-in
58
115
  * values (a stored definition holds only the theme file's own values, themes spec §6).
@@ -18,9 +18,9 @@ export declare class ThemeDeliveryController {
18
18
  */
19
19
  css(id: string, version: string, revision: string, reply: FastifyReply): Promise<void>;
20
20
  /**
21
- * A font (`font/woff2`) or logo (`image/svg+xml`, sanitized at import, served under a CSP
22
- * sandbox; `image/png`) the version names; `file` is its plugin path as one segment
23
- * (`fonts%2FMiSans.woff2`).
21
+ * A font (`font/woff2`), logo file (mark, favicon, illustration, app icons) or avatar file
22
+ * (`image/svg+xml`, sanitized at import, served under a CSP sandbox; `image/png`) the version
23
+ * names; `file` is its plugin path as one segment (`fonts%2FMiSans.woff2`).
24
24
  */
25
25
  asset(id: string, version: string, file: string, reply: FastifyReply): Promise<void>;
26
26
  }
@@ -38,9 +38,9 @@ let ThemeDeliveryController = class ThemeDeliveryController {
38
38
  .send(css);
39
39
  }
40
40
  /**
41
- * A font (`font/woff2`) or logo (`image/svg+xml`, sanitized at import, served under a CSP
42
- * sandbox; `image/png`) the version names; `file` is its plugin path as one segment
43
- * (`fonts%2FMiSans.woff2`).
41
+ * A font (`font/woff2`), logo file (mark, favicon, illustration, app icons) or avatar file
42
+ * (`image/svg+xml`, sanitized at import, served under a CSP sandbox; `image/png`) the version
43
+ * names; `file` is its plugin path as one segment (`fonts%2FMiSans.woff2`).
44
44
  */
45
45
  async asset(id, version, file, reply) {
46
46
  const a = await this.delivery.asset(id, version, file);
@@ -1,6 +1,6 @@
1
1
  import type { LocalizedName } from "@capybara-hq/plugin-sdk";
2
2
  import { KernelDb } from "../infra/database/kernel-db.js";
3
- import { type ListedTheme, type ThemeRef } from "./theme-state.js";
3
+ import { type ListedTheme, type OrgAvatars, type ThemeDefinition, type ThemeRef } from "./theme-state.js";
4
4
  /** `GET /api/v1/orgs/:orgId/themes` (themes spec §9). */
5
5
  export interface OrgThemes {
6
6
  /** The themes on in the org, by English name. */
@@ -16,6 +16,19 @@ export interface OrgThemes {
16
16
  id: string | null;
17
17
  personal: "allowed" | "locked";
18
18
  };
19
+ /**
20
+ * The agent avatar presets of the org's effective default theme ({@link ThemesService.avatarPresets};
21
+ * the same for every member, never the viewer's pick): the built-ins it hides and the presets it
22
+ * adds, whose `key` an avatar input sends as its preset id.
23
+ */
24
+ avatars: {
25
+ hidden: string[];
26
+ presets: {
27
+ key: string;
28
+ name: LocalizedName;
29
+ url: string;
30
+ }[];
31
+ };
19
32
  }
20
33
  /**
21
34
  * Which theme applies (themes spec §7) and the org's theme listing. Read-only; the levels are
@@ -41,6 +54,20 @@ export declare class ThemesService {
41
54
  * snapshot: a change committed between them shows at the next read.
42
55
  */
43
56
  forOrg(orgId: string, accountId: string | null): Promise<OrgThemes>;
57
+ /**
58
+ * The org's effective default theme (theme brand coverage spec §4): the org's default if it is
59
+ * on in the org, else the platform default if it is on in the org, else null. The same
60
+ * predicates as {@link forOrg} without the personal pick: what every member of the org shares.
61
+ */
62
+ orgDefault(orgId: string): Promise<(ThemeDefinition & {
63
+ id: string;
64
+ }) | null>;
65
+ /**
66
+ * The agent avatar presets of the org's effective default theme ({@link orgDefault}): the
67
+ * built-ins it hides and the presets it adds, each with what a stored avatar pins. No default
68
+ * theme in effect: nothing hidden, no presets.
69
+ */
70
+ avatarPresets(orgId: string): Promise<OrgAvatars>;
44
71
  /** A live theme's name (the super admin's summaries); null when there is no such theme. */
45
72
  nameOf(id: string): Promise<LocalizedName | null>;
46
73
  /** Theme `id`'s name if it is on in the org, else null (a summary never names another org's theme). */
@@ -11,7 +11,7 @@ import { Inject, Injectable } from "@nestjs/common";
11
11
  import { readUiTheme } from "../identity/settings.js";
12
12
  import { KernelDb } from "../infra/database/kernel-db.js";
13
13
  import { DEFAULT_ORG_THEME, readOrgSettings } from "../orgs/settings.service.js";
14
- import { eligiblePlatformDefault, themeDefinitions, themeOnForAccount, themeOnIn, themeRefOf, themeSwatches, themesOnIn, } from "./theme-state.js";
14
+ import { eligiblePlatformDefault, themeAvatarPresets, themeDefinitions, themeOnForAccount, themeOnIn, themeRefOf, themeSwatches, themesOnIn, } from "./theme-state.js";
15
15
  /**
16
16
  * Which theme applies (themes spec §7) and the org's theme listing. Read-only; the levels are
17
17
  * written by their settings services (deployment, org, person), which check availability with the
@@ -77,7 +77,41 @@ let ThemesService = class ThemesService {
77
77
  const { swatches: _swatches, ...ref } = hit;
78
78
  resolved = ref;
79
79
  }
80
- return { themes, resolved, org: { id: org.id, personal: org.personal } };
80
+ const { hidden, presets } = await this.avatarPresets(orgId);
81
+ return {
82
+ themes,
83
+ resolved,
84
+ org: { id: org.id, personal: org.personal },
85
+ avatars: { hidden, presets: presets.map(({ key, name, url }) => ({ key, name, url })) },
86
+ };
87
+ }
88
+ /**
89
+ * The org's effective default theme (theme brand coverage spec §4): the org's default if it is
90
+ * on in the org, else the platform default if it is on in the org, else null. The same
91
+ * predicates as {@link forOrg} without the personal pick: what every member of the org shares.
92
+ */
93
+ async orgDefault(orgId) {
94
+ const org = (await readOrgSettings(this.db.db, orgId)).theme ?? DEFAULT_ORG_THEME;
95
+ const platform = (await readUiTheme(this.db.db)).id;
96
+ for (const id of [org.id, platform]) {
97
+ if (id === null || !(await themeOnIn(this.db.db, orgId, id)))
98
+ continue;
99
+ const d = (await themeDefinitions(this.db.db, [id])).get(id);
100
+ if (d)
101
+ return { id, ...d };
102
+ }
103
+ return null;
104
+ }
105
+ /**
106
+ * The agent avatar presets of the org's effective default theme ({@link orgDefault}): the
107
+ * built-ins it hides and the presets it adds, each with what a stored avatar pins. No default
108
+ * theme in effect: nothing hidden, no presets.
109
+ */
110
+ async avatarPresets(orgId) {
111
+ const d = await this.orgDefault(orgId);
112
+ return d
113
+ ? themeAvatarPresets(d.id, d.version, d.definition, d.plugin)
114
+ : { hidden: [], presets: [] };
81
115
  }
82
116
  /** A live theme's name (the super admin's summaries); null when there is no such theme. */
83
117
  async nameOf(id) {
@@ -1,6 +1,7 @@
1
1
  import { type ImageMediaType, type Logger, type ToolSpec } from "@capybara-hq/plugin-sdk";
2
2
  import type { AttachmentsService } from "../../../conversations/attachments.service.js";
3
3
  import type { EventLog } from "../../../conversations/event-log.js";
4
+ import type { DeviceUnusableReason } from "../../../devices/conversation-devices.js";
4
5
  import type { KernelConfigService } from "../../../infra/config/kernel-config.service.js";
5
6
  import type { KernelDb } from "../../../infra/database/kernel-db.js";
6
7
  import { type ImageInputCaps } from "../../../models/image-usable.js";
@@ -23,6 +24,8 @@ export declare const NO_IMAGE_MODEL_TEXT = "No image model is configured for thi
23
24
  export declare const GENERATE_IMAGE_DENIED_TEXT = "An org policy blocked this image request; continue without it or ask the user.";
24
25
  /** The device line of a call whose conversation has no device to write to. */
25
26
  export declare const NO_DEVICE_LINE = "Not written to the device: this conversation has no device.";
27
+ /** The device line of each reason a conversation's device cannot be used ({@link DeviceUnusableReason}). */
28
+ export declare const DEVICE_UNUSABLE_LINE: Record<DeviceUnusableReason, string>;
26
29
  /** What the `GenerateImage` builtin needs (everything read per call: no process state). */
27
30
  export interface GenerateImageDeps {
28
31
  images: Pick<ModelImages, "prepare" | "run">;
@@ -8,7 +8,7 @@ import { appendCounted } from "../../../runtime/model-call.js";
8
8
  import { ProviderListError } from "../../../runtime/providers.js";
9
9
  import { NO_STORAGE, NO_STORAGE_REASON, REPEAT_CLAUSE, storeArtifacts, } from "../artifacts.js";
10
10
  import { findConversationFile } from "../conversation-files.js";
11
- import { checkFilePathShape, checkToolWritable, clip, display, inToolSandbox, sandboxConversationOf, sandboxUsable, withNotices, withPathLease, } from "../sandbox/common.js";
11
+ import { checkFilePathShape, checkToolWritable, clip, display, inToolSandbox, sandboxConversationOf, sandboxUnusableReason, withNotices, withPathLease, } from "../sandbox/common.js";
12
12
  import { assertReadAndUnchanged, FileGuardError, fileStateOf } from "../sandbox/file-state.js";
13
13
  import { READ_MAX_BYTES } from "../sandbox/read.js";
14
14
  import { sizeText } from "../size-text.js";
@@ -138,6 +138,12 @@ const modifiedText = (path) => `${clip(path, 200)} has changed since this conver
138
138
  const vanishedText = (path) => `${clip(path, 200)} disappeared while it was being written; retry the call.`;
139
139
  /** The device line of a call whose conversation has no device to write to. */
140
140
  export const NO_DEVICE_LINE = "Not written to the device: this conversation has no device.";
141
+ /** The device line of each reason a conversation's device cannot be used ({@link DeviceUnusableReason}). */
142
+ export const DEVICE_UNUSABLE_LINE = {
143
+ "provider-off": "Not written to the device: this conversation's device runs on a device provider that is off in this organization or not installed; its files are kept.",
144
+ "no-device": NO_DEVICE_LINE,
145
+ none: "Not written to the device: no device provider is on in this organization.",
146
+ };
141
147
  /** The file extension of each image media type. */
142
148
  const EXTENSIONS = {
143
149
  "image/png": "png",
@@ -447,8 +453,9 @@ async function recordDenial(deps, ctx, runId, verdict) {
447
453
  async function copyToDevice(deps, ctx, filePath, files) {
448
454
  const sb = deps.sandbox;
449
455
  const conv = sandboxConversationOf(ctx);
450
- if (!(await hasDevice(sb, ctx.orgId, conv)))
451
- return { line: NO_DEVICE_LINE, notices: [] };
456
+ const noDevice = await noDeviceLine(sb, ctx.orgId, conv);
457
+ if (noDevice !== null)
458
+ return { line: noDevice, notices: [] };
452
459
  const targets = generateImagePaths({ file_path: filePath, n: files.length });
453
460
  // the paths written so far (a rebuilt instance runs the copy again from the start)
454
461
  let written = [];
@@ -535,21 +542,24 @@ const MEDIA_EXTENSIONS = {
535
542
  "image/webp": ["webp"],
536
543
  };
537
544
  /**
538
- * Whether the conversation tree has a device to write to: a provider it can run on, and a device
539
- * its owner has (an anonymous IM sender or a deployment without a cloud provider has none).
545
+ * The device line when the conversation tree has no device to write to, or null when it has one:
546
+ * why its device cannot be used ({@link DEVICE_UNUSABLE_LINE}: its provider is off, no device to
547
+ * bind, no provider on), or {@link NO_DEVICE_LINE} when binding one finds none (an anonymous IM
548
+ * sender has none).
540
549
  */
541
- async function hasDevice(sb, orgId, conv) {
542
- if (!(await sandboxUsable(sb, orgId, conv)))
543
- return false;
550
+ async function noDeviceLine(sb, orgId, conv) {
551
+ const reason = await sandboxUnusableReason(sb, orgId, conv);
552
+ if (reason !== null)
553
+ return DEVICE_UNUSABLE_LINE[reason];
544
554
  try {
545
555
  await sb.devices.forTool(orgId, conv);
546
- return true;
556
+ return null;
547
557
  }
548
558
  catch (e) {
549
559
  if (e instanceof ApiError && e.code === "sandbox.unavailable")
550
- return false;
560
+ return NO_DEVICE_LINE;
551
561
  // any other refusal (a gone or forbidden device) is reported by the copy itself
552
- return true;
562
+ return null;
553
563
  }
554
564
  }
555
565
  /** The model-visible result (spec §5.3): what was generated, delivered or repeated, billing, the device copy. */
@@ -1,2 +1,2 @@
1
- export { GENERATE_IMAGE_DENIED_TEXT, GENERATE_IMAGE_SPEC, type GenerateImageDeps, generateImageTool, NO_DEVICE_LINE, NO_IMAGE_MODEL_REASON, NO_IMAGE_MODEL_TEXT, } from "./generate.js";
1
+ export { DEVICE_UNUSABLE_LINE, GENERATE_IMAGE_DENIED_TEXT, GENERATE_IMAGE_SPEC, type GenerateImageDeps, generateImageTool, NO_DEVICE_LINE, NO_IMAGE_MODEL_REASON, NO_IMAGE_MODEL_TEXT, } from "./generate.js";
2
2
  export { generateImagePaths, suffixedPath } from "./paths.js";
@@ -1,2 +1,2 @@
1
- export { GENERATE_IMAGE_DENIED_TEXT, GENERATE_IMAGE_SPEC, generateImageTool, NO_DEVICE_LINE, NO_IMAGE_MODEL_REASON, NO_IMAGE_MODEL_TEXT, } from "./generate.js";
1
+ export { DEVICE_UNUSABLE_LINE, GENERATE_IMAGE_DENIED_TEXT, GENERATE_IMAGE_SPEC, generateImageTool, NO_DEVICE_LINE, NO_IMAGE_MODEL_REASON, NO_IMAGE_MODEL_TEXT, } from "./generate.js";
2
2
  export { generateImagePaths, suffixedPath } from "./paths.js";
@@ -5,7 +5,7 @@ import { availability, PLATFORM_UNAVAILABLE_OFF, } from "../../platform/availabi
5
5
  import { errorRoleOf, errorsFor, nextStepFor, OPERATION_ERROR_NEXT, resolveNext, sentence, toToolError, } from "../../platform/errors.js";
6
6
  import { FILE_CHANGED_TEXT, fileCardDetail, } from "../../platform/file-ref.js";
7
7
  import { PLATFORM_METHOD } from "../../platform/method.js";
8
- import { OPERATION_ID, operationDomain, PRECHECK_TIMEOUT_MS, } from "../../platform/operation.js";
8
+ import { OPERATION_ID, operationDomain, PLATFORM_DOMAINS, PRECHECK_TIMEOUT_MS, } from "../../platform/operation.js";
9
9
  import { PersonFieldsRefused, planPersonFields, } from "../../platform/person-fields.js";
10
10
  import { SealedInputsExpiredError } from "../../platform/sealed-inputs.js";
11
11
  import { BUILTIN } from "../builtin-names.js";
@@ -42,16 +42,12 @@ export const LIST_MAX = 50;
42
42
  /** The most operations `search` returns. */
43
43
  const SEARCH_MAX = 20;
44
44
  const ACTIONS = ["browse", "search", "describe", "call", "read"];
45
- const SPEC = {
46
- name: BUILTIN.Platform,
47
- description: "Discover and use the platform's own operations (agents, skills, templates, plugins, " +
48
- "connectors, extensions, conversations, devices, models, evals, channels, requests, " +
49
- "approvals and the inbox, org settings, and for admins accounts, orgs and the admin console) " +
50
- 'and its documentation, as the person you are working for. Start with action "browse", which ' +
51
- 'lists every domain; "describe" gives an operation\'s input schema and an example. ' +
52
- 'Writes ask the person to confirm. Use "read" for how-to documentation (plugin ' +
53
- "format, skills, extension points).",
54
- inputSchema: {
45
+ /**
46
+ * The input schema. `domain` is an enum of the registered domain ids, so the model picks a real id
47
+ * from the schema instead of guessing one (`browseDomain` still refuses an unknown id).
48
+ */
49
+ function platformInputSchema(domainIds) {
50
+ return {
55
51
  type: "object",
56
52
  properties: {
57
53
  action: {
@@ -64,8 +60,8 @@ const SPEC = {
64
60
  },
65
61
  domain: {
66
62
  type: "string",
67
- maxLength: 100,
68
- description: 'For browse: a domain id from the browse result, e.g. "skills".',
63
+ enum: [...domainIds],
64
+ description: "For browse: the domain whose operations to list.",
69
65
  },
70
66
  query: {
71
67
  type: "string",
@@ -90,9 +86,8 @@ const SPEC = {
90
86
  },
91
87
  required: ["action"],
92
88
  additionalProperties: false,
93
- },
94
- keyArgs: ["action", "operation", "domain"],
95
- };
89
+ };
90
+ }
96
91
  const json = (value, summary) => ({
97
92
  content: [{ type: "text", text: JSON.stringify(value) }],
98
93
  display: { summary },
@@ -318,6 +313,19 @@ const factsCtx = (ctx) => ({
318
313
  runId: ctx.runId ?? null,
319
314
  });
320
315
  export function platformTool(deps) {
316
+ const spec = {
317
+ name: BUILTIN.Platform,
318
+ description: "Discover and use the platform's own operations (agents, skills, templates, plugins, " +
319
+ "connectors, extensions, conversations, devices, models, evals, channels, requests, " +
320
+ "approvals and the inbox, org settings, and for admins accounts, orgs and the admin console) " +
321
+ 'and its documentation, as the person you are working for. Start with action "browse", which ' +
322
+ 'lists every domain; "describe" gives an operation\'s input schema and an example. ' +
323
+ "Writes may need approval, depending on the conversation's permission profile. Use " +
324
+ '"read" for how-to documentation (plugin format, skills, extension points).',
325
+ // the fixed domain list, the same on every replica and in every org
326
+ inputSchema: platformInputSchema(PLATFORM_DOMAINS.map((d) => d.id)),
327
+ keyArgs: ["action", "operation", "domain"],
328
+ };
321
329
  const facts = (ctx) => deps.actor.facts(ctx);
322
330
  async function callPolicy(raw, ctx) {
323
331
  const input = raw;
@@ -615,7 +623,7 @@ export function platformTool(deps) {
615
623
  };
616
624
  }
617
625
  return {
618
- spec: SPEC,
626
+ spec,
619
627
  defaultPolicy: "allow",
620
628
  run,
621
629
  callPolicy,