@capybara-hq/kernel 0.1.0-rc.104 → 0.1.0-rc.106
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/agents.schemas.d.ts +9 -9
- package/dist/{schedules/schedules.controller.d.ts → automations/automations.controller.d.ts} +37 -32
- package/dist/{schedules/schedules.controller.js → automations/automations.controller.js} +68 -57
- package/dist/automations/automations.module.d.ts +16 -0
- package/dist/{schedules/schedules.module.js → automations/automations.module.js} +18 -15
- package/dist/{schedules/schedules.schemas.d.ts → automations/automations.schemas.d.ts} +151 -50
- package/dist/automations/automations.schemas.js +253 -0
- package/dist/{schedules/scheduled-tasks.service.d.ts → automations/automations.service.d.ts} +99 -52
- package/dist/{schedules/scheduled-tasks.service.js → automations/automations.service.js} +303 -134
- package/dist/{schedules → automations}/calendar.d.ts +8 -8
- package/dist/{schedules → automations}/calendar.js +2 -2
- package/dist/automations/effective-settings.d.ts +28 -0
- package/dist/automations/effective-settings.js +25 -0
- package/dist/automations/errors.d.ts +19 -0
- package/dist/automations/errors.js +19 -0
- package/dist/automations/events/coalesce.d.ts +28 -0
- package/dist/automations/events/coalesce.js +131 -0
- package/dist/automations/events/deadline.d.ts +10 -0
- package/dist/automations/events/deadline.js +24 -0
- package/dist/automations/events/dispatcher.d.ts +74 -0
- package/dist/automations/events/dispatcher.js +353 -0
- package/dist/automations/events/events.module.d.ts +7 -0
- package/dist/automations/events/events.module.js +26 -0
- package/dist/automations/events/guards.d.ts +32 -0
- package/dist/automations/events/guards.js +87 -0
- package/dist/automations/events/sweep.job.d.ts +49 -0
- package/dist/automations/events/sweep.job.js +202 -0
- package/dist/automations/events/token.d.ts +5 -0
- package/dist/automations/events/token.js +5 -0
- package/dist/automations/events/trigger-events.service.d.ts +47 -0
- package/dist/automations/events/trigger-events.service.js +254 -0
- package/dist/{schedules → automations}/fire.d.ts +57 -17
- package/dist/{schedules → automations}/fire.js +311 -79
- package/dist/{schedules → automations}/grant-rules.d.ts +1 -1
- package/dist/{schedules → automations}/grant-rules.js +5 -5
- package/dist/automations/job-ids.d.ts +113 -0
- package/dist/automations/job-ids.js +117 -0
- package/dist/{schedules → automations}/pause.d.ts +3 -3
- package/dist/{schedules → automations}/pause.js +3 -3
- package/dist/{schedules → automations}/run-tracker.d.ts +21 -10
- package/dist/{schedules → automations}/run-tracker.js +68 -56
- package/dist/{schedules → automations}/scan.job.d.ts +12 -8
- package/dist/{schedules → automations}/scan.job.js +39 -23
- package/dist/{schedules → automations}/schedule-math.d.ts +19 -12
- package/dist/{schedules → automations}/schedule-math.js +17 -7
- package/dist/{schedules → automations}/store.d.ts +57 -27
- package/dist/{schedules → automations}/store.js +102 -52
- package/dist/automations/store.module.d.ts +6 -0
- package/dist/{schedules → automations}/store.module.js +9 -9
- package/dist/automations/types.d.ts +178 -0
- package/dist/{schedules → automations}/unattended.d.ts +22 -11
- package/dist/{schedules → automations}/unattended.js +53 -30
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/channels.module.js +3 -3
- package/dist/channels/outbound.d.ts +5 -5
- package/dist/channels/outbound.js +17 -17
- package/dist/channels/threads.d.ts +1 -1
- package/dist/channels/threads.js +1 -1
- package/dist/config/schema.d.ts +5 -1
- package/dist/config/schema.js +44 -6
- package/dist/conversations/approval-profile.d.ts +2 -2
- package/dist/conversations/approval-profile.js +3 -3
- package/dist/conversations/conversations.controller.d.ts +7 -1
- package/dist/conversations/conversations.controller.js +26 -10
- package/dist/conversations/conversations.service.d.ts +103 -25
- package/dist/conversations/conversations.service.js +138 -33
- package/dist/conversations/events.d.ts +48 -1
- package/dist/conversations/events.js +61 -9
- package/dist/conversations/message-context.d.ts +2 -2
- package/dist/conversations/message-context.js +1 -1
- package/dist/conversations/permission-profile-store.d.ts +2 -1
- package/dist/conversations/permission-profiles.controller.d.ts +3 -0
- package/dist/conversations/permission-profiles.service.js +1 -1
- package/dist/conversations/prompt-suggestion-request.d.ts +1 -1
- package/dist/conversations/prompt-suggestion-request.js +2 -1
- package/dist/conversations/queue.d.ts +7 -4
- package/dist/conversations/queue.js +6 -2
- package/dist/conversations/queue.service.d.ts +5 -5
- package/dist/conversations/queue.service.js +20 -14
- package/dist/ctx/create-ctx.d.ts +20 -1
- package/dist/ctx/create-ctx.js +59 -2
- package/dist/db/kernel-schema.d.ts +104 -25
- package/dist/devices/device-project-files.service.d.ts +88 -0
- package/dist/devices/device-project-files.service.js +249 -0
- package/dist/devices/device-projects.service.d.ts +40 -0
- package/dist/devices/device-projects.service.js +16 -13
- package/dist/devices/devices.controller.d.ts +9 -3
- package/dist/devices/devices.controller.js +27 -5
- package/dist/devices/devices.module.js +9 -1
- package/dist/devices/devices.schemas.js +6 -1
- package/dist/devices/dto.d.ts +15 -0
- package/dist/devices/dto.js +11 -0
- package/dist/devices/project-paths.d.ts +29 -0
- package/dist/devices/project-paths.js +66 -0
- package/dist/devices/project-rules.d.ts +5 -1
- package/dist/devices/project-rules.js +5 -1
- package/dist/errors.d.ts +47 -13
- package/dist/errors.js +47 -13
- package/dist/evals/reconstruct.d.ts +10 -1
- package/dist/evals/reconstruct.js +7 -0
- package/dist/extensions/host.d.ts +6 -1
- package/dist/extensions/host.js +10 -0
- package/dist/extensions/permission-set.d.ts +17 -1
- package/dist/extensions/permission-set.js +13 -1
- package/dist/extensions/permission-view.d.ts +1 -1
- package/dist/extensions/permission-view.js +4 -1
- package/dist/git/gateway.js +2 -2
- package/dist/handoff/app-schemes.d.ts +28 -0
- package/dist/handoff/app-schemes.js +41 -0
- package/dist/handoff/handoff-paths.d.ts +26 -0
- package/dist/handoff/handoff-paths.js +25 -0
- package/dist/handoff/handoff-tickets.d.ts +28 -0
- package/dist/handoff/handoff-tickets.js +111 -0
- package/dist/handoff/handoff.controller.d.ts +24 -0
- package/dist/handoff/handoff.controller.js +74 -0
- package/dist/handoff/handoff.module.d.ts +7 -0
- package/dist/handoff/handoff.module.js +26 -0
- package/dist/handoff/handoff.schemas.d.ts +13 -0
- package/dist/handoff/handoff.schemas.js +3 -0
- package/dist/handoff/handoff.service.d.ts +49 -0
- package/dist/handoff/handoff.service.js +96 -0
- package/dist/http/api.module.js +13 -5
- package/dist/http/meta.controller.d.ts +1 -0
- package/dist/http/meta.controller.js +7 -0
- package/dist/http/request-signal.d.ts +8 -0
- package/dist/http/request-signal.js +14 -0
- package/dist/identity/sso.controller.d.ts +30 -6
- package/dist/identity/sso.controller.js +51 -17
- package/dist/identity/sso.d.ts +10 -2
- package/dist/identity/sso.js +15 -3
- package/dist/inbox/inbox.module.js +2 -2
- package/dist/inbox/inbox.service.d.ts +8 -8
- package/dist/inbox/inbox.service.js +7 -7
- package/dist/infra/config/kernel-config.service.js +10 -5
- package/dist/infra/outbox/registry.d.ts +29 -2
- package/dist/infra/outbox/registry.js +30 -7
- package/dist/kernel.module.js +3 -0
- package/dist/orgs/roles.d.ts +1 -1
- package/dist/orgs/roles.js +3 -3
- package/dist/orgs/settings.controller.d.ts +1 -1
- package/dist/orgs/settings.service.d.ts +27 -11
- package/dist/orgs/settings.service.js +42 -24
- package/dist/overrides.d.ts +4 -4
- package/dist/overrides.js +1 -1
- package/dist/platform/exclusions.js +5 -0
- package/dist/platform/operation.js +2 -2
- package/dist/platform/ops/{schedules.ops.d.ts → automations.ops.d.ts} +4 -4
- package/dist/platform/ops/automations.ops.js +560 -0
- package/dist/platform/ops/connectors.ops.js +4 -2
- package/dist/platform/ops/devices.ops.d.ts +3 -1
- package/dist/platform/ops/devices.ops.js +77 -3
- package/dist/platform/ops/inbox.ops.js +4 -4
- package/dist/platform/ops/orgs.ops.js +1 -1
- package/dist/platform/ops/platform.ops.js +4 -4
- package/dist/platform/platform-ops.module.d.ts +2 -2
- package/dist/platform/platform-ops.module.js +5 -5
- package/dist/platform/route-schemas.js +3 -3
- package/dist/push/jobs.d.ts +3 -3
- package/dist/push/jobs.js +2 -2
- package/dist/push/preferences.service.js +1 -1
- package/dist/push/push-owed.d.ts +3 -3
- package/dist/push/push-owed.js +6 -6
- package/dist/push/push.schemas.d.ts +4 -4
- package/dist/push/push.schemas.js +3 -3
- package/dist/push/recipients.d.ts +4 -4
- package/dist/push/recipients.js +23 -23
- package/dist/push/texts.d.ts +3 -3
- package/dist/push/texts.js +2 -2
- package/dist/push/triggers.d.ts +1 -1
- package/dist/roles/worker.module.js +3 -3
- package/dist/runtime/compaction.service.d.ts +3 -1
- package/dist/runtime/compaction.service.js +3 -1
- package/dist/runtime/context/build.d.ts +6 -0
- package/dist/runtime/context/build.js +14 -3
- package/dist/runtime/context/compaction.d.ts +27 -1
- package/dist/runtime/context/compaction.js +102 -37
- package/dist/runtime/context/run-context.d.ts +38 -0
- package/dist/runtime/context/run-context.js +54 -0
- package/dist/runtime/maintenance.d.ts +8 -4
- package/dist/runtime/maintenance.js +37 -16
- package/dist/runtime/model-call.d.ts +6 -4
- package/dist/runtime/model-call.js +17 -7
- package/dist/runtime/project/knowledge.service.d.ts +16 -7
- package/dist/runtime/project/knowledge.service.js +31 -13
- package/dist/runtime/run-finish.d.ts +4 -4
- package/dist/runtime/run-finish.js +3 -3
- package/dist/runtime/run-queue.js +12 -7
- package/dist/runtime/run-worker.js +7 -1
- package/dist/runtime/runtime.module.js +3 -3
- package/dist/runtime/subagents/dispatch.js +11 -3
- package/dist/sandbox/browse-roots.d.ts +8 -0
- package/dist/sandbox/browse-roots.js +22 -0
- package/dist/sandbox/network-grants.d.ts +4 -4
- package/dist/sandbox/network-grants.js +7 -7
- package/dist/sandbox/operation-authority.d.ts +10 -3
- package/dist/sandbox/operation-authority.js +20 -10
- package/dist/sandbox/operation-intents.d.ts +3 -1
- package/dist/sandbox/operation-intents.js +11 -4
- package/dist/sandbox/permission-call-grants.js +2 -2
- package/dist/sandbox/permission-facts.js +1 -1
- package/dist/sandbox/review/classifier.d.ts +2 -2
- package/dist/sandbox/review/classifier.js +22 -11
- package/dist/sandbox/review/permission-candidate.d.ts +1 -1
- package/dist/sandbox/review/permission-candidate.js +1 -1
- package/dist/sandbox/sandbox.service.d.ts +15 -5
- package/dist/sandbox/sandbox.service.js +14 -8
- package/dist/storage/purge.d.ts +1 -1
- package/dist/storage/purge.js +2 -2
- package/dist/tools/approvals.service.d.ts +6 -6
- package/dist/tools/approvals.service.js +19 -19
- package/dist/tools/builtin-names.d.ts +12 -12
- package/dist/tools/builtin-names.js +29 -29
- package/dist/tools/builtins/{schedules.d.ts → automations.d.ts} +35 -33
- package/dist/tools/builtins/{schedules.js → automations.js} +236 -105
- package/dist/tools/builtins/builtin-tools.d.ts +8 -8
- package/dist/tools/builtins/builtin-tools.js +16 -16
- package/dist/tools/call-scope.d.ts +1 -1
- package/dist/tools/connectors.service.d.ts +4 -13
- package/dist/tools/connectors.service.js +12 -21
- package/dist/tools/git-asks.js +1 -1
- package/dist/tools/git-push-policy.d.ts +3 -3
- package/dist/tools/git-push-policy.js +6 -6
- package/dist/tools/network-asks.d.ts +3 -3
- package/dist/tools/network-asks.js +3 -3
- package/dist/tools/oauth/flow.d.ts +16 -2
- package/dist/tools/oauth/flow.js +23 -4
- package/dist/tools/oauth/oauth.controller.d.ts +19 -7
- package/dist/tools/oauth/oauth.controller.js +42 -12
- package/dist/tools/oauth/oauth.schemas.d.ts +14 -1
- package/dist/tools/oauth/oauth.schemas.js +4 -1
- package/dist/tools/pipeline.d.ts +4 -4
- package/dist/tools/pipeline.js +2 -2
- package/dist/tools/policy.d.ts +3 -3
- package/dist/tools/policy.js +3 -3
- package/dist/tools/tools.module.js +9 -9
- package/package.json +3 -3
- package/src/migrations/0188_automations_rename.sql +309 -0
- package/src/migrations/0189_event_automations.sql +136 -0
- package/dist/platform/ops/schedules.ops.js +0 -509
- package/dist/schedules/effective-settings.d.ts +0 -22
- package/dist/schedules/effective-settings.js +0 -18
- package/dist/schedules/errors.d.ts +0 -8
- package/dist/schedules/errors.js +0 -8
- package/dist/schedules/job-ids.d.ts +0 -81
- package/dist/schedules/job-ids.js +0 -95
- package/dist/schedules/schedules.module.d.ts +0 -16
- package/dist/schedules/schedules.schemas.js +0 -213
- package/dist/schedules/store.module.d.ts +0 -6
- package/dist/schedules/types.d.ts +0 -110
- /package/dist/{schedules → automations}/types.js +0 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { HandoffRequestSchema } from "../../handoff/app-schemes.js";
|
|
2
3
|
import { ConnectorPathParams } from "../connectors.schemas.js";
|
|
3
4
|
import { isSafeReturnPath } from "./flow-paths.js";
|
|
4
5
|
/**
|
|
5
6
|
* `POST …/connectors/:connectorId/connect`: where the browser returns after the authorization (a
|
|
6
|
-
* relative path on this site; default the connections page).
|
|
7
|
+
* relative path on this site; default the connections page). `handoff` (a native shell): finish
|
|
8
|
+
* the authorization in the system browser through a handoff ticket instead.
|
|
7
9
|
*/
|
|
8
10
|
export const OAuthConnectBodySchema = z
|
|
9
11
|
.object({
|
|
@@ -12,6 +14,7 @@ export const OAuthConnectBodySchema = z
|
|
|
12
14
|
.max(500)
|
|
13
15
|
.refine(isSafeReturnPath, { message: "returnTo must be a relative path on this site" })
|
|
14
16
|
.optional(),
|
|
17
|
+
handoff: HandoffRequestSchema.optional(),
|
|
15
18
|
})
|
|
16
19
|
.strict();
|
|
17
20
|
/**
|
package/dist/tools/pipeline.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ConversationSource, type FormAnswer, type InputForm, type Logger, type ServiceBlockedHost, type ToolCallContext, type ToolDisplay } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { AgentDefinition } from "../agents/definition.js";
|
|
3
|
+
import { type UnattendedRun } from "../automations/unattended.js";
|
|
3
4
|
import { ConversationApprovalProfile } from "../conversations/approval-profile.js";
|
|
4
5
|
import { AttachmentsService } from "../conversations/attachments.service.js";
|
|
5
6
|
import { EventLog } from "../conversations/event-log.js";
|
|
@@ -25,7 +26,6 @@ import { PermissionAutoGrants } from "../sandbox/permission-auto-grants.js";
|
|
|
25
26
|
import { PermissionCallGrants } from "../sandbox/permission-call-grants.js";
|
|
26
27
|
import { type CommandReview } from "../sandbox/review/index.js";
|
|
27
28
|
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
28
|
-
import { type UnattendedRun } from "../schedules/unattended.js";
|
|
29
29
|
import { ApprovalsService, type NetworkAskDetail } from "./approvals.service.js";
|
|
30
30
|
import { Breaker } from "./breaker.js";
|
|
31
31
|
import { Credentials } from "./credentials.js";
|
|
@@ -90,7 +90,7 @@ export declare const INPUT_SKIPPED_TEXT = "The user did not provide the requeste
|
|
|
90
90
|
*/
|
|
91
91
|
export declare const WAIT_SKIPPED_TEXT = "The user sent a message while this wait was running, which ended it; read the message below and continue. Call the tool again only if the wait is still needed.";
|
|
92
92
|
/** A watched ask over `tools.maxWatchedWaitsPerAccount` (spec §5.2). */
|
|
93
|
-
export declare const TOO_MANY_WATCHED_WAITS_TEXT = "Too many waits are running for this user; end one, or finish and let
|
|
93
|
+
export declare const TOO_MANY_WATCHED_WAITS_TEXT = "Too many waits are running for this user; end one, or finish and let an automation check later.";
|
|
94
94
|
/** A tool asked for a watched wait without a registered watcher (spec §5.2). */
|
|
95
95
|
export declare const watchWithoutWatcherText: (key: string) => string;
|
|
96
96
|
/** 同一调用连续请求输入超过上限。 */
|
|
@@ -208,7 +208,7 @@ export interface PolicyContext {
|
|
|
208
208
|
*/
|
|
209
209
|
callPolicy?: CallPolicy | null;
|
|
210
210
|
/**
|
|
211
|
-
* The
|
|
211
|
+
* The automation run the run serves, unattended or trial (scheduled tasks spec §7); unset or
|
|
212
212
|
* null: an attended run.
|
|
213
213
|
*/
|
|
214
214
|
unattended?: UnattendedRun | null;
|
|
@@ -344,7 +344,7 @@ export interface ToolStepContext {
|
|
|
344
344
|
*/
|
|
345
345
|
parent?: SubagentParent;
|
|
346
346
|
/**
|
|
347
|
-
* The
|
|
347
|
+
* The automation run this run serves (scheduled tasks spec §7); filled by `runStep` once per
|
|
348
348
|
* step from PG (`unattendedRunOf`), null when attended. Callers leave it unset.
|
|
349
349
|
*/
|
|
350
350
|
unattended?: UnattendedRun | null;
|
package/dist/tools/pipeline.js
CHANGED
|
@@ -10,6 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { CARD_BADGE_MAX, CARD_TEXT_MAX, DeviceAccessError, ToolError, validateInputForm, validateToolDisplay, } from "@capybara-hq/plugin-sdk";
|
|
11
11
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
|
+
import { appendMissingGrant, connectionGrantKey, UNATTENDED_CONNECTION_ERROR, UNATTENDED_ELICITATION_NOTE, UNATTENDED_QUESTION_ERROR, unattendedFails, unattendedRules, unattendedRunOf, } from "../automations/unattended.js";
|
|
13
14
|
import { backgroundMaxSeconds } from "../background/launch.js";
|
|
14
15
|
import { ConversationApprovalProfile } from "../conversations/approval-profile.js";
|
|
15
16
|
import { AttachmentsService } from "../conversations/attachments.service.js";
|
|
@@ -49,7 +50,6 @@ import { isSessionGrantableRule, } from "../sandbox/review/index.js";
|
|
|
49
50
|
import { approverForCrossing, buildPermissionCandidate, crossingOfCandidate, ESCALATION_RETRY_HINT, ESCALATION_UNATTENDED_WHY, escalationRefusedText, isEscalatedCall, } from "../sandbox/review/permission-candidate.js";
|
|
50
51
|
import { CommandReviewService } from "../sandbox/review/review.service.js";
|
|
51
52
|
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
52
|
-
import { appendMissingGrant, connectionGrantKey, UNATTENDED_CONNECTION_ERROR, UNATTENDED_ELICITATION_NOTE, UNATTENDED_QUESTION_ERROR, unattendedFails, unattendedRules, unattendedRunOf, } from "../schedules/unattended.js";
|
|
53
53
|
import { skillLoadOfferedIn } from "../skills/catalog.js";
|
|
54
54
|
import { ApprovalsService, } from "./approvals.service.js";
|
|
55
55
|
import { Breaker, breakerOpenMessage } from "./breaker.js";
|
|
@@ -144,7 +144,7 @@ export const INPUT_SKIPPED_TEXT = "The user did not provide the requested input
|
|
|
144
144
|
*/
|
|
145
145
|
export const WAIT_SKIPPED_TEXT = "The user sent a message while this wait was running, which ended it; read the message below and continue. Call the tool again only if the wait is still needed.";
|
|
146
146
|
/** A watched ask over `tools.maxWatchedWaitsPerAccount` (spec §5.2). */
|
|
147
|
-
export const TOO_MANY_WATCHED_WAITS_TEXT = "Too many waits are running for this user; end one, or finish and let
|
|
147
|
+
export const TOO_MANY_WATCHED_WAITS_TEXT = "Too many waits are running for this user; end one, or finish and let an automation check later.";
|
|
148
148
|
/** A tool asked for a watched wait without a registered watcher (spec §5.2). */
|
|
149
149
|
export const watchWithoutWatcherText = (key) => `Tool ${key} asked for a watched wait but registers no watcher.`;
|
|
150
150
|
/** 同一调用连续请求输入超过上限。 */
|
package/dist/tools/policy.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { R3_FIXED_ASK_TOOL_KEYS } from "./builtin-names.js";
|
|
|
6
6
|
export { isFixedAsk } from "./fixed-ask.js";
|
|
7
7
|
/**
|
|
8
8
|
* What allowed an ask without an approval: this conversation's grant, an "always" grant, or a
|
|
9
|
-
*
|
|
9
|
+
* automation's grant (its unattended runs, scheduled tasks spec §7).
|
|
10
10
|
*/
|
|
11
11
|
export type GrantKind = "session" | "always" | "task";
|
|
12
12
|
/** 取更严的策略(`allow < ask < deny`)。 */
|
|
@@ -16,10 +16,10 @@ export interface PolicyInput {
|
|
|
16
16
|
connectorDefault: ToolPolicy;
|
|
17
17
|
/** agent 负责人的收紧(`definition.toolPolicies[key]`)。 */
|
|
18
18
|
agentOverride?: "ask" | "deny";
|
|
19
|
-
/** `requiresUserInteraction
|
|
19
|
+
/** `requiresUserInteraction`. */
|
|
20
20
|
fixedAsk: boolean;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* A remembered grant whose specHash matches the current one; `task`: an automation's grant in its unattended run.
|
|
23
23
|
*/
|
|
24
24
|
grant: GrantKind | null;
|
|
25
25
|
}
|
package/dist/tools/policy.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { sql } from "kysely";
|
|
2
2
|
import { normalizeStoredDefinition } from "../agents/definition.js";
|
|
3
|
+
import { grantRefusalOf } from "../automations/grant-rules.js";
|
|
4
|
+
import { findTaskGrant } from "../automations/store.js";
|
|
5
|
+
import { changesAgentSkills, UNATTENDED_ASK_ERROR, UNATTENDED_FIXED_ASK_ERROR, UNATTENDED_QUESTION_ERROR, unattendedRules, } from "../automations/unattended.js";
|
|
3
6
|
import { roleAtLeast } from "../orgs/roles.js";
|
|
4
7
|
import { FORBIDDEN_TOOLS_UNREADABLE_ERROR, readOrgSettings } from "../orgs/settings.service.js";
|
|
5
|
-
import { grantRefusalOf } from "../schedules/grant-rules.js";
|
|
6
|
-
import { findTaskGrant } from "../schedules/store.js";
|
|
7
|
-
import { changesAgentSkills, UNATTENDED_ASK_ERROR, UNATTENDED_FIXED_ASK_ERROR, UNATTENDED_QUESTION_ERROR, unattendedRules, } from "../schedules/unattended.js";
|
|
8
8
|
import { BUILTIN, SANDBOX_ASK_TOOL_NAMES } from "./builtin-names.js";
|
|
9
9
|
import { personalAuth } from "./connector-account-policies.js";
|
|
10
10
|
import { isFixedAsk } from "./fixed-ask.js";
|
|
@@ -5,6 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Module } from "@nestjs/common";
|
|
8
|
+
import { AutomationStoreModule } from "../automations/store.module.js";
|
|
8
9
|
import { BackgroundModule } from "../background/background.module.js";
|
|
9
10
|
import { ConversationAccessModule } from "../conversations/access.js";
|
|
10
11
|
import { ConversationApprovalProfileModule } from "../conversations/approval-profile.js";
|
|
@@ -29,14 +30,13 @@ import { OperationAuthorityModule } from "../sandbox/operation-authority.module.
|
|
|
29
30
|
import { PermissionAuthorityModule } from "../sandbox/permission-authority.module.js";
|
|
30
31
|
import { PermissionCallGrantsModule } from "../sandbox/permission-call-grants.module.js";
|
|
31
32
|
import { SandboxModule } from "../sandbox/sandbox.module.js";
|
|
32
|
-
import { ScheduledTaskStoreModule } from "../schedules/store.module.js";
|
|
33
33
|
import { SkillsModule } from "../skills/skills.module.js";
|
|
34
34
|
import { StorageModule } from "../storage/storage.module.js";
|
|
35
35
|
import { AdminConnectors } from "./admin-connectors.js";
|
|
36
36
|
import { ApprovalsService } from "./approvals.service.js";
|
|
37
37
|
import { Breaker } from "./breaker.js";
|
|
38
|
+
import { AutomationToolsPort, AutomationUpdates } from "./builtins/automations.js";
|
|
38
39
|
import { BuiltinTools } from "./builtins/builtin-tools.js";
|
|
39
|
-
import { ScheduleToolsPort, ScheduleUpdates } from "./builtins/schedules.js";
|
|
40
40
|
import { WebPages } from "./builtins/web/page-cache.js";
|
|
41
41
|
import { ConnectorAccountPolicies } from "./connector-account-policies.js";
|
|
42
42
|
import { ConnectorContent } from "./connector-content.js";
|
|
@@ -108,8 +108,8 @@ ToolsModule = __decorate([
|
|
|
108
108
|
// ConnectorToolsProcessor)
|
|
109
109
|
ConnectorToolsQueueModule,
|
|
110
110
|
ToolWatchQueueModule,
|
|
111
|
-
// a trial run's approvals become its
|
|
112
|
-
|
|
111
|
+
// a trial run's approvals become its automation's grants (scheduled tasks spec §7)
|
|
112
|
+
AutomationStoreModule,
|
|
113
113
|
// connector credentials (also the git gateway's, without importing this module)
|
|
114
114
|
CredentialsModule,
|
|
115
115
|
],
|
|
@@ -119,10 +119,10 @@ ToolsModule = __decorate([
|
|
|
119
119
|
BuiltinTools,
|
|
120
120
|
// a Platform write's file reference (a conversation file)
|
|
121
121
|
FileRefs,
|
|
122
|
-
// `
|
|
123
|
-
|
|
124
|
-
// where `
|
|
125
|
-
|
|
122
|
+
// `AutomationUpdate`'s write in one transaction (scheduled tasks spec §11)
|
|
123
|
+
AutomationUpdates,
|
|
124
|
+
// where `AutomationsModule` binds the task service for the automation tools (no provider cycle)
|
|
125
|
+
AutomationToolsPort,
|
|
126
126
|
WebPages,
|
|
127
127
|
ToolRegistry,
|
|
128
128
|
ApprovalsService,
|
|
@@ -144,7 +144,7 @@ ToolsModule = __decorate([
|
|
|
144
144
|
],
|
|
145
145
|
exports: [
|
|
146
146
|
PermissionApprovalJobs,
|
|
147
|
-
|
|
147
|
+
AutomationToolsPort,
|
|
148
148
|
CredentialsModule,
|
|
149
149
|
ToolOutputs,
|
|
150
150
|
BuiltinTools,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/kernel",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.106",
|
|
4
4
|
"description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"yaml": "^2.9.1",
|
|
67
67
|
"yauzl": "3.4.0",
|
|
68
68
|
"zod": "^4.6.7",
|
|
69
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
69
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.85"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@langchain/langgraph-checkpoint-validation": "^1.2.0",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@types/ws": "^8.18.2",
|
|
76
76
|
"@types/yauzl": "3.4.0",
|
|
77
77
|
"ws": "^8.22.0",
|
|
78
|
-
"@capybara-hq/testing": "0.1.0-rc.
|
|
78
|
+
"@capybara-hq/testing": "0.1.0-rc.47"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"build": "tsc -b"
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
-- Scheduled tasks become automations (collaboration spec 2026-11-25 §4.1; no compatibility before
|
|
2
|
+
-- 0.1.0): the tables, their columns, indexes and constraints, and the columns that point at them
|
|
3
|
+
-- take the new names, and the mutable state that names the feature is rewritten once, here:
|
|
4
|
+
-- - the push category `schedules` (the CHECK of 0172 and the stored preferences) → `automations`;
|
|
5
|
+
-- - the org settings group `scheduledTasks` → `automations` (its `forbiddenTools` in new keys);
|
|
6
|
+
-- - audit actions `schedule.*` → `automation.*`;
|
|
7
|
+
-- - the builtin tool keys `ScheduleCreate`, `ScheduleUpdate`, `ScheduleList`, `ScheduleTargets`
|
|
8
|
+
-- and `ScheduleDelete` → `Automation*`, in tool grants, an automation's grants, pending
|
|
9
|
+
-- approvals and questions, and stored agent definitions and agent templates (the pattern of
|
|
10
|
+
-- 0063 and 0139: only tool key positions, never prose);
|
|
11
|
+
-- - pending outbox rows: the jobs `sched-fire` / `sched-settle` → `automation-fire` /
|
|
12
|
+
-- `automation-settle` with their ids, and push jobs of an automation run (`sched-<taskRunId>`
|
|
13
|
+
-- event ids, source kind `schedule`) → `automation-<taskRunId>`, kind `automation`.
|
|
14
|
+
-- Logs and recordings are never rewritten (as in 0063): the event log keeps its frozen names
|
|
15
|
+
-- (`user_message.schedule`, `run_started.trigger = 'schedule'`), and so does the
|
|
16
|
+
-- `conversation_queue.schedule` column that carries the frozen marker. Decided approvals and
|
|
17
|
+
-- answered questions are history and stay. Not migrated (pre-0.1.0, no compatibility layer):
|
|
18
|
+
-- - pending push deliveries keep `message.threadId` `schedule-<taskId>` (it only groups
|
|
19
|
+
-- notifications on the device);
|
|
20
|
+
-- - jobs already handed to Redis under the old names, and pending Platform-tool approvals that name
|
|
21
|
+
-- a `schedules.*` operation;
|
|
22
|
+
-- - deployment config: a deployment renames its `schedules.*` config (env `CAPYBARA_SCHEDULES__*`,
|
|
23
|
+
-- config file or Nacos) to `automations.*` itself.
|
|
24
|
+
--
|
|
25
|
+
-- `automation_grants` has no `org_id`, so, like `scheduled_task_grants` before it, it gets no RLS
|
|
26
|
+
-- policy (RLS spec §6, child tables); the `org_scope` policies of 0182 follow their tables through
|
|
27
|
+
-- the rename and are stated again under the new names. Idempotent: a second run matches nothing it could change.
|
|
28
|
+
|
|
29
|
+
-- capybara:allow-destructive table rename; the kernel code is renamed in the same release (project not released, no compatibility layer)
|
|
30
|
+
ALTER TABLE IF EXISTS scheduled_tasks RENAME TO automations;
|
|
31
|
+
-- capybara:allow-destructive table rename; the kernel code is renamed in the same release (project not released, no compatibility layer)
|
|
32
|
+
ALTER TABLE IF EXISTS scheduled_task_runs RENAME TO automation_runs;
|
|
33
|
+
-- capybara:allow-destructive table rename; the kernel code is renamed in the same release (project not released, no compatibility layer)
|
|
34
|
+
ALTER TABLE IF EXISTS scheduled_task_grants RENAME TO automation_grants;
|
|
35
|
+
|
|
36
|
+
-- Column and constraint renames: RENAME COLUMN / RENAME CONSTRAINT take no IF EXISTS, so each runs
|
|
37
|
+
-- only while its old name is there.
|
|
38
|
+
-- capybara:allow-destructive column and constraint renames; the kernel code is renamed in the same release (project not released, no compatibility layer)
|
|
39
|
+
DO $$
|
|
40
|
+
DECLARE
|
|
41
|
+
c record;
|
|
42
|
+
BEGIN
|
|
43
|
+
FOR c IN SELECT * FROM (VALUES
|
|
44
|
+
('automation_runs', 'task_id', 'automation_id'),
|
|
45
|
+
('automation_grants', 'task_id', 'automation_id'),
|
|
46
|
+
('runs', 'scheduled_task_run_id', 'automation_run_id'),
|
|
47
|
+
('conversations', 'scheduled_task_id', 'automation_id')
|
|
48
|
+
) AS m(tbl, old_name, new_name) LOOP
|
|
49
|
+
IF EXISTS (SELECT 1 FROM information_schema.columns
|
|
50
|
+
WHERE table_schema = current_schema() AND table_name = c.tbl
|
|
51
|
+
AND column_name = c.old_name) THEN
|
|
52
|
+
EXECUTE format('ALTER TABLE %I RENAME COLUMN %I TO %I', c.tbl, c.old_name, c.new_name);
|
|
53
|
+
END IF;
|
|
54
|
+
END LOOP;
|
|
55
|
+
FOR c IN SELECT * FROM (VALUES
|
|
56
|
+
('automations', 'scheduled_tasks_org_id_fkey', 'automations_org_id_fkey'),
|
|
57
|
+
('automations', 'scheduled_tasks_mode_check', 'automations_mode_check'),
|
|
58
|
+
('automations', 'scheduled_tasks_status_check', 'automations_status_check'),
|
|
59
|
+
('automations', 'scheduled_tasks_pause_reason_check', 'automations_pause_reason_check'),
|
|
60
|
+
('automation_runs', 'scheduled_task_runs_task_id_fkey', 'automation_runs_automation_id_fkey'),
|
|
61
|
+
('automation_runs', 'scheduled_task_runs_org_id_fkey', 'automation_runs_org_id_fkey'),
|
|
62
|
+
('automation_runs', 'scheduled_task_runs_status_check', 'automation_runs_status_check'),
|
|
63
|
+
('automation_runs', 'scheduled_task_runs_skip_reason_check',
|
|
64
|
+
'automation_runs_skip_reason_check'),
|
|
65
|
+
('automation_grants', 'scheduled_task_grants_task_id_fkey',
|
|
66
|
+
'automation_grants_automation_id_fkey')
|
|
67
|
+
) AS m(tbl, old_name, new_name) LOOP
|
|
68
|
+
IF EXISTS (SELECT 1 FROM pg_constraint k
|
|
69
|
+
JOIN pg_class t ON t.oid = k.conrelid
|
|
70
|
+
WHERE t.relnamespace = current_schema()::regnamespace AND t.relname = c.tbl
|
|
71
|
+
AND k.conname = c.old_name) THEN
|
|
72
|
+
EXECUTE format('ALTER TABLE %I RENAME CONSTRAINT %I TO %I', c.tbl, c.old_name, c.new_name);
|
|
73
|
+
END IF;
|
|
74
|
+
END LOOP;
|
|
75
|
+
END
|
|
76
|
+
$$;
|
|
77
|
+
|
|
78
|
+
-- Indexes (a primary key's index renames its constraint with it).
|
|
79
|
+
-- capybara:allow-destructive index rename; the kernel code is renamed in the same release (project not released, no compatibility layer)
|
|
80
|
+
ALTER INDEX IF EXISTS scheduled_tasks_pkey RENAME TO automations_pkey;
|
|
81
|
+
-- capybara:allow-destructive index rename; the kernel code is renamed in the same release (project not released, no compatibility layer)
|
|
82
|
+
ALTER INDEX IF EXISTS scheduled_tasks_due_idx RENAME TO automations_due_idx;
|
|
83
|
+
-- capybara:allow-destructive index rename; the kernel code is renamed in the same release (project not released, no compatibility layer)
|
|
84
|
+
ALTER INDEX IF EXISTS scheduled_tasks_account_idx RENAME TO automations_account_idx;
|
|
85
|
+
-- capybara:allow-destructive index rename; the kernel code is renamed in the same release (project not released, no compatibility layer)
|
|
86
|
+
ALTER INDEX IF EXISTS scheduled_task_runs_pkey RENAME TO automation_runs_pkey;
|
|
87
|
+
-- capybara:allow-destructive index rename; the kernel code is renamed in the same release (project not released, no compatibility layer)
|
|
88
|
+
ALTER INDEX IF EXISTS scheduled_task_runs_tick_uq RENAME TO automation_runs_tick_uq;
|
|
89
|
+
-- capybara:allow-destructive index rename; the kernel code is renamed in the same release (project not released, no compatibility layer)
|
|
90
|
+
ALTER INDEX IF EXISTS scheduled_task_runs_pending_idx RENAME TO automation_runs_pending_idx;
|
|
91
|
+
-- capybara:allow-destructive index rename; the kernel code is renamed in the same release (project not released, no compatibility layer)
|
|
92
|
+
ALTER INDEX IF EXISTS scheduled_task_runs_task_idx RENAME TO automation_runs_automation_idx;
|
|
93
|
+
-- capybara:allow-destructive index rename; the kernel code is renamed in the same release (project not released, no compatibility layer)
|
|
94
|
+
ALTER INDEX IF EXISTS scheduled_task_runs_fired_idx RENAME TO automation_runs_fired_idx;
|
|
95
|
+
-- capybara:allow-destructive index rename; the kernel code is renamed in the same release (project not released, no compatibility layer)
|
|
96
|
+
ALTER INDEX IF EXISTS scheduled_task_grants_pkey RENAME TO automation_grants_pkey;
|
|
97
|
+
-- capybara:allow-destructive index rename; the kernel code is renamed in the same release (project not released, no compatibility layer)
|
|
98
|
+
ALTER INDEX IF EXISTS conversations_scheduled_task_idx RENAME TO conversations_automation_idx;
|
|
99
|
+
|
|
100
|
+
-- The `org_scope` policies of 0182 followed their tables through the rename; stated again under
|
|
101
|
+
-- the new names (still dark: nothing enables row level security before phase 5).
|
|
102
|
+
DROP POLICY IF EXISTS org_scope ON automations;
|
|
103
|
+
CREATE POLICY org_scope ON automations USING (rls_admits(org_id)) WITH CHECK (rls_admits(org_id));
|
|
104
|
+
DROP POLICY IF EXISTS org_scope ON automation_runs;
|
|
105
|
+
CREATE POLICY org_scope ON automation_runs USING (rls_admits(org_id)) WITH CHECK (rls_admits(org_id));
|
|
106
|
+
|
|
107
|
+
-- The push category: the CHECK of 0172 is replaced (drop and add in this file's one transaction),
|
|
108
|
+
-- the stored preferences follow.
|
|
109
|
+
ALTER TABLE push_preferences DROP CONSTRAINT IF EXISTS push_preferences_category_check;
|
|
110
|
+
-- capybara:allow-destructive rewrites the category in place; no kernel version reads the old name
|
|
111
|
+
UPDATE push_preferences SET category = 'automations' WHERE category = 'schedules';
|
|
112
|
+
ALTER TABLE push_preferences ADD CONSTRAINT push_preferences_category_check
|
|
113
|
+
CHECK (category IN ('waiting', 'replies', 'tasks', 'automations'));
|
|
114
|
+
|
|
115
|
+
-- The new key of builtin tool key `k` (every other key as it is).
|
|
116
|
+
CREATE OR REPLACE FUNCTION pg_temp.automation_tool_key(k text) RETURNS text
|
|
117
|
+
LANGUAGE sql IMMUTABLE AS $fn$
|
|
118
|
+
SELECT CASE k
|
|
119
|
+
WHEN 'ScheduleCreate' THEN 'AutomationCreate'
|
|
120
|
+
WHEN 'ScheduleUpdate' THEN 'AutomationUpdate'
|
|
121
|
+
WHEN 'ScheduleList' THEN 'AutomationList'
|
|
122
|
+
WHEN 'ScheduleTargets' THEN 'AutomationTargets'
|
|
123
|
+
WHEN 'ScheduleDelete' THEN 'AutomationDelete'
|
|
124
|
+
ELSE k
|
|
125
|
+
END
|
|
126
|
+
$fn$;
|
|
127
|
+
|
|
128
|
+
-- A list of tool keys in new keys, in order; other values (and a non-list) as they are.
|
|
129
|
+
CREATE OR REPLACE FUNCTION pg_temp.automation_key_list(l jsonb) RETURNS jsonb
|
|
130
|
+
LANGUAGE sql IMMUTABLE AS $fn$
|
|
131
|
+
SELECT CASE WHEN jsonb_typeof(l) IS DISTINCT FROM 'array' THEN l ELSE coalesce((
|
|
132
|
+
SELECT jsonb_agg(
|
|
133
|
+
CASE WHEN jsonb_typeof(x.e) = 'string'
|
|
134
|
+
THEN to_jsonb(pg_temp.automation_tool_key(x.e #>> '{}')) ELSE x.e END
|
|
135
|
+
ORDER BY x.ord)
|
|
136
|
+
FROM jsonb_array_elements(l) WITH ORDINALITY AS x(e, ord)), '[]'::jsonb) END
|
|
137
|
+
$fn$;
|
|
138
|
+
|
|
139
|
+
-- `toolPolicies` (an object keyed by tool key) in new keys.
|
|
140
|
+
CREATE OR REPLACE FUNCTION pg_temp.automation_policies(p jsonb) RETURNS jsonb
|
|
141
|
+
LANGUAGE sql IMMUTABLE AS $fn$
|
|
142
|
+
SELECT CASE WHEN jsonb_typeof(p) IS DISTINCT FROM 'object' THEN p ELSE coalesce((
|
|
143
|
+
SELECT jsonb_object_agg(pg_temp.automation_tool_key(e.key), e.value)
|
|
144
|
+
FROM jsonb_each(p) AS e), '{}'::jsonb) END
|
|
145
|
+
$fn$;
|
|
146
|
+
|
|
147
|
+
-- `disabledTools` (tools default-on spec §2): a builtin entry names its tool by key; extension and
|
|
148
|
+
-- connector entries name their own tools and stay.
|
|
149
|
+
CREATE OR REPLACE FUNCTION pg_temp.automation_disabled(l jsonb) RETURNS jsonb
|
|
150
|
+
LANGUAGE sql IMMUTABLE AS $fn$
|
|
151
|
+
SELECT CASE WHEN jsonb_typeof(l) IS DISTINCT FROM 'array' THEN l ELSE coalesce((
|
|
152
|
+
SELECT jsonb_agg(
|
|
153
|
+
CASE WHEN jsonb_typeof(x.e) = 'object' AND x.e ->> 'kind' = 'builtin'
|
|
154
|
+
AND jsonb_typeof(x.e -> 'name') = 'string'
|
|
155
|
+
THEN jsonb_set(x.e, '{name}', to_jsonb(pg_temp.automation_tool_key(x.e ->> 'name')))
|
|
156
|
+
ELSE x.e END
|
|
157
|
+
ORDER BY x.ord)
|
|
158
|
+
FROM jsonb_array_elements(l) WITH ORDINALITY AS x(e, ord)), '[]'::jsonb) END
|
|
159
|
+
$fn$;
|
|
160
|
+
|
|
161
|
+
-- A template-shaped value (an agent template, an inline sub-agent, an agent definition) in new keys.
|
|
162
|
+
CREATE OR REPLACE FUNCTION pg_temp.automation_template(t jsonb) RETURNS jsonb
|
|
163
|
+
LANGUAGE sql IMMUTABLE AS $fn$
|
|
164
|
+
SELECT CASE WHEN jsonb_typeof(t) IS DISTINCT FROM 'object' THEN t ELSE t
|
|
165
|
+
|| CASE WHEN t ? 'tools'
|
|
166
|
+
THEN jsonb_build_object('tools', pg_temp.automation_key_list(t -> 'tools'))
|
|
167
|
+
ELSE '{}'::jsonb END
|
|
168
|
+
|| CASE WHEN t ? 'disallowedTools'
|
|
169
|
+
THEN jsonb_build_object('disallowedTools',
|
|
170
|
+
pg_temp.automation_key_list(t -> 'disallowedTools'))
|
|
171
|
+
ELSE '{}'::jsonb END
|
|
172
|
+
|| CASE WHEN t ? 'toolPolicies'
|
|
173
|
+
THEN jsonb_build_object('toolPolicies', pg_temp.automation_policies(t -> 'toolPolicies'))
|
|
174
|
+
ELSE '{}'::jsonb END
|
|
175
|
+
|| CASE WHEN t ? 'disabledTools'
|
|
176
|
+
THEN jsonb_build_object('disabledTools',
|
|
177
|
+
pg_temp.automation_disabled(t -> 'disabledTools'))
|
|
178
|
+
ELSE '{}'::jsonb END
|
|
179
|
+
END
|
|
180
|
+
$fn$;
|
|
181
|
+
|
|
182
|
+
-- An agent definition or an agent template in new keys: its own keys and those of its inline
|
|
183
|
+
-- sub-agent templates.
|
|
184
|
+
CREATE OR REPLACE FUNCTION pg_temp.automation_definition(d jsonb) RETURNS jsonb
|
|
185
|
+
LANGUAGE sql IMMUTABLE AS $fn$
|
|
186
|
+
SELECT pg_temp.automation_template(d) || CASE
|
|
187
|
+
WHEN jsonb_typeof(d -> 'subagents' -> 'inline') = 'array' THEN jsonb_build_object(
|
|
188
|
+
'subagents',
|
|
189
|
+
jsonb_set(d -> 'subagents', '{inline}', (
|
|
190
|
+
SELECT coalesce(jsonb_agg(pg_temp.automation_template(x.e) ORDER BY x.ord), '[]'::jsonb)
|
|
191
|
+
FROM jsonb_array_elements(d -> 'subagents' -> 'inline') WITH ORDINALITY AS x(e, ord))))
|
|
192
|
+
ELSE '{}'::jsonb
|
|
193
|
+
END
|
|
194
|
+
$fn$;
|
|
195
|
+
|
|
196
|
+
-- capybara:allow-destructive rewrites builtin tool keys in place; no kernel version reads the old keys
|
|
197
|
+
UPDATE agent_versions
|
|
198
|
+
SET definition = pg_temp.automation_definition(definition)
|
|
199
|
+
WHERE pg_temp.automation_definition(definition) <> definition;
|
|
200
|
+
|
|
201
|
+
-- capybara:allow-destructive rewrites builtin tool keys in place; no kernel version reads the old keys
|
|
202
|
+
UPDATE agent_template_versions
|
|
203
|
+
SET definition = pg_temp.automation_definition(definition)
|
|
204
|
+
WHERE pg_temp.automation_definition(definition) <> definition;
|
|
205
|
+
|
|
206
|
+
-- capybara:allow-destructive rewrites builtin tool keys in place; no kernel version reads the old keys
|
|
207
|
+
UPDATE platform_agent_template_versions
|
|
208
|
+
SET definition = pg_temp.automation_definition(definition)
|
|
209
|
+
WHERE pg_temp.automation_definition(definition) <> definition;
|
|
210
|
+
|
|
211
|
+
-- The org settings group moves to `automations`; its `forbiddenTools` (tool keys) in new keys.
|
|
212
|
+
-- capybara:allow-destructive moves the settings group in place; no kernel version reads the old key
|
|
213
|
+
UPDATE orgs
|
|
214
|
+
SET settings = (settings - 'scheduledTasks') || jsonb_build_object('automations',
|
|
215
|
+
CASE WHEN jsonb_typeof(settings -> 'scheduledTasks') = 'object'
|
|
216
|
+
AND settings -> 'scheduledTasks' ? 'forbiddenTools'
|
|
217
|
+
THEN jsonb_set(settings -> 'scheduledTasks', '{forbiddenTools}',
|
|
218
|
+
pg_temp.automation_key_list(settings -> 'scheduledTasks' -> 'forbiddenTools'))
|
|
219
|
+
ELSE settings -> 'scheduledTasks' END)
|
|
220
|
+
WHERE jsonb_typeof(settings) = 'object' AND settings ? 'scheduledTasks';
|
|
221
|
+
|
|
222
|
+
-- Grants: a grant whose new key already exists for the same owner stays as it is (the primary key).
|
|
223
|
+
-- capybara:allow-destructive rewrites builtin tool keys in place; no kernel version reads the old keys
|
|
224
|
+
UPDATE tool_grants g
|
|
225
|
+
SET tool_key = pg_temp.automation_tool_key(g.tool_key)
|
|
226
|
+
WHERE pg_temp.automation_tool_key(g.tool_key) <> g.tool_key
|
|
227
|
+
AND NOT EXISTS (
|
|
228
|
+
SELECT 1 FROM tool_grants x
|
|
229
|
+
WHERE x.org_id = g.org_id AND x.account_id = g.account_id AND x.agent_id = g.agent_id
|
|
230
|
+
AND x.tool_key = pg_temp.automation_tool_key(g.tool_key)
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
-- capybara:allow-destructive rewrites builtin tool keys in place; no kernel version reads the old keys
|
|
234
|
+
UPDATE conversation_tool_grants g
|
|
235
|
+
SET tool_key = pg_temp.automation_tool_key(g.tool_key)
|
|
236
|
+
WHERE pg_temp.automation_tool_key(g.tool_key) <> g.tool_key
|
|
237
|
+
AND NOT EXISTS (
|
|
238
|
+
SELECT 1 FROM conversation_tool_grants x
|
|
239
|
+
WHERE x.conversation_id = g.conversation_id
|
|
240
|
+
AND x.tool_key = pg_temp.automation_tool_key(g.tool_key)
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
-- capybara:allow-destructive rewrites builtin tool keys in place; no kernel version reads the old keys
|
|
244
|
+
UPDATE automation_grants g
|
|
245
|
+
SET tool_key = pg_temp.automation_tool_key(g.tool_key)
|
|
246
|
+
WHERE pg_temp.automation_tool_key(g.tool_key) <> g.tool_key
|
|
247
|
+
AND NOT EXISTS (
|
|
248
|
+
SELECT 1 FROM automation_grants x
|
|
249
|
+
WHERE x.automation_id = g.automation_id
|
|
250
|
+
AND x.tool_key = pg_temp.automation_tool_key(g.tool_key)
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
-- capybara:allow-destructive rewrites tool keys of pending approvals in place (resumed by run and call id, never by key)
|
|
254
|
+
UPDATE approvals
|
|
255
|
+
SET tool_key = pg_temp.automation_tool_key(tool_key)
|
|
256
|
+
WHERE status = 'pending' AND pg_temp.automation_tool_key(tool_key) <> tool_key;
|
|
257
|
+
|
|
258
|
+
-- capybara:allow-destructive rewrites tool keys of pending questions in place (resumed by run and call id, never by key)
|
|
259
|
+
UPDATE questions
|
|
260
|
+
SET spec = jsonb_set(spec, '{toolKey}', to_jsonb(pg_temp.automation_tool_key(spec ->> 'toolKey')))
|
|
261
|
+
WHERE status = 'pending' AND jsonb_typeof(spec -> 'toolKey') = 'string'
|
|
262
|
+
AND pg_temp.automation_tool_key(spec ->> 'toolKey') <> spec ->> 'toolKey';
|
|
263
|
+
|
|
264
|
+
DROP FUNCTION IF EXISTS pg_temp.automation_definition(jsonb);
|
|
265
|
+
DROP FUNCTION IF EXISTS pg_temp.automation_template(jsonb);
|
|
266
|
+
DROP FUNCTION IF EXISTS pg_temp.automation_disabled(jsonb);
|
|
267
|
+
DROP FUNCTION IF EXISTS pg_temp.automation_policies(jsonb);
|
|
268
|
+
DROP FUNCTION IF EXISTS pg_temp.automation_key_list(jsonb);
|
|
269
|
+
DROP FUNCTION IF EXISTS pg_temp.automation_tool_key(text);
|
|
270
|
+
|
|
271
|
+
-- capybara:allow-destructive renames audit actions in place; no kernel version reads the old names
|
|
272
|
+
UPDATE audit_events
|
|
273
|
+
SET action = 'automation.' || substr(action, length('schedule.') + 1)
|
|
274
|
+
WHERE action LIKE 'schedule.%';
|
|
275
|
+
|
|
276
|
+
-- Pending outbox rows (dead ones too, so a retry by hand still finds its handler): the
|
|
277
|
+
-- automation jobs and their ids (`sched-fire-<taskRunId>`, `sched-settle-<taskRunId>[-…]`).
|
|
278
|
+
-- capybara:allow-destructive renames owed jobs in place; no kernel version handles the old names
|
|
279
|
+
UPDATE outbox
|
|
280
|
+
SET job_name = 'automation-fire',
|
|
281
|
+
job_id = 'automation-fire-' || substr(job_id, length('sched-fire-') + 1)
|
|
282
|
+
WHERE job_name = 'sched-fire' AND job_id LIKE 'sched-fire-%';
|
|
283
|
+
|
|
284
|
+
-- capybara:allow-destructive renames owed jobs in place; no kernel version handles the old names
|
|
285
|
+
UPDATE outbox
|
|
286
|
+
SET job_name = 'automation-settle',
|
|
287
|
+
job_id = 'automation-settle-' || substr(job_id, length('sched-settle-') + 1)
|
|
288
|
+
WHERE job_name = 'sched-settle' AND job_id LIKE 'sched-settle-%';
|
|
289
|
+
|
|
290
|
+
-- Push jobs of an automation run: the event id `sched-<taskRunId>` becomes
|
|
291
|
+
-- `automation-<taskRunId>`, in the fanout's id and data (source kind `schedule` → `automation`)
|
|
292
|
+
-- and in each delivery's id and data.
|
|
293
|
+
-- capybara:allow-destructive renames owed push jobs in place; no kernel version reads the old source kind
|
|
294
|
+
UPDATE outbox
|
|
295
|
+
SET job_id = 'push-fanout-automation-' || substr(job_id, length('push-fanout-sched-') + 1),
|
|
296
|
+
data = jsonb_set(
|
|
297
|
+
jsonb_set(data, '{eventId}',
|
|
298
|
+
to_jsonb('automation-' || substr(data ->> 'eventId', length('sched-') + 1))),
|
|
299
|
+
'{source,kind}', '"automation"'::jsonb)
|
|
300
|
+
WHERE queue = 'cap-push-deliver' AND job_name = 'push-fanout'
|
|
301
|
+
AND job_id LIKE 'push-fanout-sched-%' AND data -> 'source' ->> 'kind' = 'schedule';
|
|
302
|
+
|
|
303
|
+
-- capybara:allow-destructive renames owed push jobs in place; no kernel version reads the old event ids
|
|
304
|
+
UPDATE outbox
|
|
305
|
+
SET job_id = 'push-automation-' || substr(job_id, length('push-sched-') + 1),
|
|
306
|
+
data = jsonb_set(data, '{eventId}',
|
|
307
|
+
to_jsonb('automation-' || substr(data ->> 'eventId', length('sched-') + 1)))
|
|
308
|
+
WHERE queue = 'cap-push-deliver' AND job_name = 'push-deliver'
|
|
309
|
+
AND job_id LIKE 'push-sched-%' AND data ->> 'eventId' LIKE 'sched-%';
|