@javargasm/opencode-kiro-auth 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/README.md +190 -0
- package/dist/dashboard-stats.d.ts +22 -0
- package/dist/dashboard-stats.d.ts.map +1 -0
- package/dist/dashboard-ui.d.ts +2 -0
- package/dist/dashboard-ui.d.ts.map +1 -0
- package/dist/debug.d.ts +12 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/event-parser.d.ts +61 -0
- package/dist/event-parser.d.ts.map +1 -0
- package/dist/health.d.ts +6 -0
- package/dist/health.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3647 -0
- package/dist/kiro-cli-sync.d.ts +16 -0
- package/dist/kiro-cli-sync.d.ts.map +1 -0
- package/dist/kiro-defaults.d.ts +25 -0
- package/dist/kiro-defaults.d.ts.map +1 -0
- package/dist/models.d.ts +104 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/oauth.d.ts +46 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/server.d.ts +8 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/stream.d.ts +29 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/thinking-parser.d.ts +24 -0
- package/dist/thinking-parser.d.ts.map +1 -0
- package/dist/tokenizer.d.ts +2 -0
- package/dist/tokenizer.d.ts.map +1 -0
- package/dist/transform.d.ts +119 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/types.d.ts +180 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface KiroCliCredentials {
|
|
2
|
+
accessToken: string;
|
|
3
|
+
refreshToken: string;
|
|
4
|
+
clientId?: string;
|
|
5
|
+
clientSecret?: string;
|
|
6
|
+
region: string;
|
|
7
|
+
authMethod: "idc" | "desktop";
|
|
8
|
+
email?: string;
|
|
9
|
+
profileArn?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Import credentials from Kiro CLI DB first, then SSO cache fallback.
|
|
13
|
+
* Returns null if neither source yields valid credentials. Never throws.
|
|
14
|
+
*/
|
|
15
|
+
export declare function importFromKiroCli(): Promise<KiroCliCredentials | null>;
|
|
16
|
+
//# sourceMappingURL=kiro-cli-sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kiro-cli-sync.d.ts","sourceRoot":"","sources":["../src/kiro-cli-sync.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,KAAK,GAAG,SAAS,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAgND;;;GAGG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAI5E"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synthetic history seed injected at the start of every conversation.
|
|
3
|
+
* The real Kiro CLI sends this exact pair before real history.
|
|
4
|
+
* Use `{{modelId}}` placeholder — replaced at runtime with the dot-format model id.
|
|
5
|
+
*/
|
|
6
|
+
export declare const SYSTEM_SEED_INSTRUCTION: string;
|
|
7
|
+
export declare const SYSTEM_SEED_ACK: string;
|
|
8
|
+
/**
|
|
9
|
+
* Every tool schema in the real Kiro CLI includes this extra property.
|
|
10
|
+
* Injected by `convertToolsToKiro()` into each tool's input schema.
|
|
11
|
+
*/
|
|
12
|
+
export declare const TOOL_PURPOSE_FIELD: {
|
|
13
|
+
readonly type: "string";
|
|
14
|
+
readonly description: "A brief explanation why you are making this tool use.";
|
|
15
|
+
};
|
|
16
|
+
/** Map `process.platform` to Kiro's `operatingSystem` values. */
|
|
17
|
+
export declare function resolveOS(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Context usage percentage at which pi-kiro forces Pi's overflow detection.
|
|
20
|
+
* When Kiro reports >= this value, `usage.input` is inflated above
|
|
21
|
+
* `contextWindow` so Pi's `isContextOverflow()` returns true and triggers
|
|
22
|
+
* compaction before hitting a 413.
|
|
23
|
+
*/
|
|
24
|
+
export declare const COMPACTION_THRESHOLD_PCT = 95;
|
|
25
|
+
//# sourceMappingURL=kiro-defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kiro-defaults.d.ts","sourceRoot":"","sources":["../src/kiro-defaults.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,QAKG,CAAC;AAExC,eAAO,MAAM,eAAe,QAE0D,CAAC;AAEvF;;;GAGG;AACH,eAAO,MAAM,kBAAkB;;;CAGrB,CAAC;AAEX,iEAAiE;AACjE,wBAAgB,SAAS,IAAI,MAAM,CASlC;AAED;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,KAAK,CAAC"}
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/** Canonical Kiro API IDs (dot form) accepted by the server. */
|
|
2
|
+
export declare const KIRO_MODEL_IDS: Set<string>;
|
|
3
|
+
/** Convert Kiro API's dot form to pi's dash form (e.g. 4.6 → 4-6). */
|
|
4
|
+
export declare function dotToDash(modelId: string): string;
|
|
5
|
+
/** Convert pi's dash form to the Kiro API's dot form (e.g. 4-6 → 4.6). */
|
|
6
|
+
export declare function resolveKiroModel(modelId: string): string;
|
|
7
|
+
export declare function resolveApiRegion(ssoRegion: string | undefined): string;
|
|
8
|
+
type Input = ("text" | "image")[];
|
|
9
|
+
export interface KiroModel {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
api: "kiro-api";
|
|
13
|
+
provider: "kiro";
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
reasoning: boolean;
|
|
16
|
+
input: Input;
|
|
17
|
+
cost: {
|
|
18
|
+
input: number;
|
|
19
|
+
output: number;
|
|
20
|
+
cacheRead: number;
|
|
21
|
+
cacheWrite: number;
|
|
22
|
+
};
|
|
23
|
+
contextWindow: number;
|
|
24
|
+
maxTokens: number;
|
|
25
|
+
/** Optional per-model override for the first-token timeout (ms). */
|
|
26
|
+
firstTokenTimeout?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Upstream is expected to hide reasoning from clients — tags and
|
|
29
|
+
* native reasoning events should be absent. When set:
|
|
30
|
+
*
|
|
31
|
+
* - The `<thinking_mode>` system-prompt directive is skipped
|
|
32
|
+
* (the provider ignores it for these models).
|
|
33
|
+
* - A redacted-thinking breadcrumb is emitted lazily — only if
|
|
34
|
+
* no content or tool-call arrives within
|
|
35
|
+
* `HIDDEN_REASONING_COUNTDOWN_MS`. Fast responses emit no
|
|
36
|
+
* thinking block; slow responses get a single "Reasoning
|
|
37
|
+
* hidden by provider" marker so downstream UIs can show a
|
|
38
|
+
* "reasoning hidden" marker via the standard event stream contract.
|
|
39
|
+
*
|
|
40
|
+
* Does NOT gate the ThinkingTagParser — that runs unconditionally
|
|
41
|
+
* when `reasoning` is enabled. The adaptive-thinking policy is
|
|
42
|
+
* advisory: some models (Opus 4.7) intermittently leak
|
|
43
|
+
* `<thinking>...</thinking>` tags inline, and the parser handles
|
|
44
|
+
* them correctly when they do arrive.
|
|
45
|
+
*
|
|
46
|
+
* Applies to Claude Opus 4.7, which flipped Anthropic's
|
|
47
|
+
* adaptive-thinking default from "summarized" to "omitted".
|
|
48
|
+
* See https://docs.anthropic.com/en/docs/build-with-claude/adaptive-thinking
|
|
49
|
+
*/
|
|
50
|
+
reasoningHidden?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Effort levels supported by this model for adaptive thinking.
|
|
53
|
+
* Sourced from `ListAvailableModels` → `additionalModelRequestFieldsSchema`.
|
|
54
|
+
* When present, the effort is sent via `additionalModelRequestFields.output_config.effort`
|
|
55
|
+
* in the GenerateAssistantResponse request body.
|
|
56
|
+
*/
|
|
57
|
+
supportedEfforts?: string[];
|
|
58
|
+
/** Whether the model supports `thinking` block configuration. */
|
|
59
|
+
supportsThinkingConfig?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export declare const kiroModels: KiroModel[];
|
|
62
|
+
export interface KiroApiModel {
|
|
63
|
+
modelId: string;
|
|
64
|
+
modelName: string;
|
|
65
|
+
tokenLimits?: {
|
|
66
|
+
maxInputTokens?: number;
|
|
67
|
+
maxOutputTokens?: number;
|
|
68
|
+
};
|
|
69
|
+
supportedInputTypes?: string[];
|
|
70
|
+
/** Schema for extra fields accepted by GenerateAssistantResponse. */
|
|
71
|
+
additionalModelRequestFieldsSchema?: {
|
|
72
|
+
properties?: {
|
|
73
|
+
output_config?: {
|
|
74
|
+
properties?: {
|
|
75
|
+
effort?: {
|
|
76
|
+
enum?: string[];
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
thinking?: {
|
|
81
|
+
properties?: {
|
|
82
|
+
type?: {
|
|
83
|
+
enum?: string[];
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Fetch the list of models actually available for this account from Kiro.
|
|
92
|
+
* Filters out "auto" — it appears in ListAvailableModels but is rejected
|
|
93
|
+
* by GenerateAssistantResponse with INVALID_MODEL_ID.
|
|
94
|
+
*/
|
|
95
|
+
export declare function fetchAvailableModels(accessToken: string, apiRegion: string, fallbackProfileArn?: string): Promise<KiroApiModel[]>;
|
|
96
|
+
/**
|
|
97
|
+
* Build pi model definitions from the Kiro ListAvailableModels API response.
|
|
98
|
+
* Adds any new model IDs dynamically to KIRO_MODEL_IDS so resolveKiroModel passes.
|
|
99
|
+
*/
|
|
100
|
+
export declare function buildModelsFromApi(apiModels: KiroApiModel[]): KiroModel[];
|
|
101
|
+
export declare function getCachedDynamicModels(): KiroModel[] | null;
|
|
102
|
+
export declare function setCachedDynamicModels(models: KiroModel[] | null): void;
|
|
103
|
+
export {};
|
|
104
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAQA,gEAAgE;AAChE,eAAO,MAAM,cAAc,aAuBzB,CAAC;AAGH,sEAAsE;AACtE,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,0EAA0E;AAC1E,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMxD;AA8BD,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAGtE;AAaD,KAAK,KAAK,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;AAIlC,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,UAAU,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/E,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;OAKG;I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0,0 +1,46 @@
|
|
|
1
|
+
export declare const BUILDER_ID_START_URL = "https://view.awsapps.com/start";
|
|
2
|
+
export declare const BUILDER_ID_REGION = "us-east-1";
|
|
3
|
+
export declare const SSO_SCOPES: string[];
|
|
4
|
+
/** Regions probed when an IdC user leaves the region blank. */
|
|
5
|
+
export declare const IDC_PROBE_REGIONS: string[];
|
|
6
|
+
/** 5-minute safety buffer subtracted from real token expiry. */
|
|
7
|
+
export declare const EXPIRES_BUFFER_MS: number;
|
|
8
|
+
export interface KiroCredentials {
|
|
9
|
+
refresh: string;
|
|
10
|
+
access: string;
|
|
11
|
+
expires: number;
|
|
12
|
+
clientId: string;
|
|
13
|
+
clientSecret: string;
|
|
14
|
+
region: string;
|
|
15
|
+
authMethod: "builder-id" | "idc" | "desktop";
|
|
16
|
+
}
|
|
17
|
+
export interface DeviceAuthResponse {
|
|
18
|
+
verificationUri: string;
|
|
19
|
+
verificationUriComplete: string;
|
|
20
|
+
userCode: string;
|
|
21
|
+
deviceCode: string;
|
|
22
|
+
interval: number;
|
|
23
|
+
expiresIn: number;
|
|
24
|
+
}
|
|
25
|
+
interface TokenResponse {
|
|
26
|
+
error?: string;
|
|
27
|
+
accessToken?: string;
|
|
28
|
+
refreshToken?: string;
|
|
29
|
+
expiresIn?: number;
|
|
30
|
+
}
|
|
31
|
+
/** Promise-based delay that rejects promptly if the signal fires. */
|
|
32
|
+
export declare function abortableDelay(ms: number, signal?: AbortSignal): Promise<void>;
|
|
33
|
+
export declare function tryRegisterAndAuthorize(startUrl: string, region: string): Promise<{
|
|
34
|
+
clientId: string;
|
|
35
|
+
clientSecret: string;
|
|
36
|
+
oidcEndpoint: string;
|
|
37
|
+
devAuth: DeviceAuthResponse;
|
|
38
|
+
} | null>;
|
|
39
|
+
export declare function pollForToken(oidcEndpoint: string, clientId: string, clientSecret: string, devAuth: DeviceAuthResponse, signal: AbortSignal | undefined): Promise<TokenResponse>;
|
|
40
|
+
export declare function refreshKiroToken(refreshTokenPacked: string, region: string, authMethod: "builder-id" | "idc" | "desktop"): Promise<{
|
|
41
|
+
access: string;
|
|
42
|
+
refresh: string;
|
|
43
|
+
expires: number;
|
|
44
|
+
}>;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=oauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,oBAAoB,mCAAmC,CAAC;AACrE,eAAO,MAAM,iBAAiB,cAAc,CAAC;AAC7C,eAAO,MAAM,UAAU,UAMtB,CAAC;AAEF,+DAA+D;AAC/D,eAAO,MAAM,iBAAiB,UAW7B,CAAC;AAEF,gEAAgE;AAChE,eAAO,MAAM,iBAAiB,QAAgB,CAAC;AAE/C,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,YAAY,GAAG,KAAK,GAAG,SAAS,CAAC;CAC9C;AAED,MAAM,WAAW,kBAAkB;IACjC,eAAe,EAAE,MAAM,CAAC;IACxB,uBAAuB,EAAE,MAAM,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAOD,UAAU,aAAa;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qEAAqE;AACrE,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAa9E;AAED,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;IACT,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,kBAAkB,CAAC;CAC7B,GAAG,IAAI,CAAC,CAkCR;AAED,wBAAsB,YAAY,CAChC,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,kBAAkB,EAC3B,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,aAAa,CAAC,CA8CxB;AAED,wBAAsB,gBAAgB,CACpC,kBAAkB,EAAE,MAAM,EAC1B,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,YAAY,GAAG,KAAK,GAAG,SAAS,GAC3C,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CA6D/D"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Server } from "bun";
|
|
2
|
+
export declare function getAuthRegion(): string;
|
|
3
|
+
/** Called once at plugin startup from index.ts */
|
|
4
|
+
export declare function initGatewayAuth(): Promise<void>;
|
|
5
|
+
/** @internal — test helper to inject credentials without Kiro CLI */
|
|
6
|
+
export declare function _seedCredentials(token: string, region?: string): void;
|
|
7
|
+
export declare function startGatewayServer(port?: number): Promise<Server<any>>;
|
|
8
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AA2BlC,wBAAgB,aAAa,IAAI,MAAM,CAA0C;AAEjF,kDAAkD;AAClD,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAuCrD;AAsBD,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,SAAc,QAQnE;AAwBD,wBAAgB,kBAAkB,CAAC,IAAI,GAAE,MAAU,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAobzE"}
|
package/dist/stream.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Api, Context, Model, SimpleStreamOptions } from "./types";
|
|
2
|
+
import { AssistantMessageEventStream } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* How long to wait after `start` before emitting the lazy
|
|
5
|
+
* hidden-reasoning breadcrumb. Short enough that the marker appears
|
|
6
|
+
* exactly when a wait starts feeling palpable, long enough that fast
|
|
7
|
+
* responses never flash it. Content / tool-call events cancel the
|
|
8
|
+
* timer, so the breadcrumb only fires when nothing else arrives in
|
|
9
|
+
* time.
|
|
10
|
+
*/
|
|
11
|
+
export declare const HIDDEN_REASONING_COUNTDOWN_MS = 2000;
|
|
12
|
+
/**
|
|
13
|
+
* Reset cache state. Pass `skipResolution: true` to disable profileArn lookup
|
|
14
|
+
* entirely (useful for tests that don't mock ListAvailableProfiles).
|
|
15
|
+
* Production code should never pass true — cache is reset on logout/refresh
|
|
16
|
+
* without disabling resolution.
|
|
17
|
+
*/
|
|
18
|
+
export declare function resetProfileArnCache(skipResolution?: boolean): void;
|
|
19
|
+
/**
|
|
20
|
+
* Pre-seed the profileArn cache for a given endpoint. When set,
|
|
21
|
+
* `resolveProfileArn` returns the seeded value without hitting the
|
|
22
|
+
* management endpoint. Use this to inject a known profileArn from
|
|
23
|
+
* external sources (e.g. Kiro CLI auth.json) as a fallback when the
|
|
24
|
+
* management API returns 400.
|
|
25
|
+
*/
|
|
26
|
+
export declare function seedProfileArn(endpoint: string, arn: string): void;
|
|
27
|
+
export declare function resolveProfileArn(accessToken: string, endpoint: string): Promise<string | undefined>;
|
|
28
|
+
export declare function streamKiro(model: Model<Api>, context: Context, options?: SimpleStreamOptions): AssistantMessageEventStream;
|
|
29
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,GAAG,EAEH,OAAO,EAEP,KAAK,EACL,mBAAmB,EAKpB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,2BAA2B,EAAiB,MAAM,SAAS,CAAC;AA6FrE;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6B,OAAO,CAAC;AAgDlD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,cAAc,UAAQ,GAAG,IAAI,CAGjE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAElE;AAED,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAuC1G;AA2DD,wBAAgB,UAAU,CACxB,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,2BAA2B,CAg0B7B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AssistantMessage, AssistantMessageEventStream } from "./types";
|
|
2
|
+
export declare const THINKING_START_TAG = "<thinking>";
|
|
3
|
+
export declare const THINKING_END_TAG = "</thinking>";
|
|
4
|
+
export declare class ThinkingTagParser {
|
|
5
|
+
private output;
|
|
6
|
+
private stream;
|
|
7
|
+
private textBuffer;
|
|
8
|
+
private inThinking;
|
|
9
|
+
private thinkingExtracted;
|
|
10
|
+
private thinkingBlockIndex;
|
|
11
|
+
private textBlockIndex;
|
|
12
|
+
private lastTextBlockIndex;
|
|
13
|
+
private activeEndTag;
|
|
14
|
+
constructor(output: AssistantMessage, stream: AssistantMessageEventStream);
|
|
15
|
+
processChunk(chunk: string): void;
|
|
16
|
+
finalize(): void;
|
|
17
|
+
getTextBlockIndex(): number | null;
|
|
18
|
+
private processBeforeThinking;
|
|
19
|
+
private processInsideThinking;
|
|
20
|
+
private processAfterThinking;
|
|
21
|
+
private emitText;
|
|
22
|
+
private emitThinking;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=thinking-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thinking-parser.d.ts","sourceRoot":"","sources":["../src/thinking-parser.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAA2B,EAAgC,MAAM,SAAS,CAAC;AAG3G,eAAO,MAAM,kBAAkB,eAAe,CAAC;AAC/C,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AA2B9C,qBAAa,iBAAiB;IAU1B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IAVhB,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,kBAAkB,CAAuB;IACjD,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,kBAAkB,CAAuB;IACjD,OAAO,CAAC,YAAY,CAA4B;gBAGtC,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,2BAA2B;IAG7C,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IA4BjC,QAAQ,IAAI,IAAI;IAkChB,iBAAiB,IAAI,MAAM,GAAG,IAAI;IAIlC,OAAO,CAAC,qBAAqB;IAgC7B,OAAO,CAAC,qBAAqB;IAmC7B,OAAO,CAAC,oBAAoB;IAK5B,OAAO,CAAC,QAAQ;IAkBhB,OAAO,CAAC,YAAY;CA6BrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenizer.d.ts","sourceRoot":"","sources":["../src/tokenizer.ts"],"names":[],"mappings":"AAKA,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGhD"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { ImageContent, Message, Tool } from "./types";
|
|
2
|
+
/** Drop assistant messages that ended in error/aborted — partial turns
|
|
3
|
+
* shouldn't be replayed. */
|
|
4
|
+
export declare function normalizeMessages(messages: Message[]): Message[];
|
|
5
|
+
export interface KiroImage {
|
|
6
|
+
format: string;
|
|
7
|
+
source: {
|
|
8
|
+
bytes: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface KiroToolUse {
|
|
12
|
+
name: string;
|
|
13
|
+
toolUseId: string;
|
|
14
|
+
input: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
export interface KiroToolResult {
|
|
17
|
+
content: Array<{
|
|
18
|
+
text: string;
|
|
19
|
+
}>;
|
|
20
|
+
status: "success" | "error";
|
|
21
|
+
toolUseId: string;
|
|
22
|
+
}
|
|
23
|
+
export interface KiroToolSpec {
|
|
24
|
+
toolSpecification: {
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
inputSchema: {
|
|
28
|
+
json: Record<string, unknown>;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface KiroEnvState {
|
|
33
|
+
operatingSystem: string;
|
|
34
|
+
currentWorkingDirectory: string;
|
|
35
|
+
}
|
|
36
|
+
export interface KiroUserInputMessage {
|
|
37
|
+
content: string;
|
|
38
|
+
modelId?: string;
|
|
39
|
+
origin: "KIRO_CLI";
|
|
40
|
+
images?: KiroImage[];
|
|
41
|
+
userInputMessageContext?: {
|
|
42
|
+
envState?: KiroEnvState;
|
|
43
|
+
toolResults?: KiroToolResult[];
|
|
44
|
+
tools?: KiroToolSpec[];
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export interface KiroAssistantResponseMessage {
|
|
48
|
+
content: string;
|
|
49
|
+
toolUses?: KiroToolUse[];
|
|
50
|
+
reasoningContent?: {
|
|
51
|
+
reasoningText: {
|
|
52
|
+
text: string;
|
|
53
|
+
signature: string;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export interface KiroHistoryEntry {
|
|
58
|
+
userInputMessage?: KiroUserInputMessage;
|
|
59
|
+
assistantResponseMessage?: KiroAssistantResponseMessage;
|
|
60
|
+
}
|
|
61
|
+
export declare const TOOL_RESULT_LIMIT = 250000;
|
|
62
|
+
/** Maximum images per message accepted by the Kiro API. */
|
|
63
|
+
export declare const MAX_KIRO_IMAGES = 4;
|
|
64
|
+
/** Maximum decoded size per image (bytes) accepted by the Kiro API. */
|
|
65
|
+
export declare const MAX_KIRO_IMAGE_BYTES = 3750000;
|
|
66
|
+
/** Middle-ellipsis truncation: preserve start and end. */
|
|
67
|
+
export declare function truncate(text: string, limit: number): string;
|
|
68
|
+
export declare function extractImages(msg: Message): ImageContent[];
|
|
69
|
+
export declare function getContentText(msg: Message): string;
|
|
70
|
+
/**
|
|
71
|
+
* Parse tool-call arguments defensively. Historical messages (including
|
|
72
|
+
* those from other providers via cross-provider handoff) may carry args
|
|
73
|
+
* that aren't valid JSON. Fall back to {} rather than crashing the stream.
|
|
74
|
+
*/
|
|
75
|
+
export declare function parseToolArgs(input: unknown): Record<string, unknown>;
|
|
76
|
+
/**
|
|
77
|
+
* Kiro accepts its own compact `tooluse_*` IDs in replayed history. Other
|
|
78
|
+
* providers / harness layers can produce IDs such as `call_...|fc_...`, which
|
|
79
|
+
* Kiro rejects as `Invalid tool use format`. Canonicalize only the wire-format
|
|
80
|
+
* ID while preserving deterministic toolUse/toolResult matching.
|
|
81
|
+
*/
|
|
82
|
+
export declare function toKiroToolUseId(id: string): string;
|
|
83
|
+
export declare function convertToolsToKiro(tools: Tool[]): KiroToolSpec[];
|
|
84
|
+
/**
|
|
85
|
+
* Convert images to Kiro wire format, enforcing API limits:
|
|
86
|
+
* - Max {@link MAX_KIRO_IMAGES} images per call
|
|
87
|
+
* - Max {@link MAX_KIRO_IMAGE_BYTES} decoded bytes per image
|
|
88
|
+
*
|
|
89
|
+
* Oversized/excess images are silently dropped and counted in `omitted`.
|
|
90
|
+
*/
|
|
91
|
+
export declare function convertImagesToKiro(images: Array<{
|
|
92
|
+
mimeType: string;
|
|
93
|
+
data: string;
|
|
94
|
+
}>): {
|
|
95
|
+
images: KiroImage[];
|
|
96
|
+
omitted: number;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Split messages into history + current turn. The current turn is the trailing
|
|
100
|
+
* user message (+ any following tool results) or the trailing assistant
|
|
101
|
+
* message when it carries tool calls. Everything before goes into history.
|
|
102
|
+
*
|
|
103
|
+
* System prompt is prepended to the first user message in history, not sent
|
|
104
|
+
* as a separate field (Kiro doesn't have one).
|
|
105
|
+
*/
|
|
106
|
+
export declare function buildHistory(messages: Message[], _modelId: string, systemPrompt?: string): {
|
|
107
|
+
history: KiroHistoryEntry[];
|
|
108
|
+
systemPrepended: boolean;
|
|
109
|
+
currentMsgStartIdx: number;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Collapse consecutive tool-use loops in history. When the agent calls
|
|
113
|
+
* tools N times in sequence (ASST(toolUses) → USER(toolResults) pairs),
|
|
114
|
+
* keep text only on the first assistant message and replace subsequent
|
|
115
|
+
* ones with a short placeholder. This prevents the model from re-deriving
|
|
116
|
+
* its preamble on every iteration, saving context tokens.
|
|
117
|
+
*/
|
|
118
|
+
export declare function collapseAgenticLoops(history: KiroHistoryEntry[]): KiroHistoryEntry[];
|
|
119
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../src/transform.ts"],"names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,CAAA;CAAE,CAsB1C;AAID;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,OAAO,EAAE,EACnB,QAAQ,EAAE,MAAM,EAChB,YAAY,CAAC,EAAE,MAAM,GACpB;IAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAAC,eAAe,EAAE,OAAO,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAA;CAAE,CAwIvF;AAID;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,EAAE,CA0DpF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
export interface TextContent {
|
|
2
|
+
type: "text";
|
|
3
|
+
text: string;
|
|
4
|
+
textSignature?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ThinkingContent {
|
|
7
|
+
type: "thinking";
|
|
8
|
+
thinking: string;
|
|
9
|
+
thinkingSignature?: string;
|
|
10
|
+
/** When true, the thinking content was redacted by safety filters. */
|
|
11
|
+
redacted?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface ImageContent {
|
|
14
|
+
type: "image";
|
|
15
|
+
data: string;
|
|
16
|
+
mimeType: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ToolCall {
|
|
19
|
+
type: "toolCall";
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
arguments: Record<string, any>;
|
|
23
|
+
thoughtSignature?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface Usage {
|
|
26
|
+
input: number;
|
|
27
|
+
output: number;
|
|
28
|
+
cacheRead: number;
|
|
29
|
+
cacheWrite: number;
|
|
30
|
+
totalTokens: number;
|
|
31
|
+
cost: {
|
|
32
|
+
input: number;
|
|
33
|
+
output: number;
|
|
34
|
+
cacheRead: number;
|
|
35
|
+
cacheWrite: number;
|
|
36
|
+
total: number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export type StopReason = "stop" | "length" | "toolUse" | "error" | "aborted";
|
|
40
|
+
export interface UserMessage {
|
|
41
|
+
role: "user";
|
|
42
|
+
content: string | (TextContent | ImageContent)[];
|
|
43
|
+
timestamp: number;
|
|
44
|
+
}
|
|
45
|
+
export interface AssistantMessage {
|
|
46
|
+
role: "assistant";
|
|
47
|
+
content: (TextContent | ThinkingContent | ToolCall)[];
|
|
48
|
+
api: Api;
|
|
49
|
+
provider: string;
|
|
50
|
+
model: string;
|
|
51
|
+
responseModel?: string;
|
|
52
|
+
responseId?: string;
|
|
53
|
+
usage: Usage;
|
|
54
|
+
stopReason: StopReason;
|
|
55
|
+
errorMessage?: string;
|
|
56
|
+
timestamp: number;
|
|
57
|
+
}
|
|
58
|
+
export interface ToolResultMessage<TDetails = any> {
|
|
59
|
+
role: "toolResult";
|
|
60
|
+
toolCallId: string;
|
|
61
|
+
toolName: string;
|
|
62
|
+
content: (TextContent | ImageContent)[];
|
|
63
|
+
details?: TDetails;
|
|
64
|
+
isError: boolean;
|
|
65
|
+
timestamp: number;
|
|
66
|
+
}
|
|
67
|
+
export type Message = UserMessage | AssistantMessage | ToolResultMessage;
|
|
68
|
+
export type Api = string;
|
|
69
|
+
export type ThinkingLevel = "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
70
|
+
export interface Model<TApi extends Api> {
|
|
71
|
+
id: string;
|
|
72
|
+
name: string;
|
|
73
|
+
api: TApi;
|
|
74
|
+
provider: string;
|
|
75
|
+
baseUrl: string;
|
|
76
|
+
reasoning: boolean;
|
|
77
|
+
input: ("text" | "image")[];
|
|
78
|
+
cost: {
|
|
79
|
+
input: number;
|
|
80
|
+
output: number;
|
|
81
|
+
cacheRead: number;
|
|
82
|
+
cacheWrite: number;
|
|
83
|
+
};
|
|
84
|
+
contextWindow: number;
|
|
85
|
+
maxTokens: number;
|
|
86
|
+
headers?: Record<string, string>;
|
|
87
|
+
}
|
|
88
|
+
export interface Tool {
|
|
89
|
+
name: string;
|
|
90
|
+
description: string;
|
|
91
|
+
parameters: Record<string, unknown>;
|
|
92
|
+
}
|
|
93
|
+
export interface Context {
|
|
94
|
+
systemPrompt?: string;
|
|
95
|
+
messages: Message[];
|
|
96
|
+
tools?: Tool[];
|
|
97
|
+
}
|
|
98
|
+
export interface SimpleStreamOptions {
|
|
99
|
+
temperature?: number;
|
|
100
|
+
maxTokens?: number;
|
|
101
|
+
signal?: AbortSignal;
|
|
102
|
+
apiKey?: string;
|
|
103
|
+
sessionId?: string;
|
|
104
|
+
reasoning?: ThinkingLevel;
|
|
105
|
+
headers?: Record<string, string>;
|
|
106
|
+
}
|
|
107
|
+
export type AssistantMessageEvent = {
|
|
108
|
+
type: "start";
|
|
109
|
+
partial: AssistantMessage;
|
|
110
|
+
} | {
|
|
111
|
+
type: "text_start";
|
|
112
|
+
contentIndex: number;
|
|
113
|
+
partial: AssistantMessage;
|
|
114
|
+
} | {
|
|
115
|
+
type: "text_delta";
|
|
116
|
+
contentIndex: number;
|
|
117
|
+
delta: string;
|
|
118
|
+
partial: AssistantMessage;
|
|
119
|
+
} | {
|
|
120
|
+
type: "text_end";
|
|
121
|
+
contentIndex: number;
|
|
122
|
+
content: string;
|
|
123
|
+
partial: AssistantMessage;
|
|
124
|
+
} | {
|
|
125
|
+
type: "thinking_start";
|
|
126
|
+
contentIndex: number;
|
|
127
|
+
partial: AssistantMessage;
|
|
128
|
+
} | {
|
|
129
|
+
type: "thinking_delta";
|
|
130
|
+
contentIndex: number;
|
|
131
|
+
delta: string;
|
|
132
|
+
partial: AssistantMessage;
|
|
133
|
+
} | {
|
|
134
|
+
type: "thinking_end";
|
|
135
|
+
contentIndex: number;
|
|
136
|
+
content: string;
|
|
137
|
+
partial: AssistantMessage;
|
|
138
|
+
} | {
|
|
139
|
+
type: "toolcall_start";
|
|
140
|
+
contentIndex: number;
|
|
141
|
+
partial: AssistantMessage;
|
|
142
|
+
} | {
|
|
143
|
+
type: "toolcall_delta";
|
|
144
|
+
contentIndex: number;
|
|
145
|
+
delta: string;
|
|
146
|
+
partial: AssistantMessage;
|
|
147
|
+
} | {
|
|
148
|
+
type: "toolcall_end";
|
|
149
|
+
contentIndex: number;
|
|
150
|
+
toolCall: ToolCall;
|
|
151
|
+
partial: AssistantMessage;
|
|
152
|
+
} | {
|
|
153
|
+
type: "done";
|
|
154
|
+
reason: Extract<StopReason, "stop" | "length" | "toolUse">;
|
|
155
|
+
message: AssistantMessage;
|
|
156
|
+
} | {
|
|
157
|
+
type: "error";
|
|
158
|
+
reason: Extract<StopReason, "aborted" | "error">;
|
|
159
|
+
error: AssistantMessage;
|
|
160
|
+
};
|
|
161
|
+
export declare class EventStream<T, R = T> implements AsyncIterable<T> {
|
|
162
|
+
private queue;
|
|
163
|
+
private waiting;
|
|
164
|
+
private done;
|
|
165
|
+
private finalResultPromise;
|
|
166
|
+
private resolveFinalResult;
|
|
167
|
+
private isComplete;
|
|
168
|
+
private extractResult;
|
|
169
|
+
constructor(isComplete: (event: T) => boolean, extractResult: (event: T) => R);
|
|
170
|
+
push(event: T): void;
|
|
171
|
+
end(result?: R): void;
|
|
172
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
173
|
+
result(): Promise<R>;
|
|
174
|
+
}
|
|
175
|
+
export declare class AssistantMessageEventStream extends EventStream<AssistantMessageEvent, AssistantMessage> {
|
|
176
|
+
constructor();
|
|
177
|
+
}
|
|
178
|
+
export declare function createAssistantMessageEventStream(): AssistantMessageEventStream;
|
|
179
|
+
export declare function calculateCost<TApi extends Api>(model: Model<TApi>, usage: Usage): Usage["cost"];
|
|
180
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,eAAe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