@bogyie/opencode-kiro-plugin 0.2.10 → 0.2.12
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/dist/auth.d.ts +1 -0
- package/dist/auth.js +31 -0
- package/dist/cli-transport.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/kiro-rest-transport.js +21 -8
- package/dist/kiro-transport.js +20 -11
- package/dist/plugin.js +2 -2
- package/dist/request-adapter.js +13 -1
- package/package.json +1 -1
package/dist/auth.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export declare function regionFromProfileArn(profileArn: string | undefined): st
|
|
|
43
43
|
export declare function readKiroCliSessionCredential(options?: KiroCliSessionCredentialOptions, runner?: CommandRunner): Promise<KiroCliSessionCredential | undefined>;
|
|
44
44
|
export declare function extractKiroLoginUrl(output: string): string;
|
|
45
45
|
export declare function startKiroCliLogin(spawner?: ProcessSpawner): KiroLoginSession;
|
|
46
|
+
export declare function startKiroCliLoginOnce(spawner?: ProcessSpawner): KiroLoginSession;
|
|
46
47
|
export declare function redacted(value: string | undefined): string | undefined;
|
|
47
48
|
export declare function detectAuth(env?: NodeJS.ProcessEnv, runner?: CommandRunner): Promise<AuthDiagnostics>;
|
|
48
49
|
export declare function resolveApiKey(auth: () => Promise<{
|
package/dist/auth.js
CHANGED
|
@@ -8,6 +8,9 @@ const execFileAsync = promisify(execFile);
|
|
|
8
8
|
export const KIRO_LOGIN_URL = "https://view.awsapps.com/start";
|
|
9
9
|
export const DEFAULT_KIRO_CLI_DB_PATH = join(homedir(), "Library", "Application Support", "kiro-cli", "data.sqlite3");
|
|
10
10
|
export const DEFAULT_KIRO_CLI_TOKEN_KEYS = ["kirocli:odic:token", "codewhisperer:odic:token"];
|
|
11
|
+
const LOGIN_REUSE_WINDOW_MS = 2 * 60 * 1000;
|
|
12
|
+
let sharedLoginSession;
|
|
13
|
+
let sharedLoginStartedAt = 0;
|
|
11
14
|
export async function runCommand(command, args, options = {}) {
|
|
12
15
|
try {
|
|
13
16
|
const result = await execFileAsync(command, [...args], { timeout: options.timeoutMs ?? 5000 });
|
|
@@ -141,6 +144,34 @@ export function startKiroCliLogin(spawner = (command, args) => spawn(command, [.
|
|
|
141
144
|
},
|
|
142
145
|
};
|
|
143
146
|
}
|
|
147
|
+
export function startKiroCliLoginOnce(spawner = (command, args) => spawn(command, [...args], { stdio: ["ignore", "pipe", "pipe"] })) {
|
|
148
|
+
const now = Date.now();
|
|
149
|
+
if (sharedLoginSession && now - sharedLoginStartedAt < LOGIN_REUSE_WINDOW_MS)
|
|
150
|
+
return sharedLoginSession;
|
|
151
|
+
const session = startKiroCliLogin(spawner);
|
|
152
|
+
const wrapped = {
|
|
153
|
+
get url() {
|
|
154
|
+
return session.url;
|
|
155
|
+
},
|
|
156
|
+
get instructions() {
|
|
157
|
+
return session.instructions;
|
|
158
|
+
},
|
|
159
|
+
async waitForAuth(runner) {
|
|
160
|
+
try {
|
|
161
|
+
return await session.waitForAuth(runner);
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
if (sharedLoginSession === wrapped) {
|
|
165
|
+
sharedLoginSession = undefined;
|
|
166
|
+
sharedLoginStartedAt = 0;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
sharedLoginSession = wrapped;
|
|
172
|
+
sharedLoginStartedAt = now;
|
|
173
|
+
return wrapped;
|
|
174
|
+
}
|
|
144
175
|
export function redacted(value) {
|
|
145
176
|
if (!value)
|
|
146
177
|
return undefined;
|
package/dist/cli-transport.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { runCommand,
|
|
1
|
+
import { runCommand, startKiroCliLoginOnce as startSharedKiroCliLoginOnce } from "./auth.js";
|
|
2
2
|
import { KiroPluginError } from "./errors.js";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
let lastLoginStartAt = 0;
|
|
@@ -7,7 +7,7 @@ function startKiroCliLoginOnce() {
|
|
|
7
7
|
if (now - lastLoginStartAt < 30_000)
|
|
8
8
|
return;
|
|
9
9
|
lastLoginStartAt = now;
|
|
10
|
-
|
|
10
|
+
startSharedKiroCliLoginOnce();
|
|
11
11
|
}
|
|
12
12
|
export function promptForCli(request) {
|
|
13
13
|
const parts = [
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export type { AcpConnection, AcpNotificationHandler, AcpStdioClientOptions, Json
|
|
|
3
3
|
export { acpPermissionResponse, KiroAcpTransport } from "./acp-transport.js";
|
|
4
4
|
export type { AcpSessionClient, KiroAcpTransportOptions } from "./acp-transport.js";
|
|
5
5
|
export { createKiroPlugin, effectiveBackend, KiroPlugin } from "./plugin.js";
|
|
6
|
-
export { detectAuth, extractKiroLoginUrl, KIRO_LOGIN_URL, readKiroCliSessionCredential, redacted, regionFromProfileArn, resolveApiKey, startKiroCliLogin, } from "./auth.js";
|
|
6
|
+
export { detectAuth, extractKiroLoginUrl, KIRO_LOGIN_URL, readKiroCliSessionCredential, redacted, regionFromProfileArn, resolveApiKey, startKiroCliLogin, startKiroCliLoginOnce, } from "./auth.js";
|
|
7
7
|
export { cliChatArgs, KiroCliChatTransport, promptForCli } from "./cli-transport.js";
|
|
8
8
|
export { createKiroFetch } from "./fetch-adapter.js";
|
|
9
9
|
export { loadOptions } from "./config.js";
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { KiroPlugin } from "./plugin.js";
|
|
|
2
2
|
export { AcpJsonRpcClient, createAcpStdioClient, decodeJsonRpc, encodeJsonRpc } from "./acp-client.js";
|
|
3
3
|
export { acpPermissionResponse, KiroAcpTransport } from "./acp-transport.js";
|
|
4
4
|
export { createKiroPlugin, effectiveBackend, KiroPlugin } from "./plugin.js";
|
|
5
|
-
export { detectAuth, extractKiroLoginUrl, KIRO_LOGIN_URL, readKiroCliSessionCredential, redacted, regionFromProfileArn, resolveApiKey, startKiroCliLogin, } from "./auth.js";
|
|
5
|
+
export { detectAuth, extractKiroLoginUrl, KIRO_LOGIN_URL, readKiroCliSessionCredential, redacted, regionFromProfileArn, resolveApiKey, startKiroCliLogin, startKiroCliLoginOnce, } from "./auth.js";
|
|
6
6
|
export { cliChatArgs, KiroCliChatTransport, promptForCli } from "./cli-transport.js";
|
|
7
7
|
export { createKiroFetch } from "./fetch-adapter.js";
|
|
8
8
|
export { loadOptions } from "./config.js";
|
|
@@ -15,6 +15,12 @@ function conversationId(request) {
|
|
|
15
15
|
return `opencode-${hash.toString(16)}-${Date.now().toString(36)}`;
|
|
16
16
|
}
|
|
17
17
|
export function toKiroRestPayload(request, profileArn) {
|
|
18
|
+
const toolResults = request.toolResults.map((item) => ({
|
|
19
|
+
toolUseId: item.toolUseId,
|
|
20
|
+
content: [{ text: item.content }],
|
|
21
|
+
status: "success",
|
|
22
|
+
...(item.toolName ? { toolName: item.toolName } : {}),
|
|
23
|
+
}));
|
|
18
24
|
const history = [
|
|
19
25
|
...(request.system
|
|
20
26
|
? [
|
|
@@ -54,6 +60,20 @@ export function toKiroRestPayload(request, profileArn) {
|
|
|
54
60
|
origin: "AI_EDITOR",
|
|
55
61
|
},
|
|
56
62
|
}),
|
|
63
|
+
...(toolResults.length > 0
|
|
64
|
+
? [
|
|
65
|
+
{
|
|
66
|
+
userInputMessage: {
|
|
67
|
+
content: "",
|
|
68
|
+
modelId: request.modelId,
|
|
69
|
+
origin: "AI_EDITOR",
|
|
70
|
+
userInputMessageContext: {
|
|
71
|
+
toolResults,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
]
|
|
76
|
+
: []),
|
|
57
77
|
];
|
|
58
78
|
const tools = request.tools.map((item) => ({
|
|
59
79
|
toolSpecification: {
|
|
@@ -62,16 +82,9 @@ export function toKiroRestPayload(request, profileArn) {
|
|
|
62
82
|
inputSchema: { json: item.inputSchema },
|
|
63
83
|
},
|
|
64
84
|
}));
|
|
65
|
-
const
|
|
66
|
-
toolUseId: item.toolUseId,
|
|
67
|
-
content: [{ text: item.content }],
|
|
68
|
-
status: "success",
|
|
69
|
-
...(item.toolName ? { toolName: item.toolName } : {}),
|
|
70
|
-
}));
|
|
71
|
-
const userInputMessageContext = tools.length > 0 || toolResults.length > 0
|
|
85
|
+
const userInputMessageContext = tools.length > 0
|
|
72
86
|
? {
|
|
73
87
|
...(tools.length > 0 ? { tools } : {}),
|
|
74
|
-
...(toolResults.length > 0 ? { toolResults } : {}),
|
|
75
88
|
}
|
|
76
89
|
: undefined;
|
|
77
90
|
const inferenceConfig = request.modelOptions.maxTokens !== undefined || request.modelOptions.temperature !== undefined
|
package/dist/kiro-transport.js
CHANGED
|
@@ -49,6 +49,12 @@ export function createCodeWhispererClient(options) {
|
|
|
49
49
|
export function toGenerateAssistantResponseInput(request, options = {}) {
|
|
50
50
|
const content = request.prompt;
|
|
51
51
|
const modelFields = additionalModelRequestFields(request);
|
|
52
|
+
const toolResults = request.toolResults.map((item) => ({
|
|
53
|
+
toolUseId: item.toolUseId,
|
|
54
|
+
content: [{ text: item.content }],
|
|
55
|
+
status: "SUCCESS",
|
|
56
|
+
...(item.toolName ? { toolName: item.toolName } : {}),
|
|
57
|
+
}));
|
|
52
58
|
return {
|
|
53
59
|
...(options.profileArn ? { profileArn: options.profileArn } : {}),
|
|
54
60
|
agentMode: options.agentMode ?? DEFAULT_AGENT_MODE,
|
|
@@ -87,6 +93,19 @@ export function toGenerateAssistantResponseInput(request, options = {}) {
|
|
|
87
93
|
origin: "AI_EDITOR",
|
|
88
94
|
},
|
|
89
95
|
}),
|
|
96
|
+
...(toolResults.length > 0
|
|
97
|
+
? [
|
|
98
|
+
{
|
|
99
|
+
userInputMessage: {
|
|
100
|
+
content: "",
|
|
101
|
+
origin: "AI_EDITOR",
|
|
102
|
+
userInputMessageContext: {
|
|
103
|
+
toolResults,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
]
|
|
108
|
+
: []),
|
|
90
109
|
],
|
|
91
110
|
currentMessage: {
|
|
92
111
|
userInputMessage: {
|
|
@@ -110,7 +129,7 @@ export function toGenerateAssistantResponseInput(request, options = {}) {
|
|
|
110
129
|
})),
|
|
111
130
|
}
|
|
112
131
|
: {}),
|
|
113
|
-
userInputMessageContext: request.tools.length > 0
|
|
132
|
+
userInputMessageContext: request.tools.length > 0
|
|
114
133
|
? {
|
|
115
134
|
...(request.tools.length > 0
|
|
116
135
|
? {
|
|
@@ -123,16 +142,6 @@ export function toGenerateAssistantResponseInput(request, options = {}) {
|
|
|
123
142
|
})),
|
|
124
143
|
}
|
|
125
144
|
: {}),
|
|
126
|
-
...(request.toolResults.length > 0
|
|
127
|
-
? {
|
|
128
|
-
toolResults: request.toolResults.map((item) => ({
|
|
129
|
-
toolUseId: item.toolUseId,
|
|
130
|
-
content: [{ text: item.content }],
|
|
131
|
-
status: "SUCCESS",
|
|
132
|
-
...(item.toolName ? { toolName: item.toolName } : {}),
|
|
133
|
-
})),
|
|
134
|
-
}
|
|
135
|
-
: {}),
|
|
136
145
|
}
|
|
137
146
|
: undefined,
|
|
138
147
|
},
|
package/dist/plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { tool } from "@opencode-ai/plugin";
|
|
2
2
|
import { KiroAcpTransport } from "./acp-transport.js";
|
|
3
|
-
import { detectAuth, resolveApiKey,
|
|
3
|
+
import { detectAuth, resolveApiKey, startKiroCliLoginOnce } from "./auth.js";
|
|
4
4
|
import { KiroCliChatTransport } from "./cli-transport.js";
|
|
5
5
|
import { loadOptions } from "./config.js";
|
|
6
6
|
import { createKiroFetch } from "./fetch-adapter.js";
|
|
@@ -170,7 +170,7 @@ export function createKiroPlugin() {
|
|
|
170
170
|
type: "oauth",
|
|
171
171
|
label: "Kiro CLI login",
|
|
172
172
|
authorize: async () => {
|
|
173
|
-
const session =
|
|
173
|
+
const session = startKiroCliLoginOnce();
|
|
174
174
|
return {
|
|
175
175
|
url: session.url,
|
|
176
176
|
instructions: session.instructions,
|
package/dist/request-adapter.js
CHANGED
|
@@ -164,6 +164,17 @@ function trailingToolMessageIndexes(messages) {
|
|
|
164
164
|
}
|
|
165
165
|
return indexes;
|
|
166
166
|
}
|
|
167
|
+
function previousAssistantIndexForTrailingTools(messages, trailingIndexes) {
|
|
168
|
+
if (trailingIndexes.size === 0)
|
|
169
|
+
return undefined;
|
|
170
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
171
|
+
const message = messages[index];
|
|
172
|
+
if (!message || message.role === "system" || trailingIndexes.has(index))
|
|
173
|
+
continue;
|
|
174
|
+
return message.role === "assistant" ? index : undefined;
|
|
175
|
+
}
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
167
178
|
function toolUses(message) {
|
|
168
179
|
return (message.tool_calls ?? [])
|
|
169
180
|
.map((toolCall) => {
|
|
@@ -222,6 +233,7 @@ export function toKiroGenerateRequest(request, resolver) {
|
|
|
222
233
|
const resolved = resolver.resolve(request.model);
|
|
223
234
|
const activeToolResults = toolResults(request.messages);
|
|
224
235
|
const activeTrailingToolIndexes = activeToolResults.length > 0 ? trailingToolMessageIndexes(request.messages) : new Set();
|
|
236
|
+
const activeToolUseAssistantIndex = previousAssistantIndexForTrailingTools(request.messages, activeTrailingToolIndexes);
|
|
225
237
|
const system = request.messages
|
|
226
238
|
.filter((message) => message.role === "system")
|
|
227
239
|
.map((message) => textFromContent(message.content))
|
|
@@ -232,7 +244,7 @@ export function toKiroGenerateRequest(request, resolver) {
|
|
|
232
244
|
if (message.role === "system" || activeTrailingToolIndexes.has(index))
|
|
233
245
|
continue;
|
|
234
246
|
const content = textFromContent(message.content);
|
|
235
|
-
const assistantToolUses = message.role === "assistant" ? toolUses(message) : [];
|
|
247
|
+
const assistantToolUses = message.role === "assistant" && index === activeToolUseAssistantIndex ? toolUses(message) : [];
|
|
236
248
|
if (!content && assistantToolUses.length === 0)
|
|
237
249
|
continue;
|
|
238
250
|
turns.push({
|