@echofiles/echo-pdf 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -0
- package/dist/agent-defaults.d.ts +3 -0
- package/dist/agent-defaults.js +18 -0
- package/dist/auth.d.ts +18 -0
- package/dist/auth.js +24 -0
- package/dist/core/index.d.ts +50 -0
- package/dist/core/index.js +7 -0
- package/dist/file-ops.d.ts +11 -0
- package/dist/file-ops.js +36 -0
- package/dist/file-store-do.d.ts +36 -0
- package/dist/file-store-do.js +298 -0
- package/dist/file-utils.d.ts +6 -0
- package/dist/file-utils.js +36 -0
- package/dist/http-error.d.ts +9 -0
- package/dist/http-error.js +14 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mcp-server.d.ts +3 -0
- package/dist/mcp-server.js +127 -0
- package/dist/pdf-agent.d.ts +18 -0
- package/dist/pdf-agent.js +217 -0
- package/dist/pdf-config.d.ts +4 -0
- package/dist/pdf-config.js +130 -0
- package/dist/pdf-storage.d.ts +8 -0
- package/dist/pdf-storage.js +86 -0
- package/dist/pdf-types.d.ts +79 -0
- package/dist/pdf-types.js +1 -0
- package/dist/pdfium-engine.d.ts +9 -0
- package/dist/pdfium-engine.js +180 -0
- package/dist/provider-client.d.ts +12 -0
- package/dist/provider-client.js +134 -0
- package/dist/provider-keys.d.ts +10 -0
- package/dist/provider-keys.js +27 -0
- package/dist/r2-file-store.d.ts +20 -0
- package/dist/r2-file-store.js +176 -0
- package/dist/response-schema.d.ts +15 -0
- package/dist/response-schema.js +159 -0
- package/dist/tool-registry.d.ts +16 -0
- package/dist/tool-registry.js +175 -0
- package/dist/types.d.ts +91 -0
- package/dist/types.js +1 -0
- package/dist/worker.d.ts +7 -0
- package/dist/worker.js +366 -0
- package/package.json +22 -4
- package/wrangler.toml +1 -1
- package/src/agent-defaults.ts +0 -25
- package/src/file-ops.ts +0 -50
- package/src/file-store-do.ts +0 -349
- package/src/file-utils.ts +0 -43
- package/src/http-error.ts +0 -21
- package/src/index.ts +0 -415
- package/src/mcp-server.ts +0 -171
- package/src/pdf-agent.ts +0 -252
- package/src/pdf-config.ts +0 -143
- package/src/pdf-storage.ts +0 -109
- package/src/pdf-types.ts +0 -85
- package/src/pdfium-engine.ts +0 -207
- package/src/provider-client.ts +0 -176
- package/src/provider-keys.ts +0 -44
- package/src/r2-file-store.ts +0 -195
- package/src/response-schema.ts +0 -182
- package/src/tool-registry.ts +0 -203
- package/src/types.ts +0 -40
- package/src/wasm.d.ts +0 -4
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
const MAX_TEXT_STRING = 1200;
|
|
2
|
+
const MAX_TEXT_ARRAY = 40;
|
|
3
|
+
const MAX_TEXT_DEPTH = 8;
|
|
4
|
+
const asObj = (value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
5
|
+
? value
|
|
6
|
+
: {};
|
|
7
|
+
const inferKind = (mimeType) => {
|
|
8
|
+
const mime = (mimeType || "").toLowerCase();
|
|
9
|
+
if (mime.startsWith("image/"))
|
|
10
|
+
return "image";
|
|
11
|
+
if (mime === "application/pdf")
|
|
12
|
+
return "pdf";
|
|
13
|
+
if (mime.includes("json"))
|
|
14
|
+
return "json";
|
|
15
|
+
if (mime.startsWith("text/"))
|
|
16
|
+
return "text";
|
|
17
|
+
return "file";
|
|
18
|
+
};
|
|
19
|
+
const toAbsoluteUrl = (value, baseUrl) => {
|
|
20
|
+
try {
|
|
21
|
+
return new URL(value, baseUrl).toString();
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const addArtifact = (artifacts, artifact) => {
|
|
28
|
+
if (!artifact.id && !artifact.url && !artifact.filename)
|
|
29
|
+
return;
|
|
30
|
+
artifacts.push(artifact);
|
|
31
|
+
};
|
|
32
|
+
export const buildToolOutputEnvelope = (result, baseUrl) => {
|
|
33
|
+
const root = asObj(result);
|
|
34
|
+
const artifacts = [];
|
|
35
|
+
const fileMeta = asObj(root.file);
|
|
36
|
+
if (typeof fileMeta.id === "string") {
|
|
37
|
+
addArtifact(artifacts, {
|
|
38
|
+
id: fileMeta.id,
|
|
39
|
+
kind: inferKind(typeof fileMeta.mimeType === "string" ? fileMeta.mimeType : undefined),
|
|
40
|
+
mimeType: typeof fileMeta.mimeType === "string" ? fileMeta.mimeType : undefined,
|
|
41
|
+
filename: typeof fileMeta.filename === "string" ? fileMeta.filename : undefined,
|
|
42
|
+
sizeBytes: typeof fileMeta.sizeBytes === "number" ? fileMeta.sizeBytes : undefined,
|
|
43
|
+
url: typeof root.url === "string" ? toAbsoluteUrl(root.url, baseUrl) : undefined,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const images = Array.isArray(root.images) ? root.images : [];
|
|
47
|
+
for (const item of images) {
|
|
48
|
+
const image = asObj(item);
|
|
49
|
+
const fileId = typeof image.fileId === "string" ? image.fileId : undefined;
|
|
50
|
+
const rawUrl = typeof image.url === "string" ? image.url : undefined;
|
|
51
|
+
if (!fileId && !rawUrl)
|
|
52
|
+
continue;
|
|
53
|
+
addArtifact(artifacts, {
|
|
54
|
+
id: fileId,
|
|
55
|
+
kind: "image",
|
|
56
|
+
mimeType: typeof image.mimeType === "string" ? image.mimeType : "image/png",
|
|
57
|
+
filename: fileId ? `artifact-${fileId}.png` : undefined,
|
|
58
|
+
url: rawUrl ? toAbsoluteUrl(rawUrl, baseUrl) : undefined,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const files = Array.isArray(root.files) ? root.files : [];
|
|
62
|
+
for (const item of files) {
|
|
63
|
+
const meta = asObj(item);
|
|
64
|
+
if (typeof meta.id !== "string")
|
|
65
|
+
continue;
|
|
66
|
+
addArtifact(artifacts, {
|
|
67
|
+
id: meta.id,
|
|
68
|
+
kind: inferKind(typeof meta.mimeType === "string" ? meta.mimeType : undefined),
|
|
69
|
+
mimeType: typeof meta.mimeType === "string" ? meta.mimeType : undefined,
|
|
70
|
+
filename: typeof meta.filename === "string" ? meta.filename : undefined,
|
|
71
|
+
sizeBytes: typeof meta.sizeBytes === "number" ? meta.sizeBytes : undefined,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
ok: true,
|
|
76
|
+
data: result,
|
|
77
|
+
artifacts,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const summarizeData = (data) => {
|
|
81
|
+
const root = asObj(data);
|
|
82
|
+
if (typeof root.returnMode === "string" && Array.isArray(root.images)) {
|
|
83
|
+
return `Extracted ${root.images.length} page image(s) in returnMode=${root.returnMode}.`;
|
|
84
|
+
}
|
|
85
|
+
if (Array.isArray(root.pages)) {
|
|
86
|
+
return `Processed ${root.pages.length} page(s).`;
|
|
87
|
+
}
|
|
88
|
+
if (Array.isArray(root.files)) {
|
|
89
|
+
return `Listed ${root.files.length} file(s).`;
|
|
90
|
+
}
|
|
91
|
+
if (typeof root.deleted === "boolean") {
|
|
92
|
+
return root.deleted ? "File deleted." : "File not found.";
|
|
93
|
+
}
|
|
94
|
+
return "Tool executed successfully.";
|
|
95
|
+
};
|
|
96
|
+
const sanitizeString = (value) => {
|
|
97
|
+
if (value.startsWith("data:")) {
|
|
98
|
+
const [head] = value.split(",", 1);
|
|
99
|
+
return `${head},<omitted>`;
|
|
100
|
+
}
|
|
101
|
+
if (/^[A-Za-z0-9+/=]{300,}$/.test(value)) {
|
|
102
|
+
return `<base64 omitted len=${value.length}>`;
|
|
103
|
+
}
|
|
104
|
+
if (value.length > MAX_TEXT_STRING) {
|
|
105
|
+
return `${value.slice(0, MAX_TEXT_STRING)}...(truncated ${value.length - MAX_TEXT_STRING} chars)`;
|
|
106
|
+
}
|
|
107
|
+
return value;
|
|
108
|
+
};
|
|
109
|
+
const sanitizeForText = (value, depth = 0) => {
|
|
110
|
+
if (depth >= MAX_TEXT_DEPTH)
|
|
111
|
+
return "<max-depth>";
|
|
112
|
+
if (typeof value === "string")
|
|
113
|
+
return sanitizeString(value);
|
|
114
|
+
if (typeof value !== "object" || value === null)
|
|
115
|
+
return value;
|
|
116
|
+
if (Array.isArray(value)) {
|
|
117
|
+
const items = value.slice(0, MAX_TEXT_ARRAY).map((item) => sanitizeForText(item, depth + 1));
|
|
118
|
+
if (value.length > MAX_TEXT_ARRAY) {
|
|
119
|
+
items.push(`<truncated ${value.length - MAX_TEXT_ARRAY} items>`);
|
|
120
|
+
}
|
|
121
|
+
return items;
|
|
122
|
+
}
|
|
123
|
+
const out = {};
|
|
124
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
125
|
+
out[key] = sanitizeForText(nested, depth + 1);
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
};
|
|
129
|
+
export const buildMcpContent = (envelope) => {
|
|
130
|
+
const lines = [summarizeData(envelope.data)];
|
|
131
|
+
if (envelope.artifacts.length > 0) {
|
|
132
|
+
lines.push("Artifacts:");
|
|
133
|
+
for (const artifact of envelope.artifacts) {
|
|
134
|
+
const descriptor = [
|
|
135
|
+
artifact.kind,
|
|
136
|
+
artifact.filename ?? artifact.id ?? "artifact",
|
|
137
|
+
artifact.mimeType ?? "",
|
|
138
|
+
artifact.url ?? "",
|
|
139
|
+
]
|
|
140
|
+
.filter((v) => v.length > 0)
|
|
141
|
+
.join(" | ");
|
|
142
|
+
lines.push(`- ${descriptor}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
lines.push("");
|
|
146
|
+
lines.push(JSON.stringify(sanitizeForText(envelope), null, 2));
|
|
147
|
+
const content = [{ type: "text", text: lines.join("\n") }];
|
|
148
|
+
for (const artifact of envelope.artifacts) {
|
|
149
|
+
if (!artifact.url)
|
|
150
|
+
continue;
|
|
151
|
+
content.push({
|
|
152
|
+
type: "resource_link",
|
|
153
|
+
name: artifact.filename ?? artifact.id ?? "artifact",
|
|
154
|
+
uri: artifact.url,
|
|
155
|
+
mimeType: artifact.mimeType ?? "application/octet-stream",
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return content;
|
|
159
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { EchoPdfConfig, ToolSchema } from "./pdf-types.js";
|
|
2
|
+
import type { Env, FileStore } from "./types.js";
|
|
3
|
+
export interface ToolRuntimeContext {
|
|
4
|
+
readonly config: EchoPdfConfig;
|
|
5
|
+
readonly env: Env;
|
|
6
|
+
readonly fileStore: FileStore;
|
|
7
|
+
readonly providerApiKeys?: Record<string, string>;
|
|
8
|
+
readonly trace?: (event: {
|
|
9
|
+
kind: "step";
|
|
10
|
+
phase: "start" | "end" | "log";
|
|
11
|
+
name: string;
|
|
12
|
+
payload?: unknown;
|
|
13
|
+
}) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare const listToolSchemas: () => ReadonlyArray<ToolSchema>;
|
|
16
|
+
export declare const callTool: (name: string, args: unknown, ctx: ToolRuntimeContext) => Promise<unknown>;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { normalizeReturnMode } from "./file-utils.js";
|
|
2
|
+
import { runFileOp } from "./file-ops.js";
|
|
3
|
+
import { runPdfAgent } from "./pdf-agent.js";
|
|
4
|
+
const asNumberArray = (value) => Array.isArray(value) ? value.map((item) => Number(item)).filter((item) => Number.isInteger(item) && item > 0) : [];
|
|
5
|
+
const asObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
6
|
+
? value
|
|
7
|
+
: {};
|
|
8
|
+
const readString = (obj, key) => {
|
|
9
|
+
const value = obj[key];
|
|
10
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
11
|
+
};
|
|
12
|
+
const toolDefinitions = [
|
|
13
|
+
{
|
|
14
|
+
schema: {
|
|
15
|
+
name: "pdf_extract_pages",
|
|
16
|
+
description: "Render specific PDF pages to image and return inline/file_id/url mode.",
|
|
17
|
+
inputSchema: {
|
|
18
|
+
type: "object",
|
|
19
|
+
properties: {
|
|
20
|
+
fileId: { type: "string" },
|
|
21
|
+
url: { type: "string" },
|
|
22
|
+
base64: { type: "string" },
|
|
23
|
+
filename: { type: "string" },
|
|
24
|
+
pages: { type: "array", items: { type: "integer" } },
|
|
25
|
+
renderScale: { type: "number" },
|
|
26
|
+
returnMode: { type: "string", enum: ["inline", "file_id", "url"] },
|
|
27
|
+
},
|
|
28
|
+
required: ["pages"],
|
|
29
|
+
},
|
|
30
|
+
source: { kind: "local", toolName: "pdf.extract_pages" },
|
|
31
|
+
},
|
|
32
|
+
run: async (ctx, args) => {
|
|
33
|
+
const req = {
|
|
34
|
+
operation: "extract_pages",
|
|
35
|
+
fileId: readString(args, "fileId"),
|
|
36
|
+
url: readString(args, "url"),
|
|
37
|
+
base64: readString(args, "base64"),
|
|
38
|
+
filename: readString(args, "filename"),
|
|
39
|
+
pages: asNumberArray(args.pages),
|
|
40
|
+
renderScale: typeof args.renderScale === "number" ? args.renderScale : undefined,
|
|
41
|
+
provider: undefined,
|
|
42
|
+
model: "not-required",
|
|
43
|
+
providerApiKeys: ctx.providerApiKeys,
|
|
44
|
+
returnMode: normalizeReturnMode(args.returnMode),
|
|
45
|
+
};
|
|
46
|
+
return runPdfAgent(ctx.config, ctx.env, req, {
|
|
47
|
+
fileStore: ctx.fileStore,
|
|
48
|
+
trace: ctx.trace,
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
schema: {
|
|
54
|
+
name: "pdf_ocr_pages",
|
|
55
|
+
description: "OCR specific PDF pages using configured multimodal model.",
|
|
56
|
+
inputSchema: {
|
|
57
|
+
type: "object",
|
|
58
|
+
properties: {
|
|
59
|
+
fileId: { type: "string" },
|
|
60
|
+
url: { type: "string" },
|
|
61
|
+
base64: { type: "string" },
|
|
62
|
+
filename: { type: "string" },
|
|
63
|
+
pages: { type: "array", items: { type: "integer" } },
|
|
64
|
+
renderScale: { type: "number" },
|
|
65
|
+
provider: { type: "string" },
|
|
66
|
+
model: { type: "string" },
|
|
67
|
+
prompt: { type: "string" },
|
|
68
|
+
},
|
|
69
|
+
required: ["pages"],
|
|
70
|
+
},
|
|
71
|
+
source: { kind: "local", toolName: "pdf.ocr_pages" },
|
|
72
|
+
},
|
|
73
|
+
run: async (ctx, args) => {
|
|
74
|
+
const req = {
|
|
75
|
+
operation: "ocr_pages",
|
|
76
|
+
fileId: readString(args, "fileId"),
|
|
77
|
+
url: readString(args, "url"),
|
|
78
|
+
base64: readString(args, "base64"),
|
|
79
|
+
filename: readString(args, "filename"),
|
|
80
|
+
pages: asNumberArray(args.pages),
|
|
81
|
+
renderScale: typeof args.renderScale === "number" ? args.renderScale : undefined,
|
|
82
|
+
provider: readString(args, "provider"),
|
|
83
|
+
model: readString(args, "model") ?? "",
|
|
84
|
+
prompt: readString(args, "prompt"),
|
|
85
|
+
providerApiKeys: ctx.providerApiKeys,
|
|
86
|
+
returnMode: "inline",
|
|
87
|
+
};
|
|
88
|
+
return runPdfAgent(ctx.config, ctx.env, req, {
|
|
89
|
+
fileStore: ctx.fileStore,
|
|
90
|
+
trace: ctx.trace,
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
schema: {
|
|
96
|
+
name: "pdf_tables_to_latex",
|
|
97
|
+
description: "Recognize tables from pages and return LaTeX tabular output.",
|
|
98
|
+
inputSchema: {
|
|
99
|
+
type: "object",
|
|
100
|
+
properties: {
|
|
101
|
+
fileId: { type: "string" },
|
|
102
|
+
url: { type: "string" },
|
|
103
|
+
base64: { type: "string" },
|
|
104
|
+
filename: { type: "string" },
|
|
105
|
+
pages: { type: "array", items: { type: "integer" } },
|
|
106
|
+
renderScale: { type: "number" },
|
|
107
|
+
provider: { type: "string" },
|
|
108
|
+
model: { type: "string" },
|
|
109
|
+
prompt: { type: "string" },
|
|
110
|
+
},
|
|
111
|
+
required: ["pages"],
|
|
112
|
+
},
|
|
113
|
+
source: { kind: "local", toolName: "pdf.tables_to_latex" },
|
|
114
|
+
},
|
|
115
|
+
run: async (ctx, args) => {
|
|
116
|
+
const req = {
|
|
117
|
+
operation: "tables_to_latex",
|
|
118
|
+
fileId: readString(args, "fileId"),
|
|
119
|
+
url: readString(args, "url"),
|
|
120
|
+
base64: readString(args, "base64"),
|
|
121
|
+
filename: readString(args, "filename"),
|
|
122
|
+
pages: asNumberArray(args.pages),
|
|
123
|
+
renderScale: typeof args.renderScale === "number" ? args.renderScale : undefined,
|
|
124
|
+
provider: readString(args, "provider"),
|
|
125
|
+
model: readString(args, "model") ?? "",
|
|
126
|
+
prompt: readString(args, "prompt"),
|
|
127
|
+
providerApiKeys: ctx.providerApiKeys,
|
|
128
|
+
returnMode: "inline",
|
|
129
|
+
};
|
|
130
|
+
return runPdfAgent(ctx.config, ctx.env, req, {
|
|
131
|
+
fileStore: ctx.fileStore,
|
|
132
|
+
trace: ctx.trace,
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
schema: {
|
|
138
|
+
name: "file_ops",
|
|
139
|
+
description: "Basic file operations: list/read/delete/put for runtime file store.",
|
|
140
|
+
inputSchema: {
|
|
141
|
+
type: "object",
|
|
142
|
+
properties: {
|
|
143
|
+
op: { type: "string", enum: ["list", "read", "delete", "put"] },
|
|
144
|
+
fileId: { type: "string" },
|
|
145
|
+
includeBase64: { type: "boolean" },
|
|
146
|
+
text: { type: "string" },
|
|
147
|
+
filename: { type: "string" },
|
|
148
|
+
mimeType: { type: "string" },
|
|
149
|
+
base64: { type: "string" },
|
|
150
|
+
returnMode: { type: "string", enum: ["inline", "file_id", "url"] },
|
|
151
|
+
},
|
|
152
|
+
required: ["op"],
|
|
153
|
+
},
|
|
154
|
+
source: { kind: "local", toolName: "file.ops" },
|
|
155
|
+
},
|
|
156
|
+
run: async (ctx, args) => runFileOp(ctx.fileStore, {
|
|
157
|
+
op: readString(args, "op") ?? "list",
|
|
158
|
+
fileId: readString(args, "fileId"),
|
|
159
|
+
includeBase64: Boolean(args.includeBase64),
|
|
160
|
+
text: readString(args, "text"),
|
|
161
|
+
filename: readString(args, "filename"),
|
|
162
|
+
mimeType: readString(args, "mimeType"),
|
|
163
|
+
base64: readString(args, "base64"),
|
|
164
|
+
returnMode: normalizeReturnMode(args.returnMode),
|
|
165
|
+
}),
|
|
166
|
+
},
|
|
167
|
+
];
|
|
168
|
+
export const listToolSchemas = () => toolDefinitions.map((item) => item.schema);
|
|
169
|
+
export const callTool = async (name, args, ctx) => {
|
|
170
|
+
const definition = toolDefinitions.find((item) => item.schema.name === name);
|
|
171
|
+
if (!definition) {
|
|
172
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
173
|
+
}
|
|
174
|
+
return definition.run(ctx, asObject(args));
|
|
175
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
2
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
3
|
+
export type JsonArray = JsonValue[];
|
|
4
|
+
export interface JsonObject {
|
|
5
|
+
[key: string]: JsonValue;
|
|
6
|
+
}
|
|
7
|
+
export type ProviderType = "openai" | "openrouter" | "vercel-ai-gateway";
|
|
8
|
+
export type ReturnMode = "inline" | "file_id" | "url";
|
|
9
|
+
export interface Fetcher {
|
|
10
|
+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
11
|
+
}
|
|
12
|
+
export interface DurableObjectStub {
|
|
13
|
+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
14
|
+
}
|
|
15
|
+
export interface DurableObjectId {
|
|
16
|
+
}
|
|
17
|
+
export interface DurableObjectNamespace {
|
|
18
|
+
idFromName(name: string): DurableObjectId;
|
|
19
|
+
get(id: DurableObjectId): DurableObjectStub;
|
|
20
|
+
}
|
|
21
|
+
export interface DurableObjectStorage {
|
|
22
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
23
|
+
put<T>(key: string, value: T): Promise<void>;
|
|
24
|
+
list<T>(options?: {
|
|
25
|
+
prefix?: string;
|
|
26
|
+
}): Promise<Map<string, T>>;
|
|
27
|
+
delete(key: string): Promise<boolean>;
|
|
28
|
+
}
|
|
29
|
+
export interface DurableObjectState {
|
|
30
|
+
storage: DurableObjectStorage;
|
|
31
|
+
}
|
|
32
|
+
export interface R2ObjectBody {
|
|
33
|
+
key: string;
|
|
34
|
+
size: number;
|
|
35
|
+
uploaded: Date;
|
|
36
|
+
httpMetadata?: {
|
|
37
|
+
contentType?: string;
|
|
38
|
+
};
|
|
39
|
+
customMetadata?: Record<string, string>;
|
|
40
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
41
|
+
}
|
|
42
|
+
export interface R2Bucket {
|
|
43
|
+
put(key: string, value: ArrayBuffer | ArrayBufferView, options?: {
|
|
44
|
+
httpMetadata?: {
|
|
45
|
+
contentType?: string;
|
|
46
|
+
};
|
|
47
|
+
customMetadata?: Record<string, string>;
|
|
48
|
+
}): Promise<unknown>;
|
|
49
|
+
get(key: string): Promise<R2ObjectBody | null>;
|
|
50
|
+
delete(key: string | string[]): Promise<void>;
|
|
51
|
+
list(options?: {
|
|
52
|
+
prefix?: string;
|
|
53
|
+
limit?: number;
|
|
54
|
+
cursor?: string;
|
|
55
|
+
}): Promise<{
|
|
56
|
+
objects: R2ObjectBody[];
|
|
57
|
+
truncated: boolean;
|
|
58
|
+
cursor?: string;
|
|
59
|
+
}>;
|
|
60
|
+
}
|
|
61
|
+
export interface Env {
|
|
62
|
+
readonly ECHO_PDF_CONFIG_JSON?: string;
|
|
63
|
+
readonly ASSETS?: Fetcher;
|
|
64
|
+
readonly FILE_STORE_BUCKET?: R2Bucket;
|
|
65
|
+
readonly FILE_STORE_DO?: DurableObjectNamespace;
|
|
66
|
+
readonly [key: string]: string | Fetcher | DurableObjectNamespace | R2Bucket | undefined;
|
|
67
|
+
}
|
|
68
|
+
export interface WorkerExecutionContext {
|
|
69
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
70
|
+
passThroughOnException?(): void;
|
|
71
|
+
}
|
|
72
|
+
export interface StoredFileMeta {
|
|
73
|
+
readonly id: string;
|
|
74
|
+
readonly filename: string;
|
|
75
|
+
readonly mimeType: string;
|
|
76
|
+
readonly sizeBytes: number;
|
|
77
|
+
readonly createdAt: string;
|
|
78
|
+
}
|
|
79
|
+
export interface StoredFileRecord extends StoredFileMeta {
|
|
80
|
+
readonly bytes: Uint8Array;
|
|
81
|
+
}
|
|
82
|
+
export interface FileStore {
|
|
83
|
+
put(input: {
|
|
84
|
+
readonly filename: string;
|
|
85
|
+
readonly mimeType: string;
|
|
86
|
+
readonly bytes: Uint8Array;
|
|
87
|
+
}): Promise<StoredFileMeta>;
|
|
88
|
+
get(fileId: string): Promise<StoredFileRecord | null>;
|
|
89
|
+
list(): Promise<ReadonlyArray<StoredFileMeta>>;
|
|
90
|
+
delete(fileId: string): Promise<boolean>;
|
|
91
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FileStoreDO } from "./file-store-do.js";
|
|
2
|
+
import type { Env, WorkerExecutionContext } from "./types.js";
|
|
3
|
+
declare const _default: {
|
|
4
|
+
fetch(request: Request, env: Env, ctx: WorkerExecutionContext): Promise<Response>;
|
|
5
|
+
};
|
|
6
|
+
export default _default;
|
|
7
|
+
export { FileStoreDO };
|