@agentfield/sdk 0.1.131-rc.1 → 0.1.131-rc.3
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.js +153 -56
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import fs, { promises, readFileSync } from 'fs';
|
|
2
|
-
import * as path3 from 'path';
|
|
3
|
-
import path3__default, { resolve, dirname } from 'path';
|
|
4
1
|
import { createRequire } from 'module';
|
|
2
|
+
import * as path4 from 'path';
|
|
3
|
+
import path4__default, { resolve, dirname } from 'path';
|
|
4
|
+
import fs, { promises, readFileSync } from 'fs';
|
|
5
5
|
import { spawn } from 'child_process';
|
|
6
6
|
import express from 'express';
|
|
7
7
|
import rateLimit from 'express-rate-limit';
|
|
@@ -69,7 +69,8 @@ function resolveOpenRouterAttribution(options = {}) {
|
|
|
69
69
|
}
|
|
70
70
|
const siteUrl = clean(options.siteUrl) ?? clean(env.AGENTFIELD_OPENROUTER_SITE_URL) ?? clean(env.OR_SITE_URL) ?? DEFAULT_OPENROUTER_SITE_URL;
|
|
71
71
|
const appName = clean(options.appName) ?? clean(env.AGENTFIELD_OPENROUTER_APP_NAME) ?? clean(env.OR_APP_NAME) ?? DEFAULT_OPENROUTER_APP_NAME;
|
|
72
|
-
|
|
72
|
+
const categories = clean(options.categories) ?? clean(env.AGENTFIELD_OPENROUTER_CATEGORIES) ?? clean(env.OR_CATEGORIES) ?? DEFAULT_OPENROUTER_CATEGORIES;
|
|
73
|
+
return { siteUrl, appName, categories };
|
|
73
74
|
}
|
|
74
75
|
function openRouterAttributionHeaders(options = {}) {
|
|
75
76
|
const resolved = resolveOpenRouterAttribution(options);
|
|
@@ -79,7 +80,8 @@ function openRouterAttributionHeaders(options = {}) {
|
|
|
79
80
|
return {
|
|
80
81
|
"HTTP-Referer": resolved.siteUrl,
|
|
81
82
|
"X-OpenRouter-Title": resolved.appName,
|
|
82
|
-
"X-Title": resolved.appName
|
|
83
|
+
"X-Title": resolved.appName,
|
|
84
|
+
"X-OpenRouter-Categories": resolved.categories
|
|
83
85
|
};
|
|
84
86
|
}
|
|
85
87
|
function mergeOpenRouterAttributionHeaders(existing = {}, options = {}) {
|
|
@@ -108,8 +110,10 @@ function openRouterAttributionEnv(env = process.env) {
|
|
|
108
110
|
return {
|
|
109
111
|
AGENTFIELD_OPENROUTER_SITE_URL: resolved.siteUrl,
|
|
110
112
|
AGENTFIELD_OPENROUTER_APP_NAME: resolved.appName,
|
|
113
|
+
AGENTFIELD_OPENROUTER_CATEGORIES: resolved.categories,
|
|
111
114
|
OR_SITE_URL: resolved.siteUrl,
|
|
112
|
-
OR_APP_NAME: resolved.appName
|
|
115
|
+
OR_APP_NAME: resolved.appName,
|
|
116
|
+
OR_CATEGORIES: resolved.categories
|
|
113
117
|
};
|
|
114
118
|
}
|
|
115
119
|
function applyOpenRouterAttributionEnv(env) {
|
|
@@ -117,8 +121,10 @@ function applyOpenRouterAttributionEnv(env) {
|
|
|
117
121
|
for (const key of [
|
|
118
122
|
"AGENTFIELD_OPENROUTER_SITE_URL",
|
|
119
123
|
"AGENTFIELD_OPENROUTER_APP_NAME",
|
|
124
|
+
"AGENTFIELD_OPENROUTER_CATEGORIES",
|
|
120
125
|
"OR_SITE_URL",
|
|
121
|
-
"OR_APP_NAME"
|
|
126
|
+
"OR_APP_NAME",
|
|
127
|
+
"OR_CATEGORIES"
|
|
122
128
|
]) {
|
|
123
129
|
delete env[key];
|
|
124
130
|
}
|
|
@@ -135,11 +141,12 @@ function clean(value) {
|
|
|
135
141
|
const trimmed = value?.trim();
|
|
136
142
|
return trimmed ? trimmed : void 0;
|
|
137
143
|
}
|
|
138
|
-
var DEFAULT_OPENROUTER_SITE_URL, DEFAULT_OPENROUTER_APP_NAME;
|
|
144
|
+
var DEFAULT_OPENROUTER_SITE_URL, DEFAULT_OPENROUTER_APP_NAME, DEFAULT_OPENROUTER_CATEGORIES;
|
|
139
145
|
var init_openrouterAttribution = __esm({
|
|
140
146
|
"src/ai/openrouterAttribution.ts"() {
|
|
141
147
|
DEFAULT_OPENROUTER_SITE_URL = "https://agentfield.ai";
|
|
142
148
|
DEFAULT_OPENROUTER_APP_NAME = "AgentField AI";
|
|
149
|
+
DEFAULT_OPENROUTER_CATEGORIES = "cli-agent,programming-app";
|
|
143
150
|
}
|
|
144
151
|
});
|
|
145
152
|
|
|
@@ -170,6 +177,54 @@ var init_modelVariant = __esm({
|
|
|
170
177
|
MODEL_VARIANT_SEP = "#";
|
|
171
178
|
}
|
|
172
179
|
});
|
|
180
|
+
function isRecord2(value) {
|
|
181
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
182
|
+
}
|
|
183
|
+
function isZod4Schema(value) {
|
|
184
|
+
if (!isRecord2(value) || !("_zod" in value) || !isRecord2(value._zod)) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
return isRecord2(value._zod.def);
|
|
188
|
+
}
|
|
189
|
+
function getZod4Converter() {
|
|
190
|
+
if (zod4Converter !== void 0) {
|
|
191
|
+
return zod4Converter;
|
|
192
|
+
}
|
|
193
|
+
const requires = [];
|
|
194
|
+
try {
|
|
195
|
+
requires.push(createRequire(path4__default.join(process.cwd(), "package.json")));
|
|
196
|
+
} catch {
|
|
197
|
+
}
|
|
198
|
+
requires.push(createRequire(import.meta.url));
|
|
199
|
+
for (const req of requires) {
|
|
200
|
+
for (const moduleName of ["zod", "zod/v4"]) {
|
|
201
|
+
try {
|
|
202
|
+
const mod = req(moduleName);
|
|
203
|
+
if (typeof mod.toJSONSchema === "function") {
|
|
204
|
+
zod4Converter = mod.toJSONSchema;
|
|
205
|
+
return zod4Converter;
|
|
206
|
+
}
|
|
207
|
+
} catch {
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
zod4Converter = null;
|
|
212
|
+
return zod4Converter;
|
|
213
|
+
}
|
|
214
|
+
function zod4ToJsonSchema(schema) {
|
|
215
|
+
const converter = getZod4Converter();
|
|
216
|
+
if (converter === null) {
|
|
217
|
+
throw new TypeError(
|
|
218
|
+
'Cannot convert a Zod 4 schema: install the "zod" package with its "zod/v4" entry point available.'
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
return converter(schema);
|
|
222
|
+
}
|
|
223
|
+
var zod4Converter;
|
|
224
|
+
var init_zod_schema = __esm({
|
|
225
|
+
"src/utils/zod-schema.ts"() {
|
|
226
|
+
}
|
|
227
|
+
});
|
|
173
228
|
function getZodConverter() {
|
|
174
229
|
if (zodConverter !== void 0) {
|
|
175
230
|
return zodConverter;
|
|
@@ -183,21 +238,21 @@ function getZodConverter() {
|
|
|
183
238
|
}
|
|
184
239
|
return zodConverter;
|
|
185
240
|
}
|
|
186
|
-
function
|
|
241
|
+
function isRecord3(value) {
|
|
187
242
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
188
243
|
}
|
|
189
244
|
function hasJsonSchema(value) {
|
|
190
|
-
return
|
|
245
|
+
return isRecord3(value) && typeof value.jsonSchema === "function";
|
|
191
246
|
}
|
|
192
247
|
function hasParse(value) {
|
|
193
|
-
return
|
|
248
|
+
return isRecord3(value) && typeof value.parse === "function";
|
|
194
249
|
}
|
|
195
250
|
function estimateTokens(text2) {
|
|
196
251
|
return Math.floor(text2.length / 4);
|
|
197
252
|
}
|
|
198
253
|
function writeSchemaFile(schemaJson, cwd) {
|
|
199
254
|
const filePath = getSchemaPath(cwd);
|
|
200
|
-
fs.mkdirSync(
|
|
255
|
+
fs.mkdirSync(path4__default.dirname(filePath), { recursive: true });
|
|
201
256
|
const fd = fs.openSync(filePath, "w", 384);
|
|
202
257
|
try {
|
|
203
258
|
fs.writeFileSync(fd, schemaJson, "utf8");
|
|
@@ -213,13 +268,16 @@ function validateAgainstSchema(data, schema) {
|
|
|
213
268
|
return data;
|
|
214
269
|
}
|
|
215
270
|
function getOutputPath(cwd) {
|
|
216
|
-
return
|
|
271
|
+
return path4__default.join(cwd, OUTPUT_FILENAME);
|
|
217
272
|
}
|
|
218
273
|
function getSchemaPath(cwd) {
|
|
219
|
-
return
|
|
274
|
+
return path4__default.join(cwd, SCHEMA_FILENAME);
|
|
220
275
|
}
|
|
221
276
|
function schemaToJsonSchema(schema) {
|
|
222
|
-
if (
|
|
277
|
+
if (isZod4Schema(schema)) {
|
|
278
|
+
return zod4ToJsonSchema(schema);
|
|
279
|
+
}
|
|
280
|
+
if (isRecord3(schema)) {
|
|
223
281
|
if ("type" in schema || "properties" in schema || "$schema" in schema) {
|
|
224
282
|
return schema;
|
|
225
283
|
}
|
|
@@ -231,7 +289,9 @@ function schemaToJsonSchema(schema) {
|
|
|
231
289
|
if (converter !== null) {
|
|
232
290
|
return converter(schema);
|
|
233
291
|
}
|
|
234
|
-
throw new TypeError(
|
|
292
|
+
throw new TypeError(
|
|
293
|
+
'Unsupported schema type. Expected a Zod schema (requires "zod-to-json-schema" for Zod 3 or "zod" for Zod 4), JSON schema object, or jsonSchema() provider.'
|
|
294
|
+
);
|
|
235
295
|
}
|
|
236
296
|
function isLargeSchema(schemaJson) {
|
|
237
297
|
return estimateTokens(schemaJson) > LARGE_SCHEMA_TOKEN_THRESHOLD;
|
|
@@ -322,7 +382,7 @@ function parseAndValidate(filePath, schema) {
|
|
|
322
382
|
function cleanupTempFiles(cwd) {
|
|
323
383
|
for (const filename of [OUTPUT_FILENAME, SCHEMA_FILENAME]) {
|
|
324
384
|
try {
|
|
325
|
-
fs.unlinkSync(
|
|
385
|
+
fs.unlinkSync(path4__default.join(cwd, filename));
|
|
326
386
|
} catch {
|
|
327
387
|
}
|
|
328
388
|
}
|
|
@@ -330,6 +390,7 @@ function cleanupTempFiles(cwd) {
|
|
|
330
390
|
var OUTPUT_FILENAME, SCHEMA_FILENAME, LARGE_SCHEMA_TOKEN_THRESHOLD, zodConverter;
|
|
331
391
|
var init_schema = __esm({
|
|
332
392
|
"src/harness/schema.ts"() {
|
|
393
|
+
init_zod_schema();
|
|
333
394
|
OUTPUT_FILENAME = ".agentfield_output.json";
|
|
334
395
|
SCHEMA_FILENAME = ".agentfield_schema.json";
|
|
335
396
|
LARGE_SCHEMA_TOKEN_THRESHOLD = 4e3;
|
|
@@ -754,7 +815,7 @@ var claude_exports = {};
|
|
|
754
815
|
__export(claude_exports, {
|
|
755
816
|
ClaudeCodeProvider: () => ClaudeCodeProvider
|
|
756
817
|
});
|
|
757
|
-
function
|
|
818
|
+
function isRecord4(value) {
|
|
758
819
|
return typeof value === "object" && value !== null;
|
|
759
820
|
}
|
|
760
821
|
function getString(record, key) {
|
|
@@ -785,14 +846,14 @@ var init_claude = __esm({
|
|
|
785
846
|
const { model: modelValue } = resolveModelAndVariant(options);
|
|
786
847
|
if (modelValue !== void 0) agentOptions.model = modelValue;
|
|
787
848
|
if (options.cwd !== void 0) agentOptions.cwd = options.cwd;
|
|
788
|
-
if (options.maxTurns !== void 0) agentOptions.
|
|
789
|
-
if (options.tools !== void 0) agentOptions.
|
|
790
|
-
if (options.systemPrompt !== void 0) agentOptions.
|
|
791
|
-
if (options.maxBudgetUsd !== void 0) agentOptions.
|
|
849
|
+
if (options.maxTurns !== void 0) agentOptions.maxTurns = options.maxTurns;
|
|
850
|
+
if (options.tools !== void 0) agentOptions.allowedTools = options.tools;
|
|
851
|
+
if (options.systemPrompt !== void 0) agentOptions.systemPrompt = options.systemPrompt;
|
|
852
|
+
if (options.maxBudgetUsd !== void 0) agentOptions.maxBudgetUsd = options.maxBudgetUsd;
|
|
792
853
|
if (options.permissionMode !== void 0) {
|
|
793
854
|
const modeMap = { auto: "bypassPermissions", plan: "plan" };
|
|
794
855
|
const raw = String(options.permissionMode);
|
|
795
|
-
agentOptions.
|
|
856
|
+
agentOptions.permissionMode = modeMap[raw] ?? raw;
|
|
796
857
|
}
|
|
797
858
|
if (options.env !== void 0) agentOptions.env = options.env;
|
|
798
859
|
const messages = [];
|
|
@@ -809,7 +870,7 @@ var init_claude = __esm({
|
|
|
809
870
|
const startApi = Date.now();
|
|
810
871
|
try {
|
|
811
872
|
for await (const msg of sdk.query({ prompt, options: agentOptions })) {
|
|
812
|
-
const msgObj =
|
|
873
|
+
const msgObj = isRecord4(msg) ? msg : { raw: String(msg) };
|
|
813
874
|
messages.push(msgObj);
|
|
814
875
|
const msgType = getString(msgObj, "type") ?? "";
|
|
815
876
|
if (msgType === "result") {
|
|
@@ -828,7 +889,7 @@ var init_claude = __esm({
|
|
|
828
889
|
}
|
|
829
890
|
const turns = getNumber(msgObj, "num_turns");
|
|
830
891
|
numTurns = turns === void 0 ? messages.length : Math.trunc(turns);
|
|
831
|
-
if (
|
|
892
|
+
if (isRecord4(msgObj.usage)) {
|
|
832
893
|
usageObj = msgObj.usage;
|
|
833
894
|
inputTokens = getNumber(usageObj, "input_tokens");
|
|
834
895
|
outputTokens = getNumber(usageObj, "output_tokens");
|
|
@@ -837,19 +898,19 @@ var init_claude = __esm({
|
|
|
837
898
|
}
|
|
838
899
|
modelName = getString(msgObj, "model") ?? modelName;
|
|
839
900
|
} else if (msgType === "assistant") {
|
|
840
|
-
if (modelName === void 0 &&
|
|
901
|
+
if (modelName === void 0 && isRecord4(msgObj.message)) {
|
|
841
902
|
modelName = getString(msgObj.message, "model");
|
|
842
903
|
}
|
|
843
904
|
if (resultText !== void 0) continue;
|
|
844
905
|
let content = msgObj.content;
|
|
845
|
-
if (content === void 0 &&
|
|
906
|
+
if (content === void 0 && isRecord4(msgObj.message)) {
|
|
846
907
|
content = msgObj.message.content;
|
|
847
908
|
}
|
|
848
909
|
if (typeof content === "string") {
|
|
849
910
|
resultText = content;
|
|
850
911
|
} else if (Array.isArray(content)) {
|
|
851
912
|
for (const block of content) {
|
|
852
|
-
if (
|
|
913
|
+
if (isRecord4(block) && block.type === "text" && typeof block.text === "string") {
|
|
853
914
|
resultText = block.text;
|
|
854
915
|
}
|
|
855
916
|
}
|
|
@@ -986,11 +1047,10 @@ var init_gemini = __esm({
|
|
|
986
1047
|
}
|
|
987
1048
|
async execute(prompt, options) {
|
|
988
1049
|
const cmd = [this.bin];
|
|
989
|
-
if (options.cwd) {
|
|
990
|
-
cmd.push("-C", String(options.cwd));
|
|
991
|
-
}
|
|
992
1050
|
if (options.permissionMode === "auto") {
|
|
993
|
-
cmd.push("--
|
|
1051
|
+
cmd.push("--yolo");
|
|
1052
|
+
} else if (options.permissionMode === "plan") {
|
|
1053
|
+
cmd.push("--approval-mode", "plan");
|
|
994
1054
|
}
|
|
995
1055
|
const { model: modelValue } = resolveModelAndVariant(options);
|
|
996
1056
|
if (modelValue) {
|
|
@@ -1041,13 +1101,30 @@ var opencode_exports = {};
|
|
|
1041
1101
|
__export(opencode_exports, {
|
|
1042
1102
|
OpenCodeProvider: () => OpenCodeProvider
|
|
1043
1103
|
});
|
|
1044
|
-
|
|
1104
|
+
function extractOpenCodeError(stderr) {
|
|
1105
|
+
const lines = stderr.split(/\r?\n/);
|
|
1106
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
1107
|
+
if (STDERR_ERROR_PATTERNS.some((pattern) => pattern.test(lines[index]))) {
|
|
1108
|
+
return lines.slice(Math.max(0, index - 1), index + 5).join("\n").trim().slice(0, 1e3);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
return stderr.slice(0, 1e3);
|
|
1112
|
+
}
|
|
1113
|
+
var ANSI_PATTERN2, STDERR_ERROR_PATTERNS, OpenCodeProvider;
|
|
1045
1114
|
var init_opencode = __esm({
|
|
1046
1115
|
"src/harness/providers/opencode.ts"() {
|
|
1047
1116
|
init_types();
|
|
1048
1117
|
init_cli();
|
|
1049
1118
|
init_modelVariant();
|
|
1050
1119
|
init_openrouterAttribution();
|
|
1120
|
+
ANSI_PATTERN2 = /\x1B\[[0-?]*[ -/]*[@-~]/g;
|
|
1121
|
+
STDERR_ERROR_PATTERNS = [
|
|
1122
|
+
/^Error:/m,
|
|
1123
|
+
/\bModel not found\b/,
|
|
1124
|
+
/\bAuthenticationError\b/,
|
|
1125
|
+
/\bUnauthorized\b/,
|
|
1126
|
+
/\bAPIError\b/
|
|
1127
|
+
];
|
|
1051
1128
|
OpenCodeProvider = class {
|
|
1052
1129
|
bin;
|
|
1053
1130
|
constructor(binPath = "opencode") {
|
|
@@ -1098,7 +1175,19 @@ ${prompt}`;
|
|
|
1098
1175
|
try {
|
|
1099
1176
|
const { stdout, stderr, exitCode } = await runCli(cmd, { env });
|
|
1100
1177
|
const resultText = stdout.trim() || void 0;
|
|
1101
|
-
const
|
|
1178
|
+
const cleanStderr = stderr.trim().replace(ANSI_PATTERN2, "");
|
|
1179
|
+
let isError = false;
|
|
1180
|
+
let errorMessage;
|
|
1181
|
+
if (exitCode < 0) {
|
|
1182
|
+
isError = true;
|
|
1183
|
+
errorMessage = cleanStderr ? `Process killed by signal ${-exitCode}. stderr: ${cleanStderr.slice(0, 500)}` : `Process killed by signal ${-exitCode}.`;
|
|
1184
|
+
} else if (exitCode !== 0 && !resultText) {
|
|
1185
|
+
isError = true;
|
|
1186
|
+
errorMessage = cleanStderr ? extractOpenCodeError(cleanStderr) : `Process exited with code ${exitCode} and produced no output.`;
|
|
1187
|
+
} else if (!resultText && cleanStderr && STDERR_ERROR_PATTERNS.some((pattern) => pattern.test(cleanStderr))) {
|
|
1188
|
+
isError = true;
|
|
1189
|
+
errorMessage = extractOpenCodeError(cleanStderr);
|
|
1190
|
+
}
|
|
1102
1191
|
return createRawResult({
|
|
1103
1192
|
result: resultText,
|
|
1104
1193
|
messages: [],
|
|
@@ -1109,7 +1198,8 @@ ${prompt}`;
|
|
|
1109
1198
|
model: modelValue
|
|
1110
1199
|
}),
|
|
1111
1200
|
isError,
|
|
1112
|
-
errorMessage
|
|
1201
|
+
errorMessage,
|
|
1202
|
+
failureType: isError ? "crash" : "none"
|
|
1113
1203
|
});
|
|
1114
1204
|
} catch (err) {
|
|
1115
1205
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -1224,7 +1314,7 @@ var init_runner = __esm({
|
|
|
1224
1314
|
let outputDir;
|
|
1225
1315
|
if (schema !== void 0) {
|
|
1226
1316
|
fs.mkdirSync(outputRoot, { recursive: true });
|
|
1227
|
-
outputDir = fs.mkdtempSync(
|
|
1317
|
+
outputDir = fs.mkdtempSync(path4__default.join(outputRoot, ".agentfield-out-"));
|
|
1228
1318
|
}
|
|
1229
1319
|
const effectivePrompt = schema === void 0 ? prompt : `${prompt}${buildPromptSuffix(schema, outputDir)}`;
|
|
1230
1320
|
const startTime = Date.now();
|
|
@@ -4840,6 +4930,9 @@ function matchesPattern(pattern, value) {
|
|
|
4840
4930
|
const regex = new RegExp(`^${escaped}$`);
|
|
4841
4931
|
return regex.test(value);
|
|
4842
4932
|
}
|
|
4933
|
+
|
|
4934
|
+
// src/utils/schema.ts
|
|
4935
|
+
init_zod_schema();
|
|
4843
4936
|
function isZodSchema(value) {
|
|
4844
4937
|
if (!value || typeof value !== "object") return false;
|
|
4845
4938
|
const obj = value;
|
|
@@ -4849,6 +4942,10 @@ function toJsonSchema(schema) {
|
|
|
4849
4942
|
if (schema === void 0 || schema === null) {
|
|
4850
4943
|
return {};
|
|
4851
4944
|
}
|
|
4945
|
+
if (isZod4Schema(schema)) {
|
|
4946
|
+
const { $schema, ...rest } = zod4ToJsonSchema(schema);
|
|
4947
|
+
return rest;
|
|
4948
|
+
}
|
|
4852
4949
|
if (isZodSchema(schema)) {
|
|
4853
4950
|
const jsonSchema2 = zodToJsonSchema(schema, {
|
|
4854
4951
|
target: "openApi3",
|
|
@@ -6134,22 +6231,22 @@ var Agent = class {
|
|
|
6134
6231
|
},
|
|
6135
6232
|
message: { error: "rate_limit_exceeded", message: "Too many authentication attempts. Try again later." },
|
|
6136
6233
|
skip: (req) => {
|
|
6137
|
-
const
|
|
6138
|
-
if (!
|
|
6234
|
+
const path5 = req.path;
|
|
6235
|
+
if (!path5.startsWith("/reasoners/") && !path5.startsWith("/skills/") && !path5.startsWith("/execute") && !path5.startsWith("/api/v1/reasoners/") && !path5.startsWith("/api/v1/skills/")) {
|
|
6139
6236
|
return true;
|
|
6140
6237
|
}
|
|
6141
|
-
const parts =
|
|
6238
|
+
const parts = path5.replace(/^\/+/, "").split("/");
|
|
6142
6239
|
const funcName = parts[parts.length - 1] ?? "";
|
|
6143
6240
|
return realtimeFunctions.has(funcName);
|
|
6144
6241
|
}
|
|
6145
6242
|
});
|
|
6146
6243
|
this.app.use(authRateLimiter);
|
|
6147
6244
|
this.app.use(async (req, res, next) => {
|
|
6148
|
-
const
|
|
6149
|
-
if (!
|
|
6245
|
+
const path5 = req.path;
|
|
6246
|
+
if (!path5.startsWith("/reasoners/") && !path5.startsWith("/skills/") && !path5.startsWith("/execute") && !path5.startsWith("/api/v1/reasoners/") && !path5.startsWith("/api/v1/skills/")) {
|
|
6150
6247
|
return next();
|
|
6151
6248
|
}
|
|
6152
|
-
const parts =
|
|
6249
|
+
const parts = path5.replace(/^\/+/, "").split("/");
|
|
6153
6250
|
const funcName = parts[parts.length - 1] ?? "";
|
|
6154
6251
|
if (realtimeFunctions.has(funcName)) {
|
|
6155
6252
|
return next();
|
|
@@ -6349,9 +6446,9 @@ var Agent = class {
|
|
|
6349
6446
|
return handler(req, res);
|
|
6350
6447
|
}
|
|
6351
6448
|
async handleServerlessEvent(event) {
|
|
6352
|
-
const
|
|
6449
|
+
const path5 = event?.path ?? event?.rawPath ?? "";
|
|
6353
6450
|
const action = event?.action ?? "";
|
|
6354
|
-
if (
|
|
6451
|
+
if (path5 === "/discover" || action === "discover") {
|
|
6355
6452
|
return {
|
|
6356
6453
|
statusCode: 200,
|
|
6357
6454
|
headers: { "content-type": "application/json" },
|
|
@@ -6360,7 +6457,7 @@ var Agent = class {
|
|
|
6360
6457
|
}
|
|
6361
6458
|
const body = this.normalizeEventBody(event);
|
|
6362
6459
|
const invocation = this.extractInvocationDetails({
|
|
6363
|
-
path:
|
|
6460
|
+
path: path5,
|
|
6364
6461
|
query: event?.queryStringParameters,
|
|
6365
6462
|
body,
|
|
6366
6463
|
reasoner: event?.reasoner,
|
|
@@ -6439,9 +6536,9 @@ var Agent = class {
|
|
|
6439
6536
|
const input = this.normalizeInputPayload(params.body);
|
|
6440
6537
|
return { name: name ?? void 0, targetType: typeValue, input };
|
|
6441
6538
|
}
|
|
6442
|
-
parsePathTarget(
|
|
6443
|
-
if (!
|
|
6444
|
-
const normalized =
|
|
6539
|
+
parsePathTarget(path5) {
|
|
6540
|
+
if (!path5) return {};
|
|
6541
|
+
const normalized = path5.split("?")[0];
|
|
6445
6542
|
const reasonerMatch = normalized.match(/\/reasoners\/([^/]+)/);
|
|
6446
6543
|
if (reasonerMatch?.[1]) {
|
|
6447
6544
|
return { name: reasonerMatch[1], targetType: "reasoner" };
|
|
@@ -7611,7 +7708,7 @@ var MultimodalResponse = class {
|
|
|
7611
7708
|
*/
|
|
7612
7709
|
async saveImage(image, imagePath) {
|
|
7613
7710
|
const bytes = await this.getImageBytes(image);
|
|
7614
|
-
await promises.mkdir(
|
|
7711
|
+
await promises.mkdir(path4.dirname(imagePath), { recursive: true });
|
|
7615
7712
|
await promises.writeFile(imagePath, bytes);
|
|
7616
7713
|
}
|
|
7617
7714
|
/**
|
|
@@ -7619,7 +7716,7 @@ var MultimodalResponse = class {
|
|
|
7619
7716
|
*/
|
|
7620
7717
|
async saveAudio(audio, audioPath) {
|
|
7621
7718
|
const bytes = await this.getAudioBytes(audio);
|
|
7622
|
-
await promises.mkdir(
|
|
7719
|
+
await promises.mkdir(path4.dirname(audioPath), { recursive: true });
|
|
7623
7720
|
await promises.writeFile(audioPath, bytes);
|
|
7624
7721
|
}
|
|
7625
7722
|
/**
|
|
@@ -7627,7 +7724,7 @@ var MultimodalResponse = class {
|
|
|
7627
7724
|
*/
|
|
7628
7725
|
async saveFile(file, filePath) {
|
|
7629
7726
|
const bytes = await this.getFileBytes(file);
|
|
7630
|
-
await promises.mkdir(
|
|
7727
|
+
await promises.mkdir(path4.dirname(filePath), { recursive: true });
|
|
7631
7728
|
await promises.writeFile(filePath, bytes);
|
|
7632
7729
|
}
|
|
7633
7730
|
/**
|
|
@@ -7638,7 +7735,7 @@ var MultimodalResponse = class {
|
|
|
7638
7735
|
const savedFiles = {};
|
|
7639
7736
|
await promises.mkdir(outputDir, { recursive: true });
|
|
7640
7737
|
if (this._audio) {
|
|
7641
|
-
const audioPath =
|
|
7738
|
+
const audioPath = path4.join(outputDir, `${prefix}_audio.${this._audio.format}`);
|
|
7642
7739
|
await this.saveAudio(this._audio, audioPath);
|
|
7643
7740
|
savedFiles["audio"] = audioPath;
|
|
7644
7741
|
}
|
|
@@ -7646,22 +7743,22 @@ var MultimodalResponse = class {
|
|
|
7646
7743
|
const image = this._images[i];
|
|
7647
7744
|
let ext = "png";
|
|
7648
7745
|
if (image.url) {
|
|
7649
|
-
const urlExt =
|
|
7746
|
+
const urlExt = path4.extname(image.url).slice(1);
|
|
7650
7747
|
if (urlExt) ext = urlExt;
|
|
7651
7748
|
}
|
|
7652
|
-
const imagePath =
|
|
7749
|
+
const imagePath = path4.join(outputDir, `${prefix}_image_${i}.${ext}`);
|
|
7653
7750
|
await this.saveImage(image, imagePath);
|
|
7654
7751
|
savedFiles[`image_${i}`] = imagePath;
|
|
7655
7752
|
}
|
|
7656
7753
|
for (let i = 0; i < this._files.length; i++) {
|
|
7657
7754
|
const file = this._files[i];
|
|
7658
7755
|
const filename = file.filename || `${prefix}_file_${i}`;
|
|
7659
|
-
const filePath =
|
|
7756
|
+
const filePath = path4.join(outputDir, filename);
|
|
7660
7757
|
await this.saveFile(file, filePath);
|
|
7661
7758
|
savedFiles[`file_${i}`] = filePath;
|
|
7662
7759
|
}
|
|
7663
7760
|
if (this._text) {
|
|
7664
|
-
const textPath =
|
|
7761
|
+
const textPath = path4.join(outputDir, `${prefix}_text.txt`);
|
|
7665
7762
|
await promises.writeFile(textPath, this._text, "utf-8");
|
|
7666
7763
|
savedFiles["text"] = textPath;
|
|
7667
7764
|
}
|