@ever-works/google-plugin 1.0.6 → 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/dist/index.cjs CHANGED
@@ -20935,6 +20935,9 @@ async function safeFetchWithDnsPin(rawUrl, init, options) {
20935
20935
  }
20936
20936
  return fetch(rawUrl, init);
20937
20937
  }
20938
+ function namesParam(msg, param) {
20939
+ return [`'${param}'`, `"${param}"`, `\`${param}\``].some((quoted) => msg.includes(quoted));
20940
+ }
20938
20941
  var AiOperations = class {
20939
20942
  constructor(defaultConfig) {
20940
20943
  this.defaultConfig = defaultConfig;
@@ -20947,7 +20950,7 @@ var AiOperations = class {
20947
20950
  async createChatCompletion(options, configOverrides) {
20948
20951
  const config2 = this.mergeConfig(configOverrides);
20949
20952
  const model = options.model || config2.model;
20950
- return this.withParamRetry(model, async (skip) => {
20953
+ return this.withParamRetry(this.paramCacheKey(config2, model), async (skip) => {
20951
20954
  const baseLlm = this.createChatModel(config2, model, options, skip);
20952
20955
  const llm = this.bindTools(baseLlm, options, skip);
20953
20956
  const tracker = new TokenUsageTracker();
@@ -20992,7 +20995,7 @@ var AiOperations = class {
20992
20995
  async askJson(prompt, schema, configOverrides, options) {
20993
20996
  const config2 = this.mergeConfig(configOverrides);
20994
20997
  const model = config2.model;
20995
- return this.withParamRetry(model, async (skip) => {
20998
+ return this.withParamRetry(this.paramCacheKey(config2, model), async (skip) => {
20996
20999
  const llm = this.createChatModel(
20997
21000
  config2,
20998
21001
  model,
@@ -21015,20 +21018,21 @@ var AiOperations = class {
21015
21018
  const config2 = this.mergeConfig(configOverrides);
21016
21019
  const model = options.model || config2.model;
21017
21020
  const messages = this.toLangChainMessages(options.messages);
21018
- const skip = new Set(this.rejectedParams.get(model));
21021
+ const cacheKey = this.paramCacheKey(config2, model);
21022
+ const skip = new Set(this.rejectedParams.get(cacheKey));
21019
21023
  let stream;
21020
- try {
21021
- const baseLlm = this.createChatModel(config2, model, options, skip);
21022
- const llm = this.bindTools(baseLlm, options, skip);
21023
- stream = await llm.stream(messages);
21024
- } catch (error62) {
21025
- const param = this.parseRejectedParam(error62);
21026
- if (!param || skip.has(param)) throw error62;
21027
- skip.add(param);
21028
- this.rejectedParams.set(model, new Set(skip));
21029
- const baseLlm = this.createChatModel(config2, model, options, skip);
21030
- const llm = this.bindTools(baseLlm, options, skip);
21031
- stream = await llm.stream(messages);
21024
+ for (; ; ) {
21025
+ try {
21026
+ const baseLlm = this.createChatModel(config2, model, options, skip);
21027
+ const llm = this.bindTools(baseLlm, options, skip);
21028
+ stream = await llm.stream(messages);
21029
+ break;
21030
+ } catch (error62) {
21031
+ const param = this.nextRejectedParam(error62, skip);
21032
+ if (!param) throw error62;
21033
+ skip.add(param);
21034
+ this.rejectedParams.set(cacheKey, new Set(skip));
21035
+ }
21032
21036
  }
21033
21037
  let hadToolCalls = false;
21034
21038
  let isFirstChunk = true;
@@ -21149,10 +21153,18 @@ var AiOperations = class {
21149
21153
  const TIMEOUT_MS = 15e3;
21150
21154
  try {
21151
21155
  const config2 = this.mergeConfig(configOverrides);
21152
- const llm = this.createChatModel(config2, modelOverride ?? config2.model);
21156
+ const model = modelOverride ?? config2.model;
21153
21157
  let timeoutHandle;
21154
21158
  await Promise.race([
21155
- llm.invoke([new messages.HumanMessage('Respond with just "OK" to confirm you are working.')]).then((r) => {
21159
+ // Same rejected-parameter retry as a real request, so a model
21160
+ // that refuses a default parameter (e.g. `temperature` on
21161
+ // Claude 4.7+) does not fail validation that real calls pass.
21162
+ this.withParamRetry(
21163
+ this.paramCacheKey(config2, model),
21164
+ (skip) => this.createChatModel(config2, model, void 0, skip).invoke([
21165
+ new messages.HumanMessage('Respond with just "OK" to confirm you are working.')
21166
+ ])
21167
+ ).then((r) => {
21156
21168
  clearTimeout(timeoutHandle);
21157
21169
  return r;
21158
21170
  }),
@@ -21261,25 +21273,36 @@ var AiOperations = class {
21261
21273
  }
21262
21274
  /**
21263
21275
  * Generic retry: if the API rejects an unsupported parameter, rebuild
21264
- * the model without it and retry once. Handles temperature, reasoning,
21265
- * etc. across all providers/models in one place.
21276
+ * the model without it and retry, once per newly rejected parameter (a
21277
+ * request can be refused for `temperature`, then for a forced
21278
+ * `tool_choice`). Handles temperature, reasoning, etc. across all
21279
+ * providers/models in one place.
21266
21280
  *
21267
- * Uses a per-model cache so the same param is never sent twice.
21281
+ * Uses a per-endpoint-and-model cache so the same param is never sent twice.
21268
21282
  */
21269
- async withParamRetry(model, operation) {
21270
- const skip = new Set(this.rejectedParams.get(model));
21271
- try {
21272
- return await operation(skip);
21273
- } catch (error62) {
21274
- const param = this.parseRejectedParam(error62);
21275
- if (param && !skip.has(param)) {
21283
+ async withParamRetry(cacheKey, operation) {
21284
+ const skip = new Set(this.rejectedParams.get(cacheKey));
21285
+ for (; ; ) {
21286
+ try {
21287
+ return await operation(skip);
21288
+ } catch (error62) {
21289
+ const param = this.nextRejectedParam(error62, skip);
21290
+ if (!param) throw error62;
21276
21291
  skip.add(param);
21277
- this.rejectedParams.set(model, new Set(skip));
21278
- return operation(skip);
21292
+ this.rejectedParams.set(cacheKey, new Set(skip));
21279
21293
  }
21280
- throw error62;
21281
21294
  }
21282
21295
  }
21296
+ /** The param to leave out on the next attempt, or `undefined` when a retry cannot help. */
21297
+ nextRejectedParam(error62, skip) {
21298
+ let param = this.parseRejectedParam(error62);
21299
+ if (param === "tool_choice" && skip.has("tool_choice")) param = "tools";
21300
+ return param && !skip.has(param) ? param : void 0;
21301
+ }
21302
+ /** Key for {@link rejectedParams}: the endpoint and the model. */
21303
+ paramCacheKey(config2, model) {
21304
+ return `${config2.baseURL ?? ""}|${model}`;
21305
+ }
21283
21306
  mapTokenUsage(tracker) {
21284
21307
  const usage = tracker.usage;
21285
21308
  if (usage.totalTokens === 0) return void 0;
@@ -21309,7 +21332,8 @@ var AiOperations = class {
21309
21332
  }
21310
21333
  }));
21311
21334
  const callOptions = { tools };
21312
- if (options.toolChoice) {
21335
+ const forced = options.toolChoice === "required" || typeof options.toolChoice === "object";
21336
+ if (options.toolChoice && !(forced && skip?.has("tool_choice"))) {
21313
21337
  callOptions.tool_choice = options.toolChoice;
21314
21338
  }
21315
21339
  return llm.withConfig(callOptions);
@@ -21317,11 +21341,12 @@ var AiOperations = class {
21317
21341
  parseRejectedParam(error62) {
21318
21342
  if (!(error62 instanceof Error)) return void 0;
21319
21343
  const msg = error62.message.toLowerCase();
21320
- if (msg.includes("'temperature'") || msg.includes('"temperature"')) return "temperature";
21321
- if (msg.includes("'reasoning'") || msg.includes("'reasoning_effort'")) return "reasoning";
21344
+ if (namesParam(msg, "temperature")) return "temperature";
21345
+ if (namesParam(msg, "reasoning") || namesParam(msg, "reasoning_effort")) return "reasoning";
21322
21346
  if (msg.includes("json_schema") || msg.includes("response_format") || msg.includes("structured output"))
21323
21347
  return "structured_output";
21324
- if (msg.includes("'tools'") || msg.includes('"tools"') || msg.includes("tool_choice")) return "tools";
21348
+ if (msg.includes("tool_choice")) return "tool_choice";
21349
+ if (namesParam(msg, "tools")) return "tools";
21325
21350
  return void 0;
21326
21351
  }
21327
21352
  /**
package/dist/index.js CHANGED
@@ -20911,6 +20911,9 @@ async function safeFetchWithDnsPin(rawUrl, init, options) {
20911
20911
  }
20912
20912
  return fetch(rawUrl, init);
20913
20913
  }
20914
+ function namesParam(msg, param) {
20915
+ return [`'${param}'`, `"${param}"`, `\`${param}\``].some((quoted) => msg.includes(quoted));
20916
+ }
20914
20917
  var AiOperations = class {
20915
20918
  constructor(defaultConfig) {
20916
20919
  this.defaultConfig = defaultConfig;
@@ -20923,7 +20926,7 @@ var AiOperations = class {
20923
20926
  async createChatCompletion(options, configOverrides) {
20924
20927
  const config2 = this.mergeConfig(configOverrides);
20925
20928
  const model = options.model || config2.model;
20926
- return this.withParamRetry(model, async (skip) => {
20929
+ return this.withParamRetry(this.paramCacheKey(config2, model), async (skip) => {
20927
20930
  const baseLlm = this.createChatModel(config2, model, options, skip);
20928
20931
  const llm = this.bindTools(baseLlm, options, skip);
20929
20932
  const tracker = new TokenUsageTracker();
@@ -20968,7 +20971,7 @@ var AiOperations = class {
20968
20971
  async askJson(prompt, schema, configOverrides, options) {
20969
20972
  const config2 = this.mergeConfig(configOverrides);
20970
20973
  const model = config2.model;
20971
- return this.withParamRetry(model, async (skip) => {
20974
+ return this.withParamRetry(this.paramCacheKey(config2, model), async (skip) => {
20972
20975
  const llm = this.createChatModel(
20973
20976
  config2,
20974
20977
  model,
@@ -20991,20 +20994,21 @@ var AiOperations = class {
20991
20994
  const config2 = this.mergeConfig(configOverrides);
20992
20995
  const model = options.model || config2.model;
20993
20996
  const messages = this.toLangChainMessages(options.messages);
20994
- const skip = new Set(this.rejectedParams.get(model));
20997
+ const cacheKey = this.paramCacheKey(config2, model);
20998
+ const skip = new Set(this.rejectedParams.get(cacheKey));
20995
20999
  let stream;
20996
- try {
20997
- const baseLlm = this.createChatModel(config2, model, options, skip);
20998
- const llm = this.bindTools(baseLlm, options, skip);
20999
- stream = await llm.stream(messages);
21000
- } catch (error62) {
21001
- const param = this.parseRejectedParam(error62);
21002
- if (!param || skip.has(param)) throw error62;
21003
- skip.add(param);
21004
- this.rejectedParams.set(model, new Set(skip));
21005
- const baseLlm = this.createChatModel(config2, model, options, skip);
21006
- const llm = this.bindTools(baseLlm, options, skip);
21007
- stream = await llm.stream(messages);
21000
+ for (; ; ) {
21001
+ try {
21002
+ const baseLlm = this.createChatModel(config2, model, options, skip);
21003
+ const llm = this.bindTools(baseLlm, options, skip);
21004
+ stream = await llm.stream(messages);
21005
+ break;
21006
+ } catch (error62) {
21007
+ const param = this.nextRejectedParam(error62, skip);
21008
+ if (!param) throw error62;
21009
+ skip.add(param);
21010
+ this.rejectedParams.set(cacheKey, new Set(skip));
21011
+ }
21008
21012
  }
21009
21013
  let hadToolCalls = false;
21010
21014
  let isFirstChunk = true;
@@ -21125,10 +21129,18 @@ var AiOperations = class {
21125
21129
  const TIMEOUT_MS = 15e3;
21126
21130
  try {
21127
21131
  const config2 = this.mergeConfig(configOverrides);
21128
- const llm = this.createChatModel(config2, modelOverride ?? config2.model);
21132
+ const model = modelOverride ?? config2.model;
21129
21133
  let timeoutHandle;
21130
21134
  await Promise.race([
21131
- llm.invoke([new HumanMessage('Respond with just "OK" to confirm you are working.')]).then((r) => {
21135
+ // Same rejected-parameter retry as a real request, so a model
21136
+ // that refuses a default parameter (e.g. `temperature` on
21137
+ // Claude 4.7+) does not fail validation that real calls pass.
21138
+ this.withParamRetry(
21139
+ this.paramCacheKey(config2, model),
21140
+ (skip) => this.createChatModel(config2, model, void 0, skip).invoke([
21141
+ new HumanMessage('Respond with just "OK" to confirm you are working.')
21142
+ ])
21143
+ ).then((r) => {
21132
21144
  clearTimeout(timeoutHandle);
21133
21145
  return r;
21134
21146
  }),
@@ -21237,25 +21249,36 @@ var AiOperations = class {
21237
21249
  }
21238
21250
  /**
21239
21251
  * Generic retry: if the API rejects an unsupported parameter, rebuild
21240
- * the model without it and retry once. Handles temperature, reasoning,
21241
- * etc. across all providers/models in one place.
21252
+ * the model without it and retry, once per newly rejected parameter (a
21253
+ * request can be refused for `temperature`, then for a forced
21254
+ * `tool_choice`). Handles temperature, reasoning, etc. across all
21255
+ * providers/models in one place.
21242
21256
  *
21243
- * Uses a per-model cache so the same param is never sent twice.
21257
+ * Uses a per-endpoint-and-model cache so the same param is never sent twice.
21244
21258
  */
21245
- async withParamRetry(model, operation) {
21246
- const skip = new Set(this.rejectedParams.get(model));
21247
- try {
21248
- return await operation(skip);
21249
- } catch (error62) {
21250
- const param = this.parseRejectedParam(error62);
21251
- if (param && !skip.has(param)) {
21259
+ async withParamRetry(cacheKey, operation) {
21260
+ const skip = new Set(this.rejectedParams.get(cacheKey));
21261
+ for (; ; ) {
21262
+ try {
21263
+ return await operation(skip);
21264
+ } catch (error62) {
21265
+ const param = this.nextRejectedParam(error62, skip);
21266
+ if (!param) throw error62;
21252
21267
  skip.add(param);
21253
- this.rejectedParams.set(model, new Set(skip));
21254
- return operation(skip);
21268
+ this.rejectedParams.set(cacheKey, new Set(skip));
21255
21269
  }
21256
- throw error62;
21257
21270
  }
21258
21271
  }
21272
+ /** The param to leave out on the next attempt, or `undefined` when a retry cannot help. */
21273
+ nextRejectedParam(error62, skip) {
21274
+ let param = this.parseRejectedParam(error62);
21275
+ if (param === "tool_choice" && skip.has("tool_choice")) param = "tools";
21276
+ return param && !skip.has(param) ? param : void 0;
21277
+ }
21278
+ /** Key for {@link rejectedParams}: the endpoint and the model. */
21279
+ paramCacheKey(config2, model) {
21280
+ return `${config2.baseURL ?? ""}|${model}`;
21281
+ }
21259
21282
  mapTokenUsage(tracker) {
21260
21283
  const usage = tracker.usage;
21261
21284
  if (usage.totalTokens === 0) return void 0;
@@ -21285,7 +21308,8 @@ var AiOperations = class {
21285
21308
  }
21286
21309
  }));
21287
21310
  const callOptions = { tools };
21288
- if (options.toolChoice) {
21311
+ const forced = options.toolChoice === "required" || typeof options.toolChoice === "object";
21312
+ if (options.toolChoice && !(forced && skip?.has("tool_choice"))) {
21289
21313
  callOptions.tool_choice = options.toolChoice;
21290
21314
  }
21291
21315
  return llm.withConfig(callOptions);
@@ -21293,11 +21317,12 @@ var AiOperations = class {
21293
21317
  parseRejectedParam(error62) {
21294
21318
  if (!(error62 instanceof Error)) return void 0;
21295
21319
  const msg = error62.message.toLowerCase();
21296
- if (msg.includes("'temperature'") || msg.includes('"temperature"')) return "temperature";
21297
- if (msg.includes("'reasoning'") || msg.includes("'reasoning_effort'")) return "reasoning";
21320
+ if (namesParam(msg, "temperature")) return "temperature";
21321
+ if (namesParam(msg, "reasoning") || namesParam(msg, "reasoning_effort")) return "reasoning";
21298
21322
  if (msg.includes("json_schema") || msg.includes("response_format") || msg.includes("structured output"))
21299
21323
  return "structured_output";
21300
- if (msg.includes("'tools'") || msg.includes('"tools"') || msg.includes("tool_choice")) return "tools";
21324
+ if (msg.includes("tool_choice")) return "tool_choice";
21325
+ if (namesParam(msg, "tools")) return "tools";
21301
21326
  return void 0;
21302
21327
  }
21303
21328
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ever-works/google-plugin",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Google Gemini AI provider plugin for Ever Works platform",
5
5
  "author": {
6
6
  "name": "Ever Co. LTD",
@@ -32,7 +32,7 @@
32
32
  "test:watch": "vitest"
33
33
  },
34
34
  "dependencies": {
35
- "@ever-works/plugin": "^1.2.13",
35
+ "@ever-works/plugin": "^1.2.15",
36
36
  "@langchain/openai": "^1.7.1",
37
37
  "@langchain/core": "^1.3.0"
38
38
  },
@@ -71,8 +71,8 @@
71
71
  "url": "https://github.com/ever-works/ever-works/issues"
72
72
  },
73
73
  "everworksRelease": {
74
- "contentHash": "sha256:1e33a17b7781b6ff31c60ababb377a7516bf6236dee7f80447d239255828479a",
75
- "commit": "24837e5bb875bf996052fb319844b6c1d55b7041",
76
- "source": "https://github.com/ever-works/ever-works/tree/24837e5bb875bf996052fb319844b6c1d55b7041/packages/plugins/google"
74
+ "contentHash": "sha256:386af8b315e9d10049788b259149db129884c302d4f5e84cb7ec15472cb0fa20",
75
+ "commit": "fe7305a350776ba5d206efb483149855c58f1344",
76
+ "source": "https://github.com/ever-works/ever-works/tree/fe7305a350776ba5d206efb483149855c58f1344/packages/plugins/google"
77
77
  }
78
78
  }