@capybara-hq/kernel 0.1.0-rc.32 → 0.1.0-rc.34
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/bootstrap.json +3 -3
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/requests.service.d.ts +8 -6
- package/dist/catalog/requests.service.js +52 -29
- package/dist/channels/inbound.d.ts +0 -25
- package/dist/channels/inbound.js +26 -1
- package/dist/channels/phrases.d.ts +28 -0
- package/dist/channels/phrases.js +28 -0
- package/dist/config/schema.d.ts +4 -0
- package/dist/config/schema.js +7 -1
- package/dist/conversations/conversations.controller.d.ts +4 -1
- package/dist/conversations/conversations.controller.js +14 -2
- package/dist/conversations/conversations.service.d.ts +43 -3
- package/dist/conversations/conversations.service.js +93 -19
- package/dist/conversations/event-log.d.ts +3 -3
- package/dist/conversations/event-log.js +3 -3
- package/dist/conversations/events.d.ts +24 -0
- package/dist/conversations/events.js +69 -0
- package/dist/db/kernel-schema.d.ts +20 -0
- package/dist/devices/conversation-devices.d.ts +57 -3
- package/dist/devices/conversation-devices.js +63 -11
- package/dist/devices/device-projects.service.d.ts +162 -0
- package/dist/devices/device-projects.service.js +503 -0
- package/dist/devices/devices.controller.d.ts +15 -2
- package/dist/devices/devices.controller.js +60 -3
- package/dist/devices/devices.module.js +15 -2
- package/dist/devices/devices.schemas.js +9 -1
- package/dist/devices/devices.service.js +8 -4
- package/dist/devices/dto.d.ts +31 -0
- package/dist/devices/dto.js +38 -1
- package/dist/devices/working-root.d.ts +41 -0
- package/dist/devices/working-root.js +50 -0
- package/dist/errors.d.ts +39 -0
- package/dist/errors.js +39 -0
- package/dist/evals/run-replay.d.ts +9 -1
- package/dist/evals/run-replay.js +15 -1
- package/dist/local-devices/local-device-provider.d.ts +37 -1
- package/dist/local-devices/local-device-provider.js +33 -0
- package/dist/local-devices/machines.d.ts +2 -1
- package/dist/local-devices/machines.js +4 -1
- package/dist/local-devices/network-grants.d.ts +1 -1
- package/dist/local-devices/network-grants.js +2 -3
- package/dist/local-devices/policy-summary.js +1 -0
- package/dist/local-devices/relay.d.ts +2 -0
- package/dist/local-devices/relay.js +3 -1
- package/dist/local-devices/targets.d.ts +6 -1
- package/dist/local-devices/targets.js +14 -0
- package/dist/orgs/settings.controller.d.ts +3 -1
- package/dist/orgs/settings.controller.js +7 -3
- package/dist/orgs/settings.service.d.ts +78 -31
- package/dist/orgs/settings.service.js +109 -52
- package/dist/overrides.d.ts +4 -0
- package/dist/overrides.js +2 -0
- package/dist/platform/ops/agent-skills.ops.js +2 -1
- package/dist/platform/ops/devices.ops.d.ts +3 -1
- package/dist/platform/ops/devices.ops.js +136 -3
- package/dist/platform/ops/org-settings.ops.js +20 -10
- package/dist/runtime/context/build.d.ts +3 -0
- package/dist/runtime/context/build.js +14 -0
- package/dist/runtime/context/compaction.js +2 -0
- package/dist/runtime/context/project-root.d.ts +43 -0
- package/dist/runtime/context/project-root.js +85 -0
- package/dist/runtime/model-call.js +25 -1
- package/dist/runtime/project/knowledge.d.ts +129 -0
- package/dist/runtime/project/knowledge.js +248 -0
- package/dist/runtime/project/knowledge.service.d.ts +85 -0
- package/dist/runtime/project/knowledge.service.js +288 -0
- package/dist/runtime/run-worker.d.ts +5 -0
- package/dist/runtime/run-worker.js +27 -6
- package/dist/runtime/runtime.module.js +7 -0
- package/dist/sandbox/modes.d.ts +31 -19
- package/dist/sandbox/modes.js +43 -24
- package/dist/sandbox/review/review.service.d.ts +14 -2
- package/dist/sandbox/review/review.service.js +2 -0
- package/dist/sandbox/review/rules.d.ts +6 -4
- package/dist/sandbox/review/rules.js +185 -62
- package/dist/sandbox/review/types.d.ts +14 -0
- package/dist/sandbox/sandbox.service.d.ts +20 -2
- package/dist/sandbox/sandbox.service.js +86 -3
- package/dist/schedules/grant-rules.d.ts +2 -0
- package/dist/schedules/grant-rules.js +3 -1
- package/dist/schedules/schedule-math.js +21 -2
- package/dist/schedules/scheduled-tasks.service.js +3 -1
- package/dist/skills/catalog.d.ts +6 -1
- package/dist/skills/catalog.js +18 -4
- package/dist/skills/invoke.d.ts +64 -2
- package/dist/skills/invoke.js +214 -6
- package/dist/skills/skills.module.js +5 -0
- package/dist/tools/approvals.service.d.ts +6 -0
- package/dist/tools/builtins/sandbox/bash.js +19 -4
- package/dist/tools/builtins/sandbox/common.d.ts +36 -6
- package/dist/tools/builtins/sandbox/common.js +69 -8
- package/dist/tools/builtins/sandbox/edit.js +2 -2
- package/dist/tools/builtins/sandbox/glob.js +3 -2
- package/dist/tools/builtins/sandbox/grep.js +2 -1
- package/dist/tools/builtins/sandbox/read.js +3 -3
- package/dist/tools/builtins/sandbox/write.js +2 -2
- package/dist/tools/builtins/skill-load.d.ts +47 -2
- package/dist/tools/builtins/skill-load.js +160 -2
- package/dist/tools/network-asks.d.ts +7 -0
- package/dist/tools/network-asks.js +11 -1
- package/dist/tools/pipeline.d.ts +1 -1
- package/dist/tools/pipeline.js +60 -9
- package/dist/tools/registry.d.ts +6 -0
- package/package.json +2 -2
- package/src/migrations/0133_project_root.sql +30 -0
- package/src/migrations/0134_org_cloud_network_delta.sql +38 -0
package/bootstrap.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"schemaVersion": 1,
|
|
4
4
|
"marketplace": {
|
|
5
5
|
"url": "https://github.com/capybara-hq/plugins.git",
|
|
6
|
-
"commit": "
|
|
6
|
+
"commit": "85aaf6598bee6f27ed9da9836084e2295eb29e03"
|
|
7
7
|
},
|
|
8
8
|
"plugins": [
|
|
9
9
|
{
|
|
@@ -90,8 +90,8 @@
|
|
|
90
90
|
"name": "sandbox-docker",
|
|
91
91
|
"source": "npm",
|
|
92
92
|
"npm": "@capybara-hq/plugin-sandbox-docker",
|
|
93
|
-
"version": "0.1.0-rc.
|
|
94
|
-
"integrity": "sha512-
|
|
93
|
+
"version": "0.1.0-rc.16",
|
|
94
|
+
"integrity": "sha512-6LQ9TA4wRbqYJ7cfzYXrD4A+ICBvwDck9QmREal7M9kneO/Bb25hoSPsBpCxJT8/d6K+Gg7gmUd3+8rsueHeKg==",
|
|
95
95
|
"required": false
|
|
96
96
|
},
|
|
97
97
|
{
|
|
@@ -188,7 +188,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
|
|
|
188
188
|
/** The host versions (an entry's `minKernel` is judged against them). */
|
|
189
189
|
export declare const HOST_VERSIONS: {
|
|
190
190
|
readonly kernel: string;
|
|
191
|
-
readonly sdk: "0.1.0-rc.
|
|
191
|
+
readonly sdk: "0.1.0-rc.24";
|
|
192
192
|
};
|
|
193
193
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
194
194
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
|
@@ -265,12 +265,14 @@ export declare class CatalogRequestsService {
|
|
|
265
265
|
private writeDecision;
|
|
266
266
|
/**
|
|
267
267
|
* Approves a `network_allowlist` request inside its decision's transaction: the hosts the org's
|
|
268
|
-
* sandbox allowlist does not hold yet are added to the
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
* list
|
|
272
|
-
*
|
|
273
|
-
* spec K1).
|
|
268
|
+
* sandbox allowlist does not hold yet are added to the org's `cloudNetwork` delta (an extra
|
|
269
|
+
* host, or out of the exclusions for a platform host the org had dropped), through
|
|
270
|
+
* {@link OrgSettingsService.update} (audited `org.settings_updated` with `requestId`). The
|
|
271
|
+
* platform's list is never copied, so the org keeps following it (org egress ceiling spec §D1).
|
|
272
|
+
* The org's network mode is kept: the hosts cap local sandbox devices, and approving a host
|
|
273
|
+
* never turns an open cloud network into an allowlist (auto mode hardening spec K1). A host
|
|
274
|
+
* beyond the platform's ceiling (`orgHosts: within`) refuses the whole request. The platform
|
|
275
|
+
* kill switch, more
|
|
274
276
|
* than {@link ORG_SANDBOX_ALLOW_HOSTS_MAX} hosts -> `catalog.request_invalid`; decided with an API
|
|
275
277
|
* token -> `org.sandbox_egress_not_allowed` (only a person widens the network). Hosts all allowed
|
|
276
278
|
* already: nothing is written.
|
|
@@ -24,7 +24,7 @@ import { orgAllows } from "../local-devices/network-grants.js";
|
|
|
24
24
|
import { OrgLock } from "../orgs/org-lock.js";
|
|
25
25
|
import { roleAtLeast } from "../orgs/roles.js";
|
|
26
26
|
import { ORG_SANDBOX_ALLOW_HOSTS_MAX, OrgSettingsService, readOrgSettings, } from "../orgs/settings.service.js";
|
|
27
|
-
import {
|
|
27
|
+
import { orgEffectiveHosts, orgHostOutsideCeiling } from "../sandbox/modes.js";
|
|
28
28
|
import { CatalogService } from "./catalog.service.js";
|
|
29
29
|
import { CatalogScopeService } from "./catalog-scope.service.js";
|
|
30
30
|
import { assertEntryNotDeprecated, loadMarketplaceEntry } from "./marketplaces.service.js";
|
|
@@ -43,19 +43,16 @@ const alreadyDecided = () => new ApiError("catalog.request_decided", "This reque
|
|
|
43
43
|
const pendingExists = () => new ApiError("catalog.request_pending", "This organization already has a pending request of this kind for it");
|
|
44
44
|
const deploymentEgressNone = () => new ApiError("catalog.request_invalid", "The platform turned sandbox network off; only a super admin can turn it on");
|
|
45
45
|
/**
|
|
46
|
-
* The allowlist the organization's sandbox-mode devices reach (
|
|
47
|
-
* hosts
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* its network ask tells the person to ask an admin about must be addable (network ask spec §5.3).
|
|
46
|
+
* The allowlist the organization's sandbox-mode devices reach (org egress ceiling spec §D3): the
|
|
47
|
+
* org's effective hosts, whatever its cloud mode. An open cloud network does not make a host
|
|
48
|
+
* "already allowed": a local device in sandbox mode always receives the allowlist, so a host its
|
|
49
|
+
* network ask tells the person to ask an admin about must be addable (network ask spec §5.3).
|
|
51
50
|
*/
|
|
52
|
-
function sandboxAllowlist(
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
kind: "allowlist",
|
|
56
|
-
hosts: network.kind === "allowlist" ? network.hosts : (org?.allowHosts ?? deployment.allowHosts),
|
|
57
|
-
};
|
|
51
|
+
function sandboxAllowlist(limits, org) {
|
|
52
|
+
return { kind: "allowlist", hosts: orgEffectiveHosts(limits, org) };
|
|
58
53
|
}
|
|
54
|
+
/** Hosts beyond the platform's ceiling: only a super admin adds them (spec §D2). */
|
|
55
|
+
const outsideCeiling = (hosts) => new ApiError("catalog.request_invalid", `The platform limits sandbox hosts to its allowlist; only a super admin can add ${hosts.join(", ")} (sandbox.limits.allowHosts)`);
|
|
59
56
|
/** A unique violation (the partial index of pending requests). */
|
|
60
57
|
const isUniqueViolation = (e) => typeof e === "object" && e !== null && e.code === "23505";
|
|
61
58
|
/** The deployment-level kinds (decided by the super admin). */
|
|
@@ -215,14 +212,17 @@ let CatalogRequestsService = class CatalogRequestsService {
|
|
|
215
212
|
const t = this.db;
|
|
216
213
|
await this.orgLock.lockAndAuthorize(orgId, actor, "catalog.request");
|
|
217
214
|
const hosts = [...new Set(input.hosts.map((h) => h.toLowerCase()))].sort();
|
|
218
|
-
|
|
215
|
+
const limits = this.config.get().sandbox.limits;
|
|
216
|
+
if (limits.egress === "none")
|
|
219
217
|
throw deploymentEgressNone();
|
|
220
|
-
const deployment = (await this.orgSettings.deployment()).cloudNetwork;
|
|
221
218
|
const settings = await readOrgSettings(t, orgId);
|
|
222
|
-
const network = sandboxAllowlist(
|
|
219
|
+
const network = sandboxAllowlist(limits, settings.cloudNetwork);
|
|
223
220
|
if (hosts.every((h) => orgAllows(h, { network }))) {
|
|
224
221
|
throw new ApiError("catalog.request_invalid", "This organization's sandbox network already allows these hosts; nothing to request");
|
|
225
222
|
}
|
|
223
|
+
const beyond = hosts.filter((h) => orgHostOutsideCeiling(limits, h));
|
|
224
|
+
if (beyond.length > 0)
|
|
225
|
+
throw outsideCeiling(beyond);
|
|
226
226
|
if (input.conversationId !== undefined) {
|
|
227
227
|
const c = await t
|
|
228
228
|
.selectFrom("conversations")
|
|
@@ -621,36 +621,59 @@ let CatalogRequestsService = class CatalogRequestsService {
|
|
|
621
621
|
}
|
|
622
622
|
/**
|
|
623
623
|
* Approves a `network_allowlist` request inside its decision's transaction: the hosts the org's
|
|
624
|
-
* sandbox allowlist does not hold yet are added to the
|
|
625
|
-
*
|
|
626
|
-
*
|
|
627
|
-
* list
|
|
628
|
-
*
|
|
629
|
-
* spec K1).
|
|
624
|
+
* sandbox allowlist does not hold yet are added to the org's `cloudNetwork` delta (an extra
|
|
625
|
+
* host, or out of the exclusions for a platform host the org had dropped), through
|
|
626
|
+
* {@link OrgSettingsService.update} (audited `org.settings_updated` with `requestId`). The
|
|
627
|
+
* platform's list is never copied, so the org keeps following it (org egress ceiling spec §D1).
|
|
628
|
+
* The org's network mode is kept: the hosts cap local sandbox devices, and approving a host
|
|
629
|
+
* never turns an open cloud network into an allowlist (auto mode hardening spec K1). A host
|
|
630
|
+
* beyond the platform's ceiling (`orgHosts: within`) refuses the whole request. The platform
|
|
631
|
+
* kill switch, more
|
|
630
632
|
* than {@link ORG_SANDBOX_ALLOW_HOSTS_MAX} hosts -> `catalog.request_invalid`; decided with an API
|
|
631
633
|
* token -> `org.sandbox_egress_not_allowed` (only a person widens the network). Hosts all allowed
|
|
632
634
|
* already: nothing is written.
|
|
633
635
|
*/
|
|
634
636
|
async approveNetwork(orgId, actor, requestId, detail, opts) {
|
|
635
637
|
const hosts = detail?.hosts ?? [];
|
|
636
|
-
|
|
638
|
+
const limits = this.config.get().sandbox.limits;
|
|
639
|
+
if (limits.egress === "none")
|
|
637
640
|
throw deploymentEgressNone();
|
|
638
|
-
const deployment = (await this.orgSettings.deployment()).cloudNetwork;
|
|
639
641
|
const current = (await readOrgSettings(this.db, orgId)).cloudNetwork;
|
|
640
642
|
// the hosts the org's sandbox-mode devices reach now (an open cloud network still gives them
|
|
641
643
|
// the allowlist: a host their network ask names must be addable)
|
|
642
|
-
const network = sandboxAllowlist(
|
|
644
|
+
const network = sandboxAllowlist(limits, current);
|
|
643
645
|
const missing = hosts.filter((h) => !orgAllows(h, { network }));
|
|
644
646
|
if (missing.length === 0)
|
|
645
647
|
return;
|
|
646
|
-
|
|
647
|
-
const
|
|
648
|
-
if (
|
|
649
|
-
throw
|
|
648
|
+
// the whole request is refused when a host is beyond the platform's ceiling (never partly)
|
|
649
|
+
const beyond = missing.filter((h) => orgHostOutsideCeiling(limits, h));
|
|
650
|
+
if (beyond.length > 0)
|
|
651
|
+
throw outsideCeiling(beyond);
|
|
652
|
+
// a delta, never a copy of the platform's list: a host the org had dropped from the platform's
|
|
653
|
+
// list comes back out of the exclusions (base platform), any other becomes an extra
|
|
654
|
+
const excluded = current?.excludedHosts ?? [];
|
|
655
|
+
const platformBase = (current?.base ?? "platform") === "platform";
|
|
656
|
+
const readmit = platformBase
|
|
657
|
+
? missing.filter((h) => excluded.includes(h) && limits.allowHosts.includes(h))
|
|
658
|
+
: [];
|
|
659
|
+
const added = missing.filter((h) => !readmit.includes(h));
|
|
660
|
+
const extraHosts = [...new Set([...(current?.extraHosts ?? []), ...added])];
|
|
661
|
+
if (extraHosts.length > ORG_SANDBOX_ALLOW_HOSTS_MAX) {
|
|
662
|
+
throw new ApiError("catalog.request_invalid", `The organization's sandbox allowlist would exceed ${ORG_SANDBOX_ALLOW_HOSTS_MAX} extra hosts; remove some in the organization settings first`);
|
|
650
663
|
}
|
|
664
|
+
const excludedHosts = excluded.filter((h) => !readmit.includes(h));
|
|
665
|
+
// the stored value is sent back whole with the hosts changed; the mode is never written
|
|
666
|
+
// (approving a host never turns an open cloud network into an allowlist, K1)
|
|
667
|
+
const cloudNetwork = {
|
|
668
|
+
...current,
|
|
669
|
+
...(extraHosts.length > 0 ? { extraHosts } : {}),
|
|
670
|
+
...(excludedHosts.length > 0 ? { excludedHosts } : {}),
|
|
671
|
+
};
|
|
672
|
+
if (excludedHosts.length === 0)
|
|
673
|
+
delete cloudNetwork.excludedHosts;
|
|
651
674
|
// approving widens the org's network allowlist: only a person in a session does that, never an
|
|
652
675
|
// API token (auto mode spec §4.3; the Platform tool has no decide operation at all)
|
|
653
|
-
await this.orgSettings.update(orgId, { cloudNetwork
|
|
676
|
+
await this.orgSettings.update(orgId, { cloudNetwork }, actor, opts.actorTokenId, { requestId }, { onlyNarrows: opts.actorTokenId !== undefined });
|
|
654
677
|
}
|
|
655
678
|
/**
|
|
656
679
|
* The requester dismisses a decided request from the inbox (`POST /orgs/:orgId/
|
|
@@ -24,31 +24,6 @@ export declare const DEDUPE_PENDING_TTL_SECONDS = 60;
|
|
|
24
24
|
export declare const messageDedupeKey: (connectionId: string, messageId: string) => string;
|
|
25
25
|
/** 带平台事件 id 的卡片点击的去重键(Ruling A26,Redis 键,可以含 `:`)。 */
|
|
26
26
|
export declare const actionDedupeKey: (connectionId: string, eventId: string) => string;
|
|
27
|
-
/**
|
|
28
|
-
* 渠道入站(Ruling A21:持久化处理)。
|
|
29
|
-
* - `onEvent`(插件 `connect` 的回调,必须快):消息按 `capk:channel-msg:<连接>:<消息>` `SET NX` 24 小时去重,
|
|
30
|
-
* 再排一个入站任务(`inbound-<连接>-<消息 id 哈希>`)后返回;入队失败删掉去重键并抛错(插件不确认,平台重投)。
|
|
31
|
-
* 带 `eventId` 的卡片操作同样按 `capk:channel-act:<连接>:<eventId>` 去重(任务 id 由 eventId 哈希,Ruling A26),
|
|
32
|
-
* 不带的直接入队(任务 id 随机);`directory_changed` 只是投递一个通讯录同步任务,就地完成。
|
|
33
|
-
* 返回即「内核已持久接收」:插件此后才向平台确认。
|
|
34
|
-
* - `handle`(worker 上执行入站任务):失败抛错由 BullMQ 指数退避重试(共 5 次;插件在本副本未加载时推迟、
|
|
35
|
-
* 回复报 auth / target_gone 时不重试);写用户消息带 `clientMessageId = "<连接>:<消息>"`,回复带由
|
|
36
|
-
* `<连接>-<消息 id>-reply` 哈希的幂等键,重试不会重复写 / 重复回复。步骤:
|
|
37
|
-
* 1. 连接停用、所属组织已删除或插件在该组织停用 → 什么都不做;群聊未 @ 机器人 → 忽略;
|
|
38
|
-
* 2. 发言人按 `<插件>:<租户>` + externalId 纯查找账号(不建账号、不合并),且须是连接所属组织的活跃成员;
|
|
39
|
-
* 否则按连接的未绑定策略:`bind` → 私聊回绑定卡片(群里只提示去私聊,绑定链接不能发在群里)、
|
|
40
|
-
* 已绑定但非成员回提示;`anonymous` → 仅当绑定的 agent 全组织可见、且发言人与连接同一租户时用该组织的
|
|
41
|
-
* 匿名访客(外部租户的人只能绑定),否则回提示。识别不出发言人时绝不借用连接创建者或任何人的身份;
|
|
42
|
-
* 3. 私聊 `/new` → 归档当前对话行并回「已开始新对话」;
|
|
43
|
-
* 4. 按话题找或建会话,写用户消息,记下投递目标并投递出站任务(Task 11)。A message whose text
|
|
44
|
-
* (bot mention stripped) is `/name args` is posted as a skill invocation (phase D spec §9): the
|
|
45
|
-
* same kernel path as the web, so the skill is resolved among the connection's agent's skills
|
|
46
|
-
* for the bound person; a refusal (`skill.not_invocable`: unknown, not user-invocable, gone
|
|
47
|
-
* since; `validation_failed`: over the limits) posts the text as typed, so nothing is lost.
|
|
48
|
-
* `directory_changed` → 投递通讯录同步(Task 12);`card_action` 见 actions.ts。
|
|
49
|
-
* 边界(已接受):同一 chat 的连续消息由不同任务并发处理,极少数情况下写入顺序可能与平台顺序不同;
|
|
50
|
-
* 处理在写入用户消息之后失败而重试时,固定话术 / 卡片回复可能再发一次。
|
|
51
|
-
*/
|
|
52
27
|
export declare class ChannelInbound {
|
|
53
28
|
private readonly kdb;
|
|
54
29
|
private readonly redis;
|
package/dist/channels/inbound.js
CHANGED
|
@@ -60,11 +60,31 @@ export const actionDedupeKey = (connectionId, eventId) => `capk:channel-act:${co
|
|
|
60
60
|
* (bot mention stripped) is `/name args` is posted as a skill invocation (phase D spec §9): the
|
|
61
61
|
* same kernel path as the web, so the skill is resolved among the connection's agent's skills
|
|
62
62
|
* for the bound person; a refusal (`skill.not_invocable`: unknown, not user-invocable, gone
|
|
63
|
-
* since; `validation_failed`: over the limits) posts the text as typed, so nothing is lost
|
|
63
|
+
* since; `validation_failed`: over the limits) posts the text as typed, so nothing is lost; a
|
|
64
|
+
* project skill the project cannot serve (`skill.project_unavailable`) is refused with its
|
|
65
|
+
* reason and nothing is posted.
|
|
64
66
|
* `directory_changed` → 投递通讯录同步(Task 12);`card_action` 见 actions.ts。
|
|
65
67
|
* 边界(已接受):同一 chat 的连续消息由不同任务并发处理,极少数情况下写入顺序可能与平台顺序不同;
|
|
66
68
|
* 处理在写入用户消息之后失败而重试时,固定话术 / 卡片回复可能再发一次。
|
|
67
69
|
*/
|
|
70
|
+
/** The note for a `skill.project_unavailable` refusal, by its reason. */
|
|
71
|
+
function projectSkillPhrase(err) {
|
|
72
|
+
const reason = err.details?.[0]?.reason;
|
|
73
|
+
switch (reason) {
|
|
74
|
+
case "gone":
|
|
75
|
+
return "projectSkillGone";
|
|
76
|
+
case "outside_mode":
|
|
77
|
+
return "projectSkillOutsideMode";
|
|
78
|
+
case "unparsable":
|
|
79
|
+
return "projectSkillUnparsable";
|
|
80
|
+
case "unsupported":
|
|
81
|
+
return "projectSkillUnsupported";
|
|
82
|
+
case "removed":
|
|
83
|
+
return "projectSkillRemoved";
|
|
84
|
+
default:
|
|
85
|
+
return "projectSkillUnreadable";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
68
88
|
let ChannelInbound = class ChannelInbound {
|
|
69
89
|
kdb;
|
|
70
90
|
redis;
|
|
@@ -270,6 +290,11 @@ let ChannelInbound = class ChannelInbound {
|
|
|
270
290
|
}
|
|
271
291
|
}
|
|
272
292
|
catch (err) {
|
|
293
|
+
// a project skill the project cannot serve now: say why, post nothing (project root §4.6)
|
|
294
|
+
if (err instanceof ApiError && err.code === "skill.project_unavailable") {
|
|
295
|
+
await reply(projectSkillPhrase(err));
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
273
298
|
// agent 已对此人不可用(改了可见范围 / 已删除):会话按不存在处理
|
|
274
299
|
if (err instanceof ApiError && err.code === "conversation.not_found") {
|
|
275
300
|
await reply("agentUnavailable");
|
|
@@ -175,6 +175,34 @@ export declare const CHANNEL_PHRASES: {
|
|
|
175
175
|
readonly zh: "技能没有运行:参数或技能内容过长。你的消息已按普通文本发送。";
|
|
176
176
|
readonly en: "The skill was not run: its arguments or instructions are too long. Your message was sent as plain text.";
|
|
177
177
|
};
|
|
178
|
+
/**
|
|
179
|
+
* Project root spec §4.6: `/project:<name>` named a skill of the conversation's project, but the
|
|
180
|
+
* kernel refused it (`skill.project_unavailable`, one phrase per reason); nothing was posted.
|
|
181
|
+
*/
|
|
182
|
+
readonly projectSkillGone: {
|
|
183
|
+
readonly zh: "项目技能没有运行:项目或它的 SKILL.md 已不在设备上。你的消息没有发送。";
|
|
184
|
+
readonly en: "The project skill was not run: the project is no longer on the device. Your message was not sent.";
|
|
185
|
+
};
|
|
186
|
+
readonly projectSkillOutsideMode: {
|
|
187
|
+
readonly zh: "项目技能没有运行:设备当前的运行模式读不到它。你的消息没有发送。";
|
|
188
|
+
readonly en: "The project skill was not run: the device's current mode cannot read it. Your message was not sent.";
|
|
189
|
+
};
|
|
190
|
+
readonly projectSkillUnreadable: {
|
|
191
|
+
readonly zh: "项目技能没有运行:读取设备上的 SKILL.md 失败,请稍后重试。你的消息没有发送。";
|
|
192
|
+
readonly en: "The project skill was not run: reading its SKILL.md on the device failed; try again later. Your message was not sent.";
|
|
193
|
+
};
|
|
194
|
+
readonly projectSkillUnparsable: {
|
|
195
|
+
readonly zh: "项目技能没有运行:它的 SKILL.md 格式不正确,请在项目里修正。你的消息没有发送。";
|
|
196
|
+
readonly en: "The project skill was not run: its SKILL.md is not valid; fix it in the project. Your message was not sent.";
|
|
197
|
+
};
|
|
198
|
+
readonly projectSkillUnsupported: {
|
|
199
|
+
readonly zh: "项目技能没有运行:这台设备不支持项目。你的消息没有发送。";
|
|
200
|
+
readonly en: "The project skill was not run: this device does not support projects. Your message was not sent.";
|
|
201
|
+
};
|
|
202
|
+
readonly projectSkillRemoved: {
|
|
203
|
+
readonly zh: "项目技能没有运行:这个项目已从设备的项目中移除。你的消息没有发送。";
|
|
204
|
+
readonly en: "The project skill was not run: the project was removed from the device's projects. Your message was not sent.";
|
|
205
|
+
};
|
|
178
206
|
/** 运行被中止(收尾挂着的草稿时附在已有文本之后)。 */
|
|
179
207
|
readonly runStopped: {
|
|
180
208
|
readonly zh: "已停止。";
|
package/dist/channels/phrases.js
CHANGED
|
@@ -137,6 +137,34 @@ export const CHANNEL_PHRASES = {
|
|
|
137
137
|
zh: "技能没有运行:参数或技能内容过长。你的消息已按普通文本发送。",
|
|
138
138
|
en: "The skill was not run: its arguments or instructions are too long. Your message was sent as plain text.",
|
|
139
139
|
},
|
|
140
|
+
/**
|
|
141
|
+
* Project root spec §4.6: `/project:<name>` named a skill of the conversation's project, but the
|
|
142
|
+
* kernel refused it (`skill.project_unavailable`, one phrase per reason); nothing was posted.
|
|
143
|
+
*/
|
|
144
|
+
projectSkillGone: {
|
|
145
|
+
zh: "项目技能没有运行:项目或它的 SKILL.md 已不在设备上。你的消息没有发送。",
|
|
146
|
+
en: "The project skill was not run: the project is no longer on the device. Your message was not sent.",
|
|
147
|
+
},
|
|
148
|
+
projectSkillOutsideMode: {
|
|
149
|
+
zh: "项目技能没有运行:设备当前的运行模式读不到它。你的消息没有发送。",
|
|
150
|
+
en: "The project skill was not run: the device's current mode cannot read it. Your message was not sent.",
|
|
151
|
+
},
|
|
152
|
+
projectSkillUnreadable: {
|
|
153
|
+
zh: "项目技能没有运行:读取设备上的 SKILL.md 失败,请稍后重试。你的消息没有发送。",
|
|
154
|
+
en: "The project skill was not run: reading its SKILL.md on the device failed; try again later. Your message was not sent.",
|
|
155
|
+
},
|
|
156
|
+
projectSkillUnparsable: {
|
|
157
|
+
zh: "项目技能没有运行:它的 SKILL.md 格式不正确,请在项目里修正。你的消息没有发送。",
|
|
158
|
+
en: "The project skill was not run: its SKILL.md is not valid; fix it in the project. Your message was not sent.",
|
|
159
|
+
},
|
|
160
|
+
projectSkillUnsupported: {
|
|
161
|
+
zh: "项目技能没有运行:这台设备不支持项目。你的消息没有发送。",
|
|
162
|
+
en: "The project skill was not run: this device does not support projects. Your message was not sent.",
|
|
163
|
+
},
|
|
164
|
+
projectSkillRemoved: {
|
|
165
|
+
zh: "项目技能没有运行:这个项目已从设备的项目中移除。你的消息没有发送。",
|
|
166
|
+
en: "The project skill was not run: the project was removed from the device's projects. Your message was not sent.",
|
|
167
|
+
},
|
|
140
168
|
/** 运行被中止(收尾挂着的草稿时附在已有文本之后)。 */
|
|
141
169
|
runStopped: { zh: "已停止。", en: "Stopped." },
|
|
142
170
|
/** 运行失败。 */
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -241,6 +241,10 @@ export declare const KernelConfigSchema: z.ZodObject<{
|
|
|
241
241
|
none: "none";
|
|
242
242
|
}>>;
|
|
243
243
|
allowHosts: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
244
|
+
orgHosts: z.ZodDefault<z.ZodEnum<{
|
|
245
|
+
extend: "extend";
|
|
246
|
+
within: "within";
|
|
247
|
+
}>>;
|
|
244
248
|
}, z.core.$strip>>;
|
|
245
249
|
}, z.core.$strip>>;
|
|
246
250
|
devices: z.ZodPrefault<z.ZodObject<{
|
package/dist/config/schema.js
CHANGED
|
@@ -1337,7 +1337,13 @@ export const KernelConfigSchema = z.object({
|
|
|
1337
1337
|
});
|
|
1338
1338
|
})
|
|
1339
1339
|
.meta(meta({
|
|
1340
|
-
description: "
|
|
1340
|
+
description: "Host list of the allowlist: in sandbox mode, the hosts a cloud device instance may reach on allowlist and a local device's allowlist; organizations follow it, adding or dropping hosts of their own (see orgHosts); lowercase hostnames, optional leading '*.', no IPs, ports or internal-only names; applies to instances created after the change",
|
|
1341
|
+
})),
|
|
1342
|
+
orgHosts: z
|
|
1343
|
+
.enum(["extend", "within"])
|
|
1344
|
+
.default("extend")
|
|
1345
|
+
.meta(meta({
|
|
1346
|
+
description: "Whether organizations may go beyond allowHosts in sandbox mode: extend (the default: an organization may use the open cloud network and add hosts, and its admins approve network requests) or within (allowHosts is the ceiling: an organization's cloud network in sandbox mode is the allowlist, and it may only keep or drop hosts the list covers; only a super admin adds others). Auto mode is not limited by it: devices.autoMode governs auto mode's open network, so set devices.autoMode off as well for a hard ceiling",
|
|
1341
1347
|
})),
|
|
1342
1348
|
})
|
|
1343
1349
|
.prefault({}),
|
|
@@ -79,11 +79,14 @@ declare const MessageBody: z.ZodObject<{
|
|
|
79
79
|
* first send; `clientMessageId` is required and makes a retry return the same conversation).
|
|
80
80
|
* Without it the conversation is created empty (API clients; the web never does).
|
|
81
81
|
* `deviceId` binds it to one of the caller's devices; without it the caller's default
|
|
82
|
-
* device (environments spec §4.1 item 1).
|
|
82
|
+
* device (environments spec §4.1 item 1). `project` binds it to one of that device's projects
|
|
83
|
+
* (project root design §4.3; the device's owner only, refused when the device's current mode
|
|
84
|
+
* cannot read it); without it the conversation runs in free mode.
|
|
83
85
|
*/
|
|
84
86
|
declare const CreateBody: z.ZodObject<{
|
|
85
87
|
agentId: z.ZodString;
|
|
86
88
|
deviceId: z.ZodOptional<z.ZodString>;
|
|
89
|
+
project: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
|
|
87
90
|
message: z.ZodOptional<z.ZodObject<{
|
|
88
91
|
text: z.ZodString;
|
|
89
92
|
attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
+
import { isDeviceProjectName } from "@capybara-hq/plugin-sdk";
|
|
10
11
|
import { Controller, Delete, Get, Header, HttpCode, Inject, Param, Patch, Post, Res, } from "@nestjs/common";
|
|
11
12
|
import { z } from "zod";
|
|
12
13
|
import { ModelRef } from "../agents/definition.js";
|
|
@@ -107,12 +108,20 @@ const MessageBody = MessageFields.strict().refine(...textRule);
|
|
|
107
108
|
* first send; `clientMessageId` is required and makes a retry return the same conversation).
|
|
108
109
|
* Without it the conversation is created empty (API clients; the web never does).
|
|
109
110
|
* `deviceId` binds it to one of the caller's devices; without it the caller's default
|
|
110
|
-
* device (environments spec §4.1 item 1).
|
|
111
|
+
* device (environments spec §4.1 item 1). `project` binds it to one of that device's projects
|
|
112
|
+
* (project root design §4.3; the device's owner only, refused when the device's current mode
|
|
113
|
+
* cannot read it); without it the conversation runs in free mode.
|
|
111
114
|
*/
|
|
112
115
|
const CreateBody = z
|
|
113
116
|
.object({
|
|
114
117
|
agentId: z.string().min(1).max(100),
|
|
115
118
|
deviceId: z.string().min(1).max(100).optional(),
|
|
119
|
+
project: z
|
|
120
|
+
.string()
|
|
121
|
+
.refine(isDeviceProjectName, {
|
|
122
|
+
message: "A project name is 1-64 characters, not . or .., without / or control characters, and without leading or trailing spaces",
|
|
123
|
+
})
|
|
124
|
+
.optional(),
|
|
116
125
|
message: MessageFields.omit({ retryOf: true })
|
|
117
126
|
.extend({ clientMessageId: z.string().min(1).max(200) })
|
|
118
127
|
.strict()
|
|
@@ -189,7 +198,10 @@ let ConversationsController = class ConversationsController {
|
|
|
189
198
|
*/
|
|
190
199
|
async create(principal, org, body, reply) {
|
|
191
200
|
const p = requireUser(principal);
|
|
192
|
-
const pick =
|
|
201
|
+
const pick = {
|
|
202
|
+
...(body.deviceId !== undefined && { deviceId: body.deviceId }),
|
|
203
|
+
...(body.project !== undefined && { project: body.project }),
|
|
204
|
+
};
|
|
193
205
|
if (body.message === undefined) {
|
|
194
206
|
return {
|
|
195
207
|
conversation: await this.conversations.create(org.orgId, p.account.id, body.agentId, pick, {
|
|
@@ -5,6 +5,7 @@ import type { AgentAvatar } from "../agents/profile.js";
|
|
|
5
5
|
import { BackgroundTaskStopper } from "../background/stop.js";
|
|
6
6
|
import type { TitleSource } from "../db/kernel-schema.js";
|
|
7
7
|
import { ConversationDevices, type NewConversationDevice } from "../devices/conversation-devices.js";
|
|
8
|
+
import { DeviceProjectsService } from "../devices/device-projects.service.js";
|
|
8
9
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
9
10
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
10
11
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
@@ -50,12 +51,35 @@ export interface ConversationView {
|
|
|
50
51
|
deviceId: string | null;
|
|
51
52
|
/** The scheduled task that created it (a `new`-mode task's run); null otherwise (spec §4). */
|
|
52
53
|
scheduledTaskId: string | null;
|
|
54
|
+
/**
|
|
55
|
+
* The device project it is bound to (project root spec §4.3: chosen at creation, never
|
|
56
|
+
* changed), as resolved then: its name and absolute path on the device; null in free mode (a
|
|
57
|
+
* sub-agent's is null too: it works in its root conversation's).
|
|
58
|
+
*/
|
|
59
|
+
project: {
|
|
60
|
+
name: string;
|
|
61
|
+
path: string;
|
|
62
|
+
} | null;
|
|
63
|
+
/**
|
|
64
|
+
* The latest `project_root` snapshot of its log (project root spec §4.7), however far back:
|
|
65
|
+
* `loaded` with whether the project's `AGENTS.md` was found, or the reason the project is
|
|
66
|
+
* `unavailable`; null when no run start has recorded one (a free conversation, a bound one before
|
|
67
|
+
* its first run). Single-conversation responses compute it; the list queries carry null.
|
|
68
|
+
*/
|
|
69
|
+
projectState: ProjectState | null;
|
|
53
70
|
/**
|
|
54
71
|
* What the latest run is doing: `running` (queued or running), `waiting` (an approval or a
|
|
55
72
|
* question), else null. Only the list queries compute it; other responses carry null.
|
|
56
73
|
*/
|
|
57
74
|
activity: "running" | "waiting" | null;
|
|
58
75
|
}
|
|
76
|
+
/** The state a conversation's latest `project_root` event records ({@link ConversationView}). */
|
|
77
|
+
export type ProjectState = {
|
|
78
|
+
loaded: true;
|
|
79
|
+
agentsMd: boolean;
|
|
80
|
+
} | {
|
|
81
|
+
unavailable: "gone" | "outside_mode" | "unreadable" | "unsupported" | "removed";
|
|
82
|
+
};
|
|
59
83
|
/** Escapes `\`, `%` and `_` so user text is matched literally by `LIKE … ESCAPE '\'`. */
|
|
60
84
|
export declare function escapeLike(s: string): string;
|
|
61
85
|
/** One agent's group in the sidebar list: the caller's newest conversations with that agent. */
|
|
@@ -267,6 +291,8 @@ export declare class ConversationsService {
|
|
|
267
291
|
private readonly background;
|
|
268
292
|
/** The device a new conversation is bound to (environments spec §4.1 item 1). */
|
|
269
293
|
private readonly devices;
|
|
294
|
+
/** The project of that device a new conversation is bound to (project root design §4.3). */
|
|
295
|
+
private readonly projects;
|
|
270
296
|
/** A starter's message skips the run's pending questions (reply-while-question spec §8.1). */
|
|
271
297
|
private readonly questions;
|
|
272
298
|
/** ... and its pending network asks (network ask-to-allow spec §6.7). */
|
|
@@ -288,6 +314,8 @@ export declare class ConversationsService {
|
|
|
288
314
|
background: Pick<BackgroundTaskStopper, "stopForDeletedConversation">,
|
|
289
315
|
/** The device a new conversation is bound to (environments spec §4.1 item 1). */
|
|
290
316
|
devices: Pick<ConversationDevices, "forNew">,
|
|
317
|
+
/** The project of that device a new conversation is bound to (project root design §4.3). */
|
|
318
|
+
projects: Pick<DeviceProjectsService, "resolveForBinding">,
|
|
291
319
|
/** A starter's message skips the run's pending questions (reply-while-question spec §8.1). */
|
|
292
320
|
questions: Pick<QuestionsService, "skipPendingIn">,
|
|
293
321
|
/** ... and its pending network asks (network ask-to-allow spec §6.7). */
|
|
@@ -296,8 +324,9 @@ export declare class ConversationsService {
|
|
|
296
324
|
* Creates an empty conversation bound to its device (`pick`, see
|
|
297
325
|
* {@link ConversationDevices.forNew}); an agent the account cannot use →
|
|
298
326
|
* `agent.not_found`, a device it may not use → `device.not_found` /
|
|
299
|
-
* `device.unavailable`, and nothing is created. `
|
|
300
|
-
*
|
|
327
|
+
* `device.unavailable`, and nothing is created. `pick.project` binds it to one of that device's
|
|
328
|
+
* projects ({@link bindingFor}), refused as that says. `opts.source` records where the
|
|
329
|
+
* conversation comes from.
|
|
301
330
|
*/
|
|
302
331
|
create(orgId: string, accountId: string, agentId: string, pick: NewConversationDevice | undefined, opts: NewConversationOptions): Promise<ConversationView>;
|
|
303
332
|
/**
|
|
@@ -309,7 +338,9 @@ export declare class ConversationsService {
|
|
|
309
338
|
* `events` are every event the create wrote, in seq order from seq 1 (a `model_switched` before
|
|
310
339
|
* the message when the send switched), so a client can seed the new conversation's log whole.
|
|
311
340
|
* `internal`: the conversation's source and, for kernel callers only, a scheduled task's marker,
|
|
312
|
-
* which also sets `conversations.scheduled_task_id`, and its zone override.
|
|
341
|
+
* which also sets `conversations.scheduled_task_id`, and its zone override. `pick.project` binds
|
|
342
|
+
* the conversation to one of its device's projects inside the write ({@link bindingFor}); a
|
|
343
|
+
* retry answers with the conversation the first send created, its binding unchanged.
|
|
313
344
|
*/
|
|
314
345
|
createWithMessage(orgId: string, accountId: string, agentId: string, input: UserMessageInput & {
|
|
315
346
|
clientMessageId: string;
|
|
@@ -321,6 +352,15 @@ export declare class ConversationsService {
|
|
|
321
352
|
}>;
|
|
322
353
|
/** The conversation row and its first message (undefined: a concurrent retry committed first). */
|
|
323
354
|
private createIn;
|
|
355
|
+
/**
|
|
356
|
+
* The project a new conversation binds to (project root design §4.3): `name` resolved against
|
|
357
|
+
* the chosen device's projects by `DeviceProjectsService.resolveForBinding`, which reads only and
|
|
358
|
+
* checks the owner and the device's current mode (refused with `device.not_found`,
|
|
359
|
+
* `device.projects_unsupported`, `device.project_not_found` or `device.project_outside_mode`).
|
|
360
|
+
* Called inside the transaction that writes the conversation. A conversation without a device
|
|
361
|
+
* (no cloud provider, an anonymous IM sender) cannot have one. Undefined name: free mode.
|
|
362
|
+
*/
|
|
363
|
+
private bindingFor;
|
|
324
364
|
/**
|
|
325
365
|
* The conversation (and its first event) an earlier first send with this id created. The id used
|
|
326
366
|
* for another agent's conversation → `conflict` (the caller only checked access to `agentId`, so
|