@capybara-hq/kernel 0.1.0-rc.42 → 0.1.0-rc.44

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 (60) hide show
  1. package/dist/catalog/marketplaces.service.d.ts +1 -1
  2. package/dist/catalog/scope-sync.d.ts +3 -2
  3. package/dist/catalog/scope-sync.js +3 -2
  4. package/dist/client/client-access.service.js +4 -4
  5. package/dist/config/schema.d.ts +3 -0
  6. package/dist/config/schema.js +30 -0
  7. package/dist/conversations/events.d.ts +3 -0
  8. package/dist/conversations/events.js +7 -3
  9. package/dist/ctx/create-ctx.d.ts +13 -6
  10. package/dist/ctx/create-ctx.js +21 -5
  11. package/dist/db/kernel-schema.d.ts +10 -0
  12. package/dist/extensions/enabled.d.ts +24 -4
  13. package/dist/extensions/enabled.js +47 -10
  14. package/dist/extensions/host.d.ts +7 -3
  15. package/dist/extensions/host.js +13 -8
  16. package/dist/extensions/org-config.d.ts +5 -2
  17. package/dist/extensions/org-config.js +32 -22
  18. package/dist/infra/config/kernel-config.service.js +4 -0
  19. package/dist/models/enablement.d.ts +1 -1
  20. package/dist/models/enablement.js +1 -1
  21. package/dist/models/image-usable.d.ts +22 -0
  22. package/dist/models/image-usable.js +29 -0
  23. package/dist/models/images.d.ts +125 -0
  24. package/dist/models/images.js +440 -0
  25. package/dist/models/models.module.d.ts +3 -2
  26. package/dist/models/models.module.js +16 -5
  27. package/dist/models/org-models.schemas.js +1 -0
  28. package/dist/models/purposes.controller.d.ts +7 -0
  29. package/dist/models/purposes.controller.js +9 -0
  30. package/dist/models/purposes.d.ts +28 -3
  31. package/dist/models/purposes.js +40 -13
  32. package/dist/platform/ops/models.ops.js +10 -0
  33. package/dist/runtime/hook-calls.d.ts +11 -1
  34. package/dist/runtime/hook-calls.js +24 -1
  35. package/dist/runtime/providers.d.ts +10 -6
  36. package/dist/runtime/providers.js +23 -4
  37. package/dist/runtime/usage-report.d.ts +10 -6
  38. package/dist/runtime/usage-report.js +31 -11
  39. package/dist/sandbox/review/permission-candidate.js +22 -6
  40. package/dist/sandbox/review/review.service.d.ts +1 -1
  41. package/dist/sandbox/review/review.service.js +43 -12
  42. package/dist/tools/builtin-names.d.ts +3 -1
  43. package/dist/tools/builtin-names.js +5 -1
  44. package/dist/tools/builtins/artifacts.d.ts +43 -0
  45. package/dist/tools/builtins/artifacts.js +67 -0
  46. package/dist/tools/builtins/builtin-tools.d.ts +4 -0
  47. package/dist/tools/builtins/builtin-tools.js +28 -5
  48. package/dist/tools/builtins/image/generate.d.ts +59 -0
  49. package/dist/tools/builtins/image/generate.js +535 -0
  50. package/dist/tools/builtins/image/index.d.ts +2 -0
  51. package/dist/tools/builtins/image/index.js +2 -0
  52. package/dist/tools/builtins/image/paths.d.ts +12 -0
  53. package/dist/tools/builtins/image/paths.js +26 -0
  54. package/dist/tools/builtins/sandbox/deliver.js +7 -49
  55. package/dist/tools/pipeline.js +15 -7
  56. package/dist/tools/registry.d.ts +2 -2
  57. package/dist/tools/registry.js +2 -2
  58. package/dist/tools/tools.module.js +3 -0
  59. package/package.json +4 -4
  60. package/src/migrations/0160_model_usage_image_kind.sql +10 -0
@@ -51,6 +51,7 @@ import { Breaker, breakerOpenMessage } from "./breaker.js";
51
51
  import { SEND_MESSAGE, SUBAGENT_HANDBACK, TOOL_SEARCH } from "./builtin-names.js";
52
52
  import { AGENT_TOOL, AgentToolInput } from "./builtins/agent.js";
53
53
  import { HandbackInput } from "./builtins/handback.js";
54
+ import { generateImagePaths } from "./builtins/image/paths.js";
54
55
  import { DEVICE_CODE_PATTERN, deviceCodeIdemKey, GITHUB_DEVICE_LOGIN_URL, } from "./builtins/sandbox/device-code.js";
55
56
  import { SendMessageInput } from "./builtins/send-message.js";
56
57
  import { isAlwaysLoaded, notLoadedText } from "./builtins/tool-search.js";
@@ -179,10 +180,16 @@ function reviewParentOf(parent) {
179
180
  }
180
181
  /**
181
182
  * The tools the command review covers (auto mode spec §5.1): the shell and the file tools whose
182
- * writes may leave the workspace. Any other tool call is not reviewed (the review service answers
183
- * `allow` for it too; the pipeline skips the facts read).
183
+ * writes may leave the workspace, and `GenerateImage` when it writes its images into the device
184
+ * (`file_path`; image generation spec §5.3, reviewed as a `Write`). Any other tool call is not
185
+ * reviewed (the review service answers `allow` for it too; the pipeline skips the facts read).
184
186
  */
185
- const REVIEWED_TOOL_KEYS = new Set(["Bash", "Write", "Edit"]);
187
+ const REVIEWED_TOOL_KEYS = new Set(["Bash", "Write", "Edit", "GenerateImage"]);
188
+ /** Whether the review covers this call ({@link REVIEWED_TOOL_KEYS}; `GenerateImage` with a path). */
189
+ const isReviewedCall = (toolKey, input) => REVIEWED_TOOL_KEYS.has(toolKey) &&
190
+ (toolKey !== "GenerateImage" || generateImagePaths(input).length > 0);
191
+ /** The paths a reviewed write writes: `file_path`, or every path of a `GenerateImage` call. */
192
+ const writePathsOf = (toolKey, input) => toolKey === "GenerateImage" ? generateImagePaths(input) : [textField(input, "file_path")];
186
193
  /** Whether the review holds a shell command or a file write, for the texts and the ask's detail. */
187
194
  const reviewKindOf = (toolKey) => toolKey === "Bash" ? "command" : "write";
188
195
  /**
@@ -1001,7 +1008,7 @@ let ToolPipeline = class ToolPipeline {
1001
1008
  const devices = this.deps.devices;
1002
1009
  if (review === undefined || devices === undefined)
1003
1010
  return { kind: "continue" };
1004
- if (!REVIEWED_TOOL_KEYS.has(tool.key))
1011
+ if (!isReviewedCall(tool.key, input))
1005
1012
  return { kind: "continue" };
1006
1013
  const asked = await this.deps.approvals.commandForCall(ctx.runId, call.id);
1007
1014
  const rootConversationId = ctx.parent?.rootConversationId ?? ctx.conversationId;
@@ -1095,10 +1102,11 @@ let ToolPipeline = class ToolPipeline {
1095
1102
  // the whole command the approval covers (the event keeps a clamped copy for display)
1096
1103
  command,
1097
1104
  // a relative path as it will be written: resolved against the working root
1105
+ // (every path a GenerateImage call writes, comma-separated)
1098
1106
  ...(kind === "write" && {
1099
- path: clipText(facts.workingRoot === undefined
1100
- ? textField(input, "file_path")
1101
- : pathAgainstWorkingRoot(textField(input, "file_path"), facts.workingRoot), 4096),
1107
+ path: clipText(writePathsOf(tool.key, input)
1108
+ .map((p) => facts.workingRoot === undefined ? p : pathAgainstWorkingRoot(p, facts.workingRoot))
1109
+ .join(", "), 4096),
1102
1110
  }),
1103
1111
  rule: verdict.rule,
1104
1112
  reason: clipText(verdict.reason, COMMAND_ASK_TEXT_MAX_CHARS),
@@ -266,8 +266,8 @@ export interface AgentTools {
266
266
  * - builtins: every {@link AGENT_BUILTIN_NAMES} entry registered here that can run (`unavailable`
267
267
  * says why not), `TaskOutput` / `TaskStop` / `TaskList` with `Bash`, `Agent` while its roster is not empty;
268
268
  * - extension tools: every tool registered by an extension loaded on this replica and enabled in
269
- * the org (`extension_org_configs.enabled`; required bootstrap plugins are enabled in every org,
270
- * `enabled.ts`), whose effective config for the org is valid (layering spec A §6) and that the
269
+ * the org (`extension_org_configs.enabled`; required bootstrap plugins and builtin plugins'
270
+ * extensions are enabled in every org, `enabled.ts`), whose effective config for the org is valid (layering spec A §6) and that the
271
271
  * org did not switch off (§7: the org's switch wins);
272
272
  * - connector tools: every enabled tool of every live, active connector of the org whose
273
273
  * connector extension is installed, with a valid key.
@@ -95,8 +95,8 @@ const builtinTool = (b, spec) => ({
95
95
  * - builtins: every {@link AGENT_BUILTIN_NAMES} entry registered here that can run (`unavailable`
96
96
  * says why not), `TaskOutput` / `TaskStop` / `TaskList` with `Bash`, `Agent` while its roster is not empty;
97
97
  * - extension tools: every tool registered by an extension loaded on this replica and enabled in
98
- * the org (`extension_org_configs.enabled`; required bootstrap plugins are enabled in every org,
99
- * `enabled.ts`), whose effective config for the org is valid (layering spec A §6) and that the
98
+ * the org (`extension_org_configs.enabled`; required bootstrap plugins and builtin plugins'
99
+ * extensions are enabled in every org, `enabled.ts`), whose effective config for the org is valid (layering spec A §6) and that the
100
100
  * org did not switch off (§7: the org's switch wins);
101
101
  * - connector tools: every enabled tool of every live, active connector of the org whose
102
102
  * connector extension is installed, with a valid key.
@@ -17,6 +17,7 @@ import { ModelsModule } from "../models/models.module.js";
17
17
  import { OrgLockModule } from "../orgs/org-lock.js";
18
18
  import { PlatformModule } from "../platform/platform.module.js";
19
19
  import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
20
+ import { ProvidersModule } from "../runtime/providers.js";
20
21
  import { RunJobsModule } from "../runtime/run-jobs.js";
21
22
  import { StepLogModule } from "../runtime/step-log.js";
22
23
  import { SubagentsModule } from "../runtime/subagents/subagents.service.js";
@@ -85,6 +86,8 @@ ToolsModule = __decorate([
85
86
  ConversationAccessModule,
86
87
  // the WebFetch extraction call: its purpose and step writes (its usage report owed with them)
87
88
  ModelsModule,
89
+ // `GenerateImage`'s availability resolves the image purpose's model in the org
90
+ ProvidersModule,
88
91
  StepLogModule,
89
92
  // a decision resumes its waiting run in the decision's transaction (`RunResume`)
90
93
  RunJobsModule,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.42",
3
+ "version": "0.1.0-rc.44",
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": {
@@ -65,7 +65,7 @@
65
65
  "yaml": "^2.9.1",
66
66
  "yauzl": "3.4.0",
67
67
  "zod": "^4.6.7",
68
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.31"
68
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.32"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",
@@ -74,8 +74,8 @@
74
74
  "@types/ws": "^8.18.2",
75
75
  "@types/yauzl": "3.4.0",
76
76
  "ws": "^8.22.0",
77
- "@capybara-hq/testing": "0.1.0-rc.24",
78
- "@capybara-hq/device": "0.1.0-rc.14"
77
+ "@capybara-hq/device": "0.1.0-rc.14",
78
+ "@capybara-hq/testing": "0.1.0-rc.25"
79
79
  },
80
80
  "scripts": {
81
81
  "build": "tsc -b"
@@ -0,0 +1,10 @@
1
+ -- Image generation through `ctx.models.generateImage` (image generation spec §9): a `model_usage`
2
+ -- row records the kind of call that made it, so its `usage.report` purpose is `image` or
3
+ -- `embedding` (the `purpose` column keeps the extension's own purpose name), how many images
4
+ -- the call produced, and the answer's output and cache tokens (an image model may bill output
5
+ -- tokens). Existing rows are embedding calls with no images and no output or cache tokens.
6
+ ALTER TABLE model_usage ADD COLUMN IF NOT EXISTS kind text NOT NULL DEFAULT 'embedding';
7
+ ALTER TABLE model_usage ADD COLUMN IF NOT EXISTS output_images integer NOT NULL DEFAULT 0;
8
+ ALTER TABLE model_usage ADD COLUMN IF NOT EXISTS output_tokens integer NOT NULL DEFAULT 0;
9
+ ALTER TABLE model_usage ADD COLUMN IF NOT EXISTS cache_read_tokens integer NOT NULL DEFAULT 0;
10
+ ALTER TABLE model_usage ADD COLUMN IF NOT EXISTS cache_write_tokens integer NOT NULL DEFAULT 0;