Skip to content

Commit ad768bf

Browse files
committed
fix(build): rename LoopToolCallRequest/Result to avoid barrel collision, fix Buffer→Uint8Array in speech providers
1 parent de920a9 commit ad768bf

6 files changed

Lines changed: 26 additions & 26 deletions

File tree

src/orchestration/__tests__/loop-controller.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import type {
1818
LoopContext,
1919
LoopChunk,
2020
LoopOutput,
21-
ToolCallRequest,
22-
ToolCallResult,
21+
LoopToolCallRequest,
22+
LoopToolCallResult,
2323
} from '../runtime/LoopController.js';
2424

2525
// ---------------------------------------------------------------------------
@@ -67,15 +67,15 @@ function createMockContext(
6767
toolCallsPerIteration = 1,
6868
) {
6969
let calls = 0;
70-
const addedResults: ToolCallResult[][] = [];
70+
const addedResults: LoopToolCallResult[][] = [];
7171

7272
const context: LoopContext = {
7373
generateStream: async function* () {
7474
calls++;
7575

7676
if (calls <= toolCallIterations) {
7777
// Build N tool calls for this iteration.
78-
const tc: ToolCallRequest[] = Array.from(
78+
const tc: LoopToolCallRequest[] = Array.from(
7979
{ length: toolCallsPerIteration },
8080
(_, j) => ({
8181
id: `tc-${calls}-${j}`,
@@ -100,7 +100,7 @@ function createMockContext(
100100
} satisfies LoopOutput;
101101
},
102102

103-
executeTool: vi.fn<[ToolCallRequest], Promise<ToolCallResult>>().mockImplementation(
103+
executeTool: vi.fn<[LoopToolCallRequest], Promise<LoopToolCallResult>>().mockImplementation(
104104
async (tc) => ({
105105
id: tc.id,
106106
name: tc.name,
@@ -109,7 +109,7 @@ function createMockContext(
109109
}),
110110
),
111111

112-
addToolResults: vi.fn((results: ToolCallResult[]) => {
112+
addToolResults: vi.fn((results: LoopToolCallResult[]) => {
113113
addedResults.push(results);
114114
}),
115115
};
@@ -198,7 +198,7 @@ describe('LoopController', () => {
198198
name: 'test_tool',
199199
success: false,
200200
error: 'something went wrong',
201-
} satisfies ToolCallResult);
201+
} satisfies LoopToolCallResult);
202202

203203
const controller = new LoopController();
204204
const config = baseConfig({ failureMode: 'fail_closed' });
@@ -221,7 +221,7 @@ describe('LoopController', () => {
221221
name: 'test_tool',
222222
success: false,
223223
error: 'transient error',
224-
} satisfies ToolCallResult);
224+
} satisfies LoopToolCallResult);
225225

226226
const events = await collectEvents(baseConfig({ failureMode: 'fail_open' }), context);
227227

@@ -246,7 +246,7 @@ describe('LoopController', () => {
246246

247247
// Override executeTool to track concurrent invocations
248248
(context.executeTool as ReturnType<typeof vi.fn>).mockImplementation(
249-
async (tc: ToolCallRequest): Promise<ToolCallResult> => {
249+
async (tc: LoopToolCallRequest): Promise<LoopToolCallResult> => {
250250
const idx = dispatchOrder.length;
251251
dispatchOrder.push(idx);
252252

src/orchestration/runtime/LoopController.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ export interface LoopContext {
6868
* Implementations should never throw — instead return a result with
6969
* `success: false` and a populated `error` field.
7070
*/
71-
executeTool: (toolCall: ToolCallRequest) => Promise<ToolCallResult>;
71+
executeTool: (toolCall: LoopToolCallRequest) => Promise<LoopToolCallResult>;
7272

7373
/**
7474
* Feed tool results back into the conversation so the next `generateStream`
7575
* call has access to them. Typically appends tool messages to the message list.
7676
*/
77-
addToolResults: (results: ToolCallResult[]) => void;
77+
addToolResults: (results: LoopToolCallResult[]) => void;
7878
}
7979

8080
// ---------------------------------------------------------------------------
@@ -84,7 +84,7 @@ export interface LoopContext {
8484
/**
8585
* A single tool invocation requested by the LLM.
8686
*/
87-
export interface ToolCallRequest {
87+
export interface LoopToolCallRequest {
8888
/** Unique identifier for this tool call within a response (matches the tool result). */
8989
id: string;
9090

@@ -96,10 +96,10 @@ export interface ToolCallRequest {
9696
}
9797

9898
/**
99-
* The outcome of executing a {@link ToolCallRequest}.
99+
* The outcome of executing a {@link LoopToolCallRequest}.
100100
*/
101-
export interface ToolCallResult {
102-
/** Matches the originating {@link ToolCallRequest.id}. */
101+
export interface LoopToolCallResult {
102+
/** Matches the originating {@link LoopToolCallRequest.id}. */
103103
id: string;
104104

105105
/** Name of the tool that was called. */
@@ -134,7 +134,7 @@ export interface LoopChunk {
134134
content?: string;
135135

136136
/** Present when `type === 'tool_call_request'`. */
137-
toolCalls?: ToolCallRequest[];
137+
toolCalls?: LoopToolCallRequest[];
138138
}
139139

140140
/**
@@ -149,7 +149,7 @@ export interface LoopOutput {
149149
* All tool calls requested in this iteration. An empty array signals that
150150
* the LLM is done and the loop should terminate.
151151
*/
152-
toolCalls: ToolCallRequest[];
152+
toolCalls: LoopToolCallRequest[];
153153

154154
/**
155155
* The LLM finish reason (e.g. `'stop'`, `'tool_calls'`, `'length'`).
@@ -168,8 +168,8 @@ export interface LoopOutput {
168168
*/
169169
export type LoopEvent =
170170
| { type: 'text_delta'; content: string }
171-
| { type: 'tool_call_request'; toolCalls: ToolCallRequest[] }
172-
| { type: 'tool_result'; toolName: string; result: ToolCallResult }
171+
| { type: 'tool_call_request'; toolCalls: LoopToolCallRequest[] }
172+
| { type: 'tool_result'; toolName: string; result: LoopToolCallResult }
173173
| { type: 'tool_error'; toolName: string; error: string }
174174
| { type: 'max_iterations_reached'; iteration: number }
175175
| { type: 'loop_complete'; totalIterations: number };
@@ -249,7 +249,7 @@ export class LoopController {
249249
// Act phase: execute tool calls (parallel or sequential).
250250
// ------------------------------------------------------------------
251251
const toolCalls = gmiOutput.toolCalls;
252-
let results: ToolCallResult[];
252+
let results: LoopToolCallResult[];
253253

254254
if (config.parallelTools) {
255255
// Dispatch all tool calls simultaneously; collect all outcomes even
@@ -261,7 +261,7 @@ export class LoopController {
261261
results = settled.map((s, i) => {
262262
if (s.status === 'fulfilled') return s.value;
263263

264-
// Convert a rejected promise into a failed ToolCallResult so
264+
// Convert a rejected promise into a failed LoopToolCallResult so
265265
// downstream handling is uniform.
266266
return {
267267
id: toolCalls[i].id,

src/orchestration/runtime/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export type {
1313
LoopConfig,
1414
LoopContext,
1515
LoopEvent,
16-
ToolCallRequest,
17-
ToolCallResult,
16+
LoopToolCallRequest,
17+
LoopToolCallResult,
1818
} from './LoopController.js';
1919
export { NodeExecutor } from './NodeExecutor.js';
2020
export type { NodeExecutionResult } from './NodeExecutor.js';

src/speech/providers/AssemblyAISTTProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class AssemblyAISTTProvider implements SpeechToTextProvider {
125125
Authorization: this.config.apiKey,
126126
'Content-Type': audio.mimeType ?? 'audio/wav',
127127
},
128-
body: audio.data,
128+
body: audio.data instanceof Buffer ? new Uint8Array(audio.data) : audio.data,
129129
signal,
130130
});
131131

src/speech/providers/AzureSpeechSTTProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class AzureSpeechSTTProvider implements SpeechToTextProvider {
9393
'Ocp-Apim-Subscription-Key': key,
9494
'Content-Type': 'audio/wav',
9595
},
96-
body: audio.data,
96+
body: audio.data instanceof Buffer ? new Uint8Array(audio.data) : audio.data,
9797
});
9898

9999
if (!response.ok) {

src/speech/providers/DeepgramBatchSTTProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class DeepgramBatchSTTProvider implements SpeechToTextProvider {
138138
Authorization: `Token ${this.config.apiKey}`,
139139
'Content-Type': contentType,
140140
},
141-
body: audio.data,
141+
body: audio.data instanceof Buffer ? new Uint8Array(audio.data) : audio.data,
142142
});
143143

144144
if (!response.ok) {

0 commit comments

Comments
 (0)