@capybara-hq/kernel 0.1.0-rc.114 → 0.1.0-rc.116
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.
- package/bootstrap.json +9 -9
- package/dist/admin/admin.schemas.d.ts +1 -0
- package/dist/agents/agents.controller.d.ts +13 -1
- package/dist/agents/agents.controller.js +24 -2
- package/dist/catalog/catalog.service.d.ts +11 -1
- package/dist/catalog/catalog.service.js +36 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/platform-components.js +13 -0
- package/dist/catalog/plugin-connectors.d.ts +35 -0
- package/dist/catalog/plugin-connectors.js +81 -0
- package/dist/channels/supervisor.d.ts +5 -1
- package/dist/channels/supervisor.js +17 -1
- package/dist/conversations/conversations.controller.d.ts +46 -14
- package/dist/conversations/conversations.controller.js +82 -47
- package/dist/conversations/conversations.service.d.ts +93 -59
- package/dist/conversations/conversations.service.js +255 -72
- package/dist/conversations/events.d.ts +39 -0
- package/dist/conversations/events.js +52 -2
- package/dist/conversations/inline-tokens.d.ts +87 -0
- package/dist/conversations/inline-tokens.js +154 -0
- package/dist/conversations/permission-profiles.controller.d.ts +14 -7
- package/dist/conversations/permission-profiles.controller.js +1 -5
- package/dist/conversations/prompt-suggestions.js +2 -4
- package/dist/conversations/queue.d.ts +0 -2
- package/dist/conversations/queue.service.js +9 -13
- package/dist/db/kernel-schema.d.ts +5 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.js +12 -0
- package/dist/evals/snapshot.js +4 -2
- package/dist/files/library-files.service.d.ts +13 -0
- package/dist/files/library-files.service.js +33 -6
- package/dist/identity/settings.d.ts +5 -0
- package/dist/identity/settings.js +4 -0
- package/dist/models/purposes.js +5 -0
- package/dist/net/safe-fetch.js +1 -1
- package/dist/orgs/settings.service.d.ts +2 -0
- package/dist/platform/exclusions.js +6 -1
- package/dist/platform/ops/org-settings.ops.js +1 -1
- package/dist/runtime/compaction-model.d.ts +57 -0
- package/dist/runtime/compaction-model.js +87 -0
- package/dist/runtime/compaction.service.d.ts +23 -8
- package/dist/runtime/compaction.service.js +15 -10
- package/dist/runtime/context/build.d.ts +7 -2
- package/dist/runtime/context/build.js +17 -6
- package/dist/runtime/context/compaction.d.ts +22 -5
- package/dist/runtime/context/compaction.js +35 -15
- package/dist/runtime/context/idle-compaction-rules.d.ts +17 -2
- package/dist/runtime/context/idle-compaction-rules.js +20 -5
- package/dist/runtime/idle-arm.d.ts +12 -2
- package/dist/runtime/idle-arm.js +66 -18
- package/dist/runtime/idle-compaction-jobs.d.ts +24 -3
- package/dist/runtime/idle-compaction.d.ts +11 -3
- package/dist/runtime/idle-compaction.js +61 -30
- package/dist/runtime/model-call.d.ts +52 -16
- package/dist/runtime/model-call.js +71 -24
- package/dist/runtime/run-finish.d.ts +12 -3
- package/dist/runtime/run-finish.js +14 -7
- package/dist/runtime/run-queue.d.ts +5 -2
- package/dist/runtime/run-queue.js +7 -4
- package/dist/runtime/run-steps.d.ts +4 -1
- package/dist/runtime/run-steps.js +9 -2
- package/dist/runtime/run-worker.js +4 -2
- package/dist/runtime/runtime.module.js +3 -0
- package/dist/sandbox/review/classifier.js +5 -1
- package/dist/tools/connector-content.controller.d.ts +6 -2
- package/dist/tools/connector-content.controller.js +13 -3
- package/dist/tools/connector-content.d.ts +55 -15
- package/dist/tools/connector-content.js +112 -54
- package/dist/tools/connectors.service.d.ts +3 -2
- package/dist/tools/connectors.service.js +6 -20
- package/dist/tools/mentionable-connectors.d.ts +88 -0
- package/dist/tools/mentionable-connectors.js +218 -0
- package/dist/tools/pipeline.js +43 -6
- package/dist/tools/specs.d.ts +13 -4
- package/dist/tools/specs.js +22 -8
- package/dist/tools/tools.module.js +7 -0
- package/package.json +3 -3
- package/src/migrations/0200_runs_idle_mode.sql +4 -0
- package/src/migrations/0201_tool_specs_text.sql +8 -0
package/dist/tools/pipeline.js
CHANGED
|
@@ -1598,9 +1598,10 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1598
1598
|
let loopbackNotes = [];
|
|
1599
1599
|
if (scoped?.loopback !== undefined) {
|
|
1600
1600
|
const lb = scoped.loopback;
|
|
1601
|
-
const
|
|
1601
|
+
const otherHosts = scoped.hosts.filter((h) => serviceHostKey(h.host) !== serviceHostKey(lb.host));
|
|
1602
|
+
const handled = await this.loopbackBlocked(ctx, call, tool, input, outKey, { deviceId: scoped.deviceId, loopback: lb, url: scoped.url, otherHosts }, attempt, keptResult, rerun.loopbackRerun === true, pre, callAudit);
|
|
1602
1603
|
if (handled.kind !== "none") {
|
|
1603
|
-
serviceHosts =
|
|
1604
|
+
serviceHosts = otherHosts;
|
|
1604
1605
|
if (handled.kind === "wait") {
|
|
1605
1606
|
if (hooks && hookBase) {
|
|
1606
1607
|
fireObserve(hooks, "tool.postExecute", { ...hookBase, isError: rendered.isError, content: handled.content, durationMs }, ctx.signal, this.deps.log);
|
|
@@ -2453,7 +2454,12 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2453
2454
|
* A device service's refusals (browser use spec §7.1): the extension whose service asked and
|
|
2454
2455
|
* the call's attempt. Only "always" is offered; once approved the call runs again.
|
|
2455
2456
|
*/
|
|
2456
|
-
service
|
|
2457
|
+
service,
|
|
2458
|
+
/**
|
|
2459
|
+
* Plan-only pass: compute the `network_blocked` event and every refused host's note without
|
|
2460
|
+
* opening a second network ask (used when a loopback ask already takes this call's ask slot).
|
|
2461
|
+
*/
|
|
2462
|
+
planOnly) {
|
|
2457
2463
|
const hosts = blockedEventHosts(report.blocked);
|
|
2458
2464
|
if (hosts.length === 0)
|
|
2459
2465
|
return { kind: "write", event: null, notes: [] };
|
|
@@ -2500,6 +2506,16 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2500
2506
|
const addressNote = plan.addressNote;
|
|
2501
2507
|
if (plan.ask.length === 0 || offer === undefined)
|
|
2502
2508
|
return { kind: "write", event, notes: plan.notes, addressNote };
|
|
2509
|
+
// plan-only pass (loopback ask takes this call's ask slot): keep every other refused host's
|
|
2510
|
+
// note without opening a second ask
|
|
2511
|
+
if (planOnly === true) {
|
|
2512
|
+
return {
|
|
2513
|
+
kind: "write",
|
|
2514
|
+
event,
|
|
2515
|
+
notes: [...plan.notes, serviceAskedNote(plan.ask.map((h) => h.host))],
|
|
2516
|
+
addressNote,
|
|
2517
|
+
};
|
|
2518
|
+
}
|
|
2503
2519
|
// one ask per call: a service call that ran again after its ask is not asked again; only a
|
|
2504
2520
|
// would-be ask is replaced, the plan's other notes (a host on the list, not yet applied) stay
|
|
2505
2521
|
if (service !== undefined &&
|
|
@@ -2755,8 +2771,29 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2755
2771
|
return { kind: "write", notes: [otherAskPendingNote([hp])] };
|
|
2756
2772
|
if ((run?.asks ?? 0) >= MAX_NETWORK_ASKS_PER_RUN)
|
|
2757
2773
|
return { kind: "write", notes: [tooManyNote([hp])] };
|
|
2758
|
-
|
|
2759
|
-
|
|
2774
|
+
// plan-only pass for other refused hosts reported alongside the loopback port, so their notes
|
|
2775
|
+
// and `network_blocked` event are kept when the loopback ask settles
|
|
2776
|
+
let otherEvent = null;
|
|
2777
|
+
let otherNotes = [];
|
|
2778
|
+
if (report.otherHosts.length > 0) {
|
|
2779
|
+
const other = await this.networkBlocked(ctx, call.id, toolKey, input, {
|
|
2780
|
+
deviceId: report.deviceId,
|
|
2781
|
+
blocked: report.otherHosts.map(({ host, layer }) => ({ host, port: 443, layer })),
|
|
2782
|
+
}, pre, callAudit, kept, undefined, undefined, {
|
|
2783
|
+
name: tool.source.kind === "plugin" ? tool.source.plugin : tool.key,
|
|
2784
|
+
attempt,
|
|
2785
|
+
url: report.url,
|
|
2786
|
+
}, true);
|
|
2787
|
+
if (other.kind === "write") {
|
|
2788
|
+
otherEvent = other.event;
|
|
2789
|
+
otherNotes = other.notes;
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
const keptWithOther = otherNotes.length === 0
|
|
2793
|
+
? kept
|
|
2794
|
+
: { ...kept, content: withNetworkNotes(kept.content, otherNotes) };
|
|
2795
|
+
const { content, outputId } = await this.keptContent(ctx, call.id, keptWithOther);
|
|
2796
|
+
const { text: _text, denialHint: _hint, ...rest } = keptWithOther;
|
|
2760
2797
|
const result = {
|
|
2761
2798
|
...rest,
|
|
2762
2799
|
content: clipKept(content),
|
|
@@ -2764,7 +2801,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2764
2801
|
};
|
|
2765
2802
|
// the service's call ran: its display-only events and tool.called now, the result once the
|
|
2766
2803
|
// ask settles
|
|
2767
|
-
const written = await this.writeResultIn(ctx, call.id, toolKey,
|
|
2804
|
+
const written = await this.writeResultIn(ctx, call.id, toolKey, keptWithOther, otherEvent !== null ? [...pre, otherEvent] : [...pre], callAudit, []);
|
|
2768
2805
|
if (written.length > 0)
|
|
2769
2806
|
await this.deps.eventLog.notify(ctx.conversationId, Math.max(...written.map((e) => e.seq)));
|
|
2770
2807
|
const ask = await this.deps.approvals.requestLoopback({
|
package/dist/tools/specs.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { ToolSpec } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* `
|
|
6
|
-
*
|
|
4
|
+
* Stores tool definitions by fingerprint in `capybara.tool_specs` (content-addressed: one row per
|
|
5
|
+
* fingerprint, never changed, except that a row written before `spec_text` existed gets it on the
|
|
6
|
+
* next write). `model_call` records only `{key, specHash}`; the definition lives here, so after a
|
|
7
|
+
* connector refresh or a plugin upgrade the definitions an earlier request used can still be read
|
|
8
|
+
* back and the request rebuilt from the log. `spec_text` keeps the JSON text as sent: `spec` is
|
|
9
|
+
* jsonb, which reorders keys, and a rebuilt request must serialize byte for byte like the original
|
|
10
|
+
* (a provider renders its tools from that JSON; a reordered schema misses the prompt cache).
|
|
7
11
|
*/
|
|
8
12
|
export declare function recordToolSpecs(
|
|
9
13
|
/** The pool or a transaction (a transaction is a Kysely handle too). */
|
|
@@ -11,5 +15,10 @@ db: KernelSchemaDb, specs: readonly {
|
|
|
11
15
|
specHash: string;
|
|
12
16
|
spec: ToolSpec;
|
|
13
17
|
}[]): Promise<void>;
|
|
14
|
-
/**
|
|
18
|
+
/** A stored definition: its JSON text as sent when recorded, else the jsonb value. */
|
|
19
|
+
export declare function storedToolSpec(row: {
|
|
20
|
+
spec: unknown;
|
|
21
|
+
spec_text: string | null;
|
|
22
|
+
}): ToolSpec;
|
|
23
|
+
/** The tool definition stored under a fingerprint ({@link storedToolSpec}); null when none. */
|
|
15
24
|
export declare function loadToolSpec(db: KernelSchemaDb, specHash: string): Promise<ToolSpec | null>;
|
package/dist/tools/specs.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* `
|
|
4
|
-
*
|
|
2
|
+
* Stores tool definitions by fingerprint in `capybara.tool_specs` (content-addressed: one row per
|
|
3
|
+
* fingerprint, never changed, except that a row written before `spec_text` existed gets it on the
|
|
4
|
+
* next write). `model_call` records only `{key, specHash}`; the definition lives here, so after a
|
|
5
|
+
* connector refresh or a plugin upgrade the definitions an earlier request used can still be read
|
|
6
|
+
* back and the request rebuilt from the log. `spec_text` keeps the JSON text as sent: `spec` is
|
|
7
|
+
* jsonb, which reorders keys, and a rebuilt request must serialize byte for byte like the original
|
|
8
|
+
* (a provider renders its tools from that JSON; a reordered schema misses the prompt cache).
|
|
5
9
|
*/
|
|
6
10
|
export async function recordToolSpecs(
|
|
7
11
|
/** The pool or a transaction (a transaction is a Kysely handle too). */
|
|
@@ -15,19 +19,29 @@ db, specs) {
|
|
|
15
19
|
// 按指纹排序插入:并发事务插入同一批指纹时加锁顺序一致,不会互相死锁
|
|
16
20
|
const rows = [...unique]
|
|
17
21
|
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
18
|
-
.map(([hash, spec]) =>
|
|
22
|
+
.map(([hash, spec]) => {
|
|
23
|
+
const text = JSON.stringify(spec);
|
|
24
|
+
return { spec_hash: hash, spec: text, spec_text: text };
|
|
25
|
+
});
|
|
19
26
|
await db
|
|
20
27
|
.insertInto("tool_specs")
|
|
21
28
|
.values(rows)
|
|
22
|
-
.onConflict((oc) => oc
|
|
29
|
+
.onConflict((oc) => oc
|
|
30
|
+
.column("spec_hash")
|
|
31
|
+
.doUpdateSet((eb) => ({ spec_text: eb.ref("excluded.spec_text") }))
|
|
32
|
+
.where("tool_specs.spec_text", "is", null))
|
|
23
33
|
.execute();
|
|
24
34
|
}
|
|
25
|
-
/**
|
|
35
|
+
/** A stored definition: its JSON text as sent when recorded, else the jsonb value. */
|
|
36
|
+
export function storedToolSpec(row) {
|
|
37
|
+
return (row.spec_text !== null ? JSON.parse(row.spec_text) : row.spec);
|
|
38
|
+
}
|
|
39
|
+
/** The tool definition stored under a fingerprint ({@link storedToolSpec}); null when none. */
|
|
26
40
|
export async function loadToolSpec(db, specHash) {
|
|
27
41
|
const row = await db
|
|
28
42
|
.selectFrom("tool_specs")
|
|
29
|
-
.select("spec")
|
|
43
|
+
.select(["spec", "spec_text"])
|
|
30
44
|
.where("spec_hash", "=", specHash)
|
|
31
45
|
.executeTakeFirst();
|
|
32
|
-
return row ? row
|
|
46
|
+
return row ? storedToolSpec(row) : null;
|
|
33
47
|
}
|
|
@@ -5,6 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Module } from "@nestjs/common";
|
|
8
|
+
import { AgentLookupModule } from "../agents/agent-lookup.js";
|
|
8
9
|
import { AutomationStoreModule } from "../automations/store.module.js";
|
|
9
10
|
import { BackgroundModule } from "../background/background.module.js";
|
|
10
11
|
import { ConversationAccessModule } from "../conversations/access.js";
|
|
@@ -48,6 +49,7 @@ import { ConnectorsService } from "./connectors.service.js";
|
|
|
48
49
|
import { CredentialsModule } from "./credentials.module.js";
|
|
49
50
|
import { ToolDrift } from "./drift.js";
|
|
50
51
|
import { ConversationToolInfo, OrgExtensionTools } from "./info.js";
|
|
52
|
+
import { MentionableConnectorsService } from "./mentionable-connectors.js";
|
|
51
53
|
import { OAuthFlow } from "./oauth/flow.js";
|
|
52
54
|
import { OrgToolSwitches } from "./org-tool-switches.js";
|
|
53
55
|
import { ToolOutputs } from "./outputs.js";
|
|
@@ -121,6 +123,8 @@ ToolsModule = __decorate([
|
|
|
121
123
|
AutomationStoreModule,
|
|
122
124
|
// connector credentials (also the git gateway's, without importing this module)
|
|
123
125
|
CredentialsModule,
|
|
126
|
+
// the agent the mentionable connectors are listed for, as the viewer may see it
|
|
127
|
+
AgentLookupModule,
|
|
124
128
|
],
|
|
125
129
|
providers: [
|
|
126
130
|
PermissionApprovalJobs,
|
|
@@ -150,6 +154,8 @@ ToolsModule = __decorate([
|
|
|
150
154
|
ConversationToolInfo,
|
|
151
155
|
OrgExtensionTools,
|
|
152
156
|
OrgToolSwitches,
|
|
157
|
+
// the composer's `@` menu: the connectors an agent can be pointed at
|
|
158
|
+
MentionableConnectorsService,
|
|
153
159
|
],
|
|
154
160
|
exports: [
|
|
155
161
|
PermissionApprovalJobs,
|
|
@@ -171,6 +177,7 @@ ToolsModule = __decorate([
|
|
|
171
177
|
ConversationToolInfo,
|
|
172
178
|
OrgExtensionTools,
|
|
173
179
|
OrgToolSwitches,
|
|
180
|
+
MentionableConnectorsService,
|
|
174
181
|
],
|
|
175
182
|
})
|
|
176
183
|
], ToolsModule);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/kernel",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.116",
|
|
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.
|
|
69
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.91"
|
|
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.
|
|
78
|
+
"@capybara-hq/testing": "0.1.0-rc.50"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"build": "tsc -b"
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
-- Compaction model (compaction model spec §6.1): the mode of an idle compact run, decided when
|
|
2
|
+
-- its job was armed; null on every other run.
|
|
3
|
+
ALTER TABLE runs ADD COLUMN IF NOT EXISTS idle_mode text NULL
|
|
4
|
+
CONSTRAINT runs_idle_mode_check CHECK (idle_mode IN ('cache', 'compaction_model'));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- The exact JSON text of a tool definition as the runtime sent it. `spec` is jsonb, which reorders
|
|
2
|
+
-- object keys (shorter keys first), so a request rebuilt from it (an eval replay, the prompt
|
|
3
|
+
-- suggestion's side request) serialized its input schemas in another key order than the original
|
|
4
|
+
-- request: a provider renders the tools from that JSON, so the rebuilt prompt differed and missed
|
|
5
|
+
-- the prompt cache from the tools on. Readers prefer `spec_text`; null on rows written before it
|
|
6
|
+
-- (filled by the next write of the same fingerprint).
|
|
7
|
+
|
|
8
|
+
ALTER TABLE tool_specs ADD COLUMN IF NOT EXISTS spec_text text;
|