@aiwayds/dsh-model-sync 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +9 -4
- package/README.zh-CN.md +9 -4
- package/lib/builtin-catalog-snapshot.d.ts +5 -1
- package/lib/builtin-catalog-snapshot.js +13 -10
- package/lib/builtin-catalog-snapshot.js.map +1 -1
- package/lib/index.d.ts +366 -0
- package/lib/index.js +729 -13
- package/lib/index.js.map +1 -1
- package/lib/opencode-go-diagnose.d.ts +74 -0
- package/lib/opencode-go-diagnose.js +146 -0
- package/lib/opencode-go-diagnose.js.map +1 -0
- package/lib/opencode-go-grouping.d.ts +29 -0
- package/lib/opencode-go-grouping.js +77 -0
- package/lib/opencode-go-grouping.js.map +1 -0
- package/lib/opencode-go-journal.d.ts +110 -0
- package/lib/opencode-go-journal.js +406 -0
- package/lib/opencode-go-journal.js.map +1 -0
- package/lib/opencode-go-migrate.d.ts +343 -0
- package/lib/opencode-go-migrate.js +1300 -0
- package/lib/opencode-go-migrate.js.map +1 -0
- package/lib/opencode-go-migration.d.ts +227 -0
- package/lib/opencode-go-migration.js +384 -0
- package/lib/opencode-go-migration.js.map +1 -0
- package/lib/opencode-go-planner.d.ts +153 -0
- package/lib/opencode-go-planner.js +339 -0
- package/lib/opencode-go-planner.js.map +1 -0
- package/lib/opencode-go-profile.d.ts +57 -0
- package/lib/opencode-go-profile.js +103 -0
- package/lib/opencode-go-profile.js.map +1 -0
- package/lib/opencode-go-scheduler.d.ts +128 -0
- package/lib/opencode-go-scheduler.js +241 -0
- package/lib/opencode-go-scheduler.js.map +1 -0
- package/lib/opencode-go-source.d.ts +117 -0
- package/lib/opencode-go-source.js +331 -0
- package/lib/opencode-go-source.js.map +1 -0
- package/lib/opencode-go-store.d.ts +18 -0
- package/lib/opencode-go-store.js +68 -0
- package/lib/opencode-go-store.js.map +1 -0
- package/lib/opencode-go-sync.d.ts +94 -0
- package/lib/opencode-go-sync.js +364 -0
- package/lib/opencode-go-sync.js.map +1 -0
- package/lib/opencode-go-writer.d.ts +132 -0
- package/lib/opencode-go-writer.js +966 -0
- package/lib/opencode-go-writer.js.map +1 -0
- package/lib/provider-native.d.ts +3 -1
- package/lib/provider-native.js +4 -2
- package/lib/provider-native.js.map +1 -1
- package/lib/remote-catalog.d.ts +37 -0
- package/lib/remote-catalog.js +261 -3
- package/lib/remote-catalog.js.map +1 -1
- package/package.json +18 -18
- package/src/builtin-catalog-snapshot.ts +18 -11
- package/src/index.ts +873 -12
- package/src/opencode-go-diagnose.ts +222 -0
- package/src/opencode-go-grouping.ts +97 -0
- package/src/opencode-go-journal.ts +458 -0
- package/src/opencode-go-migrate.ts +1694 -0
- package/src/opencode-go-migration.ts +552 -0
- package/src/opencode-go-planner.ts +505 -0
- package/src/opencode-go-profile.ts +114 -0
- package/src/opencode-go-scheduler.ts +315 -0
- package/src/opencode-go-source.ts +424 -0
- package/src/opencode-go-store.ts +73 -0
- package/src/opencode-go-sync.ts +503 -0
- package/src/opencode-go-writer.ts +1189 -0
- package/src/provider-native.ts +3 -1
- package/src/remote-catalog.ts +293 -3
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// P1c-2: async timer + scheduling layer for the opencode-go sync round.
|
|
2
|
+
//
|
|
3
|
+
// This module owns ONLY scheduling (design §6.3 / §14.6): startup delay +
|
|
4
|
+
// jitter, the 60min (floor 15) interval with live re-arm, single-flight with
|
|
5
|
+
// the manual /model-sync go command, failure backoff with caps, and timer
|
|
6
|
+
// cleanup on plugin unload. It does NOT run the round itself — `runRound` is
|
|
7
|
+
// injected and is normally index.ts's runGoRound (source → planner → writer).
|
|
8
|
+
//
|
|
9
|
+
// Every clock/random input is injected (GoSchedulerTimers / GoSchedulerRandom),
|
|
10
|
+
// so the whole state machine runs deterministically under a fake timer: no
|
|
11
|
+
// real sleep, no network. The production adapters live in index.ts.
|
|
12
|
+
//
|
|
13
|
+
// Last-good safety: scheduling never persists anything. Backoff state is an
|
|
14
|
+
// in-memory streak only. A failed round returns before the writer, so settings
|
|
15
|
+
// and the ownership ledger keep their last-good values (design §6.3 "离线:
|
|
16
|
+
// settings 中 last-good 继续可用"). M-4 zero-write is enforced by routeWriter
|
|
17
|
+
// inside the round (P1d-1); this layer only adds the M-5 `applying` drop.
|
|
18
|
+
/** Cordis service seams used by index.ts to inject test doubles. */
|
|
19
|
+
export const GO_SCHEDULER_TIMERS_SERVICE = 'goSchedulerTimers';
|
|
20
|
+
export const GO_SCHEDULER_RANDOM_SERVICE = 'goSchedulerRandom';
|
|
21
|
+
// Implementation constants. Design §6.3 / ADR-007 fix the interval floor and
|
|
22
|
+
// the transport/auth caps; the backoff BASE and the startup jitter window are
|
|
23
|
+
// not specified numerically by the design, so these are the documented
|
|
24
|
+
// implementation choices (kept exported for tests).
|
|
25
|
+
export const GO_INTERVAL_MIN_MINUTES = 15;
|
|
26
|
+
export const GO_INTERVAL_DEFAULT_MINUTES = 60;
|
|
27
|
+
export const GO_STARTUP_JITTER_MAX_MS = 5_000;
|
|
28
|
+
export const GO_TRANSPORT_BACKOFF_BASE_MS = 60_000;
|
|
29
|
+
export const GO_TRANSPORT_BACKOFF_CAP_MS = 30 * 60_000;
|
|
30
|
+
export const GO_AUTH_BACKOFF_BASE_MS = 60 * 60_000;
|
|
31
|
+
export const GO_AUTH_BACKOFF_CAP_MS = 6 * 60 * 60_000;
|
|
32
|
+
/** Clamp an interval to the design floor; non-finite falls back to the default. */
|
|
33
|
+
export function clampGoIntervalMinutes(value) {
|
|
34
|
+
if (!Number.isFinite(value))
|
|
35
|
+
return GO_INTERVAL_DEFAULT_MINUTES;
|
|
36
|
+
return Math.max(GO_INTERVAL_MIN_MINUTES, Math.floor(value));
|
|
37
|
+
}
|
|
38
|
+
/** startupDelaySeconds*1000 plus bounded jitter (random is in [0,1)). */
|
|
39
|
+
export function goStartupDelayMs(seconds, random) {
|
|
40
|
+
const base = Number.isFinite(seconds) && seconds > 0 ? seconds * 1000 : 0;
|
|
41
|
+
const r = Math.min(1, Math.max(0, Number.isFinite(random) ? random : 0));
|
|
42
|
+
return base + Math.floor(r * GO_STARTUP_JITTER_MAX_MS);
|
|
43
|
+
}
|
|
44
|
+
/** Exponential backoff with per-class cap (design §6.3). */
|
|
45
|
+
export function goBackoffDelayMs(streak, failureKind) {
|
|
46
|
+
const n = Math.max(1, Math.floor(streak));
|
|
47
|
+
const auth = failureKind === 'auth' || failureKind === 'entitlement';
|
|
48
|
+
const base = auth ? GO_AUTH_BACKOFF_BASE_MS : GO_TRANSPORT_BACKOFF_BASE_MS;
|
|
49
|
+
const cap = auth ? GO_AUTH_BACKOFF_CAP_MS : GO_TRANSPORT_BACKOFF_CAP_MS;
|
|
50
|
+
return Math.min(cap, base * 2 ** (n - 1));
|
|
51
|
+
}
|
|
52
|
+
/** Report text for a skipped round — always states the reason explicitly. */
|
|
53
|
+
export function goSchedulerSkipReport(reason, trigger) {
|
|
54
|
+
const when = `opencode-go scheduler (${trigger})`;
|
|
55
|
+
switch (reason) {
|
|
56
|
+
case 'disabled':
|
|
57
|
+
// Keep the legacy phrase "disabled — set opencode.go.enabled=true" so
|
|
58
|
+
// manual /model-sync go reports stay byte-compatible with P1c-1.
|
|
59
|
+
return `${when}: skipped — opencode.go sync is disabled — set opencode.go.enabled=true; no request, no settings write. (The migration gate is enforced separately by routeWriter on every write path.)`;
|
|
60
|
+
case 'already-in-flight':
|
|
61
|
+
return `${when}: skipped — a go round is already in flight (single-flight); no queue, no retry, no settings write (design §14.6).`;
|
|
62
|
+
case 'migration-applying':
|
|
63
|
+
return `${when}: skipped — migration apply in progress (M-5); no queue, no retry, no settings write (design §14.6).`;
|
|
64
|
+
case 'disposed':
|
|
65
|
+
return `${when}: skipped — scheduler disposed (plugin unload); no request, no settings write.`;
|
|
66
|
+
default:
|
|
67
|
+
return `${when}: skipped — ${reason}; no request, no settings write.`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function isBackoffFailure(outcome) {
|
|
71
|
+
// Configuration/skip states (disabled, no-key, settings-unavailable) are not
|
|
72
|
+
// failures — they keep the normal interval. Only source failures back off.
|
|
73
|
+
return outcome.reason === 'source-failed' || outcome.failureKind !== undefined;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The scheduler state machine. One instance per plugin activation; it owns a
|
|
77
|
+
* single timer handle and a single in-flight flag shared by auto and manual
|
|
78
|
+
* triggers (that is the single-flight lock).
|
|
79
|
+
*/
|
|
80
|
+
export class GoScheduler {
|
|
81
|
+
config;
|
|
82
|
+
timers;
|
|
83
|
+
random;
|
|
84
|
+
runRound;
|
|
85
|
+
report;
|
|
86
|
+
isApplying;
|
|
87
|
+
handle;
|
|
88
|
+
started = false;
|
|
89
|
+
inFlight = false;
|
|
90
|
+
disposed = false;
|
|
91
|
+
streak = 0;
|
|
92
|
+
lastFailureKind;
|
|
93
|
+
/** Single lifetime signal: dispose() aborts the round that is currently in flight. */
|
|
94
|
+
abort = new AbortController();
|
|
95
|
+
constructor(deps) {
|
|
96
|
+
this.config = deps.config;
|
|
97
|
+
this.timers = deps.timers;
|
|
98
|
+
this.random = deps.random;
|
|
99
|
+
this.runRound = deps.runRound;
|
|
100
|
+
this.report = deps.report;
|
|
101
|
+
this.isApplying = deps.isApplying;
|
|
102
|
+
}
|
|
103
|
+
/** Arm the startup timer. No-op when disabled — zero triggers at enabled=false. */
|
|
104
|
+
start() {
|
|
105
|
+
if (this.started || this.disposed)
|
|
106
|
+
return;
|
|
107
|
+
this.started = true;
|
|
108
|
+
const cfg = this.config();
|
|
109
|
+
if (!cfg.enabled)
|
|
110
|
+
return;
|
|
111
|
+
this.arm(goStartupDelayMs(cfg.startupDelaySeconds, this.random.next()), 'startup');
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Live re-arm after a settings edit. Cancels the pending timer and reads
|
|
115
|
+
* fresh config; a round already in flight keeps its lock and picks up the
|
|
116
|
+
* new config when it schedules its own successor.
|
|
117
|
+
*/
|
|
118
|
+
rearm() {
|
|
119
|
+
if (this.disposed || !this.started)
|
|
120
|
+
return;
|
|
121
|
+
this.cancel();
|
|
122
|
+
if (this.inFlight)
|
|
123
|
+
return;
|
|
124
|
+
this.armFromConfig();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Reset backoff after a credential change. Clears the in-memory streak and
|
|
128
|
+
* re-arms at the normal interval instead of waiting out a capped (up to 6h)
|
|
129
|
+
* backoff — a fixed key must not stay frozen for hours (design §6.3). The
|
|
130
|
+
* caller's listener is disposed with the plugin; a disposed scheduler is a
|
|
131
|
+
* no-op.
|
|
132
|
+
*/
|
|
133
|
+
resetBackoff() {
|
|
134
|
+
this.clearBackoff();
|
|
135
|
+
if (this.disposed || !this.started || this.inFlight)
|
|
136
|
+
return;
|
|
137
|
+
this.armFromConfig();
|
|
138
|
+
}
|
|
139
|
+
/** Cancel every timer and abort a round already in flight (design §6.3 卸载). */
|
|
140
|
+
dispose() {
|
|
141
|
+
this.disposed = true;
|
|
142
|
+
this.abort.abort();
|
|
143
|
+
this.cancel();
|
|
144
|
+
}
|
|
145
|
+
get isInFlight() {
|
|
146
|
+
return this.inFlight;
|
|
147
|
+
}
|
|
148
|
+
get failureStreak() {
|
|
149
|
+
return this.streak;
|
|
150
|
+
}
|
|
151
|
+
/** Manual /model-sync go trigger — shares the single-flight lock with auto rounds. */
|
|
152
|
+
triggerManual(options = {}) {
|
|
153
|
+
return this.fire('manual', options.adopt === true);
|
|
154
|
+
}
|
|
155
|
+
arm(delayMs, trigger) {
|
|
156
|
+
this.cancel();
|
|
157
|
+
// Returning the promise is harmless to real setTimeout (return value is
|
|
158
|
+
// ignored) and lets a fake timer await the whole round deterministically.
|
|
159
|
+
this.handle = this.timers.setTimeout(() => this.fire(trigger), Math.max(0, delayMs));
|
|
160
|
+
}
|
|
161
|
+
cancel() {
|
|
162
|
+
if (this.handle !== undefined) {
|
|
163
|
+
this.timers.clearTimeout(this.handle);
|
|
164
|
+
this.handle = undefined;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
armFromConfig() {
|
|
168
|
+
const cfg = this.config();
|
|
169
|
+
if (!cfg.enabled)
|
|
170
|
+
return;
|
|
171
|
+
if (this.streak > 0) {
|
|
172
|
+
this.arm(goBackoffDelayMs(this.streak, this.lastFailureKind), 'backoff');
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
this.arm(clampGoIntervalMinutes(cfg.intervalMinutes) * 60_000, 'interval');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/** Forget the entire backoff history (transport === auth) — used by reset paths. */
|
|
179
|
+
clearBackoff() {
|
|
180
|
+
this.streak = 0;
|
|
181
|
+
this.lastFailureKind = undefined;
|
|
182
|
+
}
|
|
183
|
+
async fire(trigger, adopt = false) {
|
|
184
|
+
if (this.disposed)
|
|
185
|
+
return this.skip('disposed', trigger);
|
|
186
|
+
if (!this.config().enabled)
|
|
187
|
+
return this.skip('disabled', trigger);
|
|
188
|
+
if (this.inFlight)
|
|
189
|
+
return this.skip('already-in-flight', trigger);
|
|
190
|
+
// M-5: an in-progress migration owns the routes; drop the round now rather
|
|
191
|
+
// than racing a half-applied settings document. Same non-queueing rule as
|
|
192
|
+
// the single-flight lock (§14.6).
|
|
193
|
+
if (this.isApplying !== undefined && await this.isApplying() === true)
|
|
194
|
+
return this.skip('migration-applying', trigger);
|
|
195
|
+
// The timer that fired is now consumed; a new one is armed after the round.
|
|
196
|
+
this.cancel();
|
|
197
|
+
this.inFlight = true;
|
|
198
|
+
// A manual round is an explicit force: forget any accumulated backoff
|
|
199
|
+
// before it runs (design §6.3 "手动 force 必须重置退避").
|
|
200
|
+
if (trigger === 'manual')
|
|
201
|
+
this.clearBackoff();
|
|
202
|
+
let result;
|
|
203
|
+
try {
|
|
204
|
+
const raw = await this.runRound({ trigger, adopt, signal: this.abort.signal });
|
|
205
|
+
if (raw.ok) {
|
|
206
|
+
this.streak = 0;
|
|
207
|
+
this.lastFailureKind = undefined;
|
|
208
|
+
}
|
|
209
|
+
else if (isBackoffFailure(raw)) {
|
|
210
|
+
this.streak += 1;
|
|
211
|
+
this.lastFailureKind = raw.failureKind;
|
|
212
|
+
}
|
|
213
|
+
result = { ...raw, skipped: false };
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
217
|
+
this.streak += 1;
|
|
218
|
+
this.lastFailureKind = 'transport';
|
|
219
|
+
result = {
|
|
220
|
+
ok: false,
|
|
221
|
+
reason: 'scheduler-error',
|
|
222
|
+
text: `opencode-go scheduler: round error — ${message}; kept last-good, no further settings write`,
|
|
223
|
+
failureKind: 'transport',
|
|
224
|
+
skipped: false,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
finally {
|
|
228
|
+
this.inFlight = false;
|
|
229
|
+
}
|
|
230
|
+
this.report(result.text);
|
|
231
|
+
if (!this.disposed)
|
|
232
|
+
this.armFromConfig();
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
skip(reason, trigger) {
|
|
236
|
+
const text = goSchedulerSkipReport(reason, trigger);
|
|
237
|
+
this.report(text);
|
|
238
|
+
return { ok: false, reason, text, skipped: true };
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
//# sourceMappingURL=opencode-go-scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode-go-scheduler.js","sourceRoot":"","sources":["../src/opencode-go-scheduler.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,0EAA0E;AAC1E,6EAA6E;AAC7E,8EAA8E;AAC9E,EAAE;AACF,gFAAgF;AAChF,2EAA2E;AAC3E,oEAAoE;AACpE,EAAE;AACF,4EAA4E;AAC5E,+EAA+E;AAC/E,yEAAyE;AACzE,yEAAyE;AACzE,0EAA0E;AAI1E,oEAAoE;AACpE,MAAM,CAAC,MAAM,2BAA2B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vB,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACxB,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,IAAI,CAAC,aAAa,EAAE,CAAA;QACxC,OAAO,MAAM,CAAA;IACf,CAAC;IAEO,IAAI,CAAC,MAAc,EAAE,OAAkB;QAC7C,MAAM,IAAI,GAAG,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACnD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACjB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IACnD,CAAC;CACF"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/** Official model-listing endpoint (design §6.2.6 default). */
|
|
2
|
+
export declare const OPENCODE_GO_MODELS_URL = "https://opencode.ai/inference/go/v1/models";
|
|
3
|
+
/** P0 fixed default polling interval for the go source (design §6.2.6). */
|
|
4
|
+
export declare const OPENCODE_GO_DEFAULT_INTERVAL_MINUTES = 60;
|
|
5
|
+
/** Explicit UA — the gateway bans default library UAs with CF 1010 (05 §1). */
|
|
6
|
+
export declare const GO_USER_AGENT = "dsh-model-sync/0.10.0";
|
|
7
|
+
/** Auth states carried by the diagnostic report (design §6.1 SourceSnapshot). */
|
|
8
|
+
export type GoAuthStatus = 'unknown' | 'ok' | 'invalid' | 'not-entitled' | 'unreachable';
|
|
9
|
+
/** Failure taxonomy (design §6.1 lastError.kind + no-key for the opt-out path). */
|
|
10
|
+
export type GoFailureKind = 'auth' | 'entitlement' | 'transport' | 'parse' | 'offline' | 'no-key';
|
|
11
|
+
/** One normalized official model entry. `created` is intentionally absent. */
|
|
12
|
+
export interface GoModelRecord {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
canonicalId?: string;
|
|
16
|
+
releaseDate?: string;
|
|
17
|
+
lastUpdated?: string;
|
|
18
|
+
contextWindow?: number;
|
|
19
|
+
maxOutput?: number;
|
|
20
|
+
inputModalities: string[];
|
|
21
|
+
reasoning?: {
|
|
22
|
+
supported: boolean;
|
|
23
|
+
efforts: string[];
|
|
24
|
+
};
|
|
25
|
+
/** Keys of the official `api` dictionary (the protocol names). */
|
|
26
|
+
protocols: string[];
|
|
27
|
+
recommendedProtocol?: string;
|
|
28
|
+
/** Official per-protocol `base_url`, used by P1 route planning only. */
|
|
29
|
+
baseUrls: Record<string, string>;
|
|
30
|
+
provenance: 'go-official';
|
|
31
|
+
}
|
|
32
|
+
/** Failure detail attached to a source result (never contains a key value). */
|
|
33
|
+
export interface GoSourceError {
|
|
34
|
+
kind: GoFailureKind;
|
|
35
|
+
status?: number;
|
|
36
|
+
message: string;
|
|
37
|
+
}
|
|
38
|
+
/** Outcome of one source read. */
|
|
39
|
+
export interface GoSourceResult {
|
|
40
|
+
ok: boolean;
|
|
41
|
+
entries: GoModelRecord[];
|
|
42
|
+
authStatus: GoAuthStatus;
|
|
43
|
+
/** sha256(key) first 16 hex; '-' when no key was available. */
|
|
44
|
+
keyFingerprint: string;
|
|
45
|
+
/** sha256 of canonical normalized JSON; excludes `created`. */
|
|
46
|
+
payloadHash?: string;
|
|
47
|
+
observedAt: number;
|
|
48
|
+
error?: GoSourceError;
|
|
49
|
+
}
|
|
50
|
+
/** Outcome of the unauthenticated *public* catalog read (classification only, C2). */
|
|
51
|
+
export interface GoPublicCatalogResult {
|
|
52
|
+
ok: boolean;
|
|
53
|
+
ids: string[];
|
|
54
|
+
error?: GoSourceError;
|
|
55
|
+
}
|
|
56
|
+
/** Minimal response shape the fetch accepts (injected in tests). */
|
|
57
|
+
export interface GoFetchResponse {
|
|
58
|
+
status: number;
|
|
59
|
+
json(): Promise<unknown>;
|
|
60
|
+
}
|
|
61
|
+
/** Injectable fetch: a plain function, like provider-native.ts's FetchLike. */
|
|
62
|
+
export type GoFetchLike = (url: string, init: {
|
|
63
|
+
headers: Record<string, string>;
|
|
64
|
+
signal: AbortSignal;
|
|
65
|
+
}) => Promise<GoFetchResponse>;
|
|
66
|
+
/** Options for one source read. */
|
|
67
|
+
export interface FetchGoOfficialOptions {
|
|
68
|
+
url?: string;
|
|
69
|
+
apiKey?: string;
|
|
70
|
+
timeoutMs?: number;
|
|
71
|
+
observedAt?: number;
|
|
72
|
+
fetchImpl?: GoFetchLike;
|
|
73
|
+
/** Plugin-lifetime signal: aborting it aborts the in-flight fetch (design §6.3 卸载). */
|
|
74
|
+
signal?: AbortSignal;
|
|
75
|
+
}
|
|
76
|
+
/** Irreversible key fingerprint — the only key-derived value ever retained. */
|
|
77
|
+
export declare function fingerprintKey(key: string): string;
|
|
78
|
+
/** Hash of the normalized set. `created` never reaches this function. */
|
|
79
|
+
export declare function computeGoPayloadHash(entries: readonly GoModelRecord[]): string;
|
|
80
|
+
/**
|
|
81
|
+
* Parse the official `{ object: 'list', data: [...] }` payload into normalized
|
|
82
|
+
* records. Unknown fields (cost, sdk, go.monthly_usage, …) are dropped; every
|
|
83
|
+
* field the diagnostic or P1 planning needs is mapped explicitly. `created`
|
|
84
|
+
* is deliberately not copied, so it can never enter the payload hash.
|
|
85
|
+
*/
|
|
86
|
+
export declare function parseGoModelsPayload(value: unknown): GoModelRecord[];
|
|
87
|
+
export interface GoHttpClassification {
|
|
88
|
+
authStatus: GoAuthStatus;
|
|
89
|
+
failureKind?: GoFailureKind;
|
|
90
|
+
/** Human-readable reason; never includes a key value. */
|
|
91
|
+
message: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Classify an official HTTP response. 401 = invalid key, 403 = either the
|
|
95
|
+
* documented EntitlementError (not-entitled) or the Cloudflare 1010 UA ban
|
|
96
|
+
* (transport), 5xx/429 = transport. Only 200 is a usable source.
|
|
97
|
+
*/
|
|
98
|
+
export declare function classifyGoHttpStatus(status: number, body: unknown): GoHttpClassification;
|
|
99
|
+
/**
|
|
100
|
+
* Read the official listing once. No key → no request (design V4), no entries,
|
|
101
|
+
* status 'unknown'. With a key the request carries Bearer + explicit UA; the
|
|
102
|
+
* key itself is never logged or stored, only its fingerprint.
|
|
103
|
+
*/
|
|
104
|
+
/**
|
|
105
|
+
* Read the official *unauthenticated* public listing for one purpose only:
|
|
106
|
+
* answering "is this id official?" during migration planning (design §14.2).
|
|
107
|
+
* Per C2 the public list is NEVER a servable source — no authorization header
|
|
108
|
+
* is sent, no model is written to settings from it. If the read fails the
|
|
109
|
+
* caller must fail closed (ids become `unclassified`, never deleted).
|
|
110
|
+
*/
|
|
111
|
+
export declare function fetchGoPublicCatalogIds(options?: {
|
|
112
|
+
url?: string;
|
|
113
|
+
timeoutMs?: number;
|
|
114
|
+
fetchImpl?: GoFetchLike;
|
|
115
|
+
signal?: AbortSignal;
|
|
116
|
+
}): Promise<GoPublicCatalogResult>;
|
|
117
|
+
export declare function fetchGoOfficialModels(options?: FetchGoOfficialOptions): Promise<GoSourceResult>;
|