dsh-xdpool 3.0.7 → 3.0.8
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 +2432 -2361
- package/LICENSE +21 -21
- package/README.en.md +308 -308
- package/README.md +12 -1
- package/cordis.patch.yml +24 -24
- package/lib/bin.js +699 -32
- package/lib/client.js +1125 -135
- package/lib/index.d.ts +468 -7
- package/lib/index.js +5392 -478
- package/package.json +1 -1
- package/screenshots.json +9 -9
- package/scripts/extract-design-css.mjs +322 -322
- package/scripts/link-host-peers.mjs +359 -359
- package/scripts/make-rail-icons.mjs +46 -46
- package/scripts/probe-channels.mjs +142 -142
- package/vendor/channel-pack/LICENSE +21 -21
- package/vendor/channel-pack/NOTICE.md +53 -53
- package/vendor/channel-pack/pack.js +243 -45
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
|
*
|
|
@@ -1378,6 +1529,21 @@ export declare class WorkBuddyAccountPool {
|
|
|
1378
1529
|
* model, e.g. CLI diagnostics).
|
|
1379
1530
|
*/
|
|
1380
1531
|
private available;
|
|
1532
|
+
/**
|
|
1533
|
+
* Whether ANY account can serve this model right now.
|
|
1534
|
+
*
|
|
1535
|
+
* Exposed because the retry loop needs this answer *between* attempts, not
|
|
1536
|
+
* only when it starts one: after penalising the account that just returned
|
|
1537
|
+
* 429, the loop must know whether the next attempt has any chance. Without
|
|
1538
|
+
* it, a per-account rate limit walks the whole pool — each attempt is a
|
|
1539
|
+
* guaranteed 429 that also burns that account's quota for the model, so a
|
|
1540
|
+
* single request can leave every account cooling until the next day.
|
|
1541
|
+
*
|
|
1542
|
+
* `available()` already computes exactly this; it stays private because the
|
|
1543
|
+
* account objects it returns are mutable state the pool owns. This reports
|
|
1544
|
+
* the count only, which is all a caller should act on.
|
|
1545
|
+
*/
|
|
1546
|
+
anyAvailable(modelId?: string, region?: WorkBuddyRegion, reserveExempt?: ReadonlySet<string>): boolean;
|
|
1381
1547
|
/**
|
|
1382
1548
|
* The pool ordered into three bands, so a resting account is deferred instead of
|
|
1383
1549
|
* discarded.
|
|
@@ -1592,6 +1758,16 @@ export declare class WorkBuddyAccountPool {
|
|
|
1592
1758
|
* {@link creditExpiryNone} so the account is not read again on every pass.
|
|
1593
1759
|
*/
|
|
1594
1760
|
noteCredits(accountId: string, balance: number, nearestExpiryMs?: number): void;
|
|
1761
|
+
/**
|
|
1762
|
+
* Restore the balances mirrored by the previous run.
|
|
1763
|
+
*
|
|
1764
|
+
* Best effort by construction: an unreadable or missing file means "first
|
|
1765
|
+
* run", which is exactly the cold start the mirror exists to narrow rather
|
|
1766
|
+
* than to replace — the pool keeps working either way.
|
|
1767
|
+
*/
|
|
1768
|
+
private loadCreditBalances;
|
|
1769
|
+
/** Mirror every known balance, atomically. Never throws. */
|
|
1770
|
+
private saveCreditBalances;
|
|
1595
1771
|
/**
|
|
1596
1772
|
* Record ONLY the deadline, never the balance.
|
|
1597
1773
|
*
|
|
@@ -1913,6 +2089,19 @@ interface PoolWebAggregateProvider {
|
|
|
1913
2089
|
* rows and never put one back.
|
|
1914
2090
|
*/
|
|
1915
2091
|
availableModels: readonly string[];
|
|
2092
|
+
/**
|
|
2093
|
+
* True when the registry declares no models, so the ids are the user's to
|
|
2094
|
+
* type.
|
|
2095
|
+
*
|
|
2096
|
+
* Four records are in that state today: `custom` (a gateway the registry
|
|
2097
|
+
* cannot know about), Azure (ids are per-deployment) and the three local
|
|
2098
|
+
* servers (the ids are whatever the user loaded). None of them can be served
|
|
2099
|
+
* until someone names a model, and none can offer a chooser over a roster
|
|
2100
|
+
* that does not exist — so this flag is what tells the card to draw a text
|
|
2101
|
+
* field instead. The flag travels rather than the id, because the card must
|
|
2102
|
+
* not keep a list of vendor names that mean "empty on purpose".
|
|
2103
|
+
*/
|
|
2104
|
+
manualModels: boolean;
|
|
1916
2105
|
/** True when the exposed set came from a live listing rather than the registry. */
|
|
1917
2106
|
discovered: boolean;
|
|
1918
2107
|
/** When the provider was first configured. */
|
|
@@ -2290,6 +2479,83 @@ interface PoolWebAccount {
|
|
|
2290
2479
|
*/
|
|
2291
2480
|
checkin?: PoolWebCheckin;
|
|
2292
2481
|
checkinError?: string;
|
|
2482
|
+
/**
|
|
2483
|
+
* Per-task claim state for this account, read-only.
|
|
2484
|
+
*
|
|
2485
|
+
* Exists because `automationToday` answers "how much did it earn" but not the
|
|
2486
|
+
* question a person actually asks: WHICH rewards are still sitting there. The
|
|
2487
|
+
* two are different in a way that matters — a pass can report
|
|
2488
|
+
* `claimed: 0 / credit: 0` (nothing left to take) while the board still shows
|
|
2489
|
+
* unclaimed rows, and it can report a healthy `claimed: 5` while six tasks
|
|
2490
|
+
* have never progressed. Neither number says which.
|
|
2491
|
+
*
|
|
2492
|
+
* Absent when the board could not be read, so the card stays quiet rather than
|
|
2493
|
+
* drawing an empty list that reads like "you have nothing".
|
|
2494
|
+
*/
|
|
2495
|
+
tasks?: PoolWebTaskBoard;
|
|
2496
|
+
tasksError?: string;
|
|
2497
|
+
}
|
|
2498
|
+
/**
|
|
2499
|
+
* One task on the growth board, as the card shows it.
|
|
2500
|
+
*
|
|
2501
|
+
* The states are the upstream's own vocabulary, collapsed to the three a person
|
|
2502
|
+
* can act on:
|
|
2503
|
+
*
|
|
2504
|
+
* - `claimed` — reward collected; nothing to do.
|
|
2505
|
+
* - `claimable` — progress met, reward NOT yet collected. This is the only
|
|
2506
|
+
* state where the automation has work left, so it is the one
|
|
2507
|
+
* worth surfacing loudest.
|
|
2508
|
+
* - `locked` — upstream marked it unreachable right now.
|
|
2509
|
+
* - `todo` — accepted and still short of its target. Some of these the
|
|
2510
|
+
* automation can finish (it drives the expert/chat tasks);
|
|
2511
|
+
* some it cannot (`wb_wechat_oa_subscribe_task` needs a human
|
|
2512
|
+
* to follow an official account), which is why `automatable`
|
|
2513
|
+
* is carried separately rather than folded into the state.
|
|
2514
|
+
*/
|
|
2515
|
+
interface PoolWebTask {
|
|
2516
|
+
/** Upstream task code; the card's stable key. */
|
|
2517
|
+
code: string;
|
|
2518
|
+
/** Human title from the board, already localised upstream. */
|
|
2519
|
+
title: string;
|
|
2520
|
+
/** Credits this task pays when collected. */
|
|
2521
|
+
credit: number;
|
|
2522
|
+
/** `current`/`target` progress, for the "0/1" the board itself prints. */
|
|
2523
|
+
current: number;
|
|
2524
|
+
target: number;
|
|
2525
|
+
/** One of `claimed` / `claimable` / `todo` / `locked`. */
|
|
2526
|
+
state: PoolWebTaskState;
|
|
2527
|
+
/**
|
|
2528
|
+
* Whether the automation has a chain that can score this task.
|
|
2529
|
+
*
|
|
2530
|
+
* A `todo` task with `automatable: false` will never move on its own — that is
|
|
2531
|
+
* the honest distinction between "it hasn't run yet" and "it will never".
|
|
2532
|
+
*/
|
|
2533
|
+
automatable: boolean;
|
|
2534
|
+
}
|
|
2535
|
+
type PoolWebTaskState = 'claimed' | 'claimable' | 'todo' | 'locked';
|
|
2536
|
+
/**
|
|
2537
|
+
* Per-account totals derived from the task board.
|
|
2538
|
+
*
|
|
2539
|
+
* Counts rather than just a credit sum, because "3 of 19 still unclaimed" is
|
|
2540
|
+
* the actionable fact and "1600 credits" is not.
|
|
2541
|
+
*/
|
|
2542
|
+
interface PoolWebTaskBoard {
|
|
2543
|
+
/** Tasks whose reward is already collected. */
|
|
2544
|
+
claimed: number;
|
|
2545
|
+
/** Tasks with progress met but reward outstanding — the automation's queue. */
|
|
2546
|
+
claimable: number;
|
|
2547
|
+
/** Tasks accepted and still short of target. */
|
|
2548
|
+
todo: number;
|
|
2549
|
+
/** Tasks the upstream reports as unreachable. */
|
|
2550
|
+
locked: number;
|
|
2551
|
+
/** Total rows on the board. */
|
|
2552
|
+
total: number;
|
|
2553
|
+
/** Credits still collectable (`claimable` rows only). */
|
|
2554
|
+
claimableCredit: number;
|
|
2555
|
+
/** Credits already collected on the board. */
|
|
2556
|
+
claimedCredit: number;
|
|
2557
|
+
/** The rows themselves, in board order. */
|
|
2558
|
+
rows: readonly PoolWebTask[];
|
|
2293
2559
|
}
|
|
2294
2560
|
/** One credit package (as surfaced by the pool's upstream client), node-free. */
|
|
2295
2561
|
interface PoolWebCreditPackage {
|
|
@@ -2995,6 +3261,48 @@ interface HostModelRow {
|
|
|
2995
3261
|
channel: string;
|
|
2996
3262
|
modelId: string;
|
|
2997
3263
|
name: string;
|
|
3264
|
+
/**
|
|
3265
|
+
* What the host's own model picker would enforce for this row.
|
|
3266
|
+
*
|
|
3267
|
+
* The host's LISTING publishes neither the window nor the modalities (its
|
|
3268
|
+
* mapper keeps four fields), but `resolveModelInfo(channel, model)` answers
|
|
3269
|
+
* both, and that is where the picker and the compaction planner read them
|
|
3270
|
+
* from. Optional on purpose: a channel whose catalogue is a bare id list
|
|
3271
|
+
* cannot describe a row, and the chain then has to fall back to the
|
|
3272
|
+
* documented defaults rather than invent a capacity.
|
|
3273
|
+
*/
|
|
3274
|
+
contextWindow?: number;
|
|
3275
|
+
maxOutputTokens?: number;
|
|
3276
|
+
/** Modalities in the host's own vocabulary, e.g. `['text', 'image']`. */
|
|
3277
|
+
inputModalities?: readonly string[];
|
|
3278
|
+
}
|
|
3279
|
+
//#endregion
|
|
3280
|
+
//#region src/group-routing.d.ts
|
|
3281
|
+
/** 可插拔策略名。smart=额度优先(最早过期先用),ordered=按成员顺序。 */
|
|
3282
|
+
declare const GROUP_STRATEGIES: readonly ['smart', 'ordered', 'round-robin', 'cheapest', 'free-first'];
|
|
3283
|
+
type GroupStrategy = (typeof GROUP_STRATEGIES)[number];
|
|
3284
|
+
/** 一个路由组的落盘结构。 */
|
|
3285
|
+
interface GroupSetting {
|
|
3286
|
+
/** 稳定 id;对外虚拟模型是 `group:<id>`。 */
|
|
3287
|
+
id: string;
|
|
3288
|
+
name: string;
|
|
3289
|
+
note?: string;
|
|
3290
|
+
/** 有序成员串:`provider/model[:effort][#account]` 或 `group:<id>`。 */
|
|
3291
|
+
members: readonly string[];
|
|
3292
|
+
/** 策略;缺省 smart。 */
|
|
3293
|
+
strategy?: GroupStrategy;
|
|
3294
|
+
/** 关掉的成员(保留位置),便于 A/B。 */
|
|
3295
|
+
off?: readonly string[];
|
|
3296
|
+
/** 手动模式当前指定的成员。 */
|
|
3297
|
+
pick?: string;
|
|
3298
|
+
/** 整组开关;显式 false 才关。 */
|
|
3299
|
+
enabled?: boolean;
|
|
3300
|
+
/** 自动发现组:保存改动即接管(Seen/Hidden 语义留给 B4 存储层)。 */
|
|
3301
|
+
auto?: boolean;
|
|
3302
|
+
/** 用户删掉的自动组。 */
|
|
3303
|
+
hidden?: boolean;
|
|
3304
|
+
/** 接管时见过的成员,用于增量合并新来的 provider。 */
|
|
3305
|
+
seen?: readonly string[];
|
|
2998
3306
|
}
|
|
2999
3307
|
//#endregion
|
|
3000
3308
|
//#region src/store.d.ts
|
|
@@ -3011,6 +3319,8 @@ interface HostModelRow {
|
|
|
3011
3319
|
*/
|
|
3012
3320
|
type AggregateStore = AggregateSettings & {
|
|
3013
3321
|
combos?: readonly ComboSetting[];
|
|
3322
|
+
/** 路由组(阶段 B4):与 combos 同一份文档,删一个文件即可全部撤销。 */
|
|
3323
|
+
groups?: readonly GroupSetting[];
|
|
3014
3324
|
relay?: RelaySetting;
|
|
3015
3325
|
};
|
|
3016
3326
|
/**
|
|
@@ -3437,9 +3747,133 @@ interface ChannelLane {
|
|
|
3437
3747
|
modelId: string;
|
|
3438
3748
|
body: Record<string, unknown>;
|
|
3439
3749
|
signal: AbortSignal;
|
|
3750
|
+
/**
|
|
3751
|
+
* The DSH Session this turn belongs to, when the caller knows it.
|
|
3752
|
+
*
|
|
3753
|
+
* Forwarded onto the host call as `sessionId`. The host's own `LlmAdapter`
|
|
3754
|
+
* seam already carries that field (`GenerateOptions.sessionId`), and dropping
|
|
3755
|
+
* it here was the reason a channel model's turn could not be attributed to
|
|
3756
|
+
* the conversation that caused it: the pool lanes get the id from pi-ai's
|
|
3757
|
+
* affinity header, and this lane — which rebuilds the request by hand — has
|
|
3758
|
+
* to pass it explicitly.
|
|
3759
|
+
*/
|
|
3760
|
+
sessionId?: string | undefined;
|
|
3440
3761
|
}) => AsyncGenerator<ChannelLaneEvent>;
|
|
3441
3762
|
}
|
|
3442
3763
|
//#endregion
|
|
3764
|
+
//#region src/session-route.d.ts
|
|
3765
|
+
/**
|
|
3766
|
+
* 「这个会话现在是走哪家、用哪个号」——一张会话 id 到归属的小表。
|
|
3767
|
+
*
|
|
3768
|
+
* WHY THIS IS A SEPARATE MODULE
|
|
3769
|
+
*
|
|
3770
|
+
* The usage ledger (`stats.ts`) already records which channel and which account
|
|
3771
|
+
* served every physical call. It cannot answer this question, for a reason that
|
|
3772
|
+
* is structural rather than a bug: it files calls under a `turnId` minted per
|
|
3773
|
+
* request, and it keeps a bounded ring of samples that a busy session flushes
|
|
3774
|
+
* out. "Which account is this conversation on" is a question about the CURRENT
|
|
3775
|
+
* state of one conversation, not about the last 2000 calls.
|
|
3776
|
+
*
|
|
3777
|
+
* The identity that makes it answerable exists: `GenerateOptions.sessionId` is
|
|
3778
|
+
* the DSH Session id, and pi-ai turns it into session-affinity headers on the
|
|
3779
|
+
* wire. So a lane that receives a request can say, at the moment it serves it,
|
|
3780
|
+
* "session X is on channel C, account A". This module holds exactly that fact
|
|
3781
|
+
* and nothing else.
|
|
3782
|
+
*
|
|
3783
|
+
* WHAT IT DELIBERATELY DOES NOT HOLD
|
|
3784
|
+
*
|
|
3785
|
+
* No prompts, no message text, no token counts. A conversation id mapped to a
|
|
3786
|
+
* vendor and an account label is what the reader asked for; copying the rest
|
|
3787
|
+
* would turn a status readout into a second copy of the transcript.
|
|
3788
|
+
*
|
|
3789
|
+
* BOUNDED ON PURPOSE
|
|
3790
|
+
*
|
|
3791
|
+
* One entry per live conversation is small, but sessions accumulate. The map is
|
|
3792
|
+
* an LRU with a fixed ceiling, so a long-running host cannot grow it without
|
|
3793
|
+
* limit. An evicted session simply reads as "unknown" until its next call
|
|
3794
|
+
* repopulates it, which is the honest state rather than a stale guess.
|
|
3795
|
+
*
|
|
3796
|
+
* @module dsh-xdpool/session-route
|
|
3797
|
+
*/
|
|
3798
|
+
/** One conversation's current归属, as the serving lane last saw it. */
|
|
3799
|
+
interface SessionRoute {
|
|
3800
|
+
/** The DSH Session id this describes. */
|
|
3801
|
+
sessionId: string;
|
|
3802
|
+
/**
|
|
3803
|
+
* The channel that served it.
|
|
3804
|
+
*
|
|
3805
|
+
* `workbuddy` for the pooled WorkBuddy lanes, `free` for the keyless lane, or
|
|
3806
|
+
* a provider / channel id (a third-party vendor or a sign-in channel).
|
|
3807
|
+
*/
|
|
3808
|
+
channel: string;
|
|
3809
|
+
/** Gateway region for the pooled lanes: `cn`, `global`, or empty elsewhere. */
|
|
3810
|
+
region: string;
|
|
3811
|
+
/** The model id the last call asked for. */
|
|
3812
|
+
model: string;
|
|
3813
|
+
/**
|
|
3814
|
+
* Display label of the account that served it, or `''` when the lane cannot
|
|
3815
|
+
* name one.
|
|
3816
|
+
*
|
|
3817
|
+
* Empty is a real answer, not a missing one: a sign-in channel's account is
|
|
3818
|
+
* chosen inside the host's adapter, which does not report it back, so the
|
|
3819
|
+
* honest value is "the channel picked one of its own". Inventing a label
|
|
3820
|
+
* would put a name on screen that nobody verified.
|
|
3821
|
+
*/
|
|
3822
|
+
account: string;
|
|
3823
|
+
/** When this route was last confirmed by an answered call, in epoch ms. */
|
|
3824
|
+
at: number;
|
|
3825
|
+
}
|
|
3826
|
+
/**
|
|
3827
|
+
* A bounded, most-recent-wins map of conversation → serving route.
|
|
3828
|
+
*
|
|
3829
|
+
* Reads are cheap and synchronous because the HTTP route that serves the panel
|
|
3830
|
+
* is answering a poll that runs while a turn streams; an async read here would
|
|
3831
|
+
* make the panel lag the call it is describing.
|
|
3832
|
+
*/
|
|
3833
|
+
declare class SessionRouteBook {
|
|
3834
|
+
private readonly routes;
|
|
3835
|
+
/**
|
|
3836
|
+
* 会话 → 强制指定的账号 id。
|
|
3837
|
+
*
|
|
3838
|
+
* 只存 id 字符串,不碰凭据:这是用户「这个会话就用这个号」的选择,不是号的
|
|
3839
|
+
* 登录态。账号被删掉、被换掉、冷却、被关掉时 pin 都照旧留着 —— 选号时若这个
|
|
3840
|
+
* id 不可用就 fail-open 回退普通选号,而不是让会话卡死(见 shim 的
|
|
3841
|
+
* `acquireForRequest`)。和 `routes` 一样是 LRU,共用 SESSION_ROUTE_LIMIT,
|
|
3842
|
+
* 因为一个长期运行的宿主不能让「指定过一次」的记录无限长地留下去。
|
|
3843
|
+
*/
|
|
3844
|
+
private readonly pins;
|
|
3845
|
+
private readonly limit;
|
|
3846
|
+
constructor(limit?: number);
|
|
3847
|
+
/**
|
|
3848
|
+
* Remember which route served one session.
|
|
3849
|
+
*
|
|
3850
|
+
* Re-inserting also refreshes LRU position: a conversation that just spoke is
|
|
3851
|
+
* the one most likely to be read next.
|
|
3852
|
+
*/
|
|
3853
|
+
record(route: SessionRoute): void;
|
|
3854
|
+
/** The current route for one conversation, or undefined when unknown. */
|
|
3855
|
+
of(sessionId: string | undefined): SessionRoute | undefined;
|
|
3856
|
+
/** Every retained route, most recently confirmed last. */
|
|
3857
|
+
list(): readonly SessionRoute[];
|
|
3858
|
+
/** Conversations currently retained. */
|
|
3859
|
+
size(): number;
|
|
3860
|
+
/**
|
|
3861
|
+
* 强制这个会话使用某个账号。
|
|
3862
|
+
*
|
|
3863
|
+
* 会话 id 与账号 id 都按 id 的规则校验:前者来自请求参数,后者来自 body,
|
|
3864
|
+
* 放任意文本进来只会让面板显示一段没人验证过的字。账号 id 只按形状验,
|
|
3865
|
+
* 不查它是否真的存在 —— 池子会在之后 rescan,pin 一个「还不在」的号应当
|
|
3866
|
+
* 在它出现后自动生效。重复 pin 同一个号会刷新 LRU 位置。
|
|
3867
|
+
*/
|
|
3868
|
+
pin(sessionId: string | undefined, accountId: string | undefined): void;
|
|
3869
|
+
/** 取消指定。未知会话也是空操作,不报错。 */
|
|
3870
|
+
unpin(sessionId: string | undefined): void;
|
|
3871
|
+
/** 这个会话被指定用哪个号;没有就是 undefined(不是空字符串)。 */
|
|
3872
|
+
pinned(sessionId: string | undefined): string | undefined;
|
|
3873
|
+
/** Forget everything. Used by reset paths and by tests. */
|
|
3874
|
+
clear(): void;
|
|
3875
|
+
}
|
|
3876
|
+
//#endregion
|
|
3443
3877
|
//#region src/shim.d.ts
|
|
3444
3878
|
interface ShimLogger {
|
|
3445
3879
|
info?(...args: unknown[]): void;
|
|
@@ -3597,6 +4031,15 @@ interface WorkBuddyShimOptions {
|
|
|
3597
4031
|
* for other machines.
|
|
3598
4032
|
*/
|
|
3599
4033
|
lanModels?: () => readonly string[] | undefined;
|
|
4034
|
+
/**
|
|
4035
|
+
* Where one conversation's serving route is remembered.
|
|
4036
|
+
*
|
|
4037
|
+
* Optional like `usageRecorder`, and for the same reason: the CLI and the
|
|
4038
|
+
* tests run a shim with no panel, and threading an argument nobody reads would
|
|
4039
|
+
* only be noise. When absent, nothing about a request's behaviour changes —
|
|
4040
|
+
* only the readout the composer chip draws is missing.
|
|
4041
|
+
*/
|
|
4042
|
+
sessionRoutes?: SessionRouteBook;
|
|
3600
4043
|
}
|
|
3601
4044
|
export declare function createWorkBuddyShim(options: WorkBuddyShimOptions): WorkBuddyShim;
|
|
3602
4045
|
//#endregion
|
|
@@ -4092,18 +4535,32 @@ export declare class WorkBuddyScheduler {
|
|
|
4092
4535
|
* report would have moved. This is what the card's single button calls.
|
|
4093
4536
|
*/
|
|
4094
4537
|
/**
|
|
4095
|
-
* Start a
|
|
4538
|
+
* Start a pass in the background and return immediately.
|
|
4096
4539
|
*
|
|
4097
4540
|
* A pass takes tens of seconds - one upstream round trip per account per job,
|
|
4098
4541
|
* plus the scoring wait - which is far too long to hold the card request open:
|
|
4099
4542
|
* the browser or the host web server would time out, and the user would see
|
|
4100
4543
|
* a hung button for a run that is actually working.
|
|
4101
4544
|
*
|
|
4545
|
+
* `job` names ONE job (the card's per-job button) or `'all'` for the ordered
|
|
4546
|
+
* full pass; anything else is treated as `'all'` by the caller's validation,
|
|
4547
|
+
* not here. `force` bypasses the already-ran-today guard for a single job,
|
|
4548
|
+
* which is what "run it now anyway" means.
|
|
4549
|
+
*
|
|
4102
4550
|
* Returns whether a run started. A second call while one is in flight is
|
|
4103
4551
|
* ignored rather than queued: pressing the button twice means hurry up, and
|
|
4104
4552
|
* the run already under way covers it.
|
|
4105
4553
|
*/
|
|
4106
|
-
startRunAll(): boolean;
|
|
4554
|
+
startRunAll(job?: AutomationJobKind | 'all', force?: boolean): boolean;
|
|
4555
|
+
/**
|
|
4556
|
+
* issue #222:启动一个指定 job 的后台运行,供「立即执行」按任务调用。
|
|
4557
|
+
*
|
|
4558
|
+
* 和 `startRunAll` 一样立刻返回(跑一轮要几十秒,不能挂在卡片请求上),
|
|
4559
|
+
* 也复用同一把 `runInFlight` 锁:同时检查 `busy`,避免手动单任务和定时 tick
|
|
4560
|
+
* 并发跑同一批账号(共享 ledger 的 read-modify-write 不是原子的)。
|
|
4561
|
+
* `force` 交给 `runNow`,让它跳过同小时的节流。
|
|
4562
|
+
*/
|
|
4563
|
+
startRunNow(kind: AutomationJobKind, force?: boolean): boolean;
|
|
4107
4564
|
runAll(): Promise<AutomationRunSummary>;
|
|
4108
4565
|
status(): AutomationStatus;
|
|
4109
4566
|
/**
|
|
@@ -4703,6 +5160,15 @@ interface PoolStatusRouteOptions {
|
|
|
4703
5160
|
* document. The catalog refresh is what makes a new chain pickable at once.
|
|
4704
5161
|
*/
|
|
4705
5162
|
saveCombos?: (raw: unknown) => Promise<PoolWebCombosStatus>;
|
|
5163
|
+
/** 路由组文档与保存(阶段 B4-4):与 combos 同构,写后由 catalog.refresh 立刻生效。 */
|
|
5164
|
+
groupsDocument?: () => {
|
|
5165
|
+
groups: readonly unknown[];
|
|
5166
|
+
} | Promise<{
|
|
5167
|
+
groups: readonly unknown[];
|
|
5168
|
+
}>;
|
|
5169
|
+
saveGroups?: (raw: unknown) => Promise<{
|
|
5170
|
+
groups: readonly unknown[];
|
|
5171
|
+
}>;
|
|
4706
5172
|
/**
|
|
4707
5173
|
* Estimated credit spend per channel and model, for the composer strip.
|
|
4708
5174
|
*
|
|
@@ -4724,11 +5190,6 @@ interface PoolStatusRouteOptions {
|
|
|
4724
5190
|
/** Apply a relay patch, re-evaluate the listener, and answer with the new state. */
|
|
4725
5191
|
saveRelay?: (patch: PoolWebRelayPatch) => Promise<PoolWebRelayStatus>;
|
|
4726
5192
|
}
|
|
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
5193
|
export declare function poolWebStatus(deps: PoolStatusRouteOptions, region?: PoolRegion): Promise<PoolWebStatus>;
|
|
4733
5194
|
/**
|
|
4734
5195
|
* Mount the read-only routes on a context where `webServer` is available. The
|