@@ -52,6 +52,24 @@ const AMZ_TARGET = "AmazonCodeWhispererStreamingService.GenerateAssistantRespons
5252const SDK_VERSION = "1.0.27" ;
5353const NODE_VERSION = "22.21.1" ;
5454const KIRO_IDE_VERSION = "1.0.0" ;
55+ type KiroWireClient = "ide" | "cli" ;
56+
57+ function kiroCliPlatform ( ) : "linux" | "macos" | "windows" {
58+ return process . platform === "win32" ? "windows" : process . platform === "darwin" ? "macos" : "linux" ;
59+ }
60+
61+ function kiroCliUserAgent ( includeAppVersion : boolean ) : string {
62+ return [
63+ "aws-sdk-rust/1.3.15" ,
64+ "ua/2.1" ,
65+ "api/codewhispererstreaming/0.1.17975" ,
66+ `os/${ kiroCliPlatform ( ) } ` ,
67+ "lang/rust/1.92.0" ,
68+ ...( includeAppVersion ? [ "md/appVersion-2.14.2" ] : [ ] ) ,
69+ "m/F" ,
70+ "app/AmazonQ-For-CLI" ,
71+ ] . join ( " " ) ;
72+ }
5573
5674// Payload construction (conversationState)
5775interface KiroToolUse {
@@ -68,7 +86,11 @@ interface KiroUserInputMessage {
6886 content : string ;
6987 modelId ?: string ;
7088 origin ?: string ;
71- userInputMessageContext ?: { tools ?: unknown [ ] ; toolResults ?: KiroToolResult [ ] } ;
89+ userInputMessageContext ?: {
90+ tools ?: unknown [ ] ;
91+ toolResults ?: KiroToolResult [ ] ;
92+ envState ?: { operatingSystem : string ; currentWorkingDirectory : string } ;
93+ } ;
7294 images ?: KiroImage [ ] ;
7395}
7496interface KiroHistoryEntry {
@@ -385,6 +407,7 @@ export function buildKiroPayload(
385407 parsed : OcxParsedRequest ,
386408 profileArn : string | undefined ,
387409 forcedCompletionMode ?: KiroCompletionMode ,
410+ wireClient : KiroWireClient = "ide" ,
388411) : {
389412 payload : Record < string , unknown > ;
390413 nameMap : Map < string , string > ;
@@ -509,7 +532,7 @@ export function buildKiroPayload(
509532 userInputMessage : {
510533 content : turn . content ,
511534 modelId,
512- origin : "AI_EDITOR" ,
535+ origin : wireClient === "cli" ? "KIRO_CLI" : "AI_EDITOR" ,
513536 ...( turn . images . length > 0 ? { images : turn . images } : { } ) ,
514537 ...( turn . toolResults . length > 0 ? { userInputMessageContext : { toolResults : turn . toolResults } } : { } ) ,
515538 } ,
@@ -526,6 +549,12 @@ export function buildKiroPayload(
526549 if ( kiroTools . length > 0 ) {
527550 currentUim . userInputMessageContext = { ...( currentUim . userInputMessageContext ?? { } ) , tools : kiroTools } ;
528551 }
552+ if ( wireClient === "cli" ) {
553+ currentUim . userInputMessageContext = {
554+ ...( currentUim . userInputMessageContext ?? { } ) ,
555+ envState : { operatingSystem : kiroCliPlatform ( ) , currentWorkingDirectory : process . cwd ( ) } ,
556+ } ;
557+ }
529558 if ( completionMode === "text_fallback" ) {
530559 if ( currentUim . content !== KIRO_COMPLETION_RETRY_MESSAGE ) {
531560 currentUim . content = appendTurnText ( currentUim . content , KIRO_COMPLETION_RETRY_MESSAGE ) ;
@@ -539,6 +568,10 @@ export function buildKiroPayload(
539568 const payload : Record < string , unknown > = {
540569 conversationState : {
541570 chatTriggerType : "MANUAL" ,
571+ ...( wireClient === "cli" ? {
572+ agentContinuationId : crypto . randomUUID ( ) ,
573+ agentTaskType : "vibe" ,
574+ } : { } ) ,
542575 conversationId,
543576 currentMessage : { userInputMessage : currentUim } ,
544577 ...( history . length > 0 ? { history } : { } ) ,
@@ -1447,8 +1480,23 @@ export function createKiroAdapter(provider: OcxProviderConfig): ProviderAdapter
14471480 }
14481481 const region = resolveKiroApiRegion ( parsed . _kiroAuthContext ) ;
14491482 const profileArn = resolveKiroProfileArn ( parsed . _kiroAuthContext ) ;
1483+ // Builder ID and Kiro API keys have no profile ARN and are accepted only on Kiro's CLI
1484+ // request path. Enterprise profiles retain the existing IDE-shaped request.
1485+ const wireClient : KiroWireClient = profileArn ? "ide" : "cli" ;
1486+ const isApiKey = provider . apiKey . trim ( ) . startsWith ( "ksk_" ) ;
14501487 const fp = fingerprint ( ) . slice ( 0 , 64 ) ;
1451- const headers : Record < string , string > = {
1488+ const headers : Record < string , string > = wireClient === "cli" ? {
1489+ authorization : `Bearer ${ provider . apiKey } ` ,
1490+ "content-type" : "application/x-amz-json-1.0" ,
1491+ accept : "*/*" ,
1492+ "x-amz-target" : AMZ_TARGET ,
1493+ "user-agent" : kiroCliUserAgent ( true ) ,
1494+ "x-amz-user-agent" : kiroCliUserAgent ( false ) ,
1495+ "x-amzn-codewhisperer-optout" : "false" ,
1496+ "amz-sdk-request" : "attempt=1; max=3" ,
1497+ "amz-sdk-invocation-id" : invocationId ( ) ,
1498+ ...( isApiKey ? { tokentype : "API_KEY" } : { } ) ,
1499+ } : {
14521500 authorization : `Bearer ${ provider . apiKey } ` ,
14531501 "content-type" : "application/x-amz-json-1.0" ,
14541502 accept : "application/vnd.amazon.eventstream" ,
@@ -1460,7 +1508,7 @@ export function createKiroAdapter(provider: OcxProviderConfig): ProviderAdapter
14601508 "amz-sdk-invocation-id" : invocationId ( ) ,
14611509 } ;
14621510 if ( profileArn ) headers [ "x-amzn-kiro-profile-arn" ] = profileArn ;
1463- const built = buildKiroPayload ( parsed , profileArn , forcedCompletionMode ) ;
1511+ const built = buildKiroPayload ( parsed , profileArn , forcedCompletionMode , wireClient ) ;
14641512 await normalizeKiroImages ( built . payload ) ;
14651513 const contextInputEstimate = estimateKiroPayloadInputTokens ( built . payload , parsed . modelId ) ;
14661514 const body = JSON . stringify ( built . payload ) ;
@@ -1472,6 +1520,7 @@ export function createKiroAdapter(provider: OcxProviderConfig): ProviderAdapter
14721520 messageCount : kiroPayloadMessages ( parsed ) . length ,
14731521 toolCount : parsed . context . tools ?. length ?? 0 ,
14741522 hasProfileArn : Boolean ( profileArn ) ,
1523+ wireClient,
14751524 hasPreviousResponseId : Boolean ( parsed . previousResponseId ) ,
14761525 } ) ;
14771526 return {
0 commit comments