@qilin-agent/cli 0.0.0-stage → 3.1.4
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/LICENSE +21 -0
- package/README.i18n.yaml +22 -0
- package/README.md +78 -2
- package/README.zh.md +79 -0
- package/lib/bin.js +349 -0
- package/lib/dump-config-_HRfhhWz.js +53 -0
- package/lib/plugin-BQ1sn-63.js +239 -0
- package/lib/profile-boot-DSy6PUHQ.js +315 -0
- package/lib/profile-boot.js +2 -0
- package/lib/tenant-runtime-ChD53FKq.js +489 -0
- package/lib/tenants-roster-Bhr9x2Jw.js +252 -0
- package/lib/types/args.d.ts +65 -0
- package/lib/types/bin.d.ts +11 -0
- package/lib/types/dump-config.d.ts +18 -0
- package/lib/types/plugin.d.ts +29 -0
- package/lib/types/process-shutdown.d.ts +20 -0
- package/lib/types/profile-boot.d.ts +92 -0
- package/lib/types/scheduler-yield.d.ts +19 -0
- package/lib/types/startup-diagnostics.d.ts +19 -0
- package/lib/types/tenant-proxy.d.ts +101 -0
- package/lib/types/tenant-runtime.d.ts +338 -0
- package/lib/types/tenants-roster.d.ts +138 -0
- package/lib/types/tenants.d.ts +175 -0
- package/lib/types/usage-ledger.d.ts +143 -0
- package/lib/types/web-entry.d.ts +97 -0
- package/lib/web-entry-C--0C6wG.js +1500 -0
- package/package.json +179 -3
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The deployment's per-account token ledger.
|
|
3
|
+
*
|
|
4
|
+
* One runtime serves one account and reports each completed Turn of that
|
|
5
|
+
* account's sessions; the hub appends every report to that account's own file.
|
|
6
|
+
* A report is one Turn's increment, identified by its session and turn number,
|
|
7
|
+
* so a repeated report never double counts and a session that spans a month
|
|
8
|
+
* boundary lands in each month it actually spent in. Files are plain JSON lines
|
|
9
|
+
* the operator can read.
|
|
10
|
+
* @module @qilin-agent/cli/usage-ledger
|
|
11
|
+
*/
|
|
12
|
+
/** One account's reported spend for one completed Turn. */
|
|
13
|
+
export interface UsageReport {
|
|
14
|
+
/** Session the Turn belongs to. */
|
|
15
|
+
readonly sessionId: string;
|
|
16
|
+
/** Turn number inside that session; session plus turn identifies the record. */
|
|
17
|
+
readonly turn: number;
|
|
18
|
+
/** Prompt tokens billed as uncached input. */
|
|
19
|
+
readonly inputTokens: number;
|
|
20
|
+
/** Completion tokens billed for the Turn. */
|
|
21
|
+
readonly outputTokens: number;
|
|
22
|
+
/** Prompt tokens the provider served from its cache, when every attempt reported them. */
|
|
23
|
+
readonly cacheReadTokens?: number;
|
|
24
|
+
/** Prompt tokens written to that cache, when every attempt reported them. */
|
|
25
|
+
readonly cacheWriteTokens?: number;
|
|
26
|
+
/** When the runtime reported it, in epoch milliseconds. */
|
|
27
|
+
readonly at: number;
|
|
28
|
+
}
|
|
29
|
+
/** A window of report times; an absent bound is unbounded on that side. */
|
|
30
|
+
export interface UsageWindow {
|
|
31
|
+
/** Earliest report time to include, inclusive. */
|
|
32
|
+
readonly from?: number | undefined;
|
|
33
|
+
/** Latest report time to include, inclusive. */
|
|
34
|
+
readonly to?: number | undefined;
|
|
35
|
+
}
|
|
36
|
+
/** What one account spent across the records inside a window. */
|
|
37
|
+
export interface UsageTotal {
|
|
38
|
+
/** Sessions with at least one record in the window. */
|
|
39
|
+
readonly sessions: number;
|
|
40
|
+
/** Turns recorded in the window. */
|
|
41
|
+
readonly turns: number;
|
|
42
|
+
/** Uncached prompt tokens across those Turns. */
|
|
43
|
+
readonly inputTokens: number;
|
|
44
|
+
/** Completion tokens across those Turns. */
|
|
45
|
+
readonly outputTokens: number;
|
|
46
|
+
/** Prompt tokens served from the provider cache, summed over the Turns that reported them. */
|
|
47
|
+
readonly cacheReadTokens: number;
|
|
48
|
+
/** Prompt tokens written to that cache, likewise. */
|
|
49
|
+
readonly cacheWriteTokens: number;
|
|
50
|
+
/** Share of prompt tokens that came from cache, in [0, 1]; 0 when the window never read cache. */
|
|
51
|
+
readonly cacheHitRate: number;
|
|
52
|
+
/** The most recent report time in the window. */
|
|
53
|
+
readonly at: number;
|
|
54
|
+
}
|
|
55
|
+
/** Directory of the ledger inside one deployment home. */
|
|
56
|
+
/** The browser-facing read the hub answers from its own ledger. */
|
|
57
|
+
export declare const USAGE_BROWSER_READ_PATH = "/api/usage/me";
|
|
58
|
+
export declare function usageDirectory(home: string): string;
|
|
59
|
+
/** Absolute path of one account's ledger file. */
|
|
60
|
+
export declare function usageFilePath(home: string, accountId: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* Append one report to an account's ledger, creating the directory on first use.
|
|
63
|
+
* @param home - deployment home.
|
|
64
|
+
* @param accountId - the account the reporting runtime serves.
|
|
65
|
+
* @param report - the values it reported.
|
|
66
|
+
*/
|
|
67
|
+
export declare function appendUsage(home: string, accountId: string, report: UsageReport): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Read one account's records, latest line per Turn, oldest first.
|
|
70
|
+
*
|
|
71
|
+
* A Turn reported twice keeps the later line and an out-of-order earlier line
|
|
72
|
+
* never replaces it; a line that is not a report is skipped rather than failing
|
|
73
|
+
* the read, because runtimes append to this file while the hub reads it.
|
|
74
|
+
* @param home - deployment home.
|
|
75
|
+
* @param accountId - the account whose ledger to read.
|
|
76
|
+
* @param window - report times to include.
|
|
77
|
+
* @returns the records inside the window, sorted by report time.
|
|
78
|
+
*/
|
|
79
|
+
export declare function readUsageRecords(home: string, accountId: string, window?: UsageWindow): Promise<UsageReport[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Total the records of one account's ledger inside a window.
|
|
82
|
+
* @param home - deployment home.
|
|
83
|
+
* @param accountId - the account whose ledger to total.
|
|
84
|
+
* @param window - report times to include.
|
|
85
|
+
* @returns the total, zeroes when nothing was reported in the window.
|
|
86
|
+
*/
|
|
87
|
+
export declare function readUsageTotal(home: string, accountId: string, window?: UsageWindow): Promise<UsageTotal>;
|
|
88
|
+
/**
|
|
89
|
+
* The report-time window one read asks for.
|
|
90
|
+
* @param params - query parameters of the read.
|
|
91
|
+
* @returns the window, or undefined when a bound is not a whole non-negative
|
|
92
|
+
* number of epoch milliseconds or the bounds are inverted.
|
|
93
|
+
*/
|
|
94
|
+
export declare function readUsageWindow(params: URLSearchParams): UsageWindow | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* The newest records one answer carries, and whether older ones were left out.
|
|
97
|
+
*
|
|
98
|
+
* Records are sorted by report time, so a chart drawn from the newest slice is
|
|
99
|
+
* missing its oldest days rather than scattered holes; the flag says so.
|
|
100
|
+
* @param records - records in report-time order.
|
|
101
|
+
* @param cap - most records one answer may carry.
|
|
102
|
+
* @returns the records to send and whether the cap dropped any.
|
|
103
|
+
*/
|
|
104
|
+
export declare function capUsageRecords<T>(records: readonly T[], cap: number): {
|
|
105
|
+
records: T[];
|
|
106
|
+
truncated: boolean;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Sum one account's records into a total.
|
|
110
|
+
* @param records - records already deduplicated per Turn.
|
|
111
|
+
* @returns the total they add up to.
|
|
112
|
+
*/
|
|
113
|
+
export declare function totalUsage(records: readonly UsageReport[]): UsageTotal;
|
|
114
|
+
/**
|
|
115
|
+
* Total every account's ledger inside a window.
|
|
116
|
+
* @param home - deployment home.
|
|
117
|
+
* @param window - report times to include.
|
|
118
|
+
* @returns one total per account that reported in the window.
|
|
119
|
+
*/
|
|
120
|
+
export declare function readUsageTotals(home: string, window?: UsageWindow): Promise<Record<string, UsageTotal>>;
|
|
121
|
+
/**
|
|
122
|
+
* Sum every account's total into the deployment's own.
|
|
123
|
+
*
|
|
124
|
+
* The session and turn counts add up rather than deduplicating, because one
|
|
125
|
+
* session belongs to one account: two accounts reporting a session each
|
|
126
|
+
* reported two.
|
|
127
|
+
* @param totals - totals keyed by account identity.
|
|
128
|
+
* @returns the summed total, zeroes when no account has reported.
|
|
129
|
+
*/
|
|
130
|
+
export declare function sumUsageTotals(totals: Readonly<Record<string, UsageTotal>>): UsageTotal;
|
|
131
|
+
/**
|
|
132
|
+
* Read one ledger line as a report.
|
|
133
|
+
* @param line - one line of an account's ledger.
|
|
134
|
+
* @returns the report, or undefined when the line is empty, torn, or not a report.
|
|
135
|
+
*/
|
|
136
|
+
export declare function parseUsageReport(line: string): UsageReport | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* Whether a parsed value carries the report fields with usable values.
|
|
139
|
+
* @param value - the parsed line.
|
|
140
|
+
* @returns true when it is one report.
|
|
141
|
+
*/
|
|
142
|
+
export declare function isUsageReport(value: unknown): value is UsageReport;
|
|
143
|
+
//# sourceMappingURL=usage-ledger.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The deployment entry: one public address, one supervisor, and one runtime per
|
|
3
|
+
* account.
|
|
4
|
+
*
|
|
5
|
+
* Every profile that serves a browser address is a deployment: `qilin web` and
|
|
6
|
+
* the product surface `qilin` both come here. This process binds the address a
|
|
7
|
+
* browser reaches, terminates TLS when the invocation carries a certificate and
|
|
8
|
+
* key, and starts one child runtime per account on demand. A child boots the same
|
|
9
|
+
* profile with {@link TENANT_VARIABLE} set, so the application is what a runtime
|
|
10
|
+
* process runs and the supervisor is what the deployment runs.
|
|
11
|
+
*
|
|
12
|
+
* Runtimes stay on loopback: the public address is the supervisor's. That is
|
|
13
|
+
* why this entry serves every account through its own origin rather than
|
|
14
|
+
* redirecting a browser to a runtime port — a redirect target a client cannot
|
|
15
|
+
* reach is not a deployment.
|
|
16
|
+
*
|
|
17
|
+
* The entry reads the deployment's own flags and hands every other argument to
|
|
18
|
+
* each runtime's command line, so an application flag reaches the process that
|
|
19
|
+
* implements it instead of being dropped here. `--patch` is the exception it
|
|
20
|
+
* forwards as a launcher flag, because an overlay applies to the composition
|
|
21
|
+
* each runtime boots.
|
|
22
|
+
*
|
|
23
|
+
* The desktop shell boots the product profile in-process through
|
|
24
|
+
* `profile-boot`, so it never reaches this module and keeps serving one
|
|
25
|
+
* account directly.
|
|
26
|
+
* @module @qilin-agent/cli/web-entry
|
|
27
|
+
*/
|
|
28
|
+
/** The profiles whose boot is a deployment of the product surface. */
|
|
29
|
+
export declare const ENTRY_PROFILES: readonly string[];
|
|
30
|
+
/** Certificate chain and private key the deployment address serves with. */
|
|
31
|
+
export interface DeploymentTls {
|
|
32
|
+
/** PEM certificate chain file. */
|
|
33
|
+
readonly certFile: string;
|
|
34
|
+
/** Unencrypted PEM private key file. */
|
|
35
|
+
readonly keyFile: string;
|
|
36
|
+
}
|
|
37
|
+
/** What one deployment invocation asks the entry to serve. */
|
|
38
|
+
export interface DeploymentOptions {
|
|
39
|
+
/** Interface the public address binds. */
|
|
40
|
+
readonly host: string;
|
|
41
|
+
/** Port the public address binds; 0 lets the OS pick one. */
|
|
42
|
+
readonly port: number;
|
|
43
|
+
/** Profile each account's runtime boots. */
|
|
44
|
+
readonly tenantProfile: string;
|
|
45
|
+
/** Idle window after which an account's runtime is reclaimed. */
|
|
46
|
+
readonly idleMilliseconds: number;
|
|
47
|
+
/** Most account runtimes alive at once; 0 keeps every one. */
|
|
48
|
+
readonly maxTenants: number;
|
|
49
|
+
/** First wait before retrying a runtime that failed to start. */
|
|
50
|
+
readonly restartBackoffMilliseconds: number;
|
|
51
|
+
/** Serve every account through the public address instead of per-account origins. */
|
|
52
|
+
readonly singleOrigin: boolean;
|
|
53
|
+
/** Interface each account's runtime binds; loopback serves one public address. */
|
|
54
|
+
readonly tenantHost: string | undefined;
|
|
55
|
+
/** Who may create accounts on this deployment. */
|
|
56
|
+
readonly registration: 'open' | 'closed';
|
|
57
|
+
/** TLS the public address terminates with, when the invocation named a key pair. */
|
|
58
|
+
readonly tls: DeploymentTls | undefined;
|
|
59
|
+
/** Whether the invocation asked for help instead of serving. */
|
|
60
|
+
readonly help: boolean;
|
|
61
|
+
/** Overlay files the deployment arguments name, as absolute paths, in argv order. */
|
|
62
|
+
readonly patches: readonly string[];
|
|
63
|
+
/** Arguments belonging to the served application, in argv order. */
|
|
64
|
+
readonly appArguments: readonly string[];
|
|
65
|
+
}
|
|
66
|
+
/** What the launcher resolved for one deployment boot. */
|
|
67
|
+
export interface WebEntryInvocation {
|
|
68
|
+
/** Arguments for the served application, after the launcher's own flags. */
|
|
69
|
+
readonly args: readonly string[];
|
|
70
|
+
/** Profile this deployment serves. */
|
|
71
|
+
readonly profile: string;
|
|
72
|
+
/** Overlay files applied to every runtime's composition, in argv order. */
|
|
73
|
+
readonly patches: readonly string[];
|
|
74
|
+
/** Shipped template named by `--from-default-profile`, which this entry refuses. */
|
|
75
|
+
readonly fromDefaultProfile?: string | undefined;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Read one deployment invocation.
|
|
79
|
+
* @param args - the arguments after the launcher's own flags.
|
|
80
|
+
* @param servedProfile - profile this deployment serves when the invocation names none.
|
|
81
|
+
* @returns what the entry should serve.
|
|
82
|
+
* @throws Error when a named flag cannot be honoured.
|
|
83
|
+
*/
|
|
84
|
+
export declare function deploymentOptions(args: readonly string[], servedProfile: string): DeploymentOptions;
|
|
85
|
+
/**
|
|
86
|
+
* Whether this process is the deployment entry rather than one account's runtime.
|
|
87
|
+
* @returns true when no tenant marker is present.
|
|
88
|
+
*/
|
|
89
|
+
export declare function isWebEntry(): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Serve the deployment: the public address, and one runtime per account.
|
|
92
|
+
* @param invocation - the served profile, its overlays, and the app's arguments.
|
|
93
|
+
* @returns the process exit code.
|
|
94
|
+
* @throws Error when the invocation names a flag the deployment cannot honour.
|
|
95
|
+
*/
|
|
96
|
+
export declare function runWebEntry(invocation: WebEntryInvocation): Promise<number>;
|
|
97
|
+
//# sourceMappingURL=web-entry.d.ts.map
|