vidspotai-shared 1.0.143 → 1.0.144

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.
@@ -42,6 +42,9 @@ export type ChatTurnEvent = {
42
42
  } | {
43
43
  kind: "error";
44
44
  message: string;
45
+ /** Set when the LLM provider ACCOUNT is unusable (spend cap / no credit):
46
+ * an operator problem, not a per-turn bug — hosts warn instead of paging. */
47
+ code?: "PROVIDER_ACCOUNT_UNAVAILABLE";
45
48
  };
46
49
  export interface ChatTurnTool {
47
50
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"chatAgent.d.ts","sourceRoot":"","sources":["../../../src/services/agent/chatAgent.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,SAAS,GAAG,MAAM,CAAA;CAAE,GACxE;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC/D;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB;oFACgF;IAChF,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E,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,CAAC,CAAC;IACV,mDAAmD;IACnD,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CACxD;AAaD,wBAAgB,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,YAAY,CAQ/E;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,qEAAqE;IACrE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7D,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kFAAkF;IAClF,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAqGD;;;;;;GAMG;AACH,wBAAuB,WAAW,CAChC,GAAG,EAAE,eAAe,GACnB,cAAc,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,CAAC,CAyL3C"}
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.defineTool = defineTool;
7
7
  exports.runChatTurn = runChatTurn;
8
8
  const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
9
+ const llmRetry_1 = require("./llmRetry");
9
10
  const zod_1 = require("zod");
10
11
  const logger_1 = require("../../utils/logger");
11
12
  /** Strip JSON-Schema keys Anthropic's tool `input_schema` doesn't want. */
@@ -187,6 +188,18 @@ async function* runChatTurn(req) {
187
188
  yield { kind: "error", message: "aborted" };
188
189
  return;
189
190
  }
191
+ // The chat loop is Anthropic-only (tool use), so there's no cross-
192
+ // provider fallback here. When the account itself is capped (prod
193
+ // 2026-11-20 workspace usage limit), tell the user plainly instead of
194
+ // surfacing the raw API JSON, and tag it so the host doesn't page per turn.
195
+ if ((0, llmRetry_1.isProviderAccountUnavailableError)(err)) {
196
+ yield {
197
+ kind: "error",
198
+ code: "PROVIDER_ACCOUNT_UNAVAILABLE",
199
+ message: "The chat assistant is temporarily unavailable. You can still create and generate videos — please try chat again later.",
200
+ };
201
+ return;
202
+ }
190
203
  yield {
191
204
  kind: "error",
192
205
  message: `chat turn failed: ${err.message}`,
@@ -53,4 +53,9 @@ export declare class OpenAiLlmCaller implements LlmCaller {
53
53
  */
54
54
  private withRetry;
55
55
  }
56
+ /**
57
+ * OpenAI reasoning models (gpt-5 family incl. gpt-5.x, o1/o3/o4…) reject any
58
+ * temperature other than the default 1. Exported for tests.
59
+ */
60
+ export declare function supportsCustomTemperature(modelId: string): boolean;
56
61
  //# sourceMappingURL=llmCallerOpenai.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"llmCallerOpenai.d.ts","sourceRoot":"","sources":["../../../src/services/agent/llmCallerOpenai.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,WAAW,EACX,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAKrB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAID,qBAAa,eAAgB,YAAW,SAAS;IAC/C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;I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CAAC,EAAE,MAAM,CAAC;CACrB;AAID,qBAAa,eAAgB,YAAW,SAAS;IAC/C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,GAAG,EAAE,kBAAkB;IAU7B,IAAI,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAoB7C,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EACrC,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACxB,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;IA8BjC,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;YAgBc,cAAc;IAqE7B,+EAA+E;IAC/E,OAAO,CAAC,UAAU;IA6BlB,OAAO,CAAC,aAAa;IAkBrB,iFAAiF;IACjF,OAAO,CAAC,eAAe;IA0BvB,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,KAAK;IAUb;;;;OAIG;IACH,OAAO,CAAC,SAAS;CAyBlB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAElE"}
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.OpenAiLlmCaller = void 0;
7
+ exports.supportsCustomTemperature = supportsCustomTemperature;
8
+ const logger_1 = require("../../utils/logger");
7
9
  const openai_1 = __importDefault(require("openai"));
8
10
  const zod_1 = require("zod");
9
11
  const llmModelRegistry_1 = require("./llmModelRegistry");
@@ -36,7 +38,7 @@ class OpenAiLlmCaller {
36
38
  }
37
39
  async structured(req) {
38
40
  const jsonSchema = zod_1.z.toJSONSchema(req.schema, { target: "draft-7" });
39
- const completion = await this.withRetry(() => this.client.chat.completions.create({
41
+ const completion = await withStrictSchemaFallback(req.schemaName, (strict) => this.withRetry(() => this.client.chat.completions.create({
40
42
  ...this.baseParams(req.model, req.messages, {
41
43
  temperature: req.temperature,
42
44
  maxTokens: req.maxTokens,
@@ -46,10 +48,10 @@ class OpenAiLlmCaller {
46
48
  json_schema: {
47
49
  name: req.schemaName,
48
50
  schema: jsonSchema,
49
- strict: true,
51
+ strict,
50
52
  },
51
53
  },
52
- }));
54
+ })));
53
55
  const txt = completion.choices?.[0]?.message?.content ?? "";
54
56
  return {
55
57
  ...this.parseStructured(req, txt),
@@ -83,7 +85,7 @@ class OpenAiLlmCaller {
83
85
  // Connect with transient retry; once bytes flow a mid-stream drop
84
86
  // propagates and the planner's own retry loop handles it (mirrors the
85
87
  // gateway's streaming contract).
86
- const stream = await this.withRetry(() => this.client.chat.completions.create({
88
+ const stream = await withStrictSchemaFallback(req.schemaName, (strict) => this.withRetry(() => this.client.chat.completions.create({
87
89
  ...this.baseParams(req.model, req.messages, {
88
90
  temperature: req.temperature,
89
91
  maxTokens: req.maxTokens,
@@ -93,12 +95,12 @@ class OpenAiLlmCaller {
93
95
  json_schema: {
94
96
  name: req.schemaName,
95
97
  schema: jsonSchema,
96
- strict: true,
98
+ strict,
97
99
  },
98
100
  },
99
101
  stream: true,
100
102
  stream_options: { include_usage: true },
101
- }));
103
+ })));
102
104
  for await (const chunk of stream) {
103
105
  if (chunk.id)
104
106
  requestId = chunk.id;
@@ -140,12 +142,20 @@ class OpenAiLlmCaller {
140
142
  // ---------- helpers ----------
141
143
  /** Shared non-streaming params: model id, encoded messages, sampling knobs. */
142
144
  baseParams(model, messages, opts) {
145
+ const modelId = this.resolveModelId(model);
146
+ // REMOVED FOR v1 — kept for reference: "most agent calls leave it unset"
147
+ // was false — the Planner always sets 0.4, so when Anthropic hit its spend
148
+ // cap and planning fell back to gpt-5.5, every plan 400'd ("'temperature'
149
+ // does not support 0.4 with this model") in prod 2026-11-19/20.
150
+ // ...(opts.temperature !== undefined ? { temperature: opts.temperature } : {}),
151
+ const sendTemperature = opts.temperature !== undefined &&
152
+ (supportsCustomTemperature(modelId) || opts.temperature === 1);
143
153
  return {
144
- model: this.resolveModelId(model),
154
+ model: modelId,
145
155
  messages: messages.map((m) => this.encodeMessage(m)),
146
- // Only send temperature when explicitly set — gpt-5 reasoning models
147
- // reject non-default temperatures, and most agent calls leave it unset.
148
- ...(opts.temperature !== undefined ? { temperature: opts.temperature } : {}),
156
+ // Reasoning models (gpt-5 family, o-series) accept only the default
157
+ // temperature; drop it for them rather than 400 the whole call.
158
+ ...(sendTemperature ? { temperature: opts.temperature } : {}),
149
159
  // gpt-5 family requires max_completion_tokens (max_tokens is rejected on
150
160
  // reasoning models); it's also accepted by non-reasoning models.
151
161
  ...(opts.maxTokens !== undefined
@@ -228,3 +238,41 @@ class OpenAiLlmCaller {
228
238
  }
229
239
  }
230
240
  exports.OpenAiLlmCaller = OpenAiLlmCaller;
241
+ /**
242
+ * OpenAI reasoning models (gpt-5 family incl. gpt-5.x, o1/o3/o4…) reject any
243
+ * temperature other than the default 1. Exported for tests.
244
+ */
245
+ function supportsCustomTemperature(modelId) {
246
+ return !/^(gpt-5|o\d)/i.test(modelId);
247
+ }
248
+ /**
249
+ * Schemas OpenAI rejected for strict mode. Strict `json_schema` demands every
250
+ * property be `required`; our Zod schemas use `.optional()` freely (VideoPlan's
251
+ * captionStyle etc.), so strict 400s before generating ("Invalid schema for
252
+ * response_format"). That stayed hidden while OpenAI was only a fallback, and
253
+ * surfaced when the Anthropic spend cap pushed all planning onto gpt-5.5
254
+ * (prod 2026-11-20). Non-strict json_schema still steers the model; the Zod
255
+ * parse + the planner's correction loop remain the real validators.
256
+ */
257
+ const nonStrictSchemas = new Set();
258
+ function isStrictSchemaRejection(err) {
259
+ const e = err;
260
+ return !!e && e.status === 400 && /Invalid schema for response_format/i.test(String(e.message ?? ""));
261
+ }
262
+ async function withStrictSchemaFallback(schemaName, run) {
263
+ if (nonStrictSchemas.has(schemaName))
264
+ return run(false);
265
+ try {
266
+ return await run(true);
267
+ }
268
+ catch (err) {
269
+ if (!isStrictSchemaRejection(err))
270
+ throw err;
271
+ nonStrictSchemas.add(schemaName);
272
+ logger_1.logger.warn("OpenAI rejected schema for strict mode — using non-strict json_schema", {
273
+ schemaName,
274
+ err: String(err.message ?? err).slice(0, 300),
275
+ });
276
+ return run(false);
277
+ }
278
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vidspotai-shared",
3
- "version": "1.0.143",
3
+ "version": "1.0.144",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "exports": {