From d3d1032122d5b90ed3f30a1ad1472f7d578d376f Mon Sep 17 00:00:00 2001 From: Pugazhendhi Date: Fri, 30 May 2025 16:54:33 +0530 Subject: [PATCH 1/2] Add structured task metadata to Unbound API requests --- src/api/providers/unbound.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/api/providers/unbound.ts b/src/api/providers/unbound.ts index 20ec1b54bc..0e3403ed06 100644 --- a/src/api/providers/unbound.ts +++ b/src/api/providers/unbound.ts @@ -20,6 +20,20 @@ interface UnboundUsage extends OpenAI.CompletionUsage { cache_read_input_tokens?: number } +type UnboundChatCompletionCreateParamsStreaming = OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming & { + unbound_metadata: { + originApp: string + taskId?: string + mode?: string + } +} + +type UnboundChatCompletionCreateParamsNonStreaming = OpenAI.Chat.Completions.ChatCompletionCreateParamsNonStreaming & { + unbound_metadata: { + originApp: string + } +} + export class UnboundHandler extends RouterProvider implements SingleCompletionHandler { constructor(options: ApiHandlerOptions) { super({ @@ -60,11 +74,16 @@ export class UnboundHandler extends RouterProvider implements SingleCompletionHa maxTokens = info.maxTokens ?? undefined } - const requestOptions: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming = { + const requestOptions: UnboundChatCompletionCreateParamsStreaming = { model: modelId.split("/")[1], max_tokens: maxTokens, messages: openAiMessages, stream: true, + unbound_metadata: { + originApp: "roo-code", + taskId: metadata?.taskId, + mode: metadata?.mode, + }, } if (this.supportsTemperature(modelId)) { @@ -108,9 +127,12 @@ export class UnboundHandler extends RouterProvider implements SingleCompletionHa const { id: modelId, info } = await this.fetchModel() try { - const requestOptions: OpenAI.Chat.Completions.ChatCompletionCreateParamsNonStreaming = { + const requestOptions: UnboundChatCompletionCreateParamsNonStreaming = { model: modelId.split("/")[1], messages: [{ role: "user", content: prompt }], + unbound_metadata: { + originApp: "roo-code", + }, } if (this.supportsTemperature(modelId)) { From c5c1c5d633f1a739c720048b2299e0aeb0cff74e Mon Sep 17 00:00:00 2001 From: Pugazhendhi Date: Fri, 30 May 2025 17:02:05 +0530 Subject: [PATCH 2/2] Moves origin app to a constant --- src/api/providers/unbound.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/providers/unbound.ts b/src/api/providers/unbound.ts index 0e3403ed06..2a41d5416c 100644 --- a/src/api/providers/unbound.ts +++ b/src/api/providers/unbound.ts @@ -11,6 +11,8 @@ import { addCacheBreakpoints as addGeminiCacheBreakpoints } from "../transform/c import type { SingleCompletionHandler, ApiHandlerCreateMessageMetadata } from "../index" import { RouterProvider } from "./router-provider" +const ORIGIN_APP = "roo-code" + const DEFAULT_HEADERS = { "X-Unbound-Metadata": JSON.stringify({ labels: [{ key: "app", value: "roo-code" }] }), } @@ -80,7 +82,7 @@ export class UnboundHandler extends RouterProvider implements SingleCompletionHa messages: openAiMessages, stream: true, unbound_metadata: { - originApp: "roo-code", + originApp: ORIGIN_APP, taskId: metadata?.taskId, mode: metadata?.mode, }, @@ -131,7 +133,7 @@ export class UnboundHandler extends RouterProvider implements SingleCompletionHa model: modelId.split("/")[1], messages: [{ role: "user", content: prompt }], unbound_metadata: { - originApp: "roo-code", + originApp: ORIGIN_APP, }, }