@wirecat/tg-cli 0.99.0 → 0.101.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/README.md +6 -5
- package/dist/bin/tg.js +23 -28
- package/dist/bundle/adapter-A3VD4Y6Z.js +2790 -0
- package/dist/bundle/all-profiles-UPVNHXB2.js +264 -0
- package/dist/bundle/anthropic-IRKNWPIB.js +71 -0
- package/dist/bundle/bot-api-UNTQG2M5.js +39793 -0
- package/dist/bundle/bot-history-V4RTY5K7.js +167 -0
- package/dist/bundle/bun-2JZPG2NL.js +169 -0
- package/dist/bundle/bun-sqlite-TZHKM225.js +70 -0
- package/dist/bundle/chunk-22PQUX72.js +190 -0
- package/dist/bundle/chunk-2DGOFLDA.js +58 -0
- package/dist/bundle/chunk-2SJOUK6J.js +2 -0
- package/dist/bundle/chunk-2XBSVRT2.js +98 -0
- package/dist/bundle/chunk-3KHKYYCR.js +24782 -0
- package/dist/bundle/chunk-4ZS73HTJ.js +6848 -0
- package/dist/bundle/chunk-54R2GDQ3.js +119 -0
- package/dist/bundle/chunk-5GKXETRP.js +1345 -0
- package/dist/bundle/chunk-5KU4UQBM.js +570 -0
- package/dist/bundle/chunk-5TPT2S2Z.js +41 -0
- package/dist/bundle/chunk-64DK7S4F.js +76 -0
- package/dist/bundle/chunk-6IPY2QRG.js +82 -0
- package/dist/bundle/chunk-7BFO3DY6.js +21 -0
- package/dist/bundle/chunk-7CBUCTB6.js +1142 -0
- package/dist/bundle/chunk-A5JSTZZZ.js +122 -0
- package/dist/bundle/chunk-ACGTFLEB.js +1275 -0
- package/dist/bundle/chunk-AFV74GK3.js +50 -0
- package/dist/bundle/chunk-AVWK4NCW.js +24600 -0
- package/dist/bundle/chunk-BJG6JA5U.js +35 -0
- package/dist/bundle/chunk-BX6HH4F6.js +215 -0
- package/dist/bundle/chunk-BXQS5RCE.js +8170 -0
- package/dist/bundle/chunk-CJ6IYCYP.js +583 -0
- package/dist/bundle/chunk-DG62L57H.js +2795 -0
- package/dist/bundle/chunk-DYNSP6FW.js +33720 -0
- package/dist/bundle/chunk-F7TDFWXY.js +82 -0
- package/dist/bundle/chunk-G2US6LJB.js +35 -0
- package/dist/bundle/chunk-G3ZRY436.js +3077 -0
- package/dist/bundle/chunk-G77QOTXE.js +18 -0
- package/dist/bundle/chunk-H6OXALTJ.js +45 -0
- package/dist/bundle/chunk-LPB2MDUW.js +452 -0
- package/dist/bundle/chunk-MLLJ74LM.js +24 -0
- package/dist/bundle/chunk-N5UFBWDM.js +166 -0
- package/dist/bundle/chunk-NC5WS7OP.js +31 -0
- package/dist/bundle/chunk-NKJJJAIJ.js +237 -0
- package/dist/bundle/chunk-NMGO6LW6.js +1950 -0
- package/dist/bundle/chunk-ODSVNH3H.js +18588 -0
- package/dist/bundle/chunk-OEJ5DMCX.js +2374 -0
- package/dist/bundle/chunk-OILBDLWL.js +724 -0
- package/dist/bundle/chunk-OPBTNQ35.js +1007 -0
- package/dist/bundle/chunk-PUBS2F5J.js +35803 -0
- package/dist/bundle/chunk-PYTOIDSM.js +153 -0
- package/dist/bundle/chunk-QOWSVDPZ.js +3526 -0
- package/dist/bundle/chunk-QYVVRQTN.js +73 -0
- package/dist/bundle/chunk-RF54YDBB.js +46 -0
- package/dist/bundle/chunk-RVCS7Q3A.js +6672 -0
- package/dist/bundle/chunk-S2JSZWEC.js +277 -0
- package/dist/bundle/chunk-S7ZNLLY5.js +54 -0
- package/dist/bundle/chunk-TGREFJVA.js +2315 -0
- package/dist/bundle/chunk-U46UNBMT.js +524 -0
- package/dist/bundle/chunk-UN6CKIBN.js +285 -0
- package/dist/bundle/chunk-VA5YEJS3.js +161 -0
- package/dist/bundle/chunk-VCGL2ETF.js +78 -0
- package/dist/bundle/chunk-VRSN7VLO.js +63 -0
- package/dist/bundle/chunk-VYDTI254.js +3332 -0
- package/dist/bundle/chunk-W2336E7Y.js +886 -0
- package/dist/bundle/chunk-X4Y2ROJI.js +541 -0
- package/dist/bundle/chunk-XCKD54TN.js +100 -0
- package/dist/bundle/chunk-ZEOCU24Z.js +738 -0
- package/dist/bundle/chunk-ZJVZXJOG.js +71 -0
- package/dist/bundle/chunk-ZV24I2UJ.js +25 -0
- package/dist/bundle/chunk-ZZLKX62Z.js +928 -0
- package/dist/bundle/command-contract-TKDI7E56.js +31 -0
- package/dist/bundle/dist-RJMT44PL.js +7577 -0
- package/dist/bundle/echarts-QZ6PR3VC.js +42501 -0
- package/dist/bundle/embed-UBXCXSRD.js +35 -0
- package/dist/bundle/embedder-B4ZTKC23.js +108 -0
- package/dist/bundle/entry-BTUTHO5M.js +14 -0
- package/dist/bundle/first-run-UC4HRIFV.js +24 -0
- package/dist/bundle/first-screen-SMCX6YKY.js +29 -0
- package/dist/bundle/identity-QSDEGDH7.js +11 -0
- package/dist/bundle/instructions-BBGLZKO3.js +9 -0
- package/dist/bundle/mcp-4Y37G2UY.js +165 -0
- package/dist/bundle/node-IUL5HSYI.js +2340 -0
- package/dist/bundle/node-LZZX22VR.js +176 -0
- package/dist/bundle/node-UPPL626U.js +21 -0
- package/dist/bundle/node-sqlite-BPGT6T5U.js +46 -0
- package/dist/bundle/oauth-XNE2KPKJ.js +18 -0
- package/dist/bundle/open-SXGYZLB5.js +20 -0
- package/dist/bundle/process-GPUXC4PG.js +91 -0
- package/dist/bundle/program-NEXEAL7T.js +1060 -0
- package/dist/bundle/prompt-SORGLEYI.js +13 -0
- package/dist/bundle/proxy-transport-G4MA6BGU.js +17 -0
- package/dist/bundle/recognize-UJBXORVD.js +191 -0
- package/dist/bundle/remote-W72AR7KH.js +26 -0
- package/dist/bundle/rerank-3Y2VZM3J.js +49 -0
- package/dist/bundle/serve-VDZIVOPR.js +196 -0
- package/dist/bundle/server-BERXP4GW.js +785 -0
- package/dist/bundle/server-ZFHN4GUF.js +178 -0
- package/dist/bundle/state-DGR4EE3E.js +34 -0
- package/dist/bundle/store-MRCFSCZD.js +121 -0
- package/dist/bundle/store-maintenance-command-DCMZDMYS.js +46 -0
- package/dist/bundle/tg.js +40 -0
- package/dist/commands/context.d.ts.map +1 -1
- package/dist/commands/context.js +3 -1
- package/dist/commands/context.js.map +1 -1
- package/dist/install/postinstall.js +1 -1
- package/dist/install/postinstall.js.map +1 -1
- package/dist/program.js +1 -1
- package/dist/program.js.map +1 -1
- package/dist/telegram/errors.js +1 -1
- package/dist/telegram/errors.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/install/windows.ps1 +1 -1
- package/package.json +6 -4
- package/skills/{wirecat-tg → tg-cli}/SKILL.md +4 -4
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { createRequire as __tgRequire } from "node:module";
|
|
2
|
+
const require = __tgRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
openSessionStorage,
|
|
5
|
+
toCliError,
|
|
6
|
+
toHistoryChannel,
|
|
7
|
+
toHistoryMessages
|
|
8
|
+
} from "./chunk-ZEOCU24Z.js";
|
|
9
|
+
import {
|
|
10
|
+
proxiedTransport
|
|
11
|
+
} from "./chunk-ZJVZXJOG.js";
|
|
12
|
+
import "./chunk-2XBSVRT2.js";
|
|
13
|
+
import "./chunk-RF54YDBB.js";
|
|
14
|
+
import "./chunk-54R2GDQ3.js";
|
|
15
|
+
import "./chunk-PUBS2F5J.js";
|
|
16
|
+
import "./chunk-G3ZRY436.js";
|
|
17
|
+
import "./chunk-TGREFJVA.js";
|
|
18
|
+
import "./chunk-W2336E7Y.js";
|
|
19
|
+
import "./chunk-2SJOUK6J.js";
|
|
20
|
+
import "./chunk-G77QOTXE.js";
|
|
21
|
+
import "./chunk-XCKD54TN.js";
|
|
22
|
+
import "./chunk-4ZS73HTJ.js";
|
|
23
|
+
import "./chunk-DG62L57H.js";
|
|
24
|
+
import {
|
|
25
|
+
CliError,
|
|
26
|
+
isCliError
|
|
27
|
+
} from "./chunk-OEJ5DMCX.js";
|
|
28
|
+
import "./chunk-BJG6JA5U.js";
|
|
29
|
+
import {
|
|
30
|
+
__name
|
|
31
|
+
} from "./chunk-AFV74GK3.js";
|
|
32
|
+
|
|
33
|
+
// dist/telegram/bot-history.js
|
|
34
|
+
import { mkdirSync } from "node:fs";
|
|
35
|
+
import { dirname } from "node:path";
|
|
36
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
37
|
+
import { getMarkedPeerId, Long, MtPeerNotFoundError, TelegramClient } from "@mtcute/node";
|
|
38
|
+
import { links } from "@mtcute/node/utils.js";
|
|
39
|
+
var numberOf = /* @__PURE__ */ __name((id, maximum = 2147483647) => {
|
|
40
|
+
const number = Number(id);
|
|
41
|
+
if (!/^\d+$/.test(id) || !Number.isInteger(number) || number < 1 || number > maximum)
|
|
42
|
+
throw new CliError("validation_error", "a Telegram message number must be between 1 and 2147483647");
|
|
43
|
+
return number;
|
|
44
|
+
}, "numberOf");
|
|
45
|
+
var channelNumber = /* @__PURE__ */ __name((chat) => {
|
|
46
|
+
const id = Number(chat);
|
|
47
|
+
if (!/^-\d+$/.test(chat) || !Number.isSafeInteger(id) || id >= -1e12)
|
|
48
|
+
throw new CliError("validation_error", "bot messages sync supports channels and supergroups only; private chats and basic groups share one message numbering across all of the bot's chats");
|
|
49
|
+
return id;
|
|
50
|
+
}, "channelNumber");
|
|
51
|
+
var historyError = /* @__PURE__ */ __name((error, words) => {
|
|
52
|
+
const mapped = toCliError(error, words, words("bot.auth.set"));
|
|
53
|
+
if (isCliError(mapped))
|
|
54
|
+
return mapped;
|
|
55
|
+
return new CliError(error instanceof Error && error.name === "AbortError" ? "cancelled" : "provider_error", "Telegram history read did not finish");
|
|
56
|
+
}, "historyError");
|
|
57
|
+
var openBotHistory = /* @__PURE__ */ __name(async (options) => {
|
|
58
|
+
mkdirSync(dirname(options.sessionPath), { recursive: true, mode: 448 });
|
|
59
|
+
const proxied = options.proxy ? proxiedTransport(options.proxy) : void 0;
|
|
60
|
+
const client = new TelegramClient({
|
|
61
|
+
...proxied ? { transport: proxied.transport } : {},
|
|
62
|
+
apiId: options.credentials.id,
|
|
63
|
+
apiHash: options.credentials.hash,
|
|
64
|
+
storage: await openSessionStorage(options.sessionPath),
|
|
65
|
+
// The storage manager has an exit hook of its own; the close is the command's (storage.ts `setup`).
|
|
66
|
+
storageOptions: { cleanup: false },
|
|
67
|
+
disableUpdates: true,
|
|
68
|
+
logLevel: 0
|
|
69
|
+
});
|
|
70
|
+
client.log.mgr.handler = () => {
|
|
71
|
+
};
|
|
72
|
+
let closing;
|
|
73
|
+
const close = /* @__PURE__ */ __name(() => closing ??= client.destroy(), "close");
|
|
74
|
+
options.track?.({ close });
|
|
75
|
+
try {
|
|
76
|
+
const starting = client.start({ botToken: options.token, ...options.stop ? { abortSignal: options.stop } : {} });
|
|
77
|
+
const self = await (proxied ? Promise.race([starting, proxied.failed]) : starting);
|
|
78
|
+
if (!self.isBot || String(self.id) !== options.token.split(":", 1)[0])
|
|
79
|
+
throw new CliError("authentication_error", "the history session belongs to a different bot");
|
|
80
|
+
} catch (error) {
|
|
81
|
+
await close();
|
|
82
|
+
throw historyError(error, options.checks);
|
|
83
|
+
}
|
|
84
|
+
const channelOf = /* @__PURE__ */ __name(async (chatId) => {
|
|
85
|
+
try {
|
|
86
|
+
return await client.resolveChannel(chatId);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (!(error instanceof MtPeerNotFoundError))
|
|
89
|
+
throw error;
|
|
90
|
+
const id = -chatId - 1e12;
|
|
91
|
+
const result = await client.call({ _: "channels.getChannels", id: [{ _: "inputChannel", channelId: id, accessHash: Long.ZERO }] }, { floodSleepThreshold: 0 });
|
|
92
|
+
const channel = toHistoryChannel(result.chats, id);
|
|
93
|
+
if (!channel)
|
|
94
|
+
throw new CliError("permission_error", "this bot cannot access that channel or supergroup");
|
|
95
|
+
return channel;
|
|
96
|
+
}
|
|
97
|
+
}, "channelOf");
|
|
98
|
+
let pending;
|
|
99
|
+
return {
|
|
100
|
+
close,
|
|
101
|
+
historyBefore: /* @__PURE__ */ __name(async (chat, window) => {
|
|
102
|
+
try {
|
|
103
|
+
const chatId = channelNumber(chat);
|
|
104
|
+
const channel = await channelOf(chatId);
|
|
105
|
+
let before = window.before === void 0 ? void 0 : numberOf(window.before, 2147483648);
|
|
106
|
+
if (pending?.chat === chat && pending.before === window.before)
|
|
107
|
+
before = pending.next;
|
|
108
|
+
if (before === void 0) {
|
|
109
|
+
let newest;
|
|
110
|
+
if (options.from !== void 0) {
|
|
111
|
+
let link;
|
|
112
|
+
try {
|
|
113
|
+
link = links.message.parse(options.from);
|
|
114
|
+
} catch {
|
|
115
|
+
link = null;
|
|
116
|
+
}
|
|
117
|
+
if (!link || link.commentId !== void 0)
|
|
118
|
+
throw new CliError("validation_error", "--from takes a channel or supergroup message link, without comments");
|
|
119
|
+
const linkedId = "username" in link ? getMarkedPeerId(await client.resolvePeer(link.username)) : -1e12 - link.channelId;
|
|
120
|
+
if (linkedId !== chatId)
|
|
121
|
+
throw new CliError("validation_error", "--from names a message in a different chat");
|
|
122
|
+
newest = String(link.id);
|
|
123
|
+
} else
|
|
124
|
+
newest = await options.newest(chat);
|
|
125
|
+
if (newest === void 0)
|
|
126
|
+
throw new CliError("validation_error", "no newest message number is known for this chat \u2014 give --until-id <message link>, or keep a bot update first");
|
|
127
|
+
before = numberOf(newest) + 1;
|
|
128
|
+
}
|
|
129
|
+
let cursor = before;
|
|
130
|
+
while (cursor > 1) {
|
|
131
|
+
options.stop?.throwIfAborted();
|
|
132
|
+
const low = Math.max(1, cursor - Math.min(100, window.limit));
|
|
133
|
+
const ids = Array.from({ length: cursor - low }, (_, index) => ({
|
|
134
|
+
_: "inputMessageID",
|
|
135
|
+
id: cursor - index - 1
|
|
136
|
+
}));
|
|
137
|
+
options.events?.({ event: "request", operation: "bot.history", counts: { ids: ids.length } });
|
|
138
|
+
const result = await client.call({ _: "channels.getMessages", channel, id: ids }, { floodSleepThreshold: 0 });
|
|
139
|
+
if (result._ === "messages.messagesNotModified")
|
|
140
|
+
throw new CliError("provider_error", "Telegram returned no message page for this id range");
|
|
141
|
+
const items = toHistoryMessages(result).sort((a, b) => Number(b.id) - Number(a.id));
|
|
142
|
+
options.events?.({
|
|
143
|
+
event: "response",
|
|
144
|
+
operation: "bot.history",
|
|
145
|
+
outcome: "ok",
|
|
146
|
+
counts: { messages: items.length }
|
|
147
|
+
});
|
|
148
|
+
if (items.length > 0) {
|
|
149
|
+
pending = void 0;
|
|
150
|
+
return { items, hasMore: low > 1 };
|
|
151
|
+
}
|
|
152
|
+
cursor = low;
|
|
153
|
+
pending = { chat, before: window.before, next: cursor };
|
|
154
|
+
if (cursor > 1)
|
|
155
|
+
await sleep(options.pauseMs, void 0, options.stop ? { signal: options.stop } : {});
|
|
156
|
+
}
|
|
157
|
+
pending = void 0;
|
|
158
|
+
return { items: [], hasMore: false };
|
|
159
|
+
} catch (error) {
|
|
160
|
+
throw historyError(error, options.checks);
|
|
161
|
+
}
|
|
162
|
+
}, "historyBefore")
|
|
163
|
+
};
|
|
164
|
+
}, "openBotHistory");
|
|
165
|
+
export {
|
|
166
|
+
openBotHistory
|
|
167
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { createRequire as __tgRequire } from "node:module";
|
|
2
|
+
const require = __tgRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
DefaultLogger,
|
|
5
|
+
DrizzleQueryError,
|
|
6
|
+
NoopLogger,
|
|
7
|
+
SQLiteAsyncDatabase,
|
|
8
|
+
SQLiteAsyncPreparedQuery,
|
|
9
|
+
SQLiteAsyncSession,
|
|
10
|
+
SQLiteAsyncTransaction,
|
|
11
|
+
SQLiteDialect,
|
|
12
|
+
booleanFromInteger,
|
|
13
|
+
bufferFromBytes,
|
|
14
|
+
castToText,
|
|
15
|
+
dateFromStoredMilliseconds,
|
|
16
|
+
dateFromStoredSeconds,
|
|
17
|
+
entityKind,
|
|
18
|
+
jitCompatCheck,
|
|
19
|
+
refineSqliteCodecs,
|
|
20
|
+
sql
|
|
21
|
+
} from "./chunk-4ZS73HTJ.js";
|
|
22
|
+
import {
|
|
23
|
+
__name
|
|
24
|
+
} from "./chunk-AFV74GK3.js";
|
|
25
|
+
|
|
26
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.466.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._f7e4048410ccbe1e801fd184c043d197/node_modules/@wirecat/cli-core/dist/store/sqlite/drizzle/bun.js
|
|
27
|
+
import { Database } from "bun:sqlite";
|
|
28
|
+
var bunSQLiteCodecs = refineSqliteCodecs({
|
|
29
|
+
"integer:boolean": { normalize: booleanFromInteger },
|
|
30
|
+
"integer:timestamp": { normalize: dateFromStoredSeconds },
|
|
31
|
+
"integer:timestamp_ms": { normalize: dateFromStoredMilliseconds },
|
|
32
|
+
"text:json": { normalize: JSON.parse },
|
|
33
|
+
blob: { normalize: bufferFromBytes },
|
|
34
|
+
"blob:json": {
|
|
35
|
+
cast: castToText,
|
|
36
|
+
normalize: JSON.parse
|
|
37
|
+
},
|
|
38
|
+
"blob:bigint": {
|
|
39
|
+
cast: castToText,
|
|
40
|
+
normalize: BigInt
|
|
41
|
+
},
|
|
42
|
+
numeric: {
|
|
43
|
+
cast: castToText,
|
|
44
|
+
normalize: String
|
|
45
|
+
},
|
|
46
|
+
"numeric:number": { normalize: Number },
|
|
47
|
+
"numeric:bigint": {
|
|
48
|
+
cast: castToText,
|
|
49
|
+
normalize: BigInt
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
var SQLiteBunSession = class extends SQLiteAsyncSession {
|
|
53
|
+
static {
|
|
54
|
+
__name(this, "SQLiteBunSession");
|
|
55
|
+
}
|
|
56
|
+
client;
|
|
57
|
+
relations;
|
|
58
|
+
options;
|
|
59
|
+
static [entityKind] = "SQLiteBunSession";
|
|
60
|
+
logger;
|
|
61
|
+
constructor(client, dialect, relations, options = {}) {
|
|
62
|
+
super(dialect, "sync");
|
|
63
|
+
this.client = client;
|
|
64
|
+
this.relations = relations;
|
|
65
|
+
this.options = options;
|
|
66
|
+
this.logger = options.logger ?? new NoopLogger();
|
|
67
|
+
}
|
|
68
|
+
exec(query) {
|
|
69
|
+
this.client.exec(query);
|
|
70
|
+
}
|
|
71
|
+
prepareQuery(query, mode, _prepare, executeMethod, mapper, queryMetadata) {
|
|
72
|
+
let stmt;
|
|
73
|
+
try {
|
|
74
|
+
stmt = this.client.query(query.sql);
|
|
75
|
+
} catch (e) {
|
|
76
|
+
throw new DrizzleQueryError(query.sql, this.options.paramsInErrors ? query.params : void 0, e);
|
|
77
|
+
}
|
|
78
|
+
return new SQLiteAsyncPreparedQuery("sync", executeMethod, {
|
|
79
|
+
all: /* @__PURE__ */ __name((params) => {
|
|
80
|
+
if (mode === "arrays") return stmt.values(...params);
|
|
81
|
+
return stmt.all(...params);
|
|
82
|
+
}, "all"),
|
|
83
|
+
get: /* @__PURE__ */ __name((params) => {
|
|
84
|
+
if (mode === "arrays") return stmt.values(...params)[0];
|
|
85
|
+
return stmt.get(...params);
|
|
86
|
+
}, "get"),
|
|
87
|
+
run: /* @__PURE__ */ __name((params) => {
|
|
88
|
+
return stmt.run(...params);
|
|
89
|
+
}, "run")
|
|
90
|
+
}, query, mapper, mode, this.logger, void 0, queryMetadata, void 0, this.options.paramsInErrors);
|
|
91
|
+
}
|
|
92
|
+
transaction(transaction, config = {}) {
|
|
93
|
+
const tx = new SQLiteBunTransaction("sync", this.dialect, this, this.relations);
|
|
94
|
+
let result;
|
|
95
|
+
const nativeTx = this.client.transaction(() => {
|
|
96
|
+
result = transaction(tx);
|
|
97
|
+
});
|
|
98
|
+
if (config.behavior === "concurrent") throw new Error("Concurrent transactions are not supported by driver");
|
|
99
|
+
nativeTx[config.behavior ?? "deferred"]();
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var SQLiteBunTransaction = class SQLiteBunTransaction2 extends SQLiteAsyncTransaction {
|
|
104
|
+
static {
|
|
105
|
+
__name(this, "SQLiteBunTransaction2");
|
|
106
|
+
}
|
|
107
|
+
static [entityKind] = "SQLiteBunTransaction";
|
|
108
|
+
transaction(transaction) {
|
|
109
|
+
const savepointName = `sp${this.nestedIndex}`;
|
|
110
|
+
const tx = new SQLiteBunTransaction2("sync", this.dialect, this.session, this._.relations, this.nestedIndex + 1);
|
|
111
|
+
this.session.run(sql.raw(`savepoint ${savepointName}`));
|
|
112
|
+
try {
|
|
113
|
+
const result = transaction(tx);
|
|
114
|
+
this.session.run(sql.raw(`release savepoint ${savepointName}`));
|
|
115
|
+
return result;
|
|
116
|
+
} catch (err) {
|
|
117
|
+
try {
|
|
118
|
+
this.session.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
119
|
+
} catch {
|
|
120
|
+
}
|
|
121
|
+
throw err;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var SQLiteBunDatabase = class extends SQLiteAsyncDatabase {
|
|
126
|
+
static {
|
|
127
|
+
__name(this, "SQLiteBunDatabase");
|
|
128
|
+
}
|
|
129
|
+
static [entityKind] = "SQLiteBunDatabase";
|
|
130
|
+
};
|
|
131
|
+
function construct(client, config = {}) {
|
|
132
|
+
const dialect = new SQLiteDialect({
|
|
133
|
+
codecs: config.codecs ?? bunSQLiteCodecs,
|
|
134
|
+
useJitMappers: jitCompatCheck(config.jit)
|
|
135
|
+
});
|
|
136
|
+
let logger;
|
|
137
|
+
if (config.logger === true) logger = new DefaultLogger();
|
|
138
|
+
else if (config.logger !== false) logger = config.logger;
|
|
139
|
+
const relations = config.relations ?? {};
|
|
140
|
+
const db = new SQLiteBunDatabase("sync", dialect, new SQLiteBunSession(client, dialect, relations, {
|
|
141
|
+
logger,
|
|
142
|
+
paramsInErrors: config.paramsInErrors
|
|
143
|
+
}), relations);
|
|
144
|
+
db.$client = client;
|
|
145
|
+
return db;
|
|
146
|
+
}
|
|
147
|
+
__name(construct, "construct");
|
|
148
|
+
function drizzle(...params) {
|
|
149
|
+
if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new Database() : new Database(params[0]), params[1]);
|
|
150
|
+
const { connection, client, ...DrizzleSQLiteConfig } = params[0];
|
|
151
|
+
if (client) return construct(client, DrizzleSQLiteConfig);
|
|
152
|
+
if (typeof connection === "object") {
|
|
153
|
+
const { source, ...opts } = connection;
|
|
154
|
+
const options = Object.values(opts).filter((v) => v !== void 0).length ? opts : void 0;
|
|
155
|
+
return construct(new Database(source, options), DrizzleSQLiteConfig);
|
|
156
|
+
}
|
|
157
|
+
return construct(new Database(connection), DrizzleSQLiteConfig);
|
|
158
|
+
}
|
|
159
|
+
__name(drizzle, "drizzle");
|
|
160
|
+
(function(_drizzle) {
|
|
161
|
+
function mock(config) {
|
|
162
|
+
return construct({}, config);
|
|
163
|
+
}
|
|
164
|
+
__name(mock, "mock");
|
|
165
|
+
_drizzle.mock = mock;
|
|
166
|
+
})(drizzle || (drizzle = {}));
|
|
167
|
+
export {
|
|
168
|
+
drizzle
|
|
169
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createRequire as __tgRequire } from "node:module";
|
|
2
|
+
const require = __tgRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
loadVectorExtension,
|
|
5
|
+
vectorExtension
|
|
6
|
+
} from "./chunk-2DGOFLDA.js";
|
|
7
|
+
import "./chunk-DG62L57H.js";
|
|
8
|
+
import "./chunk-OEJ5DMCX.js";
|
|
9
|
+
import {
|
|
10
|
+
importFrom
|
|
11
|
+
} from "./chunk-BJG6JA5U.js";
|
|
12
|
+
import {
|
|
13
|
+
__name
|
|
14
|
+
} from "./chunk-AFV74GK3.js";
|
|
15
|
+
|
|
16
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.466.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._f7e4048410ccbe1e801fd184c043d197/node_modules/@wirecat/cli-core/dist/store/drivers/bun-sqlite.js
|
|
17
|
+
var customised = false;
|
|
18
|
+
var ownLibrary = /* @__PURE__ */ __name(async () => {
|
|
19
|
+
try {
|
|
20
|
+
const { libraryFor } = await importFrom(new URL("store/drivers/bun-sqlite.js", import.meta.resolve("@wirecat/cli-core")).href, "@wirecat/cli-core-sqlite");
|
|
21
|
+
return libraryFor();
|
|
22
|
+
} catch {
|
|
23
|
+
return void 0;
|
|
24
|
+
}
|
|
25
|
+
}, "ownLibrary");
|
|
26
|
+
var bunDatabase = /* @__PURE__ */ __name(async () => {
|
|
27
|
+
const specifier = "bun:sqlite";
|
|
28
|
+
const { Database } = await importFrom(new URL("store/drivers/bun-sqlite.js", import.meta.resolve("@wirecat/cli-core")).href, specifier);
|
|
29
|
+
if (process.platform === "darwin" && !customised) {
|
|
30
|
+
customised = true;
|
|
31
|
+
const library = await ownLibrary();
|
|
32
|
+
if (library)
|
|
33
|
+
Database.setCustomSQLite(library);
|
|
34
|
+
}
|
|
35
|
+
return Database;
|
|
36
|
+
}, "bunDatabase");
|
|
37
|
+
var openWithBunSqlite = /* @__PURE__ */ __name(async (path) => cacheOverBunSqlite(await bunClient(path)), "openWithBunSqlite");
|
|
38
|
+
var bunClient = /* @__PURE__ */ __name(async (path, options) => {
|
|
39
|
+
const Database = await bunDatabase();
|
|
40
|
+
const extension = await vectorExtension();
|
|
41
|
+
const client = options ? new Database(path, options) : new Database(path);
|
|
42
|
+
try {
|
|
43
|
+
loadVectorExtension(client, extension);
|
|
44
|
+
return client;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
client.close();
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}, "bunClient");
|
|
50
|
+
var cacheOverBunSqlite = /* @__PURE__ */ __name((database) => {
|
|
51
|
+
return {
|
|
52
|
+
exec: /* @__PURE__ */ __name((sql) => database.exec(sql), "exec"),
|
|
53
|
+
prepare: /* @__PURE__ */ __name((sql) => {
|
|
54
|
+
const statement = database.query(sql);
|
|
55
|
+
return {
|
|
56
|
+
run: /* @__PURE__ */ __name((...parameters) => ({ changes: Number(statement.run(...parameters).changes) }), "run"),
|
|
57
|
+
// Bun answers null for no row; the seam promises undefined, and `!== undefined` checks rely on it.
|
|
58
|
+
get: /* @__PURE__ */ __name((...parameters) => statement.get(...parameters) ?? void 0, "get"),
|
|
59
|
+
all: /* @__PURE__ */ __name((...parameters) => statement.all(...parameters), "all")
|
|
60
|
+
};
|
|
61
|
+
}, "prepare"),
|
|
62
|
+
close: /* @__PURE__ */ __name(() => database.close(), "close")
|
|
63
|
+
};
|
|
64
|
+
}, "cacheOverBunSqlite");
|
|
65
|
+
export {
|
|
66
|
+
bunClient,
|
|
67
|
+
bunDatabase,
|
|
68
|
+
cacheOverBunSqlite,
|
|
69
|
+
openWithBunSqlite
|
|
70
|
+
};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { createRequire as __tgRequire } from "node:module";
|
|
2
|
+
const require = __tgRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
stringWidth,
|
|
5
|
+
wrapAnsi
|
|
6
|
+
} from "./chunk-ZZLKX62Z.js";
|
|
7
|
+
import {
|
|
8
|
+
singleLine,
|
|
9
|
+
visibleControls
|
|
10
|
+
} from "./chunk-DG62L57H.js";
|
|
11
|
+
import {
|
|
12
|
+
__name
|
|
13
|
+
} from "./chunk-AFV74GK3.js";
|
|
14
|
+
|
|
15
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.466.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._f7e4048410ccbe1e801fd184c043d197/node_modules/@wirecat/cli-core/dist/render/messages.js
|
|
16
|
+
import { styleText } from "node:util";
|
|
17
|
+
var TIME_WIDTH = 8;
|
|
18
|
+
var INDENT = " ".repeat(TIME_WIDTH + 2);
|
|
19
|
+
var MIN_WIDTH = 40;
|
|
20
|
+
var SENDER_COLOURS = ["green", "yellow", "magenta", "blue", "red"];
|
|
21
|
+
var renderMessages = /* @__PURE__ */ __name((messages, options = {}) => {
|
|
22
|
+
if (messages.length === 0)
|
|
23
|
+
return "(nothing)";
|
|
24
|
+
const day = dayFormatter(options);
|
|
25
|
+
const paint = painter(options);
|
|
26
|
+
let previous;
|
|
27
|
+
const blocks = [];
|
|
28
|
+
for (const message of messages) {
|
|
29
|
+
const date = day(message.timestamp);
|
|
30
|
+
if (date !== previous)
|
|
31
|
+
blocks.push(paint("dim", `\u2500\u2500 ${date} \u2500\u2500`));
|
|
32
|
+
previous = date;
|
|
33
|
+
blocks.push(renderMessage(message, options));
|
|
34
|
+
}
|
|
35
|
+
return blocks.join("\n\n");
|
|
36
|
+
}, "renderMessages");
|
|
37
|
+
var renderMessage = /* @__PURE__ */ __name((message, options = {}) => {
|
|
38
|
+
const paint = painter(options);
|
|
39
|
+
const width = Math.max(MIN_WIDTH, options.width ?? 80);
|
|
40
|
+
const room = width - INDENT.length;
|
|
41
|
+
const time = timeFormatter(options);
|
|
42
|
+
const verbosity = options.verbosity ?? 0;
|
|
43
|
+
const chat = "chatTitle" in message ? paint("dim", ` \xB7 ${singleLine(message.chatTitle ?? message.chatId)}`) : "";
|
|
44
|
+
const mark = "anchor" in message && message.anchor ? paint("bold", " \u25C0") : "";
|
|
45
|
+
const lines = [`${paint("dim", time(message.timestamp))} ${senderOf(message, options)}${chat}${mark}`];
|
|
46
|
+
const body = /* @__PURE__ */ __name((text) => wrapAnsi(visibleControls(text), room, { hard: true }).split("\n"), "body");
|
|
47
|
+
const email = message.email;
|
|
48
|
+
if (email)
|
|
49
|
+
lines.push(paint("dim", mailLine(email)));
|
|
50
|
+
if (message.replyTo)
|
|
51
|
+
lines.push(paint("dim", preview("\u21B3", message.replyTo, room, options)));
|
|
52
|
+
if (message.forwardedFrom) {
|
|
53
|
+
lines.push(paint("dim", `\u21AA ${nameOf(message.forwardedFrom, options)}`));
|
|
54
|
+
if (message.forwardedFrom.text)
|
|
55
|
+
for (const line of body(message.forwardedFrom.text))
|
|
56
|
+
lines.push(line);
|
|
57
|
+
lines.push(...attachmentLines(message.forwardedFrom.attachments, paint, options));
|
|
58
|
+
}
|
|
59
|
+
if (message.text)
|
|
60
|
+
for (const line of body(message.text))
|
|
61
|
+
lines.push(line);
|
|
62
|
+
lines.push(...attachmentLines(message.attachments, paint, options));
|
|
63
|
+
if (message.reactions && message.reactions.total > 0)
|
|
64
|
+
lines.push(paint("dim", reactionLine(message.reactions)));
|
|
65
|
+
if (message.editedAt)
|
|
66
|
+
lines.push(paint("dim", `edited ${editedAt(message, options)}`));
|
|
67
|
+
if (verbosity >= 1) {
|
|
68
|
+
const fields = [
|
|
69
|
+
["message", message.id],
|
|
70
|
+
["sender", message.senderId],
|
|
71
|
+
["chat", message.chatId],
|
|
72
|
+
["reply to", message.replyTo?.id ?? message.replyToId],
|
|
73
|
+
["thread", message.threadId],
|
|
74
|
+
["forward of", message.forwardedFrom?.id],
|
|
75
|
+
...message.attachments.map((a) => ["link", a.url])
|
|
76
|
+
];
|
|
77
|
+
if (verbosity >= 2) {
|
|
78
|
+
fields.push(["provider", options.provider], ["profile", options.profile], ["sent", message.timestamp], ["edited", message.editedAt], ["outgoing", message.outgoing === null ? "unknown" : String(message.outgoing)], ...message.attachments.map((a) => ["attachment", JSON.stringify(a)]), ["metadata", message.providerMetadata && JSON.stringify(message.providerMetadata)]);
|
|
79
|
+
}
|
|
80
|
+
const shown = fields.filter((field) => typeof field[1] === "string");
|
|
81
|
+
const label = Math.max(...shown.map(([key]) => key.length));
|
|
82
|
+
lines.push("", ...shown.map(([key, value]) => paint("dim", `${key.padEnd(label)} ${singleLine(value)}`)));
|
|
83
|
+
}
|
|
84
|
+
return lines.map((line, index) => index === 0 || line === "" ? line : `${INDENT}${line}`).join("\n");
|
|
85
|
+
}, "renderMessage");
|
|
86
|
+
var mailLine = /* @__PURE__ */ __name(({ to, cc, labels }) => {
|
|
87
|
+
const names = /* @__PURE__ */ __name((people) => people.map(({ name, address }) => singleLine(name ?? address)).join(", "), "names");
|
|
88
|
+
return [to.length ? `to ${names(to)}` : "", cc.length ? `cc ${names(cc)}` : "", labels.join(", ")].filter(Boolean).join(" \xB7 ");
|
|
89
|
+
}, "mailLine");
|
|
90
|
+
var painter = /* @__PURE__ */ __name(({ color = false }) => (style, text) => color ? styleText(style, text, { validateStream: false }) : text, "painter");
|
|
91
|
+
var senderOf = /* @__PURE__ */ __name((message, options) => {
|
|
92
|
+
const paint = painter(options);
|
|
93
|
+
if (message.outgoing === true)
|
|
94
|
+
return paint(["bold", "cyan"], you(options));
|
|
95
|
+
const name = nameOf(message, options);
|
|
96
|
+
if (!options.senderColors)
|
|
97
|
+
return paint("bold", name);
|
|
98
|
+
const colour = SENDER_COLOURS[hash(message.senderId ?? name) % SENDER_COLOURS.length] ?? "green";
|
|
99
|
+
return paint(["bold", colour], name);
|
|
100
|
+
}, "senderOf");
|
|
101
|
+
var nameOf = /* @__PURE__ */ __name(({ senderName, senderId, outgoing }, options) => outgoing === true ? you(options) : singleLine(senderName ?? senderId ?? "unknown"), "nameOf");
|
|
102
|
+
var DEFAULT_LOCALE = "ru-RU";
|
|
103
|
+
var you = /* @__PURE__ */ __name(({ locale = DEFAULT_LOCALE }) => locale.startsWith("ru") ? "\u0432\u044B" : "you", "you");
|
|
104
|
+
var hash = /* @__PURE__ */ __name((value) => [...value].reduce((sum, char) => sum * 31 + char.charCodeAt(0) >>> 0, 7), "hash");
|
|
105
|
+
var preview = /* @__PURE__ */ __name((mark, quoted, room, options) => {
|
|
106
|
+
const text = singleLine(quoted.text.split("\n")[0] ?? "") || (quoted.attachments[0] ? `\u{1F4CE} ${quoted.attachments[0].kind}` : "");
|
|
107
|
+
const line = text ? `${mark} ${nameOf(quoted, options)}: ${text}` : `${mark} message ${quoted.id}`;
|
|
108
|
+
if (stringWidth(line) <= room)
|
|
109
|
+
return line;
|
|
110
|
+
return `${wrapAnsi(line, room - 1, { hard: true }).split("\n")[0]}\u2026`;
|
|
111
|
+
}, "preview");
|
|
112
|
+
var attachmentLines = /* @__PURE__ */ __name((attachments, paint, options) => {
|
|
113
|
+
const link = /* @__PURE__ */ __name((label, raw) => {
|
|
114
|
+
if (raw === void 0)
|
|
115
|
+
return label;
|
|
116
|
+
const url = singleLine(raw);
|
|
117
|
+
return options.color ? `\x1B]8;;${url}\x07${label}\x1B]8;;\x07` : `${label} ${url}`;
|
|
118
|
+
}, "link");
|
|
119
|
+
let number = 0;
|
|
120
|
+
const keyboard = attachments.flatMap((attachment) => attachment.buttons ?? []).map((row) => paint("dim", row.map((button) => link(`[${++number} ${singleLine(button.text)}]`, button.url)).join(" ")));
|
|
121
|
+
const polls = attachments.flatMap((attachment) => attachment.poll ? pollLines(attachment.poll) : []);
|
|
122
|
+
const groups = /* @__PURE__ */ new Map();
|
|
123
|
+
for (const attachment of attachments) {
|
|
124
|
+
if (attachment.buttons || attachment.poll)
|
|
125
|
+
continue;
|
|
126
|
+
const key = singleLine(attachment.name ?? attachment.title ?? attachment.kind);
|
|
127
|
+
groups.set(key, [...groups.get(key) ?? [], attachment]);
|
|
128
|
+
}
|
|
129
|
+
const files = [...groups].map(([label, same]) => {
|
|
130
|
+
const first = same[0];
|
|
131
|
+
const size = first?.size === void 0 ? "" : ` \xB7 ${megabytes(first.size)}`;
|
|
132
|
+
if (same.length === 1)
|
|
133
|
+
return paint("dim", `\u{1F4CE} ${link(`${label}${size}`, first?.url)}`);
|
|
134
|
+
const each = same.map((attachment, index) => link(String(index + 1), attachment.url)).join(" ");
|
|
135
|
+
return paint("dim", `\u{1F4CE} ${label} \xD7${same.length} ${each}`);
|
|
136
|
+
});
|
|
137
|
+
return [...polls, ...files, ...keyboard];
|
|
138
|
+
}, "attachmentLines");
|
|
139
|
+
var pollLines = /* @__PURE__ */ __name((poll) => {
|
|
140
|
+
const kind = [
|
|
141
|
+
poll.closed ? "closed" : "",
|
|
142
|
+
poll.multiple ? "several answers" : "",
|
|
143
|
+
poll.anonymous ? "anonymous" : "",
|
|
144
|
+
poll.quiz ? "quiz" : ""
|
|
145
|
+
].filter(Boolean);
|
|
146
|
+
const count = /* @__PURE__ */ __name((voters) => voters === null ? "?" : String(voters), "count");
|
|
147
|
+
return [
|
|
148
|
+
`\u{1F4CA} ${visibleControls(poll.question)}`,
|
|
149
|
+
...poll.answers.map((answer) => ` [${answer.id}] ${visibleControls(answer.text)} \u2014 ${count(answer.voters)}${answer.chosen ? " \u2713" : ""}`),
|
|
150
|
+
` ${[`${count(poll.voters)} voted`, ...kind].join(" \xB7 ")}`
|
|
151
|
+
];
|
|
152
|
+
}, "pollLines");
|
|
153
|
+
var megabytes = /* @__PURE__ */ __name((bytes) => bytes >= 1e6 ? `${Math.round(bytes / 1e6)} MB` : `${Math.max(1, Math.round(bytes / 1e3))} KB`, "megabytes");
|
|
154
|
+
var parts = /* @__PURE__ */ __name((format, iso) => Object.fromEntries(format.formatToParts(new Date(iso)).map(({ type, value }) => [type, value])), "parts");
|
|
155
|
+
var timeFormatter = /* @__PURE__ */ __name(({ timeZone }) => {
|
|
156
|
+
const format = new Intl.DateTimeFormat("en-GB", {
|
|
157
|
+
hour: "2-digit",
|
|
158
|
+
minute: "2-digit",
|
|
159
|
+
second: "2-digit",
|
|
160
|
+
hourCycle: "h23",
|
|
161
|
+
...timeZone ? { timeZone } : {}
|
|
162
|
+
});
|
|
163
|
+
return (iso) => {
|
|
164
|
+
const { hour, minute, second } = parts(format, iso);
|
|
165
|
+
return `${hour}:${minute}:${second}`;
|
|
166
|
+
};
|
|
167
|
+
}, "timeFormatter");
|
|
168
|
+
var dayFormatter = /* @__PURE__ */ __name(({ locale = DEFAULT_LOCALE, timeZone }) => {
|
|
169
|
+
const format = new Intl.DateTimeFormat(locale, {
|
|
170
|
+
day: "numeric",
|
|
171
|
+
month: "long",
|
|
172
|
+
year: "numeric",
|
|
173
|
+
...timeZone ? { timeZone } : {}
|
|
174
|
+
});
|
|
175
|
+
return (iso) => format.format(new Date(iso)).replace(/\s*г\.$/, "");
|
|
176
|
+
}, "dayFormatter");
|
|
177
|
+
var reactionLine = /* @__PURE__ */ __name(({ counts, mine }) => {
|
|
178
|
+
const shown = counts.map(({ reaction, count }) => `${singleLine(reaction)} ${count}`).join(" ");
|
|
179
|
+
return mine ? `${shown} (you: ${singleLine(mine)})` : shown;
|
|
180
|
+
}, "reactionLine");
|
|
181
|
+
var editedAt = /* @__PURE__ */ __name((message, options) => {
|
|
182
|
+
const edited = message.editedAt ?? message.timestamp;
|
|
183
|
+
const time = timeFormatter(options)(edited);
|
|
184
|
+
const day = dayFormatter(options);
|
|
185
|
+
return day(edited) === day(message.timestamp) ? time : `${day(edited)} ${time}`;
|
|
186
|
+
}, "editedAt");
|
|
187
|
+
|
|
188
|
+
export {
|
|
189
|
+
renderMessages
|
|
190
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createRequire as __tgRequire } from "node:module";
|
|
2
|
+
const require = __tgRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
CliError
|
|
5
|
+
} from "./chunk-OEJ5DMCX.js";
|
|
6
|
+
import {
|
|
7
|
+
importFrom
|
|
8
|
+
} from "./chunk-BJG6JA5U.js";
|
|
9
|
+
import {
|
|
10
|
+
__name
|
|
11
|
+
} from "./chunk-AFV74GK3.js";
|
|
12
|
+
|
|
13
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.466.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._f7e4048410ccbe1e801fd184c043d197/node_modules/@wirecat/cli-core/dist/store/vector-extension.js
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
15
|
+
var musl = /* @__PURE__ */ __name(() => {
|
|
16
|
+
if (process.platform !== "linux")
|
|
17
|
+
return false;
|
|
18
|
+
try {
|
|
19
|
+
return readFileSync("/proc/self/maps", "utf8").includes("ld-musl");
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}, "musl");
|
|
24
|
+
var found;
|
|
25
|
+
var vectorExtension = /* @__PURE__ */ __name(() => {
|
|
26
|
+
found ??= locate();
|
|
27
|
+
return found;
|
|
28
|
+
}, "vectorExtension");
|
|
29
|
+
var locate = /* @__PURE__ */ __name(async () => {
|
|
30
|
+
const onMusl = musl();
|
|
31
|
+
const target = `${process.platform}-${process.arch}${onMusl ? "-musl" : ""}`;
|
|
32
|
+
let path;
|
|
33
|
+
try {
|
|
34
|
+
const { extensionFor } = await importFrom(new URL("store/vector-extension.js", import.meta.resolve("@wirecat/cli-core")).href, "@wirecat/cli-core-sqlite");
|
|
35
|
+
path = extensionFor({ musl: onMusl });
|
|
36
|
+
} catch {
|
|
37
|
+
path = void 0;
|
|
38
|
+
}
|
|
39
|
+
if (path === void 0) {
|
|
40
|
+
found = void 0;
|
|
41
|
+
throw new CliError("configuration_error", `the message store needs the sqlite-vec extension, and @wirecat/cli-core-sqlite has none for ${target} \u2014 reinstall the CLI so its dependencies install with it (an install that skips optional or native packages leaves it out)`, { reason: "store.vector-extension-missing", target });
|
|
42
|
+
}
|
|
43
|
+
return path;
|
|
44
|
+
}, "locate");
|
|
45
|
+
var loadVectorExtension = /* @__PURE__ */ __name((database, path) => {
|
|
46
|
+
try {
|
|
47
|
+
database.loadExtension(path);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
throw new CliError("configuration_error", `the sqlite-vec extension did not load on ${process.platform}-${process.arch} \u2014 reinstall the CLI; on macOS under Bun, @wirecat/cli-core-sqlite's SQLite must be installed, since the system's cannot load extensions`, { reason: "store.vector-extension-failed", cause: error instanceof Error ? error.message : String(error) });
|
|
50
|
+
} finally {
|
|
51
|
+
database.enableLoadExtension?.(false);
|
|
52
|
+
}
|
|
53
|
+
}, "loadVectorExtension");
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
vectorExtension,
|
|
57
|
+
loadVectorExtension
|
|
58
|
+
};
|