@botcord/daemon 0.2.38 → 0.2.40

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.
@@ -8,13 +8,49 @@
8
8
  * gateway, login-session store, fetch impl, and config I/O — `provision.ts`
9
9
  * wires the production defaults.
10
10
  */
11
- import type { ControlAck, GatewayLoginStartParams, GatewayLoginStatusParams, RemoveGatewayParams, TestGatewayParams, UpsertGatewayParams } from "@botcord/protocol-core";
11
+ import type { ControlAck } from "@botcord/protocol-core";
12
12
  import type { Gateway } from "./gateway/index.js";
13
13
  import { type DaemonConfig } from "./config.js";
14
14
  import { LoginSessionStore } from "./gateway/channels/login-session.js";
15
15
  import { getBotQrcode, getQrcodeStatus } from "./gateway/channels/wechat-login.js";
16
16
  import type { FetchLike } from "./gateway/channels/http-types.js";
17
17
  type AckBody = Omit<ControlAck, "id">;
18
+ type GatewayProvider = "telegram" | "wechat";
19
+ interface UpsertGatewayParams {
20
+ id: string;
21
+ type: GatewayProvider;
22
+ accountId: string;
23
+ label?: string;
24
+ enabled?: boolean;
25
+ loginId?: string;
26
+ secret?: {
27
+ botToken?: string;
28
+ };
29
+ settings?: {
30
+ baseUrl?: string;
31
+ allowedSenderIds?: string[];
32
+ allowedChatIds?: string[];
33
+ splitAt?: number;
34
+ };
35
+ }
36
+ interface RemoveGatewayParams {
37
+ id: string;
38
+ deleteSecret?: boolean;
39
+ }
40
+ interface TestGatewayParams {
41
+ id: string;
42
+ }
43
+ interface GatewayLoginStartParams {
44
+ provider: GatewayProvider;
45
+ accountId: string;
46
+ gatewayId?: string;
47
+ baseUrl?: string;
48
+ }
49
+ interface GatewayLoginStatusParams {
50
+ provider: GatewayProvider;
51
+ loginId: string;
52
+ accountId: string;
53
+ }
18
54
  export type { FetchLike };
19
55
  export interface GatewayControlContext {
20
56
  gateway: Gateway;
package/dist/provision.js CHANGED
@@ -201,9 +201,9 @@ export function createProvisioner(opts) {
201
201
  daemonLog.debug("list_runtimes", { count: snapshot.runtimes.length });
202
202
  return { ok: true, result: snapshot };
203
203
  }
204
- case CONTROL_FRAME_TYPES.LIST_GATEWAYS:
204
+ case "list_gateways":
205
205
  return gatewayControl.handleList();
206
- case CONTROL_FRAME_TYPES.UPSERT_GATEWAY: {
206
+ case "upsert_gateway": {
207
207
  const v = validateGatewayParams(frame.params, {
208
208
  required: ["id", "type", "accountId"],
209
209
  });
@@ -211,19 +211,19 @@ export function createProvisioner(opts) {
211
211
  return v.ack;
212
212
  return gatewayControl.handleUpsert(v.params);
213
213
  }
214
- case CONTROL_FRAME_TYPES.REMOVE_GATEWAY: {
214
+ case "remove_gateway": {
215
215
  const v = validateGatewayParams(frame.params, { required: ["id"] });
216
216
  if (!v.ok)
217
217
  return v.ack;
218
218
  return gatewayControl.handleRemove(v.params);
219
219
  }
220
- case CONTROL_FRAME_TYPES.TEST_GATEWAY: {
220
+ case "test_gateway": {
221
221
  const v = validateGatewayParams(frame.params, { required: ["id"] });
222
222
  if (!v.ok)
223
223
  return v.ack;
224
224
  return gatewayControl.handleTest(v.params);
225
225
  }
226
- case CONTROL_FRAME_TYPES.GATEWAY_LOGIN_START: {
226
+ case "gateway_login_start": {
227
227
  const v = validateGatewayParams(frame.params, {
228
228
  required: ["provider", "accountId"],
229
229
  });
@@ -231,7 +231,7 @@ export function createProvisioner(opts) {
231
231
  return v.ack;
232
232
  return gatewayControl.handleLoginStart(v.params);
233
233
  }
234
- case CONTROL_FRAME_TYPES.GATEWAY_LOGIN_STATUS: {
234
+ case "gateway_login_status": {
235
235
  const v = validateGatewayParams(frame.params, {
236
236
  required: ["provider", "loginId"],
237
237
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botcord/daemon",
3
- "version": "0.2.38",
3
+ "version": "0.2.40",
4
4
  "description": "BotCord local daemon — bridges Hub inbox push to local Claude Code / Codex / Gemini CLIs",
5
5
  "type": "module",
6
6
  "bin": {
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@botcord/cli": "^0.1.7",
31
- "@botcord/protocol-core": "^0.2.2",
31
+ "@botcord/protocol-core": "^0.2.4",
32
32
  "ws": "^8.18.0"
33
33
  },
34
34
  "devDependencies": {
@@ -1698,7 +1698,7 @@ describe("W8: gateway frame param validation in provision dispatch", () => {
1698
1698
  });
1699
1699
  const ack = await provisioner({
1700
1700
  id: "req_w8a",
1701
- type: CONTROL_FRAME_TYPES.UPSERT_GATEWAY,
1701
+ type: "upsert_gateway",
1702
1702
  params: { id: "gw_x", type: "telegram" } as unknown as Record<string, unknown>,
1703
1703
  });
1704
1704
  expect(ack.ok).toBe(false);
@@ -1714,7 +1714,7 @@ describe("W8: gateway frame param validation in provision dispatch", () => {
1714
1714
  });
1715
1715
  const ack = await provisioner({
1716
1716
  id: "req_w8b",
1717
- type: CONTROL_FRAME_TYPES.REMOVE_GATEWAY,
1717
+ type: "remove_gateway",
1718
1718
  // @ts-expect-error — exercising the runtime guard
1719
1719
  params: "not-an-object",
1720
1720
  });
@@ -1729,7 +1729,7 @@ describe("W8: gateway frame param validation in provision dispatch", () => {
1729
1729
  });
1730
1730
  const ack = await provisioner({
1731
1731
  id: "req_w8c",
1732
- type: CONTROL_FRAME_TYPES.TEST_GATEWAY,
1732
+ type: "test_gateway",
1733
1733
  params: {},
1734
1734
  });
1735
1735
  expect(ack.ok).toBe(false);
@@ -1743,7 +1743,7 @@ describe("W8: gateway frame param validation in provision dispatch", () => {
1743
1743
  });
1744
1744
  const ack = await provisioner({
1745
1745
  id: "req_w8d",
1746
- type: CONTROL_FRAME_TYPES.GATEWAY_LOGIN_START,
1746
+ type: "gateway_login_start",
1747
1747
  params: { accountId: "ag_a" },
1748
1748
  });
1749
1749
  expect(ack.ok).toBe(false);
@@ -1757,7 +1757,7 @@ describe("W8: gateway frame param validation in provision dispatch", () => {
1757
1757
  });
1758
1758
  const ack = await provisioner({
1759
1759
  id: "req_w8e",
1760
- type: CONTROL_FRAME_TYPES.GATEWAY_LOGIN_STATUS,
1760
+ type: "gateway_login_status",
1761
1761
  params: { provider: "wechat" },
1762
1762
  });
1763
1763
  expect(ack.ok).toBe(false);
@@ -9,22 +9,7 @@
9
9
  * wires the production defaults.
10
10
  */
11
11
 
12
- import type {
13
- ControlAck,
14
- GatewayLoginStartParams,
15
- GatewayLoginStartResult,
16
- GatewayLoginStatusParams,
17
- GatewayLoginStatusResult,
18
- GatewayProfileSummary,
19
- GatewayProvider,
20
- ListGatewaysResult,
21
- RemoveGatewayParams,
22
- RemoveGatewayResult,
23
- TestGatewayParams,
24
- TestGatewayResult,
25
- UpsertGatewayParams,
26
- UpsertGatewayResult,
27
- } from "@botcord/protocol-core";
12
+ import type { ControlAck } from "@botcord/protocol-core";
28
13
  import type { Gateway, GatewayChannelConfig } from "./gateway/index.js";
29
14
  import {
30
15
  loadConfig,
@@ -56,6 +41,108 @@ import type { FetchLike } from "./gateway/channels/http-types.js";
56
41
 
57
42
  type AckBody = Omit<ControlAck, "id">;
58
43
 
44
+ type GatewayProvider = "telegram" | "wechat";
45
+
46
+ interface GatewayProfileSummary {
47
+ id: string;
48
+ type: GatewayProvider;
49
+ accountId: string;
50
+ label?: string;
51
+ enabled: boolean;
52
+ baseUrl?: string;
53
+ allowedSenderIds?: string[];
54
+ allowedChatIds?: string[];
55
+ splitAt?: number;
56
+ status?: {
57
+ running: boolean;
58
+ connected?: boolean;
59
+ authorized?: boolean;
60
+ lastPollAt?: number;
61
+ lastInboundAt?: number;
62
+ lastSendAt?: number;
63
+ lastError?: string | null;
64
+ };
65
+ }
66
+
67
+ interface ListGatewaysResult {
68
+ gateways: GatewayProfileSummary[];
69
+ }
70
+
71
+ interface UpsertGatewayParams {
72
+ id: string;
73
+ type: GatewayProvider;
74
+ accountId: string;
75
+ label?: string;
76
+ enabled?: boolean;
77
+ loginId?: string;
78
+ secret?: {
79
+ botToken?: string;
80
+ };
81
+ settings?: {
82
+ baseUrl?: string;
83
+ allowedSenderIds?: string[];
84
+ allowedChatIds?: string[];
85
+ splitAt?: number;
86
+ };
87
+ }
88
+
89
+ interface UpsertGatewayResult {
90
+ id: string;
91
+ type: GatewayProvider;
92
+ accountId: string;
93
+ enabled: boolean;
94
+ tokenPreview?: string;
95
+ status?: GatewayProfileSummary["status"];
96
+ }
97
+
98
+ interface RemoveGatewayParams {
99
+ id: string;
100
+ deleteSecret?: boolean;
101
+ }
102
+
103
+ interface RemoveGatewayResult {
104
+ id: string;
105
+ removed: boolean;
106
+ secretDeleted: boolean;
107
+ }
108
+
109
+ interface TestGatewayParams {
110
+ id: string;
111
+ }
112
+
113
+ interface TestGatewayResult {
114
+ id: string;
115
+ ok: boolean;
116
+ info?: Record<string, unknown>;
117
+ error?: string;
118
+ }
119
+
120
+ interface GatewayLoginStartParams {
121
+ provider: GatewayProvider;
122
+ accountId: string;
123
+ gatewayId?: string;
124
+ baseUrl?: string;
125
+ }
126
+
127
+ interface GatewayLoginStartResult {
128
+ loginId: string;
129
+ qrcode?: string;
130
+ qrcodeUrl?: string;
131
+ expiresAt: number;
132
+ }
133
+
134
+ interface GatewayLoginStatusParams {
135
+ provider: GatewayProvider;
136
+ loginId: string;
137
+ accountId: string;
138
+ }
139
+
140
+ interface GatewayLoginStatusResult {
141
+ status: "pending" | "scanned" | "confirmed" | "expired" | "failed";
142
+ baseUrl?: string;
143
+ tokenPreview?: string;
144
+ }
145
+
59
146
  export type { FetchLike };
60
147
 
61
148
  export interface GatewayControlContext {
package/src/provision.ts CHANGED
@@ -322,10 +322,10 @@ export function createProvisioner(opts: ProvisionerOptions): (
322
322
  return { ok: true, result: snapshot };
323
323
  }
324
324
 
325
- case CONTROL_FRAME_TYPES.LIST_GATEWAYS:
325
+ case "list_gateways":
326
326
  return gatewayControl.handleList();
327
327
 
328
- case CONTROL_FRAME_TYPES.UPSERT_GATEWAY: {
328
+ case "upsert_gateway": {
329
329
  const v = validateGatewayParams(frame.params, {
330
330
  required: ["id", "type", "accountId"],
331
331
  });
@@ -335,7 +335,7 @@ export function createProvisioner(opts: ProvisionerOptions): (
335
335
  );
336
336
  }
337
337
 
338
- case CONTROL_FRAME_TYPES.REMOVE_GATEWAY: {
338
+ case "remove_gateway": {
339
339
  const v = validateGatewayParams(frame.params, { required: ["id"] });
340
340
  if (!v.ok) return v.ack;
341
341
  return gatewayControl.handleRemove(
@@ -343,7 +343,7 @@ export function createProvisioner(opts: ProvisionerOptions): (
343
343
  );
344
344
  }
345
345
 
346
- case CONTROL_FRAME_TYPES.TEST_GATEWAY: {
346
+ case "test_gateway": {
347
347
  const v = validateGatewayParams(frame.params, { required: ["id"] });
348
348
  if (!v.ok) return v.ack;
349
349
  return gatewayControl.handleTest(
@@ -351,7 +351,7 @@ export function createProvisioner(opts: ProvisionerOptions): (
351
351
  );
352
352
  }
353
353
 
354
- case CONTROL_FRAME_TYPES.GATEWAY_LOGIN_START: {
354
+ case "gateway_login_start": {
355
355
  const v = validateGatewayParams(frame.params, {
356
356
  required: ["provider", "accountId"],
357
357
  });
@@ -361,7 +361,7 @@ export function createProvisioner(opts: ProvisionerOptions): (
361
361
  );
362
362
  }
363
363
 
364
- case CONTROL_FRAME_TYPES.GATEWAY_LOGIN_STATUS: {
364
+ case "gateway_login_status": {
365
365
  const v = validateGatewayParams(frame.params, {
366
366
  required: ["provider", "loginId"],
367
367
  });