@capybara-hq/kernel 0.1.0-rc.104 → 0.1.0-rc.105
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/catalog/marketplaces.service.d.ts +1 -1
- package/dist/conversations/conversations.service.d.ts +2 -0
- package/dist/conversations/conversations.service.js +6 -1
- package/dist/conversations/events.d.ts +2 -1
- package/dist/conversations/events.js +7 -6
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +13 -0
- 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 +8 -0
- package/dist/http/meta.controller.d.ts +1 -0
- package/dist/http/meta.controller.js +7 -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/overrides.d.ts +4 -4
- package/dist/overrides.js +1 -1
- package/dist/platform/exclusions.js +5 -0
- package/dist/platform/ops/connectors.ops.js +4 -2
- package/dist/runtime/compaction.service.d.ts +3 -1
- package/dist/runtime/compaction.service.js +3 -1
- package/dist/runtime/context/compaction.d.ts +27 -1
- package/dist/runtime/context/compaction.js +87 -32
- 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/tools/connectors.service.d.ts +4 -13
- package/dist/tools/connectors.service.js +12 -21
- 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/package.json +3 -3
|
@@ -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).
|
|
@@ -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/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.105",
|
|
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.84"
|
|
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.46"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"build": "tsc -b"
|