@standardagents/builder 0.40.5-next.3b25e2a → 0.40.5
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 +17 -27
- package/dist/built-in-routes.js.map +1 -1
- package/dist/index.js +137 -92
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +7 -0
- package/dist/plugin.js +90 -19
- package/dist/plugin.js.map +1 -1
- package/dist/runtime.d.ts +3 -4
- package/dist/runtime.js +324 -341
- package/dist/runtime.js.map +1 -1
- package/package.json +8 -8
package/dist/runtime.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { getProviderModelPricing } from '@standardagents/provider-pricing';
|
|
2
2
|
import { jsonPathReader } from '@formkit/jsonreader';
|
|
3
3
|
import { ProviderError, mapReasoningLevel, THREAD_STREAM_REASONING_PARAM, isUserEndpoint } from '@standardagents/spec';
|
|
4
|
-
export { ProviderError, belongsToPackage, defineAgent, defineHook, defineModel, definePrompt, defineTool, isPacked, isVisibleInNamespace, mapReasoningLevel } from '@standardagents/spec';
|
|
4
|
+
export { ProviderError, belongsToPackage, defineAgent, defineHook, defineModel, definePrompt, defineProvider, defineTool, isPacked, isVisibleInNamespace, mapReasoningLevel, providerConst, providerEnv, providerValue } from '@standardagents/spec';
|
|
5
5
|
import 'virtual:@standardagents-providers';
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import { transform, collect } from '@standardagents/sip';
|
|
8
8
|
import { DurableObject, WorkerEntrypoint } from 'cloudflare:workers';
|
|
9
|
+
import 'fs';
|
|
10
|
+
import 'path';
|
|
9
11
|
|
|
10
12
|
var __defProp = Object.defineProperty;
|
|
11
13
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -454,8 +456,8 @@ async function readCompletedArg(partialJson, argName) {
|
|
|
454
456
|
controller.close();
|
|
455
457
|
}
|
|
456
458
|
}).getReader();
|
|
457
|
-
for await (const [value,
|
|
458
|
-
if (
|
|
459
|
+
for await (const [value, path2] of jsonPathReader(reader, [argName])) {
|
|
460
|
+
if (path2 === argName) {
|
|
459
461
|
return typeof value === "string" ? value : void 0;
|
|
460
462
|
}
|
|
461
463
|
}
|
|
@@ -1535,11 +1537,11 @@ function stripBase64FromMessages(messages, imagePathMap) {
|
|
|
1535
1537
|
const data = part.data;
|
|
1536
1538
|
if (typeof data === "string") {
|
|
1537
1539
|
if (data.startsWith("data:") || data.length > 1e3) {
|
|
1538
|
-
const
|
|
1540
|
+
const path2 = imagePathMap?.get(data);
|
|
1539
1541
|
return {
|
|
1540
1542
|
...part,
|
|
1541
1543
|
data: "[base64 omitted]",
|
|
1542
|
-
...
|
|
1544
|
+
...path2 ? { path: path2 } : {}
|
|
1543
1545
|
};
|
|
1544
1546
|
}
|
|
1545
1547
|
}
|
|
@@ -2105,14 +2107,14 @@ var init_LLMRequest = __esm({
|
|
|
2105
2107
|
*/
|
|
2106
2108
|
static async callModel(modelId, context, state, logId) {
|
|
2107
2109
|
const { ProviderRegistry: ProviderRegistry2 } = await Promise.resolve().then(() => (init_providers(), providers_exports));
|
|
2108
|
-
const
|
|
2110
|
+
const providerEnv2 = await ProviderRegistry2.buildThreadScopedEnv(state);
|
|
2109
2111
|
const getThreadState = async () => {
|
|
2110
2112
|
const { ThreadStateImpl: ThreadStateImpl2 } = await Promise.resolve().then(() => (init_ThreadStateImpl(), ThreadStateImpl_exports));
|
|
2111
2113
|
return ThreadStateImpl2.fromFlowState(state);
|
|
2112
2114
|
};
|
|
2113
2115
|
const { provider, modelName, modelDef, viaPlatform, platformProxyOrigin } = await ProviderRegistry2.getProvider(
|
|
2114
2116
|
modelId,
|
|
2115
|
-
|
|
2117
|
+
providerEnv2,
|
|
2116
2118
|
state.thread.instance,
|
|
2117
2119
|
getThreadState
|
|
2118
2120
|
);
|
|
@@ -2755,11 +2757,11 @@ var init_LLMRequest = __esm({
|
|
|
2755
2757
|
...choice.message,
|
|
2756
2758
|
images: choice.message?.images?.map(
|
|
2757
2759
|
(img) => {
|
|
2758
|
-
const
|
|
2759
|
-
if (
|
|
2760
|
+
const path2 = img._id ? imagePathMap.get(img._id) : void 0;
|
|
2761
|
+
if (path2) {
|
|
2760
2762
|
return {
|
|
2761
2763
|
type: img.type,
|
|
2762
|
-
image_url: { url:
|
|
2764
|
+
image_url: { url: path2 }
|
|
2763
2765
|
};
|
|
2764
2766
|
}
|
|
2765
2767
|
return img;
|
|
@@ -3286,20 +3288,20 @@ function detectStorageBackend(location) {
|
|
|
3286
3288
|
return "url";
|
|
3287
3289
|
return "local";
|
|
3288
3290
|
}
|
|
3289
|
-
function basename(
|
|
3290
|
-
const parts =
|
|
3291
|
+
function basename(path2) {
|
|
3292
|
+
const parts = path2.split("/").filter(Boolean);
|
|
3291
3293
|
return parts[parts.length - 1] || "";
|
|
3292
3294
|
}
|
|
3293
|
-
function normalizePath(
|
|
3294
|
-
let normalized =
|
|
3295
|
+
function normalizePath(path2) {
|
|
3296
|
+
let normalized = path2.replace(/\/+/g, "/");
|
|
3295
3297
|
if (!normalized.startsWith("/")) normalized = "/" + normalized;
|
|
3296
3298
|
if (normalized.length > 1 && normalized.endsWith("/")) {
|
|
3297
3299
|
normalized = normalized.slice(0, -1);
|
|
3298
3300
|
}
|
|
3299
3301
|
return normalized;
|
|
3300
3302
|
}
|
|
3301
|
-
function dirname(
|
|
3302
|
-
const normalized = normalizePath(
|
|
3303
|
+
function dirname(path2) {
|
|
3304
|
+
const normalized = normalizePath(path2);
|
|
3303
3305
|
const lastSlash = normalized.lastIndexOf("/");
|
|
3304
3306
|
if (lastSlash <= 0) return "/";
|
|
3305
3307
|
return normalized.slice(0, lastSlash);
|
|
@@ -3317,7 +3319,7 @@ function validateMovePaths(source, destination, isDirectory) {
|
|
|
3317
3319
|
);
|
|
3318
3320
|
}
|
|
3319
3321
|
}
|
|
3320
|
-
function resolveRenameDestination(
|
|
3322
|
+
function resolveRenameDestination(path2, newName) {
|
|
3321
3323
|
if (typeof newName !== "string" || newName.length === 0) {
|
|
3322
3324
|
throw new Error("New name must be a non-empty string");
|
|
3323
3325
|
}
|
|
@@ -3327,7 +3329,7 @@ function resolveRenameDestination(path, newName) {
|
|
|
3327
3329
|
if (newName === "." || newName === "..") {
|
|
3328
3330
|
throw new Error("New name must not be '.' or '..'");
|
|
3329
3331
|
}
|
|
3330
|
-
const normalized = normalizePath(
|
|
3332
|
+
const normalized = normalizePath(path2);
|
|
3331
3333
|
const parent = dirname(normalized);
|
|
3332
3334
|
return parent === "/" ? `/${newName}` : `${parent}/${newName}`;
|
|
3333
3335
|
}
|
|
@@ -3451,8 +3453,8 @@ var init_files = __esm({
|
|
|
3451
3453
|
* Write a file to storage.
|
|
3452
3454
|
* Files > CHUNK_SIZE are automatically chunked into file_chunks table.
|
|
3453
3455
|
*/
|
|
3454
|
-
async writeFile(
|
|
3455
|
-
const normalizedPath = normalizePath(
|
|
3456
|
+
async writeFile(path2, data, mimeType, options) {
|
|
3457
|
+
const normalizedPath = normalizePath(path2);
|
|
3456
3458
|
const name = basename(normalizedPath);
|
|
3457
3459
|
const isText = isTextMimeType(mimeType);
|
|
3458
3460
|
const now = Date.now();
|
|
@@ -3564,8 +3566,8 @@ var init_files = __esm({
|
|
|
3564
3566
|
/**
|
|
3565
3567
|
* Link to an external file (URL, S3, R2)
|
|
3566
3568
|
*/
|
|
3567
|
-
async linkFile(
|
|
3568
|
-
const normalizedPath = normalizePath(
|
|
3569
|
+
async linkFile(path2, location, options) {
|
|
3570
|
+
const normalizedPath = normalizePath(path2);
|
|
3569
3571
|
const name = basename(normalizedPath);
|
|
3570
3572
|
const storage = detectStorageBackend(location);
|
|
3571
3573
|
const now = Date.now();
|
|
@@ -3604,8 +3606,8 @@ var init_files = __esm({
|
|
|
3604
3606
|
* WARNING: For large chunked files, this loads the entire file into memory.
|
|
3605
3607
|
* Use streamFile() for memory-efficient access to large files.
|
|
3606
3608
|
*/
|
|
3607
|
-
async readFile(
|
|
3608
|
-
const normalizedPath = normalizePath(
|
|
3609
|
+
async readFile(path2) {
|
|
3610
|
+
const normalizedPath = normalizePath(path2);
|
|
3609
3611
|
const cursor = await this.sql.exec(
|
|
3610
3612
|
`SELECT data, content, storage, is_chunked, chunk_count FROM files WHERE path = ? AND is_directory = 0`,
|
|
3611
3613
|
normalizedPath
|
|
@@ -3657,8 +3659,8 @@ var init_files = __esm({
|
|
|
3657
3659
|
* Memory-efficient way to read large chunked files.
|
|
3658
3660
|
* Yields one chunk at a time for streaming HTTP responses.
|
|
3659
3661
|
*/
|
|
3660
|
-
async *streamFile(
|
|
3661
|
-
const normalizedPath = normalizePath(
|
|
3662
|
+
async *streamFile(path2) {
|
|
3663
|
+
const normalizedPath = normalizePath(path2);
|
|
3662
3664
|
const cursor = await this.sql.exec(
|
|
3663
3665
|
`SELECT data, content, storage, is_chunked, chunk_count FROM files WHERE path = ? AND is_directory = 0`,
|
|
3664
3666
|
normalizedPath
|
|
@@ -3692,8 +3694,8 @@ var init_files = __esm({
|
|
|
3692
3694
|
/**
|
|
3693
3695
|
* Read text file content
|
|
3694
3696
|
*/
|
|
3695
|
-
async readTextFile(
|
|
3696
|
-
const normalizedPath = normalizePath(
|
|
3697
|
+
async readTextFile(path2) {
|
|
3698
|
+
const normalizedPath = normalizePath(path2);
|
|
3697
3699
|
const cursor = await this.sql.exec(
|
|
3698
3700
|
`SELECT content, data, storage FROM files WHERE path = ? AND is_directory = 0`,
|
|
3699
3701
|
normalizedPath
|
|
@@ -3711,8 +3713,8 @@ var init_files = __esm({
|
|
|
3711
3713
|
/**
|
|
3712
3714
|
* Get file metadata (stat)
|
|
3713
3715
|
*/
|
|
3714
|
-
async stat(
|
|
3715
|
-
const normalizedPath = normalizePath(
|
|
3716
|
+
async stat(path2) {
|
|
3717
|
+
const normalizedPath = normalizePath(path2);
|
|
3716
3718
|
const cursor = await this.sql.exec(
|
|
3717
3719
|
`SELECT path, name, mime_type, storage, location, size, metadata, is_directory, created_at, width, height, is_chunked, chunk_count
|
|
3718
3720
|
FROM files WHERE path = ?`,
|
|
@@ -3725,8 +3727,8 @@ var init_files = __esm({
|
|
|
3725
3727
|
/**
|
|
3726
3728
|
* Check if file or directory exists
|
|
3727
3729
|
*/
|
|
3728
|
-
async exists(
|
|
3729
|
-
const normalizedPath = normalizePath(
|
|
3730
|
+
async exists(path2) {
|
|
3731
|
+
const normalizedPath = normalizePath(path2);
|
|
3730
3732
|
const cursor = await this.sql.exec(
|
|
3731
3733
|
`SELECT COUNT(*) as count FROM files WHERE path = ?`,
|
|
3732
3734
|
normalizedPath
|
|
@@ -3736,8 +3738,8 @@ var init_files = __esm({
|
|
|
3736
3738
|
/**
|
|
3737
3739
|
* Delete a file
|
|
3738
3740
|
*/
|
|
3739
|
-
async unlink(
|
|
3740
|
-
const normalizedPath = normalizePath(
|
|
3741
|
+
async unlink(path2) {
|
|
3742
|
+
const normalizedPath = normalizePath(path2);
|
|
3741
3743
|
await this.sql.exec(
|
|
3742
3744
|
`DELETE FROM files WHERE path = ? AND is_directory = 0`,
|
|
3743
3745
|
normalizedPath
|
|
@@ -3747,8 +3749,8 @@ var init_files = __esm({
|
|
|
3747
3749
|
/**
|
|
3748
3750
|
* Create a directory marker
|
|
3749
3751
|
*/
|
|
3750
|
-
async mkdir(
|
|
3751
|
-
const normalizedPath = normalizePath(
|
|
3752
|
+
async mkdir(path2) {
|
|
3753
|
+
const normalizedPath = normalizePath(path2);
|
|
3752
3754
|
const name = basename(normalizedPath);
|
|
3753
3755
|
const now = Date.now();
|
|
3754
3756
|
await this.sql.exec(
|
|
@@ -3773,8 +3775,8 @@ var init_files = __esm({
|
|
|
3773
3775
|
/**
|
|
3774
3776
|
* List directory contents
|
|
3775
3777
|
*/
|
|
3776
|
-
async readdir(
|
|
3777
|
-
const normalizedPath = normalizePath(
|
|
3778
|
+
async readdir(path2) {
|
|
3779
|
+
const normalizedPath = normalizePath(path2);
|
|
3778
3780
|
const prefix = normalizedPath === "/" ? "/" : normalizedPath + "/";
|
|
3779
3781
|
const cursor = await this.sql.exec(
|
|
3780
3782
|
`SELECT path, name, mime_type, storage, location, size, metadata, is_directory, created_at
|
|
@@ -3792,8 +3794,8 @@ var init_files = __esm({
|
|
|
3792
3794
|
/**
|
|
3793
3795
|
* Remove empty directory
|
|
3794
3796
|
*/
|
|
3795
|
-
async rmdir(
|
|
3796
|
-
const normalizedPath = normalizePath(
|
|
3797
|
+
async rmdir(path2) {
|
|
3798
|
+
const normalizedPath = normalizePath(path2);
|
|
3797
3799
|
const prefix = normalizedPath + "/";
|
|
3798
3800
|
const cursor = await this.sql.exec(
|
|
3799
3801
|
`SELECT COUNT(*) as count FROM files WHERE path LIKE ? || '%'`,
|
|
@@ -3891,9 +3893,9 @@ var init_files = __esm({
|
|
|
3891
3893
|
* Rename a file or directory in place, keeping it in the same parent
|
|
3892
3894
|
* directory. `newName` must be a bare file name with no path separators.
|
|
3893
3895
|
*/
|
|
3894
|
-
async rename(
|
|
3895
|
-
const destination = resolveRenameDestination(
|
|
3896
|
-
return this.move(normalizePath(
|
|
3896
|
+
async rename(path2, newName) {
|
|
3897
|
+
const destination = resolveRenameDestination(path2, newName);
|
|
3898
|
+
return this.move(normalizePath(path2), destination);
|
|
3897
3899
|
}
|
|
3898
3900
|
/**
|
|
3899
3901
|
* Get storage statistics
|
|
@@ -3923,8 +3925,8 @@ var init_files = __esm({
|
|
|
3923
3925
|
/**
|
|
3924
3926
|
* Get thumbnail for an image
|
|
3925
3927
|
*/
|
|
3926
|
-
async getThumbnail(
|
|
3927
|
-
const normalizedPath = normalizePath(
|
|
3928
|
+
async getThumbnail(path2) {
|
|
3929
|
+
const normalizedPath = normalizePath(path2);
|
|
3928
3930
|
const cursor = await this.sql.exec(
|
|
3929
3931
|
`SELECT thumbnail FROM files WHERE path = ? AND is_directory = 0`,
|
|
3930
3932
|
normalizedPath
|
|
@@ -4375,8 +4377,8 @@ var init_ToolExecutor = __esm({
|
|
|
4375
4377
|
const validation = argsSchema.safeParse(args);
|
|
4376
4378
|
if (!validation.success) {
|
|
4377
4379
|
const errorMessage = validation.error.issues.map((issue) => {
|
|
4378
|
-
const
|
|
4379
|
-
return `[${
|
|
4380
|
+
const path2 = issue.path.length > 0 ? issue.path.map(String).join(".") : "root";
|
|
4381
|
+
return `[${path2}] ${issue.message}`;
|
|
4380
4382
|
}).join("; ");
|
|
4381
4383
|
return {
|
|
4382
4384
|
status: "error",
|
|
@@ -5074,9 +5076,7 @@ Message one with subagent_message(referenceId, message).`
|
|
|
5074
5076
|
if (resumable) {
|
|
5075
5077
|
await this.settleResumableChildAfterRun(
|
|
5076
5078
|
state,
|
|
5077
|
-
|
|
5078
|
-
childThreadId,
|
|
5079
|
-
childResult
|
|
5079
|
+
childThreadId
|
|
5080
5080
|
);
|
|
5081
5081
|
} else if (stub.terminateThread) {
|
|
5082
5082
|
await stub.terminateThread(childThreadId);
|
|
@@ -5088,7 +5088,7 @@ Message one with subagent_message(referenceId, message).`
|
|
|
5088
5088
|
attachments: copiedAttachments,
|
|
5089
5089
|
subagent_id: childThreadId
|
|
5090
5090
|
};
|
|
5091
|
-
return resumable
|
|
5091
|
+
return resumable ? this.withReferenceInToolResult(toolResult, childThreadId) : toolResult;
|
|
5092
5092
|
}
|
|
5093
5093
|
const backgroundRun = (async () => {
|
|
5094
5094
|
try {
|
|
@@ -5123,9 +5123,7 @@ Message one with subagent_message(referenceId, message).`
|
|
|
5123
5123
|
if (resumable) {
|
|
5124
5124
|
await this.settleResumableChildAfterRun(
|
|
5125
5125
|
state,
|
|
5126
|
-
|
|
5127
|
-
childThreadId,
|
|
5128
|
-
childResult
|
|
5126
|
+
childThreadId
|
|
5129
5127
|
);
|
|
5130
5128
|
} else if (stub.terminateThread) {
|
|
5131
5129
|
await stub.terminateThread(childThreadId);
|
|
@@ -5374,13 +5372,13 @@ Message one with subagent_message(referenceId, message).`
|
|
|
5374
5372
|
new Set(
|
|
5375
5373
|
issues.map(
|
|
5376
5374
|
(issue) => Array.isArray(issue.path) ? issue.path.map(String).join(".") : String(issue.path ?? "")
|
|
5377
|
-
).filter((
|
|
5375
|
+
).filter((path2) => path2.length > 0)
|
|
5378
5376
|
)
|
|
5379
5377
|
);
|
|
5380
5378
|
const detail = issues.map((issue) => {
|
|
5381
|
-
const
|
|
5379
|
+
const path2 = Array.isArray(issue.path) ? issue.path.map(String).join(".") : "";
|
|
5382
5380
|
const message = typeof issue.message === "string" ? issue.message : "invalid value";
|
|
5383
|
-
return
|
|
5381
|
+
return path2 ? `${path2}: ${message}` : message;
|
|
5384
5382
|
}).join("; ") || parsed.error.message || "invalid arguments";
|
|
5385
5383
|
const agentLabel = agentDef.title || agentDef.name || options.agentName || qualifiedPromptName;
|
|
5386
5384
|
return {
|
|
@@ -5520,18 +5518,8 @@ Message one with subagent_message(referenceId, message).`
|
|
|
5520
5518
|
JSON.stringify(next)
|
|
5521
5519
|
);
|
|
5522
5520
|
}
|
|
5523
|
-
static
|
|
5524
|
-
|
|
5525
|
-
}
|
|
5526
|
-
static async settleResumableChildAfterRun(state, childThread, reference, result) {
|
|
5527
|
-
if (!this.isTerminalSubagentResult(result)) {
|
|
5528
|
-
await this.updateChildStatus(state, reference, "idle");
|
|
5529
|
-
return;
|
|
5530
|
-
}
|
|
5531
|
-
await this.updateChildStatus(state, reference, "terminated");
|
|
5532
|
-
if (typeof childThread.terminateThread === "function") {
|
|
5533
|
-
await childThread.terminateThread(reference);
|
|
5534
|
-
}
|
|
5521
|
+
static async settleResumableChildAfterRun(state, reference) {
|
|
5522
|
+
await this.updateChildStatus(state, reference, "idle");
|
|
5535
5523
|
}
|
|
5536
5524
|
static async buildChildInvocationMessages(state, childThread, content, receivesMessages, parentAttachments, initialArguments) {
|
|
5537
5525
|
const copiedAttachments = await this.copyAttachmentsBetweenThreads(
|
|
@@ -5739,8 +5727,8 @@ Reference: ${referenceId}` : `Reference: ${referenceId}`;
|
|
|
5739
5727
|
}
|
|
5740
5728
|
return [];
|
|
5741
5729
|
}
|
|
5742
|
-
static inferMimeTypeFromPath(
|
|
5743
|
-
const normalized =
|
|
5730
|
+
static inferMimeTypeFromPath(path2) {
|
|
5731
|
+
const normalized = path2.toLowerCase();
|
|
5744
5732
|
if (normalized.endsWith(".png")) return "image/png";
|
|
5745
5733
|
if (normalized.endsWith(".jpg") || normalized.endsWith(".jpeg")) return "image/jpeg";
|
|
5746
5734
|
if (normalized.endsWith(".webp")) return "image/webp";
|
|
@@ -5779,7 +5767,7 @@ Reference: ${referenceId}` : `Reference: ${referenceId}`;
|
|
|
5779
5767
|
ext: value.slice(lastDot + 1).toLowerCase()
|
|
5780
5768
|
};
|
|
5781
5769
|
}
|
|
5782
|
-
static resolveAttachmentMimeType(sourceMimeType, fallbackMimeType,
|
|
5770
|
+
static resolveAttachmentMimeType(sourceMimeType, fallbackMimeType, path2) {
|
|
5783
5771
|
const source = sourceMimeType?.trim();
|
|
5784
5772
|
if (source && source !== "application/octet-stream") {
|
|
5785
5773
|
return source;
|
|
@@ -5788,7 +5776,7 @@ Reference: ${referenceId}` : `Reference: ${referenceId}`;
|
|
|
5788
5776
|
if (fallback && fallback !== "application/octet-stream") {
|
|
5789
5777
|
return fallback;
|
|
5790
5778
|
}
|
|
5791
|
-
return this.inferMimeTypeFromPath(
|
|
5779
|
+
return this.inferMimeTypeFromPath(path2) ?? source ?? fallback ?? "application/octet-stream";
|
|
5792
5780
|
}
|
|
5793
5781
|
static buildAttachmentTargetPath(preferredName, mimeType, sourcePath) {
|
|
5794
5782
|
const safeName = this.sanitizeFilename(preferredName);
|
|
@@ -5885,8 +5873,8 @@ Reference: ${referenceId}` : `Reference: ${referenceId}`;
|
|
|
5885
5873
|
}
|
|
5886
5874
|
return copied;
|
|
5887
5875
|
}
|
|
5888
|
-
static async readAttachmentDataFromSource(sourceThread,
|
|
5889
|
-
const sourceData = await sourceThread.readFile(
|
|
5876
|
+
static async readAttachmentDataFromSource(sourceThread, path2, sourceFile, allowedAttachmentFetchHosts) {
|
|
5877
|
+
const sourceData = await sourceThread.readFile(path2);
|
|
5890
5878
|
if (sourceData.success && sourceData.data) {
|
|
5891
5879
|
return sourceData.data;
|
|
5892
5880
|
}
|
|
@@ -5923,7 +5911,7 @@ Reference: ${referenceId}` : `Reference: ${referenceId}`;
|
|
|
5923
5911
|
if (!attachments || attachments.length === 0) {
|
|
5924
5912
|
return "";
|
|
5925
5913
|
}
|
|
5926
|
-
const paths = attachments.map((attachment) => attachment.path).filter((
|
|
5914
|
+
const paths = attachments.map((attachment) => attachment.path).filter((path2) => typeof path2 === "string" && path2.length > 0);
|
|
5927
5915
|
if (paths.length === 0) {
|
|
5928
5916
|
return "";
|
|
5929
5917
|
}
|
|
@@ -6220,7 +6208,7 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
6220
6208
|
mappedAttachmentValue
|
|
6221
6209
|
);
|
|
6222
6210
|
const resolvedPaths = new Set(mappedRefs.map((ref) => ref.path));
|
|
6223
|
-
const missingPaths = candidatePaths.filter((
|
|
6211
|
+
const missingPaths = candidatePaths.filter((path2) => !resolvedPaths.has(path2));
|
|
6224
6212
|
if (candidatePaths.length === 0 || missingPaths.length > 0) {
|
|
6225
6213
|
processedResult = {
|
|
6226
6214
|
status: "error",
|
|
@@ -6402,8 +6390,8 @@ ${attachmentPaths}`;
|
|
|
6402
6390
|
if (mimeType.startsWith("image/")) {
|
|
6403
6391
|
return true;
|
|
6404
6392
|
}
|
|
6405
|
-
const
|
|
6406
|
-
return
|
|
6393
|
+
const path2 = ref.path.toLowerCase();
|
|
6394
|
+
return path2.endsWith(".png") || path2.endsWith(".jpg") || path2.endsWith(".jpeg") || path2.endsWith(".webp") || path2.endsWith(".gif") || path2.endsWith(".bmp") || path2.endsWith(".svg");
|
|
6407
6395
|
});
|
|
6408
6396
|
if (imageRefs.length === 0) {
|
|
6409
6397
|
return;
|
|
@@ -6469,27 +6457,27 @@ ${attachmentPaths}`;
|
|
|
6469
6457
|
*/
|
|
6470
6458
|
static async processToolAttachments(attachments, state) {
|
|
6471
6459
|
const { FileStorage: FileStorage2 } = await Promise.resolve().then(() => (init_files(), files_exports));
|
|
6472
|
-
const
|
|
6460
|
+
const fs2 = new FileStorage2(state.storage.sql);
|
|
6473
6461
|
const refs = [];
|
|
6474
6462
|
for (const attachment of attachments) {
|
|
6475
6463
|
try {
|
|
6476
6464
|
const attachmentId = crypto.randomUUID();
|
|
6477
6465
|
const timestamp = Date.now();
|
|
6478
6466
|
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";
|
|
6479
|
-
const
|
|
6467
|
+
const path2 = `/attachments/${timestamp}-${attachmentId.slice(0, 8)}.${ext}`;
|
|
6480
6468
|
const binaryString = atob(attachment.data);
|
|
6481
6469
|
const dataBuffer = new Uint8Array(binaryString.length);
|
|
6482
6470
|
for (let i = 0; i < binaryString.length; i++) {
|
|
6483
6471
|
dataBuffer[i] = binaryString.charCodeAt(i);
|
|
6484
6472
|
}
|
|
6485
|
-
await
|
|
6473
|
+
await fs2.writeFile(path2, dataBuffer.buffer, attachment.mimeType, {
|
|
6486
6474
|
width: attachment.width,
|
|
6487
6475
|
height: attachment.height
|
|
6488
6476
|
});
|
|
6489
6477
|
const ref = {
|
|
6490
6478
|
id: attachmentId,
|
|
6491
6479
|
type: "file",
|
|
6492
|
-
path,
|
|
6480
|
+
path: path2,
|
|
6493
6481
|
name: attachment.name,
|
|
6494
6482
|
mimeType: attachment.mimeType,
|
|
6495
6483
|
size: dataBuffer.byteLength
|
|
@@ -10852,20 +10840,20 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
10852
10840
|
continue;
|
|
10853
10841
|
}
|
|
10854
10842
|
const attachmentId = crypto.randomUUID();
|
|
10855
|
-
const
|
|
10843
|
+
const path2 = `/attachments/${Date.now()}-${attachmentId.slice(0, 8)}.${ext}`;
|
|
10856
10844
|
try {
|
|
10857
|
-
const written = await state.thread.instance.writeFile(
|
|
10845
|
+
const written = await state.thread.instance.writeFile(path2, base64Data, mimeType);
|
|
10858
10846
|
if (written && written.success === false) {
|
|
10859
10847
|
console.error("[FlowEngine] Generated image write failed:", written.error);
|
|
10860
10848
|
continue;
|
|
10861
10849
|
}
|
|
10862
10850
|
if (image.id) {
|
|
10863
|
-
imagePathMap.set(image.id,
|
|
10851
|
+
imagePathMap.set(image.id, path2);
|
|
10864
10852
|
}
|
|
10865
10853
|
refs.push({
|
|
10866
10854
|
id: attachmentId,
|
|
10867
10855
|
type: "file",
|
|
10868
|
-
path,
|
|
10856
|
+
path: path2,
|
|
10869
10857
|
name: `generated-${attachmentId}.${ext}`,
|
|
10870
10858
|
mimeType,
|
|
10871
10859
|
size: Math.ceil(base64Data.length * 3 / 4)
|
|
@@ -10930,9 +10918,9 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
10930
10918
|
continue;
|
|
10931
10919
|
}
|
|
10932
10920
|
const attachmentId = crypto.randomUUID();
|
|
10933
|
-
const
|
|
10921
|
+
const path2 = `/attachments/${Date.now()}-${attachmentId.slice(0, 8)}.${ext}`;
|
|
10934
10922
|
try {
|
|
10935
|
-
const written = await state.thread.instance.writeFile(
|
|
10923
|
+
const written = await state.thread.instance.writeFile(path2, base64Data, mimeType);
|
|
10936
10924
|
if (written && written.success === false) {
|
|
10937
10925
|
console.error(`[FlowEngine] ${toolName} image write failed:`, written.error);
|
|
10938
10926
|
continue;
|
|
@@ -10940,7 +10928,7 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
10940
10928
|
const attachmentRef = {
|
|
10941
10929
|
id: attachmentId,
|
|
10942
10930
|
type: "file",
|
|
10943
|
-
path,
|
|
10931
|
+
path: path2,
|
|
10944
10932
|
name: `generated-${attachmentId}.${ext}`,
|
|
10945
10933
|
mimeType,
|
|
10946
10934
|
size: Math.ceil(base64Data.length * 3 / 4)
|
|
@@ -11003,7 +10991,7 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
11003
10991
|
content: "Image generated successfully",
|
|
11004
10992
|
status: "success",
|
|
11005
10993
|
timestamp: Date.now(),
|
|
11006
|
-
attachment_path:
|
|
10994
|
+
attachment_path: path2
|
|
11007
10995
|
});
|
|
11008
10996
|
await state.storage.sql.exec(
|
|
11009
10997
|
`UPDATE logs SET tool_results = ?1 WHERE id = ?2`,
|
|
@@ -11025,7 +11013,7 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
|
|
|
11025
11013
|
}
|
|
11026
11014
|
}
|
|
11027
11015
|
if (image.id) {
|
|
11028
|
-
imagePathMap.set(image.id,
|
|
11016
|
+
imagePathMap.set(image.id, path2);
|
|
11029
11017
|
}
|
|
11030
11018
|
} catch (error) {
|
|
11031
11019
|
console.error(`[FlowEngine] Failed to store provider tool result for ${toolName}:`, error);
|
|
@@ -11890,7 +11878,7 @@ async function updateThread(thread, params) {
|
|
|
11890
11878
|
}
|
|
11891
11879
|
return result.thread;
|
|
11892
11880
|
}
|
|
11893
|
-
async function writeFile(flow,
|
|
11881
|
+
async function writeFile(flow, path2, data, mimeType, options) {
|
|
11894
11882
|
const instance = flow.thread.instance;
|
|
11895
11883
|
let base64Data;
|
|
11896
11884
|
if (typeof data === "string") {
|
|
@@ -11912,7 +11900,7 @@ async function writeFile(flow, path, data, mimeType, options) {
|
|
|
11912
11900
|
}
|
|
11913
11901
|
base64Thumbnail = btoa(binary);
|
|
11914
11902
|
}
|
|
11915
|
-
const result = await instance.writeFile(
|
|
11903
|
+
const result = await instance.writeFile(path2, base64Data, mimeType, {
|
|
11916
11904
|
metadata: options?.metadata,
|
|
11917
11905
|
thumbnail: base64Thumbnail
|
|
11918
11906
|
});
|
|
@@ -11921,20 +11909,20 @@ async function writeFile(flow, path, data, mimeType, options) {
|
|
|
11921
11909
|
}
|
|
11922
11910
|
return result.file;
|
|
11923
11911
|
}
|
|
11924
|
-
async function writeImage(flow,
|
|
11925
|
-
return writeFile(flow,
|
|
11912
|
+
async function writeImage(flow, path2, data, mimeType, options) {
|
|
11913
|
+
return writeFile(flow, path2, data, mimeType, options);
|
|
11926
11914
|
}
|
|
11927
|
-
async function linkFile(flow,
|
|
11915
|
+
async function linkFile(flow, path2, location, options) {
|
|
11928
11916
|
const instance = flow.thread.instance;
|
|
11929
|
-
const result = await instance.linkFile(
|
|
11917
|
+
const result = await instance.linkFile(path2, location, options);
|
|
11930
11918
|
if (!result.success) {
|
|
11931
11919
|
throw new Error(result.error || "Failed to link file");
|
|
11932
11920
|
}
|
|
11933
11921
|
return result.file;
|
|
11934
11922
|
}
|
|
11935
|
-
async function readFile(flow,
|
|
11923
|
+
async function readFile(flow, path2) {
|
|
11936
11924
|
const instance = flow.thread.instance;
|
|
11937
|
-
const result = await instance.readFile(
|
|
11925
|
+
const result = await instance.readFile(path2);
|
|
11938
11926
|
if (!result.success) {
|
|
11939
11927
|
return null;
|
|
11940
11928
|
}
|
|
@@ -11945,45 +11933,45 @@ async function readFile(flow, path) {
|
|
|
11945
11933
|
}
|
|
11946
11934
|
return bytes.buffer;
|
|
11947
11935
|
}
|
|
11948
|
-
async function stat(flow,
|
|
11936
|
+
async function stat(flow, path2) {
|
|
11949
11937
|
const instance = flow.thread.instance;
|
|
11950
|
-
const result = await instance.statFile(
|
|
11938
|
+
const result = await instance.statFile(path2);
|
|
11951
11939
|
if (!result.success) {
|
|
11952
11940
|
return null;
|
|
11953
11941
|
}
|
|
11954
11942
|
return result.file;
|
|
11955
11943
|
}
|
|
11956
|
-
async function exists(flow,
|
|
11944
|
+
async function exists(flow, path2) {
|
|
11957
11945
|
const instance = flow.thread.instance;
|
|
11958
|
-
const result = await instance.fileExists(
|
|
11946
|
+
const result = await instance.fileExists(path2);
|
|
11959
11947
|
return result.success && result.exists;
|
|
11960
11948
|
}
|
|
11961
|
-
async function unlink(flow,
|
|
11949
|
+
async function unlink(flow, path2) {
|
|
11962
11950
|
const instance = flow.thread.instance;
|
|
11963
|
-
const result = await instance.unlinkFile(
|
|
11951
|
+
const result = await instance.unlinkFile(path2);
|
|
11964
11952
|
if (!result.success) {
|
|
11965
11953
|
throw new Error(result.error || "Failed to delete file");
|
|
11966
11954
|
}
|
|
11967
11955
|
}
|
|
11968
|
-
async function mkdir(flow,
|
|
11956
|
+
async function mkdir(flow, path2) {
|
|
11969
11957
|
const instance = flow.thread.instance;
|
|
11970
|
-
const result = await instance.mkdirFile(
|
|
11958
|
+
const result = await instance.mkdirFile(path2);
|
|
11971
11959
|
if (!result.success) {
|
|
11972
11960
|
throw new Error(result.error || "Failed to create directory");
|
|
11973
11961
|
}
|
|
11974
11962
|
return result.directory;
|
|
11975
11963
|
}
|
|
11976
|
-
async function readdir(flow,
|
|
11964
|
+
async function readdir(flow, path2) {
|
|
11977
11965
|
const instance = flow.thread.instance;
|
|
11978
|
-
const result = await instance.readdirFile(
|
|
11966
|
+
const result = await instance.readdirFile(path2);
|
|
11979
11967
|
if (!result.success) {
|
|
11980
11968
|
throw new Error(result.error || "Failed to read directory");
|
|
11981
11969
|
}
|
|
11982
11970
|
return result.files;
|
|
11983
11971
|
}
|
|
11984
|
-
async function rmdir(flow,
|
|
11972
|
+
async function rmdir(flow, path2) {
|
|
11985
11973
|
const instance = flow.thread.instance;
|
|
11986
|
-
const result = await instance.rmdirFile(
|
|
11974
|
+
const result = await instance.rmdirFile(path2);
|
|
11987
11975
|
if (!result.success) {
|
|
11988
11976
|
throw new Error(result.error || "Failed to remove directory");
|
|
11989
11977
|
}
|
|
@@ -11996,9 +11984,9 @@ async function move(flow, sourcePath, destinationPath) {
|
|
|
11996
11984
|
}
|
|
11997
11985
|
return result.file;
|
|
11998
11986
|
}
|
|
11999
|
-
async function rename(flow,
|
|
11987
|
+
async function rename(flow, path2, newName) {
|
|
12000
11988
|
const instance = flow.thread.instance;
|
|
12001
|
-
const result = await instance.renameFile(
|
|
11989
|
+
const result = await instance.renameFile(path2, newName);
|
|
12002
11990
|
if (!result.success) {
|
|
12003
11991
|
throw new Error(result.error || "Failed to rename file");
|
|
12004
11992
|
}
|
|
@@ -12012,9 +12000,9 @@ async function getFileStats(flow) {
|
|
|
12012
12000
|
}
|
|
12013
12001
|
return result.stats;
|
|
12014
12002
|
}
|
|
12015
|
-
async function getThumbnail(flow,
|
|
12003
|
+
async function getThumbnail(flow, path2) {
|
|
12016
12004
|
const instance = flow.thread.instance;
|
|
12017
|
-
const result = await instance.getFileThumbnail(
|
|
12005
|
+
const result = await instance.getFileThumbnail(path2);
|
|
12018
12006
|
if (!result.success) {
|
|
12019
12007
|
return null;
|
|
12020
12008
|
}
|
|
@@ -12025,22 +12013,22 @@ async function getThumbnail(flow, path) {
|
|
|
12025
12013
|
}
|
|
12026
12014
|
return bytes.buffer;
|
|
12027
12015
|
}
|
|
12028
|
-
async function cat(flow,
|
|
12016
|
+
async function cat(flow, path2) {
|
|
12029
12017
|
const instance = flow.thread.instance;
|
|
12030
|
-
const result = await instance.readTextFile(
|
|
12018
|
+
const result = await instance.readTextFile(path2);
|
|
12031
12019
|
if (!result.success) {
|
|
12032
12020
|
return null;
|
|
12033
12021
|
}
|
|
12034
12022
|
return result.content;
|
|
12035
12023
|
}
|
|
12036
|
-
async function head(flow,
|
|
12037
|
-
const content = await cat(flow,
|
|
12024
|
+
async function head(flow, path2, lines = 10) {
|
|
12025
|
+
const content = await cat(flow, path2);
|
|
12038
12026
|
if (content === null) return null;
|
|
12039
12027
|
const allLines = content.split("\n");
|
|
12040
12028
|
return allLines.slice(0, lines).join("\n");
|
|
12041
12029
|
}
|
|
12042
|
-
async function tail(flow,
|
|
12043
|
-
const content = await cat(flow,
|
|
12030
|
+
async function tail(flow, path2, lines = 10) {
|
|
12031
|
+
const content = await cat(flow, path2);
|
|
12044
12032
|
if (content === null) return null;
|
|
12045
12033
|
const allLines = content.split("\n");
|
|
12046
12034
|
return allLines.slice(-lines).join("\n");
|
|
@@ -12579,32 +12567,32 @@ function prepareBridge(options, reports, logs) {
|
|
|
12579
12567
|
logs
|
|
12580
12568
|
};
|
|
12581
12569
|
}
|
|
12582
|
-
function prepareNamespaceRecord(value,
|
|
12570
|
+
function prepareNamespaceRecord(value, path2, functions) {
|
|
12583
12571
|
const out = {};
|
|
12584
12572
|
for (const [key, namespace] of Object.entries(value)) {
|
|
12585
|
-
out[key] = prepareValueRecord(namespace, `${
|
|
12573
|
+
out[key] = prepareValueRecord(namespace, `${path2}.${key}`, functions);
|
|
12586
12574
|
}
|
|
12587
12575
|
return out;
|
|
12588
12576
|
}
|
|
12589
|
-
function prepareValueRecord(value,
|
|
12577
|
+
function prepareValueRecord(value, path2, functions) {
|
|
12590
12578
|
const out = {};
|
|
12591
12579
|
for (const [key, item] of Object.entries(value)) {
|
|
12592
|
-
out[key] = prepareBridgeValue(item, `${
|
|
12580
|
+
out[key] = prepareBridgeValue(item, `${path2}.${key}`, functions);
|
|
12593
12581
|
}
|
|
12594
12582
|
return out;
|
|
12595
12583
|
}
|
|
12596
|
-
function prepareBridgeValue(value,
|
|
12584
|
+
function prepareBridgeValue(value, path2, functions) {
|
|
12597
12585
|
if (typeof value === "function") {
|
|
12598
|
-
functions.set(
|
|
12599
|
-
return { __agentbuilderType: "function", id:
|
|
12586
|
+
functions.set(path2, value);
|
|
12587
|
+
return { __agentbuilderType: "function", id: path2 };
|
|
12600
12588
|
}
|
|
12601
12589
|
if (isThenable(value)) {
|
|
12602
|
-
const promiseId = `${
|
|
12590
|
+
const promiseId = `${path2}.__promise`;
|
|
12603
12591
|
functions.set(promiseId, async () => value);
|
|
12604
12592
|
return { __agentbuilderType: "promise", id: promiseId };
|
|
12605
12593
|
}
|
|
12606
12594
|
if (Array.isArray(value)) {
|
|
12607
|
-
return value.map((item, index) => prepareBridgeValue(item, `${
|
|
12595
|
+
return value.map((item, index) => prepareBridgeValue(item, `${path2}.${index}`, functions));
|
|
12608
12596
|
}
|
|
12609
12597
|
if (value && typeof value === "object") {
|
|
12610
12598
|
if (value instanceof Date || value instanceof Map || value instanceof Set || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {
|
|
@@ -12615,7 +12603,7 @@ function prepareBridgeValue(value, path, functions) {
|
|
|
12615
12603
|
}
|
|
12616
12604
|
const out = {};
|
|
12617
12605
|
for (const [key, item] of Object.entries(value)) {
|
|
12618
|
-
out[key] = prepareBridgeValue(item, `${
|
|
12606
|
+
out[key] = prepareBridgeValue(item, `${path2}.${key}`, functions);
|
|
12619
12607
|
}
|
|
12620
12608
|
return out;
|
|
12621
12609
|
}
|
|
@@ -13490,12 +13478,12 @@ function normalizeVirtualModulePath(basePath, specifier) {
|
|
|
13490
13478
|
}
|
|
13491
13479
|
return normalized;
|
|
13492
13480
|
}
|
|
13493
|
-
function dirnameModulePath(
|
|
13494
|
-
const index =
|
|
13495
|
-
return index <= 0 ? "" :
|
|
13481
|
+
function dirnameModulePath(path2) {
|
|
13482
|
+
const index = path2.lastIndexOf("/");
|
|
13483
|
+
return index <= 0 ? "" : path2.slice(0, index);
|
|
13496
13484
|
}
|
|
13497
|
-
function hasModuleExtension(
|
|
13498
|
-
return /\.[A-Za-z0-9]+$/.test(
|
|
13485
|
+
function hasModuleExtension(path2) {
|
|
13486
|
+
return /\.[A-Za-z0-9]+$/.test(path2);
|
|
13499
13487
|
}
|
|
13500
13488
|
function resolveGraphModuleSpecifier(fromPath, specifier, modulePaths) {
|
|
13501
13489
|
const base = normalizeVirtualModulePath(dirnameModulePath(fromPath), specifier);
|
|
@@ -13852,9 +13840,9 @@ function isPlainObject2(value) {
|
|
|
13852
13840
|
const prototype = Object.getPrototypeOf(value);
|
|
13853
13841
|
return prototype === Object.prototype || prototype === null;
|
|
13854
13842
|
}
|
|
13855
|
-
function findUntransferableOption(value,
|
|
13843
|
+
function findUntransferableOption(value, path2, seen = /* @__PURE__ */ new WeakSet()) {
|
|
13856
13844
|
if (typeof value === "function" || typeof value === "symbol") {
|
|
13857
|
-
return
|
|
13845
|
+
return path2;
|
|
13858
13846
|
}
|
|
13859
13847
|
if (!value || typeof value !== "object") {
|
|
13860
13848
|
return null;
|
|
@@ -13868,7 +13856,7 @@ function findUntransferableOption(value, path, seen = /* @__PURE__ */ new WeakSe
|
|
|
13868
13856
|
seen.add(value);
|
|
13869
13857
|
if (Array.isArray(value)) {
|
|
13870
13858
|
for (const [index, item] of value.entries()) {
|
|
13871
|
-
const found = findUntransferableOption(item, `${
|
|
13859
|
+
const found = findUntransferableOption(item, `${path2}.${index}`, seen);
|
|
13872
13860
|
if (found) return found;
|
|
13873
13861
|
}
|
|
13874
13862
|
return null;
|
|
@@ -13876,9 +13864,9 @@ function findUntransferableOption(value, path, seen = /* @__PURE__ */ new WeakSe
|
|
|
13876
13864
|
if (value instanceof Map) {
|
|
13877
13865
|
let index = 0;
|
|
13878
13866
|
for (const [key, item] of value.entries()) {
|
|
13879
|
-
const foundKey = findUntransferableOption(key, `${
|
|
13867
|
+
const foundKey = findUntransferableOption(key, `${path2}.mapKey${index}`, seen);
|
|
13880
13868
|
if (foundKey) return foundKey;
|
|
13881
|
-
const foundValue = findUntransferableOption(item, `${
|
|
13869
|
+
const foundValue = findUntransferableOption(item, `${path2}.mapValue${index}`, seen);
|
|
13882
13870
|
if (foundValue) return foundValue;
|
|
13883
13871
|
index += 1;
|
|
13884
13872
|
}
|
|
@@ -13887,17 +13875,17 @@ function findUntransferableOption(value, path, seen = /* @__PURE__ */ new WeakSe
|
|
|
13887
13875
|
if (value instanceof Set) {
|
|
13888
13876
|
let index = 0;
|
|
13889
13877
|
for (const item of value.values()) {
|
|
13890
|
-
const found = findUntransferableOption(item, `${
|
|
13878
|
+
const found = findUntransferableOption(item, `${path2}.setValue${index}`, seen);
|
|
13891
13879
|
if (found) return found;
|
|
13892
13880
|
index += 1;
|
|
13893
13881
|
}
|
|
13894
13882
|
return null;
|
|
13895
13883
|
}
|
|
13896
13884
|
if (!isPlainObject2(value)) {
|
|
13897
|
-
return
|
|
13885
|
+
return path2;
|
|
13898
13886
|
}
|
|
13899
13887
|
for (const [key, item] of Object.entries(value)) {
|
|
13900
|
-
const found = findUntransferableOption(item, `${
|
|
13888
|
+
const found = findUntransferableOption(item, `${path2}.${key}`, seen);
|
|
13901
13889
|
if (found) return found;
|
|
13902
13890
|
}
|
|
13903
13891
|
return null;
|
|
@@ -14873,7 +14861,7 @@ var init_ThreadStateImpl = __esm({
|
|
|
14873
14861
|
// ─────────────────────────────────────────────────────────────────────────
|
|
14874
14862
|
// File System
|
|
14875
14863
|
// ─────────────────────────────────────────────────────────────────────────
|
|
14876
|
-
async writeFile(
|
|
14864
|
+
async writeFile(path2, data, mimeType, options) {
|
|
14877
14865
|
const isText = this._isTextMimeType(mimeType);
|
|
14878
14866
|
if (isText) {
|
|
14879
14867
|
let textContent;
|
|
@@ -14882,7 +14870,7 @@ var init_ThreadStateImpl = __esm({
|
|
|
14882
14870
|
} else {
|
|
14883
14871
|
textContent = new TextDecoder().decode(data);
|
|
14884
14872
|
}
|
|
14885
|
-
const result = await this._threadInstance.writeTextFile(
|
|
14873
|
+
const result = await this._threadInstance.writeTextFile(path2, textContent, mimeType, options);
|
|
14886
14874
|
return this._mapFileRecord(result.file);
|
|
14887
14875
|
} else {
|
|
14888
14876
|
let base64Data;
|
|
@@ -14902,7 +14890,7 @@ var init_ThreadStateImpl = __esm({
|
|
|
14902
14890
|
}
|
|
14903
14891
|
base64Data = btoa(binary);
|
|
14904
14892
|
}
|
|
14905
|
-
const result = await this._threadInstance.writeFile(
|
|
14893
|
+
const result = await this._threadInstance.writeFile(path2, base64Data, mimeType, options);
|
|
14906
14894
|
return this._mapFileRecord(result.file);
|
|
14907
14895
|
}
|
|
14908
14896
|
}
|
|
@@ -14974,8 +14962,8 @@ var init_ThreadStateImpl = __esm({
|
|
|
14974
14962
|
(type) => mimeType === type || mimeType.startsWith(type + ";")
|
|
14975
14963
|
);
|
|
14976
14964
|
}
|
|
14977
|
-
async readFile(
|
|
14978
|
-
const result = await this._threadInstance.readFile(
|
|
14965
|
+
async readFile(path2) {
|
|
14966
|
+
const result = await this._threadInstance.readFile(path2);
|
|
14979
14967
|
if (!result.success || !result.data) {
|
|
14980
14968
|
return null;
|
|
14981
14969
|
}
|
|
@@ -14986,8 +14974,8 @@ var init_ThreadStateImpl = __esm({
|
|
|
14986
14974
|
}
|
|
14987
14975
|
return bytes.buffer;
|
|
14988
14976
|
}
|
|
14989
|
-
async readFileStream(
|
|
14990
|
-
const fileInfo = this._unwrapStatRecord(await this._threadInstance.statFile(
|
|
14977
|
+
async readFileStream(path2, options) {
|
|
14978
|
+
const fileInfo = this._unwrapStatRecord(await this._threadInstance.statFile(path2));
|
|
14991
14979
|
if (!fileInfo) {
|
|
14992
14980
|
return null;
|
|
14993
14981
|
}
|
|
@@ -15002,7 +14990,7 @@ var init_ThreadStateImpl = __esm({
|
|
|
15002
14990
|
return {
|
|
15003
14991
|
[Symbol.asyncIterator]: async function* () {
|
|
15004
14992
|
if (!isChunked) {
|
|
15005
|
-
const result = await threadInstance.readFile(
|
|
14993
|
+
const result = await threadInstance.readFile(path2);
|
|
15006
14994
|
if (!result.success || !result.data) {
|
|
15007
14995
|
return;
|
|
15008
14996
|
}
|
|
@@ -15023,7 +15011,7 @@ var init_ThreadStateImpl = __esm({
|
|
|
15023
15011
|
if (signal?.aborted) {
|
|
15024
15012
|
return;
|
|
15025
15013
|
}
|
|
15026
|
-
const result = await threadInstance.readFileChunk(
|
|
15014
|
+
const result = await threadInstance.readFileChunk(path2, i);
|
|
15027
15015
|
if (!result.success || !result.data) {
|
|
15028
15016
|
throw new Error(result.error || `Failed to read chunk ${i}`);
|
|
15029
15017
|
}
|
|
@@ -15056,31 +15044,31 @@ var init_ThreadStateImpl = __esm({
|
|
|
15056
15044
|
if (!("path" in record) && !("name" in record)) return null;
|
|
15057
15045
|
return record;
|
|
15058
15046
|
}
|
|
15059
|
-
async statFile(
|
|
15060
|
-
const record = this._unwrapStatRecord(await this._threadInstance.statFile(
|
|
15047
|
+
async statFile(path2) {
|
|
15048
|
+
const record = this._unwrapStatRecord(await this._threadInstance.statFile(path2));
|
|
15061
15049
|
return record ? this._mapFileRecord(record) : null;
|
|
15062
15050
|
}
|
|
15063
|
-
async readdirFile(
|
|
15064
|
-
const result = await this._threadInstance.readdirFile(
|
|
15051
|
+
async readdirFile(path2) {
|
|
15052
|
+
const result = await this._threadInstance.readdirFile(path2);
|
|
15065
15053
|
const entries = Array.isArray(result) ? result : result?.files;
|
|
15066
15054
|
if (!Array.isArray(entries)) {
|
|
15067
15055
|
throw new Error(
|
|
15068
|
-
result?.error || `Could not list directory: ${
|
|
15056
|
+
result?.error || `Could not list directory: ${path2}`
|
|
15069
15057
|
);
|
|
15070
15058
|
}
|
|
15071
15059
|
return {
|
|
15072
15060
|
entries: entries.map((e) => this._mapFileRecord(e))
|
|
15073
15061
|
};
|
|
15074
15062
|
}
|
|
15075
|
-
async unlinkFile(
|
|
15076
|
-
await this._threadInstance.unlinkFile(
|
|
15063
|
+
async unlinkFile(path2) {
|
|
15064
|
+
await this._threadInstance.unlinkFile(path2);
|
|
15077
15065
|
}
|
|
15078
|
-
async mkdirFile(
|
|
15079
|
-
const result = await this._threadInstance.mkdirFile(
|
|
15066
|
+
async mkdirFile(path2) {
|
|
15067
|
+
const result = await this._threadInstance.mkdirFile(path2);
|
|
15080
15068
|
return this._mapFileRecord(result);
|
|
15081
15069
|
}
|
|
15082
|
-
async rmdirFile(
|
|
15083
|
-
await this._threadInstance.rmdirFile(
|
|
15070
|
+
async rmdirFile(path2) {
|
|
15071
|
+
await this._threadInstance.rmdirFile(path2);
|
|
15084
15072
|
}
|
|
15085
15073
|
async moveFile(sourcePath, destinationPath) {
|
|
15086
15074
|
const result = await this._threadInstance.moveFile(sourcePath, destinationPath);
|
|
@@ -15089,8 +15077,8 @@ var init_ThreadStateImpl = __esm({
|
|
|
15089
15077
|
}
|
|
15090
15078
|
return this._mapFileRecord(result.file);
|
|
15091
15079
|
}
|
|
15092
|
-
async renameFile(
|
|
15093
|
-
const result = await this._threadInstance.renameFile(
|
|
15080
|
+
async renameFile(path2, newName) {
|
|
15081
|
+
const result = await this._threadInstance.renameFile(path2, newName);
|
|
15094
15082
|
if (!result.success || !result.file) {
|
|
15095
15083
|
throw new Error(result.error || "Failed to rename file");
|
|
15096
15084
|
}
|
|
@@ -15117,8 +15105,8 @@ var init_ThreadStateImpl = __esm({
|
|
|
15117
15105
|
paths: Array.isArray(results) ? results : results.paths || []
|
|
15118
15106
|
};
|
|
15119
15107
|
}
|
|
15120
|
-
async getFileThumbnail(
|
|
15121
|
-
return this._threadInstance.getFileThumbnail(
|
|
15108
|
+
async getFileThumbnail(path2) {
|
|
15109
|
+
return this._threadInstance.getFileThumbnail(path2);
|
|
15122
15110
|
}
|
|
15123
15111
|
// ─────────────────────────────────────────────────────────────────────────
|
|
15124
15112
|
// Execution State
|
|
@@ -15423,7 +15411,7 @@ var init_ThreadStateImpl = __esm({
|
|
|
15423
15411
|
const skillMd = await stub.getSkillFile(scope, name, "SKILL.md") ?? "";
|
|
15424
15412
|
return { metadata, skillMd };
|
|
15425
15413
|
},
|
|
15426
|
-
readFile: (name,
|
|
15414
|
+
readFile: (name, path2) => stub.getSkillFile(scope, name, path2),
|
|
15427
15415
|
install: async (files) => {
|
|
15428
15416
|
await requireMutationAdmin();
|
|
15429
15417
|
return stub.upsertSkill(scope, files);
|
|
@@ -15710,7 +15698,14 @@ function isHostedInstance(env) {
|
|
|
15710
15698
|
}
|
|
15711
15699
|
return Boolean(value);
|
|
15712
15700
|
}
|
|
15713
|
-
function
|
|
15701
|
+
function compiledTrustedDevHosts() {
|
|
15702
|
+
try {
|
|
15703
|
+
return typeof __STANDARD_AGENTS_TRUSTED_DEV_HOSTS__ !== "undefined" && Array.isArray(__STANDARD_AGENTS_TRUSTED_DEV_HOSTS__) ? __STANDARD_AGENTS_TRUSTED_DEV_HOSTS__ : [];
|
|
15704
|
+
} catch {
|
|
15705
|
+
return [];
|
|
15706
|
+
}
|
|
15707
|
+
}
|
|
15708
|
+
function isTrustedLocalDevelopmentRequest(request, env, trustedDevHosts = compiledTrustedDevHosts()) {
|
|
15714
15709
|
if (isHostedInstance(env)) return false;
|
|
15715
15710
|
let hostname;
|
|
15716
15711
|
try {
|
|
@@ -15718,7 +15713,7 @@ function isTrustedLocalDevelopmentRequest(request, env) {
|
|
|
15718
15713
|
} catch {
|
|
15719
15714
|
return false;
|
|
15720
15715
|
}
|
|
15721
|
-
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname.endsWith(".localhost") || hostname.endsWith(".orb.local");
|
|
15716
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname.endsWith(".localhost") || hostname.endsWith(".orb.local") || trustedDevHosts.some((trusted) => trusted.trim().toLowerCase() === hostname);
|
|
15722
15717
|
}
|
|
15723
15718
|
function isPublicApiRoute(routePath, request, env) {
|
|
15724
15719
|
if (PUBLIC_ROUTES.has(routePath)) return true;
|
|
@@ -19013,10 +19008,10 @@ var DurableAgentBuilder = class extends DurableObject {
|
|
|
19013
19008
|
for (const entry of value) {
|
|
19014
19009
|
if (!entry || typeof entry !== "object") continue;
|
|
19015
19010
|
const attachment = entry;
|
|
19016
|
-
const
|
|
19017
|
-
if (!
|
|
19011
|
+
const path2 = typeof attachment.path === "string" ? attachment.path.trim() : "";
|
|
19012
|
+
if (!path2) continue;
|
|
19018
19013
|
output.push({
|
|
19019
|
-
path,
|
|
19014
|
+
path: path2,
|
|
19020
19015
|
name: typeof attachment.name === "string" ? attachment.name : void 0,
|
|
19021
19016
|
mimeType: typeof attachment.mimeType === "string" ? attachment.mimeType : void 0,
|
|
19022
19017
|
size: typeof attachment.size === "number" ? attachment.size : void 0,
|
|
@@ -19033,8 +19028,8 @@ var DurableAgentBuilder = class extends DurableObject {
|
|
|
19033
19028
|
const trimmed = sanitized.replace(/^[-.]+|[-.]+$/g, "");
|
|
19034
19029
|
return trimmed || "attachment";
|
|
19035
19030
|
}
|
|
19036
|
-
inferMimeTypeFromPath(
|
|
19037
|
-
const normalized =
|
|
19031
|
+
inferMimeTypeFromPath(path2) {
|
|
19032
|
+
const normalized = path2.toLowerCase();
|
|
19038
19033
|
if (normalized.endsWith(".png")) return "image/png";
|
|
19039
19034
|
if (normalized.endsWith(".jpg") || normalized.endsWith(".jpeg")) return "image/jpeg";
|
|
19040
19035
|
if (normalized.endsWith(".webp")) return "image/webp";
|
|
@@ -19072,7 +19067,7 @@ var DurableAgentBuilder = class extends DurableObject {
|
|
|
19072
19067
|
if (!attachments || attachments.length === 0) {
|
|
19073
19068
|
return "";
|
|
19074
19069
|
}
|
|
19075
|
-
const paths = attachments.map((attachment) => attachment.path).filter((
|
|
19070
|
+
const paths = attachments.map((attachment) => attachment.path).filter((path2) => typeof path2 === "string" && path2.length > 0);
|
|
19076
19071
|
if (paths.length === 0) {
|
|
19077
19072
|
return "";
|
|
19078
19073
|
}
|
|
@@ -20474,12 +20469,9 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
20474
20469
|
await parentThread.updateChildRegistryStatus(
|
|
20475
20470
|
params.parent_thread_id,
|
|
20476
20471
|
childThread.id,
|
|
20477
|
-
|
|
20472
|
+
"idle"
|
|
20478
20473
|
);
|
|
20479
20474
|
}
|
|
20480
|
-
if (childResult.terminal && typeof childThreadStub.terminateThread === "function") {
|
|
20481
|
-
await childThreadStub.terminateThread(childThread.id);
|
|
20482
|
-
}
|
|
20483
20475
|
} else if (typeof childThreadStub.terminateThread === "function") {
|
|
20484
20476
|
await childThreadStub.terminateThread(childThread.id);
|
|
20485
20477
|
}
|
|
@@ -21752,7 +21744,7 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
21752
21744
|
for (const row of cursor.toArray()) {
|
|
21753
21745
|
if (skills.has(row.name)) continue;
|
|
21754
21746
|
const parsedFiles = row.files ? JSON.parse(row.files) : [];
|
|
21755
|
-
const files = Array.isArray(parsedFiles) ? parsedFiles.filter((
|
|
21747
|
+
const files = Array.isArray(parsedFiles) ? parsedFiles.filter((path2) => typeof path2 === "string").sort() : [];
|
|
21756
21748
|
skills.set(row.name, {
|
|
21757
21749
|
name: row.name,
|
|
21758
21750
|
description: row.description,
|
|
@@ -21770,7 +21762,7 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
21770
21762
|
return all.find((s) => s.name === name) ?? null;
|
|
21771
21763
|
}
|
|
21772
21764
|
/** One bundled file's text (null when the skill or file is missing). */
|
|
21773
|
-
async getSkillFile(scope, name,
|
|
21765
|
+
async getSkillFile(scope, name, path2) {
|
|
21774
21766
|
await this.ensureMigrated();
|
|
21775
21767
|
const cursor = await this.ctx.storage.sql.exec(
|
|
21776
21768
|
`SELECT f.content FROM skill_files f
|
|
@@ -21780,7 +21772,7 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
21780
21772
|
ORDER BY CASE WHEN f.owner_id = ? THEN 0 ELSE 1 END
|
|
21781
21773
|
LIMIT 1`,
|
|
21782
21774
|
name,
|
|
21783
|
-
|
|
21775
|
+
path2.replace(/^\.\//, ""),
|
|
21784
21776
|
scope.ownerId,
|
|
21785
21777
|
scope.includeShared ? 1 : 0,
|
|
21786
21778
|
scope.ownerId
|
|
@@ -22075,12 +22067,12 @@ async function authorizesToolDelivery(pending, proof) {
|
|
|
22075
22067
|
return matchesToolDeliveryOwner(pending, proof) && await matchesToolDeliveryToken(pending.delivery_token_hash, proof.token);
|
|
22076
22068
|
}
|
|
22077
22069
|
var RUNTIME_STORAGE_PREFIX = "__agentbuilder_runtime_storage__:";
|
|
22078
|
-
function normalizeEndpointThreadPath(
|
|
22079
|
-
if (!
|
|
22070
|
+
function normalizeEndpointThreadPath(path2) {
|
|
22071
|
+
if (!path2 || /^[A-Za-z][A-Za-z\d+\-.]*:/.test(path2)) {
|
|
22080
22072
|
throw new Error("Use a relative thread filesystem path");
|
|
22081
22073
|
}
|
|
22082
22074
|
const parts = [];
|
|
22083
|
-
for (const part of
|
|
22075
|
+
for (const part of path2.replace(/\\/g, "/").split("/")) {
|
|
22084
22076
|
if (!part || part === ".") continue;
|
|
22085
22077
|
if (part === "..") {
|
|
22086
22078
|
if (parts.length === 0) throw new Error("Path cannot escape the thread filesystem root");
|
|
@@ -22130,12 +22122,12 @@ function createEndpointFetchBridge() {
|
|
|
22130
22122
|
function createEndpointFsBridge(state) {
|
|
22131
22123
|
const decoder = new TextDecoder();
|
|
22132
22124
|
return {
|
|
22133
|
-
readFile: async (
|
|
22134
|
-
const data = await state.readFile(normalizeEndpointThreadPath(
|
|
22125
|
+
readFile: async (path2) => {
|
|
22126
|
+
const data = await state.readFile(normalizeEndpointThreadPath(path2));
|
|
22135
22127
|
return data ? decoder.decode(data) : null;
|
|
22136
22128
|
},
|
|
22137
|
-
writeFile: async (
|
|
22138
|
-
return state.writeFile(normalizeEndpointThreadPath(
|
|
22129
|
+
writeFile: async (path2, content, mimeType = "text/plain") => {
|
|
22130
|
+
return state.writeFile(normalizeEndpointThreadPath(path2), content, mimeType);
|
|
22139
22131
|
}
|
|
22140
22132
|
};
|
|
22141
22133
|
}
|
|
@@ -22204,24 +22196,24 @@ function createEndpointThreadStateBridge(state) {
|
|
|
22204
22196
|
emit: (event, data) => state.emit(event, data),
|
|
22205
22197
|
getValue: (key) => state.getValue(key),
|
|
22206
22198
|
setValue: (key, value) => state.setValue(key, value),
|
|
22207
|
-
readFile: (
|
|
22208
|
-
writeFile: (
|
|
22209
|
-
return state.writeFile(normalizeEndpointThreadPath(
|
|
22199
|
+
readFile: (path2) => state.readFile(normalizeEndpointThreadPath(path2)),
|
|
22200
|
+
writeFile: (path2, data, mimeType = "application/octet-stream", options) => {
|
|
22201
|
+
return state.writeFile(normalizeEndpointThreadPath(path2), data, mimeType, options);
|
|
22210
22202
|
},
|
|
22211
|
-
statFile: (
|
|
22212
|
-
readdirFile: (
|
|
22213
|
-
unlinkFile: (
|
|
22214
|
-
mkdirFile: (
|
|
22215
|
-
rmdirFile: (
|
|
22203
|
+
statFile: (path2) => state.statFile(normalizeEndpointThreadPath(path2)),
|
|
22204
|
+
readdirFile: (path2) => state.readdirFile(normalizeEndpointThreadPath(path2)),
|
|
22205
|
+
unlinkFile: (path2) => state.unlinkFile(normalizeEndpointThreadPath(path2)),
|
|
22206
|
+
mkdirFile: (path2) => state.mkdirFile(normalizeEndpointThreadPath(path2)),
|
|
22207
|
+
rmdirFile: (path2) => state.rmdirFile(normalizeEndpointThreadPath(path2)),
|
|
22216
22208
|
moveFile: (sourcePath, destinationPath) => state.moveFile(
|
|
22217
22209
|
normalizeEndpointThreadPath(sourcePath),
|
|
22218
22210
|
normalizeEndpointThreadPath(destinationPath)
|
|
22219
22211
|
),
|
|
22220
|
-
renameFile: (
|
|
22212
|
+
renameFile: (path2, newName) => state.renameFile(normalizeEndpointThreadPath(path2), newName),
|
|
22221
22213
|
getFileStats: () => state.getFileStats(),
|
|
22222
22214
|
grepFiles: (pattern) => state.grepFiles(pattern),
|
|
22223
22215
|
findFiles: (pattern) => state.findFiles(pattern),
|
|
22224
|
-
getFileThumbnail: (
|
|
22216
|
+
getFileThumbnail: (path2) => state.getFileThumbnail(normalizeEndpointThreadPath(path2))
|
|
22225
22217
|
};
|
|
22226
22218
|
}
|
|
22227
22219
|
function routeBridgeClientFrame(socket, message, handlers) {
|
|
@@ -22973,7 +22965,7 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
22973
22965
|
this.assertJsonSerializableThreadValue(value, "$", /* @__PURE__ */ new WeakSet());
|
|
22974
22966
|
return JSON.stringify(value);
|
|
22975
22967
|
}
|
|
22976
|
-
assertJsonSerializableThreadValue(value,
|
|
22968
|
+
assertJsonSerializableThreadValue(value, path2, seen) {
|
|
22977
22969
|
if (value === null) {
|
|
22978
22970
|
return;
|
|
22979
22971
|
}
|
|
@@ -22983,36 +22975,36 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
22983
22975
|
return;
|
|
22984
22976
|
case "number":
|
|
22985
22977
|
if (!Number.isFinite(value)) {
|
|
22986
|
-
throw new Error(`Thread value at ${
|
|
22978
|
+
throw new Error(`Thread value at ${path2} must be a finite number`);
|
|
22987
22979
|
}
|
|
22988
22980
|
return;
|
|
22989
22981
|
case "object": {
|
|
22990
22982
|
if (seen.has(value)) {
|
|
22991
|
-
throw new Error(`Thread value at ${
|
|
22983
|
+
throw new Error(`Thread value at ${path2} cannot contain circular references`);
|
|
22992
22984
|
}
|
|
22993
22985
|
seen.add(value);
|
|
22994
22986
|
if (Array.isArray(value)) {
|
|
22995
22987
|
for (let i = 0; i < value.length; i += 1) {
|
|
22996
|
-
this.assertJsonSerializableThreadValue(value[i], `${
|
|
22988
|
+
this.assertJsonSerializableThreadValue(value[i], `${path2}[${i}]`, seen);
|
|
22997
22989
|
}
|
|
22998
22990
|
seen.delete(value);
|
|
22999
22991
|
return;
|
|
23000
22992
|
}
|
|
23001
22993
|
const prototype = Object.getPrototypeOf(value);
|
|
23002
22994
|
if (prototype !== Object.prototype && prototype !== null) {
|
|
23003
|
-
throw new Error(`Thread value at ${
|
|
22995
|
+
throw new Error(`Thread value at ${path2} must be a JSON object, array, or primitive`);
|
|
23004
22996
|
}
|
|
23005
22997
|
if (Object.getOwnPropertySymbols(value).length > 0) {
|
|
23006
|
-
throw new Error(`Thread value at ${
|
|
22998
|
+
throw new Error(`Thread value at ${path2} cannot contain symbol keys`);
|
|
23007
22999
|
}
|
|
23008
23000
|
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
23009
|
-
this.assertJsonSerializableThreadValue(entryValue, `${
|
|
23001
|
+
this.assertJsonSerializableThreadValue(entryValue, `${path2}.${entryKey}`, seen);
|
|
23010
23002
|
}
|
|
23011
23003
|
seen.delete(value);
|
|
23012
23004
|
return;
|
|
23013
23005
|
}
|
|
23014
23006
|
default:
|
|
23015
|
-
throw new Error(`Thread value at ${
|
|
23007
|
+
throw new Error(`Thread value at ${path2} must be JSON-serializable`);
|
|
23016
23008
|
}
|
|
23017
23009
|
}
|
|
23018
23010
|
// ============================================================
|
|
@@ -24213,8 +24205,8 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
24213
24205
|
);
|
|
24214
24206
|
return terminalCursor.toArray()[0] ?? null;
|
|
24215
24207
|
}
|
|
24216
|
-
inferMimeTypeFromPath(
|
|
24217
|
-
const normalized =
|
|
24208
|
+
inferMimeTypeFromPath(path2) {
|
|
24209
|
+
const normalized = path2.toLowerCase();
|
|
24218
24210
|
if (normalized.endsWith(".png")) return "image/png";
|
|
24219
24211
|
if (normalized.endsWith(".jpg") || normalized.endsWith(".jpeg")) return "image/jpeg";
|
|
24220
24212
|
if (normalized.endsWith(".webp")) return "image/webp";
|
|
@@ -24253,7 +24245,7 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
24253
24245
|
ext: value.slice(lastDot + 1).toLowerCase()
|
|
24254
24246
|
};
|
|
24255
24247
|
}
|
|
24256
|
-
resolveAttachmentMimeType(sourceMimeType, fallbackMimeType,
|
|
24248
|
+
resolveAttachmentMimeType(sourceMimeType, fallbackMimeType, path2) {
|
|
24257
24249
|
const source = sourceMimeType?.trim();
|
|
24258
24250
|
if (source && source !== "application/octet-stream") {
|
|
24259
24251
|
return source;
|
|
@@ -24262,7 +24254,7 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
24262
24254
|
if (fallback && fallback !== "application/octet-stream") {
|
|
24263
24255
|
return fallback;
|
|
24264
24256
|
}
|
|
24265
|
-
return this.inferMimeTypeFromPath(
|
|
24257
|
+
return this.inferMimeTypeFromPath(path2) ?? source ?? fallback ?? "application/octet-stream";
|
|
24266
24258
|
}
|
|
24267
24259
|
buildAttachmentTargetPath(preferredName, mimeType, sourcePath) {
|
|
24268
24260
|
const safeName = this.sanitizeFilename(preferredName);
|
|
@@ -24357,8 +24349,8 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
24357
24349
|
}
|
|
24358
24350
|
return copied;
|
|
24359
24351
|
}
|
|
24360
|
-
async readAttachmentDataFromSource(
|
|
24361
|
-
const sourceData = await this.readFile(
|
|
24352
|
+
async readAttachmentDataFromSource(path2, sourceFile) {
|
|
24353
|
+
const sourceData = await this.readFile(path2);
|
|
24362
24354
|
if (sourceData.success && sourceData.data) {
|
|
24363
24355
|
return sourceData.data;
|
|
24364
24356
|
}
|
|
@@ -24395,7 +24387,7 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
24395
24387
|
if (!attachments || attachments.length === 0) {
|
|
24396
24388
|
return "";
|
|
24397
24389
|
}
|
|
24398
|
-
const paths = attachments.map((attachment) => attachment.path).filter((
|
|
24390
|
+
const paths = attachments.map((attachment) => attachment.path).filter((path2) => typeof path2 === "string" && path2.length > 0);
|
|
24399
24391
|
if (paths.length === 0) {
|
|
24400
24392
|
return "";
|
|
24401
24393
|
}
|
|
@@ -24475,11 +24467,13 @@ ${paths.join("\n")}`;
|
|
|
24475
24467
|
try {
|
|
24476
24468
|
const parentId = this.env.AGENT_BUILDER_THREAD.idFromName(parentThreadId);
|
|
24477
24469
|
const parentStub = this.env.AGENT_BUILDER_THREAD.get(parentId);
|
|
24478
|
-
const
|
|
24470
|
+
const childRegistryEntry = await this.getParentRegistryEntryForChild(
|
|
24479
24471
|
parentStub,
|
|
24480
24472
|
parentThreadId,
|
|
24481
24473
|
threadId
|
|
24482
24474
|
);
|
|
24475
|
+
const parentCommunication = childRegistryEntry?.parentCommunication === "explicit" ? "explicit" : "implicit";
|
|
24476
|
+
const resumableChild = childRegistryEntry?.resumable === true;
|
|
24483
24477
|
const copiedRefs = await this.copyAttachmentRefsToThread(
|
|
24484
24478
|
refs,
|
|
24485
24479
|
parentStub,
|
|
@@ -24502,10 +24496,11 @@ ${resultContent}${attachmentSummary}`;
|
|
|
24502
24496
|
});
|
|
24503
24497
|
}
|
|
24504
24498
|
const terminalChildRun = sessionStopped || hasTerminalSessionTools;
|
|
24499
|
+
const terminateChildThread = terminalChildRun && !resumableChild;
|
|
24505
24500
|
await parentStub.updateChildRegistryStatus(
|
|
24506
24501
|
parentThreadId,
|
|
24507
24502
|
threadId,
|
|
24508
|
-
|
|
24503
|
+
terminateChildThread ? "terminated" : "idle"
|
|
24509
24504
|
);
|
|
24510
24505
|
if (parentCommunication !== "explicit") {
|
|
24511
24506
|
await this.persistParentHandoffStatusMessage(
|
|
@@ -24513,23 +24508,22 @@ ${resultContent}${attachmentSummary}`;
|
|
|
24513
24508
|
isErrorTerminal ? "failure" : "result"
|
|
24514
24509
|
);
|
|
24515
24510
|
}
|
|
24516
|
-
if (
|
|
24511
|
+
if (terminateChildThread) {
|
|
24517
24512
|
await this.terminateThread(threadId);
|
|
24518
24513
|
}
|
|
24519
24514
|
} catch (error) {
|
|
24520
24515
|
console.error("[DurableThread] Failed to deliver subagent completion to parent:", error);
|
|
24521
24516
|
}
|
|
24522
24517
|
}
|
|
24523
|
-
async
|
|
24518
|
+
async getParentRegistryEntryForChild(parentStub, parentThreadId, childThreadId) {
|
|
24524
24519
|
if (typeof parentStub.getChildrenRegistry !== "function") {
|
|
24525
|
-
return
|
|
24520
|
+
return void 0;
|
|
24526
24521
|
}
|
|
24527
24522
|
try {
|
|
24528
24523
|
const entries = await parentStub.getChildrenRegistry(parentThreadId);
|
|
24529
|
-
|
|
24530
|
-
return childEntry?.parentCommunication === "explicit" ? "explicit" : "implicit";
|
|
24524
|
+
return entries.find((entry) => entry.reference === childThreadId);
|
|
24531
24525
|
} catch {
|
|
24532
|
-
return
|
|
24526
|
+
return void 0;
|
|
24533
24527
|
}
|
|
24534
24528
|
}
|
|
24535
24529
|
/**
|
|
@@ -26077,7 +26071,7 @@ ${resultContent}${attachmentSummary}`;
|
|
|
26077
26071
|
void 0,
|
|
26078
26072
|
INTERNAL_TOOL_DELIVERY
|
|
26079
26073
|
);
|
|
26080
|
-
if (delivered
|
|
26074
|
+
if (delivered) sides.add(delivered.side);
|
|
26081
26075
|
}
|
|
26082
26076
|
if (threadId) {
|
|
26083
26077
|
for (const side of sides) {
|
|
@@ -26379,17 +26373,14 @@ ${resultContent}${attachmentSummary}`;
|
|
|
26379
26373
|
deliveredResultWaiters = /* @__PURE__ */ new Map();
|
|
26380
26374
|
notifyDeliveredResultWaiters(toolCallId) {
|
|
26381
26375
|
const waiters = this.deliveredResultWaiters?.get(toolCallId);
|
|
26382
|
-
if (!waiters
|
|
26376
|
+
if (!waiters) return;
|
|
26383
26377
|
this.deliveredResultWaiters.delete(toolCallId);
|
|
26384
|
-
let notified = false;
|
|
26385
26378
|
for (const wake of waiters) {
|
|
26386
26379
|
try {
|
|
26387
26380
|
wake();
|
|
26388
|
-
notified = true;
|
|
26389
26381
|
} catch {
|
|
26390
26382
|
}
|
|
26391
26383
|
}
|
|
26392
|
-
return notified;
|
|
26393
26384
|
}
|
|
26394
26385
|
/**
|
|
26395
26386
|
* Await a parked forwarded call's delivered result: one immediate read,
|
|
@@ -26534,46 +26525,37 @@ ${resultContent}${attachmentSummary}`;
|
|
|
26534
26525
|
const side = pending.side === "b" ? "b" : "a";
|
|
26535
26526
|
const content = ok ? result ?? "" : `Error: ${error ?? "tool failed"}`;
|
|
26536
26527
|
const toolStatus = ok ? "success" : "error";
|
|
26537
|
-
|
|
26538
|
-
|
|
26539
|
-
|
|
26540
|
-
|
|
26541
|
-
|
|
26542
|
-
|
|
26543
|
-
|
|
26528
|
+
await this.ctx.storage.sql.exec(
|
|
26529
|
+
`UPDATE messages SET content = ?, tool_status = ? WHERE tool_call_id = ? AND role = 'tool'`,
|
|
26530
|
+
content,
|
|
26531
|
+
toolStatus,
|
|
26532
|
+
toolCallId
|
|
26533
|
+
);
|
|
26534
|
+
const updated = await this.ctx.storage.sql.exec(
|
|
26535
|
+
`SELECT COUNT(*) AS total FROM messages WHERE tool_call_id = ? AND role = 'tool'`,
|
|
26536
|
+
toolCallId
|
|
26537
|
+
);
|
|
26538
|
+
if (Number(updated.toArray()[0]?.total ?? 0) === 0) {
|
|
26539
|
+
const toolRow = await this.ctx.storage.sql.exec(
|
|
26540
|
+
`SELECT tool FROM pending_client_calls WHERE tool_call_id = ? LIMIT 1`,
|
|
26544
26541
|
toolCallId
|
|
26545
26542
|
);
|
|
26546
|
-
|
|
26547
|
-
|
|
26548
|
-
|
|
26543
|
+
await this.ctx.storage.sql.exec(
|
|
26544
|
+
`INSERT INTO messages (id, role, content, name, tool_call_id, tool_status, created_at, status, prompt)
|
|
26545
|
+
VALUES (?, 'tool', ?, ?, ?, ?, ?, 'completed', NULL)`,
|
|
26546
|
+
crypto.randomUUID(),
|
|
26549
26547
|
content,
|
|
26548
|
+
toolRow.toArray()[0]?.tool ?? null,
|
|
26549
|
+
toolCallId,
|
|
26550
26550
|
toolStatus,
|
|
26551
|
-
|
|
26551
|
+
Date.now() * TIMESTAMP_MULTIPLIER
|
|
26552
26552
|
);
|
|
26553
|
-
|
|
26554
|
-
|
|
26555
|
-
|
|
26556
|
-
|
|
26557
|
-
|
|
26558
|
-
|
|
26559
|
-
`SELECT tool FROM pending_client_calls WHERE tool_call_id = ? LIMIT 1`,
|
|
26560
|
-
toolCallId
|
|
26561
|
-
);
|
|
26562
|
-
this.ctx.storage.sql.exec(
|
|
26563
|
-
`INSERT INTO messages (id, role, content, name, tool_call_id, tool_status, created_at, status, prompt)
|
|
26564
|
-
VALUES (?, 'tool', ?, ?, ?, ?, ?, 'completed', NULL)`,
|
|
26565
|
-
resultMessageId,
|
|
26566
|
-
content,
|
|
26567
|
-
toolRow.toArray()[0]?.tool ?? null,
|
|
26568
|
-
toolCallId,
|
|
26569
|
-
toolStatus,
|
|
26570
|
-
resultCreatedAt
|
|
26571
|
-
);
|
|
26572
|
-
}
|
|
26573
|
-
return true;
|
|
26574
|
-
});
|
|
26575
|
-
if (!accepted) return null;
|
|
26576
|
-
const resumedInline = this.notifyDeliveredResultWaiters(toolCallId);
|
|
26553
|
+
}
|
|
26554
|
+
await this.ctx.storage.sql.exec(
|
|
26555
|
+
`UPDATE pending_client_calls SET status = 'resolved' WHERE tool_call_id = ?`,
|
|
26556
|
+
toolCallId
|
|
26557
|
+
);
|
|
26558
|
+
this.notifyDeliveredResultWaiters(toolCallId);
|
|
26577
26559
|
try {
|
|
26578
26560
|
const msgCursor = await this.ctx.storage.sql.exec(
|
|
26579
26561
|
`SELECT id, role, content, name, tool_call_id, tool_status, created_at, depth
|
|
@@ -26584,7 +26566,7 @@ ${resultContent}${attachmentSummary}`;
|
|
|
26584
26566
|
if (msg) this.broadcastMessage(msg);
|
|
26585
26567
|
} catch {
|
|
26586
26568
|
}
|
|
26587
|
-
return { side
|
|
26569
|
+
return { side };
|
|
26588
26570
|
}
|
|
26589
26571
|
// ─── Runtime byte streams ──────────────────────────────────────────────────
|
|
26590
26572
|
// The existing bridge frames carry opaque capability metadata and bytes
|
|
@@ -27758,11 +27740,12 @@ ${resultContent}${attachmentSummary}`;
|
|
|
27758
27740
|
if (!parentThreadId) return;
|
|
27759
27741
|
const parentId = this.env.AGENT_BUILDER_THREAD.idFromName(parentThreadId);
|
|
27760
27742
|
const parentStub = this.env.AGENT_BUILDER_THREAD.get(parentId);
|
|
27761
|
-
const
|
|
27743
|
+
const childRegistryEntry = await this.getParentRegistryEntryForChild(
|
|
27762
27744
|
parentStub,
|
|
27763
27745
|
parentThreadId,
|
|
27764
27746
|
threadId
|
|
27765
27747
|
);
|
|
27748
|
+
const parentCommunication = childRegistryEntry?.parentCommunication === "explicit" ? "explicit" : "implicit";
|
|
27766
27749
|
if (parentCommunication !== "explicit") {
|
|
27767
27750
|
await parentStub.queueMessage(parentThreadId, {
|
|
27768
27751
|
role: "user",
|
|
@@ -28521,11 +28504,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28521
28504
|
/**
|
|
28522
28505
|
* Write a file to storage (RPC method)
|
|
28523
28506
|
*/
|
|
28524
|
-
async writeFile(
|
|
28507
|
+
async writeFile(path2, data, mimeType, options) {
|
|
28525
28508
|
await this.ensureMigrated();
|
|
28526
28509
|
try {
|
|
28527
|
-
const
|
|
28528
|
-
const existingFile = await
|
|
28510
|
+
const fs2 = this.getFileStorage();
|
|
28511
|
+
const existingFile = await fs2.stat(path2);
|
|
28529
28512
|
const isUpdate = existingFile !== null;
|
|
28530
28513
|
const binaryString = atob(data);
|
|
28531
28514
|
const dataBuffer = new Uint8Array(binaryString.length);
|
|
@@ -28547,12 +28530,12 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28547
28530
|
}
|
|
28548
28531
|
}
|
|
28549
28532
|
}
|
|
28550
|
-
const record = await
|
|
28533
|
+
const record = await fs2.writeFile(path2, dataBuffer, mimeType, {
|
|
28551
28534
|
metadata: options?.metadata,
|
|
28552
28535
|
thumbnail: thumbnailBuffer
|
|
28553
28536
|
});
|
|
28554
28537
|
this.broadcastEvent(isUpdate ? "file_updated" : "file_created", {
|
|
28555
|
-
path,
|
|
28538
|
+
path: path2,
|
|
28556
28539
|
file: record
|
|
28557
28540
|
});
|
|
28558
28541
|
return { success: true, file: record };
|
|
@@ -28564,15 +28547,15 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28564
28547
|
/**
|
|
28565
28548
|
* Write a text file to storage (RPC method)
|
|
28566
28549
|
*/
|
|
28567
|
-
async writeTextFile(
|
|
28550
|
+
async writeTextFile(path2, content, mimeType = "text/plain", options) {
|
|
28568
28551
|
await this.ensureMigrated();
|
|
28569
28552
|
try {
|
|
28570
|
-
const
|
|
28571
|
-
const existingFile = await
|
|
28553
|
+
const fs2 = this.getFileStorage();
|
|
28554
|
+
const existingFile = await fs2.stat(path2);
|
|
28572
28555
|
const isUpdate = existingFile !== null;
|
|
28573
|
-
const record = await
|
|
28556
|
+
const record = await fs2.writeFile(path2, content, mimeType, options);
|
|
28574
28557
|
this.broadcastEvent(isUpdate ? "file_updated" : "file_created", {
|
|
28575
|
-
path,
|
|
28558
|
+
path: path2,
|
|
28576
28559
|
file: record
|
|
28577
28560
|
});
|
|
28578
28561
|
return { success: true, file: record };
|
|
@@ -28609,11 +28592,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28609
28592
|
/**
|
|
28610
28593
|
* Link to an external file (RPC method)
|
|
28611
28594
|
*/
|
|
28612
|
-
async linkFile(
|
|
28595
|
+
async linkFile(path2, location, options) {
|
|
28613
28596
|
await this.ensureMigrated();
|
|
28614
28597
|
try {
|
|
28615
|
-
const
|
|
28616
|
-
const record = await
|
|
28598
|
+
const fs2 = this.getFileStorage();
|
|
28599
|
+
const record = await fs2.linkFile(path2, location, options);
|
|
28617
28600
|
return { success: true, file: record };
|
|
28618
28601
|
} catch (error) {
|
|
28619
28602
|
console.error("Error in linkFile:", error);
|
|
@@ -28624,11 +28607,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28624
28607
|
* Read a file from storage (RPC method)
|
|
28625
28608
|
* Returns base64-encoded data
|
|
28626
28609
|
*/
|
|
28627
|
-
async readFile(
|
|
28610
|
+
async readFile(path2) {
|
|
28628
28611
|
await this.ensureMigrated();
|
|
28629
28612
|
try {
|
|
28630
|
-
const
|
|
28631
|
-
const data = await
|
|
28613
|
+
const fs2 = this.getFileStorage();
|
|
28614
|
+
const data = await fs2.readFile(path2);
|
|
28632
28615
|
if (data === null) {
|
|
28633
28616
|
return { success: false, error: "File not found or external" };
|
|
28634
28617
|
}
|
|
@@ -28647,11 +28630,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28647
28630
|
/**
|
|
28648
28631
|
* Read a text file from storage (RPC method)
|
|
28649
28632
|
*/
|
|
28650
|
-
async readTextFile(
|
|
28633
|
+
async readTextFile(path2) {
|
|
28651
28634
|
await this.ensureMigrated();
|
|
28652
28635
|
try {
|
|
28653
|
-
const
|
|
28654
|
-
const content = await
|
|
28636
|
+
const fs2 = this.getFileStorage();
|
|
28637
|
+
const content = await fs2.readTextFile(path2);
|
|
28655
28638
|
if (content === null) {
|
|
28656
28639
|
return { success: false, error: "File not found or external" };
|
|
28657
28640
|
}
|
|
@@ -28664,11 +28647,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28664
28647
|
/**
|
|
28665
28648
|
* Get file metadata (RPC method)
|
|
28666
28649
|
*/
|
|
28667
|
-
async statFile(
|
|
28650
|
+
async statFile(path2) {
|
|
28668
28651
|
await this.ensureMigrated();
|
|
28669
28652
|
try {
|
|
28670
|
-
const
|
|
28671
|
-
const record = await
|
|
28653
|
+
const fs2 = this.getFileStorage();
|
|
28654
|
+
const record = await fs2.stat(path2);
|
|
28672
28655
|
if (record === null) {
|
|
28673
28656
|
return { success: false, error: "File not found" };
|
|
28674
28657
|
}
|
|
@@ -28681,11 +28664,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28681
28664
|
/**
|
|
28682
28665
|
* Check if file exists (RPC method)
|
|
28683
28666
|
*/
|
|
28684
|
-
async fileExists(
|
|
28667
|
+
async fileExists(path2) {
|
|
28685
28668
|
await this.ensureMigrated();
|
|
28686
28669
|
try {
|
|
28687
|
-
const
|
|
28688
|
-
const exists2 = await
|
|
28670
|
+
const fs2 = this.getFileStorage();
|
|
28671
|
+
const exists2 = await fs2.exists(path2);
|
|
28689
28672
|
return { success: true, exists: exists2 };
|
|
28690
28673
|
} catch (error) {
|
|
28691
28674
|
console.error("Error in fileExists:", error);
|
|
@@ -28695,12 +28678,12 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28695
28678
|
/**
|
|
28696
28679
|
* Delete a file (RPC method)
|
|
28697
28680
|
*/
|
|
28698
|
-
async unlinkFile(
|
|
28681
|
+
async unlinkFile(path2) {
|
|
28699
28682
|
await this.ensureMigrated();
|
|
28700
28683
|
try {
|
|
28701
|
-
const
|
|
28702
|
-
await
|
|
28703
|
-
this.broadcastEvent("file_deleted", { path });
|
|
28684
|
+
const fs2 = this.getFileStorage();
|
|
28685
|
+
await fs2.unlink(path2);
|
|
28686
|
+
this.broadcastEvent("file_deleted", { path: path2 });
|
|
28704
28687
|
return { success: true };
|
|
28705
28688
|
} catch (error) {
|
|
28706
28689
|
console.error("Error in unlinkFile:", error);
|
|
@@ -28710,12 +28693,12 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28710
28693
|
/**
|
|
28711
28694
|
* Create a directory (RPC method)
|
|
28712
28695
|
*/
|
|
28713
|
-
async mkdirFile(
|
|
28696
|
+
async mkdirFile(path2) {
|
|
28714
28697
|
await this.ensureMigrated();
|
|
28715
28698
|
try {
|
|
28716
|
-
const
|
|
28717
|
-
const record = await
|
|
28718
|
-
this.broadcastEvent("file_created", { path, file: record });
|
|
28699
|
+
const fs2 = this.getFileStorage();
|
|
28700
|
+
const record = await fs2.mkdir(path2);
|
|
28701
|
+
this.broadcastEvent("file_created", { path: path2, file: record });
|
|
28719
28702
|
return { success: true, directory: record };
|
|
28720
28703
|
} catch (error) {
|
|
28721
28704
|
console.error("Error in mkdirFile:", error);
|
|
@@ -28725,11 +28708,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28725
28708
|
/**
|
|
28726
28709
|
* List directory contents (RPC method)
|
|
28727
28710
|
*/
|
|
28728
|
-
async readdirFile(
|
|
28711
|
+
async readdirFile(path2) {
|
|
28729
28712
|
await this.ensureMigrated();
|
|
28730
28713
|
try {
|
|
28731
|
-
const
|
|
28732
|
-
const files = await
|
|
28714
|
+
const fs2 = this.getFileStorage();
|
|
28715
|
+
const files = await fs2.readdir(path2);
|
|
28733
28716
|
return { success: true, files };
|
|
28734
28717
|
} catch (error) {
|
|
28735
28718
|
console.error("Error in readdirFile:", error);
|
|
@@ -28739,12 +28722,12 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28739
28722
|
/**
|
|
28740
28723
|
* Remove empty directory (RPC method)
|
|
28741
28724
|
*/
|
|
28742
|
-
async rmdirFile(
|
|
28725
|
+
async rmdirFile(path2) {
|
|
28743
28726
|
await this.ensureMigrated();
|
|
28744
28727
|
try {
|
|
28745
|
-
const
|
|
28746
|
-
await
|
|
28747
|
-
this.broadcastEvent("file_deleted", { path });
|
|
28728
|
+
const fs2 = this.getFileStorage();
|
|
28729
|
+
await fs2.rmdir(path2);
|
|
28730
|
+
this.broadcastEvent("file_deleted", { path: path2 });
|
|
28748
28731
|
return { success: true };
|
|
28749
28732
|
} catch (error) {
|
|
28750
28733
|
console.error("Error in rmdirFile:", error);
|
|
@@ -28759,9 +28742,9 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28759
28742
|
await this.ensureMigrated();
|
|
28760
28743
|
try {
|
|
28761
28744
|
const { normalizePath: normalizePath2 } = await Promise.resolve().then(() => (init_files(), files_exports));
|
|
28762
|
-
const
|
|
28745
|
+
const fs2 = this.getFileStorage();
|
|
28763
28746
|
const from = normalizePath2(sourcePath);
|
|
28764
|
-
const record = await
|
|
28747
|
+
const record = await fs2.move(sourcePath, destinationPath);
|
|
28765
28748
|
this.broadcastEvent("file_moved", { from, path: record.path, file: record });
|
|
28766
28749
|
this.broadcastEvent("file_deleted", { path: from });
|
|
28767
28750
|
this.broadcastEvent("file_created", { path: record.path, file: record });
|
|
@@ -28774,13 +28757,13 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28774
28757
|
/**
|
|
28775
28758
|
* Rename a file or directory in place (RPC method).
|
|
28776
28759
|
*/
|
|
28777
|
-
async renameFile(
|
|
28760
|
+
async renameFile(path2, newName) {
|
|
28778
28761
|
await this.ensureMigrated();
|
|
28779
28762
|
try {
|
|
28780
28763
|
const { normalizePath: normalizePath2 } = await Promise.resolve().then(() => (init_files(), files_exports));
|
|
28781
|
-
const
|
|
28782
|
-
const from = normalizePath2(
|
|
28783
|
-
const record = await
|
|
28764
|
+
const fs2 = this.getFileStorage();
|
|
28765
|
+
const from = normalizePath2(path2);
|
|
28766
|
+
const record = await fs2.rename(path2, newName);
|
|
28784
28767
|
this.broadcastEvent("file_moved", { from, path: record.path, file: record });
|
|
28785
28768
|
this.broadcastEvent("file_deleted", { path: from });
|
|
28786
28769
|
this.broadcastEvent("file_created", { path: record.path, file: record });
|
|
@@ -28796,8 +28779,8 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28796
28779
|
async getFileStats() {
|
|
28797
28780
|
await this.ensureMigrated();
|
|
28798
28781
|
try {
|
|
28799
|
-
const
|
|
28800
|
-
const stats = await
|
|
28782
|
+
const fs2 = this.getFileStorage();
|
|
28783
|
+
const stats = await fs2.getFileStats();
|
|
28801
28784
|
return { success: true, stats };
|
|
28802
28785
|
} catch (error) {
|
|
28803
28786
|
console.error("Error in getFileStats:", error);
|
|
@@ -28808,11 +28791,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28808
28791
|
* Get thumbnail for an image (RPC method)
|
|
28809
28792
|
* Returns base64-encoded data
|
|
28810
28793
|
*/
|
|
28811
|
-
async getFileThumbnail(
|
|
28794
|
+
async getFileThumbnail(path2) {
|
|
28812
28795
|
await this.ensureMigrated();
|
|
28813
28796
|
try {
|
|
28814
|
-
const
|
|
28815
|
-
const data = await
|
|
28797
|
+
const fs2 = this.getFileStorage();
|
|
28798
|
+
const data = await fs2.getThumbnail(path2);
|
|
28816
28799
|
if (data === null) {
|
|
28817
28800
|
return { success: false, error: "Thumbnail not found" };
|
|
28818
28801
|
}
|
|
@@ -28834,8 +28817,8 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28834
28817
|
async grepFiles(pattern, options) {
|
|
28835
28818
|
await this.ensureMigrated();
|
|
28836
28819
|
try {
|
|
28837
|
-
const
|
|
28838
|
-
const results = await
|
|
28820
|
+
const fs2 = this.getFileStorage();
|
|
28821
|
+
const results = await fs2.grep(pattern, options);
|
|
28839
28822
|
return { success: true, results };
|
|
28840
28823
|
} catch (error) {
|
|
28841
28824
|
console.error("Error in grepFiles:", error);
|
|
@@ -28848,8 +28831,8 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28848
28831
|
async findFiles(pattern, options) {
|
|
28849
28832
|
await this.ensureMigrated();
|
|
28850
28833
|
try {
|
|
28851
|
-
const
|
|
28852
|
-
const files = await
|
|
28834
|
+
const fs2 = this.getFileStorage();
|
|
28835
|
+
const files = await fs2.find(pattern, options);
|
|
28853
28836
|
return { success: true, files };
|
|
28854
28837
|
} catch (error) {
|
|
28855
28838
|
console.error("Error in findFiles:", error);
|
|
@@ -28864,11 +28847,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28864
28847
|
* Creates file record with is_chunked=1 and chunk_count=null.
|
|
28865
28848
|
* Caller should then use writeFileChunk() to write chunks.
|
|
28866
28849
|
*/
|
|
28867
|
-
async startChunkedUpload(
|
|
28850
|
+
async startChunkedUpload(path2, totalSize, mimeType, options) {
|
|
28868
28851
|
await this.ensureMigrated();
|
|
28869
28852
|
try {
|
|
28870
28853
|
const { CHUNK_SIZE: CHUNK_SIZE2, normalizePath: normalizePath2, basename: basename2 } = await Promise.resolve().then(() => (init_files(), files_exports));
|
|
28871
|
-
const normalizedPath = normalizePath2(
|
|
28854
|
+
const normalizedPath = normalizePath2(path2);
|
|
28872
28855
|
const name = basename2(normalizedPath);
|
|
28873
28856
|
const now = Date.now();
|
|
28874
28857
|
const expectedChunks = Math.ceil(totalSize / CHUNK_SIZE2);
|
|
@@ -28905,11 +28888,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28905
28888
|
* @param chunkIndex - 0-based chunk index
|
|
28906
28889
|
* @param data - Base64 encoded chunk data
|
|
28907
28890
|
*/
|
|
28908
|
-
async writeFileChunk(
|
|
28891
|
+
async writeFileChunk(path2, chunkIndex, data) {
|
|
28909
28892
|
await this.ensureMigrated();
|
|
28910
28893
|
try {
|
|
28911
28894
|
const { normalizePath: normalizePath2 } = await Promise.resolve().then(() => (init_files(), files_exports));
|
|
28912
|
-
const normalizedPath = normalizePath2(
|
|
28895
|
+
const normalizedPath = normalizePath2(path2);
|
|
28913
28896
|
const binaryString = atob(data);
|
|
28914
28897
|
const dataBuffer = new Uint8Array(binaryString.length);
|
|
28915
28898
|
for (let i = 0; i < binaryString.length; i++) {
|
|
@@ -28931,12 +28914,12 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28931
28914
|
* Complete a chunked file upload.
|
|
28932
28915
|
* Validates all chunks are present and sets chunk_count.
|
|
28933
28916
|
*/
|
|
28934
|
-
async completeChunkedUpload(
|
|
28917
|
+
async completeChunkedUpload(path2, expectedChunks, options) {
|
|
28935
28918
|
await this.ensureMigrated();
|
|
28936
28919
|
try {
|
|
28937
28920
|
const { normalizePath: normalizePath2 } = await Promise.resolve().then(() => (init_files(), files_exports));
|
|
28938
|
-
const
|
|
28939
|
-
const normalizedPath = normalizePath2(
|
|
28921
|
+
const fs2 = this.getFileStorage();
|
|
28922
|
+
const normalizedPath = normalizePath2(path2);
|
|
28940
28923
|
const countResult = await this.ctx.storage.sql.exec(
|
|
28941
28924
|
`SELECT COUNT(*) as count FROM file_chunks WHERE file_path = ?`,
|
|
28942
28925
|
normalizedPath
|
|
@@ -28962,7 +28945,7 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28962
28945
|
thumbnailBuffer || null,
|
|
28963
28946
|
normalizedPath
|
|
28964
28947
|
);
|
|
28965
|
-
const file = await
|
|
28948
|
+
const file = await fs2.stat(normalizedPath);
|
|
28966
28949
|
if (file) {
|
|
28967
28950
|
this.broadcastEvent("file_created", { path: normalizedPath, file });
|
|
28968
28951
|
}
|
|
@@ -28976,11 +28959,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
28976
28959
|
* Read a single chunk of a file.
|
|
28977
28960
|
* Use for streaming large files to client.
|
|
28978
28961
|
*/
|
|
28979
|
-
async readFileChunk(
|
|
28962
|
+
async readFileChunk(path2, chunkIndex) {
|
|
28980
28963
|
await this.ensureMigrated();
|
|
28981
28964
|
try {
|
|
28982
28965
|
const { normalizePath: normalizePath2 } = await Promise.resolve().then(() => (init_files(), files_exports));
|
|
28983
|
-
const normalizedPath = normalizePath2(
|
|
28966
|
+
const normalizedPath = normalizePath2(path2);
|
|
28984
28967
|
const cursor = await this.ctx.storage.sql.exec(
|
|
28985
28968
|
`SELECT data FROM file_chunks WHERE file_path = ? AND chunk_index = ?`,
|
|
28986
28969
|
normalizedPath,
|
|
@@ -29005,11 +28988,11 @@ Its execution was lost (the executor restarted or hung) and automatic recovery w
|
|
|
29005
28988
|
/**
|
|
29006
28989
|
* Get file info including chunking metadata.
|
|
29007
28990
|
*/
|
|
29008
|
-
async getFileInfo(
|
|
28991
|
+
async getFileInfo(path2) {
|
|
29009
28992
|
await this.ensureMigrated();
|
|
29010
28993
|
try {
|
|
29011
|
-
const
|
|
29012
|
-
const file = await
|
|
28994
|
+
const fs2 = this.getFileStorage();
|
|
28995
|
+
const file = await fs2.stat(path2);
|
|
29013
28996
|
if (!file) {
|
|
29014
28997
|
return { success: false, error: "File not found" };
|
|
29015
28998
|
}
|
|
@@ -29227,16 +29210,16 @@ function parseUserRouteKey(key) {
|
|
|
29227
29210
|
}
|
|
29228
29211
|
return { key, method, segments, dynamism };
|
|
29229
29212
|
}
|
|
29230
|
-
function matchSegments(route,
|
|
29213
|
+
function matchSegments(route, path2) {
|
|
29231
29214
|
const params = {};
|
|
29232
29215
|
for (let i = 0; i < route.length; i++) {
|
|
29233
29216
|
const seg = route[i];
|
|
29234
29217
|
if (seg === "[*]") {
|
|
29235
29218
|
if (i !== route.length - 1) return null;
|
|
29236
|
-
params["*"] =
|
|
29219
|
+
params["*"] = path2.slice(i).join("/");
|
|
29237
29220
|
return params;
|
|
29238
29221
|
}
|
|
29239
|
-
const value =
|
|
29222
|
+
const value = path2[i];
|
|
29240
29223
|
if (value === void 0) return null;
|
|
29241
29224
|
if (seg.startsWith("[") && seg.endsWith("]")) {
|
|
29242
29225
|
params[seg.slice(1, -1)] = value;
|
|
@@ -29244,16 +29227,16 @@ function matchSegments(route, path) {
|
|
|
29244
29227
|
return null;
|
|
29245
29228
|
}
|
|
29246
29229
|
}
|
|
29247
|
-
return
|
|
29230
|
+
return path2.length === route.length ? params : null;
|
|
29248
29231
|
}
|
|
29249
29232
|
function matchUserRoute(keys, method, endpointPath) {
|
|
29250
|
-
const
|
|
29233
|
+
const path2 = endpointPath.split("/").filter((s) => s.length > 0);
|
|
29251
29234
|
const wanted = method.toUpperCase();
|
|
29252
29235
|
let best = null;
|
|
29253
29236
|
for (const key of keys) {
|
|
29254
29237
|
const route = parseUserRouteKey(key);
|
|
29255
29238
|
if (route.method !== wanted) continue;
|
|
29256
|
-
const params = matchSegments(route.segments,
|
|
29239
|
+
const params = matchSegments(route.segments, path2);
|
|
29257
29240
|
if (!params) continue;
|
|
29258
29241
|
if (!best || route.dynamism < best.route.dynamism) {
|
|
29259
29242
|
best = { route, params };
|