@itookit/dsht 0.3.0 → 0.3.2
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 +30 -15
- package/README.zh.md +30 -15
- 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} +40 -24
- package/dist/controller/connection.d.ts +80 -0
- package/dist/controller/connection.js +190 -0
- package/dist/controller/controller.d.ts +260 -0
- package/dist/controller/controller.js +362 -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/controller.d.ts +34 -0
- package/dist/cost/controller.js +107 -0
- package/dist/cost/index.d.ts +9 -0
- package/dist/cost/index.js +7 -0
- package/dist/cost/ledger-files.d.ts +20 -0
- package/dist/cost/ledger-files.js +128 -0
- package/dist/cost/ledger.d.ts +65 -0
- package/dist/cost/ledger.js +136 -0
- package/dist/cost/pricing.d.ts +48 -0
- package/dist/cost/pricing.js +141 -0
- package/dist/cost/records.d.ts +17 -0
- package/dist/cost/records.js +66 -0
- package/dist/cost/scanner.d.ts +22 -0
- package/dist/cost/scanner.js +95 -0
- package/dist/cost/types.d.ts +69 -0
- package/dist/cost/types.js +3 -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/{navigation.d.ts → session/navigation.d.ts} +1 -1
- package/dist/{navigation.js → session/navigation.js} +1 -1
- 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} +23 -1
- package/dist/{transcript.js → session/transcript.js} +36 -18
- 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 +43 -0
- package/dist/storage/files.js +135 -0
- package/dist/storage/index.d.ts +3 -0
- package/dist/storage/index.js +3 -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 +726 -0
- package/dist/ui/chat/header.d.ts +11 -0
- package/dist/ui/chat/header.js +14 -0
- package/dist/{history-view.d.ts → ui/chat/history-view.d.ts} +1 -1
- package/dist/{history-view.js → ui/chat/history-view.js} +3 -3
- package/dist/ui/chat/status.d.ts +79 -0
- package/dist/ui/chat/status.js +311 -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 +96 -0
- package/dist/ui/commands/parse.js +121 -0
- package/dist/ui/commands/registry.d.ts +33 -0
- package/dist/ui/commands/registry.js +72 -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} +3 -3
- 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/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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** Origin-scoped cookie persistence; launch tokens are never written to disk. */
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { ensurePrivateDirectory, readPrivateFile, writePrivateFile } from "../storage/index.js";
|
|
6
|
+
import { HttpError } from "./client.js";
|
|
7
|
+
/** Fatal authentication failure requiring a new startup token. */
|
|
8
|
+
export class AuthenticationRequired extends Error {
|
|
9
|
+
}
|
|
10
|
+
/** Private, atomic cookie files, separated by the complete HTTP origin. */
|
|
11
|
+
export class CookieStore {
|
|
12
|
+
directory;
|
|
13
|
+
constructor(directory = process.env.DSHT_AUTH_DIR
|
|
14
|
+
?? join(process.env.XDG_STATE_HOME ?? join(homedir(), '.local', 'state'), 'dsht', 'auth')) {
|
|
15
|
+
this.directory = directory;
|
|
16
|
+
}
|
|
17
|
+
/** Read an unexpired cookie, rejecting unsafe permissions or malformed storage. */
|
|
18
|
+
async load(origin) {
|
|
19
|
+
const raw = await readPrivateFile(this.path(origin), 'Cookie file');
|
|
20
|
+
if (raw === undefined)
|
|
21
|
+
return undefined;
|
|
22
|
+
let saved;
|
|
23
|
+
try {
|
|
24
|
+
saved = JSON.parse(raw);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
throw new Error('Invalid cookie file JSON. Remove the origin cookie file and log in again.');
|
|
28
|
+
}
|
|
29
|
+
if (saved === null || typeof saved !== 'object' || !('version' in saved) || saved.version !== 1
|
|
30
|
+
|| !('origin' in saved) || saved.origin !== origin || !('cookie' in saved) || typeof saved.cookie !== 'string'
|
|
31
|
+
|| !('expiresAt' in saved) || typeof saved.expiresAt !== 'number' || !Number.isSafeInteger(saved.expiresAt)) {
|
|
32
|
+
throw new Error('Invalid saved cookie. Remove the origin cookie file and log in again.');
|
|
33
|
+
}
|
|
34
|
+
return saved.expiresAt > Date.now() ? saved.cookie : undefined;
|
|
35
|
+
}
|
|
36
|
+
/** Atomically save a persistent host cookie with owner-only POSIX permissions. */
|
|
37
|
+
async save(origin, cookie, expiresAt) {
|
|
38
|
+
await ensurePrivateDirectory(this.directory, 'Cookie directory');
|
|
39
|
+
await writePrivateFile(this.path(origin), JSON.stringify({ version: 1, origin, cookie, expiresAt }) + '\n');
|
|
40
|
+
}
|
|
41
|
+
path(origin) {
|
|
42
|
+
return join(this.directory, `${createHash('sha256').update(origin).digest('hex')}.json`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Reuse a validated cookie first; only authentication rejection permits token fallback. */
|
|
46
|
+
export async function login(client, token, store) {
|
|
47
|
+
const cookie = await store.load(client.base.origin);
|
|
48
|
+
if (cookie) {
|
|
49
|
+
client.restoreCookie(cookie);
|
|
50
|
+
try {
|
|
51
|
+
await client.call('session/list', { _request: {} });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (!(error instanceof HttpError) || error.status !== 401)
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!token)
|
|
60
|
+
throw new AuthenticationRequired('Login required: export DSH_TOKEN, or export DSH_URL as the URL printed by dsh web');
|
|
61
|
+
await client.authenticate(token);
|
|
62
|
+
const session = client.persistentCookie;
|
|
63
|
+
if (session)
|
|
64
|
+
await store.save(client.base.origin, session.cookie, session.expiresAt);
|
|
65
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Host access contract every domain controller uses for the active connection generation. */
|
|
2
|
+
import type { Client } from './client.ts';
|
|
3
|
+
/** One authenticated host connection, as seen by a domain that never owns it. */
|
|
4
|
+
export interface HostAccess {
|
|
5
|
+
/** Connected client, or undefined while offline or between generations. */
|
|
6
|
+
client(): Client | undefined;
|
|
7
|
+
/** Connected client, or a `Not connected` failure. */
|
|
8
|
+
require(): Client;
|
|
9
|
+
/** Whether the current generation has applied its host baseline. */
|
|
10
|
+
online(): boolean;
|
|
11
|
+
/** Client lifetime signal, aborted when the process closes the connection. */
|
|
12
|
+
signal(): AbortSignal;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/ui/app.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Theme } from './theme/index.ts';
|
|
2
|
+
import { Controller } from '../controller/controller.ts';
|
|
3
|
+
/** The caller owns starting and stopping the controller around the Ink render lifetime.
|
|
4
|
+
* @param props - Controller, panel lifetime and semantic theme.
|
|
5
|
+
* @returns The rendered terminal interface.
|
|
6
|
+
*/
|
|
7
|
+
export declare function App({ controller, panelLifetimeMs, theme }: {
|
|
8
|
+
controller: Controller;
|
|
9
|
+
panelLifetimeMs?: number;
|
|
10
|
+
theme?: Theme;
|
|
11
|
+
}): import("react").JSX.Element;
|