t3code-cli 0.14.0 → 0.14.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.md +1 -0
- package/dist/application.d.ts +2 -2
- package/dist/application.js +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +1 -1
- package/dist/bin.js +551 -265
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/client-runtime/authorization.d.ts +1 -1
- package/dist/client-runtime/authorization.js +1 -1
- package/dist/client-runtime/connection.d.ts +1 -1
- package/dist/client-runtime/connection.js +1 -1
- package/dist/client-runtime/environment.d.ts +5 -1
- package/dist/client-runtime/environment.js +1 -1
- package/dist/client-runtime/errors.js +1 -1
- package/dist/client-runtime/operations/projects.d.ts +2 -2
- package/dist/client-runtime/operations/projects.js +2 -2
- package/dist/client-runtime/operations.d.ts +2 -2
- package/dist/client-runtime/operations.js +2 -2
- package/dist/client-runtime/platform.d.ts +1 -1
- package/dist/client-runtime/platform.js +1 -1
- package/dist/client-runtime/relay.d.ts +5 -1
- package/dist/client-runtime/relay.js +1 -1
- package/dist/client-runtime/rpc.d.ts +2 -2
- package/dist/client-runtime/rpc.js +2 -2
- package/dist/client-runtime/state/assets.d.ts +17 -11
- package/dist/client-runtime/state/assets.js +1 -1
- package/dist/client-runtime/state/auth.d.ts +1 -1
- package/dist/client-runtime/state/auth.js +1 -1
- package/dist/client-runtime/state/connections.js +1 -1
- package/dist/client-runtime/state/entities.d.ts +1 -1
- package/dist/client-runtime/state/entities.js +1 -1
- package/dist/client-runtime/state/filesystem.d.ts +1 -1
- package/dist/client-runtime/state/filesystem.js +1 -1
- package/dist/client-runtime/state/git.d.ts +5 -5
- package/dist/client-runtime/state/git.js +1 -1
- package/dist/client-runtime/state/models.d.ts +1 -1
- package/dist/client-runtime/state/models.js +1 -1
- package/dist/client-runtime/state/orchestration.d.ts +42 -2
- package/dist/client-runtime/state/orchestration.js +13 -1
- package/dist/client-runtime/state/presentation.d.ts +9 -3
- package/dist/client-runtime/state/presentation.js +1 -1
- package/dist/client-runtime/state/preview.d.ts +55 -48
- package/dist/client-runtime/state/preview.js +1 -1
- package/dist/client-runtime/state/project-grouping.d.ts +26 -2
- package/dist/client-runtime/state/project-grouping.js +83 -3
- package/dist/client-runtime/state/projects.d.ts +24 -18
- package/dist/client-runtime/state/projects.js +1 -1
- package/dist/client-runtime/state/relay.d.ts +1 -1
- package/dist/client-runtime/state/relay.js +1 -1
- package/dist/client-runtime/state/review.d.ts +16 -1
- package/dist/client-runtime/state/review.js +27 -6
- package/dist/client-runtime/state/runtime.d.ts +2 -2
- package/dist/client-runtime/state/runtime.js +2 -2
- package/dist/client-runtime/state/server.d.ts +299 -172
- package/dist/client-runtime/state/server.js +192 -16
- package/dist/client-runtime/state/session.d.ts +65 -7
- package/dist/client-runtime/state/session.js +32 -3
- package/dist/client-runtime/state/shell.d.ts +41 -7
- package/dist/client-runtime/state/shell.js +1 -1
- package/dist/client-runtime/state/source-control.d.ts +2 -2
- package/dist/client-runtime/state/source-control.js +1 -1
- package/dist/client-runtime/state/subagentRuntime.d.ts +145 -0
- package/dist/client-runtime/state/subagentRuntime.js +521 -0
- package/dist/client-runtime/state/terminal.d.ts +17 -17
- package/dist/client-runtime/state/terminal.js +1 -1
- package/dist/client-runtime/state/thread-search.d.ts +23 -0
- package/dist/client-runtime/state/thread-search.js +38 -0
- package/dist/client-runtime/state/thread-settled.d.ts +28 -3
- package/dist/client-runtime/state/thread-settled.js +74 -2
- package/dist/client-runtime/state/thread-sort.d.ts +59 -2
- package/dist/client-runtime/state/thread-sort.js +128 -2
- package/dist/client-runtime/state/threads.d.ts +115 -3
- package/dist/client-runtime/state/threads.js +309 -28
- package/dist/client-runtime/state/vcs.d.ts +14 -14
- package/dist/client-runtime/state/vcs.js +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/connection.d.ts +1 -1
- package/dist/connection.js +1 -1
- package/dist/contracts.d.ts +1 -1
- package/dist/contracts.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +1 -1
- package/dist/orchestration.d.ts +144 -1
- package/dist/orchestration.js +1 -1
- package/dist/preview.d.ts +1 -1
- package/dist/preview.js +1 -1
- package/dist/rpc.d.ts +883 -351
- package/dist/rpc.js +1 -1
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.js +1 -1
- package/dist/shared/DrainableWorker.js +1 -1
- package/dist/shared/KeyedCoalescingWorker.js +1 -1
- package/dist/shared/Net.js +1 -1
- package/dist/shared/advertisedEndpoint.d.ts +1 -1
- package/dist/shared/advertisedEndpoint.js +1 -1
- package/dist/shared/agentAwareness.d.ts +1 -1
- package/dist/shared/backgroundActivitySettings.d.ts +1 -1
- package/dist/shared/composerInlineTokens.js +1 -1
- package/dist/shared/connectAuth.js +1 -1
- package/dist/shared/devHome.js +1 -1
- package/dist/shared/dpop.js +1 -1
- package/dist/shared/git.d.ts +1 -1
- package/dist/shared/httpObservability.js +1 -1
- package/dist/shared/httpReadiness.js +1 -1
- package/dist/shared/keybindings.d.ts +2 -2
- package/dist/shared/keybindings.js +15 -1
- package/dist/shared/model.d.ts +1 -1
- package/dist/shared/oauthScope.js +1 -1
- package/dist/shared/observability.d.ts +8 -1
- package/dist/shared/observability.js +49 -5
- package/dist/shared/path.js +1 -1
- package/dist/shared/preview.js +1 -1
- package/dist/shared/previewViewport.d.ts +1 -1
- package/dist/shared/previewViewport.js +1 -1
- package/dist/shared/projectFavicon.d.ts +2 -1
- package/dist/shared/projectFavicon.js +13 -1
- package/dist/shared/projectScripts.d.ts +1 -1
- package/dist/shared/relayAuth.js +1 -1
- package/dist/shared/relayClient.d.ts +1 -1
- package/dist/shared/relayClient.js +1 -1
- package/dist/shared/relayJwt.js +1 -1
- package/dist/shared/relayTracing.js +1 -1
- package/dist/shared/relayUrl.js +1 -1
- package/dist/shared/remote.js +1 -1
- package/dist/shared/schemaYaml.js +3 -3
- package/dist/shared/semver.js +1 -1
- package/dist/shared/serverSettings.d.ts +1 -1
- package/dist/shared/serverSettings.js +1 -1
- package/dist/shared/shell.d.ts +6 -1
- package/dist/shared/shell.js +42 -4
- package/dist/shared/sourceControl.d.ts +1 -1
- package/dist/shared/t3ProjectFile.d.ts +9 -1
- package/dist/shared/t3ProjectFile.js +12 -2
- package/dist/shared/terminalLabels.d.ts +1 -1
- package/dist/shared/threadEnvMode.d.ts +29 -0
- package/dist/shared/threadEnvMode.js +24 -0
- package/dist/shared/toolActivity.d.ts +1 -1
- package/dist/shared/usageFormat.d.ts +21 -0
- package/dist/shared/usageFormat.js +90 -0
- package/dist/shared/usageMerge.d.ts +67 -0
- package/dist/shared/usageMerge.js +218 -0
- package/dist/shared.d.ts +4472 -668
- package/dist/shared.js +16867 -16273
- package/dist/t3tools.d.ts +2 -2
- package/dist/t3tools.js +2 -2
- package/package.json +5 -5
- package/src/application/index.ts +1 -0
- package/src/application/service.ts +5 -1
- package/src/application/threads.ts +43 -1
- package/src/bin.ts +10 -7
- package/src/cli/app.ts +2 -0
- package/src/cli/format/thread.ts +23 -1
- package/src/cli/search.ts +48 -0
- package/src/config/persist/schema.ts +1 -1
- package/src/orchestration/layer.ts +6 -0
- package/src/orchestration/service.ts +5 -0
- package/src/rpc/error.ts +2 -0
- package/src/rpc/operation.ts +2 -0
- package/src/rpc/ws-group.ts +2 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { su as T3ProjectFile } from "../shared.js";
|
|
1
2
|
import * as Schema from "effect/Schema";
|
|
2
3
|
//#region upstream-t3code/packages/shared/src/t3ProjectFile.d.ts
|
|
3
4
|
/**
|
|
@@ -7,6 +8,7 @@ import * as Schema from "effect/Schema";
|
|
|
7
8
|
declare const T3ProjectFileFromJson: Schema.decodeTo<Schema.Struct<{
|
|
8
9
|
readonly $schema: Schema.optionalKey<Schema.String>;
|
|
9
10
|
readonly iconPath: Schema.optionalKey<Schema.decodeTo<Schema.String, Schema.String, never, never>>;
|
|
11
|
+
readonly defaultThreadEnvMode: Schema.optionalKey<Schema.Literals<readonly ["local", "worktree"]>>;
|
|
10
12
|
readonly scripts: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
11
13
|
readonly name: Schema.decodeTo<Schema.String, Schema.String, never, never>;
|
|
12
14
|
readonly command: Schema.decodeTo<Schema.String, Schema.String, never, never>;
|
|
@@ -16,6 +18,12 @@ declare const T3ProjectFileFromJson: Schema.decodeTo<Schema.Struct<{
|
|
|
16
18
|
readonly autoOpenPreview: Schema.optionalKey<Schema.Boolean>;
|
|
17
19
|
}>>>;
|
|
18
20
|
}>, Schema.String, never, never>;
|
|
21
|
+
/**
|
|
22
|
+
* Decode raw `t3.json` contents, treating invalid or malformed files as
|
|
23
|
+
* absent. Clients use this to read optional defaults (scripts, thread env
|
|
24
|
+
* mode) without surfacing decode errors to the user.
|
|
25
|
+
*/
|
|
26
|
+
declare function parseT3ProjectFile(contents: string): T3ProjectFile | null;
|
|
19
27
|
/**
|
|
20
28
|
* Build the publishable JSON Schema document for `t3.json` (draft 2020-12).
|
|
21
29
|
*
|
|
@@ -24,4 +32,4 @@ declare const T3ProjectFileFromJson: Schema.decodeTo<Schema.Struct<{
|
|
|
24
32
|
*/
|
|
25
33
|
declare function buildT3ProjectFileJsonSchema(): Record<string, unknown>;
|
|
26
34
|
//#endregion
|
|
27
|
-
export { T3ProjectFileFromJson, buildT3ProjectFileJsonSchema };
|
|
35
|
+
export { T3ProjectFileFromJson, buildT3ProjectFileJsonSchema, parseT3ProjectFile };
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ND as decodeExit, UD as toJsonSchemaDocument, XA as isSuccess, g as fromLenientJson, vd as T3ProjectFile, xd as T3_PROJECT_FILE_SCHEMA_URL } from "../shared.js";
|
|
2
2
|
//#region upstream-t3code/packages/shared/src/t3ProjectFile.ts
|
|
3
3
|
/**
|
|
4
4
|
* Codec between the raw `t3.json` file contents (lenient JSONC string) and the
|
|
5
5
|
* decoded {@link T3ProjectFile}.
|
|
6
6
|
*/
|
|
7
7
|
const T3ProjectFileFromJson = fromLenientJson(T3ProjectFile);
|
|
8
|
+
const decodeT3ProjectFile = decodeExit(T3ProjectFileFromJson);
|
|
9
|
+
/**
|
|
10
|
+
* Decode raw `t3.json` contents, treating invalid or malformed files as
|
|
11
|
+
* absent. Clients use this to read optional defaults (scripts, thread env
|
|
12
|
+
* mode) without surfacing decode errors to the user.
|
|
13
|
+
*/
|
|
14
|
+
function parseT3ProjectFile(contents) {
|
|
15
|
+
const decoded = decodeT3ProjectFile(contents);
|
|
16
|
+
return isSuccess(decoded) ? decoded.value : null;
|
|
17
|
+
}
|
|
8
18
|
/**
|
|
9
19
|
* Build the publishable JSON Schema document for `t3.json` (draft 2020-12).
|
|
10
20
|
*
|
|
@@ -22,4 +32,4 @@ function buildT3ProjectFileJsonSchema() {
|
|
|
22
32
|
return jsonSchema;
|
|
23
33
|
}
|
|
24
34
|
//#endregion
|
|
25
|
-
export { T3ProjectFileFromJson, buildT3ProjectFileJsonSchema };
|
|
35
|
+
export { T3ProjectFileFromJson, buildT3ProjectFileJsonSchema, parseT3ProjectFile };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NS as TerminalSummary } from "../shared.js";
|
|
2
2
|
//#region upstream-t3code/packages/shared/src/terminalLabels.d.ts
|
|
3
3
|
/** Human-readable label for a terminal tab; matches mobile and web sidebars. */
|
|
4
4
|
declare function getTerminalLabel(terminalId: string): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { yE as ThreadEnvMode } from "../shared.js";
|
|
2
|
+
//#region upstream-t3code/packages/shared/src/threadEnvMode.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Canonical priority order for a project's default thread env mode:
|
|
5
|
+
* per-project setting > checked-in t3.json > global server setting.
|
|
6
|
+
*
|
|
7
|
+
* An explicit composer pick outranks all of these; callers apply it before
|
|
8
|
+
* consulting the defaults. Web resolves the sources imperatively at draft
|
|
9
|
+
* creation, mobile reactively — both must route through this function so the
|
|
10
|
+
* platforms cannot disagree on the order.
|
|
11
|
+
*/
|
|
12
|
+
declare function resolveDefaultThreadEnvMode(sources: {
|
|
13
|
+
readonly projectSetting: ThreadEnvMode | null | undefined;
|
|
14
|
+
readonly projectFile: ThreadEnvMode | null | undefined;
|
|
15
|
+
readonly globalDefault: ThreadEnvMode;
|
|
16
|
+
}): ThreadEnvMode;
|
|
17
|
+
/**
|
|
18
|
+
* True once the resolved default can no longer change: an explicit pick or a
|
|
19
|
+
* source that outranks t3.json decided, or the file read settled. While
|
|
20
|
+
* false, nothing may persist the provisional default (for example into a
|
|
21
|
+
* draft's workspace selection) — it could differ from the final value.
|
|
22
|
+
*/
|
|
23
|
+
declare function isDefaultThreadEnvModeSettled(sources: {
|
|
24
|
+
readonly explicitMode: ThreadEnvMode | undefined;
|
|
25
|
+
readonly projectSetting: ThreadEnvMode | null | undefined;
|
|
26
|
+
readonly projectFilePending: boolean;
|
|
27
|
+
}): boolean;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { isDefaultThreadEnvModeSettled, resolveDefaultThreadEnvMode };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region upstream-t3code/packages/shared/src/threadEnvMode.ts
|
|
2
|
+
/**
|
|
3
|
+
* Canonical priority order for a project's default thread env mode:
|
|
4
|
+
* per-project setting > checked-in t3.json > global server setting.
|
|
5
|
+
*
|
|
6
|
+
* An explicit composer pick outranks all of these; callers apply it before
|
|
7
|
+
* consulting the defaults. Web resolves the sources imperatively at draft
|
|
8
|
+
* creation, mobile reactively — both must route through this function so the
|
|
9
|
+
* platforms cannot disagree on the order.
|
|
10
|
+
*/
|
|
11
|
+
function resolveDefaultThreadEnvMode(sources) {
|
|
12
|
+
return sources.projectSetting ?? sources.projectFile ?? sources.globalDefault;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* True once the resolved default can no longer change: an explicit pick or a
|
|
16
|
+
* source that outranks t3.json decided, or the file read settled. While
|
|
17
|
+
* false, nothing may persist the provisional default (for example into a
|
|
18
|
+
* draft's workspace selection) — it could differ from the final value.
|
|
19
|
+
*/
|
|
20
|
+
function isDefaultThreadEnvModeSettled(sources) {
|
|
21
|
+
return sources.explicitMode !== void 0 || sources.projectSetting != null || !sources.projectFilePending;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { isDefaultThreadEnvModeSettled, resolveDefaultThreadEnvMode };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bm as ToolLifecycleItemType } from "../shared.js";
|
|
2
2
|
//#region upstream-t3code/packages/shared/src/toolActivity.d.ts
|
|
3
3
|
interface ToolActivityPresentationInput {
|
|
4
4
|
readonly itemType?: ToolLifecycleItemType | null | undefined;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ol as UsageSummaryInput } from "../shared.js";
|
|
2
|
+
//#region upstream-t3code/packages/shared/src/usageFormat.d.ts
|
|
3
|
+
declare function formatUsd(value: number): string;
|
|
4
|
+
declare function formatCount(value: number): string;
|
|
5
|
+
/**
|
|
6
|
+
* Compacts a token count to three significant figures with a unit suffix, so
|
|
7
|
+
* columns of numbers line up at a glance (`19.9B`, `76.7M`, `804K`).
|
|
8
|
+
*/
|
|
9
|
+
declare function formatTokens(value: number): string;
|
|
10
|
+
declare function formatPercent(share: number, digits?: number): string;
|
|
11
|
+
/** `2026-08-07` to `Aug 7`. */
|
|
12
|
+
declare function formatDayShort(day: string): string;
|
|
13
|
+
/** Inclusive day list between two `YYYY-MM-DD` bounds. */
|
|
14
|
+
declare function enumerateDays(sinceDay: string, untilDay: string): readonly string[];
|
|
15
|
+
/**
|
|
16
|
+
* The window the page requests, expressed in the viewer's own time zone so days
|
|
17
|
+
* line up with what they actually experienced.
|
|
18
|
+
*/
|
|
19
|
+
declare function makeWindow(days: number, now?: Date): UsageSummaryInput;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { enumerateDays, formatCount, formatDayShort, formatPercent, formatTokens, formatUsd, makeWindow };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Sl as UsageDay } from "../shared.js";
|
|
2
|
+
//#region upstream-t3code/packages/shared/src/usageFormat.ts
|
|
3
|
+
/**
|
|
4
|
+
* Display formatting for the usage page.
|
|
5
|
+
*
|
|
6
|
+
* @module usageFormat
|
|
7
|
+
*/
|
|
8
|
+
const CURRENCY = new Intl.NumberFormat("en-US", {
|
|
9
|
+
style: "currency",
|
|
10
|
+
currency: "USD",
|
|
11
|
+
minimumFractionDigits: 2,
|
|
12
|
+
maximumFractionDigits: 2
|
|
13
|
+
});
|
|
14
|
+
const INTEGER = new Intl.NumberFormat("en-US");
|
|
15
|
+
function formatUsd(value) {
|
|
16
|
+
return CURRENCY.format(value);
|
|
17
|
+
}
|
|
18
|
+
function formatCount(value) {
|
|
19
|
+
return INTEGER.format(Math.round(value));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Compacts a token count to three significant figures with a unit suffix, so
|
|
23
|
+
* columns of numbers line up at a glance (`19.9B`, `76.7M`, `804K`).
|
|
24
|
+
*/
|
|
25
|
+
function formatTokens(value) {
|
|
26
|
+
const abs = Math.abs(value);
|
|
27
|
+
if (abs >= 0xe8d4a51000) return `${trim(value / 0xe8d4a51000)}T`;
|
|
28
|
+
if (abs >= 1e9) return `${trim(value / 1e9)}B`;
|
|
29
|
+
if (abs >= 1e6) return `${trim(value / 1e6)}M`;
|
|
30
|
+
if (abs >= 1e3) return `${trim(value / 1e3)}K`;
|
|
31
|
+
return INTEGER.format(Math.round(value));
|
|
32
|
+
}
|
|
33
|
+
function trim(value) {
|
|
34
|
+
const abs = Math.abs(value);
|
|
35
|
+
const digits = abs >= 100 ? 0 : abs >= 10 ? 1 : 2;
|
|
36
|
+
return value.toFixed(digits).replace(/\.0+$/, "");
|
|
37
|
+
}
|
|
38
|
+
function formatPercent(share, digits = 1) {
|
|
39
|
+
return `${(share * 100).toFixed(digits)}%`;
|
|
40
|
+
}
|
|
41
|
+
/** `2026-08-07` to `Aug 7`. */
|
|
42
|
+
function formatDayShort(day) {
|
|
43
|
+
const [year, month, dayOfMonth] = day.split("-").map((part) => Number(part));
|
|
44
|
+
if (year === void 0 || month === void 0 || dayOfMonth === void 0) return day;
|
|
45
|
+
return `${[
|
|
46
|
+
"Jan",
|
|
47
|
+
"Feb",
|
|
48
|
+
"Mar",
|
|
49
|
+
"Apr",
|
|
50
|
+
"May",
|
|
51
|
+
"Jun",
|
|
52
|
+
"Jul",
|
|
53
|
+
"Aug",
|
|
54
|
+
"Sep",
|
|
55
|
+
"Oct",
|
|
56
|
+
"Nov",
|
|
57
|
+
"Dec"
|
|
58
|
+
][month - 1] ?? ""} ${dayOfMonth}`;
|
|
59
|
+
}
|
|
60
|
+
/** Inclusive day list between two `YYYY-MM-DD` bounds. */
|
|
61
|
+
function enumerateDays(sinceDay, untilDay) {
|
|
62
|
+
const days = [];
|
|
63
|
+
const start = Date.parse(`${sinceDay}T00:00:00Z`);
|
|
64
|
+
const end = Date.parse(`${untilDay}T00:00:00Z`);
|
|
65
|
+
if (Number.isNaN(start) || Number.isNaN(end) || end < start) return days;
|
|
66
|
+
for (let cursor = start; cursor <= end; cursor += 864e5) days.push(new Date(cursor).toISOString().slice(0, 10));
|
|
67
|
+
return days;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The window the page requests, expressed in the viewer's own time zone so days
|
|
71
|
+
* line up with what they actually experienced.
|
|
72
|
+
*/
|
|
73
|
+
function makeWindow(days, now = /* @__PURE__ */ new Date()) {
|
|
74
|
+
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
|
|
75
|
+
const untilDay = new Intl.DateTimeFormat("en-CA", {
|
|
76
|
+
timeZone,
|
|
77
|
+
year: "numeric",
|
|
78
|
+
month: "2-digit",
|
|
79
|
+
day: "2-digit"
|
|
80
|
+
}).format(now);
|
|
81
|
+
const [year = 0, month = 1, dayOfMonth = 1] = untilDay.split("-").map((part) => Number.parseInt(part, 10));
|
|
82
|
+
const start = new Date(Date.UTC(year, month - 1, dayOfMonth - (days - 1)));
|
|
83
|
+
return {
|
|
84
|
+
sinceDay: UsageDay.make(start.toISOString().slice(0, 10)),
|
|
85
|
+
untilDay: UsageDay.make(untilDay),
|
|
86
|
+
timeZone
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
export { enumerateDays, formatCount, formatDayShort, formatPercent, formatTokens, formatUsd, makeWindow };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { CD as EnvironmentId, al as UsageSummary, el as UsageProviderKind } from "../shared.js";
|
|
2
|
+
//#region upstream-t3code/packages/shared/src/usageMerge.d.ts
|
|
3
|
+
interface EnvironmentUsage {
|
|
4
|
+
readonly environmentId: EnvironmentId;
|
|
5
|
+
readonly label: string;
|
|
6
|
+
readonly summary: UsageSummary;
|
|
7
|
+
}
|
|
8
|
+
interface ProviderTotals {
|
|
9
|
+
readonly provider: UsageProviderKind;
|
|
10
|
+
readonly costUsd: number;
|
|
11
|
+
readonly totalTokens: number;
|
|
12
|
+
readonly records: number;
|
|
13
|
+
readonly costShare: number;
|
|
14
|
+
readonly tokenShare: number;
|
|
15
|
+
}
|
|
16
|
+
interface ModelTotals {
|
|
17
|
+
readonly model: string;
|
|
18
|
+
readonly provider: UsageProviderKind;
|
|
19
|
+
readonly costUsd: number;
|
|
20
|
+
readonly totalTokens: number;
|
|
21
|
+
readonly records: number;
|
|
22
|
+
readonly costShare: number;
|
|
23
|
+
}
|
|
24
|
+
interface DailyTotals {
|
|
25
|
+
readonly day: string;
|
|
26
|
+
readonly costUsd: number;
|
|
27
|
+
readonly totalTokens: number;
|
|
28
|
+
readonly byProvider: ReadonlyMap<UsageProviderKind, {
|
|
29
|
+
costUsd: number;
|
|
30
|
+
totalTokens: number;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
interface CostQuality {
|
|
34
|
+
readonly providerReportedShare: number;
|
|
35
|
+
readonly modelPricedShare: number;
|
|
36
|
+
readonly unpricedShare: number;
|
|
37
|
+
readonly cacheSavingsUsd: number;
|
|
38
|
+
}
|
|
39
|
+
interface MergedUsage {
|
|
40
|
+
readonly costUsd: number;
|
|
41
|
+
readonly uncachedInputTokens: number;
|
|
42
|
+
readonly cachedInputTokens: number;
|
|
43
|
+
readonly cacheCreationTokens: number;
|
|
44
|
+
readonly outputTokens: number;
|
|
45
|
+
readonly reasoningTokens: number;
|
|
46
|
+
readonly totalTokens: number;
|
|
47
|
+
readonly records: number;
|
|
48
|
+
readonly sessions: number;
|
|
49
|
+
readonly providers: readonly ProviderTotals[];
|
|
50
|
+
readonly models: readonly ModelTotals[];
|
|
51
|
+
readonly daily: readonly DailyTotals[];
|
|
52
|
+
readonly costQuality: CostQuality;
|
|
53
|
+
/** Environments whose data was dropped as a duplicate of another's. */
|
|
54
|
+
readonly duplicateSources: readonly string[];
|
|
55
|
+
readonly contributingEnvironments: readonly EnvironmentId[];
|
|
56
|
+
readonly staleEnvironments: readonly EnvironmentId[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Merges every connected environment's summary.
|
|
60
|
+
*
|
|
61
|
+
* `expectedContractVersion` guards against an environment running older server
|
|
62
|
+
* code: rather than blocking the page, its data is excluded and its id is
|
|
63
|
+
* reported so the UI can say coverage is partial.
|
|
64
|
+
*/
|
|
65
|
+
declare function mergeUsage(environments: readonly EnvironmentUsage[], expectedContractVersion: number): MergedUsage;
|
|
66
|
+
//#endregion
|
|
67
|
+
export { CostQuality, DailyTotals, EnvironmentUsage, MergedUsage, ModelTotals, ProviderTotals, mergeUsage };
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
//#region upstream-t3code/packages/shared/src/usageMerge.ts
|
|
2
|
+
/**
|
|
3
|
+
* Two sources are the same physical transcript directory only when host,
|
|
4
|
+
* provider, path and filesystem identity all agree.
|
|
5
|
+
*
|
|
6
|
+
* `volumeId` is what stops two machines that happen to share a hostname and a
|
|
7
|
+
* home path, which is every Mac in a fleet, from collapsing into one source and
|
|
8
|
+
* having one of them silently dropped.
|
|
9
|
+
*/
|
|
10
|
+
function fingerprintKey(fingerprint) {
|
|
11
|
+
return [
|
|
12
|
+
fingerprint.hostId,
|
|
13
|
+
fingerprint.provider,
|
|
14
|
+
fingerprint.resolvedHomePath,
|
|
15
|
+
fingerprint.volumeId
|
|
16
|
+
].join(" ");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Decides which environment owns each physical transcript directory.
|
|
20
|
+
*
|
|
21
|
+
* Several environments on one machine (worktree servers, for instance) resolve
|
|
22
|
+
* the same provider home and would otherwise double count every token. The
|
|
23
|
+
* first environment in a stable order claims a fingerprint; the rest have that
|
|
24
|
+
* provider's buckets dropped. Environments are sorted by id so the winner does
|
|
25
|
+
* not change between renders.
|
|
26
|
+
*/
|
|
27
|
+
function claimSources(environments) {
|
|
28
|
+
const ownerByFingerprint = /* @__PURE__ */ new Map();
|
|
29
|
+
const duplicates = [];
|
|
30
|
+
const ordered = [...environments].sort((a, b) => a.environmentId.localeCompare(b.environmentId));
|
|
31
|
+
for (const environment of ordered) for (const source of environment.summary.sources) {
|
|
32
|
+
if (source.status === "missing") continue;
|
|
33
|
+
const key = fingerprintKey(source.fingerprint);
|
|
34
|
+
if (ownerByFingerprint.has(key)) {
|
|
35
|
+
duplicates.push(`${environment.label}: ${source.fingerprint.resolvedHomePath}`);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
ownerByFingerprint.set(key, environment.environmentId);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
ownerByFingerprint,
|
|
42
|
+
duplicates
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** Sources this environment owns after fingerprint claims, plus their buckets. */
|
|
46
|
+
function ownedContribution(environment, ownerByFingerprint) {
|
|
47
|
+
const ownedProviders = /* @__PURE__ */ new Set();
|
|
48
|
+
let sessions = 0;
|
|
49
|
+
for (const source of environment.summary.sources) {
|
|
50
|
+
if (source.status === "missing") continue;
|
|
51
|
+
const key = fingerprintKey(source.fingerprint);
|
|
52
|
+
if (ownerByFingerprint.get(key) === environment.environmentId) {
|
|
53
|
+
ownedProviders.add(source.fingerprint.provider);
|
|
54
|
+
sessions += source.distinctSessions;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
buckets: environment.summary.buckets.filter((bucket) => ownedProviders.has(bucket.provider)),
|
|
59
|
+
sessions
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function bucketTokens(bucket) {
|
|
63
|
+
return bucket.totals.uncachedInputTokens + bucket.totals.cachedInputTokens + bucket.totals.cacheCreationTokens + bucket.totals.outputTokens;
|
|
64
|
+
}
|
|
65
|
+
const EMPTY_MERGED = {
|
|
66
|
+
costUsd: 0,
|
|
67
|
+
uncachedInputTokens: 0,
|
|
68
|
+
cachedInputTokens: 0,
|
|
69
|
+
cacheCreationTokens: 0,
|
|
70
|
+
outputTokens: 0,
|
|
71
|
+
reasoningTokens: 0,
|
|
72
|
+
totalTokens: 0,
|
|
73
|
+
records: 0,
|
|
74
|
+
sessions: 0,
|
|
75
|
+
providers: [],
|
|
76
|
+
models: [],
|
|
77
|
+
daily: [],
|
|
78
|
+
costQuality: {
|
|
79
|
+
providerReportedShare: 0,
|
|
80
|
+
modelPricedShare: 0,
|
|
81
|
+
unpricedShare: 0,
|
|
82
|
+
cacheSavingsUsd: 0
|
|
83
|
+
},
|
|
84
|
+
duplicateSources: [],
|
|
85
|
+
contributingEnvironments: [],
|
|
86
|
+
staleEnvironments: []
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Merges every connected environment's summary.
|
|
90
|
+
*
|
|
91
|
+
* `expectedContractVersion` guards against an environment running older server
|
|
92
|
+
* code: rather than blocking the page, its data is excluded and its id is
|
|
93
|
+
* reported so the UI can say coverage is partial.
|
|
94
|
+
*/
|
|
95
|
+
function mergeUsage(environments, expectedContractVersion) {
|
|
96
|
+
if (environments.length === 0) return EMPTY_MERGED;
|
|
97
|
+
const current = [];
|
|
98
|
+
const staleEnvironments = [];
|
|
99
|
+
for (const environment of environments) if (environment.summary.contractVersion === expectedContractVersion) current.push(environment);
|
|
100
|
+
else staleEnvironments.push(environment.environmentId);
|
|
101
|
+
const { ownerByFingerprint, duplicates } = claimSources(current);
|
|
102
|
+
let costUsd = 0;
|
|
103
|
+
let uncachedInputTokens = 0;
|
|
104
|
+
let cachedInputTokens = 0;
|
|
105
|
+
let cacheCreationTokens = 0;
|
|
106
|
+
let outputTokens = 0;
|
|
107
|
+
let reasoningTokens = 0;
|
|
108
|
+
let records = 0;
|
|
109
|
+
let sessions = 0;
|
|
110
|
+
let cacheSavingsUsd = 0;
|
|
111
|
+
let providerReportedRecords = 0;
|
|
112
|
+
let unpricedRecords = 0;
|
|
113
|
+
const providerAccumulator = /* @__PURE__ */ new Map();
|
|
114
|
+
const modelAccumulator = /* @__PURE__ */ new Map();
|
|
115
|
+
const dailyAccumulator = /* @__PURE__ */ new Map();
|
|
116
|
+
const contributingEnvironments = [];
|
|
117
|
+
for (const environment of current) {
|
|
118
|
+
const { buckets, sessions: environmentSessions } = ownedContribution(environment, ownerByFingerprint);
|
|
119
|
+
if (buckets.length > 0) contributingEnvironments.push(environment.environmentId);
|
|
120
|
+
sessions += environmentSessions;
|
|
121
|
+
for (const bucket of buckets) {
|
|
122
|
+
const tokens = bucketTokens(bucket);
|
|
123
|
+
costUsd += bucket.costUsd;
|
|
124
|
+
cacheSavingsUsd += bucket.cacheSavingsUsd;
|
|
125
|
+
uncachedInputTokens += bucket.totals.uncachedInputTokens;
|
|
126
|
+
cachedInputTokens += bucket.totals.cachedInputTokens;
|
|
127
|
+
cacheCreationTokens += bucket.totals.cacheCreationTokens;
|
|
128
|
+
outputTokens += bucket.totals.outputTokens;
|
|
129
|
+
reasoningTokens += bucket.totals.reasoningTokens;
|
|
130
|
+
records += bucket.records;
|
|
131
|
+
unpricedRecords += bucket.unpricedRecords;
|
|
132
|
+
if (bucket.costSource === "providerReported") providerReportedRecords += bucket.records;
|
|
133
|
+
const provider = providerAccumulator.get(bucket.provider) ?? {
|
|
134
|
+
costUsd: 0,
|
|
135
|
+
totalTokens: 0,
|
|
136
|
+
records: 0
|
|
137
|
+
};
|
|
138
|
+
provider.costUsd += bucket.costUsd;
|
|
139
|
+
provider.totalTokens += tokens;
|
|
140
|
+
provider.records += bucket.records;
|
|
141
|
+
providerAccumulator.set(bucket.provider, provider);
|
|
142
|
+
const modelKey = `${bucket.provider} ${bucket.model}`;
|
|
143
|
+
const model = modelAccumulator.get(modelKey) ?? {
|
|
144
|
+
provider: bucket.provider,
|
|
145
|
+
costUsd: 0,
|
|
146
|
+
totalTokens: 0,
|
|
147
|
+
records: 0
|
|
148
|
+
};
|
|
149
|
+
model.costUsd += bucket.costUsd;
|
|
150
|
+
model.totalTokens += tokens;
|
|
151
|
+
model.records += bucket.records;
|
|
152
|
+
modelAccumulator.set(modelKey, model);
|
|
153
|
+
const day = dailyAccumulator.get(bucket.day) ?? {
|
|
154
|
+
costUsd: 0,
|
|
155
|
+
totalTokens: 0,
|
|
156
|
+
byProvider: /* @__PURE__ */ new Map()
|
|
157
|
+
};
|
|
158
|
+
day.costUsd += bucket.costUsd;
|
|
159
|
+
day.totalTokens += tokens;
|
|
160
|
+
const dayProvider = day.byProvider.get(bucket.provider) ?? {
|
|
161
|
+
costUsd: 0,
|
|
162
|
+
totalTokens: 0
|
|
163
|
+
};
|
|
164
|
+
dayProvider.costUsd += bucket.costUsd;
|
|
165
|
+
dayProvider.totalTokens += tokens;
|
|
166
|
+
day.byProvider.set(bucket.provider, dayProvider);
|
|
167
|
+
dailyAccumulator.set(bucket.day, day);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const totalTokens = uncachedInputTokens + cachedInputTokens + cacheCreationTokens + outputTokens;
|
|
171
|
+
const providers = [...providerAccumulator.entries()].map(([provider, totals]) => ({
|
|
172
|
+
provider,
|
|
173
|
+
costUsd: totals.costUsd,
|
|
174
|
+
totalTokens: totals.totalTokens,
|
|
175
|
+
records: totals.records,
|
|
176
|
+
costShare: costUsd === 0 ? 0 : totals.costUsd / costUsd,
|
|
177
|
+
tokenShare: totalTokens === 0 ? 0 : totals.totalTokens / totalTokens
|
|
178
|
+
})).sort((a, b) => b.costUsd - a.costUsd);
|
|
179
|
+
const models = [...modelAccumulator.entries()].map(([key, totals]) => ({
|
|
180
|
+
model: key.slice(key.indexOf(" ") + 1),
|
|
181
|
+
provider: totals.provider,
|
|
182
|
+
costUsd: totals.costUsd,
|
|
183
|
+
totalTokens: totals.totalTokens,
|
|
184
|
+
records: totals.records,
|
|
185
|
+
costShare: costUsd === 0 ? 0 : totals.costUsd / costUsd
|
|
186
|
+
})).sort((a, b) => b.costUsd - a.costUsd || b.totalTokens - a.totalTokens);
|
|
187
|
+
const daily = [...dailyAccumulator.entries()].map(([day, totals]) => ({
|
|
188
|
+
day,
|
|
189
|
+
costUsd: totals.costUsd,
|
|
190
|
+
totalTokens: totals.totalTokens,
|
|
191
|
+
byProvider: totals.byProvider
|
|
192
|
+
})).sort((a, b) => a.day.localeCompare(b.day));
|
|
193
|
+
return {
|
|
194
|
+
costUsd,
|
|
195
|
+
uncachedInputTokens,
|
|
196
|
+
cachedInputTokens,
|
|
197
|
+
cacheCreationTokens,
|
|
198
|
+
outputTokens,
|
|
199
|
+
reasoningTokens,
|
|
200
|
+
totalTokens,
|
|
201
|
+
records,
|
|
202
|
+
sessions,
|
|
203
|
+
providers,
|
|
204
|
+
models,
|
|
205
|
+
daily,
|
|
206
|
+
costQuality: {
|
|
207
|
+
providerReportedShare: records === 0 ? 0 : providerReportedRecords / records,
|
|
208
|
+
unpricedShare: records === 0 ? 0 : unpricedRecords / records,
|
|
209
|
+
modelPricedShare: records === 0 ? 0 : (records - providerReportedRecords - unpricedRecords) / records,
|
|
210
|
+
cacheSavingsUsd
|
|
211
|
+
},
|
|
212
|
+
duplicateSources: duplicates,
|
|
213
|
+
contributingEnvironments,
|
|
214
|
+
staleEnvironments
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
//#endregion
|
|
218
|
+
export { mergeUsage };
|