@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,4 +1,5 @@
|
|
|
1
1
|
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { AutomationStore } from "../../automations/store.js";
|
|
2
3
|
import { BackgroundTaskFinisher } from "../../background/finish.js";
|
|
3
4
|
import { BackgroundTaskStopper } from "../../background/stop.js";
|
|
4
5
|
import { BackgroundTaskStore } from "../../background/store.js";
|
|
@@ -20,11 +21,10 @@ import { ProviderRegistry } from "../../runtime/providers.js";
|
|
|
20
21
|
import { StepLog } from "../../runtime/step-log.js";
|
|
21
22
|
import { ManagedDeviceContextRecorder } from "../../sandbox/managed-device-context.js";
|
|
22
23
|
import { SandboxService } from "../../sandbox/sandbox.service.js";
|
|
23
|
-
import { ScheduledTaskStore } from "../../schedules/store.js";
|
|
24
24
|
import { StorageService } from "../../storage/storage.service.js";
|
|
25
25
|
import { ToolOutputs } from "../outputs.js";
|
|
26
26
|
import type { BuiltinCallContext, BuiltinTool } from "../registry.js";
|
|
27
|
-
import {
|
|
27
|
+
import { AutomationToolsPort, AutomationUpdates } from "./automations.js";
|
|
28
28
|
import { WebPages } from "./web/index.js";
|
|
29
29
|
/**
|
|
30
30
|
* The kernel's builtin tools, built once from the injected services (their specs: names,
|
|
@@ -43,12 +43,12 @@ export declare class BuiltinTools {
|
|
|
43
43
|
sealedInputs: SealedInputs,
|
|
44
44
|
/** A Platform write's file reference: a conversation file (spec §5). */
|
|
45
45
|
fileRefs: FileRefs,
|
|
46
|
-
/** The
|
|
47
|
-
|
|
48
|
-
/** `
|
|
49
|
-
|
|
50
|
-
/** The task service, bound by `
|
|
51
|
-
|
|
46
|
+
/** The automation tools read tasks and grants; their writes go through the task service. */
|
|
47
|
+
automationStore: AutomationStore,
|
|
48
|
+
/** `AutomationUpdate`'s write: its field change and grant changes in one transaction. */
|
|
49
|
+
automationUpdates: AutomationUpdates,
|
|
50
|
+
/** The task service, bound by `AutomationsModule` at start (a registration port: no cycle). */
|
|
51
|
+
automationPort: AutomationToolsPort,
|
|
52
52
|
/** `GenerateImage`: the image calls, and the image model's availability per listing. */
|
|
53
53
|
images: ModelImages, providers: ProviderRegistry,
|
|
54
54
|
/** The clock `CurrentTime` reads (the run context's clock seam; `Date.now` by default). */
|
|
@@ -8,6 +8,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
11
|
+
import { AutomationStore } from "../../automations/store.js";
|
|
11
12
|
import { BackgroundTaskFinisher } from "../../background/finish.js";
|
|
12
13
|
import { BackgroundTaskStopper } from "../../background/stop.js";
|
|
13
14
|
import { BackgroundTaskStore } from "../../background/store.js";
|
|
@@ -35,18 +36,17 @@ import { conversationTimeZone, RUN_CONTEXT_CLOCK } from "../../runtime/run-conte
|
|
|
35
36
|
import { StepLog } from "../../runtime/step-log.js";
|
|
36
37
|
import { ManagedDeviceContextRecorder } from "../../sandbox/managed-device-context.js";
|
|
37
38
|
import { SandboxService } from "../../sandbox/sandbox.service.js";
|
|
38
|
-
import { ScheduledTaskStore } from "../../schedules/store.js";
|
|
39
39
|
import { StorageService } from "../../storage/storage.service.js";
|
|
40
40
|
import { ToolOutputs } from "../outputs.js";
|
|
41
41
|
import { agentTool } from "./agent.js";
|
|
42
42
|
import { askUserTool } from "./ask-user.js";
|
|
43
|
+
import { AutomationToolsPort, AutomationUpdates, automationTools } from "./automations.js";
|
|
43
44
|
import { currentTimeTool } from "./current-time.js";
|
|
44
45
|
import { handbackTool } from "./handback.js";
|
|
45
46
|
import { generateImageTool } from "./image/index.js";
|
|
46
47
|
import { platformTool } from "./platform.js";
|
|
47
48
|
import { readToolOutputTool } from "./read-tool-output.js";
|
|
48
49
|
import { sandboxTools } from "./sandbox/index.js";
|
|
49
|
-
import { ScheduleToolsPort, ScheduleUpdates, scheduleTools } from "./schedules.js";
|
|
50
50
|
import { sendMessageTool } from "./send-message.js";
|
|
51
51
|
import { skillLoadTool } from "./skill-load.js";
|
|
52
52
|
import { toolSearchTool } from "./tool-search.js";
|
|
@@ -66,12 +66,12 @@ let BuiltinTools = class BuiltinTools {
|
|
|
66
66
|
sealedInputs,
|
|
67
67
|
/** A Platform write's file reference: a conversation file (spec §5). */
|
|
68
68
|
fileRefs,
|
|
69
|
-
/** The
|
|
70
|
-
|
|
71
|
-
/** `
|
|
72
|
-
|
|
73
|
-
/** The task service, bound by `
|
|
74
|
-
|
|
69
|
+
/** The automation tools read tasks and grants; their writes go through the task service. */
|
|
70
|
+
automationStore,
|
|
71
|
+
/** `AutomationUpdate`'s write: its field change and grant changes in one transaction. */
|
|
72
|
+
automationUpdates,
|
|
73
|
+
/** The task service, bound by `AutomationsModule` at start (a registration port: no cycle). */
|
|
74
|
+
automationPort,
|
|
75
75
|
/** `GenerateImage`: the image calls, and the image model's availability per listing. */
|
|
76
76
|
images, providers,
|
|
77
77
|
/** The clock `CurrentTime` reads (the run context's clock seam; `Date.now` by default). */
|
|
@@ -211,13 +211,13 @@ let BuiltinTools = class BuiltinTools {
|
|
|
211
211
|
now: now ?? Date.now,
|
|
212
212
|
timeZoneOf: ({ orgId, conversationId }) => conversationTimeZone(db.db, orgId, conversationId),
|
|
213
213
|
}),
|
|
214
|
-
// the person's
|
|
215
|
-
...
|
|
214
|
+
// the person's automations (scheduled tasks spec §11)
|
|
215
|
+
...automationTools({
|
|
216
216
|
db: () => db.db,
|
|
217
217
|
config,
|
|
218
|
-
store:
|
|
219
|
-
service: () =>
|
|
220
|
-
updates:
|
|
218
|
+
store: automationStore,
|
|
219
|
+
service: () => automationPort.get(),
|
|
220
|
+
updates: automationUpdates,
|
|
221
221
|
timeZoneOf: (orgId, conversationId) => conversationTimeZone(db.db, orgId, conversationId),
|
|
222
222
|
now: now ?? Date.now,
|
|
223
223
|
}),
|
|
@@ -252,9 +252,9 @@ BuiltinTools = __decorate([
|
|
|
252
252
|
__param(19, Inject(AgentDocs)),
|
|
253
253
|
__param(20, Inject(SealedInputs)),
|
|
254
254
|
__param(21, Inject(FileRefs)),
|
|
255
|
-
__param(22, Inject(
|
|
256
|
-
__param(23, Inject(
|
|
257
|
-
__param(24, Inject(
|
|
255
|
+
__param(22, Inject(AutomationStore)),
|
|
256
|
+
__param(23, Inject(AutomationUpdates)),
|
|
257
|
+
__param(24, Inject(AutomationToolsPort)),
|
|
258
258
|
__param(25, Inject(ModelImages)),
|
|
259
259
|
__param(26, Inject(ProviderRegistry)),
|
|
260
260
|
__param(27, Inject(ManagedDeviceContextRecorder)),
|
|
@@ -15,7 +15,7 @@ export interface CallFacts {
|
|
|
15
15
|
step: number;
|
|
16
16
|
/** The root conversation of the run's tree (a sub-agent works in its root's device). */
|
|
17
17
|
rootConversationId: string;
|
|
18
|
-
/** An unattended run (
|
|
18
|
+
/** An unattended run (an automation): nobody is there to answer an ask. */
|
|
19
19
|
unattended: boolean;
|
|
20
20
|
agentVersion: number;
|
|
21
21
|
conversationKind?: ConversationKindForHooks;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type AuthHint, type ConnectorOperation, type GitSource, type ToolAnnotations } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { type ConnectionGuideState, type GuideAck, PluginGuides } from "../extensions/plugin-guides.js";
|
|
3
|
-
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
4
3
|
import type { WriteActor } from "../identity/write-actor.js";
|
|
5
4
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
6
5
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -259,11 +258,6 @@ export interface OAuthSetup {
|
|
|
259
258
|
export declare class ConnectorsService {
|
|
260
259
|
private readonly kdb;
|
|
261
260
|
private readonly registry;
|
|
262
|
-
/**
|
|
263
|
-
* Extension manifests: a derived default slug avoids an extension's name (an explicit slug may
|
|
264
|
-
* take one; connector and extension tool keys live in separate namespaces).
|
|
265
|
-
*/
|
|
266
|
-
private readonly extensions;
|
|
267
261
|
private readonly credentials;
|
|
268
262
|
private readonly config;
|
|
269
263
|
private readonly drift;
|
|
@@ -276,12 +270,7 @@ export declare class ConnectorsService {
|
|
|
276
270
|
readonly txHost: TransactionHost;
|
|
277
271
|
/** Setup guides of connector templates (spec 2026-11-09-setup-guides-v2-design.md §11). */
|
|
278
272
|
private readonly guides;
|
|
279
|
-
constructor(kdb: KernelDb, registry: ToolRegistry,
|
|
280
|
-
/**
|
|
281
|
-
* Extension manifests: a derived default slug avoids an extension's name (an explicit slug may
|
|
282
|
-
* take one; connector and extension tool keys live in separate namespaces).
|
|
283
|
-
*/
|
|
284
|
-
extensions: Pick<ExtensionRegistry, "manifests">, credentials: Credentials, config: Pick<KernelConfigService, "get">, drift: ToolDrift,
|
|
273
|
+
constructor(kdb: KernelDb, registry: ToolRegistry, credentials: Credentials, config: Pick<KernelConfigService, "get">, drift: ToolDrift,
|
|
285
274
|
/** The org row lock (orgs/org-lock.ts): joins the caller's transaction. */
|
|
286
275
|
orgLock: Pick<OrgLock, "lock" | "tryLock" | "lockAndAuthorize">,
|
|
287
276
|
/** Owed work: the tool listings that follow a deferred create or a setup (§5.2.1). */
|
|
@@ -300,7 +289,9 @@ export declare class ConnectorsService {
|
|
|
300
289
|
private slugTaken;
|
|
301
290
|
/**
|
|
302
291
|
* The first free default name and slug ({@link CreateConnectorInput.slugDefault}), read in the
|
|
303
|
-
* caller's transaction under the org lock.
|
|
292
|
+
* caller's transaction under the org lock. Only live connectors hold a slug: an extension's name
|
|
293
|
+
* does not, as for an explicit slug, since connector tools are `mcp__<slug>__<tool>` and extension
|
|
294
|
+
* tools `plugin__<plugin>__<tool>` (a template's default slug is often its plugin's name: slack).
|
|
304
295
|
*/
|
|
305
296
|
private freeName;
|
|
306
297
|
private resolveSlug;
|
|
@@ -17,7 +17,6 @@ import { assertItemInstallable } from "../catalog/request-rules.js";
|
|
|
17
17
|
import { productName } from "../config/product-name.js";
|
|
18
18
|
import { ApiError } from "../errors.js";
|
|
19
19
|
import { PluginGuides, } from "../extensions/plugin-guides.js";
|
|
20
|
-
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
21
20
|
import { audit } from "../identity/audit.js";
|
|
22
21
|
import { assertCustomAllowed } from "../identity/settings.js";
|
|
23
22
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
@@ -116,7 +115,6 @@ const unannotated = (a) => a?.readOnlyHint === undefined && a?.destructiveHint =
|
|
|
116
115
|
let ConnectorsService = class ConnectorsService {
|
|
117
116
|
kdb;
|
|
118
117
|
registry;
|
|
119
|
-
extensions;
|
|
120
118
|
credentials;
|
|
121
119
|
config;
|
|
122
120
|
drift;
|
|
@@ -125,12 +123,7 @@ let ConnectorsService = class ConnectorsService {
|
|
|
125
123
|
locks;
|
|
126
124
|
txHost;
|
|
127
125
|
guides;
|
|
128
|
-
constructor(kdb, registry,
|
|
129
|
-
/**
|
|
130
|
-
* Extension manifests: a derived default slug avoids an extension's name (an explicit slug may
|
|
131
|
-
* take one; connector and extension tool keys live in separate namespaces).
|
|
132
|
-
*/
|
|
133
|
-
extensions, credentials, config, drift,
|
|
126
|
+
constructor(kdb, registry, credentials, config, drift,
|
|
134
127
|
/** The org row lock (orgs/org-lock.ts): joins the caller's transaction. */
|
|
135
128
|
orgLock,
|
|
136
129
|
/** Owed work: the tool listings that follow a deferred create or a setup (§5.2.1). */
|
|
@@ -141,7 +134,6 @@ let ConnectorsService = class ConnectorsService {
|
|
|
141
134
|
guides) {
|
|
142
135
|
this.kdb = kdb;
|
|
143
136
|
this.registry = registry;
|
|
144
|
-
this.extensions = extensions;
|
|
145
137
|
this.credentials = credentials;
|
|
146
138
|
this.config = config;
|
|
147
139
|
this.drift = drift;
|
|
@@ -189,7 +181,9 @@ let ConnectorsService = class ConnectorsService {
|
|
|
189
181
|
}
|
|
190
182
|
/**
|
|
191
183
|
* The first free default name and slug ({@link CreateConnectorInput.slugDefault}), read in the
|
|
192
|
-
* caller's transaction under the org lock.
|
|
184
|
+
* caller's transaction under the org lock. Only live connectors hold a slug: an extension's name
|
|
185
|
+
* does not, as for an explicit slug, since connector tools are `mcp__<slug>__<tool>` and extension
|
|
186
|
+
* tools `plugin__<plugin>__<tool>` (a template's default slug is often its plugin's name: slack).
|
|
193
187
|
*/
|
|
194
188
|
async freeName(t, orgId, d) {
|
|
195
189
|
const base = deriveSlug(d.name ?? d.display) ?? deriveSlug(d.display);
|
|
@@ -202,8 +196,6 @@ let ConnectorsService = class ConnectorsService {
|
|
|
202
196
|
.where("org_id", "=", orgId)
|
|
203
197
|
.where("deleted_at", "is", null)
|
|
204
198
|
.execute()).map((r) => r.slug));
|
|
205
|
-
for (const m of this.extensions.manifests())
|
|
206
|
-
taken.add(m.name);
|
|
207
199
|
for (let n = 1;; n++) {
|
|
208
200
|
const suffix = n === 1 ? "" : `_${n}`;
|
|
209
201
|
const slug = `${base.slice(0, 24 - suffix.length).replace(/_+$/, "")}${suffix}`;
|
|
@@ -1987,14 +1979,13 @@ ConnectorsService = __decorate([
|
|
|
1987
1979
|
Injectable(),
|
|
1988
1980
|
__param(0, Inject(KernelDb)),
|
|
1989
1981
|
__param(1, Inject(ToolRegistry)),
|
|
1990
|
-
__param(2, Inject(
|
|
1991
|
-
__param(3, Inject(
|
|
1992
|
-
__param(4, Inject(
|
|
1993
|
-
__param(5, Inject(
|
|
1994
|
-
__param(6, Inject(
|
|
1995
|
-
__param(7, Inject(
|
|
1996
|
-
__param(8, Inject(
|
|
1997
|
-
__param(9, Inject(
|
|
1998
|
-
__param(10, Inject(PluginGuides))
|
|
1982
|
+
__param(2, Inject(Credentials)),
|
|
1983
|
+
__param(3, Inject(KernelConfigService)),
|
|
1984
|
+
__param(4, Inject(ToolDrift)),
|
|
1985
|
+
__param(5, Inject(OrgLock)),
|
|
1986
|
+
__param(6, Inject(OutboxService)),
|
|
1987
|
+
__param(7, Inject(LockService)),
|
|
1988
|
+
__param(8, Inject(TransactionHost)),
|
|
1989
|
+
__param(9, Inject(PluginGuides))
|
|
1999
1990
|
], ConnectorsService);
|
|
2000
1991
|
export { ConnectorsService };
|
package/dist/tools/git-asks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { gitPushGrantKey, normalizeGitRepo } from "../automations/grant-rules.js";
|
|
1
2
|
import { GIT_ASK_MAX_REFS, GIT_REF_MAX_CHARS } from "../conversations/events.js";
|
|
2
|
-
import { gitPushGrantKey, normalizeGitRepo } from "../schedules/grant-rules.js";
|
|
3
3
|
import { GIT_ASK_CANCELLED_NOTE } from "./approvals.service.js";
|
|
4
4
|
import { clipKeptWith } from "./network-asks.js";
|
|
5
5
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type UnattendedRun } from "../automations/unattended.js";
|
|
1
2
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
2
3
|
import type { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
3
|
-
import { type UnattendedRun } from "../schedules/unattended.js";
|
|
4
4
|
import { type GitRunState } from "./git-asks.js";
|
|
5
5
|
import type { ToolPolicy } from "./registry.js";
|
|
6
6
|
/** Why {@link decideGitPush} decided as it did. */
|
|
@@ -11,7 +11,7 @@ export type GitPushReason =
|
|
|
11
11
|
| "member_allow"
|
|
12
12
|
/** An approved 「这次允许」 of the run tree for the repository. */
|
|
13
13
|
| "run_grant"
|
|
14
|
-
/** The
|
|
14
|
+
/** The automation's `git:push` / `git:push:<owner>/<repo>` grant (unattended run). */
|
|
15
15
|
| "task_grant"
|
|
16
16
|
/** The policy asks the actor. */
|
|
17
17
|
| "ask"
|
|
@@ -55,7 +55,7 @@ export interface GitPushInput {
|
|
|
55
55
|
/** `<owner>/<repo>` (a trailing `.git` and case are normalized here). */
|
|
56
56
|
repo: string;
|
|
57
57
|
/**
|
|
58
|
-
* The
|
|
58
|
+
* The automation context of the run, when the caller has it (`unattendedRunOf`); undefined:
|
|
59
59
|
* read here. Null: an attended run.
|
|
60
60
|
*/
|
|
61
61
|
unattended?: UnattendedRun | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { sql } from "kysely";
|
|
2
|
+
import { GIT_PUSH_GRANT, gitPushForbidden, gitPushGrantKey, normalizeGitRepo, } from "../automations/grant-rules.js";
|
|
3
|
+
import { unattendedRules, unattendedRunOf } from "../automations/unattended.js";
|
|
2
4
|
import { budgetRunOf } from "../runtime/subagents/limits.js";
|
|
3
|
-
import { GIT_PUSH_GRANT, gitPushForbidden, gitPushGrantKey, normalizeGitRepo, } from "../schedules/grant-rules.js";
|
|
4
|
-
import { unattendedRules, unattendedRunOf } from "../schedules/unattended.js";
|
|
5
5
|
import { gitPushPolicyName, personalAuth } from "./connector-account-policies.js";
|
|
6
6
|
import { gitRepoKey } from "./git-asks.js";
|
|
7
7
|
import { connectorPolicy } from "./policy.js";
|
|
@@ -13,8 +13,8 @@ import { connectorPolicy } from "./policy.js";
|
|
|
13
13
|
* Storage (no new table): the org's default is `connectors.git_push_policy` (default `ask`); a
|
|
14
14
|
* member's standing allow (or deny) for one repository is their `connector_tool_account_policies`
|
|
15
15
|
* row `git_push:<host>/<owner>/<repo>` (a personal connector only: an org connector's push acts as the
|
|
16
|
-
* org); a run grant is an approved `once` git ask of the run tree;
|
|
17
|
-
* `git:push` and `git:push:<owner>/<repo>` in `
|
|
16
|
+
* org); a run grant is an approved `once` git ask of the run tree; an automation's grants are
|
|
17
|
+
* `git:push` and `git:push:<owner>/<repo>` in `automation_grants`.
|
|
18
18
|
*/
|
|
19
19
|
/** The statuses of a run that has not ended: its run grants still apply. */
|
|
20
20
|
const LIVE_RUN = ["queued", "running", "waiting"];
|
|
@@ -92,9 +92,9 @@ export async function decideGitPush(db, config, input) {
|
|
|
92
92
|
}
|
|
93
93
|
if (rules !== null) {
|
|
94
94
|
const granted = await db
|
|
95
|
-
.selectFrom("
|
|
95
|
+
.selectFrom("automation_grants")
|
|
96
96
|
.select("tool_key")
|
|
97
|
-
.where("
|
|
97
|
+
.where("automation_id", "=", rules.taskId)
|
|
98
98
|
.where("tool_key", "in", [GIT_PUSH_GRANT, key])
|
|
99
99
|
.executeTakeFirst();
|
|
100
100
|
if (granted !== undefined)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type NetworkBlockedHost } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { type UnattendedRun } from "../automations/unattended.js";
|
|
2
3
|
import type { NetworkRunState } from "../sandbox/network-grants.js";
|
|
3
|
-
import { type UnattendedRun } from "../schedules/unattended.js";
|
|
4
4
|
import { type ApprovalRecord, type NetworkAppliesAt } from "./approvals.service.js";
|
|
5
5
|
/**
|
|
6
6
|
* Network asks in the tool pipeline (network ask-to-allow spec §6.2, §6.6–§6.9, §8.3): what a
|
|
@@ -154,7 +154,7 @@ export interface NetworkPlanContext {
|
|
|
154
154
|
* is never asked about.
|
|
155
155
|
*/
|
|
156
156
|
offer?: (hosts: string[]) => NetworkAskOffer | null;
|
|
157
|
-
/** The
|
|
157
|
+
/** The automation run the run serves (null / undefined: attended). */
|
|
158
158
|
unattended: UnattendedRun | null | undefined;
|
|
159
159
|
/**
|
|
160
160
|
* Whether a host is beyond the platform's ceiling (`sandbox.limits.orgHosts: within`, org egress
|
|
@@ -245,7 +245,7 @@ export declare function blockedEventHosts(blocked: readonly NetworkBlockedHost[]
|
|
|
245
245
|
* carried that list (`ctx.deviceBlocks`): a note saying so, never asked;
|
|
246
246
|
* - a `device` host the device's settings already allow (`ctx.onList`: not yet applied to the
|
|
247
247
|
* instance): a note saying when it applies, never asked again;
|
|
248
|
-
* - approved by the
|
|
248
|
+
* - approved by the automation the run serves (`run.taskGranted`) yet refused: a note that
|
|
249
249
|
* the device ignores the task's grants (never asked, never a missing grant);
|
|
250
250
|
* - refused earlier in the run tree: the denied note; an unattended run in `fail` mode: its note
|
|
251
251
|
* and a missing grant;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { validateAllowHost } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { networkGrantKey, unattendedFails, unattendedRules, } from "../automations/unattended.js";
|
|
2
3
|
import { NETWORK_ASK_MAX_HOSTS, NETWORK_HOST_MAX_CHARS } from "../conversations/events.js";
|
|
3
4
|
import { coversHost } from "../sandbox/modes.js";
|
|
4
5
|
import { ESCALATION_UNATTENDED_WHY } from "../sandbox/review/permission-candidate.js";
|
|
5
|
-
import { networkGrantKey, unattendedFails, unattendedRules, } from "../schedules/unattended.js";
|
|
6
6
|
import { NETWORK_ASK_CANCELLED_NOTE, networkAskHosts, } from "./approvals.service.js";
|
|
7
7
|
/**
|
|
8
8
|
* Network asks in the tool pipeline (network ask-to-allow spec §6.2, §6.6–§6.9, §8.3): what a
|
|
@@ -191,7 +191,7 @@ export const unavailableHostNote = (host, why) => `[network] ${host} was blocked
|
|
|
191
191
|
* provider did not apply the task's network grant. Not asked, not a missing grant: the device's
|
|
192
192
|
* owner adds the host to the device's network list on its page.
|
|
193
193
|
*/
|
|
194
|
-
export const taskGrantIgnoredNote = (hosts) => `${blockedLead(hosts)} The
|
|
194
|
+
export const taskGrantIgnoredNote = (hosts) => `${blockedLead(hosts)} The automation approves ${pron(hosts)}, but this device did not apply the task's network grant. The device owner can add ${pron(hosts)} to the device's network list on its page. Continue without ${pron(hosts)}.`;
|
|
195
195
|
/** An unattended run in `fail` mode (spec §8.3): no ask, the creator can add a task grant. */
|
|
196
196
|
export const unattendedNetworkNote = (hosts) => `[network] ${list(hosts)} ${one(hosts) ? "is" : "are"} blocked on this device and this scheduled run cannot ask for network access. The task's owner can add ${pron(hosts)} to the task's approved domains. Continue without ${pron(hosts)}.`;
|
|
197
197
|
/**
|
|
@@ -239,7 +239,7 @@ export function blockedEventHosts(blocked) {
|
|
|
239
239
|
* carried that list (`ctx.deviceBlocks`): a note saying so, never asked;
|
|
240
240
|
* - a `device` host the device's settings already allow (`ctx.onList`: not yet applied to the
|
|
241
241
|
* instance): a note saying when it applies, never asked again;
|
|
242
|
-
* - approved by the
|
|
242
|
+
* - approved by the automation the run serves (`run.taskGranted`) yet refused: a note that
|
|
243
243
|
* the device ignores the task's grants (never asked, never a missing grant);
|
|
244
244
|
* - refused earlier in the run tree: the denied note; an unattended run in `fail` mode: its note
|
|
245
245
|
* and a missing grant;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { Redis } from "ioredis";
|
|
3
|
+
import { type HandoffRecord } from "../../handoff/handoff-paths.js";
|
|
3
4
|
import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
|
|
4
5
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
5
6
|
import { TransactionHost } from "../../infra/database/transaction-host.js";
|
|
@@ -36,8 +37,21 @@ export declare class OAuthFlow {
|
|
|
36
37
|
/** 某成员首次成功连接、而连接器还没有工具快照时(A16:用该成员的 token 刷新工具清单)。 */
|
|
37
38
|
private onFirstConnect;
|
|
38
39
|
private app;
|
|
39
|
-
/**
|
|
40
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Every check {@link start} makes before it writes the state: `http.publicUrl` is set, the
|
|
42
|
+
* connector exists, is an active `oauth_code` connector and has a client with an authorization
|
|
43
|
+
* endpoint (a dcr connector created without a client registers it now, once across replicas,
|
|
44
|
+
* R16). A browser handoff start runs it so a connector that cannot be connected fails in the app,
|
|
45
|
+
* not after the person signed in in the browser.
|
|
46
|
+
*/
|
|
47
|
+
check(orgId: string, connectorId: string, accountId: string): Promise<void>;
|
|
48
|
+
private prepare;
|
|
49
|
+
/**
|
|
50
|
+
* Builds the authorization URL. `binding` is this browser's binding value (the controller writes
|
|
51
|
+
* the cookie). With `handoff` (a browser handoff redeemed in this browser), the state's return
|
|
52
|
+
* page is the handoff done page built from the ticket's record, and `returnTo` is ignored.
|
|
53
|
+
*/
|
|
54
|
+
start(orgId: string, connectorId: string, accountId: string, returnTo: string | undefined, binding: string, handoff?: HandoffRecord): Promise<{
|
|
41
55
|
authorizationUrl: string;
|
|
42
56
|
}>;
|
|
43
57
|
/** 回跳地址:`http.publicUrl` + 站内路径 + 结果参数(未配置 publicUrl 时为相对地址)。 */
|
package/dist/tools/oauth/flow.js
CHANGED
|
@@ -10,6 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { createHash, randomBytes } from "node:crypto";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { ApiError } from "../../errors.js";
|
|
13
|
+
import { handoffDonePath } from "../../handoff/handoff-paths.js";
|
|
13
14
|
import { audit } from "../../identity/audit.js";
|
|
14
15
|
import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
|
|
15
16
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
@@ -77,8 +78,17 @@ let OAuthFlow = class OAuthFlow {
|
|
|
77
78
|
.where("deleted_at", "is", null)
|
|
78
79
|
.executeTakeFirst();
|
|
79
80
|
}
|
|
80
|
-
/**
|
|
81
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Every check {@link start} makes before it writes the state: `http.publicUrl` is set, the
|
|
83
|
+
* connector exists, is an active `oauth_code` connector and has a client with an authorization
|
|
84
|
+
* endpoint (a dcr connector created without a client registers it now, once across replicas,
|
|
85
|
+
* R16). A browser handoff start runs it so a connector that cannot be connected fails in the app,
|
|
86
|
+
* not after the person signed in in the browser.
|
|
87
|
+
*/
|
|
88
|
+
async check(orgId, connectorId, accountId) {
|
|
89
|
+
await this.prepare(orgId, connectorId, accountId);
|
|
90
|
+
}
|
|
91
|
+
async prepare(orgId, connectorId, accountId) {
|
|
82
92
|
const publicUrl = this.config.get().http.publicUrl;
|
|
83
93
|
if (!publicUrl)
|
|
84
94
|
throw publicUrlRequired();
|
|
@@ -103,6 +113,15 @@ let OAuthFlow = class OAuthFlow {
|
|
|
103
113
|
if (!client?.authorizationEndpoint) {
|
|
104
114
|
throw new ApiError("connector.connect_failed", "This connector needs to be configured by an organization admin before members can connect it.");
|
|
105
115
|
}
|
|
116
|
+
return { publicUrl, app, client, authorizationEndpoint: client.authorizationEndpoint };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Builds the authorization URL. `binding` is this browser's binding value (the controller writes
|
|
120
|
+
* the cookie). With `handoff` (a browser handoff redeemed in this browser), the state's return
|
|
121
|
+
* page is the handoff done page built from the ticket's record, and `returnTo` is ignored.
|
|
122
|
+
*/
|
|
123
|
+
async start(orgId, connectorId, accountId, returnTo, binding, handoff) {
|
|
124
|
+
const { publicUrl, app, client, authorizationEndpoint } = await this.prepare(orgId, connectorId, accountId);
|
|
106
125
|
const state = b64url();
|
|
107
126
|
const verifier = b64url();
|
|
108
127
|
const redirectUri = callbackUrl(publicUrl);
|
|
@@ -112,12 +131,12 @@ let OAuthFlow = class OAuthFlow {
|
|
|
112
131
|
accountId,
|
|
113
132
|
verifier,
|
|
114
133
|
redirectUri,
|
|
115
|
-
returnTo: returnTo ?? DEFAULT_RETURN_PATH,
|
|
134
|
+
returnTo: handoff !== undefined ? handoffDonePath(handoff) : (returnTo ?? DEFAULT_RETURN_PATH),
|
|
116
135
|
binding: sha256(binding),
|
|
117
136
|
...(client.issuer !== undefined && { issuer: client.issuer }),
|
|
118
137
|
};
|
|
119
138
|
await this.redis.set(stateKey(state), JSON.stringify(rec), "EX", OAUTH_STATE_TTL_SECONDS);
|
|
120
|
-
const url = new URL(
|
|
139
|
+
const url = new URL(authorizationEndpoint);
|
|
121
140
|
url.searchParams.set("response_type", "code");
|
|
122
141
|
url.searchParams.set("client_id", client.clientId);
|
|
123
142
|
url.searchParams.set("redirect_uri", redirectUri);
|
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
2
|
import type { z } from "zod";
|
|
3
|
+
import { HandoffTickets } from "../../handoff/handoff-tickets.js";
|
|
3
4
|
import { type Principal } from "../../identity/principal.js";
|
|
4
5
|
import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
|
|
5
6
|
import { type OrgContext } from "../../orgs/org.guard.js";
|
|
6
7
|
import { OAuthFlow } from "./flow.js";
|
|
7
|
-
import { OAuthConnectBodySchema } from "./oauth.schemas.js";
|
|
8
|
+
import { OAuthConnectBodySchema, type OAuthConnectResponse } from "./oauth.schemas.js";
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
10
|
+
* Writes the OAuth browser binding cookie `cap_oauth` (HttpOnly, SameSite=Lax: the authorization
|
|
11
|
+
* server's redirect back is a cross-site top-level GET, which Lax sends; Path only the callback).
|
|
12
|
+
*/
|
|
13
|
+
export declare function setOAuthBindingCookie(reply: FastifyReply, binding: string, config: {
|
|
14
|
+
auth: {
|
|
15
|
+
cookieSecure: boolean;
|
|
16
|
+
};
|
|
17
|
+
}): void;
|
|
18
|
+
/**
|
|
19
|
+
* Starts an OAuth connection (`POST /orgs/:orgId/connectors/:connectorId/connect`,
|
|
20
|
+
* `connectors.use`, user principals only): returns the authorization URL and writes the browser
|
|
21
|
+
* binding cookie ({@link setOAuthBindingCookie}). With `handoff` (a native shell, shell external
|
|
22
|
+
* authorization spec §1): the same checks, then a handoff ticket and its web page instead, with
|
|
23
|
+
* no cookie and no OAuth state; the flow starts when the person redeems it in the system browser.
|
|
11
24
|
*/
|
|
12
25
|
export declare class OAuthConnectController {
|
|
13
26
|
private readonly flow;
|
|
14
27
|
private readonly config;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}>;
|
|
28
|
+
private readonly tickets;
|
|
29
|
+
constructor(flow: OAuthFlow, config: KernelConfigService, tickets: HandoffTickets);
|
|
30
|
+
connect(principal: Principal, org: OrgContext, connectorId: string, body: z.infer<typeof OAuthConnectBodySchema>, req: FastifyRequest, reply: FastifyReply): Promise<OAuthConnectResponse>;
|
|
19
31
|
}
|
|
20
32
|
/**
|
|
21
33
|
* 授权服务器的回跳(`GET /api/v1/oauth/callback`,公开路由:浏览器从授权服务器跳回来,会话 Cookie 可能已过期;
|
|
@@ -8,39 +8,68 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { Controller, Get, HttpCode, Inject, Param, Post, Query, Req, Res } from "@nestjs/common";
|
|
11
|
+
import { assertReturnSchemeAllowed } from "../../handoff/app-schemes.js";
|
|
12
|
+
import { HandoffTickets } from "../../handoff/handoff-tickets.js";
|
|
11
13
|
import { CurrentPrincipal, Public, requireUser } from "../../identity/principal.js";
|
|
12
14
|
import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
|
|
13
15
|
import { createZodDto } from "../../infra/validation/create-zod-dto.js";
|
|
14
16
|
import { ZBody } from "../../infra/validation/zod-params.js";
|
|
15
17
|
import { CurrentOrg, OrgAction } from "../../orgs/org.guard.js";
|
|
16
|
-
import { browserBinding, OAUTH_BINDING_COOKIE, OAUTH_CALLBACK_PATH, OAUTH_STATE_TTL_SECONDS, OAuthFlow, } from "./flow.js";
|
|
18
|
+
import { browserBinding, DEFAULT_RETURN_PATH, OAUTH_BINDING_COOKIE, OAUTH_CALLBACK_PATH, OAUTH_STATE_TTL_SECONDS, OAuthFlow, } from "./flow.js";
|
|
17
19
|
import { OAuthConnectBodySchema } from "./oauth.schemas.js";
|
|
18
20
|
class OAuthConnectBody extends createZodDto(OAuthConnectBodySchema, "OAuthConnectBody") {
|
|
19
21
|
}
|
|
20
22
|
/** 查询参数只取单值字符串(重复参数 / 数组按缺失处理)。 */
|
|
21
23
|
const one = (v) => typeof v === "string" && v.length <= 4096 ? v : undefined;
|
|
22
24
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
+
* Writes the OAuth browser binding cookie `cap_oauth` (HttpOnly, SameSite=Lax: the authorization
|
|
26
|
+
* server's redirect back is a cross-site top-level GET, which Lax sends; Path only the callback).
|
|
27
|
+
*/
|
|
28
|
+
export function setOAuthBindingCookie(reply, binding, config) {
|
|
29
|
+
reply.setCookie(OAUTH_BINDING_COOKIE, binding, {
|
|
30
|
+
path: OAUTH_CALLBACK_PATH,
|
|
31
|
+
httpOnly: true,
|
|
32
|
+
sameSite: "lax",
|
|
33
|
+
secure: config.auth.cookieSecure,
|
|
34
|
+
maxAge: OAUTH_STATE_TTL_SECONDS,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Starts an OAuth connection (`POST /orgs/:orgId/connectors/:connectorId/connect`,
|
|
39
|
+
* `connectors.use`, user principals only): returns the authorization URL and writes the browser
|
|
40
|
+
* binding cookie ({@link setOAuthBindingCookie}). With `handoff` (a native shell, shell external
|
|
41
|
+
* authorization spec §1): the same checks, then a handoff ticket and its web page instead, with
|
|
42
|
+
* no cookie and no OAuth state; the flow starts when the person redeems it in the system browser.
|
|
25
43
|
*/
|
|
26
44
|
let OAuthConnectController = class OAuthConnectController {
|
|
27
45
|
flow;
|
|
28
46
|
config;
|
|
29
|
-
|
|
47
|
+
tickets;
|
|
48
|
+
constructor(flow, config, tickets) {
|
|
30
49
|
this.flow = flow;
|
|
31
50
|
this.config = config;
|
|
51
|
+
this.tickets = tickets;
|
|
32
52
|
}
|
|
33
53
|
async connect(principal, org, connectorId, body, req, reply) {
|
|
34
54
|
const p = requireUser(principal);
|
|
55
|
+
if (body.handoff !== undefined) {
|
|
56
|
+
const returnScheme = body.handoff.returnScheme;
|
|
57
|
+
assertReturnSchemeAllowed(this.config.get(), returnScheme);
|
|
58
|
+
await this.flow.check(org.orgId, connectorId, p.account.id);
|
|
59
|
+
const ticket = await this.tickets.create({
|
|
60
|
+
kind: "connector",
|
|
61
|
+
accountId: p.account.id,
|
|
62
|
+
orgId: org.orgId,
|
|
63
|
+
connectorId,
|
|
64
|
+
returnTo: body.returnTo ?? DEFAULT_RETURN_PATH,
|
|
65
|
+
...(returnScheme !== undefined && { returnScheme }),
|
|
66
|
+
});
|
|
67
|
+
reply.header("cache-control", "no-store");
|
|
68
|
+
return { handoffUrl: this.tickets.url(ticket) };
|
|
69
|
+
}
|
|
35
70
|
const binding = browserBinding(req.cookies[OAUTH_BINDING_COOKIE]);
|
|
36
71
|
const out = await this.flow.start(org.orgId, connectorId, p.account.id, body.returnTo, binding);
|
|
37
|
-
reply
|
|
38
|
-
path: OAUTH_CALLBACK_PATH,
|
|
39
|
-
httpOnly: true,
|
|
40
|
-
sameSite: "lax",
|
|
41
|
-
secure: this.config.get().auth.cookieSecure,
|
|
42
|
-
maxAge: OAUTH_STATE_TTL_SECONDS,
|
|
43
|
-
});
|
|
72
|
+
setOAuthBindingCookie(reply, binding, this.config.get());
|
|
44
73
|
return out;
|
|
45
74
|
}
|
|
46
75
|
};
|
|
@@ -58,7 +87,8 @@ __decorate([
|
|
|
58
87
|
OAuthConnectController = __decorate([
|
|
59
88
|
Controller("api/v1/orgs/:orgId/connectors"),
|
|
60
89
|
__param(0, Inject(OAuthFlow)),
|
|
61
|
-
__param(1, Inject(KernelConfigService))
|
|
90
|
+
__param(1, Inject(KernelConfigService)),
|
|
91
|
+
__param(2, Inject(HandoffTickets))
|
|
62
92
|
], OAuthConnectController);
|
|
63
93
|
export { OAuthConnectController };
|
|
64
94
|
/**
|
|
@@ -2,11 +2,24 @@ import { z } from "zod";
|
|
|
2
2
|
import type { RouteSchemas } from "../../platform/route-schemas.js";
|
|
3
3
|
/**
|
|
4
4
|
* `POST …/connectors/:connectorId/connect`: where the browser returns after the authorization (a
|
|
5
|
-
* relative path on this site; default the connections page).
|
|
5
|
+
* relative path on this site; default the connections page). `handoff` (a native shell): finish
|
|
6
|
+
* the authorization in the system browser through a handoff ticket instead.
|
|
6
7
|
*/
|
|
7
8
|
export declare const OAuthConnectBodySchema: z.ZodObject<{
|
|
8
9
|
returnTo: z.ZodOptional<z.ZodString>;
|
|
10
|
+
handoff: z.ZodOptional<z.ZodObject<{
|
|
11
|
+
returnScheme: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, z.core.$strict>>;
|
|
9
13
|
}, z.core.$strict>;
|
|
14
|
+
/**
|
|
15
|
+
* The connect route's answer: the authorization URL (the binding cookie is set on this browser),
|
|
16
|
+
* or with `handoff` the web page that starts it in the system browser (no cookie, no state).
|
|
17
|
+
*/
|
|
18
|
+
export type OAuthConnectResponse = {
|
|
19
|
+
authorizationUrl: string;
|
|
20
|
+
} | {
|
|
21
|
+
handoffUrl: string;
|
|
22
|
+
};
|
|
10
23
|
/**
|
|
11
24
|
* The connect route's schemas for the Platform parity check (`connectors.connect` mirrors it; the
|
|
12
25
|
* OAuth callback stays an exclusion).
|