opencode-oncall 0.1.0
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/LICENSE +151 -0
- package/README.md +50 -0
- package/dist/common-settings-actions.d.ts +15 -0
- package/dist/common-settings-actions.js +48 -0
- package/dist/common-settings-store.d.ts +1 -0
- package/dist/common-settings-store.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/plugin-hooks.d.ts +51 -0
- package/dist/plugin-hooks.js +288 -0
- package/dist/plugin.d.ts +10 -0
- package/dist/plugin.js +115 -0
- package/dist/settings-store.d.ts +50 -0
- package/dist/settings-store.js +214 -0
- package/dist/store-paths.d.ts +16 -0
- package/dist/store-paths.js +61 -0
- package/dist/ui/wechat-menu.d.ts +26 -0
- package/dist/ui/wechat-menu.js +90 -0
- package/dist/wechat/bind-flow.d.ts +29 -0
- package/dist/wechat/bind-flow.js +207 -0
- package/dist/wechat/bridge.d.ts +136 -0
- package/dist/wechat/bridge.js +1059 -0
- package/dist/wechat/broker-client.d.ts +23 -0
- package/dist/wechat/broker-client.js +274 -0
- package/dist/wechat/broker-endpoint.d.ts +21 -0
- package/dist/wechat/broker-endpoint.js +78 -0
- package/dist/wechat/broker-entry.d.ts +123 -0
- package/dist/wechat/broker-entry.js +1321 -0
- package/dist/wechat/broker-launcher.d.ts +37 -0
- package/dist/wechat/broker-launcher.js +418 -0
- package/dist/wechat/broker-mutation-queue.d.ts +93 -0
- package/dist/wechat/broker-mutation-queue.js +126 -0
- package/dist/wechat/broker-server.d.ts +86 -0
- package/dist/wechat/broker-server.js +1340 -0
- package/dist/wechat/broker-state-store.d.ts +335 -0
- package/dist/wechat/broker-state-store.js +1964 -0
- package/dist/wechat/command-parser.d.ts +18 -0
- package/dist/wechat/command-parser.js +58 -0
- package/dist/wechat/compat/jiti-loader.d.ts +27 -0
- package/dist/wechat/compat/jiti-loader.js +118 -0
- package/dist/wechat/compat/openclaw-account-helpers.d.ts +29 -0
- package/dist/wechat/compat/openclaw-account-helpers.js +60 -0
- package/dist/wechat/compat/openclaw-bind-helpers.d.ts +29 -0
- package/dist/wechat/compat/openclaw-bind-helpers.js +169 -0
- package/dist/wechat/compat/openclaw-guided-smoke.d.ts +180 -0
- package/dist/wechat/compat/openclaw-guided-smoke.js +1134 -0
- package/dist/wechat/compat/openclaw-public-entry.d.ts +33 -0
- package/dist/wechat/compat/openclaw-public-entry.js +62 -0
- package/dist/wechat/compat/openclaw-public-helpers.d.ts +70 -0
- package/dist/wechat/compat/openclaw-public-helpers.js +68 -0
- package/dist/wechat/compat/openclaw-qr-gateway.d.ts +15 -0
- package/dist/wechat/compat/openclaw-qr-gateway.js +39 -0
- package/dist/wechat/compat/openclaw-smoke.d.ts +48 -0
- package/dist/wechat/compat/openclaw-smoke.js +100 -0
- package/dist/wechat/compat/openclaw-sync-buf.d.ts +24 -0
- package/dist/wechat/compat/openclaw-sync-buf.js +80 -0
- package/dist/wechat/compat/openclaw-updates-send.d.ts +47 -0
- package/dist/wechat/compat/openclaw-updates-send.js +38 -0
- package/dist/wechat/compat/qrcode-terminal-loader.d.ts +12 -0
- package/dist/wechat/compat/qrcode-terminal-loader.js +16 -0
- package/dist/wechat/compat/slash-guard.d.ts +11 -0
- package/dist/wechat/compat/slash-guard.js +24 -0
- package/dist/wechat/dead-letter-store.d.ts +48 -0
- package/dist/wechat/dead-letter-store.js +224 -0
- package/dist/wechat/debug-bundle-collector.d.ts +49 -0
- package/dist/wechat/debug-bundle-collector.js +580 -0
- package/dist/wechat/debug-bundle-flow.d.ts +37 -0
- package/dist/wechat/debug-bundle-flow.js +180 -0
- package/dist/wechat/debug-bundle-redaction.d.ts +14 -0
- package/dist/wechat/debug-bundle-redaction.js +339 -0
- package/dist/wechat/handle.d.ts +10 -0
- package/dist/wechat/handle.js +57 -0
- package/dist/wechat/ipc-auth.d.ts +6 -0
- package/dist/wechat/ipc-auth.js +39 -0
- package/dist/wechat/latest-account-state-store.d.ts +8 -0
- package/dist/wechat/latest-account-state-store.js +38 -0
- package/dist/wechat/notification-dispatcher.d.ts +34 -0
- package/dist/wechat/notification-dispatcher.js +266 -0
- package/dist/wechat/notification-format.d.ts +15 -0
- package/dist/wechat/notification-format.js +196 -0
- package/dist/wechat/notification-store.d.ts +72 -0
- package/dist/wechat/notification-store.js +807 -0
- package/dist/wechat/notification-types.d.ts +37 -0
- package/dist/wechat/notification-types.js +1 -0
- package/dist/wechat/openclaw-account-adapter.d.ts +30 -0
- package/dist/wechat/openclaw-account-adapter.js +60 -0
- package/dist/wechat/operator-store.d.ts +9 -0
- package/dist/wechat/operator-store.js +69 -0
- package/dist/wechat/protocol.d.ts +150 -0
- package/dist/wechat/protocol.js +197 -0
- package/dist/wechat/question-interaction.d.ts +24 -0
- package/dist/wechat/question-interaction.js +180 -0
- package/dist/wechat/request-store.d.ts +108 -0
- package/dist/wechat/request-store.js +669 -0
- package/dist/wechat/session-digest.d.ts +50 -0
- package/dist/wechat/session-digest.js +167 -0
- package/dist/wechat/state-paths.d.ts +26 -0
- package/dist/wechat/state-paths.js +92 -0
- package/dist/wechat/status-format.d.ts +26 -0
- package/dist/wechat/status-format.js +616 -0
- package/dist/wechat/token-store.d.ts +20 -0
- package/dist/wechat/token-store.js +193 -0
- package/dist/wechat/wechat-status-runtime.d.ts +89 -0
- package/dist/wechat/wechat-status-runtime.js +518 -0
- package/package.json +74 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Message, Part, PermissionRequest, QuestionRequest, Session, SessionStatus, Todo } from "@opencode-ai/sdk/v2";
|
|
2
|
+
type SessionState = "busy" | "idle" | "retry" | "unknown";
|
|
3
|
+
type SessionMessages = Array<{
|
|
4
|
+
info: Message;
|
|
5
|
+
parts: Part[];
|
|
6
|
+
}>;
|
|
7
|
+
export type SessionDigestHighlight = {
|
|
8
|
+
kind: "question" | "permission" | "running-tool" | "completed-tool" | "todo" | "status";
|
|
9
|
+
text: string;
|
|
10
|
+
};
|
|
11
|
+
export type SessionDigestTodoItem = {
|
|
12
|
+
status: "pending" | "in_progress" | "completed" | "cancelled";
|
|
13
|
+
content: string;
|
|
14
|
+
};
|
|
15
|
+
export type SessionDigest = {
|
|
16
|
+
sessionID: string;
|
|
17
|
+
parentID?: string;
|
|
18
|
+
title: string;
|
|
19
|
+
directory: string;
|
|
20
|
+
updatedAt: number;
|
|
21
|
+
status: SessionState;
|
|
22
|
+
pendingQuestionCount: number;
|
|
23
|
+
pendingPermissionCount: number;
|
|
24
|
+
todoSummary: {
|
|
25
|
+
total: number;
|
|
26
|
+
inProgress: number;
|
|
27
|
+
completed: number;
|
|
28
|
+
};
|
|
29
|
+
unavailable?: Array<"messages" | "todo">;
|
|
30
|
+
highlights: SessionDigestHighlight[];
|
|
31
|
+
todoItems?: SessionDigestTodoItem[];
|
|
32
|
+
questionHighlights?: string[];
|
|
33
|
+
};
|
|
34
|
+
export type BuildSessionDigestInput = {
|
|
35
|
+
session: Pick<Session, "id" | "title" | "directory" | "time"> & {
|
|
36
|
+
parentID?: string;
|
|
37
|
+
};
|
|
38
|
+
statusBySession: Record<string, SessionStatus | undefined>;
|
|
39
|
+
questionsBySession: Map<string, QuestionRequest[]>;
|
|
40
|
+
permissionsBySession: Map<string, PermissionRequest[]>;
|
|
41
|
+
todos?: Todo[];
|
|
42
|
+
messages?: SessionMessages;
|
|
43
|
+
unavailable?: Array<"messages" | "todo">;
|
|
44
|
+
};
|
|
45
|
+
export declare function groupQuestionsBySession(questions?: QuestionRequest[]): Map<string, QuestionRequest[]>;
|
|
46
|
+
export declare function groupPermissionsBySession(permissions?: PermissionRequest[]): Map<string, PermissionRequest[]>;
|
|
47
|
+
export declare function buildSessionDigest(input: BuildSessionDigestInput): SessionDigest;
|
|
48
|
+
type RecentSessionLike = Pick<Session, "time">;
|
|
49
|
+
export declare function pickRecentSessions<TSession extends RecentSessionLike>(sessions: TSession[], limit?: number): TSession[];
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
function asSessionState(status) {
|
|
2
|
+
if (!status) {
|
|
3
|
+
return "unknown";
|
|
4
|
+
}
|
|
5
|
+
return status.type;
|
|
6
|
+
}
|
|
7
|
+
function toUpdatedAt(session) {
|
|
8
|
+
const updated = session.time?.updated;
|
|
9
|
+
if (typeof updated === "number" && Number.isFinite(updated)) {
|
|
10
|
+
return updated;
|
|
11
|
+
}
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
function collectToolSlices(messages) {
|
|
15
|
+
const runningTools = [];
|
|
16
|
+
let latestCompletedTool;
|
|
17
|
+
for (const message of messages) {
|
|
18
|
+
const parts = Array.isArray(message.parts) ? message.parts : [];
|
|
19
|
+
for (const part of parts) {
|
|
20
|
+
if (part.type !== "tool") {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const toolName = part.tool;
|
|
24
|
+
const status = part.state?.status;
|
|
25
|
+
if (status === "pending" || status === "running") {
|
|
26
|
+
if (!runningTools.includes(toolName)) {
|
|
27
|
+
runningTools.push(toolName);
|
|
28
|
+
}
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (status === "completed") {
|
|
32
|
+
latestCompletedTool = toolName;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
runningText: runningTools.length > 0 ? `running tool: ${runningTools.join(", ")}` : undefined,
|
|
38
|
+
completedText: latestCompletedTool ? `completed tool: ${latestCompletedTool}` : undefined,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function summarizeTodos(todos) {
|
|
42
|
+
let inProgress = 0;
|
|
43
|
+
let completed = 0;
|
|
44
|
+
for (const todo of todos) {
|
|
45
|
+
if (todo.status === "in_progress") {
|
|
46
|
+
inProgress += 1;
|
|
47
|
+
}
|
|
48
|
+
if (todo.status === "completed") {
|
|
49
|
+
completed += 1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
total: todos.length,
|
|
54
|
+
inProgress,
|
|
55
|
+
completed,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function normalizeTodoStatus(status) {
|
|
59
|
+
return status === "pending" || status === "in_progress" || status === "completed" || status === "cancelled"
|
|
60
|
+
? status
|
|
61
|
+
: null;
|
|
62
|
+
}
|
|
63
|
+
function pushIfDefined(highlights, kind, text) {
|
|
64
|
+
if (!text) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
highlights.push({ kind, text });
|
|
68
|
+
}
|
|
69
|
+
function summarizeQuestionHighlight(question) {
|
|
70
|
+
const first = Array.isArray(question.questions) ? question.questions[0] : undefined;
|
|
71
|
+
if (first && typeof first.question === "string" && first.question.trim().length > 0) {
|
|
72
|
+
return `问题:${first.question.trim()}`;
|
|
73
|
+
}
|
|
74
|
+
const fallback = question.text;
|
|
75
|
+
if (typeof fallback === "string" && fallback.trim().length > 0) {
|
|
76
|
+
return `问题:${fallback.trim()}`;
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
export function groupQuestionsBySession(questions = []) {
|
|
81
|
+
const grouped = new Map();
|
|
82
|
+
for (const question of questions) {
|
|
83
|
+
const sessionID = question.sessionID;
|
|
84
|
+
if (sessionID.length === 0) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const list = grouped.get(sessionID) ?? [];
|
|
88
|
+
list.push(question);
|
|
89
|
+
grouped.set(sessionID, list);
|
|
90
|
+
}
|
|
91
|
+
return grouped;
|
|
92
|
+
}
|
|
93
|
+
export function groupPermissionsBySession(permissions = []) {
|
|
94
|
+
const grouped = new Map();
|
|
95
|
+
for (const permission of permissions) {
|
|
96
|
+
const sessionID = permission.sessionID;
|
|
97
|
+
if (sessionID.length === 0) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const list = grouped.get(sessionID) ?? [];
|
|
101
|
+
list.push(permission);
|
|
102
|
+
grouped.set(sessionID, list);
|
|
103
|
+
}
|
|
104
|
+
return grouped;
|
|
105
|
+
}
|
|
106
|
+
export function buildSessionDigest(input) {
|
|
107
|
+
const sessionID = input.session.id;
|
|
108
|
+
const questions = input.questionsBySession.get(sessionID) ?? [];
|
|
109
|
+
const permissions = input.permissionsBySession.get(sessionID) ?? [];
|
|
110
|
+
const todos = input.todos ?? [];
|
|
111
|
+
const messages = input.messages ?? [];
|
|
112
|
+
const todoSummary = summarizeTodos(todos);
|
|
113
|
+
const toolSlices = collectToolSlices(messages);
|
|
114
|
+
const status = asSessionState(input.statusBySession[sessionID]);
|
|
115
|
+
const highlights = [];
|
|
116
|
+
const todoItems = todos
|
|
117
|
+
.map((todo) => {
|
|
118
|
+
const status = normalizeTodoStatus(todo.status);
|
|
119
|
+
return {
|
|
120
|
+
status,
|
|
121
|
+
content: typeof todo.content === "string" ? todo.content.trim() : "",
|
|
122
|
+
};
|
|
123
|
+
})
|
|
124
|
+
.filter((item) => item.status !== null && item.content.length > 0);
|
|
125
|
+
const questionHighlights = questions
|
|
126
|
+
.map((question) => summarizeQuestionHighlight(question))
|
|
127
|
+
.filter((item) => typeof item === "string" && item.length > 0);
|
|
128
|
+
if (permissions.length > 0) {
|
|
129
|
+
highlights.push({ kind: "permission", text: `pending permission: ${permissions.length}` });
|
|
130
|
+
}
|
|
131
|
+
if (questions.length > 0) {
|
|
132
|
+
highlights.push({ kind: "question", text: `pending question: ${questions.length}` });
|
|
133
|
+
}
|
|
134
|
+
pushIfDefined(highlights, "running-tool", toolSlices.runningText);
|
|
135
|
+
pushIfDefined(highlights, "completed-tool", toolSlices.completedText);
|
|
136
|
+
if (todoSummary.total > 0) {
|
|
137
|
+
highlights.push({
|
|
138
|
+
kind: "todo",
|
|
139
|
+
text: `todo: ${todoSummary.inProgress} in progress, ${todoSummary.completed} completed, ${todoSummary.total} total`,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
highlights.push({ kind: "status", text: `status: ${status}` });
|
|
143
|
+
const unavailable = (input.unavailable ?? []).filter((item) => item === "messages" || item === "todo");
|
|
144
|
+
return {
|
|
145
|
+
sessionID,
|
|
146
|
+
...(typeof input.session.parentID === "string" && input.session.parentID.trim().length > 0
|
|
147
|
+
? { parentID: input.session.parentID.trim() }
|
|
148
|
+
: {}),
|
|
149
|
+
title: input.session.title ?? "",
|
|
150
|
+
directory: input.session.directory ?? "",
|
|
151
|
+
updatedAt: toUpdatedAt(input.session),
|
|
152
|
+
status,
|
|
153
|
+
pendingQuestionCount: questions.length,
|
|
154
|
+
pendingPermissionCount: permissions.length,
|
|
155
|
+
todoSummary,
|
|
156
|
+
unavailable: unavailable.length > 0 ? unavailable : undefined,
|
|
157
|
+
highlights,
|
|
158
|
+
...(todoItems.length > 0 ? { todoItems } : {}),
|
|
159
|
+
...(questionHighlights.length > 0 ? { questionHighlights } : {}),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
export function pickRecentSessions(sessions, limit = 3) {
|
|
163
|
+
const safeLimit = Number.isFinite(limit) && limit > 0 ? Math.floor(limit) : 3;
|
|
164
|
+
return [...sessions]
|
|
165
|
+
.sort((a, b) => toUpdatedAt(b) - toUpdatedAt(a))
|
|
166
|
+
.slice(0, safeLimit);
|
|
167
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const WECHAT_DIR_MODE = 448;
|
|
2
|
+
export declare const WECHAT_FILE_MODE = 384;
|
|
3
|
+
export type WechatRequestKind = "question" | "permission";
|
|
4
|
+
export declare function wechatStateRoot(): string;
|
|
5
|
+
export declare function brokerStatePath(): string;
|
|
6
|
+
export declare function brokerStateStorePath(): string;
|
|
7
|
+
export declare function brokerStateSchemaPath(): string;
|
|
8
|
+
export declare function wechatStatusRuntimeDiagnosticsPath(stateRoot?: string): string;
|
|
9
|
+
export declare function brokerStartupDiagnosticsPath(stateRoot?: string): string;
|
|
10
|
+
export declare function wechatBrokerDiagnosticsPath(stateRoot?: string): string;
|
|
11
|
+
export declare function wechatBridgeDiagnosticsPath(stateRoot?: string): string;
|
|
12
|
+
export declare function launchLockPath(): string;
|
|
13
|
+
export declare function operatorStatePath(): string;
|
|
14
|
+
export declare function instancesDir(): string;
|
|
15
|
+
export declare function instanceStatePath(instanceID: string): string;
|
|
16
|
+
export declare function tokensDir(): string;
|
|
17
|
+
export declare function tokenStatePath(wechatAccountId: string, userId: string): string;
|
|
18
|
+
export declare function latestAccountStatePath(stateRoot?: string): string;
|
|
19
|
+
export declare function notificationsDir(): string;
|
|
20
|
+
export declare function notificationStatePath(idempotencyKey: string): string;
|
|
21
|
+
export declare function requestKindDir(kind: WechatRequestKind): string;
|
|
22
|
+
export declare function requestStatePath(kind: WechatRequestKind, routeKey: string): string;
|
|
23
|
+
export declare function wechatDeadLetterRoot(stateRoot?: string): string;
|
|
24
|
+
export declare function wechatDeadLetterKindDir(kind: WechatRequestKind, stateRoot?: string): string;
|
|
25
|
+
export declare function wechatDeadLetterPath(kind: WechatRequestKind, routeKey: string, stateRoot?: string): string;
|
|
26
|
+
export declare function ensureWechatStateLayout(): Promise<void>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { mkdir } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { wechatBridgeDiagnosticsPath as defaultWechatBridgeDiagnosticsPath, wechatStatusRuntimeDiagnosticsPath as defaultWechatStatusRuntimeDiagnosticsPath, opencodeWechatConfigDir, wechatBrokerStateStorePath, wechatDeadLetterDir, wechatInstancesDir, wechatLatestAccountPath, wechatNotificationsDir, wechatOperatorPath, wechatRequestsDir, wechatTokensDir, } from "../store-paths.js";
|
|
4
|
+
export const WECHAT_DIR_MODE = 0o700;
|
|
5
|
+
export const WECHAT_FILE_MODE = 0o600;
|
|
6
|
+
export function wechatStateRoot() {
|
|
7
|
+
const override = process.env.WECHAT_STATE_ROOT_OVERRIDE;
|
|
8
|
+
if (typeof override === "string" && override.trim().length > 0) {
|
|
9
|
+
return override;
|
|
10
|
+
}
|
|
11
|
+
return opencodeWechatConfigDir();
|
|
12
|
+
}
|
|
13
|
+
function usesDefaultStateRoot(stateRoot = wechatStateRoot()) {
|
|
14
|
+
return stateRoot === opencodeWechatConfigDir();
|
|
15
|
+
}
|
|
16
|
+
export function brokerStatePath() {
|
|
17
|
+
return path.join(wechatStateRoot(), "broker.json");
|
|
18
|
+
}
|
|
19
|
+
export function brokerStateStorePath() {
|
|
20
|
+
return usesDefaultStateRoot() ? wechatBrokerStateStorePath() : path.join(wechatStateRoot(), "broker-state-store.json");
|
|
21
|
+
}
|
|
22
|
+
export function brokerStateSchemaPath() {
|
|
23
|
+
return path.join(wechatStateRoot(), "broker-state-store.schema.json");
|
|
24
|
+
}
|
|
25
|
+
export function wechatStatusRuntimeDiagnosticsPath(stateRoot = wechatStateRoot()) {
|
|
26
|
+
return usesDefaultStateRoot(stateRoot) ? defaultWechatStatusRuntimeDiagnosticsPath() : path.join(stateRoot, "wechat-status-runtime.diagnostics.jsonl");
|
|
27
|
+
}
|
|
28
|
+
export function brokerStartupDiagnosticsPath(stateRoot = wechatStateRoot()) {
|
|
29
|
+
return path.join(stateRoot, "broker-startup.diagnostics.log");
|
|
30
|
+
}
|
|
31
|
+
export function wechatBrokerDiagnosticsPath(stateRoot = wechatStateRoot()) {
|
|
32
|
+
return path.join(stateRoot, "wechat-broker.diagnostics.jsonl");
|
|
33
|
+
}
|
|
34
|
+
export function wechatBridgeDiagnosticsPath(stateRoot = wechatStateRoot()) {
|
|
35
|
+
return usesDefaultStateRoot(stateRoot) ? defaultWechatBridgeDiagnosticsPath() : path.join(stateRoot, "wechat-bridge.diagnostics.jsonl");
|
|
36
|
+
}
|
|
37
|
+
export function launchLockPath() {
|
|
38
|
+
return path.join(wechatStateRoot(), "launch.lock");
|
|
39
|
+
}
|
|
40
|
+
export function operatorStatePath() {
|
|
41
|
+
return usesDefaultStateRoot() ? wechatOperatorPath() : path.join(wechatStateRoot(), "operator.json");
|
|
42
|
+
}
|
|
43
|
+
export function instancesDir() {
|
|
44
|
+
return usesDefaultStateRoot() ? wechatInstancesDir() : path.join(wechatStateRoot(), "instances");
|
|
45
|
+
}
|
|
46
|
+
export function instanceStatePath(instanceID) {
|
|
47
|
+
return path.join(instancesDir(), `${instanceID}.json`);
|
|
48
|
+
}
|
|
49
|
+
export function tokensDir() {
|
|
50
|
+
return usesDefaultStateRoot() ? wechatTokensDir() : path.join(wechatStateRoot(), "tokens");
|
|
51
|
+
}
|
|
52
|
+
export function tokenStatePath(wechatAccountId, userId) {
|
|
53
|
+
return path.join(tokensDir(), wechatAccountId, `${userId}.json`);
|
|
54
|
+
}
|
|
55
|
+
export function latestAccountStatePath(stateRoot = wechatStateRoot()) {
|
|
56
|
+
return usesDefaultStateRoot(stateRoot) ? wechatLatestAccountPath() : path.join(stateRoot, "latest-account.json");
|
|
57
|
+
}
|
|
58
|
+
export function notificationsDir() {
|
|
59
|
+
return usesDefaultStateRoot() ? wechatNotificationsDir() : path.join(wechatStateRoot(), "notifications");
|
|
60
|
+
}
|
|
61
|
+
export function notificationStatePath(idempotencyKey) {
|
|
62
|
+
return path.join(notificationsDir(), `${idempotencyKey}.json`);
|
|
63
|
+
}
|
|
64
|
+
export function requestKindDir(kind) {
|
|
65
|
+
const requestsRoot = usesDefaultStateRoot() ? wechatRequestsDir() : path.join(wechatStateRoot(), "requests");
|
|
66
|
+
return path.join(requestsRoot, kind);
|
|
67
|
+
}
|
|
68
|
+
export function requestStatePath(kind, routeKey) {
|
|
69
|
+
return path.join(requestKindDir(kind), `${routeKey}.json`);
|
|
70
|
+
}
|
|
71
|
+
export function wechatDeadLetterRoot(stateRoot = wechatStateRoot()) {
|
|
72
|
+
return usesDefaultStateRoot(stateRoot) ? wechatDeadLetterDir() : path.join(stateRoot, "dead-letter");
|
|
73
|
+
}
|
|
74
|
+
export function wechatDeadLetterKindDir(kind, stateRoot = wechatStateRoot()) {
|
|
75
|
+
return path.join(wechatDeadLetterRoot(stateRoot), kind);
|
|
76
|
+
}
|
|
77
|
+
export function wechatDeadLetterPath(kind, routeKey, stateRoot = wechatStateRoot()) {
|
|
78
|
+
return path.join(wechatDeadLetterKindDir(kind, stateRoot), `${routeKey}.json`);
|
|
79
|
+
}
|
|
80
|
+
async function ensureDir(dirPath) {
|
|
81
|
+
await mkdir(dirPath, { recursive: true, mode: WECHAT_DIR_MODE });
|
|
82
|
+
}
|
|
83
|
+
export async function ensureWechatStateLayout() {
|
|
84
|
+
await ensureDir(wechatStateRoot());
|
|
85
|
+
await ensureDir(tokensDir());
|
|
86
|
+
await ensureDir(notificationsDir());
|
|
87
|
+
await ensureDir(instancesDir());
|
|
88
|
+
await ensureDir(wechatDeadLetterKindDir("question"));
|
|
89
|
+
await ensureDir(wechatDeadLetterKindDir("permission"));
|
|
90
|
+
await ensureDir(requestKindDir("question"));
|
|
91
|
+
await ensureDir(requestKindDir("permission"));
|
|
92
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BrokerAuthoritativeView } from "./broker-state-store.js";
|
|
2
|
+
export type AggregatedStatusInstance = {
|
|
3
|
+
instanceID: string;
|
|
4
|
+
status: "ok";
|
|
5
|
+
snapshot: unknown;
|
|
6
|
+
} | {
|
|
7
|
+
instanceID: string;
|
|
8
|
+
status: "timeout/unreachable";
|
|
9
|
+
};
|
|
10
|
+
type ActiveQuestionTodoItem = {
|
|
11
|
+
handle: string;
|
|
12
|
+
summary: string;
|
|
13
|
+
instanceID?: string;
|
|
14
|
+
createdAt?: number;
|
|
15
|
+
};
|
|
16
|
+
export type AggregatedStatusReplyInput = {
|
|
17
|
+
requestId: string;
|
|
18
|
+
instances: AggregatedStatusInstance[];
|
|
19
|
+
activeQuestions?: ActiveQuestionTodoItem[];
|
|
20
|
+
};
|
|
21
|
+
export declare function formatInstanceStatusSnapshot(snapshotInput: unknown): string;
|
|
22
|
+
export declare function formatAggregatedStatusReply(input: AggregatedStatusReplyInput): string;
|
|
23
|
+
export declare function buildAggregatedStatusInstancesFromBrokerView(view: BrokerAuthoritativeView | undefined): AggregatedStatusInstance[];
|
|
24
|
+
export declare function formatAggregatedStatusReplyFromBrokerView(view: BrokerAuthoritativeView | undefined): string;
|
|
25
|
+
export declare function formatTodoReplyFromBrokerView(view: BrokerAuthoritativeView | undefined): string;
|
|
26
|
+
export {};
|