ns-omp-provider-kiro 0.3.4 → 0.3.7
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/index.js +77 -22
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2336,17 +2336,19 @@ ${text.substring(text.length - half)}`;
|
|
|
2336
2336
|
}
|
|
2337
2337
|
var KIRO_TOOL_USE_ID_PATTERN = /^[a-zA-Z0-9_.:-]{1,64}$/;
|
|
2338
2338
|
function toKiroToolUseId(toolUseId) {
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2339
|
+
const id = typeof toolUseId === "string" ? toolUseId : String(toolUseId);
|
|
2340
|
+
if (KIRO_TOOL_USE_ID_PATTERN.test(id))
|
|
2341
|
+
return id;
|
|
2342
|
+
const digest = createHash2("sha256").update(id).digest("base64url").slice(0, 32);
|
|
2342
2343
|
return `pi_${digest}`;
|
|
2343
2344
|
}
|
|
2344
2345
|
var KIRO_TOOL_NAME_PATTERN = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
2345
2346
|
function toKiroToolName(name) {
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
const
|
|
2347
|
+
const str2 = typeof name === "string" ? name : String(name);
|
|
2348
|
+
if (KIRO_TOOL_NAME_PATTERN.test(str2))
|
|
2349
|
+
return str2;
|
|
2350
|
+
const clean = str2.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 55);
|
|
2351
|
+
const digest = createHash2("sha256").update(str2).digest("base64url").slice(0, 8);
|
|
2350
2352
|
return `${clean || "tool"}_${digest}`;
|
|
2351
2353
|
}
|
|
2352
2354
|
function kiroToolNameAliases(tools) {
|
|
@@ -2404,17 +2406,66 @@ function toKiroInputSchema(parameters) {
|
|
|
2404
2406
|
}
|
|
2405
2407
|
return { type: "object", properties: {} };
|
|
2406
2408
|
}
|
|
2409
|
+
function toKiroToolDescription(description) {
|
|
2410
|
+
if (typeof description === "string")
|
|
2411
|
+
return description === "" ? {} : { description };
|
|
2412
|
+
return description == null ? {} : { description: String(description) };
|
|
2413
|
+
}
|
|
2407
2414
|
function convertToolsToKiro(tools) {
|
|
2408
2415
|
return tools.map((tool) => ({
|
|
2409
2416
|
toolSpecification: {
|
|
2410
2417
|
name: toKiroToolName(tool.name),
|
|
2411
|
-
|
|
2418
|
+
...toKiroToolDescription(tool.description),
|
|
2412
2419
|
inputSchema: { json: toKiroInputSchema(tool.parameters) }
|
|
2413
2420
|
}
|
|
2414
2421
|
}));
|
|
2415
2422
|
}
|
|
2423
|
+
var KIRO_IMAGE_FORMAT_ALIASES = {
|
|
2424
|
+
png: "png",
|
|
2425
|
+
"x-png": "png",
|
|
2426
|
+
jpeg: "jpeg",
|
|
2427
|
+
jpg: "jpeg",
|
|
2428
|
+
pjpeg: "jpeg",
|
|
2429
|
+
gif: "gif",
|
|
2430
|
+
webp: "webp"
|
|
2431
|
+
};
|
|
2432
|
+
function toKiroImageFormat(mimeType) {
|
|
2433
|
+
const subtype = mimeType.trim().toLowerCase().split("/").pop()?.split(";")[0]?.trim() ?? "";
|
|
2434
|
+
return KIRO_IMAGE_FORMAT_ALIASES[subtype];
|
|
2435
|
+
}
|
|
2436
|
+
function toKiroImageBytes(data) {
|
|
2437
|
+
const trimmed = data.trim();
|
|
2438
|
+
const marker = "base64,";
|
|
2439
|
+
if (!trimmed.startsWith("data:") || !trimmed.includes(marker))
|
|
2440
|
+
return trimmed;
|
|
2441
|
+
return trimmed.slice(trimmed.indexOf(marker) + marker.length);
|
|
2442
|
+
}
|
|
2416
2443
|
function convertImagesToKiro(images) {
|
|
2417
|
-
|
|
2444
|
+
const out = [];
|
|
2445
|
+
for (const img of images) {
|
|
2446
|
+
const format = toKiroImageFormat(img.mimeType);
|
|
2447
|
+
const bytes = toKiroImageBytes(img.data);
|
|
2448
|
+
if (!format || !bytes)
|
|
2449
|
+
continue;
|
|
2450
|
+
out.push({ format, source: { bytes } });
|
|
2451
|
+
}
|
|
2452
|
+
return out;
|
|
2453
|
+
}
|
|
2454
|
+
function toKiroToolInput(input) {
|
|
2455
|
+
if (isPlainObject(input))
|
|
2456
|
+
return input;
|
|
2457
|
+
if (typeof input === "string") {
|
|
2458
|
+
try {
|
|
2459
|
+
const parsed = JSON.parse(input);
|
|
2460
|
+
if (isPlainObject(parsed))
|
|
2461
|
+
return parsed;
|
|
2462
|
+
} catch {
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
return {};
|
|
2466
|
+
}
|
|
2467
|
+
function isPlainObject(value) {
|
|
2468
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
2418
2469
|
}
|
|
2419
2470
|
function toolResultOf(msg) {
|
|
2420
2471
|
return {
|
|
@@ -2446,12 +2497,12 @@ function buildHistory(messages, modelId, systemPrompt) {
|
|
|
2446
2497
|
${content}`;
|
|
2447
2498
|
systemPrepended = true;
|
|
2448
2499
|
}
|
|
2449
|
-
const images = extractImages(msg);
|
|
2500
|
+
const images = convertImagesToKiro(extractImages(msg));
|
|
2450
2501
|
const uim = {
|
|
2451
2502
|
content: sanitizeSurrogates(content),
|
|
2452
2503
|
modelId,
|
|
2453
2504
|
origin: "KIRO_CLI",
|
|
2454
|
-
...images.length > 0 ? { images
|
|
2505
|
+
...images.length > 0 ? { images } : {}
|
|
2455
2506
|
};
|
|
2456
2507
|
const prevUim = history[history.length - 1]?.userInputMessage;
|
|
2457
2508
|
if (prevUim) {
|
|
@@ -2477,7 +2528,7 @@ ${uim.content}` : prevUim.content || uim.content;
|
|
|
2477
2528
|
armToolUses.push({
|
|
2478
2529
|
name: toKiroToolName(block.name),
|
|
2479
2530
|
toolUseId: toKiroToolUseId(block.id),
|
|
2480
|
-
input: block.arguments
|
|
2531
|
+
input: toKiroToolInput(block.arguments)
|
|
2481
2532
|
});
|
|
2482
2533
|
armHadBlocks = true;
|
|
2483
2534
|
}
|
|
@@ -2502,8 +2553,9 @@ ${uim.content}` : prevUim.content || uim.content;
|
|
|
2502
2553
|
i = j - 1;
|
|
2503
2554
|
const prevTr = history[history.length - 1]?.userInputMessage;
|
|
2504
2555
|
if (prevTr) {
|
|
2505
|
-
|
|
2506
|
-
|
|
2556
|
+
const images = convertImagesToKiro(trImages);
|
|
2557
|
+
if (images.length > 0)
|
|
2558
|
+
prevTr.images = [...prevTr.images || [], ...images];
|
|
2507
2559
|
if (!prevTr.userInputMessageContext)
|
|
2508
2560
|
prevTr.userInputMessageContext = {};
|
|
2509
2561
|
prevTr.userInputMessageContext.toolResults = [
|
|
@@ -2511,6 +2563,7 @@ ${uim.content}` : prevUim.content || uim.content;
|
|
|
2511
2563
|
...toolResults
|
|
2512
2564
|
];
|
|
2513
2565
|
} else {
|
|
2566
|
+
const images = convertImagesToKiro(trImages);
|
|
2514
2567
|
history.push({
|
|
2515
2568
|
userInputMessage: {
|
|
2516
2569
|
// Empty by design: `toolResults` is this turn's payload. See
|
|
@@ -2518,7 +2571,7 @@ ${uim.content}` : prevUim.content || uim.content;
|
|
|
2518
2571
|
content: "",
|
|
2519
2572
|
modelId,
|
|
2520
2573
|
origin: "KIRO_CLI",
|
|
2521
|
-
...
|
|
2574
|
+
...images.length > 0 ? { images } : {},
|
|
2522
2575
|
userInputMessageContext: { toolResults }
|
|
2523
2576
|
}
|
|
2524
2577
|
});
|
|
@@ -3071,7 +3124,7 @@ function buildKiroRequest(params) {
|
|
|
3071
3124
|
armToolUses.push({
|
|
3072
3125
|
name: toKiroToolName(block.name),
|
|
3073
3126
|
toolUseId: toKiroToolUseId(block.id),
|
|
3074
|
-
input: block.arguments
|
|
3127
|
+
input: toKiroToolInput(block.arguments)
|
|
3075
3128
|
});
|
|
3076
3129
|
}
|
|
3077
3130
|
}
|
|
@@ -3100,8 +3153,9 @@ ${armContent}` : prevArm.content || armContent;
|
|
|
3100
3153
|
currentToolResults.push(toolResultOf2(m));
|
|
3101
3154
|
toolResultImages.push(...extractImages(m));
|
|
3102
3155
|
}
|
|
3103
|
-
|
|
3104
|
-
|
|
3156
|
+
const convertedToolImages = convertImagesToKiro(toolResultImages);
|
|
3157
|
+
if (convertedToolImages.length > 0)
|
|
3158
|
+
currentImages = convertedToolImages;
|
|
3105
3159
|
currentContent = "";
|
|
3106
3160
|
} else if (firstMsg?.role === "toolResult") {
|
|
3107
3161
|
const toolResultImages = [];
|
|
@@ -3111,8 +3165,9 @@ ${armContent}` : prevArm.content || armContent;
|
|
|
3111
3165
|
currentToolResults.push(toolResultOf2(m));
|
|
3112
3166
|
toolResultImages.push(...extractImages(m));
|
|
3113
3167
|
}
|
|
3114
|
-
|
|
3115
|
-
|
|
3168
|
+
const convertedToolImages = convertImagesToKiro(toolResultImages);
|
|
3169
|
+
if (convertedToolImages.length > 0)
|
|
3170
|
+
currentImages = convertedToolImages;
|
|
3116
3171
|
currentContent = "";
|
|
3117
3172
|
} else if (firstMsg?.role === "user") {
|
|
3118
3173
|
currentContent = getContentText(firstMsg);
|
|
@@ -3138,9 +3193,9 @@ ${currentContent}`;
|
|
|
3138
3193
|
uimc.tools = finalTools;
|
|
3139
3194
|
}
|
|
3140
3195
|
if (firstMsg?.role === "user") {
|
|
3141
|
-
const imgs = extractImages(firstMsg);
|
|
3196
|
+
const imgs = convertImagesToKiro(extractImages(firstMsg));
|
|
3142
3197
|
if (imgs.length > 0)
|
|
3143
|
-
currentImages =
|
|
3198
|
+
currentImages = imgs;
|
|
3144
3199
|
}
|
|
3145
3200
|
if (currentContent === "" && currentToolResults.length === 0)
|
|
3146
3201
|
currentContent = EMPTY_CONTENT_PLACEHOLDER;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ns-omp-provider-kiro",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "OMP (oh-my-pi) provider plugin: adds Kiro (AWS CodeWhisperer/Q) models via your kiro-cli login",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"README.md"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"ns-kiro-core": "0.3.
|
|
40
|
+
"ns-kiro-core": "0.3.7"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@oh-my-pi/pi-ai": ">=18.2.0",
|