ns-kiro-core 0.1.0
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/LICENSE +22 -0
- package/README.md +51 -0
- package/dist/blocks.d.ts +32 -0
- package/dist/blocks.js +83 -0
- package/dist/blocks.js.map +1 -0
- package/dist/bracket-tool-parser.d.ts +11 -0
- package/dist/bracket-tool-parser.js +78 -0
- package/dist/bracket-tool-parser.js.map +1 -0
- package/dist/cost.d.ts +3 -0
- package/dist/cost.js +10 -0
- package/dist/cost.js.map +1 -0
- package/dist/debug.d.ts +6 -0
- package/dist/debug.js +63 -0
- package/dist/debug.js.map +1 -0
- package/dist/effort.d.ts +36 -0
- package/dist/effort.js +138 -0
- package/dist/effort.js.map +1 -0
- package/dist/endpoints.d.ts +8 -0
- package/dist/endpoints.js +43 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/event-parser.d.ts +49 -0
- package/dist/event-parser.js +56 -0
- package/dist/event-parser.js.map +1 -0
- package/dist/history-validator.d.ts +91 -0
- package/dist/history-validator.js +370 -0
- package/dist/history-validator.js.map +1 -0
- package/dist/history.d.ts +21 -0
- package/dist/history.js +130 -0
- package/dist/history.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/invoke-tool-parser.d.ts +16 -0
- package/dist/invoke-tool-parser.js +152 -0
- package/dist/invoke-tool-parser.js.map +1 -0
- package/dist/kiro-cli.d.ts +31 -0
- package/dist/kiro-cli.js +308 -0
- package/dist/kiro-cli.js.map +1 -0
- package/dist/kiro-ide.d.ts +12 -0
- package/dist/kiro-ide.js +74 -0
- package/dist/kiro-ide.js.map +1 -0
- package/dist/management.d.ts +34 -0
- package/dist/management.js +226 -0
- package/dist/management.js.map +1 -0
- package/dist/models.d.ts +58 -0
- package/dist/models.js +462 -0
- package/dist/models.js.map +1 -0
- package/dist/oauth.d.ts +50 -0
- package/dist/oauth.js +295 -0
- package/dist/oauth.js.map +1 -0
- package/dist/retry.d.ts +74 -0
- package/dist/retry.js +156 -0
- package/dist/retry.js.map +1 -0
- package/dist/stream.d.ts +36 -0
- package/dist/stream.js +898 -0
- package/dist/stream.js.map +1 -0
- package/dist/thinking-parser.d.ts +21 -0
- package/dist/thinking-parser.js +150 -0
- package/dist/thinking-parser.js.map +1 -0
- package/dist/token-type.d.ts +18 -0
- package/dist/token-type.js +45 -0
- package/dist/token-type.js.map +1 -0
- package/dist/tokenizer.d.ts +1 -0
- package/dist/tokenizer.js +19 -0
- package/dist/tokenizer.js.map +1 -0
- package/dist/transform.d.ts +111 -0
- package/dist/transform.js +268 -0
- package/dist/transform.js.map +1 -0
- package/dist/truncation.d.ts +3 -0
- package/dist/truncation.js +12 -0
- package/dist/truncation.js.map +1 -0
- package/dist/types.d.ts +159 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/usage.d.ts +86 -0
- package/dist/usage.js +85 -0
- package/dist/usage.js.map +1 -0
- package/package.json +31 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// Message transformation: neutral conversation shapes onto Kiro's wire format.
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
export const TOOL_RESULT_LIMIT = 250000;
|
|
4
|
+
/** Kiro's own requirement is content **or** tool results, not content
|
|
5
|
+
* unconditionally. First-party Kiro Agent states it as an explicit invariant
|
|
6
|
+
* — `NON_EMPTY_USER_MESSAGE`: "User messages must have either content or tool
|
|
7
|
+
* results" — and its validator implements `hasContent || hasToolResults`.
|
|
8
|
+
* It ships `content: ''` on synthesized and consolidated tool turns.
|
|
9
|
+
*
|
|
10
|
+
* A tool turn therefore needs no text: its payload is
|
|
11
|
+
* `userInputMessageContext.toolResults`.
|
|
12
|
+
*
|
|
13
|
+
* This placeholder remains for the case it was added for: a turn that reaches
|
|
14
|
+
* the request builder with neither text nor tool results — an image-only user
|
|
15
|
+
* message, or an empty-text user message. Send a neutral prompt there so the
|
|
16
|
+
* attachments still reach the model. Do not apply it to tool turns; that
|
|
17
|
+
* fabricates a user utterance the model reads as human. */
|
|
18
|
+
export const EMPTY_CONTENT_PLACEHOLDER = "Please proceed with the task.";
|
|
19
|
+
export function sanitizeSurrogates(text) {
|
|
20
|
+
// Replace unpaired high surrogates (0xD800-0xDBFF not followed by low surrogate)
|
|
21
|
+
// Replace unpaired low surrogates (0xDC00-0xDFFF not preceded by high surrogate)
|
|
22
|
+
// Properly paired surrogates (e.g. emoji like 🙈) are preserved.
|
|
23
|
+
return text.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "");
|
|
24
|
+
}
|
|
25
|
+
export function truncate(text, limit) {
|
|
26
|
+
if (text.length <= limit)
|
|
27
|
+
return text;
|
|
28
|
+
const half = Math.floor(limit / 2);
|
|
29
|
+
return `${text.substring(0, half)}\n... [TRUNCATED] ...\n${text.substring(text.length - half)}`;
|
|
30
|
+
}
|
|
31
|
+
const KIRO_TOOL_USE_ID_PATTERN = /^[a-zA-Z0-9_.:-]{1,64}$/;
|
|
32
|
+
/**
|
|
33
|
+
* Preserve native Kiro tool IDs, but deterministically remap IDs from providers
|
|
34
|
+
* whose syntax Kiro rejects (for example OpenAI Responses' 83-character
|
|
35
|
+
* `call_…|fc_…` IDs). Tool uses and results are transformed independently, so
|
|
36
|
+
* the mapping must be stable rather than random.
|
|
37
|
+
*/
|
|
38
|
+
export function toKiroToolUseId(toolUseId) {
|
|
39
|
+
if (KIRO_TOOL_USE_ID_PATTERN.test(toolUseId))
|
|
40
|
+
return toolUseId;
|
|
41
|
+
const digest = createHash("sha256").update(toolUseId).digest("base64url").slice(0, 32);
|
|
42
|
+
return `pi_${digest}`;
|
|
43
|
+
}
|
|
44
|
+
export function normalizeMessages(messages) {
|
|
45
|
+
return messages.filter((msg) => {
|
|
46
|
+
if (msg.role !== "assistant")
|
|
47
|
+
return true;
|
|
48
|
+
return msg.stopReason !== "error" && msg.stopReason !== "aborted";
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Move each `toolResult` to sit immediately after the assistant turn that
|
|
53
|
+
* issued its `toolCall`, matching by id.
|
|
54
|
+
*
|
|
55
|
+
* Concurrent tool executions appending to one transcript can interleave, so a
|
|
56
|
+
* result arrives behind a LATER assistant turn than the one that called it:
|
|
57
|
+
*
|
|
58
|
+
* assistant(toolUses=[A]) / user(text) / assistant(toolUses=[B]) / toolResult(A)
|
|
59
|
+
*
|
|
60
|
+
* Bedrock requires the message after a tool use to carry that use's results,
|
|
61
|
+
* matched by id, so this shape is rejected with `400 TOOL_USE_RESULT_MISMATCH`.
|
|
62
|
+
* Without this pass the downstream repair still makes the request sendable, but
|
|
63
|
+
* only by discarding `A`'s real output: `sanitizeHistory` tests pairing
|
|
64
|
+
* POSITIONALLY and drops `assistant(toolUses=[A])` because its next entry is
|
|
65
|
+
* the interjection, after which `A`'s result answers nothing and is stripped.
|
|
66
|
+
*
|
|
67
|
+
* This is a pure reorder. Nothing is fabricated, dropped, or rewritten, and a
|
|
68
|
+
* result whose `toolCall` appears nowhere is left in place for
|
|
69
|
+
* `injectSyntheticToolCalls` to handle. A well-formed transcript — where every
|
|
70
|
+
* result already follows its call — is returned unchanged.
|
|
71
|
+
*
|
|
72
|
+
* The cost is wire chronology: a user turn that interrupted between the call
|
|
73
|
+
* and its result now appears AFTER that result. That misplaces when the user
|
|
74
|
+
* spoke, which is a fidelity loss, but it is not fabrication and it is strictly
|
|
75
|
+
* less lossy than discarding real tool output the model is waiting on.
|
|
76
|
+
*/
|
|
77
|
+
export function relocateDisplacedToolResults(messages) {
|
|
78
|
+
const out = [];
|
|
79
|
+
const pending = [...messages];
|
|
80
|
+
while (pending.length > 0) {
|
|
81
|
+
const msg = pending.shift();
|
|
82
|
+
if (!msg)
|
|
83
|
+
break;
|
|
84
|
+
out.push(msg);
|
|
85
|
+
if (msg.role !== "assistant")
|
|
86
|
+
continue;
|
|
87
|
+
// Emit this turn's results in the order the turn declared its calls, so a
|
|
88
|
+
// multi-call turn keeps its results contiguous behind it.
|
|
89
|
+
for (const block of msg.content) {
|
|
90
|
+
if (block.type !== "toolCall")
|
|
91
|
+
continue;
|
|
92
|
+
const id = block.id;
|
|
93
|
+
// Search only what is still pending: a result already emitted belongs to
|
|
94
|
+
// an earlier turn and must not be pulled forward.
|
|
95
|
+
const at = pending.findIndex((p) => p.role === "toolResult" && p.toolCallId === id);
|
|
96
|
+
if (at >= 0)
|
|
97
|
+
out.push(...pending.splice(at, 1));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
export function extractImages(msg) {
|
|
103
|
+
return msg.content.filter((c) => c.type === "image");
|
|
104
|
+
}
|
|
105
|
+
export function getContentText(msg) {
|
|
106
|
+
return msg.content
|
|
107
|
+
.map((c) => {
|
|
108
|
+
if (c.type === "text")
|
|
109
|
+
return c.text;
|
|
110
|
+
if (c.type === "thinking")
|
|
111
|
+
return c.thinking;
|
|
112
|
+
return "";
|
|
113
|
+
})
|
|
114
|
+
.join("");
|
|
115
|
+
}
|
|
116
|
+
export function convertToolsToKiro(tools) {
|
|
117
|
+
return tools.map((tool) => ({
|
|
118
|
+
toolSpecification: {
|
|
119
|
+
name: tool.name,
|
|
120
|
+
description: tool.description,
|
|
121
|
+
inputSchema: { json: tool.parameters },
|
|
122
|
+
},
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
export function convertImagesToKiro(images) {
|
|
126
|
+
return images.map((img) => ({ format: img.mimeType.split("/")[1] || "png", source: { bytes: img.data } }));
|
|
127
|
+
}
|
|
128
|
+
function toolResultOf(msg) {
|
|
129
|
+
return {
|
|
130
|
+
content: [{ text: truncate(getContentText(msg), TOOL_RESULT_LIMIT) }],
|
|
131
|
+
status: msg.isError ? "error" : "success",
|
|
132
|
+
toolUseId: toKiroToolUseId(msg.toolCallId),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export function buildHistory(messages, modelId, systemPrompt) {
|
|
136
|
+
const history = [];
|
|
137
|
+
let systemPrepended = false;
|
|
138
|
+
let currentMsgStartIdx = messages.length - 1;
|
|
139
|
+
while (currentMsgStartIdx > 0 && messages[currentMsgStartIdx]?.role === "toolResult")
|
|
140
|
+
currentMsgStartIdx--;
|
|
141
|
+
const boundary = messages[currentMsgStartIdx];
|
|
142
|
+
if (boundary?.role === "assistant" && !boundary.content.some((b) => b.type === "toolCall")) {
|
|
143
|
+
currentMsgStartIdx++;
|
|
144
|
+
}
|
|
145
|
+
const historyMessages = messages.slice(0, currentMsgStartIdx);
|
|
146
|
+
for (let i = 0; i < historyMessages.length; i++) {
|
|
147
|
+
const msg = historyMessages[i];
|
|
148
|
+
if (!msg)
|
|
149
|
+
continue;
|
|
150
|
+
if (msg.role === "user") {
|
|
151
|
+
let content = getContentText(msg);
|
|
152
|
+
if (systemPrompt && !systemPrepended) {
|
|
153
|
+
content = `${systemPrompt}\n\n${content}`;
|
|
154
|
+
systemPrepended = true;
|
|
155
|
+
}
|
|
156
|
+
const images = extractImages(msg);
|
|
157
|
+
const uim = {
|
|
158
|
+
content: sanitizeSurrogates(content),
|
|
159
|
+
modelId,
|
|
160
|
+
origin: "KIRO_CLI",
|
|
161
|
+
...(images.length > 0 ? { images: convertImagesToKiro(images) } : {}),
|
|
162
|
+
};
|
|
163
|
+
const prevUim = history[history.length - 1]?.userInputMessage;
|
|
164
|
+
if (prevUim) {
|
|
165
|
+
// Merge into previous user message to maintain alternation without
|
|
166
|
+
// synthetic padding.
|
|
167
|
+
//
|
|
168
|
+
// Join only NON-EMPTY sides. A tool-result carrier has `content: ""`,
|
|
169
|
+
// so an unconditional separator would turn a real user utterance into
|
|
170
|
+
// `"\n\ncontinue"` on the wire — fabricating text onto a message the
|
|
171
|
+
// user actually wrote. Two real utterances still get the separator.
|
|
172
|
+
prevUim.content =
|
|
173
|
+
prevUim.content && uim.content ? `${prevUim.content}\n\n${uim.content}` : prevUim.content || uim.content;
|
|
174
|
+
if (uim.images)
|
|
175
|
+
prevUim.images = [...(prevUim.images || []), ...uim.images];
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
history.push({ userInputMessage: uim });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else if (msg.role === "assistant") {
|
|
182
|
+
let armContent = "";
|
|
183
|
+
const armToolUses = [];
|
|
184
|
+
// Tracks whether the turn had *any* block at all. A turn whose only block
|
|
185
|
+
// was thinking yields `armContent === ""`, which the drop guard below
|
|
186
|
+
// would otherwise read as "nothing to say" and delete — silently removing
|
|
187
|
+
// a real turn and breaking ALTERNATING_MESSAGES for the very validator
|
|
188
|
+
// this provider runs pre-send.
|
|
189
|
+
let armHadBlocks = false;
|
|
190
|
+
for (const block of msg.content) {
|
|
191
|
+
if (block.type === "text") {
|
|
192
|
+
armContent += block.text;
|
|
193
|
+
armHadBlocks = true;
|
|
194
|
+
}
|
|
195
|
+
else if (block.type === "thinking") {
|
|
196
|
+
// Deliberately NOT serialized. Reasoning is excluded from the text
|
|
197
|
+
// channel, matching first-party Kiro Agent's `extractTextContent`,
|
|
198
|
+
// which type-filters to `text` before joining. Flattening it to
|
|
199
|
+
// `<thinking>...</thinking>` writes literal markup into the model's
|
|
200
|
+
// own remembered speech — a dialect this provider would then read
|
|
201
|
+
// back out again in `thinking-parser.ts`.
|
|
202
|
+
armHadBlocks = true;
|
|
203
|
+
}
|
|
204
|
+
else if (block.type === "toolCall") {
|
|
205
|
+
armToolUses.push({
|
|
206
|
+
name: block.name,
|
|
207
|
+
toolUseId: toKiroToolUseId(block.id),
|
|
208
|
+
input: block.arguments,
|
|
209
|
+
});
|
|
210
|
+
armHadBlocks = true;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Drop only a turn that genuinely carried nothing. A thinking-only turn is
|
|
214
|
+
// retained with `content: ""`, which is what first-party sends for the
|
|
215
|
+
// same shape.
|
|
216
|
+
if (!armContent && armToolUses.length === 0 && !armHadBlocks)
|
|
217
|
+
continue;
|
|
218
|
+
history.push({
|
|
219
|
+
assistantResponseMessage: { content: armContent, ...(armToolUses.length > 0 ? { toolUses: armToolUses } : {}) },
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
const toolResults = [toolResultOf(msg)];
|
|
224
|
+
const trImages = [...extractImages(msg)];
|
|
225
|
+
let j = i + 1;
|
|
226
|
+
while (j < historyMessages.length) {
|
|
227
|
+
const next = historyMessages[j];
|
|
228
|
+
if (next?.role !== "toolResult")
|
|
229
|
+
break;
|
|
230
|
+
toolResults.push(toolResultOf(next));
|
|
231
|
+
trImages.push(...extractImages(next));
|
|
232
|
+
j++;
|
|
233
|
+
}
|
|
234
|
+
i = j - 1;
|
|
235
|
+
const prevTr = history[history.length - 1]?.userInputMessage;
|
|
236
|
+
if (prevTr) {
|
|
237
|
+
// Merge tool results into the previous user message to maintain
|
|
238
|
+
// alternation without synthetic padding. Its `content` is the text a
|
|
239
|
+
// user actually wrote (or a prior turn's tool carrier) — leave it
|
|
240
|
+
// byte-identical. `toolResults` is the payload; text is not needed to
|
|
241
|
+
// carry it, and appending narration here rewrites a human utterance.
|
|
242
|
+
if (trImages.length > 0)
|
|
243
|
+
prevTr.images = [...(prevTr.images || []), ...convertImagesToKiro(trImages)];
|
|
244
|
+
if (!prevTr.userInputMessageContext)
|
|
245
|
+
prevTr.userInputMessageContext = {};
|
|
246
|
+
prevTr.userInputMessageContext.toolResults = [
|
|
247
|
+
...(prevTr.userInputMessageContext.toolResults || []),
|
|
248
|
+
...toolResults,
|
|
249
|
+
];
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
history.push({
|
|
253
|
+
userInputMessage: {
|
|
254
|
+
// Empty by design: `toolResults` is this turn's payload. See
|
|
255
|
+
// EMPTY_CONTENT_PLACEHOLDER for the content-or-toolResults rule.
|
|
256
|
+
content: "",
|
|
257
|
+
modelId,
|
|
258
|
+
origin: "KIRO_CLI",
|
|
259
|
+
...(trImages.length > 0 ? { images: convertImagesToKiro(trImages) } : {}),
|
|
260
|
+
userInputMessageContext: { toolResults },
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return { history, systemPrepended, currentMsgStartIdx };
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAE/E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAqCzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAExC;;;;;;;;;;;;;4DAa4D;AAC5D,MAAM,CAAC,MAAM,yBAAyB,GAAG,+BAA+B,CAAC;AAEzE,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,iFAAiF;IACjF,iFAAiF;IACjF,iEAAiE;IACjE,OAAO,IAAI,CAAC,OAAO,CAAC,yEAAyE,EAAE,EAAE,CAAC,CAAC;AACrG,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,KAAa;IAClD,IAAI,IAAI,CAAC,MAAM,IAAI,KAAK;QAAE,OAAO,IAAI,CAAC;IACtC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IACnC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,0BAA0B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;AAClG,CAAC;AAED,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,SAAiB;IAC/C,IAAI,wBAAwB,CAAC,IAAI,CAAC,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IAC/D,MAAM,MAAM,GA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MAAM,CAAC,uBAAuB,GAAG,EAAE,CAAC;gBACzE,MAAM,CAAC,uBAAuB,CAAC,WAAW,GAAG;oBAC3C,GAAG,CAAC,MAAM,CAAC,uBAAuB,CAAC,WAAW,IAAI,EAAE,CAAC;oBACrD,GAAG,WAAW;iBACf,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC;oBACX,gBAAgB,EAAE;wBAChB,6DAA6D;wBAC7D,iEAAiE;wBACjE,OAAO,EAAE,EAAE;wBACX,OAAO;wBACP,MAAM,EAAE,UAAU;wBAClB,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,mBAAmB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;wBACzE,uBAAuB,EAAE,EAAE,WAAW,EAAE;qBACzC;iBACF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { KiroMessage } from "./types.js";
|
|
2
|
+
export declare const TRUNCATION_NOTICE = "[NOTE: Your previous response was cut off due to length limits. Please continue from where you left off.]";
|
|
3
|
+
export declare function wasPreviousResponseTruncated(messages: KiroMessage[]): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// ABOUTME: Truncation detection and recovery notice for interrupted Kiro responses.
|
|
2
|
+
// ABOUTME: Detects when the previous assistant response was cut off and injects a continuation notice.
|
|
3
|
+
export const TRUNCATION_NOTICE = "[NOTE: Your previous response was cut off due to length limits. Please continue from where you left off.]";
|
|
4
|
+
export function wasPreviousResponseTruncated(messages) {
|
|
5
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
6
|
+
const message = messages[i];
|
|
7
|
+
if (message?.role === "assistant")
|
|
8
|
+
return message.stopReason === "length";
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=truncation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncation.js","sourceRoot":"","sources":["../src/truncation.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,uGAAuG;AAIvG,MAAM,CAAC,MAAM,iBAAiB,GAC5B,2GAA2G,CAAC;AAE9G,MAAM,UAAU,4BAA4B,CAAC,QAAuB;IAClE,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9C,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,OAAO,EAAE,IAAI,KAAK,WAAW;YAAE,OAAO,OAAO,CAAC,UAAU,KAAK,QAAQ,CAAC;IAC5E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/** User-facing reasoning levels, ordered least to most intensive. */
|
|
2
|
+
export type KiroEffort = "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
3
|
+
export declare const KIRO_EFFORT_ORDER: readonly KiroEffort[];
|
|
4
|
+
export interface KiroTextContent {
|
|
5
|
+
type: "text";
|
|
6
|
+
text: string;
|
|
7
|
+
}
|
|
8
|
+
export interface KiroImageContent {
|
|
9
|
+
type: "image";
|
|
10
|
+
/** Base64-encoded bytes, without a data-URL prefix. */
|
|
11
|
+
data: string;
|
|
12
|
+
mimeType: string;
|
|
13
|
+
}
|
|
14
|
+
export interface KiroThinkingContent {
|
|
15
|
+
type: "thinking";
|
|
16
|
+
thinking: string;
|
|
17
|
+
thinkingSignature?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface KiroToolCallContent {
|
|
20
|
+
type: "toolCall";
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
arguments: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
export type KiroUserContent = KiroTextContent | KiroImageContent;
|
|
26
|
+
export type KiroAssistantContent = KiroTextContent | KiroThinkingContent | KiroToolCallContent;
|
|
27
|
+
/** Why the previous assistant turn stopped; only `length` changes request shaping. */
|
|
28
|
+
export type KiroStopReason = "stop" | "length" | "toolUse" | "error" | "aborted";
|
|
29
|
+
export interface KiroUserMessage {
|
|
30
|
+
role: "user";
|
|
31
|
+
content: KiroUserContent[];
|
|
32
|
+
}
|
|
33
|
+
export interface KiroAssistantMessage {
|
|
34
|
+
role: "assistant";
|
|
35
|
+
content: KiroAssistantContent[];
|
|
36
|
+
stopReason?: KiroStopReason;
|
|
37
|
+
}
|
|
38
|
+
export interface KiroToolResultMessage {
|
|
39
|
+
role: "toolResult";
|
|
40
|
+
toolCallId: string;
|
|
41
|
+
toolName: string;
|
|
42
|
+
content: KiroUserContent[];
|
|
43
|
+
isError: boolean;
|
|
44
|
+
}
|
|
45
|
+
export type KiroMessage = KiroUserMessage | KiroAssistantMessage | KiroToolResultMessage;
|
|
46
|
+
/** One tool offered to the model, in JSON-schema form. */
|
|
47
|
+
export interface KiroTool {
|
|
48
|
+
name: string;
|
|
49
|
+
description: string;
|
|
50
|
+
parameters: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
export interface KiroCost {
|
|
53
|
+
/** Cost per million tokens. */
|
|
54
|
+
input: number;
|
|
55
|
+
output: number;
|
|
56
|
+
cacheRead: number;
|
|
57
|
+
cacheWrite: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* One model as this provider needs to see it. Hosts carry richer descriptors;
|
|
61
|
+
* an adapter projects theirs onto this before entering the core.
|
|
62
|
+
*/
|
|
63
|
+
export interface KiroModelSpec {
|
|
64
|
+
/** Local id used for selection and cost attribution (e.g. `claude-sonnet-4-6`). */
|
|
65
|
+
id: string;
|
|
66
|
+
/** Wire id Kiro accepts, when it differs from {@link id}. */
|
|
67
|
+
kiroModelId?: string;
|
|
68
|
+
name: string;
|
|
69
|
+
reasoning: boolean;
|
|
70
|
+
/** Selectable efforts, least to most intensive. Absent means no effort control. */
|
|
71
|
+
efforts?: readonly KiroEffort[];
|
|
72
|
+
/** Effort to wire-value remap; identity for efforts the map omits. */
|
|
73
|
+
effortMap?: Partial<Record<KiroEffort, string>>;
|
|
74
|
+
/** Authenticated-catalog schema describing the effort field this model accepts. */
|
|
75
|
+
additionalModelRequestFieldsSchema?: unknown;
|
|
76
|
+
input: ("text" | "image")[];
|
|
77
|
+
cost: KiroCost;
|
|
78
|
+
contextWindow: number;
|
|
79
|
+
maxTokens: number;
|
|
80
|
+
/** Kiro API region this model is served from. */
|
|
81
|
+
region?: string;
|
|
82
|
+
/** Profile the request bills against, when the credential resolved one. */
|
|
83
|
+
profileArn?: string;
|
|
84
|
+
}
|
|
85
|
+
export interface KiroUsage {
|
|
86
|
+
input: number;
|
|
87
|
+
output: number;
|
|
88
|
+
totalTokens: number;
|
|
89
|
+
/** Percentage of the context window Kiro reported for this turn. */
|
|
90
|
+
contextPercent?: number;
|
|
91
|
+
cost: {
|
|
92
|
+
input: number;
|
|
93
|
+
output: number;
|
|
94
|
+
cacheRead: number;
|
|
95
|
+
cacheWrite: number;
|
|
96
|
+
total: number;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* What the core emits while a response streams. Block indexes are allocated
|
|
101
|
+
* monotonically and never reused, so a consumer that ignores {@link KiroResetEvent}
|
|
102
|
+
* still sees a well-formed, if longer, block sequence.
|
|
103
|
+
*/
|
|
104
|
+
export type KiroStreamEvent = {
|
|
105
|
+
type: "start";
|
|
106
|
+
} | {
|
|
107
|
+
type: "text_start";
|
|
108
|
+
index: number;
|
|
109
|
+
} | {
|
|
110
|
+
type: "text_delta";
|
|
111
|
+
index: number;
|
|
112
|
+
delta: string;
|
|
113
|
+
} | {
|
|
114
|
+
type: "text_end";
|
|
115
|
+
index: number;
|
|
116
|
+
text: string;
|
|
117
|
+
} | {
|
|
118
|
+
type: "thinking_start";
|
|
119
|
+
index: number;
|
|
120
|
+
} | {
|
|
121
|
+
type: "thinking_delta";
|
|
122
|
+
index: number;
|
|
123
|
+
delta: string;
|
|
124
|
+
} | {
|
|
125
|
+
type: "thinking_end";
|
|
126
|
+
index: number;
|
|
127
|
+
thinking: string;
|
|
128
|
+
signature?: string;
|
|
129
|
+
} | {
|
|
130
|
+
type: "tool_call_start";
|
|
131
|
+
index: number;
|
|
132
|
+
id: string;
|
|
133
|
+
name: string;
|
|
134
|
+
} | {
|
|
135
|
+
type: "tool_call_delta";
|
|
136
|
+
index: number;
|
|
137
|
+
id: string;
|
|
138
|
+
argumentsDelta: string;
|
|
139
|
+
} | {
|
|
140
|
+
type: "tool_call_end";
|
|
141
|
+
index: number;
|
|
142
|
+
id: string;
|
|
143
|
+
name: string;
|
|
144
|
+
arguments: Record<string, unknown>;
|
|
145
|
+
} | KiroResetEvent | {
|
|
146
|
+
type: "usage";
|
|
147
|
+
usage: KiroUsage;
|
|
148
|
+
} | {
|
|
149
|
+
type: "done";
|
|
150
|
+
stopReason: "stop" | "toolUse" | "length";
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* An internal retry discarded everything emitted so far. Hosts able to drop
|
|
154
|
+
* already-delivered blocks should; hosts that cannot may ignore this, because
|
|
155
|
+
* the blocks that follow carry fresh indexes.
|
|
156
|
+
*/
|
|
157
|
+
export interface KiroResetEvent {
|
|
158
|
+
type: "reset";
|
|
159
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// ABOUTME: Host-neutral vocabulary shared by every Kiro adapter.
|
|
2
|
+
// ABOUTME: Keeps the wire protocol independent of any one agent's message types.
|
|
3
|
+
export const KIRO_EFFORT_ORDER = ["minimal", "low", "medium", "high", "xhigh", "max"];
|
|
4
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,iFAAiF;AAKjF,MAAM,CAAC,MAAM,iBAAiB,GAA0B,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC"}
|
package/dist/usage.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { KiroCredentials } from "./oauth.js";
|
|
2
|
+
type EpochLike = number | string;
|
|
3
|
+
interface KiroFreeTrialInfo {
|
|
4
|
+
freeTrialStatus?: string;
|
|
5
|
+
freeTrialExpiry?: EpochLike;
|
|
6
|
+
currentUsage?: number;
|
|
7
|
+
currentUsageWithPrecision?: number;
|
|
8
|
+
usageLimit?: number;
|
|
9
|
+
usageLimitWithPrecision?: number;
|
|
10
|
+
}
|
|
11
|
+
interface KiroUsageBreakdown {
|
|
12
|
+
resourceType?: string;
|
|
13
|
+
displayName?: string;
|
|
14
|
+
displayNamePlural?: string;
|
|
15
|
+
currentUsage: number;
|
|
16
|
+
currentUsageWithPrecision?: number;
|
|
17
|
+
currentOverages: number;
|
|
18
|
+
currentOveragesWithPrecision?: number;
|
|
19
|
+
usageLimit: number;
|
|
20
|
+
usageLimitWithPrecision?: number;
|
|
21
|
+
unit?: string;
|
|
22
|
+
overageCharges: number;
|
|
23
|
+
currency?: string;
|
|
24
|
+
overageRate?: number;
|
|
25
|
+
nextDateReset?: EpochLike;
|
|
26
|
+
overageCap?: number;
|
|
27
|
+
overageCapWithPrecision?: number;
|
|
28
|
+
freeTrialInfo?: KiroFreeTrialInfo;
|
|
29
|
+
}
|
|
30
|
+
interface KiroUsageLimitList {
|
|
31
|
+
type?: string;
|
|
32
|
+
currentUsage?: number;
|
|
33
|
+
totalUsageLimit?: number;
|
|
34
|
+
percentUsed?: number;
|
|
35
|
+
}
|
|
36
|
+
export interface KiroGetUsageLimitsResponse {
|
|
37
|
+
limits?: KiroUsageLimitList[];
|
|
38
|
+
nextDateReset?: EpochLike;
|
|
39
|
+
daysUntilReset?: number;
|
|
40
|
+
usageBreakdown?: KiroUsageBreakdown;
|
|
41
|
+
usageBreakdownList?: KiroUsageBreakdown[];
|
|
42
|
+
subscriptionInfo?: {
|
|
43
|
+
subscriptionTitle?: string;
|
|
44
|
+
};
|
|
45
|
+
overageConfiguration?: {
|
|
46
|
+
overageStatus?: string;
|
|
47
|
+
};
|
|
48
|
+
userInfo?: {
|
|
49
|
+
userId?: string;
|
|
50
|
+
email?: string;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export interface KiroProviderUsageBonus {
|
|
54
|
+
label: string;
|
|
55
|
+
usedDisplay?: string;
|
|
56
|
+
limitDisplay?: string;
|
|
57
|
+
expiresAt?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface KiroProviderUsageBucket {
|
|
60
|
+
id: string;
|
|
61
|
+
label: string;
|
|
62
|
+
resourceType?: string;
|
|
63
|
+
/** Raw amounts, for hosts that render their own gauges. */
|
|
64
|
+
used: number;
|
|
65
|
+
limit?: number;
|
|
66
|
+
overages?: number;
|
|
67
|
+
usedDisplay: string;
|
|
68
|
+
limitDisplay?: string;
|
|
69
|
+
unit?: string;
|
|
70
|
+
overagesDisplay?: string;
|
|
71
|
+
overageChargesDisplay?: string;
|
|
72
|
+
resetAt?: string;
|
|
73
|
+
bonus?: KiroProviderUsageBonus;
|
|
74
|
+
}
|
|
75
|
+
export interface KiroProviderUsage {
|
|
76
|
+
summary?: string;
|
|
77
|
+
subscriptionTitle?: string;
|
|
78
|
+
resetAt?: string;
|
|
79
|
+
daysUntilReset?: number;
|
|
80
|
+
overageStatus?: string;
|
|
81
|
+
manageUrl?: string;
|
|
82
|
+
usageBuckets?: KiroProviderUsageBucket[];
|
|
83
|
+
raw?: Record<string, unknown>;
|
|
84
|
+
}
|
|
85
|
+
export declare function fetchKiroUsage(credentials: KiroCredentials): Promise<KiroProviderUsage>;
|
|
86
|
+
export {};
|
package/dist/usage.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// ABOUTME: Fetches Kiro account usage through the current Kiro management control plane.
|
|
2
|
+
// ABOUTME: Maps the response into a host-neutral shape each adapter projects for its own UI.
|
|
3
|
+
import { resolveApiRegion } from "./endpoints.js";
|
|
4
|
+
import { getUsageLimits, resolveKiroProfileArn } from "./management.js";
|
|
5
|
+
const MANAGE_USAGE_URL = "https://app.kiro.dev/account/usage";
|
|
6
|
+
function toIsoDate(value) {
|
|
7
|
+
if (value === undefined || value === null)
|
|
8
|
+
return undefined;
|
|
9
|
+
const date = typeof value === "number" ? new Date(value * 1000) : new Date(value);
|
|
10
|
+
return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
|
|
11
|
+
}
|
|
12
|
+
function formatCount(value) {
|
|
13
|
+
if (value === undefined || Number.isNaN(value))
|
|
14
|
+
return undefined;
|
|
15
|
+
return Number.isInteger(value) ? String(value) : value.toFixed(2);
|
|
16
|
+
}
|
|
17
|
+
function formatMoney(amount, currency) {
|
|
18
|
+
if (amount === undefined || Number.isNaN(amount) || amount <= 0)
|
|
19
|
+
return undefined;
|
|
20
|
+
const code = currency || "USD";
|
|
21
|
+
try {
|
|
22
|
+
return new Intl.NumberFormat("en-US", { style: "currency", currency: code }).format(amount);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return `${amount.toFixed(2)} ${code}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function mapBucket(bucket, index) {
|
|
29
|
+
const used = bucket.currentUsageWithPrecision ?? bucket.currentUsage;
|
|
30
|
+
const limit = bucket.usageLimitWithPrecision ?? bucket.usageLimit;
|
|
31
|
+
const overages = bucket.currentOveragesWithPrecision ?? bucket.currentOverages;
|
|
32
|
+
const freeTrialUsed = bucket.freeTrialInfo?.currentUsageWithPrecision ?? bucket.freeTrialInfo?.currentUsage;
|
|
33
|
+
const freeTrialLimit = bucket.freeTrialInfo?.usageLimitWithPrecision ?? bucket.freeTrialInfo?.usageLimit;
|
|
34
|
+
return {
|
|
35
|
+
id: bucket.resourceType || bucket.displayName || `usage-${index}`,
|
|
36
|
+
label: bucket.displayName || bucket.displayNamePlural || bucket.resourceType || "Usage",
|
|
37
|
+
resourceType: bucket.resourceType,
|
|
38
|
+
used: used ?? 0,
|
|
39
|
+
limit,
|
|
40
|
+
overages: overages && overages > 0 ? overages : undefined,
|
|
41
|
+
usedDisplay: formatCount(used) || "0",
|
|
42
|
+
limitDisplay: formatCount(limit),
|
|
43
|
+
unit: bucket.unit,
|
|
44
|
+
overagesDisplay: overages && overages > 0 ? formatCount(overages) : undefined,
|
|
45
|
+
overageChargesDisplay: formatMoney(bucket.overageCharges, bucket.currency),
|
|
46
|
+
resetAt: toIsoDate(bucket.nextDateReset),
|
|
47
|
+
bonus: freeTrialUsed !== undefined || freeTrialLimit !== undefined || bucket.freeTrialInfo?.freeTrialExpiry !== undefined
|
|
48
|
+
? {
|
|
49
|
+
label: "Bonus credits",
|
|
50
|
+
usedDisplay: formatCount(freeTrialUsed),
|
|
51
|
+
limitDisplay: formatCount(freeTrialLimit),
|
|
52
|
+
expiresAt: toIsoDate(bucket.freeTrialInfo?.freeTrialExpiry),
|
|
53
|
+
}
|
|
54
|
+
: undefined,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function fetchRawUsage(auth, profileArn) {
|
|
58
|
+
const resolvedProfileArn = await resolveKiroProfileArn(auth, profileArn);
|
|
59
|
+
return getUsageLimits(auth, {
|
|
60
|
+
profileArn: resolvedProfileArn,
|
|
61
|
+
origin: "KIRO_CLI",
|
|
62
|
+
resourceType: "CREDIT",
|
|
63
|
+
isEmailRequired: false,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export async function fetchKiroUsage(credentials) {
|
|
67
|
+
const auth = { accessToken: credentials.access, region: resolveApiRegion(credentials.region) };
|
|
68
|
+
const raw = await fetchRawUsage(auth, credentials.profileArn);
|
|
69
|
+
const usageBuckets = raw.usageBreakdownList?.length
|
|
70
|
+
? raw.usageBreakdownList.map(mapBucket)
|
|
71
|
+
: raw.usageBreakdown
|
|
72
|
+
? [mapBucket(raw.usageBreakdown, 0)]
|
|
73
|
+
: [];
|
|
74
|
+
return {
|
|
75
|
+
summary: raw.subscriptionInfo?.subscriptionTitle,
|
|
76
|
+
subscriptionTitle: raw.subscriptionInfo?.subscriptionTitle,
|
|
77
|
+
resetAt: toIsoDate(raw.nextDateReset),
|
|
78
|
+
daysUntilReset: raw.daysUntilReset,
|
|
79
|
+
overageStatus: raw.overageConfiguration?.overageStatus,
|
|
80
|
+
manageUrl: MANAGE_USAGE_URL,
|
|
81
|
+
usageBuckets,
|
|
82
|
+
raw: raw,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,6FAA6F;AAE7F,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,cAAc,EAA2B,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGjG,MAAM,gBAAgB,GAAG,oCAAoC,CAAC;AAsF9D,SAAS,SAAS,CAAC,KAA4B;IAC7C,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5D,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;IAClF,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;AACvE,CAAC;AAED,SAA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