Skip to content

Commit 48178d4

Browse files
committed
fix(acp): fallback unknown turn end reasons
1 parent 7644f10 commit 48178d4

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@moonshot-ai/kimi-code": patch
3+
---
4+
5+
Fallback ACP turn-end stop reason mapping to `end_turn` for unknown runtime values.

packages/acp-adapter/src/events-map.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export function assistantDeltaToSessionUpdate(
5656
* belong on the JSON-RPC error channel). Returning `end_turn` keeps the
5757
* client unblocked; the caller is expected to log the `error` payload
5858
* separately so the failure is observable in the agent logs.
59+
* Unknown runtime values also fall back to `end_turn` so a newer SDK
60+
* reason cannot leak `undefined` onto the ACP wire.
5961
*/
6062
export function turnEndReasonToStopReason(reason: TurnEndReason): AcpStopReason {
6163
switch (reason) {
@@ -65,6 +67,8 @@ export function turnEndReasonToStopReason(reason: TurnEndReason): AcpStopReason
6567
return 'cancelled';
6668
case 'failed':
6769
return 'end_turn';
70+
default:
71+
return 'end_turn';
6872
}
6973
}
7074

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
import type { TurnEndReason } from '@moonshot-ai/kimi-code-sdk';
4+
5+
import { turnEndReasonToStopReason } from '../src/events-map';
6+
7+
describe('turnEndReasonToStopReason', () => {
8+
it('maps known SDK turn-end reasons to ACP stop reasons', () => {
9+
expect(turnEndReasonToStopReason('completed')).toBe('end_turn');
10+
expect(turnEndReasonToStopReason('cancelled')).toBe('cancelled');
11+
expect(turnEndReasonToStopReason('failed')).toBe('end_turn');
12+
});
13+
14+
it('falls back to end_turn for unknown runtime reasons', () => {
15+
expect(turnEndReasonToStopReason('interrupted' as TurnEndReason)).toBe('end_turn');
16+
});
17+
});

0 commit comments

Comments
 (0)