@syengup/friday-channel-next 0.0.37 → 0.0.39
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/index.js +10 -4
- package/index.ts +10 -4
- package/install.js +132 -257
- package/package.json +1 -1
- package/dist/attachments/0768c9b1-53b0-44df-83e8-be15c4ea188f.jpg +0 -0
- package/dist/attachments/0a379d01-116b-4da1-bf15-77cb2cbb0093.jpg +0 -0
- package/dist/attachments/181caab2-64a7-4004-a057-225a144f949e.mp3 +0 -0
- package/dist/attachments/19662331-e527-47d2-bc0e-0e19a7a91419.jpg +0 -0
- package/dist/attachments/26a23b2b-52df-4572-a5e1-15b34fb87e44.jpg +0 -0
- package/dist/attachments/2f9282c5-8db4-4c4a-a060-e65104f6f9ff.jpg +0 -0
- package/dist/attachments/3929ec3d-ea15-4de6-96bc-97e8b0b658a7.jpg +0 -0
- package/dist/attachments/403c0cbc-4e3c-4146-a3be-ff3746ee7cda.jpg +0 -0
- package/dist/attachments/441977f5-0f7b-4aa2-841a-1d63e787ea53.jpg +0 -0
- package/dist/attachments/453e8aa2-76e3-498d-8d6f-d7b96d6bf45b.jpg +0 -0
- package/dist/attachments/538cde71-d26e-4d3d-b901-e8dd905e668c.mp3 +0 -0
- package/dist/attachments/55c7f628-4ba2-4252-aa4b-4f3eb6045a8a.mp3 +0 -0
- package/dist/attachments/5f7683f5-8194-4698-b077-31d209525379.jpg +0 -0
- package/dist/attachments/60614a35-8f44-4197-b783-2f58f5a72ac8.jpeg +0 -0
- package/dist/attachments/62830489-8814-48b1-851c-3845e514f35e.mp3 +0 -0
- package/dist/attachments/66f4a62d-1531-4f38-a531-7456f9edf221.png +0 -0
- package/dist/attachments/6735d749-769e-483a-9b84-43b9338a720b.png +0 -0
- package/dist/attachments/6d1766b1-05e4-4b04-b3c8-1c25e9d182a1.png +0 -0
- package/dist/attachments/782b077b-06e3-484b-baf5-33e7160234ed.png +0 -0
- package/dist/attachments/7ad638b2-1f56-4d93-9ad8-b40346e0650f.jpg +0 -0
- package/dist/attachments/89f6fb15-e652-4111-a60c-baa414659052.png +0 -0
- package/dist/attachments/8a88b14f-442f-45fb-b01d-e51bab8f800d.mp3 +0 -0
- package/dist/attachments/92292034-9cf6-4f26-8d77-fddca3deb638.png +0 -0
- package/dist/attachments/92c2b414-d33d-4d93-bcb6-013da7bec9a4.jpg +0 -0
- package/dist/attachments/9664f69e-3c05-45ca-9a52-f2d0b9f9bf7e.jpg +0 -0
- package/dist/attachments/977d28c1-43c0-40e0-95e3-defe0f41afe8.jpg +0 -0
- package/dist/attachments/9df40f1a-c6e1-4177-8a03-06757a30b19e.png +0 -0
- package/dist/attachments/a68e6815-6163-4421-a70f-34493aa9a217.jpg +0 -0
- package/dist/attachments/aab32fea-6d99-47ec-ab1f-2340f31312eb.jpg +0 -0
- package/dist/attachments/ab403224-2fb1-49c1-8738-ea194ab65d44.png +0 -0
- package/dist/attachments/ac3da190-d6ee-4038-a673-8b893035a687.png +0 -0
- package/dist/attachments/af02be9c-87f7-4c5a-9969-7db32039bb58.png +0 -0
- package/dist/attachments/b011d42a-00e5-4f77-86bc-08da6112e6e1.mp3 +0 -0
- package/dist/attachments/b7d7df40-c627-4b1f-9b09-167b88545c25.mp3 +0 -0
- package/dist/attachments/c5e9bf09-a718-422c-bcb3-94c173e3755b.mp3 +0 -0
- package/dist/attachments/d5449e13-1995-44ba-9392-ecbfe5f9876f.jpg +0 -0
- package/dist/attachments/ea0069f5-01cf-4ea1-985e-3a1e426399c3.png +0 -0
- package/dist/attachments/f3989ff2-7b70-4a80-a896-74a6b197f7d8.png +0 -0
- package/dist/attachments/f64a4a14-e3aa-4eed-a8d9-1603f04baa5b.jpg +0 -0
- package/dist/src/http/handlers/device-token.d.ts +0 -2
- package/dist/src/http/handlers/device-token.js +0 -43
- package/dist/src/http/handlers/import.d.ts +0 -7
- package/dist/src/http/handlers/import.js +0 -69
- package/dist/src/http/handlers/info.d.ts +0 -2
- package/dist/src/http/handlers/info.js +0 -13
- package/dist/src/http/handlers/messages-list.d.ts +0 -7
- package/dist/src/http/handlers/messages-list.js +0 -44
- package/dist/src/http/handlers/pair.d.ts +0 -2
- package/dist/src/http/handlers/pair.js +0 -39
- package/dist/src/http/handlers/sessions-list.d.ts +0 -8
- package/dist/src/http/handlers/sessions-list.js +0 -24
- package/dist/src/http/handlers/sessions-messages-get.d.ts +0 -2
- package/dist/src/http/handlers/sessions-messages-get.js +0 -55
- package/dist/src/http/handlers/sessions-messages-post.d.ts +0 -2
- package/dist/src/http/handlers/sessions-messages-post.js +0 -92
- package/dist/src/http/handlers/sessions-messages.d.ts +0 -2
- package/dist/src/http/handlers/sessions-messages.js +0 -135
- package/dist/src/http/handlers/sync.d.ts +0 -7
- package/dist/src/http/handlers/sync.js +0 -56
- package/dist/src/push/apns.d.ts +0 -15
- package/dist/src/push/apns.js +0 -56
- package/dist/src/push/device-tokens.d.ts +0 -3
- package/dist/src/push/device-tokens.js +0 -39
- package/dist/src/sync/account-identity.d.ts +0 -14
- package/dist/src/sync/account-identity.js +0 -101
- package/dist/src/sync/archive.d.ts +0 -9
- package/dist/src/sync/archive.js +0 -25
- package/dist/src/sync/database.d.ts +0 -66
- package/dist/src/sync/database.js +0 -364
- package/dist/src/sync/init.d.ts +0 -3
- package/dist/src/sync/init.js +0 -14
- package/dist/src/sync/installation-id.d.ts +0 -1
- package/dist/src/sync/installation-id.js +0 -41
- package/dist/src/sync/message-accumulator.d.ts +0 -29
- package/dist/src/sync/message-accumulator.js +0 -188
- package/dist/src/sync/message-store.d.ts +0 -68
- package/dist/src/sync/message-store.js +0 -262
- package/dist/src/sync/push-store.d.ts +0 -5
- package/dist/src/sync/push-store.js +0 -54
- package/dist/src/sync/session-key.d.ts +0 -12
- package/dist/src/sync/session-key.js +0 -47
- package/dist/src/sync/sync-state.d.ts +0 -5
- package/dist/src/sync/sync-state.js +0 -54
- package/dist/src/sync/transcript-archive.d.ts +0 -13
- package/dist/src/sync/transcript-archive.js +0 -37
- package/dist/src/sync/transcript-store.d.ts +0 -35
- package/dist/src/sync/transcript-store.js +0 -221
- package/dist/src/sync/translate.d.ts +0 -42
- package/dist/src/sync/translate.js +0 -171
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { extractBearerToken } from "../middleware/auth.js";
|
|
2
|
-
import { readJsonBody } from "../middleware/body.js";
|
|
3
|
-
import { processSync } from "../../sync/message-store.js";
|
|
4
|
-
import { toSessionStoreKey } from "../../session/session-manager.js";
|
|
5
|
-
function extractSessionKey(url, prefix, suffix) {
|
|
6
|
-
const pathname = new URL(url, "http://localhost").pathname;
|
|
7
|
-
if (!pathname.startsWith(prefix) || !pathname.endsWith(suffix))
|
|
8
|
-
return null;
|
|
9
|
-
const middle = pathname.slice(prefix.length, pathname.length - suffix.length);
|
|
10
|
-
return decodeURIComponent(middle) || null;
|
|
11
|
-
}
|
|
12
|
-
export async function handleSync(req, res) {
|
|
13
|
-
if (req.method !== "POST") {
|
|
14
|
-
res.statusCode = 405;
|
|
15
|
-
res.setHeader("Content-Type", "application/json");
|
|
16
|
-
res.end(JSON.stringify({ error: "Method Not Allowed" }));
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
const token = extractBearerToken(req);
|
|
20
|
-
if (!token) {
|
|
21
|
-
res.statusCode = 401;
|
|
22
|
-
res.setHeader("Content-Type", "application/json");
|
|
23
|
-
res.end(JSON.stringify({ error: "Unauthorized" }));
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
const rawKey = extractSessionKey(req.url ?? "/", "/friday-next/sessions/", "/sync");
|
|
27
|
-
if (!rawKey) {
|
|
28
|
-
res.statusCode = 400;
|
|
29
|
-
res.setHeader("Content-Type", "application/json");
|
|
30
|
-
res.end(JSON.stringify({ error: "Missing sessionKey in URL path" }));
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
const sessionKey = toSessionStoreKey(rawKey);
|
|
34
|
-
const body = await readJsonBody(req);
|
|
35
|
-
if (!body) {
|
|
36
|
-
res.statusCode = 400;
|
|
37
|
-
res.setHeader("Content-Type", "application/json");
|
|
38
|
-
res.end(JSON.stringify({ error: "Invalid JSON body" }));
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
const deviceId = typeof body.deviceId === "string" ? body.deviceId.trim() : "";
|
|
42
|
-
if (!deviceId) {
|
|
43
|
-
res.statusCode = 400;
|
|
44
|
-
res.setHeader("Content-Type", "application/json");
|
|
45
|
-
res.end(JSON.stringify({ error: "Missing required field: deviceId" }));
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
const syncSeq = typeof body.syncSeq === "number" ? Math.floor(body.syncSeq) : 0;
|
|
49
|
-
const lastServerId = typeof body.lastServerId === "string" ? body.lastServerId : undefined;
|
|
50
|
-
const messages = Array.isArray(body.messages) ? body.messages : [];
|
|
51
|
-
const result = processSync({ sessionKey, deviceId, syncSeq, lastServerId, messages });
|
|
52
|
-
res.statusCode = 200;
|
|
53
|
-
res.setHeader("Content-Type", "application/json");
|
|
54
|
-
res.end(JSON.stringify(result));
|
|
55
|
-
return true;
|
|
56
|
-
}
|
package/dist/src/push/apns.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
type DeliverNotificationOpts = {
|
|
2
|
-
deviceId: string;
|
|
3
|
-
token: string;
|
|
4
|
-
summary: string;
|
|
5
|
-
sessionKey: string;
|
|
6
|
-
runId: string;
|
|
7
|
-
};
|
|
8
|
-
export declare class FridayPushService {
|
|
9
|
-
private provider;
|
|
10
|
-
private apn;
|
|
11
|
-
private getProvider;
|
|
12
|
-
sendDeliverNotification(opts: DeliverNotificationOpts): Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
export declare const fridayPush: FridayPushService;
|
|
15
|
-
export {};
|
package/dist/src/push/apns.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { resolveFridayNextConfig } from "../config.js";
|
|
2
|
-
import { getHostOpenClawConfigSnapshot } from "../host-config.js";
|
|
3
|
-
import { getFridayNextRuntime } from "../runtime.js";
|
|
4
|
-
export class FridayPushService {
|
|
5
|
-
provider = null;
|
|
6
|
-
apn = null;
|
|
7
|
-
async getProvider() {
|
|
8
|
-
const cfg = resolveFridayNextConfig(getHostOpenClawConfigSnapshot(getFridayNextRuntime().config));
|
|
9
|
-
const apnsCfg = cfg.push.apns;
|
|
10
|
-
if (!apnsCfg)
|
|
11
|
-
return null;
|
|
12
|
-
if (!this.apn) {
|
|
13
|
-
try {
|
|
14
|
-
this.apn = await import("apn");
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
const { keyPath, keyId, teamId, bundleId, production } = apnsCfg;
|
|
21
|
-
if (!keyPath || !keyId || !teamId)
|
|
22
|
-
return null;
|
|
23
|
-
if (!this.provider) {
|
|
24
|
-
this.provider = new this.apn.Provider({
|
|
25
|
-
token: {
|
|
26
|
-
key: keyPath,
|
|
27
|
-
keyId,
|
|
28
|
-
teamId,
|
|
29
|
-
},
|
|
30
|
-
production,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return { provider: this.provider, apn: this.apn, bundleId };
|
|
34
|
-
}
|
|
35
|
-
async sendDeliverNotification(opts) {
|
|
36
|
-
const ctx = await this.getProvider();
|
|
37
|
-
if (!ctx)
|
|
38
|
-
return;
|
|
39
|
-
const { provider, apn, bundleId } = ctx;
|
|
40
|
-
const note = new apn.Notification();
|
|
41
|
-
note.alert = {
|
|
42
|
-
title: "Friday",
|
|
43
|
-
body: opts.summary || "New reply ready",
|
|
44
|
-
};
|
|
45
|
-
note.sound = "default";
|
|
46
|
-
note.mutableContent = 1;
|
|
47
|
-
note.topic = bundleId;
|
|
48
|
-
note.payload = {
|
|
49
|
-
sessionKey: opts.sessionKey,
|
|
50
|
-
runId: opts.runId,
|
|
51
|
-
deviceId: opts.deviceId,
|
|
52
|
-
};
|
|
53
|
-
await provider.send(note, opts.token);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export const fridayPush = new FridayPushService();
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
function tokensPath() {
|
|
5
|
-
return path.join(os.homedir(), ".openclaw", "friday-next", "device-tokens.json");
|
|
6
|
-
}
|
|
7
|
-
function loadTokens() {
|
|
8
|
-
const file = tokensPath();
|
|
9
|
-
if (!fs.existsSync(file))
|
|
10
|
-
return {};
|
|
11
|
-
try {
|
|
12
|
-
const raw = fs.readFileSync(file, "utf8");
|
|
13
|
-
return JSON.parse(raw);
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
return {};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function saveTokens(tokens) {
|
|
20
|
-
const file = tokensPath();
|
|
21
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
22
|
-
fs.writeFileSync(file, JSON.stringify(tokens, null, 2), "utf8");
|
|
23
|
-
}
|
|
24
|
-
export function saveToken(deviceId, token) {
|
|
25
|
-
const key = deviceId.trim().toUpperCase();
|
|
26
|
-
const tokens = loadTokens();
|
|
27
|
-
tokens[key] = { token, updatedAt: Date.now() };
|
|
28
|
-
saveTokens(tokens);
|
|
29
|
-
}
|
|
30
|
-
export function getToken(deviceId) {
|
|
31
|
-
const key = deviceId.trim().toUpperCase();
|
|
32
|
-
return loadTokens()[key]?.token ?? null;
|
|
33
|
-
}
|
|
34
|
-
export function removeToken(deviceId) {
|
|
35
|
-
const key = deviceId.trim().toUpperCase();
|
|
36
|
-
const tokens = loadTokens();
|
|
37
|
-
delete tokens[key];
|
|
38
|
-
saveTokens(tokens);
|
|
39
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { IncomingMessage } from "node:http";
|
|
2
|
-
export interface PairAccountResult {
|
|
3
|
-
accountId: string;
|
|
4
|
-
status: "new" | "existing" | "unknown";
|
|
5
|
-
suggestedAccountId?: string;
|
|
6
|
-
}
|
|
7
|
-
export declare function getOrCreateAccountId(params: {
|
|
8
|
-
deviceId: string;
|
|
9
|
-
claimAccountId?: string;
|
|
10
|
-
claimConfirmed?: boolean;
|
|
11
|
-
historyDir?: string;
|
|
12
|
-
}): PairAccountResult;
|
|
13
|
-
export declare function isKnownAccountId(accountId: string, historyDir?: string): boolean;
|
|
14
|
-
export declare function resolveAccountIdFromRequest(req: IncomingMessage): string | null;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import crypto from "node:crypto";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { resolveFridayNextConfig } from "../config.js";
|
|
5
|
-
import { getHostOpenClawConfigSnapshot } from "../host-config.js";
|
|
6
|
-
import { getFridayNextRuntime } from "../runtime.js";
|
|
7
|
-
function currentHistoryDir() {
|
|
8
|
-
const cfg = resolveFridayNextConfig(getHostOpenClawConfigSnapshot(getFridayNextRuntime().config));
|
|
9
|
-
return cfg.historyDir;
|
|
10
|
-
}
|
|
11
|
-
function indexPath(historyDir = currentHistoryDir()) {
|
|
12
|
-
return path.join(historyDir, "accounts", "index.json");
|
|
13
|
-
}
|
|
14
|
-
function normalizeDeviceId(deviceId) {
|
|
15
|
-
return deviceId.trim().toUpperCase();
|
|
16
|
-
}
|
|
17
|
-
function readIndex(historyDir = currentHistoryDir()) {
|
|
18
|
-
try {
|
|
19
|
-
const parsed = JSON.parse(fs.readFileSync(indexPath(historyDir), "utf8"));
|
|
20
|
-
return {
|
|
21
|
-
accounts: parsed.accounts && typeof parsed.accounts === "object" ? parsed.accounts : {},
|
|
22
|
-
deviceToAccount: parsed.deviceToAccount && typeof parsed.deviceToAccount === "object" ? parsed.deviceToAccount : {},
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
return { accounts: {}, deviceToAccount: {} };
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function writeIndex(index, historyDir = currentHistoryDir()) {
|
|
30
|
-
const file = indexPath(historyDir);
|
|
31
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
32
|
-
fs.writeFileSync(file, JSON.stringify(index, null, 2), "utf8");
|
|
33
|
-
}
|
|
34
|
-
function touchAccount(index, accountId, deviceId) {
|
|
35
|
-
const now = Date.now();
|
|
36
|
-
const existing = index.accounts[accountId];
|
|
37
|
-
const entry = existing ?? {
|
|
38
|
-
accountId,
|
|
39
|
-
createdAt: now,
|
|
40
|
-
lastSeenAt: now,
|
|
41
|
-
deviceIds: [],
|
|
42
|
-
};
|
|
43
|
-
entry.lastSeenAt = now;
|
|
44
|
-
if (deviceId) {
|
|
45
|
-
const normalized = normalizeDeviceId(deviceId);
|
|
46
|
-
if (normalized && !entry.deviceIds.includes(normalized)) {
|
|
47
|
-
entry.deviceIds.push(normalized);
|
|
48
|
-
}
|
|
49
|
-
if (normalized)
|
|
50
|
-
index.deviceToAccount[normalized] = accountId;
|
|
51
|
-
}
|
|
52
|
-
index.accounts[accountId] = entry;
|
|
53
|
-
return entry;
|
|
54
|
-
}
|
|
55
|
-
export function getOrCreateAccountId(params) {
|
|
56
|
-
const historyDir = params.historyDir ?? currentHistoryDir();
|
|
57
|
-
const index = readIndex(historyDir);
|
|
58
|
-
const deviceId = normalizeDeviceId(params.deviceId);
|
|
59
|
-
const claimed = params.claimAccountId?.trim();
|
|
60
|
-
if (claimed) {
|
|
61
|
-
const existed = Boolean(index.accounts[claimed]);
|
|
62
|
-
if (existed || params.claimConfirmed === true) {
|
|
63
|
-
touchAccount(index, claimed, deviceId);
|
|
64
|
-
writeIndex(index, historyDir);
|
|
65
|
-
return { accountId: claimed, status: existed ? "existing" : "new" };
|
|
66
|
-
}
|
|
67
|
-
const suggested = crypto.randomUUID();
|
|
68
|
-
return { accountId: suggested, status: "unknown", suggestedAccountId: suggested };
|
|
69
|
-
}
|
|
70
|
-
const mapped = deviceId ? index.deviceToAccount[deviceId] : undefined;
|
|
71
|
-
if (mapped && index.accounts[mapped]) {
|
|
72
|
-
touchAccount(index, mapped, deviceId);
|
|
73
|
-
writeIndex(index, historyDir);
|
|
74
|
-
return { accountId: mapped, status: "existing" };
|
|
75
|
-
}
|
|
76
|
-
const existingAccounts = Object.values(index.accounts);
|
|
77
|
-
if (existingAccounts.length === 1) {
|
|
78
|
-
const accountId = existingAccounts[0].accountId;
|
|
79
|
-
touchAccount(index, accountId, deviceId);
|
|
80
|
-
writeIndex(index, historyDir);
|
|
81
|
-
return { accountId, status: "existing" };
|
|
82
|
-
}
|
|
83
|
-
const accountId = crypto.randomUUID();
|
|
84
|
-
touchAccount(index, accountId, deviceId);
|
|
85
|
-
writeIndex(index, historyDir);
|
|
86
|
-
return { accountId, status: "new" };
|
|
87
|
-
}
|
|
88
|
-
export function isKnownAccountId(accountId, historyDir = currentHistoryDir()) {
|
|
89
|
-
const id = accountId.trim();
|
|
90
|
-
if (!id)
|
|
91
|
-
return false;
|
|
92
|
-
return Boolean(readIndex(historyDir).accounts[id]);
|
|
93
|
-
}
|
|
94
|
-
export function resolveAccountIdFromRequest(req) {
|
|
95
|
-
const raw = req.headers["x-account-id"];
|
|
96
|
-
const accountId = Array.isArray(raw) ? raw[0] : raw;
|
|
97
|
-
if (typeof accountId !== "string" || !accountId.trim())
|
|
98
|
-
return null;
|
|
99
|
-
const trimmed = accountId.trim();
|
|
100
|
-
return isKnownAccountId(trimmed) ? trimmed : null;
|
|
101
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { IncomingMessage } from "node:http";
|
|
2
|
-
import { type TranscriptEventInput } from "./transcript-store.js";
|
|
3
|
-
export declare function accountIdFromSessionKey(sessionKey: string): string | null;
|
|
4
|
-
export declare function resolveArchiveAccountId(req: IncomingMessage | null, sessionKey: string): string | null;
|
|
5
|
-
export declare function archiveTranscriptEvent(params: {
|
|
6
|
-
accountId: string | null | undefined;
|
|
7
|
-
sessionKey: string | null | undefined;
|
|
8
|
-
event: TranscriptEventInput;
|
|
9
|
-
}): void;
|
package/dist/src/sync/archive.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { resolveAccountIdFromRequest } from "./account-identity.js";
|
|
2
|
-
import { getTranscriptStore } from "./transcript-store.js";
|
|
3
|
-
export function accountIdFromSessionKey(sessionKey) {
|
|
4
|
-
const trimmed = sessionKey.trim();
|
|
5
|
-
const rawMatch = trimmed.match(/^friday:account:([^:]+):/i);
|
|
6
|
-
if (rawMatch?.[1])
|
|
7
|
-
return rawMatch[1];
|
|
8
|
-
const storeMatch = trimmed.match(/^agent:main:friday:account:([^:]+):/i);
|
|
9
|
-
return storeMatch?.[1] ?? null;
|
|
10
|
-
}
|
|
11
|
-
export function resolveArchiveAccountId(req, sessionKey) {
|
|
12
|
-
return (req ? resolveAccountIdFromRequest(req) : null) ?? accountIdFromSessionKey(sessionKey);
|
|
13
|
-
}
|
|
14
|
-
export function archiveTranscriptEvent(params) {
|
|
15
|
-
const accountId = params.accountId?.trim();
|
|
16
|
-
const sessionKey = params.sessionKey?.trim();
|
|
17
|
-
if (!accountId || !sessionKey)
|
|
18
|
-
return;
|
|
19
|
-
try {
|
|
20
|
-
getTranscriptStore().appendEvent(accountId, sessionKey, params.event);
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
console.error(`[Friday-SYNC] archive failed: ${String(err)}`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import Database from "better-sqlite3";
|
|
2
|
-
/** ULID-like server ID: time-sortable (monotonic within same ms), globally unique. */
|
|
3
|
-
export declare function generateServerId(): string;
|
|
4
|
-
export type SyncMessageRecord = {
|
|
5
|
-
server_id: string;
|
|
6
|
-
session_key: string;
|
|
7
|
-
local_id: string | null;
|
|
8
|
-
sender_type: "user" | "assistant";
|
|
9
|
-
sender_name: string;
|
|
10
|
-
content: string;
|
|
11
|
-
timestamp_ms: number;
|
|
12
|
-
seq: number;
|
|
13
|
-
status: string;
|
|
14
|
-
is_from_current_user: number;
|
|
15
|
-
message_json: string;
|
|
16
|
-
run_id: string | null;
|
|
17
|
-
created_at: string;
|
|
18
|
-
};
|
|
19
|
-
export type SyncSessionRecord = {
|
|
20
|
-
session_key: string;
|
|
21
|
-
device_id: string;
|
|
22
|
-
title: string;
|
|
23
|
-
created_at: string;
|
|
24
|
-
last_active_at: string;
|
|
25
|
-
message_count: number;
|
|
26
|
-
latest_msg_id: string | null;
|
|
27
|
-
};
|
|
28
|
-
export type SyncStateRecord = {
|
|
29
|
-
device_id: string;
|
|
30
|
-
last_sync_seq: number;
|
|
31
|
-
updated_at: string;
|
|
32
|
-
};
|
|
33
|
-
export declare function resolveSyncDbPath(): string;
|
|
34
|
-
export declare function initDatabase(dbPath?: string): void;
|
|
35
|
-
/** Test-only: initialize with an in-memory database. */
|
|
36
|
-
export declare function initMemoryDatabase(): void;
|
|
37
|
-
export declare function getDatabase(): Database.Database;
|
|
38
|
-
export declare function closeDatabase(): void;
|
|
39
|
-
export interface InsertMessageParams {
|
|
40
|
-
serverId: string;
|
|
41
|
-
sessionKey: string;
|
|
42
|
-
deviceId?: string;
|
|
43
|
-
localId?: string | null;
|
|
44
|
-
senderType: "user" | "assistant";
|
|
45
|
-
senderName: string;
|
|
46
|
-
content: string;
|
|
47
|
-
timestampMs: number;
|
|
48
|
-
seq: number;
|
|
49
|
-
status: string;
|
|
50
|
-
isFromCurrentUser: boolean;
|
|
51
|
-
messageJson: string;
|
|
52
|
-
runId?: string | null;
|
|
53
|
-
}
|
|
54
|
-
export declare function insertMessage(params: InsertMessageParams): void;
|
|
55
|
-
export declare function getMessagesAfterCursor(sessionKey: string, afterServerId: string, limit: number): string[];
|
|
56
|
-
export declare function getLatestServerId(sessionKey: string): string | null;
|
|
57
|
-
export declare function getMessagesBeforeCursor(sessionKey: string, beforeServerId: string, limit: number): string[];
|
|
58
|
-
export declare function getLastMessageJson(sessionKey: string): string | null;
|
|
59
|
-
export declare function getLastSyncSeq(deviceId: string): number;
|
|
60
|
-
export declare function setLastSyncSeq(deviceId: string, seq: number): void;
|
|
61
|
-
export declare function sessionExists(sessionKey: string): boolean;
|
|
62
|
-
export declare function getSessionMessageCount(sessionKey: string): number;
|
|
63
|
-
export declare function listSessionsByDevice(deviceId: string): SyncSessionRecord[];
|
|
64
|
-
export declare function listAllSessions(): SyncSessionRecord[];
|
|
65
|
-
export declare function findServerIdByRunAndSender(runId: string, senderType: string): string | null;
|
|
66
|
-
export declare function deleteSessionFromDb(sessionKey: string): void;
|