@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
|
@@ -3,11 +3,11 @@ import type { KernelConfig } from "../config/schema.js";
|
|
|
3
3
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
4
4
|
import type { KernelLogger } from "../log.js";
|
|
5
5
|
/**
|
|
6
|
-
* The
|
|
6
|
+
* The attribution of agent-created git commits and pull requests (spec
|
|
7
7
|
* 2026-11-14-agent-attribution): the platform defaults, and the merge of an agent's own override
|
|
8
8
|
* over them. Each field is read env > config file (or Nacos) > the super admin's choice in the
|
|
9
9
|
* admin console (deployment setting {@link PLATFORM_ATTRIBUTION_SETTING}) > {@link
|
|
10
|
-
*
|
|
10
|
+
* attributionDefaults} for the platform name; a field set in the startup config is read-only in the admin console.
|
|
11
11
|
* Nothing here is enforcement: the run records the effective values in its log and the model is
|
|
12
12
|
* instructed to use them.
|
|
13
13
|
*/
|
|
@@ -54,7 +54,13 @@ export interface PlatformAttribution {
|
|
|
54
54
|
/** Whether agent-created pull requests also carry the conversation link. */
|
|
55
55
|
sessionUrl: boolean;
|
|
56
56
|
}
|
|
57
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* What a field falls back to when neither the startup config nor the admin console sets it, for
|
|
59
|
+
* the platform name `product` (`platform.name`): the trailer names the platform (the address stays
|
|
60
|
+
* the no-reply one), and the pull-request line links the upstream project only under its own name.
|
|
61
|
+
*/
|
|
62
|
+
export declare function attributionDefaults(product: string): Readonly<PlatformAttribution>;
|
|
63
|
+
/** The defaults of a deployment that sets no `platform.name`. */
|
|
58
64
|
export declare const ATTRIBUTION_DEFAULTS: Readonly<PlatformAttribution>;
|
|
59
65
|
/** Where a field's effective value comes from. */
|
|
60
66
|
export type PlatformAttributionSource = "env" | "file" | "nacos" | "db" | "default";
|
|
@@ -70,15 +76,18 @@ export type ConfigAttribution = KernelConfig["attribution"];
|
|
|
70
76
|
* attribution line on a commit or a pull request.
|
|
71
77
|
*/
|
|
72
78
|
export declare function parseStoredPlatformAttribution(value: unknown, log?: Pick<KernelLogger, "warn">): PlatformAttributionStored;
|
|
73
|
-
/**
|
|
74
|
-
|
|
79
|
+
/**
|
|
80
|
+
* The effective defaults of the startup config over the stored choice, else the built-in ones for
|
|
81
|
+
* the platform name `product`.
|
|
82
|
+
*/
|
|
83
|
+
export declare function resolvePlatformAttribution(config: ConfigAttribution, stored: PlatformAttributionStored, product: string): PlatformAttribution;
|
|
75
84
|
/** The stored choice with `patch` applied (null clears a field). */
|
|
76
85
|
export declare function applyPlatformAttributionPatch(stored: PlatformAttributionStored, patch: PlatformAttributionPatch): PlatformAttributionStored;
|
|
77
86
|
/** The stored choice, read live (in the caller's transaction when there is one). */
|
|
78
87
|
export declare function readStoredPlatformAttribution(db: KernelSchemaDb, log?: Pick<KernelLogger, "warn">): Promise<PlatformAttributionStored>;
|
|
79
88
|
/** The platform's effective defaults, read live: see {@link resolvePlatformAttribution}. */
|
|
80
89
|
export declare function readPlatformAttribution(db: KernelSchemaDb, config: {
|
|
81
|
-
get(): Pick<KernelConfig, "attribution">;
|
|
90
|
+
get(): Pick<KernelConfig, "attribution" | "platform">;
|
|
82
91
|
}, log?: Pick<KernelLogger, "warn">): Promise<PlatformAttribution>;
|
|
83
92
|
/**
|
|
84
93
|
* The link that ends an agent-created pull request when the deployment set `http.publicUrl` (a
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { DEFAULT_PRODUCT_NAME, productName } from "../config/product-name.js";
|
|
2
3
|
/**
|
|
3
|
-
* The
|
|
4
|
+
* The attribution of agent-created git commits and pull requests (spec
|
|
4
5
|
* 2026-11-14-agent-attribution): the platform defaults, and the merge of an agent's own override
|
|
5
6
|
* over them. Each field is read env > config file (or Nacos) > the super admin's choice in the
|
|
6
7
|
* admin console (deployment setting {@link PLATFORM_ATTRIBUTION_SETTING}) > {@link
|
|
7
|
-
*
|
|
8
|
+
* attributionDefaults} for the platform name; a field set in the startup config is read-only in the admin console.
|
|
8
9
|
* Nothing here is enforcement: the run records the effective values in its log and the model is
|
|
9
10
|
* instructed to use them.
|
|
10
11
|
*/
|
|
@@ -55,12 +56,22 @@ export const PLATFORM_ATTRIBUTION_PATCH = z
|
|
|
55
56
|
.refine((o) => Object.values(o).some((v) => v !== undefined), {
|
|
56
57
|
message: "give commit, pr, sessionUrl or several",
|
|
57
58
|
});
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
/**
|
|
60
|
+
* What a field falls back to when neither the startup config nor the admin console sets it, for
|
|
61
|
+
* the platform name `product` (`platform.name`): the trailer names the platform (the address stays
|
|
62
|
+
* the no-reply one), and the pull-request line links the upstream project only under its own name.
|
|
63
|
+
*/
|
|
64
|
+
export function attributionDefaults(product) {
|
|
65
|
+
return Object.freeze({
|
|
66
|
+
commit: `Co-Authored-By: ${product} <noreply@capybarahq.com>`,
|
|
67
|
+
pr: product === DEFAULT_PRODUCT_NAME
|
|
68
|
+
? `🤖 Generated with [${DEFAULT_PRODUCT_NAME}](https://github.com/capybara-hq/core)`
|
|
69
|
+
: `🤖 Generated with ${product}`,
|
|
70
|
+
sessionUrl: false,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/** The defaults of a deployment that sets no `platform.name`. */
|
|
74
|
+
export const ATTRIBUTION_DEFAULTS = attributionDefaults(DEFAULT_PRODUCT_NAME);
|
|
64
75
|
/**
|
|
65
76
|
* Parses the stored choice: missing -> `{}`; invalid -> `{}` (the defaults), with a warning on
|
|
66
77
|
* `log`. Unlike the sandbox tiers there is no narrower reading: the worst case is a visible
|
|
@@ -77,12 +88,16 @@ export function parseStoredPlatformAttribution(value, log) {
|
|
|
77
88
|
});
|
|
78
89
|
return {};
|
|
79
90
|
}
|
|
80
|
-
/**
|
|
81
|
-
|
|
91
|
+
/**
|
|
92
|
+
* The effective defaults of the startup config over the stored choice, else the built-in ones for
|
|
93
|
+
* the platform name `product`.
|
|
94
|
+
*/
|
|
95
|
+
export function resolvePlatformAttribution(config, stored, product) {
|
|
96
|
+
const defaults = attributionDefaults(product);
|
|
82
97
|
return {
|
|
83
|
-
commit: config.commit ?? stored.commit ??
|
|
84
|
-
pr: config.pr ?? stored.pr ??
|
|
85
|
-
sessionUrl: config.sessionUrl ?? stored.sessionUrl ??
|
|
98
|
+
commit: config.commit ?? stored.commit ?? defaults.commit,
|
|
99
|
+
pr: config.pr ?? stored.pr ?? defaults.pr,
|
|
100
|
+
sessionUrl: config.sessionUrl ?? stored.sessionUrl ?? defaults.sessionUrl,
|
|
86
101
|
};
|
|
87
102
|
}
|
|
88
103
|
/** The stored choice with `patch` applied (null clears a field). */
|
|
@@ -108,7 +123,9 @@ export async function readStoredPlatformAttribution(db, log) {
|
|
|
108
123
|
}
|
|
109
124
|
/** The platform's effective defaults, read live: see {@link resolvePlatformAttribution}. */
|
|
110
125
|
export async function readPlatformAttribution(db, config, log) {
|
|
111
|
-
|
|
126
|
+
const stored = await readStoredPlatformAttribution(db, log);
|
|
127
|
+
const current = config.get();
|
|
128
|
+
return resolvePlatformAttribution(current.attribution, stored, productName(current));
|
|
112
129
|
}
|
|
113
130
|
/**
|
|
114
131
|
* The link that ends an agent-created pull request when the deployment set `http.publicUrl` (a
|
|
@@ -267,16 +267,19 @@ export interface CatalogTheme {
|
|
|
267
267
|
/** Relative to the plugin root. */
|
|
268
268
|
path: string;
|
|
269
269
|
theme: ParsedTheme;
|
|
270
|
-
/** The theme's fonts and
|
|
270
|
+
/** The theme's fonts, logo and avatar files (paths relative to the plugin root), sanitized. */
|
|
271
271
|
assets: SkillPackageFile[];
|
|
272
272
|
/** {@link themeAssetsDigest} of the version's records of those files. */
|
|
273
273
|
assetsDigest: string;
|
|
274
274
|
}
|
|
275
|
-
/**
|
|
275
|
+
/**
|
|
276
|
+
* The asset paths a parsed theme references ({@link themeAssetRefs}: fonts, logo files, avatar
|
|
277
|
+
* files), without `./`.
|
|
278
|
+
*/
|
|
276
279
|
export declare function themeAssetPaths(theme: ParsedTheme): string[];
|
|
277
280
|
/**
|
|
278
281
|
* The digest of a theme's assets as recorded on a catalog version (`files`): equal digests = the
|
|
279
|
-
* same fonts and
|
|
282
|
+
* same fonts, logo and avatar files. With the canonical definition it decides whether a theme changed.
|
|
280
283
|
*/
|
|
281
284
|
export declare function themeAssetsDigest(files: {
|
|
282
285
|
path: string;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// OrgCatalogService: kept out of org-catalog.service.ts so the installer's module never imports a
|
|
4
4
|
// module whose provider injects PluginInstaller (an ESM import cycle would run decorators early).
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
|
-
import { parseAgentTemplate, parseConnectorTemplateFile, parseThemeFile, themeIdOf, validateThemeAssets, } from "@capybara-hq/plugin-sdk";
|
|
6
|
+
import { parseAgentTemplate, parseConnectorTemplateFile, parseThemeFile, themeAssetRefs, themeIdOf, validateThemeAssets, } from "@capybara-hq/plugin-sdk";
|
|
7
7
|
import { ApiError } from "../errors.js";
|
|
8
8
|
import { can } from "../orgs/roles.js";
|
|
9
9
|
import { packagePath } from "../packages/tgz.js";
|
|
@@ -367,17 +367,16 @@ export async function readCatalogAgentTemplates(storage, v) {
|
|
|
367
367
|
return { path, template: parsed.template };
|
|
368
368
|
});
|
|
369
369
|
}
|
|
370
|
-
/**
|
|
370
|
+
/**
|
|
371
|
+
* The asset paths a parsed theme references ({@link themeAssetRefs}: fonts, logo files, avatar
|
|
372
|
+
* files), without `./`.
|
|
373
|
+
*/
|
|
371
374
|
export function themeAssetPaths(theme) {
|
|
372
|
-
|
|
373
|
-
for (const ref of [theme.logo?.mark, theme.logo?.favicon])
|
|
374
|
-
if (ref !== undefined)
|
|
375
|
-
refs.push(ref);
|
|
376
|
-
return [...new Set(refs.map((r) => packagePath(r)))];
|
|
375
|
+
return [...new Set(themeAssetRefs(theme).map((r) => packagePath(r.ref)))];
|
|
377
376
|
}
|
|
378
377
|
/**
|
|
379
378
|
* The digest of a theme's assets as recorded on a catalog version (`files`): equal digests = the
|
|
380
|
-
* same fonts and
|
|
379
|
+
* same fonts, logo and avatar files. With the canonical definition it decides whether a theme changed.
|
|
381
380
|
*/
|
|
382
381
|
export function themeAssetsDigest(files, theme) {
|
|
383
382
|
const paths = new Set(themeAssetPaths(theme));
|
|
@@ -809,7 +809,7 @@ export function translateClaudePlugin(files, o) {
|
|
|
809
809
|
for (const h of harness)
|
|
810
810
|
add(item("other_harness", "file", h, { path: h }));
|
|
811
811
|
if (imported.length === 0 && mcp.files.size === 0 && agents.agents.length === 0) {
|
|
812
|
-
invalidManifest("the Claude Code plugin has no skill
|
|
812
|
+
invalidManifest("the Claude Code plugin has no skill this platform can import, no agent and no remote MCP server (see the translation report)");
|
|
813
813
|
}
|
|
814
814
|
// The synthesized manifest lists every skill and template, so the reader never scans.
|
|
815
815
|
const templatePaths = [];
|
|
@@ -203,7 +203,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
|
|
|
203
203
|
/** The host versions (an entry's `minKernel` is judged against them). */
|
|
204
204
|
export declare const HOST_VERSIONS: {
|
|
205
205
|
readonly kernel: string;
|
|
206
|
-
readonly sdk: "0.1.0-rc.
|
|
206
|
+
readonly sdk: "0.1.0-rc.50";
|
|
207
207
|
};
|
|
208
208
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
209
209
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
|
@@ -35,7 +35,8 @@ import { withoutRemovedManifestFields } from "./plugin-package.js";
|
|
|
35
35
|
import { compareVersions, newestFirst, sameRelease } from "./versions.js";
|
|
36
36
|
/** 官方清单来源的 id。 */
|
|
37
37
|
export const OFFICIAL_MARKETPLACE_ID = "official";
|
|
38
|
-
|
|
38
|
+
/** Neutral: the official marketplace lists the upstream project's plugins under any platform name. */
|
|
39
|
+
const OFFICIAL_MARKETPLACE_NAME = "Official marketplace";
|
|
39
40
|
/** 企业清单的可选令牌:secrets 的 namespace `kernel`、org `_deployment`、键 `catalog-token:<id>`(preflight #65)。 */
|
|
40
41
|
const SECRETS_NAMESPACE = "kernel";
|
|
41
42
|
const tokenKey = (id) => `catalog-token:${id}`;
|
|
@@ -59,8 +59,9 @@ export interface PluginPackageTheme {
|
|
|
59
59
|
path: string;
|
|
60
60
|
theme: ParsedTheme;
|
|
61
61
|
/**
|
|
62
|
-
* The theme's fonts
|
|
63
|
-
* unchanged), keyed by their path relative
|
|
62
|
+
* The theme's fonts, logo files (mark, favicon, illustration, app icons) and avatar files after
|
|
63
|
+
* `validateThemeAssets` (the SVGs sanitized, the rest unchanged), keyed by their path relative
|
|
64
|
+
* to the package root (no leading `./`).
|
|
64
65
|
*/
|
|
65
66
|
assets: Map<string, Uint8Array>;
|
|
66
67
|
}
|
|
@@ -43,6 +43,8 @@ export declare function fileLinkText(input: {
|
|
|
43
43
|
conversationId: string;
|
|
44
44
|
base: string | undefined;
|
|
45
45
|
locale: ChannelLocale;
|
|
46
|
+
/** The platform name (`platform.name`) the line without a link names. */
|
|
47
|
+
product: string;
|
|
46
48
|
}): string;
|
|
47
49
|
/** The root message text of a native file delivery. */
|
|
48
50
|
export declare function fileRootText(name: string, locale: ChannelLocale): string;
|
|
@@ -77,7 +77,7 @@ export function fileLinkText(input) {
|
|
|
77
77
|
const name = asCode(input.name);
|
|
78
78
|
const size = formatFileSize(input.size);
|
|
79
79
|
if (input.base === undefined) {
|
|
80
|
-
return fill(phrase("fileOnWebNoLink", input.locale), { name, size, url: "" });
|
|
80
|
+
return fill(phrase("fileOnWebNoLink", input.locale, input.product), { name, size, url: "" });
|
|
81
81
|
}
|
|
82
82
|
const url = `${conversationUrl(input.base, input.conversationId)}#file=${input.artifactId}`;
|
|
83
83
|
return fill(phrase("fileOnWeb", input.locale), { name, size, url });
|
|
@@ -4,6 +4,7 @@ import { ConversationsService } from "../conversations/conversations.service.js"
|
|
|
4
4
|
import { DevicesService } from "../devices/devices.service.js";
|
|
5
5
|
import { IdentityBinding } from "../identity/binding.js";
|
|
6
6
|
import { ExternalIdentities } from "../identity/external.js";
|
|
7
|
+
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
7
8
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
8
9
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
9
10
|
import { DirectorySync } from "../orgs/directory-sync.js";
|
|
@@ -39,6 +40,8 @@ export declare class ChannelInbound {
|
|
|
39
40
|
private readonly jobs;
|
|
40
41
|
private readonly guests;
|
|
41
42
|
private readonly devices;
|
|
43
|
+
/** `platform.name`, which the bind phrases name (read at each reply: the field is hot). */
|
|
44
|
+
private readonly config;
|
|
42
45
|
private readonly log;
|
|
43
46
|
private readonly actions;
|
|
44
47
|
constructor(kdb: KernelDb, redis: Pick<Redis, "set">,
|
|
@@ -49,7 +52,9 @@ export declare class ChannelInbound {
|
|
|
49
52
|
/** The channel queue: inbound jobs (`onEvent` only dedupes and enqueues) and deliveries. */
|
|
50
53
|
jobs: Pick<ChannelJobs, "enqueue" | "enqueueInbound" | "bind">,
|
|
51
54
|
/** 卡片操作:审批决定与提问回答(授权由这两个服务按点击者映射到的账号判定)。 */
|
|
52
|
-
approvals: Pick<ApprovalsService, "decide">, questions: Pick<QuestionsService, "answer">, guests: Pick<AnonymousGuests, "ensure">, devices: Pick<DevicesService, "list" | "imDefault" | "setImDefault">,
|
|
55
|
+
approvals: Pick<ApprovalsService, "decide">, questions: Pick<QuestionsService, "answer">, guests: Pick<AnonymousGuests, "ensure">, devices: Pick<DevicesService, "list" | "imDefault" | "setImDefault">,
|
|
56
|
+
/** `platform.name`, which the bind phrases name (read at each reply: the field is hot). */
|
|
57
|
+
config: Pick<KernelConfigService, "get">, log: Pick<Logger, "warn" | "info">);
|
|
53
58
|
/**
|
|
54
59
|
* 插件 `onEvent`:去重并入队后返回(见类注释)。返回后插件才向平台确认;抛错时插件不确认。
|
|
55
60
|
*/
|
package/dist/channels/inbound.js
CHANGED
|
@@ -9,6 +9,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
9
9
|
};
|
|
10
10
|
import { randomUUID } from "node:crypto";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
|
+
import { productName } from "../config/product-name.js";
|
|
12
13
|
import { ConversationsService } from "../conversations/conversations.service.js";
|
|
13
14
|
import { imSenderContext, recipientLocale, } from "../conversations/message-context.js";
|
|
14
15
|
import { channelSource } from "../conversations/source.js";
|
|
@@ -17,6 +18,7 @@ import { DEFAULT_DEVICE_ALIASES, deviceLabel } from "../devices/label.js";
|
|
|
17
18
|
import { ApiError } from "../errors.js";
|
|
18
19
|
import { IdentityBinding } from "../identity/binding.js";
|
|
19
20
|
import { ExternalIdentities } from "../identity/external.js";
|
|
21
|
+
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
20
22
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
21
23
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
22
24
|
import { KERNEL_LOGGER, REDIS } from "../infra/tokens.js";
|
|
@@ -99,6 +101,7 @@ let ChannelInbound = class ChannelInbound {
|
|
|
99
101
|
jobs;
|
|
100
102
|
guests;
|
|
101
103
|
devices;
|
|
104
|
+
config;
|
|
102
105
|
log;
|
|
103
106
|
actions;
|
|
104
107
|
constructor(kdb, redis,
|
|
@@ -109,7 +112,9 @@ let ChannelInbound = class ChannelInbound {
|
|
|
109
112
|
/** The channel queue: inbound jobs (`onEvent` only dedupes and enqueues) and deliveries. */
|
|
110
113
|
jobs,
|
|
111
114
|
/** 卡片操作:审批决定与提问回答(授权由这两个服务按点击者映射到的账号判定)。 */
|
|
112
|
-
approvals, questions, guests, devices,
|
|
115
|
+
approvals, questions, guests, devices,
|
|
116
|
+
/** `platform.name`, which the bind phrases name (read at each reply: the field is hot). */
|
|
117
|
+
config, log) {
|
|
113
118
|
this.kdb = kdb;
|
|
114
119
|
this.redis = redis;
|
|
115
120
|
this.locks = locks;
|
|
@@ -121,6 +126,7 @@ let ChannelInbound = class ChannelInbound {
|
|
|
121
126
|
this.jobs = jobs;
|
|
122
127
|
this.guests = guests;
|
|
123
128
|
this.devices = devices;
|
|
129
|
+
this.config = config;
|
|
124
130
|
this.log = log;
|
|
125
131
|
this.actions = new ChannelCardActions({
|
|
126
132
|
get db() {
|
|
@@ -219,7 +225,7 @@ let ChannelInbound = class ChannelInbound {
|
|
|
219
225
|
const replyText = async (text, cards) => {
|
|
220
226
|
await connections.send(connectionId, replyTarget, { text, ...(cards !== undefined && { cards }) }, replyKey, locale);
|
|
221
227
|
};
|
|
222
|
-
const reply = (key, cards) => replyText(phrase(key, locale), cards);
|
|
228
|
+
const reply = (key, cards) => replyText(phrase(key, locale, productName(this.config.get())), cards);
|
|
223
229
|
const speaker = await this.resolveSpeaker(connectionId, row, e.sender, isGroup, locale, reply);
|
|
224
230
|
if (speaker === undefined)
|
|
225
231
|
return;
|
|
@@ -436,7 +442,8 @@ let ChannelInbound = class ChannelInbound {
|
|
|
436
442
|
await reply("bindUnavailable");
|
|
437
443
|
return undefined;
|
|
438
444
|
}
|
|
439
|
-
|
|
445
|
+
const bindText = phrase("bindPrompt", locale, productName(this.config.get()));
|
|
446
|
+
await reply("bindPrompt", [{ kind: "bind", url, text: bindText }]);
|
|
440
447
|
return undefined;
|
|
441
448
|
}
|
|
442
449
|
/** 账号是该组织成员且账号未停用。 */
|
|
@@ -479,7 +486,8 @@ ChannelInbound = __decorate([
|
|
|
479
486
|
__param(10, Inject(QuestionsService)),
|
|
480
487
|
__param(11, Inject(AnonymousGuests)),
|
|
481
488
|
__param(12, Inject(DevicesService)),
|
|
482
|
-
__param(13, Inject(
|
|
489
|
+
__param(13, Inject(KernelConfigService)),
|
|
490
|
+
__param(14, Inject(KERNEL_LOGGER))
|
|
483
491
|
], ChannelInbound);
|
|
484
492
|
export { ChannelInbound };
|
|
485
493
|
/** `/device` or `/device <name>` (the exact command word, case-insensitive); anything else is null. */
|
|
@@ -12,6 +12,7 @@ import { isChannelSendError, } from "@capybara-hq/plugin-sdk";
|
|
|
12
12
|
import { Inject, Injectable } from "@nestjs/common";
|
|
13
13
|
import { DelayedError, UnrecoverableError } from "bullmq";
|
|
14
14
|
import { sql } from "kysely";
|
|
15
|
+
import { productName } from "../config/product-name.js";
|
|
15
16
|
import { conversationTopic, EventLog, } from "../conversations/event-log.js";
|
|
16
17
|
import { recipientLocale } from "../conversations/message-context.js";
|
|
17
18
|
import { ApiError } from "../errors.js";
|
|
@@ -574,6 +575,10 @@ class Delivery {
|
|
|
574
575
|
return this.session;
|
|
575
576
|
}
|
|
576
577
|
/** 普通消息的幂等键(Ruling A15):`<会话>-<seq>[后缀]` 的稳定哈希。 */
|
|
578
|
+
/** The platform name the web hints name (`platform.name`, read at each use: the field is hot). */
|
|
579
|
+
product() {
|
|
580
|
+
return productName(this.d.config.get());
|
|
581
|
+
}
|
|
577
582
|
key(seq, suffix = "") {
|
|
578
583
|
return idempotencyKey(`${this.conversationId}-${seq}${suffix}`);
|
|
579
584
|
}
|
|
@@ -697,7 +702,7 @@ class Delivery {
|
|
|
697
702
|
this.d.log.warn("cannot close channel draft before skipping", { err: errMsg(err) });
|
|
698
703
|
}
|
|
699
704
|
try {
|
|
700
|
-
await this.send({ text: phrase("handleOnWeb", this.locale) }, this.key(seq, "-skipped"));
|
|
705
|
+
await this.send({ text: phrase("handleOnWeb", this.locale, this.product()) }, this.key(seq, "-skipped"));
|
|
701
706
|
}
|
|
702
707
|
catch (err) {
|
|
703
708
|
this.d.log.warn("cannot send channel skip notice", { err: errMsg(err) });
|
|
@@ -954,7 +959,7 @@ class Delivery {
|
|
|
954
959
|
case "connection_required": {
|
|
955
960
|
const text = phrase("connectTitle", this.locale);
|
|
956
961
|
await this.send(this.base === undefined
|
|
957
|
-
? { text: phrase("handleOnWeb", this.locale) }
|
|
962
|
+
? { text: phrase("handleOnWeb", this.locale, this.product()) }
|
|
958
963
|
: cardMessage(text, {
|
|
959
964
|
kind: "connect",
|
|
960
965
|
appName: e.payload.appName,
|
|
@@ -969,7 +974,7 @@ class Delivery {
|
|
|
969
974
|
if (v?.kind !== "handoff")
|
|
970
975
|
return;
|
|
971
976
|
await this.send(this.base === undefined
|
|
972
|
-
? { text: phrase("handleOnWeb", this.locale) }
|
|
977
|
+
? { text: phrase("handleOnWeb", this.locale, this.product()) }
|
|
973
978
|
: cardMessage(v.title[this.locale], {
|
|
974
979
|
kind: "bind",
|
|
975
980
|
text: v.title[this.locale],
|
|
@@ -1023,7 +1028,7 @@ class Delivery {
|
|
|
1023
1028
|
/** Sends the approval card of `approvalId` for the event at `seq` (or the web hint). */
|
|
1024
1029
|
async approvalCardAt(seq, approvalId) {
|
|
1025
1030
|
if (this.base === undefined) {
|
|
1026
|
-
await this.send({ text: phrase("handleOnWeb", this.locale) }, this.key(seq));
|
|
1031
|
+
await this.send({ text: phrase("handleOnWeb", this.locale, this.product()) }, this.key(seq));
|
|
1027
1032
|
return this.advance(seq);
|
|
1028
1033
|
}
|
|
1029
1034
|
// secrets are typed on the web only (a secure input request, or a tool ask with person
|
|
@@ -1173,6 +1178,7 @@ class Delivery {
|
|
|
1173
1178
|
conversationId: this.conversationId,
|
|
1174
1179
|
base: this.base,
|
|
1175
1180
|
locale: this.locale,
|
|
1181
|
+
product: this.product(),
|
|
1176
1182
|
});
|
|
1177
1183
|
await this.send({ text }, this.key(seq, "-link"));
|
|
1178
1184
|
return this.advance(seq);
|
|
@@ -1184,7 +1190,7 @@ class Delivery {
|
|
|
1184
1190
|
*/
|
|
1185
1191
|
async questionCardAt(seq, questionId, form, child) {
|
|
1186
1192
|
if (this.base === undefined) {
|
|
1187
|
-
await this.send({ text: phrase("handleOnWeb", this.locale) }, this.key(seq));
|
|
1193
|
+
await this.send({ text: phrase("handleOnWeb", this.locale, this.product()) }, this.key(seq));
|
|
1188
1194
|
return this.advance(seq);
|
|
1189
1195
|
}
|
|
1190
1196
|
// the person can skip the conversation's own question by replying; a sub-agent's question
|
|
@@ -4,6 +4,7 @@ export type ChannelLocale = "zh" | "en";
|
|
|
4
4
|
* 机器人在 IM 里说的固定话术(全部集中在这里,zh / en 同步). Chosen per recipient (run context spec
|
|
5
5
|
* §3.4): the sender's platform language, else their latest web language, else the org's.
|
|
6
6
|
* 模型回复不经过这里,原样转换为 IM 富文本、不翻译。
|
|
7
|
+
* `{product}` is the platform name (`platform.name`): {@link phrase} requires it for those phrases.
|
|
7
8
|
*/
|
|
8
9
|
export declare const CHANNEL_PHRASES: {
|
|
9
10
|
/** 私聊 `/new` 之后。 */
|
|
@@ -43,13 +44,13 @@ export declare const CHANNEL_PHRASES: {
|
|
|
43
44
|
};
|
|
44
45
|
/** 未绑定的人在私聊里发消息:附绑定卡片。 */
|
|
45
46
|
readonly bindPrompt: {
|
|
46
|
-
readonly zh: "请先绑定你的
|
|
47
|
-
readonly en: "Please link your
|
|
47
|
+
readonly zh: "请先绑定你的 {product} 账号,再与我对话。";
|
|
48
|
+
readonly en: "Please link your {product} account before chatting with me.";
|
|
48
49
|
};
|
|
49
50
|
/** 未绑定的人在群里 @ 机器人:绑定链接只在私聊里发(群里谁都能点)。 */
|
|
50
51
|
readonly bindInDm: {
|
|
51
|
-
readonly zh: "请先私聊我,绑定你的
|
|
52
|
-
readonly en: "Please send me a direct message to link your
|
|
52
|
+
readonly zh: "请先私聊我,绑定你的 {product} 账号。";
|
|
53
|
+
readonly en: "Please send me a direct message to link your {product} account first.";
|
|
53
54
|
};
|
|
54
55
|
/** 无法生成绑定链接(部署未配置 http.publicUrl)。 */
|
|
55
56
|
readonly bindUnavailable: {
|
|
@@ -224,8 +225,8 @@ export declare const CHANNEL_PHRASES: {
|
|
|
224
225
|
};
|
|
225
226
|
/** 部署未配置 http.publicUrl,无法给出网页链接与卡片时的退回文本。 */
|
|
226
227
|
readonly handleOnWeb: {
|
|
227
|
-
readonly zh: "有一条请求需要你到
|
|
228
|
-
readonly en: "A request is waiting for you in
|
|
228
|
+
readonly zh: "有一条请求需要你到 {product} 网页上处理。";
|
|
229
|
+
readonly en: "A request is waiting for you in {product} on the web.";
|
|
229
230
|
};
|
|
230
231
|
/**
|
|
231
232
|
* Phase D: `/name args` named an invocable skill, but the kernel refused to render it
|
|
@@ -275,8 +276,8 @@ export declare const CHANNEL_PHRASES: {
|
|
|
275
276
|
};
|
|
276
277
|
/** The same without a web link (no public base URL configured). */
|
|
277
278
|
readonly fileOnWebNoLink: {
|
|
278
|
-
readonly zh: "{name}({size})已交付,请在网页上打开
|
|
279
|
-
readonly en: "{name} ({size}) was delivered; open the conversation in
|
|
279
|
+
readonly zh: "{name}({size})已交付,请在网页上打开 {product} 中的这个会话获取。";
|
|
280
|
+
readonly en: "{name} ({size}) was delivered; open the conversation in {product} on the web to get it.";
|
|
280
281
|
};
|
|
281
282
|
/**
|
|
282
283
|
* The root message of a native file delivery (a scheduled group run's first post); `{name}` is
|
|
@@ -299,5 +300,12 @@ export declare const CHANNEL_PHRASES: {
|
|
|
299
300
|
};
|
|
300
301
|
};
|
|
301
302
|
export type ChannelPhrase = keyof typeof CHANNEL_PHRASES;
|
|
302
|
-
/**
|
|
303
|
-
export
|
|
303
|
+
/** The phrases that name the platform (`{product}`): {@link phrase} takes the name for them. */
|
|
304
|
+
export type ProductPhrase = {
|
|
305
|
+
[K in ChannelPhrase]: (typeof CHANNEL_PHRASES)[K]["en"] extends `${string}{product}${string}` ? K : never;
|
|
306
|
+
}[ChannelPhrase];
|
|
307
|
+
/**
|
|
308
|
+
* One phrase in `locale`. A phrase that names the platform takes its name (`productName(config)`,
|
|
309
|
+
* read at each use: `platform.name` is hot), which replaces `{product}`.
|
|
310
|
+
*/
|
|
311
|
+
export declare function phrase<K extends ChannelPhrase>(key: K, locale: ChannelLocale, ...product: K extends ProductPhrase ? [product: string] : []): string;
|
package/dist/channels/phrases.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* 机器人在 IM 里说的固定话术(全部集中在这里,zh / en 同步). Chosen per recipient (run context spec
|
|
3
3
|
* §3.4): the sender's platform language, else their latest web language, else the org's.
|
|
4
4
|
* 模型回复不经过这里,原样转换为 IM 富文本、不翻译。
|
|
5
|
+
* `{product}` is the platform name (`platform.name`): {@link phrase} requires it for those phrases.
|
|
5
6
|
*/
|
|
6
7
|
export const CHANNEL_PHRASES = {
|
|
7
8
|
/** 私聊 `/new` 之后。 */
|
|
@@ -35,13 +36,13 @@ export const CHANNEL_PHRASES = {
|
|
|
35
36
|
deviceCurrent: { zh: "(当前)", en: " (current)" },
|
|
36
37
|
/** 未绑定的人在私聊里发消息:附绑定卡片。 */
|
|
37
38
|
bindPrompt: {
|
|
38
|
-
zh: "请先绑定你的
|
|
39
|
-
en: "Please link your
|
|
39
|
+
zh: "请先绑定你的 {product} 账号,再与我对话。",
|
|
40
|
+
en: "Please link your {product} account before chatting with me.",
|
|
40
41
|
},
|
|
41
42
|
/** 未绑定的人在群里 @ 机器人:绑定链接只在私聊里发(群里谁都能点)。 */
|
|
42
43
|
bindInDm: {
|
|
43
|
-
zh: "请先私聊我,绑定你的
|
|
44
|
-
en: "Please send me a direct message to link your
|
|
44
|
+
zh: "请先私聊我,绑定你的 {product} 账号。",
|
|
45
|
+
en: "Please send me a direct message to link your {product} account first.",
|
|
45
46
|
},
|
|
46
47
|
/** 无法生成绑定链接(部署未配置 http.publicUrl)。 */
|
|
47
48
|
bindUnavailable: {
|
|
@@ -186,8 +187,8 @@ export const CHANNEL_PHRASES = {
|
|
|
186
187
|
},
|
|
187
188
|
/** 部署未配置 http.publicUrl,无法给出网页链接与卡片时的退回文本。 */
|
|
188
189
|
handleOnWeb: {
|
|
189
|
-
zh: "有一条请求需要你到
|
|
190
|
-
en: "A request is waiting for you in
|
|
190
|
+
zh: "有一条请求需要你到 {product} 网页上处理。",
|
|
191
|
+
en: "A request is waiting for you in {product} on the web.",
|
|
191
192
|
},
|
|
192
193
|
/**
|
|
193
194
|
* Phase D: `/name args` named an invocable skill, but the kernel refused to render it
|
|
@@ -237,8 +238,8 @@ export const CHANNEL_PHRASES = {
|
|
|
237
238
|
},
|
|
238
239
|
/** The same without a web link (no public base URL configured). */
|
|
239
240
|
fileOnWebNoLink: {
|
|
240
|
-
zh: "{name}({size})已交付,请在网页上打开
|
|
241
|
-
en: "{name} ({size}) was delivered; open the conversation in
|
|
241
|
+
zh: "{name}({size})已交付,请在网页上打开 {product} 中的这个会话获取。",
|
|
242
|
+
en: "{name} ({size}) was delivered; open the conversation in {product} on the web to get it.",
|
|
242
243
|
},
|
|
243
244
|
/**
|
|
244
245
|
* The root message of a native file delivery (a scheduled group run's first post); `{name}` is
|
|
@@ -254,7 +255,13 @@ export const CHANNEL_PHRASES = {
|
|
|
254
255
|
en: "Sorry, something went wrong. Please try again later.",
|
|
255
256
|
},
|
|
256
257
|
};
|
|
257
|
-
/**
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
/**
|
|
259
|
+
* One phrase in `locale`. A phrase that names the platform takes its name (`productName(config)`,
|
|
260
|
+
* read at each use: `platform.name` is hot), which replaces `{product}`.
|
|
261
|
+
*/
|
|
262
|
+
export function phrase(key, locale, ...product) {
|
|
263
|
+
const text = CHANNEL_PHRASES[key][locale];
|
|
264
|
+
const name = product[0];
|
|
265
|
+
// a function replacement: `$&` in a name is text, not a pattern
|
|
266
|
+
return name === undefined ? text : text.replaceAll("{product}", () => name);
|
|
260
267
|
}
|
|
@@ -78,7 +78,7 @@ export function checkClientFiles(section, files) {
|
|
|
78
78
|
}
|
|
79
79
|
if (section.apiVersion > CLIENT_API_VERSION) {
|
|
80
80
|
throw new ApiError("client.api_unsupported", `The plugin's client code was built for client API ${section.apiVersion}; this deployment ` +
|
|
81
|
-
`supports ${CLIENT_API_VERSION}. Upgrade
|
|
81
|
+
`supports ${CLIENT_API_VERSION}. Upgrade the platform, or build the plugin against ` +
|
|
82
82
|
`@capybara-hq/plugin-client for client API ${CLIENT_API_VERSION}.`, [{ apiVersion: section.apiVersion, supported: CLIENT_API_VERSION }]);
|
|
83
83
|
}
|
|
84
84
|
const styles = section.styles ?? [];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { KernelConfig } from "./schema.js";
|
|
2
|
+
/** The product name when the deployment sets no `platform.name`. */
|
|
3
|
+
export declare const DEFAULT_PRODUCT_NAME = "Capybara";
|
|
4
|
+
/**
|
|
5
|
+
* The name people see for this deployment (`platform.name`, else {@link DEFAULT_PRODUCT_NAME}).
|
|
6
|
+
* `platform.name` is hot: read it per use, never cache it.
|
|
7
|
+
*/
|
|
8
|
+
export declare function productName(config: Pick<KernelConfig, "platform">): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The product name when the deployment sets no `platform.name`. */
|
|
2
|
+
export const DEFAULT_PRODUCT_NAME = "Capybara";
|
|
3
|
+
/**
|
|
4
|
+
* The name people see for this deployment (`platform.name`, else {@link DEFAULT_PRODUCT_NAME}).
|
|
5
|
+
* `platform.name` is hot: read it per use, never cache it.
|
|
6
|
+
*/
|
|
7
|
+
export function productName(config) {
|
|
8
|
+
return config.platform.name ?? DEFAULT_PRODUCT_NAME;
|
|
9
|
+
}
|
package/dist/config/schema.js
CHANGED
|
@@ -315,7 +315,7 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
315
315
|
.optional()
|
|
316
316
|
.meta(meta({
|
|
317
317
|
hot: true,
|
|
318
|
-
description: "The platform's display name (1 to 64 characters)
|
|
318
|
+
description: "The platform's display name (1 to 64 characters): the product name people see in the web app, the installed web app and native clients (GET /api/v1/meta), IM bot replies, git gateway messages, OAuth client registrations and the attribution defaults; unset: Capybara",
|
|
319
319
|
})),
|
|
320
320
|
})
|
|
321
321
|
.prefault({}),
|
|
@@ -1343,7 +1343,7 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1343
1343
|
.optional()
|
|
1344
1344
|
.meta(meta({
|
|
1345
1345
|
hot: true,
|
|
1346
|
-
description: "The trailer an agent ends the message of a git commit it creates with; an empty string turns it off. Overridable per agent; unset follows the admin console's value, else 'Co-Authored-By:
|
|
1346
|
+
description: "The trailer an agent ends the message of a git commit it creates with; an empty string turns it off. Overridable per agent; unset follows the admin console's value, else 'Co-Authored-By: <platform.name> <noreply@capybarahq.com>'",
|
|
1347
1347
|
})),
|
|
1348
1348
|
pr: z
|
|
1349
1349
|
.string()
|
|
@@ -1352,7 +1352,7 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1352
1352
|
.optional()
|
|
1353
1353
|
.meta(meta({
|
|
1354
1354
|
hot: true,
|
|
1355
|
-
description: "The line an agent ends the body of a pull request it opens with; an empty string turns it off. Overridable per agent; unset follows the admin console's value, else '🤖 Generated with [Capybara](https://github.com/capybara-hq/core)'",
|
|
1355
|
+
description: "The line an agent ends the body of a pull request it opens with; an empty string turns it off. Overridable per agent; unset follows the admin console's value, else '🤖 Generated with [Capybara](https://github.com/capybara-hq/core)' ('🤖 Generated with <platform.name>' when platform.name is set to another name)",
|
|
1356
1356
|
})),
|
|
1357
1357
|
sessionUrl: z
|
|
1358
1358
|
.boolean()
|
|
@@ -1287,6 +1287,17 @@ let ConversationsService = class ConversationsService {
|
|
|
1287
1287
|
// terminal transaction
|
|
1288
1288
|
await this.holdTree(conversationId);
|
|
1289
1289
|
await runs.requestAbort(run.id, accountId);
|
|
1290
|
+
// the suspend handshake (`WaitsService.suspend`): a run that became `waiting` after the read
|
|
1291
|
+
// above may have checked the marker before it was set and ended its job, so nobody hears the
|
|
1292
|
+
// broadcast; check `waiting` again after setting the marker and end it as a waiting run
|
|
1293
|
+
const now = await this.db
|
|
1294
|
+
.selectFrom("runs")
|
|
1295
|
+
.select("status")
|
|
1296
|
+
.where("id", "=", run.id)
|
|
1297
|
+
.executeTakeFirst();
|
|
1298
|
+
if (now?.status === "waiting" && (await runs.abortWaiting(conversationId, run.id, accountId))) {
|
|
1299
|
+
await runs.ensureRunAfterCommit(conversationId);
|
|
1300
|
+
}
|
|
1290
1301
|
return run.id;
|
|
1291
1302
|
}
|
|
1292
1303
|
};
|