opencode-provider-litellm 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/plugin.test.ts +1 -0
- package/src/plugin.ts +17 -6
- package/src/utils.test.ts +4 -0
package/package.json
CHANGED
package/src/plugin.test.ts
CHANGED
package/src/plugin.ts
CHANGED
|
@@ -24,9 +24,21 @@ export const LiteLLMPlugin: Plugin = async (
|
|
|
24
24
|
|
|
25
25
|
const providerId = getProviderId()
|
|
26
26
|
|
|
27
|
+
const isGcloudAuth = !!(process.env.LITELLM_GCLOUD_TOKEN_AUTH &&
|
|
28
|
+
process.env.LITELLM_GCLOUD_TOKEN_AUTH !== '' &&
|
|
29
|
+
process.env.LITELLM_GCLOUD_TOKEN_AUTH !== '0')
|
|
30
|
+
|
|
31
|
+
// When gcloud token auth is enabled, fetch a live token instead of using the static apiKey
|
|
32
|
+
const getToken = async (): Promise<string> => {
|
|
33
|
+
if (isGcloudAuth) {
|
|
34
|
+
return (await getGcloudToken()) ?? ''
|
|
35
|
+
}
|
|
36
|
+
return pluginConfig.apiKey
|
|
37
|
+
}
|
|
38
|
+
|
|
27
39
|
let mcpTools: Record<string, any> = {}
|
|
28
40
|
try {
|
|
29
|
-
mcpTools = await createMcpToolDefinitions(pluginConfig,
|
|
41
|
+
mcpTools = await createMcpToolDefinitions(pluginConfig, await getToken())
|
|
30
42
|
} catch (e) {
|
|
31
43
|
console.warn(`[opencode-provider-litellm] MCP tool discovery failed: ${e}`)
|
|
32
44
|
}
|
|
@@ -36,7 +48,7 @@ export const LiteLLMPlugin: Plugin = async (
|
|
|
36
48
|
try {
|
|
37
49
|
const models = await discoverModels(
|
|
38
50
|
pluginConfig,
|
|
39
|
-
|
|
51
|
+
getToken,
|
|
40
52
|
)
|
|
41
53
|
|
|
42
54
|
if (Object.keys(models).length === 0) {
|
|
@@ -48,11 +60,12 @@ export const LiteLLMPlugin: Plugin = async (
|
|
|
48
60
|
},
|
|
49
61
|
})
|
|
50
62
|
} else {
|
|
63
|
+
const token = await getToken()
|
|
51
64
|
injectModelsIntoConfig(
|
|
52
65
|
config as Parameters<typeof injectModelsIntoConfig>[0],
|
|
53
66
|
providerId,
|
|
54
67
|
pluginConfig.url,
|
|
55
|
-
|
|
68
|
+
token,
|
|
56
69
|
models,
|
|
57
70
|
)
|
|
58
71
|
await input.client.app.log({
|
|
@@ -104,9 +117,7 @@ export const LiteLLMPlugin: Plugin = async (
|
|
|
104
117
|
},
|
|
105
118
|
}
|
|
106
119
|
|
|
107
|
-
if (
|
|
108
|
-
process.env.LITELLM_GCLOUD_TOKEN_AUTH !== '' &&
|
|
109
|
-
process.env.LITELLM_GCLOUD_TOKEN_AUTH !== '0') {
|
|
120
|
+
if (isGcloudAuth) {
|
|
110
121
|
result['chat.headers'] = async (_input: Record<string, unknown>, output: { headers: Record<string, string> }) => {
|
|
111
122
|
const token = await getGcloudToken()
|
|
112
123
|
if (token) {
|
package/src/utils.test.ts
CHANGED
|
@@ -55,6 +55,10 @@ describe('resolvePluginConfig', () => {
|
|
|
55
55
|
})
|
|
56
56
|
|
|
57
57
|
describe('environment variable priority', () => {
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
delete process.env.LITELLM_GCLOUD_TOKEN_AUTH
|
|
60
|
+
})
|
|
61
|
+
|
|
58
62
|
it('returns config from env vars when both are set', () => {
|
|
59
63
|
process.env.LITELLM_URL = 'https://env.example.com'
|
|
60
64
|
process.env.LITELLM_KEY = 'env-key-123'
|