@wirecat/tg-cli 0.98.0 → 0.100.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 +2 -1
- package/dist/bin/tg.js +23 -28
- package/dist/bundle/adapter-2LVPMFKF.js +2790 -0
- package/dist/bundle/all-profiles-BLTK2AAB.js +255 -0
- package/dist/bundle/anthropic-RJE4XEOO.js +71 -0
- package/dist/bundle/bot-api-4XM3NVWG.js +39793 -0
- package/dist/bundle/bot-history-WVM5GEQN.js +167 -0
- package/dist/bundle/bun-UZXO2LRQ.js +169 -0
- package/dist/bundle/bun-sqlite-GJLGSQIT.js +70 -0
- package/dist/bundle/chunk-2IM4M7Q2.js +98 -0
- package/dist/bundle/chunk-2MXQ2EUN.js +1344 -0
- package/dist/bundle/chunk-2XUGPE5W.js +73 -0
- package/dist/bundle/chunk-3KHKYYCR.js +24782 -0
- package/dist/bundle/chunk-3MVHRZWR.js +2 -0
- package/dist/bundle/chunk-3N6LXAPE.js +724 -0
- package/dist/bundle/chunk-3QDPV34J.js +6668 -0
- package/dist/bundle/chunk-3S5CL55R.js +100 -0
- package/dist/bundle/chunk-4U7QOFDA.js +33511 -0
- package/dist/bundle/chunk-4VBDVZNE.js +524 -0
- package/dist/bundle/chunk-4YCLWWZ3.js +277 -0
- package/dist/bundle/chunk-66E5QDLH.js +24 -0
- package/dist/bundle/chunk-6VEOR6GD.js +166 -0
- package/dist/bundle/chunk-6YLT4YVJ.js +45 -0
- package/dist/bundle/chunk-7BFO3DY6.js +21 -0
- package/dist/bundle/chunk-A7OBVRJV.js +738 -0
- package/dist/bundle/chunk-AFV74GK3.js +50 -0
- package/dist/bundle/chunk-ASDZHG5I.js +25 -0
- package/dist/bundle/chunk-ATZ44Z77.js +3253 -0
- package/dist/bundle/chunk-AVWK4NCW.js +24600 -0
- package/dist/bundle/chunk-BAIZAZ6Q.js +82 -0
- package/dist/bundle/chunk-BJG6JA5U.js +35 -0
- package/dist/bundle/chunk-BL36RR34.js +285 -0
- package/dist/bundle/chunk-BZANDKWT.js +71 -0
- package/dist/bundle/chunk-CV5ASHTW.js +8170 -0
- package/dist/bundle/chunk-DN4QUTWU.js +78 -0
- package/dist/bundle/chunk-DVOUKGFK.js +1950 -0
- package/dist/bundle/chunk-GTURDJJD.js +570 -0
- package/dist/bundle/chunk-GYEOQS2D.js +2795 -0
- package/dist/bundle/chunk-H3X5LS6U.js +153 -0
- package/dist/bundle/chunk-HKT5EOT5.js +6848 -0
- package/dist/bundle/chunk-HXTTDIL7.js +82 -0
- package/dist/bundle/chunk-I6WZJVRT.js +1123 -0
- package/dist/bundle/chunk-JFJVS5JC.js +41 -0
- package/dist/bundle/chunk-JSKT5UZX.js +2315 -0
- package/dist/bundle/chunk-KE6L2UEG.js +3068 -0
- package/dist/bundle/chunk-LI7TXFLS.js +122 -0
- package/dist/bundle/chunk-MQNFEVAH.js +58 -0
- package/dist/bundle/chunk-MUEXF4ME.js +582 -0
- package/dist/bundle/chunk-OOOV3JBZ.js +35527 -0
- package/dist/bundle/chunk-OW3COBN5.js +1275 -0
- package/dist/bundle/chunk-P26LWFNZ.js +35 -0
- package/dist/bundle/chunk-Q26JMPBP.js +215 -0
- package/dist/bundle/chunk-QU2FJMFB.js +18282 -0
- package/dist/bundle/chunk-QY3YOOTP.js +18 -0
- package/dist/bundle/chunk-RDQMV6EU.js +46 -0
- package/dist/bundle/chunk-RER6DAHP.js +3514 -0
- package/dist/bundle/chunk-SGJYU3SB.js +54 -0
- package/dist/bundle/chunk-SMJTL5U7.js +117 -0
- package/dist/bundle/chunk-SYPL4PHV.js +76 -0
- package/dist/bundle/chunk-THVNP6S6.js +31 -0
- package/dist/bundle/chunk-U7LXA4SO.js +1007 -0
- package/dist/bundle/chunk-UD4DOZCN.js +886 -0
- package/dist/bundle/chunk-UMLPXNJI.js +63 -0
- package/dist/bundle/chunk-V4JSVH4M.js +190 -0
- package/dist/bundle/chunk-WE3LBRMB.js +2374 -0
- package/dist/bundle/chunk-WKOY3POD.js +452 -0
- package/dist/bundle/chunk-X4Y2ROJI.js +541 -0
- package/dist/bundle/chunk-YG7PNCSW.js +230 -0
- package/dist/bundle/chunk-Z2FHEIXN.js +63 -0
- package/dist/bundle/chunk-ZZLKX62Z.js +928 -0
- package/dist/bundle/command-contract-AIVKJYIR.js +31 -0
- package/dist/bundle/dist-RJMT44PL.js +7577 -0
- package/dist/bundle/echarts-YHSYUWLY.js +42501 -0
- package/dist/bundle/embed-3HGI2XIW.js +35 -0
- package/dist/bundle/embedder-2CJMZETJ.js +108 -0
- package/dist/bundle/entry-UVE53OV3.js +14 -0
- package/dist/bundle/first-run-6GYC2QS3.js +24 -0
- package/dist/bundle/first-screen-HRRLVLOG.js +29 -0
- package/dist/bundle/identity-HEV5E57G.js +11 -0
- package/dist/bundle/instructions-5UVAXSQV.js +9 -0
- package/dist/bundle/mcp-NWXBVNUA.js +165 -0
- package/dist/bundle/node-IUL5HSYI.js +2340 -0
- package/dist/bundle/node-UPPL626U.js +21 -0
- package/dist/bundle/node-YHYEGYVE.js +176 -0
- package/dist/bundle/node-sqlite-CQ33A3R2.js +46 -0
- package/dist/bundle/oauth-OB3JFAD7.js +18 -0
- package/dist/bundle/open-JHGZIXU2.js +20 -0
- package/dist/bundle/process-PSKS3N5B.js +91 -0
- package/dist/bundle/program-RPYVPNRX.js +1060 -0
- package/dist/bundle/prompt-7BXUMJGG.js +13 -0
- package/dist/bundle/proxy-transport-3EEMW2HW.js +17 -0
- package/dist/bundle/recognize-YMZPL47R.js +191 -0
- package/dist/bundle/remote-LQ3Q22NG.js +26 -0
- package/dist/bundle/rerank-SM7IYVXJ.js +49 -0
- package/dist/bundle/serve-GHUEP5H5.js +181 -0
- package/dist/bundle/server-A45HVXQY.js +178 -0
- package/dist/bundle/server-K2BQPPHN.js +785 -0
- package/dist/bundle/state-WIOL52GZ.js +30 -0
- package/dist/bundle/store-XE5AKUJZ.js +121 -0
- package/dist/bundle/store-maintenance-command-YS5E7VUN.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 -2
- package/dist/commands/context.js.map +1 -1
- package/dist/telegram/errors.d.ts.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/package.json +5 -3
- package/skills/tg-cli/SKILL.md +2 -1
|
@@ -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-A7OBVRJV.js";
|
|
9
|
+
import {
|
|
10
|
+
proxiedTransport
|
|
11
|
+
} from "./chunk-BZANDKWT.js";
|
|
12
|
+
import "./chunk-2IM4M7Q2.js";
|
|
13
|
+
import "./chunk-RDQMV6EU.js";
|
|
14
|
+
import "./chunk-SMJTL5U7.js";
|
|
15
|
+
import "./chunk-OOOV3JBZ.js";
|
|
16
|
+
import "./chunk-KE6L2UEG.js";
|
|
17
|
+
import "./chunk-JSKT5UZX.js";
|
|
18
|
+
import "./chunk-UD4DOZCN.js";
|
|
19
|
+
import "./chunk-3MVHRZWR.js";
|
|
20
|
+
import "./chunk-QY3YOOTP.js";
|
|
21
|
+
import "./chunk-3S5CL55R.js";
|
|
22
|
+
import "./chunk-HKT5EOT5.js";
|
|
23
|
+
import "./chunk-GYEOQS2D.js";
|
|
24
|
+
import {
|
|
25
|
+
CliError,
|
|
26
|
+
isCliError
|
|
27
|
+
} from "./chunk-WE3LBRMB.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-HKT5EOT5.js";
|
|
22
|
+
import {
|
|
23
|
+
__name
|
|
24
|
+
} from "./chunk-AFV74GK3.js";
|
|
25
|
+
|
|
26
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.452.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.63.0_commander@15._e609b9d6c8060966368a91e843fe8bd2/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-MQNFEVAH.js";
|
|
7
|
+
import "./chunk-GYEOQS2D.js";
|
|
8
|
+
import "./chunk-WE3LBRMB.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.452.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.63.0_commander@15._e609b9d6c8060966368a91e843fe8bd2/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,98 @@
|
|
|
1
|
+
import { createRequire as __tgRequire } from "node:module";
|
|
2
|
+
const require = __tgRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
CliError,
|
|
5
|
+
check,
|
|
6
|
+
pipe,
|
|
7
|
+
string
|
|
8
|
+
} from "./chunk-WE3LBRMB.js";
|
|
9
|
+
import {
|
|
10
|
+
__name
|
|
11
|
+
} from "./chunk-AFV74GK3.js";
|
|
12
|
+
|
|
13
|
+
// dist/proxy.js
|
|
14
|
+
var SHAPES = "socks5://host:port, http://host:port, https://host:port or an MTProxy link (tg://proxy?server=\u2026)";
|
|
15
|
+
var TELEGRAM_HOSTS = /* @__PURE__ */ new Set(["t.me", "telegram.me", "telegram.dog"]);
|
|
16
|
+
var parseProxy = /* @__PURE__ */ __name((text, from) => {
|
|
17
|
+
const fail = /* @__PURE__ */ __name((why) => {
|
|
18
|
+
throw new CliError("configuration_error", `${from} ${why} \u2014 it takes ${SHAPES}`);
|
|
19
|
+
}, "fail");
|
|
20
|
+
let url;
|
|
21
|
+
try {
|
|
22
|
+
url = new URL(text.trim());
|
|
23
|
+
} catch {
|
|
24
|
+
return fail("is not a URL");
|
|
25
|
+
}
|
|
26
|
+
const link = telegramLink(url);
|
|
27
|
+
if (link)
|
|
28
|
+
return fromLink(link.kind, url.searchParams, fail);
|
|
29
|
+
const port = /* @__PURE__ */ __name((fallback) => {
|
|
30
|
+
const number = url.port === "" ? fallback : Number(url.port);
|
|
31
|
+
return number >= 1 && number <= 65535 ? number : fail("has no valid port");
|
|
32
|
+
}, "port");
|
|
33
|
+
if (url.hostname === "")
|
|
34
|
+
fail("names no host");
|
|
35
|
+
const credentials = {
|
|
36
|
+
...url.username ? { user: decodeURIComponent(url.username) } : {},
|
|
37
|
+
...url.password ? { secret: decodeURIComponent(url.password) } : {}
|
|
38
|
+
};
|
|
39
|
+
const host = url.hostname.replace(/^\[(.*)\]$/, "$1");
|
|
40
|
+
switch (url.protocol) {
|
|
41
|
+
case "socks5:":
|
|
42
|
+
case "socks5h:":
|
|
43
|
+
return { kind: "socks5", host, port: port(1080), tls: false, ...credentials };
|
|
44
|
+
case "http:":
|
|
45
|
+
return { kind: "http", host, port: port(80), tls: false, ...credentials };
|
|
46
|
+
case "https:":
|
|
47
|
+
return { kind: "http", host, port: port(443), tls: true, ...credentials };
|
|
48
|
+
default:
|
|
49
|
+
return fail(`uses ${url.protocol.replace(/:$/, "")}, which tg does not speak`);
|
|
50
|
+
}
|
|
51
|
+
}, "parseProxy");
|
|
52
|
+
var telegramLink = /* @__PURE__ */ __name((url) => {
|
|
53
|
+
const path = url.protocol === "tg:" ? (url.hostname || url.pathname.replace(/^\/+/, "")).toLowerCase() : (url.protocol === "https:" || url.protocol === "http:") && TELEGRAM_HOSTS.has(url.hostname.toLowerCase()) ? url.pathname.replace(/^\/+|\/+$/g, "").toLowerCase() : void 0;
|
|
54
|
+
return path === "proxy" || path === "socks" ? { kind: path } : void 0;
|
|
55
|
+
}, "telegramLink");
|
|
56
|
+
var fromLink = /* @__PURE__ */ __name((kind, query, fail) => {
|
|
57
|
+
const host = query.get("server") ?? fail("has no server");
|
|
58
|
+
const port = Number(query.get("port"));
|
|
59
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
60
|
+
fail("has no valid port");
|
|
61
|
+
const secret = query.get(kind === "proxy" ? "secret" : "pass") ?? void 0;
|
|
62
|
+
const user = kind === "socks" ? query.get("user") ?? void 0 : void 0;
|
|
63
|
+
return {
|
|
64
|
+
kind: kind === "proxy" ? "mtproxy" : "socks5",
|
|
65
|
+
host,
|
|
66
|
+
port,
|
|
67
|
+
tls: false,
|
|
68
|
+
...user ? { user } : {},
|
|
69
|
+
...secret ? { secret } : {}
|
|
70
|
+
};
|
|
71
|
+
}, "fromLink");
|
|
72
|
+
var proxyLabel = /* @__PURE__ */ __name((proxy) => {
|
|
73
|
+
if (proxy.kind === "mtproxy")
|
|
74
|
+
return `tg://proxy?server=${encodeURIComponent(proxy.host)}&port=${proxy.port}`;
|
|
75
|
+
const user = proxy.user === void 0 ? "" : `${encodeURIComponent(proxy.user)}@`;
|
|
76
|
+
return proxyAddress(proxy).replace("://", `://${user}`);
|
|
77
|
+
}, "proxyLabel");
|
|
78
|
+
var proxyAddress = /* @__PURE__ */ __name((proxy) => {
|
|
79
|
+
const host = proxy.host.includes(":") ? `[${proxy.host}]` : proxy.host;
|
|
80
|
+
const scheme = proxy.kind === "socks5" ? "socks5" : proxy.tls ? "https" : "http";
|
|
81
|
+
return `${scheme}://${host}:${proxy.port}`;
|
|
82
|
+
}, "proxyAddress");
|
|
83
|
+
var proxyError = /* @__PURE__ */ __name((proxy, reason) => new CliError("configuration_error", `the proxy ${proxyLabel(proxy)} ${reason} \u2014 check it, or change it with \`tg config set proxy\` or TG_PROXY`, { proxy: proxyLabel(proxy), retryable: true }), "proxyError");
|
|
84
|
+
var proxySetting = pipe(string("has to be a proxy URL, in quotes"), check((text) => {
|
|
85
|
+
try {
|
|
86
|
+
return parseProxy(text, "proxy").secret === void 0;
|
|
87
|
+
} catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}, `has to be ${SHAPES}, without its password or secret \u2014 \`tg config set proxy -\` keeps those in the OS keyring`));
|
|
91
|
+
|
|
92
|
+
export {
|
|
93
|
+
parseProxy,
|
|
94
|
+
proxyLabel,
|
|
95
|
+
proxyAddress,
|
|
96
|
+
proxyError,
|
|
97
|
+
proxySetting
|
|
98
|
+
};
|