@bogyie/opencode-kiro-plugin 0.3.15 → 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 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. `/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.
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/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,14 +74,22 @@ export function effectiveBackend(options, accessToken) {
72
74
  return "fetch";
73
75
  return "fetch";
74
76
  }
75
- function localTransport(options, accessToken) {
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);
77
- const login = () => runKiroLoginFlowOnce({
78
- login: {
79
- ...options.login,
80
- useDeviceFlow: true,
81
- },
82
- });
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
+ };
83
93
  if (backend === "acp")
84
94
  return new KiroAcpTransport(acpTransportOptions(options));
85
95
  if (backend === "cli-chat") {
@@ -171,7 +181,9 @@ export function createKiroPlugin() {
171
181
  if (localServer)
172
182
  return localServer;
173
183
  const localFetch = async (input, init) => {
174
- const transport = localTransport(options, bearerToken(init));
184
+ const transport = localTransport(options, bearerToken(init), {
185
+ loginOnAuthFailure: shouldLoginOnAuthFailure(init),
186
+ });
175
187
  return createKiroFetch({
176
188
  resolver,
177
189
  models: async () => {
@@ -343,6 +355,11 @@ export function createKiroPlugin() {
343
355
  }));
344
356
  },
345
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
+ },
346
363
  };
347
364
  };
348
365
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bogyie/opencode-kiro-plugin",
3
- "version": "0.3.15",
3
+ "version": "0.3.16",
4
4
  "description": "OpenCode plugin for using Kiro as a provider adapter",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",