@bogyie/opencode-kiro-plugin 0.3.14 → 0.3.15
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 +13 -3
- 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. 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
|
@@ -74,13 +74,19 @@ export function effectiveBackend(options, accessToken) {
|
|
|
74
74
|
}
|
|
75
75
|
function localTransport(options, accessToken) {
|
|
76
76
|
const backend = effectiveBackend(options, accessToken);
|
|
77
|
+
const login = () => runKiroLoginFlowOnce({
|
|
78
|
+
login: {
|
|
79
|
+
...options.login,
|
|
80
|
+
useDeviceFlow: true,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
77
83
|
if (backend === "acp")
|
|
78
84
|
return new KiroAcpTransport(acpTransportOptions(options));
|
|
79
85
|
if (backend === "cli-chat") {
|
|
80
86
|
return new KiroCliChatTransport({
|
|
81
87
|
trustAllTools: options.trustAllTools,
|
|
82
88
|
...(options.requestTimeoutMs ? { requestTimeoutMs: options.requestTimeoutMs } : {}),
|
|
83
|
-
login
|
|
89
|
+
login,
|
|
84
90
|
});
|
|
85
91
|
}
|
|
86
92
|
if (backend === "fetch") {
|
|
@@ -88,11 +94,11 @@ function localTransport(options, accessToken) {
|
|
|
88
94
|
if (isKiroDeviceAuthKey(apiKey)) {
|
|
89
95
|
return new KiroRestTransport(fetchTransportOptions(options), {
|
|
90
96
|
credentialProvider: async () => (await credentialFromKiroDeviceAuthKey(apiKey).catch(() => undefined)) ?? readKiroCliSessionCredential(),
|
|
91
|
-
login
|
|
97
|
+
login,
|
|
92
98
|
});
|
|
93
99
|
}
|
|
94
100
|
return new KiroRestTransport(fetchTransportOptions(options, apiKey === "kiro-plugin-local-transport" ? undefined : apiKey), {
|
|
95
|
-
login
|
|
101
|
+
login,
|
|
96
102
|
});
|
|
97
103
|
}
|
|
98
104
|
return undefined;
|
|
@@ -168,6 +174,10 @@ export function createKiroPlugin() {
|
|
|
168
174
|
const transport = localTransport(options, bearerToken(init));
|
|
169
175
|
return createKiroFetch({
|
|
170
176
|
resolver,
|
|
177
|
+
models: async () => {
|
|
178
|
+
await refreshModels(true).catch(() => []);
|
|
179
|
+
return Object.keys(visibleProviderModels(modelCache, configuredModels, options.hiddenModels, disabledModels));
|
|
180
|
+
},
|
|
171
181
|
...(transport ? { transport } : {}),
|
|
172
182
|
})(input, init);
|
|
173
183
|
};
|