opencode-kilocode-auth 1.0.6 → 1.0.8

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/plugin.ts +34 -11
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opencode-kilocode-auth",
3
3
  "module": "index.ts",
4
- "version": "1.0.6",
4
+ "version": "1.0.8",
5
5
  "author": "ported from Kilo Code",
6
6
  "description": "OpenCode plugin for Kilo Code authentication with support for various models including Giga Potato",
7
7
  "files": [
package/src/plugin.ts CHANGED
@@ -103,18 +103,22 @@ export async function KilocodeAuthPlugin(input: PluginInput): Promise<Hooks> {
103
103
  }
104
104
  }
105
105
 
106
- // Set Kilo Code authorization and required headers
106
+ // EXACT headers from Kilo Code VSCode extension (DEFAULT_HEADERS + customRequestOptions)
107
+ // Authorization is set by OpenAI SDK internally
107
108
  headers.set("Authorization", `Bearer ${currentToken}`)
108
- headers.set("x-api-key", currentToken) // Kilo Code uses both
109
+
110
+ // DEFAULT_HEADERS from kilocode/src/api/providers/constants.ts
109
111
  headers.set("HTTP-Referer", "https://kilocode.ai")
110
112
  headers.set("X-Title", "Kilo Code")
111
113
  headers.set("X-KiloCode-Version", "4.151.0")
112
114
  headers.set("User-Agent", "Kilo-Code/4.151.0")
115
+
116
+ // customRequestOptions from KilocodeOpenrouterHandler
113
117
  headers.set("X-KiloCode-EditorName", "Visual Studio Code 1.96.0")
114
118
 
115
- // Add organization header if present
119
+ // Organization header (exact casing from headers.ts)
116
120
  if (currentKilocodeAuth.organizationId) {
117
- headers.set("X-KILOCODE-ORGANIZATIONID", currentKilocodeAuth.organizationId)
121
+ headers.set("X-KiloCode-OrganizationId", currentKilocodeAuth.organizationId)
118
122
  }
119
123
 
120
124
  // Rewrite URL to Kilo Code endpoint
@@ -126,8 +130,33 @@ export async function KilocodeAuthPlugin(input: PluginInput): Promise<Hooks> {
126
130
  // Map to Kilo Code OpenRouter-compatible endpoint
127
131
  // Kilo Code uses: https://api.kilo.ai/api/openrouter/chat/completions
128
132
  let url: URL
133
+ let body = init?.body
134
+
129
135
  if (parsed.pathname.includes("/chat/completions")) {
130
136
  url = new URL(getApiUrl("/api/openrouter/chat/completions", currentToken))
137
+
138
+ // Modify request body to include Kilo Code system prompt prefix
139
+ if (body && typeof body === "string") {
140
+ try {
141
+ const payload = JSON.parse(body)
142
+ if (payload.messages && Array.isArray(payload.messages)) {
143
+ // Find system message and prepend Kilo Code role
144
+ const systemIdx = payload.messages.findIndex((m: any) => m.role === "system")
145
+ const kiloCodeRole = "You are Kilo Code, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices."
146
+
147
+ if (systemIdx >= 0) {
148
+ // Prepend Kilo Code role to existing system message
149
+ payload.messages[systemIdx].content = kiloCodeRole + "\n\n" + payload.messages[systemIdx].content
150
+ } else {
151
+ // Add system message at the beginning
152
+ payload.messages.unshift({ role: "system", content: kiloCodeRole })
153
+ }
154
+ body = JSON.stringify(payload)
155
+ }
156
+ } catch {
157
+ // Keep original body if parsing fails
158
+ }
159
+ }
131
160
  } else if (parsed.pathname.includes("/models")) {
132
161
  url = new URL(getApiUrl("/api/openrouter/models", currentToken))
133
162
  } else {
@@ -137,6 +166,7 @@ export async function KilocodeAuthPlugin(input: PluginInput): Promise<Hooks> {
137
166
  return fetch(url, {
138
167
  ...init,
139
168
  headers,
169
+ body,
140
170
  })
141
171
  },
142
172
  }
@@ -216,13 +246,6 @@ export async function KilocodeAuthPlugin(input: PluginInput): Promise<Hooks> {
216
246
  ],
217
247
  },
218
248
 
219
- // Add custom headers for Kilo Code requests
220
- "chat.headers": async (input, output) => {
221
- if (input.model.providerID !== KILOCODE_PROVIDER_ID) return
222
-
223
- output.headers["X-KILOCODE-EDITORNAME"] = "opencode"
224
- output.headers["X-KILOCODE-SESSIONID"] = input.sessionID
225
- },
226
249
  }
227
250
  }
228
251