@capybara-hq/kernel 0.1.0-rc.135 → 0.1.0-rc.137
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/dist/admin/admin.module.js +3 -0
- package/dist/admin/audit-log.service.d.ts +96 -12
- package/dist/admin/audit-log.service.js +508 -44
- package/dist/admin/audit-targets.d.ts +17 -0
- package/dist/admin/audit-targets.js +84 -0
- package/dist/admin/audit.controller.d.ts +12 -9
- package/dist/admin/audit.controller.js +29 -8
- package/dist/admin/audit.schemas.d.ts +20 -4
- package/dist/admin/audit.schemas.js +42 -17
- package/dist/admin/health.service.d.ts +2 -2
- package/dist/admin/health.service.js +6 -2
- package/dist/agents/templates.js +3 -10
- package/dist/app.d.ts +3 -1
- package/dist/app.js +1 -0
- package/dist/automations/automations.service.js +4 -5
- package/dist/catalog/catalog-content.d.ts +1 -1
- package/dist/catalog/catalog-content.js +17 -22
- package/dist/catalog/catalog-items.d.ts +5 -10
- package/dist/catalog/catalog-items.js +27 -51
- package/dist/catalog/catalog-scope.service.d.ts +4 -2
- package/dist/catalog/catalog-scope.service.js +105 -141
- package/dist/catalog/catalog.module.js +2 -0
- package/dist/catalog/catalog.service.d.ts +3 -3
- package/dist/catalog/catalog.service.js +33 -8
- package/dist/catalog/cli.js +17 -0
- package/dist/catalog/component-promotion.js +8 -4
- package/dist/catalog/component-scope.service.d.ts +3 -1
- package/dist/catalog/component-scope.service.js +101 -140
- package/dist/catalog/component-state.d.ts +10 -8
- package/dist/catalog/component-state.js +42 -30
- package/dist/catalog/dependency-edges.d.ts +25 -0
- package/dist/catalog/dependency-edges.js +125 -0
- package/dist/catalog/install-status.d.ts +2 -3
- package/dist/catalog/install-status.js +2 -3
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +3 -1
- package/dist/catalog/org-catalog.service.js +33 -94
- package/dist/catalog/org-intent.d.ts +43 -0
- package/dist/catalog/org-intent.js +184 -0
- package/dist/catalog/owned-items.d.ts +1 -1
- package/dist/catalog/owned-items.js +9 -29
- package/dist/catalog/ownership.d.ts +2 -3
- package/dist/catalog/ownership.js +10 -28
- package/dist/catalog/platform-components.d.ts +3 -1
- package/dist/catalog/platform-components.js +9 -1
- package/dist/catalog/plugin-import.js +12 -16
- package/dist/catalog/plugin-install.d.ts +3 -4
- package/dist/catalog/plugin-install.js +25 -49
- package/dist/catalog/plugin-upgrade.d.ts +2 -2
- package/dist/catalog/plugin-upgrade.js +18 -34
- package/dist/catalog/request-rules.js +20 -8
- package/dist/catalog/scope-orgs.js +2 -7
- package/dist/catalog/scope-state.d.ts +6 -6
- package/dist/catalog/scope-state.js +24 -43
- package/dist/catalog/scope-sync.d.ts +0 -2
- package/dist/catalog/scope-sync.js +11 -39
- package/dist/catalog/scope-writer.d.ts +78 -0
- package/dist/catalog/scope-writer.js +181 -0
- package/dist/catalog/unshare.js +8 -41
- package/dist/channels/connections.service.js +6 -6
- package/dist/channels/supervisor.js +3 -7
- package/dist/client/client-access.service.js +2 -12
- package/dist/config/schema.d.ts +6 -0
- package/dist/config/schema.js +29 -1
- package/dist/conversations/access.d.ts +15 -7
- package/dist/conversations/access.js +59 -10
- package/dist/conversations/conversation-agent.d.ts +18 -0
- package/dist/conversations/conversation-agent.js +23 -0
- package/dist/conversations/conversation-ref.d.ts +3 -2
- package/dist/conversations/conversation-ref.js +6 -1
- package/dist/conversations/conversations.controller.d.ts +28 -5
- package/dist/conversations/conversations.controller.js +99 -10
- package/dist/conversations/conversations.module.js +10 -0
- package/dist/conversations/conversations.schemas.d.ts +6 -0
- package/dist/conversations/conversations.schemas.js +15 -0
- package/dist/conversations/conversations.service.d.ts +125 -21
- package/dist/conversations/conversations.service.js +260 -90
- package/dist/conversations/event-log.d.ts +9 -1
- package/dist/conversations/event-log.js +2 -0
- package/dist/conversations/events.d.ts +57 -0
- package/dist/conversations/events.js +73 -1
- package/dist/conversations/external/external-calls.d.ts +75 -0
- package/dist/conversations/external/external-calls.js +91 -0
- package/dist/conversations/external/external-calls.processor.d.ts +45 -0
- package/dist/conversations/external/external-calls.processor.js +144 -0
- package/dist/conversations/external/external-conversations.service.d.ts +266 -0
- package/dist/conversations/external/external-conversations.service.js +1138 -0
- package/dist/conversations/external/external.schemas.d.ts +63 -0
- package/dist/conversations/external/external.schemas.js +52 -0
- package/dist/conversations/external/token.d.ts +6 -0
- package/dist/conversations/external/token.js +6 -0
- package/dist/conversations/permission-profile-store.d.ts +4 -1
- package/dist/conversations/permission-profiles.controller.d.ts +33 -9
- package/dist/conversations/permission-profiles.controller.js +86 -6
- package/dist/conversations/prompt-suggestions.js +2 -1
- package/dist/conversations/queue.js +2 -1
- package/dist/conversations/titles.js +4 -3
- package/dist/ctx/create-ctx.d.ts +9 -2
- package/dist/ctx/create-ctx.js +47 -62
- package/dist/ctx/guard-db.d.ts +6 -0
- package/dist/ctx/guard-db.js +55 -0
- package/dist/db/extension-handoff-schema.d.ts +1 -1
- package/dist/db/extension-handoff-schema.js +48 -10
- package/dist/db/extension-schema-transfer.js +5 -2
- package/dist/db/kernel-schema.d.ts +42 -5
- package/dist/device-access/host-services.d.ts +2 -2
- package/dist/device-access/host-services.js +8 -8
- package/dist/device-access/person-handles.d.ts +16 -7
- package/dist/device-access/person-handles.js +14 -9
- package/dist/devices/conversation-devices.d.ts +5 -0
- package/dist/devices/conversation-devices.js +16 -0
- package/dist/erasure/org-catalog.js +2 -2
- package/dist/erasure/org-rules.js +5 -0
- package/dist/errors.d.ts +34 -0
- package/dist/errors.js +34 -0
- package/dist/evals/snapshot.js +3 -1
- package/dist/evals/trajectory.service.d.ts +2 -2
- package/dist/evals/trajectory.service.js +11 -7
- package/dist/extensions/admin-ops.d.ts +9 -5
- package/dist/extensions/admin-ops.js +52 -8
- package/dist/extensions/admin-view.js +1 -4
- package/dist/extensions/bootstrap.js +4 -1
- package/dist/extensions/cli.js +1 -0
- package/dist/extensions/effective-config.js +1 -4
- package/dist/extensions/enabled.d.ts +23 -29
- package/dist/extensions/enabled.js +141 -62
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/host.d.ts +71 -45
- package/dist/extensions/host.js +454 -128
- package/dist/extensions/installs.d.ts +9 -0
- package/dist/extensions/installs.js +23 -0
- package/dist/extensions/isolated/admission.d.ts +10 -0
- package/dist/extensions/isolated/admission.js +206 -0
- package/dist/extensions/isolated/authorization.d.ts +37 -0
- package/dist/extensions/isolated/authorization.js +146 -0
- package/dist/extensions/isolated/broker.d.ts +15 -0
- package/dist/extensions/isolated/broker.js +452 -0
- package/dist/extensions/isolated/child-protocol.d.ts +84 -0
- package/dist/extensions/isolated/child-protocol.js +21 -0
- package/dist/extensions/isolated/child-registration.d.ts +22 -0
- package/dist/extensions/isolated/child-registration.js +152 -0
- package/dist/extensions/isolated/child-session.d.ts +6 -0
- package/dist/extensions/isolated/child-session.js +343 -0
- package/dist/extensions/isolated/child-streams.d.ts +4 -0
- package/dist/extensions/isolated/child-streams.js +142 -0
- package/dist/extensions/isolated/child.d.ts +1 -0
- package/dist/extensions/isolated/child.js +10 -0
- package/dist/extensions/isolated/configured-package.d.ts +15 -0
- package/dist/extensions/isolated/configured-package.js +73 -0
- package/dist/extensions/isolated/lanes.d.ts +100 -0
- package/dist/extensions/isolated/lanes.js +699 -0
- package/dist/extensions/isolated/postgres-gate.d.ts +14 -0
- package/dist/extensions/isolated/postgres-gate.js +255 -0
- package/dist/extensions/isolated/revision.d.ts +32 -0
- package/dist/extensions/isolated/revision.js +358 -0
- package/dist/extensions/isolated/rpc-frame.d.ts +50 -0
- package/dist/extensions/isolated/rpc-frame.js +193 -0
- package/dist/extensions/isolated/rpc.d.ts +66 -0
- package/dist/extensions/isolated/rpc.js +314 -0
- package/dist/extensions/isolated/sandbox.d.ts +35 -0
- package/dist/extensions/isolated/sandbox.js +372 -0
- package/dist/extensions/isolated/tier.d.ts +6 -0
- package/dist/extensions/isolated/tier.js +45 -0
- package/dist/extensions/ledger.d.ts +1 -1
- package/dist/extensions/lifecycle-topics.d.ts +1 -0
- package/dist/extensions/lifecycle-topics.js +1 -0
- package/dist/extensions/lifecycle.d.ts +3 -1
- package/dist/extensions/lifecycle.js +32 -5
- package/dist/extensions/locks.d.ts +2 -0
- package/dist/extensions/locks.js +7 -0
- package/dist/extensions/org-config.d.ts +17 -27
- package/dist/extensions/org-config.js +114 -129
- package/dist/extensions/permission-view.d.ts +3 -1
- package/dist/extensions/permission-view.js +4 -1
- package/dist/extensions/plugin-guides.d.ts +5 -10
- package/dist/extensions/plugin-guides.js +18 -37
- package/dist/extensions/plugin-icons.d.ts +3 -21
- package/dist/extensions/plugin-icons.js +9 -44
- package/dist/extensions/plugin-items.d.ts +10 -30
- package/dist/extensions/plugin-items.js +32 -73
- package/dist/extensions/point-defaults.d.ts +13 -21
- package/dist/extensions/point-defaults.js +32 -72
- package/dist/extensions/point-serving.d.ts +56 -0
- package/dist/extensions/point-serving.js +120 -0
- package/dist/extensions/source-intent.d.ts +14 -0
- package/dist/extensions/source-intent.js +77 -0
- package/dist/inbox/inbox-items.service.d.ts +11 -0
- package/dist/inbox/inbox-items.service.js +39 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/infra/database/database.module.js +6 -1
- package/dist/infra/database/kernel-db.d.ts +3 -1
- package/dist/infra/database/kernel-db.js +4 -0
- package/dist/infra/outbox/registry.d.ts +70 -0
- package/dist/infra/outbox/registry.js +44 -0
- package/dist/infra/paging/paged-read.d.ts +56 -0
- package/dist/infra/paging/paged-read.js +78 -0
- package/dist/infra/queue/queue-names.d.ts +1 -1
- package/dist/infra/queue/queue-names.js +1 -0
- package/dist/kernel.d.ts +3 -2
- package/dist/kernel.js +21 -2
- package/dist/kernel.module.js +4 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +22 -12
- package/dist/lifecycle/tokens.d.ts +8 -0
- package/dist/lifecycle/tokens.js +2 -0
- package/dist/orgs/directory-sync.js +1 -4
- package/dist/platform/exclusions.js +10 -0
- package/dist/platform/ops/admin.ops.js +14 -3
- package/dist/platform/ops/conversations.ops.d.ts +8 -1
- package/dist/platform/ops/conversations.ops.js +52 -14
- package/dist/platform/ops/orgs.ops.js +13 -3
- package/dist/plugin-reads/plugin-reads.service.js +4 -1
- package/dist/push/recipients.js +5 -2
- package/dist/retention/worker.js +2 -1
- package/dist/roles/worker-role.d.ts +3 -1
- package/dist/roles/worker-role.js +8 -2
- package/dist/roles/worker.module.js +3 -0
- package/dist/runtime/context/build.js +8 -0
- package/dist/runtime/context/compaction.js +7 -0
- package/dist/runtime/idle-arm.js +3 -1
- package/dist/runtime/idle-compaction.js +2 -1
- package/dist/runtime/run-finish.js +2 -1
- package/dist/runtime/run-jobs.js +2 -1
- package/dist/runtime/run-queue.js +4 -2
- package/dist/runtime/run-worker.js +5 -2
- package/dist/runtime/stream.js +10 -0
- package/dist/runtime/usage-report.js +2 -1
- package/dist/runtime/waits.js +2 -1
- package/dist/setup/setup-checks.service.js +3 -2
- package/dist/skills/usable.js +41 -30
- package/dist/themes/theme-state.js +3 -3
- package/dist/tools/approvals.service.js +6 -2
- package/dist/tools/builtins/skill-load.js +3 -2
- package/dist/tools/registry.d.ts +1 -1
- package/dist/tools/registry.js +1 -1
- package/dist/tools/tool-watch.service.js +3 -1
- package/package.json +3 -3
- package/src/migrations/0227_external_conversations.sql +33 -0
- package/src/migrations/0228_extension_org_switches.sql +56 -0
- package/src/migrations/0229_catalog_dependency_edges.sql +17 -0
- package/src/migrations/0230_audit_filter_idx.sql +18 -0
package/dist/skills/usable.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { skillDisabled } from "../agents/definition.js";
|
|
2
2
|
import { componentOn, platformBuiltin } from "../catalog/component-state.js";
|
|
3
|
-
import {
|
|
3
|
+
import { orgUsable } from "../catalog/org-intent.js";
|
|
4
4
|
/** The `source` prefix of a platform skill version in a snapshot or an invocation record. */
|
|
5
5
|
export const PLATFORM_SOURCE = "platform:";
|
|
6
6
|
/** The snapshot `source` of a platform skill version stored at `prefix` (in `deployment/`). */
|
|
@@ -41,14 +41,25 @@ async function platformRowsOn(db, orgId, ids) {
|
|
|
41
41
|
"c.owner_org_id as item_owner",
|
|
42
42
|
"p.owner_org_id",
|
|
43
43
|
"p.shareable",
|
|
44
|
+
orgUsable(db, orgId, eb.ref("p.catalog_item_id")).as("plugin_usable"),
|
|
44
45
|
eb
|
|
45
|
-
.
|
|
46
|
-
.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
.or([
|
|
47
|
+
eb.exists(eb
|
|
48
|
+
.selectFrom("catalog_item_org_switches as ps")
|
|
49
|
+
.select("ps.item_id")
|
|
50
|
+
.whereRef("ps.item_id", "=", "p.catalog_item_id")
|
|
51
|
+
.where("ps.org_id", "=", orgId)
|
|
52
|
+
.where("ps.enabled", "=", true)),
|
|
53
|
+
eb.and([
|
|
54
|
+
eb("c.scope", "=", "named"),
|
|
55
|
+
eb.exists(eb
|
|
56
|
+
.selectFrom("catalog_item_scope_orgs as pl")
|
|
57
|
+
.select("pl.item_id")
|
|
58
|
+
.whereRef("pl.item_id", "=", "p.catalog_item_id")
|
|
59
|
+
.where("pl.org_id", "=", orgId)),
|
|
60
|
+
]),
|
|
61
|
+
])
|
|
62
|
+
.as("plugin_associated"),
|
|
52
63
|
eb
|
|
53
64
|
.exists(eb
|
|
54
65
|
.selectFrom("component_scope_orgs as l")
|
|
@@ -69,28 +80,28 @@ async function platformRowsOn(db, orgId, ids) {
|
|
|
69
80
|
.where("p.disabled", "=", false);
|
|
70
81
|
if (ids !== undefined)
|
|
71
82
|
q = q.where("p.id", "in", [...ids]);
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
// A foreign skill stays available after unsharing only through an explicit association.
|
|
84
|
+
// The parent plugin's implicit defaults cannot grant access to another org's skill.
|
|
85
|
+
return (await q.execute()).filter((r) => {
|
|
86
|
+
const admitted = r.owner_org_id === null ||
|
|
87
|
+
r.owner_org_id === orgId ||
|
|
88
|
+
r.shareable ||
|
|
89
|
+
Boolean(r.listed) ||
|
|
90
|
+
(r.plugin_usable && Boolean(r.plugin_associated)) ||
|
|
91
|
+
r.switch === true;
|
|
92
|
+
return (admitted &&
|
|
93
|
+
componentOn({ scopeMode: r.scope_mode, scope: r.scope, disabled: false, itemId: r.catalog_item_id }, r.catalog_item_id === null
|
|
94
|
+
? null
|
|
95
|
+
: {
|
|
96
|
+
live: r.item_id !== null,
|
|
97
|
+
disabled: r.item_disabled === true,
|
|
98
|
+
builtin: platformBuiltin({ builtin: r.item_builtin, owner_org_id: r.item_owner }),
|
|
99
|
+
// the plugin's own scope and list do not decide whether a component is on
|
|
100
|
+
scope: "optional",
|
|
101
|
+
listed: false,
|
|
102
|
+
usable: r.plugin_usable,
|
|
103
|
+
}, Boolean(r.listed), r.switch ?? null));
|
|
104
|
+
});
|
|
94
105
|
}
|
|
95
106
|
/**
|
|
96
107
|
* The ids among `ids` of the platform skills on in the org (see {@link platformOn}), whatever the
|
|
@@ -154,7 +154,7 @@ export async function themesOnIn(db, orgId) {
|
|
|
154
154
|
const comps = await loadComponents(db, "theme");
|
|
155
155
|
if (comps.length === 0)
|
|
156
156
|
return [];
|
|
157
|
-
const st = await loadScopeState(db, "theme", comps);
|
|
157
|
+
const st = await loadScopeState(db, "theme", comps, orgId);
|
|
158
158
|
return comps.filter((c) => onIn(st, c, orgId));
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
@@ -251,7 +251,7 @@ export async function assertPlatformDefaultEligible(db, id) {
|
|
|
251
251
|
export async function assertThemeOnIn(db, orgId, id) {
|
|
252
252
|
await lockThemeShared(db, id);
|
|
253
253
|
const [c] = await loadComponents(db, "theme", { ids: [id] });
|
|
254
|
-
const st = c && (await loadScopeState(db, "theme", [c]));
|
|
254
|
+
const st = c && (await loadScopeState(db, "theme", [c], orgId));
|
|
255
255
|
if (!c || !st || !onIn(st, c, orgId))
|
|
256
256
|
throw themeNotAvailable(id, "in this organization");
|
|
257
257
|
}
|
|
@@ -260,7 +260,7 @@ export async function themeOnIn(db, orgId, id) {
|
|
|
260
260
|
const [c] = await loadComponents(db, "theme", { ids: [id] });
|
|
261
261
|
if (!c)
|
|
262
262
|
return false;
|
|
263
|
-
return onIn(await loadScopeState(db, "theme", [c]), c, orgId);
|
|
263
|
+
return onIn(await loadScopeState(db, "theme", [c], orgId), c, orgId);
|
|
264
264
|
}
|
|
265
265
|
/** Whether theme `id` is on in at least one of the person's live orgs. */
|
|
266
266
|
export async function themeOnForAccount(db, accountId, id) {
|
|
@@ -15,6 +15,7 @@ import { normalizeStoredDefinition } from "../agents/definition.js";
|
|
|
15
15
|
import { GIT_GRANT_SPEC_HASH, gitGrantRefusal, gitPushGrantKey, grantRefusalOf, NETWORK_GRANT_PREFIX, NETWORK_GRANT_SPEC_HASH, networkGrantRefusal, normalizeGitRepo, } from "../automations/grant-rules.js";
|
|
16
16
|
import { AutomationStore } from "../automations/store.js";
|
|
17
17
|
import { unattendedRunOf, unattendedTaskRunOf } from "../automations/unattended.js";
|
|
18
|
+
import { agentIdOf } from "../conversations/conversation-agent.js";
|
|
18
19
|
import { EventLog } from "../conversations/event-log.js";
|
|
19
20
|
import { COMMAND_ASK_TEXT_MAX_CHARS, GIT_ASK_MAX_REFS, GIT_REF_MAX_CHARS, NETWORK_ASK_MAX_HOSTS, NETWORK_HOST_MAX_CHARS, SECURE_INPUT_MAX_FIELDS, } from "../conversations/events.js";
|
|
20
21
|
import { ConversationLeakCheck } from "../conversations/leak-check.js";
|
|
@@ -1675,7 +1676,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1675
1676
|
.values({
|
|
1676
1677
|
org_id: orgId,
|
|
1677
1678
|
account_id: before.requestedFor,
|
|
1678
|
-
|
|
1679
|
+
// a run's conversation always has an agent (an external one has no runs)
|
|
1680
|
+
agent_id: agentIdOf(ctx),
|
|
1679
1681
|
tool_key: before.toolKey,
|
|
1680
1682
|
spec_hash: hash,
|
|
1681
1683
|
connector_id: connectorId,
|
|
@@ -2432,7 +2434,9 @@ let ApprovalsService = class ApprovalsService {
|
|
|
2432
2434
|
"conversations.parent_conversation_id",
|
|
2433
2435
|
])
|
|
2434
2436
|
.where("runs.id", "in", [...new Set(recs.map((r) => r.runId))])
|
|
2435
|
-
.execute()
|
|
2437
|
+
.execute()
|
|
2438
|
+
// a run's conversation always has an agent (an external one has no runs)
|
|
2439
|
+
.then((rows) => rows.map((r) => ({ ...r, agent_id: agentIdOf(r) })));
|
|
2436
2440
|
const ctx = new Map(ctxRows.map((r) => [r.id, r]));
|
|
2437
2441
|
// a sub-agent's approval links to the root conversation of its tree (agent map spec §7)
|
|
2438
2442
|
const roots = new Map();
|
|
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { parseSkillMd, renderSkillBody, SKILL_ENTRY_FILE, SKILL_INVOCATION_LIMITS, SKILLS_SANDBOX_ROOT, skillDigest, skillInvocation, skillSandboxDir, skillSandboxPath, ToolError, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
|
|
3
3
|
import { sql } from "kysely";
|
|
4
4
|
import { normalizeStoredDefinition } from "../../agents/definition.js";
|
|
5
|
+
import { agentIdOf } from "../../conversations/conversation-agent.js";
|
|
5
6
|
import { ApiError } from "../../errors.js";
|
|
6
7
|
import { callableProjectSkills, projectSkillName, projectSkillOf, } from "../../runtime/context/project-root.js";
|
|
7
8
|
import { latestInvocation } from "../../runtime/context/skills.js";
|
|
@@ -292,7 +293,7 @@ async function runAgent(db, ctx) {
|
|
|
292
293
|
.where("conversations.org_id", "=", ctx.orgId)
|
|
293
294
|
.executeTakeFirst();
|
|
294
295
|
return row
|
|
295
|
-
? { agentId: row
|
|
296
|
+
? { agentId: agentIdOf(row), definition: normalizeStoredDefinition(row.definition) }
|
|
296
297
|
: undefined;
|
|
297
298
|
}
|
|
298
299
|
/**
|
|
@@ -323,7 +324,7 @@ async function invocationScope(db, ctx) {
|
|
|
323
324
|
.executeTakeFirst();
|
|
324
325
|
return row
|
|
325
326
|
? {
|
|
326
|
-
agentId: row
|
|
327
|
+
agentId: agentIdOf(row),
|
|
327
328
|
definition: normalizeStoredDefinition(row.definition),
|
|
328
329
|
conversationId: dispatch.parentConversationId,
|
|
329
330
|
}
|
package/dist/tools/registry.d.ts
CHANGED
|
@@ -359,7 +359,7 @@ export interface AgentTools {
|
|
|
359
359
|
* - builtins: every {@link AGENT_BUILTIN_NAMES} entry registered here that can run (`unavailable`
|
|
360
360
|
* says why not), `TaskOutput` / `TaskStop` / `TaskList` with `Bash`, `Agent` while its roster is not empty;
|
|
361
361
|
* - extension tools: every tool registered by an extension loaded on this replica and enabled in
|
|
362
|
-
* the org (
|
|
362
|
+
* the org (required bootstrap plugins and builtin plugins'
|
|
363
363
|
* extensions are enabled in every org, `enabled.ts`), whose effective config for the org is valid (layering spec A §6) and that the
|
|
364
364
|
* org did not switch off (§7: the org's switch wins);
|
|
365
365
|
* - connector tools: every enabled tool of every live, active, `ready` connector of the org
|
package/dist/tools/registry.js
CHANGED
|
@@ -110,7 +110,7 @@ const builtinTool = (b, spec) => ({
|
|
|
110
110
|
* - builtins: every {@link AGENT_BUILTIN_NAMES} entry registered here that can run (`unavailable`
|
|
111
111
|
* says why not), `TaskOutput` / `TaskStop` / `TaskList` with `Bash`, `Agent` while its roster is not empty;
|
|
112
112
|
* - extension tools: every tool registered by an extension loaded on this replica and enabled in
|
|
113
|
-
* the org (
|
|
113
|
+
* the org (required bootstrap plugins and builtin plugins'
|
|
114
114
|
* extensions are enabled in every org, `enabled.ts`), whose effective config for the org is valid (layering spec A §6) and that the
|
|
115
115
|
* org did not switch off (§7: the org's switch wins);
|
|
116
116
|
* - connector tools: every enabled tool of every live, active, `ready` connector of the org
|
|
@@ -11,6 +11,7 @@ import { parseToolKey } from "@capybara-hq/plugin-sdk";
|
|
|
11
11
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
12
12
|
import { DelayedError } from "bullmq";
|
|
13
13
|
import { sql } from "kysely";
|
|
14
|
+
import { agentIdOf } from "../conversations/conversation-agent.js";
|
|
14
15
|
import { EffectiveConfigs } from "../extensions/effective-config.js";
|
|
15
16
|
import { isExtensionEnabled } from "../extensions/enabled.js";
|
|
16
17
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -151,7 +152,8 @@ let ToolWatchService = class ToolWatchService {
|
|
|
151
152
|
...extensionCallContext({
|
|
152
153
|
orgId: row.org_id,
|
|
153
154
|
accountId: row.trigger_account_id,
|
|
154
|
-
|
|
155
|
+
// a question belongs to a run: its conversation has an agent (an external one has none)
|
|
156
|
+
agentId: agentIdOf(row),
|
|
155
157
|
conversationId: row.conversation_id,
|
|
156
158
|
rootConversationId,
|
|
157
159
|
runId: row.run_id,
|
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.137",
|
|
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": {
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"yaml": "^2.9.1",
|
|
71
71
|
"yauzl": "3.4.0",
|
|
72
72
|
"zod": "^4.6.7",
|
|
73
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
73
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.100"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@langchain/langgraph-checkpoint-validation": "^1.2.0",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"@types/yauzl": "3.4.0",
|
|
83
83
|
"pg-cursor": "^2.22.1",
|
|
84
84
|
"ws": "^8.22.0",
|
|
85
|
-
"@capybara-hq/testing": "0.1.0-rc.
|
|
85
|
+
"@capybara-hq/testing": "0.1.0-rc.57"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
88
|
"build": "tsc -b"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
-- External conversations (local agents spec 2026-12-01, Part 2): a conversation the person holds
|
|
2
|
+
-- with a `conversation-target@1` target (a local agent on their device). The kernel mirrors it and
|
|
3
|
+
-- never runs it, so it has no agent.
|
|
4
|
+
-- - kind gains 'external'; agent_id becomes nullable: null exactly for 'external', which names its
|
|
5
|
+
-- target in `external` ({ extension, targetKey, label }) instead (one CHECK).
|
|
6
|
+
-- - external_state: what the target last reported (running / waiting / idle / ended).
|
|
7
|
+
-- - external_delivered_seq: the highest `external_user_message.deliverySeq` handed to the target;
|
|
8
|
+
-- -1 (written only by the kernel) marks a conversation whose `start` was dropped after its retries.
|
|
9
|
+
-- Additive only: the new columns have a default or are nullable and the CHECKs admit every
|
|
10
|
+
-- existing row, so a running older version keeps working during a rolling upgrade (it never
|
|
11
|
+
-- writes 'external' and always writes an agent).
|
|
12
|
+
-- The widened kind CHECK is re-added NOT VALID: the old CHECK implies the new one, so existing
|
|
13
|
+
-- rows need no scan. The shape CHECK is new, so it is added NOT VALID and then validated: the scan
|
|
14
|
+
-- proves every existing row (all of them have an agent and no target) fits it.
|
|
15
|
+
|
|
16
|
+
-- capybara:allow-destructive the CHECK is re-added with one more allowed value in the same transaction
|
|
17
|
+
ALTER TABLE conversations DROP CONSTRAINT IF EXISTS conversations_kind_check;
|
|
18
|
+
ALTER TABLE conversations ADD CONSTRAINT conversations_kind_check
|
|
19
|
+
CHECK (kind IN ('chat', 'eval', 'subagent', 'external')) NOT VALID;
|
|
20
|
+
|
|
21
|
+
ALTER TABLE conversations ALTER COLUMN agent_id DROP NOT NULL;
|
|
22
|
+
ALTER TABLE conversations ADD COLUMN IF NOT EXISTS external jsonb;
|
|
23
|
+
ALTER TABLE conversations ADD COLUMN IF NOT EXISTS external_state text NOT NULL DEFAULT 'idle'
|
|
24
|
+
CONSTRAINT conversations_external_state_check
|
|
25
|
+
CHECK (external_state IN ('running', 'waiting', 'idle', 'ended'));
|
|
26
|
+
ALTER TABLE conversations ADD COLUMN IF NOT EXISTS external_delivered_seq bigint NOT NULL DEFAULT 0;
|
|
27
|
+
|
|
28
|
+
ALTER TABLE conversations DROP CONSTRAINT IF EXISTS conversations_external_shape;
|
|
29
|
+
ALTER TABLE conversations ADD CONSTRAINT conversations_external_shape CHECK (
|
|
30
|
+
kind = 'external' AND agent_id IS NULL AND external IS NOT NULL
|
|
31
|
+
OR kind <> 'external' AND agent_id IS NOT NULL AND external IS NULL
|
|
32
|
+
) NOT VALID;
|
|
33
|
+
ALTER TABLE conversations VALIDATE CONSTRAINT conversations_external_shape;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
-- Apply with all old kernel roles stopped. This release reads and writes only these switches.
|
|
2
|
+
-- capybara:allow-destructive the wider check immediately replaces the previous kind constraint
|
|
3
|
+
ALTER TABLE component_org_switches DROP CONSTRAINT IF EXISTS component_org_switches_kind_check;
|
|
4
|
+
ALTER TABLE component_org_switches ADD CONSTRAINT component_org_switches_kind_check
|
|
5
|
+
CHECK (kind IN ('skill', 'agent_template', 'connector_template', 'theme', 'extension'));
|
|
6
|
+
|
|
7
|
+
CREATE INDEX IF NOT EXISTS component_org_switches_extension_org_idx
|
|
8
|
+
ON component_org_switches (org_id, component_id) WHERE kind = 'extension';
|
|
9
|
+
|
|
10
|
+
WITH sources AS (
|
|
11
|
+
SELECT name AS plugin, catalog_item_id AS item_id
|
|
12
|
+
FROM extension_installs
|
|
13
|
+
WHERE catalog_item_id IS NOT NULL
|
|
14
|
+
UNION
|
|
15
|
+
SELECT plugin, item_id FROM extension_catalog_sources
|
|
16
|
+
)
|
|
17
|
+
INSERT INTO component_org_switches (kind, component_id, org_id, enabled, updated_by, updated_at)
|
|
18
|
+
SELECT 'extension', old.plugin, old.org_id, old.enabled, old.updated_by, old.updated_at
|
|
19
|
+
FROM extension_org_configs AS old
|
|
20
|
+
JOIN orgs AS org ON org.id = old.org_id AND org.deleted_at IS NULL
|
|
21
|
+
CROSS JOIN LATERAL (
|
|
22
|
+
SELECT count(*) AS all_sources,
|
|
23
|
+
count(*) FILTER (WHERE item.deleted_at IS NULL) AS live_sources,
|
|
24
|
+
bool_or(item.builtin AND item.owner_org_id IS NULL) FILTER (WHERE item.deleted_at IS NULL) AS builtin,
|
|
25
|
+
bool_or(install.id IS NOT NULL) FILTER (WHERE item.deleted_at IS NULL) AS installed,
|
|
26
|
+
bool_and(
|
|
27
|
+
NOT item.disabled
|
|
28
|
+
AND (
|
|
29
|
+
item.owner_org_id IS NULL OR item.owner_org_id = old.org_id OR (
|
|
30
|
+
item.shareable AND EXISTS (
|
|
31
|
+
SELECT 1 FROM catalog_item_versions AS published
|
|
32
|
+
WHERE published.item_id = item.id AND published.version = item.latest_version
|
|
33
|
+
AND published.applied_at IS NOT NULL
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
AND (item.scope <> 'named' OR listed.item_id IS NOT NULL)
|
|
38
|
+
) FILTER (WHERE item.deleted_at IS NULL) AS authorized
|
|
39
|
+
FROM sources AS source
|
|
40
|
+
JOIN catalog_items AS item ON item.id = source.item_id
|
|
41
|
+
LEFT JOIN catalog_item_scope_orgs AS listed
|
|
42
|
+
ON listed.item_id = item.id AND listed.org_id = old.org_id
|
|
43
|
+
LEFT JOIN plugin_installs AS install
|
|
44
|
+
ON install.item_id = item.id AND install.org_id = old.org_id AND install.status = 'installed'
|
|
45
|
+
WHERE source.plugin = old.plugin
|
|
46
|
+
) AS scope
|
|
47
|
+
WHERE NOT EXISTS (
|
|
48
|
+
SELECT 1 FROM extension_installs AS install WHERE install.name = old.plugin AND install.required
|
|
49
|
+
)
|
|
50
|
+
AND NOT coalesce(scope.builtin, false)
|
|
51
|
+
AND (
|
|
52
|
+
(scope.live_sources = 1 AND scope.installed AND NOT old.enabled)
|
|
53
|
+
OR (scope.all_sources = 0 AND old.enabled)
|
|
54
|
+
OR (scope.live_sources > 1 AND scope.authorized AND old.enabled)
|
|
55
|
+
)
|
|
56
|
+
ON CONFLICT (kind, component_id, org_id) DO NOTHING;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
-- A deployment projection of the selected catalog versions. The kernel populates it with
|
|
2
|
+
-- its catalog SemVer resolver before starting the new roles.
|
|
3
|
+
CREATE TABLE IF NOT EXISTS catalog_dependency_edges (
|
|
4
|
+
item_id uuid NOT NULL,
|
|
5
|
+
item_version text NOT NULL,
|
|
6
|
+
dependency_name text NOT NULL,
|
|
7
|
+
-- Empty for a declared dependency, otherwise the stable connector template ID.
|
|
8
|
+
template_id text NOT NULL DEFAULT '',
|
|
9
|
+
dependency_item_id uuid,
|
|
10
|
+
dependency_version text,
|
|
11
|
+
PRIMARY KEY (item_id, dependency_name, template_id),
|
|
12
|
+
CHECK ((dependency_item_id IS NULL) = (dependency_version IS NULL))
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
CREATE INDEX IF NOT EXISTS catalog_dependency_edges_reverse_idx
|
|
16
|
+
ON catalog_dependency_edges (dependency_item_id, dependency_version, item_id)
|
|
17
|
+
WHERE dependency_item_id IS NOT NULL;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
-- The audit log's actor filter and actor options (table pagination spec §3): one org's (or, with
|
|
2
|
+
-- org_id IS NULL, the platform's) events by one account, newest first, and the distinct accounts
|
|
3
|
+
-- and tokens that acted, read by a skip scan. The indexes are not partial on org_id, so the same
|
|
4
|
+
-- index serves `org_id = $1` and `org_id IS NULL`. The time filter needs no new index: 0003's
|
|
5
|
+
-- audit_events_org_at_idx (org_id, at DESC) is not partial either and serves both scopes.
|
|
6
|
+
-- Plain CREATE INDEX: the migrator runs each file in a transaction.
|
|
7
|
+
CREATE INDEX IF NOT EXISTS audit_events_actor_idx
|
|
8
|
+
ON audit_events (org_id, actor_account_id, id DESC);
|
|
9
|
+
|
|
10
|
+
-- Events done with an access token (a small share of the log): the token filter and the token
|
|
11
|
+
-- options.
|
|
12
|
+
CREATE INDEX IF NOT EXISTS audit_events_token_idx
|
|
13
|
+
ON audit_events (org_id, actor_token_id, id DESC) WHERE actor_token_id IS NOT NULL;
|
|
14
|
+
|
|
15
|
+
-- The object filter (q): a target id matched exactly, or against the ids a name semi-join finds,
|
|
16
|
+
-- within the scope, newest first.
|
|
17
|
+
CREATE INDEX IF NOT EXISTS audit_events_target_idx
|
|
18
|
+
ON audit_events (org_id, target, id DESC);
|