-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add upstash box support #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
aba1e03
feat: add upstash box
ytkimirti c8efd49
feat: support readonly API keys
ytkimirti b0595f2
fix: resolve pre-existing lint errors in box tools
ytkimirti 707ff6c
feat(box): support Box API key via CLI flag and env var
ytkimirti c77b157
docs(box): document optional Box API key for install paths
ytkimirti fe5bee9
refactor(box): narrow response types to fields actually read
ytkimirti 125cad6
docs: rewrite README with per-client install guides
ytkimirti dc96909
fix(release): detect prereleases from event and strip v prefix
ytkimirti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build & Lint | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: oven-sh/setup-bun@v1 | ||
| with: | ||
| bun-version: latest | ||
|
|
||
| - run: bun install | ||
|
|
||
| - run: bun run build | ||
|
|
||
| - run: bun run lint | ||
|
|
||
| test: | ||
| name: E2E Tests | ||
| runs-on: ubuntu-latest | ||
| needs: build | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: oven-sh/setup-bun@v1 | ||
| with: | ||
| bun-version: latest | ||
|
|
||
| - run: bun install | ||
|
|
||
| - name: Run tests | ||
| env: | ||
| UPSTASH_EMAIL: ${{ secrets.UPSTASH_EMAIL }} | ||
| UPSTASH_API_KEY: ${{ secrets.UPSTASH_API_KEY }} | ||
| UPSTASH_API_KEY_READONLY: ${{ secrets.UPSTASH_API_KEY_READONLY }} | ||
| UPSTASH_BOX_API_KEY: ${{ secrets.UPSTASH_BOX_API_KEY }} | ||
| run: bun test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,5 @@ export const config = { | |
| apiKey: "", | ||
| email: "", | ||
| disableTelemetry: false, | ||
| readonly: false, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| #!/usr/bin/env bun | ||
|
|
||
| import { describe, it, expect, beforeAll, afterAll } from "bun:test"; | ||
| import { config } from "./config"; | ||
| import { testConnection } from "./test-connection"; | ||
| import { redisDbOpsTools } from "./tools/redis/db"; | ||
| import { redisCommandTools } from "./tools/redis/command"; | ||
| import { redisBackupTools } from "./tools/redis/backup"; | ||
| import { qstashTools } from "./tools/qstash/qstash"; | ||
| import { workflowTools } from "./tools/qstash/workflow"; | ||
| import { clearTokenCache } from "./tools/qstash/utils"; | ||
| import { http } from "./http"; | ||
| import type { RedisDatabase } from "./tools/redis/types"; | ||
| import type { CustomTool } from "./tool"; | ||
|
|
||
| const redisTools = { ...redisDbOpsTools, ...redisCommandTools, ...redisBackupTools } as Record< | ||
| string, | ||
| CustomTool<any> | ||
| >; | ||
| const qstashAllTools = { ...qstashTools, ...workflowTools } as Record<string, CustomTool<any>>; | ||
|
|
||
| // Save original config to restore after tests | ||
| let originalEmail: string; | ||
| let originalApiKey: string; | ||
| let originalReadonly: boolean; | ||
|
|
||
| beforeAll(async () => { | ||
| const email = process.env.UPSTASH_EMAIL; | ||
| const readonlyKey = process.env.UPSTASH_API_KEY_READONLY; | ||
|
|
||
| if (!email || !readonlyKey) { | ||
| throw new Error("UPSTASH_EMAIL and UPSTASH_API_KEY_READONLY must be set in .env file"); | ||
| } | ||
|
|
||
| // Save original config | ||
| originalEmail = config.email; | ||
| originalApiKey = config.apiKey; | ||
| originalReadonly = config.readonly; | ||
|
|
||
| // Set readonly credentials | ||
| config.email = email; | ||
| config.apiKey = readonlyKey; | ||
| config.readonly = false; // Reset so testConnection can detect it | ||
| clearTokenCache(); // Clear any cached QStash tokens from other test files | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| // Restore original config | ||
| config.email = originalEmail; | ||
| config.apiKey = originalApiKey; | ||
| config.readonly = originalReadonly; | ||
| }); | ||
|
|
||
| describe("readonly detection", () => { | ||
| it("testConnection detects readonly API key", async () => { | ||
| await testConnection(); | ||
| expect(config.readonly).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe("server tool filtering", () => { | ||
| it("only registers readonly tools when config.readonly is true", () => { | ||
| const allTools = { ...redisTools, ...qstashAllTools }; | ||
| const writeToolNames = Object.entries(allTools) | ||
| .filter(([_, tool]) => !tool.readonly) | ||
| .map(([name]) => name); | ||
|
|
||
| const readonlyToolNames = Object.entries(allTools) | ||
| .filter(([_, tool]) => tool.readonly) | ||
| .map(([name]) => name); | ||
|
|
||
| // Verify we have both categories defined | ||
| expect(writeToolNames.length).toBeGreaterThan(0); | ||
| expect(readonlyToolNames.length).toBeGreaterThan(0); | ||
|
|
||
| // Verify specific write tools are correctly NOT marked readonly | ||
| expect(writeToolNames).toContain("redis_database_create_new"); | ||
| expect(writeToolNames).toContain("redis_database_delete"); | ||
| expect(writeToolNames).toContain("redis_database_reset_password"); | ||
| expect(writeToolNames).toContain("qstash_publish_message"); | ||
| expect(writeToolNames).toContain("qstash_schedules_manage"); | ||
|
|
||
| // All QStash/workflow tools should be hidden in readonly mode (not supported yet) | ||
| expect(writeToolNames).toContain("qstash_logs_list"); | ||
| expect(writeToolNames).toContain("qstash_schedules_list"); | ||
| expect(writeToolNames).toContain("workflow_logs_list"); | ||
|
|
||
| // Verify specific Redis read tools ARE marked readonly | ||
| expect(readonlyToolNames).toContain("redis_database_list_databases"); | ||
| expect(readonlyToolNames).toContain("redis_database_get_details"); | ||
| expect(readonlyToolNames).toContain("redis_database_get_statistics"); | ||
| expect(readonlyToolNames).toContain("redis_database_run_redis_commands"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("readonly redis read operations", () => { | ||
| it("can list databases", async () => { | ||
| const result = await redisTools.redis_database_list_databases.handler({}); | ||
| expect(Array.isArray(result)).toBe(true); | ||
| }); | ||
|
|
||
| it("can get database details", async () => { | ||
| const dbs = await http.get<RedisDatabase[]>("v2/redis/databases"); | ||
| if (dbs.length === 0) return; // Skip if no databases | ||
|
|
||
| const result = await redisTools.redis_database_get_details.handler({ | ||
| database_id: dbs[0].database_id, | ||
| }); | ||
|
|
||
| expect(typeof result).toBe("string"); | ||
| expect(result).toContain(dbs[0].database_name); | ||
| }); | ||
|
|
||
| it("runs read-only redis commands using read_only_rest_token", async () => { | ||
| const dbs = await http.get<RedisDatabase[]>("v2/redis/databases"); | ||
| if (dbs.length === 0) return; // Skip if no databases | ||
|
|
||
| const result = await redisTools.redis_database_run_redis_commands.handler({ | ||
| database_id: dbs[0].database_id, | ||
| commands: [["DBSIZE"]], | ||
| }); | ||
|
|
||
| const text = Array.isArray(result) ? result.join("") : String(result); | ||
| expect(text).toContain("result"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("readonly redis write operations blocked", () => { | ||
| it("rejects create database", async () => { | ||
| expect( | ||
| redisTools.redis_database_create_new.handler({ | ||
| name: "readonly-test-should-fail", | ||
| primary_region: "us-east-1", | ||
| }) | ||
| ).rejects.toThrow(/readonly api key/i); | ||
| }); | ||
|
|
||
| it("rejects delete database", async () => { | ||
| expect( | ||
| redisTools.redis_database_delete.handler({ | ||
| database_id: "fake-id-should-not-matter", | ||
| }) | ||
| ).rejects.toThrow(/readonly api key/i); | ||
| }); | ||
|
|
||
| it("rejects reset password", async () => { | ||
| expect( | ||
| redisTools.redis_database_reset_password.handler({ | ||
| id: "fake-id-should-not-matter", | ||
| }) | ||
| ).rejects.toThrow(/readonly api key/i); | ||
| }); | ||
| }); | ||
|
|
||
| describe("readonly qstash operations", () => { | ||
| it("qstash tools are not available in readonly mode", async () => { | ||
| expect( | ||
| qstashAllTools.qstash_schedules_list.handler({}) | ||
| ).rejects.toThrow("QStash is not available in readonly mode yet"); | ||
| }); | ||
|
|
||
| it("workflow tools are not available in readonly mode", async () => { | ||
| expect( | ||
| qstashAllTools.workflow_logs_list.handler({ count: 3 }) | ||
| ).rejects.toThrow("QStash is not available in readonly mode yet"); | ||
| }); | ||
|
|
||
| it("qstash tools are hidden from server in readonly mode", () => { | ||
| const allQstashTools = Object.keys(qstashAllTools); | ||
| for (const name of allQstashTools) { | ||
| expect(qstashAllTools[name].readonly).toBeFalsy(); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { z } from "zod"; | ||
| import { tool } from "../helpers"; | ||
| import { boxCommon } from "./common"; | ||
| import { getBoxClient } from "./utils"; | ||
| import type { RunResponse } from "./types"; | ||
|
|
||
| export const boxAgentRunTool = { | ||
| box_agent_run: tool({ | ||
| description: `Run an AI agent prompt inside an Upstash Box. The agent has access to shell, filesystem, and git inside the box. It reasons, executes commands, and iterates until the task is complete. This is a synchronous call that may take a while depending on the complexity of the prompt.`, | ||
| inputSchema: z.object({ | ||
| box_id: z.string().describe("The box ID to run the agent in"), | ||
| prompt: z.string().describe("The natural-language prompt for the agent to execute"), | ||
| model: z | ||
| .string() | ||
| .optional() | ||
| .describe("Override the box's default LLM model for this run"), | ||
| folder: z | ||
| .string() | ||
| .optional() | ||
| .describe("Working directory inside the box for the agent"), | ||
| ...boxCommon, | ||
| }), | ||
| handler: async (params) => { | ||
| const { box_id, prompt, model, folder } = params; | ||
| const client = getBoxClient(params); | ||
|
|
||
| const body: Record<string, unknown> = { prompt }; | ||
| if (model) body.model = model; | ||
| if (folder) body.folder = folder; | ||
|
|
||
| const response = await client.post<RunResponse>(`v2/box/${box_id}/run`, body); | ||
|
|
||
| const result: string[] = [ | ||
| `Agent run completed`, | ||
| ]; | ||
|
|
||
| if (response.run_id) { | ||
| result.push(`Run ID: ${response.run_id}`); | ||
| } | ||
|
|
||
| result.push(response.output || "(no output)"); | ||
|
|
||
| if (response.metadata) { | ||
| result.push( | ||
| `Tokens: ${response.metadata.input_tokens ?? 0} in / ${response.metadata.output_tokens ?? 0} out` + | ||
| (response.metadata.cost_usd ? ` ($${response.metadata.cost_usd.toFixed(4)})` : "") | ||
| ); | ||
| } | ||
|
|
||
| return result; | ||
| }, | ||
| }), | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.