@copilotkitnext/runtime 0.0.3 → 0.0.4
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/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/.turbo/turbo-build.log +0 -23
- package/.turbo/turbo-check-types.log +0 -4
- package/.turbo/turbo-lint.log +0 -56
- package/.turbo/turbo-test$colon$coverage.log +0 -149
- package/.turbo/turbo-test.log +0 -108
- package/src/__tests__/get-runtime-info.test.ts +0 -117
- package/src/__tests__/handle-run.test.ts +0 -69
- package/src/__tests__/handle-transcribe.test.ts +0 -289
- package/src/__tests__/in-process-agent-runner-messages.test.ts +0 -599
- package/src/__tests__/in-process-agent-runner.test.ts +0 -726
- package/src/__tests__/middleware.test.ts +0 -432
- package/src/__tests__/routing.test.ts +0 -257
- package/src/endpoint.ts +0 -150
- package/src/handler.ts +0 -3
- package/src/handlers/get-runtime-info.ts +0 -50
- package/src/handlers/handle-connect.ts +0 -144
- package/src/handlers/handle-run.ts +0 -156
- package/src/handlers/handle-transcribe.ts +0 -126
- package/src/index.ts +0 -8
- package/src/middleware.ts +0 -232
- package/src/runner/__tests__/enterprise-runner.test.ts +0 -992
- package/src/runner/__tests__/event-compaction.test.ts +0 -253
- package/src/runner/__tests__/in-memory-runner.test.ts +0 -483
- package/src/runner/__tests__/sqlite-runner.test.ts +0 -975
- package/src/runner/agent-runner.ts +0 -27
- package/src/runner/enterprise.ts +0 -653
- package/src/runner/event-compaction.ts +0 -250
- package/src/runner/in-memory.ts +0 -328
- package/src/runner/index.ts +0 -0
- package/src/runner/sqlite.ts +0 -481
- package/src/runtime.ts +0 -53
- package/src/transcription-service/transcription-service-openai.ts +0 -29
- package/src/transcription-service/transcription-service.ts +0 -11
- package/tsconfig.json +0 -13
- package/tsup.config.ts +0 -11
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { handleTranscribe } from "../handlers/handle-transcribe";
|
|
2
|
-
import { CopilotRuntime } from "../runtime";
|
|
3
|
-
import {
|
|
4
|
-
TranscriptionService,
|
|
5
|
-
TranscribeFileOptions,
|
|
6
|
-
} from "../transcription-service/transcription-service";
|
|
7
|
-
import { describe, it, expect } from "vitest";
|
|
8
|
-
|
|
9
|
-
// Mock TranscriptionService
|
|
10
|
-
class MockTranscriptionService extends TranscriptionService {
|
|
11
|
-
public lastOptions?: TranscribeFileOptions;
|
|
12
|
-
|
|
13
|
-
constructor(
|
|
14
|
-
private shouldThrow = false,
|
|
15
|
-
private returnText = "Mock transcription"
|
|
16
|
-
) {
|
|
17
|
-
super();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async transcribeFile(options: TranscribeFileOptions): Promise<string> {
|
|
21
|
-
this.lastOptions = options;
|
|
22
|
-
if (this.shouldThrow) {
|
|
23
|
-
throw new Error("Transcription service error");
|
|
24
|
-
}
|
|
25
|
-
return this.returnText;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
describe("handleTranscribe", () => {
|
|
30
|
-
const createMockRuntime = (
|
|
31
|
-
transcriptionService?: TranscriptionService
|
|
32
|
-
): CopilotRuntime => {
|
|
33
|
-
return {
|
|
34
|
-
agents: Promise.resolve({}),
|
|
35
|
-
transcriptionService,
|
|
36
|
-
beforeRequestMiddleware: undefined,
|
|
37
|
-
afterRequestMiddleware: undefined,
|
|
38
|
-
} as CopilotRuntime;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const createMockAudioFile = (
|
|
42
|
-
name = "test.mp3",
|
|
43
|
-
type = "audio/mpeg",
|
|
44
|
-
size = 1024
|
|
45
|
-
): File => {
|
|
46
|
-
const content = new Uint8Array(size);
|
|
47
|
-
return new File([content], name, { type });
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const createFormDataRequest = (audioFile?: File): Request => {
|
|
51
|
-
const formData = new FormData();
|
|
52
|
-
if (audioFile) {
|
|
53
|
-
formData.append("audio", audioFile);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return new Request("https://example.com/transcribe", {
|
|
57
|
-
method: "POST",
|
|
58
|
-
body: formData,
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const createJsonRequest = (): Request => {
|
|
63
|
-
return new Request("https://example.com/transcribe", {
|
|
64
|
-
method: "POST",
|
|
65
|
-
headers: { "Content-Type": "application/json" },
|
|
66
|
-
body: JSON.stringify({ test: "data" }),
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
it("should successfully transcribe an audio file", async () => {
|
|
71
|
-
const mockService = new MockTranscriptionService(false, "Hello world");
|
|
72
|
-
const runtime = createMockRuntime(mockService);
|
|
73
|
-
const audioFile = createMockAudioFile("test.mp3", "audio/mpeg", 2048);
|
|
74
|
-
const request = createFormDataRequest(audioFile);
|
|
75
|
-
|
|
76
|
-
const response = await handleTranscribe({ runtime, request });
|
|
77
|
-
|
|
78
|
-
expect(response.status).toBe(200);
|
|
79
|
-
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
80
|
-
|
|
81
|
-
const body = await response.json();
|
|
82
|
-
expect(body).toEqual({
|
|
83
|
-
text: "Hello world",
|
|
84
|
-
size: 2048,
|
|
85
|
-
type: "audio/mpeg",
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("should return 503 when transcription service is not configured", async () => {
|
|
90
|
-
const runtime = createMockRuntime(); // No transcription service
|
|
91
|
-
const audioFile = createMockAudioFile();
|
|
92
|
-
const request = createFormDataRequest(audioFile);
|
|
93
|
-
|
|
94
|
-
const response = await handleTranscribe({ runtime, request });
|
|
95
|
-
|
|
96
|
-
expect(response.status).toBe(503);
|
|
97
|
-
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
98
|
-
|
|
99
|
-
const body = await response.json();
|
|
100
|
-
expect(body).toEqual({
|
|
101
|
-
error: "Transcription service not configured",
|
|
102
|
-
message: "No transcription service has been configured in the runtime",
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("should return 400 when request is not form data", async () => {
|
|
107
|
-
const mockService = new MockTranscriptionService();
|
|
108
|
-
const runtime = createMockRuntime(mockService);
|
|
109
|
-
const request = createJsonRequest();
|
|
110
|
-
|
|
111
|
-
const response = await handleTranscribe({ runtime, request });
|
|
112
|
-
|
|
113
|
-
expect(response.status).toBe(400);
|
|
114
|
-
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
115
|
-
|
|
116
|
-
const body = await response.json();
|
|
117
|
-
expect(body).toEqual({
|
|
118
|
-
error: "Invalid content type",
|
|
119
|
-
message: "Request must contain multipart/form-data with an audio file",
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("should return 400 when no audio file is provided", async () => {
|
|
124
|
-
const mockService = new MockTranscriptionService();
|
|
125
|
-
const runtime = createMockRuntime(mockService);
|
|
126
|
-
const request = createFormDataRequest(); // No audio file
|
|
127
|
-
|
|
128
|
-
const response = await handleTranscribe({ runtime, request });
|
|
129
|
-
|
|
130
|
-
expect(response.status).toBe(400);
|
|
131
|
-
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
132
|
-
|
|
133
|
-
const body = await response.json();
|
|
134
|
-
expect(body).toEqual({
|
|
135
|
-
error: "Missing audio file",
|
|
136
|
-
message:
|
|
137
|
-
"No audio file found in form data. Please include an 'audio' field.",
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("should accept various valid audio file types", async () => {
|
|
142
|
-
const mockService = new MockTranscriptionService();
|
|
143
|
-
const runtime = createMockRuntime(mockService);
|
|
144
|
-
|
|
145
|
-
const validTypes = [
|
|
146
|
-
"audio/mpeg",
|
|
147
|
-
"audio/mp3",
|
|
148
|
-
"audio/mp4",
|
|
149
|
-
"audio/wav",
|
|
150
|
-
"audio/webm",
|
|
151
|
-
"audio/ogg",
|
|
152
|
-
"audio/flac",
|
|
153
|
-
"audio/aac",
|
|
154
|
-
];
|
|
155
|
-
|
|
156
|
-
for (const type of validTypes) {
|
|
157
|
-
const audioFile = createMockAudioFile(`test.${type.split("/")[1]}`, type);
|
|
158
|
-
const request = createFormDataRequest(audioFile);
|
|
159
|
-
|
|
160
|
-
const response = await handleTranscribe({ runtime, request });
|
|
161
|
-
expect(response.status).toBe(200);
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it("should accept files with empty type (some browsers/systems)", async () => {
|
|
166
|
-
const mockService = new MockTranscriptionService();
|
|
167
|
-
const runtime = createMockRuntime(mockService);
|
|
168
|
-
const audioFile = createMockAudioFile("test.mp3", ""); // Empty type
|
|
169
|
-
const request = createFormDataRequest(audioFile);
|
|
170
|
-
|
|
171
|
-
const response = await handleTranscribe({ runtime, request });
|
|
172
|
-
|
|
173
|
-
expect(response.status).toBe(200);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("should accept files with application/octet-stream type (fallback)", async () => {
|
|
177
|
-
const mockService = new MockTranscriptionService();
|
|
178
|
-
const runtime = createMockRuntime(mockService);
|
|
179
|
-
const audioFile = createMockAudioFile(
|
|
180
|
-
"test.mp3",
|
|
181
|
-
"application/octet-stream"
|
|
182
|
-
);
|
|
183
|
-
const request = createFormDataRequest(audioFile);
|
|
184
|
-
|
|
185
|
-
const response = await handleTranscribe({ runtime, request });
|
|
186
|
-
|
|
187
|
-
expect(response.status).toBe(200);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it("should return 400 for invalid file types", async () => {
|
|
191
|
-
const mockService = new MockTranscriptionService();
|
|
192
|
-
const runtime = createMockRuntime(mockService);
|
|
193
|
-
const audioFile = createMockAudioFile("test.txt", "text/plain");
|
|
194
|
-
const request = createFormDataRequest(audioFile);
|
|
195
|
-
|
|
196
|
-
const response = await handleTranscribe({ runtime, request });
|
|
197
|
-
|
|
198
|
-
expect(response.status).toBe(400);
|
|
199
|
-
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
200
|
-
|
|
201
|
-
const body = await response.json();
|
|
202
|
-
expect(body.error).toBe("Invalid file type");
|
|
203
|
-
expect(body.message).toContain("Unsupported audio file type: text/plain");
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it("should return 500 when transcription service throws an error", async () => {
|
|
207
|
-
const mockService = new MockTranscriptionService(true); // Will throw error
|
|
208
|
-
const runtime = createMockRuntime(mockService);
|
|
209
|
-
const audioFile = createMockAudioFile();
|
|
210
|
-
const request = createFormDataRequest(audioFile);
|
|
211
|
-
|
|
212
|
-
const response = await handleTranscribe({ runtime, request });
|
|
213
|
-
|
|
214
|
-
expect(response.status).toBe(500);
|
|
215
|
-
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
216
|
-
|
|
217
|
-
const body = await response.json();
|
|
218
|
-
expect(body).toEqual({
|
|
219
|
-
error: "Transcription failed",
|
|
220
|
-
message: "Transcription service error",
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it("should handle form data parsing errors gracefully", async () => {
|
|
225
|
-
const mockService = new MockTranscriptionService();
|
|
226
|
-
const runtime = createMockRuntime(mockService);
|
|
227
|
-
|
|
228
|
-
// Create a request with malformed form data
|
|
229
|
-
const request = new Request("https://example.com/transcribe", {
|
|
230
|
-
method: "POST",
|
|
231
|
-
headers: { "Content-Type": "multipart/form-data; boundary=invalid" },
|
|
232
|
-
body: "invalid form data",
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
const response = await handleTranscribe({ runtime, request });
|
|
236
|
-
|
|
237
|
-
expect(response.status).toBe(500);
|
|
238
|
-
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
239
|
-
|
|
240
|
-
const body = await response.json();
|
|
241
|
-
expect(body.error).toBe("Transcription failed");
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it("should handle non-File objects in form data", async () => {
|
|
245
|
-
const mockService = new MockTranscriptionService();
|
|
246
|
-
const runtime = createMockRuntime(mockService);
|
|
247
|
-
|
|
248
|
-
const formData = new FormData();
|
|
249
|
-
formData.append("audio", "not a file"); // String instead of File
|
|
250
|
-
|
|
251
|
-
const request = new Request("https://example.com/transcribe", {
|
|
252
|
-
method: "POST",
|
|
253
|
-
body: formData,
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
const response = await handleTranscribe({ runtime, request });
|
|
257
|
-
|
|
258
|
-
expect(response.status).toBe(400);
|
|
259
|
-
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
260
|
-
|
|
261
|
-
const body = await response.json();
|
|
262
|
-
expect(body).toEqual({
|
|
263
|
-
error: "Missing audio file",
|
|
264
|
-
message:
|
|
265
|
-
"No audio file found in form data. Please include an 'audio' field.",
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it("should pass file metadata to transcription service", async () => {
|
|
270
|
-
const mockService = new MockTranscriptionService();
|
|
271
|
-
const runtime = createMockRuntime(mockService);
|
|
272
|
-
const audioFile = createMockAudioFile(
|
|
273
|
-
"my-recording.wav",
|
|
274
|
-
"audio/wav",
|
|
275
|
-
2048
|
|
276
|
-
);
|
|
277
|
-
|
|
278
|
-
const request = createFormDataRequest(audioFile);
|
|
279
|
-
|
|
280
|
-
const response = await handleTranscribe({ runtime, request });
|
|
281
|
-
|
|
282
|
-
expect(response.status).toBe(200);
|
|
283
|
-
expect(mockService.lastOptions).toEqual({
|
|
284
|
-
audioFile,
|
|
285
|
-
mimeType: "audio/wav",
|
|
286
|
-
size: 2048,
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
});
|