@capybara-hq/kernel 0.1.0-rc.127 → 0.1.0-rc.129
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 +3 -3
- package/dist/admin/admin.schemas.d.ts +14 -0
- package/dist/agents/readiness.service.d.ts +6 -0
- package/dist/agents/readiness.service.js +1 -1
- package/dist/automations/automations.service.js +15 -21
- package/dist/automations/effective-settings.d.ts +3 -9
- package/dist/automations/effective-settings.js +3 -5
- package/dist/automations/fire.js +0 -11
- package/dist/automations/grant-rules.d.ts +7 -10
- package/dist/automations/grant-rules.js +9 -18
- package/dist/automations/unattended.d.ts +1 -4
- package/dist/automations/unattended.js +0 -2
- package/dist/catalog/catalog-items.d.ts +7 -4
- package/dist/catalog/catalog-items.js +8 -7
- package/dist/catalog/catalog-scope.service.d.ts +3 -2
- package/dist/catalog/catalog-scope.service.js +5 -4
- package/dist/catalog/org-extension.controller.d.ts +1 -20
- package/dist/catalog/org-extension.controller.js +1 -48
- package/dist/catalog/org-extension.schemas.d.ts +1 -9
- package/dist/catalog/org-extension.schemas.js +1 -17
- package/dist/config/schema.d.ts +12 -0
- package/dist/config/schema.js +16 -0
- package/dist/conversations/approval-profile.d.ts +8 -1
- package/dist/conversations/approval-profile.js +20 -0
- package/dist/conversations/conversations.service.d.ts +1 -1
- package/dist/conversations/conversations.service.js +8 -3
- package/dist/conversations/events.d.ts +25 -1
- package/dist/conversations/events.js +7 -2
- package/dist/conversations/permission-profiles.controller.d.ts +4 -0
- package/dist/conversations/permission-profiles.schemas.d.ts +5 -0
- package/dist/conversations/permission-profiles.schemas.js +8 -0
- package/dist/conversations/permission-profiles.service.d.ts +8 -1
- package/dist/conversations/permission-profiles.service.js +13 -1
- package/dist/db/kernel-schema.d.ts +21 -0
- package/dist/device-access/device-access.service.d.ts +4 -1
- package/dist/device-access/device-access.service.js +26 -7
- package/dist/device-access/viewer.d.ts +3 -1
- package/dist/device-access/viewer.js +18 -9
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +6 -0
- package/dist/extensions/admin-view.d.ts +1 -3
- package/dist/extensions/admin-view.js +5 -8
- package/dist/git/gateway.d.ts +8 -1
- package/dist/git/gateway.js +68 -11
- package/dist/git/git.module.d.ts +2 -3
- package/dist/git/git.module.js +4 -4
- package/dist/http/api.module.js +3 -3
- package/dist/identity/settings.d.ts +20 -5
- package/dist/identity/settings.js +52 -9
- package/dist/infra/config/kernel-config.service.js +4 -0
- package/dist/orgs/orgs.module.js +12 -1
- package/dist/orgs/orgs.schemas.js +3 -0
- package/dist/orgs/security-settings.service.d.ts +94 -0
- package/dist/orgs/security-settings.service.js +223 -0
- package/dist/orgs/settings.controller.d.ts +33 -0
- package/dist/orgs/settings.controller.js +41 -1
- package/dist/orgs/settings.service.d.ts +48 -63
- package/dist/orgs/settings.service.js +86 -103
- package/dist/platform/exclusions.js +1 -1
- package/dist/platform/operation.js +4 -0
- package/dist/platform/ops/admin.ops.js +18 -4
- package/dist/platform/ops/agents.ops.js +1 -1
- package/dist/platform/ops/connectors.ops.js +2 -2
- package/dist/platform/ops/extensions.ops.d.ts +1 -3
- package/dist/platform/ops/extensions.ops.js +4 -131
- package/dist/platform/ops/org-settings.ops.d.ts +3 -1
- package/dist/platform/ops/org-settings.ops.js +76 -3
- package/dist/platform/ops/orgs.ops.js +2 -0
- package/dist/runtime/context/permission-profile.js +6 -0
- package/dist/runtime/subagents/dispatch.d.ts +3 -0
- package/dist/runtime/subagents/dispatch.js +2 -1
- package/dist/runtime/subagents/messages.d.ts +3 -1
- package/dist/runtime/subagents/messages.js +9 -6
- package/dist/sandbox/device-sandbox-settings.d.ts +55 -1
- package/dist/sandbox/device-sandbox-settings.js +64 -1
- package/dist/sandbox/device-sandbox.d.ts +9 -1
- package/dist/sandbox/device-sandbox.js +17 -2
- package/dist/sandbox/device-services.d.ts +26 -3
- package/dist/sandbox/device-services.js +95 -16
- package/dist/sandbox/loopback-grant-records.d.ts +3 -2
- package/dist/sandbox/loopback-grant-records.js +32 -5
- package/dist/sandbox/operation-authority.d.ts +3 -2
- package/dist/sandbox/operation-authority.js +21 -1
- package/dist/sandbox/operation-intents.js +5 -1
- package/dist/sandbox/permission-call-types.d.ts +2 -1
- package/dist/sandbox/permission-ceiling-writes.d.ts +14 -5
- package/dist/sandbox/permission-ceiling-writes.js +122 -13
- package/dist/sandbox/permission-config-publication.d.ts +10 -0
- package/dist/sandbox/permission-config-publication.js +27 -5
- package/dist/sandbox/permission-facts.d.ts +21 -2
- package/dist/sandbox/permission-facts.js +101 -9
- package/dist/sandbox/permission-transitions.d.ts +1 -1
- package/dist/sandbox/sandbox.service.d.ts +2 -2
- package/dist/sandbox/sandbox.service.js +7 -3
- package/dist/tools/admin-connectors.js +2 -2
- package/dist/tools/approvals.service.d.ts +7 -2
- package/dist/tools/approvals.service.js +39 -7
- package/dist/tools/builtin-names.d.ts +0 -6
- package/dist/tools/builtin-names.js +0 -11
- package/dist/tools/builtins/sandbox/index.d.ts +3 -5
- package/dist/tools/builtins/sandbox/index.js +3 -5
- package/dist/tools/connector-account-policies.js +7 -4
- package/dist/tools/connectors.controller.d.ts +0 -6
- package/dist/tools/connectors.schemas.d.ts +1 -8
- package/dist/tools/connectors.schemas.js +1 -4
- package/dist/tools/connectors.service.d.ts +3 -7
- package/dist/tools/connectors.service.js +29 -44
- package/dist/tools/drift.js +12 -4
- package/dist/tools/git-push-policy.d.ts +1 -4
- package/dist/tools/git-push-policy.js +4 -5
- package/dist/tools/org-tool-policies.d.ts +24 -0
- package/dist/tools/org-tool-policies.js +113 -0
- package/dist/tools/org-tool-switches.d.ts +5 -70
- package/dist/tools/org-tool-switches.js +13 -141
- package/dist/tools/pipeline.d.ts +11 -5
- package/dist/tools/pipeline.js +173 -38
- package/dist/tools/policy.d.ts +3 -7
- package/dist/tools/policy.js +29 -48
- package/dist/tools/registry.d.ts +5 -0
- package/dist/tools/registry.js +44 -13
- package/package.json +1 -1
- package/src/migrations/0212_org_security_policy.sql +234 -0
|
@@ -47,6 +47,8 @@ const SettingsInput = DEPLOYMENT_SETTINGS_PATCH.pick({
|
|
|
47
47
|
clientExtensions: true,
|
|
48
48
|
devicesOutsideSandbox: true,
|
|
49
49
|
devicesNetwork: true,
|
|
50
|
+
devicesAllowedProfiles: true,
|
|
51
|
+
devicesProjectReach: true,
|
|
50
52
|
devicesDefaultProvider: true,
|
|
51
53
|
attribution: true,
|
|
52
54
|
externalSharing: true,
|
|
@@ -242,7 +244,7 @@ let AdminOperations = class AdminOperations {
|
|
|
242
244
|
}),
|
|
243
245
|
defineOperation({
|
|
244
246
|
id: "admin.settings",
|
|
245
|
-
description: "Read the deployment settings (super admin): who may create orgs (orgCreation), the price currency, whether orgs may create their own connectors and skills, whether org admins may browse the marketplaces, the per-org limit overrides keyed by org id (orgs.get reads one org's), the platform's device sandbox settings in effect (devicesOutsideSandbox: permission allowed or off, whether a device may be granted running a call outside its sandbox; devicesNetwork: default and ceiling, open for the public internet with private addresses closed or allowlist, the network a device gets and the widest an org or device may choose), devicesDefaultProvider (provider: the device provider extension that makes a person's default device, null for none), the platform's attribution defaults for agent-created git commits and pull requests (attribution: commit, pr, sessionUrl), file sharing (externalSharing: value allow or deny, whether orgs may turn on public links to conversation files; shareMaxExpiryDays: value, the longest expiry a share may take in days), htmlRenderCdnAllowlist (the https origins a rendered HTML file may load libraries, styles, fonts and images from) and promptSuggestions (on or off, absent meaning on: whether the composer suggests the person's next message after a completed run; an org's own promptSuggestions must be on too); the switches each with sources: env, file or nacos are set in the startup config and read-only, db chosen in the admin console, default.",
|
|
247
|
+
description: "Read the deployment settings (super admin): who may create orgs (orgCreation), the price currency, whether orgs may create their own connectors and skills, whether org admins may browse the marketplaces, the per-org limit overrides keyed by org id (orgs.get reads one org's), the platform's device sandbox settings in effect (devicesOutsideSandbox: permission allowed or off, whether a device may be granted running a call outside its sandbox; devicesNetwork: default and ceiling, open for the public internet with private addresses closed or allowlist, the network a device gets and the widest an org or device may choose), devicesAllowedProfiles ({ value }: profiles members may choose), devicesProjectReach ({ ceiling }: workspace, paths or machine), devicesDefaultProvider (provider: the device provider extension that makes a person's default device, null for none), the platform's attribution defaults for agent-created git commits and pull requests (attribution: commit, pr, sessionUrl), file sharing (externalSharing: value allow or deny, whether orgs may turn on public links to conversation files; shareMaxExpiryDays: value, the longest expiry a share may take in days), htmlRenderCdnAllowlist (the https origins a rendered HTML file may load libraries, styles, fonts and images from) and promptSuggestions (on or off, absent meaning on: whether the composer suggests the person's next message after a completed run; an org's own promptSuggestions must be on too); the switches each with sources: env, file or nacos are set in the startup config and read-only, db chosen in the admin console, default.",
|
|
246
248
|
input: z.object({}).strict(),
|
|
247
249
|
example: {},
|
|
248
250
|
authz: { superAdmin: true },
|
|
@@ -252,7 +254,7 @@ let AdminOperations = class AdminOperations {
|
|
|
252
254
|
}),
|
|
253
255
|
defineOperation({
|
|
254
256
|
id: "admin.update-settings",
|
|
255
|
-
description: "Change deployment settings (super admin); give only the keys to change: orgCreation (anyone or super_admin), priceCurrency (ISO 4217 code), customConnectors / customSkills (allow or deny: whether orgs may create their own instead of installing from the catalog), orgMarketplaceBrowse (true or false), uiTheme ({ id }: the platform default theme, a platform theme whose scope is all, or null for the built-in theme; it is what every org falls back to and what the sign-in pages show), uiArrangement ({ <slot>: { hidden, order } } for a list slot, { <slot>: { use } } for a single slot: the platform default arrangement of UI slots, with contribution keys <extension>/<contribution>; hidden ones are not listed but still open by URL; use names the contribution that replaces the built-in, null for the built-in; null for a slot removes its entry), clientExtensions ({ enabled?, disabled? }: the kill switch of plugin client code; enabled false stops every plugin's interface code in every browser, disabled is the whole list of plugins whose interface code alone is stopped while their tools keep working; read the current list from admin.settings first), devicesOutsideSandbox ({ permission }: whether a device may be granted running a call outside its sandbox, allowed or off; null clears it back to the default, allowed; through this tool it may only be turned off, never allowed, and a value set in the startup config is read-only), devicesNetwork ({ default?, ceiling? }: the device sandbox network, open or allowlist; null clears a field back to the default, open; the default may not be above the ceiling; through this tool either may only be narrowed to allowlist, never opened, and a field set in the startup config is read-only), devicesDefaultProvider ({ provider }: the device provider extension that makes a person's default device; null clears it back to none; read-only when set in the startup config), attribution ({ commit?, pr?, sessionUrl? }: the platform's defaults for agent-created git commits and pull requests; null clears a field back to its default, an empty string turns that line off, and fields set in the startup config are read-only), externalSharing (allow or deny: whether orgs may turn on public links to conversation files; null clears it back to the default, deny; externalSharing may only be turned off through this tool, and a value set in the startup config is read-only), shareMaxExpiryDays (1 to 365: the longest expiry a share may take, in days; null clears it back to 30; through this tool it may only be lowered, never raised, and it is read-only when set in the startup config), htmlRenderCdnAllowlist (the whole list of https origins, scheme and host with an optional port and nothing else, that a rendered HTML file may load from; at most 50; through this tool origins may only be removed, never added, so read the current list from admin.settings first and send it without the ones to drop). promptSuggestions (on or off; null clears it, absent meaning on: whether the composer suggests the person's next message after a completed run; an org's own promptSuggestions must be on too) may be set either way. promptCache ({ longTtl }: true or false; whether requests use the model's prompt cache tier of at least 30 minutes, such as 1 hour, where cache writes cost more; an org may override it) may be set either way. Per-org limits are orgs.set-limits.",
|
|
257
|
+
description: "Change deployment settings (super admin); give only the keys to change: orgCreation (anyone or super_admin), priceCurrency (ISO 4217 code), customConnectors / customSkills (allow or deny: whether orgs may create their own instead of installing from the catalog), orgMarketplaceBrowse (true or false), uiTheme ({ id }: the platform default theme, a platform theme whose scope is all, or null for the built-in theme; it is what every org falls back to and what the sign-in pages show), uiArrangement ({ <slot>: { hidden, order } } for a list slot, { <slot>: { use } } for a single slot: the platform default arrangement of UI slots, with contribution keys <extension>/<contribution>; hidden ones are not listed but still open by URL; use names the contribution that replaces the built-in, null for the built-in; null for a slot removes its entry), clientExtensions ({ enabled?, disabled? }: the kill switch of plugin client code; enabled false stops every plugin's interface code in every browser, disabled is the whole list of plugins whose interface code alone is stopped while their tools keep working; read the current list from admin.settings first), devicesOutsideSandbox ({ permission }: whether a device may be granted running a call outside its sandbox, allowed or off; null clears it back to the default, allowed; through this tool it may only be turned off, never allowed, and a value set in the startup config is read-only), devicesNetwork ({ default?, ceiling? }: the device sandbox network, open or allowlist; null clears a field back to the default, open; the default may not be above the ceiling; through this tool either may only be narrowed to allowlist, never opened, and a field set in the startup config is read-only), devicesAllowedProfiles ({ value }: choose a subset including request-approval), devicesProjectReach ({ ceiling }: workspace, paths or machine); these two may only narrow through this tool, null follows the default, and startup config is read-only. A super admin decides on wider profile or project reach ceilings in the web admin settings at /admin/settings. The other settings are devicesDefaultProvider ({ provider }: the device provider extension that makes a person's default device; null clears it back to none; read-only when set in the startup config), attribution ({ commit?, pr?, sessionUrl? }: the platform's defaults for agent-created git commits and pull requests; null clears a field back to its default, an empty string turns that line off, and fields set in the startup config are read-only), externalSharing (allow or deny: whether orgs may turn on public links to conversation files; null clears it back to the default, deny; externalSharing may only be turned off through this tool, and a value set in the startup config is read-only), shareMaxExpiryDays (1 to 365: the longest expiry a share may take, in days; null clears it back to 30; through this tool it may only be lowered, never raised, and it is read-only when set in the startup config), htmlRenderCdnAllowlist (the whole list of https origins, scheme and host with an optional port and nothing else, that a rendered HTML file may load from; at most 50; through this tool origins may only be removed, never added, so read the current list from admin.settings first and send it without the ones to drop). promptSuggestions (on or off; null clears it, absent meaning on: whether the composer suggests the person's next message after a completed run; an org's own promptSuggestions must be on too) may be set either way. promptCache ({ longTtl }: true or false; whether requests use the model's prompt cache tier of at least 30 minutes, such as 1 hour, where cache writes cost more; an org may override it) may be set either way. Per-org limits are orgs.set-limits.",
|
|
256
258
|
input: SettingsInput.refine((b) => Object.keys(b).length > 0, {
|
|
257
259
|
message: "at least one setting is required",
|
|
258
260
|
}),
|
|
@@ -268,6 +270,7 @@ let AdminOperations = class AdminOperations {
|
|
|
268
270
|
"compaction",
|
|
269
271
|
],
|
|
270
272
|
confirm: "platform",
|
|
273
|
+
noHandoff: "Widenings are refused before confirmation. A super admin makes a separate edit in web settings, where there is no pending operation to review.",
|
|
271
274
|
errors: [
|
|
272
275
|
{
|
|
273
276
|
code: "validation_failed",
|
|
@@ -285,6 +288,10 @@ let AdminOperations = class AdminOperations {
|
|
|
285
288
|
code: "deployment.external_sharing_not_allowed",
|
|
286
289
|
next: "Through this tool external sharing may only be turned off (deny); to allow it, ask a super admin to change it in the admin console settings on the web.",
|
|
287
290
|
},
|
|
291
|
+
{
|
|
292
|
+
code: "deployment.security_widen_not_allowed",
|
|
293
|
+
next: "Profile and project reach ceilings may only be narrowed through this tool. A super admin can widen them on the web at /admin/settings.",
|
|
294
|
+
},
|
|
288
295
|
{
|
|
289
296
|
code: "deployment.sharing_widen_not_allowed",
|
|
290
297
|
next: "Through this tool shareMaxExpiryDays may only be lowered and htmlRenderCdnAllowlist may only lose origins (send the current list from admin.settings minus the ones to drop); to raise the maximum or add an origin, ask a super admin to change it in the admin console settings on the web.",
|
|
@@ -308,7 +315,10 @@ let AdminOperations = class AdminOperations {
|
|
|
308
315
|
};
|
|
309
316
|
}
|
|
310
317
|
return precheckBy(async () => {
|
|
311
|
-
if (i.devicesOutsideSandbox !== undefined ||
|
|
318
|
+
if (i.devicesOutsideSandbox !== undefined ||
|
|
319
|
+
i.devicesNetwork !== undefined ||
|
|
320
|
+
i.devicesAllowedProfiles !== undefined ||
|
|
321
|
+
i.devicesProjectReach !== undefined)
|
|
312
322
|
await this.settings.checkDeviceSandbox(i, { onlyNarrows: true });
|
|
313
323
|
if (i.devicesDefaultProvider !== undefined)
|
|
314
324
|
this.settings.checkDefaultProvider(i.devicesDefaultProvider);
|
|
@@ -316,7 +326,7 @@ let AdminOperations = class AdminOperations {
|
|
|
316
326
|
});
|
|
317
327
|
},
|
|
318
328
|
summary: async (i) => {
|
|
319
|
-
const { uiTheme, uiArrangement, clientExtensions, devicesOutsideSandbox, devicesNetwork, devicesDefaultProvider, attribution, htmlRenderCdnAllowlist, promptCache, ...rest } = i;
|
|
329
|
+
const { uiTheme, uiArrangement, clientExtensions, devicesOutsideSandbox, devicesNetwork, devicesAllowedProfiles, devicesProjectReach, devicesDefaultProvider, attribution, htmlRenderCdnAllowlist, promptCache, ...rest } = i;
|
|
320
330
|
const parts = Object.entries(rest).map(([k, v]) => `${k}=${String(v)}`);
|
|
321
331
|
if (htmlRenderCdnAllowlist !== undefined) {
|
|
322
332
|
parts.push(`htmlRenderCdnAllowlist=[${htmlRenderCdnAllowlist.join(", ")}]`);
|
|
@@ -329,6 +339,10 @@ let AdminOperations = class AdminOperations {
|
|
|
329
339
|
if (devicesNetwork[field] !== undefined)
|
|
330
340
|
parts.push(`devicesNetwork.${field}=${String(devicesNetwork[field])}`);
|
|
331
341
|
}
|
|
342
|
+
if (devicesAllowedProfiles !== undefined)
|
|
343
|
+
parts.push(`devicesAllowedProfiles=${devicesAllowedProfiles.value?.join(", ") ?? "default"}`);
|
|
344
|
+
if (devicesProjectReach !== undefined)
|
|
345
|
+
parts.push(`devicesProjectReach=${devicesProjectReach.ceiling ?? "default"}`);
|
|
332
346
|
if (devicesDefaultProvider !== undefined)
|
|
333
347
|
parts.push(`devicesDefaultProvider=${String(devicesDefaultProvider.provider)}`);
|
|
334
348
|
if (promptCache?.longTtl !== undefined)
|
|
@@ -780,7 +780,7 @@ let AgentsOperations = class AgentsOperations {
|
|
|
780
780
|
}),
|
|
781
781
|
defineOperation({
|
|
782
782
|
id: "agents.readiness",
|
|
783
|
-
description: "Whether the org can run agents: modelProvider is ready when the org has a chat model an agent can pick (the list agents.create chooses from); no_models when model providers are on but none gives one (unusableProviders names each provider and its reason: list_failed with errorKind, e.g. auth for a rejected key, or no_chat_models; orgCanFix says whether an org admin can fix it on Settings > Models, else only the super admin can on the admin Models page); org_fixable when no provider is on but an org admin can make one available on Settings > Models (orgFixableProviders names each provider and its reason: not_enabled, switch it on; needs_config, fill the org's config); none when only the super admin can help; how many agents you can see, and the optional setup steps visible to your role. checklistDismissed is your own preference in this org.",
|
|
783
|
+
description: "Whether the org can run agents: modelProvider is ready when the org has a chat model an agent can pick (the list agents.create chooses from); no_models when model providers are on but none gives one (unusableProviders names each provider and its reason: list_failed with errorKind, e.g. auth for a rejected key, or no_chat_models; orgCanFix says whether an org admin can fix it on Settings > Models, else only the super admin can on the admin Models page); org_fixable when no provider is on but an org admin can make one available on Settings > Models (orgFixableProviders names each provider and its reason: not_enabled, switch it on; needs_config, fill the org's config; needsOrgConfig says whether it also needs the org's own config, such as an API key the platform left empty); none when only the super admin can help; how many agents you can see, and the optional setup steps visible to your role. checklistDismissed is your own preference in this org.",
|
|
784
784
|
input: z.object({}).strict(),
|
|
785
785
|
example: {},
|
|
786
786
|
authz: { orgAction: "org.read" },
|
|
@@ -44,7 +44,7 @@ const CreateInput = ConnectorCreateSchema.omit({ credential: true })
|
|
|
44
44
|
/** `connectors.update`: the PATCH body without per-tool policies (ruling R4). */
|
|
45
45
|
const UpdateInput = z
|
|
46
46
|
.object({ connectorId: ConnectorId })
|
|
47
|
-
.extend(ConnectorUpdateSchema.omit({ tools: true
|
|
47
|
+
.extend(ConnectorUpdateSchema.omit({ tools: true }).shape)
|
|
48
48
|
.strict();
|
|
49
49
|
/** `connectors.add-from-template`: the route's name and its `config` flattened, no secrets. */
|
|
50
50
|
const FromTemplateInput = z
|
|
@@ -492,7 +492,7 @@ let ConnectorsOperations = class ConnectorsOperations {
|
|
|
492
492
|
authz: { orgAction: "connectors.manage" },
|
|
493
493
|
mirrors: ["PATCH /api/v1/orgs/:orgId/connectors/:connectorId"],
|
|
494
494
|
// per-tool policies decide what agents may call without asking (ruling R4)
|
|
495
|
-
omits: ["tools"
|
|
495
|
+
omits: ["tools"],
|
|
496
496
|
confirm: "org",
|
|
497
497
|
errors: [
|
|
498
498
|
{ code: "connector.not_found", next: "Check the connector id with connectors.list." },
|
|
@@ -4,7 +4,6 @@ import { OrgExtensionConfigs } from "../../extensions/org-config.js";
|
|
|
4
4
|
import { OrgOverrides, type OrgOverrideView } from "../../extensions/org-overrides.js";
|
|
5
5
|
import { ExtensionPointDefaults } from "../../extensions/point-defaults.js";
|
|
6
6
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
7
|
-
import { OrgToolSwitches } from "../../tools/org-tool-switches.js";
|
|
8
7
|
import { type PersonFieldTarget } from "../person-fields.js";
|
|
9
8
|
import { PlatformOperations } from "../registry.js";
|
|
10
9
|
/**
|
|
@@ -25,10 +24,9 @@ export declare class ExtensionsOperations implements OnModuleInit {
|
|
|
25
24
|
private readonly configs;
|
|
26
25
|
private readonly displayNames;
|
|
27
26
|
private readonly kdb;
|
|
28
|
-
private readonly switches;
|
|
29
27
|
private readonly pointDefaults;
|
|
30
28
|
private readonly overrides;
|
|
31
|
-
constructor(registry: PlatformOperations, configs: OrgExtensionConfigs, displayNames: ExtensionDisplayNames, kdb: KernelDb,
|
|
29
|
+
constructor(registry: PlatformOperations, configs: OrgExtensionConfigs, displayNames: ExtensionDisplayNames, kdb: KernelDb, pointDefaults: ExtensionPointDefaults, overrides: OrgOverrides);
|
|
32
30
|
/**
|
|
33
31
|
* Why `extensions.set-enabled` refuses the switch before writing, or null: switching on needs the
|
|
34
32
|
* extension's plugin installed in the org; a required or builtin one cannot go off. The write
|
|
@@ -10,7 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { EXTENSION_POINTS, parseExtensionPoint } from "@capybara-hq/plugin-sdk";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { z } from "zod";
|
|
13
|
-
import { OrgExtensionParams, OrgExtensionPut,
|
|
13
|
+
import { OrgExtensionParams, OrgExtensionPut, OrgOverridesPut, OrgOverridesTake, } from "../../catalog/org-extension.schemas.js";
|
|
14
14
|
import { ApiError } from "../../errors.js";
|
|
15
15
|
import { ExtensionDisplayNames } from "../../extensions/display-name.js";
|
|
16
16
|
import { listedInOrg, OrgExtensionConfigs, pluginNotInstalledError, providesOf, } from "../../extensions/org-config.js";
|
|
@@ -19,7 +19,6 @@ import { ExtensionPointDefaults } from "../../extensions/point-defaults.js";
|
|
|
19
19
|
import { ExtensionPointDefaultBody, ExtensionPointParams, } from "../../extensions/point-defaults.schemas.js";
|
|
20
20
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
21
21
|
import { can } from "../../orgs/roles.js";
|
|
22
|
-
import { OrgToolSwitches } from "../../tools/org-tool-switches.js";
|
|
23
22
|
import { resolveNext } from "../errors.js";
|
|
24
23
|
import { defineOperation } from "../operation.js";
|
|
25
24
|
import { personFieldParams, secretFieldsOf } from "../person-fields.js";
|
|
@@ -32,8 +31,6 @@ import { localized, named, orElse } from "./summary.js";
|
|
|
32
31
|
import { roleFor, unavailableFields } from "./unavailable.js";
|
|
33
32
|
const NoInput = z.object({}).strict();
|
|
34
33
|
const Extension = OrgExtensionParams.shape.extension;
|
|
35
|
-
const Tool = OrgExtensionToolParams.shape.tool;
|
|
36
|
-
const SwitchConfirm = OrgToolSwitchPut.shape.confirm.unwrap();
|
|
37
34
|
const Force = OrgExtensionPut.shape.force;
|
|
38
35
|
/** The next step of an extension that needs its org config. */
|
|
39
36
|
const NEEDS_ORG_CONFIG = {
|
|
@@ -90,15 +87,13 @@ let ExtensionsOperations = class ExtensionsOperations {
|
|
|
90
87
|
configs;
|
|
91
88
|
displayNames;
|
|
92
89
|
kdb;
|
|
93
|
-
switches;
|
|
94
90
|
pointDefaults;
|
|
95
91
|
overrides;
|
|
96
|
-
constructor(registry, configs, displayNames, kdb,
|
|
92
|
+
constructor(registry, configs, displayNames, kdb, pointDefaults, overrides) {
|
|
97
93
|
this.registry = registry;
|
|
98
94
|
this.configs = configs;
|
|
99
95
|
this.displayNames = displayNames;
|
|
100
96
|
this.kdb = kdb;
|
|
101
|
-
this.switches = switches;
|
|
102
97
|
this.pointDefaults = pointDefaults;
|
|
103
98
|
this.overrides = overrides;
|
|
104
99
|
}
|
|
@@ -256,127 +251,6 @@ let ExtensionsOperations = class ExtensionsOperations {
|
|
|
256
251
|
};
|
|
257
252
|
},
|
|
258
253
|
}),
|
|
259
|
-
defineOperation({
|
|
260
|
-
id: "extensions.tools",
|
|
261
|
-
description: "List the tools an extension registers, each with this org's switch (on unless an org admin turned it off).",
|
|
262
|
-
input: z.object({ extension: Extension }).strict(),
|
|
263
|
-
example: { extension: "todo" },
|
|
264
|
-
authz: { orgAction: "org.extensions.read" },
|
|
265
|
-
mirrors: ["GET /api/v1/orgs/:orgId/extensions/:extension/tools"],
|
|
266
|
-
confirm: "read",
|
|
267
|
-
errors: [
|
|
268
|
-
{
|
|
269
|
-
code: "extension.not_found",
|
|
270
|
-
next: "The extension is not running or not visible to this org; check the name with extensions.list.",
|
|
271
|
-
},
|
|
272
|
-
],
|
|
273
|
-
run: async (input, ctx) => ({
|
|
274
|
-
tools: await this.switches.list(ctx.orgId, input.extension),
|
|
275
|
-
}),
|
|
276
|
-
}),
|
|
277
|
-
defineOperation({
|
|
278
|
-
id: "extensions.tool-disable-preview",
|
|
279
|
-
description: "Preview turning one extension tool off in this org (org admins): the org's agents that have it (every agent that does not turn it off), and the confirm value extensions.set-tool-enabled needs. Show the preview to the person before turning it off.",
|
|
280
|
-
input: z.object({ extension: Extension, tool: Tool }).strict(),
|
|
281
|
-
example: { extension: "todo", tool: "add_item" },
|
|
282
|
-
// the web previews through the switch route itself (no confirm); writes nothing here
|
|
283
|
-
authz: { orgAction: "org.extensions.manage" },
|
|
284
|
-
mirrors: [],
|
|
285
|
-
confirm: "read",
|
|
286
|
-
errors: [
|
|
287
|
-
{
|
|
288
|
-
code: "extension.not_found",
|
|
289
|
-
next: "The extension is not running or not visible to this org; check the name with extensions.list.",
|
|
290
|
-
},
|
|
291
|
-
{ code: "extension.tool_not_found", next: "Check the tool names with extensions.tools." },
|
|
292
|
-
],
|
|
293
|
-
run: async (input, ctx) => {
|
|
294
|
-
const p = await this.switches.previewOff(ctx.orgId, input.extension, input.tool);
|
|
295
|
-
return p === null
|
|
296
|
-
? { preview: null, next: "The tool is off in this org already." }
|
|
297
|
-
: { affectedAgents: p.affectedAgents, confirm: p.confirm };
|
|
298
|
-
},
|
|
299
|
-
}),
|
|
300
|
-
defineOperation({
|
|
301
|
-
id: "extensions.set-tool-enabled",
|
|
302
|
-
description: "Turn one extension tool on or off in this org (org admins). Turning on applies at once; turning off needs confirm: the value extensions.tool-disable-preview returned with the preview the person saw.",
|
|
303
|
-
input: z.discriminatedUnion("enabled", [
|
|
304
|
-
z.object({ extension: Extension, tool: Tool, enabled: z.literal(true) }).strict(),
|
|
305
|
-
z
|
|
306
|
-
.object({
|
|
307
|
-
extension: Extension,
|
|
308
|
-
tool: Tool,
|
|
309
|
-
enabled: z.literal(false),
|
|
310
|
-
confirm: SwitchConfirm,
|
|
311
|
-
})
|
|
312
|
-
.strict(),
|
|
313
|
-
]),
|
|
314
|
-
example: { extension: "todo", tool: "add_item", enabled: true },
|
|
315
|
-
authz: { orgAction: "org.extensions.manage" },
|
|
316
|
-
mirrors: ["PUT /api/v1/orgs/:orgId/extensions/:extension/tools/:tool"],
|
|
317
|
-
confirm: "org",
|
|
318
|
-
errors: [
|
|
319
|
-
{
|
|
320
|
-
code: "extension.not_found",
|
|
321
|
-
next: "The extension is not running or not visible to this org; check the name with extensions.list.",
|
|
322
|
-
},
|
|
323
|
-
{ code: "extension.tool_not_found", next: "Check the tool names with extensions.tools." },
|
|
324
|
-
{
|
|
325
|
-
code: "plugin.switch_stale",
|
|
326
|
-
next: "What turning it off affects changed: call extensions.tool-disable-preview again, show it, and call again with the new confirm value.",
|
|
327
|
-
},
|
|
328
|
-
],
|
|
329
|
-
precheck: async (i, ctx) => {
|
|
330
|
-
if (i.enabled) {
|
|
331
|
-
let tools = [];
|
|
332
|
-
const r = await precheckBy(async () => {
|
|
333
|
-
tools = await this.switches.list(ctx.orgId, i.extension);
|
|
334
|
-
});
|
|
335
|
-
if (!r.ok)
|
|
336
|
-
return r;
|
|
337
|
-
return tools.some((t) => t.tool === i.tool)
|
|
338
|
-
? { ok: true }
|
|
339
|
-
: {
|
|
340
|
-
ok: false,
|
|
341
|
-
code: "extension.tool_not_found",
|
|
342
|
-
message: `Extension ${i.extension} does not register a tool named ${i.tool}`,
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
let confirm = null;
|
|
346
|
-
const r = await precheckBy(async () => {
|
|
347
|
-
confirm =
|
|
348
|
-
(await this.switches.previewOff(ctx.orgId, i.extension, i.tool))?.confirm ?? null;
|
|
349
|
-
});
|
|
350
|
-
if (!r.ok)
|
|
351
|
-
return r;
|
|
352
|
-
return confirm === null || confirm === i.confirm
|
|
353
|
-
? { ok: true }
|
|
354
|
-
: {
|
|
355
|
-
ok: false,
|
|
356
|
-
code: "plugin.switch_stale",
|
|
357
|
-
message: "What turning this tool off affects has changed since the preview",
|
|
358
|
-
};
|
|
359
|
-
},
|
|
360
|
-
summary: async (i, ctx) => {
|
|
361
|
-
const x = await this.nameOf(i.extension);
|
|
362
|
-
if (i.enabled) {
|
|
363
|
-
return {
|
|
364
|
-
zh: `在本组织开启扩展「${x.zh}」的工具 ${named(i.tool)}`,
|
|
365
|
-
en: `Turn on tool ${named(i.tool)} of extension "${x.en}" in the org`,
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
const p = await this.switches.previewOff(ctx.orgId, i.extension, i.tool);
|
|
369
|
-
const n = p?.affectedAgents.length ?? 0;
|
|
370
|
-
return {
|
|
371
|
-
zh: `在本组织关闭扩展「${x.zh}」的工具 ${named(i.tool)}:${n} 个智能体选用了它`,
|
|
372
|
-
en: `Turn off tool ${named(i.tool)} of extension "${x.en}" in the org: ${n} agents selected it`,
|
|
373
|
-
};
|
|
374
|
-
},
|
|
375
|
-
run: async (input, ctx) => this.switches.set(ctx.orgId, input.extension, input.tool, input.enabled, {
|
|
376
|
-
accountId: ctx.actorAccountId,
|
|
377
|
-
auditDetail: viaAgent("extensions.set-tool-enabled", ctx),
|
|
378
|
-
}, input.enabled ? undefined : input.confirm),
|
|
379
|
-
}),
|
|
380
254
|
defineOperation({
|
|
381
255
|
id: "extensions.org-config",
|
|
382
256
|
description: "Read an extension's config in this org (org admins): configurable (it has fields the org can override) and needsConfig (its config for this org is not valid); deploymentCopy is the org's side of the platform's deployment config: following the platform or a copy, the overridable fields (platform values, the copy's values, secrets as set or not, never a value) and whether the effective config is valid. deploymentCopy is null when the extension does not run on the platform.",
|
|
@@ -646,8 +520,7 @@ ExtensionsOperations = __decorate([
|
|
|
646
520
|
__param(1, Inject(OrgExtensionConfigs)),
|
|
647
521
|
__param(2, Inject(ExtensionDisplayNames)),
|
|
648
522
|
__param(3, Inject(KernelDb)),
|
|
649
|
-
__param(4, Inject(
|
|
650
|
-
__param(5, Inject(
|
|
651
|
-
__param(6, Inject(OrgOverrides))
|
|
523
|
+
__param(4, Inject(ExtensionPointDefaults)),
|
|
524
|
+
__param(5, Inject(OrgOverrides))
|
|
652
525
|
], ExtensionsOperations);
|
|
653
526
|
export { ExtensionsOperations };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type OnModuleInit } from "@nestjs/common";
|
|
2
2
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
3
|
+
import { OrgSecuritySettingsService } from "../../orgs/security-settings.service.js";
|
|
3
4
|
import { OrgSettingsService } from "../../orgs/settings.service.js";
|
|
4
5
|
import { ThemesService } from "../../themes/themes.service.js";
|
|
5
6
|
import { PlatformOperations } from "../registry.js";
|
|
@@ -15,6 +16,7 @@ export declare class OrgSettingsOperations implements OnModuleInit {
|
|
|
15
16
|
private readonly settings;
|
|
16
17
|
private readonly themes;
|
|
17
18
|
private readonly db;
|
|
18
|
-
|
|
19
|
+
private readonly security;
|
|
20
|
+
constructor(registry: PlatformOperations, settings: OrgSettingsService, themes: ThemesService, db: KernelDb, security: OrgSecuritySettingsService);
|
|
19
21
|
onModuleInit(): void;
|
|
20
22
|
}
|
|
@@ -9,7 +9,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
9
9
|
};
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { z } from "zod";
|
|
12
|
+
import { ApiError } from "../../errors.js";
|
|
12
13
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
14
|
+
import { OrgSecurityPatchSchema, OrgSecurityQuerySchema, OrgSecuritySettingsService, } from "../../orgs/security-settings.service.js";
|
|
13
15
|
import { OrgSettingsPatchSchema, OrgSettingsService } from "../../orgs/settings.service.js";
|
|
14
16
|
import { ThemesService } from "../../themes/themes.service.js";
|
|
15
17
|
import { defineOperation } from "../operation.js";
|
|
@@ -33,17 +35,87 @@ let OrgSettingsOperations = class OrgSettingsOperations {
|
|
|
33
35
|
settings;
|
|
34
36
|
themes;
|
|
35
37
|
db;
|
|
36
|
-
|
|
38
|
+
security;
|
|
39
|
+
constructor(registry, settings, themes, db, security) {
|
|
37
40
|
this.registry = registry;
|
|
38
41
|
this.settings = settings;
|
|
39
42
|
this.themes = themes;
|
|
40
43
|
this.db = db;
|
|
44
|
+
this.security = security;
|
|
41
45
|
}
|
|
42
46
|
onModuleInit() {
|
|
43
47
|
this.registry.register([
|
|
48
|
+
defineOperation({
|
|
49
|
+
id: "org-security.get",
|
|
50
|
+
description: "Read organization security ceilings and a page of canonical tool policies. Pass nextCursor as cursor to continue.",
|
|
51
|
+
input: OrgSecurityQuerySchema,
|
|
52
|
+
example: { limit: 50 },
|
|
53
|
+
authz: { orgAction: "org.update" },
|
|
54
|
+
mirrors: ["GET /api/v1/orgs/:orgId/settings/security"],
|
|
55
|
+
confirm: "read",
|
|
56
|
+
run: (input, ctx) => this.security.view(ctx.orgId, input),
|
|
57
|
+
}),
|
|
58
|
+
defineOperation({
|
|
59
|
+
id: "org-security.update",
|
|
60
|
+
description: "Narrow organization tool policy, unattended Git push denials, allowed permission profiles or project reach. Use the revision from org-security.get. Widen in the organization security settings on the web.",
|
|
61
|
+
input: OrgSecurityPatchSchema,
|
|
62
|
+
example: {
|
|
63
|
+
expectedRevision: "0".repeat(64),
|
|
64
|
+
tools: [{ toolKey: "Bash", policy: "ask", unattendedPolicy: "deny" }],
|
|
65
|
+
},
|
|
66
|
+
authz: { orgAction: "org.update" },
|
|
67
|
+
mirrors: ["PATCH /api/v1/orgs/:orgId/settings/security"],
|
|
68
|
+
confirm: "org",
|
|
69
|
+
summary: (input) => {
|
|
70
|
+
const count = (input.tools?.length ?? 0) + (input.gitPush?.length ?? 0);
|
|
71
|
+
return {
|
|
72
|
+
en: `Update organization security settings (${count} tool and Git rules)`,
|
|
73
|
+
zh: `修改组织安全设置(${count} 条工具及 Git 规则)`,
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
errors: [
|
|
77
|
+
{
|
|
78
|
+
code: "org.security_revision_conflict",
|
|
79
|
+
next: "Run org-security.get again to get the latest revision.",
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
code: "org.security_widening_not_allowed",
|
|
83
|
+
next: "Ask an organization admin to open /settings/security on the web.",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
code: "org.security_confirmation_required",
|
|
87
|
+
next: "Ask an organization admin to review the affected agents at /settings/security on the web.",
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
run: async (input, ctx) => {
|
|
91
|
+
try {
|
|
92
|
+
return {
|
|
93
|
+
applied: true,
|
|
94
|
+
...(await this.security.update(ctx.orgId, input, ctx.actorAccountId, {
|
|
95
|
+
onlyNarrows: true,
|
|
96
|
+
auditDetail: viaAgent("org-security.update", ctx),
|
|
97
|
+
})),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (error instanceof ApiError &&
|
|
102
|
+
(error.code === "org.security_widening_not_allowed" ||
|
|
103
|
+
error.code === "org.security_confirmation_required"))
|
|
104
|
+
return { applied: false, code: error.code, message: error.message };
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
handoff: (_input, result) => result?.applied === false
|
|
109
|
+
? {
|
|
110
|
+
kind: "handoff",
|
|
111
|
+
title: { en: "Review organization security", zh: "检查组织安全设置" },
|
|
112
|
+
target: { type: "link", url: "/settings/security" },
|
|
113
|
+
}
|
|
114
|
+
: null,
|
|
115
|
+
}),
|
|
44
116
|
defineOperation({
|
|
45
117
|
id: "org-settings.get",
|
|
46
|
-
description: "Read this org's settings: toolSearch, locale,
|
|
118
|
+
description: "Read this org's settings: toolSearch, locale, allowedProfiles and projectReach (edit these with org-security.update), platformTool (on, read-only or off), outsideSandbox (allowed or off: whether the org's devices may be granted running a call outside their sandbox; absent follows the deployment, and the org may never exceed it), deviceNetwork (the org's device sandbox network: default, the network a device gets when its owner chooses none, and ceiling, the widest a device may choose, each open or allowlist and absent following the platform; base platform or none; extraHosts the org adds; excludedHosts platform hosts it drops; open means any public host, while loopback, private and cloud metadata addresses stay closed), wakeOnBackgroundTask (absent means it follows the deployment), theme (the org's default theme id, null or absent following the platform, and personal: allowed or locked), navigation (pluginPages: per plugin page contribution key <extension>/<contribution>, the section primary or more an org admin chose; at most 3 primary; absent means every page follows its own suggestion), uiArrangement (per list slot, the extension contributions the org hides and their order; per single slot, the contribution that replaces the built-in as use, null for the built-in; a slot not listed follows the platform), the deployment's outside-sandbox switch (outsideSandbox) and device network (deviceNetwork: its default and ceiling, its allowlist, orgHosts: extend lets the org go beyond the allowlist, within makes it the hosts' ceiling, and off for the platform kill switch), effectiveNetwork (the mode and hosts the org's devices really get), externalSharing (on or off, absent meaning off: whether members may share conversation files through public links; the deployment's externalSharing must be allow too) with the deployment's externalSharing and shareMaxExpiryDays, promptSuggestions (on or off, absent meaning on: whether the composer suggests the person's next message after a completed run; the deployment's promptSuggestions must be on too) with the deployment's promptSuggestions, the sandbox cpu / memory limits in effect, and fileLibraryBytes (the org-wide storage total for org admins).",
|
|
47
119
|
input: z.object({}).strict(),
|
|
48
120
|
example: {},
|
|
49
121
|
authz: { orgAction: "org.read" },
|
|
@@ -151,6 +223,7 @@ OrgSettingsOperations = __decorate([
|
|
|
151
223
|
__param(0, Inject(PlatformOperations)),
|
|
152
224
|
__param(1, Inject(OrgSettingsService)),
|
|
153
225
|
__param(2, Inject(ThemesService)),
|
|
154
|
-
__param(3, Inject(KernelDb))
|
|
226
|
+
__param(3, Inject(KernelDb)),
|
|
227
|
+
__param(4, Inject(OrgSecuritySettingsService))
|
|
155
228
|
], OrgSettingsOperations);
|
|
156
229
|
export { OrgSettingsOperations };
|
|
@@ -144,12 +144,18 @@ export function permissionContextText(payload) {
|
|
|
144
144
|
`Permission context for new operations: ${p.availability.state === "supported" && p.effectiveProfile !== null ? labels[p.effectiveProfile] : "unavailable"}.`,
|
|
145
145
|
"This context supersedes earlier device-mode descriptions for new operations.",
|
|
146
146
|
];
|
|
147
|
+
if (p.allowedProfiles)
|
|
148
|
+
lines.push(`Permission profiles available in this organization: ${p.allowedProfiles.map((profile) => labels[profile]).join(", ")}.`);
|
|
147
149
|
if (s !== null) {
|
|
148
150
|
if (box !== null)
|
|
149
151
|
lines.push(box.boundary === "instance"
|
|
150
152
|
? "Sandbox: the same under every profile; the provisioned device instance is the sandbox, its whole filesystem is in scope and its outer network applies."
|
|
151
153
|
: "Sandbox: the same under every profile; new commands run in the device's OS sandbox, limited to the directories and network below.");
|
|
152
154
|
lines.push(`Working directory: ${permissionQuote(s.workingRoot)}.`);
|
|
155
|
+
if (box?.projectReach !== undefined)
|
|
156
|
+
lines.push(box.projectReach === "workspace"
|
|
157
|
+
? "Project reach is capped at the device workspace."
|
|
158
|
+
: "Project reach is capped at the device owner's approved paths.");
|
|
153
159
|
if (s.filesystem.kind === "scoped") {
|
|
154
160
|
lines.push("Readable files: set by this device's provider, not by the permission profile.", `Writable directories: ${arrayText(s.filesystem.writeDirectories)}.`);
|
|
155
161
|
}
|
|
@@ -33,12 +33,15 @@ export interface DispatchDeps {
|
|
|
33
33
|
*/
|
|
34
34
|
commitDispatch: (a: DispatchArgs, plan: DispatchPlan, child: ChildWriter) => Promise<DispatchCommit | null>;
|
|
35
35
|
}
|
|
36
|
+
/** Apply the tool admission fence to the one transaction that writes this dispatch. */
|
|
37
|
+
export type DispatchAdmission = <T>(commit: () => Promise<T>) => Promise<T>;
|
|
36
38
|
/** One dispatch's call. */
|
|
37
39
|
export interface DispatchArgs {
|
|
38
40
|
ctx: ToolStepContext;
|
|
39
41
|
callId: string;
|
|
40
42
|
input: AgentToolInputT;
|
|
41
43
|
forSkill?: SkillForkDispatch;
|
|
44
|
+
admit?: DispatchAdmission;
|
|
42
45
|
/**
|
|
43
46
|
* The `Agent` call's own record (not for a fork invocation): the logged key its `tool_result`
|
|
44
47
|
* keeps (the rc `agent` for a call logged before the rename), the `tool.called` audit's
|
|
@@ -493,7 +493,8 @@ export async function commit(d, a, plan,
|
|
|
493
493
|
/** Writes the child's events; `checked` is the org agent version the in-lock gates passed. */
|
|
494
494
|
child) {
|
|
495
495
|
const { ctx } = a;
|
|
496
|
-
const
|
|
496
|
+
const write = () => d.commitDispatch(a, plan, child);
|
|
497
|
+
const out = await (a.admit === undefined ? write() : a.admit(write));
|
|
497
498
|
if (out === null)
|
|
498
499
|
return null;
|
|
499
500
|
if (out.kind === "existing") {
|
|
@@ -6,6 +6,7 @@ import type { KernelLogger } from "../../log.js";
|
|
|
6
6
|
import type { ToolStepContext } from "../../tools/pipeline.js";
|
|
7
7
|
import { RunJobs } from "../run-jobs.js";
|
|
8
8
|
import { SubagentDeliveries } from "./deliveries.js";
|
|
9
|
+
import { type DispatchAdmission } from "./dispatch.js";
|
|
9
10
|
/** The message tools' test seams (`SUBAGENT_MESSAGES_HOOKS`; the kernel never provides them). */
|
|
10
11
|
export interface SubagentMessagesHooks {
|
|
11
12
|
/**
|
|
@@ -73,13 +74,14 @@ export declare class SubagentMessages {
|
|
|
73
74
|
/** The pipeline's record of why the call was allowed (the `tool.called` audit of a restart). */
|
|
74
75
|
opts?: {
|
|
75
76
|
authorization?: Record<string, unknown>;
|
|
77
|
+
admit?: DispatchAdmission;
|
|
76
78
|
}): Promise<MessageOutcome>;
|
|
77
79
|
/**
|
|
78
80
|
* A sub-agent's note (`SendMessage` to `"parent"`) or report (`SubagentHandback`) to its parent
|
|
79
81
|
* (agent map spec §4.3, §5.2): one `subagent_delivery` of this run in the parent's log,
|
|
80
82
|
* idempotent by the call; an active parent run absorbs it, an idle parent is woken.
|
|
81
83
|
*/
|
|
82
|
-
toParent(ctx: ToolStepContext, kind: "note" | "report", text: string, callId: string): Promise<MessageOutcome>;
|
|
84
|
+
toParent(ctx: ToolStepContext, kind: "note" | "report", text: string, callId: string, admit?: DispatchAdmission): Promise<MessageOutcome>;
|
|
83
85
|
/**
|
|
84
86
|
* Appends the message to a sub-agent whose run is active, under its row lock (a run's terminal
|
|
85
87
|
* write takes the same lock, so the run is still active when the message lands). Null when no
|
|
@@ -100,7 +100,7 @@ let SubagentMessages = class SubagentMessages {
|
|
|
100
100
|
/** The pipeline's record of why the call was allowed (the `tool.called` audit of a restart). */
|
|
101
101
|
opts = {}) {
|
|
102
102
|
if (childId === PARENT_TARGET && ctx.parent !== undefined) {
|
|
103
|
-
return this.toParent(ctx, "note", text, callId);
|
|
103
|
+
return this.toParent(ctx, "note", text, callId, opts.admit);
|
|
104
104
|
}
|
|
105
105
|
const child = await this.db
|
|
106
106
|
.selectFrom("conversations")
|
|
@@ -149,7 +149,8 @@ let SubagentMessages = class SubagentMessages {
|
|
|
149
149
|
const active = prior === undefined && (await this.activeRunOf(child.id)) !== undefined;
|
|
150
150
|
await this.hooks?.afterStatusRead?.(child.id);
|
|
151
151
|
if (active) {
|
|
152
|
-
const
|
|
152
|
+
const write = () => this.appendToRunning(ctx, callId, child.id, text, narrowFollowUp(frozen, current));
|
|
153
|
+
const seq = await (opts.admit === undefined ? write() : opts.admit(write));
|
|
153
154
|
if (seq !== null) {
|
|
154
155
|
await this.eventLog.notify(child.id, seq);
|
|
155
156
|
return { content: sentToRunningText(target), isError: false };
|
|
@@ -165,7 +166,7 @@ let SubagentMessages = class SubagentMessages {
|
|
|
165
166
|
resumed: true,
|
|
166
167
|
model: started.payload.definition.model,
|
|
167
168
|
tierFallback: false,
|
|
168
|
-
}, frozen);
|
|
169
|
+
}, frozen, opts.admit);
|
|
169
170
|
if (out === "active")
|
|
170
171
|
continue;
|
|
171
172
|
return out;
|
|
@@ -177,7 +178,7 @@ let SubagentMessages = class SubagentMessages {
|
|
|
177
178
|
* (agent map spec §4.3, §5.2): one `subagent_delivery` of this run in the parent's log,
|
|
178
179
|
* idempotent by the call; an active parent run absorbs it, an idle parent is woken.
|
|
179
180
|
*/
|
|
180
|
-
async toParent(ctx, kind, text, callId) {
|
|
181
|
+
async toParent(ctx, kind, text, callId, admit) {
|
|
181
182
|
if (ctx.parent === undefined)
|
|
182
183
|
return refused(HANDBACK_NOT_A_CHILD_TEXT);
|
|
183
184
|
const row = await deliveryRowOfChildRun(this.db, ctx.runId);
|
|
@@ -186,7 +187,8 @@ let SubagentMessages = class SubagentMessages {
|
|
|
186
187
|
// a fork invocation's parent run waits for the final reply (phase D, agent map spec §5.4)
|
|
187
188
|
if (row.forSkill === true)
|
|
188
189
|
return refused(HANDBACK_FORK_TEXT);
|
|
189
|
-
|
|
190
|
+
const write = () => this.deliveries.deliverIn(row, { kind, text }, { idemKey: toParentIdemKey(ctx.runId, callId) });
|
|
191
|
+
await (admit === undefined ? write() : admit(write));
|
|
190
192
|
return {
|
|
191
193
|
content: kind === "report" ? HANDBACK_RESULT_TEXT : SENT_TO_PARENT_TEXT,
|
|
192
194
|
isError: false,
|
|
@@ -217,11 +219,12 @@ let SubagentMessages = class SubagentMessages {
|
|
|
217
219
|
* is locked only after no active run was found, and again checked under the lock. `"active"`
|
|
218
220
|
* when a run is active after all (the caller appends to it instead).
|
|
219
221
|
*/
|
|
220
|
-
async restart(ctx, callId, text, target, authorization, plan, frozen) {
|
|
222
|
+
async restart(ctx, callId, text, target, authorization, plan, frozen, admit) {
|
|
221
223
|
const a = {
|
|
222
224
|
ctx,
|
|
223
225
|
callId,
|
|
224
226
|
input: { description: target.description || target.id, prompt: text },
|
|
227
|
+
...(admit !== undefined && { admit }),
|
|
225
228
|
call: {
|
|
226
229
|
toolKey: SEND_MESSAGE,
|
|
227
230
|
authorization: authorization ?? { policy: "allow" },
|