@chibitek/chibi 0.1.193 → 0.1.195
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/assets/{TerminalPanel-BtDirrJJ.js → TerminalPanel-ColKaJYW.js} +1 -1
- package/dist/assets/{abnfDiagram-O67JEVCF-C37-IeyR.js → abnfDiagram-O67JEVCF-3Ob4zw74.js} +1 -1
- package/dist/assets/{arc-glzbadrM.js → arc-HPFapNIH.js} +1 -1
- package/dist/assets/{architectureDiagram-NJMV4G6O-Bcx1rmTd.js → architectureDiagram-NJMV4G6O-DkCwaZOT.js} +1 -1
- package/dist/assets/{blockDiagram-BEXU5L5S-B6KUNaLE.js → blockDiagram-BEXU5L5S-BimJc2cp.js} +1 -1
- package/dist/assets/{c4Diagram-YGBWAQC7-DZ__tNnZ.js → c4Diagram-YGBWAQC7-RwjFYoqV.js} +1 -1
- package/dist/assets/channel-CCkmsk9Z.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-Dn-yLeEA.js → chunk-2Q5K7J3B-KYH4VNAA.js} +1 -1
- package/dist/assets/{chunk-3FUC2YCW-BB0MhLD8.js → chunk-3FUC2YCW-CoGh3EJb.js} +2 -2
- package/dist/assets/{chunk-5VM5RSS4-B0MU1Lq4.js → chunk-5VM5RSS4-BWgviAjX.js} +1 -1
- package/dist/assets/{chunk-GTNCS2PH-BmT88VI9.js → chunk-GTNCS2PH-Ddlqcpyc.js} +1 -1
- package/dist/assets/{chunk-GWA4HPMP-hgdMCsOk.js → chunk-GWA4HPMP-RV94Cbaa.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-zlkz0m7Z.js → chunk-JWPE2WC7-B0BTZ6sh.js} +1 -1
- package/dist/assets/{chunk-NETBCI7D-Dz15-399.js → chunk-NETBCI7D-CfcSF9jy.js} +1 -1
- package/dist/assets/{chunk-WEXAMYUT-CrWvQLTH.js → chunk-WEXAMYUT-srnz312I.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-BRuLbyd6.js → chunk-XXDRQBXY-C4vdFU17.js} +1 -1
- package/dist/assets/{classDiagram-v2-NBCMYWYE-BoexnyNG.js → classDiagram-v2-NBCMYWYE-DNy2vFs-.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-CPTjVRUh.js → cose-bilkent-JH36ORCC-D0i9E7vP.js} +1 -1
- package/dist/assets/{cynefin-OW5HDTMX-DtqtEAnC.js → cynefin-OW5HDTMX-gkAOk-jI.js} +1 -1
- package/dist/assets/{cynefinDiagram-VND7K2PF-BVP8JLg8.js → cynefinDiagram-VND7K2PF-Q4524mSo.js} +1 -1
- package/dist/assets/{dagre-6A5THRUB-BBDMxGXp.js → dagre-6A5THRUB-Bzq01xjc.js} +1 -1
- package/dist/assets/{diagram-22UHCM2B-BRZ8cAsI.js → diagram-22UHCM2B-Cm5DPMsm.js} +1 -1
- package/dist/assets/{diagram-3UASUU5V-D3lhs7ty.js → diagram-3UASUU5V-6tnEN2tD.js} +1 -1
- package/dist/assets/{diagram-ATOU4E4O-n8v1YvKt.js → diagram-ATOU4E4O-Ce8MaZqL.js} +1 -1
- package/dist/assets/{diagram-CDSNMT55-B6jeaO-z.js → diagram-CDSNMT55-DmxP3ZT3.js} +1 -1
- package/dist/assets/{diagram-MLGK6HIB-BLmKtNgD.js → diagram-MLGK6HIB-BG4kwPCS.js} +1 -1
- package/dist/assets/{diagram-MPIPVDR6-CNWlEkJQ.js → diagram-MPIPVDR6-BnLYiwBc.js} +1 -1
- package/dist/assets/{ebnfDiagram-ZINNZB2B-C0uBXIgJ.js → ebnfDiagram-ZINNZB2B-Dd19Rw8P.js} +1 -1
- package/dist/assets/{elk-276RUBZZ-DCjvJpgP.js → elk-276RUBZZ-B2-jAuba.js} +1 -1
- package/dist/assets/{erDiagram-OPXOYQCR-BryVWOsq.js → erDiagram-OPXOYQCR-CVXqmXQ8.js} +1 -1
- package/dist/assets/{flowDiagram-KWPJA3E3-Cq-t83b3.js → flowDiagram-KWPJA3E3-RrANAUuT.js} +1 -1
- package/dist/assets/{ganttDiagram-FUAMR5RP-4vyfI4a8.js → ganttDiagram-FUAMR5RP-C5vGW4y-.js} +1 -1
- package/dist/assets/{gitGraphDiagram-X574FWY7-DxZIWlPq.js → gitGraphDiagram-X574FWY7-BHvq9YfO.js} +1 -1
- package/dist/assets/{index-C2Rnf5Lg.js → index-1PLvu0_F.js} +1 -1
- package/dist/assets/{index-DtMmBnv1.js → index-DQQGKX5x.js} +158 -158
- package/dist/assets/{infoDiagram-VRGFBTTK-CdS4oDZm.js → infoDiagram-VRGFBTTK-DvuzWS54.js} +1 -1
- package/dist/assets/{ishikawaDiagram-OU5B5YK6-7FJ6XPAt.js → ishikawaDiagram-OU5B5YK6-cCkUTtkg.js} +1 -1
- package/dist/assets/{journeyDiagram-ZHPQQLJL-DK5jSuP5.js → journeyDiagram-ZHPQQLJL-B0RmSvGs.js} +1 -1
- package/dist/assets/{kanban-definition-PNTS6WVX-LSLVTPp1.js → kanban-definition-PNTS6WVX-xbVsCFqa.js} +1 -1
- package/dist/assets/{linear-C8T48PcW.js → linear-ChjewIA3.js} +1 -1
- package/dist/assets/{mermaid.core-CajU6Pki.js → mermaid.core-s9HcmFG6.js} +5 -5
- package/dist/assets/{mindmap-definition-NLK3R4M7-26gQ6jip.js → mindmap-definition-NLK3R4M7-DyOdKH03.js} +1 -1
- package/dist/assets/{pegDiagram-GJSIUBJH-rvhqKdDP.js → pegDiagram-GJSIUBJH-CIvAV7Do.js} +1 -1
- package/dist/assets/{pieDiagram-5QR66LMP-BOFsvwEp.js → pieDiagram-5QR66LMP-wPi-yl9z.js} +1 -1
- package/dist/assets/{quadrantDiagram-O4NWA36T-BGd_kb8s.js → quadrantDiagram-O4NWA36T-SBFfoKYC.js} +1 -1
- package/dist/assets/{railroadDiagram-XR7U4H2S-DROi1ea2.js → railroadDiagram-XR7U4H2S-Otwi150n.js} +1 -1
- package/dist/assets/{requirementDiagram-PLB6GJNP-BLFC_C4R.js → requirementDiagram-PLB6GJNP-D8He2y9Y.js} +1 -1
- package/dist/assets/{sankeyDiagram-IPEJSGJF-bCdrWFYF.js → sankeyDiagram-IPEJSGJF-Z39wdwHB.js} +1 -1
- package/dist/assets/{sequenceDiagram-PO4LG4MO-CaCPCA52.js → sequenceDiagram-PO4LG4MO-ELX5hqvT.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-DZr2YdGO.js → sizeCapture-INFHLROL-BDeFl-HY.js} +1 -1
- package/dist/assets/{stateDiagram-v2-GCMORJYK-BymY8iLv.js → stateDiagram-v2-GCMORJYK-DUbETp8f.js} +1 -1
- package/dist/assets/{swimlanes-2SLR337P-NumTJ1tl.js → swimlanes-2SLR337P-D3WtSrRL.js} +1 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX-cEw5_whO.js +8 -0
- package/dist/assets/{timeline-definition-EJHVYXUP-d9-CUPKk.js → timeline-definition-EJHVYXUP-C4s78-PG.js} +1 -1
- package/dist/assets/{usecaseDiagram-POWQR4AR-CGvoockc.js → usecaseDiagram-POWQR4AR-D6Gf3aB1.js} +1 -1
- package/dist/assets/{vennDiagram-UO4OBE2U-CUkwrnK7.js → vennDiagram-UO4OBE2U-RMzQilxk.js} +1 -1
- package/dist/assets/{wardleyDiagram-VNRHLVJA-DALQej81.js → wardleyDiagram-VNRHLVJA-B9YM9a43.js} +1 -1
- package/dist/assets/{xychartDiagram-PMCCYNJV-2oukzPo1.js → xychartDiagram-PMCCYNJV-D7GxLZwD.js} +1 -1
- package/dist/index.html +1 -1
- package/dist-server/container-mcp.js +81 -81
- package/dist-server/drivers/agents-proxy.js +81 -81
- package/dist-server/index.js +642 -516
- package/dist-server/openmausbot.js +566 -566
- package/dist-server/pair-cli.js +566 -566
- package/dist-server/server/index.js +2 -3
- package/dist-server/server/routes/team-rooms.js +5 -1
- package/dist-server/server/team-rooms/host.js +4 -0
- package/dist-server/server/team-rooms/installation.js +83 -0
- package/dist-server/server/team-rooms/service.js +51 -12
- package/dist-server/server/team-rooms/testing/fake-rooms-backend.js +3 -0
- package/dist-server/server/team-rooms/types.js +1 -0
- package/dist-server/server/workspace-backup.js +1 -1
- package/dist-server/shared/team-rooms.js +9 -0
- package/dist-server/vps-container-mcp.js +81 -81
- package/package.json +1 -1
- package/dist/assets/channel-C2UiHr1q.js +0 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX-CjJ-nT3Z.js +0 -8
|
@@ -298,7 +298,7 @@ import { applyChibiDefaults, chibiDefaultSelection } from "./chibi-defaults.js";
|
|
|
298
298
|
import { createPrimaryBotRoutes } from "./routes/primary-bot.js";
|
|
299
299
|
import { EngineSnapshotCache, botTier, canDriveComputer, classLadder, engineAccount, engineHealth, engineLabel, engineTierClasses, engineTierLadders, failoverClassOrder, engineTiersIncludeFree, generateLadders, handlesClientData, ladderForClass, keyBased, needsDelegation, resolveFailover, resolveLadder } from "./engine-tiers.js";
|
|
300
300
|
import { PRIMARY_BOT_THREAD_TITLE, PRIMARY_BOT_TRIGGER, PrimaryBotStore, routesAsSweep, PrimaryBotSweeper } from "./primary-bot.js";
|
|
301
|
-
import { PRIMARY_BOT_LOCKED, primaryBotChoiceField } from "../shared/primary-bot.js";
|
|
301
|
+
import { PRIMARY_BOT_LOCKED, primaryBotChoiceField, isPrimaryBot } from "../shared/primary-bot.js";
|
|
302
302
|
import { moveIntoChibi } from "./move-into-chibi.js";
|
|
303
303
|
import { MODEL_CLASSES, TIERS_THAT_MAY_DROP_A_CLASS, botEngineMode, isBotTier, modeClass, parseClassChoice, threadEngineMode } from "../shared/engine-tiers.js";
|
|
304
304
|
import { EngineRestStore } from "./engine-rest.js";
|
|
@@ -15633,8 +15633,7 @@ teamRoomsHost = new TeamRoomsHost({
|
|
|
15633
15633
|
dataDir: DATA_DIR,
|
|
15634
15634
|
enabled: () => teamRoomsEnabled(cfg),
|
|
15635
15635
|
localBots: () => store.bots.filter((bot) => !personalBotHidden(bot)).map((bot) => ({
|
|
15636
|
-
id: bot.id,
|
|
15637
|
-
name: bot.name,
|
|
15636
|
+
id: bot.id, name: bot.name, primary: isPrimaryBot(bot),
|
|
15638
15637
|
private: isPersonalBot(bot),
|
|
15639
15638
|
hipaa: bot.hipaa === true || workspaceHipaa().enabled,
|
|
15640
15639
|
})),
|
|
@@ -71,6 +71,10 @@ export function createTeamRoomsRoutes(deps) {
|
|
|
71
71
|
if (path === "/api/team-rooms" && method === "POST") {
|
|
72
72
|
const body = record(await readBody(req, 16_000));
|
|
73
73
|
const title = typeof body.title === "string" ? body.title : "";
|
|
74
|
+
if (body.kind !== undefined && body.kind !== "channel" && body.kind !== "room")
|
|
75
|
+
return json(res, 400, { error: "Unknown room type.", code: "bad_request" });
|
|
76
|
+
if (body.kind === "channel" && body.share !== undefined)
|
|
77
|
+
return json(res, 400, { error: "Channels start without private conversation history.", code: "bad_request" });
|
|
74
78
|
const share = record(body.share);
|
|
75
79
|
if (body.share !== undefined) {
|
|
76
80
|
const botId = typeof share.botId === "string" && LOCAL_ID.test(share.botId) ? share.botId : null;
|
|
@@ -82,7 +86,7 @@ export function createTeamRoomsRoutes(deps) {
|
|
|
82
86
|
return json(res, 404, { error: "That conversation is not on this computer.", code: "not_found" });
|
|
83
87
|
return json(res, 200, await service.createRoom({ title, share: { localBotId: botId, threadId, history } }));
|
|
84
88
|
}
|
|
85
|
-
return json(res, 200, await service.createRoom({ title }));
|
|
89
|
+
return json(res, 200, await service.createRoom({ title, ...(body.kind === "channel" ? { kind: "channel" } : {}) }));
|
|
86
90
|
}
|
|
87
91
|
if (path === "/api/team-rooms/join/preview" && method === "POST") {
|
|
88
92
|
const body = record(await readBody(req, 4_096));
|
|
@@ -8,6 +8,7 @@ import { randomUUID } from "node:crypto";
|
|
|
8
8
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
9
9
|
import { join } from "node:path";
|
|
10
10
|
import { onStikiSessionChange, setStikiSessionSource, stikiSession } from "../stiki-session.js";
|
|
11
|
+
import { ChannelInstallation } from "./installation.js";
|
|
11
12
|
import { RoomsBackend } from "./backend.js";
|
|
12
13
|
import { TeamRoomsService } from "./service.js";
|
|
13
14
|
/** Longest a room turn may take before the room is told it did not finish. */
|
|
@@ -20,10 +21,12 @@ export class TeamRoomsHost {
|
|
|
20
21
|
svc = null;
|
|
21
22
|
installId;
|
|
22
23
|
backend;
|
|
24
|
+
installation;
|
|
23
25
|
deps;
|
|
24
26
|
constructor(deps) {
|
|
25
27
|
this.deps = deps;
|
|
26
28
|
this.installId = loadInstallId(deps.dataDir);
|
|
29
|
+
this.installation = new ChannelInstallation(deps.dataDir, this.installId, stikiSession);
|
|
27
30
|
this.backend = deps.backend ?? new RoomsBackend({
|
|
28
31
|
url: process.env.ATOMIC_ROOMS_URL || undefined,
|
|
29
32
|
key: process.env.ATOMIC_ROOMS_KEY || undefined,
|
|
@@ -47,6 +50,7 @@ export class TeamRoomsHost {
|
|
|
47
50
|
installId: this.installId,
|
|
48
51
|
device: process.platform === "darwin" ? "mac" : process.platform === "win32" ? "windows" : "linux",
|
|
49
52
|
localBots: this.deps.localBots,
|
|
53
|
+
channelProof: (botId) => this.installation.proof(botId),
|
|
50
54
|
runTurn: (run) => this.runTurn(run),
|
|
51
55
|
notify: this.deps.notify,
|
|
52
56
|
changed: this.deps.changed,
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createHash, createPrivateKey, createPublicKey, generateKeyPairSync, randomBytes, sign } from "node:crypto";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { writeFileAtomic } from "../atomic.js";
|
|
5
|
+
/** Device identity is never backed up or returned to the renderer. Like the
|
|
6
|
+
* private-scope key, it is stored owner-readable only. This proves possession,
|
|
7
|
+
* not executable integrity; revocation must be checked on every room write. */
|
|
8
|
+
export class ChannelInstallation {
|
|
9
|
+
pending = new Map();
|
|
10
|
+
dataDir;
|
|
11
|
+
installId;
|
|
12
|
+
session;
|
|
13
|
+
request;
|
|
14
|
+
constructor(dataDir, installId, session, request = fetch) {
|
|
15
|
+
this.dataDir = dataDir;
|
|
16
|
+
this.installId = installId;
|
|
17
|
+
this.session = session;
|
|
18
|
+
this.request = request;
|
|
19
|
+
}
|
|
20
|
+
async proof(primaryBotId) {
|
|
21
|
+
const source = this.session();
|
|
22
|
+
const token = await source.accessToken();
|
|
23
|
+
const owner = source.identity()?.userId;
|
|
24
|
+
if (!token || !owner)
|
|
25
|
+
throw new Error("Sign in to Chibitek to use your Chibi in Channels.");
|
|
26
|
+
const dir = join(this.dataDir, "channel-identity");
|
|
27
|
+
const path = join(dir, `${createHash("sha256").update(owner).digest("hex")}.json`);
|
|
28
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
29
|
+
if (!existsSync(path)) {
|
|
30
|
+
const { privateKey } = generateKeyPairSync("ec", { namedCurve: "prime256v1" });
|
|
31
|
+
writeFileAtomic(path, JSON.stringify({ primaryBotId, keyId: randomBytes(16).toString("hex"), pem: privateKey.export({ type: "pkcs8", format: "pem" }) }), { mode: 0o600 });
|
|
32
|
+
}
|
|
33
|
+
const stored = JSON.parse(readFileSync(path, "utf8"));
|
|
34
|
+
if (stored.primaryBotId !== primaryBotId)
|
|
35
|
+
throw new Error("This installation is bound to a different primary Chibi. Revoke its binding before replacing it.");
|
|
36
|
+
const key = createPrivateKey(stored.pem);
|
|
37
|
+
const identifiers = [owner, this.installId, stored.keyId, primaryBotId, "primary_chibi"];
|
|
38
|
+
const signature = (lines) => sign("sha256", Buffer.from(lines.join("\n")), key).toString("base64");
|
|
39
|
+
const api = async (suffix, body) => {
|
|
40
|
+
const response = await this.request(`https://auth.chibitek.com/api/atomic-installations${suffix}`, {
|
|
41
|
+
method: body ? "POST" : "GET", headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
|
|
42
|
+
...(body ? { body: JSON.stringify(body) } : {}), redirect: "error", signal: AbortSignal.timeout(15_000),
|
|
43
|
+
});
|
|
44
|
+
if (response.status === 404 && !body)
|
|
45
|
+
return null;
|
|
46
|
+
if (!response.ok)
|
|
47
|
+
throw new Error(`Chibi installation verification failed (${response.status}). Sign in again or check the Channels service.`);
|
|
48
|
+
return await response.json();
|
|
49
|
+
};
|
|
50
|
+
// Serialize enrollment for simultaneous channel admissions. Every call still
|
|
51
|
+
// performs a live lookup; a revoked key is never silently replaced.
|
|
52
|
+
const previous = this.pending.get(owner) ?? Promise.resolve();
|
|
53
|
+
const enrollment = previous.catch(() => { }).then(async () => {
|
|
54
|
+
const current = await api(`?install_id=${encodeURIComponent(this.installId)}&key_id=${stored.keyId}`);
|
|
55
|
+
if (current) {
|
|
56
|
+
const binding = current.installation;
|
|
57
|
+
if (!binding || binding.revoked !== false || binding.user_id !== owner || binding.install_id !== this.installId || binding.key_id !== stored.keyId || binding.primary_bot_id !== primaryBotId || binding.role !== "primary_chibi") {
|
|
58
|
+
throw new Error("This Chibi installation binding is revoked or does not match this computer.");
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const challenge = await api("/challenge", { install_id: this.installId, key_id: stored.keyId, primary_bot_id: primaryBotId });
|
|
63
|
+
if (!challenge || challenge.user_id !== owner || challenge.install_id !== this.installId || challenge.key_id !== stored.keyId || challenge.primary_bot_id !== primaryBotId || challenge.role !== "primary_chibi" || typeof challenge.challenge !== "string" || typeof challenge.challenge_id !== "string") {
|
|
64
|
+
throw new Error("Chibi enrollment challenge did not match this installation.");
|
|
65
|
+
}
|
|
66
|
+
await api("", { challenge_id: challenge.challenge_id, public_key: createPublicKey(key).export({ type: "spki", format: "der" }).toString("base64"), signature: signature(["stiki.atomic-install-enroll.v1", ...identifiers, challenge.challenge]) });
|
|
67
|
+
});
|
|
68
|
+
this.pending.set(owner, enrollment);
|
|
69
|
+
try {
|
|
70
|
+
await enrollment;
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
if (this.pending.get(owner) === enrollment)
|
|
74
|
+
this.pending.delete(owner);
|
|
75
|
+
}
|
|
76
|
+
if (source !== this.session() || source.identity()?.userId !== owner)
|
|
77
|
+
throw new Error("Chibitek sign-in changed during verification.");
|
|
78
|
+
const nonce = randomBytes(24).toString("base64url");
|
|
79
|
+
const issuedAt = new Date().toISOString();
|
|
80
|
+
return { stiki_token: token, installation_proof: { install_id: this.installId, key_id: stored.keyId, audience: "atomic-rooms", nonce, issued_at: issuedAt,
|
|
81
|
+
signature: signature(["stiki.atomic-install-attest.v1", ...identifiers, "atomic-rooms", nonce, issuedAt]) } };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { randomUUID } from "node:crypto";
|
|
9
9
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
10
10
|
import { join } from "node:path";
|
|
11
|
-
import { PRESENCE_HEARTBEAT_MS, ROOM_MESSAGE_MAX, ROOM_TITLE_MAX, botAvailable, canAddBot, companyNames, inviteTokenFrom, isCrossCompany, mentionedBots,
|
|
11
|
+
import { PRESENCE_HEARTBEAT_MS, ROOM_MESSAGE_MAX, ROOM_TITLE_MAX, botAvailable, canAddBot, companyNames, inviteTokenFrom, isChannel, isCrossCompany, mentionedBots, roomSharePolicy, SHARE_CATEGORIES, } from "../../shared/team-rooms.js";
|
|
12
12
|
import { RoomsApiError } from "./backend.js";
|
|
13
13
|
import { RoomsRealtime } from "./realtime.js";
|
|
14
14
|
import { roomTurnText } from "./turn.js";
|
|
@@ -270,6 +270,7 @@ export class TeamRoomsService {
|
|
|
270
270
|
return {
|
|
271
271
|
id: state.room.id,
|
|
272
272
|
title: state.room.title,
|
|
273
|
+
kind: isChannel(state.room.source) ? "channel" : "room",
|
|
273
274
|
isOwner: mine?.role === "owner",
|
|
274
275
|
crossCompany: isCrossCompany(realms),
|
|
275
276
|
companies: companyNames(realms),
|
|
@@ -297,7 +298,7 @@ export class TeamRoomsService {
|
|
|
297
298
|
isMine: b.owner_user_id === me,
|
|
298
299
|
localBotId: b.owner_user_id === me && b.host_install_id === this.deps.installId && local.has(b.local_bot_id) ? b.local_bot_id : null,
|
|
299
300
|
available: botAvailable(this.presence.get(b.id) ?? null, now),
|
|
300
|
-
share:
|
|
301
|
+
share: roomSharePolicy(state.room.source, b.share_policy, crossCompany),
|
|
301
302
|
dailyTurnCap: b.daily_turn_cap,
|
|
302
303
|
})),
|
|
303
304
|
messages: state.messages.filter((m) => !m.deleted_at).map((m) => ({
|
|
@@ -314,6 +315,8 @@ export class TeamRoomsService {
|
|
|
314
315
|
// ── Actions ───────────────────────────────────────────────────────────
|
|
315
316
|
async createRoom(input) {
|
|
316
317
|
this.me();
|
|
318
|
+
if (input.kind === "channel" && input.share)
|
|
319
|
+
throw new RoomsApiError(400, "bad_request", "Channels start without private conversation history.");
|
|
317
320
|
const title = input.title.trim().slice(0, ROOM_TITLE_MAX);
|
|
318
321
|
if (!title)
|
|
319
322
|
throw new RoomsApiError(400, "bad_request", "Give the room a name.");
|
|
@@ -327,8 +330,14 @@ export class TeamRoomsService {
|
|
|
327
330
|
throw new RoomsApiError(403, "private_bot", "Your Private Bot stays out of Team Rooms.");
|
|
328
331
|
bot = { install_id: this.deps.installId, local_bot_id: local.id, bot_name: local.name, hipaa: local.hipaa, private: false };
|
|
329
332
|
}
|
|
333
|
+
if (input.kind === "channel") {
|
|
334
|
+
const capability = await this.deps.backend.api("channels/capabilities");
|
|
335
|
+
if (capability.version !== 1)
|
|
336
|
+
throw new RoomsApiError(409, "bad_request", "This server does not support Channels yet.");
|
|
337
|
+
}
|
|
330
338
|
const result = await this.deps.backend.api("rooms/create", {
|
|
331
339
|
title,
|
|
340
|
+
...(input.kind === "channel" ? { kind: "channel" } : {}),
|
|
332
341
|
...(input.share ? {
|
|
333
342
|
source: { installId: this.deps.installId, botId: input.share.localBotId, threadId: input.share.threadId },
|
|
334
343
|
bot,
|
|
@@ -377,7 +386,7 @@ export class TeamRoomsService {
|
|
|
377
386
|
throw new RoomsApiError(400, "invite_not_found", "This invite link is not valid.");
|
|
378
387
|
const result = await this.deps.backend.api("join", { token });
|
|
379
388
|
await this.sync();
|
|
380
|
-
return { roomId: result.room.id };
|
|
389
|
+
return { roomId: result.room.id, kind: this.detail(result.room.id)?.kind ?? "room" };
|
|
381
390
|
}
|
|
382
391
|
async leave(roomId) {
|
|
383
392
|
await this.deps.backend.api("leave", { room_id: roomId });
|
|
@@ -396,6 +405,9 @@ export class TeamRoomsService {
|
|
|
396
405
|
const local = this.deps.localBots().find((b) => b.id === localBotId);
|
|
397
406
|
if (!state || !local)
|
|
398
407
|
throw new RoomsApiError(404, "not_found", "That bot is not on this computer.");
|
|
408
|
+
if (isChannel(state.room.source) && local.primary !== true) {
|
|
409
|
+
throw new RoomsApiError(403, "bad_request", "Only your primary Chibi can join a channel.");
|
|
410
|
+
}
|
|
399
411
|
const decision = canAddBot(local, {
|
|
400
412
|
crossCompany: isCrossCompany(state.members.map((m) => ({ realm: m.realm, realmName: m.realm_name }))),
|
|
401
413
|
activeBots: state.bots.length,
|
|
@@ -403,7 +415,7 @@ export class TeamRoomsService {
|
|
|
403
415
|
});
|
|
404
416
|
if (!decision.ok)
|
|
405
417
|
throw new RoomsApiError(403, decision.code, decision.reason);
|
|
406
|
-
await this.deps.backend.api("bots/add", { room_id: roomId, install_id: this.deps.installId, local_bot_id: local.id, bot_name: local.name, hipaa: local.hipaa, private: false });
|
|
418
|
+
await this.deps.backend.api("bots/add", { ...await this.channelProof(roomId, local.id), room_id: roomId, install_id: this.deps.installId, local_bot_id: local.id, bot_name: local.name, hipaa: local.hipaa, private: false });
|
|
407
419
|
await this.sync();
|
|
408
420
|
void this.heartbeat();
|
|
409
421
|
}
|
|
@@ -417,7 +429,10 @@ export class TeamRoomsService {
|
|
|
417
429
|
if (!state || !bot || bot.owner_user_id !== this.me())
|
|
418
430
|
throw new RoomsApiError(403, "not_bot_owner", "Only the bot's owner changes what it may share.");
|
|
419
431
|
const crossCompany = isCrossCompany(state.members.map((m) => ({ realm: m.realm, realmName: m.realm_name })));
|
|
420
|
-
|
|
432
|
+
if (isChannel(state.room.source) && SHARE_CATEGORIES.some(key => patch.share?.[key] === true)) {
|
|
433
|
+
throw new RoomsApiError(403, "bad_request", "Private capabilities stay with their owner in Channels.");
|
|
434
|
+
}
|
|
435
|
+
const next = roomSharePolicy(state.room.source, bot.share_policy, crossCompany);
|
|
421
436
|
for (const key of SHARE_CATEGORIES)
|
|
422
437
|
if (typeof patch.share?.[key] === "boolean")
|
|
423
438
|
next[key] = patch.share[key];
|
|
@@ -492,14 +507,35 @@ export class TeamRoomsService {
|
|
|
492
507
|
}
|
|
493
508
|
}
|
|
494
509
|
}
|
|
510
|
+
async channelProof(roomId, botId) {
|
|
511
|
+
const state = this.rooms.get(roomId);
|
|
512
|
+
if (!state)
|
|
513
|
+
throw new Error("Room is no longer available.");
|
|
514
|
+
if (!isChannel(state.room.source))
|
|
515
|
+
return {};
|
|
516
|
+
if (!this.deps.localBots().some((bot) => bot.id === botId && bot.primary && !bot.private))
|
|
517
|
+
throw new Error("Only your primary Chibi can answer in Channels.");
|
|
518
|
+
if (!this.deps.channelProof)
|
|
519
|
+
throw new Error("Chibi installation verification is unavailable.");
|
|
520
|
+
return this.deps.channelProof(botId);
|
|
521
|
+
}
|
|
522
|
+
async turnProof(turnId) {
|
|
523
|
+
for (const state of this.rooms.values()) {
|
|
524
|
+
const turn = state.turns.get(turnId);
|
|
525
|
+
const bot = turn && state.bots.find((entry) => entry.id === turn.bot_id);
|
|
526
|
+
if (bot)
|
|
527
|
+
return this.channelProof(state.room.id, bot.local_bot_id);
|
|
528
|
+
}
|
|
529
|
+
throw new Error("Room turn is no longer available.");
|
|
530
|
+
}
|
|
495
531
|
async finish(turnId, body, ok, usage) {
|
|
496
|
-
await this.deps.backend.api("turns/finish", { turn_id: turnId, install_id: this.deps.installId, body, status: ok ? "done" : "failed", ...(usage ? { usage } : {}) });
|
|
532
|
+
await this.deps.backend.api("turns/finish", { ...await this.turnProof(turnId), turn_id: turnId, install_id: this.deps.installId, body, status: ok ? "done" : "failed", ...(usage ? { usage } : {}) });
|
|
497
533
|
}
|
|
498
534
|
async runTurn(state, turn, bot) {
|
|
499
535
|
const local = this.deps.localBots().find((b) => b.id === bot.local_bot_id);
|
|
500
536
|
let claim;
|
|
501
537
|
try {
|
|
502
|
-
claim = await this.deps.backend.api("turns/claim", { turn_id: turn.id, install_id: this.deps.installId });
|
|
538
|
+
claim = await this.deps.backend.api("turns/claim", { ...await this.channelProof(state.room.id, bot.local_bot_id), turn_id: turn.id, install_id: this.deps.installId });
|
|
503
539
|
}
|
|
504
540
|
catch (error) {
|
|
505
541
|
console.warn(`[team-rooms] claim ${turn.id}: ${errorText(error)}`);
|
|
@@ -508,7 +544,7 @@ export class TeamRoomsService {
|
|
|
508
544
|
if (!claim.claimed)
|
|
509
545
|
return;
|
|
510
546
|
// Refused twice: Atomic here, the backend at add time.
|
|
511
|
-
if (!local || local.private) {
|
|
547
|
+
if (!local || local.private || (isChannel(state.room.source) && local.primary !== true)) {
|
|
512
548
|
await this.finish(turn.id, `${bot.display_name} is no longer available on its owner's computer.`, false).catch(() => { });
|
|
513
549
|
return;
|
|
514
550
|
}
|
|
@@ -527,7 +563,7 @@ export class TeamRoomsService {
|
|
|
527
563
|
roomTitle: state.room.title,
|
|
528
564
|
turnId: turn.id,
|
|
529
565
|
botDisplayName: bot.display_name,
|
|
530
|
-
share:
|
|
566
|
+
share: roomSharePolicy(state.room.source, bot.share_policy, crossCompany),
|
|
531
567
|
crossCompany,
|
|
532
568
|
requestedByOwner: turn.requested_by === bot.owner_user_id,
|
|
533
569
|
requestedByName,
|
|
@@ -537,9 +573,12 @@ export class TeamRoomsService {
|
|
|
537
573
|
.map((m) => ({ author: m.author_name || "Someone", body: m.body, kind: m.author_kind }));
|
|
538
574
|
const text = roomTurnText(lines, { from: requestedByName, body: trigger.body });
|
|
539
575
|
try {
|
|
540
|
-
await this.deps.backend.api("turns/status", { turn_id: turn.id, install_id: this.deps.installId, status: "running" });
|
|
576
|
+
await this.deps.backend.api("turns/status", { ...await this.channelProof(state.room.id, bot.local_bot_id), turn_id: turn.id, install_id: this.deps.installId, status: "running" });
|
|
577
|
+
}
|
|
578
|
+
catch {
|
|
579
|
+
if (isChannel(state.room.source))
|
|
580
|
+
return;
|
|
541
581
|
}
|
|
542
|
-
catch { /* status is informational */ }
|
|
543
582
|
let outcome;
|
|
544
583
|
try {
|
|
545
584
|
outcome = await this.deps.runTurn({ localBotId: local.id, restriction, text });
|
|
@@ -574,7 +613,7 @@ export class TeamRoomsService {
|
|
|
574
613
|
return;
|
|
575
614
|
try {
|
|
576
615
|
const result = await this.deps.backend.api("approvals/request", {
|
|
577
|
-
turn_id: run.turn.id, install_id: this.deps.installId, summary: summary.slice(0, 500) || "An action", action_hash: actionHash,
|
|
616
|
+
...await this.channelProof(run.turn.room_id, run.bot.local_bot_id), turn_id: run.turn.id, install_id: this.deps.installId, summary: summary.slice(0, 500) || "An action", action_hash: actionHash,
|
|
578
617
|
});
|
|
579
618
|
run.approvals.set(requestId, result.approval_id);
|
|
580
619
|
}
|
|
@@ -182,8 +182,11 @@ export class FakeRoomsBackend {
|
|
|
182
182
|
const turns = this.tables.room_turns;
|
|
183
183
|
const bots = this.tables.room_bots;
|
|
184
184
|
switch (route) {
|
|
185
|
+
case "channels/capabilities": return reply(200, { version: 1, chibiAdmission: false });
|
|
185
186
|
case "rooms/create": {
|
|
186
187
|
const id = this.addRoom(me, String(body.title));
|
|
188
|
+
if (body.kind === "channel")
|
|
189
|
+
this.tables.rooms.find(row => row.id === id).source = { kind: "channel" };
|
|
187
190
|
let botId = null;
|
|
188
191
|
const bot = body.bot;
|
|
189
192
|
if (bot) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -25,7 +25,7 @@ const ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}
|
|
|
25
25
|
const EXCLUDED = new Set([
|
|
26
26
|
".backups", "tools", "cache", ".cache", "tmp", ".tmp", "dist-native", "tunnel-runtime",
|
|
27
27
|
".openmausbot-server-child", "environment-id", "sessions.json", "tunnel-account.json",
|
|
28
|
-
"team-computers.json",
|
|
28
|
+
"team-computers.json", "channel-identity",
|
|
29
29
|
"openmausbot-server.lease", "box-create-requests.lock", "messages.db-wal", "messages.db-shm",
|
|
30
30
|
]);
|
|
31
31
|
/** Dependency and build folders a project reinstalls with one command. They
|
|
@@ -240,3 +240,12 @@ export function botAvailable(lastSeen, now) {
|
|
|
240
240
|
const at = typeof lastSeen === "number" ? lastSeen : Date.parse(lastSeen);
|
|
241
241
|
return Number.isFinite(at) && now - at <= PRESENCE_FRESH_MS;
|
|
242
242
|
}
|
|
243
|
+
/** Stored by rooms-api; legacy room sources have no channel marker. */
|
|
244
|
+
export function isChannel(source) {
|
|
245
|
+
return !!source && typeof source === "object" && !Array.isArray(source)
|
|
246
|
+
&& source.kind === "channel";
|
|
247
|
+
}
|
|
248
|
+
/** Channels never expose an owner's private capabilities through room sharing. */
|
|
249
|
+
export function roomSharePolicy(source, raw, crossCompany) {
|
|
250
|
+
return isChannel(source) ? { ...CROSS_COMPANY_SHARE } : sharePolicy(raw, crossCompany);
|
|
251
|
+
}
|