




















@@ -48,6 +48,14 @@ function makeAgentModelEntry(overrides: Record<string, unknown> = {}) {
4848};
4949}
505051+function jsonResponse(payload: unknown, init: ResponseInit = {}): Response {
52+return new Response(JSON.stringify(payload), {
53+status: 200,
54+headers: { "Content-Type": "application/json" },
55+ ...init,
56+});
57+}
58+5159function expectedStaticChatCatalog() {
5260return DEEPINFRA_MODEL_CATALOG.map((model) => {
5361const compat = Object.assign({}, model.compat, {
@@ -195,10 +203,7 @@ describe("discoverDeepInfraModels (chat-only shim)", () => {
195203});
196204197205it("fetches the openclaw-projection endpoint and parses chat-surface entries when an API key is configured", async () => {
198-const mockFetch = vi.fn().mockResolvedValue({
199-ok: true,
200-json: () => Promise.resolve({ data: [makeAgentModelEntry()] }),
201-});
206+const mockFetch = vi.fn().mockResolvedValue(jsonResponse({ data: [makeAgentModelEntry()] }));
202207203208await withFetchPathTest(mockFetch, { DEEPINFRA_API_KEY: "sk-test" }, async () => {
204209const models = await discoverDeepInfraModels();
@@ -228,21 +233,19 @@ describe("discoverDeepInfraModels (chat-only shim)", () => {
228233});
229234230235it("skips entries with no metadata or no surface tag, and deduplicates ids", async () => {
231-const mockFetch = vi.fn().mockResolvedValue({
232-ok: true,
233-json: () =>
234-Promise.resolve({
235-data: [
236-{ id: "BAAI/bge-m3", object: "model", metadata: null },
237-makeAgentModelEntry({
238-id: "untagged/model",
239-metadata: { context_length: 1, max_tokens: 1, pricing: {}, tags: [] },
240-}),
241-makeAgentModelEntry(),
242-makeAgentModelEntry(),
243-],
244-}),
245-});
236+const mockFetch = vi.fn().mockResolvedValue(
237+jsonResponse({
238+data: [
239+{ id: "BAAI/bge-m3", object: "model", metadata: null },
240+makeAgentModelEntry({
241+id: "untagged/model",
242+metadata: { context_length: 1, max_tokens: 1, pricing: {}, tags: [] },
243+}),
244+makeAgentModelEntry(),
245+makeAgentModelEntry(),
246+],
247+}),
248+);
246249247250await withFetchPathTest(mockFetch, { DEEPINFRA_API_KEY: "sk-test" }, async () => {
248251const models = await discoverDeepInfraModels();
@@ -283,7 +286,7 @@ describe("discoverDeepInfraModels (chat-only shim)", () => {
283286});
284287285288it("falls back to the static catalog on non-2xx HTTP responses", async () => {
286-const mockFetch = vi.fn().mockResolvedValue({ ok: false, status: 503 });
289+const mockFetch = vi.fn().mockResolvedValue(new Response("", { status: 503 }));
287290288291await withFetchPathTest(mockFetch, { DEEPINFRA_API_KEY: "sk-test" }, async () => {
289292const models = await discoverDeepInfraModels();
@@ -294,14 +297,10 @@ describe("discoverDeepInfraModels (chat-only shim)", () => {
294297it("falls back without caching malformed successful model list payloads", async () => {
295298const mockFetch = vi
296299.fn()
297-.mockResolvedValueOnce({
298-ok: true,
299-json: () => Promise.resolve({ data: {} }),
300-})
301-.mockResolvedValueOnce({
302-ok: true,
303-json: () => Promise.resolve({ data: [makeAgentModelEntry({ id: "recovered/model" })] }),
304-});
300+.mockResolvedValueOnce(jsonResponse({ data: {} }))
301+.mockResolvedValueOnce(
302+jsonResponse({ data: [makeAgentModelEntry({ id: "recovered/model" })] }),
303+);
305304306305await withFetchPathTest(mockFetch, { DEEPINFRA_API_KEY: "sk-test" }, async () => {
307306expect((await discoverDeepInfraModels()).map((m) => m.id)).toEqual(
@@ -328,14 +327,8 @@ describe("discoverDeepInfraModels (chat-only shim)", () => {
328327it("caches successful discovery responses only", async () => {
329328const mockFetch = vi
330329.fn()
331-.mockResolvedValueOnce({
332-ok: true,
333-json: () => Promise.resolve({ data: [makeAgentModelEntry({ id: "first/model" })] }),
334-})
335-.mockResolvedValueOnce({
336-ok: true,
337-json: () => Promise.resolve({ data: [makeAgentModelEntry({ id: "second/model" })] }),
338-});
330+.mockResolvedValueOnce(jsonResponse({ data: [makeAgentModelEntry({ id: "first/model" })] }))
331+.mockResolvedValueOnce(jsonResponse({ data: [makeAgentModelEntry({ id: "second/model" })] }));
339332340333await withFetchPathTest(mockFetch, { DEEPINFRA_API_KEY: "sk-test" }, async () => {
341334const expectedIds = expectedLiveChatCatalog([
@@ -359,14 +352,10 @@ describe("discoverDeepInfraModels (chat-only shim)", () => {
359352it("does not cache successful responses that produce no live catalog rows", async () => {
360353const mockFetch = vi
361354.fn()
362-.mockResolvedValueOnce({
363-ok: true,
364-json: () => Promise.resolve({ data: [] }),
365-})
366-.mockResolvedValueOnce({
367-ok: true,
368-json: () => Promise.resolve({ data: [makeAgentModelEntry({ id: "recovered/model" })] }),
369-});
355+.mockResolvedValueOnce(jsonResponse({ data: [] }))
356+.mockResolvedValueOnce(
357+jsonResponse({ data: [makeAgentModelEntry({ id: "recovered/model" })] }),
358+);
370359371360await withFetchPathTest(mockFetch, { DEEPINFRA_API_KEY: "sk-test" }, async () => {
372361expect((await discoverDeepInfraModels()).map((m) => m.id)).toEqual(
@@ -393,67 +382,65 @@ describe("discoverDeepInfraModels (chat-only shim)", () => {
393382394383describe("discoverDeepInfraSurfaces (per-surface bucketing)", () => {
395384it("buckets dynamic entries by short-alias surface tag", async () => {
396-const mockFetch = vi.fn().mockResolvedValue({
397-ok: true,
398-json: () =>
399-Promise.resolve({
400-data: [
401-makeAgentModelEntry({
402-id: "anthropic/claude-sonnet-4-6",
403-metadata: {
404-description: "claude sonnet 4.6",
405-context_length: 200000,
406-max_tokens: 8192,
407-pricing: { input_tokens: 3, output_tokens: 15 },
408-tags: ["chat", "vlm", "vision", "prompt_cache"],
409-},
410-}),
411-makeAgentModelEntry({
412-id: "BAAI/bge-m3",
413-metadata: {
414-description: "bge-m3",
415-pricing: { input_tokens: 0.01 },
416-tags: ["embed"],
417-},
418-}),
419-makeAgentModelEntry({
420-id: "black-forest-labs/FLUX-1-schnell",
421-metadata: {
422-description: "FLUX schnell",
423-pricing: { per_image_unit: 0.003 },
424-tags: ["image-gen"],
425-default_width: 1024,
426-default_height: 1024,
427-default_iterations: 4,
428-},
429-}),
430-makeAgentModelEntry({
431-id: "Wan-AI/Wan2.6-T2V",
432-metadata: {
433-description: "Wan T2V",
434-pricing: { output_seconds: 0.05 },
435-tags: ["video-gen"],
436-},
437-}),
438-makeAgentModelEntry({
439-id: "Qwen/Qwen3-TTS",
440-metadata: {
441-description: "Qwen3 TTS",
442-pricing: { input_characters: 0.65 },
443-tags: ["tts"],
444-},
445-}),
446-makeAgentModelEntry({
447-id: "openai/whisper-large-v3-turbo",
448-metadata: {
449-description: "whisper",
450-pricing: { input_seconds: 0.00004 },
451-tags: ["stt"],
452-},
453-}),
454-],
455-}),
456-});
385+const mockFetch = vi.fn().mockResolvedValue(
386+jsonResponse({
387+data: [
388+makeAgentModelEntry({
389+id: "anthropic/claude-sonnet-4-6",
390+metadata: {
391+description: "claude sonnet 4.6",
392+context_length: 200000,
393+max_tokens: 8192,
394+pricing: { input_tokens: 3, output_tokens: 15 },
395+tags: ["chat", "vlm", "vision", "prompt_cache"],
396+},
397+}),
398+makeAgentModelEntry({
399+id: "BAAI/bge-m3",
400+metadata: {
401+description: "bge-m3",
402+pricing: { input_tokens: 0.01 },
403+tags: ["embed"],
404+},
405+}),
406+makeAgentModelEntry({
407+id: "black-forest-labs/FLUX-1-schnell",
408+metadata: {
409+description: "FLUX schnell",
410+pricing: { per_image_unit: 0.003 },
411+tags: ["image-gen"],
412+default_width: 1024,
413+default_height: 1024,
414+default_iterations: 4,
415+},
416+}),
417+makeAgentModelEntry({
418+id: "Wan-AI/Wan2.6-T2V",
419+metadata: {
420+description: "Wan T2V",
421+pricing: { output_seconds: 0.05 },
422+tags: ["video-gen"],
423+},
424+}),
425+makeAgentModelEntry({
426+id: "Qwen/Qwen3-TTS",
427+metadata: {
428+description: "Qwen3 TTS",
429+pricing: { input_characters: 0.65 },
430+tags: ["tts"],
431+},
432+}),
433+makeAgentModelEntry({
434+id: "openai/whisper-large-v3-turbo",
435+metadata: {
436+description: "whisper",
437+pricing: { input_seconds: 0.00004 },
438+tags: ["stt"],
439+},
440+}),
441+],
442+}),
443+);
457444458445await withFetchPathTest(mockFetch, { DEEPINFRA_API_KEY: "sk-test" }, async () => {
459446const catalog = await discoverDeepInfraSurfaces();
@@ -471,35 +458,33 @@ describe("discoverDeepInfraSurfaces (per-surface bucketing)", () => {
471458});
472459473460it("drops malformed live numeric metadata", async () => {
474-const mockFetch = vi.fn().mockResolvedValue({
475-ok: true,
476-json: () =>
477-Promise.resolve({
478-data: [
479-makeAgentModelEntry({
480-id: "bad/chat",
481-metadata: {
482-description: "bad chat",
483-context_length: -1,
484-max_tokens: 1.5,
485-pricing: { input_tokens: 3, output_tokens: 15 },
486-tags: ["chat"],
487-},
488-}),
489-makeAgentModelEntry({
490-id: "bad/image",
491-metadata: {
492-description: "bad image",
493-pricing: { per_image_unit: 0.003 },
494-tags: ["image-gen"],
495-default_width: Number.POSITIVE_INFINITY,
496-default_height: 1024.5,
497-default_iterations: 0,
498-},
499-}),
500-],
501-}),
502-});
461+const mockFetch = vi.fn().mockResolvedValue(
462+jsonResponse({
463+data: [
464+makeAgentModelEntry({
465+id: "bad/chat",
466+metadata: {
467+description: "bad chat",
468+context_length: -1,
469+max_tokens: 1.5,
470+pricing: { input_tokens: 3, output_tokens: 15 },
471+tags: ["chat"],
472+},
473+}),
474+makeAgentModelEntry({
475+id: "bad/image",
476+metadata: {
477+description: "bad image",
478+pricing: { per_image_unit: 0.003 },
479+tags: ["image-gen"],
480+default_width: Number.POSITIVE_INFINITY,
481+default_height: 1024.5,
482+default_iterations: 0,
483+},
484+}),
485+],
486+}),
487+);
503488504489await withFetchPathTest(mockFetch, { DEEPINFRA_API_KEY: "sk-test" }, async () => {
505490const catalog = await discoverDeepInfraSurfaces();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。