@standardagents/builder 0.37.0 → 0.37.2
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/built-in-routes.js +1168 -905
- package/dist/built-in-routes.js.map +1 -1
- package/dist/client/{ApiKeysView-CTfDKe47.js → ApiKeysView-BhuT3pIF.js} +1 -1
- package/dist/client/{CenteredContentView-BrVntknT.js → CenteredContentView-CfgX3Ao3.js} +1 -1
- package/dist/client/{CompositionView-BT-1sFij.js → CompositionView-B9FfWMHd.js} +1 -1
- package/dist/client/{ConfirmDialog.vue_vue_type_script_setup_true_lang-yyjbXnqu.js → ConfirmDialog.vue_vue_type_script_setup_true_lang-BqwwsXWJ.js} +1 -1
- package/dist/client/{CopyButton.vue_vue_type_script_setup_true_lang-BWgZbcol.js → CopyButton.vue_vue_type_script_setup_true_lang-Cqm3Vt3E.js} +1 -1
- package/dist/client/{DataTable.vue_vue_type_script_setup_true_lang-DP_WTiEu.js → DataTable.vue_vue_type_script_setup_true_lang-CA5qgsty.js} +1 -1
- package/dist/client/{JsonViewer-DY4s92Td.js → JsonViewer-ByQKCShF.js} +1 -1
- package/dist/client/{LoginView-DHYLpkb0.js → LoginView-J4qtHbQK.js} +1 -1
- package/dist/client/{MarketplaceView-Bcil0ES3.js → MarketplaceView-CshdWDqp.js} +1 -1
- package/dist/client/{Modal.vue_vue_type_script_setup_true_lang-BJgJZ56X.js → Modal.vue_vue_type_script_setup_true_lang-DKdB9A8Z.js} +1 -1
- package/dist/client/{ModelModal.vue_vue_type_script_setup_true_lang-BXTP0K4Z.js → ModelModal.vue_vue_type_script_setup_true_lang-BAxaBZsx.js} +1 -1
- package/dist/client/{ModelsView-_RY4gQ79.js → ModelsView-B_n306yk.js} +1 -1
- package/dist/client/{PromptEditView-D8kyGi30.js → PromptEditView-C85qRgsE.js} +1 -1
- package/dist/client/{PromptModal-DSPIuleV.js → PromptModal-PNpoJfqD.js} +1 -1
- package/dist/client/{PromptsView-DPvBDPJf.js → PromptsView-BKnfThIF.js} +1 -1
- package/dist/client/{ProvidersView-PaPnME7I.js → ProvidersView-Df41VhHD.js} +1 -1
- package/dist/client/ThreadInspectorPane.vue_vue_type_script_setup_true_lang-CtIBWHUR.js +22 -0
- package/dist/client/{ThreadsView-BW4SYvFN.js → ThreadsView-sjo5Rrcm.js} +1 -1
- package/dist/client/{ToolsView-xsIVTHh0.js → ToolsView-C0MH9x3N.js} +1 -1
- package/dist/client/{UsersView-CSXdBGA-.js → UsersView--TQiJYP7.js} +1 -1
- package/dist/client/{VariablesView-Bl5S2ZDn.js → VariablesView-BO3UljZu.js} +1 -1
- package/dist/client/assets/{ThreadInspectorPane-CnbmdCdH.css → ThreadInspectorPane-D9ZMzSTn.css} +1 -1
- package/dist/client/{index-Df4DTwgs.js → index-BgZnQr8X.js} +2 -2
- package/dist/client/index.html +1 -1
- package/dist/{index-yV9JL4r3.d.ts → index-DceFbLG9.d.ts} +45 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +958 -815
- package/dist/index.js.map +1 -1
- package/dist/packing.js +213 -161
- package/dist/packing.js.map +1 -1
- package/dist/plugin.js +535 -505
- package/dist/plugin.js.map +1 -1
- package/dist/runtime.d.ts +110 -38
- package/dist/runtime.js +174 -21
- package/dist/runtime.js.map +1 -1
- package/dist/test.d.ts +1 -1
- package/package.json +5 -5
- package/dist/client/ThreadInspectorPane.vue_vue_type_script_setup_true_lang-BAUlrnb6.js +0 -23
package/dist/index.js
CHANGED
|
@@ -5,10 +5,10 @@ export { ProviderError, belongsToPackage, defineAgent, defineHook, defineModel,
|
|
|
5
5
|
import 'virtual:@standardagents-providers';
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import { transform, collect } from '@standardagents/sip';
|
|
8
|
-
import * as
|
|
9
|
-
import
|
|
10
|
-
import * as
|
|
11
|
-
import
|
|
8
|
+
import * as fs9 from 'fs';
|
|
9
|
+
import fs9__default from 'fs';
|
|
10
|
+
import * as path9 from 'path';
|
|
11
|
+
import path9__default from 'path';
|
|
12
12
|
import { fileURLToPath } from 'url';
|
|
13
13
|
import MagicString from 'magic-string';
|
|
14
14
|
import { exec } from 'child_process';
|
|
@@ -211,8 +211,8 @@ var init_StreamManager = __esm({
|
|
|
211
211
|
}
|
|
212
212
|
});
|
|
213
213
|
this.beforeCloseHooks = Array.isArray(beforeClose) ? beforeClose : [beforeClose];
|
|
214
|
-
this.then = new Promise((
|
|
215
|
-
this.resolver =
|
|
214
|
+
this.then = new Promise((resolve3) => {
|
|
215
|
+
this.resolver = resolve3;
|
|
216
216
|
});
|
|
217
217
|
}
|
|
218
218
|
/**
|
|
@@ -455,8 +455,8 @@ async function readCompletedArg(partialJson, argName) {
|
|
|
455
455
|
controller.close();
|
|
456
456
|
}
|
|
457
457
|
}).getReader();
|
|
458
|
-
for await (const [value,
|
|
459
|
-
if (
|
|
458
|
+
for await (const [value, path21] of jsonPathReader(reader, [argName])) {
|
|
459
|
+
if (path21 === argName) {
|
|
460
460
|
return typeof value === "string" ? value : void 0;
|
|
461
461
|
}
|
|
462
462
|
}
|
|
@@ -865,7 +865,7 @@ var init_TestProvider = __esm({
|
|
|
865
865
|
}, 0);
|
|
866
866
|
}
|
|
867
867
|
sleep(ms) {
|
|
868
|
-
return new Promise((
|
|
868
|
+
return new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
869
869
|
}
|
|
870
870
|
// ============ Test Utility Methods ============
|
|
871
871
|
/**
|
|
@@ -1350,12 +1350,12 @@ async function awaitBounded(work, budgetMs, label) {
|
|
|
1350
1350
|
let timer;
|
|
1351
1351
|
work.catch(() => {
|
|
1352
1352
|
});
|
|
1353
|
-
const timeout = new Promise((
|
|
1353
|
+
const timeout = new Promise((resolve3) => {
|
|
1354
1354
|
timer = setTimeout(() => {
|
|
1355
1355
|
console.error(
|
|
1356
1356
|
`[LLMRequest] ${label} did not settle within ${budgetMs}ms \u2014 continuing without it`
|
|
1357
1357
|
);
|
|
1358
|
-
|
|
1358
|
+
resolve3(void 0);
|
|
1359
1359
|
}, budgetMs);
|
|
1360
1360
|
});
|
|
1361
1361
|
try {
|
|
@@ -1533,11 +1533,11 @@ function stripBase64FromMessages(messages, imagePathMap) {
|
|
|
1533
1533
|
const data = part.data;
|
|
1534
1534
|
if (typeof data === "string") {
|
|
1535
1535
|
if (data.startsWith("data:") || data.length > 1e3) {
|
|
1536
|
-
const
|
|
1536
|
+
const path21 = imagePathMap?.get(data);
|
|
1537
1537
|
return {
|
|
1538
1538
|
...part,
|
|
1539
1539
|
data: "[base64 omitted]",
|
|
1540
|
-
...
|
|
1540
|
+
...path21 ? { path: path21 } : {}
|
|
1541
1541
|
};
|
|
1542
1542
|
}
|
|
1543
1543
|
}
|
|
@@ -2714,7 +2714,7 @@ var init_LLMRequest = __esm({
|
|
|
2714
2714
|
* Sleep utility for backoff
|
|
2715
2715
|
*/
|
|
2716
2716
|
static sleep(ms) {
|
|
2717
|
-
return new Promise((
|
|
2717
|
+
return new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
2718
2718
|
}
|
|
2719
2719
|
/**
|
|
2720
2720
|
* Update the response_body in a log record to replace base64 image URLs with file paths
|
|
@@ -2753,11 +2753,11 @@ var init_LLMRequest = __esm({
|
|
|
2753
2753
|
...choice.message,
|
|
2754
2754
|
images: choice.message?.images?.map(
|
|
2755
2755
|
(img) => {
|
|
2756
|
-
const
|
|
2757
|
-
if (
|
|
2756
|
+
const path21 = img._id ? imagePathMap.get(img._id) : void 0;
|
|
2757
|
+
if (path21) {
|
|
2758
2758
|
return {
|
|
2759
2759
|
type: img.type,
|
|
2760
|
-
image_url: { url:
|
|
2760
|
+
image_url: { url: path21 }
|
|
2761
2761
|
};
|
|
2762
2762
|
}
|
|
2763
2763
|
return img;
|
|
@@ -3166,7 +3166,7 @@ __export(files_exports, {
|
|
|
3166
3166
|
FileStorage: () => FileStorage,
|
|
3167
3167
|
basename: () => basename2,
|
|
3168
3168
|
detectStorageBackend: () => detectStorageBackend,
|
|
3169
|
-
dirname: () =>
|
|
3169
|
+
dirname: () => dirname4,
|
|
3170
3170
|
isTextMimeType: () => isTextMimeType,
|
|
3171
3171
|
normalizePath: () => normalizePath,
|
|
3172
3172
|
resolveRenameDestination: () => resolveRenameDestination,
|
|
@@ -3186,20 +3186,20 @@ function detectStorageBackend(location) {
|
|
|
3186
3186
|
return "url";
|
|
3187
3187
|
return "local";
|
|
3188
3188
|
}
|
|
3189
|
-
function basename2(
|
|
3190
|
-
const parts =
|
|
3189
|
+
function basename2(path21) {
|
|
3190
|
+
const parts = path21.split("/").filter(Boolean);
|
|
3191
3191
|
return parts[parts.length - 1] || "";
|
|
3192
3192
|
}
|
|
3193
|
-
function normalizePath(
|
|
3194
|
-
let normalized =
|
|
3193
|
+
function normalizePath(path21) {
|
|
3194
|
+
let normalized = path21.replace(/\/+/g, "/");
|
|
3195
3195
|
if (!normalized.startsWith("/")) normalized = "/" + normalized;
|
|
3196
3196
|
if (normalized.length > 1 && normalized.endsWith("/")) {
|
|
3197
3197
|
normalized = normalized.slice(0, -1);
|
|
3198
3198
|
}
|
|
3199
3199
|
return normalized;
|
|
3200
3200
|
}
|
|
3201
|
-
function
|
|
3202
|
-
const normalized = normalizePath(
|
|
3201
|
+
function dirname4(path21) {
|
|
3202
|
+
const normalized = normalizePath(path21);
|
|
3203
3203
|
const lastSlash = normalized.lastIndexOf("/");
|
|
3204
3204
|
if (lastSlash <= 0) return "/";
|
|
3205
3205
|
return normalized.slice(0, lastSlash);
|
|
@@ -3217,7 +3217,7 @@ function validateMovePaths(source, destination, isDirectory) {
|
|
|
3217
3217
|
);
|
|
3218
3218
|
}
|
|
3219
3219
|
}
|
|
3220
|
-
function resolveRenameDestination(
|
|
3220
|
+
function resolveRenameDestination(path21, newName) {
|
|
3221
3221
|
if (typeof newName !== "string" || newName.length === 0) {
|
|
3222
3222
|
throw new Error("New name must be a non-empty string");
|
|
3223
3223
|
}
|
|
@@ -3227,8 +3227,8 @@ function resolveRenameDestination(path20, newName) {
|
|
|
3227
3227
|
if (newName === "." || newName === "..") {
|
|
3228
3228
|
throw new Error("New name must not be '.' or '..'");
|
|
3229
3229
|
}
|
|
3230
|
-
const normalized = normalizePath(
|
|
3231
|
-
const parent =
|
|
3230
|
+
const normalized = normalizePath(path21);
|
|
3231
|
+
const parent = dirname4(normalized);
|
|
3232
3232
|
return parent === "/" ? `/${newName}` : `${parent}/${newName}`;
|
|
3233
3233
|
}
|
|
3234
3234
|
function rowToFileRecord(row) {
|
|
@@ -3351,8 +3351,8 @@ var init_files = __esm({
|
|
|
3351
3351
|
* Write a file to storage.
|
|
3352
3352
|
* Files > CHUNK_SIZE are automatically chunked into file_chunks table.
|
|
3353
3353
|
*/
|
|
3354
|
-
async writeFile(
|
|
3355
|
-
const normalizedPath = normalizePath(
|
|
3354
|
+
async writeFile(path21, data, mimeType, options) {
|
|
3355
|
+
const normalizedPath = normalizePath(path21);
|
|
3356
3356
|
const name = basename2(normalizedPath);
|
|
3357
3357
|
const isText = isTextMimeType(mimeType);
|
|
3358
3358
|
const now = Date.now();
|
|
@@ -3464,8 +3464,8 @@ var init_files = __esm({
|
|
|
3464
3464
|
/**
|
|
3465
3465
|
* Link to an external file (URL, S3, R2)
|
|
3466
3466
|
*/
|
|
3467
|
-
async linkFile(
|
|
3468
|
-
const normalizedPath = normalizePath(
|
|
3467
|
+
async linkFile(path21, location, options) {
|
|
3468
|
+
const normalizedPath = normalizePath(path21);
|
|
3469
3469
|
const name = basename2(normalizedPath);
|
|
3470
3470
|
const storage = detectStorageBackend(location);
|
|
3471
3471
|
const now = Date.now();
|
|
@@ -3504,8 +3504,8 @@ var init_files = __esm({
|
|
|
3504
3504
|
* WARNING: For large chunked files, this loads the entire file into memory.
|
|
3505
3505
|
* Use streamFile() for memory-efficient access to large files.
|
|
3506
3506
|
*/
|
|
3507
|
-
async readFile(
|
|
3508
|
-
const normalizedPath = normalizePath(
|
|
3507
|
+
async readFile(path21) {
|
|
3508
|
+
const normalizedPath = normalizePath(path21);
|
|
3509
3509
|
const cursor = await this.sql.exec(
|
|
3510
3510
|
`SELECT data, content, storage, is_chunked, chunk_count FROM files WHERE path = ? AND is_directory = 0`,
|
|
3511
3511
|
normalizedPath
|
|
@@ -3557,8 +3557,8 @@ var init_files = __esm({
|
|
|
3557
3557
|
* Memory-efficient way to read large chunked files.
|
|
3558
3558
|
* Yields one chunk at a time for streaming HTTP responses.
|
|
3559
3559
|
*/
|
|
3560
|
-
async *streamFile(
|
|
3561
|
-
const normalizedPath = normalizePath(
|
|
3560
|
+
async *streamFile(path21) {
|
|
3561
|
+
const normalizedPath = normalizePath(path21);
|
|
3562
3562
|
const cursor = await this.sql.exec(
|
|
3563
3563
|
`SELECT data, content, storage, is_chunked, chunk_count FROM files WHERE path = ? AND is_directory = 0`,
|
|
3564
3564
|
normalizedPath
|
|
@@ -3592,8 +3592,8 @@ var init_files = __esm({
|
|
|
3592
3592
|
/**
|
|
3593
3593
|
* Read text file content
|
|
3594
3594
|
*/
|
|
3595
|
-
async readTextFile(
|
|
3596
|
-
const normalizedPath = normalizePath(
|
|
3595
|
+
async readTextFile(path21) {
|
|
3596
|
+
const normalizedPath = normalizePath(path21);
|
|
3597
3597
|
const cursor = await this.sql.exec(
|
|
3598
3598
|
`SELECT content, data, storage FROM files WHERE path = ? AND is_directory = 0`,
|
|
3599
3599
|
normalizedPath
|
|
@@ -3611,8 +3611,8 @@ var init_files = __esm({
|
|
|
3611
3611
|
/**
|
|
3612
3612
|
* Get file metadata (stat)
|
|
3613
3613
|
*/
|
|
3614
|
-
async stat(
|
|
3615
|
-
const normalizedPath = normalizePath(
|
|
3614
|
+
async stat(path21) {
|
|
3615
|
+
const normalizedPath = normalizePath(path21);
|
|
3616
3616
|
const cursor = await this.sql.exec(
|
|
3617
3617
|
`SELECT path, name, mime_type, storage, location, size, metadata, is_directory, created_at, width, height, is_chunked, chunk_count
|
|
3618
3618
|
FROM files WHERE path = ?`,
|
|
@@ -3625,8 +3625,8 @@ var init_files = __esm({
|
|
|
3625
3625
|
/**
|
|
3626
3626
|
* Check if file or directory exists
|
|
3627
3627
|
*/
|
|
3628
|
-
async exists(
|
|
3629
|
-
const normalizedPath = normalizePath(
|
|
3628
|
+
async exists(path21) {
|
|
3629
|
+
const normalizedPath = normalizePath(path21);
|
|
3630
3630
|
const cursor = await this.sql.exec(
|
|
3631
3631
|
`SELECT COUNT(*) as count FROM files WHERE path = ?`,
|
|
3632
3632
|
normalizedPath
|
|
@@ -3636,8 +3636,8 @@ var init_files = __esm({
|
|
|
3636
3636
|
/**
|
|
3637
3637
|
* Delete a file
|
|
3638
3638
|
*/
|
|
3639
|
-
async unlink(
|
|
3640
|
-
const normalizedPath = normalizePath(
|
|
3639
|
+
async unlink(path21) {
|
|
3640
|
+
const normalizedPath = normalizePath(path21);
|
|
3641
3641
|
await this.sql.exec(
|
|
3642
3642
|
`DELETE FROM files WHERE path = ? AND is_directory = 0`,
|
|
3643
3643
|
normalizedPath
|
|
@@ -3647,8 +3647,8 @@ var init_files = __esm({
|
|
|
3647
3647
|
/**
|
|
3648
3648
|
* Create a directory marker
|
|
3649
3649
|
*/
|
|
3650
|
-
async mkdir(
|
|
3651
|
-
const normalizedPath = normalizePath(
|
|
3650
|
+
async mkdir(path21) {
|
|
3651
|
+
const normalizedPath = normalizePath(path21);
|
|
3652
3652
|
const name = basename2(normalizedPath);
|
|
3653
3653
|
const now = Date.now();
|
|
3654
3654
|
await this.sql.exec(
|
|
@@ -3673,8 +3673,8 @@ var init_files = __esm({
|
|
|
3673
3673
|
/**
|
|
3674
3674
|
* List directory contents
|
|
3675
3675
|
*/
|
|
3676
|
-
async readdir(
|
|
3677
|
-
const normalizedPath = normalizePath(
|
|
3676
|
+
async readdir(path21) {
|
|
3677
|
+
const normalizedPath = normalizePath(path21);
|
|
3678
3678
|
const prefix = normalizedPath === "/" ? "/" : normalizedPath + "/";
|
|
3679
3679
|
const cursor = await this.sql.exec(
|
|
3680
3680
|
`SELECT path, name, mime_type, storage, location, size, metadata, is_directory, created_at
|
|
@@ -3692,8 +3692,8 @@ var init_files = __esm({
|
|
|
3692
3692
|
/**
|
|
3693
3693
|
* Remove empty directory
|
|
3694
3694
|
*/
|
|
3695
|
-
async rmdir(
|
|
3696
|
-
const normalizedPath = normalizePath(
|
|
3695
|
+
async rmdir(path21) {
|
|
3696
|
+
const normalizedPath = normalizePath(path21);
|
|
3697
3697
|
const prefix = normalizedPath + "/";
|
|
3698
3698
|
const cursor = await this.sql.exec(
|
|
3699
3699
|
`SELECT COUNT(*) as count FROM files WHERE path LIKE ? || '%'`,
|
|
@@ -3791,9 +3791,9 @@ var init_files = __esm({
|
|
|
3791
3791
|
* Rename a file or directory in place, keeping it in the same parent
|
|
3792
3792
|
* directory. `newName` must be a bare file name with no path separators.
|
|
3793
3793
|
*/
|
|
3794
|
-
async rename(
|
|
3795
|
-
const destination = resolveRenameDestination(
|
|
3796
|
-
return this.move(normalizePath(
|
|
3794
|
+
async rename(path21, newName) {
|
|
3795
|
+
const destination = resolveRenameDestination(path21, newName);
|
|
3796
|
+
return this.move(normalizePath(path21), destination);
|
|
3797
3797
|
}
|
|
3798
3798
|
/**
|
|
3799
3799
|
* Get storage statistics
|
|
@@ -3823,8 +3823,8 @@ var init_files = __esm({
|
|
|
3823
3823
|
/**
|
|
3824
3824
|
* Get thumbnail for an image
|
|
3825
3825
|
*/
|
|
3826
|
-
async getThumbnail(
|
|
3827
|
-
const normalizedPath = normalizePath(
|
|
3826
|
+
async getThumbnail(path21) {
|
|
3827
|
+
const normalizedPath = normalizePath(path21);
|
|
3828
3828
|
const cursor = await this.sql.exec(
|
|
3829
3829
|
`SELECT thumbnail FROM files WHERE path = ? AND is_directory = 0`,
|
|
3830
3830
|
normalizedPath
|
|
@@ -4256,8 +4256,8 @@ var init_ToolExecutor = __esm({
|
|
|
4256
4256
|
const validation = argsSchema.safeParse(args);
|
|
4257
4257
|
if (!validation.success) {
|
|
4258
4258
|
const errorMessage = validation.error.issues.map((issue) => {
|
|
4259
|
-
const
|
|
4260
|
-
return `[${
|
|
4259
|
+
const path21 = issue.path.length > 0 ? issue.path.map(String).join(".") : "root";
|
|
4260
|
+
return `[${path21}] ${issue.message}`;
|
|
4261
4261
|
}).join("; ");
|
|
4262
4262
|
return {
|
|
4263
4263
|
status: "error",
|
|
@@ -5248,13 +5248,13 @@ Message one with subagent_message(referenceId, message).`
|
|
|
5248
5248
|
new Set(
|
|
5249
5249
|
issues.map(
|
|
5250
5250
|
(issue) => Array.isArray(issue.path) ? issue.path.map(String).join(".") : String(issue.path ?? "")
|
|
5251
|
-
).filter((
|
|
5251
|
+
).filter((path21) => path21.length > 0)
|
|
5252
5252
|
)
|
|
5253
5253
|
);
|
|
5254
5254
|
const detail = issues.map((issue) => {
|
|
5255
|
-
const
|
|
5255
|
+
const path21 = Array.isArray(issue.path) ? issue.path.map(String).join(".") : "";
|
|
5256
5256
|
const message = typeof issue.message === "string" ? issue.message : "invalid value";
|
|
5257
|
-
return
|
|
5257
|
+
return path21 ? `${path21}: ${message}` : message;
|
|
5258
5258
|
}).join("; ") || parsed.error.message || "invalid arguments";
|
|
5259
5259
|
const agentLabel = agentDef.title || agentDef.name || options.agentName || qualifiedPromptName;
|
|
5260
5260
|
return {
|
|
@@ -5591,8 +5591,8 @@ Reference: ${referenceId}` : `Reference: ${referenceId}`;
|
|
|
5591
5591
|
}
|
|
5592
5592
|
return [];
|
|
5593
5593
|
}
|
|
5594
|
-
static inferMimeTypeFromPath(
|
|
5595
|
-
const normalized =
|
|
5594
|
+
static inferMimeTypeFromPath(path21) {
|
|
5595
|
+
const normalized = path21.toLowerCase();
|
|
5596
5596
|
if (normalized.endsWith(".png")) return "image/png";
|
|
5597
5597
|
if (normalized.endsWith(".jpg") || normalized.endsWith(".jpeg")) return "image/jpeg";
|
|
5598
5598
|
if (normalized.endsWith(".webp")) return "image/webp";
|
|
@@ -5631,7 +5631,7 @@ Reference: ${referenceId}` : `Reference: ${referenceId}`;
|
|
|
5631
5631
|
ext: value.slice(lastDot + 1).toLowerCase()
|
|
5632
5632
|
};
|
|
5633
5633
|
}
|
|
5634
|
-
static resolveAttachmentMimeType(sourceMimeType, fallbackMimeType,
|
|
5634
|
+
static resolveAttachmentMimeType(sourceMimeType, fallbackMimeType, path21) {
|
|
5635
5635
|
const source = sourceMimeType?.trim();
|
|
5636
5636
|
if (source && source !== "application/octet-stream") {
|
|
5637
5637
|
return source;
|
|
@@ -5640,7 +5640,7 @@ Reference: ${referenceId}` : `Reference: ${referenceId}`;
|
|
|
5640
5640
|
if (fallback && fallback !== "application/octet-stream") {
|
|
5641
5641
|
return fallback;
|
|
5642
5642
|
}
|
|
5643
|
-
return this.inferMimeTypeFromPath(
|
|
5643
|
+
return this.inferMimeTypeFromPath(path21) ?? source ?? fallback ?? "application/octet-stream";
|
|
5644
5644
|
}
|
|
5645
5645
|
static buildAttachmentTargetPath(preferredName, mimeType, sourcePath) {
|
|
5646
5646
|
const safeName = this.sanitizeFilename(preferredName);
|
|
@@ -5736,8 +5736,8 @@ Reference: ${referenceId}` : `Reference: ${referenceId}`;
|
|
|
5736
5736
|
}
|
|
5737
5737
|
return copied;
|
|
5738
5738
|
}
|
|
5739
|
-
static async readAttachmentDataFromSource(sourceThread,
|
|
5740
|
-
const sourceData = await sourceThread.readFile(
|
|
5739
|
+
static async readAttachmentDataFromSource(sourceThread, path21, sourceFile) {
|
|
5740
|
+
const sourceData = await sourceThread.readFile(path21);
|
|
5741
5741
|
if (sourceData.success && sourceData.data) {
|
|
5742
5742
|
return sourceData.data;
|
|
5743
5743
|
}
|
|
@@ -5771,7 +5771,7 @@ Reference: ${referenceId}` : `Reference: ${referenceId}`;
|
|
|
5771
5771
|
if (!attachments || attachments.length === 0) {
|
|
5772
5772
|
return "";
|
|
5773
5773
|
}
|
|
5774
|
-
const paths = attachments.map((attachment) => attachment.path).filter((
|
|
5774
|
+
const paths = attachments.map((attachment) => attachment.path).filter((path21) => typeof path21 === "string" && path21.length > 0);
|
|
5775
5775
|
if (paths.length === 0) {
|
|
5776
5776
|
return "";
|
|
5777
5777
|
}
|
|
@@ -6067,7 +6067,7 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
6067
6067
|
mappedAttachmentValue
|
|
6068
6068
|
);
|
|
6069
6069
|
const resolvedPaths = new Set(mappedRefs.map((ref) => ref.path));
|
|
6070
|
-
const missingPaths = candidatePaths.filter((
|
|
6070
|
+
const missingPaths = candidatePaths.filter((path21) => !resolvedPaths.has(path21));
|
|
6071
6071
|
if (candidatePaths.length === 0 || missingPaths.length > 0) {
|
|
6072
6072
|
processedResult = {
|
|
6073
6073
|
status: "error",
|
|
@@ -6249,8 +6249,8 @@ ${attachmentPaths}`;
|
|
|
6249
6249
|
if (mimeType.startsWith("image/")) {
|
|
6250
6250
|
return true;
|
|
6251
6251
|
}
|
|
6252
|
-
const
|
|
6253
|
-
return
|
|
6252
|
+
const path21 = ref.path.toLowerCase();
|
|
6253
|
+
return path21.endsWith(".png") || path21.endsWith(".jpg") || path21.endsWith(".jpeg") || path21.endsWith(".webp") || path21.endsWith(".gif") || path21.endsWith(".bmp") || path21.endsWith(".svg");
|
|
6254
6254
|
});
|
|
6255
6255
|
if (imageRefs.length === 0) {
|
|
6256
6256
|
return;
|
|
@@ -6316,27 +6316,27 @@ ${attachmentPaths}`;
|
|
|
6316
6316
|
*/
|
|
6317
6317
|
static async processToolAttachments(attachments, state) {
|
|
6318
6318
|
const { FileStorage: FileStorage2 } = await Promise.resolve().then(() => (init_files(), files_exports));
|
|
6319
|
-
const
|
|
6319
|
+
const fs19 = new FileStorage2(state.storage.sql);
|
|
6320
6320
|
const refs = [];
|
|
6321
6321
|
for (const attachment of attachments) {
|
|
6322
6322
|
try {
|
|
6323
6323
|
const attachmentId = crypto.randomUUID();
|
|
6324
6324
|
const timestamp = Date.now();
|
|
6325
6325
|
const ext = attachment.mimeType === "image/png" ? "png" : attachment.mimeType === "image/jpeg" ? "jpg" : attachment.mimeType === "image/gif" ? "gif" : attachment.mimeType === "image/webp" ? "webp" : attachment.name.split(".").pop() || "bin";
|
|
6326
|
-
const
|
|
6326
|
+
const path21 = `/attachments/${timestamp}-${attachmentId.slice(0, 8)}.${ext}`;
|
|
6327
6327
|
const binaryString = atob(attachment.data);
|
|
6328
6328
|
const dataBuffer = new Uint8Array(binaryString.length);
|
|
6329
6329
|
for (let i = 0; i < binaryString.length; i++) {
|
|
6330
6330
|
dataBuffer[i] = binaryString.charCodeAt(i);
|
|
6331
6331
|
}
|
|
6332
|
-
await
|
|
6332
|
+
await fs19.writeFile(path21, dataBuffer.buffer, attachment.mimeType, {
|
|
6333
6333
|
width: attachment.width,
|
|
6334
6334
|
height: attachment.height
|
|
6335
6335
|
});
|
|
6336
6336
|
const ref = {
|
|
6337
6337
|
id: attachmentId,
|
|
6338
6338
|
type: "file",
|
|
6339
|
-
path:
|
|
6339
|
+
path: path21,
|
|
6340
6340
|
name: attachment.name,
|
|
6341
6341
|
mimeType: attachment.mimeType,
|
|
6342
6342
|
size: dataBuffer.byteLength
|
|
@@ -10113,16 +10113,16 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
10113
10113
|
const base64Data = match[2];
|
|
10114
10114
|
const ext = mimeType.split("/")[1] || "png";
|
|
10115
10115
|
const attachmentId = crypto.randomUUID();
|
|
10116
|
-
const
|
|
10116
|
+
const path21 = `/attachments/${Date.now()}-${attachmentId.slice(0, 8)}.${ext}`;
|
|
10117
10117
|
try {
|
|
10118
|
-
await state.thread.instance.writeFile(
|
|
10118
|
+
await state.thread.instance.writeFile(path21, base64Data, mimeType);
|
|
10119
10119
|
if (image.id) {
|
|
10120
|
-
imagePathMap.set(image.id,
|
|
10120
|
+
imagePathMap.set(image.id, path21);
|
|
10121
10121
|
}
|
|
10122
10122
|
refs.push({
|
|
10123
10123
|
id: attachmentId,
|
|
10124
10124
|
type: "file",
|
|
10125
|
-
path:
|
|
10125
|
+
path: path21,
|
|
10126
10126
|
name: `generated-${attachmentId}.${ext}`,
|
|
10127
10127
|
mimeType,
|
|
10128
10128
|
size: Math.ceil(base64Data.length * 3 / 4)
|
|
@@ -10183,13 +10183,13 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
10183
10183
|
const base64Data = imageUrl.slice(base64Index + base64Marker.length);
|
|
10184
10184
|
const ext = mimeType.split("/")[1] || "png";
|
|
10185
10185
|
const attachmentId = crypto.randomUUID();
|
|
10186
|
-
const
|
|
10186
|
+
const path21 = `/attachments/${Date.now()}-${attachmentId.slice(0, 8)}.${ext}`;
|
|
10187
10187
|
try {
|
|
10188
|
-
await state.thread.instance.writeFile(
|
|
10188
|
+
await state.thread.instance.writeFile(path21, base64Data, mimeType);
|
|
10189
10189
|
const attachmentRef = {
|
|
10190
10190
|
id: attachmentId,
|
|
10191
10191
|
type: "file",
|
|
10192
|
-
path:
|
|
10192
|
+
path: path21,
|
|
10193
10193
|
name: `generated-${attachmentId}.${ext}`,
|
|
10194
10194
|
mimeType,
|
|
10195
10195
|
size: Math.ceil(base64Data.length * 3 / 4)
|
|
@@ -10252,7 +10252,7 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
10252
10252
|
content: "Image generated successfully",
|
|
10253
10253
|
status: "success",
|
|
10254
10254
|
timestamp: Date.now(),
|
|
10255
|
-
attachment_path:
|
|
10255
|
+
attachment_path: path21
|
|
10256
10256
|
});
|
|
10257
10257
|
await state.storage.sql.exec(
|
|
10258
10258
|
`UPDATE logs SET tool_results = ?1 WHERE id = ?2`,
|
|
@@ -10274,7 +10274,7 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
10274
10274
|
}
|
|
10275
10275
|
}
|
|
10276
10276
|
if (image.id) {
|
|
10277
|
-
imagePathMap.set(image.id,
|
|
10277
|
+
imagePathMap.set(image.id, path21);
|
|
10278
10278
|
}
|
|
10279
10279
|
} catch (error) {
|
|
10280
10280
|
console.error(`[FlowEngine] Failed to store provider tool result for ${toolName}:`, error);
|
|
@@ -11017,7 +11017,7 @@ async function updateThread(thread, params) {
|
|
|
11017
11017
|
}
|
|
11018
11018
|
return result.thread;
|
|
11019
11019
|
}
|
|
11020
|
-
async function writeFile(flow,
|
|
11020
|
+
async function writeFile(flow, path21, data, mimeType, options) {
|
|
11021
11021
|
const instance = flow.thread.instance;
|
|
11022
11022
|
let base64Data;
|
|
11023
11023
|
if (typeof data === "string") {
|
|
@@ -11039,7 +11039,7 @@ async function writeFile(flow, path20, data, mimeType, options) {
|
|
|
11039
11039
|
}
|
|
11040
11040
|
base64Thumbnail = btoa(binary);
|
|
11041
11041
|
}
|
|
11042
|
-
const result = await instance.writeFile(
|
|
11042
|
+
const result = await instance.writeFile(path21, base64Data, mimeType, {
|
|
11043
11043
|
metadata: options?.metadata,
|
|
11044
11044
|
thumbnail: base64Thumbnail
|
|
11045
11045
|
});
|
|
@@ -11048,20 +11048,20 @@ async function writeFile(flow, path20, data, mimeType, options) {
|
|
|
11048
11048
|
}
|
|
11049
11049
|
return result.file;
|
|
11050
11050
|
}
|
|
11051
|
-
async function writeImage(flow,
|
|
11052
|
-
return writeFile(flow,
|
|
11051
|
+
async function writeImage(flow, path21, data, mimeType, options) {
|
|
11052
|
+
return writeFile(flow, path21, data, mimeType, options);
|
|
11053
11053
|
}
|
|
11054
|
-
async function linkFile(flow,
|
|
11054
|
+
async function linkFile(flow, path21, location, options) {
|
|
11055
11055
|
const instance = flow.thread.instance;
|
|
11056
|
-
const result = await instance.linkFile(
|
|
11056
|
+
const result = await instance.linkFile(path21, location, options);
|
|
11057
11057
|
if (!result.success) {
|
|
11058
11058
|
throw new Error(result.error || "Failed to link file");
|
|
11059
11059
|
}
|
|
11060
11060
|
return result.file;
|
|
11061
11061
|
}
|
|
11062
|
-
async function readFile(flow,
|
|
11062
|
+
async function readFile(flow, path21) {
|
|
11063
11063
|
const instance = flow.thread.instance;
|
|
11064
|
-
const result = await instance.readFile(
|
|
11064
|
+
const result = await instance.readFile(path21);
|
|
11065
11065
|
if (!result.success) {
|
|
11066
11066
|
return null;
|
|
11067
11067
|
}
|
|
@@ -11072,45 +11072,45 @@ async function readFile(flow, path20) {
|
|
|
11072
11072
|
}
|
|
11073
11073
|
return bytes.buffer;
|
|
11074
11074
|
}
|
|
11075
|
-
async function stat(flow,
|
|
11075
|
+
async function stat(flow, path21) {
|
|
11076
11076
|
const instance = flow.thread.instance;
|
|
11077
|
-
const result = await instance.statFile(
|
|
11077
|
+
const result = await instance.statFile(path21);
|
|
11078
11078
|
if (!result.success) {
|
|
11079
11079
|
return null;
|
|
11080
11080
|
}
|
|
11081
11081
|
return result.file;
|
|
11082
11082
|
}
|
|
11083
|
-
async function exists(flow,
|
|
11083
|
+
async function exists(flow, path21) {
|
|
11084
11084
|
const instance = flow.thread.instance;
|
|
11085
|
-
const result = await instance.fileExists(
|
|
11085
|
+
const result = await instance.fileExists(path21);
|
|
11086
11086
|
return result.success && result.exists;
|
|
11087
11087
|
}
|
|
11088
|
-
async function unlink(flow,
|
|
11088
|
+
async function unlink(flow, path21) {
|
|
11089
11089
|
const instance = flow.thread.instance;
|
|
11090
|
-
const result = await instance.unlinkFile(
|
|
11090
|
+
const result = await instance.unlinkFile(path21);
|
|
11091
11091
|
if (!result.success) {
|
|
11092
11092
|
throw new Error(result.error || "Failed to delete file");
|
|
11093
11093
|
}
|
|
11094
11094
|
}
|
|
11095
|
-
async function mkdir(flow,
|
|
11095
|
+
async function mkdir(flow, path21) {
|
|
11096
11096
|
const instance = flow.thread.instance;
|
|
11097
|
-
const result = await instance.mkdirFile(
|
|
11097
|
+
const result = await instance.mkdirFile(path21);
|
|
11098
11098
|
if (!result.success) {
|
|
11099
11099
|
throw new Error(result.error || "Failed to create directory");
|
|
11100
11100
|
}
|
|
11101
11101
|
return result.directory;
|
|
11102
11102
|
}
|
|
11103
|
-
async function readdir(flow,
|
|
11103
|
+
async function readdir(flow, path21) {
|
|
11104
11104
|
const instance = flow.thread.instance;
|
|
11105
|
-
const result = await instance.readdirFile(
|
|
11105
|
+
const result = await instance.readdirFile(path21);
|
|
11106
11106
|
if (!result.success) {
|
|
11107
11107
|
throw new Error(result.error || "Failed to read directory");
|
|
11108
11108
|
}
|
|
11109
11109
|
return result.files;
|
|
11110
11110
|
}
|
|
11111
|
-
async function rmdir(flow,
|
|
11111
|
+
async function rmdir(flow, path21) {
|
|
11112
11112
|
const instance = flow.thread.instance;
|
|
11113
|
-
const result = await instance.rmdirFile(
|
|
11113
|
+
const result = await instance.rmdirFile(path21);
|
|
11114
11114
|
if (!result.success) {
|
|
11115
11115
|
throw new Error(result.error || "Failed to remove directory");
|
|
11116
11116
|
}
|
|
@@ -11123,9 +11123,9 @@ async function move(flow, sourcePath, destinationPath) {
|
|
|
11123
11123
|
}
|
|
11124
11124
|
return result.file;
|
|
11125
11125
|
}
|
|
11126
|
-
async function rename(flow,
|
|
11126
|
+
async function rename(flow, path21, newName) {
|
|
11127
11127
|
const instance = flow.thread.instance;
|
|
11128
|
-
const result = await instance.renameFile(
|
|
11128
|
+
const result = await instance.renameFile(path21, newName);
|
|
11129
11129
|
if (!result.success) {
|
|
11130
11130
|
throw new Error(result.error || "Failed to rename file");
|
|
11131
11131
|
}
|
|
@@ -11139,9 +11139,9 @@ async function getFileStats(flow) {
|
|
|
11139
11139
|
}
|
|
11140
11140
|
return result.stats;
|
|
11141
11141
|
}
|
|
11142
|
-
async function getThumbnail(flow,
|
|
11142
|
+
async function getThumbnail(flow, path21) {
|
|
11143
11143
|
const instance = flow.thread.instance;
|
|
11144
|
-
const result = await instance.getFileThumbnail(
|
|
11144
|
+
const result = await instance.getFileThumbnail(path21);
|
|
11145
11145
|
if (!result.success) {
|
|
11146
11146
|
return null;
|
|
11147
11147
|
}
|
|
@@ -11152,22 +11152,22 @@ async function getThumbnail(flow, path20) {
|
|
|
11152
11152
|
}
|
|
11153
11153
|
return bytes.buffer;
|
|
11154
11154
|
}
|
|
11155
|
-
async function cat(flow,
|
|
11155
|
+
async function cat(flow, path21) {
|
|
11156
11156
|
const instance = flow.thread.instance;
|
|
11157
|
-
const result = await instance.readTextFile(
|
|
11157
|
+
const result = await instance.readTextFile(path21);
|
|
11158
11158
|
if (!result.success) {
|
|
11159
11159
|
return null;
|
|
11160
11160
|
}
|
|
11161
11161
|
return result.content;
|
|
11162
11162
|
}
|
|
11163
|
-
async function head(flow,
|
|
11164
|
-
const content = await cat(flow,
|
|
11163
|
+
async function head(flow, path21, lines = 10) {
|
|
11164
|
+
const content = await cat(flow, path21);
|
|
11165
11165
|
if (content === null) return null;
|
|
11166
11166
|
const allLines = content.split("\n");
|
|
11167
11167
|
return allLines.slice(0, lines).join("\n");
|
|
11168
11168
|
}
|
|
11169
|
-
async function tail(flow,
|
|
11170
|
-
const content = await cat(flow,
|
|
11169
|
+
async function tail(flow, path21, lines = 10) {
|
|
11170
|
+
const content = await cat(flow, path21);
|
|
11171
11171
|
if (content === null) return null;
|
|
11172
11172
|
const allLines = content.split("\n");
|
|
11173
11173
|
return allLines.slice(-lines).join("\n");
|
|
@@ -11219,8 +11219,8 @@ function runCodeInDynamicWorker(params) {
|
|
|
11219
11219
|
let terminated = false;
|
|
11220
11220
|
let terminateReason = "Code execution terminated";
|
|
11221
11221
|
let settleTermination = null;
|
|
11222
|
-
const termination = new Promise((
|
|
11223
|
-
settleTermination =
|
|
11222
|
+
const termination = new Promise((resolve3) => {
|
|
11223
|
+
settleTermination = resolve3;
|
|
11224
11224
|
});
|
|
11225
11225
|
const execute = async () => {
|
|
11226
11226
|
const loader = params.threadInstance.env[WORKER_LOADER_BINDING];
|
|
@@ -11706,32 +11706,32 @@ function prepareBridge(options, reports, logs) {
|
|
|
11706
11706
|
logs
|
|
11707
11707
|
};
|
|
11708
11708
|
}
|
|
11709
|
-
function prepareNamespaceRecord(value,
|
|
11709
|
+
function prepareNamespaceRecord(value, path21, functions) {
|
|
11710
11710
|
const out = {};
|
|
11711
11711
|
for (const [key, namespace] of Object.entries(value)) {
|
|
11712
|
-
out[key] = prepareValueRecord(namespace, `${
|
|
11712
|
+
out[key] = prepareValueRecord(namespace, `${path21}.${key}`, functions);
|
|
11713
11713
|
}
|
|
11714
11714
|
return out;
|
|
11715
11715
|
}
|
|
11716
|
-
function prepareValueRecord(value,
|
|
11716
|
+
function prepareValueRecord(value, path21, functions) {
|
|
11717
11717
|
const out = {};
|
|
11718
11718
|
for (const [key, item] of Object.entries(value)) {
|
|
11719
|
-
out[key] = prepareBridgeValue(item, `${
|
|
11719
|
+
out[key] = prepareBridgeValue(item, `${path21}.${key}`, functions);
|
|
11720
11720
|
}
|
|
11721
11721
|
return out;
|
|
11722
11722
|
}
|
|
11723
|
-
function prepareBridgeValue(value,
|
|
11723
|
+
function prepareBridgeValue(value, path21, functions) {
|
|
11724
11724
|
if (typeof value === "function") {
|
|
11725
|
-
functions.set(
|
|
11726
|
-
return { __agentbuilderType: "function", id:
|
|
11725
|
+
functions.set(path21, value);
|
|
11726
|
+
return { __agentbuilderType: "function", id: path21 };
|
|
11727
11727
|
}
|
|
11728
11728
|
if (isThenable(value)) {
|
|
11729
|
-
const promiseId = `${
|
|
11729
|
+
const promiseId = `${path21}.__promise`;
|
|
11730
11730
|
functions.set(promiseId, async () => value);
|
|
11731
11731
|
return { __agentbuilderType: "promise", id: promiseId };
|
|
11732
11732
|
}
|
|
11733
11733
|
if (Array.isArray(value)) {
|
|
11734
|
-
return value.map((item, index) => prepareBridgeValue(item, `${
|
|
11734
|
+
return value.map((item, index) => prepareBridgeValue(item, `${path21}.${index}`, functions));
|
|
11735
11735
|
}
|
|
11736
11736
|
if (value && typeof value === "object") {
|
|
11737
11737
|
if (value instanceof Date || value instanceof Map || value instanceof Set || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {
|
|
@@ -11742,7 +11742,7 @@ function prepareBridgeValue(value, path20, functions) {
|
|
|
11742
11742
|
}
|
|
11743
11743
|
const out = {};
|
|
11744
11744
|
for (const [key, item] of Object.entries(value)) {
|
|
11745
|
-
out[key] = prepareBridgeValue(item, `${
|
|
11745
|
+
out[key] = prepareBridgeValue(item, `${path21}.${key}`, functions);
|
|
11746
11746
|
}
|
|
11747
11747
|
return out;
|
|
11748
11748
|
}
|
|
@@ -12617,12 +12617,12 @@ function normalizeVirtualModulePath(basePath, specifier) {
|
|
|
12617
12617
|
}
|
|
12618
12618
|
return normalized;
|
|
12619
12619
|
}
|
|
12620
|
-
function dirnameModulePath(
|
|
12621
|
-
const index =
|
|
12622
|
-
return index <= 0 ? "" :
|
|
12620
|
+
function dirnameModulePath(path21) {
|
|
12621
|
+
const index = path21.lastIndexOf("/");
|
|
12622
|
+
return index <= 0 ? "" : path21.slice(0, index);
|
|
12623
12623
|
}
|
|
12624
|
-
function hasModuleExtension(
|
|
12625
|
-
return /\.[A-Za-z0-9]+$/.test(
|
|
12624
|
+
function hasModuleExtension(path21) {
|
|
12625
|
+
return /\.[A-Za-z0-9]+$/.test(path21);
|
|
12626
12626
|
}
|
|
12627
12627
|
function resolveGraphModuleSpecifier(fromPath, specifier, modulePaths) {
|
|
12628
12628
|
const base = normalizeVirtualModulePath(dirnameModulePath(fromPath), specifier);
|
|
@@ -12953,9 +12953,9 @@ function isPlainObject2(value) {
|
|
|
12953
12953
|
const prototype = Object.getPrototypeOf(value);
|
|
12954
12954
|
return prototype === Object.prototype || prototype === null;
|
|
12955
12955
|
}
|
|
12956
|
-
function findUntransferableOption(value,
|
|
12956
|
+
function findUntransferableOption(value, path21, seen = /* @__PURE__ */ new WeakSet()) {
|
|
12957
12957
|
if (typeof value === "function" || typeof value === "symbol") {
|
|
12958
|
-
return
|
|
12958
|
+
return path21;
|
|
12959
12959
|
}
|
|
12960
12960
|
if (!value || typeof value !== "object") {
|
|
12961
12961
|
return null;
|
|
@@ -12969,7 +12969,7 @@ function findUntransferableOption(value, path20, seen = /* @__PURE__ */ new Weak
|
|
|
12969
12969
|
seen.add(value);
|
|
12970
12970
|
if (Array.isArray(value)) {
|
|
12971
12971
|
for (const [index, item] of value.entries()) {
|
|
12972
|
-
const found = findUntransferableOption(item, `${
|
|
12972
|
+
const found = findUntransferableOption(item, `${path21}.${index}`, seen);
|
|
12973
12973
|
if (found) return found;
|
|
12974
12974
|
}
|
|
12975
12975
|
return null;
|
|
@@ -12977,9 +12977,9 @@ function findUntransferableOption(value, path20, seen = /* @__PURE__ */ new Weak
|
|
|
12977
12977
|
if (value instanceof Map) {
|
|
12978
12978
|
let index = 0;
|
|
12979
12979
|
for (const [key, item] of value.entries()) {
|
|
12980
|
-
const foundKey = findUntransferableOption(key, `${
|
|
12980
|
+
const foundKey = findUntransferableOption(key, `${path21}.mapKey${index}`, seen);
|
|
12981
12981
|
if (foundKey) return foundKey;
|
|
12982
|
-
const foundValue = findUntransferableOption(item, `${
|
|
12982
|
+
const foundValue = findUntransferableOption(item, `${path21}.mapValue${index}`, seen);
|
|
12983
12983
|
if (foundValue) return foundValue;
|
|
12984
12984
|
index += 1;
|
|
12985
12985
|
}
|
|
@@ -12988,17 +12988,17 @@ function findUntransferableOption(value, path20, seen = /* @__PURE__ */ new Weak
|
|
|
12988
12988
|
if (value instanceof Set) {
|
|
12989
12989
|
let index = 0;
|
|
12990
12990
|
for (const item of value.values()) {
|
|
12991
|
-
const found = findUntransferableOption(item, `${
|
|
12991
|
+
const found = findUntransferableOption(item, `${path21}.setValue${index}`, seen);
|
|
12992
12992
|
if (found) return found;
|
|
12993
12993
|
index += 1;
|
|
12994
12994
|
}
|
|
12995
12995
|
return null;
|
|
12996
12996
|
}
|
|
12997
12997
|
if (!isPlainObject2(value)) {
|
|
12998
|
-
return
|
|
12998
|
+
return path21;
|
|
12999
12999
|
}
|
|
13000
13000
|
for (const [key, item] of Object.entries(value)) {
|
|
13001
|
-
const found = findUntransferableOption(item, `${
|
|
13001
|
+
const found = findUntransferableOption(item, `${path21}.${key}`, seen);
|
|
13002
13002
|
if (found) return found;
|
|
13003
13003
|
}
|
|
13004
13004
|
return null;
|
|
@@ -13008,8 +13008,8 @@ function createCodeExecutionHandle(execute, reports = [], onTerminate) {
|
|
|
13008
13008
|
let running = true;
|
|
13009
13009
|
let terminated = false;
|
|
13010
13010
|
let settleTermination = null;
|
|
13011
|
-
const termination = new Promise((
|
|
13012
|
-
settleTermination =
|
|
13011
|
+
const termination = new Promise((resolve3) => {
|
|
13012
|
+
settleTermination = resolve3;
|
|
13013
13013
|
});
|
|
13014
13014
|
const promise = Promise.race([execute(), termination]).finally(() => {
|
|
13015
13015
|
running = false;
|
|
@@ -13719,7 +13719,7 @@ var init_ThreadStateImpl = __esm({
|
|
|
13719
13719
|
const toolCallId = this._flowState?.currentToolCall?.id;
|
|
13720
13720
|
const canPark = !!(toolCallId && this._executionState && typeof instance.dispatchClientTool === "function");
|
|
13721
13721
|
const side = this._flowState?.currentSide === "b" ? "b" : "a";
|
|
13722
|
-
const mustParkForApproval =
|
|
13722
|
+
const mustParkForApproval = await this.forwardedCallNeedsApproval(request);
|
|
13723
13723
|
if (mustParkForApproval && canPark && toolCallId && typeof instance.hasBridge === "function" && await instance.hasBridge()) {
|
|
13724
13724
|
await instance.dispatchClientTool(request, toolCallId, side);
|
|
13725
13725
|
const getDelivered = instance.getDeliveredClientToolResult;
|
|
@@ -13926,7 +13926,7 @@ var init_ThreadStateImpl = __esm({
|
|
|
13926
13926
|
// ─────────────────────────────────────────────────────────────────────────
|
|
13927
13927
|
// File System
|
|
13928
13928
|
// ─────────────────────────────────────────────────────────────────────────
|
|
13929
|
-
async writeFile(
|
|
13929
|
+
async writeFile(path21, data, mimeType, options) {
|
|
13930
13930
|
const isText = this._isTextMimeType(mimeType);
|
|
13931
13931
|
if (isText) {
|
|
13932
13932
|
let textContent;
|
|
@@ -13935,7 +13935,7 @@ var init_ThreadStateImpl = __esm({
|
|
|
13935
13935
|
} else {
|
|
13936
13936
|
textContent = new TextDecoder().decode(data);
|
|
13937
13937
|
}
|
|
13938
|
-
const result = await this._threadInstance.writeTextFile(
|
|
13938
|
+
const result = await this._threadInstance.writeTextFile(path21, textContent, mimeType, options);
|
|
13939
13939
|
return this._mapFileRecord(result.file);
|
|
13940
13940
|
} else {
|
|
13941
13941
|
let base64Data;
|
|
@@ -13955,7 +13955,7 @@ var init_ThreadStateImpl = __esm({
|
|
|
13955
13955
|
}
|
|
13956
13956
|
base64Data = btoa(binary);
|
|
13957
13957
|
}
|
|
13958
|
-
const result = await this._threadInstance.writeFile(
|
|
13958
|
+
const result = await this._threadInstance.writeFile(path21, base64Data, mimeType, options);
|
|
13959
13959
|
return this._mapFileRecord(result.file);
|
|
13960
13960
|
}
|
|
13961
13961
|
}
|
|
@@ -14027,8 +14027,8 @@ var init_ThreadStateImpl = __esm({
|
|
|
14027
14027
|
(type) => mimeType === type || mimeType.startsWith(type + ";")
|
|
14028
14028
|
);
|
|
14029
14029
|
}
|
|
14030
|
-
async readFile(
|
|
14031
|
-
const result = await this._threadInstance.readFile(
|
|
14030
|
+
async readFile(path21) {
|
|
14031
|
+
const result = await this._threadInstance.readFile(path21);
|
|
14032
14032
|
if (!result.success || !result.data) {
|
|
14033
14033
|
return null;
|
|
14034
14034
|
}
|
|
@@ -14039,8 +14039,8 @@ var init_ThreadStateImpl = __esm({
|
|
|
14039
14039
|
}
|
|
14040
14040
|
return bytes.buffer;
|
|
14041
14041
|
}
|
|
14042
|
-
async readFileStream(
|
|
14043
|
-
const fileInfo = await this._threadInstance.statFile(
|
|
14042
|
+
async readFileStream(path21, options) {
|
|
14043
|
+
const fileInfo = await this._threadInstance.statFile(path21);
|
|
14044
14044
|
if (!fileInfo) {
|
|
14045
14045
|
return null;
|
|
14046
14046
|
}
|
|
@@ -14055,7 +14055,7 @@ var init_ThreadStateImpl = __esm({
|
|
|
14055
14055
|
return {
|
|
14056
14056
|
[Symbol.asyncIterator]: async function* () {
|
|
14057
14057
|
if (!isChunked) {
|
|
14058
|
-
const result = await threadInstance.readFile(
|
|
14058
|
+
const result = await threadInstance.readFile(path21);
|
|
14059
14059
|
if (!result.success || !result.data) {
|
|
14060
14060
|
return;
|
|
14061
14061
|
}
|
|
@@ -14076,7 +14076,7 @@ var init_ThreadStateImpl = __esm({
|
|
|
14076
14076
|
if (signal?.aborted) {
|
|
14077
14077
|
return;
|
|
14078
14078
|
}
|
|
14079
|
-
const result = await threadInstance.readFileChunk(
|
|
14079
|
+
const result = await threadInstance.readFileChunk(path21, i);
|
|
14080
14080
|
if (!result.success || !result.data) {
|
|
14081
14081
|
throw new Error(result.error || `Failed to read chunk ${i}`);
|
|
14082
14082
|
}
|
|
@@ -14095,25 +14095,25 @@ var init_ThreadStateImpl = __esm({
|
|
|
14095
14095
|
}
|
|
14096
14096
|
};
|
|
14097
14097
|
}
|
|
14098
|
-
async statFile(
|
|
14099
|
-
const result = await this._threadInstance.statFile(
|
|
14098
|
+
async statFile(path21) {
|
|
14099
|
+
const result = await this._threadInstance.statFile(path21);
|
|
14100
14100
|
return result ? this._mapFileRecord(result) : null;
|
|
14101
14101
|
}
|
|
14102
|
-
async readdirFile(
|
|
14103
|
-
const entries = await this._threadInstance.readdirFile(
|
|
14102
|
+
async readdirFile(path21) {
|
|
14103
|
+
const entries = await this._threadInstance.readdirFile(path21);
|
|
14104
14104
|
return {
|
|
14105
14105
|
entries: entries.map((e) => this._mapFileRecord(e))
|
|
14106
14106
|
};
|
|
14107
14107
|
}
|
|
14108
|
-
async unlinkFile(
|
|
14109
|
-
await this._threadInstance.unlinkFile(
|
|
14108
|
+
async unlinkFile(path21) {
|
|
14109
|
+
await this._threadInstance.unlinkFile(path21);
|
|
14110
14110
|
}
|
|
14111
|
-
async mkdirFile(
|
|
14112
|
-
const result = await this._threadInstance.mkdirFile(
|
|
14111
|
+
async mkdirFile(path21) {
|
|
14112
|
+
const result = await this._threadInstance.mkdirFile(path21);
|
|
14113
14113
|
return this._mapFileRecord(result);
|
|
14114
14114
|
}
|
|
14115
|
-
async rmdirFile(
|
|
14116
|
-
await this._threadInstance.rmdirFile(
|
|
14115
|
+
async rmdirFile(path21) {
|
|
14116
|
+
await this._threadInstance.rmdirFile(path21);
|
|
14117
14117
|
}
|
|
14118
14118
|
async moveFile(sourcePath, destinationPath) {
|
|
14119
14119
|
const result = await this._threadInstance.moveFile(sourcePath, destinationPath);
|
|
@@ -14122,8 +14122,8 @@ var init_ThreadStateImpl = __esm({
|
|
|
14122
14122
|
}
|
|
14123
14123
|
return this._mapFileRecord(result.file);
|
|
14124
14124
|
}
|
|
14125
|
-
async renameFile(
|
|
14126
|
-
const result = await this._threadInstance.renameFile(
|
|
14125
|
+
async renameFile(path21, newName) {
|
|
14126
|
+
const result = await this._threadInstance.renameFile(path21, newName);
|
|
14127
14127
|
if (!result.success || !result.file) {
|
|
14128
14128
|
throw new Error(result.error || "Failed to rename file");
|
|
14129
14129
|
}
|
|
@@ -14150,8 +14150,8 @@ var init_ThreadStateImpl = __esm({
|
|
|
14150
14150
|
paths: Array.isArray(results) ? results : results.paths || []
|
|
14151
14151
|
};
|
|
14152
14152
|
}
|
|
14153
|
-
async getFileThumbnail(
|
|
14154
|
-
return this._threadInstance.getFileThumbnail(
|
|
14153
|
+
async getFileThumbnail(path21) {
|
|
14154
|
+
return this._threadInstance.getFileThumbnail(path21);
|
|
14155
14155
|
}
|
|
14156
14156
|
// ─────────────────────────────────────────────────────────────────────────
|
|
14157
14157
|
// Execution State
|
|
@@ -14356,9 +14356,9 @@ var init_ThreadStateImpl = __esm({
|
|
|
14356
14356
|
"Reentrant user-scope call: this ThreadState was raised from user-scope code; state.user().call() is unavailable here."
|
|
14357
14357
|
);
|
|
14358
14358
|
}
|
|
14359
|
-
const
|
|
14359
|
+
const path21 = endpoint.replace(/^\/+/, "");
|
|
14360
14360
|
return hub().fetch(
|
|
14361
|
-
new Request(`https://user-hub/users/${encodeURIComponent(userId)}/endpoints/${
|
|
14361
|
+
new Request(`https://user-hub/users/${encodeURIComponent(userId)}/endpoints/${path21}`, {
|
|
14362
14362
|
method: "POST",
|
|
14363
14363
|
headers: {
|
|
14364
14364
|
"Content-Type": "application/json",
|
|
@@ -14426,7 +14426,7 @@ var init_ThreadStateImpl = __esm({
|
|
|
14426
14426
|
const skillMd = await stub.getSkillFile(name, "SKILL.md") ?? "";
|
|
14427
14427
|
return { metadata, skillMd };
|
|
14428
14428
|
},
|
|
14429
|
-
readFile: (name,
|
|
14429
|
+
readFile: (name, path21) => stub.getSkillFile(name, path21),
|
|
14430
14430
|
install: (files) => stub.upsertSkill(files),
|
|
14431
14431
|
setEnabled: (name, enabled) => stub.setSkillEnabled(name, enabled),
|
|
14432
14432
|
remove: (name) => stub.deleteSkill(name)
|
|
@@ -14619,15 +14619,15 @@ function extractSchemaFields(content) {
|
|
|
14619
14619
|
}
|
|
14620
14620
|
function scanPromptsWithSchemas(dir) {
|
|
14621
14621
|
const results = [];
|
|
14622
|
-
if (!
|
|
14622
|
+
if (!fs9__default.existsSync(dir)) {
|
|
14623
14623
|
return results;
|
|
14624
14624
|
}
|
|
14625
14625
|
try {
|
|
14626
|
-
const entries =
|
|
14626
|
+
const entries = fs9__default.readdirSync(dir, { withFileTypes: true });
|
|
14627
14627
|
for (const entry of entries) {
|
|
14628
14628
|
if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
14629
|
-
const filePath =
|
|
14630
|
-
const content =
|
|
14629
|
+
const filePath = path9__default.join(dir, entry.name);
|
|
14630
|
+
const content = fs9__default.readFileSync(filePath, "utf-8");
|
|
14631
14631
|
const nameMatch = content.match(/name:\s*['"]([^'"]+)['"]/);
|
|
14632
14632
|
if (nameMatch) {
|
|
14633
14633
|
const name = nameMatch[1];
|
|
@@ -14643,15 +14643,15 @@ function scanPromptsWithSchemas(dir) {
|
|
|
14643
14643
|
}
|
|
14644
14644
|
function scanAgentsWithSideA(dir) {
|
|
14645
14645
|
const results = [];
|
|
14646
|
-
if (!
|
|
14646
|
+
if (!fs9__default.existsSync(dir)) {
|
|
14647
14647
|
return results;
|
|
14648
14648
|
}
|
|
14649
14649
|
try {
|
|
14650
|
-
const entries =
|
|
14650
|
+
const entries = fs9__default.readdirSync(dir, { withFileTypes: true });
|
|
14651
14651
|
for (const entry of entries) {
|
|
14652
14652
|
if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
14653
|
-
const filePath =
|
|
14654
|
-
const content =
|
|
14653
|
+
const filePath = path9__default.join(dir, entry.name);
|
|
14654
|
+
const content = fs9__default.readFileSync(filePath, "utf-8");
|
|
14655
14655
|
const nameMatch = content.match(/name:\s*['"]([^'"]+)['"]/);
|
|
14656
14656
|
if (nameMatch) {
|
|
14657
14657
|
const name = nameMatch[1];
|
|
@@ -14671,15 +14671,15 @@ function scanAgentsWithSideA(dir) {
|
|
|
14671
14671
|
}
|
|
14672
14672
|
function scanForNames(dir, useFilename = false) {
|
|
14673
14673
|
const names = [];
|
|
14674
|
-
if (!
|
|
14674
|
+
if (!fs9__default.existsSync(dir)) {
|
|
14675
14675
|
return names;
|
|
14676
14676
|
}
|
|
14677
14677
|
try {
|
|
14678
|
-
const entries =
|
|
14678
|
+
const entries = fs9__default.readdirSync(dir, { withFileTypes: true });
|
|
14679
14679
|
for (const entry of entries) {
|
|
14680
14680
|
if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
14681
|
-
const filePath =
|
|
14682
|
-
const content =
|
|
14681
|
+
const filePath = path9__default.join(dir, entry.name);
|
|
14682
|
+
const content = fs9__default.readFileSync(filePath, "utf-8");
|
|
14683
14683
|
if (useFilename) {
|
|
14684
14684
|
const toolName = entry.name.replace(/\.ts$/, "");
|
|
14685
14685
|
if (content.includes("defineTool")) {
|
|
@@ -14700,18 +14700,18 @@ function scanForNames(dir, useFilename = false) {
|
|
|
14700
14700
|
}
|
|
14701
14701
|
function scanHooksForIds(dir) {
|
|
14702
14702
|
const hookIds = [];
|
|
14703
|
-
if (!
|
|
14703
|
+
if (!fs9__default.existsSync(dir)) {
|
|
14704
14704
|
return hookIds;
|
|
14705
14705
|
}
|
|
14706
14706
|
try {
|
|
14707
|
-
const entries =
|
|
14707
|
+
const entries = fs9__default.readdirSync(dir, { withFileTypes: true });
|
|
14708
14708
|
for (const entry of entries) {
|
|
14709
14709
|
if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
14710
14710
|
if (entry.name === "index.ts") {
|
|
14711
14711
|
continue;
|
|
14712
14712
|
}
|
|
14713
|
-
const filePath =
|
|
14714
|
-
const content =
|
|
14713
|
+
const filePath = path9__default.join(dir, entry.name);
|
|
14714
|
+
const content = fs9__default.readFileSync(filePath, "utf-8");
|
|
14715
14715
|
const idMatch = content.match(/defineHook\s*\(\s*\{[^}]*id:\s*['"]([^'"]+)['"]/s);
|
|
14716
14716
|
if (idMatch) {
|
|
14717
14717
|
hookIds.push(idMatch[1]);
|
|
@@ -15379,44 +15379,44 @@ declare module 'virtual:@standardagents/router' {
|
|
|
15379
15379
|
`;
|
|
15380
15380
|
}
|
|
15381
15381
|
function ensureDir(dir) {
|
|
15382
|
-
if (!
|
|
15383
|
-
|
|
15382
|
+
if (!fs9__default.existsSync(dir)) {
|
|
15383
|
+
fs9__default.mkdirSync(dir, { recursive: true });
|
|
15384
15384
|
}
|
|
15385
15385
|
}
|
|
15386
15386
|
function writeFileIfChanged(filePath, content) {
|
|
15387
|
-
if (
|
|
15388
|
-
const existing =
|
|
15387
|
+
if (fs9__default.existsSync(filePath)) {
|
|
15388
|
+
const existing = fs9__default.readFileSync(filePath, "utf-8");
|
|
15389
15389
|
if (existing === content) {
|
|
15390
15390
|
return;
|
|
15391
15391
|
}
|
|
15392
15392
|
}
|
|
15393
|
-
|
|
15393
|
+
fs9__default.writeFileSync(filePath, content);
|
|
15394
15394
|
}
|
|
15395
15395
|
function generateTypes(config) {
|
|
15396
15396
|
ensureDir(config.outputDir);
|
|
15397
15397
|
const typesContent = generateTypesContent(config);
|
|
15398
|
-
writeFileIfChanged(
|
|
15398
|
+
writeFileIfChanged(path9__default.join(config.outputDir, "types.d.ts"), typesContent);
|
|
15399
15399
|
const virtualModuleContent = generateVirtualModuleContent();
|
|
15400
|
-
writeFileIfChanged(
|
|
15401
|
-
writeFileIfChanged(
|
|
15402
|
-
writeFileIfChanged(
|
|
15400
|
+
writeFileIfChanged(path9__default.join(config.outputDir, "virtual-module.d.ts"), virtualModuleContent);
|
|
15401
|
+
writeFileIfChanged(path9__default.join(config.outputDir, "tsconfig.json"), TSCONFIG_CONTENT);
|
|
15402
|
+
writeFileIfChanged(path9__default.join(config.outputDir, ".gitignore"), "*\n");
|
|
15403
15403
|
}
|
|
15404
15404
|
function needsRegeneration(config) {
|
|
15405
|
-
const typesPath =
|
|
15406
|
-
if (!
|
|
15405
|
+
const typesPath = path9__default.join(config.outputDir, "types.d.ts");
|
|
15406
|
+
if (!fs9__default.existsSync(typesPath)) {
|
|
15407
15407
|
return true;
|
|
15408
15408
|
}
|
|
15409
|
-
const typesMtime =
|
|
15409
|
+
const typesMtime = fs9__default.statSync(typesPath).mtime;
|
|
15410
15410
|
const dirs = [config.modelsDir, config.promptsDir, config.agentsDir, config.toolsDir, config.hooksDir];
|
|
15411
15411
|
for (const dir of dirs) {
|
|
15412
|
-
if (!
|
|
15412
|
+
if (!fs9__default.existsSync(dir)) {
|
|
15413
15413
|
continue;
|
|
15414
15414
|
}
|
|
15415
|
-
const entries =
|
|
15415
|
+
const entries = fs9__default.readdirSync(dir, { withFileTypes: true });
|
|
15416
15416
|
for (const entry of entries) {
|
|
15417
15417
|
if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
15418
|
-
const filePath =
|
|
15419
|
-
const fileMtime =
|
|
15418
|
+
const filePath = path9__default.join(dir, entry.name);
|
|
15419
|
+
const fileMtime = fs9__default.statSync(filePath).mtime;
|
|
15420
15420
|
if (fileMtime > typesMtime) {
|
|
15421
15421
|
return true;
|
|
15422
15422
|
}
|
|
@@ -15622,7 +15622,7 @@ function createHmrReloader() {
|
|
|
15622
15622
|
versions,
|
|
15623
15623
|
invalidateSourceFileModule(server, filePath) {
|
|
15624
15624
|
if (!filePath) return;
|
|
15625
|
-
const absolutePath =
|
|
15625
|
+
const absolutePath = path9__default.resolve(filePath);
|
|
15626
15626
|
for (const [envName, env] of Object.entries(server.environments)) {
|
|
15627
15627
|
const modules = env.moduleGraph.getModulesByFile(absolutePath);
|
|
15628
15628
|
if (!modules) continue;
|
|
@@ -15633,10 +15633,10 @@ function createHmrReloader() {
|
|
|
15633
15633
|
}
|
|
15634
15634
|
},
|
|
15635
15635
|
invalidateSourceDirectoryModules(server, dirPath) {
|
|
15636
|
-
if (!
|
|
15636
|
+
if (!fs9__default.existsSync(dirPath)) return;
|
|
15637
15637
|
const scan = (currentDir) => {
|
|
15638
|
-
for (const entry of
|
|
15639
|
-
const nextPath =
|
|
15638
|
+
for (const entry of fs9__default.readdirSync(currentDir, { withFileTypes: true })) {
|
|
15639
|
+
const nextPath = path9__default.join(currentDir, entry.name);
|
|
15640
15640
|
if (entry.isDirectory()) {
|
|
15641
15641
|
scan(nextPath);
|
|
15642
15642
|
} else if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
@@ -15800,12 +15800,12 @@ function createHmrReloader() {
|
|
|
15800
15800
|
};
|
|
15801
15801
|
return reloader;
|
|
15802
15802
|
}
|
|
15803
|
-
var STATE_RELATIVE_PATH =
|
|
15803
|
+
var STATE_RELATIVE_PATH = path9__default.join(".agents", "bootstrap-session.json");
|
|
15804
15804
|
var PROJECT_ROOT_ENV_KEYS = ["INIT_CWD", "PWD", "npm_config_local_prefix"];
|
|
15805
15805
|
function uniquePaths(paths) {
|
|
15806
15806
|
return Array.from(
|
|
15807
15807
|
new Set(
|
|
15808
|
-
paths.filter((value) => !!value?.trim()).map((value) =>
|
|
15808
|
+
paths.filter((value) => !!value?.trim()).map((value) => path9__default.resolve(value))
|
|
15809
15809
|
)
|
|
15810
15810
|
);
|
|
15811
15811
|
}
|
|
@@ -15821,11 +15821,11 @@ function mergeCookieHeader(cookieHeader, injectedCookie) {
|
|
|
15821
15821
|
return raw ? `${raw}; ${injectedCookie}` : injectedCookie;
|
|
15822
15822
|
}
|
|
15823
15823
|
function loadLocalBootstrapSession(projectRoot) {
|
|
15824
|
-
const statePath =
|
|
15825
|
-
if (!
|
|
15824
|
+
const statePath = path9__default.join(projectRoot, STATE_RELATIVE_PATH);
|
|
15825
|
+
if (!fs9__default.existsSync(statePath)) return null;
|
|
15826
15826
|
try {
|
|
15827
15827
|
const parsed = JSON.parse(
|
|
15828
|
-
|
|
15828
|
+
fs9__default.readFileSync(statePath, "utf-8")
|
|
15829
15829
|
);
|
|
15830
15830
|
if (parsed.version !== 1) return null;
|
|
15831
15831
|
if (!parsed.endpoint || !parsed.user?.id || !parsed.account?.id) return null;
|
|
@@ -15842,7 +15842,7 @@ function findLocalBootstrapSession(projectRoot, env) {
|
|
|
15842
15842
|
const envSession = loadLocalBootstrapSessionFromEnv();
|
|
15843
15843
|
if (envSession) {
|
|
15844
15844
|
return {
|
|
15845
|
-
projectRoot: projectRoot ?
|
|
15845
|
+
projectRoot: projectRoot ? path9__default.resolve(projectRoot) : process.cwd(),
|
|
15846
15846
|
session: envSession
|
|
15847
15847
|
};
|
|
15848
15848
|
}
|
|
@@ -16487,23 +16487,23 @@ function nameToFilename(name) {
|
|
|
16487
16487
|
}
|
|
16488
16488
|
function getModelFilePath(modelsDir, name) {
|
|
16489
16489
|
const filename = nameToFilename(name);
|
|
16490
|
-
return
|
|
16490
|
+
return path9__default.join(modelsDir, `${filename}.ts`);
|
|
16491
16491
|
}
|
|
16492
16492
|
function getProviderFilePath(providersDir, name) {
|
|
16493
16493
|
const filename = nameToFilename(name);
|
|
16494
|
-
return
|
|
16494
|
+
return path9__default.join(providersDir, `${filename}.ts`);
|
|
16495
16495
|
}
|
|
16496
16496
|
function extensionlessImportPath(fromDir, toFile) {
|
|
16497
|
-
let
|
|
16498
|
-
if (!
|
|
16499
|
-
|
|
16497
|
+
let relative4 = path9__default.relative(fromDir, toFile).replace(/\\/g, "/").replace(/\.ts$/, "");
|
|
16498
|
+
if (!relative4.startsWith(".")) {
|
|
16499
|
+
relative4 = `./${relative4}`;
|
|
16500
16500
|
}
|
|
16501
|
-
return
|
|
16501
|
+
return relative4;
|
|
16502
16502
|
}
|
|
16503
16503
|
function getLocalProviderInfo(modelsDir, providersDir, providerName) {
|
|
16504
16504
|
if (!providersDir) return null;
|
|
16505
16505
|
const providerPath = getProviderFilePath(providersDir, providerName);
|
|
16506
|
-
if (!
|
|
16506
|
+
if (!fs9__default.existsSync(providerPath)) return null;
|
|
16507
16507
|
return {
|
|
16508
16508
|
name: nameToFilename(providerName),
|
|
16509
16509
|
package: extensionlessImportPath(modelsDir, providerPath),
|
|
@@ -16512,15 +16512,15 @@ function getLocalProviderInfo(modelsDir, providersDir, providerName) {
|
|
|
16512
16512
|
}
|
|
16513
16513
|
function modelExists(modelsDir, name) {
|
|
16514
16514
|
const filePath = getModelFilePath(modelsDir, name);
|
|
16515
|
-
return
|
|
16515
|
+
return fs9__default.existsSync(filePath);
|
|
16516
16516
|
}
|
|
16517
16517
|
async function saveModel(modelsDir, data, overwrite = false, providerPackageMap = defaultProviderPackageMap, providersDir) {
|
|
16518
16518
|
try {
|
|
16519
|
-
if (!
|
|
16520
|
-
|
|
16519
|
+
if (!fs9__default.existsSync(modelsDir)) {
|
|
16520
|
+
fs9__default.mkdirSync(modelsDir, { recursive: true });
|
|
16521
16521
|
}
|
|
16522
16522
|
const filePath = getModelFilePath(modelsDir, data.name);
|
|
16523
|
-
if (!overwrite &&
|
|
16523
|
+
if (!overwrite && fs9__default.existsSync(filePath)) {
|
|
16524
16524
|
return {
|
|
16525
16525
|
success: false,
|
|
16526
16526
|
error: `Model file already exists: ${filePath}. Use update to modify existing models.`
|
|
@@ -16528,7 +16528,7 @@ async function saveModel(modelsDir, data, overwrite = false, providerPackageMap
|
|
|
16528
16528
|
}
|
|
16529
16529
|
const providerInfo = providerPackageMap[data.provider] ?? getLocalProviderInfo(modelsDir, providersDir, data.provider);
|
|
16530
16530
|
if (!providerInfo) {
|
|
16531
|
-
const localProviderNames = providersDir &&
|
|
16531
|
+
const localProviderNames = providersDir && fs9__default.existsSync(providersDir) ? fs9__default.readdirSync(providersDir).filter((fileName) => fileName.endsWith(".ts")).map((fileName) => fileName.replace(/\.ts$/, "")) : [];
|
|
16532
16532
|
const validProviders = [...Object.keys(providerPackageMap), ...localProviderNames];
|
|
16533
16533
|
return {
|
|
16534
16534
|
success: false,
|
|
@@ -16540,7 +16540,7 @@ async function saveModel(modelsDir, data, overwrite = false, providerPackageMap
|
|
|
16540
16540
|
providerPackage: providerInfo.package,
|
|
16541
16541
|
defaultImport: providerInfo.defaultImport
|
|
16542
16542
|
});
|
|
16543
|
-
await
|
|
16543
|
+
await fs9__default.promises.writeFile(filePath, content, "utf-8");
|
|
16544
16544
|
return {
|
|
16545
16545
|
success: true,
|
|
16546
16546
|
filePath
|
|
@@ -16555,13 +16555,13 @@ async function saveModel(modelsDir, data, overwrite = false, providerPackageMap
|
|
|
16555
16555
|
async function deleteModel(modelsDir, name) {
|
|
16556
16556
|
try {
|
|
16557
16557
|
const filePath = getModelFilePath(modelsDir, name);
|
|
16558
|
-
if (!
|
|
16558
|
+
if (!fs9__default.existsSync(filePath)) {
|
|
16559
16559
|
return {
|
|
16560
16560
|
success: false,
|
|
16561
16561
|
error: `Model file not found: ${filePath}`
|
|
16562
16562
|
};
|
|
16563
16563
|
}
|
|
16564
|
-
await
|
|
16564
|
+
await fs9__default.promises.unlink(filePath);
|
|
16565
16565
|
return {
|
|
16566
16566
|
success: true,
|
|
16567
16567
|
filePath
|
|
@@ -16607,7 +16607,7 @@ function validateModelDataWithProviders(data, providerPackageMap, providersDir)
|
|
|
16607
16607
|
const validProviders = Object.keys(providerPackageMap);
|
|
16608
16608
|
const hasLocalProvider = Boolean(getLocalProviderInfo(process.cwd(), providersDir, data.provider));
|
|
16609
16609
|
if (!validProviders.includes(data.provider) && !hasLocalProvider) {
|
|
16610
|
-
const localProviderNames = providersDir &&
|
|
16610
|
+
const localProviderNames = providersDir && fs9__default.existsSync(providersDir) ? fs9__default.readdirSync(providersDir).filter((fileName) => fileName.endsWith(".ts")).map((fileName) => fileName.replace(/\.ts$/, "")) : [];
|
|
16611
16611
|
errors["provider"] = `Invalid provider '${data.provider}'. Must be one of: ${[...validProviders, ...localProviderNames].join(", ")}`;
|
|
16612
16612
|
}
|
|
16613
16613
|
}
|
|
@@ -16824,26 +16824,26 @@ function transformPromptData(data) {
|
|
|
16824
16824
|
}
|
|
16825
16825
|
function getPromptFilePath(promptsDir, name) {
|
|
16826
16826
|
const filename = nameToFilename(name);
|
|
16827
|
-
return
|
|
16827
|
+
return path9__default.join(promptsDir, `${filename}.ts`);
|
|
16828
16828
|
}
|
|
16829
16829
|
function promptExists(promptsDir, name) {
|
|
16830
16830
|
const filePath = getPromptFilePath(promptsDir, name);
|
|
16831
|
-
return
|
|
16831
|
+
return fs9__default.existsSync(filePath);
|
|
16832
16832
|
}
|
|
16833
16833
|
async function savePrompt(promptsDir, data, overwrite = false) {
|
|
16834
16834
|
try {
|
|
16835
|
-
if (!
|
|
16836
|
-
|
|
16835
|
+
if (!fs9__default.existsSync(promptsDir)) {
|
|
16836
|
+
fs9__default.mkdirSync(promptsDir, { recursive: true });
|
|
16837
16837
|
}
|
|
16838
16838
|
const filePath = getPromptFilePath(promptsDir, data.name);
|
|
16839
|
-
if (!overwrite &&
|
|
16839
|
+
if (!overwrite && fs9__default.existsSync(filePath)) {
|
|
16840
16840
|
return {
|
|
16841
16841
|
success: false,
|
|
16842
16842
|
error: `Prompt file already exists: ${filePath}. Use update to modify existing prompts.`
|
|
16843
16843
|
};
|
|
16844
16844
|
}
|
|
16845
16845
|
const content = generatePromptFile(data);
|
|
16846
|
-
await
|
|
16846
|
+
await fs9__default.promises.writeFile(filePath, content, "utf-8");
|
|
16847
16847
|
return {
|
|
16848
16848
|
success: true,
|
|
16849
16849
|
filePath
|
|
@@ -16858,13 +16858,13 @@ async function savePrompt(promptsDir, data, overwrite = false) {
|
|
|
16858
16858
|
async function deletePrompt(promptsDir, name) {
|
|
16859
16859
|
try {
|
|
16860
16860
|
const filePath = getPromptFilePath(promptsDir, name);
|
|
16861
|
-
if (!
|
|
16861
|
+
if (!fs9__default.existsSync(filePath)) {
|
|
16862
16862
|
return {
|
|
16863
16863
|
success: false,
|
|
16864
16864
|
error: `Prompt file not found: ${filePath}`
|
|
16865
16865
|
};
|
|
16866
16866
|
}
|
|
16867
|
-
await
|
|
16867
|
+
await fs9__default.promises.unlink(filePath);
|
|
16868
16868
|
return {
|
|
16869
16869
|
success: true,
|
|
16870
16870
|
filePath
|
|
@@ -16880,25 +16880,25 @@ async function renamePrompt(promptsDir, oldName, newName) {
|
|
|
16880
16880
|
try {
|
|
16881
16881
|
const oldFilePath = getPromptFilePath(promptsDir, oldName);
|
|
16882
16882
|
const newFilePath = getPromptFilePath(promptsDir, newName);
|
|
16883
|
-
if (!
|
|
16883
|
+
if (!fs9__default.existsSync(oldFilePath)) {
|
|
16884
16884
|
return {
|
|
16885
16885
|
success: false,
|
|
16886
16886
|
error: `Prompt file not found: ${oldFilePath}`
|
|
16887
16887
|
};
|
|
16888
16888
|
}
|
|
16889
|
-
if (
|
|
16889
|
+
if (fs9__default.existsSync(newFilePath)) {
|
|
16890
16890
|
return {
|
|
16891
16891
|
success: false,
|
|
16892
16892
|
error: `Prompt file already exists: ${newFilePath}`
|
|
16893
16893
|
};
|
|
16894
16894
|
}
|
|
16895
|
-
const content = await
|
|
16895
|
+
const content = await fs9__default.promises.readFile(oldFilePath, "utf-8");
|
|
16896
16896
|
const updatedContent = content.replace(
|
|
16897
16897
|
/name:\s*['"]([^'"]+)['"]/,
|
|
16898
16898
|
`name: '${newName}'`
|
|
16899
16899
|
);
|
|
16900
|
-
await
|
|
16901
|
-
await
|
|
16900
|
+
await fs9__default.promises.writeFile(newFilePath, updatedContent, "utf-8");
|
|
16901
|
+
await fs9__default.promises.unlink(oldFilePath);
|
|
16902
16902
|
return {
|
|
16903
16903
|
success: true,
|
|
16904
16904
|
filePath: newFilePath
|
|
@@ -17198,15 +17198,15 @@ function transformAgentData(data) {
|
|
|
17198
17198
|
}
|
|
17199
17199
|
function getAgentFilePath(agentsDir, name) {
|
|
17200
17200
|
const filename = nameToFilename(name);
|
|
17201
|
-
return
|
|
17201
|
+
return path9__default.join(agentsDir, `${filename}.ts`);
|
|
17202
17202
|
}
|
|
17203
17203
|
function agentExists(agentsDir, name) {
|
|
17204
17204
|
const filePath = getAgentFilePath(agentsDir, name);
|
|
17205
|
-
return
|
|
17205
|
+
return fs9__default.existsSync(filePath);
|
|
17206
17206
|
}
|
|
17207
17207
|
function extractAgentMetadata(filePath) {
|
|
17208
17208
|
try {
|
|
17209
|
-
const content =
|
|
17209
|
+
const content = fs9__default.readFileSync(filePath, "utf-8");
|
|
17210
17210
|
const metadata = {};
|
|
17211
17211
|
const packageNameMatch = content.match(/packageName:\s*['"]([^'"]+)['"]/);
|
|
17212
17212
|
if (packageNameMatch) metadata.packageName = packageNameMatch[1];
|
|
@@ -17223,17 +17223,17 @@ function extractAgentMetadata(filePath) {
|
|
|
17223
17223
|
}
|
|
17224
17224
|
async function saveAgent(agentsDir, data, overwrite = false) {
|
|
17225
17225
|
try {
|
|
17226
|
-
if (!
|
|
17227
|
-
|
|
17226
|
+
if (!fs9__default.existsSync(agentsDir)) {
|
|
17227
|
+
fs9__default.mkdirSync(agentsDir, { recursive: true });
|
|
17228
17228
|
}
|
|
17229
17229
|
const filePath = getAgentFilePath(agentsDir, data.name);
|
|
17230
|
-
if (!overwrite &&
|
|
17230
|
+
if (!overwrite && fs9__default.existsSync(filePath)) {
|
|
17231
17231
|
return {
|
|
17232
17232
|
success: false,
|
|
17233
17233
|
error: `Agent file already exists: ${filePath}. Use update to modify existing agents.`
|
|
17234
17234
|
};
|
|
17235
17235
|
}
|
|
17236
|
-
if (overwrite &&
|
|
17236
|
+
if (overwrite && fs9__default.existsSync(filePath)) {
|
|
17237
17237
|
const existingMetadata = extractAgentMetadata(filePath);
|
|
17238
17238
|
if (existingMetadata.packageName && !data.packageName) {
|
|
17239
17239
|
data.packageName = existingMetadata.packageName;
|
|
@@ -17249,7 +17249,7 @@ async function saveAgent(agentsDir, data, overwrite = false) {
|
|
|
17249
17249
|
}
|
|
17250
17250
|
}
|
|
17251
17251
|
const content = generateAgentFile(data);
|
|
17252
|
-
await
|
|
17252
|
+
await fs9__default.promises.writeFile(filePath, content, "utf-8");
|
|
17253
17253
|
return {
|
|
17254
17254
|
success: true,
|
|
17255
17255
|
filePath
|
|
@@ -17264,13 +17264,13 @@ async function saveAgent(agentsDir, data, overwrite = false) {
|
|
|
17264
17264
|
async function deleteAgent(agentsDir, name) {
|
|
17265
17265
|
try {
|
|
17266
17266
|
const filePath = getAgentFilePath(agentsDir, name);
|
|
17267
|
-
if (!
|
|
17267
|
+
if (!fs9__default.existsSync(filePath)) {
|
|
17268
17268
|
return {
|
|
17269
17269
|
success: false,
|
|
17270
17270
|
error: `Agent file not found: ${filePath}`
|
|
17271
17271
|
};
|
|
17272
17272
|
}
|
|
17273
|
-
await
|
|
17273
|
+
await fs9__default.promises.unlink(filePath);
|
|
17274
17274
|
return {
|
|
17275
17275
|
success: true,
|
|
17276
17276
|
filePath
|
|
@@ -17286,25 +17286,25 @@ async function renameModel(modelsDir, oldName, newName) {
|
|
|
17286
17286
|
try {
|
|
17287
17287
|
const oldFilePath = getModelFilePath(modelsDir, oldName);
|
|
17288
17288
|
const newFilePath = getModelFilePath(modelsDir, newName);
|
|
17289
|
-
if (!
|
|
17289
|
+
if (!fs9__default.existsSync(oldFilePath)) {
|
|
17290
17290
|
return {
|
|
17291
17291
|
success: false,
|
|
17292
17292
|
error: `Model file not found: ${oldFilePath}`
|
|
17293
17293
|
};
|
|
17294
17294
|
}
|
|
17295
|
-
if (
|
|
17295
|
+
if (fs9__default.existsSync(newFilePath)) {
|
|
17296
17296
|
return {
|
|
17297
17297
|
success: false,
|
|
17298
17298
|
error: `Model file already exists: ${newFilePath}`
|
|
17299
17299
|
};
|
|
17300
17300
|
}
|
|
17301
|
-
const content = await
|
|
17301
|
+
const content = await fs9__default.promises.readFile(oldFilePath, "utf-8");
|
|
17302
17302
|
const updatedContent = content.replace(
|
|
17303
17303
|
/name:\s*['"]([^'"]+)['"]/,
|
|
17304
17304
|
`name: '${newName}'`
|
|
17305
17305
|
);
|
|
17306
|
-
await
|
|
17307
|
-
await
|
|
17306
|
+
await fs9__default.promises.writeFile(newFilePath, updatedContent, "utf-8");
|
|
17307
|
+
await fs9__default.promises.unlink(oldFilePath);
|
|
17308
17308
|
return {
|
|
17309
17309
|
success: true,
|
|
17310
17310
|
filePath: newFilePath
|
|
@@ -17318,17 +17318,17 @@ async function renameModel(modelsDir, oldName, newName) {
|
|
|
17318
17318
|
}
|
|
17319
17319
|
async function updateModelReferencesInPrompts(promptsDir, oldModelName, newModelName) {
|
|
17320
17320
|
const updatedFiles = [];
|
|
17321
|
-
if (!
|
|
17321
|
+
if (!fs9__default.existsSync(promptsDir)) {
|
|
17322
17322
|
return updatedFiles;
|
|
17323
17323
|
}
|
|
17324
|
-
const files =
|
|
17324
|
+
const files = fs9__default.readdirSync(promptsDir).filter((f) => f.endsWith(".ts"));
|
|
17325
17325
|
for (const file of files) {
|
|
17326
|
-
const filePath =
|
|
17327
|
-
let content = await
|
|
17326
|
+
const filePath = path9__default.join(promptsDir, file);
|
|
17327
|
+
let content = await fs9__default.promises.readFile(filePath, "utf-8");
|
|
17328
17328
|
const modelRegex = new RegExp(`model:\\s*['"]${escapeRegExp(oldModelName)}['"]`, "g");
|
|
17329
17329
|
if (modelRegex.test(content)) {
|
|
17330
17330
|
content = content.replace(modelRegex, `model: '${newModelName}'`);
|
|
17331
|
-
await
|
|
17331
|
+
await fs9__default.promises.writeFile(filePath, content, "utf-8");
|
|
17332
17332
|
updatedFiles.push(filePath);
|
|
17333
17333
|
}
|
|
17334
17334
|
}
|
|
@@ -17336,13 +17336,13 @@ async function updateModelReferencesInPrompts(promptsDir, oldModelName, newModel
|
|
|
17336
17336
|
}
|
|
17337
17337
|
async function updatePromptReferencesInPrompts(promptsDir, oldPromptName, newPromptName) {
|
|
17338
17338
|
const updatedFiles = [];
|
|
17339
|
-
if (!
|
|
17339
|
+
if (!fs9__default.existsSync(promptsDir)) {
|
|
17340
17340
|
return updatedFiles;
|
|
17341
17341
|
}
|
|
17342
|
-
const files =
|
|
17342
|
+
const files = fs9__default.readdirSync(promptsDir).filter((f) => f.endsWith(".ts"));
|
|
17343
17343
|
for (const file of files) {
|
|
17344
|
-
const filePath =
|
|
17345
|
-
let content = await
|
|
17344
|
+
const filePath = path9__default.join(promptsDir, file);
|
|
17345
|
+
let content = await fs9__default.promises.readFile(filePath, "utf-8");
|
|
17346
17346
|
let modified = false;
|
|
17347
17347
|
const toolsArrayRegex = /tools:\s*\[([^\]]*)\]/gs;
|
|
17348
17348
|
const newContent = content.replace(toolsArrayRegex, (match) => {
|
|
@@ -17355,7 +17355,7 @@ async function updatePromptReferencesInPrompts(promptsDir, oldPromptName, newPro
|
|
|
17355
17355
|
return replaced;
|
|
17356
17356
|
});
|
|
17357
17357
|
if (modified) {
|
|
17358
|
-
await
|
|
17358
|
+
await fs9__default.promises.writeFile(filePath, newContent, "utf-8");
|
|
17359
17359
|
updatedFiles.push(filePath);
|
|
17360
17360
|
}
|
|
17361
17361
|
}
|
|
@@ -17363,17 +17363,17 @@ async function updatePromptReferencesInPrompts(promptsDir, oldPromptName, newPro
|
|
|
17363
17363
|
}
|
|
17364
17364
|
async function updatePromptReferencesInAgents(agentsDir, oldPromptName, newPromptName) {
|
|
17365
17365
|
const updatedFiles = [];
|
|
17366
|
-
if (!
|
|
17366
|
+
if (!fs9__default.existsSync(agentsDir)) {
|
|
17367
17367
|
return updatedFiles;
|
|
17368
17368
|
}
|
|
17369
|
-
const files =
|
|
17369
|
+
const files = fs9__default.readdirSync(agentsDir).filter((f) => f.endsWith(".ts"));
|
|
17370
17370
|
for (const file of files) {
|
|
17371
|
-
const filePath =
|
|
17372
|
-
let content = await
|
|
17371
|
+
const filePath = path9__default.join(agentsDir, file);
|
|
17372
|
+
let content = await fs9__default.promises.readFile(filePath, "utf-8");
|
|
17373
17373
|
const promptRegex = new RegExp(`prompt:\\s*['"]${escapeRegExp(oldPromptName)}['"]`, "g");
|
|
17374
17374
|
if (promptRegex.test(content)) {
|
|
17375
17375
|
content = content.replace(promptRegex, `prompt: '${newPromptName}'`);
|
|
17376
|
-
await
|
|
17376
|
+
await fs9__default.promises.writeFile(filePath, content, "utf-8");
|
|
17377
17377
|
updatedFiles.push(filePath);
|
|
17378
17378
|
}
|
|
17379
17379
|
}
|
|
@@ -17500,16 +17500,16 @@ function parseThreadEndpointRouteKey(input) {
|
|
|
17500
17500
|
};
|
|
17501
17501
|
}
|
|
17502
17502
|
function scanThreadEndpointFiles(dir, options = {}) {
|
|
17503
|
-
if (!
|
|
17503
|
+
if (!fs9__default.existsSync(dir)) {
|
|
17504
17504
|
return [];
|
|
17505
17505
|
}
|
|
17506
17506
|
const extensions = options.extensions ?? [".ts"];
|
|
17507
17507
|
const routes = [];
|
|
17508
17508
|
const scan = (currentDir, relativeDir = "") => {
|
|
17509
|
-
const entries =
|
|
17509
|
+
const entries = fs9__default.readdirSync(currentDir, { withFileTypes: true });
|
|
17510
17510
|
for (const entry of entries) {
|
|
17511
|
-
const filePath =
|
|
17512
|
-
const relativePath = relativeDir ?
|
|
17511
|
+
const filePath = path9__default.join(currentDir, entry.name);
|
|
17512
|
+
const relativePath = relativeDir ? path9__default.posix.join(relativeDir, entry.name) : entry.name;
|
|
17513
17513
|
if (entry.isDirectory()) {
|
|
17514
17514
|
scan(filePath, relativePath);
|
|
17515
17515
|
continue;
|
|
@@ -17543,7 +17543,7 @@ function scanApiDirectory(dir) {
|
|
|
17543
17543
|
try {
|
|
17544
17544
|
return scanThreadEndpointFiles(dir, {
|
|
17545
17545
|
extensions: [".ts"],
|
|
17546
|
-
importPathForFile: (filePath) => "./" +
|
|
17546
|
+
importPathForFile: (filePath) => "./" + path9__default.relative(process.cwd(), filePath).replace(/\\/g, "/")
|
|
17547
17547
|
}).map(({ method, route, importPath }) => ({
|
|
17548
17548
|
method,
|
|
17549
17549
|
route,
|
|
@@ -17555,26 +17555,26 @@ function scanApiDirectory(dir) {
|
|
|
17555
17555
|
}
|
|
17556
17556
|
}
|
|
17557
17557
|
function discoverPackedPackageDirectories(packedDir) {
|
|
17558
|
-
if (!
|
|
17558
|
+
if (!fs9__default.existsSync(packedDir)) {
|
|
17559
17559
|
return [];
|
|
17560
17560
|
}
|
|
17561
17561
|
const packageDirs = [];
|
|
17562
|
-
const entries =
|
|
17562
|
+
const entries = fs9__default.readdirSync(packedDir, { withFileTypes: true }).filter((entry) => entry.isDirectory());
|
|
17563
17563
|
for (const entry of entries) {
|
|
17564
|
-
const fullPath =
|
|
17565
|
-
const packageJsonPath =
|
|
17566
|
-
if (
|
|
17564
|
+
const fullPath = path9__default.join(packedDir, entry.name);
|
|
17565
|
+
const packageJsonPath = path9__default.join(fullPath, "package.json");
|
|
17566
|
+
if (fs9__default.existsSync(packageJsonPath)) {
|
|
17567
17567
|
packageDirs.push(fullPath);
|
|
17568
17568
|
continue;
|
|
17569
17569
|
}
|
|
17570
17570
|
if (!entry.name.startsWith("@")) {
|
|
17571
17571
|
continue;
|
|
17572
17572
|
}
|
|
17573
|
-
const scopedEntries =
|
|
17573
|
+
const scopedEntries = fs9__default.readdirSync(fullPath, { withFileTypes: true }).filter((scopedEntry) => scopedEntry.isDirectory());
|
|
17574
17574
|
for (const scopedEntry of scopedEntries) {
|
|
17575
|
-
const scopedPackagePath =
|
|
17576
|
-
const scopedPackageJson =
|
|
17577
|
-
if (
|
|
17575
|
+
const scopedPackagePath = path9__default.join(fullPath, scopedEntry.name);
|
|
17576
|
+
const scopedPackageJson = path9__default.join(scopedPackagePath, "package.json");
|
|
17577
|
+
if (fs9__default.existsSync(scopedPackageJson)) {
|
|
17578
17578
|
packageDirs.push(scopedPackagePath);
|
|
17579
17579
|
}
|
|
17580
17580
|
}
|
|
@@ -17582,26 +17582,26 @@ function discoverPackedPackageDirectories(packedDir) {
|
|
|
17582
17582
|
return packageDirs;
|
|
17583
17583
|
}
|
|
17584
17584
|
function scanPackedDistDirectory(packagePath, outputDir, subDir) {
|
|
17585
|
-
const fullPath =
|
|
17586
|
-
if (!
|
|
17585
|
+
const fullPath = path9__default.join(packagePath, outputDir, subDir);
|
|
17586
|
+
if (!fs9__default.existsSync(fullPath)) {
|
|
17587
17587
|
return [];
|
|
17588
17588
|
}
|
|
17589
|
-
return
|
|
17589
|
+
return fs9__default.readdirSync(fullPath).filter((fileName) => fileName.endsWith(".js") || fileName.endsWith(".ts")).map((fileName) => ({
|
|
17590
17590
|
name: fileName.replace(/\.(js|ts)$/, ""),
|
|
17591
|
-
path:
|
|
17591
|
+
path: path9__default.join(fullPath, fileName).replace(/\\/g, "/")
|
|
17592
17592
|
}));
|
|
17593
17593
|
}
|
|
17594
17594
|
function scanPackedThreadEndpoints(packagePath, outputDir) {
|
|
17595
|
-
const rootDir =
|
|
17596
|
-
if (!
|
|
17595
|
+
const rootDir = path9__default.join(packagePath, outputDir, "thread-endpoints");
|
|
17596
|
+
if (!fs9__default.existsSync(rootDir)) {
|
|
17597
17597
|
return [];
|
|
17598
17598
|
}
|
|
17599
17599
|
const endpoints = [];
|
|
17600
17600
|
const scan = (dir, relativeDir = "") => {
|
|
17601
|
-
const entries =
|
|
17601
|
+
const entries = fs9__default.readdirSync(dir, { withFileTypes: true });
|
|
17602
17602
|
for (const entry of entries) {
|
|
17603
|
-
const nextRelative = relativeDir ?
|
|
17604
|
-
const absolutePath =
|
|
17603
|
+
const nextRelative = relativeDir ? path9__default.posix.join(relativeDir, entry.name) : entry.name;
|
|
17604
|
+
const absolutePath = path9__default.join(dir, entry.name);
|
|
17605
17605
|
if (entry.isDirectory()) {
|
|
17606
17606
|
scan(absolutePath, nextRelative);
|
|
17607
17607
|
continue;
|
|
@@ -17631,7 +17631,7 @@ function isSnakeCase(str) {
|
|
|
17631
17631
|
}
|
|
17632
17632
|
function validateToolFile(filePath, fileName) {
|
|
17633
17633
|
try {
|
|
17634
|
-
const content =
|
|
17634
|
+
const content = fs9__default.readFileSync(filePath, "utf-8");
|
|
17635
17635
|
const hasDefaultExport = /export\s+default\s+defineTool/.test(content);
|
|
17636
17636
|
if (!hasDefaultExport) {
|
|
17637
17637
|
return `Tool file '${fileName}.ts' must have a default export using defineTool()`;
|
|
@@ -17643,15 +17643,15 @@ function validateToolFile(filePath, fileName) {
|
|
|
17643
17643
|
}
|
|
17644
17644
|
async function scanToolsDirectory(dir) {
|
|
17645
17645
|
const tools = [];
|
|
17646
|
-
if (!
|
|
17646
|
+
if (!fs9__default.existsSync(dir)) {
|
|
17647
17647
|
return tools;
|
|
17648
17648
|
}
|
|
17649
|
-
const entries = await
|
|
17649
|
+
const entries = await fs9__default.promises.readdir(dir, { withFileTypes: true });
|
|
17650
17650
|
for (const entry of entries) {
|
|
17651
17651
|
if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
17652
17652
|
const fileName = entry.name.replace(".ts", "");
|
|
17653
|
-
const filePath =
|
|
17654
|
-
const importPath = "./" +
|
|
17653
|
+
const filePath = path9__default.join(dir, entry.name);
|
|
17654
|
+
const importPath = "./" + path9__default.relative(process.cwd(), filePath).replace(/\\/g, "/");
|
|
17655
17655
|
let toolError;
|
|
17656
17656
|
const validationError = validateToolFile(filePath, fileName);
|
|
17657
17657
|
if (validationError) {
|
|
@@ -17678,18 +17678,18 @@ async function scanToolsDirectory(dir) {
|
|
|
17678
17678
|
}
|
|
17679
17679
|
async function scanHooksDirectory(dir) {
|
|
17680
17680
|
const hooks = [];
|
|
17681
|
-
if (!
|
|
17681
|
+
if (!fs9__default.existsSync(dir)) {
|
|
17682
17682
|
return hooks;
|
|
17683
17683
|
}
|
|
17684
|
-
const entries = await
|
|
17684
|
+
const entries = await fs9__default.promises.readdir(dir, { withFileTypes: true });
|
|
17685
17685
|
for (const entry of entries) {
|
|
17686
17686
|
if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
17687
17687
|
const fileName = entry.name.replace(".ts", "");
|
|
17688
17688
|
if (fileName === "index") continue;
|
|
17689
|
-
const filePath =
|
|
17690
|
-
const importPath = "./" +
|
|
17689
|
+
const filePath = path9__default.join(dir, entry.name);
|
|
17690
|
+
const importPath = "./" + path9__default.relative(process.cwd(), filePath).replace(/\\/g, "/");
|
|
17691
17691
|
try {
|
|
17692
|
-
const content =
|
|
17692
|
+
const content = fs9__default.readFileSync(filePath, "utf-8");
|
|
17693
17693
|
const idMatch = content.match(/id:\s*['"]([^'"]+)['"]/);
|
|
17694
17694
|
const hookMatch = content.match(/hook:\s*['"]([^'"]+)['"]/);
|
|
17695
17695
|
if (idMatch && hookMatch) {
|
|
@@ -17712,16 +17712,16 @@ async function scanHooksDirectory(dir) {
|
|
|
17712
17712
|
}
|
|
17713
17713
|
async function scanConfigDirectory(dir, definePattern) {
|
|
17714
17714
|
const items = [];
|
|
17715
|
-
if (!
|
|
17715
|
+
if (!fs9__default.existsSync(dir)) {
|
|
17716
17716
|
return items;
|
|
17717
17717
|
}
|
|
17718
|
-
const entries = await
|
|
17718
|
+
const entries = await fs9__default.promises.readdir(dir, { withFileTypes: true });
|
|
17719
17719
|
for (const entry of entries) {
|
|
17720
17720
|
if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
17721
|
-
const filePath =
|
|
17722
|
-
const importPath = "./" +
|
|
17721
|
+
const filePath = path9__default.join(dir, entry.name);
|
|
17722
|
+
const importPath = "./" + path9__default.relative(process.cwd(), filePath).replace(/\\/g, "/");
|
|
17723
17723
|
try {
|
|
17724
|
-
const content =
|
|
17724
|
+
const content = fs9__default.readFileSync(filePath, "utf-8");
|
|
17725
17725
|
const hasDefaultExport = definePattern.test(content);
|
|
17726
17726
|
if (!hasDefaultExport) {
|
|
17727
17727
|
items.push({
|
|
@@ -17766,20 +17766,20 @@ async function scanAgentsDirectory(dir) {
|
|
|
17766
17766
|
}
|
|
17767
17767
|
async function scanEffectsDirectory(dir) {
|
|
17768
17768
|
const effects = [];
|
|
17769
|
-
if (!
|
|
17769
|
+
if (!fs9__default.existsSync(dir)) {
|
|
17770
17770
|
return effects;
|
|
17771
17771
|
}
|
|
17772
|
-
const entries = await
|
|
17772
|
+
const entries = await fs9__default.promises.readdir(dir, { withFileTypes: true });
|
|
17773
17773
|
for (const entry of entries) {
|
|
17774
17774
|
if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
17775
17775
|
const fileName = entry.name.replace(".ts", "");
|
|
17776
|
-
const filePath =
|
|
17777
|
-
const importPath = "./" +
|
|
17776
|
+
const filePath = path9__default.join(dir, entry.name);
|
|
17777
|
+
const importPath = "./" + path9__default.relative(process.cwd(), filePath).replace(/\\/g, "/");
|
|
17778
17778
|
if (fileName === "CLAUDE" || fileName.startsWith("_")) {
|
|
17779
17779
|
continue;
|
|
17780
17780
|
}
|
|
17781
17781
|
try {
|
|
17782
|
-
const content =
|
|
17782
|
+
const content = fs9__default.readFileSync(filePath, "utf-8");
|
|
17783
17783
|
if (!content.includes("defineEffect")) {
|
|
17784
17784
|
continue;
|
|
17785
17785
|
}
|
|
@@ -17792,14 +17792,14 @@ async function scanEffectsDirectory(dir) {
|
|
|
17792
17792
|
return effects;
|
|
17793
17793
|
}
|
|
17794
17794
|
function parseRequestBody(req) {
|
|
17795
|
-
return new Promise((
|
|
17795
|
+
return new Promise((resolve3, reject) => {
|
|
17796
17796
|
let body = "";
|
|
17797
17797
|
req.on("data", (chunk) => {
|
|
17798
17798
|
body += chunk.toString();
|
|
17799
17799
|
});
|
|
17800
17800
|
req.on("end", () => {
|
|
17801
17801
|
try {
|
|
17802
|
-
|
|
17802
|
+
resolve3(body ? JSON.parse(body) : {});
|
|
17803
17803
|
} catch {
|
|
17804
17804
|
reject(new Error("Invalid JSON body"));
|
|
17805
17805
|
}
|
|
@@ -17809,17 +17809,17 @@ function parseRequestBody(req) {
|
|
|
17809
17809
|
}
|
|
17810
17810
|
function scanUsersDirectory(dir) {
|
|
17811
17811
|
const results = [];
|
|
17812
|
-
if (!
|
|
17812
|
+
if (!fs9__default.existsSync(dir)) return results;
|
|
17813
17813
|
const walk = (current, prefix) => {
|
|
17814
17814
|
let entries;
|
|
17815
17815
|
try {
|
|
17816
|
-
entries =
|
|
17816
|
+
entries = fs9__default.readdirSync(current, { withFileTypes: true });
|
|
17817
17817
|
} catch (error) {
|
|
17818
17818
|
console.error(`Error scanning users directory ${current}:`, error);
|
|
17819
17819
|
return;
|
|
17820
17820
|
}
|
|
17821
17821
|
for (const entry of entries) {
|
|
17822
|
-
const fullPath =
|
|
17822
|
+
const fullPath = path9__default.join(current, entry.name);
|
|
17823
17823
|
if (entry.isDirectory()) {
|
|
17824
17824
|
walk(fullPath, prefix ? `${prefix}/${entry.name}` : entry.name);
|
|
17825
17825
|
continue;
|
|
@@ -17829,7 +17829,7 @@ function scanUsersDirectory(dir) {
|
|
|
17829
17829
|
const key = prefix ? `${prefix}/${base}` : base;
|
|
17830
17830
|
results.push({
|
|
17831
17831
|
key,
|
|
17832
|
-
importPath: "./" +
|
|
17832
|
+
importPath: "./" + path9__default.relative(process.cwd(), fullPath).replace(/\\/g, "/")
|
|
17833
17833
|
});
|
|
17834
17834
|
}
|
|
17835
17835
|
};
|
|
@@ -18062,7 +18062,7 @@ async function handleModelApiRequest(context) {
|
|
|
18062
18062
|
}
|
|
18063
18063
|
await hmr.reloadRouterModule(server);
|
|
18064
18064
|
await hmr.reloadBuilderModule(server);
|
|
18065
|
-
await new Promise((
|
|
18065
|
+
await new Promise((resolve3) => setTimeout(resolve3, 100));
|
|
18066
18066
|
res.statusCode = 200;
|
|
18067
18067
|
res.setHeader("Content-Type", "application/json");
|
|
18068
18068
|
res.end(JSON.stringify({
|
|
@@ -18289,6 +18289,49 @@ async function handleConfigApiRequest(context) {
|
|
|
18289
18289
|
if (await handleAgentApiRequest(context)) return true;
|
|
18290
18290
|
return false;
|
|
18291
18291
|
}
|
|
18292
|
+
|
|
18293
|
+
// src/packing/package-identifier.ts
|
|
18294
|
+
function assertSafePackageIdentifier(identifier) {
|
|
18295
|
+
const value = identifier.trim();
|
|
18296
|
+
if (!value || value.includes("\\") || value.includes("\0") || value.startsWith("/")) {
|
|
18297
|
+
throw new Error("Invalid package identifier");
|
|
18298
|
+
}
|
|
18299
|
+
const parts = value.split("/");
|
|
18300
|
+
const scoped = parts.length === 2 && parts[0].startsWith("@");
|
|
18301
|
+
if (parts.length > 1 && !scoped) throw new Error("Invalid package identifier");
|
|
18302
|
+
if (parts.some((part) => !part || part === "." || part === ".." || !/^@?[a-zA-Z0-9._-]+$/.test(part))) {
|
|
18303
|
+
throw new Error("Invalid package identifier");
|
|
18304
|
+
}
|
|
18305
|
+
return value;
|
|
18306
|
+
}
|
|
18307
|
+
|
|
18308
|
+
// src/packing/path-safety.ts
|
|
18309
|
+
function isWithin(base, candidate) {
|
|
18310
|
+
const relative4 = path9.relative(base, candidate);
|
|
18311
|
+
return relative4 === "" || !relative4.startsWith(`..${path9.sep}`) && relative4 !== ".." && !path9.isAbsolute(relative4);
|
|
18312
|
+
}
|
|
18313
|
+
function resolvePathWithin(base, ...segments) {
|
|
18314
|
+
const resolvedBase = path9.resolve(base);
|
|
18315
|
+
const candidate = path9.resolve(resolvedBase, ...segments);
|
|
18316
|
+
if (!isWithin(resolvedBase, candidate)) {
|
|
18317
|
+
throw new Error("Path must remain inside the configured AgentBuilder directory");
|
|
18318
|
+
}
|
|
18319
|
+
if (fs9.existsSync(resolvedBase)) {
|
|
18320
|
+
const realBase = fs9.realpathSync(resolvedBase);
|
|
18321
|
+
if (typeof realBase !== "string") return candidate;
|
|
18322
|
+
let existing = candidate;
|
|
18323
|
+
while (!fs9.existsSync(existing) && existing !== resolvedBase) {
|
|
18324
|
+
existing = path9.dirname(existing);
|
|
18325
|
+
}
|
|
18326
|
+
if (fs9.existsSync(existing)) {
|
|
18327
|
+
const realExisting = fs9.realpathSync(existing);
|
|
18328
|
+
if (typeof realExisting === "string" && !isWithin(realBase, realExisting)) {
|
|
18329
|
+
throw new Error("Path traverses a symlink outside the configured AgentBuilder directory");
|
|
18330
|
+
}
|
|
18331
|
+
}
|
|
18332
|
+
}
|
|
18333
|
+
return candidate;
|
|
18334
|
+
}
|
|
18292
18335
|
var MetadataService = class {
|
|
18293
18336
|
metadataDir;
|
|
18294
18337
|
/**
|
|
@@ -18297,7 +18340,7 @@ var MetadataService = class {
|
|
|
18297
18340
|
* @param agentsDir - Path to the agents/ directory
|
|
18298
18341
|
*/
|
|
18299
18342
|
constructor(agentsDir) {
|
|
18300
|
-
this.metadataDir =
|
|
18343
|
+
this.metadataDir = path9.join(agentsDir, ".standardagent");
|
|
18301
18344
|
}
|
|
18302
18345
|
/**
|
|
18303
18346
|
* Read metadata for an agent.
|
|
@@ -18307,11 +18350,11 @@ var MetadataService = class {
|
|
|
18307
18350
|
*/
|
|
18308
18351
|
async read(agentName) {
|
|
18309
18352
|
const filePath = this.getMetadataPath(agentName);
|
|
18310
|
-
if (!
|
|
18353
|
+
if (!fs9.existsSync(filePath)) {
|
|
18311
18354
|
return null;
|
|
18312
18355
|
}
|
|
18313
18356
|
try {
|
|
18314
|
-
const content =
|
|
18357
|
+
const content = fs9.readFileSync(filePath, "utf-8");
|
|
18315
18358
|
return JSON.parse(content);
|
|
18316
18359
|
} catch {
|
|
18317
18360
|
return null;
|
|
@@ -18324,11 +18367,11 @@ var MetadataService = class {
|
|
|
18324
18367
|
* @param metadata - Metadata to write
|
|
18325
18368
|
*/
|
|
18326
18369
|
async write(agentName, metadata) {
|
|
18327
|
-
if (!
|
|
18328
|
-
|
|
18370
|
+
if (!fs9.existsSync(this.metadataDir)) {
|
|
18371
|
+
fs9.mkdirSync(this.metadataDir, { recursive: true });
|
|
18329
18372
|
}
|
|
18330
18373
|
const filePath = this.getMetadataPath(agentName);
|
|
18331
|
-
|
|
18374
|
+
fs9.writeFileSync(filePath, JSON.stringify(metadata, null, 2));
|
|
18332
18375
|
}
|
|
18333
18376
|
/**
|
|
18334
18377
|
* Delete metadata for an agent.
|
|
@@ -18337,8 +18380,8 @@ var MetadataService = class {
|
|
|
18337
18380
|
*/
|
|
18338
18381
|
async delete(agentName) {
|
|
18339
18382
|
const filePath = this.getMetadataPath(agentName);
|
|
18340
|
-
if (
|
|
18341
|
-
|
|
18383
|
+
if (fs9.existsSync(filePath)) {
|
|
18384
|
+
fs9.unlinkSync(filePath);
|
|
18342
18385
|
}
|
|
18343
18386
|
}
|
|
18344
18387
|
/**
|
|
@@ -18419,7 +18462,7 @@ var MetadataService = class {
|
|
|
18419
18462
|
* Get the file path for an agent's metadata.
|
|
18420
18463
|
*/
|
|
18421
18464
|
getMetadataPath(agentName) {
|
|
18422
|
-
return
|
|
18465
|
+
return path9.join(this.metadataDir, `${agentName}.json`);
|
|
18423
18466
|
}
|
|
18424
18467
|
};
|
|
18425
18468
|
var _ts;
|
|
@@ -18791,9 +18834,9 @@ var PackingService = class {
|
|
|
18791
18834
|
* @returns Version specifier (e.g., '^1.2.3') or '*' if not found
|
|
18792
18835
|
*/
|
|
18793
18836
|
resolvePackageVersion(pkgName, rootDir) {
|
|
18794
|
-
const pkgJsonPath =
|
|
18837
|
+
const pkgJsonPath = path9.join(rootDir, "node_modules", pkgName, "package.json");
|
|
18795
18838
|
try {
|
|
18796
|
-
const pkgJson = JSON.parse(
|
|
18839
|
+
const pkgJson = JSON.parse(fs9.readFileSync(pkgJsonPath, "utf-8"));
|
|
18797
18840
|
return `^${pkgJson.version}`;
|
|
18798
18841
|
} catch {
|
|
18799
18842
|
return "*";
|
|
@@ -18810,7 +18853,7 @@ var PackingService = class {
|
|
|
18810
18853
|
* @returns Analysis result with all discovered constituents
|
|
18811
18854
|
*/
|
|
18812
18855
|
async analyzeAgent(agentName, rootDir) {
|
|
18813
|
-
const agentsDir =
|
|
18856
|
+
const agentsDir = path9.join(rootDir, "agents");
|
|
18814
18857
|
const analysis = {
|
|
18815
18858
|
agent: agentName,
|
|
18816
18859
|
primaryPrompt: "",
|
|
@@ -18834,7 +18877,7 @@ var PackingService = class {
|
|
|
18834
18877
|
warnings: [],
|
|
18835
18878
|
errors: []
|
|
18836
18879
|
};
|
|
18837
|
-
const agentFilePath = await this.findFile(
|
|
18880
|
+
const agentFilePath = await this.findFile(path9.join(agentsDir, "agents"), agentName);
|
|
18838
18881
|
if (!agentFilePath) {
|
|
18839
18882
|
analysis.errors.push(`Agent file not found: ${agentName}`);
|
|
18840
18883
|
return analysis;
|
|
@@ -18845,7 +18888,7 @@ var PackingService = class {
|
|
|
18845
18888
|
discoveredVia: "static",
|
|
18846
18889
|
sharedWith: []
|
|
18847
18890
|
});
|
|
18848
|
-
const agentSource =
|
|
18891
|
+
const agentSource = fs9.readFileSync(agentFilePath, "utf-8");
|
|
18849
18892
|
const agentPrompts = await extractAgentPrompts(agentSource);
|
|
18850
18893
|
if (agentPrompts.sideA) {
|
|
18851
18894
|
analysis.primaryPrompt = agentPrompts.sideA;
|
|
@@ -18870,13 +18913,13 @@ var PackingService = class {
|
|
|
18870
18913
|
* @returns Object with generatedReadme and agentDescription
|
|
18871
18914
|
*/
|
|
18872
18915
|
async generateReadmeForAnalysis(analysis, rootDir) {
|
|
18873
|
-
const agentsDir =
|
|
18916
|
+
const agentsDir = path9.join(rootDir, "agents");
|
|
18874
18917
|
const metadataService = new MetadataService(agentsDir);
|
|
18875
18918
|
let agentDescription;
|
|
18876
18919
|
const agentItem = analysis.constituents.agents.find((a) => a.name === analysis.agent);
|
|
18877
18920
|
if (agentItem?.filePath) {
|
|
18878
18921
|
try {
|
|
18879
|
-
const agentSource =
|
|
18922
|
+
const agentSource = fs9.readFileSync(agentItem.filePath, "utf-8");
|
|
18880
18923
|
agentDescription = await extractAgentDescription(agentSource) || void 0;
|
|
18881
18924
|
} catch {
|
|
18882
18925
|
}
|
|
@@ -18900,7 +18943,7 @@ var PackingService = class {
|
|
|
18900
18943
|
* include all endpoint modules discovered under agents/api.
|
|
18901
18944
|
*/
|
|
18902
18945
|
async analyzeThreadEndpoints(agentsDir, analysis) {
|
|
18903
|
-
const apiDir =
|
|
18946
|
+
const apiDir = path9.join(agentsDir, "api");
|
|
18904
18947
|
const endpoints = this.scanThreadEndpointFiles(apiDir);
|
|
18905
18948
|
for (const endpoint of endpoints) {
|
|
18906
18949
|
if (analysis.constituents.threadEndpoints.some((item) => item.name === endpoint.name)) {
|
|
@@ -18922,15 +18965,15 @@ var PackingService = class {
|
|
|
18922
18965
|
* - `admin/users/[userId]/sync.post`
|
|
18923
18966
|
*/
|
|
18924
18967
|
scanThreadEndpointFiles(apiDir, relativeDir = "") {
|
|
18925
|
-
if (!
|
|
18968
|
+
if (!fs9.existsSync(apiDir)) {
|
|
18926
18969
|
return [];
|
|
18927
18970
|
}
|
|
18928
18971
|
const endpoints = [];
|
|
18929
|
-
const currentDir = relativeDir ?
|
|
18930
|
-
if (!
|
|
18972
|
+
const currentDir = relativeDir ? path9.join(apiDir, relativeDir) : apiDir;
|
|
18973
|
+
if (!fs9.existsSync(currentDir)) {
|
|
18931
18974
|
return endpoints;
|
|
18932
18975
|
}
|
|
18933
|
-
const entries =
|
|
18976
|
+
const entries = fs9.readdirSync(currentDir, { withFileTypes: true });
|
|
18934
18977
|
if (entries.length > 0 && typeof entries[0] === "string") {
|
|
18935
18978
|
return endpoints;
|
|
18936
18979
|
}
|
|
@@ -18938,8 +18981,8 @@ var PackingService = class {
|
|
|
18938
18981
|
const entryName = typeof entry === "string" ? entry : entry.name;
|
|
18939
18982
|
const isDirectory = typeof entry === "string" ? false : entry.isDirectory();
|
|
18940
18983
|
const isFile = typeof entry === "string" ? true : entry.isFile();
|
|
18941
|
-
const entryRelative = relativeDir ?
|
|
18942
|
-
const absolutePath =
|
|
18984
|
+
const entryRelative = relativeDir ? path9.posix.join(relativeDir.replace(/\\/g, "/"), entryName) : entryName;
|
|
18985
|
+
const absolutePath = path9.join(apiDir, entryRelative);
|
|
18943
18986
|
if (isDirectory) {
|
|
18944
18987
|
endpoints.push(...this.scanThreadEndpointFiles(apiDir, entryRelative));
|
|
18945
18988
|
continue;
|
|
@@ -18966,7 +19009,7 @@ var PackingService = class {
|
|
|
18966
19009
|
* include all effect modules discovered under agents/effects.
|
|
18967
19010
|
*/
|
|
18968
19011
|
async analyzeEffects(agentsDir, analysis) {
|
|
18969
|
-
const effectsDir =
|
|
19012
|
+
const effectsDir = path9.join(agentsDir, "effects");
|
|
18970
19013
|
const effects = this.scanEffectFiles(effectsDir);
|
|
18971
19014
|
for (const effect of effects) {
|
|
18972
19015
|
if (analysis.constituents.effects.some((item) => item.name === effect.name)) {
|
|
@@ -18988,15 +19031,15 @@ var PackingService = class {
|
|
|
18988
19031
|
* - `notifications/digest`
|
|
18989
19032
|
*/
|
|
18990
19033
|
scanEffectFiles(effectsDir, relativeDir = "") {
|
|
18991
|
-
if (!
|
|
19034
|
+
if (!fs9.existsSync(effectsDir)) {
|
|
18992
19035
|
return [];
|
|
18993
19036
|
}
|
|
18994
19037
|
const effects = [];
|
|
18995
|
-
const currentDir = relativeDir ?
|
|
18996
|
-
if (!
|
|
19038
|
+
const currentDir = relativeDir ? path9.join(effectsDir, relativeDir) : effectsDir;
|
|
19039
|
+
if (!fs9.existsSync(currentDir)) {
|
|
18997
19040
|
return effects;
|
|
18998
19041
|
}
|
|
18999
|
-
const entries =
|
|
19042
|
+
const entries = fs9.readdirSync(currentDir, { withFileTypes: true });
|
|
19000
19043
|
if (entries.length > 0 && typeof entries[0] === "string") {
|
|
19001
19044
|
return effects;
|
|
19002
19045
|
}
|
|
@@ -19004,8 +19047,8 @@ var PackingService = class {
|
|
|
19004
19047
|
const entryName = typeof entry === "string" ? entry : entry.name;
|
|
19005
19048
|
const isDirectory = typeof entry === "string" ? false : entry.isDirectory();
|
|
19006
19049
|
const isFile = typeof entry === "string" ? true : entry.isFile();
|
|
19007
|
-
const entryRelative = relativeDir ?
|
|
19008
|
-
const absolutePath =
|
|
19050
|
+
const entryRelative = relativeDir ? path9.posix.join(relativeDir.replace(/\\/g, "/"), entryName) : entryName;
|
|
19051
|
+
const absolutePath = path9.join(effectsDir, entryRelative);
|
|
19009
19052
|
if (isDirectory) {
|
|
19010
19053
|
effects.push(...this.scanEffectFiles(effectsDir, entryRelative));
|
|
19011
19054
|
continue;
|
|
@@ -19029,7 +19072,7 @@ var PackingService = class {
|
|
|
19029
19072
|
* Recursively analyze a prompt and its dependencies.
|
|
19030
19073
|
*/
|
|
19031
19074
|
async analyzePrompt(promptName, agentsDir, analysis, visited, parentKey) {
|
|
19032
|
-
const promptFilePath = await this.findFile(
|
|
19075
|
+
const promptFilePath = await this.findFile(path9.join(agentsDir, "prompts"), promptName);
|
|
19033
19076
|
if (!promptFilePath) {
|
|
19034
19077
|
analysis.warnings.push(`Prompt file not found: ${promptName}`);
|
|
19035
19078
|
return;
|
|
@@ -19048,7 +19091,7 @@ var PackingService = class {
|
|
|
19048
19091
|
return;
|
|
19049
19092
|
}
|
|
19050
19093
|
visited.add(`prompt:${promptName}`);
|
|
19051
|
-
const promptSource =
|
|
19094
|
+
const promptSource = fs9.readFileSync(promptFilePath, "utf-8");
|
|
19052
19095
|
const modelName = await extractPromptModel(promptSource);
|
|
19053
19096
|
if (modelName) {
|
|
19054
19097
|
await this.analyzeModel(modelName, agentsDir, analysis, visited, thisKey);
|
|
@@ -19074,17 +19117,17 @@ var PackingService = class {
|
|
|
19074
19117
|
*/
|
|
19075
19118
|
async analyzeTool(toolName, agentsDir, analysis, visited, discoveredVia, parentKey) {
|
|
19076
19119
|
const thisKey = `tool:${toolName}`;
|
|
19077
|
-
const promptFilePath = await this.findFile(
|
|
19120
|
+
const promptFilePath = await this.findFile(path9.join(agentsDir, "prompts"), toolName);
|
|
19078
19121
|
if (promptFilePath) {
|
|
19079
19122
|
await this.analyzePrompt(toolName, agentsDir, analysis, visited, parentKey);
|
|
19080
19123
|
return;
|
|
19081
19124
|
}
|
|
19082
|
-
const agentFilePath = await this.findFile(
|
|
19125
|
+
const agentFilePath = await this.findFile(path9.join(agentsDir, "agents"), toolName);
|
|
19083
19126
|
if (agentFilePath) {
|
|
19084
19127
|
await this.analyzeNestedAgent(toolName, agentsDir, analysis, visited, parentKey);
|
|
19085
19128
|
return;
|
|
19086
19129
|
}
|
|
19087
|
-
const toolFilePath = await this.findFile(
|
|
19130
|
+
const toolFilePath = await this.findFile(path9.join(agentsDir, "tools"), toolName);
|
|
19088
19131
|
if (!toolFilePath) {
|
|
19089
19132
|
analysis.warnings.push(`Tool file not found: ${toolName}`);
|
|
19090
19133
|
return;
|
|
@@ -19102,7 +19145,7 @@ var PackingService = class {
|
|
|
19102
19145
|
return;
|
|
19103
19146
|
}
|
|
19104
19147
|
visited.add(`tool:${toolName}`);
|
|
19105
|
-
const toolSource =
|
|
19148
|
+
const toolSource = fs9.readFileSync(toolFilePath, "utf-8");
|
|
19106
19149
|
const { uses } = await extractToolUses(toolSource);
|
|
19107
19150
|
for (const usedItem of uses) {
|
|
19108
19151
|
await this.analyzeTool(usedItem, agentsDir, analysis, visited, "uses", thisKey);
|
|
@@ -19112,7 +19155,7 @@ var PackingService = class {
|
|
|
19112
19155
|
* Analyze a nested agent (used as a handoff target).
|
|
19113
19156
|
*/
|
|
19114
19157
|
async analyzeNestedAgent(agentName, agentsDir, analysis, visited, parentKey) {
|
|
19115
|
-
const agentFilePath = await this.findFile(
|
|
19158
|
+
const agentFilePath = await this.findFile(path9.join(agentsDir, "agents"), agentName);
|
|
19116
19159
|
if (!agentFilePath) {
|
|
19117
19160
|
analysis.warnings.push(`Agent file not found: ${agentName}`);
|
|
19118
19161
|
return;
|
|
@@ -19131,7 +19174,7 @@ var PackingService = class {
|
|
|
19131
19174
|
return;
|
|
19132
19175
|
}
|
|
19133
19176
|
visited.add(`agent:${agentName}`);
|
|
19134
|
-
const agentSource =
|
|
19177
|
+
const agentSource = fs9.readFileSync(agentFilePath, "utf-8");
|
|
19135
19178
|
const agentPrompts = await extractAgentPrompts(agentSource);
|
|
19136
19179
|
if (agentPrompts.sideA) {
|
|
19137
19180
|
await this.analyzePrompt(agentPrompts.sideA, agentsDir, analysis, visited, thisKey);
|
|
@@ -19144,7 +19187,7 @@ var PackingService = class {
|
|
|
19144
19187
|
* Analyze a model and its fallbacks.
|
|
19145
19188
|
*/
|
|
19146
19189
|
async analyzeModel(modelName, agentsDir, analysis, visited, parentKey) {
|
|
19147
|
-
const modelFilePath = await this.findFile(
|
|
19190
|
+
const modelFilePath = await this.findFile(path9.join(agentsDir, "models"), modelName);
|
|
19148
19191
|
if (!modelFilePath) {
|
|
19149
19192
|
analysis.warnings.push(`Model file not found: ${modelName}`);
|
|
19150
19193
|
return;
|
|
@@ -19163,7 +19206,7 @@ var PackingService = class {
|
|
|
19163
19206
|
return;
|
|
19164
19207
|
}
|
|
19165
19208
|
visited.add(`model:${modelName}`);
|
|
19166
|
-
const modelSource =
|
|
19209
|
+
const modelSource = fs9.readFileSync(modelFilePath, "utf-8");
|
|
19167
19210
|
const fallbacks = await extractModelFallbacks(modelSource);
|
|
19168
19211
|
for (const fallbackName of fallbacks) {
|
|
19169
19212
|
await this.analyzeModel(fallbackName, agentsDir, analysis, visited, thisKey);
|
|
@@ -19173,13 +19216,13 @@ var PackingService = class {
|
|
|
19173
19216
|
* Check which items are shared with other agents.
|
|
19174
19217
|
*/
|
|
19175
19218
|
async checkSharedItems(agentsDir, analysis) {
|
|
19176
|
-
const agentsPath =
|
|
19177
|
-
if (!
|
|
19178
|
-
const agentFiles =
|
|
19219
|
+
const agentsPath = path9.join(agentsDir, "agents");
|
|
19220
|
+
if (!fs9.existsSync(agentsPath)) return;
|
|
19221
|
+
const agentFiles = fs9.readdirSync(agentsPath).filter((f) => f.endsWith(".ts"));
|
|
19179
19222
|
for (const agentFile of agentFiles) {
|
|
19180
19223
|
const otherAgentName = agentFile.replace(".ts", "");
|
|
19181
19224
|
if (otherAgentName === analysis.agent) continue;
|
|
19182
|
-
const otherAnalysis = await this.analyzeAgentLight(otherAgentName,
|
|
19225
|
+
const otherAnalysis = await this.analyzeAgentLight(otherAgentName, path9.dirname(agentsDir));
|
|
19183
19226
|
for (const prompt of analysis.constituents.prompts) {
|
|
19184
19227
|
if (otherAnalysis.prompts.includes(prompt.name)) {
|
|
19185
19228
|
prompt.sharedWith.push(otherAgentName);
|
|
@@ -19211,19 +19254,19 @@ var PackingService = class {
|
|
|
19211
19254
|
*/
|
|
19212
19255
|
async analyzeAgentLight(agentName, rootDir) {
|
|
19213
19256
|
const result = { prompts: [], tools: [], models: [] };
|
|
19214
|
-
const agentsDir =
|
|
19257
|
+
const agentsDir = path9.join(rootDir, "agents");
|
|
19215
19258
|
const visited = /* @__PURE__ */ new Set();
|
|
19216
|
-
const agentFilePath = await this.findFile(
|
|
19259
|
+
const agentFilePath = await this.findFile(path9.join(agentsDir, "agents"), agentName);
|
|
19217
19260
|
if (!agentFilePath) return result;
|
|
19218
|
-
const agentSource =
|
|
19261
|
+
const agentSource = fs9.readFileSync(agentFilePath, "utf-8");
|
|
19219
19262
|
const agentPrompts = await extractAgentPrompts(agentSource);
|
|
19220
19263
|
const analyzePromptLight = async (promptName) => {
|
|
19221
19264
|
if (visited.has(promptName)) return;
|
|
19222
19265
|
visited.add(promptName);
|
|
19223
19266
|
result.prompts.push(promptName);
|
|
19224
|
-
const promptFilePath = await this.findFile(
|
|
19267
|
+
const promptFilePath = await this.findFile(path9.join(agentsDir, "prompts"), promptName);
|
|
19225
19268
|
if (!promptFilePath) return;
|
|
19226
|
-
const promptSource =
|
|
19269
|
+
const promptSource = fs9.readFileSync(promptFilePath, "utf-8");
|
|
19227
19270
|
const modelName = await extractPromptModel(promptSource);
|
|
19228
19271
|
if (modelName && !result.models.includes(modelName)) {
|
|
19229
19272
|
result.models.push(modelName);
|
|
@@ -19296,14 +19339,15 @@ var PackingService = class {
|
|
|
19296
19339
|
return result;
|
|
19297
19340
|
}
|
|
19298
19341
|
result.warnings = analysis.warnings;
|
|
19299
|
-
const
|
|
19300
|
-
|
|
19301
|
-
|
|
19302
|
-
|
|
19303
|
-
|
|
19304
|
-
|
|
19305
|
-
|
|
19306
|
-
|
|
19342
|
+
const safePackageId = assertSafePackageIdentifier(packageId);
|
|
19343
|
+
const pkgOutputDir = resolvePathWithin(outputDir, safePackageId);
|
|
19344
|
+
fs9.mkdirSync(path9.join(pkgOutputDir, "dist", "agents"), { recursive: true });
|
|
19345
|
+
fs9.mkdirSync(path9.join(pkgOutputDir, "dist", "prompts"), { recursive: true });
|
|
19346
|
+
fs9.mkdirSync(path9.join(pkgOutputDir, "dist", "tools"), { recursive: true });
|
|
19347
|
+
fs9.mkdirSync(path9.join(pkgOutputDir, "dist", "models"), { recursive: true });
|
|
19348
|
+
fs9.mkdirSync(path9.join(pkgOutputDir, "dist", "hooks"), { recursive: true });
|
|
19349
|
+
fs9.mkdirSync(path9.join(pkgOutputDir, "dist", "effects"), { recursive: true });
|
|
19350
|
+
fs9.mkdirSync(path9.join(pkgOutputDir, "dist", "thread-endpoints"), { recursive: true });
|
|
19307
19351
|
const seenItems = /* @__PURE__ */ new Set();
|
|
19308
19352
|
const allItems = [];
|
|
19309
19353
|
for (const a of analysis.constituents.agents) {
|
|
@@ -19357,13 +19401,13 @@ var PackingService = class {
|
|
|
19357
19401
|
}
|
|
19358
19402
|
const externalDeps = /* @__PURE__ */ new Map();
|
|
19359
19403
|
for (const item of allItems) {
|
|
19360
|
-
const outputPath =
|
|
19404
|
+
const outputPath = resolvePathWithin(
|
|
19361
19405
|
pkgOutputDir,
|
|
19362
19406
|
"dist",
|
|
19363
19407
|
this.getTypeDir(item.type),
|
|
19364
19408
|
`${item.name}.js`
|
|
19365
19409
|
);
|
|
19366
|
-
|
|
19410
|
+
fs9.mkdirSync(path9.dirname(outputPath), { recursive: true });
|
|
19367
19411
|
const deps = await this.bundleFile(item.filePath, outputPath, rootDir);
|
|
19368
19412
|
for (const [depName, depVersion] of deps) {
|
|
19369
19413
|
if (!externalDeps.has(depName)) {
|
|
@@ -19373,12 +19417,12 @@ var PackingService = class {
|
|
|
19373
19417
|
result.filesCreated.push(outputPath);
|
|
19374
19418
|
}
|
|
19375
19419
|
const indexJs = this.generateReExportIndex(analysis, meta);
|
|
19376
|
-
const indexJsPath =
|
|
19377
|
-
|
|
19420
|
+
const indexJsPath = resolvePathWithin(pkgOutputDir, "dist", "index.js");
|
|
19421
|
+
fs9.writeFileSync(indexJsPath, indexJs);
|
|
19378
19422
|
result.filesCreated.push(indexJsPath);
|
|
19379
19423
|
const indexDts = this.generateIndexDts(analysis);
|
|
19380
|
-
const indexDtsPath =
|
|
19381
|
-
|
|
19424
|
+
const indexDtsPath = resolvePathWithin(pkgOutputDir, "dist", "index.d.ts");
|
|
19425
|
+
fs9.writeFileSync(indexDtsPath, indexDts);
|
|
19382
19426
|
result.filesCreated.push(indexDtsPath);
|
|
19383
19427
|
const pkgJson = this.generatePackageJson(
|
|
19384
19428
|
finalPackageName,
|
|
@@ -19391,13 +19435,13 @@ var PackingService = class {
|
|
|
19391
19435
|
license,
|
|
19392
19436
|
licenseOwner
|
|
19393
19437
|
);
|
|
19394
|
-
const pkgJsonPath =
|
|
19395
|
-
|
|
19438
|
+
const pkgJsonPath = path9.join(pkgOutputDir, "package.json");
|
|
19439
|
+
fs9.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
|
|
19396
19440
|
result.filesCreated.push(pkgJsonPath);
|
|
19397
19441
|
if (license) {
|
|
19398
19442
|
const licenseContent = this.generateLicenseFile(license, licenseOwner);
|
|
19399
|
-
const licensePath =
|
|
19400
|
-
|
|
19443
|
+
const licensePath = path9.join(pkgOutputDir, "LICENSE");
|
|
19444
|
+
fs9.writeFileSync(licensePath, licenseContent);
|
|
19401
19445
|
result.filesCreated.push(licensePath);
|
|
19402
19446
|
}
|
|
19403
19447
|
let readmeContent = readme;
|
|
@@ -19405,7 +19449,7 @@ var PackingService = class {
|
|
|
19405
19449
|
const agentItem = analysis.constituents.agents.find((a) => a.name === agentName);
|
|
19406
19450
|
let agentDescription;
|
|
19407
19451
|
if (agentItem?.filePath) {
|
|
19408
|
-
const agentSource =
|
|
19452
|
+
const agentSource = fs9.readFileSync(agentItem.filePath, "utf-8");
|
|
19409
19453
|
agentDescription = await extractAgentDescription(agentSource) || void 0;
|
|
19410
19454
|
}
|
|
19411
19455
|
readmeContent = this.generateReadme(
|
|
@@ -19416,21 +19460,21 @@ var PackingService = class {
|
|
|
19416
19460
|
agentDescription
|
|
19417
19461
|
);
|
|
19418
19462
|
}
|
|
19419
|
-
const readmePath =
|
|
19420
|
-
|
|
19463
|
+
const readmePath = path9.join(pkgOutputDir, "README.md");
|
|
19464
|
+
fs9.writeFileSync(readmePath, readmeContent);
|
|
19421
19465
|
result.filesCreated.push(readmePath);
|
|
19422
19466
|
if (removeOriginals || itemSelections) {
|
|
19423
19467
|
result.filesRemoved = [];
|
|
19424
19468
|
for (const item of allItems) {
|
|
19425
19469
|
const selection = itemSelections?.find((s) => s.name === item.name && s.type === item.type);
|
|
19426
19470
|
const shouldRemove = selection ? selection.mode === "extract" : removeOriginals && item.sharedWith.length === 0 && item.type !== "thread-endpoint" && item.type !== "effect";
|
|
19427
|
-
if (shouldRemove &&
|
|
19428
|
-
|
|
19471
|
+
if (shouldRemove && fs9.existsSync(item.filePath)) {
|
|
19472
|
+
fs9.unlinkSync(item.filePath);
|
|
19429
19473
|
result.filesRemoved.push(item.filePath);
|
|
19430
19474
|
}
|
|
19431
19475
|
}
|
|
19432
19476
|
}
|
|
19433
|
-
const agentsDir =
|
|
19477
|
+
const agentsDir = path9.join(rootDir, "agents");
|
|
19434
19478
|
const metadataService = new MetadataService(agentsDir);
|
|
19435
19479
|
const metadata = {
|
|
19436
19480
|
packageName: finalPackageName,
|
|
@@ -19464,7 +19508,7 @@ var PackingService = class {
|
|
|
19464
19508
|
const commonjs = (await import('@rollup/plugin-commonjs')).default;
|
|
19465
19509
|
const esbuild = (await import('rollup-plugin-esbuild')).default;
|
|
19466
19510
|
const externalDeps = /* @__PURE__ */ new Map();
|
|
19467
|
-
const agentsDir =
|
|
19511
|
+
const agentsDir = path9.join(rootDir, "agents");
|
|
19468
19512
|
const resolveVersion = this.resolvePackageVersion.bind(this);
|
|
19469
19513
|
const trackExternalsPlugin = {
|
|
19470
19514
|
name: "track-externals",
|
|
@@ -19473,14 +19517,14 @@ var PackingService = class {
|
|
|
19473
19517
|
return null;
|
|
19474
19518
|
}
|
|
19475
19519
|
if (source.startsWith("./") || source.startsWith("../")) {
|
|
19476
|
-
const resolved =
|
|
19520
|
+
const resolved = path9.resolve(path9.dirname(importer), source);
|
|
19477
19521
|
let tsResolved = resolved;
|
|
19478
19522
|
if (!resolved.endsWith(".ts") && !resolved.endsWith(".js")) {
|
|
19479
|
-
if (
|
|
19523
|
+
if (fs9.existsSync(`${resolved}.ts`)) {
|
|
19480
19524
|
tsResolved = `${resolved}.ts`;
|
|
19481
|
-
} else if (
|
|
19525
|
+
} else if (fs9.existsSync(`${resolved}.js`)) {
|
|
19482
19526
|
tsResolved = `${resolved}.js`;
|
|
19483
|
-
} else if (
|
|
19527
|
+
} else if (fs9.existsSync(`${resolved}/index.ts`)) {
|
|
19484
19528
|
tsResolved = `${resolved}/index.ts`;
|
|
19485
19529
|
}
|
|
19486
19530
|
}
|
|
@@ -19529,11 +19573,11 @@ var PackingService = class {
|
|
|
19529
19573
|
exports: "named"
|
|
19530
19574
|
});
|
|
19531
19575
|
const bundledCode = output[0].code;
|
|
19532
|
-
const header = `// Bundled from: ${
|
|
19576
|
+
const header = `// Bundled from: ${path9.relative(rootDir, inputPath)}
|
|
19533
19577
|
// Local dependencies have been inlined
|
|
19534
19578
|
|
|
19535
19579
|
`;
|
|
19536
|
-
|
|
19580
|
+
fs9.writeFileSync(outputPath, header + bundledCode);
|
|
19537
19581
|
await bundle.close();
|
|
19538
19582
|
} catch (error) {
|
|
19539
19583
|
await bundle.close();
|
|
@@ -19958,30 +20002,31 @@ Copyright (c) ${year} ${copyrightHolder}
|
|
|
19958
20002
|
* @returns Package info or null if not found
|
|
19959
20003
|
*/
|
|
19960
20004
|
getPackedInfo(packageId, rootDir) {
|
|
19961
|
-
const packedDir =
|
|
19962
|
-
|
|
19963
|
-
|
|
19964
|
-
|
|
20005
|
+
const packedDir = path9.join(rootDir, "agents", "packed");
|
|
20006
|
+
const safePackageId = assertSafePackageIdentifier(packageId);
|
|
20007
|
+
let packageDir = resolvePathWithin(packedDir, safePackageId);
|
|
20008
|
+
if (!fs9.existsSync(packageDir)) {
|
|
20009
|
+
if (!fs9.existsSync(packedDir)) {
|
|
19965
20010
|
return null;
|
|
19966
20011
|
}
|
|
19967
|
-
const dirs =
|
|
20012
|
+
const dirs = fs9.readdirSync(packedDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
19968
20013
|
const matchingDir = dirs.find(
|
|
19969
20014
|
(d) => d === packageId || d === `standardagent-${packageId}` || d === `standardagent-${packageId.replace(/_/g, "-")}`
|
|
19970
20015
|
);
|
|
19971
20016
|
if (!matchingDir) {
|
|
19972
20017
|
return null;
|
|
19973
20018
|
}
|
|
19974
|
-
packageDir =
|
|
20019
|
+
packageDir = path9.join(packedDir, matchingDir);
|
|
19975
20020
|
}
|
|
19976
|
-
const pkgJsonPath =
|
|
19977
|
-
if (!
|
|
20021
|
+
const pkgJsonPath = path9.join(packageDir, "package.json");
|
|
20022
|
+
if (!fs9.existsSync(pkgJsonPath)) {
|
|
19978
20023
|
return null;
|
|
19979
20024
|
}
|
|
19980
|
-
const pkgJson = JSON.parse(
|
|
20025
|
+
const pkgJson = JSON.parse(fs9.readFileSync(pkgJsonPath, "utf-8"));
|
|
19981
20026
|
let readme;
|
|
19982
|
-
const readmePath =
|
|
19983
|
-
if (
|
|
19984
|
-
readme =
|
|
20027
|
+
const readmePath = path9.join(packageDir, "README.md");
|
|
20028
|
+
if (fs9.existsSync(readmePath)) {
|
|
20029
|
+
readme = fs9.readFileSync(readmePath, "utf-8");
|
|
19985
20030
|
}
|
|
19986
20031
|
return {
|
|
19987
20032
|
packageName: pkgJson.name,
|
|
@@ -19999,11 +20044,11 @@ Copyright (c) ${year} ${copyrightHolder}
|
|
|
19999
20044
|
* @returns Array of package directory names
|
|
20000
20045
|
*/
|
|
20001
20046
|
listPackedPackages(rootDir) {
|
|
20002
|
-
const packedDir =
|
|
20003
|
-
if (!
|
|
20047
|
+
const packedDir = path9.join(rootDir, "agents", "packed");
|
|
20048
|
+
if (!fs9.existsSync(packedDir)) {
|
|
20004
20049
|
return [];
|
|
20005
20050
|
}
|
|
20006
|
-
return
|
|
20051
|
+
return fs9.readdirSync(packedDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
20007
20052
|
}
|
|
20008
20053
|
/**
|
|
20009
20054
|
* Generate README.md content for a packed agent.
|
|
@@ -20050,17 +20095,17 @@ ${license || "See LICENSE file"}
|
|
|
20050
20095
|
* Find a file by name in a directory.
|
|
20051
20096
|
*/
|
|
20052
20097
|
async findFile(dir, name) {
|
|
20053
|
-
if (!
|
|
20098
|
+
if (!fs9.existsSync(dir)) {
|
|
20054
20099
|
return null;
|
|
20055
20100
|
}
|
|
20056
|
-
const exactPath =
|
|
20057
|
-
if (
|
|
20101
|
+
const exactPath = resolvePathWithin(dir, `${name}.ts`);
|
|
20102
|
+
if (fs9.existsSync(exactPath)) {
|
|
20058
20103
|
return exactPath;
|
|
20059
20104
|
}
|
|
20060
|
-
const files =
|
|
20105
|
+
const files = fs9.readdirSync(dir).filter((f) => f.endsWith(".ts"));
|
|
20061
20106
|
for (const file of files) {
|
|
20062
|
-
const filePath =
|
|
20063
|
-
const source =
|
|
20107
|
+
const filePath = path9.join(dir, file);
|
|
20108
|
+
const source = fs9.readFileSync(filePath, "utf-8");
|
|
20064
20109
|
const extractedName = await extractDefinitionName(source);
|
|
20065
20110
|
if (extractedName === name) {
|
|
20066
20111
|
return filePath;
|
|
@@ -20072,15 +20117,15 @@ ${license || "See LICENSE file"}
|
|
|
20072
20117
|
* List all agents in the workspace.
|
|
20073
20118
|
*/
|
|
20074
20119
|
async listAgents(rootDir) {
|
|
20075
|
-
const agentsDir =
|
|
20076
|
-
if (!
|
|
20120
|
+
const agentsDir = path9.join(rootDir, "agents", "agents");
|
|
20121
|
+
if (!fs9.existsSync(agentsDir)) {
|
|
20077
20122
|
return [];
|
|
20078
20123
|
}
|
|
20079
|
-
const files =
|
|
20124
|
+
const files = fs9.readdirSync(agentsDir).filter((f) => f.endsWith(".ts"));
|
|
20080
20125
|
const agents = [];
|
|
20081
20126
|
for (const file of files) {
|
|
20082
|
-
const filePath =
|
|
20083
|
-
const source =
|
|
20127
|
+
const filePath = path9.join(agentsDir, file);
|
|
20128
|
+
const source = fs9.readFileSync(filePath, "utf-8");
|
|
20084
20129
|
const name = await extractDefinitionName(source);
|
|
20085
20130
|
if (name) {
|
|
20086
20131
|
agents.push(name);
|
|
@@ -20096,7 +20141,7 @@ var PackageDiscoveryService = class {
|
|
|
20096
20141
|
constructor(config) {
|
|
20097
20142
|
this.config = {
|
|
20098
20143
|
rootDir: config.rootDir,
|
|
20099
|
-
packedDir: config.packedDir ??
|
|
20144
|
+
packedDir: config.packedDir ?? path9.join(config.rootDir, "agents", "packed"),
|
|
20100
20145
|
scanNpm: config.scanNpm ?? true,
|
|
20101
20146
|
scanLocal: config.scanLocal ?? true
|
|
20102
20147
|
};
|
|
@@ -20129,19 +20174,19 @@ var PackageDiscoveryService = class {
|
|
|
20129
20174
|
*/
|
|
20130
20175
|
async discoverNpmPackages() {
|
|
20131
20176
|
const packages = [];
|
|
20132
|
-
const nodeModulesDir =
|
|
20133
|
-
if (!
|
|
20177
|
+
const nodeModulesDir = path9.join(this.config.rootDir, "node_modules");
|
|
20178
|
+
if (!fs9.existsSync(nodeModulesDir)) {
|
|
20134
20179
|
return packages;
|
|
20135
20180
|
}
|
|
20136
20181
|
const rootEntries = await this.scanDirectory(nodeModulesDir);
|
|
20137
20182
|
for (const entry of rootEntries) {
|
|
20138
20183
|
if (entry.startsWith(".")) continue;
|
|
20139
20184
|
if (entry.startsWith("@")) {
|
|
20140
|
-
const scopeDir =
|
|
20185
|
+
const scopeDir = path9.join(nodeModulesDir, entry);
|
|
20141
20186
|
const scopeEntries = await this.scanDirectory(scopeDir);
|
|
20142
20187
|
for (const scopedPkg of scopeEntries) {
|
|
20143
20188
|
if (scopedPkg.startsWith(".")) continue;
|
|
20144
|
-
const pkgDir =
|
|
20189
|
+
const pkgDir = path9.join(scopeDir, scopedPkg);
|
|
20145
20190
|
const fullName = `${entry}/${scopedPkg}`;
|
|
20146
20191
|
const pkg = await this.checkNpmPackage(pkgDir, fullName);
|
|
20147
20192
|
if (pkg) {
|
|
@@ -20149,7 +20194,7 @@ var PackageDiscoveryService = class {
|
|
|
20149
20194
|
}
|
|
20150
20195
|
}
|
|
20151
20196
|
} else {
|
|
20152
|
-
const pkgDir =
|
|
20197
|
+
const pkgDir = path9.join(nodeModulesDir, entry);
|
|
20153
20198
|
const pkg = await this.checkNpmPackage(pkgDir, entry);
|
|
20154
20199
|
if (pkg) {
|
|
20155
20200
|
packages.push(pkg);
|
|
@@ -20165,12 +20210,12 @@ var PackageDiscoveryService = class {
|
|
|
20165
20210
|
* which must contain `entryAgents` array.
|
|
20166
20211
|
*/
|
|
20167
20212
|
async checkNpmPackage(pkgDir, pkgName) {
|
|
20168
|
-
const pkgJsonPath =
|
|
20169
|
-
if (!
|
|
20213
|
+
const pkgJsonPath = path9.join(pkgDir, "package.json");
|
|
20214
|
+
if (!fs9.existsSync(pkgJsonPath)) {
|
|
20170
20215
|
return null;
|
|
20171
20216
|
}
|
|
20172
20217
|
try {
|
|
20173
|
-
const pkgJson = JSON.parse(
|
|
20218
|
+
const pkgJson = JSON.parse(fs9.readFileSync(pkgJsonPath, "utf-8"));
|
|
20174
20219
|
const isStandardAgent = (
|
|
20175
20220
|
// Has "standardagent" keyword
|
|
20176
20221
|
pkgJson.keywords?.includes("standardagent") || // Has "standardagent-*" prefix
|
|
@@ -20207,21 +20252,21 @@ var PackageDiscoveryService = class {
|
|
|
20207
20252
|
*/
|
|
20208
20253
|
async discoverLocalPackages() {
|
|
20209
20254
|
const packages = [];
|
|
20210
|
-
if (!
|
|
20255
|
+
if (!fs9.existsSync(this.config.packedDir)) {
|
|
20211
20256
|
return packages;
|
|
20212
20257
|
}
|
|
20213
20258
|
const entries = await this.scanDirectory(this.config.packedDir);
|
|
20214
20259
|
for (const entry of entries) {
|
|
20215
20260
|
if (entry.startsWith(".")) continue;
|
|
20216
|
-
const pkgDir =
|
|
20217
|
-
const stat2 =
|
|
20261
|
+
const pkgDir = path9.join(this.config.packedDir, entry);
|
|
20262
|
+
const stat2 = fs9.statSync(pkgDir);
|
|
20218
20263
|
if (!stat2.isDirectory()) continue;
|
|
20219
20264
|
if (entry.startsWith("@")) {
|
|
20220
20265
|
const scopeEntries = await this.scanDirectory(pkgDir);
|
|
20221
20266
|
for (const scopedPkg of scopeEntries) {
|
|
20222
20267
|
if (scopedPkg.startsWith(".")) continue;
|
|
20223
|
-
const scopedPkgDir =
|
|
20224
|
-
const scopedStat =
|
|
20268
|
+
const scopedPkgDir = path9.join(pkgDir, scopedPkg);
|
|
20269
|
+
const scopedStat = fs9.statSync(scopedPkgDir);
|
|
20225
20270
|
if (!scopedStat.isDirectory()) continue;
|
|
20226
20271
|
const fullName = `${entry}/${scopedPkg}`;
|
|
20227
20272
|
const pkg = await this.checkLocalPackage(scopedPkgDir, fullName);
|
|
@@ -20244,12 +20289,12 @@ var PackageDiscoveryService = class {
|
|
|
20244
20289
|
* Detection is based on the `standardagent` field in package.json.
|
|
20245
20290
|
*/
|
|
20246
20291
|
async checkLocalPackage(pkgDir, dirName) {
|
|
20247
|
-
const pkgJsonPath =
|
|
20248
|
-
if (!
|
|
20292
|
+
const pkgJsonPath = path9.join(pkgDir, "package.json");
|
|
20293
|
+
if (!fs9.existsSync(pkgJsonPath)) {
|
|
20249
20294
|
return null;
|
|
20250
20295
|
}
|
|
20251
20296
|
try {
|
|
20252
|
-
const pkgJson = JSON.parse(
|
|
20297
|
+
const pkgJson = JSON.parse(fs9.readFileSync(pkgJsonPath, "utf-8"));
|
|
20253
20298
|
if (!pkgJson.standardagent?.entryAgents) {
|
|
20254
20299
|
return null;
|
|
20255
20300
|
}
|
|
@@ -20274,10 +20319,10 @@ var PackageDiscoveryService = class {
|
|
|
20274
20319
|
* Scan a directory and return entry names.
|
|
20275
20320
|
*/
|
|
20276
20321
|
async scanDirectory(dir) {
|
|
20277
|
-
if (!
|
|
20322
|
+
if (!fs9.existsSync(dir)) {
|
|
20278
20323
|
return [];
|
|
20279
20324
|
}
|
|
20280
|
-
const entries =
|
|
20325
|
+
const entries = fs9.readdirSync(dir);
|
|
20281
20326
|
return entries;
|
|
20282
20327
|
}
|
|
20283
20328
|
/**
|
|
@@ -20374,29 +20419,29 @@ var UnpackingService = class {
|
|
|
20374
20419
|
}
|
|
20375
20420
|
analysis.version = pkg.version;
|
|
20376
20421
|
analysis.source = pkg.source;
|
|
20377
|
-
const indexPath =
|
|
20378
|
-
if (!
|
|
20422
|
+
const indexPath = path9.join(pkg.path, "dist", "index.js");
|
|
20423
|
+
if (!fs9.existsSync(indexPath)) {
|
|
20379
20424
|
analysis.errors.push(`Package index not found: ${indexPath}`);
|
|
20380
20425
|
return analysis;
|
|
20381
20426
|
}
|
|
20382
|
-
const indexContent =
|
|
20427
|
+
const indexContent = fs9.readFileSync(indexPath, "utf-8");
|
|
20383
20428
|
const registryItems = await this.parseIndexExports(indexContent);
|
|
20384
20429
|
const availableItems = /* @__PURE__ */ new Map();
|
|
20385
20430
|
for (const item of registryItems) {
|
|
20386
20431
|
availableItems.set(`${item.type}:${item.name}`, item);
|
|
20387
20432
|
}
|
|
20388
|
-
const agentsDir =
|
|
20433
|
+
const agentsDir = path9.join(rootDir, "agents");
|
|
20389
20434
|
const itemsWithRelations = [];
|
|
20390
20435
|
for (const item of registryItems) {
|
|
20391
|
-
const targetPath =
|
|
20392
|
-
const sourcePath =
|
|
20436
|
+
const targetPath = resolvePathWithin(agentsDir, TYPE_TO_TARGET_DIR[item.type], `${item.name}.ts`);
|
|
20437
|
+
const sourcePath = resolvePathWithin(pkg.path, "dist", TYPE_TO_DIR[item.type], `${item.name}.js`);
|
|
20393
20438
|
const existsGlobally = this.fileExists(targetPath);
|
|
20394
|
-
const sourceExists =
|
|
20439
|
+
const sourceExists = fs9.existsSync(sourcePath);
|
|
20395
20440
|
if (!sourceExists) {
|
|
20396
20441
|
analysis.warnings.push(`Source file not found for ${item.type} "${item.name}": ${sourcePath}`);
|
|
20397
20442
|
continue;
|
|
20398
20443
|
}
|
|
20399
|
-
const bundledCode =
|
|
20444
|
+
const bundledCode = fs9.readFileSync(sourcePath, "utf-8");
|
|
20400
20445
|
const children = await this.discoverRelationships(item.type, item.name, bundledCode, availableItems);
|
|
20401
20446
|
itemsWithRelations.push({
|
|
20402
20447
|
name: item.name,
|
|
@@ -20406,10 +20451,10 @@ var UnpackingService = class {
|
|
|
20406
20451
|
action: existsGlobally ? "skip" : "generate"
|
|
20407
20452
|
});
|
|
20408
20453
|
for (const child of children) {
|
|
20409
|
-
const childTargetPath =
|
|
20410
|
-
const childSourcePath =
|
|
20454
|
+
const childTargetPath = resolvePathWithin(agentsDir, TYPE_TO_TARGET_DIR[child.type], `${child.name}.ts`);
|
|
20455
|
+
const childSourcePath = resolvePathWithin(pkg.path, "dist", TYPE_TO_DIR[child.type], `${child.name}.js`);
|
|
20411
20456
|
const childExists = this.fileExists(childTargetPath);
|
|
20412
|
-
const childSourceExists =
|
|
20457
|
+
const childSourceExists = fs9.existsSync(childSourcePath);
|
|
20413
20458
|
if (!childSourceExists) {
|
|
20414
20459
|
continue;
|
|
20415
20460
|
}
|
|
@@ -20512,8 +20557,8 @@ var UnpackingService = class {
|
|
|
20512
20557
|
return result;
|
|
20513
20558
|
}
|
|
20514
20559
|
const itemsToProcess = this.applySelections(analysis.items, itemSelections);
|
|
20515
|
-
const pkgJsonPath =
|
|
20516
|
-
const pkgJson = JSON.parse(
|
|
20560
|
+
const pkgJsonPath = path9.join(pkg.path, "package.json");
|
|
20561
|
+
const pkgJson = JSON.parse(fs9.readFileSync(pkgJsonPath, "utf-8"));
|
|
20517
20562
|
let author = "";
|
|
20518
20563
|
if (typeof pkgJson.author === "string") {
|
|
20519
20564
|
author = pkgJson.author;
|
|
@@ -20538,18 +20583,19 @@ var UnpackingService = class {
|
|
|
20538
20583
|
continue;
|
|
20539
20584
|
}
|
|
20540
20585
|
try {
|
|
20541
|
-
const sourcePath =
|
|
20542
|
-
const
|
|
20586
|
+
const sourcePath = resolvePathWithin(pkg.path, "dist", TYPE_TO_DIR[item.type], `${item.name}.js`);
|
|
20587
|
+
const targetPath = resolvePathWithin(path9.join(rootDir, "agents"), path9.relative(path9.join(rootDir, "agents"), item.targetPath));
|
|
20588
|
+
const bundledCode = fs9.readFileSync(sourcePath, "utf-8");
|
|
20543
20589
|
let tsCode = await transformBundledJs(bundledCode);
|
|
20544
20590
|
if (item.type === "agent") {
|
|
20545
20591
|
tsCode = await injectAgentMetadata(tsCode, agentMetadata);
|
|
20546
20592
|
}
|
|
20547
|
-
const dir =
|
|
20548
|
-
if (!
|
|
20549
|
-
|
|
20593
|
+
const dir = path9.dirname(targetPath);
|
|
20594
|
+
if (!fs9.existsSync(dir)) {
|
|
20595
|
+
fs9.mkdirSync(dir, { recursive: true });
|
|
20550
20596
|
}
|
|
20551
|
-
|
|
20552
|
-
result.filesGenerated.push(
|
|
20597
|
+
fs9.writeFileSync(targetPath, tsCode);
|
|
20598
|
+
result.filesGenerated.push(targetPath);
|
|
20553
20599
|
} catch (error) {
|
|
20554
20600
|
result.warnings.push(
|
|
20555
20601
|
`Failed to generate ${item.type} "${item.name}": ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -20558,7 +20604,12 @@ var UnpackingService = class {
|
|
|
20558
20604
|
}
|
|
20559
20605
|
if (deletePackage && pkg.source === "local") {
|
|
20560
20606
|
try {
|
|
20561
|
-
|
|
20607
|
+
const localPackedRoot = path9.join(rootDir, "agents", "packed");
|
|
20608
|
+
const safePackagePath = resolvePathWithin(
|
|
20609
|
+
localPackedRoot,
|
|
20610
|
+
path9.relative(localPackedRoot, pkg.path)
|
|
20611
|
+
);
|
|
20612
|
+
this.deleteDirectory(safePackagePath);
|
|
20562
20613
|
result.packageDeleted = true;
|
|
20563
20614
|
} catch (error) {
|
|
20564
20615
|
result.warnings.push(
|
|
@@ -20637,14 +20688,14 @@ var UnpackingService = class {
|
|
|
20637
20688
|
*/
|
|
20638
20689
|
async resolvePackage(pkgIdentifier, rootDir) {
|
|
20639
20690
|
if (pkgIdentifier.startsWith("/") || pkgIdentifier.startsWith("./")) {
|
|
20640
|
-
const absolutePath =
|
|
20641
|
-
const pkgJsonPath2 =
|
|
20642
|
-
if (
|
|
20691
|
+
const absolutePath = path9.isAbsolute(pkgIdentifier) ? pkgIdentifier : path9.join(rootDir, pkgIdentifier);
|
|
20692
|
+
const pkgJsonPath2 = path9.join(absolutePath, "package.json");
|
|
20693
|
+
if (fs9.existsSync(pkgJsonPath2)) {
|
|
20643
20694
|
try {
|
|
20644
|
-
const pkgJson = JSON.parse(
|
|
20695
|
+
const pkgJson = JSON.parse(fs9.readFileSync(pkgJsonPath2, "utf-8"));
|
|
20645
20696
|
if (pkgJson.standardagent?.entryAgents) {
|
|
20646
20697
|
return {
|
|
20647
|
-
packageId: pkgJson.name ||
|
|
20698
|
+
packageId: pkgJson.name || path9.basename(absolutePath),
|
|
20648
20699
|
version: pkgJson.version || "0.0.0",
|
|
20649
20700
|
source: "local",
|
|
20650
20701
|
path: absolutePath,
|
|
@@ -20656,11 +20707,12 @@ var UnpackingService = class {
|
|
|
20656
20707
|
}
|
|
20657
20708
|
return null;
|
|
20658
20709
|
}
|
|
20659
|
-
const
|
|
20660
|
-
const
|
|
20661
|
-
|
|
20710
|
+
const safeIdentifier = assertSafePackageIdentifier(pkgIdentifier);
|
|
20711
|
+
const packedDir = resolvePathWithin(path9.join(rootDir, "agents", "packed"), safeIdentifier);
|
|
20712
|
+
const pkgJsonPath = path9.join(packedDir, "package.json");
|
|
20713
|
+
if (fs9.existsSync(pkgJsonPath)) {
|
|
20662
20714
|
try {
|
|
20663
|
-
const pkgJson = JSON.parse(
|
|
20715
|
+
const pkgJson = JSON.parse(fs9.readFileSync(pkgJsonPath, "utf-8"));
|
|
20664
20716
|
if (pkgJson.standardagent?.entryAgents) {
|
|
20665
20717
|
return {
|
|
20666
20718
|
packageId: pkgJson.name || pkgIdentifier,
|
|
@@ -20701,18 +20753,18 @@ var UnpackingService = class {
|
|
|
20701
20753
|
* Check if a file exists.
|
|
20702
20754
|
*/
|
|
20703
20755
|
fileExists(filePath) {
|
|
20704
|
-
if (
|
|
20756
|
+
if (fs9.existsSync(filePath)) {
|
|
20705
20757
|
return true;
|
|
20706
20758
|
}
|
|
20707
20759
|
const withoutExt = filePath.replace(/\.(ts|js)$/, "");
|
|
20708
|
-
return
|
|
20760
|
+
return fs9.existsSync(`${withoutExt}.ts`) || fs9.existsSync(`${withoutExt}.js`);
|
|
20709
20761
|
}
|
|
20710
20762
|
/**
|
|
20711
20763
|
* Recursively delete a directory.
|
|
20712
20764
|
*/
|
|
20713
20765
|
deleteDirectory(dirPath) {
|
|
20714
|
-
if (
|
|
20715
|
-
|
|
20766
|
+
if (fs9.existsSync(dirPath)) {
|
|
20767
|
+
fs9.rmSync(dirPath, { recursive: true, force: true });
|
|
20716
20768
|
}
|
|
20717
20769
|
}
|
|
20718
20770
|
/**
|
|
@@ -20788,8 +20840,8 @@ var NpmPublishService = class {
|
|
|
20788
20840
|
error: "Registry URL must use HTTPS"
|
|
20789
20841
|
};
|
|
20790
20842
|
}
|
|
20791
|
-
const pkgJsonPath =
|
|
20792
|
-
if (!
|
|
20843
|
+
const pkgJsonPath = path9.join(packageDir, "package.json");
|
|
20844
|
+
if (!fs9.existsSync(pkgJsonPath)) {
|
|
20793
20845
|
return {
|
|
20794
20846
|
success: false,
|
|
20795
20847
|
output: "",
|
|
@@ -20799,7 +20851,7 @@ var NpmPublishService = class {
|
|
|
20799
20851
|
let packageName;
|
|
20800
20852
|
let version;
|
|
20801
20853
|
try {
|
|
20802
|
-
const pkgJson = JSON.parse(
|
|
20854
|
+
const pkgJson = JSON.parse(fs9.readFileSync(pkgJsonPath, "utf-8"));
|
|
20803
20855
|
packageName = pkgJson.name;
|
|
20804
20856
|
version = pkgJson.version;
|
|
20805
20857
|
} catch (e) {
|
|
@@ -20809,13 +20861,13 @@ var NpmPublishService = class {
|
|
|
20809
20861
|
error: `Failed to read package.json: ${e instanceof Error ? e.message : String(e)}`
|
|
20810
20862
|
};
|
|
20811
20863
|
}
|
|
20812
|
-
const npmrcPath =
|
|
20864
|
+
const npmrcPath = path9.join(packageDir, ".npmrc");
|
|
20813
20865
|
const registryHost = new URL(registry).host;
|
|
20814
20866
|
const npmrcContent = `//${registryHost}/:_authToken=${token}
|
|
20815
20867
|
registry=${registry}
|
|
20816
20868
|
`;
|
|
20817
20869
|
try {
|
|
20818
|
-
|
|
20870
|
+
fs9.writeFileSync(npmrcPath, npmrcContent, { mode: 384 });
|
|
20819
20871
|
const args = ["publish"];
|
|
20820
20872
|
if (dryRun) {
|
|
20821
20873
|
args.push("--dry-run");
|
|
@@ -20847,8 +20899,8 @@ registry=${registry}
|
|
|
20847
20899
|
};
|
|
20848
20900
|
} finally {
|
|
20849
20901
|
try {
|
|
20850
|
-
if (
|
|
20851
|
-
|
|
20902
|
+
if (fs9.existsSync(npmrcPath)) {
|
|
20903
|
+
fs9.unlinkSync(npmrcPath);
|
|
20852
20904
|
}
|
|
20853
20905
|
} catch {
|
|
20854
20906
|
}
|
|
@@ -20941,7 +20993,7 @@ async function handlePackingApiRequest(context) {
|
|
|
20941
20993
|
const body = await parseRequestBody(req);
|
|
20942
20994
|
const packingService = new PackingService();
|
|
20943
20995
|
const rootDir = process.cwd();
|
|
20944
|
-
const outputDir =
|
|
20996
|
+
const outputDir = path9__default.join(rootDir, "agents", "packed");
|
|
20945
20997
|
const result = await packingService.pack({
|
|
20946
20998
|
agentName,
|
|
20947
20999
|
rootDir,
|
|
@@ -20994,8 +21046,8 @@ async function handlePackingApiRequest(context) {
|
|
|
20994
21046
|
res.end(JSON.stringify({ error: "Cannot delete npm packages. Use npm uninstall instead." }));
|
|
20995
21047
|
return true;
|
|
20996
21048
|
}
|
|
20997
|
-
const
|
|
20998
|
-
|
|
21049
|
+
const fs19 = await import('fs');
|
|
21050
|
+
fs19.rmSync(pkg.path, { recursive: true, force: true });
|
|
20999
21051
|
await reloadAllAgentModules(context);
|
|
21000
21052
|
res.statusCode = 200;
|
|
21001
21053
|
res.setHeader("Content-Type", "application/json");
|
|
@@ -21023,8 +21075,8 @@ async function handlePackingApiRequest(context) {
|
|
|
21023
21075
|
return true;
|
|
21024
21076
|
}
|
|
21025
21077
|
const { spawn } = await import('child_process');
|
|
21026
|
-
const parentDir =
|
|
21027
|
-
const dirName =
|
|
21078
|
+
const parentDir = path9__default.dirname(pkg.path);
|
|
21079
|
+
const dirName = path9__default.basename(pkg.path);
|
|
21028
21080
|
res.setHeader("Content-Type", "application/gzip");
|
|
21029
21081
|
res.setHeader("Content-Disposition", `attachment; filename="${packageId}.tar.gz"`);
|
|
21030
21082
|
const tar = spawn("tar", ["-czf", "-", "-C", parentDir, dirName]);
|
|
@@ -21078,18 +21130,19 @@ async function handlePackingApiRequest(context) {
|
|
|
21078
21130
|
if (packPublishMatch && method === "POST") {
|
|
21079
21131
|
try {
|
|
21080
21132
|
const packageId = decodeURIComponent(packPublishMatch[1]);
|
|
21133
|
+
assertSafePackageIdentifier(packageId);
|
|
21081
21134
|
const body = await parseRequestBody(req);
|
|
21082
21135
|
const rootDir = process.cwd();
|
|
21083
|
-
const packedDir =
|
|
21084
|
-
let packageDir =
|
|
21085
|
-
if (!
|
|
21086
|
-
if (!
|
|
21136
|
+
const packedDir = path9__default.join(rootDir, "agents", "packed");
|
|
21137
|
+
let packageDir = resolvePathWithin(packedDir, packageId);
|
|
21138
|
+
if (!fs9__default.existsSync(packageDir)) {
|
|
21139
|
+
if (!fs9__default.existsSync(packedDir)) {
|
|
21087
21140
|
res.statusCode = 400;
|
|
21088
21141
|
res.setHeader("Content-Type", "application/json");
|
|
21089
21142
|
res.end(JSON.stringify({ error: "No packed packages found. Pack the agent first." }));
|
|
21090
21143
|
return true;
|
|
21091
21144
|
}
|
|
21092
|
-
const dirs =
|
|
21145
|
+
const dirs = fs9__default.readdirSync(packedDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
21093
21146
|
const matchingDir = dirs.find(
|
|
21094
21147
|
(d) => d === packageId || d === `standardagent-${packageId}` || d === `standardagent-${packageId.replace(/_/g, "-")}`
|
|
21095
21148
|
);
|
|
@@ -21101,14 +21154,14 @@ async function handlePackingApiRequest(context) {
|
|
|
21101
21154
|
}));
|
|
21102
21155
|
return true;
|
|
21103
21156
|
}
|
|
21104
|
-
packageDir =
|
|
21157
|
+
packageDir = resolvePathWithin(packedDir, matchingDir);
|
|
21105
21158
|
}
|
|
21106
21159
|
let token = body.token || process.env.NPM_TOKEN;
|
|
21107
21160
|
let tokenSource = body.token ? "provided" : "environment";
|
|
21108
21161
|
if (!token) {
|
|
21109
|
-
const devVarsPath =
|
|
21110
|
-
if (
|
|
21111
|
-
const devVars =
|
|
21162
|
+
const devVarsPath = path9__default.join(rootDir, ".dev.vars");
|
|
21163
|
+
if (fs9__default.existsSync(devVarsPath)) {
|
|
21164
|
+
const devVars = fs9__default.readFileSync(devVarsPath, "utf-8");
|
|
21112
21165
|
const match = devVars.match(/^NPM_TOKEN=(.+)$/m);
|
|
21113
21166
|
if (match) {
|
|
21114
21167
|
token = match[1].trim();
|
|
@@ -21219,27 +21272,94 @@ async function handlePackingApiRequest(context) {
|
|
|
21219
21272
|
return false;
|
|
21220
21273
|
}
|
|
21221
21274
|
|
|
21275
|
+
// src/routing/access-policy.ts
|
|
21276
|
+
var PUBLIC_ROUTES = /* @__PURE__ */ new Set([
|
|
21277
|
+
"/api/auth/bootstrap",
|
|
21278
|
+
"/api/auth/login",
|
|
21279
|
+
"/api/auth/config",
|
|
21280
|
+
"/api/auth/brolly-control",
|
|
21281
|
+
"/api/auth/platform-cleanup",
|
|
21282
|
+
"/api/auth/platform-replica",
|
|
21283
|
+
"/api/auth/sa/start",
|
|
21284
|
+
"/api/auth/sa/callback",
|
|
21285
|
+
"/api/config",
|
|
21286
|
+
"/api/auth/oauth/github",
|
|
21287
|
+
"/api/auth/oauth/google",
|
|
21288
|
+
"/api/auth/oauth/github/callback",
|
|
21289
|
+
"/api/auth/oauth/google/callback",
|
|
21290
|
+
"/api/hooks"
|
|
21291
|
+
]);
|
|
21292
|
+
function isProviderIconRoute(routePath) {
|
|
21293
|
+
return /^\/api\/providers\/[^/]+\/icon$/.test(routePath);
|
|
21294
|
+
}
|
|
21295
|
+
function isHostedInstance(env) {
|
|
21296
|
+
const value = env?.STANDARD_AGENTS_HOSTED;
|
|
21297
|
+
if (typeof value === "string") {
|
|
21298
|
+
const normalized = value.trim().toLowerCase();
|
|
21299
|
+
return normalized !== "" && normalized !== "0" && normalized !== "false";
|
|
21300
|
+
}
|
|
21301
|
+
return Boolean(value);
|
|
21302
|
+
}
|
|
21303
|
+
function isTrustedLocalDevelopmentRequest(request, env) {
|
|
21304
|
+
if (isHostedInstance(env)) return false;
|
|
21305
|
+
let hostname;
|
|
21306
|
+
try {
|
|
21307
|
+
hostname = new URL(request.url).hostname.toLowerCase();
|
|
21308
|
+
} catch {
|
|
21309
|
+
return false;
|
|
21310
|
+
}
|
|
21311
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname.endsWith(".localhost") || hostname.endsWith(".orb.local");
|
|
21312
|
+
}
|
|
21313
|
+
function isPublicApiRoute(routePath, request, env) {
|
|
21314
|
+
if (PUBLIC_ROUTES.has(routePath)) return true;
|
|
21315
|
+
if (routePath === "/api/auth/device/start" || routePath.startsWith("/api/auth/device/")) {
|
|
21316
|
+
return true;
|
|
21317
|
+
}
|
|
21318
|
+
if (isProviderIconRoute(routePath)) {
|
|
21319
|
+
return true;
|
|
21320
|
+
}
|
|
21321
|
+
if (!isTrustedLocalDevelopmentRequest(request, env)) return false;
|
|
21322
|
+
return routePath === "/api/threads" || routePath.startsWith("/api/threads/") || routePath === "/api/platform" || routePath.startsWith("/api/platform/") || routePath === "/api/platform-session" || routePath.startsWith("/api/platform-session/") || routePath === "/api/platform-auth" || routePath.startsWith("/api/platform-auth/");
|
|
21323
|
+
}
|
|
21324
|
+
function isAdminOnlyApiRoute(routePath, method = "GET") {
|
|
21325
|
+
if (routePath === "/api/skills" || routePath.startsWith("/api/skills/")) return true;
|
|
21326
|
+
if (routePath === "/api/pack" || routePath.startsWith("/api/pack/")) return true;
|
|
21327
|
+
if (routePath === "/api/unpack" || routePath.startsWith("/api/unpack/")) return true;
|
|
21328
|
+
if (routePath === "/api/prompts" || routePath.startsWith("/api/prompts/")) return true;
|
|
21329
|
+
if (routePath === "/api/tools" || routePath.startsWith("/api/tools/")) return true;
|
|
21330
|
+
if (routePath === "/api/models" || routePath.startsWith("/api/models/")) return true;
|
|
21331
|
+
if (routePath === "/api/providers") return true;
|
|
21332
|
+
if (routePath.startsWith("/api/providers/")) {
|
|
21333
|
+
return !isProviderIconRoute(routePath);
|
|
21334
|
+
}
|
|
21335
|
+
if (routePath.startsWith("/api/agents/")) {
|
|
21336
|
+
return !/^\/api\/agents\/[^/]+\/tenvs$/.test(routePath);
|
|
21337
|
+
}
|
|
21338
|
+
if (routePath === "/api/agents" && method.toUpperCase() !== "GET") return true;
|
|
21339
|
+
return false;
|
|
21340
|
+
}
|
|
21341
|
+
|
|
21222
21342
|
// src/plugin/dev-middleware.ts
|
|
21223
21343
|
function readRawRequestBody(req) {
|
|
21224
|
-
return new Promise((
|
|
21344
|
+
return new Promise((resolve3, reject) => {
|
|
21225
21345
|
const chunks = [];
|
|
21226
21346
|
req.on("data", (chunk) => {
|
|
21227
21347
|
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
21228
21348
|
});
|
|
21229
21349
|
req.on("end", () => {
|
|
21230
|
-
|
|
21350
|
+
resolve3(chunks.length > 0 ? Buffer.concat(chunks) : void 0);
|
|
21231
21351
|
});
|
|
21232
21352
|
req.on("error", reject);
|
|
21233
21353
|
});
|
|
21234
21354
|
}
|
|
21235
21355
|
function resolveContainedFile(baseDir, requestPath) {
|
|
21236
|
-
const resolvedBase =
|
|
21237
|
-
const resolved =
|
|
21238
|
-
if (resolved !== resolvedBase && !resolved.startsWith(resolvedBase +
|
|
21356
|
+
const resolvedBase = path9__default.resolve(baseDir);
|
|
21357
|
+
const resolved = path9__default.resolve(resolvedBase, `.${path9__default.sep}${requestPath.replace(/^\/+/, "")}`);
|
|
21358
|
+
if (resolved !== resolvedBase && !resolved.startsWith(resolvedBase + path9__default.sep)) {
|
|
21239
21359
|
return null;
|
|
21240
21360
|
}
|
|
21241
21361
|
try {
|
|
21242
|
-
return
|
|
21362
|
+
return fs9__default.existsSync(resolved) && fs9__default.statSync(resolved).isFile() ? resolved : null;
|
|
21243
21363
|
} catch {
|
|
21244
21364
|
return null;
|
|
21245
21365
|
}
|
|
@@ -21289,6 +21409,21 @@ function createDevMiddleware(server, context) {
|
|
|
21289
21409
|
return;
|
|
21290
21410
|
}
|
|
21291
21411
|
}
|
|
21412
|
+
const routePath = new URL(pathWithoutMount, "http://localhost").pathname;
|
|
21413
|
+
let trustedLocalHost = false;
|
|
21414
|
+
try {
|
|
21415
|
+
trustedLocalHost = isTrustedLocalDevelopmentRequest(
|
|
21416
|
+
new Request(`http://${req.headers.host || "invalid.remote"}${routePath}`),
|
|
21417
|
+
{}
|
|
21418
|
+
);
|
|
21419
|
+
} catch {
|
|
21420
|
+
}
|
|
21421
|
+
if (isAdminOnlyApiRoute(routePath, method) && !trustedLocalHost) {
|
|
21422
|
+
res.statusCode = 403;
|
|
21423
|
+
res.setHeader("Content-Type", "application/json");
|
|
21424
|
+
res.end(JSON.stringify({ error: "Authoring APIs are available only from local development hosts" }));
|
|
21425
|
+
return;
|
|
21426
|
+
}
|
|
21292
21427
|
if (await handleConfigApiRequest({
|
|
21293
21428
|
req,
|
|
21294
21429
|
res,
|
|
@@ -21378,19 +21513,19 @@ function createDevMiddleware(server, context) {
|
|
|
21378
21513
|
const clientPath = pathWithoutMount.startsWith("/agents/") ? pathWithoutMount.slice("/agents".length) || "/" : pathWithoutMount;
|
|
21379
21514
|
const isStaticAsset = clientPath.startsWith("/assets/") || clientPath.startsWith("/vendor.js") || clientPath.startsWith("/vue.js") || clientPath.startsWith("/monaco.js") || clientPath.startsWith("/index.js") || clientPath.startsWith("/index.css") || clientPath.match(/\.(js|css|png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot|ico)$/);
|
|
21380
21515
|
{
|
|
21381
|
-
const currentDir =
|
|
21516
|
+
const currentDir = path9__default.dirname(fileURLToPath(import.meta.url));
|
|
21382
21517
|
const isInDist = currentDir.endsWith("dist");
|
|
21383
|
-
const clientDir =
|
|
21518
|
+
const clientDir = path9__default.resolve(
|
|
21384
21519
|
currentDir,
|
|
21385
21520
|
isInDist ? "./client" : "../dist/client"
|
|
21386
21521
|
);
|
|
21387
21522
|
let filePath;
|
|
21388
21523
|
if (isStaticAsset) {
|
|
21389
21524
|
const cleanUrl = clientPath.split("?")[0];
|
|
21390
|
-
filePath =
|
|
21391
|
-
if (!
|
|
21525
|
+
filePath = path9__default.join(clientDir, cleanUrl);
|
|
21526
|
+
if (!fs9__default.existsSync(filePath)) {
|
|
21392
21527
|
const projectPublicFile = resolveContainedFile(
|
|
21393
|
-
|
|
21528
|
+
path9__default.resolve(server.config.root, "public"),
|
|
21394
21529
|
cleanUrl
|
|
21395
21530
|
);
|
|
21396
21531
|
if (projectPublicFile) {
|
|
@@ -21398,12 +21533,12 @@ function createDevMiddleware(server, context) {
|
|
|
21398
21533
|
}
|
|
21399
21534
|
}
|
|
21400
21535
|
} else {
|
|
21401
|
-
filePath =
|
|
21536
|
+
filePath = path9__default.join(clientDir, "index.html");
|
|
21402
21537
|
}
|
|
21403
21538
|
try {
|
|
21404
|
-
if (
|
|
21405
|
-
let content =
|
|
21406
|
-
const ext =
|
|
21539
|
+
if (fs9__default.existsSync(filePath)) {
|
|
21540
|
+
let content = fs9__default.readFileSync(filePath);
|
|
21541
|
+
const ext = path9__default.extname(filePath).toLowerCase();
|
|
21407
21542
|
if (ext === ".html") {
|
|
21408
21543
|
content = Buffer.from(
|
|
21409
21544
|
injectUiConfigIntoHtml(content.toString())
|
|
@@ -21443,7 +21578,7 @@ async function loadBuilderVirtualModule(context) {
|
|
|
21443
21578
|
const effects = await scanEffectsDirectory(effectsDir);
|
|
21444
21579
|
const toAbsolutePath = (relativePath) => {
|
|
21445
21580
|
if (relativePath.startsWith("./")) {
|
|
21446
|
-
return
|
|
21581
|
+
return path9__default.resolve(process.cwd(), relativePath).replace(/\\/g, "/");
|
|
21447
21582
|
}
|
|
21448
21583
|
return relativePath;
|
|
21449
21584
|
};
|
|
@@ -21715,7 +21850,7 @@ async function loadRegistryVirtualModule(context) {
|
|
|
21715
21850
|
const effects = await scanEffectsDirectory(effectsDir);
|
|
21716
21851
|
const toAbsolutePath = (relativePath) => {
|
|
21717
21852
|
if (relativePath.startsWith("./")) {
|
|
21718
|
-
return
|
|
21853
|
+
return path9__default.resolve(process.cwd(), relativePath).replace(/\\/g, "/");
|
|
21719
21854
|
}
|
|
21720
21855
|
return relativePath;
|
|
21721
21856
|
};
|
|
@@ -21743,23 +21878,23 @@ async function loadRegistryVirtualModule(context) {
|
|
|
21743
21878
|
const absPath = toAbsolutePath(importPath);
|
|
21744
21879
|
return ` "${name}": async () => (await import("${absPath}")).default,`;
|
|
21745
21880
|
}).join("\n");
|
|
21746
|
-
const packedDir =
|
|
21881
|
+
const packedDir = path9__default.resolve(process.cwd(), "agents/packed");
|
|
21747
21882
|
const packedPackages = [];
|
|
21748
|
-
if (
|
|
21883
|
+
if (fs9__default.existsSync(packedDir)) {
|
|
21749
21884
|
console.log(`[vite-plugin-agent] Scanning packed directory: ${packedDir}`);
|
|
21750
21885
|
const packageDirs = discoverPackedPackageDirectories(packedDir);
|
|
21751
21886
|
console.log(`[vite-plugin-agent] Found package dirs: ${packageDirs.join(", ")}`);
|
|
21752
21887
|
for (const pkgPath of packageDirs) {
|
|
21753
|
-
const pkgJsonPath =
|
|
21754
|
-
if (
|
|
21888
|
+
const pkgJsonPath = path9__default.join(pkgPath, "package.json");
|
|
21889
|
+
if (fs9__default.existsSync(pkgJsonPath)) {
|
|
21755
21890
|
try {
|
|
21756
|
-
const pkgJson = JSON.parse(
|
|
21891
|
+
const pkgJson = JSON.parse(fs9__default.readFileSync(pkgJsonPath, "utf-8"));
|
|
21757
21892
|
console.log(`[vite-plugin-agent] Loaded ${pkgPath} package.json, standardagent:`, pkgJson.standardagent);
|
|
21758
21893
|
if (!pkgJson.standardagent) {
|
|
21759
21894
|
continue;
|
|
21760
21895
|
}
|
|
21761
21896
|
const mainEntry = pkgJson.main || "./dist/index.js";
|
|
21762
|
-
const outputDir =
|
|
21897
|
+
const outputDir = path9__default.dirname(mainEntry).replace(/^\.\//, "");
|
|
21763
21898
|
const pkg = {
|
|
21764
21899
|
packageId: pkgJson.name,
|
|
21765
21900
|
version: pkgJson.version,
|
|
@@ -21877,7 +22012,7 @@ export function getVisibleToolNames() {
|
|
|
21877
22012
|
async function loadRoutesVirtualModule(context) {
|
|
21878
22013
|
const { threadApiDir, rou3Code, hmr } = context;
|
|
21879
22014
|
const threadRoutes = scanApiDirectory(threadApiDir);
|
|
21880
|
-
const toAbsolutePath = (inputPath) =>
|
|
22015
|
+
const toAbsolutePath = (inputPath) => path9__default.resolve(process.cwd(), inputPath).replace(/\\/g, "/");
|
|
21881
22016
|
const threadRouteCode = threadRoutes.map(({ method, route, importPath }) => {
|
|
21882
22017
|
const apiRoute = `/api/threads/:threadId${route}`;
|
|
21883
22018
|
return ` addRoute(
|
|
@@ -21888,20 +22023,20 @@ async function loadRoutesVirtualModule(context) {
|
|
|
21888
22023
|
);`;
|
|
21889
22024
|
}).join("\n");
|
|
21890
22025
|
const packedThreadRoutes = [];
|
|
21891
|
-
const packedDir =
|
|
22026
|
+
const packedDir = path9__default.resolve(process.cwd(), "agents/packed");
|
|
21892
22027
|
const packedPackageDirs = discoverPackedPackageDirectories(packedDir);
|
|
21893
22028
|
for (const packagePath of packedPackageDirs) {
|
|
21894
|
-
const packageJsonPath =
|
|
21895
|
-
if (!
|
|
22029
|
+
const packageJsonPath = path9__default.join(packagePath, "package.json");
|
|
22030
|
+
if (!fs9__default.existsSync(packageJsonPath)) {
|
|
21896
22031
|
continue;
|
|
21897
22032
|
}
|
|
21898
22033
|
try {
|
|
21899
|
-
const packageJson = JSON.parse(
|
|
22034
|
+
const packageJson = JSON.parse(fs9__default.readFileSync(packageJsonPath, "utf-8"));
|
|
21900
22035
|
if (!packageJson.standardagent) {
|
|
21901
22036
|
continue;
|
|
21902
22037
|
}
|
|
21903
22038
|
const mainEntry = packageJson.main || "./dist/index.js";
|
|
21904
|
-
const outputDir =
|
|
22039
|
+
const outputDir = path9__default.dirname(mainEntry).replace(/^\.\//, "");
|
|
21905
22040
|
const threadEndpoints = scanPackedThreadEndpoints(packagePath, outputDir);
|
|
21906
22041
|
for (const endpoint of threadEndpoints) {
|
|
21907
22042
|
const apiRoute = `/api/threads/:threadId${endpoint.route}`;
|
|
@@ -21935,98 +22070,16 @@ import { providers, providerNames, providerFactories } from "virtual:@standardag
|
|
|
21935
22070
|
import { prompts, promptNames } from "virtual:@standardagents-prompts";
|
|
21936
22071
|
import { agents, agentNames } from "virtual:@standardagents-agents";
|
|
21937
22072
|
import { registry } from "virtual:@standardagents-registry";
|
|
21938
|
-
import {
|
|
22073
|
+
import {
|
|
22074
|
+
requireAuth,
|
|
22075
|
+
createThreadEndpointHandler,
|
|
22076
|
+
canAccessThread,
|
|
22077
|
+
isHostedInstance,
|
|
22078
|
+
isPublicApiRoute,
|
|
22079
|
+
isAdminOnlyApiRoute,
|
|
22080
|
+
} from "@standardagents/builder/runtime";
|
|
21939
22081
|
import { isThreadEndpoint } from "@standardagents/spec";
|
|
21940
22082
|
|
|
21941
|
-
// Routes that don't require authentication
|
|
21942
|
-
const PUBLIC_ROUTES = [
|
|
21943
|
-
'/api/auth/bootstrap',
|
|
21944
|
-
'/api/auth/login',
|
|
21945
|
-
'/api/auth/config',
|
|
21946
|
-
'/api/auth/brolly-control',
|
|
21947
|
-
'/api/auth/platform-cleanup',
|
|
21948
|
-
'/api/auth/platform-replica',
|
|
21949
|
-
'/api/auth/sa/start', // Login with Standard Agents (OAuth) \u2014 unauthenticated entry
|
|
21950
|
-
'/api/auth/sa/callback', // OAuth callback (sets the session cookie)
|
|
21951
|
-
'/api/config',
|
|
21952
|
-
'/api/auth/oauth/github',
|
|
21953
|
-
'/api/auth/oauth/google',
|
|
21954
|
-
'/api/auth/oauth/github/callback',
|
|
21955
|
-
'/api/auth/oauth/google/callback',
|
|
21956
|
-
'/api/platform-auth/bootstrap',
|
|
21957
|
-
'/api/platform-auth/login',
|
|
21958
|
-
'/api/platform-auth/logout',
|
|
21959
|
-
'/api/platform-auth/me',
|
|
21960
|
-
'/api/hooks' // Hook metadata is safe to expose publicly
|
|
21961
|
-
];
|
|
21962
|
-
|
|
21963
|
-
// True when the platform deployed this instance (injects STANDARD_AGENTS_HOSTED).
|
|
21964
|
-
// Hosted instances are internet-reachable and multi-tenant, so the thread data
|
|
21965
|
-
// API and event/stream WebSockets must NOT be anonymously public the way they
|
|
21966
|
-
// are in single-user local dev \u2014 they require a session (admin) or API key (SDK).
|
|
21967
|
-
function isHostedInstance(env) {
|
|
21968
|
-
const value = env && env.STANDARD_AGENTS_HOSTED;
|
|
21969
|
-
if (typeof value === 'string') {
|
|
21970
|
-
const trimmed = value.trim().toLowerCase();
|
|
21971
|
-
return trimmed !== '' && trimmed !== '0' && trimmed !== 'false';
|
|
21972
|
-
}
|
|
21973
|
-
return Boolean(value);
|
|
21974
|
-
}
|
|
21975
|
-
|
|
21976
|
-
// Check if a route is public (no auth required)
|
|
21977
|
-
function isPublicRoute(routePath, hosted) {
|
|
21978
|
-
// Exact match for auth routes
|
|
21979
|
-
if (PUBLIC_ROUTES.includes(routePath)) {
|
|
21980
|
-
return true;
|
|
21981
|
-
}
|
|
21982
|
-
|
|
21983
|
-
// Thread routes (REST + message/log stream WebSockets) are public in local
|
|
21984
|
-
// single-user dev, but on a hosted deployment they require auth \u2014 requireAuth
|
|
21985
|
-
// accepts the admin's session (cookie or token) or the SDK's API key, so this
|
|
21986
|
-
// only blocks anonymous access to another tenant's threads/messages/files.
|
|
21987
|
-
if (!hosted && (routePath.startsWith('/api/threads/') || routePath === '/api/threads')) {
|
|
21988
|
-
return true;
|
|
21989
|
-
}
|
|
21990
|
-
|
|
21991
|
-
// Device-code CLI login: start/poll are public by design (possession of the
|
|
21992
|
-
// one-time code is the secret) and the approve page must reach its controller
|
|
21993
|
-
// even when anonymous so it can redirect the browser through the platform
|
|
21994
|
-
// login (the controller enforces session auth itself).
|
|
21995
|
-
if (routePath === '/api/auth/device/start' || routePath.startsWith('/api/auth/device/')) {
|
|
21996
|
-
return true;
|
|
21997
|
-
}
|
|
21998
|
-
|
|
21999
|
-
// Provider icon routes are public (used by <img src>)
|
|
22000
|
-
if (routePath.startsWith('/api/providers/') && routePath.includes('/icon')) {
|
|
22001
|
-
return true;
|
|
22002
|
-
}
|
|
22003
|
-
|
|
22004
|
-
// Platform proxy routes handle their own auth in local dev only.
|
|
22005
|
-
if (hosted && (routePath.startsWith('/api/platform/') || routePath === '/api/platform')) {
|
|
22006
|
-
return false;
|
|
22007
|
-
}
|
|
22008
|
-
if (routePath.startsWith('/api/platform/') || routePath === '/api/platform') {
|
|
22009
|
-
return true;
|
|
22010
|
-
}
|
|
22011
|
-
|
|
22012
|
-
// Platform session proxy and auth bridge are local-dev helpers only.
|
|
22013
|
-
if (hosted && (routePath.startsWith('/api/platform-session/') || routePath === '/api/platform-session')) {
|
|
22014
|
-
return false;
|
|
22015
|
-
}
|
|
22016
|
-
if (routePath.startsWith('/api/platform-session/') || routePath === '/api/platform-session') {
|
|
22017
|
-
return true;
|
|
22018
|
-
}
|
|
22019
|
-
|
|
22020
|
-
if (hosted && (routePath.startsWith('/api/platform-auth/') || routePath === '/api/platform-auth')) {
|
|
22021
|
-
return false;
|
|
22022
|
-
}
|
|
22023
|
-
if (routePath.startsWith('/api/platform-auth/') || routePath === '/api/platform-auth') {
|
|
22024
|
-
return true;
|
|
22025
|
-
}
|
|
22026
|
-
|
|
22027
|
-
return false;
|
|
22028
|
-
}
|
|
22029
|
-
|
|
22030
22083
|
function platformEndpoint(env) {
|
|
22031
22084
|
const configured =
|
|
22032
22085
|
env && (env.PLATFORM_ENDPOINT || env.STANDARD_AGENTS_PLATFORM_URL || env.PLATFORM_URL || env.STANDARD_AGENTS_PUBLIC_URL);
|
|
@@ -22169,7 +22222,7 @@ ${packedThreadRouteCode}
|
|
|
22169
22222
|
|
|
22170
22223
|
if (routeMatch) {
|
|
22171
22224
|
// Check if authentication is required for this route
|
|
22172
|
-
const publicRoute =
|
|
22225
|
+
const publicRoute = isPublicApiRoute(routePath, request, env);
|
|
22173
22226
|
const isApiRoute = routePath.startsWith('/api/');
|
|
22174
22227
|
|
|
22175
22228
|
let authContext = null;
|
|
@@ -22185,6 +22238,10 @@ ${packedThreadRouteCode}
|
|
|
22185
22238
|
|
|
22186
22239
|
authContext = authResult;
|
|
22187
22240
|
|
|
22241
|
+
if (isAdminOnlyApiRoute(routePath, request.method) && authContext.user.role !== 'admin') {
|
|
22242
|
+
return addCorsHeaders(Response.json({ error: 'Forbidden: Admin access required' }, { status: 403 }));
|
|
22243
|
+
}
|
|
22244
|
+
|
|
22188
22245
|
if (routePath.startsWith('/api/threads/')) {
|
|
22189
22246
|
// Packed and user thread endpoints reserve threadId for the owning
|
|
22190
22247
|
// thread while nested endpoint parameters may also be named id.
|
|
@@ -22198,7 +22255,7 @@ ${packedThreadRouteCode}
|
|
|
22198
22255
|
if (!thread) {
|
|
22199
22256
|
return addCorsHeaders(Response.json({ error: \`Thread not found: \${threadId}\` }, { status: 404 }));
|
|
22200
22257
|
}
|
|
22201
|
-
if (authContext
|
|
22258
|
+
if (!canAccessThread(authContext, thread)) {
|
|
22202
22259
|
return addCorsHeaders(Response.json({ error: "Forbidden: You don't have access to this thread" }, { status: 403 }));
|
|
22203
22260
|
}
|
|
22204
22261
|
}
|
|
@@ -22374,13 +22431,13 @@ ${hooksCode}
|
|
|
22374
22431
|
};`;
|
|
22375
22432
|
}
|
|
22376
22433
|
if (id === RESOLVED_VIRTUAL_CONFIG_ID) {
|
|
22377
|
-
const relativeToolsDir =
|
|
22378
|
-
const relativeHooksDir =
|
|
22379
|
-
const relativeApiDir =
|
|
22380
|
-
const relativeModelsDir =
|
|
22381
|
-
const relativeProvidersDir =
|
|
22382
|
-
const relativePromptsDir =
|
|
22383
|
-
const relativeAgentsDir =
|
|
22434
|
+
const relativeToolsDir = path9__default.relative(process.cwd(), toolsDir).replace(/\\/g, "/");
|
|
22435
|
+
const relativeHooksDir = path9__default.relative(process.cwd(), hooksDir).replace(/\\/g, "/");
|
|
22436
|
+
const relativeApiDir = path9__default.relative(process.cwd(), threadApiDir).replace(/\\/g, "/");
|
|
22437
|
+
const relativeModelsDir = path9__default.relative(process.cwd(), modelsDir).replace(/\\/g, "/");
|
|
22438
|
+
const relativeProvidersDir = path9__default.relative(process.cwd(), providersDir).replace(/\\/g, "/");
|
|
22439
|
+
const relativePromptsDir = path9__default.relative(process.cwd(), promptsDir).replace(/\\/g, "/");
|
|
22440
|
+
const relativeAgentsDir = path9__default.relative(process.cwd(), agentsDir).replace(/\\/g, "/");
|
|
22384
22441
|
return `// Virtual agent config module
|
|
22385
22442
|
export const config = {
|
|
22386
22443
|
toolsDir: "${relativeToolsDir}",
|
|
@@ -22597,14 +22654,14 @@ var packingDeps = [
|
|
|
22597
22654
|
"typescript"
|
|
22598
22655
|
];
|
|
22599
22656
|
function createPluginViteConfig(pluginModuleUrl) {
|
|
22600
|
-
const currentDir =
|
|
22657
|
+
const currentDir = path9__default.dirname(fileURLToPath(pluginModuleUrl));
|
|
22601
22658
|
const isInDist = currentDir.endsWith("dist");
|
|
22602
|
-
const builderClientDir =
|
|
22659
|
+
const builderClientDir = path9__default.resolve(
|
|
22603
22660
|
currentDir,
|
|
22604
22661
|
isInDist ? "./client" : "../dist/client"
|
|
22605
22662
|
);
|
|
22606
22663
|
return {
|
|
22607
|
-
publicDir:
|
|
22664
|
+
publicDir: fs9__default.existsSync(builderClientDir) ? builderClientDir : void 0,
|
|
22608
22665
|
build: {
|
|
22609
22666
|
rollupOptions: {
|
|
22610
22667
|
external: [...packingDeps]
|
|
@@ -22751,24 +22808,24 @@ function applyPluginEnvironmentConfig(config) {
|
|
|
22751
22808
|
|
|
22752
22809
|
// src/plugin.ts
|
|
22753
22810
|
function agentbuilder(options = {}) {
|
|
22754
|
-
const toolsDir = options.toolsDir ?
|
|
22755
|
-
const hooksDir = options.hooksDir ?
|
|
22756
|
-
const threadApiDir = options.apiDir ?
|
|
22757
|
-
const modelsDir = options.modelsDir ?
|
|
22758
|
-
const providersDir = options.providersDir ?
|
|
22759
|
-
const promptsDir = options.promptsDir ?
|
|
22760
|
-
const agentsDir = options.agentsDir ?
|
|
22761
|
-
const effectsDir = options.effectsDir ?
|
|
22762
|
-
const usersDir = options.usersDir ?
|
|
22763
|
-
const outputDir =
|
|
22764
|
-
const generatedWorkerEntry =
|
|
22811
|
+
const toolsDir = options.toolsDir ? path9__default.resolve(process.cwd(), options.toolsDir) : path9__default.resolve(process.cwd(), "agents/tools");
|
|
22812
|
+
const hooksDir = options.hooksDir ? path9__default.resolve(process.cwd(), options.hooksDir) : path9__default.resolve(process.cwd(), "agents/hooks");
|
|
22813
|
+
const threadApiDir = options.apiDir ? path9__default.resolve(process.cwd(), options.apiDir) : path9__default.resolve(process.cwd(), "agents/api");
|
|
22814
|
+
const modelsDir = options.modelsDir ? path9__default.resolve(process.cwd(), options.modelsDir) : path9__default.resolve(process.cwd(), "agents/models");
|
|
22815
|
+
const providersDir = options.providersDir ? path9__default.resolve(process.cwd(), options.providersDir) : path9__default.resolve(process.cwd(), "agents/providers");
|
|
22816
|
+
const promptsDir = options.promptsDir ? path9__default.resolve(process.cwd(), options.promptsDir) : path9__default.resolve(process.cwd(), "agents/prompts");
|
|
22817
|
+
const agentsDir = options.agentsDir ? path9__default.resolve(process.cwd(), options.agentsDir) : path9__default.resolve(process.cwd(), "agents/agents");
|
|
22818
|
+
const effectsDir = options.effectsDir ? path9__default.resolve(process.cwd(), options.effectsDir) : path9__default.resolve(process.cwd(), "agents/effects");
|
|
22819
|
+
const usersDir = options.usersDir ? path9__default.resolve(process.cwd(), options.usersDir) : path9__default.resolve(process.cwd(), "agents/users");
|
|
22820
|
+
const outputDir = path9__default.resolve(process.cwd(), ".agents");
|
|
22821
|
+
const generatedWorkerEntry = path9__default.join(outputDir, "worker.ts");
|
|
22765
22822
|
const isProviderPackageInstalled = (packageName) => {
|
|
22766
22823
|
let dir = process.cwd();
|
|
22767
22824
|
for (; ; ) {
|
|
22768
|
-
if (
|
|
22825
|
+
if (fs9__default.existsSync(path9__default.join(dir, "node_modules", packageName, "package.json"))) {
|
|
22769
22826
|
return true;
|
|
22770
22827
|
}
|
|
22771
|
-
const parent =
|
|
22828
|
+
const parent = path9__default.dirname(dir);
|
|
22772
22829
|
if (parent === dir) return false;
|
|
22773
22830
|
dir = parent;
|
|
22774
22831
|
}
|
|
@@ -22803,17 +22860,17 @@ export default {
|
|
|
22803
22860
|
|
|
22804
22861
|
export { CodeExecutionBridge, DurableAgentBuilder, DurableThread, ThreadWatchdog, DurableUserHub };
|
|
22805
22862
|
`;
|
|
22806
|
-
|
|
22807
|
-
if (!
|
|
22808
|
-
|
|
22863
|
+
fs9__default.mkdirSync(outputDir, { recursive: true });
|
|
22864
|
+
if (!fs9__default.existsSync(generatedWorkerEntry) || fs9__default.readFileSync(generatedWorkerEntry, "utf-8") !== content) {
|
|
22865
|
+
fs9__default.writeFileSync(generatedWorkerEntry, content);
|
|
22809
22866
|
}
|
|
22810
22867
|
}
|
|
22811
22868
|
const __filename = fileURLToPath(import.meta.url);
|
|
22812
|
-
const __dirname =
|
|
22813
|
-
const rou3Path =
|
|
22869
|
+
const __dirname = path9__default.dirname(__filename);
|
|
22870
|
+
const rou3Path = path9__default.join(__dirname, "../dist/rou3.js");
|
|
22814
22871
|
let rou3Code = "";
|
|
22815
22872
|
try {
|
|
22816
|
-
rou3Code =
|
|
22873
|
+
rou3Code = fs9__default.readFileSync(rou3Path, "utf-8").replace(/^export \{[^}]+\};?\s*$/gm, "").replace(/\/\/# sourceMappingURL=.+$/gm, "").trim();
|
|
22817
22874
|
} catch (err) {
|
|
22818
22875
|
console.warn("[vite-plugin-agent] Could not read rou3.js for inlining:", err);
|
|
22819
22876
|
}
|
|
@@ -22856,7 +22913,7 @@ export { CodeExecutionBridge, DurableAgentBuilder, DurableThread, ThreadWatchdog
|
|
|
22856
22913
|
sourceDirs,
|
|
22857
22914
|
regenerateTypes
|
|
22858
22915
|
};
|
|
22859
|
-
const workerEntry =
|
|
22916
|
+
const workerEntry = path9__default.relative(process.cwd(), generatedWorkerEntry).split(path9__default.sep).join("/");
|
|
22860
22917
|
const corePlugin = {
|
|
22861
22918
|
name: "vite-plugin-agent",
|
|
22862
22919
|
enforce: "pre",
|
|
@@ -22931,28 +22988,28 @@ export { CodeExecutionBridge, DurableAgentBuilder, DurableThread, ThreadWatchdog
|
|
|
22931
22988
|
},
|
|
22932
22989
|
writeBundle(options2, bundle) {
|
|
22933
22990
|
const outDir = options2.dir || "dist";
|
|
22934
|
-
const mountDir =
|
|
22935
|
-
const currentDir =
|
|
22991
|
+
const mountDir = path9__default.join(outDir, "../client");
|
|
22992
|
+
const currentDir = path9__default.dirname(fileURLToPath(import.meta.url));
|
|
22936
22993
|
const isInDist = currentDir.endsWith("dist");
|
|
22937
|
-
const clientDir =
|
|
22994
|
+
const clientDir = path9__default.resolve(
|
|
22938
22995
|
currentDir,
|
|
22939
22996
|
isInDist ? "./client" : "../dist/client"
|
|
22940
22997
|
);
|
|
22941
|
-
if (!
|
|
22998
|
+
if (!fs9__default.existsSync(clientDir)) {
|
|
22942
22999
|
console.warn(`[agentbuilder] Client directory not found at ${clientDir}`);
|
|
22943
23000
|
return;
|
|
22944
23001
|
}
|
|
22945
|
-
|
|
23002
|
+
fs9__default.mkdirSync(mountDir, { recursive: true });
|
|
22946
23003
|
function copyRecursive(src, dest) {
|
|
22947
|
-
const entries =
|
|
23004
|
+
const entries = fs9__default.readdirSync(src, { withFileTypes: true });
|
|
22948
23005
|
for (const entry of entries) {
|
|
22949
|
-
const srcPath =
|
|
22950
|
-
const destPath =
|
|
23006
|
+
const srcPath = path9__default.join(src, entry.name);
|
|
23007
|
+
const destPath = path9__default.join(dest, entry.name);
|
|
22951
23008
|
if (entry.isDirectory()) {
|
|
22952
|
-
|
|
23009
|
+
fs9__default.mkdirSync(destPath, { recursive: true });
|
|
22953
23010
|
copyRecursive(srcPath, destPath);
|
|
22954
23011
|
} else {
|
|
22955
|
-
let content =
|
|
23012
|
+
let content = fs9__default.readFileSync(srcPath);
|
|
22956
23013
|
if (entry.name === "index.html") {
|
|
22957
23014
|
const configScript = `<script>window.__AGENTBUILDER_CONFIG__ = {};</script>`;
|
|
22958
23015
|
let htmlContent = content.toString();
|
|
@@ -22960,27 +23017,27 @@ export { CodeExecutionBridge, DurableAgentBuilder, DurableThread, ThreadWatchdog
|
|
|
22960
23017
|
htmlContent = htmlContent.replace("</head>", `${configScript}</head>`);
|
|
22961
23018
|
content = Buffer.from(htmlContent);
|
|
22962
23019
|
}
|
|
22963
|
-
|
|
23020
|
+
fs9__default.writeFileSync(destPath, content);
|
|
22964
23021
|
}
|
|
22965
23022
|
}
|
|
22966
23023
|
}
|
|
22967
23024
|
copyRecursive(clientDir, mountDir);
|
|
22968
|
-
const projectPublicDir =
|
|
22969
|
-
if (
|
|
23025
|
+
const projectPublicDir = path9__default.resolve(process.cwd(), "public");
|
|
23026
|
+
if (fs9__default.existsSync(projectPublicDir)) {
|
|
22970
23027
|
let copyPublicRecursive2 = function(src, dest) {
|
|
22971
|
-
const entries =
|
|
23028
|
+
const entries = fs9__default.readdirSync(src, { withFileTypes: true });
|
|
22972
23029
|
for (const entry of entries) {
|
|
22973
|
-
const srcPath =
|
|
22974
|
-
const destPath =
|
|
23030
|
+
const srcPath = path9__default.join(src, entry.name);
|
|
23031
|
+
const destPath = path9__default.join(dest, entry.name);
|
|
22975
23032
|
if (entry.isDirectory()) {
|
|
22976
|
-
|
|
23033
|
+
fs9__default.mkdirSync(destPath, { recursive: true });
|
|
22977
23034
|
copyPublicRecursive2(srcPath, destPath);
|
|
22978
|
-
} else if (
|
|
23035
|
+
} else if (fs9__default.existsSync(destPath)) {
|
|
22979
23036
|
console.warn(
|
|
22980
23037
|
`[agentbuilder] Skipping public/ file that collides with a built UI asset: ${destPath}`
|
|
22981
23038
|
);
|
|
22982
23039
|
} else {
|
|
22983
|
-
|
|
23040
|
+
fs9__default.copyFileSync(srcPath, destPath);
|
|
22984
23041
|
}
|
|
22985
23042
|
}
|
|
22986
23043
|
};
|
|
@@ -23273,6 +23330,17 @@ async function requireAdmin(request, env) {
|
|
|
23273
23330
|
return result;
|
|
23274
23331
|
}
|
|
23275
23332
|
|
|
23333
|
+
// src/utils/permissions.ts
|
|
23334
|
+
function canAccessThread(auth, thread) {
|
|
23335
|
+
if (auth.user.role === "admin") {
|
|
23336
|
+
return true;
|
|
23337
|
+
}
|
|
23338
|
+
if (thread.user_id === null) {
|
|
23339
|
+
return false;
|
|
23340
|
+
}
|
|
23341
|
+
return thread.user_id === auth.user.id;
|
|
23342
|
+
}
|
|
23343
|
+
|
|
23276
23344
|
// src/index.ts
|
|
23277
23345
|
init_client_forwarding();
|
|
23278
23346
|
|
|
@@ -24953,6 +25021,18 @@ function messageTimestampSeconds(message) {
|
|
|
24953
25021
|
return Math.floor(micros / (1e3 * TIMESTAMP_MULTIPLIER));
|
|
24954
25022
|
}
|
|
24955
25023
|
|
|
25024
|
+
// src/events/access.ts
|
|
25025
|
+
var EVENT_STREAM_USER_ID_HEADER = "X-Standard-Agents-Event-User-Id";
|
|
25026
|
+
var EVENT_STREAM_SCOPE_HEADER = "X-Standard-Agents-Event-Scope";
|
|
25027
|
+
function isEventSocketAttachment(value) {
|
|
25028
|
+
if (!value || typeof value !== "object") return false;
|
|
25029
|
+
const attachment = value;
|
|
25030
|
+
return attachment.channel === "events" && (attachment.scope === "user" || attachment.scope === "all") && typeof attachment.userId === "string" && attachment.userId.length > 0;
|
|
25031
|
+
}
|
|
25032
|
+
function eventSocketCanReceive(attachment, ownerUserId) {
|
|
25033
|
+
return attachment.scope === "all" || ownerUserId !== null && attachment.userId === ownerUserId;
|
|
25034
|
+
}
|
|
25035
|
+
|
|
24956
25036
|
// src/durable-objects/agentbuilder-migrations/0001_initial.ts
|
|
24957
25037
|
var migration36 = {
|
|
24958
25038
|
version: 1,
|
|
@@ -25981,8 +26061,13 @@ var DurableAgentBuilder = class extends DurableObject {
|
|
|
25981
26061
|
const sockets = ctx.getWebSockets();
|
|
25982
26062
|
for (const ws of sockets) {
|
|
25983
26063
|
const attachment = ws.deserializeAttachment();
|
|
25984
|
-
if (attachment
|
|
26064
|
+
if (isEventSocketAttachment(attachment)) {
|
|
25985
26065
|
this.eventSockets.add(ws);
|
|
26066
|
+
} else if (attachment?.channel === "events") {
|
|
26067
|
+
try {
|
|
26068
|
+
ws.close(1012, "Reconnect to establish an authenticated event scope");
|
|
26069
|
+
} catch {
|
|
26070
|
+
}
|
|
25986
26071
|
}
|
|
25987
26072
|
}
|
|
25988
26073
|
}
|
|
@@ -26252,10 +26337,10 @@ var DurableAgentBuilder = class extends DurableObject {
|
|
|
26252
26337
|
for (const entry of value) {
|
|
26253
26338
|
if (!entry || typeof entry !== "object") continue;
|
|
26254
26339
|
const attachment = entry;
|
|
26255
|
-
const
|
|
26256
|
-
if (!
|
|
26340
|
+
const path21 = typeof attachment.path === "string" ? attachment.path.trim() : "";
|
|
26341
|
+
if (!path21) continue;
|
|
26257
26342
|
output.push({
|
|
26258
|
-
path:
|
|
26343
|
+
path: path21,
|
|
26259
26344
|
name: typeof attachment.name === "string" ? attachment.name : void 0,
|
|
26260
26345
|
mimeType: typeof attachment.mimeType === "string" ? attachment.mimeType : void 0,
|
|
26261
26346
|
size: typeof attachment.size === "number" ? attachment.size : void 0,
|
|
@@ -26272,8 +26357,8 @@ var DurableAgentBuilder = class extends DurableObject {
|
|
|
26272
26357
|
const trimmed = sanitized.replace(/^[-.]+|[-.]+$/g, "");
|
|
26273
26358
|
return trimmed || "attachment";
|
|
26274
26359
|
}
|
|
26275
|
-
inferMimeTypeFromPath(
|
|
26276
|
-
const normalized =
|
|
26360
|
+
inferMimeTypeFromPath(path21) {
|
|
26361
|
+
const normalized = path21.toLowerCase();
|
|
26277
26362
|
if (normalized.endsWith(".png")) return "image/png";
|
|
26278
26363
|
if (normalized.endsWith(".jpg") || normalized.endsWith(".jpeg")) return "image/jpeg";
|
|
26279
26364
|
if (normalized.endsWith(".webp")) return "image/webp";
|
|
@@ -26311,7 +26396,7 @@ var DurableAgentBuilder = class extends DurableObject {
|
|
|
26311
26396
|
if (!attachments || attachments.length === 0) {
|
|
26312
26397
|
return "";
|
|
26313
26398
|
}
|
|
26314
|
-
const paths = attachments.map((attachment) => attachment.path).filter((
|
|
26399
|
+
const paths = attachments.map((attachment) => attachment.path).filter((path21) => typeof path21 === "string" && path21.length > 0);
|
|
26315
26400
|
if (paths.length === 0) {
|
|
26316
26401
|
return "";
|
|
26317
26402
|
}
|
|
@@ -26611,7 +26696,10 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
26611
26696
|
executing: false
|
|
26612
26697
|
};
|
|
26613
26698
|
const eventThread = await this.toThreadEventPayload(thread);
|
|
26614
|
-
this.broadcastEvent(
|
|
26699
|
+
this.broadcastEvent(
|
|
26700
|
+
{ type: "thread_created", thread: eventThread },
|
|
26701
|
+
thread.user_id
|
|
26702
|
+
);
|
|
26615
26703
|
await this.runAfterThreadCreatedHook(thread);
|
|
26616
26704
|
return thread;
|
|
26617
26705
|
}
|
|
@@ -26914,14 +27002,20 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
26914
27002
|
stampedMessageAt = stampAt;
|
|
26915
27003
|
}
|
|
26916
27004
|
}
|
|
26917
|
-
this.
|
|
26918
|
-
|
|
26919
|
-
|
|
26920
|
-
|
|
26921
|
-
|
|
26922
|
-
|
|
26923
|
-
|
|
26924
|
-
|
|
27005
|
+
const ownerUserId = await this.getThreadOwnerId(threadId);
|
|
27006
|
+
if (ownerUserId !== void 0) {
|
|
27007
|
+
this.broadcastEvent(
|
|
27008
|
+
{
|
|
27009
|
+
type: "thread_activity",
|
|
27010
|
+
threadId,
|
|
27011
|
+
...activityAt !== void 0 ? { last_activity_at: activityAt } : {},
|
|
27012
|
+
...executing !== void 0 ? { executing } : {},
|
|
27013
|
+
...preview != null ? { last_message_preview: preview } : {},
|
|
27014
|
+
...stampedMessageAt !== void 0 ? { last_message_at: stampedMessageAt } : {}
|
|
27015
|
+
},
|
|
27016
|
+
ownerUserId
|
|
27017
|
+
);
|
|
27018
|
+
}
|
|
26925
27019
|
}
|
|
26926
27020
|
/**
|
|
26927
27021
|
* Fill in previews for threads that predate preview tracking. Callers read
|
|
@@ -26948,8 +27042,14 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
26948
27042
|
*/
|
|
26949
27043
|
async deleteThread(id) {
|
|
26950
27044
|
await this.ensureMigrated();
|
|
27045
|
+
const ownerUserId = await this.getThreadOwnerId(id);
|
|
26951
27046
|
await this.ctx.storage.sql.exec(`DELETE FROM threads WHERE id = ?`, id);
|
|
26952
|
-
|
|
27047
|
+
if (ownerUserId !== void 0) {
|
|
27048
|
+
this.broadcastEvent(
|
|
27049
|
+
{ type: "thread_deleted", threadId: id },
|
|
27050
|
+
ownerUserId
|
|
27051
|
+
);
|
|
27052
|
+
}
|
|
26953
27053
|
return true;
|
|
26954
27054
|
}
|
|
26955
27055
|
/**
|
|
@@ -27011,7 +27111,10 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
27011
27111
|
const updated = await this.getThread(id);
|
|
27012
27112
|
if (updated) {
|
|
27013
27113
|
const eventThread = await this.toThreadEventPayload(updated);
|
|
27014
|
-
this.broadcastEvent(
|
|
27114
|
+
this.broadcastEvent(
|
|
27115
|
+
{ type: "thread_updated", thread: eventThread },
|
|
27116
|
+
updated.user_id
|
|
27117
|
+
);
|
|
27015
27118
|
}
|
|
27016
27119
|
} catch {
|
|
27017
27120
|
}
|
|
@@ -27091,7 +27194,10 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
27091
27194
|
const updated = await this.getThread(id);
|
|
27092
27195
|
if (updated) {
|
|
27093
27196
|
const eventThread = await this.toThreadEventPayload(updated);
|
|
27094
|
-
this.broadcastEvent(
|
|
27197
|
+
this.broadcastEvent(
|
|
27198
|
+
{ type: "thread_updated", thread: eventThread },
|
|
27199
|
+
updated.user_id
|
|
27200
|
+
);
|
|
27095
27201
|
}
|
|
27096
27202
|
return updated;
|
|
27097
27203
|
}
|
|
@@ -27796,7 +27902,18 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
27796
27902
|
}
|
|
27797
27903
|
async toThreadEventPayload(thread) {
|
|
27798
27904
|
const eventThread = {
|
|
27799
|
-
|
|
27905
|
+
id: thread.id,
|
|
27906
|
+
agent_name: thread.agent_name,
|
|
27907
|
+
origin_agent_name: thread.origin_agent_name,
|
|
27908
|
+
user_id: thread.user_id,
|
|
27909
|
+
tags: thread.tags,
|
|
27910
|
+
parent: thread.parent,
|
|
27911
|
+
terminated: thread.terminated,
|
|
27912
|
+
created_at: thread.created_at,
|
|
27913
|
+
last_activity_at: thread.last_activity_at,
|
|
27914
|
+
executing: thread.executing,
|
|
27915
|
+
last_message_preview: thread.last_message_preview,
|
|
27916
|
+
last_message_at: thread.last_message_at
|
|
27800
27917
|
};
|
|
27801
27918
|
try {
|
|
27802
27919
|
const agentDef = await this.loadAgent(thread.agent_name);
|
|
@@ -28663,10 +28780,21 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
28663
28780
|
* Uses Hibernation API to reduce costs during inactivity
|
|
28664
28781
|
*/
|
|
28665
28782
|
async handleEventsWebSocketUpgrade(request) {
|
|
28783
|
+
const attachment = {
|
|
28784
|
+
channel: "events",
|
|
28785
|
+
scope: request.headers.get(EVENT_STREAM_SCOPE_HEADER) === "all" ? "all" : "user",
|
|
28786
|
+
userId: request.headers.get(EVENT_STREAM_USER_ID_HEADER) ?? ""
|
|
28787
|
+
};
|
|
28788
|
+
if (!isEventSocketAttachment(attachment)) {
|
|
28789
|
+
return Response.json(
|
|
28790
|
+
{ error: "Missing authenticated event subscription" },
|
|
28791
|
+
{ status: 401 }
|
|
28792
|
+
);
|
|
28793
|
+
}
|
|
28666
28794
|
const pair = new WebSocketPair();
|
|
28667
28795
|
const [client, server] = Object.values(pair);
|
|
28668
28796
|
this.ctx.acceptWebSocket(server);
|
|
28669
|
-
server.serializeAttachment(
|
|
28797
|
+
server.serializeAttachment(attachment);
|
|
28670
28798
|
this.eventSockets.add(server);
|
|
28671
28799
|
return new Response(null, {
|
|
28672
28800
|
status: 101,
|
|
@@ -28687,17 +28815,23 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
28687
28815
|
const thread = await this.getThread(threadId);
|
|
28688
28816
|
if (!thread) return;
|
|
28689
28817
|
const eventThread = await this.toThreadEventPayload(thread);
|
|
28690
|
-
this.broadcastEvent(
|
|
28818
|
+
this.broadcastEvent(
|
|
28819
|
+
{ type: "thread_updated", thread: eventThread },
|
|
28820
|
+
thread.user_id
|
|
28821
|
+
);
|
|
28691
28822
|
}
|
|
28692
28823
|
/**
|
|
28693
|
-
* Broadcast an event to
|
|
28824
|
+
* Broadcast an event only to its owner or an explicitly all-scoped admin.
|
|
28694
28825
|
*/
|
|
28695
|
-
broadcastEvent(event) {
|
|
28826
|
+
broadcastEvent(event, ownerUserId) {
|
|
28696
28827
|
const payload = JSON.stringify(event);
|
|
28697
28828
|
for (const ws of Array.from(this.eventSockets)) {
|
|
28698
28829
|
try {
|
|
28699
28830
|
if (ws.readyState === WebSocket.OPEN) {
|
|
28700
|
-
ws.
|
|
28831
|
+
const attachment = ws.deserializeAttachment();
|
|
28832
|
+
if (isEventSocketAttachment(attachment) && eventSocketCanReceive(attachment, ownerUserId)) {
|
|
28833
|
+
ws.send(payload);
|
|
28834
|
+
}
|
|
28701
28835
|
} else {
|
|
28702
28836
|
this.eventSockets.delete(ws);
|
|
28703
28837
|
}
|
|
@@ -28706,6 +28840,15 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
28706
28840
|
}
|
|
28707
28841
|
}
|
|
28708
28842
|
}
|
|
28843
|
+
/** Resolve a thread owner without decrypting its env or loading the row. */
|
|
28844
|
+
async getThreadOwnerId(threadId) {
|
|
28845
|
+
const cursor = await this.ctx.storage.sql.exec(
|
|
28846
|
+
`SELECT user_id FROM threads WHERE id = ? LIMIT 1`,
|
|
28847
|
+
threadId
|
|
28848
|
+
);
|
|
28849
|
+
const rows = cursor.toArray();
|
|
28850
|
+
return rows[0]?.user_id;
|
|
28851
|
+
}
|
|
28709
28852
|
/**
|
|
28710
28853
|
* WebSocket Hibernation API handler for incoming messages
|
|
28711
28854
|
* Called when a message is received on a hibernated WebSocket
|
|
@@ -28774,12 +28917,12 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
28774
28917
|
return all.find((s) => s.name === name) ?? null;
|
|
28775
28918
|
}
|
|
28776
28919
|
/** One bundled file's text (null when the skill or file is missing). */
|
|
28777
|
-
async getSkillFile(name,
|
|
28920
|
+
async getSkillFile(name, path21) {
|
|
28778
28921
|
await this.ensureMigrated();
|
|
28779
28922
|
const cursor = await this.ctx.storage.sql.exec(
|
|
28780
28923
|
`SELECT content FROM skill_files WHERE skill_name = ? AND path = ?`,
|
|
28781
28924
|
name,
|
|
28782
|
-
|
|
28925
|
+
path21.replace(/^\.\//, "")
|
|
28783
28926
|
);
|
|
28784
28927
|
const rows = cursor.toArray();
|
|
28785
28928
|
return rows.length ? rows[0].content : null;
|
|
@@ -29002,12 +29145,12 @@ init_code_execution();
|
|
|
29002
29145
|
var DEFAULT_CLIENT_TOOL_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
29003
29146
|
var BRIDGE_LIVENESS_TIMEOUT_MS = 20 * 1e3;
|
|
29004
29147
|
var RUNTIME_STORAGE_PREFIX = "__agentbuilder_runtime_storage__:";
|
|
29005
|
-
function normalizeEndpointThreadPath(
|
|
29006
|
-
if (!
|
|
29148
|
+
function normalizeEndpointThreadPath(path21) {
|
|
29149
|
+
if (!path21 || /^[A-Za-z][A-Za-z\d+\-.]*:/.test(path21)) {
|
|
29007
29150
|
throw new Error("Use a relative thread filesystem path");
|
|
29008
29151
|
}
|
|
29009
29152
|
const parts = [];
|
|
29010
|
-
for (const part of
|
|
29153
|
+
for (const part of path21.replace(/\\/g, "/").split("/")) {
|
|
29011
29154
|
if (!part || part === ".") continue;
|
|
29012
29155
|
if (part === "..") {
|
|
29013
29156
|
if (parts.length === 0) throw new Error("Path cannot escape the thread filesystem root");
|
|
@@ -29057,12 +29200,12 @@ function createEndpointFetchBridge() {
|
|
|
29057
29200
|
function createEndpointFsBridge(state) {
|
|
29058
29201
|
const decoder = new TextDecoder();
|
|
29059
29202
|
return {
|
|
29060
|
-
readFile: async (
|
|
29061
|
-
const data = await state.readFile(normalizeEndpointThreadPath(
|
|
29203
|
+
readFile: async (path21) => {
|
|
29204
|
+
const data = await state.readFile(normalizeEndpointThreadPath(path21));
|
|
29062
29205
|
return data ? decoder.decode(data) : null;
|
|
29063
29206
|
},
|
|
29064
|
-
writeFile: async (
|
|
29065
|
-
return state.writeFile(normalizeEndpointThreadPath(
|
|
29207
|
+
writeFile: async (path21, content, mimeType = "text/plain") => {
|
|
29208
|
+
return state.writeFile(normalizeEndpointThreadPath(path21), content, mimeType);
|
|
29066
29209
|
}
|
|
29067
29210
|
};
|
|
29068
29211
|
}
|
|
@@ -29131,24 +29274,24 @@ function createEndpointThreadStateBridge(state) {
|
|
|
29131
29274
|
emit: (event, data) => state.emit(event, data),
|
|
29132
29275
|
getValue: (key) => state.getValue(key),
|
|
29133
29276
|
setValue: (key, value) => state.setValue(key, value),
|
|
29134
|
-
readFile: (
|
|
29135
|
-
writeFile: (
|
|
29136
|
-
return state.writeFile(normalizeEndpointThreadPath(
|
|
29277
|
+
readFile: (path21) => state.readFile(normalizeEndpointThreadPath(path21)),
|
|
29278
|
+
writeFile: (path21, data, mimeType = "application/octet-stream", options) => {
|
|
29279
|
+
return state.writeFile(normalizeEndpointThreadPath(path21), data, mimeType, options);
|
|
29137
29280
|
},
|
|
29138
|
-
statFile: (
|
|
29139
|
-
readdirFile: (
|
|
29140
|
-
unlinkFile: (
|
|
29141
|
-
mkdirFile: (
|
|
29142
|
-
rmdirFile: (
|
|
29281
|
+
statFile: (path21) => state.statFile(normalizeEndpointThreadPath(path21)),
|
|
29282
|
+
readdirFile: (path21) => state.readdirFile(normalizeEndpointThreadPath(path21)),
|
|
29283
|
+
unlinkFile: (path21) => state.unlinkFile(normalizeEndpointThreadPath(path21)),
|
|
29284
|
+
mkdirFile: (path21) => state.mkdirFile(normalizeEndpointThreadPath(path21)),
|
|
29285
|
+
rmdirFile: (path21) => state.rmdirFile(normalizeEndpointThreadPath(path21)),
|
|
29143
29286
|
moveFile: (sourcePath, destinationPath) => state.moveFile(
|
|
29144
29287
|
normalizeEndpointThreadPath(sourcePath),
|
|
29145
29288
|
normalizeEndpointThreadPath(destinationPath)
|
|
29146
29289
|
),
|
|
29147
|
-
renameFile: (
|
|
29290
|
+
renameFile: (path21, newName) => state.renameFile(normalizeEndpointThreadPath(path21), newName),
|
|
29148
29291
|
getFileStats: () => state.getFileStats(),
|
|
29149
29292
|
grepFiles: (pattern) => state.grepFiles(pattern),
|
|
29150
29293
|
findFiles: (pattern) => state.findFiles(pattern),
|
|
29151
|
-
getFileThumbnail: (
|
|
29294
|
+
getFileThumbnail: (path21) => state.getFileThumbnail(normalizeEndpointThreadPath(path21))
|
|
29152
29295
|
};
|
|
29153
29296
|
}
|
|
29154
29297
|
var DurableThread = class _DurableThread extends DurableObject {
|
|
@@ -29849,7 +29992,7 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
29849
29992
|
this.assertJsonSerializableThreadValue(value, "$", /* @__PURE__ */ new WeakSet());
|
|
29850
29993
|
return JSON.stringify(value);
|
|
29851
29994
|
}
|
|
29852
|
-
assertJsonSerializableThreadValue(value,
|
|
29995
|
+
assertJsonSerializableThreadValue(value, path21, seen) {
|
|
29853
29996
|
if (value === null) {
|
|
29854
29997
|
return;
|
|
29855
29998
|
}
|
|
@@ -29859,36 +30002,36 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
29859
30002
|
return;
|
|
29860
30003
|
case "number":
|
|
29861
30004
|
if (!Number.isFinite(value)) {
|
|
29862
|
-
throw new Error(`Thread value at ${
|
|
30005
|
+
throw new Error(`Thread value at ${path21} must be a finite number`);
|
|
29863
30006
|
}
|
|
29864
30007
|
return;
|
|
29865
30008
|
case "object": {
|
|
29866
30009
|
if (seen.has(value)) {
|
|
29867
|
-
throw new Error(`Thread value at ${
|
|
30010
|
+
throw new Error(`Thread value at ${path21} cannot contain circular references`);
|
|
29868
30011
|
}
|
|
29869
30012
|
seen.add(value);
|
|
29870
30013
|
if (Array.isArray(value)) {
|
|
29871
30014
|
for (let i = 0; i < value.length; i += 1) {
|
|
29872
|
-
this.assertJsonSerializableThreadValue(value[i], `${
|
|
30015
|
+
this.assertJsonSerializableThreadValue(value[i], `${path21}[${i}]`, seen);
|
|
29873
30016
|
}
|
|
29874
30017
|
seen.delete(value);
|
|
29875
30018
|
return;
|
|
29876
30019
|
}
|
|
29877
30020
|
const prototype = Object.getPrototypeOf(value);
|
|
29878
30021
|
if (prototype !== Object.prototype && prototype !== null) {
|
|
29879
|
-
throw new Error(`Thread value at ${
|
|
30022
|
+
throw new Error(`Thread value at ${path21} must be a JSON object, array, or primitive`);
|
|
29880
30023
|
}
|
|
29881
30024
|
if (Object.getOwnPropertySymbols(value).length > 0) {
|
|
29882
|
-
throw new Error(`Thread value at ${
|
|
30025
|
+
throw new Error(`Thread value at ${path21} cannot contain symbol keys`);
|
|
29883
30026
|
}
|
|
29884
30027
|
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
29885
|
-
this.assertJsonSerializableThreadValue(entryValue, `${
|
|
30028
|
+
this.assertJsonSerializableThreadValue(entryValue, `${path21}.${entryKey}`, seen);
|
|
29886
30029
|
}
|
|
29887
30030
|
seen.delete(value);
|
|
29888
30031
|
return;
|
|
29889
30032
|
}
|
|
29890
30033
|
default:
|
|
29891
|
-
throw new Error(`Thread value at ${
|
|
30034
|
+
throw new Error(`Thread value at ${path21} must be JSON-serializable`);
|
|
29892
30035
|
}
|
|
29893
30036
|
}
|
|
29894
30037
|
// ============================================================
|
|
@@ -31053,8 +31196,8 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
31053
31196
|
);
|
|
31054
31197
|
return terminalCursor.toArray()[0] ?? null;
|
|
31055
31198
|
}
|
|
31056
|
-
inferMimeTypeFromPath(
|
|
31057
|
-
const normalized =
|
|
31199
|
+
inferMimeTypeFromPath(path21) {
|
|
31200
|
+
const normalized = path21.toLowerCase();
|
|
31058
31201
|
if (normalized.endsWith(".png")) return "image/png";
|
|
31059
31202
|
if (normalized.endsWith(".jpg") || normalized.endsWith(".jpeg")) return "image/jpeg";
|
|
31060
31203
|
if (normalized.endsWith(".webp")) return "image/webp";
|
|
@@ -31093,7 +31236,7 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
31093
31236
|
ext: value.slice(lastDot + 1).toLowerCase()
|
|
31094
31237
|
};
|
|
31095
31238
|
}
|
|
31096
|
-
resolveAttachmentMimeType(sourceMimeType, fallbackMimeType,
|
|
31239
|
+
resolveAttachmentMimeType(sourceMimeType, fallbackMimeType, path21) {
|
|
31097
31240
|
const source = sourceMimeType?.trim();
|
|
31098
31241
|
if (source && source !== "application/octet-stream") {
|
|
31099
31242
|
return source;
|
|
@@ -31102,7 +31245,7 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
31102
31245
|
if (fallback && fallback !== "application/octet-stream") {
|
|
31103
31246
|
return fallback;
|
|
31104
31247
|
}
|
|
31105
|
-
return this.inferMimeTypeFromPath(
|
|
31248
|
+
return this.inferMimeTypeFromPath(path21) ?? source ?? fallback ?? "application/octet-stream";
|
|
31106
31249
|
}
|
|
31107
31250
|
buildAttachmentTargetPath(preferredName, mimeType, sourcePath) {
|
|
31108
31251
|
const safeName = this.sanitizeFilename(preferredName);
|
|
@@ -31197,8 +31340,8 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
31197
31340
|
}
|
|
31198
31341
|
return copied;
|
|
31199
31342
|
}
|
|
31200
|
-
async readAttachmentDataFromSource(
|
|
31201
|
-
const sourceData = await this.readFile(
|
|
31343
|
+
async readAttachmentDataFromSource(path21, sourceFile) {
|
|
31344
|
+
const sourceData = await this.readFile(path21);
|
|
31202
31345
|
if (sourceData.success && sourceData.data) {
|
|
31203
31346
|
return sourceData.data;
|
|
31204
31347
|
}
|
|
@@ -31232,7 +31375,7 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
31232
31375
|
if (!attachments || attachments.length === 0) {
|
|
31233
31376
|
return "";
|
|
31234
31377
|
}
|
|
31235
|
-
const paths = attachments.map((attachment) => attachment.path).filter((
|
|
31378
|
+
const paths = attachments.map((attachment) => attachment.path).filter((path21) => typeof path21 === "string" && path21.length > 0);
|
|
31236
31379
|
if (paths.length === 0) {
|
|
31237
31380
|
return "";
|
|
31238
31381
|
}
|
|
@@ -32967,7 +33110,7 @@ ${resultContent}${attachmentSummary}`;
|
|
|
32967
33110
|
const id = durability?.toolCallId ?? crypto.randomUUID();
|
|
32968
33111
|
const timeoutMs = typeof request.timeoutMs === "number" && request.timeoutMs > 0 ? request.timeoutMs : DEFAULT_CLIENT_TOOL_TIMEOUT_MS;
|
|
32969
33112
|
this.bridgeLastSeen.set(socket, Date.now());
|
|
32970
|
-
return new Promise((
|
|
33113
|
+
return new Promise((resolve3) => {
|
|
32971
33114
|
const timer = setTimeout(() => {
|
|
32972
33115
|
this.markBridgeDead(socket);
|
|
32973
33116
|
this.settleClientCall(id, {
|
|
@@ -32987,7 +33130,7 @@ ${resultContent}${attachmentSummary}`;
|
|
|
32987
33130
|
});
|
|
32988
33131
|
}
|
|
32989
33132
|
}, 5e3);
|
|
32990
|
-
this.pendingClientCalls.set(id, { resolve:
|
|
33133
|
+
this.pendingClientCalls.set(id, { resolve: resolve3, timer, liveness, socket });
|
|
32991
33134
|
const frame = JSON.stringify({
|
|
32992
33135
|
type: "tool_request",
|
|
32993
33136
|
id,
|
|
@@ -33365,7 +33508,7 @@ ${resultContent}${attachmentSummary}`;
|
|
|
33365
33508
|
const deadline = Date.now() + timeoutMs;
|
|
33366
33509
|
while (Date.now() < deadline) {
|
|
33367
33510
|
await new Promise(
|
|
33368
|
-
(
|
|
33511
|
+
(resolve3) => setTimeout(resolve3, _DurableThread.OWNER_REATTACH_POLL_MS)
|
|
33369
33512
|
);
|
|
33370
33513
|
const owner = await this.getExecutionOwner();
|
|
33371
33514
|
const socket = this.getOpenBridgeSocket(owner?.client_id ?? null);
|
|
@@ -33398,8 +33541,8 @@ ${resultContent}${attachmentSummary}`;
|
|
|
33398
33541
|
}
|
|
33399
33542
|
});
|
|
33400
33543
|
let settleDone;
|
|
33401
|
-
const done = new Promise((
|
|
33402
|
-
settleDone =
|
|
33544
|
+
const done = new Promise((resolve3) => {
|
|
33545
|
+
settleDone = resolve3;
|
|
33403
33546
|
});
|
|
33404
33547
|
const state = {
|
|
33405
33548
|
socket,
|
|
@@ -33411,11 +33554,11 @@ ${resultContent}${attachmentSummary}`;
|
|
|
33411
33554
|
};
|
|
33412
33555
|
this.clientStreams.set(id, state);
|
|
33413
33556
|
this.bridgeLastSeen.set(socket, Date.now());
|
|
33414
|
-
const openResult = await new Promise((
|
|
33415
|
-
state.opened =
|
|
33557
|
+
const openResult = await new Promise((resolve3) => {
|
|
33558
|
+
state.opened = resolve3;
|
|
33416
33559
|
const timeoutMs = typeof request.timeoutMs === "number" && request.timeoutMs > 0 ? request.timeoutMs : _DurableThread.CLIENT_STREAM_OPEN_TIMEOUT_MS;
|
|
33417
33560
|
state.openTimer = setTimeout(() => {
|
|
33418
|
-
|
|
33561
|
+
resolve3({
|
|
33419
33562
|
ok: false,
|
|
33420
33563
|
error: `The client did not accept the ${request.tool} stream within ${Math.round(timeoutMs / 1e3)}s.`,
|
|
33421
33564
|
code: "timeout"
|
|
@@ -33431,7 +33574,7 @@ ${resultContent}${attachmentSummary}`;
|
|
|
33431
33574
|
})
|
|
33432
33575
|
);
|
|
33433
33576
|
} catch (error) {
|
|
33434
|
-
|
|
33577
|
+
resolve3({
|
|
33435
33578
|
ok: false,
|
|
33436
33579
|
error: `Failed to reach the client: ${error instanceof Error ? error.message : String(error)}`,
|
|
33437
33580
|
code: "unavailable"
|
|
@@ -33610,13 +33753,13 @@ ${resultContent}${attachmentSummary}`;
|
|
|
33610
33753
|
switch (parsed.type) {
|
|
33611
33754
|
case "stream_opened": {
|
|
33612
33755
|
if (state.opened) {
|
|
33613
|
-
const
|
|
33756
|
+
const resolve3 = state.opened;
|
|
33614
33757
|
state.opened = null;
|
|
33615
33758
|
if (state.openTimer) {
|
|
33616
33759
|
clearTimeout(state.openTimer);
|
|
33617
33760
|
state.openTimer = null;
|
|
33618
33761
|
}
|
|
33619
|
-
|
|
33762
|
+
resolve3({ ok: true });
|
|
33620
33763
|
}
|
|
33621
33764
|
return;
|
|
33622
33765
|
}
|
|
@@ -34542,7 +34685,7 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
34542
34685
|
const busyWaitBudgetMs = 3e4;
|
|
34543
34686
|
const waitStartedAt = Date.now();
|
|
34544
34687
|
while (this.isExecuting && Date.now() - waitStartedAt < busyWaitBudgetMs) {
|
|
34545
|
-
await new Promise((
|
|
34688
|
+
await new Promise((resolve3) => setTimeout(resolve3, 500));
|
|
34546
34689
|
}
|
|
34547
34690
|
if (this.isExecuting) {
|
|
34548
34691
|
throw new Error(
|
|
@@ -35205,11 +35348,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35205
35348
|
/**
|
|
35206
35349
|
* Write a file to storage (RPC method)
|
|
35207
35350
|
*/
|
|
35208
|
-
async writeFile(
|
|
35351
|
+
async writeFile(path21, data, mimeType, options) {
|
|
35209
35352
|
await this.ensureMigrated();
|
|
35210
35353
|
try {
|
|
35211
|
-
const
|
|
35212
|
-
const existingFile = await
|
|
35354
|
+
const fs19 = this.getFileStorage();
|
|
35355
|
+
const existingFile = await fs19.stat(path21);
|
|
35213
35356
|
const isUpdate = existingFile !== null;
|
|
35214
35357
|
const binaryString = atob(data);
|
|
35215
35358
|
const dataBuffer = new Uint8Array(binaryString.length);
|
|
@@ -35217,7 +35360,7 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35217
35360
|
for (let i = 0; i < binaryString.length; i++) {
|
|
35218
35361
|
dataBuffer[i] = binaryString.charCodeAt(i);
|
|
35219
35362
|
if (i > 0 && i % YIELD_INTERVAL === 0) {
|
|
35220
|
-
await new Promise((
|
|
35363
|
+
await new Promise((resolve3) => setTimeout(resolve3, 0));
|
|
35221
35364
|
}
|
|
35222
35365
|
}
|
|
35223
35366
|
let thumbnailBuffer;
|
|
@@ -35227,16 +35370,16 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35227
35370
|
for (let i = 0; i < thumbBinary.length; i++) {
|
|
35228
35371
|
thumbnailBuffer[i] = thumbBinary.charCodeAt(i);
|
|
35229
35372
|
if (i > 0 && i % YIELD_INTERVAL === 0) {
|
|
35230
|
-
await new Promise((
|
|
35373
|
+
await new Promise((resolve3) => setTimeout(resolve3, 0));
|
|
35231
35374
|
}
|
|
35232
35375
|
}
|
|
35233
35376
|
}
|
|
35234
|
-
const record = await
|
|
35377
|
+
const record = await fs19.writeFile(path21, dataBuffer, mimeType, {
|
|
35235
35378
|
metadata: options?.metadata,
|
|
35236
35379
|
thumbnail: thumbnailBuffer
|
|
35237
35380
|
});
|
|
35238
35381
|
this.broadcastEvent(isUpdate ? "file_updated" : "file_created", {
|
|
35239
|
-
path:
|
|
35382
|
+
path: path21,
|
|
35240
35383
|
file: record
|
|
35241
35384
|
});
|
|
35242
35385
|
return { success: true, file: record };
|
|
@@ -35248,15 +35391,15 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35248
35391
|
/**
|
|
35249
35392
|
* Write a text file to storage (RPC method)
|
|
35250
35393
|
*/
|
|
35251
|
-
async writeTextFile(
|
|
35394
|
+
async writeTextFile(path21, content, mimeType = "text/plain", options) {
|
|
35252
35395
|
await this.ensureMigrated();
|
|
35253
35396
|
try {
|
|
35254
|
-
const
|
|
35255
|
-
const existingFile = await
|
|
35397
|
+
const fs19 = this.getFileStorage();
|
|
35398
|
+
const existingFile = await fs19.stat(path21);
|
|
35256
35399
|
const isUpdate = existingFile !== null;
|
|
35257
|
-
const record = await
|
|
35400
|
+
const record = await fs19.writeFile(path21, content, mimeType, options);
|
|
35258
35401
|
this.broadcastEvent(isUpdate ? "file_updated" : "file_created", {
|
|
35259
|
-
path:
|
|
35402
|
+
path: path21,
|
|
35260
35403
|
file: record
|
|
35261
35404
|
});
|
|
35262
35405
|
return { success: true, file: record };
|
|
@@ -35293,11 +35436,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35293
35436
|
/**
|
|
35294
35437
|
* Link to an external file (RPC method)
|
|
35295
35438
|
*/
|
|
35296
|
-
async linkFile(
|
|
35439
|
+
async linkFile(path21, location, options) {
|
|
35297
35440
|
await this.ensureMigrated();
|
|
35298
35441
|
try {
|
|
35299
|
-
const
|
|
35300
|
-
const record = await
|
|
35442
|
+
const fs19 = this.getFileStorage();
|
|
35443
|
+
const record = await fs19.linkFile(path21, location, options);
|
|
35301
35444
|
return { success: true, file: record };
|
|
35302
35445
|
} catch (error) {
|
|
35303
35446
|
console.error("Error in linkFile:", error);
|
|
@@ -35308,11 +35451,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35308
35451
|
* Read a file from storage (RPC method)
|
|
35309
35452
|
* Returns base64-encoded data
|
|
35310
35453
|
*/
|
|
35311
|
-
async readFile(
|
|
35454
|
+
async readFile(path21) {
|
|
35312
35455
|
await this.ensureMigrated();
|
|
35313
35456
|
try {
|
|
35314
|
-
const
|
|
35315
|
-
const data = await
|
|
35457
|
+
const fs19 = this.getFileStorage();
|
|
35458
|
+
const data = await fs19.readFile(path21);
|
|
35316
35459
|
if (data === null) {
|
|
35317
35460
|
return { success: false, error: "File not found or external" };
|
|
35318
35461
|
}
|
|
@@ -35331,11 +35474,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35331
35474
|
/**
|
|
35332
35475
|
* Read a text file from storage (RPC method)
|
|
35333
35476
|
*/
|
|
35334
|
-
async readTextFile(
|
|
35477
|
+
async readTextFile(path21) {
|
|
35335
35478
|
await this.ensureMigrated();
|
|
35336
35479
|
try {
|
|
35337
|
-
const
|
|
35338
|
-
const content = await
|
|
35480
|
+
const fs19 = this.getFileStorage();
|
|
35481
|
+
const content = await fs19.readTextFile(path21);
|
|
35339
35482
|
if (content === null) {
|
|
35340
35483
|
return { success: false, error: "File not found or external" };
|
|
35341
35484
|
}
|
|
@@ -35348,11 +35491,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35348
35491
|
/**
|
|
35349
35492
|
* Get file metadata (RPC method)
|
|
35350
35493
|
*/
|
|
35351
|
-
async statFile(
|
|
35494
|
+
async statFile(path21) {
|
|
35352
35495
|
await this.ensureMigrated();
|
|
35353
35496
|
try {
|
|
35354
|
-
const
|
|
35355
|
-
const record = await
|
|
35497
|
+
const fs19 = this.getFileStorage();
|
|
35498
|
+
const record = await fs19.stat(path21);
|
|
35356
35499
|
if (record === null) {
|
|
35357
35500
|
return { success: false, error: "File not found" };
|
|
35358
35501
|
}
|
|
@@ -35365,11 +35508,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35365
35508
|
/**
|
|
35366
35509
|
* Check if file exists (RPC method)
|
|
35367
35510
|
*/
|
|
35368
|
-
async fileExists(
|
|
35511
|
+
async fileExists(path21) {
|
|
35369
35512
|
await this.ensureMigrated();
|
|
35370
35513
|
try {
|
|
35371
|
-
const
|
|
35372
|
-
const exists2 = await
|
|
35514
|
+
const fs19 = this.getFileStorage();
|
|
35515
|
+
const exists2 = await fs19.exists(path21);
|
|
35373
35516
|
return { success: true, exists: exists2 };
|
|
35374
35517
|
} catch (error) {
|
|
35375
35518
|
console.error("Error in fileExists:", error);
|
|
@@ -35379,12 +35522,12 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35379
35522
|
/**
|
|
35380
35523
|
* Delete a file (RPC method)
|
|
35381
35524
|
*/
|
|
35382
|
-
async unlinkFile(
|
|
35525
|
+
async unlinkFile(path21) {
|
|
35383
35526
|
await this.ensureMigrated();
|
|
35384
35527
|
try {
|
|
35385
|
-
const
|
|
35386
|
-
await
|
|
35387
|
-
this.broadcastEvent("file_deleted", { path:
|
|
35528
|
+
const fs19 = this.getFileStorage();
|
|
35529
|
+
await fs19.unlink(path21);
|
|
35530
|
+
this.broadcastEvent("file_deleted", { path: path21 });
|
|
35388
35531
|
return { success: true };
|
|
35389
35532
|
} catch (error) {
|
|
35390
35533
|
console.error("Error in unlinkFile:", error);
|
|
@@ -35394,12 +35537,12 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35394
35537
|
/**
|
|
35395
35538
|
* Create a directory (RPC method)
|
|
35396
35539
|
*/
|
|
35397
|
-
async mkdirFile(
|
|
35540
|
+
async mkdirFile(path21) {
|
|
35398
35541
|
await this.ensureMigrated();
|
|
35399
35542
|
try {
|
|
35400
|
-
const
|
|
35401
|
-
const record = await
|
|
35402
|
-
this.broadcastEvent("file_created", { path:
|
|
35543
|
+
const fs19 = this.getFileStorage();
|
|
35544
|
+
const record = await fs19.mkdir(path21);
|
|
35545
|
+
this.broadcastEvent("file_created", { path: path21, file: record });
|
|
35403
35546
|
return { success: true, directory: record };
|
|
35404
35547
|
} catch (error) {
|
|
35405
35548
|
console.error("Error in mkdirFile:", error);
|
|
@@ -35409,11 +35552,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35409
35552
|
/**
|
|
35410
35553
|
* List directory contents (RPC method)
|
|
35411
35554
|
*/
|
|
35412
|
-
async readdirFile(
|
|
35555
|
+
async readdirFile(path21) {
|
|
35413
35556
|
await this.ensureMigrated();
|
|
35414
35557
|
try {
|
|
35415
|
-
const
|
|
35416
|
-
const files = await
|
|
35558
|
+
const fs19 = this.getFileStorage();
|
|
35559
|
+
const files = await fs19.readdir(path21);
|
|
35417
35560
|
return { success: true, files };
|
|
35418
35561
|
} catch (error) {
|
|
35419
35562
|
console.error("Error in readdirFile:", error);
|
|
@@ -35423,12 +35566,12 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35423
35566
|
/**
|
|
35424
35567
|
* Remove empty directory (RPC method)
|
|
35425
35568
|
*/
|
|
35426
|
-
async rmdirFile(
|
|
35569
|
+
async rmdirFile(path21) {
|
|
35427
35570
|
await this.ensureMigrated();
|
|
35428
35571
|
try {
|
|
35429
|
-
const
|
|
35430
|
-
await
|
|
35431
|
-
this.broadcastEvent("file_deleted", { path:
|
|
35572
|
+
const fs19 = this.getFileStorage();
|
|
35573
|
+
await fs19.rmdir(path21);
|
|
35574
|
+
this.broadcastEvent("file_deleted", { path: path21 });
|
|
35432
35575
|
return { success: true };
|
|
35433
35576
|
} catch (error) {
|
|
35434
35577
|
console.error("Error in rmdirFile:", error);
|
|
@@ -35443,9 +35586,9 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35443
35586
|
await this.ensureMigrated();
|
|
35444
35587
|
try {
|
|
35445
35588
|
const { normalizePath: normalizePath2 } = await Promise.resolve().then(() => (init_files(), files_exports));
|
|
35446
|
-
const
|
|
35589
|
+
const fs19 = this.getFileStorage();
|
|
35447
35590
|
const from = normalizePath2(sourcePath);
|
|
35448
|
-
const record = await
|
|
35591
|
+
const record = await fs19.move(sourcePath, destinationPath);
|
|
35449
35592
|
this.broadcastEvent("file_deleted", { path: from });
|
|
35450
35593
|
this.broadcastEvent("file_created", { path: record.path, file: record });
|
|
35451
35594
|
return { success: true, file: record };
|
|
@@ -35457,13 +35600,13 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35457
35600
|
/**
|
|
35458
35601
|
* Rename a file or directory in place (RPC method).
|
|
35459
35602
|
*/
|
|
35460
|
-
async renameFile(
|
|
35603
|
+
async renameFile(path21, newName) {
|
|
35461
35604
|
await this.ensureMigrated();
|
|
35462
35605
|
try {
|
|
35463
35606
|
const { normalizePath: normalizePath2 } = await Promise.resolve().then(() => (init_files(), files_exports));
|
|
35464
|
-
const
|
|
35465
|
-
const from = normalizePath2(
|
|
35466
|
-
const record = await
|
|
35607
|
+
const fs19 = this.getFileStorage();
|
|
35608
|
+
const from = normalizePath2(path21);
|
|
35609
|
+
const record = await fs19.rename(path21, newName);
|
|
35467
35610
|
this.broadcastEvent("file_deleted", { path: from });
|
|
35468
35611
|
this.broadcastEvent("file_created", { path: record.path, file: record });
|
|
35469
35612
|
return { success: true, file: record };
|
|
@@ -35478,8 +35621,8 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35478
35621
|
async getFileStats() {
|
|
35479
35622
|
await this.ensureMigrated();
|
|
35480
35623
|
try {
|
|
35481
|
-
const
|
|
35482
|
-
const stats = await
|
|
35624
|
+
const fs19 = this.getFileStorage();
|
|
35625
|
+
const stats = await fs19.getFileStats();
|
|
35483
35626
|
return { success: true, stats };
|
|
35484
35627
|
} catch (error) {
|
|
35485
35628
|
console.error("Error in getFileStats:", error);
|
|
@@ -35490,11 +35633,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35490
35633
|
* Get thumbnail for an image (RPC method)
|
|
35491
35634
|
* Returns base64-encoded data
|
|
35492
35635
|
*/
|
|
35493
|
-
async getFileThumbnail(
|
|
35636
|
+
async getFileThumbnail(path21) {
|
|
35494
35637
|
await this.ensureMigrated();
|
|
35495
35638
|
try {
|
|
35496
|
-
const
|
|
35497
|
-
const data = await
|
|
35639
|
+
const fs19 = this.getFileStorage();
|
|
35640
|
+
const data = await fs19.getThumbnail(path21);
|
|
35498
35641
|
if (data === null) {
|
|
35499
35642
|
return { success: false, error: "Thumbnail not found" };
|
|
35500
35643
|
}
|
|
@@ -35516,8 +35659,8 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35516
35659
|
async grepFiles(pattern, options) {
|
|
35517
35660
|
await this.ensureMigrated();
|
|
35518
35661
|
try {
|
|
35519
|
-
const
|
|
35520
|
-
const results = await
|
|
35662
|
+
const fs19 = this.getFileStorage();
|
|
35663
|
+
const results = await fs19.grep(pattern, options);
|
|
35521
35664
|
return { success: true, results };
|
|
35522
35665
|
} catch (error) {
|
|
35523
35666
|
console.error("Error in grepFiles:", error);
|
|
@@ -35530,8 +35673,8 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35530
35673
|
async findFiles(pattern, options) {
|
|
35531
35674
|
await this.ensureMigrated();
|
|
35532
35675
|
try {
|
|
35533
|
-
const
|
|
35534
|
-
const files = await
|
|
35676
|
+
const fs19 = this.getFileStorage();
|
|
35677
|
+
const files = await fs19.find(pattern, options);
|
|
35535
35678
|
return { success: true, files };
|
|
35536
35679
|
} catch (error) {
|
|
35537
35680
|
console.error("Error in findFiles:", error);
|
|
@@ -35546,11 +35689,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35546
35689
|
* Creates file record with is_chunked=1 and chunk_count=null.
|
|
35547
35690
|
* Caller should then use writeFileChunk() to write chunks.
|
|
35548
35691
|
*/
|
|
35549
|
-
async startChunkedUpload(
|
|
35692
|
+
async startChunkedUpload(path21, totalSize, mimeType, options) {
|
|
35550
35693
|
await this.ensureMigrated();
|
|
35551
35694
|
try {
|
|
35552
35695
|
const { CHUNK_SIZE: CHUNK_SIZE2, normalizePath: normalizePath2, basename: basename3 } = await Promise.resolve().then(() => (init_files(), files_exports));
|
|
35553
|
-
const normalizedPath = normalizePath2(
|
|
35696
|
+
const normalizedPath = normalizePath2(path21);
|
|
35554
35697
|
const name = basename3(normalizedPath);
|
|
35555
35698
|
const now = Date.now();
|
|
35556
35699
|
const expectedChunks = Math.ceil(totalSize / CHUNK_SIZE2);
|
|
@@ -35587,11 +35730,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35587
35730
|
* @param chunkIndex - 0-based chunk index
|
|
35588
35731
|
* @param data - Base64 encoded chunk data
|
|
35589
35732
|
*/
|
|
35590
|
-
async writeFileChunk(
|
|
35733
|
+
async writeFileChunk(path21, chunkIndex, data) {
|
|
35591
35734
|
await this.ensureMigrated();
|
|
35592
35735
|
try {
|
|
35593
35736
|
const { normalizePath: normalizePath2 } = await Promise.resolve().then(() => (init_files(), files_exports));
|
|
35594
|
-
const normalizedPath = normalizePath2(
|
|
35737
|
+
const normalizedPath = normalizePath2(path21);
|
|
35595
35738
|
const binaryString = atob(data);
|
|
35596
35739
|
const dataBuffer = new Uint8Array(binaryString.length);
|
|
35597
35740
|
for (let i = 0; i < binaryString.length; i++) {
|
|
@@ -35613,12 +35756,12 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35613
35756
|
* Complete a chunked file upload.
|
|
35614
35757
|
* Validates all chunks are present and sets chunk_count.
|
|
35615
35758
|
*/
|
|
35616
|
-
async completeChunkedUpload(
|
|
35759
|
+
async completeChunkedUpload(path21, expectedChunks, options) {
|
|
35617
35760
|
await this.ensureMigrated();
|
|
35618
35761
|
try {
|
|
35619
35762
|
const { normalizePath: normalizePath2 } = await Promise.resolve().then(() => (init_files(), files_exports));
|
|
35620
|
-
const
|
|
35621
|
-
const normalizedPath = normalizePath2(
|
|
35763
|
+
const fs19 = this.getFileStorage();
|
|
35764
|
+
const normalizedPath = normalizePath2(path21);
|
|
35622
35765
|
const countResult = await this.ctx.storage.sql.exec(
|
|
35623
35766
|
`SELECT COUNT(*) as count FROM file_chunks WHERE file_path = ?`,
|
|
35624
35767
|
normalizedPath
|
|
@@ -35644,7 +35787,7 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35644
35787
|
thumbnailBuffer || null,
|
|
35645
35788
|
normalizedPath
|
|
35646
35789
|
);
|
|
35647
|
-
const file = await
|
|
35790
|
+
const file = await fs19.stat(normalizedPath);
|
|
35648
35791
|
if (file) {
|
|
35649
35792
|
this.broadcastEvent("file_created", { path: normalizedPath, file });
|
|
35650
35793
|
}
|
|
@@ -35658,11 +35801,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35658
35801
|
* Read a single chunk of a file.
|
|
35659
35802
|
* Use for streaming large files to client.
|
|
35660
35803
|
*/
|
|
35661
|
-
async readFileChunk(
|
|
35804
|
+
async readFileChunk(path21, chunkIndex) {
|
|
35662
35805
|
await this.ensureMigrated();
|
|
35663
35806
|
try {
|
|
35664
35807
|
const { normalizePath: normalizePath2 } = await Promise.resolve().then(() => (init_files(), files_exports));
|
|
35665
|
-
const normalizedPath = normalizePath2(
|
|
35808
|
+
const normalizedPath = normalizePath2(path21);
|
|
35666
35809
|
const cursor = await this.ctx.storage.sql.exec(
|
|
35667
35810
|
`SELECT data FROM file_chunks WHERE file_path = ? AND chunk_index = ?`,
|
|
35668
35811
|
normalizedPath,
|
|
@@ -35687,11 +35830,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
35687
35830
|
/**
|
|
35688
35831
|
* Get file info including chunking metadata.
|
|
35689
35832
|
*/
|
|
35690
|
-
async getFileInfo(
|
|
35833
|
+
async getFileInfo(path21) {
|
|
35691
35834
|
await this.ensureMigrated();
|
|
35692
35835
|
try {
|
|
35693
|
-
const
|
|
35694
|
-
const file = await
|
|
35836
|
+
const fs19 = this.getFileStorage();
|
|
35837
|
+
const file = await fs19.stat(path21);
|
|
35695
35838
|
if (!file) {
|
|
35696
35839
|
return { success: false, error: "File not found" };
|
|
35697
35840
|
}
|
|
@@ -35909,16 +36052,16 @@ function parseUserRouteKey(key) {
|
|
|
35909
36052
|
}
|
|
35910
36053
|
return { key, method, segments, dynamism };
|
|
35911
36054
|
}
|
|
35912
|
-
function matchSegments(route,
|
|
36055
|
+
function matchSegments(route, path21) {
|
|
35913
36056
|
const params = {};
|
|
35914
36057
|
for (let i = 0; i < route.length; i++) {
|
|
35915
36058
|
const seg = route[i];
|
|
35916
36059
|
if (seg === "[*]") {
|
|
35917
36060
|
if (i !== route.length - 1) return null;
|
|
35918
|
-
params["*"] =
|
|
36061
|
+
params["*"] = path21.slice(i).join("/");
|
|
35919
36062
|
return params;
|
|
35920
36063
|
}
|
|
35921
|
-
const value =
|
|
36064
|
+
const value = path21[i];
|
|
35922
36065
|
if (value === void 0) return null;
|
|
35923
36066
|
if (seg.startsWith("[") && seg.endsWith("]")) {
|
|
35924
36067
|
params[seg.slice(1, -1)] = value;
|
|
@@ -35926,16 +36069,16 @@ function matchSegments(route, path20) {
|
|
|
35926
36069
|
return null;
|
|
35927
36070
|
}
|
|
35928
36071
|
}
|
|
35929
|
-
return
|
|
36072
|
+
return path21.length === route.length ? params : null;
|
|
35930
36073
|
}
|
|
35931
36074
|
function matchUserRoute(keys, method, endpointPath) {
|
|
35932
|
-
const
|
|
36075
|
+
const path21 = endpointPath.split("/").filter((s) => s.length > 0);
|
|
35933
36076
|
const wanted = method.toUpperCase();
|
|
35934
36077
|
let best = null;
|
|
35935
36078
|
for (const key of keys) {
|
|
35936
36079
|
const route = parseUserRouteKey(key);
|
|
35937
36080
|
if (route.method !== wanted) continue;
|
|
35938
|
-
const params = matchSegments(route.segments,
|
|
36081
|
+
const params = matchSegments(route.segments, path21);
|
|
35939
36082
|
if (!params) continue;
|
|
35940
36083
|
if (!best || route.dynamism < best.route.dynamism) {
|
|
35941
36084
|
best = { route, params };
|
|
@@ -36960,6 +37103,6 @@ init_context();
|
|
|
36960
37103
|
init_ProviderRegistry();
|
|
36961
37104
|
init_types2();
|
|
36962
37105
|
|
|
36963
|
-
export { CLIENT_STREAM_CHUNK_BYTES, CodeExecutionBridge, DurableAgentBuilder, DurableThread, DurableUserHub, FlowStateSdk, NamespaceResolutionError, PackageDiscoveryService, ProviderRegistry, ThreadWatchdog, agentbuilder, assistantMessageText, authenticate, buildImageDescription, builder, callClient, callClientStream, cat, createNamespaceContext, createThreadEndpointHandler, decodeStreamChunk, defineController2 as defineController, discoverPackages, emitThreadEvent, encodeStreamChunk, enhanceFlowState, exists, find, forceTurn, generateAgentFile, generateImageDescription, generateModelFile, generatePromptFile, getFileStats, getMessages, getMessagesToSummarize, getShortName, getThumbnail, getUnsummarizedImageAttachments, getVisibleAgentNames, getVisibleModelNames, getVisiblePromptNames, getVisibleToolNames, grep, hasImageAttachments, hasJsonArrayEntries, head, injectMessage, isQualifiedName, isVisibleTerminalAssistantMessage, linkFile, messageTimestampSeconds, mkdir, move, optimizeImageContext, parseQualifiedName, qualifyName, queueTool, readFile, readdir, reloadHistory, rename, replaceImagesWithDescriptions, requireAdmin, requireAuth, resolveAgent, resolveHook, resolveModel, resolvePrompt, resolveTool, rmdir, stat, supportsClientForwarding, tail, unlink, updateThread, writeFile, writeImage };
|
|
37106
|
+
export { CLIENT_STREAM_CHUNK_BYTES, CodeExecutionBridge, DurableAgentBuilder, DurableThread, DurableUserHub, FlowStateSdk, NamespaceResolutionError, PackageDiscoveryService, ProviderRegistry, ThreadWatchdog, agentbuilder, assistantMessageText, authenticate, buildImageDescription, builder, callClient, callClientStream, canAccessThread, cat, createNamespaceContext, createThreadEndpointHandler, decodeStreamChunk, defineController2 as defineController, discoverPackages, emitThreadEvent, encodeStreamChunk, enhanceFlowState, exists, find, forceTurn, generateAgentFile, generateImageDescription, generateModelFile, generatePromptFile, getFileStats, getMessages, getMessagesToSummarize, getShortName, getThumbnail, getUnsummarizedImageAttachments, getVisibleAgentNames, getVisibleModelNames, getVisiblePromptNames, getVisibleToolNames, grep, hasImageAttachments, hasJsonArrayEntries, head, injectMessage, isAdminOnlyApiRoute, isHostedInstance, isPublicApiRoute, isQualifiedName, isTrustedLocalDevelopmentRequest, isVisibleTerminalAssistantMessage, linkFile, messageTimestampSeconds, mkdir, move, optimizeImageContext, parseQualifiedName, qualifyName, queueTool, readFile, readdir, reloadHistory, rename, replaceImagesWithDescriptions, requireAdmin, requireAuth, resolveAgent, resolveHook, resolveModel, resolvePrompt, resolveTool, rmdir, stat, supportsClientForwarding, tail, unlink, updateThread, writeFile, writeImage };
|
|
36964
37107
|
//# sourceMappingURL=index.js.map
|
|
36965
37108
|
//# sourceMappingURL=index.js.map
|