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

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 (54) hide show
  1. package/dist/attribution/platform-attribution.d.ts +15 -6
  2. package/dist/attribution/platform-attribution.js +31 -14
  3. package/dist/catalog/catalog-content.d.ts +6 -3
  4. package/dist/catalog/catalog-content.js +7 -8
  5. package/dist/catalog/claude/translate.js +1 -1
  6. package/dist/catalog/marketplaces.service.d.ts +1 -1
  7. package/dist/catalog/marketplaces.service.js +2 -1
  8. package/dist/catalog/plugin-package.d.ts +3 -2
  9. package/dist/channels/file-delivery.d.ts +2 -0
  10. package/dist/channels/file-delivery.js +1 -1
  11. package/dist/channels/inbound.d.ts +6 -1
  12. package/dist/channels/inbound.js +12 -4
  13. package/dist/channels/outbound.js +11 -5
  14. package/dist/channels/phrases.d.ts +18 -10
  15. package/dist/channels/phrases.js +18 -11
  16. package/dist/client/client-files.js +1 -1
  17. package/dist/config/product-name.d.ts +8 -0
  18. package/dist/config/product-name.js +9 -0
  19. package/dist/config/schema.js +3 -3
  20. package/dist/conversations/conversations.service.js +11 -0
  21. package/dist/git/gateway.d.ts +9 -0
  22. package/dist/git/gateway.js +36 -17
  23. package/dist/git/gateway.route.d.ts +1 -1
  24. package/dist/git/gateway.route.js +1 -3
  25. package/dist/http/app.d.ts +1 -1
  26. package/dist/identity/app-auth.d.ts +4 -3
  27. package/dist/identity/app-auth.js +7 -8
  28. package/dist/identity/settings.js +6 -2
  29. package/dist/identity/sso.d.ts +13 -7
  30. package/dist/identity/sso.js +21 -7
  31. package/dist/infra/config/kernel-config.service.js +1 -1
  32. package/dist/local-devices/device-routes.js +1 -1
  33. package/dist/orgs/offboarding.js +9 -0
  34. package/dist/platform/ops/platform-icons.ops.js +4 -4
  35. package/dist/platform/ops/platform.ops.js +2 -1
  36. package/dist/platform/ops/themes.ops.js +1 -1
  37. package/dist/sandbox/review/classifier.d.ts +6 -0
  38. package/dist/sandbox/review/classifier.js +12 -1
  39. package/dist/sandbox/review/index.d.ts +1 -1
  40. package/dist/sandbox/review/index.js +1 -1
  41. package/dist/themes/platform-icon.service.js +1 -1
  42. package/dist/themes/theme-delivery.service.d.ts +10 -2
  43. package/dist/themes/theme-delivery.service.js +26 -11
  44. package/dist/themes/theme-state.d.ts +14 -1
  45. package/dist/themes/theme-state.js +22 -4
  46. package/dist/themes/themes-public.controller.d.ts +3 -3
  47. package/dist/themes/themes-public.controller.js +3 -3
  48. package/dist/tools/builtins/platform.js +25 -17
  49. package/dist/tools/builtins/sandbox/common.d.ts +1 -1
  50. package/dist/tools/builtins/sandbox/common.js +1 -1
  51. package/dist/tools/connectors.service.js +2 -1
  52. package/dist/tools/oauth/discovery.d.ts +2 -0
  53. package/dist/tools/oauth/discovery.js +3 -1
  54. package/package.json +4 -4
@@ -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 ||
@@ -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
  }
@@ -2,7 +2,7 @@
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 { 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";
@@ -35,7 +35,9 @@ export function themeUrl(id, version, asset) {
35
35
  * without provenance: the key is then the file id alone).
36
36
  */
37
37
  export function themeRefOf(id, version, def, plugin) {
38
- const url = (ref) => (ref === undefined ? null : themeUrl(id, version, ref));
38
+ // A stored definition is not re-parsed: a ref that is not a theme asset path gets no URL
39
+ const url = (ref) => (isThemeAssetPath(ref) ? themeUrl(id, version, ref) : null);
40
+ const logo = def.logo;
39
41
  return {
40
42
  id,
41
43
  key: plugin === null ? def.id : `${plugin}/${def.id}`,
@@ -43,16 +45,32 @@ export function themeRefOf(id, version, def, plugin) {
43
45
  name: def.name,
44
46
  schemes: SCHEMES.filter((s) => def.schemes[s] !== undefined),
45
47
  singleScheme: def.singleScheme,
46
- logo: def.logo === undefined
48
+ logo: def.logo === undefined || logo === null || typeof logo !== "object"
47
49
  ? null
48
50
  : {
49
51
  markUrl: url(def.logo.mark),
50
- wordmark: def.logo.wordmark ?? null,
52
+ wordmark: typeof def.logo.wordmark === "string" ? def.logo.wordmark : null,
51
53
  faviconUrl: url(def.logo.favicon),
54
+ illustrationUrl: url(def.logo.illustration),
55
+ appIconUrl: url(def.logo.appIcon),
56
+ appIconMaskableUrl: url(def.logo.appIconMaskable),
52
57
  },
58
+ decoration: def.decoration === "none" ? "none" : "dither",
59
+ background: themeBackground(def),
53
60
  cssUrl: themeUrl(id, version),
54
61
  };
55
62
  }
63
+ /** The merged `color.bg` of each scheme the theme defines ({@link ThemeRef.background}). */
64
+ function themeBackground(def) {
65
+ const out = {};
66
+ const merged = mergeThemeSchemes(def);
67
+ for (const s of SCHEMES) {
68
+ const bg = merged[s]?.color.bg;
69
+ if (def.schemes[s] !== undefined && bg !== undefined)
70
+ out[s] = bg;
71
+ }
72
+ return out;
73
+ }
56
74
  /**
57
75
  * The swatches of each scheme the theme defines: its overrides merged onto the current built-in
58
76
  * 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);
@@ -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,
@@ -286,7 +286,7 @@ export declare function admissionUnavailableText(cause: PermissionAvailabilityCa
286
286
  * sends scopes it validated, so this is a kernel invariant break (or a skewed device), never the
287
287
  * model's doing; whether anything ran is not proven.
288
288
  */
289
- export declare const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in Capybara itself, not in the request. Tell the user the device rejected the operation and that it should be reported; do not retry it unchanged.";
289
+ export declare const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in the platform itself, not in the request. Tell the user the device rejected the operation and that it should be reported; do not retry it unchanged.";
290
290
  /**
291
291
  * A device request whose machine came back as a new run of capybara-device before answering
292
292
  * (`DeviceProgramRestartedError`, also as the cause of an unknown outcome): its result is lost.
@@ -332,7 +332,7 @@ export function admissionUnavailableText(cause) {
332
332
  * sends scopes it validated, so this is a kernel invariant break (or a skewed device), never the
333
333
  * model's doing; whether anything ran is not proven.
334
334
  */
335
- export const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in Capybara itself, not in the request. Tell the user the device rejected the operation and that it should be reported; do not retry it unchanged.";
335
+ export const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in the platform itself, not in the request. Tell the user the device rejected the operation and that it should be reported; do not retry it unchanged.";
336
336
  /**
337
337
  * A device request whose machine came back as a new run of capybara-device before answering
338
338
  * (`DeviceProgramRestartedError`, also as the cause of an unknown outcome): its result is lost.
@@ -14,6 +14,7 @@ import { sql } from "kysely";
14
14
  import { z } from "zod";
15
15
  import { connectorTemplateState } from "../catalog/component-state.js";
16
16
  import { assertItemInstallable } from "../catalog/request-rules.js";
17
+ import { productName } from "../config/product-name.js";
17
18
  import { ApiError } from "../errors.js";
18
19
  import { PluginGuides, } from "../extensions/plugin-guides.js";
19
20
  import { ExtensionRegistry } from "../extensions/registry.js";
@@ -289,7 +290,7 @@ let ConnectorsService = class ConnectorsService {
289
290
  if (!meta)
290
291
  throw fail("auth.client", "Dynamic client registration requires discovery mcp");
291
292
  try {
292
- const client = await registerClient({ ...meta, ...(scopes && { scopes }) }, callbackUrl(publicUrl), http, auth.tokenAuthMethod);
293
+ const client = await registerClient({ ...meta, ...(scopes && { scopes }) }, callbackUrl(publicUrl), http, productName(this.config.get()), auth.tokenAuthMethod);
293
294
  return { client };
294
295
  }
295
296
  catch (e) {
@@ -83,5 +83,7 @@ export declare function pickAuthMethod(supported: string[] | undefined, hasSecre
83
83
  * client)。注册失败只报 HTTP 状态,不带对方正文。
84
84
  */
85
85
  export declare function registerClient(meta: McpAuthMetadata, redirectUri: string, http: OAuthHttpOptions,
86
+ /** The client name the authorization server shows on its consent screen (`platform.name`). */
87
+ clientName: string,
86
88
  /** 管理员指定的客户端认证方式(`tokenAuthMethod`);不给则按授权服务器声明选择。 */
87
89
  preferred?: TokenAuthMethod): Promise<OAuthClientRecord>;
@@ -273,6 +273,8 @@ export function pickAuthMethod(supported, hasSecret) {
273
273
  * client)。注册失败只报 HTTP 状态,不带对方正文。
274
274
  */
275
275
  export async function registerClient(meta, redirectUri, http,
276
+ /** The client name the authorization server shows on its consent screen (`platform.name`). */
277
+ clientName,
276
278
  /** 管理员指定的客户端认证方式(`tokenAuthMethod`);不给则按授权服务器声明选择。 */
277
279
  preferred) {
278
280
  if (!meta.registrationEndpoint) {
@@ -286,7 +288,7 @@ preferred) {
286
288
  method: "POST",
287
289
  headers: { "content-type": "application/json", accept: "application/json" },
288
290
  body: JSON.stringify({
289
- client_name: "Capybara",
291
+ client_name: clientName,
290
292
  redirect_uris: [redirectUri],
291
293
  grant_types: ["authorization_code", "refresh_token"],
292
294
  response_types: ["code"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.65",
3
+ "version": "0.1.0-rc.66",
4
4
  "description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  "yaml": "^2.9.1",
67
67
  "yauzl": "3.4.0",
68
68
  "zod": "^4.6.7",
69
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.49"
69
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.50"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",
@@ -75,8 +75,8 @@
75
75
  "@types/ws": "^8.18.2",
76
76
  "@types/yauzl": "3.4.0",
77
77
  "ws": "^8.22.0",
78
- "@capybara-hq/testing": "0.1.0-rc.31",
79
- "@capybara-hq/device": "0.1.0-rc.26"
78
+ "@capybara-hq/device": "0.1.0-rc.26",
79
+ "@capybara-hq/testing": "0.1.0-rc.32"
80
80
  },
81
81
  "scripts": {
82
82
  "build": "tsc -b"