@capybara-hq/kernel 0.1.0-rc.97 → 0.1.0-rc.98

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 (61) hide show
  1. package/dist/catalog/marketplaces.service.d.ts +1 -1
  2. package/dist/channels/channels.schemas.d.ts +10 -0
  3. package/dist/channels/channels.schemas.js +7 -0
  4. package/dist/channels/connections.service.d.ts +7 -0
  5. package/dist/channels/connections.service.js +4 -0
  6. package/dist/channels/features.d.ts +18 -1
  7. package/dist/channels/features.js +22 -0
  8. package/dist/channels/outbound.d.ts +19 -0
  9. package/dist/channels/outbound.js +531 -18
  10. package/dist/channels/phrases.d.ts +10 -0
  11. package/dist/channels/phrases.js +4 -0
  12. package/dist/channels/progress.d.ts +75 -0
  13. package/dist/channels/progress.js +216 -0
  14. package/dist/conversations/event-log.d.ts +8 -2
  15. package/dist/conversations/events.d.ts +5 -0
  16. package/dist/conversations/events.js +5 -1
  17. package/dist/conversations/prompt-suggestions.js +2 -2
  18. package/dist/db/kernel-schema.d.ts +16 -0
  19. package/dist/evals/run-replay.js +2 -2
  20. package/dist/evals/step-replay.js +2 -2
  21. package/dist/evals/worker.js +3 -1
  22. package/dist/extensions/plugin-icons.d.ts +7 -0
  23. package/dist/extensions/plugin-icons.js +8 -0
  24. package/dist/models/purposes.js +2 -2
  25. package/dist/platform/ops/channels.ops.js +24 -5
  26. package/dist/runtime/model-call.d.ts +23 -2
  27. package/dist/runtime/model-call.js +64 -9
  28. package/dist/runtime/run-drafts.d.ts +46 -4
  29. package/dist/runtime/run-drafts.js +110 -9
  30. package/dist/runtime/run-steps.d.ts +2 -1
  31. package/dist/runtime/run-steps.js +6 -2
  32. package/dist/runtime/runtime.module.js +3 -0
  33. package/dist/runtime/stream.controller.d.ts +7 -5
  34. package/dist/runtime/stream.controller.js +10 -6
  35. package/dist/runtime/stream.js +9 -1
  36. package/dist/runtime/write-base.d.ts +95 -0
  37. package/dist/runtime/write-base.js +281 -0
  38. package/dist/runtime/write-base.service.d.ts +68 -0
  39. package/dist/runtime/write-base.service.js +184 -0
  40. package/dist/sandbox/kernel-read.d.ts +39 -9
  41. package/dist/sandbox/kernel-read.js +33 -3
  42. package/dist/sandbox/operation-authority.d.ts +16 -12
  43. package/dist/sandbox/operation-authority.js +33 -20
  44. package/dist/sandbox/operation-intents.d.ts +10 -4
  45. package/dist/sandbox/operation-intents.js +31 -11
  46. package/dist/sandbox/sandbox.service.d.ts +30 -7
  47. package/dist/sandbox/sandbox.service.js +47 -13
  48. package/dist/tools/builtins/agent.js +4 -0
  49. package/dist/tools/builtins/image/generate.js +1 -0
  50. package/dist/tools/builtins/sandbox/bash.js +1 -0
  51. package/dist/tools/builtins/sandbox/edit.js +1 -0
  52. package/dist/tools/builtins/sandbox/write.js +1 -0
  53. package/dist/tools/builtins/send-message.js +1 -0
  54. package/dist/tools/info.d.ts +21 -2
  55. package/dist/tools/info.js +55 -12
  56. package/dist/tools/pipeline.d.ts +3 -1
  57. package/dist/tools/pipeline.js +37 -3
  58. package/dist/tools/registry.d.ts +6 -5
  59. package/dist/tools/registry.js +6 -5
  60. package/package.json +3 -3
  61. package/src/migrations/0185_channel_process_display.sql +13 -0
@@ -1,6 +1,7 @@
1
- import { type LocalizedName, type ToolAnnotations } from "@capybara-hq/plugin-sdk";
1
+ import { type LocalizedName, type ToolAnnotations, type ToolInputView } from "@capybara-hq/plugin-sdk";
2
2
  import { ConversationAccess } from "../conversations/access.js";
3
3
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
4
+ import { PluginIcons } from "../extensions/plugin-icons.js";
4
5
  import { KernelDb } from "../infra/database/kernel-db.js";
5
6
  import { OrgToolSwitches } from "./org-tool-switches.js";
6
7
  import { ToolRegistry } from "./registry.js";
@@ -12,16 +13,31 @@ import { ToolRegistry } from "./registry.js";
12
13
  export type ToolKind = "command" | "read" | "edit" | "search" | "connector" | "meta"
13
14
  /** Reading background tasks (`TaskOutput`, `TaskList`): neither a file read nor a command. */
14
15
  | "task" | "tool";
16
+ /**
17
+ * The icon a step of a run shows: a named design icon, or an org catalog item's icon (web:
18
+ * `${org}/catalog/${itemId}/icon`). Display only.
19
+ */
20
+ export type ToolIcon = {
21
+ kind: "name";
22
+ name: "terminal" | "file-text" | "square-pen" | "search" | "globe" | "skills" | "agent" | "list-checks" | "connector" | "extension";
23
+ } | {
24
+ kind: "catalog";
25
+ itemId: string;
26
+ };
15
27
  export interface ToolInfo {
16
28
  /** The model-visible tool key, as asked for. */
17
29
  key: string;
18
30
  /** The declared display title (`ToolSpec.title`), or null. */
19
31
  title: string | null;
20
32
  kind: ToolKind;
33
+ /** The step's icon in the conversation's process block. */
34
+ icon: ToolIcon;
21
35
  /** True exactly for the builtin tools that run in the conversation's sandbox. */
22
36
  sandbox: boolean;
23
37
  /** The declared key arguments (`ToolSpec.keyArgs`), or []. */
24
38
  keyArgs: string[];
39
+ /** The declared streaming input preview (`ToolSpec.inputView`), or null. */
40
+ inputView: ToolInputView | null;
25
41
  /**
26
42
  * The local tool name parsed from a connector or extension key (`mcp__crm__delete` -> `delete`),
27
43
  * shown in brackets after the source's display name; null for builtins and unparsable keys.
@@ -52,6 +68,8 @@ export declare const TOOL_INFO_KEY_MAX = 200;
52
68
  export interface ToolInfoDeps {
53
69
  db: KernelSchemaDb;
54
70
  registry: Pick<ToolRegistry, "builtinSpecs" | "extensionToolSpecs">;
71
+ /** Without it every extension tool gets the generic icon (display-text callers need none). */
72
+ icons?: Pick<PluginIcons, "itemIdsWithIcon">;
55
73
  }
56
74
  /**
57
75
  * Presentation metadata for `keys` in this org, in request order with repeats dropped. Builtins
@@ -76,9 +94,10 @@ export declare class ConversationToolInfo {
76
94
  private readonly registry;
77
95
  /** Conversation visibility (the same rule as the events API). */
78
96
  private readonly access;
97
+ private readonly icons;
79
98
  constructor(db: KernelDb, registry: Pick<ToolRegistry, "builtinSpecs" | "extensionToolSpecs">,
80
99
  /** Conversation visibility (the same rule as the events API). */
81
- access: Pick<ConversationAccess, "isAccessible">);
100
+ access: Pick<ConversationAccess, "isAccessible">, icons: PluginIcons);
82
101
  get(orgId: string, conversationId: string, viewerAccountId: string, keys: readonly string[]): Promise<ToolInfo[]>;
83
102
  }
84
103
  /** One tool of {@link OrgExtensionTools}. Display only, for the agent form. */
@@ -7,10 +7,11 @@ 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 { connectorToolKey, extensionToolKey, parseToolKey, } from "@capybara-hq/plugin-sdk";
10
+ import { connectorToolKey, extensionToolKey, parseToolKey, validateToolPresentation, } from "@capybara-hq/plugin-sdk";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { ConversationAccess } from "../conversations/access.js";
13
13
  import { ApiError } from "../errors.js";
14
+ import { PluginIcons } from "../extensions/plugin-icons.js";
14
15
  import { KernelDb } from "../infra/database/kernel-db.js";
15
16
  import { UUID_RE } from "../ui/registry.js";
16
17
  import { BUILTIN_TOOL_KINDS, SANDBOX_TOOL_NAMES } from "./builtin-names.js";
@@ -18,6 +19,27 @@ import { pluginDisplayNames } from "./display-names.js";
18
19
  import { toolKeyIssue } from "./naming.js";
19
20
  import { OrgToolSwitches } from "./org-tool-switches.js";
20
21
  import { policyFromAnnotations, ToolRegistry } from "./registry.js";
22
+ /** Builtin tools whose icon follows the key, ahead of the kind. */
23
+ const BUILTIN_ICONS = {
24
+ WebSearch: "globe",
25
+ WebFetch: "globe",
26
+ Skill: "skills",
27
+ Agent: "agent",
28
+ TaskList: "list-checks",
29
+ // background tasks are commands (process blocks spec §2)
30
+ TaskOutput: "terminal",
31
+ TaskStop: "terminal",
32
+ };
33
+ const KIND_ICONS = {
34
+ command: "terminal",
35
+ read: "file-text",
36
+ edit: "square-pen",
37
+ search: "search",
38
+ };
39
+ const named = (name) => ({
40
+ kind: "name",
41
+ name,
42
+ });
21
43
  export { BUILTIN_TOOL_KINDS } from "./builtin-names.js";
22
44
  /** At most this many keys per request, each at most {@link TOOL_INFO_KEY_MAX} characters. */
23
45
  export const TOOL_INFO_MAX_KEYS = 100;
@@ -25,6 +47,9 @@ export const TOOL_INFO_KEY_MAX = 200;
25
47
  const display = (spec) => ({
26
48
  title: typeof spec?.title === "string" ? spec.title : null,
27
49
  keyArgs: Array.isArray(spec?.keyArgs) ? [...spec.keyArgs] : [],
50
+ inputView: spec?.inputView !== undefined && validateToolPresentation(spec).length === 0
51
+ ? structuredClone(spec.inputView)
52
+ : null,
28
53
  });
29
54
  /**
30
55
  * Presentation metadata for `keys` in this org, in request order with repeats dropped. Builtins
@@ -69,18 +94,27 @@ export async function toolInfo(deps, orgId, keys) {
69
94
  const e = extensions.get(k);
70
95
  return e ? [e.plugin] : [];
71
96
  }));
97
+ // An extension's icon is its plugin's catalog item icon, when the org's catalog shows one.
98
+ const catalogItems = (await deps.icons?.itemIdsWithIcon(unique.flatMap((k) => {
99
+ const e = extensions.get(k);
100
+ return e ? [e.plugin] : [];
101
+ }), { kind: "org", orgId, isAdmin: false })) ?? new Map();
72
102
  const localTool = (key) => {
73
103
  const p = parseToolKey(key);
74
104
  return p && p.kind !== "builtin" ? p.tool : null;
75
105
  };
76
- const builtinInfo = (key, spec) => ({
77
- key,
78
- ...display(spec),
79
- kind: BUILTIN_TOOL_KINDS[key] ?? "tool",
80
- sandbox: SANDBOX_TOOL_NAMES.includes(key),
81
- tool: null,
82
- source: { kind: "builtin" },
83
- });
106
+ const builtinInfo = (key, spec) => {
107
+ const kind = BUILTIN_TOOL_KINDS[key] ?? "tool";
108
+ return {
109
+ key,
110
+ ...display(spec),
111
+ kind,
112
+ icon: named(BUILTIN_ICONS[key] ?? KIND_ICONS[kind] ?? "extension"),
113
+ sandbox: SANDBOX_TOOL_NAMES.includes(key),
114
+ tool: null,
115
+ source: { kind: "builtin" },
116
+ };
117
+ };
84
118
  return unique.map((key) => {
85
119
  const b = builtins.get(key);
86
120
  if (b)
@@ -91,6 +125,9 @@ export async function toolInfo(deps, orgId, keys) {
91
125
  key,
92
126
  ...display(e.spec),
93
127
  kind: "tool",
128
+ icon: catalogItems.has(e.plugin)
129
+ ? { kind: "catalog", itemId: catalogItems.get(e.plugin) }
130
+ : named("extension"),
94
131
  sandbox: false,
95
132
  tool: e.spec.name,
96
133
  source: {
@@ -106,6 +143,7 @@ export async function toolInfo(deps, orgId, keys) {
106
143
  key,
107
144
  ...display(c.spec),
108
145
  kind: "connector",
146
+ icon: named("connector"),
109
147
  sandbox: false,
110
148
  tool: c.tool,
111
149
  source: { kind: "connector", id: c.id, name: c.name },
@@ -115,8 +153,10 @@ export async function toolInfo(deps, orgId, keys) {
115
153
  key,
116
154
  title: null,
117
155
  kind: "tool",
156
+ icon: named("extension"),
118
157
  sandbox: false,
119
158
  keyArgs: [],
159
+ inputView: null,
120
160
  tool: localTool(key),
121
161
  source: { kind: "unknown" },
122
162
  };
@@ -127,26 +167,29 @@ let ConversationToolInfo = class ConversationToolInfo {
127
167
  db;
128
168
  registry;
129
169
  access;
170
+ icons;
130
171
  constructor(db, registry,
131
172
  /** Conversation visibility (the same rule as the events API). */
132
- access) {
173
+ access, icons) {
133
174
  this.db = db;
134
175
  this.registry = registry;
135
176
  this.access = access;
177
+ this.icons = icons;
136
178
  }
137
179
  async get(orgId, conversationId, viewerAccountId, keys) {
138
180
  if (!UUID_RE.test(conversationId) ||
139
181
  !(await this.access.isAccessible(orgId, conversationId, viewerAccountId))) {
140
182
  throw new ApiError("conversation.not_found", "Conversation not found");
141
183
  }
142
- return toolInfo({ db: this.db.db, registry: this.registry }, orgId, keys);
184
+ return toolInfo({ db: this.db.db, registry: this.registry, icons: this.icons }, orgId, keys);
143
185
  }
144
186
  };
145
187
  ConversationToolInfo = __decorate([
146
188
  Injectable(),
147
189
  __param(0, Inject(KernelDb)),
148
190
  __param(1, Inject(ToolRegistry)),
149
- __param(2, Inject(ConversationAccess))
191
+ __param(2, Inject(ConversationAccess)),
192
+ __param(3, Inject(PluginIcons))
150
193
  ], ConversationToolInfo);
151
194
  export { ConversationToolInfo };
152
195
  /**
@@ -718,7 +718,9 @@ export declare class ToolPipeline {
718
718
  /**
719
719
  * A plugin tool's inline card (`ToolResult.card` → `tool_result.card`, display only): `view` must
720
720
  * be an `inline` ui contribution of the same extension and `key` at most 200 characters; anything
721
- * else is dropped with a warning and the result is written as usual.
721
+ * else is dropped with a warning and the result is written as usual. `placement` is kept when
722
+ * `pinned` or `process` (an unknown value means `output`); `text` only with `pinned`, 1 to
723
+ * {@link CARD_TEXT_MAX} characters.
722
724
  */
723
725
  private cardOf;
724
726
  /**
@@ -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 { DeviceAccessError, ToolError, validateInputForm, validateToolDisplay, } from "@capybara-hq/plugin-sdk";
10
+ import { CARD_TEXT_MAX, DeviceAccessError, ToolError, validateInputForm, validateToolDisplay, } from "@capybara-hq/plugin-sdk";
11
11
  import { Inject, Injectable, Optional } from "@nestjs/common";
12
12
  import { sql } from "kysely";
13
13
  import { backgroundMaxSeconds } from "../background/launch.js";
@@ -2988,7 +2988,9 @@ let ToolPipeline = class ToolPipeline {
2988
2988
  /**
2989
2989
  * A plugin tool's inline card (`ToolResult.card` → `tool_result.card`, display only): `view` must
2990
2990
  * be an `inline` ui contribution of the same extension and `key` at most 200 characters; anything
2991
- * else is dropped with a warning and the result is written as usual.
2991
+ * else is dropped with a warning and the result is written as usual. `placement` is kept when
2992
+ * `pinned` or `process` (an unknown value means `output`); `text` only with `pinned`, 1 to
2993
+ * {@link CARD_TEXT_MAX} characters.
2992
2994
  */
2993
2995
  cardOf(result, plugin, toolKey) {
2994
2996
  const c = result?.card;
@@ -3004,7 +3006,39 @@ let ToolPipeline = class ToolPipeline {
3004
3006
  });
3005
3007
  return undefined;
3006
3008
  }
3007
- return { plugin, view: x.view, ...(x.key !== undefined && { key: x.key }) };
3009
+ // placement: an unknown value falls back to `output` (recorded as absent)
3010
+ let placement;
3011
+ if (x.placement === "pinned" || x.placement === "process")
3012
+ placement = x.placement;
3013
+ else if (x.placement !== undefined && x.placement !== "output") {
3014
+ this.deps.log.warn("tool returned an inline card with an unknown placement; using output", {
3015
+ toolKey,
3016
+ placement: typeof x.placement === "string" ? x.placement.slice(0, 50) : undefined,
3017
+ });
3018
+ }
3019
+ // text: only a pinned card carries it, at most CARD_TEXT_MAX characters
3020
+ let text;
3021
+ if (x.text !== undefined) {
3022
+ if (placement !== "pinned") {
3023
+ this.deps.log.warn("tool returned inline card text without a pinned placement; text dropped", {
3024
+ toolKey,
3025
+ });
3026
+ }
3027
+ else if (typeof x.text !== "string" || x.text === "" || x.text.length > CARD_TEXT_MAX) {
3028
+ this.deps.log.warn("tool returned inline card text that is empty or too long; text dropped", {
3029
+ toolKey,
3030
+ });
3031
+ }
3032
+ else
3033
+ text = x.text;
3034
+ }
3035
+ return {
3036
+ plugin,
3037
+ view: x.view,
3038
+ ...(x.key !== undefined && { key: x.key }),
3039
+ ...(placement !== undefined && { placement }),
3040
+ ...(text !== undefined && { text }),
3041
+ };
3008
3042
  }
3009
3043
  /**
3010
3044
  * A plugin tool's `InputRequired.open` (display only): `contribution` must be a
@@ -302,12 +302,13 @@ export interface UnavailableTool {
302
302
  /** The first 16 hex digits of sha256(canonicalJson(v)): a fingerprint independent of key order. */
303
303
  export declare function contentHash(v: unknown): string;
304
304
  /**
305
- * `ToolSpec` fields the model never sees: the display-only `title` and `keyArgs` (UI refresh B)
306
- * and an extension tool's own time limit `timeoutMs`. Left out of the definition fingerprint, so
307
- * adding or changing them never changes `model_call.request.tools`, never sends a connector tool
308
- * to drift review and never invalidates a remembered grant.
305
+ * `ToolSpec` fields the model never sees: the display-only `title`, `keyArgs` (UI refresh B) and
306
+ * `inputView` (streaming input preview), and an extension tool's own time limit `timeoutMs`. Left
307
+ * out of the definition fingerprint, so adding or changing them never changes
308
+ * `model_call.request.tools`, never sends a connector tool to drift review and never invalidates a
309
+ * remembered grant.
309
310
  */
310
- export declare const NON_MODEL_SPEC_FIELDS: readonly ["title", "keyArgs", "timeoutMs"];
311
+ export declare const NON_MODEL_SPEC_FIELDS: readonly ["title", "keyArgs", "inputView", "timeoutMs"];
311
312
  /** A tool spec without its {@link NON_MODEL_SPEC_FIELDS} (non-objects unchanged). */
312
313
  export declare function withoutNonModelFields<T>(spec: T): T;
313
314
  /**
@@ -35,12 +35,13 @@ export function contentHash(v) {
35
35
  return createHash("sha256").update(canonicalJson(v)).digest("hex").slice(0, 16);
36
36
  }
37
37
  /**
38
- * `ToolSpec` fields the model never sees: the display-only `title` and `keyArgs` (UI refresh B)
39
- * and an extension tool's own time limit `timeoutMs`. Left out of the definition fingerprint, so
40
- * adding or changing them never changes `model_call.request.tools`, never sends a connector tool
41
- * to drift review and never invalidates a remembered grant.
38
+ * `ToolSpec` fields the model never sees: the display-only `title`, `keyArgs` (UI refresh B) and
39
+ * `inputView` (streaming input preview), and an extension tool's own time limit `timeoutMs`. Left
40
+ * out of the definition fingerprint, so adding or changing them never changes
41
+ * `model_call.request.tools`, never sends a connector tool to drift review and never invalidates a
42
+ * remembered grant.
42
43
  */
43
- export const NON_MODEL_SPEC_FIELDS = ["title", "keyArgs", "timeoutMs"];
44
+ export const NON_MODEL_SPEC_FIELDS = ["title", "keyArgs", "inputView", "timeoutMs"];
44
45
  /** A tool spec without its {@link NON_MODEL_SPEC_FIELDS} (non-objects unchanged). */
45
46
  export function withoutNonModelFields(spec) {
46
47
  if (spec === null || typeof spec !== "object" || Array.isArray(spec))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.97",
3
+ "version": "0.1.0-rc.98",
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.80"
69
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.81"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",
@@ -75,7 +75,7 @@
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.43"
78
+ "@capybara-hq/testing": "0.1.0-rc.44"
79
79
  },
80
80
  "scripts": {
81
81
  "build": "tsc -b"
@@ -0,0 +1,13 @@
1
+ -- Conversation process blocks: how an IM channel shows a run's process. Per connection,
2
+ -- 'detailed' | 'brief' | 'off'; NULL follows the chat type (direct chats detailed, groups brief).
3
+ ALTER TABLE channel_connections ADD COLUMN IF NOT EXISTS process_display text
4
+ CHECK (process_display IN ('detailed', 'brief', 'off'));
5
+ -- The run's one progress message, edited in place: its IM message id, the run it belongs to and
6
+ -- when its last milestone was sent, so any replica delivering the conversation edits the same one.
7
+ ALTER TABLE channel_deliveries ADD COLUMN IF NOT EXISTS progress_message_id text;
8
+ ALTER TABLE channel_deliveries ADD COLUMN IF NOT EXISTS progress_run_id text;
9
+ ALTER TABLE channel_deliveries ADD COLUMN IF NOT EXISTS milestone_at timestamptz;
10
+ -- The run's progress card was posted again after the platform rejected an edit (once per run).
11
+ ALTER TABLE channel_deliveries ADD COLUMN IF NOT EXISTS progress_reposted boolean NOT NULL DEFAULT false;
12
+ -- The ended run's card got its final edit (or the platform refused it for good): leave it alone.
13
+ ALTER TABLE channel_deliveries ADD COLUMN IF NOT EXISTS progress_final boolean NOT NULL DEFAULT false;