@itookit/dsht 0.3.0 → 0.3.3
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.i18n.yaml +2 -2
- package/README.md +39 -23
- package/README.zh.md +40 -24
- package/dist/catalog/controller.d.ts +32 -0
- package/dist/catalog/controller.js +88 -0
- package/dist/catalog/index.d.ts +2 -0
- package/dist/catalog/index.js +2 -0
- package/dist/{cli.js → cli/index.js} +42 -29
- package/dist/controller/connection.d.ts +80 -0
- package/dist/controller/connection.js +190 -0
- package/dist/controller/controller.d.ts +269 -0
- package/dist/controller/controller.js +372 -0
- package/dist/controller/index.d.ts +5 -0
- package/dist/controller/index.js +3 -0
- package/dist/controller/memory-log.d.ts +35 -0
- package/dist/controller/memory-log.js +95 -0
- package/dist/cost/config.d.ts +17 -0
- package/dist/cost/config.js +68 -0
- package/dist/cost/controller.d.ts +41 -0
- package/dist/cost/controller.js +115 -0
- package/dist/cost/index.d.ts +10 -0
- package/dist/cost/index.js +8 -0
- package/dist/cost/ledger-files.d.ts +16 -0
- package/dist/cost/ledger-files.js +103 -0
- package/dist/cost/ledger.d.ts +78 -0
- package/dist/cost/ledger.js +146 -0
- package/dist/cost/pricing.d.ts +86 -0
- package/dist/cost/pricing.js +223 -0
- package/dist/cost/records.d.ts +17 -0
- package/dist/cost/records.js +79 -0
- package/dist/cost/scanner.d.ts +22 -0
- package/dist/cost/scanner.js +95 -0
- package/dist/cost/types.d.ts +85 -0
- package/dist/cost/types.js +7 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/session/connection-view.d.ts +18 -0
- package/dist/session/connection-view.js +1 -0
- package/dist/{controller.d.ts → session/controller.d.ts} +102 -136
- package/dist/session/controller.js +616 -0
- package/dist/session/export-html.d.ts +9 -0
- package/dist/session/export-html.js +39 -0
- package/dist/{export.d.ts → session/export.d.ts} +1 -1
- package/dist/{export.js → session/export.js} +6 -20
- package/dist/{history.d.ts → session/history.d.ts} +17 -0
- package/dist/{history.js → session/history.js} +163 -2
- package/dist/session/index.d.ts +17 -0
- package/dist/session/index.js +10 -0
- package/dist/session/markdown.d.ts +39 -0
- package/dist/session/markdown.js +255 -0
- package/dist/session/math.d.ts +11 -0
- package/dist/session/math.js +82 -0
- package/dist/session/navigation.d.ts +37 -0
- package/dist/session/navigation.js +84 -0
- package/dist/{references.js → session/references.js} +1 -1
- package/dist/{telemetry.d.ts → session/telemetry.d.ts} +1 -1
- package/dist/{telemetry.js → session/telemetry.js} +1 -1
- package/dist/{transcript.d.ts → session/transcript.d.ts} +65 -1
- package/dist/{transcript.js → session/transcript.js} +141 -20
- package/dist/session/types.d.ts +18 -0
- package/dist/session/types.js +2 -0
- package/dist/state.d.ts +41 -0
- package/dist/state.js +9 -0
- package/dist/storage/directories.d.ts +14 -0
- package/dist/storage/directories.js +24 -0
- package/dist/storage/files.d.ts +51 -0
- package/dist/storage/files.js +152 -0
- package/dist/storage/heap-snapshot.d.ts +19 -0
- package/dist/storage/heap-snapshot.js +29 -0
- package/dist/storage/index.d.ts +4 -0
- package/dist/storage/index.js +4 -0
- package/dist/transport/auth.js +65 -0
- package/dist/transport/host.d.ts +13 -0
- package/dist/transport/host.js +1 -0
- package/dist/ui/app.d.ts +11 -0
- package/dist/ui/app.js +790 -0
- package/dist/ui/chat/header.d.ts +11 -0
- package/dist/ui/chat/header.js +14 -0
- package/dist/ui/chat/history-view.d.ts +12 -0
- package/dist/ui/chat/history-view.js +17 -0
- package/dist/ui/chat/status.d.ts +91 -0
- package/dist/ui/chat/status.js +386 -0
- package/dist/ui/chat/viewport.d.ts +17 -0
- package/dist/ui/chat/viewport.js +14 -0
- package/dist/ui/commands/parse.d.ts +99 -0
- package/dist/ui/commands/parse.js +126 -0
- package/dist/ui/commands/registry.d.ts +33 -0
- package/dist/ui/commands/registry.js +73 -0
- package/dist/ui/copy-mode.d.ts +4 -0
- package/dist/ui/copy-mode.js +6 -0
- package/dist/{cost-view.d.ts → ui/dialogs/cost.d.ts} +1 -1
- package/dist/{cost-view.js → ui/dialogs/cost.js} +6 -6
- package/dist/ui/dialogs/index.d.ts +120 -0
- package/dist/ui/dialogs/index.js +113 -0
- package/dist/ui/dialogs/picker.d.ts +18 -0
- package/dist/ui/dialogs/picker.js +38 -0
- package/dist/ui/frozen.d.ts +8 -0
- package/dist/ui/frozen.js +7 -0
- package/dist/ui/input/references.d.ts +12 -0
- package/dist/ui/input/references.js +15 -0
- package/dist/ui/mount.d.ts +6 -0
- package/dist/ui/mount.js +11 -0
- package/dist/{theme.d.ts → ui/theme/index.d.ts} +1 -1
- package/package.json +19 -13
- package/dist/app.d.ts +0 -21
- package/dist/app.js +0 -805
- package/dist/auth.js +0 -108
- package/dist/controller.js +0 -961
- package/dist/cost.d.ts +0 -119
- package/dist/cost.js +0 -313
- package/dist/history-view.d.ts +0 -8
- package/dist/history-view.js +0 -12
- package/dist/navigation.d.ts +0 -11
- package/dist/navigation.js +0 -36
- package/dist/status.d.ts +0 -28
- package/dist/status.js +0 -157
- /package/dist/{cli.d.ts → cli/index.d.ts} +0 -0
- /package/dist/{memory.d.ts → session/memory.d.ts} +0 -0
- /package/dist/{memory.js → session/memory.js} +0 -0
- /package/dist/{references.d.ts → session/references.d.ts} +0 -0
- /package/dist/{auth.d.ts → transport/auth.d.ts} +0 -0
- /package/dist/{client.d.ts → transport/client.d.ts} +0 -0
- /package/dist/{client.js → transport/client.js} +0 -0
- /package/dist/{endpoint.d.ts → transport/endpoint.d.ts} +0 -0
- /package/dist/{endpoint.js → transport/endpoint.js} +0 -0
- /package/dist/{wire.d.ts → transport/wire.d.ts} +0 -0
- /package/dist/{wire.js → transport/wire.js} +0 -0
- /package/dist/{input-history.d.ts → ui/input/history.d.ts} +0 -0
- /package/dist/{input-history.js → ui/input/history.js} +0 -0
- /package/dist/{input.d.ts → ui/input/input.d.ts} +0 -0
- /package/dist/{input.js → ui/input/input.js} +0 -0
- /package/dist/{mouse.d.ts → ui/input/mouse.d.ts} +0 -0
- /package/dist/{mouse.js → ui/input/mouse.js} +0 -0
- /package/dist/{theme.js → ui/theme/index.js} +0 -0
package/dist/auth.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/** Origin-scoped cookie persistence; launch tokens are never written to disk. */
|
|
2
|
-
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
-
import { constants } from 'node:fs';
|
|
4
|
-
import { lstat, mkdir, open, rename, unlink } from 'node:fs/promises';
|
|
5
|
-
import { homedir } from 'node:os';
|
|
6
|
-
import { join } from 'node:path';
|
|
7
|
-
import { HttpError } from "./client.js";
|
|
8
|
-
/** Fatal authentication failure requiring a new startup token. */
|
|
9
|
-
export class AuthenticationRequired extends Error {
|
|
10
|
-
}
|
|
11
|
-
/** Private, atomic cookie files, separated by the complete HTTP origin. */
|
|
12
|
-
export class CookieStore {
|
|
13
|
-
directory;
|
|
14
|
-
constructor(directory = process.env.DSHT_AUTH_DIR
|
|
15
|
-
?? join(process.env.XDG_STATE_HOME ?? join(homedir(), '.local', 'state'), 'dsht', 'auth')) {
|
|
16
|
-
this.directory = directory;
|
|
17
|
-
}
|
|
18
|
-
/** Read an unexpired cookie, rejecting unsafe permissions or malformed storage. */
|
|
19
|
-
async load(origin) {
|
|
20
|
-
let handle;
|
|
21
|
-
try {
|
|
22
|
-
handle = await open(this.path(origin), constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
if (isMissing(error))
|
|
26
|
-
return undefined;
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
29
|
-
try {
|
|
30
|
-
const stat = await handle.stat();
|
|
31
|
-
if (!stat.isFile() || process.platform !== 'win32' && ((stat.mode & 0o077) !== 0 || stat.uid !== process.getuid?.())) {
|
|
32
|
-
throw new Error('Cookie file must be owned by the current user with permissions 0600');
|
|
33
|
-
}
|
|
34
|
-
const raw = await handle.readFile('utf8');
|
|
35
|
-
let saved;
|
|
36
|
-
try {
|
|
37
|
-
saved = JSON.parse(raw);
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
throw new Error('Invalid cookie file JSON. Remove the origin cookie file and log in again.');
|
|
41
|
-
}
|
|
42
|
-
if (saved === null || typeof saved !== 'object' || !('version' in saved) || saved.version !== 1
|
|
43
|
-
|| !('origin' in saved) || saved.origin !== origin || !('cookie' in saved) || typeof saved.cookie !== 'string'
|
|
44
|
-
|| !('expiresAt' in saved) || typeof saved.expiresAt !== 'number' || !Number.isSafeInteger(saved.expiresAt)) {
|
|
45
|
-
throw new Error('Invalid saved cookie. Remove the origin cookie file and log in again.');
|
|
46
|
-
}
|
|
47
|
-
return saved.expiresAt > Date.now() ? saved.cookie : undefined;
|
|
48
|
-
}
|
|
49
|
-
finally {
|
|
50
|
-
await handle.close();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/** Atomically save a persistent host cookie with owner-only POSIX permissions. */
|
|
54
|
-
async save(origin, cookie, expiresAt) {
|
|
55
|
-
await mkdir(this.directory, { recursive: true, mode: 0o700 });
|
|
56
|
-
const stat = await lstat(this.directory);
|
|
57
|
-
if (!stat.isDirectory() || process.platform !== 'win32' && ((stat.mode & 0o077) !== 0 || stat.uid !== process.getuid?.())) {
|
|
58
|
-
throw new Error('Cookie directory must be owned by the current user with permissions 0700');
|
|
59
|
-
}
|
|
60
|
-
const temporary = join(this.directory, `${randomUUID()}.tmp`);
|
|
61
|
-
const handle = await open(temporary, 'wx', 0o600);
|
|
62
|
-
try {
|
|
63
|
-
try {
|
|
64
|
-
await handle.writeFile(JSON.stringify({ version: 1, origin, cookie, expiresAt }) + '\n');
|
|
65
|
-
}
|
|
66
|
-
finally {
|
|
67
|
-
await handle.close();
|
|
68
|
-
}
|
|
69
|
-
await rename(temporary, this.path(origin));
|
|
70
|
-
}
|
|
71
|
-
finally {
|
|
72
|
-
try {
|
|
73
|
-
await unlink(temporary);
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
if (!isMissing(error))
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
path(origin) {
|
|
82
|
-
return join(this.directory, `${createHash('sha256').update(origin).digest('hex')}.json`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/** Reuse a validated cookie first; only authentication rejection permits token fallback. */
|
|
86
|
-
export async function login(client, token, store) {
|
|
87
|
-
const cookie = await store.load(client.base.origin);
|
|
88
|
-
if (cookie) {
|
|
89
|
-
client.restoreCookie(cookie);
|
|
90
|
-
try {
|
|
91
|
-
await client.call('session/list', { _request: {} });
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
if (!(error instanceof HttpError) || error.status !== 401)
|
|
96
|
-
throw error;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (!token)
|
|
100
|
-
throw new AuthenticationRequired('Login required: export DSH_TOKEN, or export DSH_URL as the URL printed by dsh web');
|
|
101
|
-
await client.authenticate(token);
|
|
102
|
-
const session = client.persistentCookie;
|
|
103
|
-
if (session)
|
|
104
|
-
await store.save(client.base.origin, session.cookie, session.expiresAt);
|
|
105
|
-
}
|
|
106
|
-
function isMissing(error) {
|
|
107
|
-
return error instanceof Error && 'code' in error && error.code === 'ENOENT';
|
|
108
|
-
}
|