vidspotai-shared 1.0.141 → 1.0.143

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.
@@ -1 +1 @@
1
- {"version":3,"file":"bytedance.d.ts","sourceRoot":"","sources":["../../../../src/globals/aiModels/providers/bytedance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAWxC,eAAO,MAAM,gBAAgB,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,CA4avE,CAAC"}
1
+ {"version":3,"file":"bytedance.d.ts","sourceRoot":"","sources":["../../../../src/globals/aiModels/providers/bytedance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAWxC,eAAO,MAAM,gBAAgB,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,CA4bvE,CAAC"}
@@ -137,8 +137,12 @@ exports.bytedanceConfigs = {
137
137
  referenceVideoUrls: { max: 10 },
138
138
  referenceAudioUrls: { max: 10 },
139
139
  },
140
- requestPerMin: 180, // individual-tier; bumps to 600 for enterprise
141
- concurrentRequests: 3, // individual-tier; bumps to 10 for enterprise
140
+ // REMOVED FOR v1 — kept for reference: individual-tier limits.
141
+ // requestPerMin: 180, // individual-tier; bumps to 600 for enterprise
142
+ // concurrentRequests: 3, // individual-tier; bumps to 10 for enterprise
143
+ // Enterprise tier confirmed in the Ark console 2026-11-11 (non-4K: 10 concurrent / 600 RPM).
144
+ requestPerMin: 600,
145
+ concurrentRequests: 10,
142
146
  cost: {
143
147
  // Online-inference USD per 1K tokens (docs list per-M: 6.40 / 10.70).
144
148
  // 1080p is priced (per-M 11.7 / 7.0, 2026-09-29) but not offered in
@@ -184,8 +188,12 @@ exports.bytedanceConfigs = {
184
188
  referenceVideoUrls: { max: 3 },
185
189
  referenceAudioUrls: { max: 3 },
186
190
  },
187
- requestPerMin: 180, // individual-tier; bumps to 600 for enterprise
188
- concurrentRequests: 3, // individual-tier; bumps to 10 for enterprise
191
+ // REMOVED FOR v1 — kept for reference: individual-tier limits.
192
+ // requestPerMin: 180, // individual-tier; bumps to 600 for enterprise
193
+ // concurrentRequests: 3, // individual-tier; bumps to 10 for enterprise
194
+ // Enterprise tier confirmed in the Ark console 2026-11-11 (non-4K: 10 concurrent / 600 RPM).
195
+ requestPerMin: 600,
196
+ concurrentRequests: 10,
189
197
  cost: {
190
198
  videoInput: {
191
199
  "480p": 0.0043,
@@ -219,8 +227,12 @@ exports.bytedanceConfigs = {
219
227
  referenceVideoUrls: { max: 3 },
220
228
  referenceAudioUrls: { max: 3 },
221
229
  },
222
- requestPerMin: 180,
223
- concurrentRequests: 3,
230
+ // REMOVED FOR v1 — kept for reference: individual-tier limits.
231
+ // requestPerMin: 180,
232
+ // concurrentRequests: 3,
233
+ // Enterprise tier confirmed in the Ark console 2026-11-11 (non-4K: 10 concurrent / 600 RPM).
234
+ requestPerMin: 600,
235
+ concurrentRequests: 10,
224
236
  cost: {
225
237
  // List price (per-M 3.3 / 5.6). The BytePlus 25%-off promo (extended
226
238
  // to 2026-10-07) applies to enterprise accounts only; we're on the
@@ -265,8 +277,12 @@ exports.bytedanceConfigs = {
265
277
  referenceVideoUrls: { max: 3 },
266
278
  referenceAudioUrls: { max: 3 },
267
279
  },
268
- requestPerMin: 180,
269
- concurrentRequests: 3,
280
+ // REMOVED FOR v1 — kept for reference: individual-tier limits.
281
+ // requestPerMin: 180,
282
+ // concurrentRequests: 3,
283
+ // Enterprise tier confirmed in the Ark console 2026-11-11 (non-4K: 10 concurrent / 600 RPM).
284
+ requestPerMin: 600,
285
+ concurrentRequests: 10,
270
286
  cost: {
271
287
  // List price (per-M 2.1 / 3.5). The BytePlus 60%-off promo (extended
272
288
  // to 2026-10-07) is enterprise-only — see 2.0 Fast above.
@@ -1,5 +1,14 @@
1
1
  import { z } from "zod";
2
2
  import { ChatRequest, ChatResponse, LlmCaller, StructuredRequest, StructuredResponse, StructuredWithToolsRequest } from "./llmCaller";
3
+ /**
4
+ * Per-process cooldown for a provider whose ACCOUNT is unusable (spend cap /
5
+ * no credit / revoked key). While cooling, calls that carry a fallbackModel go
6
+ * straight to it instead of paying a failed round-trip (and a Slack page) on
7
+ * the dead provider first. Short so a top-up / limit raise recovers on its own.
8
+ */
9
+ export declare const PROVIDER_ACCOUNT_COOLDOWN_MS: number;
10
+ /** Test hook. */
11
+ export declare function resetProviderAccountCooldowns(): void;
3
12
  /**
4
13
  * Provider-dispatching LlmCaller — the native replacement for GatewayLlmCaller
5
14
  * as the wired singleton (LLM_NATIVE_MIGRATION_PLAN Phase 5).
@@ -1 +1 @@
1
- {"version":3,"file":"llmCallerRouting.d.ts","sourceRoot":"","sources":["../../../src/services/agent/llmCallerRouting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,WAAW,EACX,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EAClB,0BAA0B,EAC3B,MAAM,aAAa,CAAC;AAKrB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB;AAED,qBAAa,wBAAyB,YAAW,SAAS;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,eAAe;IAErD,OAAO,CAAC,IAAI;IAYN,IAAI,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAoB7C,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EACrC,GAAG,EAAE,iBAAiB,CAAC,CAAC,C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AY,CAAC;IAyB7C,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EACrC,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACxB,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;IA2BjC;;;;;;OAMG;IACH,gBAAgB,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EACrC,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACxB;QACD,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;QAC9B,MAAM,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;KACxC;IAYD;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IAgCzB;;;;;OAKG;IACG,mBAAmB,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EAC9C,GAAG,EAAE,0BAA0B,CAAC,CAAC,CAAC,GACjC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;CAuBlC"}
@@ -1,8 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProviderRoutingLlmCaller = void 0;
3
+ exports.ProviderRoutingLlmCaller = exports.PROVIDER_ACCOUNT_COOLDOWN_MS = void 0;
4
+ exports.resetProviderAccountCooldowns = resetProviderAccountCooldowns;
4
5
  const llmModelRegistry_1 = require("./llmModelRegistry");
6
+ // REMOVED FOR v1 — kept for reference: fallback was transient-only.
7
+ // import { isTransientLlmError } from "./llmRetry";
5
8
  const llmRetry_1 = require("./llmRetry");
9
+ const logger_1 = require("../../utils/logger");
10
+ /**
11
+ * Per-process cooldown for a provider whose ACCOUNT is unusable (spend cap /
12
+ * no credit / revoked key). While cooling, calls that carry a fallbackModel go
13
+ * straight to it instead of paying a failed round-trip (and a Slack page) on
14
+ * the dead provider first. Short so a top-up / limit raise recovers on its own.
15
+ */
16
+ exports.PROVIDER_ACCOUNT_COOLDOWN_MS = 10 * 60000;
17
+ const accountCooldownUntil = new Map();
18
+ function isCoolingDown(provider) {
19
+ const until = accountCooldownUntil.get(provider);
20
+ return until !== undefined && until > Date.now();
21
+ }
22
+ function noteAccountFailure(model, err) {
23
+ if (!(0, llmRetry_1.isProviderAccountUnavailableError)(err))
24
+ return;
25
+ const provider = (0, llmModelRegistry_1.providerFor)(model);
26
+ if (!isCoolingDown(provider)) {
27
+ logger_1.logger.warn("LLM provider account unavailable — routing to fallback models", {
28
+ provider,
29
+ modelId: model.modelId,
30
+ cooldownMs: exports.PROVIDER_ACCOUNT_COOLDOWN_MS,
31
+ err: err instanceof Error ? err.message.slice(0, 300) : String(err).slice(0, 300),
32
+ });
33
+ }
34
+ accountCooldownUntil.set(provider, Date.now() + exports.PROVIDER_ACCOUNT_COOLDOWN_MS);
35
+ }
36
+ /** Test hook. */
37
+ function resetProviderAccountCooldowns() {
38
+ accountCooldownUntil.clear();
39
+ }
6
40
  class ProviderRoutingLlmCaller {
7
41
  constructor(callers) {
8
42
  this.callers = callers;
@@ -24,12 +58,17 @@ class ProviderRoutingLlmCaller {
24
58
  // should not attempt its own (it can't reach other providers anyway).
25
59
  return this.pick(model).chat({ ...req, model, fallbackModel: undefined });
26
60
  };
61
+ if (req.fallbackModel && isCoolingDown((0, llmModelRegistry_1.providerFor)(req.model))) {
62
+ const out = await run(req.fallbackModel);
63
+ return { ...out, attemptedModels: [...attempted], usedFallback: true };
64
+ }
27
65
  try {
28
66
  const out = await run(req.model);
29
67
  return { ...out, attemptedModels: [...attempted], usedFallback: false };
30
68
  }
31
69
  catch (err) {
32
- if (req.fallbackModel && (0, llmRetry_1.isTransientLlmError)(err)) {
70
+ noteAccountFailure(req.model, err);
71
+ if (req.fallbackModel && (0, llmRetry_1.isFallbackEligibleLlmError)(err)) {
33
72
  const out = await run(req.fallbackModel);
34
73
  return { ...out, attemptedModels: [...attempted], usedFallback: true };
35
74
  }
@@ -46,12 +85,17 @@ class ProviderRoutingLlmCaller {
46
85
  fallbackModel: undefined,
47
86
  });
48
87
  };
88
+ if (req.fallbackModel && isCoolingDown((0, llmModelRegistry_1.providerFor)(req.model))) {
89
+ const out = await run(req.fallbackModel);
90
+ return { ...out, attemptedModels: [...attempted], usedFallback: true };
91
+ }
49
92
  try {
50
93
  const out = await run(req.model);
51
94
  return { ...out, attemptedModels: [...attempted], usedFallback: false };
52
95
  }
53
96
  catch (err) {
54
- if (req.fallbackModel && (0, llmRetry_1.isTransientLlmError)(err)) {
97
+ noteAccountFailure(req.model, err);
98
+ if (req.fallbackModel && (0, llmRetry_1.isFallbackEligibleLlmError)(err)) {
55
99
  const out = await run(req.fallbackModel);
56
100
  return { ...out, attemptedModels: [...attempted], usedFallback: true };
57
101
  }
@@ -66,8 +110,10 @@ class ProviderRoutingLlmCaller {
66
110
  * handles it.
67
111
  */
68
112
  structuredStream(req) {
69
- const caller = this.pick(req.model);
70
- const streamReq = { ...req, fallbackModel: undefined };
113
+ // Primary provider's account is known-dead → stream from the fallback.
114
+ const model = req.fallbackModel && isCoolingDown((0, llmModelRegistry_1.providerFor)(req.model)) ? req.fallbackModel : req.model;
115
+ const caller = this.pick(model);
116
+ const streamReq = { ...req, model, fallbackModel: undefined };
71
117
  if (typeof caller.structuredStream === "function") {
72
118
  return caller.structuredStream(streamReq);
73
119
  }
@@ -114,11 +160,25 @@ class ProviderRoutingLlmCaller {
114
160
  */
115
161
  async structuredWithTools(req) {
116
162
  const caller = this.pick(req.model);
163
+ if (isCoolingDown((0, llmModelRegistry_1.providerFor)(req.model))) {
164
+ // Server tools are provider-specific, so there's no cross-provider
165
+ // fallback here — fail fast with an account error the caller (Planner
166
+ // research path) downgrades to the plain dispatcher on.
167
+ throw Object.assign(new Error("provider account unavailable (usage limits) — cooling down"), {
168
+ status: 400,
169
+ });
170
+ }
117
171
  if (typeof caller.structuredWithTools !== "function") {
118
172
  throw new Error(`ProviderRoutingLlmCaller: provider for model=${req.model.modelId} ` +
119
173
  `does not support server-side tools (structuredWithTools).`);
120
174
  }
121
- return caller.structuredWithTools(req);
175
+ try {
176
+ return await caller.structuredWithTools(req);
177
+ }
178
+ catch (err) {
179
+ noteAccountFailure(req.model, err);
180
+ throw err;
181
+ }
122
182
  }
123
183
  }
124
184
  exports.ProviderRoutingLlmCaller = ProviderRoutingLlmCaller;
@@ -54,4 +54,17 @@ export interface RetryOptions {
54
54
  * wrapped on the final attempt; pre-wrapped `TransientLlmError`s pass through.
55
55
  */
56
56
  export declare function withRetry<T>(fn: () => Promise<T>, opts?: RetryOptions): Promise<T>;
57
+ /**
58
+ * Provider ACCOUNT is unusable (spend cap, no credit, quota, revoked key) —
59
+ * deterministic for THIS provider, but another provider will succeed.
60
+ *
61
+ * Prod 2026-11-18/19: Anthropic returned 400 "You have reached your specified
62
+ * workspace API usage limits. You will regain access on 2026-12-01" for every
63
+ * planner/persona call. A 400 is not transient, so the dispatcher never tried
64
+ * the OpenAI `fallbackModel` and agent planning was down for every user.
65
+ * These errors must fall back cross-provider (and never be retried in place).
66
+ */
67
+ export declare function isProviderAccountUnavailableError(err: unknown): boolean;
68
+ /** True when the dispatcher should try `fallbackModel` after `err`. */
69
+ export declare function isFallbackEligibleLlmError(err: unknown): boolean;
57
70
  //# sourceMappingURL=llmRetry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"llmRetry.d.ts","sourceRoot":"","sources":["../../../src/services/agent/llmRetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAGxC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;gBADxB,OAAO,EAAE,MAAM,EACN,KAAK,CAAC,EAAE,OAAO,YAAA;CAK3B;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,iBAAiB,CAE1E;AAED,sEAAsE;AACtE,eAAO,MAAM,uBAAuB,aAElC,CAAC;AAEH;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OA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,CAAC,EACpB,IAAI,GAAE,YAAiB,GACtB,OAAO,CAAC,CAAC,CAAC,CA6BZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,iCAAiC,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAWvE;AAED,uEAAuE;AACvE,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAEhE"}
@@ -21,6 +21,8 @@ exports.TRANSIENT_HTTP_STATUSES = exports.TransientLlmError = void 0;
21
21
  exports.isTransientLlmError = isTransientLlmError;
22
22
  exports.isTransientError = isTransientError;
23
23
  exports.withRetry = withRetry;
24
+ exports.isProviderAccountUnavailableError = isProviderAccountUnavailableError;
25
+ exports.isFallbackEligibleLlmError = isFallbackEligibleLlmError;
24
26
  /**
25
27
  * Marks an error worth retrying / falling back on. The provider-dispatching caller
26
28
  * catches this specifically to attempt `fallbackModel`; deterministic errors
@@ -100,3 +102,30 @@ async function withRetry(fn, opts = {}) {
100
102
  }
101
103
  throw lastErr;
102
104
  }
105
+ /**
106
+ * Provider ACCOUNT is unusable (spend cap, no credit, quota, revoked key) —
107
+ * deterministic for THIS provider, but another provider will succeed.
108
+ *
109
+ * Prod 2026-11-18/19: Anthropic returned 400 "You have reached your specified
110
+ * workspace API usage limits. You will regain access on 2026-12-01" for every
111
+ * planner/persona call. A 400 is not transient, so the dispatcher never tried
112
+ * the OpenAI `fallbackModel` and agent planning was down for every user.
113
+ * These errors must fall back cross-provider (and never be retried in place).
114
+ */
115
+ function isProviderAccountUnavailableError(err) {
116
+ if (!err || typeof err !== "object")
117
+ return false;
118
+ const e = err;
119
+ // TransientLlmError wraps the original — look through it.
120
+ if (e.cause && e.cause !== err && isProviderAccountUnavailableError(e.cause))
121
+ return true;
122
+ const status = typeof e.status === "number" ? e.status : undefined;
123
+ if (status !== undefined && ![400, 401, 402, 403, 429].includes(status))
124
+ return false;
125
+ const msg = String(e.message ?? "");
126
+ return /usage limits?|credit balance is too low|insufficient[_ ]quota|exceeded your current quota|billing|spend(ing)? limit|payment required|invalid[_ ]api[_ ]key|invalid x-api-key|api key not valid|permission[_ ]denied|account (is )?(disabled|deactivated|suspended)/i.test(msg);
127
+ }
128
+ /** True when the dispatcher should try `fallbackModel` after `err`. */
129
+ function isFallbackEligibleLlmError(err) {
130
+ return isTransientLlmError(err) || isProviderAccountUnavailableError(err);
131
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"Planner.d.ts","sourceRoot":"","sources":["../../../../src/services/agent/planner/Planner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,UAAU,EAAoB,MAAM,+BAA+B,CAAC;AAC7E,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,SAAS,EAEV,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAkB7C;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,SAAS,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,OAAO;IAIN,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IACrC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAEP,IAAI,EAAE,cAAc;IAK3C,IAAI,CACR,KAAK,EAAE,UAAU,EACjB,IAAI,GAAE;QACJ,OAAO,CAAC,EAAE,YAAY,CAAC;QACvB,QAAQ,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;QACjC,WAAW,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;QACvC,KAAK,CAAC,EAAE,gBAAgB,GA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AAU,EACjB,IAAI,GAAE;QACJ,OAAO,CAAC,EAAE,YAAY,CAAC;QACvB,QAAQ,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;QACjC,KAAK,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAC;QAChC,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,0EAA0E;QAC1E,WAAW,CAAC,EAAE,MAAM,CAAC;KACjB,GACL,OAAO,CAAC,WAAW,EAAE,CAAC;CAQ1B"}
@@ -4,6 +4,7 @@ exports.Planner = void 0;
4
4
  const brief_schema_1 = require("../../../schemas/brief.schema");
5
5
  const videoPlan_schema_1 = require("../../../schemas/videoPlan.schema");
6
6
  const llmCallerAnthropic_1 = require("../llmCallerAnthropic");
7
+ const llmRetry_1 = require("../llmRetry");
7
8
  const llmCallerRegistry_1 = require("../llmCallerRegistry");
8
9
  const modelRouter_1 = require("../modelRouter");
9
10
  const scriptFirstPlanner_1 = require("./scriptFirstPlanner");
@@ -81,7 +82,9 @@ class Planner {
81
82
  });
82
83
  }
83
84
  catch (anthErr) {
84
- if ((0, llmCallerAnthropic_1.isTransientLlmError)(anthErr)) {
85
+ // Account errors (spend cap / no credit) downgrade too: the
86
+ // dispatcher below then falls back cross-provider (prod 2026-11-19).
87
+ if ((0, llmCallerAnthropic_1.isTransientLlmError)(anthErr) || (0, llmRetry_1.isProviderAccountUnavailableError)(anthErr)) {
85
88
  // Downgrade: disable research for the rest of this plan call
86
89
  // so we don't keep retrying the failing Anthropic path on
87
90
  // subsequent attempts. The plan we produce won't be grounded,
@@ -2,6 +2,11 @@
2
2
  * the model comes back on its own within this window. */
3
3
  export declare const PROVIDER_DEPLETION_WINDOW_MS: number;
4
4
  /** Worker side: record that `modelKey`'s provider account is out of quota. */
5
+ export declare const PROVIDER_DEPLETION_MAX_WINDOW_MS: number;
6
+ export declare function nextDepletionWindowMs(prev: {
7
+ depletedUntilMs: number;
8
+ windowMs?: number;
9
+ } | null, now: number): number;
5
10
  export declare function markModelAccountDepleted(modelKey: string, code: string): Promise<void>;
6
11
  /**
7
12
  * API side: true while `modelKey` is inside a recorded depletion window.
@@ -1 +1 @@
1
- {"version":3,"file":"providerHealth.service.d.ts","sourceRoot":"","sources":["../../src/services/providerHealth.service.ts"],"names":[],"mappings":"AAkBA;0DAC0D;AAC1D,eAAO,MAAM,4BAA4B,QAAc,CAAC;AAYxD,8EAA8E;AAC9E,wBAAsB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAkB5F;AAED;;;;GAIG;AACH,wBAAsB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAqB/E"}
1
+ {"version":3,"file":"providerHealth.service.d.ts","sourceRoot":"","sources":["../../src/services/providerHealth.service.ts"],"names":[],"mappings":"AAkBA;0DAC0D;AAC1D,eAAO,MAAM,4BAA4B,QAAc,CAAC;AAcxD,8EAA8E;AAO9E,eAAO,MAAM,gCAAgC,QAAkB,CAAC;AAGhE,wBAAgB,qBAAqB,CACnC,IAAI,EAAE;IAAE,eAAe,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,EAC3D,GAAG,EAAE,MAAM,GACV,MAAM,CAOR;AAED,wBAAsB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA6B5F;AAED;;;;GAIG;AACH,wBAAsB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAqB/E"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PROVIDER_DEPLETION_WINDOW_MS = void 0;
3
+ exports.PROVIDER_DEPLETION_MAX_WINDOW_MS = exports.PROVIDER_DEPLETION_WINDOW_MS = void 0;
4
+ exports.nextDepletionWindowMs = nextDepletionWindowMs;
4
5
  exports.markModelAccountDepleted = markModelAccountDepleted;
5
6
  exports.isModelAccountDepleted = isModelAccountDepleted;
6
7
  const firestore_1 = require("firebase-admin/firestore");
@@ -25,16 +26,42 @@ exports.PROVIDER_DEPLETION_WINDOW_MS = 10 * 60000;
25
26
  const READ_CACHE_MS = 30000;
26
27
  const readCache = new Map();
27
28
  /** Worker side: record that `modelKey`'s provider account is out of quota. */
29
+ // Escalation (2026-11-19): with a fixed 10-min window a still-dry account
30
+ // failed (and paged) once per window for days — kling-v4.0 paged ~10x across
31
+ // 2026-11-17/19. If the previous window ended recently, double it, capped, so a
32
+ // long outage settles to ~1 page / 2 h. A fresh depletion (or one after a quiet
33
+ // gap) starts at the base window again, so recovery after a top-up stays fast.
34
+ // Delete providerHealth/{modelKey} to clear early.
35
+ exports.PROVIDER_DEPLETION_MAX_WINDOW_MS = 2 * 60 * 60000;
36
+ const ESCALATION_LOOKBACK_MS = 6 * 60 * 60000;
37
+ function nextDepletionWindowMs(prev, now) {
38
+ if (!prev || now - prev.depletedUntilMs > ESCALATION_LOOKBACK_MS)
39
+ return exports.PROVIDER_DEPLETION_WINDOW_MS;
40
+ const prevWindow = prev.windowMs ?? exports.PROVIDER_DEPLETION_WINDOW_MS;
41
+ // Still inside the window (sibling scenes of the same job, a BullMQ retry):
42
+ // don't compound — only a failure AFTER the window expired escalates.
43
+ if (prev.depletedUntilMs > now)
44
+ return prevWindow;
45
+ return Math.min(prevWindow * 2, exports.PROVIDER_DEPLETION_MAX_WINDOW_MS);
46
+ }
28
47
  async function markModelAccountDepleted(modelKey, code) {
29
- const until = Date.now() + exports.PROVIDER_DEPLETION_WINDOW_MS;
48
+ // REMOVED FOR v1 — kept for reference: fixed window.
49
+ // const until = Date.now() + PROVIDER_DEPLETION_WINDOW_MS;
30
50
  try {
51
+ const ref = firebase_1.firestore.collection(COLLECTION).doc(modelKey);
52
+ const prevSnap = await ref.get();
53
+ const prev = prevSnap.exists ? prevSnap.data() : undefined;
54
+ const now = Date.now();
55
+ const windowMs = nextDepletionWindowMs(prev?.depletedUntil ? { depletedUntilMs: prev.depletedUntil.toMillis(), windowMs: prev.windowMs } : null, now);
56
+ const until = now + windowMs;
31
57
  const doc = {
32
58
  modelKey,
33
59
  depletedUntil: firestore_1.Timestamp.fromMillis(until),
60
+ windowMs,
34
61
  code,
35
62
  updatedAt: firestore_1.Timestamp.now(),
36
63
  };
37
- await firebase_1.firestore.collection(COLLECTION).doc(modelKey).set(doc);
64
+ await ref.set(doc);
38
65
  readCache.set(modelKey, { at: Date.now(), depletedUntilMs: until });
39
66
  }
40
67
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vidspotai-shared",
3
- "version": "1.0.141",
3
+ "version": "1.0.143",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "exports": {