Przeglądaj źródła

config: add setCacheKey in provider options (#4654)

Co-authored-by: GitHub Action <[email protected]>
Shantur Rathore 3 miesięcy temu
rodzic
commit
9b6d03c497

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

@@ -529,6 +529,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> | undefined {
     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
     }
 

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

@@ -475,13 +475,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,
         },
         {
@@ -491,7 +492,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,7 +1415,15 @@ export namespace SessionPrompt {
       (await Provider.getSmallModel(input.providerID)) ?? (await Provider.getModel(input.providerID, input.modelID))
     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),
     )