-
-
Notifications
You must be signed in to change notification settings - Fork 106
Add Requesty as a provider option #7
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { createOpenRouter } from "@openrouter/ai-sdk-provider"; | ||
| import { createRequesty } from "@requesty/ai-sdk"; | ||
| import { generateObject } from "ai"; | ||
| import { z } from "zod"; | ||
| import { generateId } from "../utils"; | ||
|
|
@@ -104,22 +105,50 @@ export interface AttackerConfig { | |
| pruningThreshold?: number; | ||
| apiKey?: string; | ||
| model?: string; | ||
| /** | ||
| * Provider to use. Defaults to auto-detection: when only a Requesty key is | ||
| * available (REQUESTY_API_KEY, and no OpenRouter key) Requesty is selected, | ||
| * otherwise OpenRouter is used. Set explicitly to force a provider. | ||
| */ | ||
| provider?: "openrouter" | "requesty"; | ||
| } | ||
|
|
||
| export class Attacker { | ||
| private attackTree: AttackNode | null = null; | ||
| private currentBranch: AttackNode[] = []; | ||
| private exploredNodes: Map<string, AttackNode> = new Map(); | ||
| private consecutiveFailures: number = 0; | ||
| private openrouter: ReturnType<typeof createOpenRouter>; | ||
| private provider: | ||
| | ReturnType<typeof createOpenRouter> | ||
| | ReturnType<typeof createRequesty>; | ||
| private model: string; | ||
| private config: Required<Omit<AttackerConfig, "apiKey" | "model">>; | ||
| private config: Required< | ||
| Omit<AttackerConfig, "apiKey" | "model" | "provider"> | ||
| >; | ||
|
|
||
| constructor(config?: AttackerConfig) { | ||
| this.openrouter = createOpenRouter({ | ||
| apiKey: config?.apiKey || process.env.OPENROUTER_API_KEY, | ||
| }); | ||
| this.model = config?.model || "anthropic/claude-sonnet-4.5"; | ||
| const requestyKey = process.env.REQUESTY_API_KEY; | ||
| const openrouterKey = process.env.OPENROUTER_API_KEY; | ||
| // Select provider: honor an explicit config.provider, otherwise auto-detect. | ||
| // Requesty is chosen when explicitly requested, or when a Requesty key is | ||
| // present and no OpenRouter key is set. Otherwise keep the OpenRouter path. | ||
| const useRequesty = | ||
| config?.provider === "requesty" || | ||
| (config?.provider !== "openrouter" && | ||
| Boolean(requestyKey) && | ||
| !openrouterKey); | ||
|
|
||
| if (useRequesty) { | ||
| this.provider = createRequesty({ | ||
| apiKey: config?.apiKey || requestyKey, | ||
| }); | ||
| this.model = config?.model || "anthropic/claude-sonnet-4-5"; | ||
| } else { | ||
| this.provider = createOpenRouter({ | ||
| apiKey: config?.apiKey || openrouterKey, | ||
| }); | ||
| this.model = config?.model || "anthropic/claude-sonnet-4.5"; | ||
| } | ||
|
Comment on lines
+141
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Requesty branch sets |
||
| this.config = { | ||
| maxBranchingFactor: config?.maxBranchingFactor ?? 3, | ||
| maxTreeDepth: config?.maxTreeDepth ?? 5, | ||
|
|
@@ -235,7 +264,7 @@ IMPORTANT: Generate attacks that would look like legitimate user messages.`; | |
|
|
||
| try { | ||
| const result = await generateObject({ | ||
| model: this.openrouter(this.model), | ||
| model: this.provider(this.model), | ||
| schema: AttackGenerationSchema, | ||
| system: ATTACKER_PERSONA, | ||
| prompt, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,7 +26,7 @@ program | |||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| .option( | ||||||||||||||||||||||||||||||||||||||
| "--api-key <key>", | ||||||||||||||||||||||||||||||||||||||
| "OpenRouter API key (or set OPENROUTER_API_KEY env var)", | ||||||||||||||||||||||||||||||||||||||
| "OpenRouter API key (or set OPENROUTER_API_KEY env var). Requesty is also supported via REQUESTY_API_KEY.", | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| .option( | ||||||||||||||||||||||||||||||||||||||
| "--attacker-model <model>", | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -45,6 +45,10 @@ program | |||||||||||||||||||||||||||||||||||||
| "Scan mode: extraction, injection, or dual (default: dual)", | ||||||||||||||||||||||||||||||||||||||
| "dual", | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| .option( | ||||||||||||||||||||||||||||||||||||||
| "--provider <provider>", | ||||||||||||||||||||||||||||||||||||||
| "LLM provider: openrouter or requesty (auto-detected from available API keys by default)", | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| .option("--json", "Output results as JSON") | ||||||||||||||||||||||||||||||||||||||
| .action(async (options) => { | ||||||||||||||||||||||||||||||||||||||
| let systemPrompt: string; | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -59,15 +63,34 @@ program | |||||||||||||||||||||||||||||||||||||
| process.exit(1); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const apiKey = options.apiKey || process.env.OPENROUTER_API_KEY; | ||||||||||||||||||||||||||||||||||||||
| // Resolve the provider and API key. Requesty is supported as an | ||||||||||||||||||||||||||||||||||||||
| // OpenAI-compatible alternative to OpenRouter; either key works. | ||||||||||||||||||||||||||||||||||||||
| const requestyEnvKey = process.env.REQUESTY_API_KEY; | ||||||||||||||||||||||||||||||||||||||
| const openrouterEnvKey = process.env.OPENROUTER_API_KEY; | ||||||||||||||||||||||||||||||||||||||
| const provider: "openrouter" | "requesty" = | ||||||||||||||||||||||||||||||||||||||
| options.provider === "requesty" || options.provider === "openrouter" | ||||||||||||||||||||||||||||||||||||||
| ? options.provider | ||||||||||||||||||||||||||||||||||||||
| : requestyEnvKey && !openrouterEnvKey | ||||||||||||||||||||||||||||||||||||||
| ? "requesty" | ||||||||||||||||||||||||||||||||||||||
| : "openrouter"; | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+70
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const apiKey = | ||||||||||||||||||||||||||||||||||||||
| options.apiKey || | ||||||||||||||||||||||||||||||||||||||
| (provider === "requesty" ? requestyEnvKey : openrouterEnvKey); | ||||||||||||||||||||||||||||||||||||||
| if (!apiKey) { | ||||||||||||||||||||||||||||||||||||||
| console.error( | ||||||||||||||||||||||||||||||||||||||
| "Error: OpenRouter API key required. Set OPENROUTER_API_KEY or use --api-key", | ||||||||||||||||||||||||||||||||||||||
| "Error: API key required. Set OPENROUTER_API_KEY (or REQUESTY_API_KEY for Requesty) or use --api-key", | ||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
| process.exit(1); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| process.env.OPENROUTER_API_KEY = apiKey; | ||||||||||||||||||||||||||||||||||||||
| // Propagate the key to the env var the selected provider reads so the | ||||||||||||||||||||||||||||||||||||||
| // agents auto-detect the same provider chosen here. | ||||||||||||||||||||||||||||||||||||||
| if (provider === "requesty") { | ||||||||||||||||||||||||||||||||||||||
| process.env.REQUESTY_API_KEY = apiKey; | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| process.env.OPENROUTER_API_KEY = apiKey; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const spinner = ora("Initializing security scan...").start(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://router.requesty.ai/v1, which is the API base URL, not the web dashboard where users sign up and obtain keys.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!