@bogyie/opencode-kiro-plugin 0.3.14 → 0.3.16
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/README.md +1 -1
- package/dist/fetch-adapter.d.ts +5 -0
- package/dist/fetch-adapter.js +28 -0
- package/dist/plugin.js +32 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -155,7 +155,7 @@ This keeps new Kiro model ids usable before the package is updated without adver
|
|
|
155
155
|
|
|
156
156
|
The plugin injects `provider.kiro` with the `auto` placeholder needed for OpenCode's provider connector. Define `provider.kiro.models` yourself only when you need explicit model-picker metadata such as a display name or context limit. Use plugin `modelAliases` for aliases that should resolve one requested model id to another.
|
|
157
157
|
|
|
158
|
-
`modelDiscoveryCommand` defaults to `["kiro-cli", "chat", "--list-models", "--format", "json"]`. Set `modelDiscovery` to `"off"` to disable startup discovery and `kiro_refresh_models`; in that mode the plugin uses any stored cache and then the `auto` fallback. Discovery is best-effort and does not start login during OpenCode startup. Authenticate manually through the connector or let
|
|
158
|
+
`modelDiscoveryCommand` defaults to `["kiro-cli", "chat", "--list-models", "--format", "json"]`. Set `modelDiscovery` to `"off"` to disable startup discovery and `kiro_refresh_models`; in that mode the plugin uses any stored cache and then the `auto` fallback. Discovery is best-effort and does not start login during OpenCode startup. `/v1/models` also uses only this discovery/cache path: it never invokes the chat transport or login fallback, and returns the cached list or `auto` if discovery fails. OpenCode title-generation requests also suppress login fallback so startup helper traffic cannot open a Kiro login window. Authenticate manually through the connector or let a real chat completion request handle auth failure. A successful connector login also triggers a forced model refresh. Discovery stdout can be a JSON array, `{ "models": [...] }`, `{ "data": [...] }`, Kiro CLI list-models JSON, Kiro CLI plain list output, or one model id per line.
|
|
159
159
|
|
|
160
160
|
## Troubleshooting
|
|
161
161
|
|
package/dist/fetch-adapter.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ export interface KiroTransport {
|
|
|
8
8
|
export interface KiroFetchOptions {
|
|
9
9
|
readonly resolver: ModelResolver;
|
|
10
10
|
readonly transport?: KiroTransport;
|
|
11
|
+
readonly models?: () => Promise<ReadonlyArray<string | OpenAIModelListItem>>;
|
|
11
12
|
}
|
|
12
13
|
export type FetchAdapter = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
14
|
+
export interface OpenAIModelListItem {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly [key: string]: unknown;
|
|
17
|
+
}
|
|
13
18
|
export declare function createKiroFetch(options: KiroFetchOptions): FetchAdapter;
|
package/dist/fetch-adapter.js
CHANGED
|
@@ -20,10 +20,38 @@ async function* responseToStream(response, fallbackModelId) {
|
|
|
20
20
|
for (const toolCall of response.toolCalls ?? [])
|
|
21
21
|
yield toolCall;
|
|
22
22
|
}
|
|
23
|
+
function requestPath(input) {
|
|
24
|
+
const raw = input instanceof Request ? input.url : input.toString();
|
|
25
|
+
const pathname = new URL(raw, "http://127.0.0.1").pathname.replace(/\/+$/, "");
|
|
26
|
+
return pathname || "/";
|
|
27
|
+
}
|
|
28
|
+
function isModelsPath(pathname) {
|
|
29
|
+
return pathname === "/v1/models" || pathname === "/models";
|
|
30
|
+
}
|
|
31
|
+
function toOpenAIModel(item) {
|
|
32
|
+
const id = typeof item === "string" ? item : item.id;
|
|
33
|
+
const extra = typeof item === "string" ? { id } : item;
|
|
34
|
+
return {
|
|
35
|
+
...extra,
|
|
36
|
+
id,
|
|
37
|
+
object: "model",
|
|
38
|
+
created: typeof extra.created === "number" ? extra.created : 0,
|
|
39
|
+
owned_by: typeof extra.owned_by === "string" ? extra.owned_by : "kiro",
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async function toOpenAIModelsResponse(models) {
|
|
43
|
+
const data = models ? (await models()).filter((item) => (typeof item === "string" ? item.trim() : item.id.trim())).map(toOpenAIModel) : [];
|
|
44
|
+
return Response.json({
|
|
45
|
+
object: "list",
|
|
46
|
+
data,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
23
49
|
export function createKiroFetch(options) {
|
|
24
50
|
const transport = options.transport ?? unsupportedTransport;
|
|
25
51
|
return async (input, init) => {
|
|
26
52
|
try {
|
|
53
|
+
if (isModelsPath(requestPath(input)))
|
|
54
|
+
return toOpenAIModelsResponse(options.models);
|
|
27
55
|
const request = await readOpenAIRequest(input, init);
|
|
28
56
|
const kiroRequest = toKiroGenerateRequest(request, options.resolver);
|
|
29
57
|
if (request.stream === true && transport.stream) {
|
package/dist/plugin.js
CHANGED
|
@@ -12,6 +12,8 @@ import { ModelResolver, normalizeModelName } from "./model-resolver.js";
|
|
|
12
12
|
import { KiroRestTransport } from "./kiro-rest-transport.js";
|
|
13
13
|
const PLACEHOLDER_MODEL_ID = "auto";
|
|
14
14
|
const PLACEHOLDER_MODEL = { name: "Auto" };
|
|
15
|
+
const OPENCODE_AGENT_HEADER = "x-opencode-kiro-agent";
|
|
16
|
+
const LOGIN_SUPPRESSED_AGENTS = new Set(["title"]);
|
|
15
17
|
function discoveredProviderModels(cache) {
|
|
16
18
|
return Object.fromEntries(cache.all().map((model) => [
|
|
17
19
|
model.id,
|
|
@@ -72,15 +74,29 @@ export function effectiveBackend(options, accessToken) {
|
|
|
72
74
|
return "fetch";
|
|
73
75
|
return "fetch";
|
|
74
76
|
}
|
|
75
|
-
function
|
|
77
|
+
function shouldLoginOnAuthFailure(init) {
|
|
78
|
+
const agent = new Headers(init?.headers).get(OPENCODE_AGENT_HEADER);
|
|
79
|
+
return !agent || !LOGIN_SUPPRESSED_AGENTS.has(agent);
|
|
80
|
+
}
|
|
81
|
+
function localTransport(options, accessToken, behavior = {}) {
|
|
76
82
|
const backend = effectiveBackend(options, accessToken);
|
|
83
|
+
const login = () => {
|
|
84
|
+
if (behavior.loginOnAuthFailure === false)
|
|
85
|
+
return Promise.resolve(false);
|
|
86
|
+
return runKiroLoginFlowOnce({
|
|
87
|
+
login: {
|
|
88
|
+
...options.login,
|
|
89
|
+
useDeviceFlow: true,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
};
|
|
77
93
|
if (backend === "acp")
|
|
78
94
|
return new KiroAcpTransport(acpTransportOptions(options));
|
|
79
95
|
if (backend === "cli-chat") {
|
|
80
96
|
return new KiroCliChatTransport({
|
|
81
97
|
trustAllTools: options.trustAllTools,
|
|
82
98
|
...(options.requestTimeoutMs ? { requestTimeoutMs: options.requestTimeoutMs } : {}),
|
|
83
|
-
login
|
|
99
|
+
login,
|
|
84
100
|
});
|
|
85
101
|
}
|
|
86
102
|
if (backend === "fetch") {
|
|
@@ -88,11 +104,11 @@ function localTransport(options, accessToken) {
|
|
|
88
104
|
if (isKiroDeviceAuthKey(apiKey)) {
|
|
89
105
|
return new KiroRestTransport(fetchTransportOptions(options), {
|
|
90
106
|
credentialProvider: async () => (await credentialFromKiroDeviceAuthKey(apiKey).catch(() => undefined)) ?? readKiroCliSessionCredential(),
|
|
91
|
-
login
|
|
107
|
+
login,
|
|
92
108
|
});
|
|
93
109
|
}
|
|
94
110
|
return new KiroRestTransport(fetchTransportOptions(options, apiKey === "kiro-plugin-local-transport" ? undefined : apiKey), {
|
|
95
|
-
login
|
|
111
|
+
login,
|
|
96
112
|
});
|
|
97
113
|
}
|
|
98
114
|
return undefined;
|
|
@@ -165,9 +181,15 @@ export function createKiroPlugin() {
|
|
|
165
181
|
if (localServer)
|
|
166
182
|
return localServer;
|
|
167
183
|
const localFetch = async (input, init) => {
|
|
168
|
-
const transport = localTransport(options, bearerToken(init)
|
|
184
|
+
const transport = localTransport(options, bearerToken(init), {
|
|
185
|
+
loginOnAuthFailure: shouldLoginOnAuthFailure(init),
|
|
186
|
+
});
|
|
169
187
|
return createKiroFetch({
|
|
170
188
|
resolver,
|
|
189
|
+
models: async () => {
|
|
190
|
+
await refreshModels(true).catch(() => []);
|
|
191
|
+
return Object.keys(visibleProviderModels(modelCache, configuredModels, options.hiddenModels, disabledModels));
|
|
192
|
+
},
|
|
171
193
|
...(transport ? { transport } : {}),
|
|
172
194
|
})(input, init);
|
|
173
195
|
};
|
|
@@ -333,6 +355,11 @@ export function createKiroPlugin() {
|
|
|
333
355
|
}));
|
|
334
356
|
},
|
|
335
357
|
},
|
|
358
|
+
"chat.headers": async (input, output) => {
|
|
359
|
+
if (input.model.providerID !== options.providerID)
|
|
360
|
+
return;
|
|
361
|
+
output.headers[OPENCODE_AGENT_HEADER] = input.agent;
|
|
362
|
+
},
|
|
336
363
|
};
|
|
337
364
|
};
|
|
338
365
|
}
|