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
package/dist/history.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// Feature 6: History Management
|
|
2
|
+
export const HISTORY_LIMIT = 850000;
|
|
3
|
+
/** The context window size (in tokens) that HISTORY_LIMIT was calibrated for. */
|
|
4
|
+
export const HISTORY_LIMIT_CONTEXT_WINDOW = 200000;
|
|
5
|
+
/** Maximum combined base64 characters retained for one historical image-bearing turn. */
|
|
6
|
+
export const HISTORY_IMAGE_BASE64_LIMIT = 512 * 1024;
|
|
7
|
+
/**
|
|
8
|
+
* Keep at most the newest bounded image-bearing history entry.
|
|
9
|
+
*
|
|
10
|
+
* Older images are removed to bound request growth. If the newest image set is
|
|
11
|
+
* itself too large, remove it as well rather than substituting an older image
|
|
12
|
+
* that no longer matches a follow-up such as "look at that image again".
|
|
13
|
+
*/
|
|
14
|
+
export function stripHistoryImages(history, keepNewestBounded = true) {
|
|
15
|
+
let newestImageIndex = -1;
|
|
16
|
+
for (let index = history.length - 1; index >= 0; index--) {
|
|
17
|
+
if ((history[index]?.userInputMessage?.images?.length ?? 0) > 0) {
|
|
18
|
+
newestImageIndex = index;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const newestImages = newestImageIndex >= 0 ? history[newestImageIndex]?.userInputMessage?.images : undefined;
|
|
23
|
+
const keepNewest = keepNewestBounded &&
|
|
24
|
+
newestImages !== undefined &&
|
|
25
|
+
newestImages.reduce((size, image) => size + image.source.bytes.length, 0) <= HISTORY_IMAGE_BASE64_LIMIT;
|
|
26
|
+
return history.map((entry, index) => {
|
|
27
|
+
if (!entry.userInputMessage?.images || (index === newestImageIndex && keepNewest))
|
|
28
|
+
return entry;
|
|
29
|
+
const { images: _images, ...rest } = entry.userInputMessage;
|
|
30
|
+
return { ...entry, userInputMessage: { ...rest } };
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export function sanitizeHistory(history) {
|
|
34
|
+
// Strip leading entries that would make the history invalid
|
|
35
|
+
while (history.length > 0 &&
|
|
36
|
+
(!history[0]?.userInputMessage || history[0].userInputMessage.userInputMessageContext?.toolResults))
|
|
37
|
+
history = history.slice(1);
|
|
38
|
+
const result = [];
|
|
39
|
+
for (let i = 0; i < history.length; i++) {
|
|
40
|
+
const m = history[i];
|
|
41
|
+
if (!m)
|
|
42
|
+
continue;
|
|
43
|
+
// Skip assistant messages with no content and no tool uses (e.g. from API errors)
|
|
44
|
+
if (m.assistantResponseMessage && !m.assistantResponseMessage.toolUses && !m.assistantResponseMessage.content)
|
|
45
|
+
continue;
|
|
46
|
+
if (m.assistantResponseMessage?.toolUses) {
|
|
47
|
+
const next = history[i + 1];
|
|
48
|
+
if (next?.userInputMessage?.userInputMessageContext?.toolResults)
|
|
49
|
+
result.push(m);
|
|
50
|
+
}
|
|
51
|
+
else if (m.userInputMessage?.userInputMessageContext?.toolResults) {
|
|
52
|
+
const prev = result[result.length - 1];
|
|
53
|
+
if (prev?.assistantResponseMessage?.toolUses)
|
|
54
|
+
result.push(m);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
result.push(m);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Leading invalid entries already stripped above
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
export function injectSyntheticToolCalls(history) {
|
|
64
|
+
const validIds = new Set();
|
|
65
|
+
for (const entry of history) {
|
|
66
|
+
for (const tu of entry.assistantResponseMessage?.toolUses ?? []) {
|
|
67
|
+
if (tu.toolUseId)
|
|
68
|
+
validIds.add(tu.toolUseId);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const result = [];
|
|
72
|
+
for (const entry of history) {
|
|
73
|
+
const toolResults = entry.userInputMessage?.userInputMessageContext?.toolResults;
|
|
74
|
+
if (toolResults) {
|
|
75
|
+
const orphaned = toolResults.filter((tr) => !validIds.has(tr.toolUseId));
|
|
76
|
+
if (orphaned.length > 0) {
|
|
77
|
+
result.push({
|
|
78
|
+
assistantResponseMessage: {
|
|
79
|
+
content: "Tool calls were made.",
|
|
80
|
+
toolUses: orphaned.map((tr) => ({ name: "unknown_tool", toolUseId: tr.toolUseId, input: {} })),
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
for (const tr of orphaned)
|
|
84
|
+
validIds.add(tr.toolUseId);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
result.push(entry);
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
export function prepareHistory(history, keepNewestBoundedImage = true) {
|
|
92
|
+
return injectSyntheticToolCalls(sanitizeHistory(stripHistoryImages(history, keepNewestBoundedImage)));
|
|
93
|
+
}
|
|
94
|
+
/** Fail before sending rather than silently discarding conversation context. */
|
|
95
|
+
export function assertHistoryWithinLimit(history, limit) {
|
|
96
|
+
const size = JSON.stringify(history).length;
|
|
97
|
+
if (size > limit) {
|
|
98
|
+
throw new Error(`Kiro API error: context_length_exceeded (local history ${size} chars / ${history.length} entries exceeds ${limit}-char limit)`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export function extractToolNamesFromHistory(history) {
|
|
102
|
+
const names = new Set();
|
|
103
|
+
for (const entry of history) {
|
|
104
|
+
for (const tu of entry.assistantResponseMessage?.toolUses ?? []) {
|
|
105
|
+
if (tu.name)
|
|
106
|
+
names.add(tu.name);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return names;
|
|
110
|
+
}
|
|
111
|
+
export function addPlaceholderTools(tools, history) {
|
|
112
|
+
const historyNames = extractToolNamesFromHistory(history);
|
|
113
|
+
if (historyNames.size === 0)
|
|
114
|
+
return tools;
|
|
115
|
+
const existing = new Set(tools.map((t) => t.toolSpecification?.name).filter(Boolean));
|
|
116
|
+
const missing = Array.from(historyNames).filter((n) => !existing.has(n));
|
|
117
|
+
if (missing.length === 0)
|
|
118
|
+
return tools;
|
|
119
|
+
return [
|
|
120
|
+
...tools,
|
|
121
|
+
...missing.map((name) => ({
|
|
122
|
+
toolSpecification: {
|
|
123
|
+
name,
|
|
124
|
+
description: "Tool",
|
|
125
|
+
inputSchema: { json: { type: "object", properties: {} } },
|
|
126
|
+
},
|
|
127
|
+
})),
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAIhC,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC;AACpC,iFAAiF;AACjF,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAC;AACnD,yFAAyF;AACzF,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,GAAG,IAAI,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAA2B,EAAE,iBAAiB,GAAG,IAAI;IACtF,IAAI,gBAAgB,GAAG,CAAC,CAAC,CAAC;IAC1B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EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACzE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,OAAO;QACL,GAAG,KAAK;QACR,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACxB,iBAAiB,EAAE;gBACjB,IAAI;gBACJ,WAAW,EAAE,MAAM;gBACnB,WAAW,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAiB,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE;aACnE;SACF,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { KiroBlockBuffer } from "./blocks.js";
|
|
2
|
+
export { parseBracketToolCalls } from "./bracket-tool-parser.js";
|
|
3
|
+
export { calculateKiroCost } from "./cost.js";
|
|
4
|
+
export { debugEnabled, debugLog, formatSafeError, redactSensitiveText } from "./debug.js";
|
|
5
|
+
export { buildKiroAdditionalModelRequestFields, clampKiroEffort, deriveKiroEffort, fallbackKiroEffort, getKiroEffortConfig, type KiroAdditionalModelRequestFields, type KiroEffortConfig, type KiroEffortField, mapEffortToKiroValue, } from "./effort.js";
|
|
6
|
+
export { getKiroEndpoints, getKiroRegionFromEndpoint, type KiroEndpoints, resolveApiRegion, } from "./endpoints.js";
|
|
7
|
+
export { type KiroWireEvent, parseKiroEvent } from "./event-parser.js";
|
|
8
|
+
export { isKiroToolStructureRule, KIRO_TOOL_STRUCTURE_RULES, KIRO_VALIDATION_MESSAGES, type KiroRepairResult, type KiroToolStructureRule, type KiroValidationError, type KiroValidationResult, KiroValidationRule, kiroConversationEntries, repairKiroConversation, SYNTHETIC_FAILED_TOOL_RESULT_TEXT, validateKiroConversation, validateKiroToolStructure, } from "./history-validator.js";
|
|
9
|
+
export { parseInvokeToolCalls } from "./invoke-tool-parser.js";
|
|
10
|
+
export { getKiroCliCredentials, getKiroCliCredentialsAllowExpired, getKiroCliDbPath, getKiroCliSocialToken, getKiroCliSocialTokenAllowExpired, refreshViaKiroCli, saveKiroCliCredentials, } from "./kiro-cli.js";
|
|
11
|
+
export { getKiroIdeCredentials, getKiroIdeCredentialsAllowExpired } from "./kiro-ide.js";
|
|
12
|
+
export { fetchKiroModelCatalog, type KiroCatalogModel, type KiroManagementAuth, KiroManagementHttpError, resolveKiroProfileArn, } from "./management.js";
|
|
13
|
+
export { applyEffortLadder, getCachedModels, isCacheStale, KIRO_MANAGEMENT_CACHE_PATH, KIRO_MODEL_IDS, type KiroModel, kiroModels, loadCachedModelIds, mapKiroCatalogModels, resolveKiroModel, updateKiroModelsCache, } from "./models.js";
|
|
14
|
+
export { isApiKey, isExpired, type KiroAuthMethod, type KiroCredentials, kiroAuthHeaders, loginKiroWithApiKey, refreshKiroToken, resolveKiroCredentials, } from "./oauth.js";
|
|
15
|
+
export { CAPACITY_PATTERN, isCapacityError, isNonRetryableBodyError, isTooBigError, KIRO_REASON_CODES, type KiroReasonCode, NON_RETRYABLE_BODY_PATTERNS, TOO_BIG_PATTERNS, } from "./retry.js";
|
|
16
|
+
export { type KiroStreamRequest, resetProfileArnCache, streamKiro } from "./stream.js";
|
|
17
|
+
export { ThinkingTagParser } from "./thinking-parser.js";
|
|
18
|
+
export { countTokens } from "./tokenizer.js";
|
|
19
|
+
export { buildHistory, EMPTY_CONTENT_PLACEHOLDER, type KiroHistoryEntry, type KiroImage, type KiroToolResult, type KiroToolSpec, type KiroToolUse, type KiroUserInputMessage, normalizeMessages, relocateDisplacedToolResults, sanitizeSurrogates, toKiroToolUseId, } from "./transform.js";
|
|
20
|
+
export { TRUNCATION_NOTICE, wasPreviousResponseTruncated } from "./truncation.js";
|
|
21
|
+
export * from "./types.js";
|
|
22
|
+
export { fetchKiroUsage, type KiroProviderUsage, type KiroProviderUsageBucket } from "./usage.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Public surface of the host-neutral Kiro core.
|
|
2
|
+
export { KiroBlockBuffer } from "./blocks.js";
|
|
3
|
+
export { parseBracketToolCalls } from "./bracket-tool-parser.js";
|
|
4
|
+
export { calculateKiroCost } from "./cost.js";
|
|
5
|
+
export { debugEnabled, debugLog, formatSafeError, redactSensitiveText } from "./debug.js";
|
|
6
|
+
export { buildKiroAdditionalModelRequestFields, clampKiroEffort, deriveKiroEffort, fallbackKiroEffort, getKiroEffortConfig, mapEffortToKiroValue, } from "./effort.js";
|
|
7
|
+
export { getKiroEndpoints, getKiroRegionFromEndpoint, resolveApiRegion, } from "./endpoints.js";
|
|
8
|
+
export { parseKiroEvent } from "./event-parser.js";
|
|
9
|
+
export { isKiroToolStructureRule, KIRO_TOOL_STRUCTURE_RULES, KIRO_VALIDATION_MESSAGES, KiroValidationRule, kiroConversationEntries, repairKiroConversation, SYNTHETIC_FAILED_TOOL_RESULT_TEXT, validateKiroConversation, validateKiroToolStructure, } from "./history-validator.js";
|
|
10
|
+
export { parseInvokeToolCalls } from "./invoke-tool-parser.js";
|
|
11
|
+
export { getKiroCliCredentials, getKiroCliCredentialsAllowExpired, getKiroCliDbPath, getKiroCliSocialToken, getKiroCliSocialTokenAllowExpired, refreshViaKiroCli, saveKiroCliCredentials, } from "./kiro-cli.js";
|
|
12
|
+
export { getKiroIdeCredentials, getKiroIdeCredentialsAllowExpired } from "./kiro-ide.js";
|
|
13
|
+
export { fetchKiroModelCatalog, KiroManagementHttpError, resolveKiroProfileArn, } from "./management.js";
|
|
14
|
+
export { applyEffortLadder, getCachedModels, isCacheStale, KIRO_MANAGEMENT_CACHE_PATH, KIRO_MODEL_IDS, kiroModels, loadCachedModelIds, mapKiroCatalogModels, resolveKiroModel, updateKiroModelsCache, } from "./models.js";
|
|
15
|
+
export { isApiKey, isExpired, kiroAuthHeaders, loginKiroWithApiKey, refreshKiroToken, resolveKiroCredentials, } from "./oauth.js";
|
|
16
|
+
// Kiro's own error vocabulary and the predicates this core classifies it with.
|
|
17
|
+
// Published so consumers can interpret a reason code without an error instance
|
|
18
|
+
// in hand (a persisted log line, say) instead of hardcoding copies of the
|
|
19
|
+
// literals, which drift when the service adds a code.
|
|
20
|
+
export { CAPACITY_PATTERN, isCapacityError, isNonRetryableBodyError, isTooBigError, KIRO_REASON_CODES, NON_RETRYABLE_BODY_PATTERNS, TOO_BIG_PATTERNS, } from "./retry.js";
|
|
21
|
+
export { resetProfileArnCache, streamKiro } from "./stream.js";
|
|
22
|
+
export { ThinkingTagParser } from "./thinking-parser.js";
|
|
23
|
+
export { countTokens } from "./tokenizer.js";
|
|
24
|
+
export { buildHistory, EMPTY_CONTENT_PLACEHOLDER, normalizeMessages, relocateDisplacedToolResults, sanitizeSurrogates, toKiroToolUseId, } from "./transform.js";
|
|
25
|
+
export { TRUNCATION_NOTICE, wasPreviousResponseTruncated } from "./truncation.js";
|
|
26
|
+
export * from "./types.js";
|
|
27
|
+
export { fetchKiroUsage } from "./usage.js";
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC1F,OAAO,EACL,qCAAqC,EACrC,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EAInB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EAEzB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAs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AiB,EACjB,4BAA4B,EAC5B,kBAAkB,EAClB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAClF,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAwD,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface InvokeToolCall {
|
|
2
|
+
toolUseId: string;
|
|
3
|
+
name: string;
|
|
4
|
+
arguments: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export interface InvokeParseResult {
|
|
7
|
+
toolCalls: InvokeToolCall[];
|
|
8
|
+
cleanedText: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Recovers tool calls that a model emitted as XML text instead of as structured
|
|
12
|
+
* tool-use frames. Mirrors {@link parseBracketToolCalls}: returns the recovered
|
|
13
|
+
* calls plus the text with each consumed `<invoke>` span spliced out. A block
|
|
14
|
+
* that cannot be parsed in full is left in the text untouched.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseInvokeToolCalls(text: string): InvokeParseResult;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// ABOUTME: Extracts XML-dialect tool calls from content text as a fallback.
|
|
2
|
+
// ABOUTME: Parses <invoke name="..."><parameter name="...">value</parameter></invoke> blocks.
|
|
3
|
+
const INVOKE_OPEN_ANCHORED = /^<invoke name="([\w-]+)">/;
|
|
4
|
+
const INVOKE_OPEN_SEARCH = "<invoke name=";
|
|
5
|
+
const INVOKE_OPEN_ANYWHERE = /<invoke name="[\w-]+">/;
|
|
6
|
+
const PARAM_OPEN_ANCHORED = /^<parameter name="([^"]*)">/;
|
|
7
|
+
const INVOKE_CLOSE = "</invoke>";
|
|
8
|
+
const PARAM_CLOSE = "</parameter>";
|
|
9
|
+
const FENCE = "```";
|
|
10
|
+
/**
|
|
11
|
+
* Byte ranges covered by an *opened* fenced code block. Fences are counted
|
|
12
|
+
* pairwise; a trailing unclosed fence extends to end of text. Used to reject
|
|
13
|
+
* `<invoke>` blocks that appear inside documentation rather than as a real
|
|
14
|
+
* (misrouted) tool call — model output that discusses this very bug quotes the
|
|
15
|
+
* dialect verbatim, and executing a command out of a code sample would be
|
|
16
|
+
* strictly worse than not recovering it.
|
|
17
|
+
*/
|
|
18
|
+
function fencedRanges(text) {
|
|
19
|
+
const ranges = [];
|
|
20
|
+
let searchFrom = 0;
|
|
21
|
+
while (true) {
|
|
22
|
+
const open = text.indexOf(FENCE, searchFrom);
|
|
23
|
+
if (open < 0)
|
|
24
|
+
break;
|
|
25
|
+
const close = text.indexOf(FENCE, open + FENCE.length);
|
|
26
|
+
if (close < 0) {
|
|
27
|
+
ranges.push({ start: open, end: text.length });
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
ranges.push({ start: open, end: close + FENCE.length });
|
|
31
|
+
searchFrom = close + FENCE.length;
|
|
32
|
+
}
|
|
33
|
+
return ranges;
|
|
34
|
+
}
|
|
35
|
+
/** Thrown when a block's markup cannot be attributed unambiguously. */
|
|
36
|
+
class AmbiguousDialectError extends Error {
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Parses one `<invoke>` block starting at `start`, or returns null if the
|
|
40
|
+
* markup there is not a complete, well-formed block.
|
|
41
|
+
*
|
|
42
|
+
* The block end is found structurally — by walking parameters — never by
|
|
43
|
+
* searching for `</invoke>`. A naive search would stop at a `</invoke>` that
|
|
44
|
+
* happens to sit inside a parameter value, truncating the value and then
|
|
45
|
+
* accepting the truncation as if it were the whole argument.
|
|
46
|
+
*
|
|
47
|
+
* Strict by design: the body must consist of nothing but whitespace and
|
|
48
|
+
* well-formed `<parameter name="...">...</parameter>` elements. Any other
|
|
49
|
+
* content (prose, an ellipsis placeholder, a stray tag) rejects the block,
|
|
50
|
+
* because a partial parse would either fabricate arguments or half-strip the
|
|
51
|
+
* text.
|
|
52
|
+
*/
|
|
53
|
+
function parseBlockAt(text, start) {
|
|
54
|
+
const openMatch = INVOKE_OPEN_ANCHORED.exec(text.substring(start));
|
|
55
|
+
if (!openMatch)
|
|
56
|
+
return null;
|
|
57
|
+
const args = {};
|
|
58
|
+
let cursor = start + openMatch[0].length;
|
|
59
|
+
while (true) {
|
|
60
|
+
const remainder = text.substring(cursor);
|
|
61
|
+
const leadingWhitespace = remainder.length - remainder.trimStart().length;
|
|
62
|
+
if (leadingWhitespace > 0)
|
|
63
|
+
cursor += leadingWhitespace;
|
|
64
|
+
if (text.startsWith(INVOKE_CLOSE, cursor)) {
|
|
65
|
+
const end = cursor + INVOKE_CLOSE.length;
|
|
66
|
+
// A consumed block must end cleanly. This rejects a literal
|
|
67
|
+
// `</parameter></invoke>` inside a value: accepting that prefix would
|
|
68
|
+
// execute a silently truncated command and leave quote/tag debris behind.
|
|
69
|
+
if (end < text.length && !/\s/.test(text[end]))
|
|
70
|
+
return null;
|
|
71
|
+
return { name: openMatch[1], arguments: args, end };
|
|
72
|
+
}
|
|
73
|
+
const paramMatch = PARAM_OPEN_ANCHORED.exec(text.substring(cursor));
|
|
74
|
+
if (!paramMatch)
|
|
75
|
+
return null;
|
|
76
|
+
const valueStart = cursor + paramMatch[0].length;
|
|
77
|
+
const valueEnd = text.indexOf(PARAM_CLOSE, valueStart);
|
|
78
|
+
if (valueEnd < 0)
|
|
79
|
+
return null;
|
|
80
|
+
const value = text.substring(valueStart, valueEnd);
|
|
81
|
+
// A parameter value that itself contains an `<invoke>` open tag makes the
|
|
82
|
+
// block unattributable: nested markup could otherwise be harvested as a
|
|
83
|
+
// call the model never made.
|
|
84
|
+
if (INVOKE_OPEN_ANYWHERE.test(value))
|
|
85
|
+
throw new AmbiguousDialectError();
|
|
86
|
+
// Values in this dialect are raw text, not JSON. Preserve every byte:
|
|
87
|
+
// parsing or trimming can silently change a command that will be executed.
|
|
88
|
+
args[paramMatch[1]] = value;
|
|
89
|
+
cursor = valueEnd + PARAM_CLOSE.length;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Recovers tool calls that a model emitted as XML text instead of as structured
|
|
94
|
+
* tool-use frames. Mirrors {@link parseBracketToolCalls}: returns the recovered
|
|
95
|
+
* calls plus the text with each consumed `<invoke>` span spliced out. A block
|
|
96
|
+
* that cannot be parsed in full is left in the text untouched.
|
|
97
|
+
*/
|
|
98
|
+
export function parseInvokeToolCalls(text) {
|
|
99
|
+
const toolCalls = [];
|
|
100
|
+
const removals = [];
|
|
101
|
+
const fences = fencedRanges(text);
|
|
102
|
+
const untouched = { toolCalls: [], cleanedText: text };
|
|
103
|
+
let cursor = 0;
|
|
104
|
+
while (cursor < text.length) {
|
|
105
|
+
const openStart = text.indexOf(INVOKE_OPEN_SEARCH, cursor);
|
|
106
|
+
if (openStart < 0)
|
|
107
|
+
break;
|
|
108
|
+
const containingFence = fences.find((range) => openStart >= range.start && openStart < range.end);
|
|
109
|
+
if (containingFence) {
|
|
110
|
+
cursor = containingFence.end;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
let block;
|
|
114
|
+
try {
|
|
115
|
+
block = parseBlockAt(text, openStart);
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
if (e instanceof AmbiguousDialectError)
|
|
119
|
+
return untouched;
|
|
120
|
+
throw e;
|
|
121
|
+
}
|
|
122
|
+
// A malformed opener can enclose later valid-looking markup as argument
|
|
123
|
+
// data. Without a structural end, independence cannot be proven; abandon
|
|
124
|
+
// all recovery rather than execute an embedded call.
|
|
125
|
+
if (block === null)
|
|
126
|
+
return untouched;
|
|
127
|
+
// If apparent block end truncated a raw value containing closing-tag text,
|
|
128
|
+
// real outer closers remain later in prose. Never execute that prefix.
|
|
129
|
+
const nextOpen = text.indexOf(INVOKE_OPEN_SEARCH, block.end);
|
|
130
|
+
const interstitialEnd = nextOpen < 0 ? text.length : nextOpen;
|
|
131
|
+
const interstitial = text.substring(block.end, interstitialEnd);
|
|
132
|
+
if (interstitial.includes(PARAM_CLOSE) || interstitial.includes(INVOKE_CLOSE))
|
|
133
|
+
return untouched;
|
|
134
|
+
toolCalls.push({ toolUseId: crypto.randomUUID(), name: block.name, arguments: block.arguments });
|
|
135
|
+
removals.push({ start: openStart, end: block.end });
|
|
136
|
+
// Resume past the whole block: its parameter values are data, not markup.
|
|
137
|
+
// With the nesting bail above this is belt-and-braces — any value holding a
|
|
138
|
+
// full open tag has already abandoned the parse — so no test can currently
|
|
139
|
+
// distinguish it from resuming at the search hit. Kept because it is the
|
|
140
|
+
// structurally correct resume point, and the bail is the only thing making
|
|
141
|
+
// the weaker one safe.
|
|
142
|
+
cursor = block.end;
|
|
143
|
+
}
|
|
144
|
+
// Splice out consumed spans in reverse order so earlier indices stay valid.
|
|
145
|
+
let cleanedText = text;
|
|
146
|
+
for (let i = removals.length - 1; i >= 0; i--) {
|
|
147
|
+
const { start, end } = removals[i];
|
|
148
|
+
cleanedText = cleanedText.substring(0, start) + cleanedText.substring(end);
|
|
149
|
+
}
|
|
150
|
+
return { toolCalls, cleanedText };
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=invoke-tool-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoke-tool-parser.js","sourceRoot":"","sources":["../src/invoke-tool-parser.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,8FAA8F;AAa9F,MAAM,oBAAoB,GAAG,2BAA2B,CAAC;AACzD,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAC3C,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AACtD,MAAM,mBAAmB,GAAG,6BAA6B,CAAC;AAC1D,MAAM,YAAY,GAAG,WAAW,CAAC;AACjC,MAAM,WAAW,GAAG,cAAc,CAAC;AACnC,MAAM,KAAK,GAAG,KAAK,CAAC;AASpB;;;;;;;GAOG;AACH,SAAS,YAAY,CAAC,IAAY;IAChC,MAAM,MAAM,GAA0C,EAAE,CAAC;IACzD,IAAI,UAAU,GAAG,CAAC,C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|
+
export declare function getKiroCliDbPath(): string | undefined;
|
|
3
|
+
export declare function getKiroCliCredentials(): KiroCredentials | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Like getKiroCliCredentials but returns credentials even when the access token
|
|
6
|
+
* is expired, as long as a refresh token exists. Used to attempt a token refresh
|
|
7
|
+
* before falling back to the full device code login flow.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getKiroCliCredentialsAllowExpired(): KiroCredentials | undefined;
|
|
10
|
+
declare function tryKiroCliToken(dbPath: string, tokenKey: string, authMethod: KiroAuthMethod, allowExpired?: boolean): KiroCredentials | undefined;
|
|
11
|
+
export { tryKiroCliToken };
|
|
12
|
+
/**
|
|
13
|
+
* Get the social token (Google/GitHub) from kiro-cli if available.
|
|
14
|
+
* Returns undefined if no valid social token exists.
|
|
15
|
+
* This is used to prefer social login when the user has logged in that way.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getKiroCliSocialToken(): KiroCredentials | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Like getKiroCliSocialToken but returns credentials even when the access token
|
|
20
|
+
* is expired, as long as a refresh token exists.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getKiroCliSocialTokenAllowExpired(): KiroCredentials | undefined;
|
|
23
|
+
export declare function saveKiroCliCredentials(creds: KiroCredentials): void;
|
|
24
|
+
/**
|
|
25
|
+
* Ask kiro-cli to refresh its own tokens via `kiro-cli debug refresh-auth-token`,
|
|
26
|
+
* then re-read the SQLite DB for fresh credentials.
|
|
27
|
+
*
|
|
28
|
+
* Returns refreshed credentials on success, or undefined if kiro-cli is not
|
|
29
|
+
* installed, the command fails, or the DB still has no valid tokens afterward.
|
|
30
|
+
*/
|
|
31
|
+
export declare function refreshViaKiroCli(): KiroCredentials | undefined;
|