dsh-xdpool 3.0.7 → 3.0.9
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/CHANGELOG.md +90 -0
- package/README.md +16 -21
- package/assets/community-qr-qq.jpg +0 -0
- package/assets/icon.png +0 -0
- package/assets/xdpool-banner.gif +0 -0
- package/lib/bin.js +1030 -66
- package/lib/client.js +1488 -274
- package/lib/index.d.ts +507 -14
- package/lib/index.js +6158 -641
- package/package.json +1 -2
- package/vendor/channel-pack/pack.js +184 -49
package/lib/index.d.ts
CHANGED
|
@@ -266,6 +266,82 @@ interface WorkBuddyCredits {
|
|
|
266
266
|
expiringSoon: number;
|
|
267
267
|
nearestExpiryMs?: number;
|
|
268
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* One request as the billing meter recorded it.
|
|
271
|
+
*
|
|
272
|
+
* Only the fields the dashboard reads are named. The upstream also returns the
|
|
273
|
+
* PROMPT (`inputTrunc`, `input`), which is deliberately dropped at the parse
|
|
274
|
+
* boundary rather than carried around and forgotten about: a dashboard is a
|
|
275
|
+
* read-only view of a quota, and a copy of every prompt is not something to hold
|
|
276
|
+
* in memory for it.
|
|
277
|
+
*/
|
|
278
|
+
interface WorkBuddyUsageEntry {
|
|
279
|
+
/** Stable upstream id; the only safe de-duplication key across pages. */
|
|
280
|
+
requestId: string;
|
|
281
|
+
/** Credits this one request was charged. `0` for free models. */
|
|
282
|
+
credit: number;
|
|
283
|
+
/** Model id as billed. */
|
|
284
|
+
model: string;
|
|
285
|
+
/** Epoch ms of the request, in local time (the meter reports local stamps). */
|
|
286
|
+
at: number;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* One billing package, raw and unjudged.
|
|
290
|
+
*
|
|
291
|
+
* {@link WorkBuddyCreditPackage} is the CARD's shape: it drops expired and
|
|
292
|
+
* empty packages because a balance line has no room for them. The dashboard
|
|
293
|
+
* cannot work like that — "earned this month" is the sum of packages CREATED in
|
|
294
|
+
* the window, most of which are already spent or expired by the time it renders
|
|
295
|
+
* — so it needs the raw rows, including the ones a balance query would filter
|
|
296
|
+
* out.
|
|
297
|
+
*/
|
|
298
|
+
interface WorkBuddyResourceRow {
|
|
299
|
+
packageName: string;
|
|
300
|
+
/** `CapacityType`: 1 one-off, 2 subscription, 4 monthly. Decides which pair counts. */
|
|
301
|
+
capacityType: number;
|
|
302
|
+
/** Epoch ms the package was granted. */
|
|
303
|
+
createMs: number;
|
|
304
|
+
/** Credits the CURRENT cycle allows, and what is left of it. */
|
|
305
|
+
cycleSize: number;
|
|
306
|
+
cycleRemain: number;
|
|
307
|
+
/** Credits the package allows in total (all cycles). */
|
|
308
|
+
totalSize: number;
|
|
309
|
+
totalRemain: number;
|
|
310
|
+
/** Current cycle bounds, epoch ms; absent for a one-off package. */
|
|
311
|
+
cycleStartMs?: number;
|
|
312
|
+
cycleEndMs?: number;
|
|
313
|
+
/** Upstream `Status`: 3 is expired / exhausted. */
|
|
314
|
+
status: number;
|
|
315
|
+
/** Where deduction stops, epoch ms. The authoritative expiry for type 2. */
|
|
316
|
+
deductionEndMs?: number;
|
|
317
|
+
expiredMs?: number;
|
|
318
|
+
}
|
|
319
|
+
/** One page request against the per-request billing meter. */
|
|
320
|
+
interface WorkBuddyUsageQuery {
|
|
321
|
+
/** Inclusive lower bound, epoch ms. */
|
|
322
|
+
startMs: number;
|
|
323
|
+
/** Inclusive upper bound, epoch ms. */
|
|
324
|
+
endMs: number;
|
|
325
|
+
/** Rows asked for. The upstream clamps this at 3000. */
|
|
326
|
+
pageSize: number;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* One page of the meter.
|
|
330
|
+
*
|
|
331
|
+
* `count` is the RAW row count, not `entries.length`: a page whose rows all
|
|
332
|
+
* failed to parse would otherwise look like the end of the data and silently
|
|
333
|
+
* truncate a window. The caller decides "done" from `count`, which is the only
|
|
334
|
+
* number the upstream actually controls.
|
|
335
|
+
*/
|
|
336
|
+
type WorkBuddyUsagePage = {
|
|
337
|
+
ok: true;
|
|
338
|
+
entries: readonly WorkBuddyUsageEntry[];
|
|
339
|
+
count: number;
|
|
340
|
+
} | {
|
|
341
|
+
ok: false;
|
|
342
|
+
retryable: boolean;
|
|
343
|
+
reason: string;
|
|
344
|
+
};
|
|
269
345
|
/** Daily check-in activity state. */
|
|
270
346
|
interface WorkBuddyCheckinStatus {
|
|
271
347
|
active: boolean;
|
|
@@ -596,6 +672,52 @@ export declare class WorkBuddyUpstreamClient {
|
|
|
596
672
|
* in force so a signal-less caller keeps the old behaviour exactly.
|
|
597
673
|
*/
|
|
598
674
|
fetchCredits(credential: WorkBuddyCredential, signal?: AbortSignal): Promise<WorkBuddyCredits>;
|
|
675
|
+
/**
|
|
676
|
+
* One page of the per-request billing meter.
|
|
677
|
+
*
|
|
678
|
+
* WHY THIS IS A RAW READ
|
|
679
|
+
*
|
|
680
|
+
* {@link fetchCredits} answers "how much is left", which is a single number and
|
|
681
|
+
* can be normalised on the spot. This answers "what was each request charged",
|
|
682
|
+
* and the dashboard above it needs the rows themselves: it sums them per day,
|
|
683
|
+
* per account and per model, and reconciles the result against the packages.
|
|
684
|
+
* Normalising here would push that arithmetic into the caller's document
|
|
685
|
+
* builder, where a missing field has no way to say so.
|
|
686
|
+
*
|
|
687
|
+
* THREE MEASURED UPSTREAM BEHAVIOURS, all of which the caller must survive:
|
|
688
|
+
*
|
|
689
|
+
* - the rows come back NEWEST FIRST, so a second page with the same window
|
|
690
|
+
* answers empty (the meter has no offset — see {@link WorkBuddyUsageQuery.endMs});
|
|
691
|
+
* - `data.total` is CLAMPED AT 3000, so it cannot be used to decide "done";
|
|
692
|
+
* - a single day CAN exceed 3000 requests, in which case a page boundary
|
|
693
|
+
* silently drops the rest unless the caller slides the window.
|
|
694
|
+
*
|
|
695
|
+
* Excess concurrency is refused upstream with `429 Too Many Requests` as plain
|
|
696
|
+
* text (not a JSON envelope), so it is reported as a retryable failure rather
|
|
697
|
+
* than thrown as a malformed document.
|
|
698
|
+
*/
|
|
699
|
+
fetchUsageEntries(credential: WorkBuddyCredential, query: WorkBuddyUsageQuery, signal?: AbortSignal): Promise<WorkBuddyUsagePage>;
|
|
700
|
+
/**
|
|
701
|
+
* Every billing package this credential holds, raw.
|
|
702
|
+
*
|
|
703
|
+
* The window is deliberately wide on both sides. `fetchCredits` asks for
|
|
704
|
+
* packages ending in the FUTURE, because a balance only counts what can still
|
|
705
|
+
* be spent; a dashboard asking "what did I gain this month" needs the ones that
|
|
706
|
+
* already ended too, or the first day of the window reads as zero income. The
|
|
707
|
+
* upstream caps this list at `PageSize`, so it is asked for once at 300 and the
|
|
708
|
+
* caller treats a full page as "there may be more" rather than as the truth.
|
|
709
|
+
*/
|
|
710
|
+
fetchResourceRows(credential: WorkBuddyCredential, range: {
|
|
711
|
+
beginMs: number;
|
|
712
|
+
endMs: number;
|
|
713
|
+
}, signal?: AbortSignal): Promise<{
|
|
714
|
+
ok: true;
|
|
715
|
+
rows: readonly WorkBuddyResourceRow[];
|
|
716
|
+
truncated: boolean;
|
|
717
|
+
} | {
|
|
718
|
+
ok: false;
|
|
719
|
+
reason: string;
|
|
720
|
+
}>;
|
|
599
721
|
/** Query today's check-in status without changing account state. */
|
|
600
722
|
fetchCheckinStatus(credential: WorkBuddyCredential): Promise<WorkBuddyCheckinStatus>;
|
|
601
723
|
/** Claim today's check-in reward. The browser route guards this mutation. */
|
|
@@ -1013,6 +1135,14 @@ interface AccountPoolOptions {
|
|
|
1013
1135
|
* time. The caller passes the plugin's own state path; tests pass a temp file.
|
|
1014
1136
|
*/
|
|
1015
1137
|
affinityPath?: string;
|
|
1138
|
+
/**
|
|
1139
|
+
* Where to mirror the last known credit balance per account.
|
|
1140
|
+
*
|
|
1141
|
+
* Without it the balances live only in memory, so a restart resets them to
|
|
1142
|
+
* "unknown" and `available()` lets reserved accounts through until the first
|
|
1143
|
+
* reading arrives (see the field comment on `creditBalancePath`).
|
|
1144
|
+
*/
|
|
1145
|
+
creditBalancePath?: string;
|
|
1016
1146
|
/** Logger for discovery and rotation events. */
|
|
1017
1147
|
logger?: {
|
|
1018
1148
|
info?(...args: unknown[]): void;
|
|
@@ -1187,6 +1317,27 @@ export declare class WorkBuddyAccountPool {
|
|
|
1187
1317
|
* strand a healthy pool, and the first 402 still cools it as before.
|
|
1188
1318
|
*/
|
|
1189
1319
|
private creditBalances;
|
|
1320
|
+
/**
|
|
1321
|
+
* Where the last known balances are mirrored, when the host supplies a path.
|
|
1322
|
+
*
|
|
1323
|
+
* The reserve floor is the last line of defence against an account being
|
|
1324
|
+
* drained, and it silently does nothing during the cold-start window when
|
|
1325
|
+
* `creditBalances` is still empty: `available()` keeps an account with no
|
|
1326
|
+
* reading in play, deliberately, so an unprobed pool is not stranded. That
|
|
1327
|
+
* default is right for a pool that has never been measured and wrong for one
|
|
1328
|
+
* measured ten seconds before the process restarted — the pool is then
|
|
1329
|
+
* scheduled straight past the floor the user set.
|
|
1330
|
+
*
|
|
1331
|
+
* Observed 2026-10-30: an account with a 20,000 floor and a real 2,869
|
|
1332
|
+
* balance was picked and drained, because the first request after a restart
|
|
1333
|
+
* arrived before any balance reading existed.
|
|
1334
|
+
*
|
|
1335
|
+
* Mirroring the readings closes that window without changing `available()`'s
|
|
1336
|
+
* semantics: it still sees "known" balances, just ones from the previous run.
|
|
1337
|
+
* The alternative — treating unknown as unusable — would turn a transient
|
|
1338
|
+
* credits-endpoint failure into a full outage.
|
|
1339
|
+
*/
|
|
1340
|
+
private creditBalancePath;
|
|
1190
1341
|
/**
|
|
1191
1342
|
* Nearest expiry among each account's one-off credit packs, epoch ms.
|
|
1192
1343
|
*
|
|
@@ -1242,6 +1393,8 @@ export declare class WorkBuddyAccountPool {
|
|
|
1242
1393
|
*/
|
|
1243
1394
|
private lastUsedAt;
|
|
1244
1395
|
private refreshInflight;
|
|
1396
|
+
/** Three-way reconciliation anchor: only advanced after a successful store write. */
|
|
1397
|
+
private persistedCredentials;
|
|
1245
1398
|
/**
|
|
1246
1399
|
* Whether `scan()` seeds from and writes back the durable account store.
|
|
1247
1400
|
*
|
|
@@ -1325,6 +1478,7 @@ export declare class WorkBuddyAccountPool {
|
|
|
1325
1478
|
private pruneExpiredSnapshots;
|
|
1326
1479
|
/** Rescan the auth directories and merge newly discovered accounts. */
|
|
1327
1480
|
scan(): Promise<WorkBuddyAccount[]>;
|
|
1481
|
+
private scanTransaction;
|
|
1328
1482
|
/**
|
|
1329
1483
|
* Warm the deadline readings that `expiry` mode sorts on.
|
|
1330
1484
|
*
|
|
@@ -1378,6 +1532,21 @@ export declare class WorkBuddyAccountPool {
|
|
|
1378
1532
|
* model, e.g. CLI diagnostics).
|
|
1379
1533
|
*/
|
|
1380
1534
|
private available;
|
|
1535
|
+
/**
|
|
1536
|
+
* Whether ANY account can serve this model right now.
|
|
1537
|
+
*
|
|
1538
|
+
* Exposed because the retry loop needs this answer *between* attempts, not
|
|
1539
|
+
* only when it starts one: after penalising the account that just returned
|
|
1540
|
+
* 429, the loop must know whether the next attempt has any chance. Without
|
|
1541
|
+
* it, a per-account rate limit walks the whole pool — each attempt is a
|
|
1542
|
+
* guaranteed 429 that also burns that account's quota for the model, so a
|
|
1543
|
+
* single request can leave every account cooling until the next day.
|
|
1544
|
+
*
|
|
1545
|
+
* `available()` already computes exactly this; it stays private because the
|
|
1546
|
+
* account objects it returns are mutable state the pool owns. This reports
|
|
1547
|
+
* the count only, which is all a caller should act on.
|
|
1548
|
+
*/
|
|
1549
|
+
anyAvailable(modelId?: string, region?: WorkBuddyRegion, reserveExempt?: ReadonlySet<string>): boolean;
|
|
1381
1550
|
/**
|
|
1382
1551
|
* The pool ordered into three bands, so a resting account is deferred instead of
|
|
1383
1552
|
* discarded.
|
|
@@ -1592,6 +1761,16 @@ export declare class WorkBuddyAccountPool {
|
|
|
1592
1761
|
* {@link creditExpiryNone} so the account is not read again on every pass.
|
|
1593
1762
|
*/
|
|
1594
1763
|
noteCredits(accountId: string, balance: number, nearestExpiryMs?: number): void;
|
|
1764
|
+
/**
|
|
1765
|
+
* Restore the balances mirrored by the previous run.
|
|
1766
|
+
*
|
|
1767
|
+
* Best effort by construction: an unreadable or missing file means "first
|
|
1768
|
+
* run", which is exactly the cold start the mirror exists to narrow rather
|
|
1769
|
+
* than to replace — the pool keeps working either way.
|
|
1770
|
+
*/
|
|
1771
|
+
private loadCreditBalances;
|
|
1772
|
+
/** Mirror every known balance, atomically. Never throws. */
|
|
1773
|
+
private saveCreditBalances;
|
|
1595
1774
|
/**
|
|
1596
1775
|
* Record ONLY the deadline, never the balance.
|
|
1597
1776
|
*
|
|
@@ -1770,29 +1949,43 @@ export declare class WorkBuddyAccountPool {
|
|
|
1770
1949
|
* browser card renders. Route paths are plugin-owned and mounted on the Host's
|
|
1771
1950
|
* same-origin web server (see `src/web-status.ts`).
|
|
1772
1951
|
*
|
|
1952
|
+
* ## Why `/dsh-xdpool`, and not `/plugins/dsh-xdpool`
|
|
1953
|
+
*
|
|
1954
|
+
* DSH 0.2.x gives the `/plugins/` namespace to the client-module asset server
|
|
1955
|
+
* (`/plugins/??@scope/pkg/client.js`). That server answers every request under
|
|
1956
|
+
* the prefix before named routes are considered: an unknown asset path is a
|
|
1957
|
+
* bodyless 404 and a non-GET is `405 Allow: GET, HEAD`. Routes this plugin
|
|
1958
|
+
* registered under `/dsh-xdpool/...` were therefore unreachable on that
|
|
1959
|
+
* line — status answered 404, the settings card's rescan answered 405 — while
|
|
1960
|
+
* the plugin logged "routes ... ok" because registration itself succeeded.
|
|
1961
|
+
*
|
|
1962
|
+
* A plugin-owned top-level prefix is what the host's own plugins use
|
|
1963
|
+
* (`/dsh-prompt-optimizer/optimize`), so these paths live under `/dsh-xdpool/`.
|
|
1964
|
+
* Keep them there.
|
|
1965
|
+
*
|
|
1773
1966
|
* @module dsh-xdpool/status-paths
|
|
1774
1967
|
*/
|
|
1775
1968
|
/** Plugin-owned read-only pool status endpoint (account rows + models + shim). */
|
|
1776
|
-
export declare const POOL_STATUS_PATH = "/
|
|
1969
|
+
export declare const POOL_STATUS_PATH = "/dsh-xdpool/status";
|
|
1777
1970
|
/** Plugin-owned local account rescan endpoint (re-read desktop snapshots). */
|
|
1778
|
-
export declare const POOL_RESCAN_PATH = "/
|
|
1971
|
+
export declare const POOL_RESCAN_PATH = "/dsh-xdpool/accounts/rescan";
|
|
1779
1972
|
/** Plugin-owned cooldown reset endpoint (clear all 429 cooldowns). */
|
|
1780
|
-
export declare const POOL_RESET_COOLDOWN_PATH = "/
|
|
1973
|
+
export declare const POOL_RESET_COOLDOWN_PATH = "/dsh-xdpool/cooldowns/reset";
|
|
1781
1974
|
/** Plugin-owned daily check-in action endpoint (claim today's reward). */
|
|
1782
|
-
export declare const POOL_CHECKIN_PATH = "/
|
|
1975
|
+
export declare const POOL_CHECKIN_PATH = "/dsh-xdpool/checkin";
|
|
1783
1976
|
/** Plugin-owned model-selection save endpoint (writes the settings section). */
|
|
1784
|
-
export declare const POOL_MODELS_SAVE_PATH = "/
|
|
1977
|
+
export declare const POOL_MODELS_SAVE_PATH = "/dsh-xdpool/models/save";
|
|
1785
1978
|
/**
|
|
1786
1979
|
* Throw one account out of the pool for good, or take it back.
|
|
1787
1980
|
*
|
|
1788
1981
|
* Separate from the disable route because the semantics differ: disabling is a
|
|
1789
1982
|
* rotation preference the account survives, ignoring survives the account.
|
|
1790
1983
|
*/
|
|
1791
|
-
export declare const POOL_ACCOUNT_IGNORE_PATH = "/
|
|
1984
|
+
export declare const POOL_ACCOUNT_IGNORE_PATH = "/dsh-xdpool/accounts/ignored";
|
|
1792
1985
|
/** Run one automation job immediately, so the card can verify it on demand. */
|
|
1793
|
-
export declare const POOL_AUTOMATION_RUN_PATH = "/
|
|
1986
|
+
export declare const POOL_AUTOMATION_RUN_PATH = "/dsh-xdpool/automation/run";
|
|
1794
1987
|
/** Set or clear one account's reserved-credit floor. */
|
|
1795
|
-
export declare const POOL_CREDIT_RESERVE_PATH = "/
|
|
1988
|
+
export declare const POOL_CREDIT_RESERVE_PATH = "/dsh-xdpool/accounts/credit-reserve";
|
|
1796
1989
|
/**
|
|
1797
1990
|
* One model's facts, exactly as the host's catalogue spells them.
|
|
1798
1991
|
*
|
|
@@ -1913,6 +2106,19 @@ interface PoolWebAggregateProvider {
|
|
|
1913
2106
|
* rows and never put one back.
|
|
1914
2107
|
*/
|
|
1915
2108
|
availableModels: readonly string[];
|
|
2109
|
+
/**
|
|
2110
|
+
* True when the registry declares no models, so the ids are the user's to
|
|
2111
|
+
* type.
|
|
2112
|
+
*
|
|
2113
|
+
* Four records are in that state today: `custom` (a gateway the registry
|
|
2114
|
+
* cannot know about), Azure (ids are per-deployment) and the three local
|
|
2115
|
+
* servers (the ids are whatever the user loaded). None of them can be served
|
|
2116
|
+
* until someone names a model, and none can offer a chooser over a roster
|
|
2117
|
+
* that does not exist — so this flag is what tells the card to draw a text
|
|
2118
|
+
* field instead. The flag travels rather than the id, because the card must
|
|
2119
|
+
* not keep a list of vendor names that mean "empty on purpose".
|
|
2120
|
+
*/
|
|
2121
|
+
manualModels: boolean;
|
|
1916
2122
|
/** True when the exposed set came from a live listing rather than the registry. */
|
|
1917
2123
|
discovered: boolean;
|
|
1918
2124
|
/** When the provider was first configured. */
|
|
@@ -2290,6 +2496,83 @@ interface PoolWebAccount {
|
|
|
2290
2496
|
*/
|
|
2291
2497
|
checkin?: PoolWebCheckin;
|
|
2292
2498
|
checkinError?: string;
|
|
2499
|
+
/**
|
|
2500
|
+
* Per-task claim state for this account, read-only.
|
|
2501
|
+
*
|
|
2502
|
+
* Exists because `automationToday` answers "how much did it earn" but not the
|
|
2503
|
+
* question a person actually asks: WHICH rewards are still sitting there. The
|
|
2504
|
+
* two are different in a way that matters — a pass can report
|
|
2505
|
+
* `claimed: 0 / credit: 0` (nothing left to take) while the board still shows
|
|
2506
|
+
* unclaimed rows, and it can report a healthy `claimed: 5` while six tasks
|
|
2507
|
+
* have never progressed. Neither number says which.
|
|
2508
|
+
*
|
|
2509
|
+
* Absent when the board could not be read, so the card stays quiet rather than
|
|
2510
|
+
* drawing an empty list that reads like "you have nothing".
|
|
2511
|
+
*/
|
|
2512
|
+
tasks?: PoolWebTaskBoard;
|
|
2513
|
+
tasksError?: string;
|
|
2514
|
+
}
|
|
2515
|
+
/**
|
|
2516
|
+
* One task on the growth board, as the card shows it.
|
|
2517
|
+
*
|
|
2518
|
+
* The states are the upstream's own vocabulary, collapsed to the three a person
|
|
2519
|
+
* can act on:
|
|
2520
|
+
*
|
|
2521
|
+
* - `claimed` — reward collected; nothing to do.
|
|
2522
|
+
* - `claimable` — progress met, reward NOT yet collected. This is the only
|
|
2523
|
+
* state where the automation has work left, so it is the one
|
|
2524
|
+
* worth surfacing loudest.
|
|
2525
|
+
* - `locked` — upstream marked it unreachable right now.
|
|
2526
|
+
* - `todo` — accepted and still short of its target. Some of these the
|
|
2527
|
+
* automation can finish (it drives the expert/chat tasks);
|
|
2528
|
+
* some it cannot (`wb_wechat_oa_subscribe_task` needs a human
|
|
2529
|
+
* to follow an official account), which is why `automatable`
|
|
2530
|
+
* is carried separately rather than folded into the state.
|
|
2531
|
+
*/
|
|
2532
|
+
interface PoolWebTask {
|
|
2533
|
+
/** Upstream task code; the card's stable key. */
|
|
2534
|
+
code: string;
|
|
2535
|
+
/** Human title from the board, already localised upstream. */
|
|
2536
|
+
title: string;
|
|
2537
|
+
/** Credits this task pays when collected. */
|
|
2538
|
+
credit: number;
|
|
2539
|
+
/** `current`/`target` progress, for the "0/1" the board itself prints. */
|
|
2540
|
+
current: number;
|
|
2541
|
+
target: number;
|
|
2542
|
+
/** One of `claimed` / `claimable` / `todo` / `locked`. */
|
|
2543
|
+
state: PoolWebTaskState;
|
|
2544
|
+
/**
|
|
2545
|
+
* Whether the automation has a chain that can score this task.
|
|
2546
|
+
*
|
|
2547
|
+
* A `todo` task with `automatable: false` will never move on its own — that is
|
|
2548
|
+
* the honest distinction between "it hasn't run yet" and "it will never".
|
|
2549
|
+
*/
|
|
2550
|
+
automatable: boolean;
|
|
2551
|
+
}
|
|
2552
|
+
type PoolWebTaskState = 'claimed' | 'claimable' | 'todo' | 'locked';
|
|
2553
|
+
/**
|
|
2554
|
+
* Per-account totals derived from the task board.
|
|
2555
|
+
*
|
|
2556
|
+
* Counts rather than just a credit sum, because "3 of 19 still unclaimed" is
|
|
2557
|
+
* the actionable fact and "1600 credits" is not.
|
|
2558
|
+
*/
|
|
2559
|
+
interface PoolWebTaskBoard {
|
|
2560
|
+
/** Tasks whose reward is already collected. */
|
|
2561
|
+
claimed: number;
|
|
2562
|
+
/** Tasks with progress met but reward outstanding — the automation's queue. */
|
|
2563
|
+
claimable: number;
|
|
2564
|
+
/** Tasks accepted and still short of target. */
|
|
2565
|
+
todo: number;
|
|
2566
|
+
/** Tasks the upstream reports as unreachable. */
|
|
2567
|
+
locked: number;
|
|
2568
|
+
/** Total rows on the board. */
|
|
2569
|
+
total: number;
|
|
2570
|
+
/** Credits still collectable (`claimable` rows only). */
|
|
2571
|
+
claimableCredit: number;
|
|
2572
|
+
/** Credits already collected on the board. */
|
|
2573
|
+
claimedCredit: number;
|
|
2574
|
+
/** The rows themselves, in board order. */
|
|
2575
|
+
rows: readonly PoolWebTask[];
|
|
2293
2576
|
}
|
|
2294
2577
|
/** One credit package (as surfaced by the pool's upstream client), node-free. */
|
|
2295
2578
|
interface PoolWebCreditPackage {
|
|
@@ -2995,6 +3278,48 @@ interface HostModelRow {
|
|
|
2995
3278
|
channel: string;
|
|
2996
3279
|
modelId: string;
|
|
2997
3280
|
name: string;
|
|
3281
|
+
/**
|
|
3282
|
+
* What the host's own model picker would enforce for this row.
|
|
3283
|
+
*
|
|
3284
|
+
* The host's LISTING publishes neither the window nor the modalities (its
|
|
3285
|
+
* mapper keeps four fields), but `resolveModelInfo(channel, model)` answers
|
|
3286
|
+
* both, and that is where the picker and the compaction planner read them
|
|
3287
|
+
* from. Optional on purpose: a channel whose catalogue is a bare id list
|
|
3288
|
+
* cannot describe a row, and the chain then has to fall back to the
|
|
3289
|
+
* documented defaults rather than invent a capacity.
|
|
3290
|
+
*/
|
|
3291
|
+
contextWindow?: number;
|
|
3292
|
+
maxOutputTokens?: number;
|
|
3293
|
+
/** Modalities in the host's own vocabulary, e.g. `['text', 'image']`. */
|
|
3294
|
+
inputModalities?: readonly string[];
|
|
3295
|
+
}
|
|
3296
|
+
//#endregion
|
|
3297
|
+
//#region src/group-routing.d.ts
|
|
3298
|
+
/** 可插拔策略名。smart=额度优先(最早过期先用),ordered=按成员顺序。 */
|
|
3299
|
+
declare const GROUP_STRATEGIES: readonly ['smart', 'ordered', 'round-robin', 'cheapest', 'free-first'];
|
|
3300
|
+
type GroupStrategy = (typeof GROUP_STRATEGIES)[number];
|
|
3301
|
+
/** 一个路由组的落盘结构。 */
|
|
3302
|
+
interface GroupSetting {
|
|
3303
|
+
/** 稳定 id;对外虚拟模型是 `group:<id>`。 */
|
|
3304
|
+
id: string;
|
|
3305
|
+
name: string;
|
|
3306
|
+
note?: string;
|
|
3307
|
+
/** 有序成员串:`provider/model[:effort][#account]` 或 `group:<id>`。 */
|
|
3308
|
+
members: readonly string[];
|
|
3309
|
+
/** 策略;缺省 smart。 */
|
|
3310
|
+
strategy?: GroupStrategy;
|
|
3311
|
+
/** 关掉的成员(保留位置),便于 A/B。 */
|
|
3312
|
+
off?: readonly string[];
|
|
3313
|
+
/** 手动模式当前指定的成员。 */
|
|
3314
|
+
pick?: string;
|
|
3315
|
+
/** 整组开关;显式 false 才关。 */
|
|
3316
|
+
enabled?: boolean;
|
|
3317
|
+
/** 自动发现组:保存改动即接管(Seen/Hidden 语义留给 B4 存储层)。 */
|
|
3318
|
+
auto?: boolean;
|
|
3319
|
+
/** 用户删掉的自动组。 */
|
|
3320
|
+
hidden?: boolean;
|
|
3321
|
+
/** 接管时见过的成员,用于增量合并新来的 provider。 */
|
|
3322
|
+
seen?: readonly string[];
|
|
2998
3323
|
}
|
|
2999
3324
|
//#endregion
|
|
3000
3325
|
//#region src/store.d.ts
|
|
@@ -3011,6 +3336,8 @@ interface HostModelRow {
|
|
|
3011
3336
|
*/
|
|
3012
3337
|
type AggregateStore = AggregateSettings & {
|
|
3013
3338
|
combos?: readonly ComboSetting[];
|
|
3339
|
+
/** 路由组(阶段 B4):与 combos 同一份文档,删一个文件即可全部撤销。 */
|
|
3340
|
+
groups?: readonly GroupSetting[];
|
|
3014
3341
|
relay?: RelaySetting;
|
|
3015
3342
|
};
|
|
3016
3343
|
/**
|
|
@@ -3437,9 +3764,133 @@ interface ChannelLane {
|
|
|
3437
3764
|
modelId: string;
|
|
3438
3765
|
body: Record<string, unknown>;
|
|
3439
3766
|
signal: AbortSignal;
|
|
3767
|
+
/**
|
|
3768
|
+
* The DSH Session this turn belongs to, when the caller knows it.
|
|
3769
|
+
*
|
|
3770
|
+
* Forwarded onto the host call as `sessionId`. The host's own `LlmAdapter`
|
|
3771
|
+
* seam already carries that field (`GenerateOptions.sessionId`), and dropping
|
|
3772
|
+
* it here was the reason a channel model's turn could not be attributed to
|
|
3773
|
+
* the conversation that caused it: the pool lanes get the id from pi-ai's
|
|
3774
|
+
* affinity header, and this lane — which rebuilds the request by hand — has
|
|
3775
|
+
* to pass it explicitly.
|
|
3776
|
+
*/
|
|
3777
|
+
sessionId?: string | undefined;
|
|
3440
3778
|
}) => AsyncGenerator<ChannelLaneEvent>;
|
|
3441
3779
|
}
|
|
3442
3780
|
//#endregion
|
|
3781
|
+
//#region src/session-route.d.ts
|
|
3782
|
+
/**
|
|
3783
|
+
* 「这个会话现在是走哪家、用哪个号」——一张会话 id 到归属的小表。
|
|
3784
|
+
*
|
|
3785
|
+
* WHY THIS IS A SEPARATE MODULE
|
|
3786
|
+
*
|
|
3787
|
+
* The usage ledger (`stats.ts`) already records which channel and which account
|
|
3788
|
+
* served every physical call. It cannot answer this question, for a reason that
|
|
3789
|
+
* is structural rather than a bug: it files calls under a `turnId` minted per
|
|
3790
|
+
* request, and it keeps a bounded ring of samples that a busy session flushes
|
|
3791
|
+
* out. "Which account is this conversation on" is a question about the CURRENT
|
|
3792
|
+
* state of one conversation, not about the last 2000 calls.
|
|
3793
|
+
*
|
|
3794
|
+
* The identity that makes it answerable exists: `GenerateOptions.sessionId` is
|
|
3795
|
+
* the DSH Session id, and pi-ai turns it into session-affinity headers on the
|
|
3796
|
+
* wire. So a lane that receives a request can say, at the moment it serves it,
|
|
3797
|
+
* "session X is on channel C, account A". This module holds exactly that fact
|
|
3798
|
+
* and nothing else.
|
|
3799
|
+
*
|
|
3800
|
+
* WHAT IT DELIBERATELY DOES NOT HOLD
|
|
3801
|
+
*
|
|
3802
|
+
* No prompts, no message text, no token counts. A conversation id mapped to a
|
|
3803
|
+
* vendor and an account label is what the reader asked for; copying the rest
|
|
3804
|
+
* would turn a status readout into a second copy of the transcript.
|
|
3805
|
+
*
|
|
3806
|
+
* BOUNDED ON PURPOSE
|
|
3807
|
+
*
|
|
3808
|
+
* One entry per live conversation is small, but sessions accumulate. The map is
|
|
3809
|
+
* an LRU with a fixed ceiling, so a long-running host cannot grow it without
|
|
3810
|
+
* limit. An evicted session simply reads as "unknown" until its next call
|
|
3811
|
+
* repopulates it, which is the honest state rather than a stale guess.
|
|
3812
|
+
*
|
|
3813
|
+
* @module dsh-xdpool/session-route
|
|
3814
|
+
*/
|
|
3815
|
+
/** One conversation's current归属, as the serving lane last saw it. */
|
|
3816
|
+
interface SessionRoute {
|
|
3817
|
+
/** The DSH Session id this describes. */
|
|
3818
|
+
sessionId: string;
|
|
3819
|
+
/**
|
|
3820
|
+
* The channel that served it.
|
|
3821
|
+
*
|
|
3822
|
+
* `workbuddy` for the pooled WorkBuddy lanes, `free` for the keyless lane, or
|
|
3823
|
+
* a provider / channel id (a third-party vendor or a sign-in channel).
|
|
3824
|
+
*/
|
|
3825
|
+
channel: string;
|
|
3826
|
+
/** Gateway region for the pooled lanes: `cn`, `global`, or empty elsewhere. */
|
|
3827
|
+
region: string;
|
|
3828
|
+
/** The model id the last call asked for. */
|
|
3829
|
+
model: string;
|
|
3830
|
+
/**
|
|
3831
|
+
* Display label of the account that served it, or `''` when the lane cannot
|
|
3832
|
+
* name one.
|
|
3833
|
+
*
|
|
3834
|
+
* Empty is a real answer, not a missing one: a sign-in channel's account is
|
|
3835
|
+
* chosen inside the host's adapter, which does not report it back, so the
|
|
3836
|
+
* honest value is "the channel picked one of its own". Inventing a label
|
|
3837
|
+
* would put a name on screen that nobody verified.
|
|
3838
|
+
*/
|
|
3839
|
+
account: string;
|
|
3840
|
+
/** When this route was last confirmed by an answered call, in epoch ms. */
|
|
3841
|
+
at: number;
|
|
3842
|
+
}
|
|
3843
|
+
/**
|
|
3844
|
+
* A bounded, most-recent-wins map of conversation → serving route.
|
|
3845
|
+
*
|
|
3846
|
+
* Reads are cheap and synchronous because the HTTP route that serves the panel
|
|
3847
|
+
* is answering a poll that runs while a turn streams; an async read here would
|
|
3848
|
+
* make the panel lag the call it is describing.
|
|
3849
|
+
*/
|
|
3850
|
+
declare class SessionRouteBook {
|
|
3851
|
+
private readonly routes;
|
|
3852
|
+
/**
|
|
3853
|
+
* 会话 → 强制指定的账号 id。
|
|
3854
|
+
*
|
|
3855
|
+
* 只存 id 字符串,不碰凭据:这是用户「这个会话就用这个号」的选择,不是号的
|
|
3856
|
+
* 登录态。账号被删掉、被换掉、冷却、被关掉时 pin 都照旧留着 —— 选号时若这个
|
|
3857
|
+
* id 不可用就 fail-open 回退普通选号,而不是让会话卡死(见 shim 的
|
|
3858
|
+
* `acquireForRequest`)。和 `routes` 一样是 LRU,共用 SESSION_ROUTE_LIMIT,
|
|
3859
|
+
* 因为一个长期运行的宿主不能让「指定过一次」的记录无限长地留下去。
|
|
3860
|
+
*/
|
|
3861
|
+
private readonly pins;
|
|
3862
|
+
private readonly limit;
|
|
3863
|
+
constructor(limit?: number);
|
|
3864
|
+
/**
|
|
3865
|
+
* Remember which route served one session.
|
|
3866
|
+
*
|
|
3867
|
+
* Re-inserting also refreshes LRU position: a conversation that just spoke is
|
|
3868
|
+
* the one most likely to be read next.
|
|
3869
|
+
*/
|
|
3870
|
+
record(route: SessionRoute): void;
|
|
3871
|
+
/** The current route for one conversation, or undefined when unknown. */
|
|
3872
|
+
of(sessionId: string | undefined): SessionRoute | undefined;
|
|
3873
|
+
/** Every retained route, most recently confirmed last. */
|
|
3874
|
+
list(): readonly SessionRoute[];
|
|
3875
|
+
/** Conversations currently retained. */
|
|
3876
|
+
size(): number;
|
|
3877
|
+
/**
|
|
3878
|
+
* 强制这个会话使用某个账号。
|
|
3879
|
+
*
|
|
3880
|
+
* 会话 id 与账号 id 都按 id 的规则校验:前者来自请求参数,后者来自 body,
|
|
3881
|
+
* 放任意文本进来只会让面板显示一段没人验证过的字。账号 id 只按形状验,
|
|
3882
|
+
* 不查它是否真的存在 —— 池子会在之后 rescan,pin 一个「还不在」的号应当
|
|
3883
|
+
* 在它出现后自动生效。重复 pin 同一个号会刷新 LRU 位置。
|
|
3884
|
+
*/
|
|
3885
|
+
pin(sessionId: string | undefined, accountId: string | undefined): void;
|
|
3886
|
+
/** 取消指定。未知会话也是空操作,不报错。 */
|
|
3887
|
+
unpin(sessionId: string | undefined): void;
|
|
3888
|
+
/** 这个会话被指定用哪个号;没有就是 undefined(不是空字符串)。 */
|
|
3889
|
+
pinned(sessionId: string | undefined): string | undefined;
|
|
3890
|
+
/** Forget everything. Used by reset paths and by tests. */
|
|
3891
|
+
clear(): void;
|
|
3892
|
+
}
|
|
3893
|
+
//#endregion
|
|
3443
3894
|
//#region src/shim.d.ts
|
|
3444
3895
|
interface ShimLogger {
|
|
3445
3896
|
info?(...args: unknown[]): void;
|
|
@@ -3597,6 +4048,15 @@ interface WorkBuddyShimOptions {
|
|
|
3597
4048
|
* for other machines.
|
|
3598
4049
|
*/
|
|
3599
4050
|
lanModels?: () => readonly string[] | undefined;
|
|
4051
|
+
/**
|
|
4052
|
+
* Where one conversation's serving route is remembered.
|
|
4053
|
+
*
|
|
4054
|
+
* Optional like `usageRecorder`, and for the same reason: the CLI and the
|
|
4055
|
+
* tests run a shim with no panel, and threading an argument nobody reads would
|
|
4056
|
+
* only be noise. When absent, nothing about a request's behaviour changes —
|
|
4057
|
+
* only the readout the composer chip draws is missing.
|
|
4058
|
+
*/
|
|
4059
|
+
sessionRoutes?: SessionRouteBook;
|
|
3600
4060
|
}
|
|
3601
4061
|
export declare function createWorkBuddyShim(options: WorkBuddyShimOptions): WorkBuddyShim;
|
|
3602
4062
|
//#endregion
|
|
@@ -4092,18 +4552,43 @@ export declare class WorkBuddyScheduler {
|
|
|
4092
4552
|
* report would have moved. This is what the card's single button calls.
|
|
4093
4553
|
*/
|
|
4094
4554
|
/**
|
|
4095
|
-
* Start a
|
|
4555
|
+
* Start a pass in the background and return immediately.
|
|
4096
4556
|
*
|
|
4097
4557
|
* A pass takes tens of seconds - one upstream round trip per account per job,
|
|
4098
4558
|
* plus the scoring wait - which is far too long to hold the card request open:
|
|
4099
4559
|
* the browser or the host web server would time out, and the user would see
|
|
4100
4560
|
* a hung button for a run that is actually working.
|
|
4101
4561
|
*
|
|
4562
|
+
* `job` names ONE job (the card's per-job button) or `'all'` for the ordered
|
|
4563
|
+
* full pass; anything else is treated as `'all'` by the caller's validation,
|
|
4564
|
+
* not here. `force` bypasses the already-ran-today guard for a single job,
|
|
4565
|
+
* which is what "run it now anyway" means.
|
|
4566
|
+
*
|
|
4102
4567
|
* Returns whether a run started. A second call while one is in flight is
|
|
4103
4568
|
* ignored rather than queued: pressing the button twice means hurry up, and
|
|
4104
4569
|
* the run already under way covers it.
|
|
4105
4570
|
*/
|
|
4106
4571
|
startRunAll(): boolean;
|
|
4572
|
+
/**
|
|
4573
|
+
* Start one job — or the whole pass — in the background.
|
|
4574
|
+
*
|
|
4575
|
+
* The card's automation row names a job, and `force` is what a second press
|
|
4576
|
+
* within the same hour means. Both used to be dropped on the floor by the
|
|
4577
|
+
* route wiring, so "run check-in" ran every job and a repeat press inside the
|
|
4578
|
+
* hour silently did nothing. A single-job start goes through the same
|
|
4579
|
+
* in-flight guard as a full pass: overlapping passes would double-spend the
|
|
4580
|
+
* per-account delays and interleave two runs into one status document.
|
|
4581
|
+
*/
|
|
4582
|
+
startRun(kind: 'all' | AutomationJobKind, force?: boolean): boolean;
|
|
4583
|
+
/**
|
|
4584
|
+
* issue #222:启动一个指定 job 的后台运行,供「立即执行」按任务调用。
|
|
4585
|
+
*
|
|
4586
|
+
* 和 `startRunAll` 一样立刻返回(跑一轮要几十秒,不能挂在卡片请求上),
|
|
4587
|
+
* 也复用同一把 `runInFlight` 锁:同时检查 `busy`,避免手动单任务和定时 tick
|
|
4588
|
+
* 并发跑同一批账号(共享 ledger 的 read-modify-write 不是原子的)。
|
|
4589
|
+
* `force` 交给 `runNow`,让它跳过同小时的节流。
|
|
4590
|
+
*/
|
|
4591
|
+
startRunNow(kind: AutomationJobKind, force?: boolean): boolean;
|
|
4107
4592
|
runAll(): Promise<AutomationRunSummary>;
|
|
4108
4593
|
status(): AutomationStatus;
|
|
4109
4594
|
/**
|
|
@@ -4703,6 +5188,15 @@ interface PoolStatusRouteOptions {
|
|
|
4703
5188
|
* document. The catalog refresh is what makes a new chain pickable at once.
|
|
4704
5189
|
*/
|
|
4705
5190
|
saveCombos?: (raw: unknown) => Promise<PoolWebCombosStatus>;
|
|
5191
|
+
/** 路由组文档与保存(阶段 B4-4):与 combos 同构,写后由 catalog.refresh 立刻生效。 */
|
|
5192
|
+
groupsDocument?: () => {
|
|
5193
|
+
groups: readonly unknown[];
|
|
5194
|
+
} | Promise<{
|
|
5195
|
+
groups: readonly unknown[];
|
|
5196
|
+
}>;
|
|
5197
|
+
saveGroups?: (raw: unknown) => Promise<{
|
|
5198
|
+
groups: readonly unknown[];
|
|
5199
|
+
}>;
|
|
4706
5200
|
/**
|
|
4707
5201
|
* Estimated credit spend per channel and model, for the composer strip.
|
|
4708
5202
|
*
|
|
@@ -4712,6 +5206,10 @@ interface PoolStatusRouteOptions {
|
|
|
4712
5206
|
* own cadence.
|
|
4713
5207
|
*/
|
|
4714
5208
|
creditsSpend?: (days: number | undefined) => Promise<unknown>;
|
|
5209
|
+
/** Credits actually spent today, measured by the cost meter. */
|
|
5210
|
+
creditsToday?: () => Promise<unknown>;
|
|
5211
|
+
/** Cached credit history for the dashboard; `refresh=1` bypasses the cache. */
|
|
5212
|
+
spendReport?: (days: number | undefined, refresh: boolean) => Promise<unknown>;
|
|
4715
5213
|
/**
|
|
4716
5214
|
* The relay's current state, or undefined when this build has no relay.
|
|
4717
5215
|
*
|
|
@@ -4724,11 +5222,6 @@ interface PoolStatusRouteOptions {
|
|
|
4724
5222
|
/** Apply a relay patch, re-evaluate the listener, and answer with the new state. */
|
|
4725
5223
|
saveRelay?: (patch: PoolWebRelayPatch) => Promise<PoolWebRelayStatus>;
|
|
4726
5224
|
}
|
|
4727
|
-
/**
|
|
4728
|
-
* Assemble the card's status document. Per-account credits and check-in state
|
|
4729
|
-
* are queried live; a failing query degrades to `creditsError` / `checkinError`
|
|
4730
|
-
* rather than failing the whole document. Never throws.
|
|
4731
|
-
*/
|
|
4732
5225
|
export declare function poolWebStatus(deps: PoolStatusRouteOptions, region?: PoolRegion): Promise<PoolWebStatus>;
|
|
4733
5226
|
/**
|
|
4734
5227
|
* Mount the read-only routes on a context where `webServer` is available. The
|