Просмотр исходного кода

config: add setCacheKey in provider options (#4738)

Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: Aiden Cline <[email protected]>
Shantur Rathore 2 месяцев назад
Родитель
Сommit
69c2dd53ad

+ 4 - 0
packages/opencode/src/config/config.ts

@@ -540,6 +540,10 @@ export namespace Config {
                   apiKey: z.string().optional(),
                   baseURL: z.string().optional(),
                   enterpriseUrl: z.string().optional().describe("GitHub Enterprise URL for copilot authentication"),
+                  setCacheKey: z
+                    .boolean()
+                    .optional()
+                    .describe("Enable promptCacheKey for this provider (default false)"),
                   timeout: z
                     .union([
                       z

+ 8 - 2
packages/opencode/src/provider/transform.ts

@@ -128,7 +128,13 @@ export namespace ProviderTransform {
     return undefined
   }
 
-  export function options(providerID: string, modelID: string, npm: string, sessionID: string): Record<string, any> {
+  export function options(
+    providerID: string,
+    modelID: string,
+    npm: string,
+    sessionID: string,
+    providerOptions?: Record<string, any>,
+  ): Record<string, any> {
     const result: Record<string, any> = {}
 
     // switch to providerID later, for now use this
@@ -138,7 +144,7 @@ export namespace ProviderTransform {
       }
     }
 
-    if (providerID === "openai") {
+    if (providerID === "openai" || providerOptions?.setCacheKey) {
       result["promptCacheKey"] = sessionID
     }
 

+ 15 - 3
packages/opencode/src/session/prompt.ts

@@ -477,13 +477,14 @@ export namespace SessionPrompt {
         tools: lastUser.tools,
         processor,
       })
+      const provider = await Provider.getProvider(model.providerID)
       const params = await Plugin.trigger(
         "chat.params",
         {
           sessionID: sessionID,
           agent: lastUser.agent,
           model: model.info,
-          provider: await Provider.getProvider(model.providerID),
+          provider,
           message: lastUser,
         },
         {
@@ -493,7 +494,9 @@ export namespace SessionPrompt {
           topP: agent.topP ?? ProviderTransform.topP(model.providerID, model.modelID),
           options: pipe(
             {},
-            mergeDeep(ProviderTransform.options(model.providerID, model.modelID, model.npm ?? "", sessionID)),
+            mergeDeep(
+              ProviderTransform.options(model.providerID, model.modelID, model.npm ?? "", sessionID, provider?.options),
+            ),
             mergeDeep(model.info.options),
             mergeDeep(agent.options),
           ),
@@ -1412,9 +1415,18 @@ export namespace SessionPrompt {
     if (!isFirst) return
     const small =
       (await Provider.getSmallModel(input.providerID)) ?? (await Provider.getModel(input.providerID, input.modelID))
+    const provider = await Provider.getProvider(small.providerID)
     const options = pipe(
       {},
-      mergeDeep(ProviderTransform.options(small.providerID, small.modelID, small.npm ?? "", input.session.id)),
+      mergeDeep(
+        ProviderTransform.options(
+          small.providerID,
+          small.modelID,
+          small.npm ?? "",
+          input.session.id,
+          provider?.options,
+        ),
+      ),
       mergeDeep(ProviderTransform.smallOptions({ providerID: small.providerID, modelID: small.modelID })),
       mergeDeep(small.info.options),
     )

+ 5 - 1
packages/sdk/js/src/gen/types.gen.ts

@@ -1123,11 +1123,15 @@ export type Config = {
          * GitHub Enterprise URL for copilot authentication
          */
         enterpriseUrl?: string
+        /**
+         * Enable promptCacheKey for this provider (default false)
+         */
+        setCacheKey?: boolean
         /**
          * Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.
          */
         timeout?: number | false
-        [key: string]: unknown | string | (number | false) | undefined
+        [key: string]: unknown | string | boolean | (number | false) | undefined
       }
     }
   }