@capybara-hq/kernel 0.1.0-rc.65 → 0.1.0-rc.66
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/attribution/platform-attribution.d.ts +15 -6
- package/dist/attribution/platform-attribution.js +31 -14
- package/dist/catalog/catalog-content.d.ts +6 -3
- package/dist/catalog/catalog-content.js +7 -8
- package/dist/catalog/claude/translate.js +1 -1
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/marketplaces.service.js +2 -1
- package/dist/catalog/plugin-package.d.ts +3 -2
- package/dist/channels/file-delivery.d.ts +2 -0
- package/dist/channels/file-delivery.js +1 -1
- package/dist/channels/inbound.d.ts +6 -1
- package/dist/channels/inbound.js +12 -4
- package/dist/channels/outbound.js +11 -5
- package/dist/channels/phrases.d.ts +18 -10
- package/dist/channels/phrases.js +18 -11
- package/dist/client/client-files.js +1 -1
- package/dist/config/product-name.d.ts +8 -0
- package/dist/config/product-name.js +9 -0
- package/dist/config/schema.js +3 -3
- package/dist/conversations/conversations.service.js +11 -0
- package/dist/git/gateway.d.ts +9 -0
- package/dist/git/gateway.js +36 -17
- package/dist/git/gateway.route.d.ts +1 -1
- package/dist/git/gateway.route.js +1 -3
- package/dist/http/app.d.ts +1 -1
- package/dist/identity/app-auth.d.ts +4 -3
- package/dist/identity/app-auth.js +7 -8
- package/dist/identity/settings.js +6 -2
- package/dist/identity/sso.d.ts +13 -7
- package/dist/identity/sso.js +21 -7
- package/dist/infra/config/kernel-config.service.js +1 -1
- package/dist/local-devices/device-routes.js +1 -1
- package/dist/orgs/offboarding.js +9 -0
- package/dist/platform/ops/platform-icons.ops.js +4 -4
- package/dist/platform/ops/platform.ops.js +2 -1
- package/dist/platform/ops/themes.ops.js +1 -1
- package/dist/sandbox/review/classifier.d.ts +6 -0
- package/dist/sandbox/review/classifier.js +12 -1
- package/dist/sandbox/review/index.d.ts +1 -1
- package/dist/sandbox/review/index.js +1 -1
- package/dist/themes/platform-icon.service.js +1 -1
- package/dist/themes/theme-delivery.service.d.ts +10 -2
- package/dist/themes/theme-delivery.service.js +26 -11
- package/dist/themes/theme-state.d.ts +14 -1
- package/dist/themes/theme-state.js +22 -4
- package/dist/themes/themes-public.controller.d.ts +3 -3
- package/dist/themes/themes-public.controller.js +3 -3
- package/dist/tools/builtins/platform.js +25 -17
- package/dist/tools/builtins/sandbox/common.d.ts +1 -1
- package/dist/tools/builtins/sandbox/common.js +1 -1
- package/dist/tools/connectors.service.js +2 -1
- package/dist/tools/oauth/discovery.d.ts +2 -0
- package/dist/tools/oauth/discovery.js +3 -1
- package/package.json +4 -4
package/dist/git/gateway.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
2
|
import type { Redis } from "ioredis";
|
|
3
|
+
import type { KernelConfig } from "../config/schema.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 type { KernelLogger } from "../log.js";
|
|
@@ -69,6 +70,8 @@ export declare class GitGateway {
|
|
|
69
70
|
constructor(tickets: Pick<GitTickets, "resolve">, sources: Pick<GitSources, "sourcesFor">, credentials: Pick<Credentials, "gitAuthorization" | "gitUnauthorized">, db: KernelDb, redis: Redis,
|
|
70
71
|
/** Read per request: `tools.git.*` is read live. */
|
|
71
72
|
config: Pick<KernelConfigService, "get">, log: Pick<KernelLogger, "info" | "warn" | "debug">, upstreamOrigin?: GitUpstreamOrigin | undefined);
|
|
73
|
+
/** `message` as git prints it from this gateway: with the platform name before it. */
|
|
74
|
+
says(message: string): string;
|
|
72
75
|
/** Handles one gateway request (the raw route's handler). */
|
|
73
76
|
handle(req: FastifyRequest, reply: FastifyReply): Promise<void>;
|
|
74
77
|
/** The `git.push` audit row of a receive-pack and the run's fetch counters (best effort). */
|
|
@@ -91,3 +94,9 @@ export declare class GitGateway {
|
|
|
91
94
|
/** The connector's auth (it may have changed since the source was chosen); null when gone. */
|
|
92
95
|
private connectorAuth;
|
|
93
96
|
}
|
|
97
|
+
/** The note a refused push carries (the model reads it in the command's output). */
|
|
98
|
+
/**
|
|
99
|
+
* How the gateway prefixes what git prints (`remote: <platform.name>: …`), so a person reading the
|
|
100
|
+
* output of git knows which side refused.
|
|
101
|
+
*/
|
|
102
|
+
export declare function gitSays(config: Pick<KernelConfig, "platform">): (message: string) => string;
|
package/dist/git/gateway.js
CHANGED
|
@@ -10,6 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Readable, Transform } from "node:stream";
|
|
11
11
|
import { pipeline } from "node:stream/promises";
|
|
12
12
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
13
|
+
import { productName } from "../config/product-name.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";
|
|
@@ -143,15 +144,19 @@ const BYTES_TTL_SECONDS = 24 * 60 * 60;
|
|
|
143
144
|
const CONCURRENCY_TTL_SECONDS = 15 * 60;
|
|
144
145
|
/** Bytes counted locally before they are added to the Redis counter. */
|
|
145
146
|
const BYTES_FLUSH = 256 * 1024;
|
|
146
|
-
/**
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
const
|
|
154
|
-
const
|
|
147
|
+
/**
|
|
148
|
+
* Texts git prints (`remote: …`); every answer prefixes them with the platform name
|
|
149
|
+
* (`<platform.name>: …`, read per request: the field is hot).
|
|
150
|
+
*/
|
|
151
|
+
const TICKET_REFUSED = "the git ticket is not valid (expired, revoked, or the task has ended). Run the command again from the agent's task.";
|
|
152
|
+
const TOO_MANY = "too many git transfers are running in this organization; try again shortly.";
|
|
153
|
+
const BYTES_EXCEEDED = "this task reached its git transfer limit (tools.git.maxBytesPerRun).";
|
|
154
|
+
const NOT_AN_ENDPOINT = "not a git smart-HTTP endpoint.";
|
|
155
|
+
const reconnect = (host) => `${host} refused the connection's credential. Reconnect it under Settings → Connectors, then run the command again.`;
|
|
156
|
+
const repoRefused = (repo) => `this task may not use the repository ${repo}.`;
|
|
157
|
+
const upstreamFailed = (host, detail) => `the request to ${host} failed (${detail}).`;
|
|
158
|
+
const BAD_PUSH = (why) => `the push could not be read (${why}).`;
|
|
159
|
+
const notConnected = (host) => `you have no connection that can reach ${host}. Connect one under Settings → Connectors, then run the command again.`;
|
|
155
160
|
/** The bytes of one request, added to the run's Redis counter in batches. */
|
|
156
161
|
class ByteMeter {
|
|
157
162
|
redis;
|
|
@@ -282,6 +287,10 @@ let GitGateway = class GitGateway {
|
|
|
282
287
|
this.log = log;
|
|
283
288
|
this.upstreamOrigin = upstreamOrigin;
|
|
284
289
|
}
|
|
290
|
+
/** `message` as git prints it from this gateway: with the platform name before it. */
|
|
291
|
+
says(message) {
|
|
292
|
+
return gitSays(this.config.get())(message);
|
|
293
|
+
}
|
|
285
294
|
/** Handles one gateway request (the raw route's handler). */
|
|
286
295
|
async handle(req, reply) {
|
|
287
296
|
const started = performance.now();
|
|
@@ -289,6 +298,7 @@ let GitGateway = class GitGateway {
|
|
|
289
298
|
const body = req.body instanceof Readable ? req.body : undefined;
|
|
290
299
|
// a refusal closes the connection and stops reading the body: nothing unauthenticated or
|
|
291
300
|
// refused is read further, and nothing it sends is left unbounded
|
|
301
|
+
const said = gitSays(this.config.get());
|
|
292
302
|
const text = (status, message) => {
|
|
293
303
|
fields.status = status;
|
|
294
304
|
if (body !== undefined)
|
|
@@ -298,14 +308,14 @@ let GitGateway = class GitGateway {
|
|
|
298
308
|
.header("content-type", "text/plain; charset=utf-8")
|
|
299
309
|
.header("cache-control", "no-cache")
|
|
300
310
|
.header("connection", "close")
|
|
301
|
-
.send(`${message}\n`);
|
|
311
|
+
.send(`${said(message)}\n`);
|
|
302
312
|
};
|
|
303
313
|
const target = parseGitGatewayPath(req.method, req.url);
|
|
304
314
|
const wrongBody = req.method === "POST"
|
|
305
315
|
? contentTypeOf(req) !== `application/x-${target?.service}-request`
|
|
306
316
|
: body !== undefined;
|
|
307
317
|
if (target === null || wrongBody) {
|
|
308
|
-
return text(404,
|
|
318
|
+
return text(404, NOT_AN_ENDPOINT);
|
|
309
319
|
}
|
|
310
320
|
fields.host = target.host;
|
|
311
321
|
fields.repo = target.repo;
|
|
@@ -318,7 +328,7 @@ let GitGateway = class GitGateway {
|
|
|
318
328
|
if (binding === null)
|
|
319
329
|
return this.done(text(403, TICKET_REFUSED), fields, started);
|
|
320
330
|
if (!binding.hosts.map((h) => h.toLowerCase()).includes(target.host)) {
|
|
321
|
-
return this.done(text(404,
|
|
331
|
+
return this.done(text(404, NOT_AN_ENDPOINT), fields, started);
|
|
322
332
|
}
|
|
323
333
|
if (!repoAllowed(binding.repos, target.repo)) {
|
|
324
334
|
return this.done(text(403, repoRefused(target.repo)), fields, started);
|
|
@@ -327,7 +337,7 @@ let GitGateway = class GitGateway {
|
|
|
327
337
|
const source = (await this.sources.sourcesFor(binding.orgId, binding.accountId)).find((s) => s.host === target.host);
|
|
328
338
|
if (source === undefined) {
|
|
329
339
|
const message = target.service === "git-receive-pack"
|
|
330
|
-
?
|
|
340
|
+
? gitNotConnectedNote(target.host)
|
|
331
341
|
: notConnected(target.host);
|
|
332
342
|
return this.done(text(403, message), fields, started);
|
|
333
343
|
}
|
|
@@ -367,6 +377,7 @@ let GitGateway = class GitGateway {
|
|
|
367
377
|
body: metered,
|
|
368
378
|
fields,
|
|
369
379
|
text,
|
|
380
|
+
said,
|
|
370
381
|
transfer,
|
|
371
382
|
push,
|
|
372
383
|
});
|
|
@@ -472,7 +483,7 @@ let GitGateway = class GitGateway {
|
|
|
472
483
|
return result;
|
|
473
484
|
}
|
|
474
485
|
async relay(req, reply, c) {
|
|
475
|
-
const { target, binding, source, fields, text, transfer, push } = c;
|
|
486
|
+
const { target, binding, source, fields, text, said, transfer, push } = c;
|
|
476
487
|
/** Sets the audit result of a push that was read (a no-op for any other request). */
|
|
477
488
|
const pushResult = (r) => {
|
|
478
489
|
if (push.result !== undefined)
|
|
@@ -493,7 +504,7 @@ let GitGateway = class GitGateway {
|
|
|
493
504
|
.code(200)
|
|
494
505
|
.header("content-type", "application/x-git-receive-pack-advertisement")
|
|
495
506
|
.header("cache-control", "no-cache")
|
|
496
|
-
.send(advertisementError(
|
|
507
|
+
.send(advertisementError(said(refusalNote(target.repo, [], decision))));
|
|
497
508
|
return;
|
|
498
509
|
}
|
|
499
510
|
}
|
|
@@ -544,7 +555,7 @@ let GitGateway = class GitGateway {
|
|
|
544
555
|
.code(200)
|
|
545
556
|
.header("content-type", "application/x-git-receive-pack-result")
|
|
546
557
|
.header("cache-control", "no-cache")
|
|
547
|
-
.send(receivePackRefusal(parsed.capabilities, refs,
|
|
558
|
+
.send(receivePackRefusal(parsed.capabilities, refs, said(note), decision.decision === "ask" ? "needs approval" : "not allowed"));
|
|
548
559
|
return;
|
|
549
560
|
}
|
|
550
561
|
}
|
|
@@ -648,7 +659,7 @@ let GitGateway = class GitGateway {
|
|
|
648
659
|
if (res.status !== 200) {
|
|
649
660
|
await res.body?.cancel().catch(() => { });
|
|
650
661
|
if (res.status === 404 || res.status === 403) {
|
|
651
|
-
text(res.status,
|
|
662
|
+
text(res.status, `${target.host} answered ${res.status} for ${target.repo}.`);
|
|
652
663
|
}
|
|
653
664
|
else {
|
|
654
665
|
text(502, upstreamFailed(target.host, `status ${res.status}`));
|
|
@@ -741,6 +752,14 @@ const contentTypeOf = (req) => String(req.headers["content-type"] ?? "")
|
|
|
741
752
|
?.trim()
|
|
742
753
|
.toLowerCase() ?? "";
|
|
743
754
|
/** The note a refused push carries (the model reads it in the command's output). */
|
|
755
|
+
/**
|
|
756
|
+
* How the gateway prefixes what git prints (`remote: <platform.name>: …`), so a person reading the
|
|
757
|
+
* output of git knows which side refused.
|
|
758
|
+
*/
|
|
759
|
+
export function gitSays(config) {
|
|
760
|
+
const name = productName(config);
|
|
761
|
+
return (message) => `${name}: ${message}`;
|
|
762
|
+
}
|
|
744
763
|
function refusalNote(repo, refs, d) {
|
|
745
764
|
if (d.decision === "ask")
|
|
746
765
|
return gitAskedNote(repo);
|
|
@@ -13,4 +13,4 @@ export declare const GIT_GATEWAY_ROUTE = "/git/v1/*";
|
|
|
13
13
|
* gateway counts bytes against `tools.git.maxBytesPerRun`); any other type is refused by Fastify.
|
|
14
14
|
* HEAD and every other method answer 404. Registered by the api role; call before `app.init()`.
|
|
15
15
|
*/
|
|
16
|
-
export declare function registerGitGatewayRoute(fastify: FastifyInstance, gateway: Pick<GitGateway, "handle">, log: Pick<Logger, "error">): Promise<void>;
|
|
16
|
+
export declare function registerGitGatewayRoute(fastify: FastifyInstance, gateway: Pick<GitGateway, "handle" | "says">, log: Pick<Logger, "error">): Promise<void>;
|
|
@@ -27,9 +27,7 @@ export async function registerGitGatewayRoute(fastify, gateway, log) {
|
|
|
27
27
|
return reply
|
|
28
28
|
.code(status >= 400 && status < 500 ? 404 : 500)
|
|
29
29
|
.header("content-type", "text/plain; charset=utf-8")
|
|
30
|
-
.send(status >= 400 && status < 500
|
|
31
|
-
? "Capybara: not a git smart-HTTP endpoint.\n"
|
|
32
|
-
: "Capybara: internal error.\n");
|
|
30
|
+
.send(`${gateway.says(status >= 400 && status < 500 ? "not a git smart-HTTP endpoint." : "internal error.")}\n`);
|
|
33
31
|
});
|
|
34
32
|
scope.route({
|
|
35
33
|
method: ["GET", "POST"],
|
package/dist/http/app.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export interface CreateHttpAppOptions {
|
|
|
51
51
|
* The git gateway (`/git/v1/*`, a raw route outside Nest), registered only when given: the
|
|
52
52
|
* kernel passes it when `roles` includes `api`.
|
|
53
53
|
*/
|
|
54
|
-
git?: Pick<GitGateway, "handle">;
|
|
54
|
+
git?: Pick<GitGateway, "handle" | "says">;
|
|
55
55
|
/** 副本标识(`http.replicaId`):设置时每个响应带 `x-capybara-replica` 头。 */
|
|
56
56
|
replicaId?: string | undefined;
|
|
57
57
|
/**
|
|
@@ -31,10 +31,11 @@ export declare function buildRedirect(uri: string, params: Record<string, string
|
|
|
31
31
|
/** Whether `uri` is one of `allowed`, compared as exact strings (no prefix, no case folding). */
|
|
32
32
|
export declare function isAllowedRedirect(uri: string, allowed: readonly string[]): boolean;
|
|
33
33
|
/**
|
|
34
|
-
* The session user agent of an app session
|
|
35
|
-
* `
|
|
34
|
+
* The session user agent of an app session, named by the platform name `product`
|
|
35
|
+
* (`platform.name`): `<product> Desktop/<appVersion> (<name>)` or
|
|
36
|
+
* `<product> Mobile/<appVersion> (<name>)`.
|
|
36
37
|
*/
|
|
37
|
-
export declare const appUserAgent: (g: Pick<CodeGrant, "client" | "appVersion" | "name"
|
|
38
|
+
export declare const appUserAgent: (g: Pick<CodeGrant, "client" | "appVersion" | "name">, product: string) => string;
|
|
38
39
|
/**
|
|
39
40
|
* Native-app sign-in (desktop client spec §6.5, mobile spec §4.3): the authorization code flow with
|
|
40
41
|
* PKCE for native apps (RFC 8252, RFC 7636). The signed-in person consents on the web
|
|
@@ -10,6 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
|
+
import { productName } from "../config/product-name.js";
|
|
13
14
|
import { ApiError } from "../errors.js";
|
|
14
15
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
15
16
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -46,15 +47,13 @@ export function buildRedirect(uri, params) {
|
|
|
46
47
|
export function isAllowedRedirect(uri, allowed) {
|
|
47
48
|
return allowed.includes(uri);
|
|
48
49
|
}
|
|
49
|
-
const
|
|
50
|
-
desktop: "Capybara Desktop",
|
|
51
|
-
mobile: "Capybara Mobile",
|
|
52
|
-
};
|
|
50
|
+
const CLIENT_KIND = { desktop: "Desktop", mobile: "Mobile" };
|
|
53
51
|
/**
|
|
54
|
-
* The session user agent of an app session
|
|
55
|
-
* `
|
|
52
|
+
* The session user agent of an app session, named by the platform name `product`
|
|
53
|
+
* (`platform.name`): `<product> Desktop/<appVersion> (<name>)` or
|
|
54
|
+
* `<product> Mobile/<appVersion> (<name>)`.
|
|
56
55
|
*/
|
|
57
|
-
export const appUserAgent = (g) => `${
|
|
56
|
+
export const appUserAgent = (g, product) => `${product} ${CLIENT_KIND[g.client]}/${g.appVersion} (${g.name})`;
|
|
58
57
|
const codeInvalid = () => new ApiError("app_auth.code_invalid", "The sign-in code is invalid, already used or expired; start the sign-in from the app again");
|
|
59
58
|
/**
|
|
60
59
|
* Native-app sign-in (desktop client spec §6.5, mobile spec §4.3): the authorization code flow with
|
|
@@ -169,7 +168,7 @@ let AppAuthService = class AppAuthService {
|
|
|
169
168
|
if (!account)
|
|
170
169
|
throw codeInvalid();
|
|
171
170
|
const session = await this.sessions.create(grant.accountId, {
|
|
172
|
-
userAgent: appUserAgent(grant),
|
|
171
|
+
userAgent: appUserAgent(grant, productName(this.config.get())),
|
|
173
172
|
ip,
|
|
174
173
|
});
|
|
175
174
|
await audit(this.db.db, {
|
|
@@ -11,6 +11,7 @@ import { EXTENSION_NAME_RE } from "@capybara-hq/plugin-sdk";
|
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
import { applyPlatformAttributionPatch, PLATFORM_ATTRIBUTION_FIELDS, PLATFORM_ATTRIBUTION_PATCH, PLATFORM_ATTRIBUTION_SETTING, readStoredPlatformAttribution, resolvePlatformAttribution, } from "../attribution/platform-attribution.js";
|
|
14
|
+
import { productName } from "../config/product-name.js";
|
|
14
15
|
import { ApiError } from "../errors.js";
|
|
15
16
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
16
17
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -534,12 +535,15 @@ let SettingsService = class SettingsService {
|
|
|
534
535
|
};
|
|
535
536
|
}
|
|
536
537
|
attributionView(stored) {
|
|
537
|
-
const
|
|
538
|
+
const current = this.config.get();
|
|
538
539
|
const sources = Object.fromEntries(PLATFORM_ATTRIBUTION_FIELDS.map((f) => [
|
|
539
540
|
f,
|
|
540
541
|
this.config.fieldSource(`attribution.${f}`) ?? (stored[f] !== undefined ? "db" : "default"),
|
|
541
542
|
]));
|
|
542
|
-
return {
|
|
543
|
+
return {
|
|
544
|
+
...resolvePlatformAttribution(current.attribution, stored, productName(current)),
|
|
545
|
+
sources,
|
|
546
|
+
};
|
|
543
547
|
}
|
|
544
548
|
/** The cloud devices following the platform's network default (their org sets none). */
|
|
545
549
|
async devicesFollowingPlatformDefault() {
|
package/dist/identity/sso.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare const SSO_CALLBACK_TIMEOUT_MS = 15000;
|
|
|
17
17
|
* 登录失败的原因码(放进回跳 URL `/login?error=<code>`,界面按码走 i18n;不回显身份源的任何文本)。
|
|
18
18
|
* `auth.account_disabled` 与 API 错误码同名。
|
|
19
19
|
*/
|
|
20
|
-
export type SsoLoginError = "sso.unavailable" | "sso.state_invalid" | "sso.session_mismatch" | "sso.access_denied" | "sso.provider_error" | "sso.identity_not_verified" | "auth.account_disabled";
|
|
20
|
+
export type SsoLoginError = "sso.unavailable" | "sso.state_invalid" | "sso.session_mismatch" | "sso.access_denied" | "sso.provider_error" | "sso.account_not_allowed" | "sso.identity_not_verified" | "auth.account_disabled";
|
|
21
21
|
/** 一个有效的浏览器绑定值(复用请求里已有的,否则新生成)。 */
|
|
22
22
|
export declare function ssoBrowserBinding(existing: string | undefined): string;
|
|
23
23
|
/** 回跳页面:站内相对路径(以单个 `/` 开头,非 `//`),否则 `/`(防开放重定向)。 */
|
|
@@ -69,12 +69,18 @@ export declare class SsoFlow {
|
|
|
69
69
|
*/
|
|
70
70
|
start(plugin: string, returnTo: string | undefined, binding: string, sessionAccountId?: string): Promise<string>;
|
|
71
71
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
72
|
+
* Handles the identity source's redirect back. The state is read and deleted in one step (it can
|
|
73
|
+
* never be used again, whatever the outcome); a state that belongs to another plugin →
|
|
74
|
+
* `sso.state_invalid`; a browser binding cookie that does not match → `sso.session_mismatch`.
|
|
75
|
+
* Errors from the identity source map only to reason codes: a deliberate refusal
|
|
76
|
+
* (`IdentitySourceRefused`) → `sso.account_not_allowed`, any other error → `sso.provider_error`.
|
|
77
|
+
* The source key the plugin returns must be the one the kernel derives
|
|
78
|
+
* (`${plugin}:${identity.tenantId}`, Ruling A19), otherwise it is refused as `sso.provider_error`.
|
|
79
|
+
* An identity row created through an IM binding link, when the start and the callback were not
|
|
80
|
+
* made by the same signed-in account → `sso.identity_not_verified` (Ruling A18). On success it
|
|
81
|
+
* resolves to an account (without checking the account's status; the caller handles that).
|
|
82
|
+
* `sessionAccountId`: the account of the web session the callback request already carries
|
|
83
|
+
* (omitted when signed out).
|
|
78
84
|
*/
|
|
79
85
|
callback(plugin: string, query: Record<string, string>, binding: string | undefined, sessionAccountId?: string): Promise<SsoCallbackResult>;
|
|
80
86
|
}
|
package/dist/identity/sso.js
CHANGED
|
@@ -8,7 +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 { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
11
|
-
import { IDENTITY_SOURCE_EXTENSION_POINT, } from "@capybara-hq/plugin-sdk";
|
|
11
|
+
import { IDENTITY_SOURCE_EXTENSION_POINT, isIdentitySourceRefused, } from "@capybara-hq/plugin-sdk";
|
|
12
12
|
import { Inject, Injectable } from "@nestjs/common";
|
|
13
13
|
import { ApiError } from "../errors.js";
|
|
14
14
|
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
@@ -143,12 +143,18 @@ let SsoFlow = class SsoFlow {
|
|
|
143
143
|
return url;
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
146
|
+
* Handles the identity source's redirect back. The state is read and deleted in one step (it can
|
|
147
|
+
* never be used again, whatever the outcome); a state that belongs to another plugin →
|
|
148
|
+
* `sso.state_invalid`; a browser binding cookie that does not match → `sso.session_mismatch`.
|
|
149
|
+
* Errors from the identity source map only to reason codes: a deliberate refusal
|
|
150
|
+
* (`IdentitySourceRefused`) → `sso.account_not_allowed`, any other error → `sso.provider_error`.
|
|
151
|
+
* The source key the plugin returns must be the one the kernel derives
|
|
152
|
+
* (`${plugin}:${identity.tenantId}`, Ruling A19), otherwise it is refused as `sso.provider_error`.
|
|
153
|
+
* An identity row created through an IM binding link, when the start and the callback were not
|
|
154
|
+
* made by the same signed-in account → `sso.identity_not_verified` (Ruling A18). On success it
|
|
155
|
+
* resolves to an account (without checking the account's status; the caller handles that).
|
|
156
|
+
* `sessionAccountId`: the account of the web session the callback request already carries
|
|
157
|
+
* (omitted when signed out).
|
|
152
158
|
*/
|
|
153
159
|
async callback(plugin, query, binding, sessionAccountId) {
|
|
154
160
|
const state = query.state;
|
|
@@ -184,6 +190,14 @@ let SsoFlow = class SsoFlow {
|
|
|
184
190
|
});
|
|
185
191
|
}
|
|
186
192
|
catch (err) {
|
|
193
|
+
// A deliberate refusal gets its own code; its message goes to the log only, never the URL
|
|
194
|
+
if (isIdentitySourceRefused(err)) {
|
|
195
|
+
this.log.warn("identity source refused the account", {
|
|
196
|
+
plugin,
|
|
197
|
+
reason: err.message,
|
|
198
|
+
});
|
|
199
|
+
return { ok: false, error: "sso.account_not_allowed" };
|
|
200
|
+
}
|
|
187
201
|
this.log.warn("identity source callback failed", { plugin, err });
|
|
188
202
|
return { ok: false, error: "sso.provider_error" };
|
|
189
203
|
}
|
|
@@ -20,7 +20,7 @@ import { KERNEL_CONFIG_INPUT, KERNEL_LOGGER } from "../tokens.js";
|
|
|
20
20
|
* takes effect" cannot happen.
|
|
21
21
|
*/
|
|
22
22
|
const HOT_APPLIERS = {
|
|
23
|
-
//
|
|
23
|
+
// The platform name is read at every use (productName(): meta, IM phrases, git gateway, …).
|
|
24
24
|
"platform.name": () => { },
|
|
25
25
|
"log.level": (k, v) => k.log.setLevel(String(v)),
|
|
26
26
|
// The runtime reads the concurrency cap through the config service on every quota request.
|
|
@@ -82,7 +82,7 @@ export async function registerDeviceConnectRoute(fastify, opts) {
|
|
|
82
82
|
: "this capybara-device an older protocol";
|
|
83
83
|
// a newer program than this deployment: the deployment is the one to upgrade
|
|
84
84
|
const fix = number !== null && number > DEVICE_PROTOCOL_VERSION
|
|
85
|
-
? "This deployment is older than the program; ask the platform's super admin to upgrade
|
|
85
|
+
? "This deployment is older than the program; ask the platform's super admin to upgrade it, or install the capybara-device release that matches this deployment."
|
|
86
86
|
: "Update capybara-device on the machine (npm install -g @capybara-hq/device@next), then start it again.";
|
|
87
87
|
return reply
|
|
88
88
|
.code(426)
|
package/dist/orgs/offboarding.js
CHANGED
|
@@ -465,6 +465,15 @@ let Offboarding = class Offboarding {
|
|
|
465
465
|
if (await ctl.abortIfOrphaned(data.conversationId, data.runId, null))
|
|
466
466
|
return;
|
|
467
467
|
await ctl.requestAbort(data.runId, null);
|
|
468
|
+
// the suspend handshake (`WaitsService.suspend`): a run that became `waiting` after the read
|
|
469
|
+
// above may have checked the marker before it was set; check `waiting` again after setting it
|
|
470
|
+
const now = await this.db
|
|
471
|
+
.selectFrom("runs")
|
|
472
|
+
.select("status")
|
|
473
|
+
.where("id", "=", data.runId)
|
|
474
|
+
.executeTakeFirst();
|
|
475
|
+
if (now?.status === "waiting")
|
|
476
|
+
await ctl.abortWaiting(data.conversationId, data.runId, null);
|
|
468
477
|
}
|
|
469
478
|
};
|
|
470
479
|
__decorate([
|
|
@@ -38,7 +38,7 @@ let PlatformIconsOperations = class PlatformIconsOperations {
|
|
|
38
38
|
this.registry.register([
|
|
39
39
|
defineOperation({
|
|
40
40
|
id: "admin.icons",
|
|
41
|
-
description: "List the platform icons the super admin uploaded: the app icon (app), its maskable variant (maskable) and the SVG favicon (favicon), each with its public URL, SHA-256 and when it was set. The installed web app, the browser tab and the native clients use them; a purpose not listed uses the built-in
|
|
41
|
+
description: "List the platform icons the super admin uploaded: the app icon (app), its maskable variant (maskable) and the SVG favicon (favicon), each with its public URL, SHA-256 and when it was set. The installed web app, the browser tab and the native clients use them; a purpose not listed uses the built-in icon.",
|
|
42
42
|
input: z.object({}).strict(),
|
|
43
43
|
example: {},
|
|
44
44
|
authz: { superAdmin: true },
|
|
@@ -88,7 +88,7 @@ let PlatformIconsOperations = class PlatformIconsOperations {
|
|
|
88
88
|
}),
|
|
89
89
|
defineOperation({
|
|
90
90
|
id: "admin.clear-icon",
|
|
91
|
-
description: "Restore the built-in
|
|
91
|
+
description: "Restore the built-in icon for one platform icon purpose (super admin): app, maskable or favicon. The uploaded file is deleted. The platform audit log records it.",
|
|
92
92
|
input: ClearIconInput,
|
|
93
93
|
example: { purpose: "maskable" },
|
|
94
94
|
authz: { superAdmin: true },
|
|
@@ -97,8 +97,8 @@ let PlatformIconsOperations = class PlatformIconsOperations {
|
|
|
97
97
|
summary: async (i) => {
|
|
98
98
|
const n = NAMES[i.purpose];
|
|
99
99
|
return {
|
|
100
|
-
zh: `把平台的${n.zh}
|
|
101
|
-
en: `Restore the built-in
|
|
100
|
+
zh: `把平台的${n.zh}恢复为内置图标`,
|
|
101
|
+
en: `Restore the built-in ${n.en} for the platform`,
|
|
102
102
|
};
|
|
103
103
|
},
|
|
104
104
|
run: async (i, ctx) => {
|
|
@@ -10,6 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
import { AgentsService } from "../../agents/agents.service.js";
|
|
13
|
+
import { productName } from "../../config/product-name.js";
|
|
13
14
|
import { conversationSourceOf } from "../../conversations/source.js";
|
|
14
15
|
import { AccountsService } from "../../identity/accounts.js";
|
|
15
16
|
import { PreferencesSchema } from "../../identity/me.schemas.js";
|
|
@@ -134,7 +135,7 @@ let PlatformOperationsProvider = class PlatformOperationsProvider {
|
|
|
134
135
|
});
|
|
135
136
|
const role = facts.role;
|
|
136
137
|
return {
|
|
137
|
-
platform:
|
|
138
|
+
platform: `${productName(this.config.get())} is an enterprise agent platform: orgs of people build and use agents that work with skills, tools and connectors. Everything it can do is offered by extensions and plugins.`,
|
|
138
139
|
toolFamilies: FAMILIES,
|
|
139
140
|
you: {
|
|
140
141
|
role,
|
|
@@ -28,7 +28,7 @@ let ThemesOperations = class ThemesOperations {
|
|
|
28
28
|
this.registry.register([
|
|
29
29
|
defineOperation({
|
|
30
30
|
id: "themes.list",
|
|
31
|
-
description: "List the themes on in this org (id, version, name, schemes, logo and the bg / panel / ink / accent swatches per scheme), the theme in effect for you here (resolved; null is the built-in theme) and the org's setting (its default theme id, null following the platform, and whether personal picks are allowed or locked). Use a theme id with platform.set-preferences to change your own theme, or with org-settings.update to change the org's default.",
|
|
31
|
+
description: "List the themes on in this org (id, version, name, schemes, logo, decoration (the sign-in page background pattern: dither or none), background (the page background color per scheme) and the bg / panel / ink / accent swatches per scheme), the theme in effect for you here (resolved; null is the built-in theme) and the org's setting (its default theme id, null following the platform, and whether personal picks are allowed or locked). Use a theme id with platform.set-preferences to change your own theme, or with org-settings.update to change the org's default.",
|
|
32
32
|
input: z.object({}).strict(),
|
|
33
33
|
example: {},
|
|
34
34
|
authz: { orgAction: "org.read" },
|
|
@@ -130,6 +130,12 @@ export declare const PERSON_MESSAGES_READ = 20;
|
|
|
130
130
|
* tool review read the same messages.
|
|
131
131
|
*/
|
|
132
132
|
export declare function readPersonMessages(db: KernelDb["db"], rootConversationId: string, budget: number): Promise<string>;
|
|
133
|
+
/**
|
|
134
|
+
* The bounded text of person messages read newest first (as {@link readPersonMessages} queries
|
|
135
|
+
* them): put back in conversation order, oldest first, before {@link boundMessages}, which keeps
|
|
136
|
+
* the newest within the budget and which the review prompts present as "oldest first".
|
|
137
|
+
*/
|
|
138
|
+
export declare function personMessagesText(payloadsNewestFirst: readonly unknown[], budget: number): string;
|
|
133
139
|
/** The identity facts the hook payloads need (all of them: without one, no hooks fire). */
|
|
134
140
|
export interface ReviewHookFacts {
|
|
135
141
|
accountId: string;
|
|
@@ -291,7 +291,18 @@ export async function readPersonMessages(db, rootConversationId, budget) {
|
|
|
291
291
|
.orderBy("seq", "desc")
|
|
292
292
|
.limit(PERSON_MESSAGES_READ)
|
|
293
293
|
.execute();
|
|
294
|
-
|
|
294
|
+
return personMessagesText(rows.map((r) => r.payload), budget);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* The bounded text of person messages read newest first (as {@link readPersonMessages} queries
|
|
298
|
+
* them): put back in conversation order, oldest first, before {@link boundMessages}, which keeps
|
|
299
|
+
* the newest within the budget and which the review prompts present as "oldest first".
|
|
300
|
+
*/
|
|
301
|
+
export function personMessagesText(payloadsNewestFirst, budget) {
|
|
302
|
+
const texts = payloadsNewestFirst
|
|
303
|
+
.map((p) => textOfUserMessage(p))
|
|
304
|
+
.filter((t) => t !== "")
|
|
305
|
+
.reverse();
|
|
295
306
|
return boundMessages(texts, budget);
|
|
296
307
|
}
|
|
297
308
|
/* ---------------------------------------------------------------------------------------------- *
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* a model or a lock; the parser and the table are pure.
|
|
6
6
|
*/
|
|
7
7
|
export type { ClassifierAnswer, ReviewClassifierDeps, ReviewClassifierInput, ReviewHookFacts, ReviewModelCall, ReviewModelCallArgs, ReviewOutcomeTexts, RunClassifierArgs, } from "./classifier.js";
|
|
8
|
-
export { boundMessages, callReviewModel, classifierMessage, fitReviewInput, fitReviewText, newReviewTag, parseReviewAnswer, REVIEW_ASK_REASON, REVIEW_MAX_OUTPUT_TOKENS, REVIEW_PURPOSE, REVIEW_SYSTEM_PROMPT, REVIEW_TRUNCATED_ASK_REASON, REVIEW_TRUNCATED_MARKER, REVIEW_UNAVAILABLE_PREFIX, readPersonMessages, reviewModelLimits, reviewSystemPrompt, runClassifier, } from "./classifier.js";
|
|
8
|
+
export { boundMessages, callReviewModel, classifierMessage, fitReviewInput, fitReviewText, newReviewTag, parseReviewAnswer, personMessagesText, REVIEW_ASK_REASON, REVIEW_MAX_OUTPUT_TOKENS, REVIEW_PURPOSE, REVIEW_SYSTEM_PROMPT, REVIEW_TRUNCATED_ASK_REASON, REVIEW_TRUNCATED_MARKER, REVIEW_UNAVAILABLE_PREFIX, readPersonMessages, reviewModelLimits, reviewSystemPrompt, runClassifier, } from "./classifier.js";
|
|
9
9
|
export type { CommandReview, ReviewCall, ReviewInput, ReviewVerdict } from "./review.service.js";
|
|
10
10
|
export { CommandReviewService, REVIEW_REASONS, } from "./review.service.js";
|
|
11
11
|
export { parseCommand, reviewRules, reviewWrite, writtenPaths, } from "./rules.js";
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* auto mode (and for the file writes outside the workspace). Only the service touches the database,
|
|
5
5
|
* a model or a lock; the parser and the table are pure.
|
|
6
6
|
*/
|
|
7
|
-
export { boundMessages, callReviewModel, classifierMessage, fitReviewInput, fitReviewText, newReviewTag, parseReviewAnswer, REVIEW_ASK_REASON, REVIEW_MAX_OUTPUT_TOKENS, REVIEW_PURPOSE, REVIEW_SYSTEM_PROMPT, REVIEW_TRUNCATED_ASK_REASON, REVIEW_TRUNCATED_MARKER, REVIEW_UNAVAILABLE_PREFIX, readPersonMessages, reviewModelLimits, reviewSystemPrompt, runClassifier, } from "./classifier.js";
|
|
7
|
+
export { boundMessages, callReviewModel, classifierMessage, fitReviewInput, fitReviewText, newReviewTag, parseReviewAnswer, personMessagesText, REVIEW_ASK_REASON, REVIEW_MAX_OUTPUT_TOKENS, REVIEW_PURPOSE, REVIEW_SYSTEM_PROMPT, REVIEW_TRUNCATED_ASK_REASON, REVIEW_TRUNCATED_MARKER, REVIEW_UNAVAILABLE_PREFIX, readPersonMessages, reviewModelLimits, reviewSystemPrompt, runClassifier, } from "./classifier.js";
|
|
8
8
|
export { CommandReviewService, REVIEW_REASONS, } from "./review.service.js";
|
|
9
9
|
export { parseCommand, reviewRules, reviewWrite, writtenPaths, } from "./rules.js";
|
|
10
10
|
export { applySessionGrants, isSessionGrantableRule } from "./types.js";
|
|
@@ -254,7 +254,7 @@ let PlatformIconService = class PlatformIconService {
|
|
|
254
254
|
.where("purpose", "=", purpose)
|
|
255
255
|
.executeTakeFirst();
|
|
256
256
|
const notFound = () => new ApiError("platform_icon.not_found", v === undefined || row === undefined
|
|
257
|
-
? `No ${purpose} icon is uploaded; the built-in
|
|
257
|
+
? `No ${purpose} icon is uploaded; the built-in icon applies`
|
|
258
258
|
: `The ${purpose} icon was replaced; read the current URL from the platform icon settings`);
|
|
259
259
|
if (!row || (v !== undefined && v !== row.sha256))
|
|
260
260
|
throw notFound();
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import { type ParsedTheme } from "@capybara-hq/plugin-sdk";
|
|
1
2
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
2
3
|
import type { KernelLogger } from "../log.js";
|
|
3
4
|
import { StorageService } from "../storage/storage.service.js";
|
|
5
|
+
/**
|
|
6
|
+
* The asset paths a stored definition names ({@link themeAssetRefs}: fonts, logo files, avatar
|
|
7
|
+
* files), read defensively: the row is not re-parsed, so a field of the wrong shape names nothing
|
|
8
|
+
* rather than failing the request.
|
|
9
|
+
*/
|
|
10
|
+
export declare function storedAssetRefs(def: ParsedTheme): string[];
|
|
4
11
|
/** A theme asset's bytes and content type. */
|
|
5
12
|
export interface ThemeAsset {
|
|
6
13
|
contentType: string;
|
|
@@ -29,8 +36,9 @@ export declare class ThemeDeliveryService {
|
|
|
29
36
|
stylesheet(id: string, version: string, revision: string): Promise<string>;
|
|
30
37
|
/**
|
|
31
38
|
* Asset `file` (a path inside the plugin, as stored: `fonts/MiSans.woff2`) of version `version`
|
|
32
|
-
* of theme `id`: only a
|
|
33
|
-
* file
|
|
39
|
+
* of theme `id`: only a file the version's definition names ({@link themeAssetRefs}: fonts, logo
|
|
40
|
+
* files, avatar files), matched exactly against the stored path; never another file of the
|
|
41
|
+
* stored package. Unknown theme, version or file: 404 `theme.not_found`.
|
|
34
42
|
*/
|
|
35
43
|
asset(id: string, version: string, file: string): Promise<ThemeAsset>;
|
|
36
44
|
}
|