@eddyskywalker/dsh-chatgpt-subscription 0.5.0 → 0.6.5

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +36 -1
  2. package/README.md +67 -1
  3. package/lib/client.js +1425 -222
  4. package/lib/client.js.map +1 -1
  5. package/lib/index.js +4884 -1114
  6. package/lib/types/client/ProviderHubSection.d.ts.map +1 -1
  7. package/lib/types/client/common/AccountPoolSection.d.ts +14 -0
  8. package/lib/types/client/common/AccountPoolSection.d.ts.map +1 -1
  9. package/lib/types/client/index.d.ts +1 -0
  10. package/lib/types/client/index.d.ts.map +1 -1
  11. package/lib/types/client/workbuddy/WorkBuddyComposerQuota.d.ts +26 -0
  12. package/lib/types/client/workbuddy/WorkBuddyComposerQuota.d.ts.map +1 -0
  13. package/lib/types/client/workbuddy/WorkBuddySection.d.ts +41 -0
  14. package/lib/types/client/workbuddy/WorkBuddySection.d.ts.map +1 -0
  15. package/lib/types/client/workbuddy/locales.d.ts +485 -0
  16. package/lib/types/client/workbuddy/locales.d.ts.map +1 -0
  17. package/lib/types/client/workbuddy/styles.d.ts +15 -0
  18. package/lib/types/client/workbuddy/styles.d.ts.map +1 -0
  19. package/lib/types/host/common/account-pool.d.ts +18 -0
  20. package/lib/types/host/common/account-pool.d.ts.map +1 -1
  21. package/lib/types/host/workbuddy/account-pool.d.ts +106 -0
  22. package/lib/types/host/workbuddy/account-pool.d.ts.map +1 -0
  23. package/lib/types/host/workbuddy/adapter.d.ts +97 -0
  24. package/lib/types/host/workbuddy/adapter.d.ts.map +1 -0
  25. package/lib/types/host/workbuddy/client.d.ts +90 -0
  26. package/lib/types/host/workbuddy/client.d.ts.map +1 -0
  27. package/lib/types/host/workbuddy/mapper.d.ts +114 -0
  28. package/lib/types/host/workbuddy/mapper.d.ts.map +1 -0
  29. package/lib/types/host/workbuddy/model-catalog.d.ts +108 -0
  30. package/lib/types/host/workbuddy/model-catalog.d.ts.map +1 -0
  31. package/lib/types/host/workbuddy/oauth.d.ts +38 -0
  32. package/lib/types/host/workbuddy/oauth.d.ts.map +1 -0
  33. package/lib/types/host/workbuddy/routes.d.ts +33 -0
  34. package/lib/types/host/workbuddy/routes.d.ts.map +1 -0
  35. package/lib/types/host/workbuddy/token-store.d.ts +216 -0
  36. package/lib/types/host/workbuddy/token-store.d.ts.map +1 -0
  37. package/lib/types/host/workbuddy/types.d.ts +127 -0
  38. package/lib/types/host/workbuddy/types.d.ts.map +1 -0
  39. package/lib/types/index.d.ts +5 -0
  40. package/lib/types/index.d.ts.map +1 -1
  41. package/lib/types/shared/account-pool-contracts.d.ts +8 -0
  42. package/lib/types/shared/account-pool-contracts.d.ts.map +1 -1
  43. package/lib/types/shared/workbuddy-contracts.d.ts +210 -0
  44. package/lib/types/shared/workbuddy-contracts.d.ts.map +1 -0
  45. package/package.json +1 -1
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Wire contracts between the WorkBuddy host routes and the browser settings
3
+ * card. Everything here is public: no credential ever crosses this boundary.
4
+ */
5
+ import type { AccountPoolStatusDto, PoolAccountSummaryDto } from './account-pool-contracts.ts';
6
+ /**
7
+ * Which deployment region an account belongs to.
8
+ *
9
+ * The two regions are separate backends serving overlapping-but-different model
10
+ * catalogs, and a model asked of the wrong region answers 400 `code 11102`
11
+ * ("service info not found") rather than failing over. The region is therefore
12
+ * a property of the credential, not of the request.
13
+ */
14
+ export type WorkBuddyRegion = 'cn' | 'intl';
15
+ /**
16
+ * Reasoning levels this route can name.
17
+ *
18
+ * Deliberately the widest set any model declares, so a saved default is not
19
+ * discarded merely because the model that suggested it is no longer selected.
20
+ * The settings card renders the subset the account's models actually declare.
21
+ */
22
+ export type WorkBuddyReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
23
+ /** Every level this route can name, in escalating order (the card's sort key). */
24
+ export declare const WORKBUDDY_REASONING_EFFORTS: readonly WorkBuddyReasoningEffort[];
25
+ /**
26
+ * Ladder of a WorkBuddy model that leaves the level choice to the gateway.
27
+ *
28
+ * `/v3/config` publishes a model's ladder in two shapes: an explicit
29
+ * `supportedEfforts` list, or a lone `{ effort }` field that names only the
30
+ * DEFAULT. Conflating them was a real bug — the lone field first became a
31
+ * one-entry ladder, which rejected an explicit `low`; widening it to every
32
+ * level this route can name then advertised `minimal`/`xhigh` on a model that
33
+ * has three. Measured against the live gateway, such a model accepts exactly
34
+ * `low`/`high`/`max` — the same three `glm-5.3-flash` and
35
+ * `kimi-k2.8-preview` declare explicitly — and every other value is routed
36
+ * into the nearest of them rather than honoured as a level of its own.
37
+ */
38
+ export declare const WORKBUDDY_STANDARD_EFFORTS: readonly WorkBuddyReasoningEffort[];
39
+ /**
40
+ * Snap a level onto the nearest rung a model's ladder actually exposes.
41
+ *
42
+ * The gateway names a default from a wider vocabulary than the ladder it
43
+ * publishes for the same model: an effort-only entry (minimax-m3, kimi-k3,
44
+ * `glm-5.3` in the cn region) reports `effort: 'medium'` while exposing only
45
+ * `low`/`high`/`max`. Letting that value through is not cosmetic — a default
46
+ * outside the ladder is discarded by the level-resolution step, the request
47
+ * then carries no `reasoning_effort`, and the model returns an EMPTY
48
+ * `reasoning_content` (measured on minimax-m3: 0 characters across three
49
+ * samples, versus 282-659 with the field). Ties resolve upward, which is the
50
+ * mapping the sibling Kimi line documents for `medium`. A ladder that names
51
+ * no level (a text-only model) yields nothing to converge to.
52
+ */
53
+ export declare function convergeWorkBuddyEffort(effort: string, ladder: readonly string[]): WorkBuddyReasoningEffort | null;
54
+ /** One model offered by the WorkBuddy subscription. */
55
+ export interface WorkBuddyModelOption {
56
+ id: string;
57
+ name: string;
58
+ /** Enabled models are the ones DSH offers in the conversation model picker. */
59
+ enabled: boolean;
60
+ /** Context window this route assumes when the caller saves no override. */
61
+ defaultContextWindow: number;
62
+ /** Effective context window: the override when one is saved, else the default. */
63
+ contextWindow: number;
64
+ /** Maximum output tokens this route requests when a caller omits one. */
65
+ defaultMaxTokens: number;
66
+ /** Reasoning levels this route exposes; absent for non-reasoning models. */
67
+ reasoningEfforts?: string[];
68
+ /** Whether the model accepts image input on this route. */
69
+ supportsImage: boolean;
70
+ /** Regions that serve this model; the account's own region must be listed. */
71
+ regions: WorkBuddyRegion[];
72
+ /** One-line description shown beside the model in the settings card. */
73
+ description?: string;
74
+ }
75
+ /** One credit allowance reported by the billing service. */
76
+ export interface WorkBuddyMeter {
77
+ id: string;
78
+ label: string;
79
+ /** Used fraction in [0, 1] when the service reports a bounded allowance. */
80
+ usedFraction: number | null;
81
+ /** Remaining fraction in [0, 1], when the service reports one. */
82
+ remainingFraction: number | null;
83
+ used: string | null;
84
+ limit: string | null;
85
+ /** Unix milliseconds the meter resets, when reported. */
86
+ resetsAt: number | null;
87
+ description: string | null;
88
+ }
89
+ /** Account identity read from the local CodeBuddy credential file. */
90
+ export interface WorkBuddyAccount {
91
+ /** Stable, non-secret selection key derived from region + account identity. */
92
+ id: string;
93
+ uid: string | null;
94
+ nickname: string | null;
95
+ /** Tencent UIN, masked by the card rather than sent in full. */
96
+ uin: string | null;
97
+ /** Account kind the client reports, e.g. `personal`. */
98
+ accountType: string | null;
99
+ /** Enterprise/tenant id when the account is an enterprise one. */
100
+ enterpriseId: string | null;
101
+ region: WorkBuddyRegion;
102
+ /** Backend base URL this account's region resolves to. */
103
+ backend: string;
104
+ /** Auth domain recorded in the credential, e.g. `copilot.tencent.com`. */
105
+ domain: string;
106
+ /** Unix milliseconds the access token expires. */
107
+ expiresAt: number | null;
108
+ /** File the credential was read from; null for plugin-managed accounts. */
109
+ sourceFile: string | null;
110
+ /** Desktop credentials are external; managed credentials belong to this plugin. */
111
+ source: 'desktop' | 'managed';
112
+ /** Managed credentials may be deleted; desktop credentials may only be hidden. */
113
+ removable: boolean;
114
+ /** Hidden desktop accounts do not participate in automatic selection. */
115
+ hidden: boolean;
116
+ }
117
+ /** One WorkBuddy account as the shared pool card renders it. Never carries a token. */
118
+ export interface WorkBuddyAccountSummaryDto extends PoolAccountSummaryDto {
119
+ region: WorkBuddyRegion;
120
+ /** Which store owns the credential; only managed accounts may be deleted. */
121
+ source: 'desktop' | 'managed';
122
+ /** Whether the card may offer Delete for this account. */
123
+ removable: boolean;
124
+ nickname?: string;
125
+ /** Tencent UIN, masked by the card rather than shown in full. */
126
+ uin?: string;
127
+ /** IDE file a desktop account was adopted from. */
128
+ sourceFile?: string;
129
+ /** Auth domain recorded in the credential, e.g. `copilot.tencent.com`. */
130
+ domain?: string;
131
+ /** Backend base URL the account's region resolves to. */
132
+ backend?: string;
133
+ /** Account kind the client reports, e.g. `personal`. */
134
+ accountType?: string;
135
+ /**
136
+ * Whether the plugin currently routes to this account.
137
+ *
138
+ * Distinct from the pool's `activeAccountId`: a hidden account keeps its
139
+ * place in the pool but is not offered for routing while hidden.
140
+ */
141
+ hidden?: boolean;
142
+ }
143
+ /** One point-in-time quota snapshot for the signed-in WorkBuddy account. */
144
+ export interface WorkBuddyAccountQuota {
145
+ account: WorkBuddyAccount;
146
+ /** Package name the billing service reports, e.g. `Free Plan Subscription`. */
147
+ packageName: string | null;
148
+ /** Total credits the package grants, as reported. */
149
+ totalCredits: number | null;
150
+ /** Credits remaining in the current cycle. */
151
+ remainingCredits: number | null;
152
+ /** Credits consumed in the current cycle. */
153
+ cycleUsedCredits: number | null;
154
+ /** Cycle allowance, when the service reports a per-cycle cap. */
155
+ cycleCredits: number | null;
156
+ /** Start of the current billing cycle, as Unix milliseconds. */
157
+ cycleStartsAt: number | null;
158
+ /** End of the current billing cycle, as Unix milliseconds. */
159
+ cycleEndsAt: number | null;
160
+ meters: WorkBuddyMeter[];
161
+ /** When this snapshot was read. */
162
+ fetchedAt: number;
163
+ /** Billing routes that answered, for diagnostics in the settings card. */
164
+ sources: string[];
165
+ }
166
+ /** Everything the settings card and the composer badge render. */
167
+ export interface WorkBuddyWebStatus extends Partial<AccountPoolStatusDto> {
168
+ enabled?: boolean;
169
+ authenticated: boolean;
170
+ hasCredentials: boolean;
171
+ /** Where credentials are read from; the local CodeBuddy auth directory. */
172
+ authDirectory: string;
173
+ /** Storage description for the plugin's own settings file. */
174
+ storagePath: string;
175
+ account: WorkBuddyAccount | null;
176
+ quota: WorkBuddyAccountQuota | null;
177
+ lastFetchedAt: number | null;
178
+ models: WorkBuddyModelOption[];
179
+ contextWindowOverrides: Record<string, number>;
180
+ defaultReasoningEffort: WorkBuddyReasoningEffort | null;
181
+ /** Account selected for model discovery and all requests; null means automatic. */
182
+ selectedAccountId: string | null;
183
+ /** Encrypted storage used for accounts added from this plugin. */
184
+ managedStoragePath: string;
185
+ /** Route the plugin currently serves; false when another plugin owns it. */
186
+ serving: boolean;
187
+ /** Diagnostic when the route is owned by a different adapter family. */
188
+ conflict: string | null;
189
+ /** Pool summaries the shared account card renders; empty without a pool. */
190
+ accounts?: WorkBuddyAccountSummaryDto[];
191
+ }
192
+ /** Patch accepted by the models/settings route. */
193
+ export interface WorkBuddySettingsUpdateDto {
194
+ enabled?: boolean;
195
+ enabledModelIds?: string[];
196
+ contextWindowOverrides?: Record<string, number>;
197
+ defaultReasoningEffort?: WorkBuddyReasoningEffort | null;
198
+ selectedAccountId?: string | null;
199
+ }
200
+ /** Result of a connection test against the upstream chat endpoint. */
201
+ export interface WorkBuddyConnectionDto {
202
+ connected: boolean;
203
+ account: WorkBuddyAccount | null;
204
+ /** Round-trip time of the probe request. */
205
+ latencyMs: number;
206
+ /** Model the probe asked for. */
207
+ model: string;
208
+ checkedAt: number;
209
+ }
210
+ //# sourceMappingURL=workbuddy-contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workbuddy-contracts.d.ts","sourceRoot":"","sources":["../../../src/shared/workbuddy-contracts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AAE9F;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,IAAI,GAAG,MAAM,CAAA;AAE3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E,MAAM,CAAC,CAAA;IAC9C,sBAAsB,EAAE,wBAAwB,GAAG,IAAI,CAAA;IACvD,mFAAmF;IACnF,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,kEAAkE;IAClE,kBAAkB,EAAE,MAAM,CAAA;IAC1B,4EAA4E;IAC5E,OAAO,EAAE,OAAO,CAAA;IAChB,wEAAwE;IACxE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,0BAA0B,EAAE,CAAA;CACxC;AAED,mDAAmD;AACnD,MAAM,WAAW,0BAA0B;IACzC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;IAC1B,sBAAsB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/C,sBAAsB,CAAC,EAAE,wBAAwB,GAAG,IAAI,CAAA;IACxD,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAClC;AAED,sEAAsE;AACtE,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAAA;IAChC,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAA;IACjB,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;CAClB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eddyskywalker/dsh-chatgpt-subscription",
3
- "version": "0.5.0",
3
+ "version": "0.6.5",
4
4
  "description": "DSH provider plugin for Codex access through a ChatGPT subscription.",
5
5
  "author": {
6
6
  "name": "eddyskywalker",