@zqagent/core 0.3.11 → 0.3.12
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/{TurnEngine-BPKhWuSI.d.cts → TurnEngine-BSciNywD.d.cts} +23 -4
- package/dist/{TurnEngine-DtGEuVLT.d.ts → TurnEngine-BU4R7q_0.d.ts} +23 -4
- package/dist/index.cjs +48 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +48 -16
- package/dist/index.js.map +1 -1
- package/dist/internal/engine/FileLogHook.d.cts +2 -1
- package/dist/internal/engine/FileLogHook.d.ts +2 -1
- package/dist/internal/llmConfig.cjs +15 -0
- package/dist/internal/llmConfig.cjs.map +1 -1
- package/dist/internal/llmConfig.d.cts +15 -0
- package/dist/internal/llmConfig.d.ts +15 -0
- package/dist/internal/llmConfig.js +15 -0
- package/dist/internal/llmConfig.js.map +1 -1
- package/dist/internal/providers/diagnostics.cjs +22 -2
- package/dist/internal/providers/diagnostics.cjs.map +1 -1
- package/dist/internal/providers/diagnostics.d.cts +25 -3
- package/dist/internal/providers/diagnostics.d.ts +25 -3
- package/dist/internal/providers/diagnostics.js +19 -2
- package/dist/internal/providers/diagnostics.js.map +1 -1
- package/dist/internal/providers/models.cjs.map +1 -1
- package/dist/internal/providers/models.js.map +1 -1
- package/dist/internal/update/controller.cjs +1 -1
- package/dist/internal/update/controller.js +1 -1
- package/dist/internal/update/platform.cjs +1 -1
- package/dist/internal/update/platform.js +1 -1
- package/dist/tools/explore.cjs.map +1 -1
- package/dist/tools/explore.d.cts +2 -1
- package/dist/tools/explore.d.ts +2 -1
- package/dist/tools/explore.js.map +1 -1
- package/package.json +4 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { T as TokenUsage, M as Message, a as ToolSchema, R as ReasoningEffort, S as StreamChunk, b as MessageAttachment, c as StoredAttachment } from './types-BYyXWWPW.cjs';
|
|
2
2
|
import { a as ToolMetadata, T as ToolRegistry } from './ToolRegistry-DouDvn9E.cjs';
|
|
3
|
+
import { ApiMode } from './internal/providers/diagnostics.cjs';
|
|
3
4
|
import { ChatCompletionMessageParam } from 'openai/resources/chat/completions.js';
|
|
4
5
|
import { RequestOptions } from 'openai/core.mjs';
|
|
5
6
|
import { ModelCapability } from '@zqagent/shared/model-capabilities';
|
|
@@ -344,22 +345,40 @@ declare class OpenAIProvider implements ProviderClient {
|
|
|
344
345
|
private _logDir?;
|
|
345
346
|
/** 服务端点 baseURL(用于识别 DeepSeek 等特定供应商) */
|
|
346
347
|
private _baseURL;
|
|
347
|
-
/**
|
|
348
|
-
|
|
348
|
+
/**
|
|
349
|
+
* 本实例的 API 模式。
|
|
350
|
+
*
|
|
351
|
+
* 显式配置 > 全局 `OPENAI_FORCE_API_MODE` > auto(先 Responses 再降级)。
|
|
352
|
+
* 早先只有全局环境变量一种表达方式,一个节点挂两家供应商时无法各自指定。
|
|
353
|
+
*/
|
|
354
|
+
private _apiMode;
|
|
349
355
|
constructor(opts: {
|
|
350
356
|
apiKey?: string;
|
|
351
357
|
baseURL?: string;
|
|
352
358
|
/** LLM 请求日志根目录,按日期分目录,不传则不记录 */
|
|
353
359
|
logDir?: string;
|
|
360
|
+
/**
|
|
361
|
+
* 单次请求超时(毫秒)。缺省/非法时回落到 `OPENAI_TIMEOUT_MS`,再回落 10 分钟。
|
|
362
|
+
*
|
|
363
|
+
* 必须能按供应商设置:推理模型的合理预算与普通模型差一个数量级,共用一个全局值
|
|
364
|
+
* 只能二选一(慢模型被掐断,或快模型失败时干等十分钟)。
|
|
365
|
+
*/
|
|
366
|
+
timeoutMs?: number | null;
|
|
367
|
+
/**
|
|
368
|
+
* API 模式(auto / responses / chat)。缺省时读 `OPENAI_FORCE_API_MODE`,再缺省 auto。
|
|
369
|
+
*/
|
|
370
|
+
apiMode?: ApiMode | null;
|
|
354
371
|
});
|
|
355
372
|
/**
|
|
356
373
|
* 解析指定模型的 API 模式。
|
|
357
374
|
*
|
|
358
|
-
*
|
|
359
|
-
* >
|
|
375
|
+
* 优先级:本实例的显式配置(responses|chat)
|
|
376
|
+
* > 运行时降级缓存(该端点+模型曾因"不支持"失败而缓存为 chat)
|
|
360
377
|
* > 默认 responses(Responses 优先)。
|
|
361
378
|
*/
|
|
362
379
|
private _resolveMode;
|
|
380
|
+
/** 记录「该端点+模型不支持 Responses」,后续同进程内的请求直走 Chat */
|
|
381
|
+
private _markChatMode;
|
|
363
382
|
/**
|
|
364
383
|
* Responses 失败的分类(决定「能不能改走 Chat Completions」以及要不要缓存降级)。
|
|
365
384
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { T as TokenUsage, M as Message, a as ToolSchema, R as ReasoningEffort, S as StreamChunk, b as MessageAttachment, c as StoredAttachment } from './types-BYyXWWPW.js';
|
|
2
2
|
import { a as ToolMetadata, T as ToolRegistry } from './ToolRegistry-Cy0fQxrb.js';
|
|
3
|
+
import { ApiMode } from './internal/providers/diagnostics.js';
|
|
3
4
|
import { ChatCompletionMessageParam } from 'openai/resources/chat/completions.js';
|
|
4
5
|
import { RequestOptions } from 'openai/core.mjs';
|
|
5
6
|
import { ModelCapability } from '@zqagent/shared/model-capabilities';
|
|
@@ -344,22 +345,40 @@ declare class OpenAIProvider implements ProviderClient {
|
|
|
344
345
|
private _logDir?;
|
|
345
346
|
/** 服务端点 baseURL(用于识别 DeepSeek 等特定供应商) */
|
|
346
347
|
private _baseURL;
|
|
347
|
-
/**
|
|
348
|
-
|
|
348
|
+
/**
|
|
349
|
+
* 本实例的 API 模式。
|
|
350
|
+
*
|
|
351
|
+
* 显式配置 > 全局 `OPENAI_FORCE_API_MODE` > auto(先 Responses 再降级)。
|
|
352
|
+
* 早先只有全局环境变量一种表达方式,一个节点挂两家供应商时无法各自指定。
|
|
353
|
+
*/
|
|
354
|
+
private _apiMode;
|
|
349
355
|
constructor(opts: {
|
|
350
356
|
apiKey?: string;
|
|
351
357
|
baseURL?: string;
|
|
352
358
|
/** LLM 请求日志根目录,按日期分目录,不传则不记录 */
|
|
353
359
|
logDir?: string;
|
|
360
|
+
/**
|
|
361
|
+
* 单次请求超时(毫秒)。缺省/非法时回落到 `OPENAI_TIMEOUT_MS`,再回落 10 分钟。
|
|
362
|
+
*
|
|
363
|
+
* 必须能按供应商设置:推理模型的合理预算与普通模型差一个数量级,共用一个全局值
|
|
364
|
+
* 只能二选一(慢模型被掐断,或快模型失败时干等十分钟)。
|
|
365
|
+
*/
|
|
366
|
+
timeoutMs?: number | null;
|
|
367
|
+
/**
|
|
368
|
+
* API 模式(auto / responses / chat)。缺省时读 `OPENAI_FORCE_API_MODE`,再缺省 auto。
|
|
369
|
+
*/
|
|
370
|
+
apiMode?: ApiMode | null;
|
|
354
371
|
});
|
|
355
372
|
/**
|
|
356
373
|
* 解析指定模型的 API 模式。
|
|
357
374
|
*
|
|
358
|
-
*
|
|
359
|
-
* >
|
|
375
|
+
* 优先级:本实例的显式配置(responses|chat)
|
|
376
|
+
* > 运行时降级缓存(该端点+模型曾因"不支持"失败而缓存为 chat)
|
|
360
377
|
* > 默认 responses(Responses 优先)。
|
|
361
378
|
*/
|
|
362
379
|
private _resolveMode;
|
|
380
|
+
/** 记录「该端点+模型不支持 Responses」,后续同进程内的请求直走 Chat */
|
|
381
|
+
private _markChatMode;
|
|
363
382
|
/**
|
|
364
383
|
* Responses 失败的分类(决定「能不能改走 Chat Completions」以及要不要缓存降级)。
|
|
365
384
|
*
|
package/dist/index.cjs
CHANGED
|
@@ -386,9 +386,23 @@ function paramErrorHints(message, code = "") {
|
|
|
386
386
|
}
|
|
387
387
|
return hints;
|
|
388
388
|
}
|
|
389
|
-
|
|
389
|
+
var DEFAULT_LLM_TIMEOUT_MS = 6e5;
|
|
390
|
+
function normLlmTimeoutMs(v) {
|
|
391
|
+
if (v === null || v === void 0 || v === "") return null;
|
|
392
|
+
const n = Number(v);
|
|
393
|
+
if (!Number.isFinite(n) || n <= 0) return null;
|
|
394
|
+
return Math.min(Math.round(n), 30 * 6e4);
|
|
395
|
+
}
|
|
396
|
+
function llmTimeoutMs(explicit) {
|
|
397
|
+
const fromArg = normLlmTimeoutMs(explicit);
|
|
398
|
+
if (fromArg) return fromArg;
|
|
390
399
|
const n = Number(process.env.OPENAI_TIMEOUT_MS);
|
|
391
|
-
return Number.isFinite(n) && n > 0 ? n :
|
|
400
|
+
return Number.isFinite(n) && n > 0 ? n : DEFAULT_LLM_TIMEOUT_MS;
|
|
401
|
+
}
|
|
402
|
+
function normApiMode(v) {
|
|
403
|
+
const s = typeof v === "string" ? v.trim().toLowerCase() : "";
|
|
404
|
+
if (s === "auto" || s === "responses" || s === "chat") return s;
|
|
405
|
+
return null;
|
|
392
406
|
}
|
|
393
407
|
function llmStreamIdleMs() {
|
|
394
408
|
const n = Number(process.env.OPENAI_STREAM_IDLE_MS);
|
|
@@ -4615,6 +4629,11 @@ var ResponsesApiError = class extends Error {
|
|
|
4615
4629
|
type;
|
|
4616
4630
|
requestId;
|
|
4617
4631
|
};
|
|
4632
|
+
var NO_AUTH_KEY = "not-needed";
|
|
4633
|
+
var degradedModes = /* @__PURE__ */ new Map();
|
|
4634
|
+
function modeKey(baseURL, model) {
|
|
4635
|
+
return `${baseURL}::${model}`;
|
|
4636
|
+
}
|
|
4618
4637
|
var OpenAIProvider = class {
|
|
4619
4638
|
/** OpenAI SDK 客户端 */
|
|
4620
4639
|
client;
|
|
@@ -4622,23 +4641,31 @@ var OpenAIProvider = class {
|
|
|
4622
4641
|
_logDir;
|
|
4623
4642
|
/** 服务端点 baseURL(用于识别 DeepSeek 等特定供应商) */
|
|
4624
4643
|
_baseURL;
|
|
4625
|
-
/**
|
|
4626
|
-
|
|
4644
|
+
/**
|
|
4645
|
+
* 本实例的 API 模式。
|
|
4646
|
+
*
|
|
4647
|
+
* 显式配置 > 全局 `OPENAI_FORCE_API_MODE` > auto(先 Responses 再降级)。
|
|
4648
|
+
* 早先只有全局环境变量一种表达方式,一个节点挂两家供应商时无法各自指定。
|
|
4649
|
+
*/
|
|
4650
|
+
_apiMode;
|
|
4627
4651
|
constructor(opts) {
|
|
4652
|
+
const explicitKey = opts.apiKey !== void 0;
|
|
4628
4653
|
const apiKey = cleanLlmValue(opts.apiKey ?? process.env.OPENAI_API_KEY);
|
|
4629
4654
|
const baseURL = normalizeBaseURL(opts.baseURL ?? process.env.OPENAI_BASE_URL);
|
|
4630
|
-
if (!apiKey) {
|
|
4655
|
+
if (!apiKey && !explicitKey) {
|
|
4631
4656
|
throw new Error(sanitizeEmoji("\u274C \u672A\u8BBE\u7F6E OPENAI_API_KEY \u73AF\u5883\u53D8\u91CF"));
|
|
4632
4657
|
}
|
|
4658
|
+
const effectiveKey = apiKey ?? NO_AUTH_KEY;
|
|
4633
4659
|
this._baseURL = baseURL ?? "";
|
|
4660
|
+
this._apiMode = normApiMode(opts.apiMode) ?? normApiMode(process.env.OPENAI_FORCE_API_MODE) ?? "auto";
|
|
4634
4661
|
const agent = socksAgent();
|
|
4635
4662
|
const proxyHint = unsupportedProxyHint();
|
|
4636
4663
|
if (proxyHint) console.warn(`[llm] ${proxyHint}`);
|
|
4637
4664
|
const baseFetch = agent ? makeSocksFetch(agent) : ((input, init) => globalThis.fetch(input, init));
|
|
4638
4665
|
this.client = new import_openai.default({
|
|
4639
|
-
apiKey,
|
|
4666
|
+
apiKey: effectiveKey,
|
|
4640
4667
|
...baseURL ? { baseURL } : {},
|
|
4641
|
-
timeout: llmTimeoutMs(),
|
|
4668
|
+
timeout: llmTimeoutMs(opts.timeoutMs),
|
|
4642
4669
|
maxRetries: llmMaxRetries(),
|
|
4643
4670
|
// 类型:SDK 期望 (RequestInfo, RequestInit) => Promise<Response>,
|
|
4644
4671
|
// node-fetch 的 Response 与 DOM Response 结构不同,此处显式放宽
|
|
@@ -4655,14 +4682,17 @@ var OpenAIProvider = class {
|
|
|
4655
4682
|
/**
|
|
4656
4683
|
* 解析指定模型的 API 模式。
|
|
4657
4684
|
*
|
|
4658
|
-
*
|
|
4659
|
-
* >
|
|
4685
|
+
* 优先级:本实例的显式配置(responses|chat)
|
|
4686
|
+
* > 运行时降级缓存(该端点+模型曾因"不支持"失败而缓存为 chat)
|
|
4660
4687
|
* > 默认 responses(Responses 优先)。
|
|
4661
4688
|
*/
|
|
4662
4689
|
_resolveMode(model) {
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4690
|
+
if (this._apiMode !== "auto") return this._apiMode;
|
|
4691
|
+
return degradedModes.get(modeKey(this._baseURL, model)) ?? "responses";
|
|
4692
|
+
}
|
|
4693
|
+
/** 记录「该端点+模型不支持 Responses」,后续同进程内的请求直走 Chat */
|
|
4694
|
+
_markChatMode(model) {
|
|
4695
|
+
degradedModes.set(modeKey(this._baseURL, model), "chat");
|
|
4666
4696
|
}
|
|
4667
4697
|
/**
|
|
4668
4698
|
* Responses 失败的分类(决定「能不能改走 Chat Completions」以及要不要缓存降级)。
|
|
@@ -4738,7 +4768,7 @@ var OpenAIProvider = class {
|
|
|
4738
4768
|
} catch (err) {
|
|
4739
4769
|
const kind = this._responsesFailureKind(err, true);
|
|
4740
4770
|
if (kind) {
|
|
4741
|
-
if (kind === "endpoint") this.
|
|
4771
|
+
if (kind === "endpoint") this._markChatMode(model);
|
|
4742
4772
|
console.warn(
|
|
4743
4773
|
`[llm] ${model} Responses API \u4E0D\u53EF\u7528(${kind})\uFF0C\u6539\u7528 Chat Completions (${String(
|
|
4744
4774
|
err?.message ?? err
|
|
@@ -4812,7 +4842,7 @@ var OpenAIProvider = class {
|
|
|
4812
4842
|
} catch (err) {
|
|
4813
4843
|
const kind = this._responsesFailureKind(err, true);
|
|
4814
4844
|
if (kind) {
|
|
4815
|
-
if (kind === "endpoint") this.
|
|
4845
|
+
if (kind === "endpoint") this._markChatMode(model);
|
|
4816
4846
|
console.warn(
|
|
4817
4847
|
`[llm] ${model} Responses API \u4E0D\u53EF\u7528(${kind})\uFF0C\u6539\u7528 Chat Completions (${String(
|
|
4818
4848
|
err?.message ?? err
|
|
@@ -4858,7 +4888,7 @@ var OpenAIProvider = class {
|
|
|
4858
4888
|
} catch (err) {
|
|
4859
4889
|
const kind = emitted ? null : this._responsesFailureKind(err, false);
|
|
4860
4890
|
if (!kind) throw enrichLlmError(err, this._baseURL);
|
|
4861
|
-
if (kind === "endpoint") this.
|
|
4891
|
+
if (kind === "endpoint") this._markChatMode(ctx.model);
|
|
4862
4892
|
console.warn(
|
|
4863
4893
|
`[llm] ${ctx.model} Responses \u6D41\u5185\u5931\u8D25(${kind})\uFF0C\u6539\u7528 Chat Completions (${String(
|
|
4864
4894
|
err?.message ?? err
|
|
@@ -13387,6 +13417,8 @@ function createDefaultEngine(opts) {
|
|
|
13387
13417
|
mode = "interactive" /* INTERACTIVE */,
|
|
13388
13418
|
maxIterations = DEFAULT_MAX_ITERATIONS,
|
|
13389
13419
|
reasoningEffort,
|
|
13420
|
+
timeoutMs,
|
|
13421
|
+
apiMode,
|
|
13390
13422
|
allowedCommands = [],
|
|
13391
13423
|
shellPolicy = "approve",
|
|
13392
13424
|
sandbox,
|
|
@@ -13407,7 +13439,7 @@ function createDefaultEngine(opts) {
|
|
|
13407
13439
|
} = opts;
|
|
13408
13440
|
const envEffort = process.env.OPENAI_REASONING_EFFORT?.toLowerCase();
|
|
13409
13441
|
const effectiveEffort = reasoningEffort ?? (envEffort === "low" || envEffort === "medium" || envEffort === "high" ? envEffort : void 0);
|
|
13410
|
-
const effectiveProvider = provider ?? new OpenAIProvider({ logDir });
|
|
13442
|
+
const effectiveProvider = provider ?? new OpenAIProvider({ logDir, timeoutMs, apiMode });
|
|
13411
13443
|
const sandboxPlan = resolveSandbox({ ...sandbox, workspace });
|
|
13412
13444
|
const registry = new ToolRegistry();
|
|
13413
13445
|
const conflictGuard = new ConflictGuard();
|