refactor: trim file transfer helper exports · openclaw/openclaw@5bed76d
steipete
·
2026-05-02
·
via Recent Commits to openclaw:main
File tree
extensions/file-transfer/src
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3,18 +3,18 @@ import crypto from "node:crypto";
|
3 | 3 | import fs from "node:fs/promises"; |
4 | 4 | import path from "node:path"; |
5 | 5 | |
6 | | -export const DIR_FETCH_HARD_MAX_BYTES = 16 * 1024 * 1024; |
7 | | -export const DIR_FETCH_DEFAULT_MAX_BYTES = 8 * 1024 * 1024; |
| 6 | +const DIR_FETCH_HARD_MAX_BYTES = 16 * 1024 * 1024; |
| 7 | +const DIR_FETCH_DEFAULT_MAX_BYTES = 8 * 1024 * 1024; |
8 | 8 | |
9 | | -export type DirFetchParams = { |
| 9 | +type DirFetchParams = { |
10 | 10 | path?: unknown; |
11 | 11 | maxBytes?: unknown; |
12 | 12 | includeDotfiles?: unknown; |
13 | 13 | followSymlinks?: unknown; |
14 | 14 | preflightOnly?: unknown; |
15 | 15 | }; |
16 | 16 | |
17 | | -export type DirFetchOk = { |
| 17 | +type DirFetchOk = { |
18 | 18 | ok: true; |
19 | 19 | path: string; |
20 | 20 | tarBase64: string; |
@@ -25,22 +25,22 @@ export type DirFetchOk = {
|
25 | 25 | preflightOnly?: boolean; |
26 | 26 | }; |
27 | 27 | |
28 | | -export type DirFetchErrCode = |
| 28 | +type DirFetchErrCode = |
29 | 29 | | "INVALID_PATH" |
30 | 30 | | "NOT_FOUND" |
31 | 31 | | "IS_FILE" |
32 | 32 | | "TREE_TOO_LARGE" |
33 | 33 | | "SYMLINK_REDIRECT" |
34 | 34 | | "READ_ERROR"; |
35 | 35 | |
36 | | -export type DirFetchErr = { |
| 36 | +type DirFetchErr = { |
37 | 37 | ok: false; |
38 | 38 | code: DirFetchErrCode; |
39 | 39 | message: string; |
40 | 40 | canonicalPath?: string; |
41 | 41 | }; |
42 | 42 | |
43 | | -export type DirFetchResult = DirFetchOk | DirFetchErr; |
| 43 | +type DirFetchResult = DirFetchOk | DirFetchErr; |
44 | 44 | |
45 | 45 | function clampMaxBytes(input: unknown): number { |
46 | 46 | if (typeof input !== "number" || !Number.isFinite(input) || input <= 0) { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -5,14 +5,14 @@ import { mimeFromExtension } from "../shared/mime.js";
|
5 | 5 | export const DIR_LIST_DEFAULT_MAX_ENTRIES = 200; |
6 | 6 | export const DIR_LIST_HARD_MAX_ENTRIES = 5000; |
7 | 7 | |
8 | | -export type DirListParams = { |
| 8 | +type DirListParams = { |
9 | 9 | path?: unknown; |
10 | 10 | pageToken?: unknown; |
11 | 11 | maxEntries?: unknown; |
12 | 12 | followSymlinks?: unknown; |
13 | 13 | }; |
14 | 14 | |
15 | | -export type DirListEntry = { |
| 15 | +type DirListEntry = { |
16 | 16 | name: string; |
17 | 17 | path: string; |
18 | 18 | size: number; |
@@ -21,30 +21,30 @@ export type DirListEntry = {
|
21 | 21 | mtime: number; |
22 | 22 | }; |
23 | 23 | |
24 | | -export type DirListOk = { |
| 24 | +type DirListOk = { |
25 | 25 | ok: true; |
26 | 26 | path: string; |
27 | 27 | entries: DirListEntry[]; |
28 | 28 | nextPageToken?: string; |
29 | 29 | truncated: boolean; |
30 | 30 | }; |
31 | 31 | |
32 | | -export type DirListErrCode = |
| 32 | +type DirListErrCode = |
33 | 33 | | "INVALID_PATH" |
34 | 34 | | "NOT_FOUND" |
35 | 35 | | "PERMISSION_DENIED" |
36 | 36 | | "IS_FILE" |
37 | 37 | | "SYMLINK_REDIRECT" |
38 | 38 | | "READ_ERROR"; |
39 | 39 | |
40 | | -export type DirListErr = { |
| 40 | +type DirListErr = { |
41 | 41 | ok: false; |
42 | 42 | code: DirListErrCode; |
43 | 43 | message: string; |
44 | 44 | canonicalPath?: string; |
45 | 45 | }; |
46 | 46 | |
47 | | -export type DirListResult = DirListOk | DirListErr; |
| 47 | +type DirListResult = DirListOk | DirListErr; |
48 | 48 | |
49 | 49 | function clampMaxEntries(input: unknown): number { |
50 | 50 | if (typeof input !== "number" || !Number.isFinite(input) || input <= 0) { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -7,14 +7,14 @@ import { EXTENSION_MIME } from "../shared/mime.js";
|
7 | 7 | export const FILE_FETCH_HARD_MAX_BYTES = 16 * 1024 * 1024; |
8 | 8 | export const FILE_FETCH_DEFAULT_MAX_BYTES = 8 * 1024 * 1024; |
9 | 9 | |
10 | | -export type FileFetchParams = { |
| 10 | +type FileFetchParams = { |
11 | 11 | path?: unknown; |
12 | 12 | maxBytes?: unknown; |
13 | 13 | followSymlinks?: unknown; |
14 | 14 | preflightOnly?: unknown; |
15 | 15 | }; |
16 | 16 | |
17 | | -export type FileFetchOk = { |
| 17 | +type FileFetchOk = { |
18 | 18 | ok: true; |
19 | 19 | path: string; |
20 | 20 | size: number; |
@@ -24,7 +24,7 @@ export type FileFetchOk = {
|
24 | 24 | preflightOnly?: boolean; |
25 | 25 | }; |
26 | 26 | |
27 | | -export type FileFetchErrCode = |
| 27 | +type FileFetchErrCode = |
28 | 28 | | "INVALID_PATH" |
29 | 29 | | "NOT_FOUND" |
30 | 30 | | "PERMISSION_DENIED" |
@@ -34,14 +34,14 @@ export type FileFetchErrCode =
|
34 | 34 | | "SYMLINK_REDIRECT" |
35 | 35 | | "READ_ERROR"; |
36 | 36 | |
37 | | -export type FileFetchErr = { |
| 37 | +type FileFetchErr = { |
38 | 38 | ok: false; |
39 | 39 | code: FileFetchErrCode; |
40 | 40 | message: string; |
41 | 41 | canonicalPath?: string; |
42 | 42 | }; |
43 | 43 | |
44 | | -export type FileFetchResult = FileFetchOk | FileFetchErr; |
| 44 | +type FileFetchResult = FileFetchOk | FileFetchErr; |
45 | 45 | |
46 | 46 | function detectMimeType(filePath: string): string { |
47 | 47 | if (process.platform !== "win32") { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -14,7 +14,7 @@ import path from "node:path";
|
14 | 14 | |
15 | 15 | export type FileTransferAuditOp = "file.fetch" | "dir.list" | "dir.fetch" | "file.write"; |
16 | 16 | |
17 | | -export type FileTransferAuditDecision = |
| 17 | +type FileTransferAuditDecision = |
18 | 18 | | "allowed" |
19 | 19 | | "allowed:once" |
20 | 20 | | "allowed:always" |
@@ -25,7 +25,7 @@ export type FileTransferAuditDecision =
|
25 | 25 | | "denied:symlink_escape" |
26 | 26 | | "error"; |
27 | 27 | |
28 | | -export type FileTransferAuditRecord = { |
| 28 | +type FileTransferAuditRecord = { |
29 | 29 | timestamp: string; |
30 | 30 | op: FileTransferAuditOp; |
31 | 31 | nodeId: string; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2,7 +2,7 @@
|
2 | 2 | // Every tool returns the same { ok: false, code, message, canonicalPath? } |
3 | 3 | // shape so the model can reason about errors uniformly. |
4 | 4 | |
5 | | -export type FileTransferErrCode = |
| 5 | +type FileTransferErrCode = |
6 | 6 | // Path-shape errors (caller's fault) |
7 | 7 | | "INVALID_PATH" |
8 | 8 | | "INVALID_BASE64" |
@@ -27,7 +27,7 @@ export type FileTransferErrCode =
|
27 | 27 | | "POLICY_DENIED" |
28 | 28 | | "NO_POLICY"; |
29 | 29 | |
30 | | -export type FileTransferErr = { |
| 30 | +type FileTransferErr = { |
31 | 31 | ok: false; |
32 | 32 | code: FileTransferErrCode; |
33 | 33 | message: string; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | // Shared param-validation helpers used by all four agent tools. |
2 | 2 | // Goal: identical validation behavior + identical error shapes everywhere. |
3 | 3 | |
4 | | -export type GatewayCallOptions = { |
| 4 | +type GatewayCallOptions = { |
5 | 5 | gatewayUrl?: string; |
6 | 6 | gatewayToken?: string; |
7 | 7 | timeoutMs?: number; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。