@glows777/vela-lark 0.5.0 → 0.6.0-rc.1

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/legacy.d.ts DELETED
@@ -1,6 +0,0 @@
1
- /** Historical sender IDs are archives, never a chat/topic route or permission source. */
2
- export declare function isLegacySenderArchive(sessionDir: string, file: string): boolean;
3
- /** Old state must be explicitly migrated; never silently open a second conversation/store. */
4
- export declare function assertLarkState(dataDir: string): void;
5
- export declare function assertLarkEnv(env: Record<string, string | undefined>): void;
6
- //# sourceMappingURL=legacy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../src/legacy.ts"],"names":[],"mappings":"AAOA,yFAAyF;AACzF,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,GACX,OAAO,CAyBT;AAED,8FAA8F;AAC9F,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAiDrD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,IAAI,CAQ3E"}
package/dist/legacy.js DELETED
@@ -1,73 +0,0 @@
1
- import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { channelSessionId } from '@glows777/vela-channels';
4
- const instruction = 'Stop Vela and run bun scripts/migrate-lark.ts --data-dir <dataDir> --settings <settings.json> (dry run first, then --apply).';
5
- /** Historical sender IDs are archives, never a chat/topic route or permission source. */
6
- export function isLegacySenderArchive(sessionDir, file) {
7
- const id = file.endsWith('.jsonl') ? file.slice(0, -6) : file;
8
- // The built-in used open_id, then (chat_id, open_id), before shared chat sessions.
9
- // Provider IDs are short/plain; unknown or hashed tuples still require reconciliation.
10
- if (!/^feishu-(?:oc_[A-Za-z0-9_]+-)?(?:ou_[A-Za-z0-9_]+|unknown)$/.test(id))
11
- return false;
12
- const path = join(sessionDir, `${id}.jsonl`);
13
- if (!existsSync(path))
14
- return false;
15
- const line = readFileSync(path, 'utf8')
16
- .split('\n')
17
- .find((part) => part.trim());
18
- let first;
19
- try {
20
- first = line ? JSON.parse(line) : undefined;
21
- }
22
- catch (error) {
23
- if (!(error instanceof SyntaxError))
24
- throw error;
25
- return false; // A malformed would-be archive remains unknown/orphaned state.
26
- }
27
- return ((first?.type === 'session' && first.id === id) ||
28
- (first?.type === 'checkpoint' && Array.isArray(first.messages)) ||
29
- (first?.type === 'message' &&
30
- first.id === undefined &&
31
- first.message?.role === 'user'));
32
- }
33
- /** Old state must be explicitly migrated; never silently open a second conversation/store. */
34
- export function assertLarkState(dataDir) {
35
- const directory = join(dataDir, 'channels');
36
- const index = join(directory, 'index.json');
37
- const records = existsSync(index) ? JSON.parse(readFileSync(index, 'utf8')).records : [];
38
- if (records.some((record) => record.channel === 'feishu'))
39
- throw new Error(`Legacy Feishu routing requires migration to Lark. ${instruction}`);
40
- const stores = new Set();
41
- const sessions = new Set();
42
- for (const record of records.filter((entry) => entry.channel === 'lark')) {
43
- if (record.legacyKey &&
44
- record.legacyKey !==
45
- channelSessionId('feishu', record.chatId, record.rootId))
46
- throw new Error('Invalid legacy Lark routing metadata');
47
- if (record.storageKey) {
48
- if (record.storageKey !== channelSessionId('feishu', record.chatId))
49
- throw new Error('Invalid legacy Lark storage metadata');
50
- if (existsSync(join(directory, channelSessionId('lark', record.chatId))))
51
- throw new Error('Lark storage collision; resolve old/new stores before startup');
52
- stores.add(record.storageKey);
53
- }
54
- sessions.add(record.activeSessionId);
55
- for (const id of record.previousSessionIds)
56
- sessions.add(id);
57
- }
58
- for (const entry of existsSync(directory) ? readdirSync(directory) : [])
59
- if (entry.startsWith('feishu-') && !stores.has(entry))
60
- throw new Error(`Orphaned legacy Feishu storage ${entry}. ${instruction}`);
61
- const sessionDir = join(dataDir, 'sessions');
62
- for (const file of existsSync(sessionDir) ? readdirSync(sessionDir) : [])
63
- if (file.startsWith('feishu-') &&
64
- !sessions.has(file.endsWith('.jsonl') ? file.slice(0, -6) : file) &&
65
- !isLegacySenderArchive(sessionDir, file))
66
- throw new Error(`Orphaned legacy Feishu session ${file}. ${instruction}`);
67
- }
68
- export function assertLarkEnv(env) {
69
- const old = ['FEISHU_APP_ID', 'FEISHU_APP_SECRET', 'FEISHU_OWNERS'].filter((name) => env[name] !== undefined);
70
- if (old.length)
71
- throw new Error(`Legacy environment names: ${old.map((name) => `${name} -> ${name.replace('FEISHU_', 'LARK_')}`).join(', ')}. Remove old names after administrator cutover; values were not changed.`);
72
- }
73
- //# sourceMappingURL=legacy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy.js","sourceRoot":"","sources":["../src/legacy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAE1D,MAAM,WAAW,GACf,8HAA8H,CAAA;AAEhI,yFAAyF;AACzF,MAAM,UAAU,qBAAqB,CACnC,UAAkB,EAClB,IAAY;IAEZ,MAAM,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAC7D,mFAAmF;IACnF,uFAAuF;IACvF,IAAI,CAAC,6DAA6D,CAAC,IAAI,CAAC,EAAE,CAAC;QACzE,OAAO,KAAK,CAAA;IACd,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAA;IAC5C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAA;IACnC,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,E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