@ai-sdk/harness-acp 1.0.1 → 1.0.2

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.
@@ -1,5 +1,10 @@
1
1
  import type { HarnessV1StreamPart } from '@ai-sdk/harness';
2
2
  import type { PromptResponse, SessionUpdate } from '@agentclientprotocol/sdk';
3
+ import type {
4
+ ACPToolCall,
5
+ ACPToolCallStatus,
6
+ ACPToolKind,
7
+ } from '../../acp-tool-call';
3
8
  import type { ACPBuiltinToolMapping } from '../acp-v1-bridge-protocol';
4
9
 
5
10
  type HarnessUsage = Extract<
@@ -20,7 +25,6 @@ type ToolState = {
20
25
  emittedResult: boolean;
21
26
  toolName?: string;
22
27
  nativeName?: string;
23
- dynamic?: boolean;
24
28
  };
25
29
 
26
30
  export type ACPSessionUpdate = SessionUpdate;
@@ -28,9 +32,11 @@ export type ACPPromptResponse = PromptResponse;
28
32
 
29
33
  export function createACPStreamTranslator({
30
34
  emit,
35
+ emitToolCallCandidate,
31
36
  builtinTools = [],
32
37
  }: {
33
38
  emit: (event: HarnessV1StreamPart) => void;
39
+ emitToolCallCandidate?: (options: { toolCall: ACPToolCall }) => void;
34
40
  builtinTools?: ReadonlyArray<ACPBuiltinToolMapping>;
35
41
  }): {
36
42
  update: (
@@ -228,13 +234,12 @@ export function createACPStreamTranslator({
228
234
  builtin.nativeName != null && builtin.toolName !== builtin.nativeName
229
235
  ? builtin.nativeName
230
236
  : undefined;
231
- state.dynamic = false;
232
237
  } else {
233
238
  state.toolName = createDynamicToolName({
234
239
  programmaticName,
235
240
  toolCallId: state.toolCallId,
236
241
  });
237
- state.dynamic = true;
242
+ emitToolCallCandidate?.({ toolCall: createACPToolCall({ state }) });
238
243
  }
239
244
  emit({
240
245
  type: 'tool-call',
@@ -242,7 +247,6 @@ export function createACPStreamTranslator({
242
247
  toolName: state.toolName,
243
248
  input: stringifyToolInput({ input: state.values.rawInput }),
244
249
  providerExecuted: true,
245
- ...(state.dynamic ? { dynamic: true } : {}),
246
250
  ...(state.nativeName == null ? {} : { nativeName: state.nativeName }),
247
251
  });
248
252
  state.emittedCall = true;
@@ -263,7 +267,6 @@ export function createACPStreamTranslator({
263
267
  toolName: state.toolName!,
264
268
  result: createToolResult({ state }),
265
269
  ...(state.values.status === 'failed' ? { isError: true } : {}),
266
- ...(state.dynamic ? { dynamic: true } : {}),
267
270
  });
268
271
  state.emittedResult = true;
269
272
  pendingToolCallIds.delete(state.toolCallId);
@@ -697,6 +700,60 @@ function mergeToolUpdate({
697
700
  if (programmaticName != null) state.values.name = programmaticName;
698
701
  }
699
702
 
703
+ function createACPToolCall({ state }: { state: ToolState }): ACPToolCall {
704
+ const title = getStringProperty({
705
+ value: state.values,
706
+ property: 'title',
707
+ });
708
+ const kind = state.values.kind;
709
+ const status = state.values.status;
710
+ return {
711
+ toolCallId: state.toolCallId,
712
+ title: title ?? state.toolName ?? `Tool ${state.toolCallId}`,
713
+ ...(isACPToolKind(kind) ? { kind } : {}),
714
+ ...(isACPToolCallStatus(status) ? { status } : {}),
715
+ ...(Array.isArray(state.values.content)
716
+ ? { content: state.values.content as ACPToolCall['content'] }
717
+ : {}),
718
+ ...(Array.isArray(state.values.locations)
719
+ ? { locations: state.values.locations as ACPToolCall['locations'] }
720
+ : {}),
721
+ ...(Object.prototype.hasOwnProperty.call(state.values, 'rawInput')
722
+ ? { rawInput: state.values.rawInput }
723
+ : {}),
724
+ ...(Object.prototype.hasOwnProperty.call(state.values, 'rawOutput')
725
+ ? { rawOutput: state.values.rawOutput }
726
+ : {}),
727
+ ...(state.values._meta === null || isRecord(state.values._meta)
728
+ ? { _meta: state.values._meta }
729
+ : {}),
730
+ };
731
+ }
732
+
733
+ function isACPToolKind(value: unknown): value is ACPToolKind {
734
+ return (
735
+ value === 'read' ||
736
+ value === 'edit' ||
737
+ value === 'delete' ||
738
+ value === 'move' ||
739
+ value === 'search' ||
740
+ value === 'execute' ||
741
+ value === 'think' ||
742
+ value === 'fetch' ||
743
+ value === 'switch_mode' ||
744
+ value === 'other'
745
+ );
746
+ }
747
+
748
+ function isACPToolCallStatus(value: unknown): value is ACPToolCallStatus {
749
+ return (
750
+ value === 'pending' ||
751
+ value === 'in_progress' ||
752
+ value === 'completed' ||
753
+ value === 'failed'
754
+ );
755
+ }
756
+
700
757
  function emitFileChanges({
701
758
  state,
702
759
  emit,