Skip to content

Commit 4d1b9d2

Browse files
authored
Allow webviews to make OpenRouter API calls (#1778)
* Allow webviews to make OpenRouter API calls * Update package-lock.json
1 parent 7be3dee commit 4d1b9d2

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/webview/ClineProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,14 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
571571
}
572572

573573
const nonce = getNonce()
574+
574575
const stylesUri = getUri(webview, this.contextProxy.extensionUri, [
575576
"webview-ui",
576577
"build",
577578
"assets",
578579
"index.css",
579580
])
581+
580582
const codiconsUri = getUri(webview, this.contextProxy.extensionUri, [
581583
"node_modules",
582584
"@vscode",
@@ -693,7 +695,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
693695
<meta charset="utf-8">
694696
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
695697
<meta name="theme-color" content="#000000">
696-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; font-src ${webview.cspSource}; style-src ${webview.cspSource} 'unsafe-inline'; img-src ${webview.cspSource} data:; script-src 'nonce-${nonce}' https://us-assets.i.posthog.com; connect-src https://us.i.posthog.com https://us-assets.i.posthog.com;">
698+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; font-src ${webview.cspSource}; style-src ${webview.cspSource} 'unsafe-inline'; img-src ${webview.cspSource} data:; script-src 'nonce-${nonce}' https://us-assets.i.posthog.com; connect-src https://openrouter.ai https://us.i.posthog.com https://us-assets.i.posthog.com;">
697699
<link rel="stylesheet" type="text/css" href="${stylesUri}">
698700
<link href="${codiconsUri}" rel="stylesheet" />
699701
<title>Roo Code</title>

webview-ui/src/components/ui/hooks/useOpenRouterModelProviders.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ const openRouterEndpointsSchema = z.object({
1414
description: z.string().optional(),
1515
architecture: z
1616
.object({
17-
modality: z.string().optional(),
18-
tokenizer: z.string().optional(),
17+
modality: z.string().nullish(),
18+
tokenizer: z.string().nullish(),
1919
})
20-
.optional(),
20+
.nullish(),
2121
endpoints: z.array(
2222
z.object({
2323
name: z.string(),
2424
context_length: z.number(),
25-
max_completion_tokens: z.number().optional(),
25+
max_completion_tokens: z.number().nullish(),
2626
pricing: z
2727
.object({
2828
prompt: z.union([z.string(), z.number()]).optional(),
@@ -58,7 +58,7 @@ async function getOpenRouterProvidersForModel(modelId: string) {
5858
const outputPrice = parseApiPrice(endpoint.pricing?.completion)
5959

6060
const modelInfo: OpenRouterModelProvider = {
61-
maxTokens: endpoint.max_completion_tokens,
61+
maxTokens: endpoint.max_completion_tokens || endpoint.context_length,
6262
contextWindow: endpoint.context_length,
6363
supportsImages: architecture?.modality?.includes("image"),
6464
supportsPromptCache: false,

0 commit comments

Comments
 (0)