@vellumai/assistant 0.11.5-dev.202608220019.a778cf0 → 0.11.5-dev.202608230133.e60a5fb
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/node_modules/@vellumai/gateway-client/src/gateway-ipc-contracts.ts +49 -0
- package/node_modules/@vellumai/gateway-client/src/inbound-contract.ts +16 -1
- package/openapi.yaml +6 -0
- package/package.json +1 -1
- package/src/__tests__/channel-readiness-slack-remote.test.ts +141 -0
- package/src/__tests__/resolve-trust-class.test.ts +0 -48
- package/src/channels/gateway-channel-socket-health.ts +32 -0
- package/src/cli/commands/channels/__tests__/channels.test.ts +85 -0
- package/src/cli/commands/channels/index.ts +45 -31
- package/src/daemon/trust-context.ts +0 -37
- package/src/permissions/types.ts +3 -1
- package/src/runtime/channel-readiness-service.ts +83 -0
- package/src/runtime/routes/inbound-message-handler.ts +5 -2
- package/src/tools/types.ts +2 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Shared IPC contracts for assistant-to-gateway gateway-owned reads.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { CHANNEL_IDS } from "@vellumai/service-contracts/channels";
|
|
5
6
|
import { z } from "zod";
|
|
6
7
|
|
|
7
8
|
export const GATEWAY_LOG_LEVEL_NAMES = [
|
|
@@ -506,3 +507,51 @@ export const ClassifyRiskIpcResponseSchema = z.object({
|
|
|
506
507
|
export type ClassifyRiskIpcResponse = z.infer<
|
|
507
508
|
typeof ClassifyRiskIpcResponseSchema
|
|
508
509
|
>;
|
|
510
|
+
|
|
511
|
+
// ── Channel socket health ────────────────────────────────────────────────────
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Whether a channel that holds a long-lived inbound socket is currently
|
|
515
|
+
* receiving.
|
|
516
|
+
*
|
|
517
|
+
* Only channels whose ingress is a socket the gateway owns can answer this.
|
|
518
|
+
* Webhook channels answer the same question from the daemon side by checking
|
|
519
|
+
* their registration instead, so they report `unsupported` here rather than a
|
|
520
|
+
* misleading `disconnected`.
|
|
521
|
+
*/
|
|
522
|
+
export const CHANNEL_SOCKET_HEALTH_STATUSES = [
|
|
523
|
+
/** A live connection the liveness watchdog is vouching for. */
|
|
524
|
+
"connected",
|
|
525
|
+
/** The channel is configured and running, but holds no live connection. */
|
|
526
|
+
"disconnected",
|
|
527
|
+
/** No client exists, because the channel's credentials are not configured. */
|
|
528
|
+
"not_configured",
|
|
529
|
+
/** This channel's ingress is not a gateway-owned socket. */
|
|
530
|
+
"unsupported",
|
|
531
|
+
] as const;
|
|
532
|
+
|
|
533
|
+
export const ChannelSocketHealthIpcParamsSchema = z.object({
|
|
534
|
+
channel: z.enum(CHANNEL_IDS),
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
export type ChannelSocketHealthIpcParams = z.infer<
|
|
538
|
+
typeof ChannelSocketHealthIpcParamsSchema
|
|
539
|
+
>;
|
|
540
|
+
|
|
541
|
+
export const ChannelSocketHealthIpcResponseSchema = z.object({
|
|
542
|
+
channel: z.enum(CHANNEL_IDS),
|
|
543
|
+
status: z.enum(CHANNEL_SOCKET_HEALTH_STATUSES),
|
|
544
|
+
/**
|
|
545
|
+
* Epoch millis when the transport last proved it was alive, by whatever
|
|
546
|
+
* means that transport proves it: a pong on Slack, an op 11 ACK on Discord.
|
|
547
|
+
*
|
|
548
|
+
* Absent means "not proven yet", never "proven dead". A connection's first
|
|
549
|
+
* proof is one full interval after it opens, so a healthy reconnect reports
|
|
550
|
+
* `connected` with no timestamp. Corroborating evidence, not a verdict.
|
|
551
|
+
*/
|
|
552
|
+
lastLivenessAt: z.number().optional(),
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
export type ChannelSocketHealthIpcResponse = z.infer<
|
|
556
|
+
typeof ChannelSocketHealthIpcResponseSchema
|
|
557
|
+
>;
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
|
|
15
|
+
import { ChannelConversationTypeSchema } from "./channel-permission-contract.js";
|
|
16
|
+
|
|
15
17
|
import { AdmissionPolicySchema } from "./admission-policy-contract.js";
|
|
16
18
|
import { TrustVerdictSchema } from "./trust-verdict-contract.js";
|
|
17
19
|
|
|
@@ -37,8 +39,21 @@ export const SourceMetadataSchema = z
|
|
|
37
39
|
updateId: z.string().optional(),
|
|
38
40
|
/** Provider message ID (e.g. Slack message `ts`). */
|
|
39
41
|
messageId: z.string().optional(),
|
|
40
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Provider chat type (e.g. Telegram "private", "group"). Answers whether a
|
|
44
|
+
* room is multi-party, which drives group etiquette.
|
|
45
|
+
*/
|
|
41
46
|
chatType: z.string().optional(),
|
|
47
|
+
/**
|
|
48
|
+
* How visible the conversation is, on the permission matrix's axis, as
|
|
49
|
+
* decided by the sending channel's own normalizer. A different question
|
|
50
|
+
* from `chatType`: a group DM is multi-party and private, a public channel
|
|
51
|
+
* is multi-party and public.
|
|
52
|
+
*
|
|
53
|
+
* Absent means not established rather than public, so a permissive rule
|
|
54
|
+
* cannot reach a room whose visibility nobody proved.
|
|
55
|
+
*/
|
|
56
|
+
conversationType: ChannelConversationTypeSchema.optional(),
|
|
42
57
|
/** Thread/conversation-group ID (e.g. Slack `thread_ts`). */
|
|
43
58
|
threadId: z.string().optional(),
|
|
44
59
|
/** Channel name (e.g. Slack channel display name). */
|
package/openapi.yaml
CHANGED
package/package.json
CHANGED
|
@@ -29,6 +29,22 @@ mock.module("./channel-invite-transports/whatsapp.js", () => ({
|
|
|
29
29
|
resolveWhatsAppDisplayNumber: () => undefined,
|
|
30
30
|
}));
|
|
31
31
|
|
|
32
|
+
type SocketHealth = {
|
|
33
|
+
channel: string;
|
|
34
|
+
status: "connected" | "disconnected" | "not_configured" | "unsupported";
|
|
35
|
+
lastLivenessAt?: number;
|
|
36
|
+
};
|
|
37
|
+
let socketHealth: SocketHealth | Error;
|
|
38
|
+
|
|
39
|
+
mock.module("../channels/gateway-channel-socket-health.js", () => ({
|
|
40
|
+
readChannelSocketHealth: async () => {
|
|
41
|
+
if (socketHealth instanceof Error) {
|
|
42
|
+
throw socketHealth;
|
|
43
|
+
}
|
|
44
|
+
return socketHealth;
|
|
45
|
+
},
|
|
46
|
+
}));
|
|
47
|
+
|
|
32
48
|
const originalFetch = globalThis.fetch;
|
|
33
49
|
let fetchCalls: Array<{ url: string; init?: RequestInit }>;
|
|
34
50
|
let fetchHandler: (
|
|
@@ -42,6 +58,7 @@ beforeEach(() => {
|
|
|
42
58
|
setConfig("slack", {});
|
|
43
59
|
fetchCalls = [];
|
|
44
60
|
fetchHandler = () => ({ ok: true, body: { ok: true } });
|
|
61
|
+
socketHealth = { channel: "slack", status: "connected" };
|
|
45
62
|
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
46
63
|
const url = typeof input === "string" ? input : input.toString();
|
|
47
64
|
fetchCalls.push({ url, init });
|
|
@@ -295,3 +312,127 @@ describe("slack scope-grant check", () => {
|
|
|
295
312
|
expect(scopeCheck.passed).toBe(true);
|
|
296
313
|
});
|
|
297
314
|
});
|
|
315
|
+
|
|
316
|
+
describe("slack inbound delivery", () => {
|
|
317
|
+
/**
|
|
318
|
+
* Credential health and delivery health are different claims. Valid tokens,
|
|
319
|
+
* a reachable `auth.test` and a matching workspace all hold while a socket
|
|
320
|
+
* sits open and delivers nothing, so the delivery verdict must not ride on
|
|
321
|
+
* any of them.
|
|
322
|
+
*/
|
|
323
|
+
test("fails on a dead socket even while auth.test passes", async () => {
|
|
324
|
+
// Both tokens, or the channel is not fully configured and "incomplete" is
|
|
325
|
+
// the correct answer rather than the one under test.
|
|
326
|
+
mockSecureKeys[credentialKey("slack_channel", "bot_token")] = "xoxb-fake";
|
|
327
|
+
mockSecureKeys[credentialKey("slack_channel", "app_token")] = "xapp-fake";
|
|
328
|
+
setConfig("slack", { teamId: "T123" });
|
|
329
|
+
fetchHandler = () => ({
|
|
330
|
+
ok: true,
|
|
331
|
+
body: { ok: true, team_id: "T123", team: "acme", user: "apollobot" },
|
|
332
|
+
});
|
|
333
|
+
socketHealth = { channel: "slack", status: "disconnected" };
|
|
334
|
+
|
|
335
|
+
const [snapshot] = await runSlackRemoteProbe();
|
|
336
|
+
const authTest = (snapshot.remoteChecks ?? []).find(
|
|
337
|
+
(c) => c.name === "auth_test",
|
|
338
|
+
)!;
|
|
339
|
+
const delivery = snapshot.localChecks.find(
|
|
340
|
+
(c) => c.name === "inbound_delivery",
|
|
341
|
+
)!;
|
|
342
|
+
|
|
343
|
+
expect(authTest.passed).toBe(true);
|
|
344
|
+
expect(delivery.passed).toBe(false);
|
|
345
|
+
expect(delivery.indeterminate).toBeFalsy();
|
|
346
|
+
expect(delivery.message).toMatch(/not reaching this assistant/i);
|
|
347
|
+
// The point of declaring it operational: a configured channel whose
|
|
348
|
+
// socket is dead is down, not half set up.
|
|
349
|
+
expect(snapshot.setupStatus).toBe("ready");
|
|
350
|
+
expect(snapshot.health).toBe("failing");
|
|
351
|
+
expect(snapshot.ready).toBe(false);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test("passes on a live socket and reports the last keepalive", async () => {
|
|
355
|
+
socketHealth = {
|
|
356
|
+
channel: "slack",
|
|
357
|
+
status: "connected",
|
|
358
|
+
lastLivenessAt: Date.parse("2026-08-21T17:00:00.000Z"),
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const [snapshot] = await runSlackRemoteProbe();
|
|
362
|
+
const delivery = snapshot.localChecks.find(
|
|
363
|
+
(c) => c.name === "inbound_delivery",
|
|
364
|
+
)!;
|
|
365
|
+
|
|
366
|
+
expect(delivery.passed).toBe(true);
|
|
367
|
+
expect(delivery.message).toContain("2026-08-21T17:00:00.000Z");
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test("a freshly opened socket passes before its first keepalive", async () => {
|
|
371
|
+
// The first probe is a full interval after open, so requiring a keepalive
|
|
372
|
+
// would report every healthy reconnect as broken.
|
|
373
|
+
socketHealth = { channel: "slack", status: "connected" };
|
|
374
|
+
|
|
375
|
+
const [snapshot] = await runSlackRemoteProbe();
|
|
376
|
+
const delivery = snapshot.localChecks.find(
|
|
377
|
+
(c) => c.name === "inbound_delivery",
|
|
378
|
+
)!;
|
|
379
|
+
|
|
380
|
+
expect(delivery.passed).toBe(true);
|
|
381
|
+
expect(delivery.message).toMatch(/no keepalive answered yet/i);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
test("an unconfigured channel is indeterminate, not broken", async () => {
|
|
385
|
+
socketHealth = { channel: "slack", status: "not_configured" };
|
|
386
|
+
|
|
387
|
+
const [snapshot] = await runSlackRemoteProbe();
|
|
388
|
+
const delivery = snapshot.localChecks.find(
|
|
389
|
+
(c) => c.name === "inbound_delivery",
|
|
390
|
+
)!;
|
|
391
|
+
|
|
392
|
+
expect(delivery.indeterminate).toBe(true);
|
|
393
|
+
expect(delivery.passed).toBe(true);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
test("an unreachable gateway is indeterminate, not an outage", async () => {
|
|
397
|
+
// A gateway we cannot reach is a fact about the gateway. Rendering it as
|
|
398
|
+
// "Slack is disconnected" would invent an outage.
|
|
399
|
+
socketHealth = new Error("gateway socket refused");
|
|
400
|
+
|
|
401
|
+
const [snapshot] = await runSlackRemoteProbe();
|
|
402
|
+
const delivery = snapshot.localChecks.find(
|
|
403
|
+
(c) => c.name === "inbound_delivery",
|
|
404
|
+
)!;
|
|
405
|
+
|
|
406
|
+
expect(delivery.indeterminate).toBe(true);
|
|
407
|
+
expect(delivery.passed).toBe(true);
|
|
408
|
+
expect(delivery.message).toMatch(/could not reach the gateway/i);
|
|
409
|
+
// Unknown, not failing: an unreachable gateway is a fact about the
|
|
410
|
+
// gateway, and the channel must be neither vouched for nor condemned.
|
|
411
|
+
expect(snapshot.health).toBe("unknown");
|
|
412
|
+
expect(snapshot.ready).toBe(false);
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
test("runs on every request rather than riding the remote-check cache", async () => {
|
|
416
|
+
// Remote checks are cached for five minutes, which is far longer than a
|
|
417
|
+
// socket takes to die and recover, so a cached verdict would report a
|
|
418
|
+
// state the connection has already left. One service instance across both
|
|
419
|
+
// reads, or the cache under test is never populated in the first place.
|
|
420
|
+
const { createReadinessService } =
|
|
421
|
+
await import("../runtime/channel-readiness-service.js");
|
|
422
|
+
const service = createReadinessService();
|
|
423
|
+
const delivery = (
|
|
424
|
+
snapshots: Awaited<ReturnType<typeof service.getReadiness>>,
|
|
425
|
+
) => snapshots[0].localChecks.find((c) => c.name === "inbound_delivery")!;
|
|
426
|
+
|
|
427
|
+
socketHealth = { channel: "slack", status: "connected" };
|
|
428
|
+
expect(delivery(await service.getReadiness("slack", true)).passed).toBe(
|
|
429
|
+
true,
|
|
430
|
+
);
|
|
431
|
+
|
|
432
|
+
// Same service, so the remote checks beside this one are now cached.
|
|
433
|
+
socketHealth = { channel: "slack", status: "disconnected" };
|
|
434
|
+
expect(delivery(await service.getReadiness("slack", true)).passed).toBe(
|
|
435
|
+
false,
|
|
436
|
+
);
|
|
437
|
+
});
|
|
438
|
+
});
|
|
@@ -13,7 +13,6 @@ mock.module("../config/env.js", () => ({
|
|
|
13
13
|
|
|
14
14
|
import {
|
|
15
15
|
FALLBACK_TURN_TRUST,
|
|
16
|
-
mapChatTypeToConversationType,
|
|
17
16
|
resolveTrustClass,
|
|
18
17
|
} from "../daemon/trust-context.js";
|
|
19
18
|
import type { TrustContext } from "../daemon/trust-context-types.js";
|
|
@@ -73,50 +72,3 @@ describe("resolveTrustClass", () => {
|
|
|
73
72
|
expect(resolveTrustClass(FALLBACK_TURN_TRUST)).toBe("unknown");
|
|
74
73
|
});
|
|
75
74
|
});
|
|
76
|
-
|
|
77
|
-
describe("mapChatTypeToConversationType", () => {
|
|
78
|
-
test("maps DM-shaped chat types to dm", () => {
|
|
79
|
-
expect(mapChatTypeToConversationType("im")).toBe("dm"); // Slack DM
|
|
80
|
-
expect(mapChatTypeToConversationType("private")).toBe("dm"); // Telegram DM
|
|
81
|
-
expect(mapChatTypeToConversationType("dm")).toBe("dm"); // Discord DM
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test("every DM-capable channel's own word for a DM lands on the axis", () => {
|
|
85
|
-
// A missing arm is silent rather than loud: the permission cell stays
|
|
86
|
-
// settable, because the adapter validates against the channel registry,
|
|
87
|
-
// and simply never matches. The guardian sets a rule for DMs on that
|
|
88
|
-
// channel and it does nothing. Stated as a sweep so adding a DM-capable
|
|
89
|
-
// channel without its arm fails here.
|
|
90
|
-
const dmChatTypeByChannel = {
|
|
91
|
-
slack: "im",
|
|
92
|
-
telegram: "private",
|
|
93
|
-
whatsapp: "private",
|
|
94
|
-
discord: "dm",
|
|
95
|
-
};
|
|
96
|
-
for (const [channel, chatType] of Object.entries(dmChatTypeByChannel)) {
|
|
97
|
-
expect(`${channel}:${mapChatTypeToConversationType(chatType)}`).toBe(
|
|
98
|
-
`${channel}:dm`,
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test("maps closed-group chat types to private", () => {
|
|
104
|
-
expect(mapChatTypeToConversationType("mpim")).toBe("private"); // Slack multi-party DM
|
|
105
|
-
expect(mapChatTypeToConversationType("group")).toBe("private");
|
|
106
|
-
expect(mapChatTypeToConversationType("supergroup")).toBe("private");
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test("maps Slack 'channel' to undefined — public and private are indistinguishable", () => {
|
|
110
|
-
// The gateway forwards every non-DM Slack conversation as "channel"
|
|
111
|
-
// without a public/private distinction. Mapping it to "public" would let
|
|
112
|
-
// a permissive public-channel matrix cell govern private channels, so
|
|
113
|
-
// the channel-type tier must not match at all.
|
|
114
|
-
expect(mapChatTypeToConversationType("channel")).toBeUndefined();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test("maps unknown or absent chat types to undefined", () => {
|
|
118
|
-
expect(mapChatTypeToConversationType(undefined)).toBeUndefined();
|
|
119
|
-
expect(mapChatTypeToConversationType("")).toBeUndefined();
|
|
120
|
-
expect(mapChatTypeToConversationType("broadcast")).toBeUndefined();
|
|
121
|
-
});
|
|
122
|
-
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daemon-side reader for whether a socket-backed channel is receiving.
|
|
3
|
+
*
|
|
4
|
+
* The gateway holds the inbound sockets; the readiness surface that reports
|
|
5
|
+
* channel health to the user lives here. This is the relay between them.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
type ChannelSocketHealthIpcParams,
|
|
10
|
+
type ChannelSocketHealthIpcResponse,
|
|
11
|
+
ChannelSocketHealthIpcResponseSchema,
|
|
12
|
+
} from "@vellumai/gateway-client/gateway-ipc-contracts";
|
|
13
|
+
|
|
14
|
+
import { ipcCallPersistentValidated } from "../ipc/gateway-validated-call.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Ask the gateway whether `channel`'s inbound socket is live.
|
|
18
|
+
*
|
|
19
|
+
* Throws on transport failure rather than reporting a channel as down: an
|
|
20
|
+
* unreachable gateway is a fact about the gateway, and a caller that renders
|
|
21
|
+
* it as "Slack is disconnected" would be inventing an outage. Callers are
|
|
22
|
+
* expected to treat a throw as indeterminate.
|
|
23
|
+
*/
|
|
24
|
+
export async function readChannelSocketHealth(
|
|
25
|
+
channel: ChannelSocketHealthIpcParams["channel"],
|
|
26
|
+
): Promise<ChannelSocketHealthIpcResponse> {
|
|
27
|
+
return ipcCallPersistentValidated(
|
|
28
|
+
"channel_socket_health",
|
|
29
|
+
{ channel },
|
|
30
|
+
ChannelSocketHealthIpcResponseSchema,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -91,6 +91,91 @@ describe("assistant channels", () => {
|
|
|
91
91
|
});
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
+
describe("two-axis rendering", () => {
|
|
95
|
+
/**
|
|
96
|
+
* A configured channel whose delivery stopped is the state this command
|
|
97
|
+
* used to have no word for. Setup is finished, so telling the reader to
|
|
98
|
+
* finish setup sends them to re-enter credentials that are already
|
|
99
|
+
* correct, and the operational reason for the outage is the only thing
|
|
100
|
+
* they can act on.
|
|
101
|
+
*/
|
|
102
|
+
const configuredButDown = (health: string) =>
|
|
103
|
+
emptySnapshot("slack", {
|
|
104
|
+
ready: false,
|
|
105
|
+
setupStatus: "ready",
|
|
106
|
+
health,
|
|
107
|
+
localChecks: [
|
|
108
|
+
{
|
|
109
|
+
name: "inbound_delivery",
|
|
110
|
+
passed: health !== "failing",
|
|
111
|
+
kind: "operational",
|
|
112
|
+
message: "Slack Socket Mode holds no live connection",
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("list calls a configured channel that stopped delivering down, not unfinished", async () => {
|
|
118
|
+
mockResponses = [
|
|
119
|
+
{
|
|
120
|
+
ok: true,
|
|
121
|
+
result: { success: true, snapshots: [configuredButDown("failing")] },
|
|
122
|
+
},
|
|
123
|
+
];
|
|
124
|
+
const out = await runCli("channels", "list");
|
|
125
|
+
expect(out).toContain("not delivering");
|
|
126
|
+
expect(out).not.toContain("incomplete");
|
|
127
|
+
expect(out).not.toContain("not configured");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("list distinguishes a verdict it could not obtain from an outage", async () => {
|
|
131
|
+
mockResponses = [
|
|
132
|
+
{
|
|
133
|
+
ok: true,
|
|
134
|
+
result: { success: true, snapshots: [configuredButDown("unknown")] },
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
const out = await runCli("channels", "list");
|
|
138
|
+
expect(out).toContain("state unknown");
|
|
139
|
+
expect(out).not.toContain("not delivering");
|
|
140
|
+
expect(out).not.toContain("incomplete");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("setup that genuinely did not finish still reads incomplete", async () => {
|
|
144
|
+
// The sensitivity check on the two above: the word has to survive for
|
|
145
|
+
// the state it was always correct for.
|
|
146
|
+
mockResponses = [
|
|
147
|
+
{
|
|
148
|
+
ok: true,
|
|
149
|
+
result: {
|
|
150
|
+
success: true,
|
|
151
|
+
snapshots: [
|
|
152
|
+
emptySnapshot("slack", {
|
|
153
|
+
ready: false,
|
|
154
|
+
setupStatus: "incomplete",
|
|
155
|
+
}),
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
];
|
|
160
|
+
const out = await runCli("channels", "list");
|
|
161
|
+
expect(out).toContain("incomplete");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("the detail header agrees with its own glyph", async () => {
|
|
165
|
+
// It used to print the raw setupStatus beside a glyph derived from both
|
|
166
|
+
// axes, so an outage rendered as a warning sign next to the word ready.
|
|
167
|
+
mockResponses = [
|
|
168
|
+
{
|
|
169
|
+
ok: true,
|
|
170
|
+
result: { success: true, snapshots: [configuredButDown("failing")] },
|
|
171
|
+
},
|
|
172
|
+
];
|
|
173
|
+
const out = await runCli("channels", "get", "slack");
|
|
174
|
+
expect(out).toContain("slack — not delivering");
|
|
175
|
+
expect(out).not.toContain("slack — ready");
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
94
179
|
describe("get", () => {
|
|
95
180
|
test("always re-probes via the refresh route (live, never cached)", async () => {
|
|
96
181
|
mockResponses = [
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import type { Command } from "commander";
|
|
16
16
|
|
|
17
17
|
import { cliIpcCall, exitFromIpcResult } from "../../../ipc/cli-client.js";
|
|
18
|
+
import type { ChannelReadinessSnapshot } from "../../../runtime/channel-readiness-types.js";
|
|
18
19
|
import { applyCommandHelp, subcommand } from "../../lib/cli-command-help.js";
|
|
19
20
|
import { registerCommand } from "../../lib/register-command.js";
|
|
20
21
|
import { log } from "../../logger.js";
|
|
@@ -22,26 +23,16 @@ import { shouldOutputJson, writeOutput } from "../../output.js";
|
|
|
22
23
|
import { channelsHelp } from "./index.help.js";
|
|
23
24
|
|
|
24
25
|
// ---------------------------------------------------------------------------
|
|
25
|
-
// Snapshot shape
|
|
26
|
+
// Snapshot shape
|
|
26
27
|
// ---------------------------------------------------------------------------
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
channel: string;
|
|
36
|
-
ready: boolean;
|
|
37
|
-
setupStatus: "not_configured" | "incomplete" | "ready";
|
|
38
|
-
checkedAt: number;
|
|
39
|
-
stale: boolean;
|
|
40
|
-
reasons: Array<{ code: string; text: string }>;
|
|
41
|
-
localChecks: ReadinessCheck[];
|
|
42
|
-
remoteChecks?: ReadinessCheck[];
|
|
43
|
-
channelHandle?: unknown;
|
|
44
|
-
}
|
|
29
|
+
/**
|
|
30
|
+
* The readiness service's own snapshot type, not a copy of it. A local
|
|
31
|
+
* mirror is what let this command fall a field behind the contract: it had
|
|
32
|
+
* no `health`, so a channel whose setup was complete and whose delivery had
|
|
33
|
+
* stopped rendered as unfinished setup.
|
|
34
|
+
*/
|
|
35
|
+
type ChannelSnapshot = ChannelReadinessSnapshot;
|
|
45
36
|
|
|
46
37
|
interface ReadinessResponse {
|
|
47
38
|
success: boolean;
|
|
@@ -52,26 +43,49 @@ interface ReadinessResponse {
|
|
|
52
43
|
// Rendering
|
|
53
44
|
// ---------------------------------------------------------------------------
|
|
54
45
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
function
|
|
46
|
+
/**
|
|
47
|
+
* Two axes, reported as one line each.
|
|
48
|
+
*
|
|
49
|
+
* `setupStatus` says whether setup finished; `health` says whether the
|
|
50
|
+
* channel is delivering. Collapsing them into setup progress alone is how a
|
|
51
|
+
* configured channel whose socket had died came to print as `incomplete`,
|
|
52
|
+
* which tells the reader to go finish a setup that is already complete.
|
|
53
|
+
* Ordered so the operational answer wins: once setup is done, what remains
|
|
54
|
+
* to say is whether it works.
|
|
55
|
+
*/
|
|
56
|
+
function statusState(
|
|
57
|
+
s: ChannelSnapshot,
|
|
58
|
+
):
|
|
59
|
+
| "ready"
|
|
60
|
+
| "not configured"
|
|
61
|
+
| "not delivering"
|
|
62
|
+
| "state unknown"
|
|
63
|
+
| "incomplete" {
|
|
66
64
|
if (s.ready) {
|
|
67
65
|
return "ready";
|
|
68
66
|
}
|
|
69
67
|
if (s.setupStatus === "not_configured") {
|
|
70
68
|
return "not configured";
|
|
71
69
|
}
|
|
70
|
+
if (s.setupStatus === "ready") {
|
|
71
|
+
return s.health === "unknown" ? "state unknown" : "not delivering";
|
|
72
|
+
}
|
|
72
73
|
return "incomplete";
|
|
73
74
|
}
|
|
74
75
|
|
|
76
|
+
const STATE_GLYPHS: Record<ReturnType<typeof statusState>, string> = {
|
|
77
|
+
ready: "✅",
|
|
78
|
+
"not configured": "○ ",
|
|
79
|
+
"not delivering": "⚠️ ",
|
|
80
|
+
// Neither vouched for nor condemned: the checks ran and settled nothing.
|
|
81
|
+
"state unknown": "? ",
|
|
82
|
+
incomplete: "⚠️ ",
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
function statusGlyph(s: ChannelSnapshot): string {
|
|
86
|
+
return STATE_GLYPHS[statusState(s)];
|
|
87
|
+
}
|
|
88
|
+
|
|
75
89
|
function renderList(snapshots: ChannelSnapshot[]): void {
|
|
76
90
|
const sorted = [...snapshots].sort((a, b) =>
|
|
77
91
|
a.channel.localeCompare(b.channel),
|
|
@@ -79,12 +93,12 @@ function renderList(snapshots: ChannelSnapshot[]): void {
|
|
|
79
93
|
log.info("Channel Status");
|
|
80
94
|
log.info("------------- ------");
|
|
81
95
|
for (const s of sorted) {
|
|
82
|
-
log.info(`${statusGlyph(s)} ${s.channel.padEnd(12)} ${
|
|
96
|
+
log.info(`${statusGlyph(s)} ${s.channel.padEnd(12)} ${statusState(s)}`);
|
|
83
97
|
}
|
|
84
98
|
}
|
|
85
99
|
|
|
86
100
|
function renderSnapshot(s: ChannelSnapshot): void {
|
|
87
|
-
log.info(`${statusGlyph(s)} ${s.channel} — ${s
|
|
101
|
+
log.info(`${statusGlyph(s)} ${s.channel} — ${statusState(s)}`);
|
|
88
102
|
if (s.reasons.length > 0) {
|
|
89
103
|
log.info("");
|
|
90
104
|
log.info("Reasons:");
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* Extracted from conversation-runtime-assembly.ts to break circular
|
|
5
5
|
* imports (memory/conversation-crud → daemon/conversation-runtime-assembly).
|
|
6
6
|
*/
|
|
7
|
-
import type { ChannelConversationType } from "@vellumai/gateway-client";
|
|
8
7
|
|
|
9
8
|
import { isHttpAuthDisabled } from "../config/env.js";
|
|
10
9
|
import { canSeePersonalMemory } from "../runtime/effective-capabilities.js";
|
|
@@ -88,39 +87,3 @@ export function isPersonalMemoryAllowed(
|
|
|
88
87
|
trustClass: resolveTrustClass(trustContext),
|
|
89
88
|
});
|
|
90
89
|
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Map a channel-native chat type (Telegram `private`/`group`/`supergroup`,
|
|
94
|
-
* Slack `im`/`mpim`/`channel`, Discord `dm`/`channel`) onto the
|
|
95
|
-
* permission-matrix conversation-type axis. Slack and Discord both forward
|
|
96
|
-
* every non-DM as `"channel"` without distinguishing public from private, so
|
|
97
|
-
* `"channel"` maps to undefined: a permissive public-channel cell must not
|
|
98
|
-
* silently govern private channels. The channel-type tier starts matching for
|
|
99
|
-
* their non-DMs once the gateway forwards the distinct type.
|
|
100
|
-
*
|
|
101
|
-
* Every DM-capable channel must have an arm here. A missing one is silent:
|
|
102
|
-
* the cell stays settable, because the adapter validates, and simply never
|
|
103
|
-
* matches, so the guardian sets a rule for DMs and it does nothing.
|
|
104
|
-
*/
|
|
105
|
-
export function mapChatTypeToConversationType(
|
|
106
|
-
chatType?: string,
|
|
107
|
-
): ChannelConversationType | undefined {
|
|
108
|
-
switch (chatType) {
|
|
109
|
-
case "im": // Slack DM
|
|
110
|
-
case "private": // Telegram DM
|
|
111
|
-
// Discord has no string vocabulary for this: its API distinguishes a DM by
|
|
112
|
-
// a numeric channel type, and the absence of a guild. The normalizer names
|
|
113
|
-
// it for the axis rather than inventing a native-looking word.
|
|
114
|
-
case "dm":
|
|
115
|
-
return "dm";
|
|
116
|
-
// "mpim" is Slack's multi-party DM, forwarded under its own name rather
|
|
117
|
-
// than reported as "im": a room with several people in it takes the
|
|
118
|
-
// tighter `private` cell and the group-chat etiquette, not the `dm` one.
|
|
119
|
-
case "mpim":
|
|
120
|
-
case "group": // Telegram group
|
|
121
|
-
case "supergroup": // Telegram supergroup
|
|
122
|
-
return "private";
|
|
123
|
-
default:
|
|
124
|
-
return undefined;
|
|
125
|
-
}
|
|
126
|
-
}
|
package/src/permissions/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ChannelConversationType } from "@vellumai/gateway-client";
|
|
2
|
+
|
|
1
3
|
export type { AllowlistOption, ScopeOption } from "../tools/tool-types.js";
|
|
2
4
|
export { RiskLevel } from "../tools/tool-types.js";
|
|
3
5
|
|
|
@@ -79,7 +81,7 @@ export interface PolicyContext {
|
|
|
79
81
|
* Conversation type on the permission-matrix axis (dm | private | public),
|
|
80
82
|
* for the channel-type tier of cell resolution.
|
|
81
83
|
*/
|
|
82
|
-
channelConversationType?:
|
|
84
|
+
channelConversationType?: ChannelConversationType;
|
|
83
85
|
/**
|
|
84
86
|
* Whether procedural-memory-as-skills is active for this assistant (memory-v3
|
|
85
87
|
* is live). Precomputed in {@link buildPolicyContext} so the checker can gate
|
|
@@ -248,6 +248,10 @@ const telegramProbe: ChannelProbe = {
|
|
|
248
248
|
health.status === "unknown" ||
|
|
249
249
|
health.status === "unverified";
|
|
250
250
|
const result = check(
|
|
251
|
+
// Published identifier. Installed skill copies and external clients
|
|
252
|
+
// search readiness responses for this name, and they do not upgrade in
|
|
253
|
+
// lockstep with the daemon, so renaming it silently breaks their
|
|
254
|
+
// delivery gate while Telegram is healthy.
|
|
251
255
|
"webhook_delivery",
|
|
252
256
|
health.status === "healthy" || indeterminate,
|
|
253
257
|
"Telegram is delivering to this assistant",
|
|
@@ -358,6 +362,84 @@ const whatsappProbe: ChannelProbe = {
|
|
|
358
362
|
|
|
359
363
|
// ── Slack Probe ─────────────────────────────────────────────────────────────
|
|
360
364
|
|
|
365
|
+
/**
|
|
366
|
+
* Ask the gateway whether Slack's Socket Mode connection is receiving.
|
|
367
|
+
*
|
|
368
|
+
* Distinct from the credential checks: valid tokens and a reachable
|
|
369
|
+
* `auth.test` establish that Slack would accept us, not that anything is
|
|
370
|
+
* arriving. A socket can be open at the transport layer and deliver nothing.
|
|
371
|
+
*
|
|
372
|
+
* Three outcomes, matching the Telegram probe:
|
|
373
|
+
*
|
|
374
|
+
* - `connected` is the only verified pass.
|
|
375
|
+
* - `disconnected` is a failure with a concrete cause.
|
|
376
|
+
* - `not_configured`, `unsupported` and an unreachable gateway are
|
|
377
|
+
* indeterminate. None is evidence of a fault, so none may show the channel
|
|
378
|
+
* as broken; none is evidence of delivery either, so none may make it
|
|
379
|
+
* ready.
|
|
380
|
+
*
|
|
381
|
+
* `lastLivenessAt` is reported and never gated on: a connection's first
|
|
382
|
+
* keepalive is a full interval after it opens, so requiring one would call
|
|
383
|
+
* every healthy reconnect broken.
|
|
384
|
+
*
|
|
385
|
+
* Declared `operational`, so it decides the channel's health rather than its
|
|
386
|
+
* setup progress: a dead socket means a configured channel is down, not a
|
|
387
|
+
* half-configured one.
|
|
388
|
+
*
|
|
389
|
+
* It runs among the local checks purely for freshness. It costs one IPC round
|
|
390
|
+
* trip to the gateway beside us rather than a call to Slack, and the remote
|
|
391
|
+
* bucket is cached for {@link REMOTE_TTL_MS}, far longer than a socket takes
|
|
392
|
+
* to die and recover. Placement is a cost decision here; `kind` carries the
|
|
393
|
+
* meaning.
|
|
394
|
+
*/
|
|
395
|
+
async function checkSlackInboundDelivery(): Promise<ReadinessCheckResult> {
|
|
396
|
+
// Imported here rather than at module scope, matching the Telegram probe:
|
|
397
|
+
// the gateway IPC client pulls in a module graph that unrelated consumers of
|
|
398
|
+
// this service should not have to mock.
|
|
399
|
+
const { readChannelSocketHealth } =
|
|
400
|
+
await import("../channels/gateway-channel-socket-health.js");
|
|
401
|
+
|
|
402
|
+
let health;
|
|
403
|
+
try {
|
|
404
|
+
health = await readChannelSocketHealth("slack");
|
|
405
|
+
} catch {
|
|
406
|
+
return {
|
|
407
|
+
name: "inbound_delivery",
|
|
408
|
+
kind: "operational",
|
|
409
|
+
passed: true,
|
|
410
|
+
message: "Could not reach the gateway to read the Slack connection state",
|
|
411
|
+
indeterminate: true,
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (health.status === "not_configured" || health.status === "unsupported") {
|
|
416
|
+
return {
|
|
417
|
+
name: "inbound_delivery",
|
|
418
|
+
kind: "operational",
|
|
419
|
+
passed: true,
|
|
420
|
+
message:
|
|
421
|
+
health.status === "not_configured"
|
|
422
|
+
? "Slack Socket Mode is not running, because its credentials are not configured"
|
|
423
|
+
: "Slack does not report a gateway-owned socket",
|
|
424
|
+
indeterminate: true,
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const lastProof =
|
|
429
|
+
health.lastLivenessAt === undefined
|
|
430
|
+
? "no keepalive answered yet on this connection"
|
|
431
|
+
: `last keepalive ${new Date(health.lastLivenessAt).toISOString()}`;
|
|
432
|
+
return {
|
|
433
|
+
...check(
|
|
434
|
+
"inbound_delivery",
|
|
435
|
+
health.status === "connected",
|
|
436
|
+
`Slack is delivering to this assistant (${lastProof})`,
|
|
437
|
+
"Slack Socket Mode holds no live connection, so inbound messages are not reaching this assistant",
|
|
438
|
+
),
|
|
439
|
+
kind: "operational",
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
|
|
361
443
|
const slackProbe: ChannelProbe = {
|
|
362
444
|
channel: "slack",
|
|
363
445
|
async runLocalChecks(): Promise<ReadinessCheckResult[]> {
|
|
@@ -374,6 +456,7 @@ const slackProbe: ChannelProbe = {
|
|
|
374
456
|
"app_token",
|
|
375
457
|
"Slack app token",
|
|
376
458
|
),
|
|
459
|
+
await checkSlackInboundDelivery(),
|
|
377
460
|
];
|
|
378
461
|
},
|
|
379
462
|
async runRemoteChecks(): Promise<ReadinessCheckResult[]> {
|
|
@@ -39,7 +39,6 @@ import {
|
|
|
39
39
|
import { getDiskPressureStatus } from "../../daemon/disk-pressure-guard.js";
|
|
40
40
|
import { classifyDiskPressureTurnPolicy } from "../../daemon/disk-pressure-policy.js";
|
|
41
41
|
import { processMessage } from "../../daemon/process-message.js";
|
|
42
|
-
import { mapChatTypeToConversationType } from "../../daemon/trust-context.js";
|
|
43
42
|
import type { TrustContext } from "../../daemon/trust-context-types.js";
|
|
44
43
|
import { HeartbeatService } from "../../heartbeat/heartbeat-service.js";
|
|
45
44
|
import type { Message as ProviderMessage } from "../../messaging/provider-types.js";
|
|
@@ -1030,7 +1029,11 @@ export async function handleChannelInbound({
|
|
|
1030
1029
|
sourceMetadata.chatType.trim().length > 0
|
|
1031
1030
|
? sourceMetadata.chatType.trim()
|
|
1032
1031
|
: undefined;
|
|
1033
|
-
|
|
1032
|
+
// Decided by the sending channel, which is the only side that knows what its
|
|
1033
|
+
// own surfaces mean. The daemon reads the answer rather than re-deriving it
|
|
1034
|
+
// from a vocabulary where `channel` means a public room on Slack and a
|
|
1035
|
+
// broadcast feed on Telegram.
|
|
1036
|
+
trustCtx.conversationType = sourceMetadata?.conversationType;
|
|
1034
1037
|
|
|
1035
1038
|
// Preserve locale from sourceMetadata so the model can greet in the user's language
|
|
1036
1039
|
const sourceLanguageCode =
|
package/src/tools/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
ChannelConversationType,
|
|
2
3
|
RiskAllowlistOption,
|
|
3
4
|
RiskDirectoryScopeOption,
|
|
4
5
|
} from "@vellumai/gateway-client";
|
|
@@ -377,7 +378,7 @@ export interface ToolContext {
|
|
|
377
378
|
* resolution; undefined when the chat type is unknown or ambiguous.
|
|
378
379
|
* @legacy
|
|
379
380
|
*/
|
|
380
|
-
channelConversationType?:
|
|
381
|
+
channelConversationType?: ChannelConversationType;
|
|
381
382
|
/**
|
|
382
383
|
* External channel/conversation ID of the current chat (the binding's
|
|
383
384
|
* external chat id — Slack channel, Telegram chat, …). Keys the channel
|