@capybara-hq/kernel 0.1.0-rc.66 → 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 (139) 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/background/poll.job.d.ts +1 -1
  19. package/dist/background/poll.job.js +8 -6
  20. package/dist/background/tasks.service.js +1 -1
  21. package/dist/catalog/marketplaces.service.d.ts +1 -1
  22. package/dist/channels/inbound.d.ts +2 -3
  23. package/dist/channels/inbound.js +2 -3
  24. package/dist/channels/phrases.d.ts +3 -3
  25. package/dist/channels/phrases.js +3 -3
  26. package/dist/config/schema.d.ts +1 -0
  27. package/dist/config/schema.js +14 -1
  28. package/dist/conversations/conversations.service.d.ts +4 -3
  29. package/dist/conversations/conversations.service.js +4 -2
  30. package/dist/ctx/create-ctx.js +5 -2
  31. package/dist/ctx/device-provider-check.d.ts +7 -0
  32. package/dist/ctx/device-provider-check.js +21 -0
  33. package/dist/db/kernel-schema.d.ts +7 -0
  34. package/dist/devices/access.d.ts +16 -46
  35. package/dist/devices/access.js +26 -62
  36. package/dist/devices/access.module.js +2 -2
  37. package/dist/devices/conversation-devices.d.ts +38 -18
  38. package/dist/devices/conversation-devices.js +69 -51
  39. package/dist/devices/default-provider-setting.d.ts +45 -0
  40. package/dist/devices/default-provider-setting.js +59 -0
  41. package/dist/devices/device-projects.service.js +7 -2
  42. package/dist/devices/device-provider-selection.d.ts +37 -0
  43. package/dist/devices/device-provider-selection.js +86 -0
  44. package/dist/devices/device-provider-selection.module.d.ts +3 -0
  45. package/dist/devices/device-provider-selection.module.js +22 -0
  46. package/dist/devices/devices.controller.d.ts +8 -5
  47. package/dist/devices/devices.controller.js +7 -4
  48. package/dist/devices/devices.module.js +3 -1
  49. package/dist/devices/devices.schemas.js +2 -2
  50. package/dist/devices/devices.service.d.ts +72 -83
  51. package/dist/devices/devices.service.js +139 -248
  52. package/dist/devices/dto.d.ts +9 -0
  53. package/dist/devices/dto.js +15 -2
  54. package/dist/devices/label.d.ts +3 -5
  55. package/dist/devices/label.js +3 -14
  56. package/dist/devices/legacy-cleanup.job.d.ts +2 -2
  57. package/dist/devices/legacy-cleanup.job.js +6 -6
  58. package/dist/errors.d.ts +15 -1
  59. package/dist/errors.js +15 -1
  60. package/dist/extensions/guide-places.d.ts +2 -1
  61. package/dist/extensions/guide-places.js +8 -2
  62. package/dist/extensions/locks.d.ts +1 -1
  63. package/dist/extensions/locks.js +1 -1
  64. package/dist/extensions/org-config.d.ts +20 -4
  65. package/dist/extensions/org-config.js +23 -6
  66. package/dist/extensions/permission-view.d.ts +2 -2
  67. package/dist/extensions/permission-view.js +2 -2
  68. package/dist/extensions/plugin-guides.d.ts +1 -1
  69. package/dist/extensions/plugin-guides.js +11 -3
  70. package/dist/extensions/point-defaults.d.ts +14 -0
  71. package/dist/extensions/point-defaults.js +70 -47
  72. package/dist/extensions/resolve.js +7 -2
  73. package/dist/identity/settings.d.ts +8 -0
  74. package/dist/identity/settings.js +24 -1
  75. package/dist/infra/config/kernel-config.service.js +2 -0
  76. package/dist/lifecycle/kernel-lifecycle.js +7 -6
  77. package/dist/local-devices/device-routes.d.ts +1 -1
  78. package/dist/local-devices/device-routes.js +1 -1
  79. package/dist/local-devices/local-device-provider.d.ts +14 -11
  80. package/dist/local-devices/local-device-provider.js +14 -0
  81. package/dist/local-devices/local-devices.module.d.ts +4 -4
  82. package/dist/local-devices/local-devices.module.js +5 -3
  83. package/dist/local-devices/owner-report.js +2 -1
  84. package/dist/local-devices/targets.d.ts +2 -0
  85. package/dist/local-devices/targets.js +10 -0
  86. package/dist/orgs/settings.service.d.ts +26 -1
  87. package/dist/orgs/settings.service.js +44 -3
  88. package/dist/platform/ops/admin.ops.js +8 -3
  89. package/dist/platform/ops/agents.ops.d.ts +6 -1
  90. package/dist/platform/ops/agents.ops.js +38 -11
  91. package/dist/platform/ops/devices.ops.js +25 -20
  92. package/dist/platform/ops/orgs.ops.js +1 -0
  93. package/dist/platform/ops/themes.ops.js +1 -1
  94. package/dist/runtime/plugin-context.service.js +1 -12
  95. package/dist/sandbox/cloud-permission-snapshot.d.ts +2 -2
  96. package/dist/sandbox/cloud-permission-snapshot.js +3 -3
  97. package/dist/sandbox/device-reports.d.ts +50 -0
  98. package/dist/sandbox/device-reports.js +157 -0
  99. package/dist/sandbox/held-operations.d.ts +8 -8
  100. package/dist/sandbox/leases.d.ts +1 -1
  101. package/dist/sandbox/leases.js +1 -1
  102. package/dist/sandbox/operation-authority.d.ts +5 -2
  103. package/dist/sandbox/operation-authority.js +12 -11
  104. package/dist/sandbox/operation-reconcile.job.d.ts +2 -2
  105. package/dist/sandbox/operation-reconcile.job.js +5 -5
  106. package/dist/sandbox/permission-availability.d.ts +2 -2
  107. package/dist/sandbox/permission-call-types.d.ts +5 -0
  108. package/dist/sandbox/permission-facts.d.ts +2 -2
  109. package/dist/sandbox/permission-facts.js +5 -5
  110. package/dist/sandbox/providers.d.ts +23 -24
  111. package/dist/sandbox/providers.js +38 -46
  112. package/dist/sandbox/providers.module.js +3 -3
  113. package/dist/sandbox/sandbox.module.d.ts +1 -1
  114. package/dist/sandbox/sandbox.module.js +7 -2
  115. package/dist/sandbox/sandbox.service.d.ts +95 -68
  116. package/dist/sandbox/sandbox.service.js +212 -208
  117. package/dist/setup/setup-guides.service.d.ts +4 -1
  118. package/dist/setup/setup-guides.service.js +6 -1
  119. package/dist/themes/avatar-preset-key.d.ts +6 -0
  120. package/dist/themes/avatar-preset-key.js +9 -0
  121. package/dist/themes/theme-state.d.ts +29 -1
  122. package/dist/themes/theme-state.js +40 -1
  123. package/dist/themes/themes.service.d.ts +28 -1
  124. package/dist/themes/themes.service.js +36 -2
  125. package/dist/tools/builtins/image/generate.d.ts +3 -0
  126. package/dist/tools/builtins/image/generate.js +21 -11
  127. package/dist/tools/builtins/image/index.d.ts +1 -1
  128. package/dist/tools/builtins/image/index.js +1 -1
  129. package/dist/tools/builtins/sandbox/common.d.ts +36 -12
  130. package/dist/tools/builtins/sandbox/common.js +62 -18
  131. package/dist/tools/builtins/sandbox/read.d.ts +5 -2
  132. package/dist/tools/builtins/sandbox/read.js +9 -6
  133. package/dist/tools/builtins/sandbox/task-output.d.ts +2 -2
  134. package/dist/tools/builtins/sandbox/task-output.js +6 -5
  135. package/dist/tools/builtins/skill-load.js +13 -4
  136. package/dist/until-aborted.d.ts +5 -0
  137. package/dist/until-aborted.js +16 -0
  138. package/package.json +4 -4
  139. 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)}$`);
@@ -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";
@@ -68,6 +68,34 @@ export declare const THEME_CSS_REVISION = 2;
68
68
  * The one builder of these URLs: the listing, the stylesheet and the asset routes all use it.
69
69
  */
70
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;
71
99
  /**
72
100
  * The {@link ThemeRef} of version `version` of theme `id` of plugin `plugin` (null only for a row
73
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 { isThemeAssetPath, 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,6 +31,44 @@ 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).
@@ -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";
@@ -6,7 +6,7 @@ import type { KernelConfig } from "../../../config/schema.js";
6
6
  import type { ChildAgent } from "../../../conversations/agent-tree.js";
7
7
  import type { AttachmentsService } from "../../../conversations/attachments.service.js";
8
8
  import type { EventLog } from "../../../conversations/event-log.js";
9
- import { type ConversationDevices, type WorkingFacts } from "../../../devices/conversation-devices.js";
9
+ import { type ConversationDevices, type DeviceUnusableReason, type WorkingFacts } from "../../../devices/conversation-devices.js";
10
10
  import type { KernelConfigService } from "../../../infra/config/kernel-config.service.js";
11
11
  import { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot } from "../../../sandbox/attachments-path.js";
12
12
  import { type ManagedDeviceContextPort } from "../../../sandbox/managed-device-context.js";
@@ -24,14 +24,15 @@ export interface SandboxToolDeps {
24
24
  * `currentInstance` too: a background `Bash` launch records the instance it started in; and
25
25
  * `ifRunning`, which `TaskOutput` reads a task through.
26
26
  */
27
- sandbox: Pick<SandboxService, "cloudAvailable" | "availableFor" | "withSandbox"> & Partial<Pick<SandboxService, "pathLease" | "currentInstance" | "ifRunning" | "withOperations">>;
27
+ sandbox: Pick<SandboxService, "withSandbox"> & Partial<Pick<SandboxService, "pathLease" | "currentInstance" | "ifRunning" | "withOperations">>;
28
28
  /**
29
29
  * The device a call enters: the root conversation's, checked for its owner every call.
30
- * `usableNow` (absent in test stubs: only the cloud provider counts) tells a listing whether a
31
- * conversation's device can run without a cloud provider (ruling R8). `workingFacts` (absent
32
- * in test stubs: free mode) gives what decides the working root, read as the review reads it.
30
+ * `usableNow` (absent in test stubs: the device's provider serves the org) tells a listing
31
+ * whether a conversation's device has its provider on in the org (ruling R8). `workingFacts`
32
+ * (absent in test stubs: free mode) gives what decides the working root, read as the review
33
+ * reads it.
33
34
  */
34
- devices: Pick<ConversationDevices, "forTool"> & Partial<Pick<ConversationDevices, "usableNow" | "modeLevel" | "workingFacts" | "projectReach">>;
35
+ devices: Pick<ConversationDevices, "forTool"> & Partial<Pick<ConversationDevices, "usableNow" | "unusableReason" | "modeLevel" | "workingFacts" | "projectReach">>;
35
36
  /** Background `Bash` tasks; absent in test stubs, where `run_in_background` is refused. */
36
37
  background?: Pick<BackgroundTaskStore, "releaseStop" | "get" | "advanceOffset" | "runningOwnedBy" | "finishedOwnedBy"> & Partial<Pick<BackgroundTaskStore, "reserveManaged" | "failManagedPreEffect">>;
37
38
  /**
@@ -125,10 +126,17 @@ export declare const SANDBOX_RESTARTED_NOTICE = "The device's instance was resta
125
126
  export declare const sandboxFilesResetNotice: (roots: SandboxRoots) => string;
126
127
  /** {@link sandboxFilesResetNotice} of an instance with the default roots. */
127
128
  export declare const SANDBOX_FILES_RESET_NOTICE: string;
129
+ /**
130
+ * A conversation with no device while device providers are on in the org: its owner has no default
131
+ * device and the org has no default device provider to make one.
132
+ */
133
+ export declare const NO_DEVICE_TEXT = "This conversation has no device: its owner has no default device and the organization has no default device provider to make one. Ask the user to create a device on the devices page and start a new conversation on it, or ask an org admin to choose a default device provider; or do the task without the sandbox.";
128
134
  /** The message the kernel reports for a sandbox tool call with no provider, minus its final period. */
129
135
  export declare const SANDBOX_UNAVAILABLE_REASON: string;
130
- /** The error of a sandbox call in a deployment without a sandbox provider. */
136
+ /** The error of a sandbox call with no device provider on in the org. */
131
137
  export declare function noSandboxError(): ToolError;
138
+ /** A device whose provider does not serve its org now (`device.unavailable`): files kept. */
139
+ export declare const ENV_UNAVAILABLE_TEXT = "This conversation's device runs on a device provider that is off in this organization or not installed; its files are kept. Ask an org admin to switch the provider back on, or start a new conversation on another device.";
132
140
  /**
133
141
  * A provider call that never connected (refused, unknown host, unreachable network): the request
134
142
  * did not reach the provider, so the call did nothing in the sandbox.
@@ -375,14 +383,30 @@ export declare const sandboxConversationOf: (ctx: BuiltinCallContext) => string;
375
383
  */
376
384
  export declare function withPathLease<T>(deps: Pick<SandboxToolDeps, "sandbox">, s: Pick<SandboxSession, "deviceId">, path: string, signal: AbortSignal, fn: (signal: AbortSignal) => Promise<T>): Promise<T>;
377
385
  /**
378
- * Whether a sandbox tool call of the conversation tree rooted at `conversationId` can run: a
379
- * cloud provider is loaded, or (ruling R8) the conversation's device runs on a registered
380
- * kernel provider (`@local`). Without a conversation only the cloud provider counts.
386
+ * Whether a sandbox tool call of the conversation tree rooted at `conversationId` can run
387
+ * (ruling R8): the conversation's device (an unbound one: the device it would bind to) has its
388
+ * provider on in the org. Without a conversation: some device provider is on in the org
389
+ * ({@link ConversationDevices.usableNow}).
390
+ */
391
+ export declare function sandboxUsable(deps: Pick<SandboxToolDeps, "devices">, orgId: string, conversationId: string | undefined): Promise<boolean>;
392
+ /**
393
+ * Why a sandbox tool call of the tree rooted at `conversationId` cannot run, as model-facing text,
394
+ * or null when it can ({@link ConversationDevices.unusableReason}): the conversation's device has
395
+ * its provider off ({@link ENV_UNAVAILABLE_TEXT}), it has no device while providers are on
396
+ * ({@link NO_DEVICE_TEXT}), or no device provider is on in the org ({@link NO_SANDBOX_TEXT}). A
397
+ * stub with only `usableNow` reads a false answer as the last.
398
+ */
399
+ export declare function sandboxUnusableText(deps: Pick<SandboxToolDeps, "devices">, orgId: string, conversationId: string | undefined): Promise<string | null>;
400
+ /**
401
+ * The tool error of a call whose conversation's device cannot run ({@link sandboxUnusableText}),
402
+ * or null when it can.
381
403
  */
382
- export declare function sandboxUsable(deps: Pick<SandboxToolDeps, "sandbox" | "devices">, orgId: string, conversationId: string | undefined): Promise<boolean>;
404
+ export declare function sandboxUnusableError(deps: Pick<SandboxToolDeps, "devices">, orgId: string, conversationId: string | undefined): Promise<ToolError | null>;
405
+ /** {@link ConversationDevices.unusableReason}, read from a stub's `usableNow` when it has only that. */
406
+ export declare function sandboxUnusableReason(deps: Pick<SandboxToolDeps, "devices">, orgId: string, conversationId: string | undefined): Promise<DeviceUnusableReason | null>;
383
407
  /**
384
408
  * The reason the registry reports the sandbox tools unavailable with, or null when they can run
385
- * ({@link sandboxUsable}; the listing passes the root conversation of the run). An eval replay
409
+ * ({@link sandboxUnusableText}; the listing passes the root conversation of the run). An eval replay
386
410
  * lists them as available (`replay`: its calls are never executed). `memo` (one per listing)
387
411
  * makes every sandbox tool of a listing share one answer.
388
412
  */
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_SANDBOX_ROOTS, DeviceProtocolError, isFileSystemGoneError, isSandboxOperationOutcomeUnknownError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, isSandboxScopeValidationError, isSandboxWorkUnsettledError, SandboxScopeDeniedError, ToolError, validateSandboxPath, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
2
- import { ANONYMOUS_NO_DEVICE, } from "../../../devices/conversation-devices.js";
2
+ import { ANONYMOUS_NO_DEVICE, NO_DEVICE, } from "../../../devices/conversation-devices.js";
3
3
  import { canonicalRoot, workingRootOf } from "../../../devices/working-root.js";
4
4
  import { ApiError } from "../../../errors.js";
5
5
  import { InstanceBindingError } from "../../../local-devices/instance-bindings.js";
@@ -34,10 +34,15 @@ export const sandboxFilesResetNotice = (roots) => `The device's files were reset
34
34
  /** {@link sandboxFilesResetNotice} of an instance with the default roots. */
35
35
  export const SANDBOX_FILES_RESET_NOTICE = sandboxFilesResetNotice(DEFAULT_SANDBOX_ROOTS);
36
36
  const BUSY_TEXT = "The device is busy: all its command slots are taken by commands of this or another conversation sharing it; wait for one to finish and retry.";
37
- const NO_SANDBOX_TEXT = "No sandbox is configured in this deployment; ask an administrator to install a sandbox plugin, or do the task without the sandbox.";
37
+ const NO_SANDBOX_TEXT = "No device provider is on in this organization; ask an org admin to switch one on, or do the task without the sandbox.";
38
+ /**
39
+ * A conversation with no device while device providers are on in the org: its owner has no default
40
+ * device and the org has no default device provider to make one.
41
+ */
42
+ export const NO_DEVICE_TEXT = "This conversation has no device: its owner has no default device and the organization has no default device provider to make one. Ask the user to create a device on the devices page and start a new conversation on it, or ask an org admin to choose a default device provider; or do the task without the sandbox.";
38
43
  /** The message the kernel reports for a sandbox tool call with no provider, minus its final period. */
39
44
  export const SANDBOX_UNAVAILABLE_REASON = NO_SANDBOX_TEXT.slice(0, -1);
40
- /** The error of a sandbox call in a deployment without a sandbox provider. */
45
+ /** The error of a sandbox call with no device provider on in the org. */
41
46
  export function noSandboxError() {
42
47
  return new ToolError(NO_SANDBOX_TEXT);
43
48
  }
@@ -45,7 +50,8 @@ const PATH_BUSY_TEXT = "Another sub-agent or another conversation on this device
45
50
  const ANONYMOUS_TEXT = "The sandbox is not available to anonymous IM senders; do the task without the sandbox, or ask the person to link their account and start a new conversation.";
46
51
  const ENV_NOT_FOUND_TEXT = "This conversation's device was deleted or its owner can no longer use it; ask the user to start a new conversation on another device.";
47
52
  const ENV_FORBIDDEN_TEXT = "This conversation's owner may no longer use its device; ask the user to start a new conversation on a device they can use.";
48
- const ENV_UNAVAILABLE_TEXT = "This conversation's device is kept by a sandbox provider that is not active in this deployment; ask the user to start a new conversation on another device, or an administrator to re-enable that provider.";
53
+ /** A device whose provider does not serve its org now (`device.unavailable`): files kept. */
54
+ export const ENV_UNAVAILABLE_TEXT = "This conversation's device runs on a device provider that is off in this organization or not installed; its files are kept. Ask an org admin to switch the provider back on, or start a new conversation on another device.";
49
55
  const ENV_FILES_LOST_TEXT = "This device's files are gone. Ask the user to reset its files on the devices page, then retry.";
50
56
  /**
51
57
  * A provider call that never connected (refused, unknown host, unreachable network): the request
@@ -433,6 +439,8 @@ export function mapSandboxError(e, log) {
433
439
  const reason = e.details?.[0]?.reason;
434
440
  if (reason === ANONYMOUS_NO_DEVICE)
435
441
  return new ToolError(ANONYMOUS_TEXT);
442
+ if (reason === NO_DEVICE)
443
+ return new ToolError(NO_DEVICE_TEXT);
436
444
  return new ToolError(NO_SANDBOX_TEXT);
437
445
  }
438
446
  const detail = e.details?.[0];
@@ -714,20 +722,54 @@ export async function withPathLease(deps, s, path, signal, fn) {
714
722
  }
715
723
  }
716
724
  /**
717
- * Whether a sandbox tool call of the conversation tree rooted at `conversationId` can run: a
718
- * cloud provider is loaded, or (ruling R8) the conversation's device runs on a registered
719
- * kernel provider (`@local`). Without a conversation only the cloud provider counts.
725
+ * Whether a sandbox tool call of the conversation tree rooted at `conversationId` can run
726
+ * (ruling R8): the conversation's device (an unbound one: the device it would bind to) has its
727
+ * provider on in the org. Without a conversation: some device provider is on in the org
728
+ * ({@link ConversationDevices.usableNow}).
720
729
  */
721
730
  export async function sandboxUsable(deps, orgId, conversationId) {
722
- if (deps.sandbox.cloudAvailable)
723
- return true;
724
- if (conversationId === undefined || !deps.devices.usableNow)
725
- return false;
726
- return deps.devices.usableNow(orgId, conversationId);
731
+ return deps.devices.usableNow ? deps.devices.usableNow(orgId, conversationId) : true;
732
+ }
733
+ /** The model-facing text of each {@link DeviceUnusableReason}. */
734
+ const UNUSABLE_TEXT = {
735
+ "provider-off": ENV_UNAVAILABLE_TEXT,
736
+ "no-device": NO_DEVICE_TEXT,
737
+ none: NO_SANDBOX_TEXT,
738
+ };
739
+ /**
740
+ * Why a sandbox tool call of the tree rooted at `conversationId` cannot run, as model-facing text,
741
+ * or null when it can ({@link ConversationDevices.unusableReason}): the conversation's device has
742
+ * its provider off ({@link ENV_UNAVAILABLE_TEXT}), it has no device while providers are on
743
+ * ({@link NO_DEVICE_TEXT}), or no device provider is on in the org ({@link NO_SANDBOX_TEXT}). A
744
+ * stub with only `usableNow` reads a false answer as the last.
745
+ */
746
+ export async function sandboxUnusableText(deps, orgId, conversationId) {
747
+ const reason = await sandboxUnusableReason(deps, orgId, conversationId);
748
+ return reason === null ? null : UNUSABLE_TEXT[reason];
749
+ }
750
+ /**
751
+ * The tool error of a call whose conversation's device cannot run ({@link sandboxUnusableText}),
752
+ * or null when it can.
753
+ */
754
+ export async function sandboxUnusableError(deps, orgId, conversationId) {
755
+ const reason = await sandboxUnusableReason(deps, orgId, conversationId);
756
+ if (reason === null)
757
+ return null;
758
+ if (reason === "provider-off")
759
+ return new ToolError(ENV_UNAVAILABLE_TEXT);
760
+ if (reason === "no-device")
761
+ return new ToolError(NO_DEVICE_TEXT);
762
+ return noSandboxError();
763
+ }
764
+ /** {@link ConversationDevices.unusableReason}, read from a stub's `usableNow` when it has only that. */
765
+ export async function sandboxUnusableReason(deps, orgId, conversationId) {
766
+ if (deps.devices.unusableReason)
767
+ return deps.devices.unusableReason(orgId, conversationId);
768
+ return (await sandboxUsable(deps, orgId, conversationId)) ? null : "none";
727
769
  }
728
770
  /**
729
771
  * The reason the registry reports the sandbox tools unavailable with, or null when they can run
730
- * ({@link sandboxUsable}; the listing passes the root conversation of the run). An eval replay
772
+ * ({@link sandboxUnusableText}; the listing passes the root conversation of the run). An eval replay
731
773
  * lists them as available (`replay`: its calls are never executed). `memo` (one per listing)
732
774
  * makes every sandbox tool of a listing share one answer.
733
775
  */
@@ -735,12 +777,14 @@ export const unavailableWhenNoSandbox = (deps) => async (ctx) => {
735
777
  if (ctx.replay === true)
736
778
  return null;
737
779
  const key = "sandboxUsable";
738
- let usable = ctx.memo?.get(key);
739
- if (usable === undefined) {
740
- usable = sandboxUsable(deps, ctx.orgId, ctx.conversationId);
741
- ctx.memo?.set(key, usable);
780
+ let text = ctx.memo?.get(key);
781
+ if (text === undefined) {
782
+ text = sandboxUnusableText(deps, ctx.orgId, ctx.conversationId);
783
+ ctx.memo?.set(key, text);
742
784
  }
743
- return (await usable) ? null : SANDBOX_UNAVAILABLE_REASON;
785
+ const t = await text;
786
+ // the listing's reason has no final period
787
+ return t === null ? null : t.slice(0, -1);
744
788
  };
745
789
  /** 读出的字节是否像二进制(开头 8 KB 里有 NUL)。 */
746
790
  export function looksBinary(data) {
@@ -9,8 +9,11 @@ export declare const READ_MAX_BYTES: number;
9
9
  export declare const READ_DESCRIPTION: string;
10
10
  /** Neither or both of `file_path` and `file_id` (spec §1.1). */
11
11
  export declare const READ_ONE_SOURCE_TEXT = "Pass exactly one of file_path (a path on the device) and file_id (an attachment or artifact id).";
12
- /** A `file_path` read without a usable device (spec §1.1; verbatim). */
13
- export declare const READ_NO_DEVICE_TEXT = "This agent has no device; pass file_id to read an attachment or artifact.";
12
+ /**
13
+ * A `file_path` read without a usable device: why the device cannot be used
14
+ * ({@link sandboxUnusableText}), then the `file_id` way in.
15
+ */
16
+ export declare const readNoDeviceText: (unusable: string) => string;
14
17
  /** A `file_id` that is no file of this conversation or its root. */
15
18
  export declare const unknownFileIdText: (id: string) => string;
16
19
  /** A `file_id` read in a deployment without an object store. */
@@ -6,7 +6,7 @@ import { viewPath } from "../../view.js";
6
6
  import { findConversationFile, } from "../conversation-files.js";
7
7
  import { sizeText } from "../size-text.js";
8
8
  import { readImageWithVisionModel } from "../vision/read-image.js";
9
- import { checkFilePathShape, checkToolPath, clip, display, inToolSandbox, looksBinary, resolveToolPath, sandboxBaseTimeoutMs, sandboxConversationOf, sandboxUsable, unavailableWhenNoSandbox, withNotices, } from "./common.js";
9
+ import { checkFilePathShape, checkToolPath, clip, display, inToolSandbox, looksBinary, resolveToolPath, sandboxBaseTimeoutMs, sandboxConversationOf, sandboxUnusableText, unavailableWhenNoSandbox, withNotices, } from "./common.js";
10
10
  import { normalizeSandboxPath, recordedFile } from "./file-state.js";
11
11
  /** 不给 `limit` 时一次读的行数。 */
12
12
  const DEFAULT_LIMIT = 2000;
@@ -68,8 +68,11 @@ const isDirectory = (path) => `${clip(path, 200)} is a directory; use Glob to li
68
68
  const pastEnd = (offset, total) => `offset ${offset} is past the end of the file (${total} lines); pass an offset of at most ${total}.`;
69
69
  /** Neither or both of `file_path` and `file_id` (spec §1.1). */
70
70
  export const READ_ONE_SOURCE_TEXT = "Pass exactly one of file_path (a path on the device) and file_id (an attachment or artifact id).";
71
- /** A `file_path` read without a usable device (spec §1.1; verbatim). */
72
- export const READ_NO_DEVICE_TEXT = "This agent has no device; pass file_id to read an attachment or artifact.";
71
+ /**
72
+ * A `file_path` read without a usable device: why the device cannot be used
73
+ * ({@link sandboxUnusableText}), then the `file_id` way in.
74
+ */
75
+ export const readNoDeviceText = (unusable) => `${unusable} To read an attachment or artifact of this conversation, pass file_id instead.`;
73
76
  /** A `file_id` that is no file of this conversation or its root. */
74
77
  export const unknownFileIdText = (id) => `file_id ${clip(id, 100)} is not an attachment or artifact of this conversation; pass the id of one.`;
75
78
  /** A `file_id` read in a deployment without an object store. */
@@ -154,9 +157,9 @@ export function sandboxReadTool(deps) {
154
157
  return readById(deps, ctx, input, input.file_id);
155
158
  const filePath = input.file_path;
156
159
  checkFilePathShape(filePath);
157
- if (!(await sandboxUsable(deps, ctx.orgId, sandboxConversationOf(ctx)))) {
158
- throw new ToolError(READ_NO_DEVICE_TEXT);
159
- }
160
+ const unusable = await sandboxUnusableText(deps, ctx.orgId, sandboxConversationOf(ctx));
161
+ if (unusable !== null)
162
+ throw new ToolError(readNoDeviceText(unusable));
160
163
  let path = "";
161
164
  const { value, notices } = await inToolSandbox(deps, ctx, async (s) => {
162
165
  const { h, p, signal } = s;