@contraagent/api 0.0.0-stage → 0.1.0
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 +102 -2
- package/dist/client.d.ts +54 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +68 -0
- package/dist/client.js.map +1 -0
- package/dist/derive.d.ts +81 -0
- package/dist/derive.d.ts.map +1 -0
- package/dist/derive.js +89 -0
- package/dist/derive.js.map +1 -0
- package/dist/export.d.ts +36 -0
- package/dist/export.d.ts.map +1 -0
- package/dist/export.js +130 -0
- package/dist/export.js.map +1 -0
- package/dist/feed.d.ts +27 -0
- package/dist/feed.d.ts.map +1 -0
- package/dist/feed.js +39 -0
- package/dist/feed.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/outcomes.d.ts +117 -0
- package/dist/outcomes.d.ts.map +1 -0
- package/dist/outcomes.js +201 -0
- package/dist/outcomes.js.map +1 -0
- package/dist/panels.d.ts +31 -0
- package/dist/panels.d.ts.map +1 -0
- package/dist/panels.js +12 -0
- package/dist/panels.js.map +1 -0
- package/dist/quota.d.ts +32 -0
- package/dist/quota.d.ts.map +1 -0
- package/dist/quota.js +46 -0
- package/dist/quota.js.map +1 -0
- package/dist/reasons.d.ts +25 -0
- package/dist/reasons.d.ts.map +1 -0
- package/dist/reasons.js +46 -0
- package/dist/reasons.js.map +1 -0
- package/dist/run-state.d.ts +62 -0
- package/dist/run-state.d.ts.map +1 -0
- package/dist/run-state.js +109 -0
- package/dist/run-state.js.map +1 -0
- package/dist/schema.d.ts +3718 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +3 -0
- package/dist/schema.js.map +1 -0
- package/dist/spend.d.ts +46 -0
- package/dist/spend.d.ts.map +1 -0
- package/dist/spend.js +68 -0
- package/dist/spend.js.map +1 -0
- package/dist/store.d.ts +121 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +286 -0
- package/dist/store.js.map +1 -0
- package/dist/types.d.ts +112 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +19 -0
- package/dist/types.js.map +1 -0
- package/package.json +43 -4
- package/src/client.ts +119 -0
- package/src/derive.ts +155 -0
- package/src/export.ts +158 -0
- package/src/feed.ts +81 -0
- package/src/index.ts +12 -0
- package/src/outcomes.ts +267 -0
- package/src/panels.ts +51 -0
- package/src/quota.ts +78 -0
- package/src/reasons.ts +57 -0
- package/src/run-state.ts +166 -0
- package/src/schema.ts +3719 -0
- package/src/spend.ts +108 -0
- package/src/store.ts +338 -0
- package/src/types.ts +165 -0
package/dist/feed.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RunFeedMessage, StreamPage } from './types.js';
|
|
2
|
+
/** Every SSE event name of `/events` with a fixed meaning; panels add `panel:<name>`. */
|
|
3
|
+
export declare const RUN_EVENT_NAMES: readonly ["journal", "procs", "plan", "outputs", "cursor", "ready"];
|
|
4
|
+
export interface FeedHandlers<M> {
|
|
5
|
+
message(msg: M): void;
|
|
6
|
+
/** The connection opened, or re-opened after a drop (the server then starts over). */
|
|
7
|
+
open?(): void;
|
|
8
|
+
/** The connection dropped; the browser retries on its own. */
|
|
9
|
+
error?(): void;
|
|
10
|
+
}
|
|
11
|
+
export interface FeedOptions {
|
|
12
|
+
/** Where the monitor is served, as for the client; '' (the default) is the page's own origin. */
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
/** For tests and non-browser hosts. */
|
|
15
|
+
EventSource?: typeof globalThis.EventSource;
|
|
16
|
+
}
|
|
17
|
+
/** A feed to stop. */
|
|
18
|
+
export type Unsubscribe = () => void;
|
|
19
|
+
/**
|
|
20
|
+
* `/events?run=`: the run, live. The server replays the whole journal on every
|
|
21
|
+
* (re)connect and then sends `ready`; `panels` are the panel names from
|
|
22
|
+
* `/api/info` to listen for.
|
|
23
|
+
*/
|
|
24
|
+
export declare function openRunFeed(run: string, panels: readonly string[], on: FeedHandlers<RunFeedMessage>, opts?: FeedOptions): Unsubscribe;
|
|
25
|
+
/** `/events/stream`: one transcript, tailed. The first page is the tail; each later one only what is new. */
|
|
26
|
+
export declare function openStreamFeed(run: string, key: string, on: FeedHandlers<StreamPage>, opts?: FeedOptions): Unsubscribe;
|
|
27
|
+
//# sourceMappingURL=feed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feed.d.ts","sourceRoot":"","sources":["../src/feed.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAgB,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE3E,yFAAyF;AACzF,eAAO,MAAM,eAAe,qEAOgB,CAAC;AAO7C,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC;IACtB,sFAAsF;IACtF,IAAI,CAAC,IAAI,IAAI,CAAC;IACd,8DAA8D;IAC9D,KAAK,CAAC,IAAI,IAAI,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,iGAAiG;IACjG,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,WAAW,CAAC,EAAE,OAAO,UAAU,CAAC,WAAW,CAAC;CAC7C;AAED,sBAAsB;AACtB,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAkBrC;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,EAAE,EAAE,YAAY,CAAC,cAAc,CAAC,EAChC,IAAI,GAAE,WAAgB,GACrB,WAAW,CAGb;AAED,6GAA6G;AAC7G,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,YAAY,CAAC,UAAU,CAAC,EAC5B,IAAI,GAAE,WAAgB,GACrB,WAAW,CAOb"}
|
package/dist/feed.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Every SSE event name of `/events` with a fixed meaning; panels add `panel:<name>`. */
|
|
2
|
+
export const RUN_EVENT_NAMES = [
|
|
3
|
+
'journal',
|
|
4
|
+
'procs',
|
|
5
|
+
'plan',
|
|
6
|
+
'outputs',
|
|
7
|
+
'cursor',
|
|
8
|
+
'ready',
|
|
9
|
+
];
|
|
10
|
+
const _exhaustive = true;
|
|
11
|
+
void _exhaustive;
|
|
12
|
+
function connect(url, names, on, opts) {
|
|
13
|
+
const ES = opts.EventSource ?? globalThis.EventSource;
|
|
14
|
+
const es = new ES(url);
|
|
15
|
+
es.onopen = () => on.open?.();
|
|
16
|
+
es.onerror = () => on.error?.();
|
|
17
|
+
for (const name of names) {
|
|
18
|
+
es.addEventListener(name, (ev) => {
|
|
19
|
+
on.message({ event: name, data: JSON.parse(ev.data) });
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return () => es.close();
|
|
23
|
+
}
|
|
24
|
+
const q = encodeURIComponent;
|
|
25
|
+
const base = (opts) => (opts.baseUrl ?? '').replace(/\/$/, '');
|
|
26
|
+
/**
|
|
27
|
+
* `/events?run=`: the run, live. The server replays the whole journal on every
|
|
28
|
+
* (re)connect and then sends `ready`; `panels` are the panel names from
|
|
29
|
+
* `/api/info` to listen for.
|
|
30
|
+
*/
|
|
31
|
+
export function openRunFeed(run, panels, on, opts = {}) {
|
|
32
|
+
const names = [...RUN_EVENT_NAMES, ...panels.map((p) => `panel:${p}`)];
|
|
33
|
+
return connect(`${base(opts)}/events?run=${q(run)}`, names, on, opts);
|
|
34
|
+
}
|
|
35
|
+
/** `/events/stream`: one transcript, tailed. The first page is the tail; each later one only what is new. */
|
|
36
|
+
export function openStreamFeed(run, key, on, opts = {}) {
|
|
37
|
+
return connect(`${base(opts)}/events/stream?run=${q(run)}&key=${q(key)}`, ['stream'], { ...on, message: (m) => on.message(m.data) }, opts);
|
|
38
|
+
}
|
|
39
|
+
//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AE,EAAE,CAAC,CAAC;AAEpF;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,GAAW,EACX,MAAyB,EACzB,EAAgC,EAChC,OAAoB,EAAE;IAEtB,MAAM,KAAK,GAAG,CAAC,GAAG,eAAe,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;IACvE,OAAO,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;AACxE,CAAC;AAED,6GAA6G;AAC7G,MAAM,UAAU,cAAc,CAC5B,GAAW,EACX,GAAW,EACX,EAA4B,EAC5B,OAAoB,EAAE;IAEtB,OAAO,OAAO,CACZ,GAAG,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,EAAE,EACzD,CAAC,QAAQ,CAAC,EACV,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,IAAkB,CAAC,EAAE,EAC3D,IAAI,CACL,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './client.js';
|
|
3
|
+
export * from './feed.js';
|
|
4
|
+
export * from './run-state.js';
|
|
5
|
+
export * from './store.js';
|
|
6
|
+
export * from './export.js';
|
|
7
|
+
export * from './outcomes.js';
|
|
8
|
+
export * from './derive.js';
|
|
9
|
+
export * from './spend.js';
|
|
10
|
+
export * from './quota.js';
|
|
11
|
+
export * from './reasons.js';
|
|
12
|
+
export * from './panels.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './client.js';
|
|
3
|
+
export * from './feed.js';
|
|
4
|
+
export * from './run-state.js';
|
|
5
|
+
export * from './store.js';
|
|
6
|
+
export * from './export.js';
|
|
7
|
+
export * from './outcomes.js';
|
|
8
|
+
export * from './derive.js';
|
|
9
|
+
export * from './spend.js';
|
|
10
|
+
export * from './quota.js';
|
|
11
|
+
export * from './reasons.js';
|
|
12
|
+
export * from './panels.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { DeferralCause, JournalRow, Plan, PlanNode, TaskState } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* - `done`: its last attempt completed, first time.
|
|
4
|
+
* - `recovered`: a try that ran failed at least once, then its last attempt completed.
|
|
5
|
+
* - `partial`: its last attempt was partial (stop `partial`): ok, its output a placeholder; not done, not failed.
|
|
6
|
+
* - `failed`: it ran and its last attempt failed.
|
|
7
|
+
* - `not_started`: it never ran: an input was missing or off-contract, or it waits behind a task that failed.
|
|
8
|
+
* - `running`, `waiting` (queued, not started yet), `skipped`.
|
|
9
|
+
*/
|
|
10
|
+
export type Outcome = 'done' | 'recovered' | 'partial' | 'failed' | 'not_started' | 'running' | 'waiting' | 'skipped';
|
|
11
|
+
export interface TaskOutcome {
|
|
12
|
+
key: string;
|
|
13
|
+
kind: string;
|
|
14
|
+
unit: string;
|
|
15
|
+
executor: 'agent' | 'python';
|
|
16
|
+
outcome: Outcome;
|
|
17
|
+
/** Its journal rows, oldest first (a refusal included). */
|
|
18
|
+
attempts: JournalRow[];
|
|
19
|
+
/** The rows of tries that actually ran (`isLaunched`), oldest first. */
|
|
20
|
+
tries: JournalRow[];
|
|
21
|
+
/** For a task that did not start: the failed task upstream that stopped it, if one is known. */
|
|
22
|
+
cause: string | null;
|
|
23
|
+
/** For a task the queue deferred (never launched): why, as the run recorded it; '' when it was not. */
|
|
24
|
+
deferred: string;
|
|
25
|
+
/** The same as data, for words of a reader's language; null when it was not deferred, or the run recorded no cause. */
|
|
26
|
+
deferredCause: DeferralCause | null;
|
|
27
|
+
/** For a task deferred by a flow call's own deadline (`time_box`): that flow call's function (`module.qualname`); '' otherwise. */
|
|
28
|
+
deferredIn: string;
|
|
29
|
+
}
|
|
30
|
+
/** The function of the flow call whose own deadline (`time_box`) deferred a task (`cause.flow_call`); '' for the run's deadline or another cause. */
|
|
31
|
+
export declare function deferredIn(plan: Pick<Plan, 'flow_calls'> | null | undefined, cause: DeferralCause | null | undefined): string;
|
|
32
|
+
/**
|
|
33
|
+
* The row is a real try: the task ran. A task refused before launch
|
|
34
|
+
* (`invalid_input`) or skipped also gets a journal row, but never ran: it is
|
|
35
|
+
* not a try, not an agent session, and not a failed attempt.
|
|
36
|
+
*/
|
|
37
|
+
export declare const isLaunched: (r: JournalRow) => boolean;
|
|
38
|
+
/**
|
|
39
|
+
* A task's outcome from its plan node (if any) and its journal rows, oldest
|
|
40
|
+
* first. `recovered` needs a try that ran and failed: a refusal before launch
|
|
41
|
+
* (`invalid_input`) is not a failed attempt, so "not started, then done" is `done`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function outcomeOf(node: Pick<PlanNode, 'state'> | undefined, attempts: readonly JournalRow[]): Outcome;
|
|
44
|
+
/**
|
|
45
|
+
* The retries in `journal`, oldest first: the tries that ran (`isLaunched`)
|
|
46
|
+
* after an earlier try of the same task ran and failed, as in `recovered`. A
|
|
47
|
+
* try after a refusal (`invalid_input`) is not a retry.
|
|
48
|
+
*/
|
|
49
|
+
export declare function retries(journal: readonly JournalRow[]): JournalRow[];
|
|
50
|
+
/**
|
|
51
|
+
* A plan node's state as an outcome: `blocked` is `not_started` and `pending`
|
|
52
|
+
* is `waiting`. Plan state `done` covers both `done` and `recovered`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function planOutcome(state: TaskState): Outcome;
|
|
55
|
+
/** Nothing is left to do for the task in this run: done, done after retrying, partial (its later tasks run on its output), or skipped. */
|
|
56
|
+
export declare const isFinished: (o: Outcome) => boolean;
|
|
57
|
+
/** Every task of the run (from the plan, and from the journal for tasks the plan does not list), by key. */
|
|
58
|
+
export declare function taskOutcomes(journal: readonly JournalRow[], plan: Plan): Map<string, TaskOutcome>;
|
|
59
|
+
export interface Problem {
|
|
60
|
+
/** The task that failed. */
|
|
61
|
+
task: TaskOutcome;
|
|
62
|
+
/** The tasks that did not start because of it. */
|
|
63
|
+
stopped: TaskOutcome[];
|
|
64
|
+
}
|
|
65
|
+
export interface Problems {
|
|
66
|
+
/** Failed tasks, the latest first, each with the tasks it stopped. */
|
|
67
|
+
failed: Problem[];
|
|
68
|
+
/** Tasks that did not start for a reason of their own. */
|
|
69
|
+
notStarted: TaskOutcome[];
|
|
70
|
+
/** Partial tasks: ok, their output a placeholder. */
|
|
71
|
+
partial: TaskOutcome[];
|
|
72
|
+
/** Tasks done after retrying. */
|
|
73
|
+
recovered: TaskOutcome[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* What is wrong with the run, causes first: each failed task with the tasks
|
|
77
|
+
* it stopped, then tasks that did not start for a reason of their own (an
|
|
78
|
+
* input that was never produced by a task). Tasks that recovered are not
|
|
79
|
+
* problems: they are listed apart, after them.
|
|
80
|
+
*/
|
|
81
|
+
export declare function problems(outcomes: ReadonlyMap<string, TaskOutcome>): Problems;
|
|
82
|
+
/** How many tasks the run has, and how they ended. */
|
|
83
|
+
export declare function outcomeCounts(outcomes: ReadonlyMap<string, TaskOutcome>): Record<Outcome, number> & {
|
|
84
|
+
total: number;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* One task of the run as a list shows it: what happened to it (`TaskOutcome`)
|
|
88
|
+
* and what its tries add up to. A task that never ran has no tries: `wall_s` 0,
|
|
89
|
+
* `last_ts` and `last_stop` ''.
|
|
90
|
+
*/
|
|
91
|
+
export interface TaskRow extends TaskOutcome {
|
|
92
|
+
/** Its loop pass (the innermost loop of its flow path), from 1; null outside a loop. */
|
|
93
|
+
pass: number | null;
|
|
94
|
+
/** Time of its tries, summed, in seconds. */
|
|
95
|
+
wall_s: number;
|
|
96
|
+
/** When its last journal row was written; '' for none. */
|
|
97
|
+
last_ts: string;
|
|
98
|
+
/** The stop of its last journal row; '' for none. */
|
|
99
|
+
last_stop: string;
|
|
100
|
+
/** A waiting task: the keys of the earlier tasks it waits for that have not finished, in plan order. */
|
|
101
|
+
waits_for: string[];
|
|
102
|
+
/** The names it holds while it runs (`claims`); empty for none. */
|
|
103
|
+
claims: string[];
|
|
104
|
+
/** Its task call's `priority`: a tie-breaker in the queue's order; 0 by default. */
|
|
105
|
+
priority: number;
|
|
106
|
+
}
|
|
107
|
+
/** The innermost loop pass of a plan node's flow path; null outside a loop (a pass not counted reads as the first). */
|
|
108
|
+
export declare function loopPass(node: Pick<PlanNode, 'flow'> | undefined): number | null;
|
|
109
|
+
/**
|
|
110
|
+
* Every task of the run, one row each, from its outcomes (`taskOutcomes`): the
|
|
111
|
+
* plan joined with the journal, so a task that never ran (waiting, not started)
|
|
112
|
+
* is a row too. In plan order. Views read them from `deriveRun(...).rows`.
|
|
113
|
+
*/
|
|
114
|
+
export declare function taskRows(outcomes: ReadonlyMap<string, TaskOutcome>, plan: Plan): TaskRow[];
|
|
115
|
+
/** The task to open by default: a running agent task, else the agent task that ran last (it has a transcript); never a Python task. Its key, or null. */
|
|
116
|
+
export declare function latestTask(rows: readonly TaskRow[]): string | null;
|
|
117
|
+
//# sourceMappingURL=outcomes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outcomes.d.ts","sourceRoot":"","sources":["../src/outcomes.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvF;;;;;;;GAOG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,aAAa,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAEtH,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,2DAA2D;IAC3D,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,wEAAwE;IACxE,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,gGAAgG;IAChG,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,uGAAuG;IACvG,QAAQ,E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_call`); '' for the run's deadline or another cause. */
|
|
2
|
+
export function deferredIn(plan, cause) {
|
|
3
|
+
const id = cause?.flow_call;
|
|
4
|
+
return id ? (plan?.flow_calls?.find((c) => c.id === id)?.function ?? '') : '';
|
|
5
|
+
}
|
|
6
|
+
const isOk = (r) => r.ok;
|
|
7
|
+
/**
|
|
8
|
+
* The row is a real try: the task ran. A task refused before launch
|
|
9
|
+
* (`invalid_input`) or skipped also gets a journal row, but never ran: it is
|
|
10
|
+
* not a try, not an agent session, and not a failed attempt.
|
|
11
|
+
*/
|
|
12
|
+
export const isLaunched = (r) => r.stop !== 'invalid_input' && r.stop !== 'skipped';
|
|
13
|
+
/**
|
|
14
|
+
* A task's outcome from its plan node (if any) and its journal rows, oldest
|
|
15
|
+
* first. `recovered` needs a try that ran and failed: a refusal before launch
|
|
16
|
+
* (`invalid_input`) is not a failed attempt, so "not started, then done" is `done`.
|
|
17
|
+
*/
|
|
18
|
+
export function outcomeOf(node, attempts) {
|
|
19
|
+
if (node?.state === 'running')
|
|
20
|
+
return 'running';
|
|
21
|
+
const last = attempts[attempts.length - 1];
|
|
22
|
+
if (!last)
|
|
23
|
+
return node?.state === 'blocked' ? 'not_started' : 'waiting';
|
|
24
|
+
if (last.stop === 'skipped')
|
|
25
|
+
return 'skipped';
|
|
26
|
+
if (last.stop === 'invalid_input')
|
|
27
|
+
return 'not_started';
|
|
28
|
+
if (last.stop === 'partial')
|
|
29
|
+
return 'partial';
|
|
30
|
+
if (isOk(last))
|
|
31
|
+
return attempts.some((a) => isLaunched(a) && !isOk(a)) ? 'recovered' : 'done';
|
|
32
|
+
return 'failed';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The retries in `journal`, oldest first: the tries that ran (`isLaunched`)
|
|
36
|
+
* after an earlier try of the same task ran and failed, as in `recovered`. A
|
|
37
|
+
* try after a refusal (`invalid_input`) is not a retry.
|
|
38
|
+
*/
|
|
39
|
+
export function retries(journal) {
|
|
40
|
+
const failed = new Set();
|
|
41
|
+
const out = [];
|
|
42
|
+
for (const r of journal) {
|
|
43
|
+
if (!isLaunched(r))
|
|
44
|
+
continue;
|
|
45
|
+
if (failed.has(r.key))
|
|
46
|
+
out.push(r);
|
|
47
|
+
if (!isOk(r))
|
|
48
|
+
failed.add(r.key);
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A plan node's state as an outcome: `blocked` is `not_started` and `pending`
|
|
54
|
+
* is `waiting`. Plan state `done` covers both `done` and `recovered`.
|
|
55
|
+
*/
|
|
56
|
+
export function planOutcome(state) {
|
|
57
|
+
switch (state) {
|
|
58
|
+
case 'blocked':
|
|
59
|
+
return 'not_started';
|
|
60
|
+
case 'pending':
|
|
61
|
+
return 'waiting';
|
|
62
|
+
default:
|
|
63
|
+
return state;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Nothing is left to do for the task in this run: done, done after retrying, partial (its later tasks run on its output), or skipped. */
|
|
67
|
+
export const isFinished = (o) => o === 'done' || o === 'recovered' || o === 'partial' || o === 'skipped';
|
|
68
|
+
/** Every task of the run (from the plan, and from the journal for tasks the plan does not list), by key. */
|
|
69
|
+
export function taskOutcomes(journal, plan) {
|
|
70
|
+
const rows = new Map();
|
|
71
|
+
for (const r of journal) {
|
|
72
|
+
let list = rows.get(r.key);
|
|
73
|
+
if (!list)
|
|
74
|
+
rows.set(r.key, (list = []));
|
|
75
|
+
list.push(r);
|
|
76
|
+
}
|
|
77
|
+
const nodes = new Map(plan.nodes.map((n) => [n.key, n]));
|
|
78
|
+
const keys = [...new Set([...plan.nodes.map((n) => n.key), ...rows.keys()])];
|
|
79
|
+
const out = new Map();
|
|
80
|
+
for (const key of keys) {
|
|
81
|
+
const node = nodes.get(key);
|
|
82
|
+
const attempts = rows.get(key) ?? [];
|
|
83
|
+
const first = attempts[0];
|
|
84
|
+
out.set(key, {
|
|
85
|
+
key,
|
|
86
|
+
kind: node?.kind ?? first?.kind ?? '',
|
|
87
|
+
unit: node?.unit ?? first?.unit ?? '',
|
|
88
|
+
executor: node?.executor ?? first?.executor ?? 'agent',
|
|
89
|
+
outcome: outcomeOf(node, attempts),
|
|
90
|
+
attempts,
|
|
91
|
+
tries: attempts.filter(isLaunched),
|
|
92
|
+
cause: null,
|
|
93
|
+
deferred: node?.deferred ?? '',
|
|
94
|
+
deferredCause: node?.deferred_cause ?? null,
|
|
95
|
+
deferredIn: deferredIn(plan, node?.deferred_cause),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
// A task that did not start: follow what it waits for to the task that actually failed.
|
|
99
|
+
const rootOf = (key, seen) => {
|
|
100
|
+
for (const dep of nodes.get(key)?.after ?? []) {
|
|
101
|
+
if (seen.has(dep))
|
|
102
|
+
continue;
|
|
103
|
+
seen.add(dep);
|
|
104
|
+
const d = out.get(dep);
|
|
105
|
+
if (d?.outcome === 'failed')
|
|
106
|
+
return dep;
|
|
107
|
+
if (d?.outcome === 'not_started') {
|
|
108
|
+
const r = rootOf(dep, seen);
|
|
109
|
+
if (r)
|
|
110
|
+
return r;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
};
|
|
115
|
+
for (const t of out.values())
|
|
116
|
+
if (t.outcome === 'not_started')
|
|
117
|
+
t.cause = rootOf(t.key, new Set());
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* What is wrong with the run, causes first: each failed task with the tasks
|
|
122
|
+
* it stopped, then tasks that did not start for a reason of their own (an
|
|
123
|
+
* input that was never produced by a task). Tasks that recovered are not
|
|
124
|
+
* problems: they are listed apart, after them.
|
|
125
|
+
*/
|
|
126
|
+
export function problems(outcomes) {
|
|
127
|
+
const failed = new Map();
|
|
128
|
+
for (const t of outcomes.values())
|
|
129
|
+
if (t.outcome === 'failed')
|
|
130
|
+
failed.set(t.key, { task: t, stopped: [] });
|
|
131
|
+
const notStarted = [];
|
|
132
|
+
for (const t of outcomes.values()) {
|
|
133
|
+
if (t.outcome !== 'not_started')
|
|
134
|
+
continue;
|
|
135
|
+
const p = t.cause ? failed.get(t.cause) : undefined;
|
|
136
|
+
if (p)
|
|
137
|
+
p.stopped.push(t);
|
|
138
|
+
else
|
|
139
|
+
notStarted.push(t);
|
|
140
|
+
}
|
|
141
|
+
const lastTs = (t) => t.attempts[t.attempts.length - 1]?.ts ?? '';
|
|
142
|
+
return {
|
|
143
|
+
failed: [...failed.values()].sort((a, b) => lastTs(b.task).localeCompare(lastTs(a.task))),
|
|
144
|
+
notStarted,
|
|
145
|
+
partial: [...outcomes.values()].filter((t) => t.outcome === 'partial'),
|
|
146
|
+
recovered: [...outcomes.values()].filter((t) => t.outcome === 'recovered'),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/** How many tasks the run has, and how they ended. */
|
|
150
|
+
export function outcomeCounts(outcomes) {
|
|
151
|
+
const c = { done: 0, recovered: 0, partial: 0, failed: 0, not_started: 0, running: 0, waiting: 0, skipped: 0, total: 0 };
|
|
152
|
+
for (const t of outcomes.values()) {
|
|
153
|
+
c[t.outcome]++;
|
|
154
|
+
c.total++;
|
|
155
|
+
}
|
|
156
|
+
return c;
|
|
157
|
+
}
|
|
158
|
+
/** The innermost loop pass of a plan node's flow path; null outside a loop (a pass not counted reads as the first). */
|
|
159
|
+
export function loopPass(node) {
|
|
160
|
+
const frames = Array.isArray(node?.flow) ? node.flow : [];
|
|
161
|
+
for (let i = frames.length - 1; i >= 0; i--) {
|
|
162
|
+
const loops = frames[i]?.loops ?? [];
|
|
163
|
+
const inner = loops[loops.length - 1];
|
|
164
|
+
if (inner)
|
|
165
|
+
return typeof inner.pass === 'number' && inner.pass >= 1 ? inner.pass : 1;
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Every task of the run, one row each, from its outcomes (`taskOutcomes`): the
|
|
171
|
+
* plan joined with the journal, so a task that never ran (waiting, not started)
|
|
172
|
+
* is a row too. In plan order. Views read them from `deriveRun(...).rows`.
|
|
173
|
+
*/
|
|
174
|
+
export function taskRows(outcomes, plan) {
|
|
175
|
+
const nodes = new Map(plan.nodes.map((n) => [n.key, n]));
|
|
176
|
+
return [...outcomes.values()].map((t) => {
|
|
177
|
+
const last = t.attempts[t.attempts.length - 1];
|
|
178
|
+
const node = nodes.get(t.key);
|
|
179
|
+
return {
|
|
180
|
+
...t,
|
|
181
|
+
pass: loopPass(node),
|
|
182
|
+
wall_s: t.tries.reduce((s, r) => s + (r.wall_s || 0), 0),
|
|
183
|
+
last_ts: last?.ts ?? '',
|
|
184
|
+
last_stop: last?.stop ?? '',
|
|
185
|
+
waits_for: t.outcome === 'waiting' ? (node?.after ?? []).filter((d) => !isFinished(outcomes.get(d)?.outcome ?? 'waiting')) : [],
|
|
186
|
+
claims: node?.claims ?? [],
|
|
187
|
+
priority: node?.priority ?? 0,
|
|
188
|
+
};
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/** The task to open by default: a running agent task, else the agent task that ran last (it has a transcript); never a Python task. Its key, or null. */
|
|
192
|
+
export function latestTask(rows) {
|
|
193
|
+
const agent = rows.filter((t) => t.executor !== 'python');
|
|
194
|
+
const running = agent.find((t) => t.outcome === 'running');
|
|
195
|
+
if (running)
|
|
196
|
+
return running.key;
|
|
197
|
+
const ran = (t) => t.tries[t.tries.length - 1]?.ts ?? '';
|
|
198
|
+
const last = agent.filter(ran).sort((a, b) => ran(b).localeCompare(ran(a)))[0];
|
|
199
|
+
return last?.key ?? null;
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=outcomes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outcomes.js","sourceRoot":"","sources":["../src/outcomes.ts"],"names":[],"mappings":"AAoCA,qJAAqJ;AACrJ,MAAM,UAAU,UAAU,CAAC,IAAiD,EAAE,KAAuC;IACnH,MAAM,EAAE,GAAG,KAAK,EAAE,SAAS,CAAC;IAC5B,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,CAAC;SAC9B,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,yJAAyJ;AACzJ,MAAM,UAAU,UAAU,CAAC,IAAwB;IACjD,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC;IAC3D,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC,GAAG,CAAC;IAChC,MAAM,GAAG,GAAG,CAAC,CAAU,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC;IAClE,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/E,OAAO,IAAI,EAAE,GAAG,IAAI,IAAI,CAAC;AAC3B,CAAC"}
|
package/dist/panels.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { components } from './schema.js';
|
|
2
|
+
import type { JsonObject, PanelInfo } from './types.js';
|
|
3
|
+
type S = components['schemas'];
|
|
4
|
+
export type TilesBody = S['TilesBody'];
|
|
5
|
+
export type PanelTile = S['PanelTile'];
|
|
6
|
+
export type TableBody = S['TableBody'];
|
|
7
|
+
export type TableColumn = S['TableColumn'];
|
|
8
|
+
export type ColumnsBody = S['ColumnsBody'];
|
|
9
|
+
export type LinesBody = S['LinesBody'];
|
|
10
|
+
export type HeatmapBody = S['HeatmapBody'];
|
|
11
|
+
export type HBarsBody = S['HBarsBody'];
|
|
12
|
+
export type HBar = S['HBar'];
|
|
13
|
+
export type StatusGridBody = S['StatusGridBody'];
|
|
14
|
+
export type GridCell = S['GridCell'];
|
|
15
|
+
export type NoteBody = S['NoteBody'];
|
|
16
|
+
export type BlocksBody = S['BlocksBody'];
|
|
17
|
+
export type ChartSeries = S['ChartSeries'];
|
|
18
|
+
/** How a number of a body is written: `pct` is a fraction (0.97 is 97%), `duration` seconds, `datetime` an ISO time. */
|
|
19
|
+
export type ValueFormat = NonNullable<TableColumn['format']>;
|
|
20
|
+
/** A body with a `type`: drawn with the monitor's own elements. */
|
|
21
|
+
export type TypedPanelBody = TilesBody | TableBody | ColumnsBody | LinesBody | HeatmapBody | HBarsBody | StatusGridBody | NoteBody | BlocksBody;
|
|
22
|
+
/** What a panel returns: a typed body, or any JSON object. */
|
|
23
|
+
export type PanelBody = TypedPanelBody | JsonObject;
|
|
24
|
+
/** The `type` of each typed body. */
|
|
25
|
+
export declare const PANEL_TYPES: readonly ["tiles", "table", "columns", "lines", "heatmap", "hbars", "status_grid", "note", "blocks"];
|
|
26
|
+
/** `body` as a typed body, or null when it is any other JSON object (a JSON tree). */
|
|
27
|
+
export declare function typedBody(body: unknown): TypedPanelBody | null;
|
|
28
|
+
/** A panel computed per run: a tab of each run, sent on its live feed (a trends panel is not). */
|
|
29
|
+
export declare const isRunPanel: (p: Pick<PanelInfo, "scope">) => boolean;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=panels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panels.d.ts","sourceRoot":"","sources":["../src/panels.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAExD,KAAK,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;A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ACtF,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAI9D;AAED,kGAAkG;AAClG,eAAO,MAAM,UAAU,GAAI,GAAG,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,KAAG,OAAuC,CAAC"}
|
package/dist/panels.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The `type` of each typed body. */
|
|
2
|
+
export const PANEL_TYPES = ['tiles', 'table', 'columns', 'lines', 'heatmap', 'hbars', 'status_grid', 'note', 'blocks'];
|
|
3
|
+
/** `body` as a typed body, or null when it is any other JSON object (a JSON tree). */
|
|
4
|
+
export function typedBody(body) {
|
|
5
|
+
if (!body || typeof body !== 'object' || Array.isArray(body))
|
|
6
|
+
return null;
|
|
7
|
+
const type = body.type;
|
|
8
|
+
return typeof type === 'string' && PANEL_TYPES.includes(type) ? body : null;
|
|
9
|
+
}
|
|
10
|
+
/** A panel computed per run: a tab of each run, sent on its live feed (a trends panel is not). */
|
|
11
|
+
export const isRunPanel = (p) => (p.scope ?? 'run') === 'run';
|
|
12
|
+
//# sourceMappingURL=panels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panels.js","sourceRoot":"","sources":["../src/panels.ts"],"names":[],"mappings":"AAuCA,qCAAqC;AACrC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,CAAU,CAAC;AAEhI,sFAAsF;AACtF,MAAM,UAAU,SAAS,CAAC,IAAa;IACrC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1E,MAAM,IAAI,GAAI,IAA2B,CAAC,IAAI,CAAC;IAC/C,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAK,WAAiC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,IAAuB,CAAC,CAAC,CAAC,IAAI,CAAC;AACzH,CAAC;AAED,kGAAkG;AAClG,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAA2B,EAAW,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,CAAC"}
|
package/dist/quota.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { JournalRow, QuotaReading } from './types.js';
|
|
2
|
+
/** A reading, and the row (try) it came with. */
|
|
3
|
+
export interface SourcedReading {
|
|
4
|
+
reading: QuotaReading;
|
|
5
|
+
key: string;
|
|
6
|
+
attempt: number;
|
|
7
|
+
}
|
|
8
|
+
/** Every reading of the run, oldest first. */
|
|
9
|
+
export declare function runReadings(journal: readonly JournalRow[]): SourcedReading[];
|
|
10
|
+
/** One account's utilization over the run: the credential that reported it, and the account (`account`, a digest; '' when not known). */
|
|
11
|
+
export interface AccountUsage {
|
|
12
|
+
credential: string;
|
|
13
|
+
account?: string;
|
|
14
|
+
first: QuotaReading;
|
|
15
|
+
last: QuotaReading;
|
|
16
|
+
}
|
|
17
|
+
/** The account a reading is of: its credential and its account digest. `ambient` on two coding agents is two accounts. */
|
|
18
|
+
export declare const accountKey: (r: {
|
|
19
|
+
credential?: string | null;
|
|
20
|
+
account?: string | null;
|
|
21
|
+
}) => string;
|
|
22
|
+
/** Per account, the run's first and last reading; the account with the highest weekly use first. */
|
|
23
|
+
export declare function runAccounts(journal: readonly JournalRow[]): AccountUsage[];
|
|
24
|
+
export interface TryQuota {
|
|
25
|
+
/** The try's first reading: usage when its (first) session started. */
|
|
26
|
+
start: QuotaReading | null;
|
|
27
|
+
/** The first reading of the same account received after the try ended (`row.ts`), if any. */
|
|
28
|
+
next: QuotaReading | null;
|
|
29
|
+
}
|
|
30
|
+
/** One try's readings: at its start, and the next one observed after it ended. */
|
|
31
|
+
export declare function tryQuota(row: JournalRow, readings: readonly SourcedReading[]): TryQuota;
|
|
32
|
+
//# sourceMappingURL=quota.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota.d.ts","sourceRoot":"","sources":["../src/quota.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE3D,iDAAiD;AACjD,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,YAAY,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAOD,8CAA8C;AAC9C,wBAAgB,WAAW,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,GAAG,cAAc,EAAE,CAQ5E;AAED,yIAAyI;AACzI,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,YAAY,CAAC;IACpB,IAAI,EAAE,YAAY,CAAC;CACpB;AAED,0HAA0H;AAC1H,eAAO,MAAM,UAAU,GAAI,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,KAAG,MAAyD,CAAC;AAElJ,oGAAoG;AACpG,wBAAgB,WAAW,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,GAAG,YAAY,EAAE,CAe1E;AAED,MAAM,WAAW,QAAQ;IACvB,uEAAuE;IACvE,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IAC3B,6FAA6F;IAC7F,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;CAC3B;AAED,kFAAkF;AAClF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,cAAc,EAAE,GAAG,QAAQ,CAUvF"}
|
package/dist/quota.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const at = (r) => Date.parse(r.observed_at ?? '');
|
|
2
|
+
const usable = (r) => !Number.isNaN(at(r)) && (r.five_hour_pct != null || r.seven_day_pct != null);
|
|
3
|
+
/** Every reading of the run, oldest first. */
|
|
4
|
+
export function runReadings(journal) {
|
|
5
|
+
const out = [];
|
|
6
|
+
for (const row of journal) {
|
|
7
|
+
for (const reading of row.quota ?? []) {
|
|
8
|
+
if (usable(reading))
|
|
9
|
+
out.push({ reading, key: row.key, attempt: row.attempt ?? 0 });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return out.sort((a, b) => at(a.reading) - at(b.reading));
|
|
13
|
+
}
|
|
14
|
+
/** The account a reading is of: its credential and its account digest. `ambient` on two coding agents is two accounts. */
|
|
15
|
+
export const accountKey = (r) => `${r.credential ?? ''}\u0000${r.account ?? ''}`;
|
|
16
|
+
/** Per account, the run's first and last reading; the account with the highest weekly use first. */
|
|
17
|
+
export function runAccounts(journal) {
|
|
18
|
+
const by = new Map();
|
|
19
|
+
for (const { reading } of runReadings(journal)) {
|
|
20
|
+
const k = accountKey(reading);
|
|
21
|
+
let list = by.get(k);
|
|
22
|
+
if (!list)
|
|
23
|
+
by.set(k, (list = []));
|
|
24
|
+
list.push(reading);
|
|
25
|
+
}
|
|
26
|
+
const out = [];
|
|
27
|
+
for (const list of by.values()) {
|
|
28
|
+
const first = list[0];
|
|
29
|
+
const last = list[list.length - 1];
|
|
30
|
+
if (first && last)
|
|
31
|
+
out.push({ credential: last.credential ?? '', account: last.account ?? '', first, last });
|
|
32
|
+
}
|
|
33
|
+
return out.sort((a, b) => (b.last.seven_day_pct ?? 0) - (a.last.seven_day_pct ?? 0));
|
|
34
|
+
}
|
|
35
|
+
/** One try's readings: at its start, and the next one observed after it ended. */
|
|
36
|
+
export function tryQuota(row, readings) {
|
|
37
|
+
const own = (row.quota ?? []).filter(usable).sort((a, b) => at(a) - at(b));
|
|
38
|
+
const ended = Date.parse(row.ts);
|
|
39
|
+
const start = own[0] ?? null;
|
|
40
|
+
const account = start === null ? '' : accountKey(start);
|
|
41
|
+
const next = start === null || Number.isNaN(ended)
|
|
42
|
+
? undefined
|
|
43
|
+
: readings.find((r) => at(r.reading) > ended && accountKey(r.reading) === account);
|
|
44
|
+
return { start, next: next?.reading ?? null };
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=quota.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota.js","sourceRoot":"","sources":["../src/quota.ts"],"names":[],"mappings":"AAcA,MAAM,EAAE,GAAG,CAAC,CAAe,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;AAExE,MAAM,MAAM,GAAG,CAAC,CAAe,EAAW,EAAE,CAC1C,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,IAAI,IAAI,IAAI,CAAC,CAAC,aAAa,IAAI,IAAI,CAAC,CAAC;AAE/E,8CAA8C;AAC9C,MAAM,UAAU,WAAW,CAAC,OAA8B;IACxD,MAAM,GAAG,GAAqB,EAAE,CAAC;IACjC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,KAAK,MAAM,OAAO,IAAI,GAAG,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC;YACtC,IAAI,MAAM,CAAC,OAAO,CAAC;gBAAE,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC;QACtF,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,C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CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,CAAC,CAAC,CAAC;AACvF,CAAC;AASD,kFAAkF;AAClF,MAAM,UAAU,QAAQ,CAAC,GAAe,EAAE,QAAmC;IAC3E,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3E,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACjC,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IAC7B,MAAM,OAAO,GAAG,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACxD,MAAM,IAAI,GACR,KAAK,KAAK,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;QACnC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,KAAK,IAAI,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,CAAC;IACvF,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,IAAI,IAAI,EAAE,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** One input a task was refused for, read from its `invalid input: ...` reason. */
|
|
2
|
+
export interface InputProblem {
|
|
3
|
+
/** The file, as the reason gives it (absolute). */
|
|
4
|
+
path: string;
|
|
5
|
+
/** The key of the task that writes it, when the reason names one. */
|
|
6
|
+
producer: string;
|
|
7
|
+
/**
|
|
8
|
+
* `missing`: the file is not there; `checks`: it is there and failed its checks;
|
|
9
|
+
* `failed`: it is there, written by a task that did not succeed (`producer`).
|
|
10
|
+
*/
|
|
11
|
+
problem: 'missing' | 'checks' | 'failed';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The inputs a refused task's reason names (`invalid input: input from <key> is
|
|
15
|
+
* missing: <path>`, `invalid input: input from <key> ended <stop>: <path>`,
|
|
16
|
+
* `invalid input: <path>: required input is missing`, `invalid input: <path>:
|
|
17
|
+
* <check error>`), in order; [] for any other reason.
|
|
18
|
+
*/
|
|
19
|
+
export declare function inputProblems(reason: string | null | undefined): InputProblem[];
|
|
20
|
+
/**
|
|
21
|
+
* A text from the run (a failure reason) with absolute paths inside the run
|
|
22
|
+
* directory cut to the part after `runs/<run>/`: `out/summarize/zeta.json`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function runRelative(text: string | null | undefined, run: string): string;
|
|
25
|
+
//# sourceMappingURL=reasons.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reasons.d.ts","sourceRoot":"","sources":["../src/reasons.ts"],"names":[],"mappings":"AAGA,mFAAmF;AACnF,MAAM,WAAW,YAAY;IAC3B,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,OAAO,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;CAC1C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,YAAY,EAAE,CAwB/E;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAIhF"}
|