@capybara-hq/kernel 0.1.0-rc.4 → 0.1.0-rc.5
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 +61 -5
- package/dist/admin/admin.controller.d.ts +39 -13
- package/dist/admin/admin.controller.js +33 -17
- package/dist/admin/extensions.controller.d.ts +16 -2
- package/dist/admin/extensions.controller.js +26 -6
- package/dist/admin/setup-lock.d.ts +1 -1
- package/dist/admin/setup-lock.js +1 -1
- package/dist/admin/setup.controller.d.ts +1 -1
- package/dist/admin/setup.controller.js +1 -1
- package/dist/admin/setup.service.d.ts +4 -4
- package/dist/admin/setup.service.js +8 -8
- package/dist/agents/agent-lookup.d.ts +16 -0
- package/dist/agents/agent-lookup.js +11 -0
- package/dist/agents/agents.controller.d.ts +76 -1
- package/dist/agents/agents.controller.js +90 -11
- package/dist/agents/agents.module.d.ts +4 -1
- package/dist/agents/agents.module.js +32 -6
- package/dist/agents/agents.service.d.ts +51 -22
- package/dist/agents/agents.service.js +172 -70
- package/dist/agents/definition.d.ts +49 -0
- package/dist/agents/definition.js +45 -0
- package/dist/agents/from-template.d.ts +106 -0
- package/dist/agents/from-template.js +649 -0
- package/dist/agents/from-template.service.d.ts +60 -0
- package/dist/agents/from-template.service.js +161 -0
- package/dist/agents/org-templates.d.ts +176 -0
- package/dist/agents/org-templates.js +827 -0
- package/dist/agents/pending-connector-requests.d.ts +77 -0
- package/dist/agents/pending-connector-requests.js +215 -0
- package/dist/agents/pending-connectors.controller.d.ts +39 -0
- package/dist/agents/pending-connectors.controller.js +91 -0
- package/dist/agents/pending-connectors.service.d.ts +62 -0
- package/dist/agents/pending-connectors.service.js +282 -0
- package/dist/agents/templates.controller.d.ts +86 -5
- package/dist/agents/templates.controller.js +171 -7
- package/dist/agents/templates.d.ts +127 -23
- package/dist/agents/templates.js +475 -52
- package/dist/background/background.module.js +8 -1
- package/dist/background/finish.d.ts +3 -2
- package/dist/background/launch-lock.d.ts +4 -3
- package/dist/background/launch-lock.js +4 -3
- package/dist/background/poll.job.d.ts +9 -6
- package/dist/background/poll.job.js +30 -22
- package/dist/background/session.d.ts +13 -2
- package/dist/background/session.js +13 -0
- package/dist/background/stop.d.ts +12 -6
- package/dist/background/stop.js +57 -39
- package/dist/background/store.d.ts +18 -6
- package/dist/background/store.js +12 -6
- package/dist/background/tasks.service.d.ts +15 -5
- package/dist/background/tasks.service.js +42 -17
- package/dist/background/wake-rules.d.ts +27 -18
- package/dist/background/wake-rules.js +52 -22
- package/dist/background/wake.d.ts +13 -11
- package/dist/background/wake.js +20 -14
- package/dist/catalog/admin-catalog.controller.d.ts +129 -30
- package/dist/catalog/admin-catalog.controller.js +213 -42
- package/dist/catalog/catalog-content.d.ts +58 -32
- package/dist/catalog/catalog-content.js +34 -8
- package/dist/catalog/catalog-import.module.d.ts +7 -0
- package/dist/catalog/catalog-import.module.js +60 -0
- package/dist/catalog/catalog-items.d.ts +111 -7
- package/dist/catalog/catalog-items.js +279 -13
- package/dist/catalog/catalog-scope.service.d.ts +260 -0
- package/dist/catalog/catalog-scope.service.js +1116 -0
- package/dist/catalog/catalog.module.d.ts +7 -9
- package/dist/catalog/catalog.module.js +41 -31
- package/dist/catalog/catalog.service.d.ts +101 -29
- package/dist/catalog/catalog.service.js +104 -106
- package/dist/catalog/cli.d.ts +11 -1
- package/dist/catalog/cli.js +26 -1
- package/dist/catalog/component-promotion.d.ts +96 -0
- package/dist/catalog/component-promotion.js +395 -0
- package/dist/catalog/component-scope.controller.d.ts +152 -0
- package/dist/catalog/component-scope.controller.js +287 -0
- package/dist/catalog/component-scope.service.d.ts +303 -0
- package/dist/catalog/component-scope.service.js +936 -0
- package/dist/catalog/component-state.d.ts +174 -0
- package/dist/catalog/component-state.js +437 -0
- package/dist/catalog/job-ids.d.ts +30 -0
- package/dist/catalog/job-ids.js +25 -0
- package/dist/catalog/marketplace-fetch.d.ts +1 -1
- package/dist/catalog/marketplaces.controller.d.ts +22 -5
- package/dist/catalog/marketplaces.controller.js +56 -7
- package/dist/catalog/marketplaces.service.d.ts +54 -14
- package/dist/catalog/marketplaces.service.js +71 -22
- package/dist/catalog/org-catalog.controller.d.ts +125 -34
- package/dist/catalog/org-catalog.controller.js +181 -65
- package/dist/catalog/org-catalog.service.d.ts +65 -33
- package/dist/catalog/org-catalog.service.js +324 -157
- package/dist/catalog/org-extension-switch.d.ts +41 -0
- package/dist/catalog/org-extension-switch.js +115 -0
- package/dist/catalog/org-extension.controller.d.ts +119 -0
- package/dist/catalog/org-extension.controller.js +266 -0
- package/dist/catalog/org-plugin-uploads.controller.d.ts +98 -0
- package/dist/catalog/org-plugin-uploads.controller.js +213 -0
- package/dist/catalog/org-plugin-uploads.d.ts +63 -0
- package/dist/catalog/org-plugin-uploads.js +116 -0
- package/dist/catalog/owned-items.d.ts +184 -0
- package/dist/catalog/owned-items.js +789 -0
- package/dist/catalog/owned-plugin-cleanup.d.ts +56 -0
- package/dist/catalog/owned-plugin-cleanup.js +194 -0
- package/dist/catalog/ownership.d.ts +172 -0
- package/dist/catalog/ownership.js +326 -0
- package/dist/catalog/platform-components.d.ts +221 -0
- package/dist/catalog/platform-components.js +761 -0
- package/dist/catalog/platform-migration.d.ts +115 -0
- package/dist/catalog/platform-migration.js +582 -0
- package/dist/catalog/plugin-import.d.ts +178 -34
- package/dist/catalog/plugin-import.js +622 -82
- package/dist/catalog/plugin-install.d.ts +185 -41
- package/dist/catalog/plugin-install.js +758 -126
- package/dist/catalog/plugin-upgrade.d.ts +260 -225
- package/dist/catalog/plugin-upgrade.js +1147 -1136
- package/dist/catalog/request-rules.d.ts +65 -0
- package/dist/catalog/request-rules.js +217 -0
- package/dist/catalog/requests.service.d.ts +193 -118
- package/dist/catalog/requests.service.js +526 -343
- package/dist/catalog/reserved-names.d.ts +8 -0
- package/dist/catalog/reserved-names.js +42 -0
- package/dist/catalog/scope-orgs.d.ts +21 -0
- package/dist/catalog/scope-orgs.js +67 -0
- package/dist/catalog/scope-state.d.ts +35 -0
- package/dist/catalog/scope-state.js +87 -0
- package/dist/catalog/scope-sync-workers.d.ts +7 -0
- package/dist/catalog/scope-sync-workers.js +29 -0
- package/dist/catalog/scope-sync.d.ts +176 -0
- package/dist/catalog/scope-sync.js +576 -0
- package/dist/catalog/scope.d.ts +42 -0
- package/dist/catalog/scope.js +42 -0
- package/dist/catalog/unshare.d.ts +22 -0
- package/dist/catalog/unshare.js +118 -0
- package/dist/channels/actions.js +1 -0
- package/dist/channels/cards.js +20 -2
- package/dist/channels/channels.module.js +2 -0
- package/dist/channels/inbound.d.ts +9 -1
- package/dist/channels/inbound.js +67 -5
- package/dist/channels/phrases.d.ts +35 -0
- package/dist/channels/phrases.js +29 -0
- package/dist/config/docs.js +3 -1
- package/dist/config/schema.d.ts +6 -2
- package/dist/config/schema.js +46 -22
- package/dist/conversations/access.d.ts +6 -4
- package/dist/conversations/access.js +27 -5
- package/dist/conversations/agent-tree.d.ts +46 -0
- package/dist/conversations/agent-tree.js +92 -0
- package/dist/conversations/conversations.controller.d.ts +43 -18
- package/dist/conversations/conversations.controller.js +79 -38
- package/dist/conversations/conversations.module.d.ts +1 -1
- package/dist/conversations/conversations.module.js +7 -7
- package/dist/conversations/conversations.service.d.ts +69 -12
- package/dist/conversations/conversations.service.js +106 -27
- package/dist/conversations/environment-status.d.ts +24 -0
- package/dist/conversations/environment-status.js +71 -0
- package/dist/conversations/event-log.d.ts +20 -5
- package/dist/conversations/event-log.js +60 -0
- package/dist/conversations/events.d.ts +84 -2
- package/dist/conversations/events.js +91 -17
- package/dist/conversations/queue.service.d.ts +1 -1
- package/dist/conversations/queue.service.js +5 -0
- package/dist/conversations/titles.d.ts +5 -3
- package/dist/conversations/titles.js +21 -8
- package/dist/conversations/tree.d.ts +17 -0
- package/dist/conversations/tree.js +42 -0
- package/dist/ctx/create-ctx.d.ts +5 -0
- package/dist/ctx/create-ctx.js +15 -5
- package/dist/db/kernel-schema.d.ts +362 -18
- package/dist/environments/access.d.ts +41 -0
- package/dist/environments/access.js +77 -0
- package/dist/environments/conversation-environments.d.ts +61 -0
- package/dist/environments/conversation-environments.js +170 -0
- package/dist/environments/dto.d.ts +25 -0
- package/dist/environments/dto.js +12 -0
- package/dist/environments/environments.controller.d.ts +33 -0
- package/dist/environments/environments.controller.js +110 -0
- package/dist/environments/environments.module.d.ts +8 -0
- package/dist/environments/environments.module.js +27 -0
- package/dist/environments/environments.service.d.ts +153 -0
- package/dist/environments/environments.service.js +541 -0
- package/dist/environments/legacy-cleanup.job.d.ts +34 -0
- package/dist/environments/legacy-cleanup.job.js +141 -0
- package/dist/errors.d.ts +82 -2
- package/dist/errors.js +82 -2
- package/dist/evals/reconstruct.d.ts +18 -9
- package/dist/evals/reconstruct.js +26 -7
- package/dist/evals/run-replay.d.ts +4 -2
- package/dist/evals/run-replay.js +16 -4
- package/dist/evals/step-replay.d.ts +2 -5
- package/dist/evals/step-replay.js +1 -1
- package/dist/evals/trajectory.service.d.ts +8 -3
- package/dist/evals/trajectory.service.js +26 -14
- package/dist/evals/worker.d.ts +5 -5
- package/dist/evals/worker.js +9 -3
- package/dist/extensions/admin-ops.d.ts +36 -10
- package/dist/extensions/admin-ops.js +65 -42
- package/dist/extensions/admin-view.d.ts +37 -10
- package/dist/extensions/admin-view.js +103 -20
- package/dist/extensions/bootstrap.d.ts +17 -4
- package/dist/extensions/bootstrap.js +70 -9
- package/dist/extensions/cli.d.ts +12 -0
- package/dist/extensions/cli.js +11 -2
- package/dist/extensions/deployment-config.d.ts +28 -5
- package/dist/extensions/deployment-config.js +48 -7
- package/dist/extensions/effective-config.d.ts +127 -0
- package/dist/extensions/effective-config.js +368 -0
- package/dist/extensions/extensions.module.js +8 -2
- package/dist/extensions/hooks.d.ts +37 -4
- package/dist/extensions/hooks.js +82 -16
- package/dist/extensions/host.d.ts +19 -1
- package/dist/extensions/host.js +30 -7
- package/dist/extensions/installs.d.ts +20 -8
- package/dist/extensions/installs.js +37 -15
- package/dist/extensions/org-config.d.ts +75 -6
- package/dist/extensions/org-config.js +184 -32
- package/dist/extensions/org-levels.d.ts +37 -0
- package/dist/extensions/org-levels.js +71 -0
- package/dist/extensions/org-overrides.d.ts +151 -0
- package/dist/extensions/org-overrides.js +524 -0
- package/dist/extensions/permission-view.d.ts +16 -4
- package/dist/extensions/permission-view.js +4 -4
- package/dist/extensions/plugin-items.d.ts +21 -0
- package/dist/extensions/plugin-items.js +42 -0
- package/dist/extensions/point-defaults.d.ts +12 -5
- package/dist/extensions/point-defaults.js +37 -9
- package/dist/extensions/resolve.d.ts +5 -1
- package/dist/extensions/resolve.js +15 -2
- package/dist/files/previewers.d.ts +8 -1
- package/dist/files/previewers.js +35 -6
- package/dist/http/api.module.js +23 -3
- package/dist/http/app.d.ts +11 -2
- package/dist/http/app.js +31 -5
- package/dist/identity/accounts.d.ts +29 -29
- package/dist/identity/accounts.js +47 -47
- package/dist/identity/audit.d.ts +2 -1
- package/dist/identity/auth.guard.d.ts +13 -5
- package/dist/identity/auth.guard.js +26 -9
- package/dist/identity/identity.module.d.ts +1 -1
- package/dist/identity/identity.module.js +4 -4
- package/dist/identity/me.controller.js +1 -1
- package/dist/identity/principal.d.ts +3 -3
- package/dist/identity/principal.js +3 -3
- package/dist/identity/settings.d.ts +22 -11
- package/dist/identity/settings.js +53 -18
- package/dist/identity/{enterprise-admin.d.ts → super-admin.d.ts} +5 -5
- package/dist/identity/{enterprise-admin.js → super-admin.js} +24 -24
- package/dist/inbox/inbox.module.d.ts +4 -1
- package/dist/inbox/inbox.module.js +7 -3
- package/dist/inbox/inbox.service.d.ts +62 -3
- package/dist/inbox/inbox.service.js +74 -4
- package/dist/inbox/org-notices.d.ts +63 -0
- package/dist/inbox/org-notices.js +91 -0
- package/dist/inbox/platform-inbox.controller.d.ts +23 -0
- package/dist/inbox/platform-inbox.controller.js +58 -0
- package/dist/inbox/platform-inbox.service.d.ts +151 -0
- package/dist/inbox/platform-inbox.service.js +263 -0
- package/dist/inbox/platform-notices.d.ts +19 -0
- package/dist/inbox/platform-notices.js +9 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/infra/cli/kernel-cli.module.js +9 -1
- package/dist/infra/config/kernel-config.service.js +21 -1
- package/dist/infra/database/xact-lock.d.ts +1 -1
- package/dist/infra/database/xact-lock.js +1 -1
- package/dist/infra/events/kernel-events.d.ts +11 -2
- package/dist/infra/queue/add-job-once.d.ts +14 -0
- package/dist/infra/queue/add-job-once.js +16 -0
- package/dist/kernel.module.js +6 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +1 -1
- package/dist/lifecycle/kernel-lifecycle.js +4 -4
- package/dist/models/prices.d.ts +5 -5
- package/dist/models/prices.js +4 -4
- package/dist/models/purposes.controller.d.ts +6 -4
- package/dist/models/purposes.controller.js +13 -7
- package/dist/models/purposes.d.ts +20 -9
- package/dist/models/purposes.js +17 -8
- package/dist/orgs/directory-sync.d.ts +14 -5
- package/dist/orgs/directory-sync.js +41 -17
- package/dist/orgs/offboarding.d.ts +9 -7
- package/dist/orgs/offboarding.js +28 -17
- package/dist/orgs/org-lock.d.ts +5 -0
- package/dist/orgs/org-lock.js +13 -0
- package/dist/orgs/org.guard.d.ts +10 -0
- package/dist/orgs/org.guard.js +43 -32
- package/dist/orgs/orgs.module.js +3 -0
- package/dist/orgs/orgs.service.d.ts +20 -7
- package/dist/orgs/orgs.service.js +32 -12
- package/dist/orgs/roles.d.ts +1 -1
- package/dist/orgs/roles.js +5 -1
- package/dist/orgs/settings.controller.d.ts +1 -1
- package/dist/orgs/settings.service.d.ts +15 -3
- package/dist/orgs/settings.service.js +6 -2
- package/dist/overrides.d.ts +3 -0
- package/dist/overrides.js +2 -0
- package/dist/platform/actor.d.ts +48 -0
- package/dist/platform/actor.js +100 -0
- package/dist/platform/agent-docs.d.ts +18 -0
- package/dist/platform/agent-docs.js +59 -0
- package/dist/platform/availability.d.ts +14 -0
- package/dist/platform/availability.js +43 -0
- package/dist/platform/errors.d.ts +11 -0
- package/dist/platform/errors.js +26 -0
- package/dist/platform/exclusions.d.ts +12 -0
- package/dist/platform/exclusions.js +1387 -0
- package/dist/platform/method.d.ts +6 -0
- package/dist/platform/method.js +15 -0
- package/dist/platform/operation.d.ts +92 -0
- package/dist/platform/operation.js +35 -0
- package/dist/platform/ops/agent-templates.ops.d.ts +14 -0
- package/dist/platform/ops/agent-templates.ops.js +92 -0
- package/dist/platform/ops/agents.ops.d.ts +19 -0
- package/dist/platform/ops/agents.ops.js +294 -0
- package/dist/platform/ops/connectors.ops.d.ts +15 -0
- package/dist/platform/ops/connectors.ops.js +126 -0
- package/dist/platform/ops/errors.d.ts +11 -0
- package/dist/platform/ops/errors.js +22 -0
- package/dist/platform/ops/extensions.ops.d.ts +19 -0
- package/dist/platform/ops/extensions.ops.js +116 -0
- package/dist/platform/ops/marketplaces.ops.d.ts +16 -0
- package/dist/platform/ops/marketplaces.ops.js +157 -0
- package/dist/platform/ops/paging.d.ts +14 -0
- package/dist/platform/ops/paging.js +20 -0
- package/dist/platform/ops/platform.ops.d.ts +23 -0
- package/dist/platform/ops/platform.ops.js +158 -0
- package/dist/platform/ops/plugins.ops.d.ts +33 -0
- package/dist/platform/ops/plugins.ops.js +377 -0
- package/dist/platform/ops/requests.ops.d.ts +14 -0
- package/dist/platform/ops/requests.ops.js +153 -0
- package/dist/platform/ops/role.d.ts +4 -0
- package/dist/platform/ops/role.js +10 -0
- package/dist/platform/ops/skills.ops.d.ts +13 -0
- package/dist/platform/ops/skills.ops.js +98 -0
- package/dist/platform/ops/summary.d.ts +10 -0
- package/dist/platform/ops/summary.js +18 -0
- package/dist/platform/platform-ops.module.d.ts +7 -0
- package/dist/platform/platform-ops.module.js +55 -0
- package/dist/platform/platform.module.d.ts +8 -0
- package/dist/platform/platform.module.js +25 -0
- package/dist/platform/redact-orgs.d.ts +7 -0
- package/dist/platform/redact-orgs.js +52 -0
- package/dist/platform/registry.d.ts +30 -0
- package/dist/platform/registry.js +111 -0
- package/dist/roles/worker-role.d.ts +6 -4
- package/dist/roles/worker-role.js +14 -7
- package/dist/roles/worker.module.d.ts +1 -1
- package/dist/roles/worker.module.js +9 -1
- package/dist/runtime/context/build.d.ts +6 -4
- package/dist/runtime/context/build.js +26 -7
- package/dist/runtime/context/claude-tools.d.ts +2 -1
- package/dist/runtime/context/claude-tools.js +5 -4
- package/dist/runtime/context/compaction.js +9 -0
- package/dist/runtime/context/reminders.d.ts +2 -0
- package/dist/runtime/context/reminders.js +2 -0
- package/dist/runtime/context/skills.js +9 -2
- package/dist/runtime/context/tool-changes.d.ts +27 -0
- package/dist/runtime/context/tool-changes.js +60 -0
- package/dist/runtime/hook-calls.js +2 -0
- package/dist/runtime/langgraph-loop.d.ts +3 -1
- package/dist/runtime/langgraph-loop.js +35 -17
- package/dist/runtime/loop.d.ts +32 -4
- package/dist/runtime/maintenance.d.ts +7 -4
- package/dist/runtime/maintenance.js +23 -8
- package/dist/runtime/model-call.d.ts +30 -8
- package/dist/runtime/model-call.js +69 -19
- package/dist/runtime/run-control.d.ts +11 -1
- package/dist/runtime/run-control.js +12 -0
- package/dist/runtime/run-drafts.d.ts +85 -0
- package/dist/runtime/run-drafts.js +230 -0
- package/dist/runtime/run-jobs.d.ts +3 -5
- package/dist/runtime/run-jobs.js +3 -7
- package/dist/runtime/run-queue.d.ts +37 -3
- package/dist/runtime/run-queue.js +188 -11
- package/dist/runtime/run-worker.d.ts +11 -5
- package/dist/runtime/run-worker.js +54 -31
- package/dist/runtime/runtime.module.js +3 -0
- package/dist/runtime/step-log.d.ts +9 -4
- package/dist/runtime/step-log.js +8 -5
- package/dist/runtime/stream.controller.d.ts +23 -1
- package/dist/runtime/stream.controller.js +60 -3
- package/dist/runtime/stream.d.ts +4 -1
- package/dist/runtime/stream.js +27 -3
- package/dist/runtime/subagents/child.d.ts +55 -7
- package/dist/runtime/subagents/child.js +105 -7
- package/dist/runtime/subagents/definition.d.ts +12 -3
- package/dist/runtime/subagents/definition.js +43 -29
- package/dist/runtime/subagents/deliveries.d.ts +71 -0
- package/dist/runtime/subagents/deliveries.js +228 -0
- package/dist/runtime/subagents/dispatch.d.ts +115 -26
- package/dist/runtime/subagents/dispatch.js +212 -141
- package/dist/runtime/subagents/limits.d.ts +24 -5
- package/dist/runtime/subagents/limits.js +40 -6
- package/dist/runtime/subagents/messages.d.ts +95 -0
- package/dist/runtime/subagents/messages.js +328 -0
- package/dist/runtime/subagents/preamble.d.ts +4 -4
- package/dist/runtime/subagents/preamble.js +9 -7
- package/dist/runtime/subagents/progress.d.ts +8 -6
- package/dist/runtime/subagents/progress.js +11 -6
- package/dist/runtime/subagents/render.d.ts +30 -0
- package/dist/runtime/subagents/render.js +53 -0
- package/dist/runtime/subagents/roster.d.ts +24 -7
- package/dist/runtime/subagents/roster.js +47 -11
- package/dist/runtime/subagents/skill-fork.d.ts +3 -2
- package/dist/runtime/subagents/skill-fork.js +8 -4
- package/dist/runtime/subagents/status.d.ts +14 -0
- package/dist/runtime/subagents/status.js +23 -0
- package/dist/runtime/subagents/subagents.service.d.ts +7 -4
- package/dist/runtime/subagents/subagents.service.js +11 -6
- package/dist/runtime/usage-report.js +17 -12
- package/dist/runtime/waits.d.ts +140 -37
- package/dist/runtime/waits.js +394 -106
- package/dist/sandbox/jobs.d.ts +40 -13
- package/dist/sandbox/jobs.js +57 -20
- package/dist/sandbox/leases.d.ts +37 -54
- package/dist/sandbox/leases.js +71 -115
- package/dist/sandbox/providers.d.ts +2 -2
- package/dist/sandbox/providers.js +1 -1
- package/dist/sandbox/sandbox.module.d.ts +3 -2
- package/dist/sandbox/sandbox.module.js +4 -3
- package/dist/sandbox/sandbox.service.d.ts +229 -134
- package/dist/sandbox/sandbox.service.js +630 -409
- package/dist/skills/catalog.d.ts +3 -2
- package/dist/skills/catalog.js +21 -43
- package/dist/skills/changes.controller.d.ts +7 -0
- package/dist/skills/changes.controller.js +19 -1
- package/dist/skills/invoke.js +8 -3
- package/dist/skills/package.d.ts +20 -1
- package/dist/skills/package.js +28 -1
- package/dist/skills/skills.controller.d.ts +39 -4
- package/dist/skills/skills.controller.js +88 -10
- package/dist/skills/skills.module.js +10 -1
- package/dist/skills/skills.service.d.ts +106 -26
- package/dist/skills/skills.service.js +421 -75
- package/dist/skills/usable.d.ts +81 -0
- package/dist/skills/usable.js +379 -0
- package/dist/tools/approvals.service.d.ts +20 -2
- package/dist/tools/approvals.service.js +23 -4
- package/dist/tools/builtin-names.d.ts +21 -5
- package/dist/tools/builtin-names.js +30 -5
- package/dist/tools/builtins/agent.d.ts +23 -21
- package/dist/tools/builtins/agent.js +62 -55
- package/dist/tools/builtins/builtin-tools.d.ts +6 -2
- package/dist/tools/builtins/builtin-tools.js +37 -12
- package/dist/tools/builtins/handback.d.ts +28 -0
- package/dist/tools/builtins/handback.js +53 -0
- package/dist/tools/builtins/platform.d.ts +34 -0
- package/dist/tools/builtins/platform.js +362 -0
- package/dist/tools/builtins/sandbox/bash.js +13 -3
- package/dist/tools/builtins/sandbox/common.d.ts +43 -24
- package/dist/tools/builtins/sandbox/common.js +80 -45
- package/dist/tools/builtins/sandbox/edit.js +2 -2
- package/dist/tools/builtins/sandbox/glob.js +2 -2
- package/dist/tools/builtins/sandbox/grep.js +2 -4
- package/dist/tools/builtins/sandbox/index.d.ts +1 -1
- package/dist/tools/builtins/sandbox/index.js +1 -1
- package/dist/tools/builtins/sandbox/read.js +1 -1
- package/dist/tools/builtins/sandbox/task-output.d.ts +14 -3
- package/dist/tools/builtins/sandbox/task-output.js +30 -5
- package/dist/tools/builtins/sandbox/task-stop.js +2 -1
- package/dist/tools/builtins/sandbox/write.js +2 -2
- package/dist/tools/builtins/send-message.d.ts +56 -0
- package/dist/tools/builtins/send-message.js +100 -0
- package/dist/tools/builtins/skill-load.d.ts +22 -14
- package/dist/tools/builtins/skill-load.js +86 -57
- package/dist/tools/builtins/skill-write.js +1 -1
- package/dist/tools/builtins/web/extract.js +5 -1
- package/dist/tools/builtins/web/fetch.js +1 -0
- package/dist/tools/builtins/web/search.js +1 -0
- package/dist/tools/connectors.controller.d.ts +10 -0
- package/dist/tools/connectors.controller.js +12 -0
- package/dist/tools/connectors.service.d.ts +46 -5
- package/dist/tools/connectors.service.js +94 -15
- package/dist/tools/extension-tools.controller.d.ts +14 -0
- package/dist/tools/extension-tools.controller.js +37 -0
- package/dist/tools/info.d.ts +42 -1
- package/dist/tools/info.js +64 -1
- package/dist/tools/org-tool-switches.d.ts +74 -0
- package/dist/tools/org-tool-switches.js +184 -0
- package/dist/tools/pipeline.d.ts +46 -40
- package/dist/tools/pipeline.js +187 -364
- package/dist/tools/policy.d.ts +1 -1
- package/dist/tools/policy.js +36 -16
- package/dist/tools/registry.d.ts +98 -5
- package/dist/tools/registry.js +87 -9
- package/dist/tools/tools.module.js +12 -2
- package/dist/ui/views.d.ts +2 -1
- package/dist/ui/views.js +17 -3
- package/package.json +3 -3
- package/src/migrations/0074_subagent_tree.sql +50 -0
- package/src/migrations/0075_plugin_scope.sql +61 -0
- package/src/migrations/0076_skills_created_by_nullable.sql +6 -0
- package/src/migrations/0077_scope_requests.sql +52 -0
- package/src/migrations/0078_scope_grant_switches.sql +18 -0
- package/src/migrations/0079_scope_live_install_switches.sql +19 -0
- package/src/migrations/0080_rename_enterprise_admin.sql +18 -0
- package/src/migrations/0081_platform_components.sql +129 -0
- package/src/migrations/0082_platform_migration.sql +33 -0
- package/src/migrations/0083_plugin_scope_sync_failures.sql +15 -0
- package/src/migrations/0084_org_owned_items.sql +85 -0
- package/src/migrations/0085_agent_templates_phase4.sql +45 -0
- package/src/migrations/0086_org_layering.sql +30 -0
- package/src/migrations/0087_approval_summary.sql +6 -0
- package/src/migrations/0088_environments.sql +80 -0
- package/dist/catalog/upgrade-targets.d.ts +0 -56
- package/dist/catalog/upgrade-targets.js +0 -90
- package/dist/conversations/sandbox-status.d.ts +0 -24
- package/dist/conversations/sandbox-status.js +0 -52
- package/dist/extensions/org-config.controller.d.ts +0 -32
- package/dist/extensions/org-config.controller.js +0 -70
|
@@ -11,24 +11,33 @@ import { randomUUID } from "node:crypto";
|
|
|
11
11
|
import { parseSkillMd, SKILL_ENTRY_FILE } from "@capybara-hq/plugin-sdk";
|
|
12
12
|
import { Inject, Injectable } from "@nestjs/common";
|
|
13
13
|
import { sql } from "kysely";
|
|
14
|
-
import {
|
|
14
|
+
import { offeredNamed } from "../catalog/component-state.js";
|
|
15
|
+
import { PLATFORM_OWNER } from "../catalog/ownership.js";
|
|
16
|
+
import { PlatformComponents } from "../catalog/platform-components.js";
|
|
17
|
+
import { assertItemInstallable } from "../catalog/request-rules.js";
|
|
15
18
|
import { AttachmentsService, SKILL_PACKAGE_CONTENT_TYPE, skillFilesPrefix, } from "../conversations/attachments.service.js";
|
|
16
19
|
import { ApiError } from "../errors.js";
|
|
17
20
|
import { audit } from "../identity/audit.js";
|
|
18
21
|
import { assertCustomAllowed } from "../identity/settings.js";
|
|
22
|
+
import { notifySharedUpdate } from "../inbox/org-notices.js";
|
|
19
23
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
20
24
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
21
25
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
22
26
|
import { OrgLock } from "../orgs/org-lock.js";
|
|
23
27
|
import { textBytesTokens } from "../runtime/context/tokens.js";
|
|
24
28
|
import { StorageService } from "../storage/storage.service.js";
|
|
29
|
+
import { buildSkillWrite } from "../tools/builtins/skill-write.js";
|
|
25
30
|
import { invocationOf, PINNED_SKILLS_LIMITS } from "./catalog.js";
|
|
26
|
-
import { readSkillPackage,
|
|
31
|
+
import { checkBuiltSkillFiles, readSkillPackage, skillManifest, } from "./package.js";
|
|
32
|
+
import { PLATFORM_SOURCE, platformSkillsOn, platformSource, skillFileStore, skillVersionsById, usableSkills, } from "./usable.js";
|
|
27
33
|
/**
|
|
28
|
-
* The
|
|
29
|
-
* §9.2, Decision 8): the org's own skills
|
|
30
|
-
*
|
|
31
|
-
*
|
|
34
|
+
* The skills named in `skillNames` an org would see twice if catalog item `itemId` brought its
|
|
35
|
+
* skills (spec §9.2, Decision 8; rule 10 of the plugin scope spec): the org's own usable skills
|
|
36
|
+
* (`catalog_item_id` null: uploaded or written by an agent; unlinked, or pinned copies of another
|
|
37
|
+
* plugin's platform skill), org skills of other catalog items, and other plugins' platform skills
|
|
38
|
+
* on in the org. A skill of the same item (an org copy of it, linked or not) is not a conflict;
|
|
39
|
+
* an unpinned copy of another plugin's platform skill counts through that platform skill. In the
|
|
40
|
+
* order of `skillNames`.
|
|
32
41
|
*/
|
|
33
42
|
export async function skillConflicts(db, orgId, itemId, skillNames) {
|
|
34
43
|
if (skillNames.length === 0)
|
|
@@ -36,32 +45,71 @@ export async function skillConflicts(db, orgId, itemId, skillNames) {
|
|
|
36
45
|
const rows = await db
|
|
37
46
|
.selectFrom("skills as s")
|
|
38
47
|
.leftJoin("catalog_items as i", "i.id", "s.catalog_item_id")
|
|
39
|
-
.
|
|
48
|
+
.leftJoin("platform_skills as p", "p.id", "s.platform_skill_id")
|
|
49
|
+
.select([
|
|
50
|
+
"s.name",
|
|
51
|
+
"s.catalog_item_id",
|
|
52
|
+
"s.catalog_version",
|
|
53
|
+
"i.name as item_name",
|
|
54
|
+
"p.catalog_item_id as platform_item_id",
|
|
55
|
+
"p.plugin_name as platform_plugin",
|
|
56
|
+
])
|
|
40
57
|
.where("s.org_id", "=", orgId)
|
|
41
58
|
.where("s.scope", "=", "org")
|
|
42
59
|
.where("s.deleted_at", "is", null)
|
|
43
60
|
.where("s.name", "in", [...skillNames])
|
|
61
|
+
.where((eb) => eb.or([eb("s.platform_skill_id", "is", null), eb("s.pinned_version", "is not", null)]))
|
|
44
62
|
.where((eb) => eb.or([eb("s.catalog_item_id", "is", null), eb("s.catalog_item_id", "<>", itemId)]))
|
|
63
|
+
.where((eb) => eb.or([eb("p.catalog_item_id", "is", null), eb("p.catalog_item_id", "<>", itemId)]))
|
|
45
64
|
.execute();
|
|
46
|
-
const byName = new Map(
|
|
65
|
+
const byName = new Map();
|
|
66
|
+
for (const r of rows) {
|
|
67
|
+
byName.set(r.name, r.catalog_item_id !== null
|
|
68
|
+
? {
|
|
69
|
+
kind: "plugin",
|
|
70
|
+
name: r.item_name ?? r.catalog_item_id,
|
|
71
|
+
version: r.catalog_version ?? "",
|
|
72
|
+
}
|
|
73
|
+
: r.platform_plugin !== null
|
|
74
|
+
? { kind: "plugin", name: r.platform_plugin, version: "" }
|
|
75
|
+
: { kind: "org" });
|
|
76
|
+
}
|
|
77
|
+
const platform = await db
|
|
78
|
+
.selectFrom("platform_skills as p")
|
|
79
|
+
.innerJoin("platform_skill_versions as v", (j) => j.onRef("v.skill_id", "=", "p.id").onRef("v.version", "=", "p.current_version"))
|
|
80
|
+
.select(["p.id", "p.name", "p.plugin_name", "v.catalog_version"])
|
|
81
|
+
.where("p.deleted_at", "is", null)
|
|
82
|
+
.where("p.name", "in", [...skillNames])
|
|
83
|
+
.where((eb) => eb.or([eb("p.catalog_item_id", "is", null), eb("p.catalog_item_id", "<>", itemId)]))
|
|
84
|
+
.execute();
|
|
85
|
+
const on = await platformSkillsOn(db, orgId, platform.map((p) => p.id));
|
|
86
|
+
for (const p of platform) {
|
|
87
|
+
if (!on.has(p.id) || byName.has(p.name))
|
|
88
|
+
continue;
|
|
89
|
+
byName.set(p.name, p.plugin_name !== null
|
|
90
|
+
? { kind: "plugin", name: p.plugin_name, version: p.catalog_version ?? "" }
|
|
91
|
+
: { kind: "plugin", name: "platform", version: "" });
|
|
92
|
+
}
|
|
47
93
|
const out = [];
|
|
48
94
|
for (const name of new Set(skillNames)) {
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
out.push({
|
|
53
|
-
skill: name,
|
|
54
|
-
source: r.catalog_item_id === null
|
|
55
|
-
? { kind: "org" }
|
|
56
|
-
: {
|
|
57
|
-
kind: "plugin",
|
|
58
|
-
name: r.item_name ?? r.catalog_item_id,
|
|
59
|
-
version: r.catalog_version ?? "",
|
|
60
|
-
},
|
|
61
|
-
});
|
|
95
|
+
const source = byName.get(name);
|
|
96
|
+
if (source)
|
|
97
|
+
out.push({ skill: name, source });
|
|
62
98
|
}
|
|
63
99
|
return out;
|
|
64
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* 409 `plugin.skill_conflict` for a new org skill named like platform skills offered to the org
|
|
103
|
+
* (rule 10): one detail per platform skill, its plugin as the source.
|
|
104
|
+
*/
|
|
105
|
+
function platformNameTaken(name, offered) {
|
|
106
|
+
const sources = offered.map((p) => ({
|
|
107
|
+
skill: name,
|
|
108
|
+
source: { kind: "plugin", name: p.plugin ?? "platform", version: "" },
|
|
109
|
+
}));
|
|
110
|
+
const by = sources.map((s) => `plugin "${s.source.name}"`).join(", ");
|
|
111
|
+
return new ApiError("plugin.skill_conflict", `Skill "${name}" is offered to this organization by ${by}; skill names are unique in an organization. Rename your skill and upload it again.`, sources);
|
|
112
|
+
}
|
|
65
113
|
/** One line of the conflict message (spec §9.2). */
|
|
66
114
|
export function skillConflictLine(c) {
|
|
67
115
|
const source = c.source.kind === "org"
|
|
@@ -79,7 +127,8 @@ const PUT_CONCURRENCY = 4;
|
|
|
79
127
|
export const SKILL_BODY_MAX_BYTES = 1024 * 1024;
|
|
80
128
|
const notFound = () => new ApiError("skill.not_found", "Skill not found");
|
|
81
129
|
/**
|
|
82
|
-
* 在调用方事务里核对 agent 定义引用的组织技能:每个 id 都必须是该组织未删除的 `scope=org`
|
|
130
|
+
* 在调用方事务里核对 agent 定义引用的组织技能:每个 id 都必须是该组织未删除的 `scope=org` 技能
|
|
131
|
+
* (or, phase 2, a platform skill on in the org: skills/usable.ts),
|
|
83
132
|
* 否则 `validation_failed`(path `skills.orgSkills.<i>`);不可重复。调用方须已锁组织行(技能删除同样锁组织行,二者串行)。
|
|
84
133
|
* `kept`:当前版本里已有的引用(保存时合法),修改时不再核对——技能之后被删也不挡住其他改动(运行时由 T14 忽略已删除的技能)。
|
|
85
134
|
*/
|
|
@@ -93,15 +142,12 @@ export async function assertOrgSkills(db, orgId, ids, kept = new Set()) {
|
|
|
93
142
|
});
|
|
94
143
|
const toCheck = [...seen].filter((id) => !kept.has(id));
|
|
95
144
|
if (toCheck.length > 0) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
.
|
|
100
|
-
.
|
|
101
|
-
|
|
102
|
-
.where("id", "in", toCheck)
|
|
103
|
-
.execute();
|
|
104
|
-
const live = new Set([...kept, ...found.map((r) => r.id)]);
|
|
145
|
+
// The org's skills, its copies linked to a platform skill while that one is on in the org
|
|
146
|
+
// (as `assertPinnedSkills` sees them), and platform skills on in the org (phase 2)
|
|
147
|
+
const found = [...(await skillVersionsById(db, orgId, toCheck)).values()]
|
|
148
|
+
.filter((r) => r.scope === "org")
|
|
149
|
+
.map((r) => r.id);
|
|
150
|
+
const live = new Set([...kept, ...found]);
|
|
105
151
|
ids.forEach((id, i) => {
|
|
106
152
|
if (!live.has(id)) {
|
|
107
153
|
details.push({
|
|
@@ -150,17 +196,12 @@ export async function assertPinnedSkills(db, orgId, agentId, skills, kept = [])
|
|
|
150
196
|
}
|
|
151
197
|
unique.push(id);
|
|
152
198
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
.where("s.org_id", "=", orgId)
|
|
160
|
-
.where("s.deleted_at", "is", null)
|
|
161
|
-
.where("s.id", "in", unique)
|
|
162
|
-
.execute();
|
|
163
|
-
const byId = new Map(rows.map((r) => [r.id, r]));
|
|
199
|
+
// org and agent skills, org copies linked to a platform skill (its current version) and platform
|
|
200
|
+
// skills on in the org (phase 2)
|
|
201
|
+
const byId = new Map([...(await skillVersionsById(db, orgId, unique)).values()].map((r) => [
|
|
202
|
+
r.id,
|
|
203
|
+
{ id: r.id, scope: r.scope, agent_id: r.agentId, manifest: r.manifest },
|
|
204
|
+
]));
|
|
164
205
|
const keptSet = new Set(kept);
|
|
165
206
|
const selected = new Set(skills?.orgSkills ?? []);
|
|
166
207
|
for (const id of unique) {
|
|
@@ -212,8 +253,52 @@ const summary = (r) => {
|
|
|
212
253
|
tokenEstimate: textBytesTokens(entryBytes),
|
|
213
254
|
manual: inv.model === false,
|
|
214
255
|
fork: inv.fork !== undefined,
|
|
256
|
+
origin: "org",
|
|
257
|
+
shareable: r.scope === "org" && r.shareable,
|
|
215
258
|
};
|
|
216
259
|
};
|
|
260
|
+
/** Platform skills with the columns of {@link summary} (phase 2). */
|
|
261
|
+
const platformSummaryQuery = (db) => db
|
|
262
|
+
.selectFrom("platform_skills as p")
|
|
263
|
+
.leftJoin("platform_skill_versions as v", (j) => j.onRef("v.skill_id", "=", "p.id").onRef("v.version", "=", "p.current_version"))
|
|
264
|
+
.leftJoin("orgs as owner", "owner.id", "p.owner_org_id")
|
|
265
|
+
.select([
|
|
266
|
+
"p.id",
|
|
267
|
+
"p.name",
|
|
268
|
+
"p.description",
|
|
269
|
+
"p.current_version",
|
|
270
|
+
"p.created_at",
|
|
271
|
+
"p.updated_at",
|
|
272
|
+
"p.plugin_name",
|
|
273
|
+
"p.owner_org_id",
|
|
274
|
+
"owner.name as owner_name",
|
|
275
|
+
"v.source_format",
|
|
276
|
+
"v.suggest_pinned",
|
|
277
|
+
"v.manifest",
|
|
278
|
+
])
|
|
279
|
+
.where("p.deleted_at", "is", null);
|
|
280
|
+
const platformSummary = (r) => ({
|
|
281
|
+
...summary({
|
|
282
|
+
id: r.id,
|
|
283
|
+
scope: "org",
|
|
284
|
+
agent_id: null,
|
|
285
|
+
name: r.name,
|
|
286
|
+
description: r.description,
|
|
287
|
+
current_version: r.current_version,
|
|
288
|
+
created_by: null,
|
|
289
|
+
created_at: r.created_at,
|
|
290
|
+
updated_at: r.updated_at,
|
|
291
|
+
item_name: r.plugin_name,
|
|
292
|
+
source_format: r.source_format,
|
|
293
|
+
suggest_pinned: r.suggest_pinned,
|
|
294
|
+
manifest: r.manifest,
|
|
295
|
+
shareable: false,
|
|
296
|
+
}),
|
|
297
|
+
origin: "platform",
|
|
298
|
+
owner: r.owner_org_id === null
|
|
299
|
+
? PLATFORM_OWNER
|
|
300
|
+
: { kind: "org", orgId: r.owner_org_id, name: r.owner_name ?? r.owner_org_id },
|
|
301
|
+
});
|
|
217
302
|
/**
|
|
218
303
|
* Skills with their summary columns: the catalog item name (provenance) and the current version's
|
|
219
304
|
* source format, pinned suggestion and manifest.
|
|
@@ -236,33 +321,69 @@ const summaryQuery = (db) => db
|
|
|
236
321
|
"v.source_format",
|
|
237
322
|
"v.suggest_pinned",
|
|
238
323
|
"v.manifest",
|
|
324
|
+
"s.shareable",
|
|
239
325
|
]);
|
|
240
|
-
/**
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
description: pkg.description,
|
|
246
|
-
files: pkg.files.map(({ path, size, sha256 }) => ({ path, size, sha256 })),
|
|
247
|
-
...(invocation !== undefined && { invocation }),
|
|
248
|
-
};
|
|
249
|
-
}
|
|
326
|
+
/**
|
|
327
|
+
* 技能库(M5 T13):组织技能的上传(新技能或新版本)、列表、详情与软删除。
|
|
328
|
+
* 字节在对象存储 `kernel/<orgId>/skills/<uploadId>/<path>`,元数据在 PG;无进程内状态,可多副本共用。
|
|
329
|
+
*/
|
|
330
|
+
export { skillManifest } from "./package.js";
|
|
250
331
|
let SkillsService = class SkillsService {
|
|
251
332
|
db;
|
|
252
333
|
storage;
|
|
253
334
|
attachments;
|
|
254
335
|
txHost;
|
|
255
336
|
orgLock;
|
|
256
|
-
|
|
337
|
+
platform;
|
|
338
|
+
constructor(db, storage, attachments, txHost, orgLock,
|
|
339
|
+
/** The owner's new versions of a skill it promoted go to the platform row (ruling P3-4). */
|
|
340
|
+
platform) {
|
|
257
341
|
this.db = db;
|
|
258
342
|
this.storage = storage;
|
|
259
343
|
this.attachments = attachments;
|
|
260
344
|
this.txHost = txHost;
|
|
261
345
|
this.orgLock = orgLock;
|
|
346
|
+
this.platform = platform;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Writes a package's files where its version will live: for a new version of a skill the org
|
|
350
|
+
* promoted (ruling P3-3: a live org skill of the name linked without a pin to a platform skill
|
|
351
|
+
* the org owns), the platform row's next version prefix in `deployment/` (ruling P3-4); else
|
|
352
|
+
* `kernel/<orgId>/<prefix>`. Returns the platform version prepared, if any. Never inside a
|
|
353
|
+
* transaction; the transaction checks that the skill is still promoted (and still at that
|
|
354
|
+
* version).
|
|
355
|
+
*/
|
|
356
|
+
async putVersionFiles(orgId, pkg, prefix, catalog) {
|
|
357
|
+
const promoted = catalog ? undefined : await promotedSkillNamed(this.db.db, orgId, pkg.name);
|
|
358
|
+
if (promoted !== undefined)
|
|
359
|
+
return this.platform.prepareOwnerVersion(promoted, pkg.files);
|
|
360
|
+
await this.putFiles(orgId, prefix, pkg.files);
|
|
361
|
+
return undefined;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* The summary of the org's skill `copyId` it promoted to `platformId`, as it serves now: the
|
|
365
|
+
* platform row's current version (ruling P3-4) under the org row's id, still the org's own.
|
|
366
|
+
*/
|
|
367
|
+
async promotedSummary(copyId, platformId) {
|
|
368
|
+
const own = await summaryQuery(this.db.db).where("s.id", "=", copyId).executeTakeFirstOrThrow();
|
|
369
|
+
const p = await platformSummaryQuery(this.db.db)
|
|
370
|
+
.where("p.id", "=", platformId)
|
|
371
|
+
.executeTakeFirst();
|
|
372
|
+
if (!p)
|
|
373
|
+
return summary(own);
|
|
374
|
+
return {
|
|
375
|
+
...platformSummary(p),
|
|
376
|
+
id: copyId,
|
|
377
|
+
origin: "org",
|
|
378
|
+
plugin: own.item_name,
|
|
379
|
+
createdBy: own.created_by,
|
|
380
|
+
createdAt: own.created_at,
|
|
381
|
+
shareable: own.shareable,
|
|
382
|
+
};
|
|
262
383
|
}
|
|
263
384
|
/** 登记一个技能包上传(预签名 POST,`application/zip`,≤ 50MB);角色由路由的 `skills.manage` 把关。 */
|
|
264
385
|
async createUpload(orgId, accountId, input) {
|
|
265
|
-
// 部署设置 customSkills 为 deny
|
|
386
|
+
// 部署设置 customSkills 为 deny:组织只能从平台目录安装技能(C22)
|
|
266
387
|
await assertCustomAllowed(this.db.db, "customSkills");
|
|
267
388
|
return this.attachments.create(orgId, accountId, { name: input.name, contentType: SKILL_PACKAGE_CONTENT_TYPE, size: input.size }, "skill-package");
|
|
268
389
|
}
|
|
@@ -275,7 +396,7 @@ let SkillsService = class SkillsService {
|
|
|
275
396
|
* 第 3 步之前中断不会留下可见的版本;已写的文件由清理任务在上传过期后删除(未被任何版本引用时)。
|
|
276
397
|
* 同一上传已经产生过版本(上次提交了、响应丢了而重试)→ 直接返回那个版本(同组织、同一发起人)。
|
|
277
398
|
*/
|
|
278
|
-
async upload(orgId, actorAccountId, uploadId, actorTokenId) {
|
|
399
|
+
async upload(orgId, actorAccountId, uploadId, actorTokenId, shareable) {
|
|
279
400
|
this.storage.assertAvailable();
|
|
280
401
|
const prefix = skillFilesPrefix(uploadId);
|
|
281
402
|
// 重试(上次已提交、响应丢了):同一上传已产生的版本直接返回,不再要求上传仍可用
|
|
@@ -298,8 +419,18 @@ let SkillsService = class SkillsService {
|
|
|
298
419
|
await assertCustomAllowed(this.db.db, "customSkills");
|
|
299
420
|
const zip = await this.attachments.readSkillPackage(orgId, actorAccountId, uploadId);
|
|
300
421
|
const pkg = await readSkillPackage(zip);
|
|
301
|
-
|
|
302
|
-
|
|
422
|
+
// A skill the org promoted gets its version on the platform row (ruling P3-4). Its retry after
|
|
423
|
+
// a lost response is not recognized above (the lookup is by the org prefix): the consumed
|
|
424
|
+
// upload is refused and the owner sees the version in the library (accepted, review M6)
|
|
425
|
+
const owner = await this.putVersionFiles(orgId, pkg, prefix, false);
|
|
426
|
+
try {
|
|
427
|
+
return await this.createUploadedVersionIn(orgId, actorAccountId, uploadId, pkg, prefix, actorTokenId, shareable, owner);
|
|
428
|
+
}
|
|
429
|
+
catch (e) {
|
|
430
|
+
if (owner !== undefined)
|
|
431
|
+
await this.platform.discardPrefix(owner.prefix);
|
|
432
|
+
throw e;
|
|
433
|
+
}
|
|
303
434
|
}
|
|
304
435
|
/**
|
|
305
436
|
* The transaction of {@link upload}: under the org row lock (re-checking `skills.manage`), the
|
|
@@ -307,28 +438,71 @@ let SkillsService = class SkillsService {
|
|
|
307
438
|
* upload only one succeeds), then the version is written in the same transaction
|
|
308
439
|
* ({@link createVersionIn} joins it).
|
|
309
440
|
*/
|
|
310
|
-
async createUploadedVersionIn(orgId, actorAccountId, uploadId, pkg, prefix, actorTokenId) {
|
|
441
|
+
async createUploadedVersionIn(orgId, actorAccountId, uploadId, pkg, prefix, actorTokenId, shareable, owner) {
|
|
311
442
|
await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "skills.manage");
|
|
312
443
|
await assertCustomAllowed(this.db.db, "customSkills");
|
|
313
444
|
await this.attachments.consumeSkillPackage(orgId, actorAccountId, uploadId);
|
|
314
445
|
return this.createVersionIn(orgId, actorAccountId, pkg, skillManifest(pkg), prefix, {
|
|
315
446
|
prefix,
|
|
316
447
|
...(actorTokenId !== undefined && { actorTokenId }),
|
|
448
|
+
...(shareable !== undefined && { shareable }),
|
|
449
|
+
...(owner !== undefined && { owner }),
|
|
317
450
|
});
|
|
318
451
|
}
|
|
319
452
|
/**
|
|
320
|
-
*
|
|
453
|
+
* Creates an org skill from text (spec §14, P3-24): `SKILL.md` is built from the name,
|
|
454
|
+
* description and body ({@link buildSkillWrite}, the description a YAML string) and checked like
|
|
455
|
+
* an uploaded package. The same policy and name rules as an upload, except that a live org skill
|
|
456
|
+
* of that name is `skill.name_exists` (409) instead of a new version.
|
|
457
|
+
*/
|
|
458
|
+
async createFromText(orgId, actorAccountId, input) {
|
|
459
|
+
this.storage.assertAvailable();
|
|
460
|
+
await assertCustomAllowed(this.db.db, "customSkills");
|
|
461
|
+
const built = buildSkillWrite({
|
|
462
|
+
name: input.name,
|
|
463
|
+
description: input.description,
|
|
464
|
+
files: [{ path: SKILL_ENTRY_FILE, content: input.body }],
|
|
465
|
+
});
|
|
466
|
+
if ("errors" in built) {
|
|
467
|
+
throw new ApiError("validation_failed", `Invalid skill: ${built.errors[0] ?? "unknown problem"}`, built.errors.map((message) => ({ path: "body", message })));
|
|
468
|
+
}
|
|
469
|
+
const pkg = checkBuiltSkillFiles(built.files);
|
|
470
|
+
const prefix = skillFilesPrefix(randomUUID());
|
|
471
|
+
await this.putFiles(orgId, prefix, pkg.files);
|
|
472
|
+
return this.createVersionIn(orgId, actorAccountId, pkg, skillManifest(pkg), prefix, {
|
|
473
|
+
prefix,
|
|
474
|
+
failIfExists: true,
|
|
475
|
+
...(input.actorTokenId !== undefined && { actorTokenId: input.actorTokenId }),
|
|
476
|
+
...(input.auditDetail !== undefined && { auditDetail: input.auditDetail }),
|
|
477
|
+
...(input.shareable !== undefined && { shareable: input.shareable }),
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* 用一组已校验的技能文件创建组织技能或给同名技能新增版本(上传与平台目录安装共用):
|
|
321
482
|
* 1. 把文件写到 `kernel/<orgId>/<prefix>`(缺省 `skills/<新 id>/`);
|
|
322
483
|
* 2. 一个事务里:锁组织行并复核 `skills.manage`(目录安装:按条目策略复核),
|
|
323
484
|
* 同名未删除的组织技能存在则 `current_version + 1`,否则新建;技能与版本都记下 `directory` 来源(没有则清空:
|
|
324
485
|
* 自定义上传盖在目录技能上就不再算目录安装),写版本与审计
|
|
325
486
|
* (`skill.created` / `skill.version_created`,目录安装时 detail 带 directory)。
|
|
326
487
|
*/
|
|
327
|
-
async createVersionFromFiles(orgId,
|
|
488
|
+
async createVersionFromFiles(orgId,
|
|
489
|
+
/** null: the kernel itself (the plugin scope sync installing a plugin), no role check. */
|
|
490
|
+
actorAccountId, pkg, opts = {}) {
|
|
328
491
|
this.storage.assertAvailable();
|
|
329
492
|
const prefix = opts.prefix ?? skillFilesPrefix(randomUUID());
|
|
330
|
-
await this.
|
|
331
|
-
|
|
493
|
+
const owner = await this.putVersionFiles(orgId, pkg, prefix, opts.catalog !== undefined);
|
|
494
|
+
try {
|
|
495
|
+
return await this.createVersionIn(orgId, actorAccountId, pkg, skillManifest(pkg), prefix, {
|
|
496
|
+
...opts,
|
|
497
|
+
...(owner !== undefined && { owner }),
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
catch (e) {
|
|
501
|
+
// the loser of two owner versions racing for one number: its objects go (ruling P3-45)
|
|
502
|
+
if (owner !== undefined)
|
|
503
|
+
await this.platform.discardPrefix(owner.prefix);
|
|
504
|
+
throw e;
|
|
505
|
+
}
|
|
332
506
|
}
|
|
333
507
|
/** Writes a skill package's files to `kernel/<orgId>/<prefix>` (a few at a time). */
|
|
334
508
|
async putFiles(orgId, prefix, files) {
|
|
@@ -345,20 +519,49 @@ let SkillsService = class SkillsService {
|
|
|
345
519
|
}
|
|
346
520
|
/** The transaction of {@link createVersionFromFiles}. */
|
|
347
521
|
async createVersionIn(orgId, actorAccountId, pkg, manifest, prefix, opts) {
|
|
348
|
-
await this.orgLock.
|
|
522
|
+
await this.orgLock.lockFor(orgId, actorAccountId, "skills.manage");
|
|
349
523
|
if (opts.catalog) {
|
|
350
524
|
const c = opts.catalog;
|
|
351
525
|
await assertItemInstallable(this.db.db, orgId, c.itemId, c.approvedBy ?? c.itemId);
|
|
352
526
|
}
|
|
353
527
|
const existing = await this.db
|
|
354
528
|
.selectFrom("skills")
|
|
355
|
-
.select(["id", "current_version", "catalog_item_id"])
|
|
529
|
+
.select(["id", "current_version", "catalog_item_id", "platform_skill_id"])
|
|
356
530
|
.where("org_id", "=", orgId)
|
|
357
531
|
.where("scope", "=", "org")
|
|
358
532
|
.where("name", "=", pkg.name)
|
|
359
533
|
.where("deleted_at", "is", null)
|
|
360
534
|
.forUpdate()
|
|
361
535
|
.executeTakeFirst();
|
|
536
|
+
if (existing && opts.failIfExists) {
|
|
537
|
+
throw new ApiError("skill.name_exists", `A skill named "${pkg.name}" already exists in this organization. Choose another name.`);
|
|
538
|
+
}
|
|
539
|
+
// The org's own skill it promoted (ruling P3-3): its new version goes to the platform row and
|
|
540
|
+
// reaches every org using it (ruling P3-4); the files were written there before this
|
|
541
|
+
// transaction, for the platform version current then
|
|
542
|
+
const promoted = existing && !opts.catalog
|
|
543
|
+
? await promotedSkillNamed(this.db.db, orgId, pkg.name, existing.id)
|
|
544
|
+
: undefined;
|
|
545
|
+
if (promoted !== undefined || opts.owner !== undefined) {
|
|
546
|
+
if (existing === undefined || promoted === undefined || opts.owner?.platformId !== promoted) {
|
|
547
|
+
throw new ApiError("component.version_stale", "The skill changed while this version was uploaded; upload it again");
|
|
548
|
+
}
|
|
549
|
+
const version = await this.platform.addOwnerVersionIn(opts.owner, manifest, actorAccountId);
|
|
550
|
+
await audit(this.db.db, {
|
|
551
|
+
actorAccountId,
|
|
552
|
+
...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
|
|
553
|
+
orgId,
|
|
554
|
+
action: "skill.version_created",
|
|
555
|
+
target: existing.id,
|
|
556
|
+
detail: { name: pkg.name, version, files: manifest.files.length, platformId: promoted },
|
|
557
|
+
});
|
|
558
|
+
await notifySharedUpdate(this.db.db, { kind: "skill", id: promoted }, { name: pkg.name, from: String(version - 1), to: String(version) });
|
|
559
|
+
return {
|
|
560
|
+
skill: await this.promotedSummary(existing.id, promoted),
|
|
561
|
+
version,
|
|
562
|
+
created: false,
|
|
563
|
+
};
|
|
564
|
+
}
|
|
362
565
|
// A catalog install never overwrites a skill of other provenance (spec §9.2; planning checks
|
|
363
566
|
// it first, this closes the race with a skill created since)
|
|
364
567
|
if (existing && opts.catalog && existing.catalog_item_id !== opts.catalog.itemId) {
|
|
@@ -366,8 +569,20 @@ let SkillsService = class SkillsService {
|
|
|
366
569
|
if (conflicts.length > 0)
|
|
367
570
|
throw skillConflictError(conflicts);
|
|
368
571
|
}
|
|
572
|
+
// Rule 10 (plugin scope phase 2, ruling P2-3): a new org skill may not take the name of a
|
|
573
|
+
// platform skill offered to the org (on, or one an org admin could switch on)
|
|
574
|
+
if (!existing && !opts.catalog) {
|
|
575
|
+
const offered = await offeredNamed(this.db.db, orgId, "skill", pkg.name);
|
|
576
|
+
if (offered.length > 0)
|
|
577
|
+
throw platformNameTaken(pkg.name, offered);
|
|
578
|
+
}
|
|
369
579
|
const id = existing?.id ?? randomUUID();
|
|
370
580
|
const version = (existing?.current_version ?? 0) + 1;
|
|
581
|
+
// An org's own version of a copy linked to a platform skill pins the copy to it (ruling P2-4):
|
|
582
|
+
// the org's change takes effect, and shows as individually updated later
|
|
583
|
+
const pin = existing && existing.platform_skill_id !== null && !opts.catalog
|
|
584
|
+
? { pinned_version: version }
|
|
585
|
+
: {};
|
|
371
586
|
// 来源跟着最新版本走:目录安装记条目与版本,自定义上传清掉(内容已不是目录里的那份)
|
|
372
587
|
const provenance = {
|
|
373
588
|
catalog_item_id: opts.catalog?.itemId ?? null,
|
|
@@ -380,6 +595,7 @@ let SkillsService = class SkillsService {
|
|
|
380
595
|
current_version: version,
|
|
381
596
|
description: pkg.description,
|
|
382
597
|
...provenance,
|
|
598
|
+
...pin,
|
|
383
599
|
updated_at: sql `now()`,
|
|
384
600
|
})
|
|
385
601
|
.where("id", "=", id)
|
|
@@ -397,6 +613,7 @@ let SkillsService = class SkillsService {
|
|
|
397
613
|
description: pkg.description,
|
|
398
614
|
current_version: 1,
|
|
399
615
|
created_by: actorAccountId,
|
|
616
|
+
...(opts.shareable !== undefined && { shareable: opts.shareable }),
|
|
400
617
|
...provenance,
|
|
401
618
|
})
|
|
402
619
|
.execute();
|
|
@@ -425,6 +642,7 @@ let SkillsService = class SkillsService {
|
|
|
425
642
|
version,
|
|
426
643
|
files: manifest.files.length,
|
|
427
644
|
...(opts.catalog && { catalog: opts.catalog }),
|
|
645
|
+
...opts.auditDetail,
|
|
428
646
|
},
|
|
429
647
|
});
|
|
430
648
|
const row = await summaryQuery(this.db.db).where("s.id", "=", id).executeTakeFirstOrThrow();
|
|
@@ -506,15 +724,46 @@ let SkillsService = class SkillsService {
|
|
|
506
724
|
});
|
|
507
725
|
return true;
|
|
508
726
|
}
|
|
509
|
-
/**
|
|
727
|
+
/**
|
|
728
|
+
* The org skill library, sorted by name: the org's live `scope=org` skills except copies linked
|
|
729
|
+
* to a platform skill without a pin, and the platform skills on in the org (phase 2,
|
|
730
|
+
* `usableSkills`; `origin` tells them apart), each with the ids of those copies (`linkedIds`).
|
|
731
|
+
*/
|
|
510
732
|
async list(orgId) {
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
733
|
+
const usable = await usableSkills(this.db.db, orgId);
|
|
734
|
+
const orgIds = usable.filter((u) => u.origin === "org").map((u) => u.id);
|
|
735
|
+
const platformIds = usable.filter((u) => u.origin === "platform").map((u) => u.id);
|
|
736
|
+
// the org's own skills it promoted serving a newer platform version (ruling P3-4)
|
|
737
|
+
const promotedTo = new Map(usable.flatMap((u) => u.origin === "org" &&
|
|
738
|
+
u.platformSkillId !== undefined &&
|
|
739
|
+
u.source.startsWith(PLATFORM_SOURCE)
|
|
740
|
+
? [[u.id, u.platformSkillId]]
|
|
741
|
+
: []));
|
|
742
|
+
const own = orgIds.length === 0
|
|
743
|
+
? []
|
|
744
|
+
: await Promise.all((await summaryQuery(this.db.db).where("s.id", "in", orgIds).orderBy("s.name").execute()).map((r) => {
|
|
745
|
+
const to = promotedTo.get(r.id);
|
|
746
|
+
return to === undefined ? summary(r) : this.promotedSummary(r.id, to);
|
|
747
|
+
}));
|
|
748
|
+
if (platformIds.length === 0)
|
|
749
|
+
return own;
|
|
750
|
+
const links = await this.db
|
|
751
|
+
.selectFrom("skills")
|
|
752
|
+
.select(["id", "platform_skill_id"])
|
|
753
|
+
.where("org_id", "=", orgId)
|
|
754
|
+
.where("scope", "=", "org")
|
|
755
|
+
.where("deleted_at", "is", null)
|
|
756
|
+
.where("pinned_version", "is", null)
|
|
757
|
+
.where("platform_skill_id", "in", platformIds)
|
|
758
|
+
.orderBy("id")
|
|
516
759
|
.execute();
|
|
517
|
-
|
|
760
|
+
const linked = new Map();
|
|
761
|
+
for (const l of links) {
|
|
762
|
+
const k = l.platform_skill_id;
|
|
763
|
+
linked.set(k, [...(linked.get(k) ?? []), l.id]);
|
|
764
|
+
}
|
|
765
|
+
const platform = (await platformSummaryQuery(this.db.db).where("p.id", "in", platformIds).execute()).map((r) => ({ ...platformSummary(r), linkedIds: linked.get(r.id) ?? [] }));
|
|
766
|
+
return [...own, ...platform].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : a.id < b.id ? -1 : 1);
|
|
518
767
|
}
|
|
519
768
|
/** 对该 agent 自动生效的技能(`scope=agent`、未删除),按名字排序。 */
|
|
520
769
|
async listForAgent(orgId, agentId) {
|
|
@@ -527,8 +776,34 @@ let SkillsService = class SkillsService {
|
|
|
527
776
|
.execute();
|
|
528
777
|
return rows.map(summary);
|
|
529
778
|
}
|
|
530
|
-
/**
|
|
779
|
+
/**
|
|
780
|
+
* 组织技能详情:各版本与文件清单。不存在 / 已删除 / 不是组织技能 → `skill.not_found`。
|
|
781
|
+
* An org copy linked to a platform skill without a pin (ruling B2) serves the platform skill's
|
|
782
|
+
* content under its own id, so its detail is the platform skill's (its id, versions and body;
|
|
783
|
+
* 404 while that skill is off in the org); a pinned copy keeps its own (Task 10).
|
|
784
|
+
*/
|
|
531
785
|
async get(orgId, skillId) {
|
|
786
|
+
const link = await this.db
|
|
787
|
+
.selectFrom("skills")
|
|
788
|
+
.select("platform_skill_id")
|
|
789
|
+
.where("id", "=", skillId)
|
|
790
|
+
.where("org_id", "=", orgId)
|
|
791
|
+
.where("scope", "=", "org")
|
|
792
|
+
.where("deleted_at", "is", null)
|
|
793
|
+
.where("platform_skill_id", "is not", null)
|
|
794
|
+
.where("pinned_version", "is", null)
|
|
795
|
+
.executeTakeFirst();
|
|
796
|
+
if (link?.platform_skill_id) {
|
|
797
|
+
// the org's own skill it promoted is its own (ruling P3-3): its stored version while that is
|
|
798
|
+
// the platform's current one, else the platform's newer version under its id (ruling P3-4)
|
|
799
|
+
const served = (await skillVersionsById(this.db.db, orgId, [skillId])).get(skillId);
|
|
800
|
+
if (served?.origin !== "org")
|
|
801
|
+
return this.getPlatform(orgId, link.platform_skill_id);
|
|
802
|
+
if (served.source.startsWith(PLATFORM_SOURCE)) {
|
|
803
|
+
const detail = await this.getPlatform(orgId, link.platform_skill_id);
|
|
804
|
+
return { ...detail, ...(await this.promotedSummary(skillId, link.platform_skill_id)) };
|
|
805
|
+
}
|
|
806
|
+
}
|
|
532
807
|
const row = await summaryQuery(this.db.db)
|
|
533
808
|
.where("s.id", "=", skillId)
|
|
534
809
|
.where("s.org_id", "=", orgId)
|
|
@@ -536,7 +811,7 @@ let SkillsService = class SkillsService {
|
|
|
536
811
|
.where("s.deleted_at", "is", null)
|
|
537
812
|
.executeTakeFirst();
|
|
538
813
|
if (!row)
|
|
539
|
-
|
|
814
|
+
return this.getPlatform(orgId, skillId);
|
|
540
815
|
const versions = await this.db
|
|
541
816
|
.selectFrom("skill_versions")
|
|
542
817
|
.select(["version", "manifest", "created_by", "created_at", "object_prefix"])
|
|
@@ -556,13 +831,51 @@ let SkillsService = class SkillsService {
|
|
|
556
831
|
})),
|
|
557
832
|
};
|
|
558
833
|
}
|
|
834
|
+
/**
|
|
835
|
+
* A platform skill's detail (phase 2): only while it is on in the org, else `skill.not_found`.
|
|
836
|
+
* Its versions are the platform skill's.
|
|
837
|
+
*/
|
|
838
|
+
async getPlatform(orgId, skillId) {
|
|
839
|
+
const usable = (await skillVersionsById(this.db.db, orgId, [skillId])).get(skillId);
|
|
840
|
+
if (usable?.origin !== "platform" || usable.platformSkillId !== skillId)
|
|
841
|
+
throw notFound();
|
|
842
|
+
const row = await platformSummaryQuery(this.db.db)
|
|
843
|
+
.where("p.id", "=", skillId)
|
|
844
|
+
.executeTakeFirst();
|
|
845
|
+
if (!row)
|
|
846
|
+
throw notFound();
|
|
847
|
+
const versions = await this.db
|
|
848
|
+
.selectFrom("platform_skill_versions")
|
|
849
|
+
.select(["version", "manifest", "created_by", "created_at", "object_prefix"])
|
|
850
|
+
.where("skill_id", "=", skillId)
|
|
851
|
+
.orderBy("version", "desc")
|
|
852
|
+
.execute();
|
|
853
|
+
const current = versions.find((v) => v.version === row.current_version);
|
|
854
|
+
return {
|
|
855
|
+
...platformSummary(row),
|
|
856
|
+
body: current
|
|
857
|
+
? await this.readBody(orgId, {
|
|
858
|
+
manifest: current.manifest,
|
|
859
|
+
object_prefix: platformSource(current.object_prefix),
|
|
860
|
+
})
|
|
861
|
+
: null,
|
|
862
|
+
versions: versions.map((v) => ({
|
|
863
|
+
version: v.version,
|
|
864
|
+
description: v.manifest.description,
|
|
865
|
+
files: v.manifest.files,
|
|
866
|
+
createdBy: v.created_by,
|
|
867
|
+
createdAt: v.created_at,
|
|
868
|
+
})),
|
|
869
|
+
};
|
|
870
|
+
}
|
|
559
871
|
/** 读某版本 SKILL.md 的正文(见 {@link SkillDetail.body});任何读取问题都返回 null,不让详情失败。 */
|
|
560
872
|
async readBody(orgId, v) {
|
|
561
873
|
const entry = v.manifest.files.find((f) => f.path === SKILL_ENTRY_FILE);
|
|
562
874
|
if (!entry || entry.size > SKILL_BODY_MAX_BYTES)
|
|
563
875
|
return null;
|
|
564
876
|
try {
|
|
565
|
-
const
|
|
877
|
+
const { store, prefix } = skillFileStore(this.storage, orgId, v.object_prefix);
|
|
878
|
+
const got = await store.get(`${prefix}${SKILL_ENTRY_FILE}`);
|
|
566
879
|
if (!got)
|
|
567
880
|
return null;
|
|
568
881
|
const text = new TextDecoder("utf-8", { fatal: true }).decode(await new Response(got.body).arrayBuffer());
|
|
@@ -583,6 +896,15 @@ let SkillsService = class SkillsService {
|
|
|
583
896
|
/** The transaction of {@link softDelete}. */
|
|
584
897
|
async softDeleteTx(orgId, skillId, actorAccountId, actorTokenId) {
|
|
585
898
|
await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "skills.manage");
|
|
899
|
+
await this.deleteOrgSkillIn(orgId, skillId, actorAccountId, actorTokenId);
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* In the caller's transaction (`mandatory`: the caller holds the org row lock and checked
|
|
903
|
+
* `skills.manage`), soft-deletes an org-scope skill of the org: what {@link softDelete} writes
|
|
904
|
+
* (audit `skill.deleted`); missing or deleted -> `skill.not_found`. The owner delete of a
|
|
905
|
+
* promoted skill (`OwnedItems.deleteSkill`) calls it after its platform row was dealt with.
|
|
906
|
+
*/
|
|
907
|
+
async deleteOrgSkillIn(orgId, skillId, actorAccountId, actorTokenId) {
|
|
586
908
|
const r = await this.db
|
|
587
909
|
.updateTable("skills")
|
|
588
910
|
.set({ deleted_at: sql `now()`, updated_at: sql `now()` })
|
|
@@ -619,12 +941,36 @@ __decorate([
|
|
|
619
941
|
__decorate([
|
|
620
942
|
Transactional()
|
|
621
943
|
], SkillsService.prototype, "softDeleteTx", null);
|
|
944
|
+
__decorate([
|
|
945
|
+
Transactional({ propagation: "mandatory" })
|
|
946
|
+
], SkillsService.prototype, "deleteOrgSkillIn", null);
|
|
622
947
|
SkillsService = __decorate([
|
|
623
948
|
Injectable(),
|
|
624
949
|
__param(0, Inject(KernelDb)),
|
|
625
950
|
__param(1, Inject(StorageService)),
|
|
626
951
|
__param(2, Inject(AttachmentsService)),
|
|
627
952
|
__param(3, Inject(TransactionHost)),
|
|
628
|
-
__param(4, Inject(OrgLock))
|
|
953
|
+
__param(4, Inject(OrgLock)),
|
|
954
|
+
__param(5, Inject(PlatformComponents))
|
|
629
955
|
], SkillsService);
|
|
630
956
|
export { SkillsService };
|
|
957
|
+
/**
|
|
958
|
+
* The platform skill the org's live org skill `name` was promoted to (ruling P3-3: linked without
|
|
959
|
+
* a pin to a live platform skill the org owns), else undefined. `id`: only that skill.
|
|
960
|
+
*/
|
|
961
|
+
async function promotedSkillNamed(db, orgId, name, id) {
|
|
962
|
+
let q = db
|
|
963
|
+
.selectFrom("skills as s")
|
|
964
|
+
.innerJoin("platform_skills as p", "p.id", "s.platform_skill_id")
|
|
965
|
+
.select("p.id")
|
|
966
|
+
.where("s.org_id", "=", orgId)
|
|
967
|
+
.where("s.scope", "=", "org")
|
|
968
|
+
.where("s.name", "=", name)
|
|
969
|
+
.where("s.deleted_at", "is", null)
|
|
970
|
+
.where("s.pinned_version", "is", null)
|
|
971
|
+
.where("p.owner_org_id", "=", orgId)
|
|
972
|
+
.where("p.deleted_at", "is", null);
|
|
973
|
+
if (id !== undefined)
|
|
974
|
+
q = q.where("s.id", "=", id);
|
|
975
|
+
return (await q.executeTakeFirst())?.id;
|
|
976
|
+
}
|