Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.29.0",
"@rendobar/sdk": "^1.0.0",
"@rendobar/sdk": "^3.0.0",
"zod": "^3.25.0"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/tools/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,22 @@ const uploadFileTool = defineTool({
// bodies and the SDK request layer doesn't set it. Buffering avoids that
// entirely — Blob is a fully-buffered BodyInit and works everywhere.
//
// Memory bound: maxInputFileSize (free=100MB, pro=2GB) — same ceiling the
// Memory bound: maxInputFileSize (free=500MB, pro=10GB) — same ceiling the
// pre-stream gate enforces. v2 candidate: patch SDK to set duplex, then
// restore streaming + ProgressTransform for files >5MB.
const buffer = await fh.readFile();
const blob = new Blob([buffer]);

const result = await getSdk(ctx).uploads.upload(blob, {
// SDK 3.0.0: uploads.create() presigns + uploads + finalizes in one call
// and returns the ready asset; reference it by its stable content URL.
const asset = await getSdk(ctx).uploads.create(blob, {
filename: args.filename ?? path.basename(resolved),
signal: extra.signal,
});

ctx.logger.info({ msg: "upload_complete", basename: path.basename(resolved), sizeBytes });

return { downloadUrl: result.downloadUrl, sizeBytes };
return { downloadUrl: asset.url, sizeBytes };
} finally {
await fh.close();
}
Expand Down
22 changes: 11 additions & 11 deletions test/unit/tools/uploads.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ describe("upload_file", () => {
});

it("uploads a small file and returns downloadUrl + sizeBytes", async () => {
const upload = vi.fn(async () => ({ downloadUrl: "https://api.rendobar.com/uploads/dl/abc" }));
const create = vi.fn(async () => ({ url: "https://api.rendobar.com/uploads/dl/abc" }));
const sdk = {
uploads: { upload },
uploads: { create },
billing: { state: vi.fn(async () => billingState(999_999_999)) },
};
const c = ctx({ sdk: sdk as never });
Expand All @@ -75,13 +75,13 @@ describe("upload_file", () => {
downloadUrl: "https://api.rendobar.com/uploads/dl/abc",
sizeBytes: 11, // "hello world"
});
expect(upload).toHaveBeenCalledOnce();
expect(create).toHaveBeenCalledOnce();
});

it("respects custom filename", async () => {
const upload = vi.fn(async () => ({ downloadUrl: "https://x" }));
const create = vi.fn(async () => ({ url: "https://x" }));
const sdk = {
uploads: { upload },
uploads: { create },
billing: { state: vi.fn(async () => billingState(999_999_999)) },
};
const c = ctx({ sdk: sdk as never });
Expand All @@ -91,32 +91,32 @@ describe("upload_file", () => {
c,
{ signal: new AbortController().signal } as never,
);
expect(upload).toHaveBeenCalledWith(
expect(create).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ filename: "renamed.txt" }),
);
});

it("rejects oversize files using cached limit", async () => {
const upload = vi.fn();
const create = vi.fn();
const sdk = {
uploads: { upload },
uploads: { create },
billing: { state: vi.fn() }, // should NOT be called — cache is set
};
const c = ctx({ sdk: sdk as never, cachedMaxFileSize: 5 });
const tool = uploadTools().find((t) => t.name === "upload_file");
await expect(
tool!.execute({ path: small }, c, { signal: new AbortController().signal } as never),
).rejects.toThrow(/exceeds.*limit/i);
expect(upload).not.toHaveBeenCalled();
expect(create).not.toHaveBeenCalled();
expect(sdk.billing.state).not.toHaveBeenCalled();
});

it("populates limit cache via billing.state when cold", async () => {
const upload = vi.fn(async () => ({ downloadUrl: "https://x" }));
const create = vi.fn(async () => ({ url: "https://x" }));
const billingStateFn = vi.fn(async () => billingState(100));
const sdk = {
uploads: { upload },
uploads: { create },
billing: { state: billingStateFn },
};
const c = ctx({ sdk: sdk as never });
Expand Down
Loading