heybash-xdpool 1.0.5 → 1.0.7
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 +14 -0
- package/README.md +3 -1
- package/assets/licenses/dsh-connect-doubao-MIT.txt +21 -0
- package/lib/bin.js +689 -59
- package/lib/client.js +701 -45
- package/lib/index.d.ts +215 -7
- package/lib/index.js +4425 -823
- package/package.json +1 -1
- package/tools/sync-npmmirror.mjs +3 -3
- package/vendor/channel-pack/pack.js +58 -5
package/lib/index.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ type TaskEventTransport = 'desktop' | 'web';
|
|
|
29
29
|
/** A ready-to-send chain, plus the channel it must go out on. */
|
|
30
30
|
interface TaskEventChain {
|
|
31
31
|
transport: TaskEventTransport;
|
|
32
|
+
/** Skill sharing uses the newer desktop identity required by that task. */
|
|
33
|
+
identity?: 'skill-share';
|
|
32
34
|
/** Desktop chains: the event array. */
|
|
33
35
|
events?: readonly Record<string, unknown>[];
|
|
34
36
|
/** Web chains: the single page event to report. */
|
|
@@ -369,6 +371,12 @@ interface WorkBuddyTravelState {
|
|
|
369
371
|
/** Credits an arrived trip pays. */
|
|
370
372
|
rewardCredit: number;
|
|
371
373
|
}
|
|
374
|
+
/** A public marketplace skill that may be used to create a share link. */
|
|
375
|
+
interface ShareableSkill {
|
|
376
|
+
id: string;
|
|
377
|
+
name: string;
|
|
378
|
+
description: string;
|
|
379
|
+
}
|
|
372
380
|
interface WorkBuddyTask {
|
|
373
381
|
/** Upstream task code; the claim path is built from it. */
|
|
374
382
|
taskCode: string;
|
|
@@ -572,8 +580,17 @@ export declare class WorkBuddyUpstreamClient {
|
|
|
572
580
|
* list is missing half its entries for the rest of the session".
|
|
573
581
|
*/
|
|
574
582
|
private fetchModelsOnce;
|
|
575
|
-
/**
|
|
576
|
-
|
|
583
|
+
/**
|
|
584
|
+
* Read-only credits query, aggregated by package. Does not consume credits.
|
|
585
|
+
*
|
|
586
|
+
* `signal` is the caller's cancellation, merged with the built-in timeout
|
|
587
|
+
* rather than replacing it: the pool's background warm must give up when the
|
|
588
|
+
* host shuts down, and a caller that has already gone away must not leave a
|
|
589
|
+
* 30 s request running. `AbortSignal.any` is already the repo's way of
|
|
590
|
+
* combining these (see the pricing probe in the shim), and the timeout stays
|
|
591
|
+
* in force so a signal-less caller keeps the old behaviour exactly.
|
|
592
|
+
*/
|
|
593
|
+
fetchCredits(credential: WorkBuddyCredential, signal?: AbortSignal): Promise<WorkBuddyCredits>;
|
|
577
594
|
/** Query today's check-in status without changing account state. */
|
|
578
595
|
fetchCheckinStatus(credential: WorkBuddyCredential): Promise<WorkBuddyCheckinStatus>;
|
|
579
596
|
/** Claim today's check-in reward. The browser route guards this mutation. */
|
|
@@ -618,7 +635,7 @@ export declare class WorkBuddyUpstreamClient {
|
|
|
618
635
|
* Business fields win over the fingerprint, so a caller can override a device
|
|
619
636
|
* id to align with a real install.
|
|
620
637
|
*/
|
|
621
|
-
reportDesktopEvents(credential: WorkBuddyCredential, events: readonly Record<string, unknown>[]): Promise<void>;
|
|
638
|
+
reportDesktopEvents(credential: WorkBuddyCredential, events: readonly Record<string, unknown>[], identity?: 'skill-share'): Promise<void>;
|
|
622
639
|
/**
|
|
623
640
|
* Report one chat-activity event to the growth system.
|
|
624
641
|
*
|
|
@@ -659,6 +676,12 @@ export declare class WorkBuddyUpstreamClient {
|
|
|
659
676
|
* response carries the display fields the summon events replay.
|
|
660
677
|
*/
|
|
661
678
|
marketExpertList(credential: WorkBuddyCredential, expertType?: 'agent' | 'team' | ''): Promise<readonly MarketExpert[]>;
|
|
679
|
+
/** Read public marketplace skills for the share-link task. */
|
|
680
|
+
shareableSkills(credential: WorkBuddyCredential): Promise<readonly ShareableSkill[]>;
|
|
681
|
+
/** Create a real link for a public marketplace skill. Never sends it to a person. */
|
|
682
|
+
createSkillShareLink(credential: WorkBuddyCredential, skill: ShareableSkill): Promise<{
|
|
683
|
+
shareCode: string;
|
|
684
|
+
}>;
|
|
662
685
|
/**
|
|
663
686
|
* Open a REAL desktop conversation and return the ids the server assigned.
|
|
664
687
|
*
|
|
@@ -754,7 +777,10 @@ export declare class WorkBuddyUpstreamClient {
|
|
|
754
777
|
* is 400 "first_buddy task not completed yet". Callers treat that as "not yet"
|
|
755
778
|
* rather than an error, which is why it is thrown as-is for them to classify.
|
|
756
779
|
*/
|
|
757
|
-
buddyAdoptFirst(credential: WorkBuddyCredential): Promise<
|
|
780
|
+
buddyAdoptFirst(credential: WorkBuddyCredential): Promise<{
|
|
781
|
+
credit: number;
|
|
782
|
+
energy: number;
|
|
783
|
+
}>;
|
|
758
784
|
/** Current travel state for the account's buddy. */
|
|
759
785
|
buddyTravelStatus(credential: WorkBuddyCredential): Promise<WorkBuddyTravelState>;
|
|
760
786
|
/**
|
|
@@ -835,6 +861,41 @@ interface TokenRefresher {
|
|
|
835
861
|
domain?: string;
|
|
836
862
|
}>;
|
|
837
863
|
}
|
|
864
|
+
/**
|
|
865
|
+
* Minimal billing surface the pool needs to fill `creditExpiry` itself.
|
|
866
|
+
*
|
|
867
|
+
* Declared here for the same reason as {@link TokenRefresher}: the pool knows
|
|
868
|
+
* about accounts, not about HTTP, and importing `WorkBuddyUpstreamClient` would
|
|
869
|
+
* make the two modules circular. `fetchCredits` is OPTIONAL so every existing
|
|
870
|
+
* `TokenRefresher` — the test stubs, and any host that only wired token refresh
|
|
871
|
+
* — keeps working untouched; a client without it simply warms nothing.
|
|
872
|
+
*/
|
|
873
|
+
interface CreditReader {
|
|
874
|
+
fetchCredits(credential: WorkBuddyCredential, signal?: AbortSignal): Promise<{
|
|
875
|
+
total: number;
|
|
876
|
+
/** Absent (or undefined) when no one-off pack has a deadline. */
|
|
877
|
+
nearestExpiryMs?: number | undefined;
|
|
878
|
+
}>;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* What the pool knows about one account's one-off pack deadlines.
|
|
882
|
+
*
|
|
883
|
+
* The three `state`s are the whole point of the B+ fix: "never asked", "asked,
|
|
884
|
+
* nothing has a deadline" and "asked, here is the deadline" need different
|
|
885
|
+
* handling, and collapsing them into one absent-key predicate is what made a
|
|
886
|
+
* pure monthly-pack account be re-read forever (S1 in
|
|
887
|
+
* `EXPIRY-ADVERSARIAL-20261111.md`). `stale` is orthogonal: the reading is real
|
|
888
|
+
* but older than {@link EXPIRY_READING_TTL_MS}, so it describes the past.
|
|
889
|
+
*/
|
|
890
|
+
interface ExpiryReading {
|
|
891
|
+
state: 'unread' | 'none' | 'at';
|
|
892
|
+
/** Deadline, epoch ms; present exactly when `state === 'at'`. */
|
|
893
|
+
at?: number;
|
|
894
|
+
/** When this reading was written, epoch ms; absent for `unread`. */
|
|
895
|
+
readAtMs?: number;
|
|
896
|
+
/** True when the reading is older than {@link EXPIRY_READING_TTL_MS}. */
|
|
897
|
+
stale: boolean;
|
|
898
|
+
}
|
|
838
899
|
/** Live auth file name the WorkBuddy desktop app writes. */
|
|
839
900
|
export declare const WORKBUDDY_LIVE_FILENAME = "workbuddy-desktop.info";
|
|
840
901
|
/** Snapshot files left behind by previous logins share this prefix. */
|
|
@@ -963,9 +1024,16 @@ interface AccountPoolOptions {
|
|
|
963
1024
|
*/
|
|
964
1025
|
credentialDeadCooldownMs?: number;
|
|
965
1026
|
/** Upstream client used to refresh near-expiry tokens. */
|
|
966
|
-
client?: TokenRefresher
|
|
1027
|
+
client?: TokenRefresher & Partial<CreditReader>;
|
|
967
1028
|
/** Refresh this long before actual expiry; default five minutes. */
|
|
968
1029
|
refreshMarginMs?: number;
|
|
1030
|
+
/**
|
|
1031
|
+
* How long a credit-pack deadline reading is trusted, in ms.
|
|
1032
|
+
*
|
|
1033
|
+
* Defaults to {@link EXPIRY_READING_TTL_MS}; overridable so a test can age a
|
|
1034
|
+
* reading without sleeping for an hour.
|
|
1035
|
+
*/
|
|
1036
|
+
expiryReadingTtlMs?: number;
|
|
969
1037
|
/**
|
|
970
1038
|
* How requests are spread across the pool.
|
|
971
1039
|
*
|
|
@@ -1017,6 +1085,7 @@ export declare class WorkBuddyAccountPool {
|
|
|
1017
1085
|
private credentialDeadCooldownMs;
|
|
1018
1086
|
private readonly client;
|
|
1019
1087
|
private readonly refreshMarginMs;
|
|
1088
|
+
private readonly expiryReadingTtlMs;
|
|
1020
1089
|
private accounts;
|
|
1021
1090
|
/**
|
|
1022
1091
|
* Files the last scan could not read, with the reason.
|
|
@@ -1112,10 +1181,41 @@ export declare class WorkBuddyAccountPool {
|
|
|
1112
1181
|
* their own cycle and are therefore never urgent — which is why this is
|
|
1113
1182
|
* written from the same `fetchCredits` reading that fills `creditBalances`.
|
|
1114
1183
|
*
|
|
1115
|
-
*
|
|
1116
|
-
*
|
|
1184
|
+
* A positive value is a deadline. The two other states are kept in
|
|
1185
|
+
* {@link creditExpiryNone} and {@link creditExpiryReadAt} rather than as a
|
|
1186
|
+
* missing key, because a missing key cannot tell "we never looked" from "we
|
|
1187
|
+
* looked and nothing has a deadline" — and only the first is worth reading
|
|
1188
|
+
* again. An account whose packs are all monthly reads as `none` forever, which
|
|
1189
|
+
* is exactly right: asking again cannot change the answer (S1).
|
|
1117
1190
|
*/
|
|
1118
1191
|
private creditExpiry;
|
|
1192
|
+
/**
|
|
1193
|
+
* Accounts whose last reading found NO one-off deadline (all monthly packs, or
|
|
1194
|
+
* none at all). Written instead of deleting the key, so the account stops
|
|
1195
|
+
* being a candidate for re-reading.
|
|
1196
|
+
*/
|
|
1197
|
+
private creditExpiryNone;
|
|
1198
|
+
/** When each account's deadline reading was taken, epoch ms. */
|
|
1199
|
+
private creditExpiryReadAt;
|
|
1200
|
+
/**
|
|
1201
|
+
* Accounts whose deadline reading is being fetched right now.
|
|
1202
|
+
*
|
|
1203
|
+
* Same de-duplication idea as {@link refreshInflight}, for the same reason: a
|
|
1204
|
+
* scan-triggered warm and a request-triggered top-up must not both spend a
|
|
1205
|
+
* billing round trip on the same account. A Set rather than a Map of promises
|
|
1206
|
+
* because no caller ever awaits the warm — the point is only that a second
|
|
1207
|
+
* pass skips it.
|
|
1208
|
+
*/
|
|
1209
|
+
private expiryWarmInflight;
|
|
1210
|
+
/**
|
|
1211
|
+
* Last time the pool tried to warm an account's deadline reading, epoch ms.
|
|
1212
|
+
*
|
|
1213
|
+
* The TTL is the success gate, not a retry gate: a failed read writes nothing,
|
|
1214
|
+
* so without this a permanently failing billing endpoint would be hit on every
|
|
1215
|
+
* scan and every served request. One attempt per account per minute is cheap
|
|
1216
|
+
* and still recovers quickly from a transient failure.
|
|
1217
|
+
*/
|
|
1218
|
+
private expiryWarmAttemptAt;
|
|
1119
1219
|
/**
|
|
1120
1220
|
* Last time each account served a request, epoch ms. Drives the idle term
|
|
1121
1221
|
* of the priority-mode weighting below: an account that just served loses to
|
|
@@ -1210,6 +1310,47 @@ export declare class WorkBuddyAccountPool {
|
|
|
1210
1310
|
private pruneExpiredSnapshots;
|
|
1211
1311
|
/** Rescan the auth directories and merge newly discovered accounts. */
|
|
1212
1312
|
scan(): Promise<WorkBuddyAccount[]>;
|
|
1313
|
+
/**
|
|
1314
|
+
* Warm the deadline readings that `expiry` mode sorts on.
|
|
1315
|
+
*
|
|
1316
|
+
* Fire-and-forget on purpose, from `scan()`: the pool's first request arrives
|
|
1317
|
+
* before any reading exists, and the honest answer to that is the documented
|
|
1318
|
+
* fallback plus a log line, not a stalled request. Everything about the call
|
|
1319
|
+
* is chosen to be unable to make things worse:
|
|
1320
|
+
*
|
|
1321
|
+
* - `this.client` may not exist (a host that wired only token refresh), in
|
|
1322
|
+
* which case there is nothing to read with and the pass is a no-op — the
|
|
1323
|
+
* same guard `ensureFresh` uses;
|
|
1324
|
+
* - a dead sign-in is skipped, and a successful read NEVER calls
|
|
1325
|
+
* `clearCredentialDead`. That is the difference between this and
|
|
1326
|
+
* `reviveBenched`: the billing endpoint answers 200 for a banned account
|
|
1327
|
+
* (observed on 11140), so treating a read as proof of health is what got a
|
|
1328
|
+
* banned account revived six times in a day (S2). Only a token refresh or a
|
|
1329
|
+
* fresh sign-in may clear that mark;
|
|
1330
|
+
* - accounts whose reading is fresh enough are skipped, and so are accounts
|
|
1331
|
+
* already being read (S10's de-duplication, mirroring `refreshInflight`);
|
|
1332
|
+
* - a failed read writes nothing and only warns, so the next pass tries
|
|
1333
|
+
* again without the failure being mistaken for a reading.
|
|
1334
|
+
*/
|
|
1335
|
+
private warmExpiryReadings;
|
|
1336
|
+
/** One account's warm read; see {@link warmExpiryReadings} for the rules. */
|
|
1337
|
+
private warmOneExpiryReading;
|
|
1338
|
+
/**
|
|
1339
|
+
* Top up one account's deadline reading, from wherever the pool notices it is
|
|
1340
|
+
* missing or stale.
|
|
1341
|
+
*
|
|
1342
|
+
* The request path is the second caller (after `scan()`), because a reading
|
|
1343
|
+
* ages out while the pool is busy too: the shim calls this for the account that
|
|
1344
|
+
* just served a request, which is the one whose spend is most likely to have
|
|
1345
|
+
* moved its deadline. No timer is created — the existing balance refresh is
|
|
1346
|
+
* already the natural heartbeat, and this rides on it.
|
|
1347
|
+
*
|
|
1348
|
+
* Every gate lives here rather than in the callers, so both paths obey exactly
|
|
1349
|
+
* the same rules: no client, no account, a rejected sign-in, an already-running
|
|
1350
|
+
* read, a finished "nothing expires" answer, a fresh reading, or an attempt
|
|
1351
|
+
* made within the last minute all mean "do nothing".
|
|
1352
|
+
*/
|
|
1353
|
+
warmExpiryReadingFor(accountId: string): void;
|
|
1213
1354
|
/** All accounts, cooldown state included. */
|
|
1214
1355
|
list(region?: WorkBuddyRegion): readonly WorkBuddyAccount[];
|
|
1215
1356
|
/**
|
|
@@ -1331,6 +1472,14 @@ export declare class WorkBuddyAccountPool {
|
|
|
1331
1472
|
* A pool where nobody has a known expiry therefore behaves exactly like
|
|
1332
1473
|
* priority, which is the honest degradation: without a reading there is
|
|
1333
1474
|
* nothing to sort by.
|
|
1475
|
+
*
|
|
1476
|
+
* What this method must NOT do is pretend. With only SOME readings in hand it
|
|
1477
|
+
* still has to fall back to `pool[0]`, because picking the earliest of the
|
|
1478
|
+
* accounts that happen to have answered would silently drop the account that
|
|
1479
|
+
* really dies first — the failure mode S0 in `EXPIRY-ADVERSARIAL-20261111.md`
|
|
1480
|
+
* called "worse than not fixing it", since the pick looks plausible and is
|
|
1481
|
+
* wrong. So the incomplete case is announced instead: the caller keeps the old
|
|
1482
|
+
* semantics and the log says which accounts were not read.
|
|
1334
1483
|
*/
|
|
1335
1484
|
private pickByExpiry;
|
|
1336
1485
|
/**
|
|
@@ -1423,10 +1572,50 @@ export declare class WorkBuddyAccountPool {
|
|
|
1423
1572
|
* merged: a pack that has been spent or has died disappears from the next
|
|
1424
1573
|
* reading, and keeping the stale deadline would pin the pool to an account
|
|
1425
1574
|
* whose credits are already gone — the opposite of what `expiry` mode wants.
|
|
1575
|
+
*
|
|
1576
|
+
* "Nothing expires" is a real answer, not the absence of one: it is stored as
|
|
1577
|
+
* {@link creditExpiryNone} so the account is not read again on every pass.
|
|
1426
1578
|
*/
|
|
1427
1579
|
noteCredits(accountId: string, balance: number, nearestExpiryMs?: number): void;
|
|
1580
|
+
/**
|
|
1581
|
+
* Record ONLY the deadline, never the balance.
|
|
1582
|
+
*
|
|
1583
|
+
* The scan-triggered warm exists to fill `expiry` mode's sort key. Writing the
|
|
1584
|
+
* balance as a side effect would change what the reserve floor decides — an
|
|
1585
|
+
* account could be pulled out of rotation by a background read the user never
|
|
1586
|
+
* asked for, which is a behaviour change outside this fix's scope (S7 in
|
|
1587
|
+
* `EXPIRY-ADVERSARIAL-20261111.md`; the reserve's own cold-start hole is V4,
|
|
1588
|
+
* fixed separately).
|
|
1589
|
+
*/
|
|
1590
|
+
noteExpiryOnly(accountId: string, nearestExpiryMs?: number): void;
|
|
1591
|
+
/**
|
|
1592
|
+
* The three-state writer both entry points funnel through.
|
|
1593
|
+
*
|
|
1594
|
+
* One place, so the invariant "a finished reading always leaves a state" can be
|
|
1595
|
+
* read off a single function: either a deadline is stored, or the account joins
|
|
1596
|
+
* `creditExpiryNone`. Nothing here deletes the read stamp — that is what makes
|
|
1597
|
+
* "read, found nothing" distinguishable from "never read".
|
|
1598
|
+
*/
|
|
1599
|
+
private noteExpiryReading;
|
|
1428
1600
|
/** Nearest one-off pack expiry for one account, or undefined when none known. */
|
|
1429
1601
|
creditExpiryOf(accountId: string): number | undefined;
|
|
1602
|
+
/**
|
|
1603
|
+
* The full three-state reading for one account, including staleness.
|
|
1604
|
+
*
|
|
1605
|
+
* `stale` is evaluated against {@link EXPIRY_READING_TTL_MS} here rather than
|
|
1606
|
+
* baked into the stored value, so the TTL stays a constant of the policy and
|
|
1607
|
+
* not of the data.
|
|
1608
|
+
*
|
|
1609
|
+
* Only a real deadline can go stale. "We never asked" is not a reading, and
|
|
1610
|
+
* "nothing here has a deadline" does not become less true with age: a monthly
|
|
1611
|
+
* pack does not grow an expiry date by waiting. Keeping `none` permanently
|
|
1612
|
+
* valid is what makes the S1 loop impossible — an account that answered once
|
|
1613
|
+
* is never read again by the expiry machinery, so there is no predicate that
|
|
1614
|
+
* can stay true forever and re-read it on every pass. If such an account does
|
|
1615
|
+
* gain a one-off pack later, the card refresh (which writes through
|
|
1616
|
+
* `noteCredits` on every poll) is what notices.
|
|
1617
|
+
*/
|
|
1618
|
+
expiryReadingOf(accountId: string, now?: number): ExpiryReading;
|
|
1430
1619
|
/** Last known balance for one account, or undefined when never read. */
|
|
1431
1620
|
creditsOf(accountId: string): number | undefined;
|
|
1432
1621
|
/** The credit floor the user set for one account; 0 when unset. */
|
|
@@ -3664,6 +3853,17 @@ export declare class WorkBuddyScheduler {
|
|
|
3664
3853
|
private travelHours;
|
|
3665
3854
|
private compensationHours;
|
|
3666
3855
|
private timer;
|
|
3856
|
+
/** The one-shot kick scheduled just after `start`; cleared by `stop`. */
|
|
3857
|
+
private settleTimer;
|
|
3858
|
+
/**
|
|
3859
|
+
* Deadline for the start-of-day window described in {@link dueSlot}.
|
|
3860
|
+
*
|
|
3861
|
+
* Zero until {@link start} sets it, so a manual `tick` before the loop starts
|
|
3862
|
+
* keeps the original "only past hours" behaviour.
|
|
3863
|
+
*/
|
|
3864
|
+
private startupCatchUpUntilMs;
|
|
3865
|
+
/** A startup pass is extra work; it never spends a future scheduled slot. */
|
|
3866
|
+
private readonly startupCompleted;
|
|
3667
3867
|
private running;
|
|
3668
3868
|
/** Guards against a slow run overlapping the next tick. */
|
|
3669
3869
|
private busy;
|
|
@@ -3679,6 +3879,10 @@ export declare class WorkBuddyScheduler {
|
|
|
3679
3879
|
private stopped;
|
|
3680
3880
|
private readonly states;
|
|
3681
3881
|
private claimableSeen;
|
|
3882
|
+
/** Completion failures for the latest pass, keyed by account and task. */
|
|
3883
|
+
private readonly eventFailures;
|
|
3884
|
+
/** Direct rewards from first-Buddy adoption, awaiting the task summary. */
|
|
3885
|
+
private readonly buddyAdoptionReceipts;
|
|
3682
3886
|
/**
|
|
3683
3887
|
* Credits/energy/tasks earned per account TODAY, keyed by account id.
|
|
3684
3888
|
*
|
|
@@ -3798,6 +4002,8 @@ export declare class WorkBuddyScheduler {
|
|
|
3798
4002
|
* PASSED and its slot is still unconsumed, so a laptop that slept through
|
|
3799
4003
|
* 10:00 still runs the job when it wakes, on the same day.
|
|
3800
4004
|
*
|
|
4005
|
+
* Startup runs are handled separately in tick and do not spend a future slot.
|
|
4006
|
+
*
|
|
3801
4007
|
* The EARLIEST unconsumed candidate wins, which is what keeps a two-hour job
|
|
3802
4008
|
* (`travelHours: [9, 21]`) whole: consuming the earliest due slot leaves the
|
|
3803
4009
|
* later one for its own hour.
|
|
@@ -3885,6 +4091,8 @@ export declare class WorkBuddyScheduler {
|
|
|
3885
4091
|
*/
|
|
3886
4092
|
private reportOne;
|
|
3887
4093
|
private sendEventChains;
|
|
4094
|
+
/** Adopt only when the account truly lacks a Buddy; verify after the write. */
|
|
4095
|
+
private completeFirstBuddy;
|
|
3888
4096
|
/**
|
|
3889
4097
|
* Send one chain on the channel it was built for.
|
|
3890
4098
|
*
|