|
1 | 1 | import http, { IncomingMessage, ServerResponse } from "node:http"; |
2 | 2 | import { afterEach, describe, expect, test } from "vitest"; |
3 | 3 | import { HyperbrowserClient } from "../../src/client"; |
| 4 | +import type { MetaComputerUseLlm } from "../../src/types"; |
4 | 5 |
|
5 | 6 | type RecordedRequest = { |
6 | 7 | method?: string; |
@@ -38,7 +39,9 @@ const sendJson = (response: ServerResponse, statusCode: number, payload: unknown |
38 | 39 | response.end(encoded); |
39 | 40 | }; |
40 | 41 |
|
41 | | -const startServer = async (): Promise<TestServer> => { |
| 42 | +const startServer = async ( |
| 43 | + metaModel: MetaComputerUseLlm = "muse-spark-1.3" |
| 44 | +): Promise<TestServer> => { |
42 | 45 | const requests: RecordedRequest[] = []; |
43 | 46 | const server = http.createServer(async (request, response) => { |
44 | 47 | const body = await readJsonBody(request); |
@@ -90,7 +93,7 @@ const startServer = async (): Promise<TestServer> => { |
90 | 93 | output_text: "Second sentence in the Ecology section.", |
91 | 94 | error: null, |
92 | 95 | incomplete_details: null, |
93 | | - model: "muse-spark-1.3", |
| 96 | + model: metaModel, |
94 | 97 | output: [ |
95 | 98 | { |
96 | 99 | type: "function_call", |
@@ -389,76 +392,79 @@ describe("client HTTP integration", () => { |
389 | 392 | ]); |
390 | 393 | }); |
391 | 394 |
|
392 | | - test("Meta Computer Use starts, polls, reads, and stops a task", async () => { |
393 | | - const server = await startServer(); |
394 | | - servers.push(server); |
395 | | - const client = new HyperbrowserClient({ |
396 | | - apiKey: "test-api-key", |
397 | | - baseUrl: server.baseUrl, |
398 | | - }); |
399 | | - |
400 | | - const started = await client.agents.metaComputerUse.start({ |
401 | | - task: "Complete the task", |
402 | | - llm: "muse-spark-1.3", |
403 | | - reasoningEffort: "max", |
404 | | - useCustomApiKeys: true, |
405 | | - apiKeys: { meta: "meta-key" }, |
406 | | - }); |
407 | | - const status = await client.agents.metaComputerUse.getStatus(started.jobId); |
408 | | - const result = await client.agents.metaComputerUse.get(started.jobId); |
409 | | - const stopped = await client.agents.metaComputerUse.stop(started.jobId); |
410 | | - |
411 | | - expect(started).toEqual({ jobId: "meta_job_123", liveUrl: null }); |
412 | | - expect(status).toEqual({ status: "completed" }); |
413 | | - expect(result.data?.finalResult).toBe("done"); |
414 | | - expect(result.data?.steps[0]).toMatchObject({ |
415 | | - created_at: 1788743504, |
416 | | - completed_at: 1788743511, |
417 | | - model: "muse-spark-1.3", |
418 | | - reasoning: { effort: "medium", summary: "concise" }, |
419 | | - }); |
420 | | - expect(result.data?.steps[0].output?.[0]).toMatchObject({ |
421 | | - type: "function_call", |
422 | | - name: "computer.computer", |
423 | | - }); |
424 | | - expect(stopped).toEqual({ success: true }); |
425 | | - expect(server.requests).toEqual([ |
426 | | - { |
427 | | - method: "POST", |
428 | | - url: "/api/task/meta-computer-use", |
| 395 | + test.each(["muse-spark-1.3", "muse-wonder-1.0"] as const)( |
| 396 | + "Meta Computer Use starts, polls, reads, and stops a %s task", |
| 397 | + async (llm) => { |
| 398 | + const server = await startServer(llm); |
| 399 | + servers.push(server); |
| 400 | + const client = new HyperbrowserClient({ |
429 | 401 | apiKey: "test-api-key", |
430 | | - contentType: "application/json", |
431 | | - body: { |
432 | | - task: "Complete the task", |
433 | | - llm: "muse-spark-1.3", |
434 | | - reasoningEffort: "max", |
435 | | - useCustomApiKeys: true, |
436 | | - apiKeys: { meta: "meta-key" }, |
| 402 | + baseUrl: server.baseUrl, |
| 403 | + }); |
| 404 | + |
| 405 | + const started = await client.agents.metaComputerUse.start({ |
| 406 | + task: "Complete the task", |
| 407 | + llm, |
| 408 | + reasoningEffort: "max", |
| 409 | + useCustomApiKeys: true, |
| 410 | + apiKeys: { meta: "meta-key" }, |
| 411 | + }); |
| 412 | + const status = await client.agents.metaComputerUse.getStatus(started.jobId); |
| 413 | + const result = await client.agents.metaComputerUse.get(started.jobId); |
| 414 | + const stopped = await client.agents.metaComputerUse.stop(started.jobId); |
| 415 | + |
| 416 | + expect(started).toEqual({ jobId: "meta_job_123", liveUrl: null }); |
| 417 | + expect(status).toEqual({ status: "completed" }); |
| 418 | + expect(result.data?.finalResult).toBe("done"); |
| 419 | + expect(result.data?.steps[0]).toMatchObject({ |
| 420 | + created_at: 1788743504, |
| 421 | + completed_at: 1788743511, |
| 422 | + model: llm, |
| 423 | + reasoning: { effort: "medium", summary: "concise" }, |
| 424 | + }); |
| 425 | + expect(result.data?.steps[0].output?.[0]).toMatchObject({ |
| 426 | + type: "function_call", |
| 427 | + name: "computer.computer", |
| 428 | + }); |
| 429 | + expect(stopped).toEqual({ success: true }); |
| 430 | + expect(server.requests).toEqual([ |
| 431 | + { |
| 432 | + method: "POST", |
| 433 | + url: "/api/task/meta-computer-use", |
| 434 | + apiKey: "test-api-key", |
| 435 | + contentType: "application/json", |
| 436 | + body: { |
| 437 | + task: "Complete the task", |
| 438 | + llm, |
| 439 | + reasoningEffort: "max", |
| 440 | + useCustomApiKeys: true, |
| 441 | + apiKeys: { meta: "meta-key" }, |
| 442 | + }, |
437 | 443 | }, |
438 | | - }, |
439 | | - { |
440 | | - method: "GET", |
441 | | - url: "/api/task/meta-computer-use/meta_job_123/status", |
442 | | - apiKey: "test-api-key", |
443 | | - contentType: "application/json", |
444 | | - body: undefined, |
445 | | - }, |
446 | | - { |
447 | | - method: "GET", |
448 | | - url: "/api/task/meta-computer-use/meta_job_123", |
449 | | - apiKey: "test-api-key", |
450 | | - contentType: "application/json", |
451 | | - body: undefined, |
452 | | - }, |
453 | | - { |
454 | | - method: "PUT", |
455 | | - url: "/api/task/meta-computer-use/meta_job_123/stop", |
456 | | - apiKey: "test-api-key", |
457 | | - contentType: "application/json", |
458 | | - body: undefined, |
459 | | - }, |
460 | | - ]); |
461 | | - }); |
| 444 | + { |
| 445 | + method: "GET", |
| 446 | + url: "/api/task/meta-computer-use/meta_job_123/status", |
| 447 | + apiKey: "test-api-key", |
| 448 | + contentType: "application/json", |
| 449 | + body: undefined, |
| 450 | + }, |
| 451 | + { |
| 452 | + method: "GET", |
| 453 | + url: "/api/task/meta-computer-use/meta_job_123", |
| 454 | + apiKey: "test-api-key", |
| 455 | + contentType: "application/json", |
| 456 | + body: undefined, |
| 457 | + }, |
| 458 | + { |
| 459 | + method: "PUT", |
| 460 | + url: "/api/task/meta-computer-use/meta_job_123/stop", |
| 461 | + apiKey: "test-api-key", |
| 462 | + contentType: "application/json", |
| 463 | + body: undefined, |
| 464 | + }, |
| 465 | + ]); |
| 466 | + } |
| 467 | + ); |
462 | 468 |
|
463 | 469 | test("Jev Computer Use starts, polls, reads, and stops a task", async () => { |
464 | 470 | const server = await startServer(); |
|
0 commit comments