@uniquedivine/tg-sai 0.0.4 → 0.0.5
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 +24 -0
- package/RUNBOOK.md +137 -16
- package/actionExecutor.ts +55 -55
- package/adminAudit.ts +60 -60
- package/captureProvisioningGolden.ts +98 -0
- package/cfg.ts +12 -1
- package/custodyWorker.ts +259 -0
- package/custodyWorkerCli.ts +52 -0
- package/health.ts +31 -50
- package/main.ts +442 -100
- package/mtcuteAdapter.ts +14 -6
- package/ops.ts +12 -0
- package/package.json +5 -4
- package/profiles.ts +134 -27
- package/provisioning.ts +674 -0
- package/provisioningCli.ts +140 -0
- package/provisioningCloud.ts +214 -0
- package/provisioningGoldens.ts +70 -0
- package/provisioningRuntime.ts +380 -0
- package/runtimeAssets.d.ts +4 -0
- package/runtimeHealth.ts +125 -0
- package/runtimeHealthCli.ts +46 -0
- package/session_string_generator.py +36 -24
- package/telegramRuntime.ts +25 -0
package/health.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { constants } from "node:fs"
|
|
2
2
|
import { access, mkdir, readdir, readFile, stat } from "node:fs/promises"
|
|
3
3
|
import { join } from "node:path"
|
|
4
|
-
|
|
5
|
-
import { configDir, configPath, readConfig } from "./profiles"
|
|
4
|
+
import { configDir, configPath, profileLabel, readConfig } from "./profiles"
|
|
6
5
|
import type {
|
|
7
6
|
ProfileStoreEnv,
|
|
8
7
|
TelegramCredentials,
|
|
@@ -110,45 +109,43 @@ function directoryFix(path: string): string[] {
|
|
|
110
109
|
]
|
|
111
110
|
}
|
|
112
111
|
|
|
113
|
-
function missingProfileFix(
|
|
114
|
-
const addCommand = profileName
|
|
115
|
-
? `tg-sai profile add --name ${profileName} --src <number>`
|
|
116
|
-
: "tg-sai profile add --name <name> --src <number>"
|
|
112
|
+
function missingProfileFix(): string[] {
|
|
117
113
|
return [
|
|
118
114
|
"Find a Telegram credential source and save it as a tg-sai profile.",
|
|
119
115
|
"tg-sai profile find",
|
|
120
|
-
|
|
116
|
+
"tg-sai profile add",
|
|
117
|
+
"If apiId/apiHash are missing, create a Telegram API app at https://my.telegram.org/apps",
|
|
118
|
+
"Then run: tg-sai profile add --qr",
|
|
121
119
|
]
|
|
122
120
|
}
|
|
123
121
|
|
|
124
|
-
function incompleteProfileFix(
|
|
122
|
+
function incompleteProfileFix(selector: string, fields: string[]): string[] {
|
|
125
123
|
return [
|
|
126
124
|
`Fill missing profile field(s): ${fields.join(",")}`,
|
|
127
125
|
"Check the redacted active profile:",
|
|
128
|
-
`tg-sai profile show ${
|
|
129
|
-
"Then refresh it from
|
|
126
|
+
`tg-sai profile show ${selector}`,
|
|
127
|
+
"Then refresh it from detected values or generate a session:",
|
|
130
128
|
"tg-sai profile find",
|
|
131
|
-
|
|
129
|
+
"tg-sai profile add",
|
|
130
|
+
"tg-sai profile add --qr",
|
|
132
131
|
]
|
|
133
132
|
}
|
|
134
133
|
|
|
135
|
-
function connectionFix(
|
|
134
|
+
function connectionFix(selector: string): string[] {
|
|
136
135
|
return [
|
|
137
136
|
"Check the active profile API credentials and Telegram session string.",
|
|
138
|
-
`tg-sai profile show ${
|
|
137
|
+
`tg-sai profile show ${selector}`,
|
|
139
138
|
"If apiId, apiHash, or sessionString are stale, refresh from a known-good source:",
|
|
140
139
|
"tg-sai profile find",
|
|
141
|
-
|
|
140
|
+
"tg-sai profile add",
|
|
141
|
+
"tg-sai profile add --qr",
|
|
142
142
|
]
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
function passwordFix(
|
|
146
|
-
const saveCommand = profileName
|
|
147
|
-
? `tg-sai profile add --name ${profileName} --password '<password>'`
|
|
148
|
-
: "tg-sai profile add --name <name> --password '<password>'"
|
|
145
|
+
function passwordFix(): string[] {
|
|
149
146
|
return [
|
|
150
147
|
"Save the Telegram 2FA password in the active tg-sai profile:",
|
|
151
|
-
|
|
148
|
+
"tg-sai profile add --password '<password>'",
|
|
152
149
|
"You can also override it for one command with TELEGRAM_PASSWORD.",
|
|
153
150
|
]
|
|
154
151
|
}
|
|
@@ -250,7 +247,7 @@ async function checkTelegramConnection(params: {
|
|
|
250
247
|
collector,
|
|
251
248
|
"telegram_connection",
|
|
252
249
|
"telegram_connection: skipped because active profile is incomplete",
|
|
253
|
-
incompleteProfileFix(
|
|
250
|
+
incompleteProfileFix("0", missingFields),
|
|
254
251
|
)
|
|
255
252
|
return
|
|
256
253
|
}
|
|
@@ -273,7 +270,7 @@ async function checkTelegramConnection(params: {
|
|
|
273
270
|
"Use a Telegram user-account session for tg-sai admin operations.",
|
|
274
271
|
"Switch to a user profile:",
|
|
275
272
|
"tg-sai profile list",
|
|
276
|
-
"tg-sai profile use <user-
|
|
273
|
+
"tg-sai profile use <index-or-handle-or-user-id>",
|
|
277
274
|
],
|
|
278
275
|
)
|
|
279
276
|
}
|
|
@@ -282,7 +279,7 @@ async function checkTelegramConnection(params: {
|
|
|
282
279
|
collector,
|
|
283
280
|
"telegram_connection",
|
|
284
281
|
`telegram_connection: failed ${errorMessage(caught)}`,
|
|
285
|
-
connectionFix(
|
|
282
|
+
connectionFix("0"),
|
|
286
283
|
)
|
|
287
284
|
} finally {
|
|
288
285
|
if (client) {
|
|
@@ -304,7 +301,7 @@ function checkPassword(
|
|
|
304
301
|
collector,
|
|
305
302
|
"password_status",
|
|
306
303
|
"password_status: missing",
|
|
307
|
-
passwordFix(
|
|
304
|
+
passwordFix(),
|
|
308
305
|
)
|
|
309
306
|
info(
|
|
310
307
|
collector,
|
|
@@ -394,13 +391,13 @@ export async function runHealthCheck(params: {
|
|
|
394
391
|
}
|
|
395
392
|
|
|
396
393
|
const config = await readConfig(env)
|
|
397
|
-
const
|
|
398
|
-
const
|
|
399
|
-
? (
|
|
394
|
+
const activeProfile = config.profiles[0] ?? null
|
|
395
|
+
const activeProfileLabel = activeProfile
|
|
396
|
+
? profileLabel(activeProfile, 0)
|
|
400
397
|
: null
|
|
401
398
|
const missingFields = activeProfile ? missingProfileFields(activeProfile) : []
|
|
402
399
|
|
|
403
|
-
if (!
|
|
400
|
+
if (!activeProfile) {
|
|
404
401
|
error(
|
|
405
402
|
collector,
|
|
406
403
|
"active_profile",
|
|
@@ -413,33 +410,20 @@ export async function runHealthCheck(params: {
|
|
|
413
410
|
"profile_status: missing",
|
|
414
411
|
missingProfileFix(),
|
|
415
412
|
)
|
|
416
|
-
} else if (!activeProfile) {
|
|
417
|
-
error(
|
|
418
|
-
collector,
|
|
419
|
-
"active_profile",
|
|
420
|
-
`active_profile: ${activeProfileName}`,
|
|
421
|
-
missingProfileFix(activeProfileName),
|
|
422
|
-
)
|
|
423
|
-
error(
|
|
424
|
-
collector,
|
|
425
|
-
"profile_status",
|
|
426
|
-
"profile_status: missing",
|
|
427
|
-
missingProfileFix(activeProfileName),
|
|
428
|
-
)
|
|
429
413
|
} else {
|
|
430
|
-
info(collector, `active_profile: ${
|
|
414
|
+
info(collector, `active_profile: ${activeProfileLabel}`)
|
|
431
415
|
if (missingFields.length > 0) {
|
|
432
416
|
error(
|
|
433
417
|
collector,
|
|
434
418
|
"profile_status",
|
|
435
419
|
"profile_status: incomplete",
|
|
436
|
-
incompleteProfileFix(
|
|
420
|
+
incompleteProfileFix("0", missingFields),
|
|
437
421
|
)
|
|
438
422
|
error(
|
|
439
423
|
collector,
|
|
440
424
|
"missing_fields",
|
|
441
425
|
`missing_fields: ${missingFields.join(",")}`,
|
|
442
|
-
incompleteProfileFix(
|
|
426
|
+
incompleteProfileFix("0", missingFields),
|
|
443
427
|
)
|
|
444
428
|
} else {
|
|
445
429
|
good(collector, "profile_status: complete")
|
|
@@ -457,14 +441,11 @@ export async function runHealthCheck(params: {
|
|
|
457
441
|
await checkLogs(collector, logsPath)
|
|
458
442
|
}
|
|
459
443
|
|
|
460
|
-
if (!
|
|
444
|
+
if (!activeProfile) {
|
|
461
445
|
info(collector, "next: tg-sai profile find")
|
|
462
|
-
info(collector, "next: tg-sai profile add --
|
|
463
|
-
} else if (
|
|
464
|
-
info(
|
|
465
|
-
collector,
|
|
466
|
-
`next: tg-sai profile add --name ${activeProfileName} --src <number>`,
|
|
467
|
-
)
|
|
446
|
+
info(collector, "next: tg-sai profile add --qr")
|
|
447
|
+
} else if (missingFields.length > 0) {
|
|
448
|
+
info(collector, "next: tg-sai profile add --qr")
|
|
468
449
|
}
|
|
469
450
|
|
|
470
451
|
renderSuggestedFixes(collector)
|