@librechat/agents 3.1.94 → 3.1.95
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/cjs/tools/ptcTimeout.cjs +8 -2
- package/dist/cjs/tools/ptcTimeout.cjs.map +1 -1
- package/dist/esm/tools/ptcTimeout.mjs +8 -3
- package/dist/esm/tools/ptcTimeout.mjs.map +1 -1
- package/dist/types/tools/ptcTimeout.d.ts +1 -0
- package/package.json +1 -1
- package/src/tools/__tests__/CodeApiAuthHeaders.test.ts +44 -1
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +76 -0
- package/src/tools/ptcTimeout.ts +12 -2
|
@@ -4,6 +4,7 @@ var _enum = require('../common/enum.cjs');
|
|
|
4
4
|
|
|
5
5
|
const DEFAULT_CODE_API_RUN_TIMEOUT_MS = 15_000;
|
|
6
6
|
const MIN_CODE_API_RUN_TIMEOUT_MS = 1_000;
|
|
7
|
+
const MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS = 300_000;
|
|
7
8
|
function normalizeTimeoutMs(value) {
|
|
8
9
|
if (value == null || !Number.isFinite(value)) {
|
|
9
10
|
return undefined;
|
|
@@ -36,19 +37,24 @@ function clampCodeApiRunTimeoutMs(timeoutMs, maxRunTimeoutMs = resolveCodeApiRun
|
|
|
36
37
|
}
|
|
37
38
|
function createCodeApiRunTimeoutSchema(maxRunTimeoutMs = resolveCodeApiRunTimeoutMs()) {
|
|
38
39
|
const normalizedMaxRunTimeoutMs = normalizeTimeoutMs(maxRunTimeoutMs) ?? DEFAULT_CODE_API_RUN_TIMEOUT_MS;
|
|
40
|
+
const normalizedSchemaMaxRunTimeoutMs = Math.max(normalizedMaxRunTimeoutMs, MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS);
|
|
39
41
|
const formattedTimeout = formatTimeout(normalizedMaxRunTimeoutMs);
|
|
42
|
+
const formattedSchemaMaxTimeout = formatTimeout(normalizedSchemaMaxRunTimeoutMs);
|
|
40
43
|
return {
|
|
41
44
|
type: 'integer',
|
|
42
45
|
minimum: MIN_CODE_API_RUN_TIMEOUT_MS,
|
|
43
|
-
maximum:
|
|
46
|
+
maximum: normalizedSchemaMaxRunTimeoutMs,
|
|
44
47
|
default: normalizedMaxRunTimeoutMs,
|
|
45
48
|
description: 'Maximum wall-clock time in milliseconds for one sandbox run or replay iteration. ' +
|
|
46
49
|
'This is not the total multi-round-trip task budget. ' +
|
|
47
|
-
`Default: ${formattedTimeout}.
|
|
50
|
+
`Default: ${formattedTimeout}. ` +
|
|
51
|
+
'Accepted values above the configured cap are clamped before execution. ' +
|
|
52
|
+
`Schema max: ${formattedSchemaMaxTimeout}. Configured cap: ${formattedTimeout}.`,
|
|
48
53
|
};
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
exports.DEFAULT_CODE_API_RUN_TIMEOUT_MS = DEFAULT_CODE_API_RUN_TIMEOUT_MS;
|
|
57
|
+
exports.MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS = MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS;
|
|
52
58
|
exports.MIN_CODE_API_RUN_TIMEOUT_MS = MIN_CODE_API_RUN_TIMEOUT_MS;
|
|
53
59
|
exports.clampCodeApiRunTimeoutMs = clampCodeApiRunTimeoutMs;
|
|
54
60
|
exports.createCodeApiRunTimeoutSchema = createCodeApiRunTimeoutSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ptcTimeout.cjs","sources":["../../../src/tools/ptcTimeout.ts"],"sourcesContent":["import { EnvVar } from '@/common';\n\nexport const DEFAULT_CODE_API_RUN_TIMEOUT_MS = 15_000;\nexport const MIN_CODE_API_RUN_TIMEOUT_MS = 1_000;\n\ntype TimeoutSchema = {\n type: 'integer';\n minimum: number;\n maximum: number;\n default: number;\n description: string;\n};\n\nexport type ProgrammaticToolCallingJsonSchema = {\n type: 'object';\n properties: {\n code: {\n type: 'string';\n minLength: number;\n description: string;\n };\n timeout: TimeoutSchema;\n };\n required: readonly ['code'];\n};\n\nfunction normalizeTimeoutMs(value: number | undefined): number | undefined {\n if (value == null || !Number.isFinite(value)) {\n return undefined;\n }\n\n return Math.max(MIN_CODE_API_RUN_TIMEOUT_MS, Math.floor(value));\n}\n\nfunction parseTimeoutMs(value: string | undefined): number | undefined {\n if (value == null || value.trim() === '') {\n return undefined;\n }\n\n return normalizeTimeoutMs(Number(value));\n}\n\nfunction formatTimeout(timeoutMs: number): string {\n return timeoutMs % 1000 === 0\n ? `${timeoutMs / 1000} seconds`\n : `${timeoutMs} milliseconds`;\n}\n\nexport function resolveCodeApiRunTimeoutMs(override?: number): number {\n return (\n normalizeTimeoutMs(override) ??\n parseTimeoutMs(process.env[EnvVar.CODE_API_RUN_TIMEOUT_MS]) ??\n DEFAULT_CODE_API_RUN_TIMEOUT_MS\n );\n}\n\nexport function clampCodeApiRunTimeoutMs(\n timeoutMs: number | undefined,\n maxRunTimeoutMs = resolveCodeApiRunTimeoutMs()\n): number {\n const normalizedMaxRunTimeoutMs =\n normalizeTimeoutMs(maxRunTimeoutMs) ?? DEFAULT_CODE_API_RUN_TIMEOUT_MS;\n const normalizedTimeoutMs = normalizeTimeoutMs(timeoutMs);\n\n if (normalizedTimeoutMs == null) {\n return normalizedMaxRunTimeoutMs;\n }\n\n return Math.min(normalizedTimeoutMs, normalizedMaxRunTimeoutMs);\n}\n\nexport function createCodeApiRunTimeoutSchema(\n maxRunTimeoutMs = resolveCodeApiRunTimeoutMs()\n): TimeoutSchema {\n const normalizedMaxRunTimeoutMs =\n normalizeTimeoutMs(maxRunTimeoutMs) ?? DEFAULT_CODE_API_RUN_TIMEOUT_MS;\n const formattedTimeout = formatTimeout(normalizedMaxRunTimeoutMs);\n\n return {\n type: 'integer',\n minimum: MIN_CODE_API_RUN_TIMEOUT_MS,\n maximum:
|
|
1
|
+
{"version":3,"file":"ptcTimeout.cjs","sources":["../../../src/tools/ptcTimeout.ts"],"sourcesContent":["import { EnvVar } from '@/common';\n\nexport const DEFAULT_CODE_API_RUN_TIMEOUT_MS = 15_000;\nexport const MIN_CODE_API_RUN_TIMEOUT_MS = 1_000;\nexport const MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS = 300_000;\n\ntype TimeoutSchema = {\n type: 'integer';\n minimum: number;\n maximum: number;\n default: number;\n description: string;\n};\n\nexport type ProgrammaticToolCallingJsonSchema = {\n type: 'object';\n properties: {\n code: {\n type: 'string';\n minLength: number;\n description: string;\n };\n timeout: TimeoutSchema;\n };\n required: readonly ['code'];\n};\n\nfunction normalizeTimeoutMs(value: number | undefined): number | undefined {\n if (value == null || !Number.isFinite(value)) {\n return undefined;\n }\n\n return Math.max(MIN_CODE_API_RUN_TIMEOUT_MS, Math.floor(value));\n}\n\nfunction parseTimeoutMs(value: string | undefined): number | undefined {\n if (value == null || value.trim() === '') {\n return undefined;\n }\n\n return normalizeTimeoutMs(Number(value));\n}\n\nfunction formatTimeout(timeoutMs: number): string {\n return timeoutMs % 1000 === 0\n ? `${timeoutMs / 1000} seconds`\n : `${timeoutMs} milliseconds`;\n}\n\nexport function resolveCodeApiRunTimeoutMs(override?: number): number {\n return (\n normalizeTimeoutMs(override) ??\n parseTimeoutMs(process.env[EnvVar.CODE_API_RUN_TIMEOUT_MS]) ??\n DEFAULT_CODE_API_RUN_TIMEOUT_MS\n );\n}\n\nexport function clampCodeApiRunTimeoutMs(\n timeoutMs: number | undefined,\n maxRunTimeoutMs = resolveCodeApiRunTimeoutMs()\n): number {\n const normalizedMaxRunTimeoutMs =\n normalizeTimeoutMs(maxRunTimeoutMs) ?? DEFAULT_CODE_API_RUN_TIMEOUT_MS;\n const normalizedTimeoutMs = normalizeTimeoutMs(timeoutMs);\n\n if (normalizedTimeoutMs == null) {\n return normalizedMaxRunTimeoutMs;\n }\n\n return Math.min(normalizedTimeoutMs, normalizedMaxRunTimeoutMs);\n}\n\nexport function createCodeApiRunTimeoutSchema(\n maxRunTimeoutMs = resolveCodeApiRunTimeoutMs()\n): TimeoutSchema {\n const normalizedMaxRunTimeoutMs =\n normalizeTimeoutMs(maxRunTimeoutMs) ?? DEFAULT_CODE_API_RUN_TIMEOUT_MS;\n const normalizedSchemaMaxRunTimeoutMs = Math.max(\n normalizedMaxRunTimeoutMs,\n MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS\n );\n const formattedTimeout = formatTimeout(normalizedMaxRunTimeoutMs);\n const formattedSchemaMaxTimeout = formatTimeout(\n normalizedSchemaMaxRunTimeoutMs\n );\n\n return {\n type: 'integer',\n minimum: MIN_CODE_API_RUN_TIMEOUT_MS,\n maximum: normalizedSchemaMaxRunTimeoutMs,\n default: normalizedMaxRunTimeoutMs,\n description:\n 'Maximum wall-clock time in milliseconds for one sandbox run or replay iteration. ' +\n 'This is not the total multi-round-trip task budget. ' +\n `Default: ${formattedTimeout}. ` +\n 'Accepted values above the configured cap are clamped before execution. ' +\n `Schema max: ${formattedSchemaMaxTimeout}. Configured cap: ${formattedTimeout}.`,\n };\n}\n"],"names":["EnvVar"],"mappings":";;;;AAEO,MAAM,+BAA+B,GAAG;AACxC,MAAM,2BAA2B,GAAG;AACpC,MAAM,kCAAkC,GAAG;AAuBlD,SAAS,kBAAkB,CAAC,KAAyB,EAAA;AACnD,IAAA,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;AAC5C,QAAA,OAAO,SAAS;IAClB;AAEA,IAAA,OAAO,IAAI,CAAC,GAAG,CAAC,2BAA2B,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACjE;AAEA,SAAS,cAAc,CAAC,KAAyB,EAAA;IAC/C,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;AACxC,QAAA,OAAO,SAAS;IAClB;AAEA,IAAA,OAAO,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1C;AAEA,SAAS,aAAa,CAAC,SAAiB,EAAA;AACtC,IAAA,OAAO,SAAS,GAAG,IAAI,KAAK;AAC1B,UAAE,CAAA,EAAG,SAAS,GAAG,IAAI,CAAA,QAAA;AACrB,UAAE,CAAA,EAAG,SAAS,CAAA,aAAA,CAAe;AACjC;AAEM,SAAU,0BAA0B,CAAC,QAAiB,EAAA;AAC1D,IAAA,QACE,kBAAkB,CAAC,QAAQ,CAAC;QAC5B,cAAc,CAAC,OAAO,CAAC,GAAG,CAACA,YAAM,CAAC,uBAAuB,CAAC,CAAC;AAC3D,QAAA,+BAA+B;AAEnC;AAEM,SAAU,wBAAwB,CACtC,SAA6B,EAC7B,eAAe,GAAG,0BAA0B,EAAE,EAAA;IAE9C,MAAM,yBAAyB,GAC7B,kBAAkB,CAAC,eAAe,CAAC,IAAI,+BAA+B;AACxE,IAAA,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,SAAS,CAAC;AAEzD,IAAA,IAAI,mBAAmB,IAAI,IAAI,EAAE;AAC/B,QAAA,OAAO,yBAAyB;IAClC;IAEA,OAAO,IAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE,yBAAyB,CAAC;AACjE;SAEgB,6BAA6B,CAC3C,eAAe,GAAG,0BAA0B,EAAE,EAAA;IAE9C,MAAM,yBAAyB,GAC7B,kBAAkB,CAAC,eAAe,CAAC,IAAI,+BAA+B;IACxE,MAAM,+BAA+B,GAAG,IAAI,CAAC,GAAG,CAC9C,yBAAyB,EACzB,kCAAkC,CACnC;AACD,IAAA,MAAM,gBAAgB,GAAG,aAAa,CAAC,yBAAyB,CAAC;AACjE,IAAA,MAAM,yBAAyB,GAAG,aAAa,CAC7C,+BAA+B,CAChC;IAED,OAAO;AACL,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,OAAO,EAAE,2BAA2B;AACpC,QAAA,OAAO,EAAE,+BAA+B;AACxC,QAAA,OAAO,EAAE,yBAAyB;AAClC,QAAA,WAAW,EACT,mFAAmF;YACnF,sDAAsD;AACtD,YAAA,CAAA,SAAA,EAAY,gBAAgB,CAAA,EAAA,CAAI;YAChC,yEAAyE;YACzE,CAAA,YAAA,EAAe,yBAAyB,CAAA,kBAAA,EAAqB,gBAAgB,CAAA,CAAA,CAAG;KACnF;AACH;;;;;;;;;"}
|
|
@@ -2,6 +2,7 @@ import { EnvVar } from '../common/enum.mjs';
|
|
|
2
2
|
|
|
3
3
|
const DEFAULT_CODE_API_RUN_TIMEOUT_MS = 15_000;
|
|
4
4
|
const MIN_CODE_API_RUN_TIMEOUT_MS = 1_000;
|
|
5
|
+
const MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS = 300_000;
|
|
5
6
|
function normalizeTimeoutMs(value) {
|
|
6
7
|
if (value == null || !Number.isFinite(value)) {
|
|
7
8
|
return undefined;
|
|
@@ -34,17 +35,21 @@ function clampCodeApiRunTimeoutMs(timeoutMs, maxRunTimeoutMs = resolveCodeApiRun
|
|
|
34
35
|
}
|
|
35
36
|
function createCodeApiRunTimeoutSchema(maxRunTimeoutMs = resolveCodeApiRunTimeoutMs()) {
|
|
36
37
|
const normalizedMaxRunTimeoutMs = normalizeTimeoutMs(maxRunTimeoutMs) ?? DEFAULT_CODE_API_RUN_TIMEOUT_MS;
|
|
38
|
+
const normalizedSchemaMaxRunTimeoutMs = Math.max(normalizedMaxRunTimeoutMs, MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS);
|
|
37
39
|
const formattedTimeout = formatTimeout(normalizedMaxRunTimeoutMs);
|
|
40
|
+
const formattedSchemaMaxTimeout = formatTimeout(normalizedSchemaMaxRunTimeoutMs);
|
|
38
41
|
return {
|
|
39
42
|
type: 'integer',
|
|
40
43
|
minimum: MIN_CODE_API_RUN_TIMEOUT_MS,
|
|
41
|
-
maximum:
|
|
44
|
+
maximum: normalizedSchemaMaxRunTimeoutMs,
|
|
42
45
|
default: normalizedMaxRunTimeoutMs,
|
|
43
46
|
description: 'Maximum wall-clock time in milliseconds for one sandbox run or replay iteration. ' +
|
|
44
47
|
'This is not the total multi-round-trip task budget. ' +
|
|
45
|
-
`Default: ${formattedTimeout}.
|
|
48
|
+
`Default: ${formattedTimeout}. ` +
|
|
49
|
+
'Accepted values above the configured cap are clamped before execution. ' +
|
|
50
|
+
`Schema max: ${formattedSchemaMaxTimeout}. Configured cap: ${formattedTimeout}.`,
|
|
46
51
|
};
|
|
47
52
|
}
|
|
48
53
|
|
|
49
|
-
export { DEFAULT_CODE_API_RUN_TIMEOUT_MS, MIN_CODE_API_RUN_TIMEOUT_MS, clampCodeApiRunTimeoutMs, createCodeApiRunTimeoutSchema, resolveCodeApiRunTimeoutMs };
|
|
54
|
+
export { DEFAULT_CODE_API_RUN_TIMEOUT_MS, MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS, MIN_CODE_API_RUN_TIMEOUT_MS, clampCodeApiRunTimeoutMs, createCodeApiRunTimeoutSchema, resolveCodeApiRunTimeoutMs };
|
|
50
55
|
//# sourceMappingURL=ptcTimeout.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ptcTimeout.mjs","sources":["../../../src/tools/ptcTimeout.ts"],"sourcesContent":["import { EnvVar } from '@/common';\n\nexport const DEFAULT_CODE_API_RUN_TIMEOUT_MS = 15_000;\nexport const MIN_CODE_API_RUN_TIMEOUT_MS = 1_000;\n\ntype TimeoutSchema = {\n type: 'integer';\n minimum: number;\n maximum: number;\n default: number;\n description: string;\n};\n\nexport type ProgrammaticToolCallingJsonSchema = {\n type: 'object';\n properties: {\n code: {\n type: 'string';\n minLength: number;\n description: string;\n };\n timeout: TimeoutSchema;\n };\n required: readonly ['code'];\n};\n\nfunction normalizeTimeoutMs(value: number | undefined): number | undefined {\n if (value == null || !Number.isFinite(value)) {\n return undefined;\n }\n\n return Math.max(MIN_CODE_API_RUN_TIMEOUT_MS, Math.floor(value));\n}\n\nfunction parseTimeoutMs(value: string | undefined): number | undefined {\n if (value == null || value.trim() === '') {\n return undefined;\n }\n\n return normalizeTimeoutMs(Number(value));\n}\n\nfunction formatTimeout(timeoutMs: number): string {\n return timeoutMs % 1000 === 0\n ? `${timeoutMs / 1000} seconds`\n : `${timeoutMs} milliseconds`;\n}\n\nexport function resolveCodeApiRunTimeoutMs(override?: number): number {\n return (\n normalizeTimeoutMs(override) ??\n parseTimeoutMs(process.env[EnvVar.CODE_API_RUN_TIMEOUT_MS]) ??\n DEFAULT_CODE_API_RUN_TIMEOUT_MS\n );\n}\n\nexport function clampCodeApiRunTimeoutMs(\n timeoutMs: number | undefined,\n maxRunTimeoutMs = resolveCodeApiRunTimeoutMs()\n): number {\n const normalizedMaxRunTimeoutMs =\n normalizeTimeoutMs(maxRunTimeoutMs) ?? DEFAULT_CODE_API_RUN_TIMEOUT_MS;\n const normalizedTimeoutMs = normalizeTimeoutMs(timeoutMs);\n\n if (normalizedTimeoutMs == null) {\n return normalizedMaxRunTimeoutMs;\n }\n\n return Math.min(normalizedTimeoutMs, normalizedMaxRunTimeoutMs);\n}\n\nexport function createCodeApiRunTimeoutSchema(\n maxRunTimeoutMs = resolveCodeApiRunTimeoutMs()\n): TimeoutSchema {\n const normalizedMaxRunTimeoutMs =\n normalizeTimeoutMs(maxRunTimeoutMs) ?? DEFAULT_CODE_API_RUN_TIMEOUT_MS;\n const formattedTimeout = formatTimeout(normalizedMaxRunTimeoutMs);\n\n return {\n type: 'integer',\n minimum: MIN_CODE_API_RUN_TIMEOUT_MS,\n maximum:
|
|
1
|
+
{"version":3,"file":"ptcTimeout.mjs","sources":["../../../src/tools/ptcTimeout.ts"],"sourcesContent":["import { EnvVar } from '@/common';\n\nexport const DEFAULT_CODE_API_RUN_TIMEOUT_MS = 15_000;\nexport const MIN_CODE_API_RUN_TIMEOUT_MS = 1_000;\nexport const MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS = 300_000;\n\ntype TimeoutSchema = {\n type: 'integer';\n minimum: number;\n maximum: number;\n default: number;\n description: string;\n};\n\nexport type ProgrammaticToolCallingJsonSchema = {\n type: 'object';\n properties: {\n code: {\n type: 'string';\n minLength: number;\n description: string;\n };\n timeout: TimeoutSchema;\n };\n required: readonly ['code'];\n};\n\nfunction normalizeTimeoutMs(value: number | undefined): number | undefined {\n if (value == null || !Number.isFinite(value)) {\n return undefined;\n }\n\n return Math.max(MIN_CODE_API_RUN_TIMEOUT_MS, Math.floor(value));\n}\n\nfunction parseTimeoutMs(value: string | undefined): number | undefined {\n if (value == null || value.trim() === '') {\n return undefined;\n }\n\n return normalizeTimeoutMs(Number(value));\n}\n\nfunction formatTimeout(timeoutMs: number): string {\n return timeoutMs % 1000 === 0\n ? `${timeoutMs / 1000} seconds`\n : `${timeoutMs} milliseconds`;\n}\n\nexport function resolveCodeApiRunTimeoutMs(override?: number): number {\n return (\n normalizeTimeoutMs(override) ??\n parseTimeoutMs(process.env[EnvVar.CODE_API_RUN_TIMEOUT_MS]) ??\n DEFAULT_CODE_API_RUN_TIMEOUT_MS\n );\n}\n\nexport function clampCodeApiRunTimeoutMs(\n timeoutMs: number | undefined,\n maxRunTimeoutMs = resolveCodeApiRunTimeoutMs()\n): number {\n const normalizedMaxRunTimeoutMs =\n normalizeTimeoutMs(maxRunTimeoutMs) ?? DEFAULT_CODE_API_RUN_TIMEOUT_MS;\n const normalizedTimeoutMs = normalizeTimeoutMs(timeoutMs);\n\n if (normalizedTimeoutMs == null) {\n return normalizedMaxRunTimeoutMs;\n }\n\n return Math.min(normalizedTimeoutMs, normalizedMaxRunTimeoutMs);\n}\n\nexport function createCodeApiRunTimeoutSchema(\n maxRunTimeoutMs = resolveCodeApiRunTimeoutMs()\n): TimeoutSchema {\n const normalizedMaxRunTimeoutMs =\n normalizeTimeoutMs(maxRunTimeoutMs) ?? DEFAULT_CODE_API_RUN_TIMEOUT_MS;\n const normalizedSchemaMaxRunTimeoutMs = Math.max(\n normalizedMaxRunTimeoutMs,\n MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS\n );\n const formattedTimeout = formatTimeout(normalizedMaxRunTimeoutMs);\n const formattedSchemaMaxTimeout = formatTimeout(\n normalizedSchemaMaxRunTimeoutMs\n );\n\n return {\n type: 'integer',\n minimum: MIN_CODE_API_RUN_TIMEOUT_MS,\n maximum: normalizedSchemaMaxRunTimeoutMs,\n default: normalizedMaxRunTimeoutMs,\n description:\n 'Maximum wall-clock time in milliseconds for one sandbox run or replay iteration. ' +\n 'This is not the total multi-round-trip task budget. ' +\n `Default: ${formattedTimeout}. ` +\n 'Accepted values above the configured cap are clamped before execution. ' +\n `Schema max: ${formattedSchemaMaxTimeout}. Configured cap: ${formattedTimeout}.`,\n };\n}\n"],"names":[],"mappings":";;AAEO,MAAM,+BAA+B,GAAG;AACxC,MAAM,2BAA2B,GAAG;AACpC,MAAM,kCAAkC,GAAG;AAuBlD,SAAS,kBAAkB,CAAC,KAAyB,EAAA;AACnD,IAAA,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;AAC5C,QAAA,OAAO,SAAS;IAClB;AAEA,IAAA,OAAO,IAAI,CAAC,GAAG,CAAC,2BAA2B,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACjE;AAEA,SAAS,cAAc,CAAC,KAAyB,EAAA;IAC/C,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;AACxC,QAAA,OAAO,SAAS;IAClB;AAEA,IAAA,OAAO,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1C;AAEA,SAAS,aAAa,CAAC,SAAiB,EAAA;AACtC,IAAA,OAAO,SAAS,GAAG,IAAI,KAAK;AAC1B,UAAE,CAAA,EAAG,SAAS,GAAG,IAAI,CAAA,QAAA;AACrB,UAAE,CAAA,EAAG,SAAS,CAAA,aAAA,CAAe;AACjC;AAEM,SAAU,0BAA0B,CAAC,QAAiB,EAAA;AAC1D,IAAA,QACE,kBAAkB,CAAC,QAAQ,CAAC;QAC5B,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAC3D,QAAA,+BAA+B;AAEnC;AAEM,SAAU,wBAAwB,CACtC,SAA6B,EAC7B,eAAe,GAAG,0BAA0B,EAAE,EAAA;IAE9C,MAAM,yBAAyB,GAC7B,kBAAkB,CAAC,eAAe,CAAC,IAAI,+BAA+B;AACxE,IAAA,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,SAAS,CAAC;AAEzD,IAAA,IAAI,mBAAmB,IAAI,IAAI,EAAE;AAC/B,QAAA,OAAO,yBAAyB;IAClC;IAEA,OAAO,IAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE,yBAAyB,CAAC;AACjE;SAEgB,6BAA6B,CAC3C,eAAe,GAAG,0BAA0B,EAAE,EAAA;IAE9C,MAAM,yBAAyB,GAC7B,kBAAkB,CAAC,eAAe,CAAC,IAAI,+BAA+B;IACxE,MAAM,+BAA+B,GAAG,IAAI,CAAC,GAAG,CAC9C,yBAAyB,EACzB,kCAAkC,CACnC;AACD,IAAA,MAAM,gBAAgB,GAAG,aAAa,CAAC,yBAAyB,CAAC;AACjE,IAAA,MAAM,yBAAyB,GAAG,aAAa,CAC7C,+BAA+B,CAChC;IAED,OAAO;AACL,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,OAAO,EAAE,2BAA2B;AACpC,QAAA,OAAO,EAAE,+BAA+B;AACxC,QAAA,OAAO,EAAE,yBAAyB;AAClC,QAAA,WAAW,EACT,mFAAmF;YACnF,sDAAsD;AACtD,YAAA,CAAA,SAAA,EAAY,gBAAgB,CAAA,EAAA,CAAI;YAChC,yEAAyE;YACzE,CAAA,YAAA,EAAe,yBAAyB,CAAA,kBAAA,EAAqB,gBAAgB,CAAA,CAAA,CAAG;KACnF;AACH;;;;"}
|
package/package.json
CHANGED
|
@@ -16,6 +16,7 @@ import { createBashProgrammaticToolCallingTool } from '../BashProgrammaticToolCa
|
|
|
16
16
|
import {
|
|
17
17
|
clampCodeApiRunTimeoutMs,
|
|
18
18
|
createCodeApiRunTimeoutSchema,
|
|
19
|
+
MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS,
|
|
19
20
|
} from '../ptcTimeout';
|
|
20
21
|
import {
|
|
21
22
|
createLocalProgrammaticToolCallingTool,
|
|
@@ -267,6 +268,26 @@ describe('CodeAPI auth header injection', () => {
|
|
|
267
268
|
expect(requestBodyAt(0).timeout).toBe(15000);
|
|
268
269
|
});
|
|
269
270
|
|
|
271
|
+
it('accepts larger programmatic timeout inputs and clamps before execution', async () => {
|
|
272
|
+
const tool = createProgrammaticToolCallingTool({
|
|
273
|
+
runTimeoutMs: 15000,
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
await tool.invoke(
|
|
277
|
+
{ code: 'result = await lookup_user()\nprint(result)', timeout: 30000 },
|
|
278
|
+
{
|
|
279
|
+
toolCall: {
|
|
280
|
+
name: 'programmatic_code_execution',
|
|
281
|
+
args: {},
|
|
282
|
+
toolMap: toolMap(),
|
|
283
|
+
toolDefs,
|
|
284
|
+
},
|
|
285
|
+
}
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
expect(requestBodyAt(0).timeout).toBe(15000);
|
|
289
|
+
});
|
|
290
|
+
|
|
270
291
|
it('defaults bash programmatic timeout to the configured CodeAPI run cap', async () => {
|
|
271
292
|
const tool = createBashProgrammaticToolCallingTool({
|
|
272
293
|
runTimeoutMs: 15000,
|
|
@@ -287,14 +308,36 @@ describe('CodeAPI auth header injection', () => {
|
|
|
287
308
|
expect(requestBodyAt(0).timeout).toBe(15000);
|
|
288
309
|
});
|
|
289
310
|
|
|
311
|
+
it('accepts larger bash programmatic timeout inputs and clamps before execution', async () => {
|
|
312
|
+
const tool = createBashProgrammaticToolCallingTool({
|
|
313
|
+
runTimeoutMs: 15000,
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
await tool.invoke(
|
|
317
|
+
{ code: 'lookup_user "{}"', timeout: 30000 },
|
|
318
|
+
{
|
|
319
|
+
toolCall: {
|
|
320
|
+
name: 'bash_programmatic_code_execution',
|
|
321
|
+
args: {},
|
|
322
|
+
toolMap: toolMap(),
|
|
323
|
+
toolDefs,
|
|
324
|
+
},
|
|
325
|
+
}
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
expect(requestBodyAt(0).timeout).toBe(15000);
|
|
329
|
+
});
|
|
330
|
+
|
|
290
331
|
it('describes the PTC timeout as a single sandbox run cap', () => {
|
|
291
332
|
const schema = createCodeApiRunTimeoutSchema(15000);
|
|
292
333
|
|
|
293
334
|
expect(clampCodeApiRunTimeoutMs(60000, 15000)).toBe(15000);
|
|
294
335
|
expect(schema.default).toBe(15000);
|
|
295
|
-
expect(schema.maximum).toBe(
|
|
336
|
+
expect(schema.maximum).toBe(MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS);
|
|
296
337
|
expect(schema.description).toContain('one sandbox run');
|
|
297
338
|
expect(schema.description).toContain('not the total multi-round-trip');
|
|
339
|
+
expect(schema.description).toContain('clamped before execution');
|
|
340
|
+
expect(schema.description).toContain('Configured cap: 15 seconds');
|
|
298
341
|
});
|
|
299
342
|
|
|
300
343
|
it('keeps local programmatic timeout schemas aligned with local execution defaults', () => {
|
|
@@ -106,6 +106,49 @@ describe('ProgrammaticToolCalling', () => {
|
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
108
|
|
|
109
|
+
it('parses ClickHouse-style JSON strings with SQL punctuation for object-schema tools', async () => {
|
|
110
|
+
const invoke = jest.fn<
|
|
111
|
+
(_input: unknown, _config: unknown) => Promise<unknown>
|
|
112
|
+
>(async (input) => input);
|
|
113
|
+
const customTool = {
|
|
114
|
+
name: 'run_select_query_mcp_ClickHouse',
|
|
115
|
+
schema: {
|
|
116
|
+
type: 'object',
|
|
117
|
+
properties: {
|
|
118
|
+
serviceId: { type: 'string' },
|
|
119
|
+
query: { type: 'string' },
|
|
120
|
+
},
|
|
121
|
+
required: ['serviceId', 'query'],
|
|
122
|
+
},
|
|
123
|
+
invoke,
|
|
124
|
+
} as unknown as t.GenericTool;
|
|
125
|
+
const customToolMap: t.ToolMap = new Map([
|
|
126
|
+
['run_select_query_mcp_ClickHouse', customTool],
|
|
127
|
+
]);
|
|
128
|
+
const input = {
|
|
129
|
+
serviceId: '45886e06-932b-4cff-bb49-3f7281d80717',
|
|
130
|
+
query:
|
|
131
|
+
'SELECT name, round(avg(tempAvg)/10.0, 2) AS avg_temp_c ' +
|
|
132
|
+
'FROM system.columns WHERE database=\'default\' ' +
|
|
133
|
+
'AND table=\'uk_prices_3\' AND tempAvg != -9999',
|
|
134
|
+
};
|
|
135
|
+
const toolCalls: t.PTCToolCall[] = [
|
|
136
|
+
{
|
|
137
|
+
id: 'call_001',
|
|
138
|
+
name: 'run_select_query_mcp_ClickHouse',
|
|
139
|
+
input: JSON.stringify(input),
|
|
140
|
+
},
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
const results = await executeTools(toolCalls, customToolMap);
|
|
144
|
+
|
|
145
|
+
expect(results[0].is_error).toBe(false);
|
|
146
|
+
expect(results[0].result).toEqual(input);
|
|
147
|
+
expect(invoke).toHaveBeenCalledWith(input, {
|
|
148
|
+
metadata: { [Constants.PROGRAMMATIC_TOOL_CALLING]: true },
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
109
152
|
it('preserves JSON-looking strings for string-input tools', async () => {
|
|
110
153
|
const invoke = jest.fn<
|
|
111
154
|
(_input: unknown, _config: unknown) => Promise<unknown>
|
|
@@ -133,6 +176,39 @@ describe('ProgrammaticToolCalling', () => {
|
|
|
133
176
|
});
|
|
134
177
|
});
|
|
135
178
|
|
|
179
|
+
it('preserves ClickHouse-style JSON strings for raw string-input tools', async () => {
|
|
180
|
+
const invoke = jest.fn<
|
|
181
|
+
(_input: unknown, _config: unknown) => Promise<unknown>
|
|
182
|
+
>(async (input) => input);
|
|
183
|
+
const customTool = {
|
|
184
|
+
name: 'string_tool',
|
|
185
|
+
schema: { type: 'string' },
|
|
186
|
+
invoke,
|
|
187
|
+
} as unknown as t.GenericTool;
|
|
188
|
+
const customToolMap: t.ToolMap = new Map([['string_tool', customTool]]);
|
|
189
|
+
const input = JSON.stringify({
|
|
190
|
+
serviceId: '45886e06-932b-4cff-bb49-3f7281d80717',
|
|
191
|
+
query:
|
|
192
|
+
'SELECT round(avg(tempAvg)/10.0, 2) AS avg_temp_c ' +
|
|
193
|
+
'FROM default.weather_noaa_mt WHERE database=\'default\'',
|
|
194
|
+
});
|
|
195
|
+
const toolCalls: t.PTCToolCall[] = [
|
|
196
|
+
{
|
|
197
|
+
id: 'call_001',
|
|
198
|
+
name: 'string_tool',
|
|
199
|
+
input,
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
|
|
203
|
+
const results = await executeTools(toolCalls, customToolMap);
|
|
204
|
+
|
|
205
|
+
expect(results[0].is_error).toBe(false);
|
|
206
|
+
expect(results[0].result).toBe(input);
|
|
207
|
+
expect(invoke).toHaveBeenCalledWith(input, {
|
|
208
|
+
metadata: { [Constants.PROGRAMMATIC_TOOL_CALLING]: true },
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
136
212
|
it('stringifies object inputs before invoking string-input tools', async () => {
|
|
137
213
|
const invoke = jest.fn<
|
|
138
214
|
(_input: unknown, _config: unknown) => Promise<unknown>
|
package/src/tools/ptcTimeout.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { EnvVar } from '@/common';
|
|
|
2
2
|
|
|
3
3
|
export const DEFAULT_CODE_API_RUN_TIMEOUT_MS = 15_000;
|
|
4
4
|
export const MIN_CODE_API_RUN_TIMEOUT_MS = 1_000;
|
|
5
|
+
export const MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS = 300_000;
|
|
5
6
|
|
|
6
7
|
type TimeoutSchema = {
|
|
7
8
|
type: 'integer';
|
|
@@ -74,16 +75,25 @@ export function createCodeApiRunTimeoutSchema(
|
|
|
74
75
|
): TimeoutSchema {
|
|
75
76
|
const normalizedMaxRunTimeoutMs =
|
|
76
77
|
normalizeTimeoutMs(maxRunTimeoutMs) ?? DEFAULT_CODE_API_RUN_TIMEOUT_MS;
|
|
78
|
+
const normalizedSchemaMaxRunTimeoutMs = Math.max(
|
|
79
|
+
normalizedMaxRunTimeoutMs,
|
|
80
|
+
MAX_CODE_API_RUN_TIMEOUT_SCHEMA_MS
|
|
81
|
+
);
|
|
77
82
|
const formattedTimeout = formatTimeout(normalizedMaxRunTimeoutMs);
|
|
83
|
+
const formattedSchemaMaxTimeout = formatTimeout(
|
|
84
|
+
normalizedSchemaMaxRunTimeoutMs
|
|
85
|
+
);
|
|
78
86
|
|
|
79
87
|
return {
|
|
80
88
|
type: 'integer',
|
|
81
89
|
minimum: MIN_CODE_API_RUN_TIMEOUT_MS,
|
|
82
|
-
maximum:
|
|
90
|
+
maximum: normalizedSchemaMaxRunTimeoutMs,
|
|
83
91
|
default: normalizedMaxRunTimeoutMs,
|
|
84
92
|
description:
|
|
85
93
|
'Maximum wall-clock time in milliseconds for one sandbox run or replay iteration. ' +
|
|
86
94
|
'This is not the total multi-round-trip task budget. ' +
|
|
87
|
-
`Default: ${formattedTimeout}.
|
|
95
|
+
`Default: ${formattedTimeout}. ` +
|
|
96
|
+
'Accepted values above the configured cap are clamped before execution. ' +
|
|
97
|
+
`Schema max: ${formattedSchemaMaxTimeout}. Configured cap: ${formattedTimeout}.`,
|
|
88
98
|
};
|
|
89
99
|
}
|